]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Add spacing every 11 bits to the checksum
authorIan Coleman <ian@iancoleman.io>
Sun, 11 Mar 2018 23:33:07 +0000 (10:33 +1100)
committerIan Coleman <ian@iancoleman.io>
Mon, 12 Mar 2018 00:31:41 +0000 (11:31 +1100)
src/js/index.js
tests/spec/tests.js

index 0d573baa88b1fe83d2cda149df21014f928afb82..b8a76a970c98e8443a1c43ed32358fa5af8f30e8 100644 (file)
         var entropyTypeStr = getEntropyTypeStr(entropy);
         var wordCount = Math.floor(numberOfBits / 32) * 3;
         var bitsPerEvent = entropy.bitsPerEvent.toFixed(2);
-        var spacedBinaryStr = entropy.binaryStr.match(/.{1,11}/g).join(" " );
+        var spacedBinaryStr = addSpacesEveryElevenBits(entropy.binaryStr);
         DOM.entropyFiltered.html(entropy.cleanHtml);
         DOM.entropyType.text(entropyTypeStr);
         DOM.entropyCrackTime.text(timeToCrack);
                 var start = binaryStr.length - checksumBitlength;
                 var end = binaryStr.length;
                 checksum = binaryStr.substring(start, end);
+                // add spaces so the last group is 11 bits, not the first
+                checksum = checksum.split("").reverse().join("")
+                checksum = addSpacesEveryElevenBits(checksum);
+                checksum = checksum.split("").reverse().join("")
+                break;
             }
         }
         DOM.entropyChecksum.text(checksum);
         DOM.csv.val(tableCsv);
     }
 
+    function addSpacesEveryElevenBits(binaryStr) {
+        return binaryStr.match(/.{1,11}/g).join(" ");
+    }
+
     var networks = [
         {
             name: "AXE - Axe",
index f56b18d0aea1192785b540c21ee31641a38e4613..c7a988944741acb70edec4422063e5febce71323 100644 (file)
@@ -2937,4 +2937,21 @@ it('Shows the checksum for the entropy', function(done) {
     });
 });
 
+it('Shows the checksum for the entropy with the correct groupings', function(done) {
+    driver.findElement(By.css('.use-entropy'))
+        .click();
+    // create a checksum of 20 bits, which spans multiple words
+    driver.findElement(By.css('.entropy'))
+        .sendKeys("F000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
+    driver.sleep(generateDelay).then(function() {
+        driver.findElement(By.css('.checksum'))
+            .getText()
+            .then(function(text) {
+                // first group is 9 bits, second group is 11
+                expect(text).toBe("011010111 01110000110");
+                done();
+            });
+    });
+});
+
 });