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
-rw-r--r--src/js/segwit-parameters.js234
5 files changed, 339 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 c0b5847..2684c9f 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 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() {
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
diff --git a/src/js/segwit-parameters.js b/src/js/segwit-parameters.js
index 58c9f95..de4d634 100644
--- a/src/js/segwit-parameters.js
+++ b/src/js/segwit-parameters.js
@@ -263,6 +263,240 @@ bitcoinjs.bitcoin.networks.cpuchain.p2wpkhInP2sh = {
263 wif: 0x80, 263 wif: 0x80,
264}; 264};
265 265
266bitcoinjs.bitcoin.networks.monkeyproject.p2wpkh = {
267 baseNetwork: "monkeyproject",
268 messagePrefix: 'Monkey Signed Message:\n',
269 bech32: 'monkey',
270 bip32: {
271 public: 0x0488b21e,
272 private: 0x0488dde4
273 },
274 pubKeyHash: 0x33,
275 scriptHash: 0x1c,
276 wif: 0x37
277};
278
279bitcoinjs.bitcoin.networks.monkeyproject.p2wpkhInP2sh = {
280 baseNetwork: "monkeyproject",
281 messagePrefix: 'Monkey Signed Message:\n',
282 bech32: 'monkey',
283 bip32: {
284 public: 0x0488b21e,
285 private: 0x0488dde4
286 },
287 pubKeyHash: 0x33,
288 scriptHash: 0x1c,
289 wif: 0x37
290};
291
292bitcoinjs.bitcoin.networks.atom.p2wpkh = {
293 baseNetwork: "atom",
294 messagePrefix: '\x18Bitcoin Atom Signed Message:\n',
295 bech32: 'atom',
296 bip32: {
297 public: 0x0488B21E,
298 private: 0x0488ADE4
299 },
300 pubKeyHash: 0x17,
301 scriptHash: 0x0a,
302 wif: 0x80
303};
304
305bitcoinjs.bitcoin.networks.atom.p2wpkhInP2sh = {
306 baseNetwork: "atom",
307 messagePrefix: '\x18Bitcoin Atom Signed Message:\n',
308 bech32: 'atom',
309 bip32: {
310 public: 0x0488B21E,
311 private: 0x0488ADE4
312 },
313 pubKeyHash: 0x17,
314 scriptHash: 0x0a,
315 wif: 0x80
316};
317
318bitcoinjs.bitcoin.networks.bitcore.p2wpkh = {
319 baseNetwork: "bitcore",
320 messagePrefix: '\x18BitCore Signed Message:\n',
321 bech32: 'bitcore',
322 bip32: {
323 public: 0x0488B21E,
324 private: 0x0488ADE4
325 },
326 pubKeyHash: 0x03,
327 scriptHash: 0x7D,
328 wif: 0x80
329};
330
331bitcoinjs.bitcoin.networks.bitcore.p2wpkhInP2sh = {
332 baseNetwork: "bitcore",
333 messagePrefix: '\x18BitCore Signed Message:\n',
334 bech32: 'bitcore',
335 bip32: {
336 public: 0x0488B21E,
337 private: 0x0488ADE4
338 },
339 pubKeyHash: 0x03,
340 scriptHash: 0x7D,
341 wif: 0x80
342};
343
344bitcoinjs.bitcoin.networks.monacoin.p2wpkh = {
345 baseNetwork: "monacoin",
346 messagePrefix: '\x18Monacoin Signed Message:\n',
347 bech32: 'monacoin',
348 bip32: {
349 public: 0x0488b21e,
350 private: 0x0488ade4
351 },
352 pubKeyHash: 0x32,
353 scriptHash: 0x37,
354 wif: 0xb0
355};
356
357bitcoinjs.bitcoin.networks.monacoin.p2wpkhInP2sh = {
358 baseNetwork: "monacoin",
359 messagePrefix: '\x18Monacoin Signed Message:\n',
360 bech32: 'monacoin',
361 bip32: {
362 public: 0x0488b21e,
363 private: 0x0488ade4
364 },
365 pubKeyHash: 0x32,
366 scriptHash: 0x37,
367 wif: 0xb0
368};
369
370bitcoinjs.bitcoin.networks.syscoin.p2wpkh = {
371 baseNetwork: "syscoin",
372 messagePrefix: '\x18Syscoin Signed Message:\n',
373 bech32: 'sys',
374 bip32: {
375 public: 0x04b24746,
376 private: 0x04b2430c
377 },
378 pubKeyHash: 0x3f,
379 scriptHash: 0x05,
380 wif: 0x80
381};
382
383bitcoinjs.bitcoin.networks.syscoin.p2wpkhInP2sh = {
384 baseNetwork: "syscoin",
385 messagePrefix: '\x18Syscoin Signed Message:\n',
386 bech32: 'sys',
387 bip32: {
388 public: 0x049d7cb2,
389 private: 0x049d7878
390 },
391 pubKeyHash: 0x3f,
392 scriptHash: 0x05,
393 wif: 0x80
394};
395
396bitcoinjs.bitcoin.networks.viacoin.p2wpkh = {
397 baseNetwork: "viacoin",
398 messagePrefix: '\x18Viacoin Signed Message:\n',
399 bech32: 'viacoin',
400 bip32: {
401 public: 0x0488b21e,
402 private: 0x0488ade4
403 },
404 pubKeyHash: 0x47,
405 scriptHash: 0x21,
406 wif: 0xc7
407};
408
409bitcoinjs.bitcoin.networks.viacoin.p2wpkhInP2sh = {
410 baseNetwork: "viacoin",
411 messagePrefix: '\x18Viacoin Signed Message:\n',
412 bech32: 'viacoin',
413 bip32: {
414 public: 0x0488b21e,
415 private: 0x0488ade4
416 },
417 pubKeyHash: 0x47,
418 scriptHash: 0x21,
419 wif: 0xc7
420};
421
422bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkh = {
423 baseNetwork: "dogecointestnet",
424 messagePrefix: '\x19Dogecoin Signed Message:\n',
425 bech32: 'dogecointestnet',
426 bip32: {
427 public: 0x043587cf,
428 private: 0x04358394
429 },
430 pubKeyHash: 0x71,
431 scriptHash: 0xc4,
432 wif: 0xf1
433};
434
435bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkhInP2sh = {
436 baseNetwork: "dogecointestnet",
437 messagePrefix: '\x19Dogecoin Signed Message:\n',
438 bech32: 'dogecointestnet',
439 bip32: {
440 public: 0x043587cf,
441 private: 0x04358394
442 },
443 pubKeyHash: 0x71,
444 scriptHash: 0xc4,
445 wif: 0xf1
446};
447
448bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkh = {
449 baseNetwork: "dogecointestnet",
450 messagePrefix: '\x19Dogecoin Signed Message:\n',
451 bech32: 'dogecointestnet',
452 bip32: {
453 public: 0x043587cf,
454 private: 0x04358394
455 },
456 pubKeyHash: 0x71,
457 scriptHash: 0xc4,
458 wif: 0xf1
459};
460
461bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkhInP2sh = {
462 baseNetwork: "dogecointestnet",
463 messagePrefix: '\x19Dogecoin Signed Message:\n',
464 bech32: 'dogecointestnet',
465 bip32: {
466 public: 0x043587cf,
467 private: 0x04358394
468 },
469 pubKeyHash: 0x71,
470 scriptHash: 0xc4,
471 wif: 0xf1
472};
473
474bitcoinjs.bitcoin.networks.litecointestnet.p2wpkh = {
475 baseNetwork: "litecointestnet",
476 messagePrefix: '\x18Litecoin Signed Message:\n',
477 bech32: 'litecointestnet',
478 bip32: {
479 public: 0x043587cf,
480 private: 0x04358394
481 },
482 pubKeyHash: 0x6f,
483 scriptHash: 0xc4,
484 wif: 0xef
485};
486
487bitcoinjs.bitcoin.networks.litecointestnet.p2wpkhInP2sh = {
488 baseNetwork: "litecointestnet",
489 messagePrefix: '\x18Litecoin Signed Message:\n',
490 bech32: 'litecointestnet',
491 bip32: {
492 public: 0x043587cf,
493 private: 0x04358394
494 },
495 pubKeyHash: 0x6f,
496 scriptHash: 0xc4,
497 wif: 0xef
498};
499
266bitcoinjs.bitcoin.networks.groestlcoin.p2wpkh = { 500bitcoinjs.bitcoin.networks.groestlcoin.p2wpkh = {
267 baseNetwork: "groestlcoin", 501 baseNetwork: "groestlcoin",
268 messagePrefix: '\x19GroestlCoin Signed Message:\n', 502 messagePrefix: '\x19GroestlCoin Signed Message:\n',