From 1b12b2f5f12b32a2ed6e69ff77f10b889b383e97 Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Wed, 2 Nov 2016 12:13:21 +1100 Subject: [PATCH] Public key column in table, shown as hex --- bip39-standalone.html | 25 ++++++++++++++++++++-- src/index.html | 7 ++++++ src/js/index.js | 18 ++++++++++++++-- tests.js | 50 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/bip39-standalone.html b/bip39-standalone.html index bb3ea38..62bd43c 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html @@ -298,6 +298,12 @@ + +
+ Public Key   + +
+
Private Key   @@ -442,6 +448,7 @@ + @@ -16172,6 +16179,7 @@ var Mnemonic = function(language) { var showIndex = true; var showAddress = true; + var showPubKey = true; var showPrivKey = true; var phraseChangeTimeoutEvent = null; @@ -16206,6 +16214,7 @@ var Mnemonic = function(language) { DOM.tab = $(".derivation-type a"); DOM.indexToggle = $(".index-toggle"); DOM.addressToggle = $(".address-toggle"); + DOM.publicKeyToggle = $(".public-key-toggle"); DOM.privateKeyToggle = $(".private-key-toggle"); DOM.languages = $(".languages a"); @@ -16226,6 +16235,7 @@ var Mnemonic = function(language) { DOM.hardenedAddresses.on("change", calcForDerivationPath); DOM.indexToggle.on("click", toggleIndexes); DOM.addressToggle.on("click", toggleAddresses); + DOM.publicKeyToggle.on("click", togglePublicKeys); DOM.privateKeyToggle.on("click", togglePrivateKeys); DOM.languages.on("click", languageChanged); disableForms(); @@ -16362,6 +16372,11 @@ var Mnemonic = function(language) { $("td.address span").toggleClass("invisible"); } + function togglePublicKeys() { + showPubKey = !showPubKey; + $("td.pubkey span").toggleClass("invisible"); + } + function togglePrivateKeys() { showPrivKey = !showPrivKey; $("td.privkey span").toggleClass("invisible"); @@ -16560,11 +16575,12 @@ var Mnemonic = function(language) { } var address = key.getAddress().toString(); var privkey = key.privKey.toWIF(network); + var pubkey = key.pubKey.toHex(); var indexText = getDerivationPath() + "/" + index; if (useHardenedAddresses) { indexText = indexText + "'"; } - addAddressToList(indexText, address, privkey); + addAddressToList(indexText, address, pubkey, privkey); }, 50) } @@ -16605,15 +16621,17 @@ var Mnemonic = function(language) { DOM.extendedPubKey.val(""); } - function addAddressToList(indexText, address, privkey) { + function addAddressToList(indexText, address, pubkey, privkey) { var row = $(addressRowTemplate.html()); // Elements var indexCell = row.find(".index span"); var addressCell = row.find(".address span"); + var pubkeyCell = row.find(".pubkey span"); var privkeyCell = row.find(".privkey span"); // Content indexCell.text(indexText); addressCell.text(address); + pubkeyCell.text(pubkey); privkeyCell.text(privkey); // Visibility if (!showIndex) { @@ -16622,6 +16640,9 @@ var Mnemonic = function(language) { if (!showAddress) { addressCell.addClass("invisible"); } + if (!showPubKey) { + pubkeyCell.addClass("invisible"); + } if (!showPrivKey) { privkeyCell.addClass("invisible"); } diff --git a/src/index.html b/src/index.html index b24b4d4..5832a9b 100644 --- a/src/index.html +++ b/src/index.html @@ -294,6 +294,12 @@
+ +
+ Public Key   + +
+
Private Key   @@ -438,6 +444,7 @@ + diff --git a/src/js/index.js b/src/js/index.js index c5f6c11..0e4cc05 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -11,6 +11,7 @@ var showIndex = true; var showAddress = true; + var showPubKey = true; var showPrivKey = true; var phraseChangeTimeoutEvent = null; @@ -45,6 +46,7 @@ DOM.tab = $(".derivation-type a"); DOM.indexToggle = $(".index-toggle"); DOM.addressToggle = $(".address-toggle"); + DOM.publicKeyToggle = $(".public-key-toggle"); DOM.privateKeyToggle = $(".private-key-toggle"); DOM.languages = $(".languages a"); @@ -65,6 +67,7 @@ DOM.hardenedAddresses.on("change", calcForDerivationPath); DOM.indexToggle.on("click", toggleIndexes); DOM.addressToggle.on("click", toggleAddresses); + DOM.publicKeyToggle.on("click", togglePublicKeys); DOM.privateKeyToggle.on("click", togglePrivateKeys); DOM.languages.on("click", languageChanged); disableForms(); @@ -201,6 +204,11 @@ $("td.address span").toggleClass("invisible"); } + function togglePublicKeys() { + showPubKey = !showPubKey; + $("td.pubkey span").toggleClass("invisible"); + } + function togglePrivateKeys() { showPrivKey = !showPrivKey; $("td.privkey span").toggleClass("invisible"); @@ -399,11 +407,12 @@ } var address = key.getAddress().toString(); var privkey = key.privKey.toWIF(network); + var pubkey = key.pubKey.toHex(); var indexText = getDerivationPath() + "/" + index; if (useHardenedAddresses) { indexText = indexText + "'"; } - addAddressToList(indexText, address, privkey); + addAddressToList(indexText, address, pubkey, privkey); }, 50) } @@ -444,15 +453,17 @@ DOM.extendedPubKey.val(""); } - function addAddressToList(indexText, address, privkey) { + function addAddressToList(indexText, address, pubkey, privkey) { var row = $(addressRowTemplate.html()); // Elements var indexCell = row.find(".index span"); var addressCell = row.find(".address span"); + var pubkeyCell = row.find(".pubkey span"); var privkeyCell = row.find(".privkey span"); // Content indexCell.text(indexText); addressCell.text(address); + pubkeyCell.text(pubkey); privkeyCell.text(privkey); // Visibility if (!showIndex) { @@ -461,6 +472,9 @@ if (!showAddress) { addressCell.addClass("invisible"); } + if (!showPubKey) { + pubkeyCell.addClass("invisible"); + } if (!showPrivKey) { privkeyCell.addClass("invisible"); } diff --git a/tests.js b/tests.js index ebdf9ec..914be24 100644 --- a/tests.js +++ b/tests.js @@ -1166,6 +1166,56 @@ page.open(url, function(status) { }); }, +// Public key is shown +function() { +page.open(url, function(status) { + var expected = "033f5aed5f6cfbafaf223188095b5980814897295f723815fea5d3f4b648d0d0b3"; + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability").trigger("input"); + }); + // get the address + waitForGenerate(function() { + var actual = page.evaluate(function() { + return $(".pubkey:first").text(); + }); + if (actual != expected) { + console.log("Public key is not shown"); + console.log("Expected: " + expected); + console.log("Got: " + actual); + fail(); + } + next(); + }); +}); +}, + +// Public key visibility can be toggled +function() { +page.open(url, function(status) { + // set the phrase + page.evaluate(function() { + $(".phrase").val("abandon abandon ability"); + $(".phrase").trigger("input"); + }); + waitForGenerate(function() { + // toggle public key visibility + page.evaluate(function() { + $(".public-key-toggle").click(); + }); + // check the public key is not visible + var isInvisible = page.evaluate(function() { + return $(".pubkey:first span").hasClass("invisible"); + }); + if (!isInvisible) { + console.log("Toggled public key is visible"); + fail(); + } + next(); + }); +}); +}, + // Private key is shown function() { page.open(url, function(status) { -- 2.41.0