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 f3302a6..dc10d59 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);
@@ -1010,6 +1023,7 @@
1010 // Ethereum values are different 1023 // Ethereum values are different
1011 if ((networks[DOM.network.val()].name == "ETH - Ethereum") 1024 if ((networks[DOM.network.val()].name == "ETH - Ethereum")
1012 || (networks[DOM.network.val()].name == "ETC - Ethereum Classic") 1025 || (networks[DOM.network.val()].name == "ETC - Ethereum Classic")
1026 || (networks[DOM.network.val()].name == "EWT - EnergyWeb")
1013 || (networks[DOM.network.val()].name == "PIRL - Pirl") 1027 || (networks[DOM.network.val()].name == "PIRL - Pirl")
1014 || (networks[DOM.network.val()].name == "MIX - MIX") 1028 || (networks[DOM.network.val()].name == "MIX - MIX")
1015 || (networks[DOM.network.val()].name == "MUSIC - Musicoin") 1029 || (networks[DOM.network.val()].name == "MUSIC - Musicoin")
@@ -1415,6 +1429,40 @@
1415 } 1429 }
1416 return phrase; 1430 return phrase;
1417 } 1431 }
1432
1433 function writeSplitPhrase(phrase) {
1434 var wordCount = phrase.split(/\s/g).length; //get number of words in phrase
1435 var left=[]; //initialize array of indexs
1436 for (var i=0;i<wordCount;i++) left.push(i); //add all indexs to array
1437 var group=[[],[],[]], //make array for 3 groups
1438 groupI=-1; //initialize group index
1439 var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647; //start seed at sudo random value based on hash of words
1440 while (left.length>0) { //while indexs left
1441 groupI=(groupI+1)%3; //get next group to insert index into
1442 seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use)
1443 var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group
1444 group[groupI].push(left[selected]); //add index to group
1445 left.splice(selected,1); //remove selected index
1446 }
1447 var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards
1448 for (var i=0;i<3;i++) { //go through each card
1449 for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX'; //erase words listed in the group
1450 cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]); //combine words on card back to string
1451 }
1452 DOM.splitPhrase.val(cards.join("\r\n")); //make words visible
1453 var triesPerSecond=10000000000; //assumed number of tries per second
1454 var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond; //get number of bits of unknown data per card
1455 if (hackTime<1) {
1456 hackTime="<1 second";
1457 } else if (hackTime<86400) {
1458 hackTime=Math.floor(hackTime)+" seconds";
1459 } else if(hackTime<31557600) {
1460 hackTime=Math.floor(hackTime/86400)+" days";
1461 } else {
1462 hackTime=Math.floor(hackTime/31557600)+" years";
1463 }
1464 DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime);
1465 }
1418 1466
1419 function isUsingOwnEntropy() { 1467 function isUsingOwnEntropy() {
1420 return DOM.useEntropy.prop("checked"); 1468 return DOM.useEntropy.prop("checked");
@@ -1473,6 +1521,7 @@
1473 var phrase = mnemonic.toMnemonic(entropyArr); 1521 var phrase = mnemonic.toMnemonic(entropyArr);
1474 // Set the mnemonic in the UI 1522 // Set the mnemonic in the UI
1475 DOM.phrase.val(phrase); 1523 DOM.phrase.val(phrase);
1524 writeSplitPhrase(phrase);
1476 // Show the word indexes 1525 // Show the word indexes
1477 showWordIndexes(); 1526 showWordIndexes();
1478 // Show the checksum 1527 // Show the checksum
@@ -2213,7 +2262,14 @@
2213 network = bitcoinjs.bitcoin.networks.bitcoin; 2262 network = bitcoinjs.bitcoin.networks.bitcoin;
2214 setHdCoin(60); 2263 setHdCoin(60);
2215 }, 2264 },
2216 }, 2265 },
2266 {
2267 name: "EWT - EnergyWeb",
2268 onSelect: function() {
2269 network = bitcoinjs.bitcoin.networks.bitcoin;
2270 setHdCoin(246);
2271 },
2272 },
2217 { 2273 {
2218 name: "EXCL - Exclusivecoin", 2274 name: "EXCL - Exclusivecoin",
2219 onSelect: function() { 2275 onSelect: function() {