aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/index.html60
-rw-r--r--src/js/entropy.js47
-rw-r--r--src/js/index.js79
-rw-r--r--tests.js100
4 files changed, 149 insertions, 137 deletions
diff --git a/src/index.html b/src/index.html
index cb7a781..feefbd8 100644
--- a/src/index.html
+++ b/src/index.html
@@ -95,17 +95,57 @@
95 </div> 95 </div>
96 </div> 96 </div>
97 <div class="entropy-container hidden"> 97 <div class="entropy-container hidden">
98 <label for="entropy" class="col-sm-2 control-label">Entropy</label> 98 <div class="form-group">
99 <div class="col-sm-10"> 99 <label for="entropy" class="col-sm-2 control-label">Entropy</label>
100 <input id="entropy" class="entropy form-control" placeholder="Accepts binary, base 6, 6-sided dice, base 10, hexadecimal"> 100 <div class="col-sm-10">
101 <span class="help-block"> 101 <input id="entropy" class="entropy form-control" placeholder="Accepts binary, base 6, 6-sided dice, base 10, hexadecimal">
102 <div class="text-danger"> 102 <span class="help-block">
103 This is an advanced feature. 103 <div class="text-danger">
104 Your mnemonic may be insecure if this feature is used incorrectly. 104 This is an advanced feature.
105 <a href="#entropy-notes">Read more</a> 105 Your mnemonic may be insecure if this feature is used incorrectly.
106 <a href="#entropy-notes">Read more</a>
107 </div>
108 </span>
109 </div>
110 </div>
111 <div class="entropy-feedback">
112 <div class="form-group">
113 <label class="col-sm-2 control-label">Filtered</label>
114 <div class="filtered col-sm-10 form-control-static"></div>
115 </div>
116 <div class="form-group">
117 <label class="col-sm-2 control-label">Type</label>
118 <div class="type col-sm-10 form-control-static"></div>
119 </div>
120 <div class="form-group">
121 <label class="col-sm-2 control-label">Strength</label>
122 <div class="strength col-sm-10 form-control-static"></div>
123 </div>
124 <div class="form-group">
125 <label class="col-sm-2 control-label">Event Count</label>
126 <div class="event-count col-sm-10 form-control-static"></div>
127 </div>
128 <div class="form-group">
129 <label class="col-sm-2 control-label">Bits Per Event</label>
130 <div class="bits-per-event col-sm-10 form-control-static"></div>
131 </div>
132 <div class="form-group">
133 <label class="col-sm-2 control-label">Bits</label>
134 <div class="bits col-sm-10 form-control-static"></div>
135 </div>
136 <div class="form-group">
137 <label class="col-sm-2 control-label">Mnemonic Length</label>
138 <div class="col-sm-10">
139 <select class="mnemonic-length form-control">
140 <option value="raw">From entropy length</option>
141 <option value="12">12 Words</option>
142 <option value="15">15 Words</option>
143 <option value="18">18 Words</option>
144 <option value="21">21 Words</option>
145 <option value="24">24 Words</option>
146 </select>
106 </div> 147 </div>
107 <div class="text-danger entropy-error"></div> 148 </div>
108 </span>
109 </div> 149 </div>
110 </div> 150 </div>
111 <div class="form-group"> 151 <div class="form-group">
diff --git a/src/js/entropy.js b/src/js/entropy.js
index db4051b..cd9b375 100644
--- a/src/js/entropy.js
+++ b/src/js/entropy.js
@@ -96,40 +96,6 @@ window.Entropy = new (function() {
96 base: base, 96 base: base,
97 }; 97 };
98 } 98 }
99 // Pull leading zeros off
100 var leadingZeros = [];
101 while (base.ints[0] == "0") {
102 leadingZeros.push("0");
103 base.ints.shift();
104 }
105 // Convert leading zeros to binary equivalent
106 var numBinLeadingZeros = Math.floor(Math.log2(base.asInt) * leadingZeros.length);
107 var binLeadingZeros = "";
108 for (var i=0; i<numBinLeadingZeros; i++) {
109 binLeadingZeros += "0";
110 }
111 // Handle entropy of zero
112 if (base.ints.length == 0) {
113 return {
114 binaryStr: binLeadingZeros,
115 cleanStr: leadingZeros.join(""),
116 base: base,
117 }
118 }
119 // If the first integer is small, it must be padded with zeros.
120 // Otherwise the chance of the first bit being 1 is 100%, which is
121 // obviously incorrect.
122 // This is not perfect for unusual bases, so is only done for bases
123 // of 2^n, eg octal or hexadecimal
124 if (base.asInt == 16) {
125 var firstInt = base.ints[0];
126 var firstIntBits = firstInt.toString(2).length;
127 var maxFirstIntBits = (base.asInt-1).toString(2).length;
128 var missingFirstIntBits = maxFirstIntBits - firstIntBits;
129 for (var i=0; i<missingFirstIntBits; i++) {
130 binLeadingZeros += "0";
131 }
132 }
133 // Convert base.ints to BigInteger. 99 // Convert base.ints to BigInteger.
134 // Due to using unusual bases, eg cards of base52, this is not as simple as 100 // Due to using unusual bases, eg cards of base52, this is not as simple as
135 // using BigInteger.parse() 101 // using BigInteger.parse()
@@ -140,8 +106,17 @@ window.Entropy = new (function() {
140 var additionalEntropy = BigInteger.parse(base.asInt).pow(power).multiply(thisInt); 106 var additionalEntropy = BigInteger.parse(base.asInt).pow(power).multiply(thisInt);
141 entropyInt = entropyInt.add(additionalEntropy); 107 entropyInt = entropyInt.add(additionalEntropy);
142 } 108 }
143 // Convert entropy to different formats 109 // Convert entropy to binary
144 var entropyBin = binLeadingZeros + entropyInt.toString(2); 110 var entropyBin = entropyInt.toString(2);
111 // If the first integer is small, it must be padded with zeros.
112 // Otherwise the chance of the first bit being 1 is 100%, which is
113 // obviously incorrect.
114 // This is not perfect for non-2^n bases.
115 var expectedBits = Math.floor(base.parts.length * Math.log2(base.asInt));
116 while (entropyBin.length < expectedBits) {
117 entropyBin = "0" + entropyBin;
118 }
119 // Supply a 'filtered' entropy string for display purposes
145 var entropyClean = base.parts.join(""); 120 var entropyClean = base.parts.join("");
146 if (base.asInt == 52) { 121 if (base.asInt == 52) {
147 entropyClean = base.parts.join(" ").toUpperCase(); 122 entropyClean = base.parts.join(" ").toUpperCase();
diff --git a/src/js/index.js b/src/js/index.js
index 45db7b1..45f378d 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -24,7 +24,14 @@
24 DOM.useEntropy = $(".use-entropy"); 24 DOM.useEntropy = $(".use-entropy");
25 DOM.entropyContainer = $(".entropy-container"); 25 DOM.entropyContainer = $(".entropy-container");
26 DOM.entropy = $(".entropy"); 26 DOM.entropy = $(".entropy");
27 DOM.entropyError = $(".entropy-error"); 27 DOM.entropyFeedback = $(".entropy-feedback");
28 DOM.entropyFiltered = DOM.entropyFeedback.find(".filtered");
29 DOM.entropyType = DOM.entropyFeedback.find(".type");
30 DOM.entropyStrength = DOM.entropyFeedback.find(".strength");
31 DOM.entropyEventCount = DOM.entropyFeedback.find(".event-count");
32 DOM.entropyBits = DOM.entropyFeedback.find(".bits");
33 DOM.entropyBitsPerEvent = DOM.entropyFeedback.find(".bits-per-event");
34 DOM.entropyMnemonicLength = DOM.entropyFeedback.find(".mnemonic-length");
28 DOM.phrase = $(".phrase"); 35 DOM.phrase = $(".phrase");
29 DOM.passphrase = $(".passphrase"); 36 DOM.passphrase = $(".passphrase");
30 DOM.generateContainer = $(".generate-container"); 37 DOM.generateContainer = $(".generate-container");
@@ -153,7 +160,7 @@
153 // If blank entropy, clear mnemonic, addresses, errors 160 // If blank entropy, clear mnemonic, addresses, errors
154 if (DOM.entropy.val().trim().length == 0) { 161 if (DOM.entropy.val().trim().length == 0) {
155 clearDisplay(); 162 clearDisplay();
156 hideEntropyError(); 163 hideEntropyFeedback();
157 DOM.phrase.val(""); 164 DOM.phrase.val("");
158 showValidationError("Blank entropy"); 165 showValidationError("Blank entropy");
159 return; 166 return;
@@ -727,7 +734,7 @@
727 } 734 }
728 735
729 function setMnemonicFromEntropy() { 736 function setMnemonicFromEntropy() {
730 hideEntropyError(); 737 hideEntropyFeedback();
731 // Get entropy value 738 // Get entropy value
732 var entropyStr = DOM.entropy.val(); 739 var entropyStr = DOM.entropy.val();
733 // Work out minimum base for entropy 740 // Work out minimum base for entropy
@@ -736,30 +743,7 @@
736 return; 743 return;
737 } 744 }
738 // Show entropy details 745 // Show entropy details
739 var extraBits = 32 - (entropy.binaryStr.length % 32); 746 showEntropyFeedback(entropy);
740 var extraChars = Math.ceil(extraBits * Math.log(2) / Math.log(entropy.base.asInt));
741 var words = Math.floor(entropy.binaryStr.length / 32) * 3;
742 var strength = "an extremely weak";
743 if (words >= 3) {
744 strength = "a very weak";
745 }
746 if (words >= 6) {
747 strength = "a weak";
748 }
749 if (words >= 9) {
750 strength = "a strong";
751 }
752 if (words >= 12) {
753 strength = "a very strong";
754 }
755 if (words >= 15) {
756 strength = "an extremely strong";
757 }
758 if (words >= 18) {
759 strength = "an even stronger"
760 }
761 var msg = "Have " + entropy.binaryStr.length + " bits of entropy, " + extraChars + " more " + entropy.base.str + " chars required to generate " + strength + " mnemonic: " + entropy.cleanStr;
762 showEntropyError(msg);
763 // Discard trailing entropy 747 // Discard trailing entropy
764 var bitsToUse = Math.floor(entropy.binaryStr.length / 32) * 32; 748 var bitsToUse = Math.floor(entropy.binaryStr.length / 32) * 32;
765 var binaryStr = entropy.binaryStr.substring(0, bitsToUse); 749 var binaryStr = entropy.binaryStr.substring(0, bitsToUse);
@@ -776,13 +760,44 @@
776 DOM.phrase.val(phrase); 760 DOM.phrase.val(phrase);
777 } 761 }
778 762
779 function hideEntropyError() { 763 function hideEntropyFeedback() {
780 DOM.entropyError.addClass("hidden"); 764 DOM.entropyFeedback.addClass("hidden");
765 DOM.entropyFiltered.text("");
766 DOM.entropyType.text("");
767 DOM.entropyStrength.text("");
768 DOM.entropyEventCount.text("");
769 DOM.entropyBits.text("");
770 DOM.entropyBitsPerEvent.text("");
781 } 771 }
782 772
783 function showEntropyError(msg) { 773 function showEntropyFeedback(entropy) {
784 DOM.entropyError.text(msg); 774 var strength = "extremely weak";
785 DOM.entropyError.removeClass("hidden"); 775 if (entropy.binaryStr.length >= 64) {
776 strength = "very weak";
777 }
778 if (entropy.binaryStr.length >= 96) {
779 strength = "weak";
780 }
781 if (entropy.binaryStr.length >= 128) {
782 strength = "strong";
783 }
784 if (entropy.binaryStr.length >= 160) {
785 strength = "very strong";
786 }
787 if (entropy.binaryStr.length >= 192) {
788 strength = "extremely strong";
789 }
790 var bitsStr = entropy.binaryStr.length;
791 if (entropy.base.asInt != 2) {
792 bitsStr += " (" + entropy.binaryStr + ")";
793 }
794 DOM.entropyFiltered.text(entropy.cleanStr);
795 DOM.entropyType.text(entropy.base.str);
796 DOM.entropyStrength.text(strength);
797 DOM.entropyEventCount.text(entropy.base.ints.length);
798 DOM.entropyBits.text(bitsStr);
799 DOM.entropyBitsPerEvent.text(Math.log2(entropy.base.asInt).toFixed(2));
800 DOM.entropyFeedback.removeClass("hidden");
786 } 801 }
787 802
788 var networks = [ 803 var networks = [
diff --git a/tests.js b/tests.js
index 102144f..420873d 100644
--- a/tests.js
+++ b/tests.js
@@ -80,7 +80,7 @@ function waitForEntropyFeedback(fn, maxTime) {
80 maxTime = testMaxTime; 80 maxTime = testMaxTime;
81 } 81 }
82 var origFeedback = page.evaluate(function() { 82 var origFeedback = page.evaluate(function() {
83 return $(".entropy-error").text(); 83 return $(".entropy-feedback").text();
84 }); 84 });
85 var start = new Date().getTime(); 85 var start = new Date().getTime();
86 var wait = function keepWaiting() { 86 var wait = function keepWaiting() {
@@ -92,11 +92,7 @@ function waitForEntropyFeedback(fn, maxTime) {
92 return; 92 return;
93 } 93 }
94 var feedback = page.evaluate(function() { 94 var feedback = page.evaluate(function() {
95 var feedback = $(".entropy-error"); 95 return $(".entropy-feedback").text();
96 if (feedback.css("display") == "none") {
97 return "";
98 }
99 return feedback.text();
100 }); 96 });
101 var hasFinished = feedback != origFeedback; 97 var hasFinished = feedback != origFeedback;
102 if (hasFinished) { 98 if (hasFinished) {
@@ -2130,30 +2126,33 @@ page.open(url, function(status) {
2130 catch (e) { 2126 catch (e) {
2131 return e.message; 2127 return e.message;
2132 } 2128 }
2133 // Leading zeros are not used for base 6 as binary string 2129 // Leading zeros for base 6 as binary string
2130 // 20 = 2 events at 2.58 bits per event = 5 bits
2131 // 20 in base 6 = 12 in base 10 = 1100 in base 2
2132 // so it needs 1 bit of padding to be the right bit length
2134 try { 2133 try {
2135 e = Entropy.fromString("2"); 2134 e = Entropy.fromString("20");
2136 if (e.binaryStr != "10") { 2135 if (e.binaryStr != "01100") {
2137 return "Base 6 as binary has leading zeros"; 2136 return "Base 6 as binary has leading zeros";
2138 } 2137 }
2139 } 2138 }
2140 catch (e) { 2139 catch (e) {
2141 return e.message; 2140 return e.message;
2142 } 2141 }
2143 // Leading zeros are not used for base 10 as binary string 2142 // Leading zeros for base 10 as binary string
2144 try { 2143 try {
2145 e = Entropy.fromString("7"); 2144 e = Entropy.fromString("17");
2146 if (e.binaryStr != "111") { 2145 if (e.binaryStr != "010001") {
2147 return "Base 10 as binary has leading zeros"; 2146 return "Base 10 as binary has leading zeros";
2148 } 2147 }
2149 } 2148 }
2150 catch (e) { 2149 catch (e) {
2151 return e.message; 2150 return e.message;
2152 } 2151 }
2153 // Leading zeros are not used for card entropy as binary string 2152 // Leading zeros for card entropy as binary string
2154 try { 2153 try {
2155 e = Entropy.fromString("2c"); 2154 e = Entropy.fromString("2c");
2156 if (e.binaryStr != "1") { 2155 if (e.binaryStr != "00001") {
2157 return "Card entropy as binary has leading zeros"; 2156 return "Card entropy as binary has leading zeros";
2158 } 2157 }
2159 } 2158 }
@@ -2187,18 +2186,18 @@ page.open(url, function(status) {
2187 var cards = [ 2186 var cards = [
2188 [ "ac", "00000" ], 2187 [ "ac", "00000" ],
2189 [ "acac", "00000000000" ], 2188 [ "acac", "00000000000" ],
2190 [ "acac2c", "000000000001" ], 2189 [ "acac2c", "00000000000000001" ],
2191 [ "acks", "00000110011" ], 2190 [ "acks", "00000110011" ],
2192 [ "acacks", "00000000000110011" ], 2191 [ "acacks", "00000000000110011" ],
2193 [ "2c", "1" ], 2192 [ "2c", "00001" ],
2194 [ "3d", "1111" ], 2193 [ "3d", "01111" ],
2195 [ "4h", "11101" ], 2194 [ "4h", "11101" ],
2196 [ "5s", "101011" ], 2195 [ "5s", "101011" ],
2197 [ "6c", "101" ], 2196 [ "6c", "00101" ],
2198 [ "7d", "10011" ], 2197 [ "7d", "10011" ],
2199 [ "8h", "100001" ], 2198 [ "8h", "100001" ],
2200 [ "9s", "101111" ], 2199 [ "9s", "101111" ],
2201 [ "tc", "1001" ], 2200 [ "tc", "01001" ],
2202 [ "jd", "10111" ], 2201 [ "jd", "10111" ],
2203 [ "qh", "100101" ], 2202 [ "qh", "100101" ],
2204 [ "ks", "110011" ], 2203 [ "ks", "110011" ],
@@ -2489,7 +2488,7 @@ page.open(url, function(status) {
2489 [ "7", "3" ], // 7 in base 10 is 111 in base 2, no leading zeros 2488 [ "7", "3" ], // 7 in base 10 is 111 in base 2, no leading zeros
2490 [ "8", "4" ], 2489 [ "8", "4" ],
2491 [ "F", "4" ], 2490 [ "F", "4" ],
2492 [ "29", "5" ], 2491 [ "29", "6" ],
2493 [ "0A", "8" ], 2492 [ "0A", "8" ],
2494 [ "1A", "8" ], // hex is always multiple of 4 bits of entropy 2493 [ "1A", "8" ], // hex is always multiple of 4 bits of entropy
2495 [ "2A", "8" ], 2494 [ "2A", "8" ],
@@ -2499,9 +2498,10 @@ page.open(url, function(status) {
2499 [ "000A", "16" ], 2498 [ "000A", "16" ],
2500 [ "5555", "11" ], 2499 [ "5555", "11" ],
2501 [ "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) 2500 [ "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)
2502 [ "2227", "12" ], 2501 [ "2227", "13" ], // Uses base 10, which is 4 lots of 3.32 bits, which is 13.3 bits (rounded down to 13)
2503 [ "222F", "16" ], 2502 [ "222F", "16" ],
2504 [ "FFFF", "16" ], 2503 [ "FFFF", "16" ],
2504 [ "0000101017", "33" ], // 10 events at 3.32 bits per event
2505 ] 2505 ]
2506 // use entropy 2506 // use entropy
2507 page.evaluate(function(e) { 2507 page.evaluate(function(e) {
@@ -2518,11 +2518,10 @@ page.open(url, function(status) {
2518 // check the number of bits of entropy is shown 2518 // check the number of bits of entropy is shown
2519 waitForEntropyFeedback(function() { 2519 waitForEntropyFeedback(function() {
2520 var entropyText = page.evaluate(function() { 2520 var entropyText = page.evaluate(function() {
2521 return $(".entropy-error").text(); 2521 return $(".entropy-feedback").text();
2522 }); 2522 });
2523 if (entropyText.indexOf("Have " + expected + " bits of entropy") == -1) { 2523 if (entropyText.replace(/\s/g,"").indexOf("Bits" + expected) == -1) {
2524 console.log("Accumulated entropy is not shown correctly for " + entropy); 2524 console.log("Accumulated entropy is not shown correctly for " + entropy);
2525 console.log(entropyText);
2526 fail(); 2525 fail();
2527 } 2526 }
2528 var isLastTest = i == tests.length - 1; 2527 var isLastTest = i == tests.length - 1;
@@ -2538,28 +2537,6 @@ page.open(url, function(status) {
2538}); 2537});
2539}, 2538},
2540 2539
2541// The number of bits of entropy to reach the next mnemonic strength is shown
2542function() {
2543page.open(url, function(status) {
2544 // use entropy
2545 page.evaluate(function() {
2546 $(".use-entropy").prop("checked", true).trigger("change");
2547 $(".entropy").val("7654321").trigger("input");
2548 });
2549 // check the amount of additional entropy required is shown
2550 waitForEntropyFeedback(function() {
2551 var entropyText = page.evaluate(function() {
2552 return $(".entropy-container").text();
2553 });
2554 if (entropyText.indexOf("3 more base 10 chars required") == -1) {
2555 console.log("Additional entropy requirement is not shown");
2556 fail();
2557 }
2558 next();
2559 });
2560});
2561},
2562
2563// The next strength above 0-word mnemonics is considered extremely weak 2540// The next strength above 0-word mnemonics is considered extremely weak
2564// The next strength above 3-word mnemonics is considered very weak 2541// The next strength above 3-word mnemonics is considered very weak
2565// The next strength above 6-word mnemonics is considered weak 2542// The next strength above 6-word mnemonics is considered weak
@@ -2572,37 +2549,42 @@ page.open(url, function(status) {
2572 { 2549 {
2573 entropy: "A", 2550 entropy: "A",
2574 words: 0, 2551 words: 0,
2575 nextStrength: "an extremely weak", 2552 strength: "extremely weak",
2576 }, 2553 },
2577 { 2554 {
2578 entropy: "AAAAAAAA", 2555 entropy: "AAAAAAAA",
2579 words: 3, 2556 words: 3,
2580 nextStrength: "a very weak", 2557 strength: "extremely weak",
2581 }, 2558 },
2582 { 2559 {
2583 entropy: "AAAAAAAA B", 2560 entropy: "AAAAAAAA B",
2584 words: 3, 2561 words: 3,
2585 nextStrength: "a very weak", 2562 strength: "extremely weak",
2586 }, 2563 },
2587 { 2564 {
2588 entropy: "AAAAAAAA BBBBBBBB", 2565 entropy: "AAAAAAAA BBBBBBBB",
2589 words: 6, 2566 words: 6,
2590 nextStrength: "a weak", 2567 strength: "very weak",
2591 }, 2568 },
2592 { 2569 {
2593 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC", 2570 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC",
2594 words: 9, 2571 words: 9,
2595 nextStrength: "a strong", 2572 strength: "weak",
2596 }, 2573 },
2597 { 2574 {
2598 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD", 2575 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD",
2599 words: 12, 2576 words: 12,
2600 nextStrength: "a very strong", 2577 strength: "strong",
2601 }, 2578 },
2602 { 2579 {
2603 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE", 2580 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE",
2604 words: 15, 2581 words: 15,
2605 nextStrength: "an extremely strong", 2582 strength: "very strong",
2583 },
2584 {
2585 entropy: "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE FFFFFFFF",
2586 words: 18,
2587 strength: "extremely strong",
2606 } 2588 }
2607 ]; 2589 ];
2608 // use entropy 2590 // use entropy
@@ -2621,7 +2603,7 @@ page.open(url, function(status) {
2621 return $(".phrase").val(); 2603 return $(".phrase").val();
2622 }); 2604 });
2623 if (mnemonic.length > 0) { 2605 if (mnemonic.length > 0) {
2624 console.log("Mnemonic length for " + test.nextStrength + " strength is not " + test.words); 2606 console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
2625 console.log("Mnemonic: " + mnemonic); 2607 console.log("Mnemonic: " + mnemonic);
2626 fail(); 2608 fail();
2627 } 2609 }
@@ -2635,21 +2617,21 @@ page.open(url, function(status) {
2635 } 2617 }
2636 else { 2618 else {
2637 waitForGenerate(function() { 2619 waitForGenerate(function() {
2638 // check the strength of the current mnemonic 2620 // check the number of words in the current mnemonic
2639 var mnemonic = page.evaluate(function() { 2621 var mnemonic = page.evaluate(function() {
2640 return $(".phrase").val(); 2622 return $(".phrase").val();
2641 }); 2623 });
2642 if (mnemonic.split(" ").length != test.words) { 2624 if (mnemonic.split(" ").length != test.words) {
2643 console.log("Mnemonic length for " + test.nextStrength + " strength is not " + test.words); 2625 console.log("Mnemonic length for " + test.strength + " strength is not " + test.words);
2644 console.log("Mnemonic: " + mnemonic); 2626 console.log("Mnemonic: " + mnemonic);
2645 fail(); 2627 fail();
2646 } 2628 }
2647 // check the strength of the next mnemonic is shown 2629 // check the strength of the mnemonic is shown
2648 var entropyText = page.evaluate(function() { 2630 var entropyText = page.evaluate(function() {
2649 return $(".entropy-container").text(); 2631 return $(".entropy-container").text();
2650 }); 2632 });
2651 if (entropyText.indexOf("required to generate " + test.nextStrength + " mnemonic") == -1) { 2633 if (entropyText.indexOf(test.strength) == -1) {
2652 console.log("Strength indicator for " + test.nextStrength + " mnemonic is incorrect"); 2634 console.log("Strength indicator for " + test.strength + " mnemonic is incorrect");
2653 fail(); 2635 fail();
2654 } 2636 }
2655 var isLastTest = i == tests.length - 1; 2637 var isLastTest = i == tests.length - 1;