mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-05-22 08:34:45 +00:00
Warn when using weak entropy and strong mnemonic
This commit is contained in:
@@ -113,6 +113,11 @@
|
|||||||
<option value="21">21 <span>Words</span></option>
|
<option value="21">21 <span>Words</span></option>
|
||||||
<option value="24">24 <span>Words</span></option>
|
<option value="24">24 <span>Words</span></option>
|
||||||
</select>
|
</select>
|
||||||
|
<p class="weak-entropy-override-warning hidden">
|
||||||
|
<span class="text-danger">
|
||||||
|
The mnemonic will appear more secure than it really is.
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
DOM.entropyWordIndexes = DOM.entropyContainer.find(".word-indexes");
|
DOM.entropyWordIndexes = DOM.entropyContainer.find(".word-indexes");
|
||||||
DOM.entropyChecksum = DOM.entropyContainer.find(".checksum");
|
DOM.entropyChecksum = DOM.entropyContainer.find(".checksum");
|
||||||
DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length");
|
DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length");
|
||||||
|
DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning");
|
||||||
DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
|
DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
|
||||||
DOM.phrase = $(".phrase");
|
DOM.phrase = $(".phrase");
|
||||||
DOM.passphrase = $(".passphrase");
|
DOM.passphrase = $(".passphrase");
|
||||||
@@ -1190,6 +1191,17 @@
|
|||||||
mnemonicLength = parseInt(mnemonicLength);
|
mnemonicLength = parseInt(mnemonicLength);
|
||||||
var numberOfBits = 32 * mnemonicLength / 3;
|
var numberOfBits = 32 * mnemonicLength / 3;
|
||||||
bits = bits.substring(0, numberOfBits);
|
bits = bits.substring(0, numberOfBits);
|
||||||
|
// show warning for weak entropy override
|
||||||
|
if (mnemonicLength / 3 * 32 > entropy.binaryStr.length) {
|
||||||
|
DOM.entropyWeakEntropyOverrideWarning.removeClass("hidden");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// hide warning for weak entropy override
|
||||||
|
DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
|
||||||
}
|
}
|
||||||
// Discard trailing entropy
|
// Discard trailing entropy
|
||||||
var bitsToUse = Math.floor(bits.length / 32) * 32;
|
var bitsToUse = Math.floor(bits.length / 32) * 32;
|
||||||
|
|||||||
@@ -3530,4 +3530,36 @@ it('Does not show a warning if generating strong mnemonics', function(done) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Shows a warning if overriding weak entropy with longer mnemonics', function(done) {
|
||||||
|
driver.findElement(By.css('.use-entropy'))
|
||||||
|
.click();
|
||||||
|
driver.findElement(By.css('.entropy'))
|
||||||
|
.sendKeys("0123456789abcdef"); // 6 words
|
||||||
|
driver.executeScript(function() {
|
||||||
|
$(".mnemonic-length").val("12").trigger("change");
|
||||||
|
});
|
||||||
|
driver.findElement(By.css(".weak-entropy-override-warning"))
|
||||||
|
.getAttribute("class")
|
||||||
|
.then(function(classes) {
|
||||||
|
expect(classes).not.toContain("hidden");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Does not show a warning if entropy is stronger than mnemonic length', function(done) {
|
||||||
|
driver.findElement(By.css('.use-entropy'))
|
||||||
|
.click();
|
||||||
|
driver.findElement(By.css('.entropy'))
|
||||||
|
.sendKeys("0123456789abcdef0123456789abcdef0123456789abcdef"); // 18 words
|
||||||
|
driver.executeScript(function() {
|
||||||
|
$(".mnemonic-length").val("12").trigger("change");
|
||||||
|
});
|
||||||
|
driver.findElement(By.css(".weak-entropy-override-warning"))
|
||||||
|
.getAttribute("class")
|
||||||
|
.then(function(classes) {
|
||||||
|
expect(classes).toContain("hidden");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user