From 09d63290a45066e4bef3bdb31e81c50ff70f7b85 Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Mon, 12 Mar 2018 10:23:28 +1100 Subject: Show the checksum value in the entropy details --- src/index.html | 2 ++ src/js/index.js | 27 +++++++++++++++++++++++++++ tests/spec/tests.js | 15 +++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/index.html b/src/index.html index 43a8e4f..67e9101 100644 --- a/src/index.html +++ b/src/index.html @@ -94,6 +94,8 @@
+ +
 
 
diff --git a/src/js/index.js b/src/js/index.js index b36e992..0d573ba 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -38,6 +38,7 @@ DOM.entropyWordCount = DOM.entropyContainer.find(".word-count"); DOM.entropyBinary = DOM.entropyContainer.find(".binary"); DOM.entropyWordIndexes = DOM.entropyContainer.find(".word-indexes"); + DOM.entropyChecksum = DOM.entropyContainer.find(".checksum"); DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length"); DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); DOM.phrase = $(".phrase"); @@ -1195,6 +1196,8 @@ DOM.phrase.val(phrase); // Show the word indexes showWordIndexes(); + // Show the checksum + showChecksum(); } function clearEntropyFeedback() { @@ -1457,6 +1460,30 @@ DOM.entropyWordIndexes.text(wordIndexesStr); } + function showChecksum() { + var phrase = DOM.phrase.val(); + var words = phraseToWordArray(phrase); + var checksumBitlength = words.length / 3; + var checksum = ""; + var binaryStr = ""; + var language = getLanguage(); + for (var i=words.length-1; i>=0; i--) { + var word = words[i]; + var wordIndex = WORDLISTS[language].indexOf(word); + var wordBinary = wordIndex.toString(2); + while (wordBinary.length < 11) { + wordBinary = "0" + wordBinary; + } + var binaryStr = wordBinary + binaryStr; + if (binaryStr.length >= checksumBitlength) { + var start = binaryStr.length - checksumBitlength; + var end = binaryStr.length; + checksum = binaryStr.substring(start, end); + } + } + DOM.entropyChecksum.text(checksum); + } + function updateCsv() { var tableCsv = "path,address,public key,private key\n"; var rows = DOM.addresses.find("tr"); diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 9e78016..f56b18d 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -2922,4 +2922,19 @@ it('Can encrypt private keys using BIP38', function(done) { }); }, bip38delay + 5000); +it('Shows the checksum for the entropy', function(done) { + driver.findElement(By.css('.use-entropy')) + .click(); + driver.findElement(By.css('.entropy')) + .sendKeys("00000000000000000000000000000000"); + driver.sleep(generateDelay).then(function() { + driver.findElement(By.css('.checksum')) + .getText() + .then(function(text) { + expect(text).toBe("1"); + done(); + }); + }); +}); + }); -- cgit v1.2.3