diff options
author | Ian Coleman <ian@iancoleman.io> | 2019-11-11 10:15:17 +1100 |
---|---|---|
committer | Ian Coleman <ian@iancoleman.io> | 2019-11-11 10:15:17 +1100 |
commit | 96ee8ab0a0e589c1fab745953909a031f79a3873 (patch) | |
tree | 2a7c706eafb0305f8450564af2c0e93a95df51b4 /src | |
parent | 659b06a7b8fac1ba723f0bf95e5d8f630619e2f2 (diff) | |
download | BIP39-96ee8ab0a0e589c1fab745953909a031f79a3873.tar.gz BIP39-96ee8ab0a0e589c1fab745953909a031f79a3873.tar.zst BIP39-96ee8ab0a0e589c1fab745953909a031f79a3873.zip |
Replace tabs with spaces as per rest of the file
Diffstat (limited to 'src')
-rw-r--r-- | src/js/index.js | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/src/js/index.js b/src/js/index.js index 9807449..edd70c5 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -45,8 +45,8 @@ | |||
45 | DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning"); | 45 | DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning"); |
46 | DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); | 46 | DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); |
47 | DOM.phrase = $(".phrase"); | 47 | DOM.phrase = $(".phrase"); |
48 | DOM.splitPhrase = $(".phraseSplit"); | 48 | DOM.splitPhrase = $(".phraseSplit"); |
49 | DOM.phraseSplitWarn = $(".phraseSplitWarn"); | 49 | DOM.phraseSplitWarn = $(".phraseSplitWarn"); |
50 | DOM.passphrase = $(".passphrase"); | 50 | DOM.passphrase = $(".passphrase"); |
51 | DOM.generateContainer = $(".generate-container"); | 51 | DOM.generateContainer = $(".generate-container"); |
52 | DOM.generate = $(".generate"); | 52 | DOM.generate = $(".generate"); |
@@ -310,7 +310,7 @@ | |||
310 | clearDisplay(); | 310 | clearDisplay(); |
311 | clearEntropyFeedback(); | 311 | clearEntropyFeedback(); |
312 | DOM.phrase.val(""); | 312 | DOM.phrase.val(""); |
313 | DOM.phraseSplit.val(""); | 313 | DOM.phraseSplit.val(""); |
314 | showValidationError("Blank entropy"); | 314 | showValidationError("Blank entropy"); |
315 | return; | 315 | return; |
316 | } | 316 | } |
@@ -345,7 +345,7 @@ | |||
345 | showPending(); | 345 | showPending(); |
346 | // Clear existing mnemonic and passphrase | 346 | // Clear existing mnemonic and passphrase |
347 | DOM.phrase.val(""); | 347 | DOM.phrase.val(""); |
348 | DOM.phraseSplit.val(""); | 348 | DOM.phraseSplit.val(""); |
349 | DOM.passphrase.val(""); | 349 | DOM.passphrase.val(""); |
350 | seed = null; | 350 | seed = null; |
351 | if (rootKeyChangedTimeoutEvent != null) { | 351 | if (rootKeyChangedTimeoutEvent != null) { |
@@ -432,7 +432,7 @@ | |||
432 | if (DOM.phrase.val().length > 0) { | 432 | if (DOM.phrase.val().length > 0) { |
433 | var newPhrase = convertPhraseToNewLanguage(); | 433 | var newPhrase = convertPhraseToNewLanguage(); |
434 | DOM.phrase.val(newPhrase); | 434 | DOM.phrase.val(newPhrase); |
435 | writeSplitPhrase(newPhrase); | 435 | writeSplitPhrase(newPhrase); |
436 | phraseChanged(); | 436 | phraseChanged(); |
437 | } | 437 | } |
438 | else { | 438 | else { |
@@ -493,7 +493,7 @@ | |||
493 | // show the words | 493 | // show the words |
494 | var words = mnemonic.toMnemonic(data); | 494 | var words = mnemonic.toMnemonic(data); |
495 | DOM.phrase.val(words); | 495 | DOM.phrase.val(words); |
496 | writeSplitPhrase(words); | 496 | writeSplitPhrase(words); |
497 | // show the entropy | 497 | // show the entropy |
498 | var entropyHex = uint8ArrayToHex(data); | 498 | var entropyHex = uint8ArrayToHex(data); |
499 | DOM.entropy.val(entropyHex); | 499 | DOM.entropy.val(entropyHex); |
@@ -1448,40 +1448,40 @@ | |||
1448 | } | 1448 | } |
1449 | return phrase; | 1449 | return phrase; |
1450 | } | 1450 | } |
1451 | 1451 | ||
1452 | function writeSplitPhrase(phrase) { | 1452 | function writeSplitPhrase(phrase) { |
1453 | var wordCount = phrase.split(/\s/g).length; //get number of words in phrase | 1453 | var wordCount = phrase.split(/\s/g).length; //get number of words in phrase |
1454 | var left=[]; //initialize array of indexs | 1454 | var left=[]; //initialize array of indexs |
1455 | for (var i=0;i<wordCount;i++) left.push(i); //add all indexs to array | 1455 | for (var i=0;i<wordCount;i++) left.push(i); //add all indexs to array |
1456 | var group=[[],[],[]], //make array for 3 groups | 1456 | var group=[[],[],[]], //make array for 3 groups |
1457 | groupI=-1; //initialize group index | 1457 | groupI=-1; //initialize group index |
1458 | var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647; //start seed at sudo random value based on hash of words | 1458 | var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647; //start seed at sudo random value based on hash of words |
1459 | while (left.length>0) { //while indexs left | 1459 | while (left.length>0) { //while indexs left |
1460 | groupI=(groupI+1)%3; //get next group to insert index into | 1460 | groupI=(groupI+1)%3; //get next group to insert index into |
1461 | seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use) | 1461 | seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use) |
1462 | var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group | 1462 | var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group |
1463 | group[groupI].push(left[selected]); //add index to group | 1463 | group[groupI].push(left[selected]); //add index to group |
1464 | left.splice(selected,1); //remove selected index | 1464 | left.splice(selected,1); //remove selected index |
1465 | } | 1465 | } |
1466 | var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards | 1466 | var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards |
1467 | for (var i=0;i<3;i++) { //go through each card | 1467 | for (var i=0;i<3;i++) { //go through each card |
1468 | for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX'; //erase words listed in the group | 1468 | for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX'; //erase words listed in the group |
1469 | cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]); //combine words on card back to string | 1469 | cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]); //combine words on card back to string |
1470 | } | 1470 | } |
1471 | DOM.splitPhrase.val(cards.join("\r\n")); //make words visible | 1471 | DOM.splitPhrase.val(cards.join("\r\n")); //make words visible |
1472 | var triesPerSecond=10000000000; //assumed number of tries per second | 1472 | var triesPerSecond=10000000000; //assumed number of tries per second |
1473 | var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond; //get number of bits of unknown data per card | 1473 | var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond; //get number of bits of unknown data per card |
1474 | if (hackTime<1) { | 1474 | if (hackTime<1) { |
1475 | hackTime="<1 second"; | 1475 | hackTime="<1 second"; |
1476 | } else if (hackTime<86400) { | 1476 | } else if (hackTime<86400) { |
1477 | hackTime=Math.floor(hackTime)+" seconds"; | 1477 | hackTime=Math.floor(hackTime)+" seconds"; |
1478 | } else if(hackTime<31557600) { | 1478 | } else if(hackTime<31557600) { |
1479 | hackTime=Math.floor(hackTime/86400)+" days"; | 1479 | hackTime=Math.floor(hackTime/86400)+" days"; |
1480 | } else { | 1480 | } else { |
1481 | hackTime=Math.floor(hackTime/31557600)+" years"; | 1481 | hackTime=Math.floor(hackTime/31557600)+" years"; |
1482 | } | 1482 | } |
1483 | DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime); | 1483 | DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime); |
1484 | } | 1484 | } |
1485 | 1485 | ||
1486 | function isUsingOwnEntropy() { | 1486 | function isUsingOwnEntropy() { |
1487 | return DOM.useEntropy.prop("checked"); | 1487 | return DOM.useEntropy.prop("checked"); |
@@ -1540,7 +1540,7 @@ | |||
1540 | var phrase = mnemonic.toMnemonic(entropyArr); | 1540 | var phrase = mnemonic.toMnemonic(entropyArr); |
1541 | // Set the mnemonic in the UI | 1541 | // Set the mnemonic in the UI |
1542 | DOM.phrase.val(phrase); | 1542 | DOM.phrase.val(phrase); |
1543 | writeSplitPhrase(phrase); | 1543 | writeSplitPhrase(phrase); |
1544 | // Show the word indexes | 1544 | // Show the word indexes |
1545 | showWordIndexes(); | 1545 | showWordIndexes(); |
1546 | // Show the checksum | 1546 | // Show the checksum |
@@ -1936,8 +1936,8 @@ | |||
1936 | network = bitcoinjs.bitcoin.networks.axe; | 1936 | network = bitcoinjs.bitcoin.networks.axe; |
1937 | setHdCoin(4242); | 1937 | setHdCoin(4242); |
1938 | }, | 1938 | }, |
1939 | }, | 1939 | }, |
1940 | { | 1940 | { |
1941 | name: "ANON - ANON", | 1941 | name: "ANON - ANON", |
1942 | onSelect: function() { | 1942 | onSelect: function() { |
1943 | network = bitcoinjs.bitcoin.networks.anon; | 1943 | network = bitcoinjs.bitcoin.networks.anon; |
@@ -1993,7 +1993,7 @@ | |||
1993 | setHdCoin(2941); | 1993 | setHdCoin(2941); |
1994 | }, | 1994 | }, |
1995 | }, | 1995 | }, |
1996 | { | 1996 | { |
1997 | name: "tBND - Blocknode Testnet", | 1997 | name: "tBND - Blocknode Testnet", |
1998 | onSelect: function() { | 1998 | onSelect: function() { |
1999 | network = bitcoinjs.bitcoin.networks.blocknode_testnet; | 1999 | network = bitcoinjs.bitcoin.networks.blocknode_testnet; |
@@ -2014,7 +2014,7 @@ | |||
2014 | setHdCoin(91); | 2014 | setHdCoin(91); |
2015 | }, | 2015 | }, |
2016 | }, | 2016 | }, |
2017 | { | 2017 | { |
2018 | name: "BST - BlockStamp", | 2018 | name: "BST - BlockStamp", |
2019 | onSelect: function() { | 2019 | onSelect: function() { |
2020 | network = bitcoinjs.bitcoin.networks.blockstamp; | 2020 | network = bitcoinjs.bitcoin.networks.blockstamp; |
@@ -2042,7 +2042,7 @@ | |||
2042 | setHdCoin(1); | 2042 | setHdCoin(1); |
2043 | }, | 2043 | }, |
2044 | }, | 2044 | }, |
2045 | { | 2045 | { |
2046 | name: "BITG - Bitcoin Green", | 2046 | name: "BITG - Bitcoin Green", |
2047 | onSelect: function() { | 2047 | onSelect: function() { |
2048 | network = bitcoinjs.bitcoin.networks.bitcoingreen; | 2048 | network = bitcoinjs.bitcoin.networks.bitcoingreen; |
@@ -2446,14 +2446,14 @@ | |||
2446 | setHdCoin(168); | 2446 | setHdCoin(168); |
2447 | }, | 2447 | }, |
2448 | }, | 2448 | }, |
2449 | { | 2449 | { |
2450 | name: "HUSH - Hush (Legacy)", | 2450 | name: "HUSH - Hush (Legacy)", |
2451 | onSelect: function() { | 2451 | onSelect: function() { |
2452 | network = bitcoinjs.bitcoin.networks.hush; | 2452 | network = bitcoinjs.bitcoin.networks.hush; |
2453 | setHdCoin(197); | 2453 | setHdCoin(197); |
2454 | }, | 2454 | }, |
2455 | }, | 2455 | }, |
2456 | { | 2456 | { |
2457 | name: "HUSH - Hush3", | 2457 | name: "HUSH - Hush3", |
2458 | onSelect: function() { | 2458 | onSelect: function() { |
2459 | network = bitcoinjs.bitcoin.networks.hush3; | 2459 | network = bitcoinjs.bitcoin.networks.hush3; |
@@ -2733,7 +2733,7 @@ | |||
2733 | setHdCoin(174); | 2733 | setHdCoin(174); |
2734 | }, | 2734 | }, |
2735 | }, | 2735 | }, |
2736 | { | 2736 | { |
2737 | name: "PHR - Phore", | 2737 | name: "PHR - Phore", |
2738 | onSelect: function() { | 2738 | onSelect: function() { |
2739 | network = bitcoinjs.bitcoin.networks.phore; | 2739 | network = bitcoinjs.bitcoin.networks.phore; |
@@ -2798,7 +2798,7 @@ | |||
2798 | setHdCoin(6); | 2798 | setHdCoin(6); |
2799 | }, | 2799 | }, |
2800 | }, | 2800 | }, |
2801 | { | 2801 | { |
2802 | name: "PRJ - ProjectCoin", | 2802 | name: "PRJ - ProjectCoin", |
2803 | onSelect: function() { | 2803 | onSelect: function() { |
2804 | network = bitcoinjs.bitcoin.networks.projectcoin; | 2804 | network = bitcoinjs.bitcoin.networks.projectcoin; |
@@ -2861,7 +2861,7 @@ | |||
2861 | setHdCoin(19165); | 2861 | setHdCoin(19165); |
2862 | }, | 2862 | }, |
2863 | }, | 2863 | }, |
2864 | { | 2864 | { |
2865 | name: "SLS - Salus", | 2865 | name: "SLS - Salus", |
2866 | onSelect: function() { | 2866 | onSelect: function() { |
2867 | network = bitcoinjs.bitcoin.networks.salus; | 2867 | network = bitcoinjs.bitcoin.networks.salus; |
@@ -3064,7 +3064,7 @@ | |||
3064 | setHdCoin(181); | 3064 | setHdCoin(181); |
3065 | }, | 3065 | }, |
3066 | }, | 3066 | }, |
3067 | { | 3067 | { |
3068 | name: "XAX - Artax", | 3068 | name: "XAX - Artax", |
3069 | onSelect: function() { | 3069 | onSelect: function() { |
3070 | network = bitcoinjs.bitcoin.networks.artax; | 3070 | network = bitcoinjs.bitcoin.networks.artax; |