Warn when generating low entropy mnemonics

This commit is contained in:
Ian Coleman
2018-04-12 11:46:44 +10:00
parent d1b4c8c579
commit 85c906727a
3 changed files with 45 additions and 1 deletions
+6 -1
View File
@@ -48,7 +48,12 @@
<option value="21">21</option>
<option value="24">24</option>
</select>
<span>words</span>
<span>words</span>.
<p class="warning help-block hidden">
<span class="text-danger">
Mnemonics with less than 12 words have low entropy and may be guessed by an attacker.
</span>
</p>
</div>
</div>
</div>
+12
View File
@@ -88,6 +88,7 @@
DOM.bip141path = $("#bip141-path");
DOM.bip141semantics = $(".bip141-semantics");
DOM.generatedStrength = $(".generate-container .strength");
DOM.generatedStrengthWarning = $(".generate-container .warning");
DOM.hardenedAddresses = $(".hardened-addresses");
DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container");
DOM.useBitpayAddresses = $(".use-bitpay-addresses");
@@ -114,6 +115,7 @@
function init() {
// Events
DOM.generatedStrength.on("change", generatedStrengthChanged);
DOM.network.on("change", networkChanged);
DOM.bip32Client.on("change", bip32ClientChanged);
DOM.useEntropy.on("change", setEntropyVisibility);
@@ -155,6 +157,16 @@
// Event handlers
function generatedStrengthChanged() {
var strength = parseInt(DOM.generatedStrength.val());
if (strength < 12) {
DOM.generatedStrengthWarning.removeClass("hidden");
}
else {
DOM.generatedStrengthWarning.addClass("hidden");
}
}
function networkChanged(e) {
clearDerivedKeys();
clearAddressesList();
+27
View File
@@ -3503,4 +3503,31 @@ it('Uses vprv for bitcoin testnet p2wpkh', function(done) {
});
});
it('Shows a warning if generating weak mnemonics', function(done) {
driver.executeScript(function() {
$(".strength option[selected]").removeAttr("selected");
$(".strength option[value=6]").prop("selected", true);
$(".strength").trigger("change");
});
driver.findElement(By.css(".generate-container .warning"))
.getAttribute("class")
.then(function(classes) {
expect(classes).not.toContain("hidden");
done();
});
});
it('Does not show a warning if generating strong mnemonics', function(done) {
driver.executeScript(function() {
$(".strength option[selected]").removeAttr("selected");
$(".strength option[value=12]").prop("selected", true);
});
driver.findElement(By.css(".generate-container .warning"))
.getAttribute("class")
.then(function(classes) {
expect(classes).toContain("hidden");
done();
});
});
});