diff options
-rw-r--r-- | bip39-standalone.html | 2 | ||||
-rw-r--r-- | src/js/index.js | 2 | ||||
-rw-r--r-- | tests.js | 29 |
3 files changed, 31 insertions, 2 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html index afef084..3b4f0f2 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html | |||
@@ -19488,7 +19488,7 @@ window.Entropy = new (function() { | |||
19488 | var hash = sjcl.hash.sha256.hash(entropy.cleanStr); | 19488 | var hash = sjcl.hash.sha256.hash(entropy.cleanStr); |
19489 | var hex = sjcl.codec.hex.fromBits(hash); | 19489 | var hex = sjcl.codec.hex.fromBits(hash); |
19490 | bits = BigInteger.parse(hex, 16).toString(2); | 19490 | bits = BigInteger.parse(hex, 16).toString(2); |
19491 | for (var i=0; i<256-bits.length; i++) { | 19491 | while (bits.length % 256 != 0) { |
19492 | bits = "0" + bits; | 19492 | bits = "0" + bits; |
19493 | } | 19493 | } |
19494 | // Truncate hash to suit number of words | 19494 | // Truncate hash to suit number of words |
diff --git a/src/js/index.js b/src/js/index.js index 5318800..c3c0a4a 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -843,7 +843,7 @@ | |||
843 | var hash = sjcl.hash.sha256.hash(entropy.cleanStr); | 843 | var hash = sjcl.hash.sha256.hash(entropy.cleanStr); |
844 | var hex = sjcl.codec.hex.fromBits(hash); | 844 | var hex = sjcl.codec.hex.fromBits(hash); |
845 | bits = BigInteger.parse(hex, 16).toString(2); | 845 | bits = BigInteger.parse(hex, 16).toString(2); |
846 | for (var i=0; i<256-bits.length; i++) { | 846 | while (bits.length % 256 != 0) { |
847 | bits = "0" + bits; | 847 | bits = "0" + bits; |
848 | } | 848 | } |
849 | // Truncate hash to suit number of words | 849 | // Truncate hash to suit number of words |
@@ -3335,6 +3335,35 @@ page.open(url, function(status) { | |||
3335 | }); | 3335 | }); |
3336 | }, | 3336 | }, |
3337 | 3337 | ||
3338 | // Github issue 49 | ||
3339 | // padding for binary should give length with multiple of 256 | ||
3340 | // hashed entropy 1111 is length 252, so requires 4 leading zeros | ||
3341 | // prior to issue 49 it would only generate 2 leading zeros, ie missing 2 | ||
3342 | function() { | ||
3343 | page.open(url, function(status) { | ||
3344 | expected = "avocado valid quantum cross link predict excuse edit street able flame large galaxy ginger nuclear" | ||
3345 | // use entropy | ||
3346 | page.evaluate(function() { | ||
3347 | $(".use-entropy").prop("checked", true).trigger("change"); | ||
3348 | $(".entropy").val("1111").trigger("input"); | ||
3349 | }); | ||
3350 | waitForGenerate(function() { | ||
3351 | // get the mnemonic | ||
3352 | var actual = page.evaluate(function() { | ||
3353 | return $(".phrase").val(); | ||
3354 | }); | ||
3355 | // check the mnemonic is correct | ||
3356 | if (actual != expected) { | ||
3357 | console.log("Left padding error for entropy"); | ||
3358 | console.log("Expected: " + expected); | ||
3359 | console.log("Actual: " + actual); | ||
3360 | fail(); | ||
3361 | } | ||
3362 | next(); | ||
3363 | }); | ||
3364 | }); | ||
3365 | }, | ||
3366 | |||
3338 | // If you wish to add more tests, do so here... | 3367 | // If you wish to add more tests, do so here... |
3339 | 3368 | ||
3340 | // Here is a blank test template | 3369 | // Here is a blank test template |