aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriancoleman <1281387+iancoleman@users.noreply.github.com>2019-11-11 09:28:28 +1100
committerGitHub <noreply@github.com>2019-11-11 09:28:28 +1100
commitd0428a8d211dd5914c4c8547c69c75aca4cccfd6 (patch)
treeb0fbf9db522b149ac0fcce969ccaf83bf3391789 /src
parent3dbf117928bb17d58cc54fa1faa9354c014e665b (diff)
parentd9b5b5d0de33e97ae38330df860d7ff3867f7bb7 (diff)
downloadBIP39-d0428a8d211dd5914c4c8547c69c75aca4cccfd6.tar.gz
BIP39-d0428a8d211dd5914c4c8547c69c75aca4cccfd6.tar.zst
BIP39-d0428a8d211dd5914c4c8547c69c75aca4cccfd6.zip
Merge pull request #279 from mctrivia/master
Added Split Phrase Card Output
Diffstat (limited to 'src')
-rw-r--r--src/index.html6
-rw-r--r--src/js/index.js28
2 files changed, 34 insertions, 0 deletions
diff --git a/src/index.html b/src/index.html
index 95fccc1..8862904 100644
--- a/src/index.html
+++ b/src/index.html
@@ -173,6 +173,12 @@
173 </div> 173 </div>
174 </div> 174 </div>
175 <div class="form-group"> 175 <div class="form-group">
176 <label for="phrase" class="col-sm-2 control-label">BIP39 Split Mnemonic</label>
177 <div class="col-sm-10">
178 <textarea id="phraseSplit" class="phraseSplit private-data form-control" title="Only 2 of 3 cards needed to recover."></textarea>
179 </div>
180 </div>
181 <div class="form-group">
176 <label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label> 182 <label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label>
177 <div class="col-sm-10"> 183 <div class="col-sm-10">
178 <textarea id="passphrase" class="passphrase private-data form-control" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea> 184 <textarea id="passphrase" class="passphrase private-data form-control" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
diff --git a/src/js/index.js b/src/js/index.js
index da901f6..035a2b3 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");
@@ -304,6 +305,7 @@
304 clearDisplay(); 305 clearDisplay();
305 clearEntropyFeedback(); 306 clearEntropyFeedback();
306 DOM.phrase.val(""); 307 DOM.phrase.val("");
308 DOM.phraseSplit.val("");
307 showValidationError("Blank entropy"); 309 showValidationError("Blank entropy");
308 return; 310 return;
309 } 311 }
@@ -338,6 +340,7 @@
338 showPending(); 340 showPending();
339 // Clear existing mnemonic and passphrase 341 // Clear existing mnemonic and passphrase
340 DOM.phrase.val(""); 342 DOM.phrase.val("");
343 DOM.phraseSplit.val("");
341 DOM.passphrase.val(""); 344 DOM.passphrase.val("");
342 seed = null; 345 seed = null;
343 if (rootKeyChangedTimeoutEvent != null) { 346 if (rootKeyChangedTimeoutEvent != null) {
@@ -424,6 +427,7 @@
424 if (DOM.phrase.val().length > 0) { 427 if (DOM.phrase.val().length > 0) {
425 var newPhrase = convertPhraseToNewLanguage(); 428 var newPhrase = convertPhraseToNewLanguage();
426 DOM.phrase.val(newPhrase); 429 DOM.phrase.val(newPhrase);
430 writeSplitPhrase(newPhrase);
427 phraseChanged(); 431 phraseChanged();
428 } 432 }
429 else { 433 else {
@@ -484,6 +488,7 @@
484 // show the words 488 // show the words
485 var words = mnemonic.toMnemonic(data); 489 var words = mnemonic.toMnemonic(data);
486 DOM.phrase.val(words); 490 DOM.phrase.val(words);
491 writeSplitPhrase(words);
487 // show the entropy 492 // show the entropy
488 var entropyHex = uint8ArrayToHex(data); 493 var entropyHex = uint8ArrayToHex(data);
489 DOM.entropy.val(entropyHex); 494 DOM.entropy.val(entropyHex);
@@ -1422,6 +1427,28 @@
1422 } 1427 }
1423 return phrase; 1428 return phrase;
1424 } 1429 }
1430
1431 function writeSplitPhrase(phrase) {
1432 var wordCount = phrase.split(/\s/g).length; //get number of words in phrase
1433 var left=[]; //initialize array of indexs
1434 for (var i=0;i<wordCount;i++) left.push(i); //add all indexs to array
1435 var group=[[],[],[]], //make array for 3 groups
1436 groupI=-1; //initialize group index
1437 var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647; //start seed at sudo random value based on hash of words
1438 while (left.length>0) { //while indexs left
1439 groupI=(groupI+1)%3; //get next group to insert index into
1440 seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use)
1441 var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group
1442 group[groupI].push(left[selected]); //add index to group
1443 left.splice(selected,1); //remove selected index
1444 }
1445 var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards
1446 for (var i=0;i<3;i++) { //go through each card
1447 for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX'; //erase words listed in the group
1448 cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]); //combine words on card back to string
1449 }
1450 DOM.splitPhrase.val(cards.join("\r\n")); //make words visible
1451 }
1425 1452
1426 function isUsingOwnEntropy() { 1453 function isUsingOwnEntropy() {
1427 return DOM.useEntropy.prop("checked"); 1454 return DOM.useEntropy.prop("checked");
@@ -1480,6 +1507,7 @@
1480 var phrase = mnemonic.toMnemonic(entropyArr); 1507 var phrase = mnemonic.toMnemonic(entropyArr);
1481 // Set the mnemonic in the UI 1508 // Set the mnemonic in the UI
1482 DOM.phrase.val(phrase); 1509 DOM.phrase.val(phrase);
1510 writeSplitPhrase(phrase);
1483 // Show the word indexes 1511 // Show the word indexes
1484 showWordIndexes(); 1512 showWordIndexes();
1485 // Show the checksum 1513 // Show the checksum