From c554e6ff5c2c543997841c0fb0a506262843e8df Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Mon, 12 Dec 2016 10:54:08 +1100 Subject: [PATCH] BIP44 Account xprv and xpub keys are shown which are used for import / export in most BIP44 wallets. --- src/index.html | 55 ++++++++++++++++++++++++++++--------------------- src/js/index.js | 23 +++++++++++++++++++++ tests.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 23 deletions(-) diff --git a/src/index.html b/src/index.html index aab473c..e3eebd6 100644 --- a/src/index.html +++ b/src/index.html @@ -312,6 +312,36 @@ +
+ +
+

The account extendend keys can be used for importing to most BIP44 compatible wallets, such as mycelium or electrum.

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+

The BIP32 derivation path and extended keys are the basis for the derived addresses.

+
+
@@ -343,27 +373,6 @@ Use hardened addresses
-
- -
-

- m/44'/0'/0' generates extended keys for import / export -

-

- m/44'/0'/1' for the next account. Continue incrementing for more accounts (most use a single account). -

-

- m/44'/0'/0'/0 generates public addresses -

-

- m/44'/0'/0'/1 generates change addresses -

-

- For more info see the - Mycelium Wallet homepage -

-
-
@@ -394,13 +403,13 @@
- +
- +
diff --git a/src/js/index.js b/src/js/index.js index 6367c01..748a2ba 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -51,6 +51,8 @@ DOM.bip44purpose = $("#bip44 .purpose"); DOM.bip44coin = $("#bip44 .coin"); DOM.bip44account = $("#bip44 .account"); + DOM.bip44accountXprv = $("#bip44 .account-xprv"); + DOM.bip44accountXpub = $("#bip44 .account-xpub"); DOM.bip44change = $("#bip44 .change"); DOM.generatedStrength = $(".generate-container .strength"); DOM.hardenedAddresses = $(".hardened-addresses"); @@ -239,6 +241,9 @@ return; } bip32ExtendedKey = calcBip32ExtendedKey(derivationPath); + if (bip44TabSelected()) { + displayBip44Info(); + } displayBip32Info(); hidePending(); } @@ -450,6 +455,24 @@ return false; } + function displayBip44Info() { + // Get the derivation path for the account + var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); + var coin = parseIntNoNaN(DOM.bip44coin.val(), 0); + var account = parseIntNoNaN(DOM.bip44account.val(), 0); + var path = "m/"; + path += purpose + "'/"; + path += coin + "'/"; + path += account + "'/"; + // Calculate the account extended keys + var accountExtendedKey = calcBip32ExtendedKey(path); + var accountXprv = accountExtendedKey.toBase58(); + var accountXpub = accountExtendedKey.toBase58(false); + // Display the extended keys + DOM.bip44accountXprv.val(accountXprv); + DOM.bip44accountXpub.val(accountXpub); + } + function displayBip32Info() { // Display the key DOM.seed.val(seed); diff --git a/tests.js b/tests.js index 10d13a3..d5a73f6 100644 --- a/tests.js +++ b/tests.js @@ -3086,6 +3086,58 @@ page.open(url, function(status) { }); }, +// BIP44 account extendend private key is shown +// github issue 37 - compatibility with electrum +function() { +page.open(url, function(status) { + // set the phrase + var expected = "xprv9yzrnt4zWVJUr1k2VxSPy9ettKz5PpeDMgaVG7UKedhqnw1tDkxP2UyYNhuNSumk2sLE5ctwKZs9vwjsq3e1vo9egCK6CzP87H2cVYXpfwQ"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + // check the BIP44 account extended private key + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".account-xprv").val(); + }); + if (actual != expected) { + console.log("BIP44 account extended private key is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + +// BIP44 account extendend public key is shown +// github issue 37 - compatibility with electrum +function() { +page.open(url, function(status) { + // set the phrase + var expected = "xpub6CzDCPbtLrrn4VpVbyyQLHbdSMpZoHN4iuW64VswCyEpfjM2mJGdaHJ2DyuZwtst96E16VvcERb8BBeJdHSCVmAq9RhtRQg6eAZFrTKCNqf"; + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + // check the BIP44 account extended public key + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".account-xpub").val(); + }); + if (actual != expected) { + console.log("BIP44 account extended public key is incorrect"); + console.log("Expected: " + expected); + console.log("Actual: " + actual); + fail(); + } + next(); + }); +}); +}, + // If you wish to add more tests, do so here... -- 2.41.0