mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-05 18:43:47 +00:00
Add spacing every 11 bits to the checksum
This commit is contained in:
@@ -1228,7 +1228,7 @@
|
||||
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);
|
||||
@@ -1479,6 +1479,11 @@
|
||||
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);
|
||||
@@ -1504,6 +1509,10 @@
|
||||
DOM.csv.val(tableCsv);
|
||||
}
|
||||
|
||||
function addSpacesEveryElevenBits(binaryStr) {
|
||||
return binaryStr.match(/.{1,11}/g).join(" ");
|
||||
}
|
||||
|
||||
var networks = [
|
||||
{
|
||||
name: "AXE - Axe",
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user