aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-12-19 13:54:51 +1100
committerIan Coleman <coleman.ian@gmail.com>2016-12-19 13:55:21 +1100
commitba3cb9ecae2667e98af71f5b38a862ba604e8e1c (patch)
tree380d24d03b7a3e6c7e02592901a62d605b2df61e /src/js
parent52da415f0385a6a89070498d14259aed980f989b (diff)
downloadBIP39-ba3cb9ecae2667e98af71f5b38a862ba604e8e1c.tar.gz
BIP39-ba3cb9ecae2667e98af71f5b38a862ba604e8e1c.tar.zst
BIP39-ba3cb9ecae2667e98af71f5b38a862ba604e8e1c.zip
xpub key can be used as bip32 root key
Diffstat (limited to 'src/js')
-rw-r--r--src/js/index.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/js/index.js b/src/js/index.js
index cac420e..45edea8 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -228,11 +228,11 @@
228 // Calculate and display 228 // Calculate and display
229 calcBip32RootKeyFromBase58(rootKeyBase58); 229 calcBip32RootKeyFromBase58(rootKeyBase58);
230 calcForDerivationPath(); 230 calcForDerivationPath();
231 hidePending();
232 } 231 }
233 232
234 function calcForDerivationPath() { 233 function calcForDerivationPath() {
235 showPending(); 234 showPending();
235 clearAddressesList();
236 hideValidationError(); 236 hideValidationError();
237 // Get the derivation path 237 // Get the derivation path
238 var derivationPath = getDerivationPath(); 238 var derivationPath = getDerivationPath();
@@ -334,7 +334,12 @@
334 continue; 334 continue;
335 } 335 }
336 var hardened = bit[bit.length-1] == "'"; 336 var hardened = bit[bit.length-1] == "'";
337 if (hardened) { 337 var isPriv = "privKey" in extendedKey;
338 var invalidDerivationPath = hardened && !isPriv;
339 if (invalidDerivationPath) {
340 extendedKey = null;
341 }
342 else if (hardened) {
338 extendedKey = extendedKey.deriveHardened(index); 343 extendedKey = extendedKey.deriveHardened(index);
339 } 344 }
340 else { 345 else {
@@ -453,6 +458,12 @@
453 } 458 }
454 } 459 }
455 } 460 }
461 // Check no hardened derivation path when using xpub keys
462 var hardened = path.indexOf("'") > -1;
463 var isXpubkey = !("privKey" in bip32RootKey);
464 if (hardened && isXpubkey) {
465 return "Hardened derivation path is invalid with xpub key";
466 }
456 return false; 467 return false;
457 } 468 }
458 469
@@ -479,7 +490,11 @@
479 DOM.seed.val(seed); 490 DOM.seed.val(seed);
480 var rootKey = bip32RootKey.toBase58(); 491 var rootKey = bip32RootKey.toBase58();
481 DOM.rootKey.val(rootKey); 492 DOM.rootKey.val(rootKey);
482 var extendedPrivKey = bip32ExtendedKey.toBase58(); 493 var xprvkeyB58 = "NA";
494 if (bip32ExtendedKey.privKey) {
495 xprvkeyB58 = bip32ExtendedKey.toBase58();
496 }
497 var extendedPrivKey = xprvkeyB58;
483 DOM.extendedPrivKey.val(extendedPrivKey); 498 DOM.extendedPrivKey.val(extendedPrivKey);
484 var extendedPubKey = bip32ExtendedKey.toBase58(false); 499 var extendedPubKey = bip32ExtendedKey.toBase58(false);
485 DOM.extendedPubKey.val(extendedPubKey); 500 DOM.extendedPubKey.val(extendedPubKey);
@@ -513,7 +528,10 @@
513 key = bip32ExtendedKey.derive(index); 528 key = bip32ExtendedKey.derive(index);
514 } 529 }
515 var address = key.getAddress().toString(); 530 var address = key.getAddress().toString();
516 var privkey = key.privKey.toWIF(network); 531 var privkey = "NA";
532 if (key.privKey) {
533 privkey = key.privKey.toWIF(network);
534 }
517 var pubkey = key.pubKey.toHex(); 535 var pubkey = key.pubKey.toHex();
518 var indexText = getDerivationPath() + "/" + index; 536 var indexText = getDerivationPath() + "/" + index;
519 if (useHardenedAddresses) { 537 if (useHardenedAddresses) {