diff options
author | Ian Coleman <coleman.ian@gmail.com> | 2017-09-20 10:31:28 +1000 |
---|---|---|
committer | Ian Coleman <coleman.ian@gmail.com> | 2017-09-20 11:25:21 +1000 |
commit | ee0981f1ecc4c6e78831f538ef77396c1e4fbe91 (patch) | |
tree | 9abba5e09307c9dc62c52b371576d73e369672dd | |
parent | 6024e655a8b6d3c35ef189013f8cd2de605171fa (diff) | |
download | BIP39-ee0981f1ecc4c6e78831f538ef77396c1e4fbe91.tar.gz BIP39-ee0981f1ecc4c6e78831f538ef77396c1e4fbe91.tar.zst BIP39-ee0981f1ecc4c6e78831f538ef77396c1e4fbe91.zip |
Detect and warn of filtered entropy
-rw-r--r-- | src/index.html | 7 | ||||
-rw-r--r-- | src/js/index.js | 11 | ||||
-rw-r--r-- | tests.js | 38 |
3 files changed, 56 insertions, 0 deletions
diff --git a/src/index.html b/src/index.html index cc38ed0..7507a35 100644 --- a/src/index.html +++ b/src/index.html | |||
@@ -164,6 +164,13 @@ | |||
164 | <label for="entropy" class="col-sm-2 control-label" data-translate>Entropy</label> | 164 | <label for="entropy" class="col-sm-2 control-label" data-translate>Entropy</label> |
165 | <div class="col-sm-7"> | 165 | <div class="col-sm-7"> |
166 | <textarea id="entropy" rows="2" class="entropy form-control" placeholder="Accepts either binary, base 6, 6-sided dice, base 10, hexadecimal or cards" data-translate-placeholder></textarea> | 166 | <textarea id="entropy" rows="2" class="entropy form-control" placeholder="Accepts either binary, base 6, 6-sided dice, base 10, hexadecimal or cards" data-translate-placeholder></textarea> |
167 | <div class="row filter-warning text-danger hidden"> | ||
168 | <p class="col-sm-12"> | ||
169 | <strong> | ||
170 | Some characters have been discarded | ||
171 | </strong> | ||
172 | </p> | ||
173 | </div> | ||
167 | <div class="row"> | 174 | <div class="row"> |
168 | <label class="col-sm-3 control-label" data-translate><span class="more-info" data-translate-title title="Based on estimates from zxcvbn using Filtered Entropy">Time To Crack</span></label> | 175 | <label class="col-sm-3 control-label" data-translate><span class="more-info" data-translate-title title="Based on estimates from zxcvbn using Filtered Entropy">Time To Crack</span></label> |
169 | <div class="crack-time col-sm-3 form-control-static"></div> | 176 | <div class="crack-time col-sm-3 form-control-static"></div> |
diff --git a/src/js/index.js b/src/js/index.js index 9bd77b9..6a2fea6 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -38,6 +38,7 @@ | |||
38 | DOM.entropyWordCount = DOM.entropyContainer.find(".word-count"); | 38 | DOM.entropyWordCount = DOM.entropyContainer.find(".word-count"); |
39 | DOM.entropyBinary = DOM.entropyContainer.find(".binary"); | 39 | DOM.entropyBinary = DOM.entropyContainer.find(".binary"); |
40 | DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length"); | 40 | DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length"); |
41 | DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); | ||
41 | DOM.phrase = $(".phrase"); | 42 | DOM.phrase = $(".phrase"); |
42 | DOM.passphrase = $(".passphrase"); | 43 | DOM.passphrase = $(".passphrase"); |
43 | DOM.generateContainer = $(".generate-container"); | 44 | DOM.generateContainer = $(".generate-container"); |
@@ -1061,6 +1062,16 @@ | |||
1061 | DOM.entropyWordCount.text(wordCount); | 1062 | DOM.entropyWordCount.text(wordCount); |
1062 | DOM.entropyBinary.text(entropy.binaryStr); | 1063 | DOM.entropyBinary.text(entropy.binaryStr); |
1063 | DOM.entropyBitsPerEvent.text(bitsPerEvent); | 1064 | DOM.entropyBitsPerEvent.text(bitsPerEvent); |
1065 | // detect and warn of filtering | ||
1066 | var rawNoSpaces = DOM.entropy.val().replace(/\s/g, ""); | ||
1067 | var cleanNoSpaces = entropy.cleanStr.replace(/\s/g, ""); | ||
1068 | var isFiltered = rawNoSpaces.length != cleanNoSpaces.length; | ||
1069 | if (isFiltered) { | ||
1070 | DOM.entropyFilterWarning.removeClass('hidden'); | ||
1071 | } | ||
1072 | else { | ||
1073 | DOM.entropyFilterWarning.addClass('hidden'); | ||
1074 | } | ||
1064 | } | 1075 | } |
1065 | 1076 | ||
1066 | function getEntropyTypeStr(entropy) { | 1077 | function getEntropyTypeStr(entropy) { |
@@ -4306,6 +4306,44 @@ page.open(url, function(status) { | |||
4306 | }); | 4306 | }); |
4307 | }, | 4307 | }, |
4308 | 4308 | ||
4309 | // github issue 99 | ||
4310 | // https://github.com/iancoleman/bip39/issues/99#issuecomment-327094159 | ||
4311 | // "warn me emphatically when they have detected invalid input" to the entropy field | ||
4312 | // A warning is shown when entropy is filtered and discarded | ||
4313 | function() { | ||
4314 | page.open(url, function(status) { | ||
4315 | // use entropy | ||
4316 | page.evaluate(function() { | ||
4317 | $(".use-entropy").prop("checked", true).trigger("change"); | ||
4318 | $(".entropy").val("00000000 00000000 00000000 00000000").trigger("input"); | ||
4319 | }); | ||
4320 | // check the filter warning does not show | ||
4321 | waitForGenerate(function() { | ||
4322 | var warningIsHidden = page.evaluate(function() { | ||
4323 | return $(".entropy-container .filter-warning").hasClass("hidden"); | ||
4324 | }); | ||
4325 | if (!warningIsHidden) { | ||
4326 | console.log("Entropy filter warning is showing when it should not"); | ||
4327 | fail(); | ||
4328 | } | ||
4329 | page.evaluate(function() { | ||
4330 | $(".entropy").val("10000000 zxcvbn 00000000 00000000 00000000").trigger("input"); | ||
4331 | }); | ||
4332 | // check the filter warning shows | ||
4333 | waitForEntropyFeedback(function() { | ||
4334 | var warningIsHidden = page.evaluate(function() { | ||
4335 | return $(".entropy-container .filter-warning").hasClass("hidden"); | ||
4336 | }); | ||
4337 | if (warningIsHidden) { | ||
4338 | console.log("Entropy filter warning is not showing when it should"); | ||
4339 | fail(); | ||
4340 | } | ||
4341 | next(); | ||
4342 | }); | ||
4343 | }); | ||
4344 | }); | ||
4345 | }, | ||
4346 | |||
4309 | // If you wish to add more tests, do so here... | 4347 | // If you wish to add more tests, do so here... |
4310 | 4348 | ||
4311 | // Here is a blank test template | 4349 | // Here is a blank test template |