mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-28 05:10:41 +00:00
Entropy feedback in tabular format, not sentence
This commit is contained in:
+50
-10
@@ -95,17 +95,57 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="entropy-container hidden">
|
<div class="entropy-container hidden">
|
||||||
<label for="entropy" class="col-sm-2 control-label">Entropy</label>
|
<div class="form-group">
|
||||||
<div class="col-sm-10">
|
<label for="entropy" class="col-sm-2 control-label">Entropy</label>
|
||||||
<input id="entropy" class="entropy form-control" placeholder="Accepts binary, base 6, 6-sided dice, base 10, hexadecimal">
|
<div class="col-sm-10">
|
||||||
<span class="help-block">
|
<input id="entropy" class="entropy form-control" placeholder="Accepts binary, base 6, 6-sided dice, base 10, hexadecimal">
|
||||||
<div class="text-danger">
|
<span class="help-block">
|
||||||
This is an advanced feature.
|
<div class="text-danger">
|
||||||
Your mnemonic may be insecure if this feature is used incorrectly.
|
This is an advanced feature.
|
||||||
<a href="#entropy-notes">Read more</a>
|
Your mnemonic may be insecure if this feature is used incorrectly.
|
||||||
|
<a href="#entropy-notes">Read more</a>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="entropy-feedback">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">Filtered</label>
|
||||||
|
<div class="filtered col-sm-10 form-control-static"></div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">Type</label>
|
||||||
|
<div class="type col-sm-10 form-control-static"></div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">Strength</label>
|
||||||
|
<div class="strength col-sm-10 form-control-static"></div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">Event Count</label>
|
||||||
|
<div class="event-count col-sm-10 form-control-static"></div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">Bits Per Event</label>
|
||||||
|
<div class="bits-per-event col-sm-10 form-control-static"></div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">Bits</label>
|
||||||
|
<div class="bits col-sm-10 form-control-static"></div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label">Mnemonic Length</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<select class="mnemonic-length form-control">
|
||||||
|
<option value="raw">From entropy length</option>
|
||||||
|
<option value="12">12 Words</option>
|
||||||
|
<option value="15">15 Words</option>
|
||||||
|
<option value="18">18 Words</option>
|
||||||
|
<option value="21">21 Words</option>
|
||||||
|
<option value="24">24 Words</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-danger entropy-error"></div>
|
</div>
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
+11
-36
@@ -96,40 +96,6 @@ window.Entropy = new (function() {
|
|||||||
base: base,
|
base: base,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Pull leading zeros off
|
|
||||||
var leadingZeros = [];
|
|
||||||
while (base.ints[0] == "0") {
|
|
||||||
leadingZeros.push("0");
|
|
||||||
base.ints.shift();
|
|
||||||
}
|
|
||||||
// Convert leading zeros to binary equivalent
|
|
||||||
var numBinLeadingZeros = Math.floor(Math.log2(base.asInt) * leadingZeros.length);
|
|
||||||
var binLeadingZeros = "";
|
|
||||||
for (var i=0; i<numBinLeadingZeros; i++) {
|
|
||||||
binLeadingZeros += "0";
|
|
||||||
}
|
|
||||||
// Handle entropy of zero
|
|
||||||
if (base.ints.length == 0) {
|
|
||||||
return {
|
|
||||||
binaryStr: binLeadingZeros,
|
|
||||||
cleanStr: leadingZeros.join(""),
|
|
||||||
base: base,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If the first integer is small, it must be padded with zeros.
|
|
||||||
// Otherwise the chance of the first bit being 1 is 100%, which is
|
|
||||||
// obviously incorrect.
|
|
||||||
// This is not perfect for unusual bases, so is only done for bases
|
|
||||||
// of 2^n, eg octal or hexadecimal
|
|
||||||
if (base.asInt == 16) {
|
|
||||||
var firstInt = base.ints[0];
|
|
||||||
var firstIntBits = firstInt.toString(2).length;
|
|
||||||
var maxFirstIntBits = (base.asInt-1).toString(2).length;
|
|
||||||
var missingFirstIntBits = maxFirstIntBits - firstIntBits;
|
|
||||||
for (var i=0; i<missingFirstIntBits; i++) {
|
|
||||||
binLeadingZeros += "0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Convert base.ints to BigInteger.
|
// Convert base.ints to BigInteger.
|
||||||
// Due to using unusual bases, eg cards of base52, this is not as simple as
|
// Due to using unusual bases, eg cards of base52, this is not as simple as
|
||||||
// using BigInteger.parse()
|
// using BigInteger.parse()
|
||||||
@@ -140,8 +106,17 @@ window.Entropy = new (function() {
|
|||||||
var additionalEntropy = BigInteger.parse(base.asInt).pow(power).multiply(thisInt);
|
var additionalEntropy = BigInteger.parse(base.asInt).pow(power).multiply(thisInt);
|
||||||
entropyInt = entropyInt.add(additionalEntropy);
|
entropyInt = entropyInt.add(additionalEntropy);
|
||||||
}
|
}
|
||||||
// Convert entropy to different formats
|
// Convert entropy to binary
|
||||||
var entropyBin = binLeadingZeros + entropyInt.toString(2);
|
var entropyBin = entropyInt.toString(2);
|
||||||
|
// If the first integer is small, it must be padded with zeros.
|
||||||
|
// Otherwise the chance of the first bit being 1 is 100%, which is
|
||||||
|
// obviously incorrect.
|
||||||
|
// This is not perfect for non-2^n bases.
|
||||||
|
var expectedBits = Math.floor(base.parts.length * Math.log2(base.asInt));
|
||||||
|
while (entropyBin.length < expectedBits) {
|
||||||
|
entropyBin = "0" + entropyBin;
|
||||||
|
}
|
||||||
|
// Supply a 'filtered' entropy string for display purposes
|
||||||
var entropyClean = base.parts.join("");
|
var entropyClean = base.parts.join("");
|
||||||
if (base.asInt == 52) {
|
if (base.asInt == 52) {
|
||||||
entropyClean = base.parts.join(" ").toUpperCase();
|
entropyClean = base.parts.join(" ").toUpperCase();
|
||||||
|
|||||||
+47
-32
@@ -24,7 +24,14 @@
|
|||||||
DOM.useEntropy = $(".use-entropy");
|
DOM.useEntropy = $(".use-entropy");
|
||||||
DOM.entropyContainer = $(".entropy-container");
|
DOM.entropyContainer = $(".entropy-container");
|
||||||
DOM.entropy = $(".entropy");
|
DOM.entropy = $(".entropy");
|
||||||
DOM.entropyError = $(".entropy-error");
|
DOM.entropyFeedback = $(".entropy-feedback");
|
||||||
|
DOM.entropyFiltered = DOM.entropyFeedback.find(".filtered");
|
||||||
|
DOM.entropyType = DOM.entropyFeedback.find(".type");
|
||||||
|
DOM.entropyStrength = DOM.entropyFeedback.find(".strength");
|
||||||
|
DOM.entropyEventCount = DOM.entropyFeedback.find(".event-count");
|
||||||
|
DOM.entropyBits = DOM.entropyFeedback.find(".bits");
|
||||||
|
DOM.entropyBitsPerEvent = DOM.entropyFeedback.find(".bits-per-event");
|
||||||
|
DOM.entropyMnemonicLength = DOM.entropyFeedback.find(".mnemonic-length");
|
||||||
DOM.phrase = $(".phrase");
|
DOM.phrase = $(".phrase");
|
||||||
DOM.passphrase = $(".passphrase");
|
DOM.passphrase = $(".passphrase");
|
||||||
DOM.generateContainer = $(".generate-container");
|
DOM.generateContainer = $(".generate-container");
|
||||||
@@ -153,7 +160,7 @@
|
|||||||
// If blank entropy, clear mnemonic, addresses, errors
|
// If blank entropy, clear mnemonic, addresses, errors
|
||||||
if (DOM.entropy.val().trim().length == 0) {
|
if (DOM.entropy.val().trim().length == 0) {
|
||||||
clearDisplay();
|
clearDisplay();
|
||||||
hideEntropyError();
|
hideEntropyFeedback();
|
||||||
DOM.phrase.val("");
|
DOM.phrase.val("");
|
||||||
showValidationError("Blank entropy");
|
showValidationError("Blank entropy");
|
||||||
return;
|
return;
|
||||||
@@ -727,7 +734,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setMnemonicFromEntropy() {
|
function setMnemonicFromEntropy() {
|
||||||
hideEntropyError();
|
hideEntropyFeedback();
|
||||||
// Get entropy value
|
// Get entropy value
|
||||||
var entropyStr = DOM.entropy.val();
|
var entropyStr = DOM.entropy.val();
|
||||||
// Work out minimum base for entropy
|
// Work out minimum base for entropy
|
||||||
@@ -736,30 +743,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Show entropy details
|
// Show entropy details
|
||||||
var extraBits = 32 - (entropy.binaryStr.length % 32);
|
showEntropyFeedback(entropy);
|
||||||
var extraChars = Math.ceil(extraBits * Math.log(2) / Math.log(entropy.base.asInt));
|
|
||||||
var words = Math.floor(entropy.binaryStr.length / 32) * 3;
|
|
||||||
var strength = "an extremely weak";
|
|
||||||
if (words >= 3) {
|
|
||||||
strength = "a very weak";
|
|
||||||
}
|
|
||||||
if (words >= 6) {
|
|
||||||
strength = "a weak";
|
|
||||||
}
|
|
||||||
if (words >= 9) {
|
|
||||||
strength = "a strong";
|
|
||||||
}
|
|
||||||
if (words >= 12) {
|
|
||||||
strength = "a very strong";
|
|
||||||
}
|
|
||||||
if (words >= 15) {
|
|
||||||
strength = "an extremely strong";
|
|
||||||
}
|
|
||||||
if (words >= 18) {
|
|
||||||
strength = "an even stronger"
|
|
||||||
}
|
|
||||||
var msg = "Have " + entropy.binaryStr.length + " bits of entropy, " + extraChars + " more " + entropy.base.str + " chars required to generate " + strength + " mnemonic: " + entropy.cleanStr;
|
|
||||||
showEntropyError(msg);
|
|
||||||
// Discard trailing entropy
|
// Discard trailing entropy
|
||||||
var bitsToUse = Math.floor(entropy.binaryStr.length / 32) * 32;
|
var bitsToUse = Math.floor(entropy.binaryStr.length / 32) * 32;
|
||||||
var binaryStr = entropy.binaryStr.substring(0, bitsToUse);
|
var binaryStr = entropy.binaryStr.substring(0, bitsToUse);
|
||||||
@@ -776,13 +760,44 @@
|
|||||||
DOM.phrase.val(phrase);
|
DOM.phrase.val(phrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideEntropyError() {
|
function hideEntropyFeedback() {
|
||||||
DOM.entropyError.addClass("hidden");
|
DOM.entropyFeedback.addClass("hidden");
|
||||||
|
DOM.entropyFiltered.text("");
|
||||||
|
DOM.entropyType.text("");
|
||||||
|
DOM.entropyStrength.text("");
|
||||||
|
DOM.entropyEventCount.text("");
|
||||||
|
DOM.entropyBits.text("");
|
||||||
|
DOM.entropyBitsPerEvent.text("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function showEntropyError(msg) {
|
function showEntropyFeedback(entropy) {
|
||||||
DOM.entropyError.text(msg);
|
var strength = "extremely weak";
|
||||||
DOM.entropyError.removeClass("hidden");
|
if (entropy.binaryStr.length >= 64) {
|
||||||
|
strength = "very weak";
|
||||||
|
}
|
||||||
|
if (entropy.binaryStr.length >= 96) {
|
||||||
|
strength = "weak";
|
||||||
|
}
|
||||||
|
if (entropy.binaryStr.length >= 128) {
|
||||||
|
strength = "strong";
|
||||||
|
}
|
||||||
|
if (entropy.binaryStr.length >= 160) {
|
||||||
|
strength = "very strong";
|
||||||
|
}
|
||||||
|
if (entropy.binaryStr.length >= 192) {
|
||||||
|
strength = "extremely strong";
|
||||||
|
}
|
||||||
|
var bitsStr = entropy.binaryStr.length;
|
||||||
|
if (entropy.base.asInt != 2) {
|
||||||
|
bitsStr += " (" + entropy.binaryStr + ")";
|
||||||
|
}
|
||||||
|
DOM.entropyFiltered.text(entropy.cleanStr);
|
||||||
|
DOM.entropyType.text(entropy.base.str);
|
||||||
|
DOM.entropyStrength.text(strength);
|
||||||
|
DOM.entropyEventCount.text(entropy.base.ints.length);
|
||||||
|
DOM.entropyBits.text(bitsStr);
|
||||||
|
DOM.entropyBitsPerEvent.text(Math.log2(entropy.base.asInt).toFixed(2));
|
||||||
|
DOM.entropyFeedback.removeClass("hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
var networks = [
|
var networks = [
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ function waitForEntropyFeedback(fn, maxTime) {
|
|||||||
maxTime = testMaxTime;
|
maxTime = testMaxTime;
|
||||||
}
|
}
|
||||||
var origFeedback = page.evaluate(function() {
|
var origFeedback = page.evaluate(function() {
|
||||||
return $(".entropy-error").text();
|
return $(".entropy-feedback").text();
|
||||||
});
|
});
|
||||||
var start = new Date().getTime();
|
var start = new Date().getTime();
|
||||||
var wait = function keepWaiting() {
|
var wait = function keepWaiting() {
|
||||||
@@ -92,11 +92,7 @@ function waitForEntropyFeedback(fn, maxTime) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var feedback = page.evaluate(function() {
|
var feedback = page.evaluate(function() {
|
||||||
var feedback = $(".entropy-error");
|
return $(".entropy-feedback").text();
|
||||||
if (feedback.css("display") == "none") {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return feedback.text();
|
|
||||||
});
|
});
|
||||||
var hasFinished = feedback != origFeedback;
|
var hasFinished = feedback != origFeedback;
|
||||||
if (hasFinished) {
|
if (hasFinished) {
|
||||||
@@ -2130,30 +2126,33 @@ page.open(url, function(status) {
|
|||||||
catch (e) {
|
catch (e) {
|
||||||
return e.message;
|
return e.message;
|
||||||
}
|
}
|
||||||
// Leading zeros are not used for base 6 as binary string
|
// Leading zeros for base 6 as binary string
|
||||||
|
// 20 = 2 events at 2.58 bits per event = 5 bits
|
||||||
|
// 20 in base 6 = 12 in base 10 = 1100 in base 2
|
||||||
|
// so it needs 1 bit of padding to be the right bit length
|
||||||
try {
|
try {
|
||||||
e = Entropy.fromString("2");
|
e = Entropy.fromString("20");
|
||||||
if (e.binaryStr != "10") {
|
if (e.binaryStr != "01100") {
|
||||||
return "Base 6 as binary has leading zeros";
|
return "Base 6 as binary has leading zeros";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return e.message;
|
return e.message;
|
||||||
}
|
}
|
||||||
// Leading zeros are not used for base 10 as binary string
|
// Leading zeros for base 10 as binary string
|
||||||
try {
|
try {
|
||||||
e = Entropy.fromString("7");
|
e = Entropy.fromString("17");
|
||||||
if (e.binaryStr != "111") {
|
if (e.binaryStr != "010001") {
|
||||||
return "Base 10 as binary has leading zeros";
|
return "Base 10 as binary has leading zeros";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return e.message;
|
return e.message;
|
||||||
}
|
}
|
||||||
// Leading zeros are not used for card entropy as binary string
|
// Leading zeros for card entropy as binary string
|
||||||
try {
|
try {
|
||||||
e = Entropy.fromString("2c");
|
e = Entropy.fromString("2c");
|
||||||
if (e.binaryStr != "1") {
|
if (e.binaryStr != "00001") {
|
||||||
return "Card entropy as binary has leading zeros";
|
return "Card entropy as binary has leading zeros";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2187,18 +2186,18 @@ page.open(url, function(status) {
|
|||||||
var cards = [
|
var cards = [
|
||||||
[ "ac", "00000" ],
|
[ "ac", "00000" ],
|
||||||
[ "acac", "00000000000" ],
|
[ "acac", "00000000000" ],
|
||||||
[ "acac2c", "000000000001" ],
|
[ "acac2c", "00000000000000001" ],
|
||||||
[ "acks", "00000110011" ],
|
[ "acks", "00000110011" ],
|
||||||
[ "acacks", "00000000000110011" ],
|
[ "acacks", "00000000000110011" ],
|
||||||
[ "2c", "1" ],
|
[ "2c", "00001" ],
|
||||||
[ "3d", "1111" ],
|
[ "3d", "01111" ],
|
||||||
[ "4h", "11101" ],
|
[ "4h", "11101" ],
|
||||||
[ "5s", "101011" ],
|
[ "5s", "101011" ],
|
||||||
[ "6c", "101" ],
|
[ "6c", "00101" ],
|
||||||
[ "7d", "10011" ],
|
[ "7d", "10011" ],
|
||||||
[ "8h", "100001" ],
|
[ "8h", "100001" ],
|
||||||
[ "9s", "101111" ],
|
[ "9s", "101111" ],
|
||||||
[ "tc", "1001" ],
|
[ "tc", "01001" ],
|
||||||
[ "jd", "10111" ],
|
[ "jd", "10111" ],
|
||||||
[ "qh", "100101" ],
|
[ "qh", "100101" ],
|
||||||
[ "ks", "110011" ],
|
[ "ks", "110011" ],
|
||||||
@@ -2489,7 +2488,7 @@ page.open(url, function(status) {
|
|||||||
[ "7", "3" ], // 7 in base 10 is 111 in base 2, no leading zeros
|
[ "7", "3" ], // 7 in base 10 is 111 in base 2, no leading zeros
|
||||||
[ "8", "4" ],
|
[ "8", "4" ],
|
||||||
[ "F", "4" ],
|
[ "F", "4" ],
|
||||||
[ "29", "5" ],
|
[ "29", "6" ],
|
||||||
[ "0A", "8" ],
|
[ "0A", "8" ],
|
||||||
[ "1A", "8" ], // hex is always multiple of 4 bits of entropy
|
[ "1A", "8" ], // hex is always multiple of 4 bits of entropy
|
||||||
[ "2A", "8" ],
|
[ "2A", "8" ],
|
||||||
@@ -2499,9 +2498,10 @@ page.open(url, function(status) {
|
|||||||
[ "000A", "16" ],
|
[ "000A", "16" ],
|
||||||
[ "5555", "11" ],
|
[ "5555", "11" ],
|
||||||
[ "6666", "10" ], // uses dice, so entropy is actually 0000 in base 6, which is 4 lots of 2.58 bits, which is 10.32 bits (rounded down to 10 bits)
|
[ "6666", "10" ], // uses dice, so entropy is actually 0000 in base 6, which is 4 lots of 2.58 bits, which is 10.32 bits (rounded down to 10 bits)
|
||||||
[ "2227", "12" ],
|
[ "2227", "13" ], // Uses base 10, which is 4 lots of 3.32 bits, which is 13.3 bits (rounded down to 13)
|
||||||
[ "222F", "16" ],
|
[ "222F", "16" ],
|
||||||
[ "FFFF", "16" ],
|
[ "FFFF", "16" ],
|
||||||
|
[ "0000101017", "33" ], // 10 events at 3.32 bits per event
|
||||||
]
|
]
|
||||||
// use entropy
|
// use entropy
|
||||||
page.evaluate(function(e) {
|
page.evaluate(function(e) {
|
||||||
@@ -2518,11 +2518,10 @@ page.open(url, function(status) {
|
|||||||
// check the number of bits of entropy is shown
|
// check the number of bits of entropy is shown
|
||||||
waitForEntropyFeedback(function() {
|
waitForEntropyFeedback(function() {
|
||||||
var entropyText = page.evaluate(function() {
|
var entropyText = page.evaluate(function() {
|
||||||
return $(".entropy-error").text();
|
return $(".entropy-feedback").text();
|
||||||
});
|
});
|
||||||
if (entropyText.indexOf("Have " + expected + " bits of entropy") == -1) {
|
if (entropyText.replace(/\s/g,"").indexOf("Bits" + expected) == -1) {
|
||||||
console.log("Accumulated entropy is not shown correctly for " + entropy);
|
console.log("Accumulated entropy is not shown correctly for " + entropy);
|
||||||
console.log(entropyText);
|
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
var isLastTest = i == tests.length - 1;
|
var isLastTest = i == tests.length - 1;
|
||||||
@@ -2538,28 +2537,6 @@ page.open(url, function(status) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// The number of bits of entropy to reach the next mnemonic strength is shown
|
|
||||||
function() {
|
|
||||||
page.open(url, function(status) {
|
|
||||||
// use entropy
|
|
||||||
page.evaluate(function() {
|
|
||||||
$(".use-entropy").prop("checked", true).trigger("change");
|
|
||||||
$(".entropy").val("7654321").trigger("input");
|
|
||||||
});
|
|
||||||
// check the amount of additional entropy required is shown
|
|
||||||
waitForEntropyFeedback(function() {
|
|
||||||
var entropyText = page.evaluate(function() {
|
|
||||||
return $(".entropy-container").text();
|
|
||||||
});
|
|
||||||
if (entropyText.indexOf("3 more base 10 chars required") == -1) {
|
|
||||||
console.log("Additional entropy requirement is not shown");
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// The next strength above 0-word mnemonics is considered extremely weak
|
// The next strength above 0-word mnemonics is considered extremely weak
|
||||||
// The next strength above 3-word mnemonics is considered very weak
|
// The next strength above 3-word mnemonics is considered very weak
|
||||||
// The next strength above 6-word mnemonics is considered weak
|
// The next strength above 6-word mnemonics is considered weak
|
||||||
@@ -2572,37 +2549,42 @@ page.open(url, function(status) {
|
|||||||
{
|
{
|
||||||
entropy: "A",
|
entropy: "A",
|
||||||
words: 0,
|
words: 0,
|
||||||
nextStrength: "an extremely weak",
|
strength: "extremely weak",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
entropy: "AAAAAAAA",
|
entropy: "AAAAAAAA",
|
||||||
words: 3,
|
words: 3,
|
||||||
nextStrength: "a very weak",
|
strength: "extremely weak",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
entropy: "AAAAAAAA B",
|
entropy: "AAAAAAAA B",
|
||||||
words: 3,
|
words: 3,
|
||||||
nextStrength: "a very weak",
|
strength: "extremely weak",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
entropy: "AAAAAAAA BBBBBBBB",
|
entropy: "AAAAAAAA BBBBBBBB",
|
||||||
words: 6,
|
words: 6,
|
||||||
nextStrength: "a weak",
|
strength: "very weak",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
entropy: "AAAAAAAA BBBBBBBB CCCCCCCC",
|
entropy: "AAAAAAAA BBBBBBBB CCCCCCCC",
|
||||||
words: 9,
|
words: 9,
|
||||||
nextStrength: "a strong",
|
strength: "weak",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD",
|
entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD",
|
||||||
words: 12,
|
words: 12,
|
||||||
nextStrength: "a very strong",
|
strength: "strong",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE",
|
entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE",
|
||||||
words: 15,
|
words: 15,
|
||||||
nextStrength: "an extremely strong",
|
strength: "very strong",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE FFFFFFFF",
|
||||||
|
words: 18,
|
||||||
|
strength: "extremely strong",
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
// use entropy
|
// use entropy
|
||||||
@@ -2621,7 +2603,7 @@ page.open(url, function(status) {
|
|||||||
return $(".phrase").val();
|
return $(".phrase").val();
|
||||||
});
|
});
|
||||||
if (mnemonic.length > 0) {
|
if (mnemonic.length > 0) {
|
||||||
console.log("Mnemonic length for " + test.nextStrength + " strength is not " + test.words);
|
console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
|
||||||
console.log("Mnemonic: " + mnemonic);
|
console.log("Mnemonic: " + mnemonic);
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
@@ -2635,21 +2617,21 @@ page.open(url, function(status) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
waitForGenerate(function() {
|
waitForGenerate(function() {
|
||||||
// check the strength of the current mnemonic
|
// check the number of words in the current mnemonic
|
||||||
var mnemonic = page.evaluate(function() {
|
var mnemonic = page.evaluate(function() {
|
||||||
return $(".phrase").val();
|
return $(".phrase").val();
|
||||||
});
|
});
|
||||||
if (mnemonic.split(" ").length != test.words) {
|
if (mnemonic.split(" ").length != test.words) {
|
||||||
console.log("Mnemonic length for " + test.nextStrength + " strength is not " + test.words);
|
console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
|
||||||
console.log("Mnemonic: " + mnemonic);
|
console.log("Mnemonic: " + mnemonic);
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
// check the strength of the next mnemonic is shown
|
// check the strength of the mnemonic is shown
|
||||||
var entropyText = page.evaluate(function() {
|
var entropyText = page.evaluate(function() {
|
||||||
return $(".entropy-container").text();
|
return $(".entropy-container").text();
|
||||||
});
|
});
|
||||||
if (entropyText.indexOf("required to generate " + test.nextStrength + " mnemonic") == -1) {
|
if (entropyText.indexOf(test.strength) == -1) {
|
||||||
console.log("Strength indicator for " + test.nextStrength + " mnemonic is incorrect");
|
console.log("Strength indicator for " + test.strength + " mnemonic is incorrect");
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
var isLastTest = i == tests.length - 1;
|
var isLastTest = i == tests.length - 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user