From 74ab4cbe90d037604120c93230ac9b0d74a6c7f1 Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Wed, 22 Nov 2017 15:28:58 +1100 Subject: [PATCH] Show entropy from PRNG and word indexes see issue #132 --- src/index.html | 4 +++- src/js/index.js | 43 ++++++++++++++++++++++++++++++++++++++++++- tests/spec/tests.js | 27 +++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/index.html b/src/index.html index f481473..ac1ab48 100644 --- a/src/index.html +++ b/src/index.html @@ -193,6 +193,8 @@
+ +
 
- Supply my own source of entropy + Show entropy details
diff --git a/src/js/index.js b/src/js/index.js index 261a6d1..58090c3 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -37,6 +37,7 @@ DOM.entropyBitsPerEvent = DOM.entropyContainer.find(".bits-per-event"); DOM.entropyWordCount = DOM.entropyContainer.find(".word-count"); DOM.entropyBinary = DOM.entropyContainer.find(".binary"); + DOM.entropyWordIndexes = DOM.entropyContainer.find(".word-indexes"); DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length"); DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); DOM.phrase = $(".phrase"); @@ -219,6 +220,8 @@ var passphrase = DOM.passphrase.val(); calcBip32RootKeyFromSeed(phrase, passphrase); calcForDerivationPath(); + // Show the word indexes + showWordIndexes(); } function tabChanged() { @@ -420,10 +423,20 @@ showValidationError(errorText); return; } + // get the amount of entropy to use var numWords = parseInt(DOM.generatedStrength.val()); var strength = numWords / 3 * 32; - var words = mnemonic.generate(strength); + var buffer = new Uint8Array(strength / 8); + // create secure entropy + var data = crypto.getRandomValues(buffer); + // show the words + var words = mnemonic.toMnemonic(data); DOM.phrase.val(words); + // show the entropy + var entropyHex = uint8ArrayToHex(data); + DOM.entropy.val(entropyHex); + // ensure entropy fields are consistent with what is being displayed + DOM.entropyMnemonicLength.val("raw"); return words; } @@ -1103,6 +1116,8 @@ var phrase = mnemonic.toMnemonic(entropyArr); // Set the mnemonic in the UI DOM.phrase.val(phrase); + // Show the word indexes + showWordIndexes(); } function clearEntropyFeedback() { @@ -1328,6 +1343,32 @@ return parseInt(lastBitClean); } + function uint8ArrayToHex(a) { + var s = "" + for (var i=0; i