mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-05-13 12:15:04 +00:00
Warn when generating low entropy mnemonics
This commit is contained in:
+6
-1
@@ -48,7 +48,12 @@
|
|||||||
<option value="21">21</option>
|
<option value="21">21</option>
|
||||||
<option value="24">24</option>
|
<option value="24">24</option>
|
||||||
</select>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -88,6 +88,7 @@
|
|||||||
DOM.bip141path = $("#bip141-path");
|
DOM.bip141path = $("#bip141-path");
|
||||||
DOM.bip141semantics = $(".bip141-semantics");
|
DOM.bip141semantics = $(".bip141-semantics");
|
||||||
DOM.generatedStrength = $(".generate-container .strength");
|
DOM.generatedStrength = $(".generate-container .strength");
|
||||||
|
DOM.generatedStrengthWarning = $(".generate-container .warning");
|
||||||
DOM.hardenedAddresses = $(".hardened-addresses");
|
DOM.hardenedAddresses = $(".hardened-addresses");
|
||||||
DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container");
|
DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container");
|
||||||
DOM.useBitpayAddresses = $(".use-bitpay-addresses");
|
DOM.useBitpayAddresses = $(".use-bitpay-addresses");
|
||||||
@@ -114,6 +115,7 @@
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
// Events
|
// Events
|
||||||
|
DOM.generatedStrength.on("change", generatedStrengthChanged);
|
||||||
DOM.network.on("change", networkChanged);
|
DOM.network.on("change", networkChanged);
|
||||||
DOM.bip32Client.on("change", bip32ClientChanged);
|
DOM.bip32Client.on("change", bip32ClientChanged);
|
||||||
DOM.useEntropy.on("change", setEntropyVisibility);
|
DOM.useEntropy.on("change", setEntropyVisibility);
|
||||||
@@ -155,6 +157,16 @@
|
|||||||
|
|
||||||
// Event handlers
|
// 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) {
|
function networkChanged(e) {
|
||||||
clearDerivedKeys();
|
clearDerivedKeys();
|
||||||
clearAddressesList();
|
clearAddressesList();
|
||||||
|
|||||||
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user