aboutsummaryrefslogtreecommitdiff
path: root/src/js/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/index.js')
-rw-r--r--src/js/index.js60
1 files changed, 58 insertions, 2 deletions
diff --git a/src/js/index.js b/src/js/index.js
index 52fb3ff..9ace962 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -44,6 +44,8 @@
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");
48 DOM.phraseSplitWarn = $(".phraseSplitWarn");
47 DOM.passphrase = $(".passphrase"); 49 DOM.passphrase = $(".passphrase");
48 DOM.generateContainer = $(".generate-container"); 50 DOM.generateContainer = $(".generate-container");
49 DOM.generate = $(".generate"); 51 DOM.generate = $(".generate");
@@ -232,7 +234,14 @@
232 if (phraseChangeTimeoutEvent != null) { 234 if (phraseChangeTimeoutEvent != null) {
233 clearTimeout(phraseChangeTimeoutEvent); 235 clearTimeout(phraseChangeTimeoutEvent);
234 } 236 }
235 phraseChangeTimeoutEvent = setTimeout(phraseChanged, 400); 237 phraseChangeTimeoutEvent = setTimeout(function() {
238 phraseChanged();
239 var entropy = mnemonic.toRawEntropyHex(DOM.phrase.val());
240 if (entropy !== null) {
241 DOM.entropyMnemonicLength.val("raw");
242 DOM.entropy.val(entropy);
243 }
244 }, 400);
236 } 245 }
237 246
238 function phraseChanged() { 247 function phraseChanged() {
@@ -297,6 +306,7 @@
297 clearDisplay(); 306 clearDisplay();
298 clearEntropyFeedback(); 307 clearEntropyFeedback();
299 DOM.phrase.val(""); 308 DOM.phrase.val("");
309 DOM.phraseSplit.val("");
300 showValidationError("Blank entropy"); 310 showValidationError("Blank entropy");
301 return; 311 return;
302 } 312 }
@@ -331,6 +341,7 @@
331 showPending(); 341 showPending();
332 // Clear existing mnemonic and passphrase 342 // Clear existing mnemonic and passphrase
333 DOM.phrase.val(""); 343 DOM.phrase.val("");
344 DOM.phraseSplit.val("");
334 DOM.passphrase.val(""); 345 DOM.passphrase.val("");
335 seed = null; 346 seed = null;
336 if (rootKeyChangedTimeoutEvent != null) { 347 if (rootKeyChangedTimeoutEvent != null) {
@@ -417,6 +428,7 @@
417 if (DOM.phrase.val().length > 0) { 428 if (DOM.phrase.val().length > 0) {
418 var newPhrase = convertPhraseToNewLanguage(); 429 var newPhrase = convertPhraseToNewLanguage();
419 DOM.phrase.val(newPhrase); 430 DOM.phrase.val(newPhrase);
431 writeSplitPhrase(newPhrase);
420 phraseChanged(); 432 phraseChanged();
421 } 433 }
422 else { 434 else {
@@ -477,6 +489,7 @@
477 // show the words 489 // show the words
478 var words = mnemonic.toMnemonic(data); 490 var words = mnemonic.toMnemonic(data);
479 DOM.phrase.val(words); 491 DOM.phrase.val(words);
492 writeSplitPhrase(words);
480 // show the entropy 493 // show the entropy
481 var entropyHex = uint8ArrayToHex(data); 494 var entropyHex = uint8ArrayToHex(data);
482 DOM.entropy.val(entropyHex); 495 DOM.entropy.val(entropyHex);
@@ -1023,6 +1036,7 @@
1023 // Ethereum values are different 1036 // Ethereum values are different
1024 if ((networks[DOM.network.val()].name == "ETH - Ethereum") 1037 if ((networks[DOM.network.val()].name == "ETH - Ethereum")
1025 || (networks[DOM.network.val()].name == "ETC - Ethereum Classic") 1038 || (networks[DOM.network.val()].name == "ETC - Ethereum Classic")
1039 || (networks[DOM.network.val()].name == "EWT - EnergyWeb")
1026 || (networks[DOM.network.val()].name == "PIRL - Pirl") 1040 || (networks[DOM.network.val()].name == "PIRL - Pirl")
1027 || (networks[DOM.network.val()].name == "MIX - MIX") 1041 || (networks[DOM.network.val()].name == "MIX - MIX")
1028 || (networks[DOM.network.val()].name == "MUSIC - Musicoin") 1042 || (networks[DOM.network.val()].name == "MUSIC - Musicoin")
@@ -1441,6 +1455,40 @@
1441 } 1455 }
1442 return phrase; 1456 return phrase;
1443 } 1457 }
1458
1459 function writeSplitPhrase(phrase) {
1460 var wordCount = phrase.split(/\s/g).length; //get number of words in phrase
1461 var left=[]; //initialize array of indexs
1462 for (var i=0;i<wordCount;i++) left.push(i); //add all indexs to array
1463 var group=[[],[],[]], //make array for 3 groups
1464 groupI=-1; //initialize group index
1465 var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647; //start seed at sudo random value based on hash of words
1466 while (left.length>0) { //while indexs left
1467 groupI=(groupI+1)%3; //get next group to insert index into
1468 seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use)
1469 var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group
1470 group[groupI].push(left[selected]); //add index to group
1471 left.splice(selected,1); //remove selected index
1472 }
1473 var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards
1474 for (var i=0;i<3;i++) { //go through each card
1475 for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX'; //erase words listed in the group
1476 cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]); //combine words on card back to string
1477 }
1478 DOM.splitPhrase.val(cards.join("\r\n")); //make words visible
1479 var triesPerSecond=10000000000; //assumed number of tries per second
1480 var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond; //get number of bits of unknown data per card
1481 if (hackTime<1) {
1482 hackTime="<1 second";
1483 } else if (hackTime<86400) {
1484 hackTime=Math.floor(hackTime)+" seconds";
1485 } else if(hackTime<31557600) {
1486 hackTime=Math.floor(hackTime/86400)+" days";
1487 } else {
1488 hackTime=Math.floor(hackTime/31557600)+" years";
1489 }
1490 DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime);
1491 }
1444 1492
1445 function isUsingOwnEntropy() { 1493 function isUsingOwnEntropy() {
1446 return DOM.useEntropy.prop("checked"); 1494 return DOM.useEntropy.prop("checked");
@@ -1499,6 +1547,7 @@
1499 var phrase = mnemonic.toMnemonic(entropyArr); 1547 var phrase = mnemonic.toMnemonic(entropyArr);
1500 // Set the mnemonic in the UI 1548 // Set the mnemonic in the UI
1501 DOM.phrase.val(phrase); 1549 DOM.phrase.val(phrase);
1550 writeSplitPhrase(phrase);
1502 // Show the word indexes 1551 // Show the word indexes
1503 showWordIndexes(); 1552 showWordIndexes();
1504 // Show the checksum 1553 // Show the checksum
@@ -2246,7 +2295,14 @@
2246 network = bitcoinjs.bitcoin.networks.bitcoin; 2295 network = bitcoinjs.bitcoin.networks.bitcoin;
2247 setHdCoin(60); 2296 setHdCoin(60);
2248 }, 2297 },
2249 }, 2298 },
2299 {
2300 name: "EWT - EnergyWeb",
2301 onSelect: function() {
2302 network = bitcoinjs.bitcoin.networks.bitcoin;
2303 setHdCoin(246);
2304 },
2305 },
2250 { 2306 {
2251 name: "EXCL - Exclusivecoin", 2307 name: "EXCL - Exclusivecoin",
2252 onSelect: function() { 2308 onSelect: function() {