aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/index.html2
-rw-r--r--src/js/index.js21
2 files changed, 20 insertions, 3 deletions
diff --git a/src/index.html b/src/index.html
index feefbd8..beda577 100644
--- a/src/index.html
+++ b/src/index.html
@@ -137,7 +137,7 @@
137 <label class="col-sm-2 control-label">Mnemonic Length</label> 137 <label class="col-sm-2 control-label">Mnemonic Length</label>
138 <div class="col-sm-10"> 138 <div class="col-sm-10">
139 <select class="mnemonic-length form-control"> 139 <select class="mnemonic-length form-control">
140 <option value="raw">From entropy length</option> 140 <option value="raw">From entropy length (3 words per 32 bits)</option>
141 <option value="12">12 Words</option> 141 <option value="12">12 Words</option>
142 <option value="15">15 Words</option> 142 <option value="15">15 Words</option>
143 <option value="18">18 Words</option> 143 <option value="18">18 Words</option>
diff --git a/src/js/index.js b/src/js/index.js
index 45f378d..66585a9 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -68,6 +68,7 @@
68 DOM.network.on("change", networkChanged); 68 DOM.network.on("change", networkChanged);
69 DOM.useEntropy.on("change", setEntropyVisibility); 69 DOM.useEntropy.on("change", setEntropyVisibility);
70 DOM.entropy.on("input", delayedEntropyChanged); 70 DOM.entropy.on("input", delayedEntropyChanged);
71 DOM.entropyMnemonicLength.on("change", entropyChanged);
71 DOM.phrase.on("input", delayedPhraseChanged); 72 DOM.phrase.on("input", delayedPhraseChanged);
72 DOM.passphrase.on("input", delayedPhraseChanged); 73 DOM.passphrase.on("input", delayedPhraseChanged);
73 DOM.generate.on("click", generateClicked); 74 DOM.generate.on("click", generateClicked);
@@ -744,9 +745,25 @@
744 } 745 }
745 // Show entropy details 746 // Show entropy details
746 showEntropyFeedback(entropy); 747 showEntropyFeedback(entropy);
748 // Use entropy hash if not using raw entropy
749 var bits = entropy.binaryStr;
750 var mnemonicLength = DOM.entropyMnemonicLength.val();
751 if (mnemonicLength != "raw") {
752 // Get bits by hashing entropy with SHA256
753 var hash = sjcl.hash.sha256.hash(entropy.cleanStr);
754 var hex = sjcl.codec.hex.fromBits(hash);
755 bits = BigInteger.parse(hex, 16).toString(2);
756 for (var i=0; i<256-bits.length; i++) {
757 bits = "0" + bits;
758 }
759 // Truncate hash to suit number of words
760 mnemonicLength = parseInt(mnemonicLength);
761 var numberOfBits = 32 * mnemonicLength / 3;
762 bits = bits.substring(0, numberOfBits);
763 }
747 // Discard trailing entropy 764 // Discard trailing entropy
748 var bitsToUse = Math.floor(entropy.binaryStr.length / 32) * 32; 765 var bitsToUse = Math.floor(bits.length / 32) * 32;
749 var binaryStr = entropy.binaryStr.substring(0, bitsToUse); 766 var binaryStr = bits.substring(0, bitsToUse);
750 // Convert entropy string to numeric array 767 // Convert entropy string to numeric array
751 var entropyArr = []; 768 var entropyArr = [];
752 for (var i=0; i<binaryStr.length / 8; i++) { 769 for (var i=0; i<binaryStr.length / 8; i++) {