diff options
author | Ian Coleman <coleman.ian@gmail.com> | 2016-12-19 14:16:49 +1100 |
---|---|---|
committer | Ian Coleman <coleman.ian@gmail.com> | 2016-12-19 14:17:36 +1100 |
commit | 0a1f0259d1cfe5217ca9c08f7fbd371a03703594 (patch) | |
tree | 43a1ad7a58be69399aad6e3047191ec23c3c77fc | |
parent | ba3cb9ecae2667e98af71f5b38a862ba604e8e1c (diff) | |
download | BIP39-0a1f0259d1cfe5217ca9c08f7fbd371a03703594.tar.gz BIP39-0a1f0259d1cfe5217ca9c08f7fbd371a03703594.tar.zst BIP39-0a1f0259d1cfe5217ca9c08f7fbd371a03703594.zip |
Root key validity is checked before deriving
-rw-r--r-- | bip39-standalone.html | 8 | ||||
-rw-r--r-- | src/js/index.js | 8 | ||||
-rw-r--r-- | tests.js | 24 |
3 files changed, 40 insertions, 0 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html index 367d9a2..ca18ea8 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html | |||
@@ -18964,6 +18964,10 @@ window.Entropy = new (function() { | |||
18964 | } | 18964 | } |
18965 | 18965 | ||
18966 | function calcBip32ExtendedKey(path) { | 18966 | function calcBip32ExtendedKey(path) { |
18967 | // Check there's a root key to derive from | ||
18968 | if (!bip32RootKey) { | ||
18969 | return bip32RootKey; | ||
18970 | } | ||
18967 | var extendedKey = bip32RootKey; | 18971 | var extendedKey = bip32RootKey; |
18968 | // Derive the key from the path | 18972 | // Derive the key from the path |
18969 | var pathBits = path.split("/"); | 18973 | var pathBits = path.split("/"); |
@@ -19098,6 +19102,10 @@ window.Entropy = new (function() { | |||
19098 | } | 19102 | } |
19099 | } | 19103 | } |
19100 | } | 19104 | } |
19105 | // Check root key exists or else derivation path is useless! | ||
19106 | if (!bip32RootKey) { | ||
19107 | return "No root key"; | ||
19108 | } | ||
19101 | // Check no hardened derivation path when using xpub keys | 19109 | // Check no hardened derivation path when using xpub keys |
19102 | var hardened = path.indexOf("'") > -1; | 19110 | var hardened = path.indexOf("'") > -1; |
19103 | var isXpubkey = !("privKey" in bip32RootKey); | 19111 | var isXpubkey = !("privKey" in bip32RootKey); |
diff --git a/src/js/index.js b/src/js/index.js index 45edea8..13c6178 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -324,6 +324,10 @@ | |||
324 | } | 324 | } |
325 | 325 | ||
326 | function calcBip32ExtendedKey(path) { | 326 | function calcBip32ExtendedKey(path) { |
327 | // Check there's a root key to derive from | ||
328 | if (!bip32RootKey) { | ||
329 | return bip32RootKey; | ||
330 | } | ||
327 | var extendedKey = bip32RootKey; | 331 | var extendedKey = bip32RootKey; |
328 | // Derive the key from the path | 332 | // Derive the key from the path |
329 | var pathBits = path.split("/"); | 333 | var pathBits = path.split("/"); |
@@ -458,6 +462,10 @@ | |||
458 | } | 462 | } |
459 | } | 463 | } |
460 | } | 464 | } |
465 | // Check root key exists or else derivation path is useless! | ||
466 | if (!bip32RootKey) { | ||
467 | return "No root key"; | ||
468 | } | ||
461 | // Check no hardened derivation path when using xpub keys | 469 | // Check no hardened derivation path when using xpub keys |
462 | var hardened = path.indexOf("'") > -1; | 470 | var hardened = path.indexOf("'") > -1; |
463 | var isXpubkey = !("privKey" in bip32RootKey); | 471 | var isXpubkey = !("privKey" in bip32RootKey); |
@@ -3241,6 +3241,30 @@ page.open(url, function(status) { | |||
3241 | }); | 3241 | }); |
3242 | }, | 3242 | }, |
3243 | 3243 | ||
3244 | // github issue 39 | ||
3245 | // no root key shows feedback | ||
3246 | function() { | ||
3247 | page.open(url, function(status) { | ||
3248 | // click the bip32 tab on fresh page | ||
3249 | page.evaluate(function() { | ||
3250 | $("#bip32-tab a").click(); | ||
3251 | }); | ||
3252 | waitForFeedback(function() { | ||
3253 | // Check feedback is correct | ||
3254 | var expected = "No root key"; | ||
3255 | var actual = page.evaluate(function() { | ||
3256 | return $(".feedback").text(); | ||
3257 | }); | ||
3258 | if (actual != expected) { | ||
3259 | console.log("Blank root key not detected"); | ||
3260 | console.log("Expected: " + expected); | ||
3261 | console.log("Actual: " + actual); | ||
3262 | fail(); | ||
3263 | } | ||
3264 | next(); | ||
3265 | }); | ||
3266 | }); | ||
3267 | }, | ||
3244 | 3268 | ||
3245 | // If you wish to add more tests, do so here... | 3269 | // If you wish to add more tests, do so here... |
3246 | 3270 | ||