]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blobdiff - src/js/index.js
Merge pull request #48 from chrisrico/master
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / src / js / index.js
index 45edea8477b835245c3a03b34183310f226ebbc3..af09606916b22b54d28829ca4dd68f1bfa42dd75 100644 (file)
@@ -3,7 +3,7 @@
     // mnemonics is populated as required by getLanguage
     var mnemonics = { "english": new Mnemonic("english") };
     var mnemonic = mnemonics["english"];
-    var seed = null
+    var seed = null;
     var bip32RootKey = null;
     var bip32ExtendedKey = null;
     var network = bitcoin.networks.bitcoin;
     }
 
     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);
         var closestWord = words[0];
         for (var i=0; i<words.length; i++) {
             var comparedTo = words[i];
+            if (comparedTo.indexOf(word) == 0) return comparedTo;
+
             var distance = Levenshtein.get(word, comparedTo);
             if (distance < minDistance) {
                 closestWord = comparedTo;