]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Raw entropy is interpreted as binary
authorIan Coleman <ian@iancoleman.io>
Sun, 10 Nov 2019 23:31:14 +0000 (10:31 +1100)
committerIan Coleman <ian@iancoleman.io>
Sun, 10 Nov 2019 23:31:14 +0000 (10:31 +1100)
For example, using abandon abandon ability becomes 8 zeros but how does
the entropy field know it's hex and not binary? It assumes the
worst-case scenario of binary, so entropy should be shown in binary.

Perhaps if entropy type is explicitly selected in the future this can be
changed back to using hex. But while magical assumptions exist, binary
it must be.

src/js/index.js
src/js/jsbip39.js
tests/spec/tests.js

index 472d392964c011dfa8d68cc93d9efe40c7b327d5..8caa0ed440cfc3dcc012a15c2615a83cc4094024 100644 (file)
         }
         phraseChangeTimeoutEvent = setTimeout(function() {
             phraseChanged();
-            var entropy = mnemonic.toRawEntropyHex(DOM.phrase.val());
+            var entropy = mnemonic.toRawEntropyBin(DOM.phrase.val());
             if (entropy !== null) {
                 DOM.entropyMnemonicLength.val("raw");
                 DOM.entropy.val(entropy);
index 9a6e7ec696b3122a7d73ebf4ec070f7621d4c6e8..1e52d9d93296681f47b78b127904d0d2f1e7fbd3 100644 (file)
@@ -130,6 +130,12 @@ var Mnemonic = function(language) {
         return h;
     }
 
+    self.toRawEntropyBin = function(mnemonic) {
+        var b = mnemonicToBinaryString(mnemonic);
+        var d = b.substring(0, b.length / 33 * 32);
+        return d;
+    }
+
     self.toSeed = function(mnemonic, passphrase) {
         passphrase = passphrase || '';
         mnemonic = self.joinWords(self.splitWords(mnemonic)); // removes duplicate blanks
index 977294ca28ade58b2a55c390b52e37792ae2cb50..07918c2e400bd9e15f1496ec036fc9924d508de7 100644 (file)
@@ -4129,8 +4129,13 @@ fit('Converts mnemonics into raw entropy', function(done) {
         driver.findElement(By.css('.entropy'))
             .getAttribute("value")
             .then(function(entropy) {
-                expect(entropy).toBe("00000001");
-                done();
+                expect(entropy).toBe("00000000000000000000000000000001");
+                driver.findElement(By.css('.phrase'))
+                    .getAttribute("value")
+                    .then(function(phrase) {
+                        expect(phrase).toBe("abandon abandon about");
+                        done();
+                    });
             });
     });
 });