]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blobdiff - bip39-standalone.html
Generation process stopped when table rows cleared
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / bip39-standalone.html
index ca18ea8b609890fc6e2f706a02e07df8a29fb64d..afef084e9264e880e2291807f148b7525cf021e9 100644 (file)
                             random enough for the needs of this tool.
                         </span>
                     </p>
+                    <p>
+                        <strong><span data-translate>Do not store entropy.</span></strong>
+                    </p>
+                    <p>
+                        <span data-translate>Storing entropy (such as keeping a deck of cards in a specific shuffled order) is unreliable compared to storing a mnemonic.</span>
+                        <span data-translate>Instead of storing entropy, store the mnemonic generated from the entropy.</span>
+                        <span data-translate-html><a href="https://en.wikipedia.org/wiki/Steganography#Physical" target="_blank">Steganography</a> may be beneficial when storing the mnemonic.</span>
+                    </p>
                     <p>
                         <span data-translate-html>
                             The random mnemonic generator on this page uses a
@@ -18584,15 +18592,12 @@ window.Entropy = new (function() {
         // Create a normalized string of the selected cards
         var normalizedCards = cards.join("").toUpperCase();
         // Convert to binary using the SHA256 hash of the normalized cards.
-        // If the number of bits is more than 256, multiple rounds of hashing
+        // If the number of bits is more than 256, multiple hashes
         // are used until the required number of bits is reached.
         var entropyBin = "";
         var iterations = 0;
         while (entropyBin.length < numberOfBits) {
-            var hashedCards = sjcl.hash.sha256.hash(normalizedCards);
-            for (var j=0; j<iterations; j++) {
-                hashedCards = sjcl.hash.sha256.hash(hashedCards);
-            }
+            var hashedCards = sjcl.hash.sha256.hash(normalizedCards + ":" + iterations);
             var hashHex = sjcl.codec.hex.fromBits(hashedCards);
             for (var i=0; i<hashHex.length; i++) {
                 var decimal = parseInt(hashHex[i], 16);
@@ -18643,7 +18648,7 @@ window.Entropy = new (function() {
     // mnemonics is populated as required by getLanguage
     var mnemonics = { "english": new Mnemonic("english") };
     var mnemonic = mnemonics["english"];
-    var seed = null
+    var seed = null;
     var bip32RootKey = null;
     var bip32ExtendedKey = null;
     var network = bitcoin.networks.bitcoin;
@@ -18659,6 +18664,8 @@ window.Entropy = new (function() {
     var phraseChangeTimeoutEvent = null;
     var rootKeyChangedTimeoutEvent = null;
 
+    var generationProcesses = [];
+
     var DOM = {};
     DOM.network = $(".network");
     DOM.phraseNetwork = $("#network-phrase");
@@ -19152,14 +19159,28 @@ window.Entropy = new (function() {
     }
 
     function displayAddresses(start, total) {
-        for (var i=0; i<total; i++) {
-            var index = i + start;
-            new TableRow(index);
-        }
+        generationProcesses.push(new (function() {
+
+            var rows = [];
+
+            this.stop = function() {
+                for (var i=0; i<rows.length; i++) {
+                    rows[i].shouldGenerate = false;
+                }
+            }
+
+            for (var i=0; i<total; i++) {
+                var index = i + start;
+                rows.push(new TableRow(index));
+            }
+
+        })());
     }
 
     function TableRow(index) {
 
+        var self = this;
+        this.shouldGenerate = true;
         var useHardenedAddresses = DOM.hardenedAddresses.prop("checked");
 
         function init() {
@@ -19168,6 +19189,9 @@ window.Entropy = new (function() {
 
         function calculateValues() {
             setTimeout(function() {
+                if (!self.shouldGenerate) {
+                    return;
+                }
                 var key = "";
                 if (useHardenedAddresses) {
                     key = bip32ExtendedKey.deriveHardened(index);
@@ -19218,6 +19242,14 @@ window.Entropy = new (function() {
 
     function clearAddressesList() {
         DOM.addresses.empty();
+        stopGenerating();
+    }
+
+    function stopGenerating() {
+        while (generationProcesses.length > 0) {
+            var generation = generationProcesses.shift();
+            generation.stop();
+        }
     }
 
     function clearKey() {
@@ -19287,6 +19319,9 @@ window.Entropy = new (function() {
         var closestWord = words[0];
         for (var i=0; i<words.length; i++) {
             var comparedTo = words[i];
+            if (comparedTo.indexOf(word) == 0) {
+                return comparedTo;
+            }
             var distance = Levenshtein.get(word, comparedTo);
             if (distance < minDistance) {
                 closestWord = comparedTo;