]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Root key validity is checked before deriving
authorIan Coleman <coleman.ian@gmail.com>
Mon, 19 Dec 2016 03:16:49 +0000 (14:16 +1100)
committerIan Coleman <coleman.ian@gmail.com>
Mon, 19 Dec 2016 03:17:36 +0000 (14:17 +1100)
bip39-standalone.html
src/js/index.js
tests.js

index 367d9a2fdc1d923728b3cf88e45a1c2f18a0f0c6..ca18ea8b609890fc6e2f706a02e07df8a29fb64d 100644 (file)
@@ -18964,6 +18964,10 @@ window.Entropy = new (function() {
     }
 
     function calcBip32ExtendedKey(path) {
+        // Check there's a root key to derive from
+        if (!bip32RootKey) {
+            return bip32RootKey;
+        }
         var extendedKey = bip32RootKey;
         // Derive the key from the path
         var pathBits = path.split("/");
@@ -19098,6 +19102,10 @@ window.Entropy = new (function() {
                 }
             }
         }
+        // Check root key exists or else derivation path is useless!
+        if (!bip32RootKey) {
+            return "No root key";
+        }
         // Check no hardened derivation path when using xpub keys
         var hardened = path.indexOf("'") > -1;
         var isXpubkey = !("privKey" in bip32RootKey);
index 45edea8477b835245c3a03b34183310f226ebbc3..13c61780931f03282c99d043e76d7231af7fbc0f 100644 (file)
     }
 
     function calcBip32ExtendedKey(path) {
+        // Check there's a root key to derive from
+        if (!bip32RootKey) {
+            return bip32RootKey;
+        }
         var extendedKey = bip32RootKey;
         // Derive the key from the path
         var pathBits = path.split("/");
                 }
             }
         }
+        // Check root key exists or else derivation path is useless!
+        if (!bip32RootKey) {
+            return "No root key";
+        }
         // Check no hardened derivation path when using xpub keys
         var hardened = path.indexOf("'") > -1;
         var isXpubkey = !("privKey" in bip32RootKey);
index 19a371272c705a51c786a8ca10495ae57580c0cc..3cde75ff8aacd464670fe5217842e9f1ac8ecaa1 100644 (file)
--- a/tests.js
+++ b/tests.js
@@ -3241,6 +3241,30 @@ page.open(url, function(status) {
 });
 },
 
+// github issue 39
+// no root key shows feedback
+function() {
+page.open(url, function(status) {
+    // click the bip32 tab on fresh page
+    page.evaluate(function() {
+        $("#bip32-tab a").click();
+    });
+    waitForFeedback(function() {
+        // Check feedback is correct
+        var expected = "No root key";
+        var actual = page.evaluate(function() {
+            return $(".feedback").text();
+        });
+        if (actual != expected) {
+            console.log("Blank root key not detected");
+            console.log("Expected: " + expected);
+            console.log("Actual: " + actual);
+            fail();
+        }
+        next();
+    });
+});
+},
 
 // If you wish to add more tests, do so here...