X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=45db7b139861814e603903c68c5a583c5dd4fa6e;hb=88df3739e7e8b26b461a73fe3874b195e5b03fec;hp=1cc77d3eff9035590ecde2dbc0b507f6c7aba240;hpb=057722b034672d240eea2ff01a7a5a01a4706e00;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index 1cc77d3..45db7b1 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -43,7 +43,7 @@ DOM.bip44coin = $("#bip44 .coin"); DOM.bip44account = $("#bip44 .account"); DOM.bip44change = $("#bip44 .change"); - DOM.strength = $(".strength"); + DOM.generatedStrength = $(".generate-container .strength"); DOM.hardenedAddresses = $(".hardened-addresses"); DOM.addresses = $(".addresses"); DOM.rowsToAdd = $(".rows-to-add"); @@ -286,7 +286,7 @@ showValidationError(errorText); return; } - var numWords = parseInt(DOM.strength.val()); + var numWords = parseInt(DOM.generatedStrength.val()); var strength = numWords / 3 * 32; var words = mnemonic.generate(strength); DOM.phrase.val(words); @@ -738,33 +738,36 @@ // Show entropy details var extraBits = 32 - (entropy.binaryStr.length % 32); var extraChars = Math.ceil(extraBits * Math.log(2) / Math.log(entropy.base.asInt)); + var words = Math.floor(entropy.binaryStr.length / 32) * 3; var strength = "an extremely weak"; - if (entropy.hexStr.length >= 8) { + if (words >= 3) { strength = "a very weak"; } - if (entropy.hexStr.length >= 12) { + if (words >= 6) { strength = "a weak"; } - if (entropy.hexStr.length >= 24) { + if (words >= 9) { strength = "a strong"; } - if (entropy.hexStr.length >= 32) { + if (words >= 12) { strength = "a very strong"; } - if (entropy.hexStr.length >= 40) { + if (words >= 15) { strength = "an extremely strong"; } - if (entropy.hexStr.length >=48) { + if (words >= 18) { strength = "an even stronger" } var msg = "Have " + entropy.binaryStr.length + " bits of entropy, " + extraChars + " more " + entropy.base.str + " chars required to generate " + strength + " mnemonic: " + entropy.cleanStr; showEntropyError(msg); // Discard trailing entropy - var hexStr = entropy.hexStr.substring(0, Math.floor(entropy.hexStr.length / 8) * 8); + var bitsToUse = Math.floor(entropy.binaryStr.length / 32) * 32; + var binaryStr = entropy.binaryStr.substring(0, bitsToUse); // Convert entropy string to numeric array var entropyArr = []; - for (var i=0; i