Show the checksum value in the entropy details

This commit is contained in:
Ian Coleman
2018-03-12 10:23:28 +11:00
parent d6cade868f
commit 09d63290a4
3 changed files with 44 additions and 0 deletions

View File

@@ -94,6 +94,8 @@
<div class="filtered col-sm-9 form-control-static"></div>
<label class="col-sm-3 control-label">Raw Binary</label>
<div class="binary col-sm-9 form-control-static"></div>
<label class="col-sm-3 control-label">Binary Checksum</label>
<div class="checksum col-sm-9 form-control-static">&nbsp;</div>
<label class="col-sm-3 control-label">Word Indexes</label>
<div class="word-indexes col-sm-9 form-control-static">&nbsp;</div>
<label class="col-sm-3 control-label">Mnemonic Length</label>

View File

@@ -38,6 +38,7 @@
DOM.entropyWordCount = DOM.entropyContainer.find(".word-count");
DOM.entropyBinary = DOM.entropyContainer.find(".binary");
DOM.entropyWordIndexes = DOM.entropyContainer.find(".word-indexes");
DOM.entropyChecksum = DOM.entropyContainer.find(".checksum");
DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length");
DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
DOM.phrase = $(".phrase");
@@ -1195,6 +1196,8 @@
DOM.phrase.val(phrase);
// Show the word indexes
showWordIndexes();
// Show the checksum
showChecksum();
}
function clearEntropyFeedback() {
@@ -1457,6 +1460,30 @@
DOM.entropyWordIndexes.text(wordIndexesStr);
}
function showChecksum() {
var phrase = DOM.phrase.val();
var words = phraseToWordArray(phrase);
var checksumBitlength = words.length / 3;
var checksum = "";
var binaryStr = "";
var language = getLanguage();
for (var i=words.length-1; i>=0; i--) {
var word = words[i];
var wordIndex = WORDLISTS[language].indexOf(word);
var wordBinary = wordIndex.toString(2);
while (wordBinary.length < 11) {
wordBinary = "0" + wordBinary;
}
var binaryStr = wordBinary + binaryStr;
if (binaryStr.length >= checksumBitlength) {
var start = binaryStr.length - checksumBitlength;
var end = binaryStr.length;
checksum = binaryStr.substring(start, end);
}
}
DOM.entropyChecksum.text(checksum);
}
function updateCsv() {
var tableCsv = "path,address,public key,private key\n";
var rows = DOM.addresses.find("tr");

View File

@@ -2922,4 +2922,19 @@ it('Can encrypt private keys using BIP38', function(done) {
});
}, bip38delay + 5000);
it('Shows the checksum for the entropy', function(done) {
driver.findElement(By.css('.use-entropy'))
.click();
driver.findElement(By.css('.entropy'))
.sendKeys("00000000000000000000000000000000");
driver.sleep(generateDelay).then(function() {
driver.findElement(By.css('.checksum'))
.getText()
.then(function(text) {
expect(text).toBe("1");
done();
});
});
});
});