From: Kevin Cernekee Date: Sun, 28 Oct 2018 20:20:33 +0000 (-0700) Subject: Allow converting mnemonic back to raw entropy value X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=611f76238dedd0418c79a0d918d46d2c92b0149c;hp=011533e4bc1d49a6675dedf5bfaabefb7de41088;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git Allow converting mnemonic back to raw entropy value Currently, this sequence produces an unexpected result: 1) Navigate to bip39-standalone.html 2) Paste a known-good mnemonic into the BIP39 Mnemonic field 3) Select "Show entropy details" This will erase the BIP39 Mnemonic field and most of the derived address/key information. It shows an empty Entropy field, and zeroes for Event Count, Bits Per Event, Raw Entropy Words, Total Bits, etc. However, it will show valid Word Indexes and BIP39 Seed. The way to fix it is to convert the mnemonic back into a raw entropy value and populate it in DOM.entropy, so that everything stays consistent. This will only happen if the mnemonic is manually entered by the user, not if phraseChanged() is triggered by hand-editing the entropy value. --- diff --git a/src/js/index.js b/src/js/index.js index 5d031b2..0c8344f 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -232,7 +232,14 @@ if (phraseChangeTimeoutEvent != null) { clearTimeout(phraseChangeTimeoutEvent); } - phraseChangeTimeoutEvent = setTimeout(phraseChanged, 400); + phraseChangeTimeoutEvent = setTimeout(function() { + phraseChanged(); + var entropy = mnemonic.toRawEntropyHex(DOM.phrase.val()); + if (entropy !== null) { + DOM.entropyMnemonicLength.val("raw"); + DOM.entropy.val(entropy); + } + }, 400); } function phraseChanged() { diff --git a/src/js/jsbip39.js b/src/js/jsbip39.js index 3230e3b..9a6e7ec 100644 --- a/src/js/jsbip39.js +++ b/src/js/jsbip39.js @@ -97,22 +97,10 @@ var Mnemonic = function(language) { } self.check = function(mnemonic) { - var mnemonic = self.splitWords(mnemonic); - if (mnemonic.length == 0 || mnemonic.length % 3 > 0) { - return false - } - // idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic) - var idx = []; - for (var i=0; i 0) { + return null; + } + // idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic) + var idx = []; + for (var i=0; i