aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/css/app.css4
-rw-r--r--src/index.html7
-rw-r--r--src/js/index.js60
-rw-r--r--src/js/jsbip39.js51
4 files changed, 105 insertions, 17 deletions
diff --git a/src/css/app.css b/src/css/app.css
index 576b7d7..c2a0294 100644
--- a/src/css/app.css
+++ b/src/css/app.css
@@ -31,6 +31,10 @@ body {
31.phrase { 31.phrase {
32 word-break: keep-all; 32 word-break: keep-all;
33} 33}
34.phraseSplitWarn {
35 text-align: right;
36 color: red;
37}
34.generate-container .strength { 38.generate-container .strength {
35 /* override mobile width from bootstrap */ 39 /* override mobile width from bootstrap */
36 width: auto!important; 40 width: auto!important;
diff --git a/src/index.html b/src/index.html
index 95fccc1..bfb2bc1 100644
--- a/src/index.html
+++ b/src/index.html
@@ -173,6 +173,13 @@
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 id="phraseSplitWarn" class="phraseSplitWarn"></div>
181 </div>
182 <div class="form-group">
176 <label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label> 183 <label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label>
177 <div class="col-sm-10"> 184 <div class="col-sm-10">
178 <textarea id="passphrase" class="passphrase private-data form-control" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea> 185 <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 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() {
diff --git a/src/js/jsbip39.js b/src/js/jsbip39.js
index 3230e3b..9a6e7ec 100644
--- a/src/js/jsbip39.js
+++ b/src/js/jsbip39.js
@@ -97,22 +97,10 @@ var Mnemonic = function(language) {
97 } 97 }
98 98
99 self.check = function(mnemonic) { 99 self.check = function(mnemonic) {
100 var mnemonic = self.splitWords(mnemonic); 100 var b = mnemonicToBinaryString(mnemonic);
101 if (mnemonic.length == 0 || mnemonic.length % 3 > 0) { 101 if (b === null) {
102 return false 102 return false;
103 }
104 // idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
105 var idx = [];
106 for (var i=0; i<mnemonic.length; i++) {
107 var word = mnemonic[i];
108 var wordIndex = wordlist.indexOf(word);
109 if (wordIndex == -1) {
110 return false;
111 }
112 var binaryIndex = zfill(wordIndex.toString(2), 11);
113 idx.push(binaryIndex);
114 } 103 }
115 var b = idx.join('');
116 var l = b.length; 104 var l = b.length;
117 //d = b[:l / 33 * 32] 105 //d = b[:l / 33 * 32]
118 //h = b[-l / 33:] 106 //h = b[-l / 33:]
@@ -128,6 +116,20 @@ var Mnemonic = function(language) {
128 return h == nh; 116 return h == nh;
129 } 117 }
130 118
119 self.toRawEntropyHex = function(mnemonic) {
120 var b = mnemonicToBinaryString(mnemonic);
121 if (b === null)
122 return null;
123 var d = b.substring(0, b.length / 33 * 32);
124 var nd = binaryStringToWordArray(d);
125
126 var h = "";
127 for (var i=0; i<nd.length; i++) {
128 h += ('0000000' + nd[i].toString(16)).slice(-8);
129 }
130 return h;
131 }
132
131 self.toSeed = function(mnemonic, passphrase) { 133 self.toSeed = function(mnemonic, passphrase) {
132 passphrase = passphrase || ''; 134 passphrase = passphrase || '';
133 mnemonic = self.joinWords(self.splitWords(mnemonic)); // removes duplicate blanks 135 mnemonic = self.joinWords(self.splitWords(mnemonic)); // removes duplicate blanks
@@ -200,6 +202,25 @@ var Mnemonic = function(language) {
200 return a; 202 return a;
201 } 203 }
202 204
205 function mnemonicToBinaryString(mnemonic) {
206 var mnemonic = self.splitWords(mnemonic);
207 if (mnemonic.length == 0 || mnemonic.length % 3 > 0) {
208 return null;
209 }
210 // idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
211 var idx = [];
212 for (var i=0; i<mnemonic.length; i++) {
213 var word = mnemonic[i];
214 var wordIndex = wordlist.indexOf(word);
215 if (wordIndex == -1) {
216 return null;
217 }
218 var binaryIndex = zfill(wordIndex.toString(2), 11);
219 idx.push(binaryIndex);
220 }
221 return idx.join('');
222 }
223
203 // Pad a numeric string on the left with zero digits until the given width 224 // Pad a numeric string on the left with zero digits until the given width
204 // is reached. 225 // is reached.
205 // Note this differs to the python implementation because it does not 226 // Note this differs to the python implementation because it does not