diff options
author | Matthew Cornelisse <squarerootofnegativeone@gmail.com> | 2018-11-20 02:23:51 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-20 02:23:51 -0600 |
commit | 97bde20b849aca29056b1229e4ca0dbab832bf0b (patch) | |
tree | e8ea335f4a4f564d11761c5b7c7ac40e502189ec | |
parent | b1100c66eb9d3f71b350ec218d61c15951d578a9 (diff) | |
download | BIP39-97bde20b849aca29056b1229e4ca0dbab832bf0b.tar.gz BIP39-97bde20b849aca29056b1229e4ca0dbab832bf0b.tar.zst BIP39-97bde20b849aca29056b1229e4ca0dbab832bf0b.zip |
Added 2/3 Seed Card
-rw-r--r-- | src/js/index.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/js/index.js b/src/js/index.js index de509e8..a778799 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -44,6 +44,7 @@ | |||
44 | DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning"); | 44 | DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning"); |
45 | DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); | 45 | DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); |
46 | DOM.phrase = $(".phrase"); | 46 | DOM.phrase = $(".phrase"); |
47 | DOM.splitPhrase = $(".phraseSplit"); | ||
47 | DOM.passphrase = $(".passphrase"); | 48 | DOM.passphrase = $(".passphrase"); |
48 | DOM.generateContainer = $(".generate-container"); | 49 | DOM.generateContainer = $(".generate-container"); |
49 | DOM.generate = $(".generate"); | 50 | DOM.generate = $(".generate"); |
@@ -297,6 +298,7 @@ | |||
297 | clearDisplay(); | 298 | clearDisplay(); |
298 | clearEntropyFeedback(); | 299 | clearEntropyFeedback(); |
299 | DOM.phrase.val(""); | 300 | DOM.phrase.val(""); |
301 | DOM.phraseSplit.val(""); | ||
300 | showValidationError("Blank entropy"); | 302 | showValidationError("Blank entropy"); |
301 | return; | 303 | return; |
302 | } | 304 | } |
@@ -331,6 +333,7 @@ | |||
331 | showPending(); | 333 | showPending(); |
332 | // Clear existing mnemonic and passphrase | 334 | // Clear existing mnemonic and passphrase |
333 | DOM.phrase.val(""); | 335 | DOM.phrase.val(""); |
336 | DOM.phraseSplit.val(""); | ||
334 | DOM.passphrase.val(""); | 337 | DOM.passphrase.val(""); |
335 | seed = null; | 338 | seed = null; |
336 | if (rootKeyChangedTimeoutEvent != null) { | 339 | if (rootKeyChangedTimeoutEvent != null) { |
@@ -417,6 +420,7 @@ | |||
417 | if (DOM.phrase.val().length > 0) { | 420 | if (DOM.phrase.val().length > 0) { |
418 | var newPhrase = convertPhraseToNewLanguage(); | 421 | var newPhrase = convertPhraseToNewLanguage(); |
419 | DOM.phrase.val(newPhrase); | 422 | DOM.phrase.val(newPhrase); |
423 | writeSplitPhrase(newPhrase); | ||
420 | phraseChanged(); | 424 | phraseChanged(); |
421 | } | 425 | } |
422 | else { | 426 | else { |
@@ -477,6 +481,7 @@ | |||
477 | // show the words | 481 | // show the words |
478 | var words = mnemonic.toMnemonic(data); | 482 | var words = mnemonic.toMnemonic(data); |
479 | DOM.phrase.val(words); | 483 | DOM.phrase.val(words); |
484 | writeSplitPhrase(words); | ||
480 | // show the entropy | 485 | // show the entropy |
481 | var entropyHex = uint8ArrayToHex(data); | 486 | var entropyHex = uint8ArrayToHex(data); |
482 | DOM.entropy.val(entropyHex); | 487 | DOM.entropy.val(entropyHex); |
@@ -1250,6 +1255,28 @@ | |||
1250 | } | 1255 | } |
1251 | return phrase; | 1256 | return phrase; |
1252 | } | 1257 | } |
1258 | |||
1259 | function writeSplitPhrase(phrase) { | ||
1260 | var wordCount = phrase.split(/\s/g).length; //get number of words in phrase | ||
1261 | var left=[]; //initialize array of indexs | ||
1262 | for (var i=0;i<wordCount;i++) left.push(i); //add all indexs to array | ||
1263 | var group=[[],[],[]], //make array for 3 groups | ||
1264 | groupI=-1; //initialize group index | ||
1265 | var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647; //start seed at sudo random value based on hash of words | ||
1266 | while (left.length>0) { //while indexs left | ||
1267 | groupI=(groupI+1)%3; //get next group to insert index into | ||
1268 | seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use) | ||
1269 | var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group | ||
1270 | group[groupI].push(left[selected]); //add index to group | ||
1271 | left.splice(selected,1); //remove selected index | ||
1272 | } | ||
1273 | var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards | ||
1274 | for (var i=0;i<3;i++) { //go through each card | ||
1275 | for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX'; //erase words listed in the group | ||
1276 | cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]); //combine words on card back to string | ||
1277 | } | ||
1278 | DOM.splitPhrase.val(cards.join("\r\n")); //make words visible | ||
1279 | } | ||
1253 | 1280 | ||
1254 | function isUsingOwnEntropy() { | 1281 | function isUsingOwnEntropy() { |
1255 | return DOM.useEntropy.prop("checked"); | 1282 | return DOM.useEntropy.prop("checked"); |
@@ -1308,6 +1335,7 @@ | |||
1308 | var phrase = mnemonic.toMnemonic(entropyArr); | 1335 | var phrase = mnemonic.toMnemonic(entropyArr); |
1309 | // Set the mnemonic in the UI | 1336 | // Set the mnemonic in the UI |
1310 | DOM.phrase.val(phrase); | 1337 | DOM.phrase.val(phrase); |
1338 | writeSplitPhrase(phrase); | ||
1311 | // Show the word indexes | 1339 | // Show the word indexes |
1312 | showWordIndexes(); | 1340 | showWordIndexes(); |
1313 | // Show the checksum | 1341 | // Show the checksum |