X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=a717a9e45bdd0369004ba521a0a25b008ee67ae9;hb=c193ff67e821cf66f1d5bb4fcf8cf15d8a9bcde1;hp=cd7f281b5489f8e1a956a19fb4784e3fa3c1cb8c;hpb=c6624d51f4e5607202e48903352574c47571baab;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index cd7f281..a717a9e 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -109,6 +109,7 @@ DOM.entropyContainer.addClass("hidden"); DOM.generateContainer.removeClass("hidden"); DOM.phrase.prop("readonly", false); + hidePending(); } } @@ -149,8 +150,31 @@ } function entropyChanged() { + // If blank entropy, clear mnemonic, addresses, errors + if (DOM.entropy.val().trim().length == 0) { + clearDisplay(); + hideEntropyError(); + DOM.phrase.val(""); + showValidationError("Blank entropy"); + return; + } + // Get the current phrase to detect changes + var phrase = DOM.phrase.val(); + // Set the phrase from the entropy setMnemonicFromEntropy(); - phraseChanged(); + // Recalc addresses if the phrase has changed + var newPhrase = DOM.phrase.val(); + if (newPhrase != phrase) { + if (newPhrase.length == 0) { + clearDisplay(); + } + else { + phraseChanged(); + } + } + else { + hidePending(); + } } function delayedRootKeyChanged() { @@ -311,10 +335,13 @@ } function findPhraseErrors(phrase) { - // TODO make this right // Preprocess the words phrase = mnemonic.normalizeString(phrase); var words = phraseToWordArray(phrase); + // Detect blank phrase + if (words.length == 0) { + return "Blank mnemonic"; + } // Check each word for (var i=0; i= 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