]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - src/js/index.js
c9e7b44aa02a228cac4d5786ca5d0dad7a53f22b
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / src / js / index.js
1 (function() {
2
3 // mnemonics is populated as required by getLanguage
4 var mnemonics = { "english": new Mnemonic("english") };
5 var mnemonic = mnemonics["english"];
6 var seed = null;
7 var bip32RootKey = null;
8 var bip32ExtendedKey = null;
9 var network = bitcoinjs.bitcoin.networks.bitcoin;
10 var addressRowTemplate = $("#address-row-template");
11
12 var showIndex = true;
13 var showAddress = true;
14 var showPubKey = true;
15 var showPrivKey = true;
16 var showQr = false;
17 var litecoinUseLtub = true;
18
19 var entropyTypeAutoDetect = true;
20 var entropyChangeTimeoutEvent = null;
21 var phraseChangeTimeoutEvent = null;
22 var rootKeyChangedTimeoutEvent = null;
23
24 var generationProcesses = [];
25
26 var DOM = {};
27 DOM.privacyScreenToggle = $(".privacy-screen-toggle");
28 DOM.network = $(".network");
29 DOM.bip32Client = $("#bip32-client");
30 DOM.phraseNetwork = $("#network-phrase");
31 DOM.useEntropy = $(".use-entropy");
32 DOM.entropyContainer = $(".entropy-container");
33 DOM.entropy = $(".entropy");
34 DOM.entropyFiltered = DOM.entropyContainer.find(".filtered");
35 DOM.entropyType = DOM.entropyContainer.find(".type");
36 DOM.entropyTypeInputs = DOM.entropyContainer.find("input[name='entropy-type']");
37 DOM.entropyCrackTime = DOM.entropyContainer.find(".crack-time");
38 DOM.entropyEventCount = DOM.entropyContainer.find(".event-count");
39 DOM.entropyBits = DOM.entropyContainer.find(".bits");
40 DOM.entropyBitsPerEvent = DOM.entropyContainer.find(".bits-per-event");
41 DOM.entropyWordCount = DOM.entropyContainer.find(".word-count");
42 DOM.entropyBinary = DOM.entropyContainer.find(".binary");
43 DOM.entropyWordIndexes = DOM.entropyContainer.find(".word-indexes");
44 DOM.entropyChecksum = DOM.entropyContainer.find(".checksum");
45 DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length");
46 DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning");
47 DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
48 DOM.phrase = $(".phrase");
49 DOM.phraseSplit = $(".phraseSplit");
50 DOM.phraseSplitWarn = $(".phraseSplitWarn");
51 DOM.passphrase = $(".passphrase");
52 DOM.generateContainer = $(".generate-container");
53 DOM.generate = $(".generate");
54 DOM.seed = $(".seed");
55 DOM.rootKey = $(".root-key");
56 DOM.litecoinLtubContainer = $(".litecoin-ltub-container");
57 DOM.litecoinUseLtub = $(".litecoin-use-ltub");
58 DOM.extendedPrivKey = $(".extended-priv-key");
59 DOM.extendedPubKey = $(".extended-pub-key");
60 DOM.bip32tab = $("#bip32-tab");
61 DOM.bip44tab = $("#bip44-tab");
62 DOM.bip49tab = $("#bip49-tab");
63 DOM.bip84tab = $("#bip84-tab");
64 DOM.bip141tab = $("#bip141-tab");
65 DOM.bip32panel = $("#bip32");
66 DOM.bip44panel = $("#bip44");
67 DOM.bip49panel = $("#bip49");
68 DOM.bip32path = $("#bip32-path");
69 DOM.bip44path = $("#bip44-path");
70 DOM.bip44purpose = $("#bip44 .purpose");
71 DOM.bip44coin = $("#bip44 .coin");
72 DOM.bip44account = $("#bip44 .account");
73 DOM.bip44accountXprv = $("#bip44 .account-xprv");
74 DOM.bip44accountXpub = $("#bip44 .account-xpub");
75 DOM.bip44change = $("#bip44 .change");
76 DOM.bip49unavailable = $("#bip49 .unavailable");
77 DOM.bip49available = $("#bip49 .available");
78 DOM.bip49path = $("#bip49-path");
79 DOM.bip49purpose = $("#bip49 .purpose");
80 DOM.bip49coin = $("#bip49 .coin");
81 DOM.bip49account = $("#bip49 .account");
82 DOM.bip49accountXprv = $("#bip49 .account-xprv");
83 DOM.bip49accountXpub = $("#bip49 .account-xpub");
84 DOM.bip49change = $("#bip49 .change");
85 DOM.bip84unavailable = $("#bip84 .unavailable");
86 DOM.bip84available = $("#bip84 .available");
87 DOM.bip84path = $("#bip84-path");
88 DOM.bip84purpose = $("#bip84 .purpose");
89 DOM.bip84coin = $("#bip84 .coin");
90 DOM.bip84account = $("#bip84 .account");
91 DOM.bip84accountXprv = $("#bip84 .account-xprv");
92 DOM.bip84accountXpub = $("#bip84 .account-xpub");
93 DOM.bip84change = $("#bip84 .change");
94 DOM.bip141unavailable = $("#bip141 .unavailable");
95 DOM.bip141available = $("#bip141 .available");
96 DOM.bip141path = $("#bip141-path");
97 DOM.bip141semantics = $(".bip141-semantics");
98 DOM.generatedStrength = $(".generate-container .strength");
99 DOM.generatedStrengthWarning = $(".generate-container .warning");
100 DOM.hardenedAddresses = $(".hardened-addresses");
101 DOM.bitcoinCashAddressTypeContainer = $(".bch-addr-type-container");
102 DOM.bitcoinCashAddressType = $("[name=bch-addr-type]")
103 DOM.useBip38 = $(".use-bip38");
104 DOM.bip38Password = $(".bip38-password");
105 DOM.addresses = $(".addresses");
106 DOM.csvTab = $("#csv-tab a");
107 DOM.csv = $(".csv");
108 DOM.rowsToAdd = $(".rows-to-add");
109 DOM.more = $(".more");
110 DOM.moreRowsStartIndex = $(".more-rows-start-index");
111 DOM.feedback = $(".feedback");
112 DOM.tab = $(".derivation-type a");
113 DOM.indexToggle = $(".index-toggle");
114 DOM.addressToggle = $(".address-toggle");
115 DOM.publicKeyToggle = $(".public-key-toggle");
116 DOM.privateKeyToggle = $(".private-key-toggle");
117 DOM.languages = $(".languages a");
118 DOM.qrContainer = $(".qr-container");
119 DOM.qrHider = DOM.qrContainer.find(".qr-hider");
120 DOM.qrImage = DOM.qrContainer.find(".qr-image");
121 DOM.qrHint = DOM.qrContainer.find(".qr-hint");
122 DOM.showQrEls = $("[data-show-qr]");
123
124 function init() {
125 // Events
126 DOM.privacyScreenToggle.on("change", privacyScreenToggled);
127 DOM.generatedStrength.on("change", generatedStrengthChanged);
128 DOM.network.on("change", networkChanged);
129 DOM.bip32Client.on("change", bip32ClientChanged);
130 DOM.useEntropy.on("change", setEntropyVisibility);
131 DOM.entropy.on("input", delayedEntropyChanged);
132 DOM.entropyMnemonicLength.on("change", entropyChanged);
133 DOM.entropyTypeInputs.on("change", entropyTypeChanged);
134 DOM.phrase.on("input", delayedPhraseChanged);
135 DOM.passphrase.on("input", delayedPhraseChanged);
136 DOM.generate.on("click", generateClicked);
137 DOM.more.on("click", showMore);
138 DOM.rootKey.on("input", delayedRootKeyChanged);
139 DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged);
140 DOM.bip32path.on("input", calcForDerivationPath);
141 DOM.bip44account.on("input", calcForDerivationPath);
142 DOM.bip44change.on("input", calcForDerivationPath);
143 DOM.bip49account.on("input", calcForDerivationPath);
144 DOM.bip49change.on("input", calcForDerivationPath);
145 DOM.bip84account.on("input", calcForDerivationPath);
146 DOM.bip84change.on("input", calcForDerivationPath);
147 DOM.bip141path.on("input", calcForDerivationPath);
148 DOM.bip141semantics.on("change", tabChanged);
149 DOM.tab.on("shown.bs.tab", tabChanged);
150 DOM.hardenedAddresses.on("change", calcForDerivationPath);
151 DOM.useBip38.on("change", calcForDerivationPath);
152 DOM.bip38Password.on("change", calcForDerivationPath);
153 DOM.indexToggle.on("click", toggleIndexes);
154 DOM.addressToggle.on("click", toggleAddresses);
155 DOM.publicKeyToggle.on("click", togglePublicKeys);
156 DOM.privateKeyToggle.on("click", togglePrivateKeys);
157 DOM.csvTab.on("click", updateCsv);
158 DOM.languages.on("click", languageChanged);
159 DOM.bitcoinCashAddressType.on("change", bitcoinCashAddressTypeChange);
160 setQrEvents(DOM.showQrEls);
161 disableForms();
162 hidePending();
163 hideValidationError();
164 populateNetworkSelect();
165 populateClientSelect();
166 }
167
168 // Event handlers
169
170 function generatedStrengthChanged() {
171 var strength = parseInt(DOM.generatedStrength.val());
172 if (strength < 12) {
173 DOM.generatedStrengthWarning.removeClass("hidden");
174 }
175 else {
176 DOM.generatedStrengthWarning.addClass("hidden");
177 }
178 }
179
180 function networkChanged(e) {
181 clearDerivedKeys();
182 clearAddressesList();
183 DOM.litecoinLtubContainer.addClass("hidden");
184 DOM.bitcoinCashAddressTypeContainer.addClass("hidden");
185 var networkIndex = e.target.value;
186 var network = networks[networkIndex];
187 network.onSelect();
188 adjustNetworkForSegwit();
189 if (seed != null) {
190 phraseChanged();
191 }
192 else {
193 rootKeyChanged();
194 }
195 }
196
197 function bip32ClientChanged(e) {
198 var clientIndex = DOM.bip32Client.val();
199 if (clientIndex == "custom") {
200 DOM.bip32path.prop("readonly", false);
201 }
202 else {
203 DOM.bip32path.prop("readonly", true);
204 clients[clientIndex].onSelect();
205 if (seed != null) {
206 phraseChanged();
207 }
208 else {
209 rootKeyChanged();
210 }
211 }
212 }
213
214 function setEntropyVisibility() {
215 if (isUsingOwnEntropy()) {
216 DOM.entropyContainer.removeClass("hidden");
217 DOM.generateContainer.addClass("hidden");
218 DOM.phrase.prop("readonly", true);
219 DOM.entropy.focus();
220 entropyChanged();
221 }
222 else {
223 DOM.entropyContainer.addClass("hidden");
224 DOM.generateContainer.removeClass("hidden");
225 DOM.phrase.prop("readonly", false);
226 hidePending();
227 }
228 }
229
230 function delayedPhraseChanged() {
231 hideValidationError();
232 seed = null;
233 bip32RootKey = null;
234 bip32ExtendedKey = null;
235 clearAddressesList();
236 showPending();
237 if (phraseChangeTimeoutEvent != null) {
238 clearTimeout(phraseChangeTimeoutEvent);
239 }
240 phraseChangeTimeoutEvent = setTimeout(function() {
241 phraseChanged();
242 var entropy = mnemonic.toRawEntropyHex(DOM.phrase.val());
243 if (entropy !== null) {
244 DOM.entropyMnemonicLength.val("raw");
245 DOM.entropy.val(entropy);
246 DOM.entropyTypeInputs.filter("[value='hexadecimal']").prop("checked", true);
247 entropyTypeAutoDetect = false;
248 }
249 }, 400);
250 }
251
252 function phraseChanged() {
253 showPending();
254 setMnemonicLanguage();
255 // Get the mnemonic phrase
256 var phrase = DOM.phrase.val();
257 var errorText = findPhraseErrors(phrase);
258 if (errorText) {
259 showValidationError(errorText);
260 return;
261 }
262 // Calculate and display
263 var passphrase = DOM.passphrase.val();
264 calcBip32RootKeyFromSeed(phrase, passphrase);
265 calcForDerivationPath();
266 // Show the word indexes
267 showWordIndexes();
268 writeSplitPhrase(phrase);
269 }
270
271 function tabChanged() {
272 showPending();
273 adjustNetworkForSegwit();
274 var phrase = DOM.phrase.val();
275 if (phrase != "") {
276 // Calculate and display for mnemonic
277 var errorText = findPhraseErrors(phrase);
278 if (errorText) {
279 showValidationError(errorText);
280 return;
281 }
282 // Calculate and display
283 var passphrase = DOM.passphrase.val();
284 calcBip32RootKeyFromSeed(phrase, passphrase);
285 }
286 else {
287 // Calculate and display for root key
288 var rootKeyBase58 = DOM.rootKey.val();
289 var errorText = validateRootKey(rootKeyBase58);
290 if (errorText) {
291 showValidationError(errorText);
292 return;
293 }
294 // Calculate and display
295 calcBip32RootKeyFromBase58(rootKeyBase58);
296 }
297 calcForDerivationPath();
298 }
299
300 function delayedEntropyChanged() {
301 hideValidationError();
302 showPending();
303 if (entropyChangeTimeoutEvent != null) {
304 clearTimeout(entropyChangeTimeoutEvent);
305 }
306 entropyChangeTimeoutEvent = setTimeout(entropyChanged, 400);
307 }
308
309 function entropyChanged() {
310 // If blank entropy, clear mnemonic, addresses, errors
311 if (DOM.entropy.val().trim().length == 0) {
312 clearDisplay();
313 clearEntropyFeedback();
314 DOM.phrase.val("");
315 DOM.phraseSplit.val("");
316 showValidationError("Blank entropy");
317 return;
318 }
319 // Get the current phrase to detect changes
320 var phrase = DOM.phrase.val();
321 // Set the phrase from the entropy
322 setMnemonicFromEntropy();
323 // Recalc addresses if the phrase has changed
324 var newPhrase = DOM.phrase.val();
325 if (newPhrase != phrase) {
326 if (newPhrase.length == 0) {
327 clearDisplay();
328 }
329 else {
330 phraseChanged();
331 }
332 }
333 else {
334 hidePending();
335 }
336 }
337
338 function entropyTypeChanged() {
339 entropyTypeAutoDetect = false;
340 entropyChanged();
341 }
342
343 function delayedRootKeyChanged() {
344 // Warn if there is an existing mnemonic or passphrase.
345 if (DOM.phrase.val().length > 0 || DOM.passphrase.val().length > 0) {
346 if (!confirm("This will clear existing mnemonic and passphrase")) {
347 DOM.rootKey.val(bip32RootKey);
348 return
349 }
350 }
351 hideValidationError();
352 showPending();
353 // Clear existing mnemonic and passphrase
354 DOM.phrase.val("");
355 DOM.phraseSplit.val("");
356 DOM.passphrase.val("");
357 seed = null;
358 if (rootKeyChangedTimeoutEvent != null) {
359 clearTimeout(rootKeyChangedTimeoutEvent);
360 }
361 rootKeyChangedTimeoutEvent = setTimeout(rootKeyChanged, 400);
362 }
363
364 function rootKeyChanged() {
365 showPending();
366 hideValidationError();
367 var rootKeyBase58 = DOM.rootKey.val();
368 var errorText = validateRootKey(rootKeyBase58);
369 if (errorText) {
370 showValidationError(errorText);
371 return;
372 }
373 // Calculate and display
374 calcBip32RootKeyFromBase58(rootKeyBase58);
375 calcForDerivationPath();
376 }
377
378 function litecoinUseLtubChanged() {
379 litecoinUseLtub = DOM.litecoinUseLtub.prop("checked");
380 if (litecoinUseLtub) {
381 network = bitcoinjs.bitcoin.networks.litecoin;
382 }
383 else {
384 network = bitcoinjs.bitcoin.networks.litecoinXprv;
385 }
386 phraseChanged();
387 }
388
389 function calcForDerivationPath() {
390 clearDerivedKeys();
391 clearAddressesList();
392 showPending();
393 // Don't show segwit if it's selected but network doesn't support it
394 if (segwitSelected() && !networkHasSegwit()) {
395 showSegwitUnavailable();
396 hidePending();
397 return;
398 }
399 showSegwitAvailable();
400 // Get the derivation path
401 var derivationPath = getDerivationPath();
402 var errorText = findDerivationPathErrors(derivationPath);
403 if (errorText) {
404 showValidationError(errorText);
405 return;
406 }
407 bip32ExtendedKey = calcBip32ExtendedKey(derivationPath);
408 if (bip44TabSelected()) {
409 displayBip44Info();
410 }
411 else if (bip49TabSelected()) {
412 displayBip49Info();
413 }
414 else if (bip84TabSelected()) {
415 displayBip84Info();
416 }
417 displayBip32Info();
418 }
419
420 function generateClicked() {
421 if (isUsingOwnEntropy()) {
422 return;
423 }
424 clearDisplay();
425 showPending();
426 setTimeout(function() {
427 setMnemonicLanguage();
428 var phrase = generateRandomPhrase();
429 if (!phrase) {
430 return;
431 }
432 phraseChanged();
433 }, 50);
434 }
435
436 function languageChanged() {
437 setTimeout(function() {
438 setMnemonicLanguage();
439 if (DOM.phrase.val().length > 0) {
440 var newPhrase = convertPhraseToNewLanguage();
441 DOM.phrase.val(newPhrase);
442 phraseChanged();
443 }
444 else {
445 DOM.generate.trigger("click");
446 }
447 }, 50);
448 }
449
450 function bitcoinCashAddressTypeChange() {
451 phraseChanged();
452 }
453
454 function toggleIndexes() {
455 showIndex = !showIndex;
456 $("td.index span").toggleClass("invisible");
457 }
458
459 function toggleAddresses() {
460 showAddress = !showAddress;
461 $("td.address span").toggleClass("invisible");
462 }
463
464 function togglePublicKeys() {
465 showPubKey = !showPubKey;
466 $("td.pubkey span").toggleClass("invisible");
467 }
468
469 function togglePrivateKeys() {
470 showPrivKey = !showPrivKey;
471 $("td.privkey span").toggleClass("invisible");
472 }
473
474 function privacyScreenToggled() {
475 // private-data contains elements added to DOM at runtime
476 // so catch all by adding visual privacy class to the root of the DOM
477 if (DOM.privacyScreenToggle.prop("checked")) {
478 $("body").addClass("visual-privacy");
479 }
480 else {
481 $("body").removeClass("visual-privacy");
482 }
483 }
484
485 // Private methods
486
487 function generateRandomPhrase() {
488 if (!hasStrongRandom()) {
489 var errorText = "This browser does not support strong randomness";
490 showValidationError(errorText);
491 return;
492 }
493 // get the amount of entropy to use
494 var numWords = parseInt(DOM.generatedStrength.val());
495 var strength = numWords / 3 * 32;
496 var buffer = new Uint8Array(strength / 8);
497 // create secure entropy
498 var data = crypto.getRandomValues(buffer);
499 // show the words
500 var words = mnemonic.toMnemonic(data);
501 DOM.phrase.val(words);
502 // show the entropy
503 var entropyHex = uint8ArrayToHex(data);
504 DOM.entropy.val(entropyHex);
505 // ensure entropy fields are consistent with what is being displayed
506 DOM.entropyMnemonicLength.val("raw");
507 return words;
508 }
509
510 function calcBip32RootKeyFromSeed(phrase, passphrase) {
511 seed = mnemonic.toSeed(phrase, passphrase);
512 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network);
513 if(isGRS())
514 bip32RootKey = groestlcoinjs.HDNode.fromSeedHex(seed, network);
515
516 }
517
518 function calcBip32RootKeyFromBase58(rootKeyBase58) {
519 if(isGRS()) {
520 calcBip32RootKeyFromBase58GRS(rootKeyBase58);
521 return;
522 }
523 // try parsing with various segwit network params since this extended
524 // key may be from any one of them.
525 if (networkHasSegwit()) {
526 var n = network;
527 if ("baseNetwork" in n) {
528 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
529 }
530 // try parsing using base network params
531 try {
532 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n);
533 return;
534 }
535 catch (e) {}
536 // try parsing using p2wpkh params
537 if ("p2wpkh" in n) {
538 try {
539 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
540 return;
541 }
542 catch (e) {}
543 }
544 // try parsing using p2wpkh-in-p2sh network params
545 if ("p2wpkhInP2sh" in n) {
546 try {
547 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
548 return;
549 }
550 catch (e) {}
551 }
552 // try parsing using p2wsh network params
553 if ("p2wsh" in n) {
554 try {
555 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wsh);
556 return;
557 }
558 catch (e) {}
559 }
560 // try parsing using p2wsh-in-p2sh network params
561 if ("p2wshInP2sh" in n) {
562 try {
563 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wshInP2sh);
564 return;
565 }
566 catch (e) {}
567 }
568 }
569 // try the network params as currently specified
570 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
571 }
572
573 function calcBip32RootKeyFromBase58GRS(rootKeyBase58) {
574 // try parsing with various segwit network params since this extended
575 // key may be from any one of them.
576 if (networkHasSegwit()) {
577 var n = network;
578 if ("baseNetwork" in n) {
579 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
580 }
581 // try parsing using base network params
582 try {
583 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n);
584 return;
585 }
586 catch (e) {}
587 // try parsing using p2wpkh params
588 if ("p2wpkh" in n) {
589 try {
590 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
591 return;
592 }
593 catch (e) {}
594 }
595 // try parsing using p2wpkh-in-p2sh network params
596 if ("p2wpkhInP2sh" in n) {
597 try {
598 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
599 return;
600 }
601 catch (e) {}
602 }
603 }
604 // try the network params as currently specified
605 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network);
606 }
607
608 function calcBip32ExtendedKey(path) {
609 // Check there's a root key to derive from
610 if (!bip32RootKey) {
611 return bip32RootKey;
612 }
613 var extendedKey = bip32RootKey;
614 // Derive the key from the path
615 var pathBits = path.split("/");
616 for (var i=0; i<pathBits.length; i++) {
617 var bit = pathBits[i];
618 var index = parseInt(bit);
619 if (isNaN(index)) {
620 continue;
621 }
622 var hardened = bit[bit.length-1] == "'";
623 var isPriv = !(extendedKey.isNeutered());
624 var invalidDerivationPath = hardened && !isPriv;
625 if (invalidDerivationPath) {
626 extendedKey = null;
627 }
628 else if (hardened) {
629 extendedKey = extendedKey.deriveHardened(index);
630 }
631 else {
632 extendedKey = extendedKey.derive(index);
633 }
634 }
635 return extendedKey;
636 }
637
638 function showValidationError(errorText) {
639 DOM.feedback
640 .text(errorText)
641 .show();
642 }
643
644 function hideValidationError() {
645 DOM.feedback
646 .text("")
647 .hide();
648 }
649
650 function findPhraseErrors(phrase) {
651 // Preprocess the words
652 phrase = mnemonic.normalizeString(phrase);
653 var words = phraseToWordArray(phrase);
654 // Detect blank phrase
655 if (words.length == 0) {
656 return "Blank mnemonic";
657 }
658 // Check each word
659 for (var i=0; i<words.length; i++) {
660 var word = words[i];
661 var language = getLanguage();
662 if (WORDLISTS[language].indexOf(word) == -1) {
663 console.log("Finding closest match to " + word);
664 var nearestWord = findNearestWord(word);
665 return word + " not in wordlist, did you mean " + nearestWord + "?";
666 }
667 }
668 // Check the words are valid
669 var properPhrase = wordArrayToPhrase(words);
670 var isValid = mnemonic.check(properPhrase);
671 if (!isValid) {
672 return "Invalid mnemonic";
673 }
674 return false;
675 }
676
677 function validateRootKey(rootKeyBase58) {
678 if(isGRS())
679 return validateRootKeyGRS(rootKeyBase58);
680
681 // try various segwit network params since this extended key may be from
682 // any one of them.
683 if (networkHasSegwit()) {
684 var n = network;
685 if ("baseNetwork" in n) {
686 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
687 }
688 // try parsing using base network params
689 try {
690 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n);
691 return "";
692 }
693 catch (e) {}
694 // try parsing using p2wpkh params
695 if ("p2wpkh" in n) {
696 try {
697 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
698 return "";
699 }
700 catch (e) {}
701 }
702 // try parsing using p2wpkh-in-p2sh network params
703 if ("p2wpkhInP2sh" in n) {
704 try {
705 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
706 return "";
707 }
708 catch (e) {}
709 }
710 // try parsing using p2wsh network params
711 if ("p2wsh" in n) {
712 try {
713 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wsh);
714 return "";
715 }
716 catch (e) {}
717 }
718 // try parsing using p2wsh-in-p2sh network params
719 if ("p2wshInP2sh" in n) {
720 try {
721 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wshInP2sh);
722 return "";
723 }
724 catch (e) {}
725 }
726 }
727 // try the network params as currently specified
728 try {
729 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
730 }
731 catch (e) {
732 return "Invalid root key";
733 }
734 return "";
735 }
736
737 function validateRootKeyGRS(rootKeyBase58) {
738 // try various segwit network params since this extended key may be from
739 // any one of them.
740 if (networkHasSegwit()) {
741 var n = network;
742 if ("baseNetwork" in n) {
743 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
744 }
745 // try parsing using base network params
746 try {
747 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n);
748 return "";
749 }
750 catch (e) {}
751 // try parsing using p2wpkh params
752 if ("p2wpkh" in n) {
753 try {
754 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
755 return "";
756 }
757 catch (e) {}
758 }
759 // try parsing using p2wpkh-in-p2sh network params
760 if ("p2wpkhInP2sh" in n) {
761 try {
762 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
763 return "";
764 }
765 catch (e) {}
766 }
767 }
768 // try the network params as currently specified
769 try {
770 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network);
771 }
772 catch (e) {
773 return "Invalid root key";
774 }
775 return "";
776 }
777
778 function getDerivationPath() {
779 if (bip44TabSelected()) {
780 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
781 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
782 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
783 var change = parseIntNoNaN(DOM.bip44change.val(), 0);
784 var path = "m/";
785 path += purpose + "'/";
786 path += coin + "'/";
787 path += account + "'/";
788 path += change;
789 DOM.bip44path.val(path);
790 var derivationPath = DOM.bip44path.val();
791 console.log("Using derivation path from BIP44 tab: " + derivationPath);
792 return derivationPath;
793 }
794 else if (bip49TabSelected()) {
795 var purpose = parseIntNoNaN(DOM.bip49purpose.val(), 49);
796 var coin = parseIntNoNaN(DOM.bip49coin.val(), 0);
797 var account = parseIntNoNaN(DOM.bip49account.val(), 0);
798 var change = parseIntNoNaN(DOM.bip49change.val(), 0);
799 var path = "m/";
800 path += purpose + "'/";
801 path += coin + "'/";
802 path += account + "'/";
803 path += change;
804 DOM.bip49path.val(path);
805 var derivationPath = DOM.bip49path.val();
806 console.log("Using derivation path from BIP49 tab: " + derivationPath);
807 return derivationPath;
808 }
809 else if (bip84TabSelected()) {
810 var purpose = parseIntNoNaN(DOM.bip84purpose.val(), 84);
811 var coin = parseIntNoNaN(DOM.bip84coin.val(), 0);
812 var account = parseIntNoNaN(DOM.bip84account.val(), 0);
813 var change = parseIntNoNaN(DOM.bip84change.val(), 0);
814 var path = "m/";
815 path += purpose + "'/";
816 path += coin + "'/";
817 path += account + "'/";
818 path += change;
819 DOM.bip84path.val(path);
820 var derivationPath = DOM.bip84path.val();
821 console.log("Using derivation path from BIP84 tab: " + derivationPath);
822 return derivationPath;
823 }
824 else if (bip32TabSelected()) {
825 var derivationPath = DOM.bip32path.val();
826 console.log("Using derivation path from BIP32 tab: " + derivationPath);
827 return derivationPath;
828 }
829 else if (bip141TabSelected()) {
830 var derivationPath = DOM.bip141path.val();
831 console.log("Using derivation path from BIP141 tab: " + derivationPath);
832 return derivationPath;
833 }
834 else {
835 console.log("Unknown derivation path");
836 }
837 }
838
839 function findDerivationPathErrors(path) {
840 // TODO is not perfect but is better than nothing
841 // Inspired by
842 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
843 // and
844 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
845 var maxDepth = 255; // TODO verify this!!
846 var maxIndexValue = Math.pow(2, 31); // TODO verify this!!
847 if (path[0] != "m") {
848 return "First character must be 'm'";
849 }
850 if (path.length > 1) {
851 if (path[1] != "/") {
852 return "Separator must be '/'";
853 }
854 var indexes = path.split("/");
855 if (indexes.length > maxDepth) {
856 return "Derivation depth is " + indexes.length + ", must be less than " + maxDepth;
857 }
858 for (var depth = 1; depth<indexes.length; depth++) {
859 var index = indexes[depth];
860 var invalidChars = index.replace(/^[0-9]+'?$/g, "")
861 if (invalidChars.length > 0) {
862 return "Invalid characters " + invalidChars + " found at depth " + depth;
863 }
864 var indexValue = parseInt(index.replace("'", ""));
865 if (isNaN(depth)) {
866 return "Invalid number at depth " + depth;
867 }
868 if (indexValue > maxIndexValue) {
869 return "Value of " + indexValue + " at depth " + depth + " must be less than " + maxIndexValue;
870 }
871 }
872 }
873 // Check root key exists or else derivation path is useless!
874 if (!bip32RootKey) {
875 return "No root key";
876 }
877 // Check no hardened derivation path when using xpub keys
878 var hardenedPath = path.indexOf("'") > -1;
879 var hardenedAddresses = bip32TabSelected() && DOM.hardenedAddresses.prop("checked");
880 var hardened = hardenedPath || hardenedAddresses;
881 var isXpubkey = bip32RootKey.isNeutered();
882 if (hardened && isXpubkey) {
883 return "Hardened derivation path is invalid with xpub key";
884 }
885 return false;
886 }
887
888 function isGRS() {
889 return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet";
890 }
891
892 function isELA() {
893 return networks[DOM.network.val()].name == "ELA - Elastos"
894 }
895
896 function displayBip44Info() {
897 // Get the derivation path for the account
898 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
899 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
900 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
901 var path = "m/";
902 path += purpose + "'/";
903 path += coin + "'/";
904 path += account + "'/";
905 // Calculate the account extended keys
906 var accountExtendedKey = calcBip32ExtendedKey(path);
907 var accountXprv = accountExtendedKey.toBase58();
908 var accountXpub = accountExtendedKey.neutered().toBase58();
909
910 // Display the extended keys
911 DOM.bip44accountXprv.val(accountXprv);
912 DOM.bip44accountXpub.val(accountXpub);
913
914 if (isELA()) {
915 displayBip44InfoForELA();
916 }
917 }
918
919 function displayBip49Info() {
920 // Get the derivation path for the account
921 var purpose = parseIntNoNaN(DOM.bip49purpose.val(), 49);
922 var coin = parseIntNoNaN(DOM.bip49coin.val(), 0);
923 var account = parseIntNoNaN(DOM.bip49account.val(), 0);
924 var path = "m/";
925 path += purpose + "'/";
926 path += coin + "'/";
927 path += account + "'/";
928 // Calculate the account extended keys
929 var accountExtendedKey = calcBip32ExtendedKey(path);
930 var accountXprv = accountExtendedKey.toBase58();
931 var accountXpub = accountExtendedKey.neutered().toBase58();
932 // Display the extended keys
933 DOM.bip49accountXprv.val(accountXprv);
934 DOM.bip49accountXpub.val(accountXpub);
935 }
936
937 function displayBip84Info() {
938 // Get the derivation path for the account
939 var purpose = parseIntNoNaN(DOM.bip84purpose.val(), 84);
940 var coin = parseIntNoNaN(DOM.bip84coin.val(), 0);
941 var account = parseIntNoNaN(DOM.bip84account.val(), 0);
942 var path = "m/";
943 path += purpose + "'/";
944 path += coin + "'/";
945 path += account + "'/";
946 // Calculate the account extended keys
947 var accountExtendedKey = calcBip32ExtendedKey(path);
948 var accountXprv = accountExtendedKey.toBase58();
949 var accountXpub = accountExtendedKey.neutered().toBase58();
950 // Display the extended keys
951 DOM.bip84accountXprv.val(accountXprv);
952 DOM.bip84accountXpub.val(accountXpub);
953 }
954
955 function displayBip32Info() {
956 // Display the key
957 DOM.seed.val(seed);
958 var rootKey = bip32RootKey.toBase58();
959 DOM.rootKey.val(rootKey);
960 var xprvkeyB58 = "NA";
961 if (!bip32ExtendedKey.isNeutered()) {
962 xprvkeyB58 = bip32ExtendedKey.toBase58();
963 }
964 var extendedPrivKey = xprvkeyB58;
965 DOM.extendedPrivKey.val(extendedPrivKey);
966 var extendedPubKey = bip32ExtendedKey.neutered().toBase58();
967 DOM.extendedPubKey.val(extendedPubKey);
968 // Display the addresses and privkeys
969 clearAddressesList();
970 var initialAddressCount = parseInt(DOM.rowsToAdd.val());
971 displayAddresses(0, initialAddressCount);
972
973 if (isELA()) {
974 displayBip32InfoForELA();
975 }
976 }
977
978 function displayAddresses(start, total) {
979 generationProcesses.push(new (function() {
980
981 var rows = [];
982
983 this.stop = function() {
984 for (var i=0; i<rows.length; i++) {
985 rows[i].shouldGenerate = false;
986 }
987 hidePending();
988 }
989
990 for (var i=0; i<total; i++) {
991 var index = i + start;
992 var isLast = i == total - 1;
993 rows.push(new TableRow(index, isLast));
994 }
995
996 })());
997 }
998
999 function segwitSelected() {
1000 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
1001 }
1002
1003 function p2wpkhSelected() {
1004 return bip84TabSelected() ||
1005 bip141TabSelected() && DOM.bip141semantics.val() == "p2wpkh";
1006 }
1007
1008 function p2wpkhInP2shSelected() {
1009 return bip49TabSelected() ||
1010 (bip141TabSelected() && DOM.bip141semantics.val() == "p2wpkh-p2sh");
1011 }
1012
1013 function p2wshSelected() {
1014 return bip141TabSelected() && DOM.bip141semantics.val() == "p2wsh";
1015 }
1016
1017 function p2wshInP2shSelected() {
1018 return (bip141TabSelected() && DOM.bip141semantics.val() == "p2wsh-p2sh");
1019 }
1020
1021 function TableRow(index, isLast) {
1022
1023 var self = this;
1024 this.shouldGenerate = true;
1025 var useHardenedAddresses = DOM.hardenedAddresses.prop("checked");
1026 var useBip38 = DOM.useBip38.prop("checked");
1027 var bip38password = DOM.bip38Password.val();
1028 var isSegwit = segwitSelected();
1029 var segwitAvailable = networkHasSegwit();
1030 var isP2wpkh = p2wpkhSelected();
1031 var isP2wpkhInP2sh = p2wpkhInP2shSelected();
1032 var isP2wsh = p2wshSelected();
1033 var isP2wshInP2sh = p2wshInP2shSelected();
1034
1035 function init() {
1036 calculateValues();
1037 }
1038
1039 function calculateValues() {
1040 setTimeout(function() {
1041 if (!self.shouldGenerate) {
1042 return;
1043 }
1044 // derive HDkey for this row of the table
1045 var key = "NA";
1046 if (useHardenedAddresses) {
1047 key = bip32ExtendedKey.deriveHardened(index);
1048 }
1049 else {
1050 key = bip32ExtendedKey.derive(index);
1051 }
1052 // bip38 requires uncompressed keys
1053 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1054 var keyPair = key.keyPair;
1055 var useUncompressed = useBip38;
1056 if (useUncompressed) {
1057 keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false });
1058 if(isGRS())
1059 keyPair = new groestlcoinjs.ECPair(keyPair.d, null, { network: network, compressed: false });
1060
1061 }
1062 // get address
1063 var address = keyPair.getAddress().toString();
1064 // get privkey
1065 var hasPrivkey = !key.isNeutered();
1066 var privkey = "NA";
1067 if (hasPrivkey) {
1068 privkey = keyPair.toWIF();
1069 // BIP38 encode private key if required
1070 if (useBip38) {
1071 if(isGRS())
1072 privkey = groestlcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
1073 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
1074 }, null, networks[DOM.network.val()].name.includes("Testnet"));
1075 else
1076 privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
1077 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
1078 });
1079 }
1080 }
1081 // get pubkey
1082 var pubkey = keyPair.getPublicKeyBuffer().toString('hex');
1083 var indexText = getDerivationPath() + "/" + index;
1084 if (useHardenedAddresses) {
1085 indexText = indexText + "'";
1086 }
1087 // Ethereum values are different
1088 if (networkIsEthereum()) {
1089 var privKeyBuffer = keyPair.d.toBuffer(32);
1090 privkey = privKeyBuffer.toString('hex');
1091 var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
1092 var hexAddress = addressBuffer.toString('hex');
1093 var checksumAddress = ethUtil.toChecksumAddress(hexAddress);
1094 address = ethUtil.addHexPrefix(checksumAddress);
1095 privkey = ethUtil.addHexPrefix(privkey);
1096 pubkey = ethUtil.addHexPrefix(pubkey);
1097 }
1098
1099 // Stellar is different
1100 if (networks[DOM.network.val()].name == "XLM - Stellar") {
1101 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
1102 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
1103 var path = "m/";
1104 path += purpose + "'/";
1105 path += coin + "'/" + index + "'";
1106 var keypair = stellarUtil.getKeypair(path, seed);
1107 indexText = path;
1108 privkey = keypair.secret();
1109 pubkey = address = keypair.publicKey();
1110 }
1111 if ((networks[DOM.network.val()].name == "NAS - Nebulas")) {
1112 var NasAccount = require("nebulas-account");
1113 var privKeyBuffer = keyPair.d.toBuffer(32);
1114 var nebulasAccount = new NasAccount();
1115 nebulasAccount.setPrivateKey(privKeyBuffer);
1116 address = nebulasAccount.getAddressString();
1117 privkey = nebulasAccount.getPrivateKeyString();
1118 pubkey = nebulasAccount.getPublicKeyString();
1119 }
1120 // Ripple values are different
1121 if (networks[DOM.network.val()].name == "XRP - Ripple") {
1122 privkey = convertRipplePriv(privkey);
1123 address = convertRippleAdrr(address);
1124 }
1125 // CasinoCoin values are different
1126 if (networks[DOM.network.val()].name == "CSC - CasinoCoin") {
1127 privkey = convertCasinoCoinPriv(privkey);
1128 address = convertCasinoCoinAdrr(address);
1129 }
1130 // Bitcoin Cash address format may vary
1131 if (networks[DOM.network.val()].name == "BCH - Bitcoin Cash") {
1132 var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val();
1133 if (bchAddrType == "cashaddr") {
1134 address = bchaddr.toCashAddress(address);
1135 }
1136 else if (bchAddrType == "bitpay") {
1137 address = bchaddr.toBitpayAddress(address);
1138 }
1139 }
1140 // Bitcoin Cash address format may vary
1141 if (networks[DOM.network.val()].name == "SLP - Simple Ledger Protocol") {
1142 var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val();
1143 if (bchAddrType == "cashaddr") {
1144 address = bchaddr.toSlpAddress(address);
1145 }
1146 }
1147 // Segwit addresses are different
1148 if (isSegwit) {
1149 if (!segwitAvailable) {
1150 return;
1151 }
1152 if (isP2wpkh) {
1153 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
1154 var scriptpubkey = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
1155 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
1156 }
1157 else if (isP2wpkhInP2sh) {
1158 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
1159 var scriptsig = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
1160 var addressbytes = bitcoinjs.bitcoin.crypto.hash160(scriptsig);
1161 var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes);
1162 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
1163 }
1164 else if (isP2wsh) {
1165 // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71
1166 // This is a 1-of-1
1167 var witnessScript = bitcoinjs.bitcoin.script.multisig.output.encode(1, [key.getPublicKeyBuffer()]);
1168 var scriptPubKey = bitcoinjs.bitcoin.script.witnessScriptHash.output.encode(bitcoinjs.bitcoin.crypto.sha256(witnessScript));
1169 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptPubKey, network);
1170 }
1171 else if (isP2wshInP2sh) {
1172 // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183
1173 // This is a 1-of-1
1174 var witnessScript = bitcoinjs.bitcoin.script.multisig.output.encode(1, [key.getPublicKeyBuffer()]);
1175 var redeemScript = bitcoinjs.bitcoin.script.witnessScriptHash.output.encode(bitcoinjs.bitcoin.crypto.sha256(witnessScript));
1176 var scriptPubKey = bitcoinjs.bitcoin.script.scriptHash.output.encode(bitcoinjs.bitcoin.crypto.hash160(redeemScript));
1177 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptPubKey, network)
1178 }
1179 }
1180
1181 if ((networks[DOM.network.val()].name == "CRW - Crown")) {
1182 address = bitcoinjs.bitcoin.networks.crown.toNewAddress(address);
1183 }
1184
1185 if (networks[DOM.network.val()].name == "EOS - EOSIO") {
1186 address = ""
1187 pubkey = eosUtil.bufferToPublic(keyPair.getPublicKeyBuffer());
1188 privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32));
1189 }
1190
1191 //Groestlcoin Addresses are different
1192 if(isGRS()) {
1193
1194 if (isSegwit) {
1195 if (!segwitAvailable) {
1196 return;
1197 }
1198 if (isP2wpkh) {
1199 address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
1200 }
1201 else if (isP2wpkhInP2sh) {
1202 address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
1203 }
1204 }
1205 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1206 }
1207
1208 if (isELA()) {
1209 let elaAddress = calcAddressForELA(
1210 seed,
1211 parseIntNoNaN(DOM.bip44coin.val(), 0),
1212 parseIntNoNaN(DOM.bip44account.val(), 0),
1213 parseIntNoNaN(DOM.bip44change.val(), 0),
1214 index
1215 );
1216 address = elaAddress.address;
1217 privkey = elaAddress.privateKey;
1218 pubkey = elaAddress.publicKey;
1219 }
1220
1221 addAddressToList(indexText, address, pubkey, privkey);
1222 if (isLast) {
1223 hidePending();
1224 updateCsv();
1225 }
1226 }, 50)
1227 }
1228
1229 init();
1230
1231 }
1232
1233 function showMore() {
1234 var rowsToAdd = parseInt(DOM.rowsToAdd.val());
1235 if (isNaN(rowsToAdd)) {
1236 rowsToAdd = 20;
1237 DOM.rowsToAdd.val("20");
1238 }
1239 var start = parseInt(DOM.moreRowsStartIndex.val())
1240 if (isNaN(start)) {
1241 start = lastIndexInTable() + 1;
1242 }
1243 else {
1244 var newStart = start + rowsToAdd;
1245 DOM.moreRowsStartIndex.val(newStart);
1246 }
1247 if (rowsToAdd > 200) {
1248 var msg = "Generating " + rowsToAdd + " rows could take a while. ";
1249 msg += "Do you want to continue?";
1250 if (!confirm(msg)) {
1251 return;
1252 }
1253 }
1254 displayAddresses(start, rowsToAdd);
1255 }
1256
1257 function clearDisplay() {
1258 clearAddressesList();
1259 clearKeys();
1260 hideValidationError();
1261 }
1262
1263 function clearAddressesList() {
1264 DOM.addresses.empty();
1265 DOM.csv.val("");
1266 stopGenerating();
1267 }
1268
1269 function stopGenerating() {
1270 while (generationProcesses.length > 0) {
1271 var generation = generationProcesses.shift();
1272 generation.stop();
1273 }
1274 }
1275
1276 function clearKeys() {
1277 clearRootKey();
1278 clearDerivedKeys();
1279 }
1280
1281 function clearRootKey() {
1282 DOM.rootKey.val("");
1283 }
1284
1285 function clearDerivedKeys() {
1286 DOM.extendedPrivKey.val("");
1287 DOM.extendedPubKey.val("");
1288 DOM.bip44accountXprv.val("");
1289 DOM.bip44accountXpub.val("");
1290 }
1291
1292 function addAddressToList(indexText, address, pubkey, privkey) {
1293 var row = $(addressRowTemplate.html());
1294 // Elements
1295 var indexCell = row.find(".index span");
1296 var addressCell = row.find(".address span");
1297 var pubkeyCell = row.find(".pubkey span");
1298 var privkeyCell = row.find(".privkey span");
1299 // Content
1300 indexCell.text(indexText);
1301 addressCell.text(address);
1302 pubkeyCell.text(pubkey);
1303 privkeyCell.text(privkey);
1304 // Visibility
1305 if (!showIndex) {
1306 indexCell.addClass("invisible");
1307 }
1308 if (!showAddress) {
1309 addressCell.addClass("invisible");
1310 }
1311 if (!showPubKey) {
1312 pubkeyCell.addClass("invisible");
1313 }
1314 if (!showPrivKey) {
1315 privkeyCell.addClass("invisible");
1316 }
1317 DOM.addresses.append(row);
1318 var rowShowQrEls = row.find("[data-show-qr]");
1319 setQrEvents(rowShowQrEls);
1320 }
1321
1322 function hasStrongRandom() {
1323 return 'crypto' in window && window['crypto'] !== null;
1324 }
1325
1326 function disableForms() {
1327 $("form").on("submit", function(e) {
1328 e.preventDefault();
1329 });
1330 }
1331
1332 function parseIntNoNaN(val, defaultVal) {
1333 var v = parseInt(val);
1334 if (isNaN(v)) {
1335 return defaultVal;
1336 }
1337 return v;
1338 }
1339
1340 function showPending() {
1341 DOM.feedback
1342 .text("Calculating...")
1343 .show();
1344 }
1345
1346 function findNearestWord(word) {
1347 var language = getLanguage();
1348 var words = WORDLISTS[language];
1349 var minDistance = 99;
1350 var closestWord = words[0];
1351 for (var i=0; i<words.length; i++) {
1352 var comparedTo = words[i];
1353 if (comparedTo.indexOf(word) == 0) {
1354 return comparedTo;
1355 }
1356 var distance = Levenshtein.get(word, comparedTo);
1357 if (distance < minDistance) {
1358 closestWord = comparedTo;
1359 minDistance = distance;
1360 }
1361 }
1362 return closestWord;
1363 }
1364
1365 function hidePending() {
1366 DOM.feedback
1367 .text("")
1368 .hide();
1369 }
1370
1371 function populateNetworkSelect() {
1372 for (var i=0; i<networks.length; i++) {
1373 var network = networks[i];
1374 var option = $("<option>");
1375 option.attr("value", i);
1376 option.text(network.name);
1377 if (network.name == "BTC - Bitcoin") {
1378 option.prop("selected", true);
1379 }
1380 DOM.phraseNetwork.append(option);
1381 }
1382 }
1383
1384 function populateClientSelect() {
1385 for (var i=0; i<clients.length; i++) {
1386 var client = clients[i];
1387 var option = $("<option>");
1388 option.attr("value", i);
1389 option.text(client.name);
1390 DOM.bip32Client.append(option);
1391 }
1392 }
1393
1394 function getLanguage() {
1395 var defaultLanguage = "english";
1396 // Try to get from existing phrase
1397 var language = getLanguageFromPhrase();
1398 // Try to get from url if not from phrase
1399 if (language.length == 0) {
1400 language = getLanguageFromUrl();
1401 }
1402 // Default to English if no other option
1403 if (language.length == 0) {
1404 language = defaultLanguage;
1405 }
1406 return language;
1407 }
1408
1409 function getLanguageFromPhrase(phrase) {
1410 // Check if how many words from existing phrase match a language.
1411 var language = "";
1412 if (!phrase) {
1413 phrase = DOM.phrase.val();
1414 }
1415 if (phrase.length > 0) {
1416 var words = phraseToWordArray(phrase);
1417 var languageMatches = {};
1418 for (l in WORDLISTS) {
1419 // Track how many words match in this language
1420 languageMatches[l] = 0;
1421 for (var i=0; i<words.length; i++) {
1422 var wordInLanguage = WORDLISTS[l].indexOf(words[i]) > -1;
1423 if (wordInLanguage) {
1424 languageMatches[l]++;
1425 }
1426 }
1427 // Find languages with most word matches.
1428 // This is made difficult due to commonalities between Chinese
1429 // simplified vs traditional.
1430 var mostMatches = 0;
1431 var mostMatchedLanguages = [];
1432 for (var l in languageMatches) {
1433 var numMatches = languageMatches[l];
1434 if (numMatches > mostMatches) {
1435 mostMatches = numMatches;
1436 mostMatchedLanguages = [l];
1437 }
1438 else if (numMatches == mostMatches) {
1439 mostMatchedLanguages.push(l);
1440 }
1441 }
1442 }
1443 if (mostMatchedLanguages.length > 0) {
1444 // Use first language and warn if multiple detected
1445 language = mostMatchedLanguages[0];
1446 if (mostMatchedLanguages.length > 1) {
1447 console.warn("Multiple possible languages");
1448 console.warn(mostMatchedLanguages);
1449 }
1450 }
1451 }
1452 return language;
1453 }
1454
1455 function getLanguageFromUrl() {
1456 for (var language in WORDLISTS) {
1457 if (window.location.hash.indexOf(language) > -1) {
1458 return language;
1459 }
1460 }
1461 return "";
1462 }
1463
1464 function setMnemonicLanguage() {
1465 var language = getLanguage();
1466 // Load the bip39 mnemonic generator for this language if required
1467 if (!(language in mnemonics)) {
1468 mnemonics[language] = new Mnemonic(language);
1469 }
1470 mnemonic = mnemonics[language];
1471 }
1472
1473 function convertPhraseToNewLanguage() {
1474 var oldLanguage = getLanguageFromPhrase();
1475 var newLanguage = getLanguageFromUrl();
1476 var oldPhrase = DOM.phrase.val();
1477 var oldWords = phraseToWordArray(oldPhrase);
1478 var newWords = [];
1479 for (var i=0; i<oldWords.length; i++) {
1480 var oldWord = oldWords[i];
1481 var index = WORDLISTS[oldLanguage].indexOf(oldWord);
1482 var newWord = WORDLISTS[newLanguage][index];
1483 newWords.push(newWord);
1484 }
1485 newPhrase = wordArrayToPhrase(newWords);
1486 return newPhrase;
1487 }
1488
1489 // TODO look at jsbip39 - mnemonic.splitWords
1490 function phraseToWordArray(phrase) {
1491 var words = phrase.split(/\s/g);
1492 var noBlanks = [];
1493 for (var i=0; i<words.length; i++) {
1494 var word = words[i];
1495 if (word.length > 0) {
1496 noBlanks.push(word);
1497 }
1498 }
1499 return noBlanks;
1500 }
1501
1502 // TODO look at jsbip39 - mnemonic.joinWords
1503 function wordArrayToPhrase(words) {
1504 var phrase = words.join(" ");
1505 var language = getLanguageFromPhrase(phrase);
1506 if (language == "japanese") {
1507 phrase = words.join("\u3000");
1508 }
1509 return phrase;
1510 }
1511
1512 function writeSplitPhrase(phrase) {
1513 var wordCount = phrase.split(/\s/g).length;
1514 var left=[];
1515 for (var i=0;i<wordCount;i++) left.push(i);
1516 var group=[[],[],[]],
1517 groupI=-1;
1518 var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647;
1519 while (left.length>0) {
1520 groupI=(groupI+1)%3;
1521 seed = seed * 16807 % 2147483647;
1522 var selected=Math.floor(left.length*(seed - 1) / 2147483646);
1523 group[groupI].push(left[selected]);
1524 left.splice(selected,1);
1525 }
1526 var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];
1527 for (var i=0;i<3;i++) {
1528 for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX';
1529 cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]);
1530 }
1531 DOM.phraseSplit.val(cards.join("\r\n"));
1532 var triesPerSecond=10000000000;
1533 var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond;
1534 var displayRedText = false;
1535 if (hackTime<1) {
1536 hackTime="<1 second";
1537 displayRedText = true;
1538 } else if (hackTime<86400) {
1539 hackTime=Math.floor(hackTime)+" seconds";
1540 displayRedText = true;
1541 } else if(hackTime<31557600) {
1542 hackTime=Math.floor(hackTime/86400)+" days";
1543 displayRedText = true;
1544 } else {
1545 hackTime=Math.floor(hackTime/31557600)+" years";
1546 }
1547 DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime);
1548 if (displayRedText) {
1549 DOM.phraseSplitWarn.addClass("text-danger");
1550 } else {
1551 DOM.phraseSplitWarn.removeClass("text-danger");
1552 }
1553 }
1554
1555 function isUsingOwnEntropy() {
1556 return DOM.useEntropy.prop("checked");
1557 }
1558
1559 function setMnemonicFromEntropy() {
1560 clearEntropyFeedback();
1561 // Get entropy value
1562 var entropyStr = DOM.entropy.val();
1563 // Work out minimum base for entropy
1564 var entropy = null;
1565 if (entropyTypeAutoDetect) {
1566 entropy = Entropy.fromString(entropyStr);
1567 }
1568 else {
1569 let base = DOM.entropyTypeInputs.filter(":checked").val();
1570 entropy = Entropy.fromString(entropyStr, base);
1571 }
1572 if (entropy.binaryStr.length == 0) {
1573 return;
1574 }
1575 // Show entropy details
1576 showEntropyFeedback(entropy);
1577 // Use entropy hash if not using raw entropy
1578 var bits = entropy.binaryStr;
1579 var mnemonicLength = DOM.entropyMnemonicLength.val();
1580 if (mnemonicLength != "raw") {
1581 // Get bits by hashing entropy with SHA256
1582 var hash = sjcl.hash.sha256.hash(entropy.cleanStr);
1583 var hex = sjcl.codec.hex.fromBits(hash);
1584 bits = BigInteger.parse(hex, 16).toString(2);
1585 while (bits.length % 256 != 0) {
1586 bits = "0" + bits;
1587 }
1588 // Truncate hash to suit number of words
1589 mnemonicLength = parseInt(mnemonicLength);
1590 var numberOfBits = 32 * mnemonicLength / 3;
1591 bits = bits.substring(0, numberOfBits);
1592 // show warning for weak entropy override
1593 if (mnemonicLength / 3 * 32 > entropy.binaryStr.length) {
1594 DOM.entropyWeakEntropyOverrideWarning.removeClass("hidden");
1595 }
1596 else {
1597 DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
1598 }
1599 }
1600 else {
1601 // hide warning for weak entropy override
1602 DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
1603 }
1604 // Discard trailing entropy
1605 var bitsToUse = Math.floor(bits.length / 32) * 32;
1606 var start = bits.length - bitsToUse;
1607 var binaryStr = bits.substring(start);
1608 // Convert entropy string to numeric array
1609 var entropyArr = [];
1610 for (var i=0; i<binaryStr.length / 8; i++) {
1611 var byteAsBits = binaryStr.substring(i*8, i*8+8);
1612 var entropyByte = parseInt(byteAsBits, 2);
1613 entropyArr.push(entropyByte)
1614 }
1615 // Convert entropy array to mnemonic
1616 var phrase = mnemonic.toMnemonic(entropyArr);
1617 // Set the mnemonic in the UI
1618 DOM.phrase.val(phrase);
1619 writeSplitPhrase(phrase);
1620 // Show the word indexes
1621 showWordIndexes();
1622 // Show the checksum
1623 showChecksum();
1624 }
1625
1626 function clearEntropyFeedback() {
1627 DOM.entropyCrackTime.text("...");
1628 DOM.entropyType.text("");
1629 DOM.entropyWordCount.text("0");
1630 DOM.entropyEventCount.text("0");
1631 DOM.entropyBitsPerEvent.text("0");
1632 DOM.entropyBits.text("0");
1633 DOM.entropyFiltered.html("&nbsp;");
1634 DOM.entropyBinary.html("&nbsp;");
1635 }
1636
1637 function showEntropyFeedback(entropy) {
1638 var numberOfBits = entropy.binaryStr.length;
1639 var timeToCrack = "unknown";
1640 try {
1641 var z = zxcvbn(entropy.base.parts.join(""));
1642 timeToCrack = z.crack_times_display.offline_fast_hashing_1e10_per_second;
1643 if (z.feedback.warning != "") {
1644 timeToCrack = timeToCrack + " - " + z.feedback.warning;
1645 };
1646 }
1647 catch (e) {
1648 console.log("Error detecting entropy strength with zxcvbn:");
1649 console.log(e);
1650 }
1651 var entropyTypeStr = getEntropyTypeStr(entropy);
1652 DOM.entropyTypeInputs.attr("checked", false);
1653 DOM.entropyTypeInputs.filter("[value='" + entropyTypeStr + "']").attr("checked", true);
1654 var wordCount = Math.floor(numberOfBits / 32) * 3;
1655 var bitsPerEvent = entropy.bitsPerEvent.toFixed(2);
1656 var spacedBinaryStr = addSpacesEveryElevenBits(entropy.binaryStr);
1657 DOM.entropyFiltered.html(entropy.cleanHtml);
1658 DOM.entropyType.text(entropyTypeStr);
1659 DOM.entropyCrackTime.text(timeToCrack);
1660 DOM.entropyEventCount.text(entropy.base.ints.length);
1661 DOM.entropyBits.text(numberOfBits);
1662 DOM.entropyWordCount.text(wordCount);
1663 DOM.entropyBinary.text(spacedBinaryStr);
1664 DOM.entropyBitsPerEvent.text(bitsPerEvent);
1665 // detect and warn of filtering
1666 var rawNoSpaces = DOM.entropy.val().replace(/\s/g, "");
1667 var cleanNoSpaces = entropy.cleanStr.replace(/\s/g, "");
1668 var isFiltered = rawNoSpaces.length != cleanNoSpaces.length;
1669 if (isFiltered) {
1670 DOM.entropyFilterWarning.removeClass('hidden');
1671 }
1672 else {
1673 DOM.entropyFilterWarning.addClass('hidden');
1674 }
1675 }
1676
1677 function getEntropyTypeStr(entropy) {
1678 var typeStr = entropy.base.str;
1679 // Add some detail if these are cards
1680 if (entropy.base.asInt == 52) {
1681 var cardDetail = []; // array of message strings
1682 // Detect duplicates
1683 var dupes = [];
1684 var dupeTracker = {};
1685 for (var i=0; i<entropy.base.parts.length; i++) {
1686 var card = entropy.base.parts[i];
1687 var cardUpper = card.toUpperCase();
1688 if (cardUpper in dupeTracker) {
1689 dupes.push(card);
1690 }
1691 dupeTracker[cardUpper] = true;
1692 }
1693 if (dupes.length > 0) {
1694 var dupeWord = "duplicates";
1695 if (dupes.length == 1) {
1696 dupeWord = "duplicate";
1697 }
1698 var msg = dupes.length + " " + dupeWord + ": " + dupes.slice(0,3).join(" ");
1699 if (dupes.length > 3) {
1700 msg += "...";
1701 }
1702 cardDetail.push(msg);
1703 }
1704 // Detect full deck
1705 var uniqueCards = [];
1706 for (var uniqueCard in dupeTracker) {
1707 uniqueCards.push(uniqueCard);
1708 }
1709 if (uniqueCards.length == 52) {
1710 cardDetail.unshift("full deck");
1711 }
1712 // Detect missing cards
1713 var values = "A23456789TJQK";
1714 var suits = "CDHS";
1715 var missingCards = [];
1716 for (var i=0; i<suits.length; i++) {
1717 for (var j=0; j<values.length; j++) {
1718 var card = values[j] + suits[i];
1719 if (!(card in dupeTracker)) {
1720 missingCards.push(card);
1721 }
1722 }
1723 }
1724 // Display missing cards if six or less, ie clearly going for full deck
1725 if (missingCards.length > 0 && missingCards.length <= 6) {
1726 var msg = missingCards.length + " missing: " + missingCards.slice(0,3).join(" ");
1727 if (missingCards.length > 3) {
1728 msg += "...";
1729 }
1730 cardDetail.push(msg);
1731 }
1732 // Add card details to typeStr
1733 if (cardDetail.length > 0) {
1734 typeStr += " (" + cardDetail.join(", ") + ")";
1735 }
1736 }
1737 return typeStr;
1738 }
1739
1740 function setQrEvents(els) {
1741 els.on("mouseenter", createQr);
1742 els.on("mouseleave", destroyQr);
1743 els.on("click", toggleQr);
1744 }
1745
1746 function createQr(e) {
1747 var content = e.target.textContent || e.target.value;
1748 if (content) {
1749 var qrEl = kjua({
1750 text: content,
1751 render: "canvas",
1752 size: 310,
1753 ecLevel: 'H',
1754 });
1755 DOM.qrImage.append(qrEl);
1756 if (!showQr) {
1757 DOM.qrHider.addClass("hidden");
1758 }
1759 else {
1760 DOM.qrHider.removeClass("hidden");
1761 }
1762 DOM.qrContainer.removeClass("hidden");
1763 }
1764 }
1765
1766 function destroyQr() {
1767 DOM.qrImage.text("");
1768 DOM.qrContainer.addClass("hidden");
1769 }
1770
1771 function toggleQr() {
1772 showQr = !showQr;
1773 DOM.qrHider.toggleClass("hidden");
1774 DOM.qrHint.toggleClass("hidden");
1775 }
1776
1777 function bip44TabSelected() {
1778 return DOM.bip44tab.hasClass("active");
1779 }
1780
1781 function bip32TabSelected() {
1782 return DOM.bip32tab.hasClass("active");
1783 }
1784
1785 function networkIsEthereum() {
1786 var name = networks[DOM.network.val()].name;
1787 return (name == "ETH - Ethereum")
1788 || (name == "ETC - Ethereum Classic")
1789 || (name == "EWT - EnergyWeb")
1790 || (name == "PIRL - Pirl")
1791 || (name == "MIX - MIX")
1792 || (name == "MUSIC - Musicoin")
1793 || (name == "POA - Poa")
1794 || (name == "EXP - Expanse")
1795 || (name == "CLO - Callisto")
1796 || (name == "DXN - DEXON")
1797 || (name == "ELLA - Ellaism")
1798 || (name == "ESN - Ethersocial Network")
1799 || (name == "VET - VeChain")
1800 }
1801
1802 function networkHasSegwit() {
1803 var n = network;
1804 if ("baseNetwork" in network) {
1805 n = bitcoinjs.bitcoin.networks[network.baseNetwork];
1806 }
1807 // check if only p2wpkh params are required
1808 if (p2wpkhSelected()) {
1809 return "p2wpkh" in n;
1810 }
1811 // check if only p2wpkh-in-p2sh params are required
1812 else if (p2wpkhInP2shSelected()) {
1813 return "p2wpkhInP2sh" in n;
1814 }
1815 // require both if it's unclear which params are required
1816 return "p2wpkh" in n && "p2wpkhInP2sh" in n;
1817 }
1818
1819 function bip49TabSelected() {
1820 return DOM.bip49tab.hasClass("active");
1821 }
1822
1823 function bip84TabSelected() {
1824 return DOM.bip84tab.hasClass("active");
1825 }
1826
1827 function bip141TabSelected() {
1828 return DOM.bip141tab.hasClass("active");
1829 }
1830
1831 function setHdCoin(coinValue) {
1832 DOM.bip44coin.val(coinValue);
1833 DOM.bip49coin.val(coinValue);
1834 DOM.bip84coin.val(coinValue);
1835 }
1836
1837 function showSegwitAvailable() {
1838 DOM.bip49unavailable.addClass("hidden");
1839 DOM.bip49available.removeClass("hidden");
1840 DOM.bip84unavailable.addClass("hidden");
1841 DOM.bip84available.removeClass("hidden");
1842 DOM.bip141unavailable.addClass("hidden");
1843 DOM.bip141available.removeClass("hidden");
1844 }
1845
1846 function showSegwitUnavailable() {
1847 DOM.bip49available.addClass("hidden");
1848 DOM.bip49unavailable.removeClass("hidden");
1849 DOM.bip84available.addClass("hidden");
1850 DOM.bip84unavailable.removeClass("hidden");
1851 DOM.bip141available.addClass("hidden");
1852 DOM.bip141unavailable.removeClass("hidden");
1853 }
1854
1855 function adjustNetworkForSegwit() {
1856 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1857 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1858 // wallet.
1859 // See https://github.com/iancoleman/bip39/issues/125
1860 var segwitNetworks = null;
1861 // if a segwit network is alread selected, need to use base network to
1862 // look up new parameters
1863 if ("baseNetwork" in network) {
1864 network = bitcoinjs.bitcoin.networks[network.baseNetwork];
1865 }
1866 // choose the right segwit params
1867 if (p2wpkhSelected() && "p2wpkh" in network) {
1868 network = network.p2wpkh;
1869 }
1870 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network) {
1871 network = network.p2wpkhInP2sh;
1872 }
1873 else if (p2wshSelected() && "p2wsh" in network) {
1874 network = network.p2wsh;
1875 }
1876 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network) {
1877 network = network.p2wshInP2sh;
1878 }
1879 }
1880
1881 function lastIndexInTable() {
1882 var pathText = DOM.addresses.find(".index").last().text();
1883 var pathBits = pathText.split("/");
1884 var lastBit = pathBits[pathBits.length-1];
1885 var lastBitClean = lastBit.replace("'", "");
1886 return parseInt(lastBitClean);
1887 }
1888
1889 function uint8ArrayToHex(a) {
1890 var s = ""
1891 for (var i=0; i<a.length; i++) {
1892 var h = a[i].toString(16);
1893 while (h.length < 2) {
1894 h = "0" + h;
1895 }
1896 s = s + h;
1897 }
1898 return s;
1899 }
1900
1901 function showWordIndexes() {
1902 var phrase = DOM.phrase.val();
1903 var words = phraseToWordArray(phrase);
1904 var wordIndexes = [];
1905 var language = getLanguage();
1906 for (var i=0; i<words.length; i++) {
1907 var word = words[i];
1908 var wordIndex = WORDLISTS[language].indexOf(word);
1909 wordIndexes.push(wordIndex);
1910 }
1911 var wordIndexesStr = wordIndexes.join(", ");
1912 DOM.entropyWordIndexes.text(wordIndexesStr);
1913 }
1914
1915 function showChecksum() {
1916 var phrase = DOM.phrase.val();
1917 var words = phraseToWordArray(phrase);
1918 var checksumBitlength = words.length / 3;
1919 var checksum = "";
1920 var binaryStr = "";
1921 var language = getLanguage();
1922 for (var i=words.length-1; i>=0; i--) {
1923 var word = words[i];
1924 var wordIndex = WORDLISTS[language].indexOf(word);
1925 var wordBinary = wordIndex.toString(2);
1926 while (wordBinary.length < 11) {
1927 wordBinary = "0" + wordBinary;
1928 }
1929 var binaryStr = wordBinary + binaryStr;
1930 if (binaryStr.length >= checksumBitlength) {
1931 var start = binaryStr.length - checksumBitlength;
1932 var end = binaryStr.length;
1933 checksum = binaryStr.substring(start, end);
1934 // add spaces so the last group is 11 bits, not the first
1935 checksum = checksum.split("").reverse().join("")
1936 checksum = addSpacesEveryElevenBits(checksum);
1937 checksum = checksum.split("").reverse().join("")
1938 break;
1939 }
1940 }
1941 DOM.entropyChecksum.text(checksum);
1942 }
1943
1944 function updateCsv() {
1945 var tableCsv = "path,address,public key,private key\n";
1946 var rows = DOM.addresses.find("tr");
1947 for (var i=0; i<rows.length; i++) {
1948 var row = $(rows[i]);
1949 var cells = row.find("td");
1950 for (var j=0; j<cells.length; j++) {
1951 var cell = $(cells[j]);
1952 if (!cell.children().hasClass("invisible")) {
1953 tableCsv = tableCsv + cell.text();
1954 }
1955 if (j != cells.length - 1) {
1956 tableCsv = tableCsv + ",";
1957 }
1958 }
1959 tableCsv = tableCsv + "\n";
1960 }
1961 DOM.csv.val(tableCsv);
1962 }
1963
1964 function addSpacesEveryElevenBits(binaryStr) {
1965 return binaryStr.match(/.{1,11}/g).join(" ");
1966 }
1967
1968 var networks = [
1969 {
1970 name: "AC - Asiacoin",
1971 onSelect: function() {
1972 network = bitcoinjs.bitcoin.networks.asiacoin;
1973 setHdCoin(51);
1974 },
1975 },
1976 {
1977 name: "ACC - Adcoin",
1978 onSelect: function() {
1979 network = bitcoinjs.bitcoin.networks.adcoin;
1980 setHdCoin(161);
1981 },
1982 },
1983 {
1984 name: "ARYA - Aryacoin",
1985 onSelect: function() {
1986 network = bitcoinjs.bitcoin.networks.aryacoin;
1987 setHdCoin(357);
1988 },
1989 },
1990 {
1991 name: "AUR - Auroracoin",
1992 onSelect: function() {
1993 network = bitcoinjs.bitcoin.networks.auroracoin;
1994 setHdCoin(85);
1995 },
1996 },
1997 {
1998 name: "AXE - Axe",
1999 onSelect: function() {
2000 network = bitcoinjs.bitcoin.networks.axe;
2001 setHdCoin(4242);
2002 },
2003 },
2004 {
2005 name: "ANON - ANON",
2006 onSelect: function() {
2007 network = bitcoinjs.bitcoin.networks.anon;
2008 setHdCoin(220);
2009 },
2010 },
2011 {
2012 name: "BOLI - Bolivarcoin",
2013 onSelect: function() {
2014 network = bitcoinjs.bitcoin.networks.bolivarcoin;
2015 setHdCoin(278);
2016 },
2017 },
2018 {
2019 name: "BCA - Bitcoin Atom",
2020 onSelect: function() {
2021 network = bitcoinjs.bitcoin.networks.atom;
2022 setHdCoin(185);
2023 },
2024 },
2025 {
2026 name: "BCH - Bitcoin Cash",
2027 onSelect: function() {
2028 DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
2029 setHdCoin(145);
2030 },
2031 },
2032 {
2033 name: "BEET - Beetlecoin",
2034 onSelect: function() {
2035 network = bitcoinjs.bitcoin.networks.beetlecoin;
2036 setHdCoin(800);
2037 },
2038 },
2039 {
2040 name: "BELA - Belacoin",
2041 onSelect: function() {
2042 network = bitcoinjs.bitcoin.networks.belacoin;
2043 setHdCoin(73);
2044 },
2045 },
2046 {
2047 name: "BLK - BlackCoin",
2048 onSelect: function() {
2049 network = bitcoinjs.bitcoin.networks.blackcoin;
2050 setHdCoin(10);
2051 },
2052 },
2053 {
2054 name: "BND - Blocknode",
2055 onSelect: function() {
2056 network = bitcoinjs.bitcoin.networks.blocknode;
2057 setHdCoin(2941);
2058 },
2059 },
2060 {
2061 name: "tBND - Blocknode Testnet",
2062 onSelect: function() {
2063 network = bitcoinjs.bitcoin.networks.blocknode_testnet;
2064 setHdCoin(1);
2065 },
2066 },
2067 {
2068 name: "BRIT - Britcoin",
2069 onSelect: function() {
2070 network = bitcoinjs.bitcoin.networks.britcoin;
2071 setHdCoin(70);
2072 },
2073 },
2074 {
2075 name: "BSD - Bitsend",
2076 onSelect: function() {
2077 network = bitcoinjs.bitcoin.networks.bitsend;
2078 setHdCoin(91);
2079 },
2080 },
2081 {
2082 name: "BST - BlockStamp",
2083 onSelect: function() {
2084 network = bitcoinjs.bitcoin.networks.blockstamp;
2085 setHdCoin(254);
2086 },
2087 },
2088 {
2089 name: "BTA - Bata",
2090 onSelect: function() {
2091 network = bitcoinjs.bitcoin.networks.bata;
2092 setHdCoin(89);
2093 },
2094 },
2095 {
2096 name: "BTC - Bitcoin",
2097 onSelect: function() {
2098 network = bitcoinjs.bitcoin.networks.bitcoin;
2099 setHdCoin(0);
2100 },
2101 },
2102 {
2103 name: "BTC - Bitcoin Testnet",
2104 onSelect: function() {
2105 network = bitcoinjs.bitcoin.networks.testnet;
2106 setHdCoin(1);
2107 },
2108 },
2109 {
2110 name: "BITG - Bitcoin Green",
2111 onSelect: function() {
2112 network = bitcoinjs.bitcoin.networks.bitcoingreen;
2113 setHdCoin(222);
2114 },
2115 },
2116 {
2117 name: "BTCP - Bitcoin Private",
2118 onSelect: function() {
2119 network = bitcoinjs.bitcoin.networks.bitcoinprivate;
2120 setHdCoin(183);
2121 },
2122 },
2123 {
2124 name: "BSV - BitcoinSV",
2125 onSelect: function() {
2126 network = bitcoinjs.bitcoin.networks.bitcoinsv;
2127 setHdCoin(236);
2128 },
2129 },
2130 {
2131 name: "BTCZ - Bitcoinz",
2132 onSelect: function() {
2133 network = bitcoinjs.bitcoin.networks.bitcoinz;
2134 setHdCoin(177);
2135 },
2136 },
2137 {
2138 name: "BTDX - BitCloud",
2139 onSelect: function() {
2140 network = bitcoinjs.bitcoin.networks.bitcloud;
2141 setHdCoin(218);
2142 },
2143 },
2144 {
2145 name: "BTG - Bitcoin Gold",
2146 onSelect: function() {
2147 network = bitcoinjs.bitcoin.networks.bgold;
2148 setHdCoin(156);
2149 },
2150 },
2151 {
2152 name: "BTX - Bitcore",
2153 onSelect: function() {
2154 network = bitcoinjs.bitcoin.networks.bitcore;
2155 setHdCoin(160);
2156 },
2157 },
2158 {
2159 name: "CCN - Cannacoin",
2160 onSelect: function() {
2161 network = bitcoinjs.bitcoin.networks.cannacoin;
2162 setHdCoin(19);
2163 },
2164 },
2165 {
2166 name: "CESC - Cryptoescudo",
2167 onSelect: function() {
2168 network = bitcoinjs.bitcoin.networks.cannacoin;
2169 setHdCoin(111);
2170 },
2171 },
2172 {
2173 name: "CDN - Canadaecoin",
2174 onSelect: function() {
2175 network = bitcoinjs.bitcoin.networks.canadaecoin;
2176 setHdCoin(34);
2177 },
2178 },
2179 {
2180 name: "CLAM - Clams",
2181 onSelect: function() {
2182 network = bitcoinjs.bitcoin.networks.clam;
2183 setHdCoin(23);
2184 },
2185 },
2186 {
2187 name: "CLO - Callisto",
2188 segwitAvailable: false,
2189 onSelect: function() {
2190 network = bitcoinjs.bitcoin.networks.bitcoin;
2191 setHdCoin(820);
2192 },
2193 },
2194 {
2195 name: "CLUB - Clubcoin",
2196 onSelect: function() {
2197 network = bitcoinjs.bitcoin.networks.clubcoin;
2198 setHdCoin(79);
2199 },
2200 },
2201 {
2202 name: "CMP - Compcoin",
2203 onSelect: function() {
2204 network = bitcoinjs.bitcoin.networks.compcoin;
2205 setHdCoin(71);
2206 },
2207 },
2208 {
2209 name: "CPU - CPUchain",
2210 onSelect: function() {
2211 network = bitcoinjs.bitcoin.networks.cpuchain;
2212 setHdCoin(363);
2213 },
2214 },
2215 {
2216 name: "CRAVE - Crave",
2217 onSelect: function() {
2218 network = bitcoinjs.bitcoin.networks.crave;
2219 setHdCoin(186);
2220 },
2221 },
2222 {
2223 name: "CRW - Crown (Legacy)",
2224 onSelect: function() {
2225 network = bitcoinjs.bitcoin.networks.crown;
2226 setHdCoin(72);
2227 },
2228 },
2229 {
2230 name: "CRW - Crown",
2231 onSelect: function() {
2232 network = bitcoinjs.bitcoin.networks.crown;
2233 setHdCoin(72);
2234 },
2235 },
2236 {
2237 name: "CSC - CasinoCoin",
2238 onSelect: function() {
2239 network = bitcoinjs.bitcoin.networks.bitcoin;
2240 setHdCoin(359);
2241 },
2242 },
2243 {
2244 name: "DASH - Dash",
2245 onSelect: function() {
2246 network = bitcoinjs.bitcoin.networks.dash;
2247 setHdCoin(5);
2248 },
2249 },
2250 {
2251 name: "DASH - Dash Testnet",
2252 onSelect: function() {
2253 network = bitcoinjs.bitcoin.networks.dashtn;
2254 setHdCoin(1);
2255 },
2256 },
2257 {
2258 name: "DFC - Defcoin",
2259 onSelect: function() {
2260 network = bitcoinjs.bitcoin.networks.defcoin;
2261 setHdCoin(1337);
2262 },
2263 },
2264 {
2265 name: "DGB - Digibyte",
2266 onSelect: function() {
2267 network = bitcoinjs.bitcoin.networks.digibyte;
2268 setHdCoin(20);
2269 },
2270 },
2271 {
2272 name: "DGC - Digitalcoin",
2273 onSelect: function() {
2274 network = bitcoinjs.bitcoin.networks.digitalcoin;
2275 setHdCoin(18);
2276 },
2277 },
2278 {
2279 name: "DMD - Diamond",
2280 onSelect: function() {
2281 network = bitcoinjs.bitcoin.networks.diamond;
2282 setHdCoin(152);
2283 },
2284 },
2285 {
2286 name: "DNR - Denarius",
2287 onSelect: function() {
2288 network = bitcoinjs.bitcoin.networks.denarius;
2289 setHdCoin(116);
2290 },
2291 },
2292 {
2293 name: "DOGE - Dogecoin",
2294 onSelect: function() {
2295 network = bitcoinjs.bitcoin.networks.dogecoin;
2296 setHdCoin(3);
2297 },
2298 },
2299 {
2300 name: "DOGEt - Dogecoin Testnet",
2301 onSelect: function() {
2302 network = bitcoinjs.bitcoin.networks.dogecointestnet;
2303 setHdCoin(1);
2304 },
2305 },
2306 {
2307 name: "DXN - DEXON",
2308 onSelect: function() {
2309 network = bitcoinjs.bitcoin.networks.bitcoin;
2310 setHdCoin(237);
2311 },
2312 },
2313 {
2314 name: "ECN - Ecoin",
2315 onSelect: function() {
2316 network = bitcoinjs.bitcoin.networks.ecoin;
2317 setHdCoin(115);
2318 },
2319 },
2320 {
2321 name: "EDRC - Edrcoin",
2322 onSelect: function() {
2323 network = bitcoinjs.bitcoin.networks.edrcoin;
2324 setHdCoin(56);
2325 },
2326 },
2327 {
2328 name: "EFL - Egulden",
2329 onSelect: function() {
2330 network = bitcoinjs.bitcoin.networks.egulden;
2331 setHdCoin(78);
2332 },
2333 },
2334 {
2335 name: "ELA - Elastos",
2336 onSelect: function () {
2337 network = bitcoinjs.bitcoin.networks.elastos;
2338 setHdCoin(2305);
2339 },
2340 },
2341 {
2342 name: "ELLA - Ellaism",
2343 segwitAvailable: false,
2344 onSelect: function() {
2345 network = bitcoinjs.bitcoin.networks.bitcoin;
2346 setHdCoin(163);
2347 },
2348 },
2349 {
2350 name: "EMC2 - Einsteinium",
2351 onSelect: function() {
2352 network = bitcoinjs.bitcoin.networks.einsteinium;
2353 setHdCoin(41);
2354 },
2355 },
2356 {
2357 name: "ERC - Europecoin",
2358 onSelect: function() {
2359 network = bitcoinjs.bitcoin.networks.europecoin;
2360 setHdCoin(151);
2361 },
2362 },
2363 {
2364 name: "EOS - EOSIO",
2365 onSelect: function() {
2366 network = bitcoinjs.bitcoin.networks.bitcoin;
2367 setHdCoin(194);
2368 },
2369 },
2370 {
2371 name: "ESN - Ethersocial Network",
2372 segwitAvailable: false,
2373 onSelect: function() {
2374 network = bitcoinjs.bitcoin.networks.bitcoin;
2375 setHdCoin(31102);
2376 },
2377 },
2378 {
2379 name: "ETC - Ethereum Classic",
2380 segwitAvailable: false,
2381 onSelect: function() {
2382 network = bitcoinjs.bitcoin.networks.bitcoin;
2383 setHdCoin(61);
2384 },
2385 },
2386 {
2387 name: "ETH - Ethereum",
2388 onSelect: function() {
2389 network = bitcoinjs.bitcoin.networks.bitcoin;
2390 setHdCoin(60);
2391 },
2392 },
2393 {
2394 name: "EWT - EnergyWeb",
2395 onSelect: function() {
2396 network = bitcoinjs.bitcoin.networks.bitcoin;
2397 setHdCoin(246);
2398 },
2399 },
2400 {
2401 name: "EXCL - Exclusivecoin",
2402 onSelect: function() {
2403 network = bitcoinjs.bitcoin.networks.exclusivecoin;
2404 setHdCoin(190);
2405 },
2406 },
2407 {
2408 name: "EXCC - ExchangeCoin",
2409 onSelect: function() {
2410 network = bitcoinjs.bitcoin.networks.exchangecoin;
2411 setHdCoin(0);
2412 },
2413 },
2414 {
2415 name: "EXP - Expanse",
2416 segwitAvailable: false,
2417 onSelect: function() {
2418 network = bitcoinjs.bitcoin.networks.bitcoin;
2419 setHdCoin(40);
2420 },
2421 },
2422 {
2423 name: "FIX - FIX",
2424 onSelect: function() {
2425 network = bitcoinjs.bitcoin.networks.fix;
2426 setHdCoin(336);
2427 },
2428 },
2429 {
2430 name: "FIX - FIX Testnet",
2431 onSelect: function() {
2432 network = bitcoinjs.bitcoin.networks.fixtestnet;
2433 setHdCoin(1);
2434 },
2435 },
2436 {
2437 name: "FJC - Fujicoin",
2438 onSelect: function() {
2439 network = bitcoinjs.bitcoin.networks.fujicoin;
2440 setHdCoin(75);
2441 },
2442 },
2443 {
2444 name: "FLASH - Flashcoin",
2445 onSelect: function() {
2446 network = bitcoinjs.bitcoin.networks.flashcoin;
2447 setHdCoin(120);
2448 },
2449 },
2450 {
2451 name: "FRST - Firstcoin",
2452 onSelect: function() {
2453 network = bitcoinjs.bitcoin.networks.firstcoin;
2454 setHdCoin(167);
2455 },
2456 },
2457 {
2458 name: "FTC - Feathercoin",
2459 onSelect: function() {
2460 network = bitcoinjs.bitcoin.networks.feathercoin;
2461 setHdCoin(8);
2462 },
2463 },
2464 {
2465 name: "GAME - GameCredits",
2466 onSelect: function() {
2467 network = bitcoinjs.bitcoin.networks.game;
2468 setHdCoin(101);
2469 },
2470 },
2471 {
2472 name: "GBX - Gobyte",
2473 onSelect: function() {
2474 network = bitcoinjs.bitcoin.networks.gobyte;
2475 setHdCoin(176);
2476 },
2477 },
2478 {
2479 name: "GCR - GCRCoin",
2480 onSelect: function() {
2481 network = bitcoinjs.bitcoin.networks.gcr;
2482 setHdCoin(79);
2483 },
2484 },
2485 {
2486 name: "GRC - Gridcoin",
2487 onSelect: function() {
2488 network = bitcoinjs.bitcoin.networks.gridcoin;
2489 setHdCoin(84);
2490 },
2491 },
2492 {
2493 name: "GRS - Groestlcoin",
2494 onSelect: function() {
2495 network = bitcoinjs.bitcoin.networks.groestlcoin;
2496 setHdCoin(17);
2497 },
2498 },
2499 {
2500 name: "GRS - Groestlcoin Testnet",
2501 onSelect: function() {
2502 network = bitcoinjs.bitcoin.networks.groestlcointestnet;
2503 setHdCoin(1);
2504 },
2505 },
2506 {
2507 name: "HNC - Helleniccoin",
2508 onSelect: function() {
2509 network = bitcoinjs.bitcoin.networks.helleniccoin;
2510 setHdCoin(168);
2511 },
2512 },
2513 {
2514 name: "HUSH - Hush (Legacy)",
2515 onSelect: function() {
2516 network = bitcoinjs.bitcoin.networks.hush;
2517 setHdCoin(197);
2518 },
2519 },
2520 {
2521 name: "HUSH - Hush3",
2522 onSelect: function() {
2523 network = bitcoinjs.bitcoin.networks.hush3;
2524 setHdCoin(197);
2525 },
2526 },
2527 {
2528 name: "INSN - Insane",
2529 onSelect: function() {
2530 network = bitcoinjs.bitcoin.networks.insane;
2531 setHdCoin(68);
2532 },
2533 },
2534 {
2535 name: "IOP - Iop",
2536 onSelect: function() {
2537 network = bitcoinjs.bitcoin.networks.iop;
2538 setHdCoin(66);
2539 },
2540 },
2541 {
2542 name: "IXC - Ixcoin",
2543 onSelect: function() {
2544 network = bitcoinjs.bitcoin.networks.ixcoin;
2545 setHdCoin(86);
2546 },
2547 },
2548 {
2549 name: "JBS - Jumbucks",
2550 onSelect: function() {
2551 network = bitcoinjs.bitcoin.networks.jumbucks;
2552 setHdCoin(26);
2553 },
2554 },
2555 {
2556 name: "KMD - Komodo",
2557 bip49available: false,
2558 onSelect: function() {
2559 network = bitcoinjs.bitcoin.networks.komodo;
2560 setHdCoin(141);
2561 },
2562 },
2563 {
2564 name: "KOBO - Kobocoin",
2565 bip49available: false,
2566 onSelect: function() {
2567 network = bitcoinjs.bitcoin.networks.kobocoin;
2568 setHdCoin(196);
2569 },
2570 },
2571 {
2572 name: "LBC - Library Credits",
2573 onSelect: function() {
2574 network = bitcoinjs.bitcoin.networks.lbry;
2575 setHdCoin(140);
2576 },
2577 },
2578 {
2579 name: "LCC - Litecoincash",
2580 onSelect: function() {
2581 network = bitcoinjs.bitcoin.networks.litecoincash;
2582 setHdCoin(192);
2583 },
2584 },
2585 {
2586 name: "LDCN - Landcoin",
2587 onSelect: function() {
2588 network = bitcoinjs.bitcoin.networks.landcoin;
2589 setHdCoin(63);
2590 },
2591 },
2592 {
2593 name: "LINX - Linx",
2594 onSelect: function() {
2595 network = bitcoinjs.bitcoin.networks.linx;
2596 setHdCoin(114);
2597 },
2598 },
2599 {
2600 name: "LKR - Lkrcoin",
2601 segwitAvailable: false,
2602 onSelect: function() {
2603 network = bitcoinjs.bitcoin.networks.lkrcoin;
2604 setHdCoin(557);
2605 },
2606 },
2607 {
2608 name: "LTC - Litecoin",
2609 onSelect: function() {
2610 network = bitcoinjs.bitcoin.networks.litecoin;
2611 setHdCoin(2);
2612 DOM.litecoinLtubContainer.removeClass("hidden");
2613 },
2614 },
2615 {
2616 name: "LTCt - Litecoin Testnet",
2617 onSelect: function() {
2618 network = bitcoinjs.bitcoin.networks.litecointestnet;
2619 setHdCoin(1);
2620 DOM.litecoinLtubContainer.removeClass("hidden");
2621 },
2622 },
2623 {
2624 name: "LTZ - LitecoinZ",
2625 onSelect: function() {
2626 network = bitcoinjs.bitcoin.networks.litecoinz;
2627 setHdCoin(221);
2628 },
2629 },
2630 {
2631 name: "LYNX - Lynx",
2632 onSelect: function() {
2633 network = bitcoinjs.bitcoin.networks.lynx;
2634 setHdCoin(191);
2635 },
2636 },
2637 {
2638 name: "MAZA - Maza",
2639 onSelect: function() {
2640 network = bitcoinjs.bitcoin.networks.maza;
2641 setHdCoin(13);
2642 },
2643 },
2644 {
2645 name: "MEC - Megacoin",
2646 onSelect: function() {
2647 network = bitcoinjs.bitcoin.networks.megacoin;
2648 setHdCoin(217);
2649 },
2650 },
2651 {
2652 name: "MIX - MIX",
2653 segwitAvailable: false,
2654 onSelect: function() {
2655 network = bitcoinjs.bitcoin.networks.bitcoin;
2656 setHdCoin(76);
2657 },
2658 },
2659 {
2660 name: "MNX - Minexcoin",
2661 onSelect: function() {
2662 network = bitcoinjs.bitcoin.networks.minexcoin;
2663 setHdCoin(182);
2664 },
2665 },
2666 {
2667 name: "MONA - Monacoin",
2668 onSelect: function() {
2669 network = bitcoinjs.bitcoin.networks.monacoin,
2670 setHdCoin(22);
2671 },
2672 },
2673 {
2674 name: "MONK - Monkey Project",
2675 onSelect: function() {
2676 network = bitcoinjs.bitcoin.networks.monkeyproject,
2677 setHdCoin(214);
2678 },
2679 },
2680 {
2681 name: "MUSIC - Musicoin",
2682 segwitAvailable: false,
2683 onSelect: function() {
2684 network = bitcoinjs.bitcoin.networks.bitcoin;
2685 setHdCoin(184);
2686 },
2687 },
2688 {
2689 name: "NAV - Navcoin",
2690 onSelect: function() {
2691 network = bitcoinjs.bitcoin.networks.navcoin;
2692 setHdCoin(130);
2693 },
2694 },
2695 {
2696 name: "NAS - Nebulas",
2697 onSelect: function() {
2698 network = bitcoinjs.bitcoin.networks.bitcoin;
2699 setHdCoin(2718);
2700 },
2701 },
2702 {
2703 name: "NEBL - Neblio",
2704 onSelect: function() {
2705 network = bitcoinjs.bitcoin.networks.neblio;
2706 setHdCoin(146);
2707 },
2708 },
2709 {
2710 name: "NEOS - Neoscoin",
2711 onSelect: function() {
2712 network = bitcoinjs.bitcoin.networks.neoscoin;
2713 setHdCoin(25);
2714 },
2715 },
2716 {
2717 name: "NIX - NIX Platform",
2718 onSelect: function() {
2719 network = bitcoinjs.bitcoin.networks.nix;
2720 setHdCoin(400);
2721 },
2722 },
2723 {
2724 name: "NLG - Gulden",
2725 onSelect: function() {
2726 network = bitcoinjs.bitcoin.networks.gulden;
2727 setHdCoin(87);
2728 },
2729 },
2730 {
2731 name: "NMC - Namecoin",
2732 onSelect: function() {
2733 network = bitcoinjs.bitcoin.networks.namecoin;
2734 setHdCoin(7);
2735 },
2736 },
2737 {
2738 name: "NRG - Energi",
2739 onSelect: function() {
2740 network = bitcoinjs.bitcoin.networks.energi;
2741 setHdCoin(204);
2742 },
2743 },
2744 {
2745 name: "NRO - Neurocoin",
2746 onSelect: function() {
2747 network = bitcoinjs.bitcoin.networks.neurocoin;
2748 setHdCoin(110);
2749 },
2750 },
2751 {
2752 name: "NSR - Nushares",
2753 onSelect: function() {
2754 network = bitcoinjs.bitcoin.networks.nushares;
2755 setHdCoin(11);
2756 },
2757 },
2758 {
2759 name: "NYC - Newyorkc",
2760 onSelect: function() {
2761 network = bitcoinjs.bitcoin.networks.newyorkc;
2762 setHdCoin(179);
2763 },
2764 },
2765 {
2766 name: "NVC - Novacoin",
2767 onSelect: function() {
2768 network = bitcoinjs.bitcoin.networks.novacoin;
2769 setHdCoin(50);
2770 },
2771 },
2772 {
2773 name: "OK - Okcash",
2774 onSelect: function() {
2775 network = bitcoinjs.bitcoin.networks.okcash;
2776 setHdCoin(69);
2777 },
2778 },
2779 {
2780 name: "OMNI - Omnicore",
2781 onSelect: function() {
2782 network = bitcoinjs.bitcoin.networks.omnicore;
2783 setHdCoin(200);
2784 },
2785 },
2786 {
2787 name: "ONION - DeepOnion",
2788 onSelect: function() {
2789 network = bitcoinjs.bitcoin.networks.deeponion;
2790 setHdCoin(305);
2791 },
2792 },
2793 {
2794 name: "ONX - Onixcoin",
2795 onSelect: function() {
2796 network = bitcoinjs.bitcoin.networks.onixcoin;
2797 setHdCoin(174);
2798 },
2799 },
2800 {
2801 name: "PHR - Phore",
2802 onSelect: function() {
2803 network = bitcoinjs.bitcoin.networks.phore;
2804 setHdCoin(444);
2805 },
2806 },
2807 {
2808 name: "PINK - Pinkcoin",
2809 onSelect: function() {
2810 network = bitcoinjs.bitcoin.networks.pinkcoin;
2811 setHdCoin(117);
2812 },
2813 },
2814 {
2815 name: "PIRL - Pirl",
2816 segwitAvailable: false,
2817 onSelect: function() {
2818 network = bitcoinjs.bitcoin.networks.bitcoin;
2819 setHdCoin(164);
2820 },
2821 },
2822 {
2823 name: "PIVX - PIVX",
2824 onSelect: function() {
2825 network = bitcoinjs.bitcoin.networks.pivx;
2826 setHdCoin(119);
2827 },
2828 },
2829 {
2830 name: "PIVX - PIVX Testnet",
2831 onSelect: function() {
2832 network = bitcoinjs.bitcoin.networks.pivxtestnet;
2833 setHdCoin(1);
2834 },
2835 },
2836 {
2837 name: "POA - Poa",
2838 segwitAvailable: false,
2839 onSelect: function() {
2840 network = bitcoinjs.bitcoin.networks.bitcoin;
2841 setHdCoin(178);
2842 },
2843 },
2844 {
2845 name: "POSW - POSWcoin",
2846 onSelect: function() {
2847 network = bitcoinjs.bitcoin.networks.poswcoin;
2848 setHdCoin(47);
2849 },
2850 },
2851 {
2852 name: "POT - Potcoin",
2853 onSelect: function() {
2854 network = bitcoinjs.bitcoin.networks.potcoin;
2855 setHdCoin(81);
2856 },
2857 },
2858 {
2859 name: "PPC - Peercoin",
2860 onSelect: function() {
2861 network = bitcoinjs.bitcoin.networks.peercoin;
2862 setHdCoin(6);
2863 },
2864 },
2865 {
2866 name: "PRJ - ProjectCoin",
2867 onSelect: function() {
2868 network = bitcoinjs.bitcoin.networks.projectcoin;
2869 setHdCoin(533);
2870 },
2871 },
2872 {
2873 name: "PSB - Pesobit",
2874 onSelect: function() {
2875 network = bitcoinjs.bitcoin.networks.pesobit;
2876 setHdCoin(62);
2877 },
2878 },
2879 {
2880 name: "PUT - Putincoin",
2881 onSelect: function() {
2882 network = bitcoinjs.bitcoin.networks.putincoin;
2883 setHdCoin(122);
2884 },
2885 },
2886 {
2887 name: "RPD - Rapids",
2888 onSelect: function() {
2889 network = bitcoinjs.bitcoin.networks.rapids;
2890 setHdCoin(320);
2891 },
2892 },
2893 {
2894 name: "RVN - Ravencoin",
2895 onSelect: function() {
2896 network = bitcoinjs.bitcoin.networks.ravencoin;
2897 setHdCoin(175);
2898 },
2899 },
2900 {
2901 name: "RBY - Rubycoin",
2902 onSelect: function() {
2903 network = bitcoinjs.bitcoin.networks.rubycoin;
2904 setHdCoin(16);
2905 },
2906 },
2907 {
2908 name: "RDD - Reddcoin",
2909 onSelect: function() {
2910 network = bitcoinjs.bitcoin.networks.reddcoin;
2911 setHdCoin(4);
2912 },
2913 },
2914 {
2915 name: "RVR - RevolutionVR",
2916 onSelect: function() {
2917 network = bitcoinjs.bitcoin.networks.revolutionvr;
2918 setHdCoin(129);
2919 },
2920 },
2921 {
2922 name: "SAFE - Safecoin",
2923 onSelect: function() {
2924 network = bitcoinjs.bitcoin.networks.safecoin;
2925 setHdCoin(19165);
2926 },
2927 },
2928 {
2929 name: "SLS - Salus",
2930 onSelect: function() {
2931 network = bitcoinjs.bitcoin.networks.salus;
2932 setHdCoin(63);
2933 },
2934 },
2935 {
2936 name: "SDC - ShadowCash",
2937 onSelect: function() {
2938 network = bitcoinjs.bitcoin.networks.shadow;
2939 setHdCoin(35);
2940 },
2941 },
2942 {
2943 name: "SDC - ShadowCash Testnet",
2944 onSelect: function() {
2945 network = bitcoinjs.bitcoin.networks.shadowtn;
2946 setHdCoin(1);
2947 },
2948 },
2949 {
2950 name: "SLM - Slimcoin",
2951 onSelect: function() {
2952 network = bitcoinjs.bitcoin.networks.slimcoin;
2953 setHdCoin(63);
2954 },
2955 },
2956 {
2957 name: "SLM - Slimcoin Testnet",
2958 onSelect: function() {
2959 network = bitcoinjs.bitcoin.networks.slimcointn;
2960 setHdCoin(111);
2961 },
2962 },
2963 {
2964 name: "SLP - Simple Ledger Protocol",
2965 onSelect: function() {
2966 DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
2967 setHdCoin(245);
2968 },
2969 },
2970 {
2971 name: "SLR - Solarcoin",
2972 onSelect: function() {
2973 network = bitcoinjs.bitcoin.networks.solarcoin;
2974 setHdCoin(58);
2975 },
2976 },
2977 {
2978 name: "SMLY - Smileycoin",
2979 onSelect: function() {
2980 network = bitcoinjs.bitcoin.networks.smileycoin;
2981 setHdCoin(59);
2982 },
2983 },
2984 {
2985 name: "STASH - Stash",
2986 onSelect: function() {
2987 network = bitcoinjs.bitcoin.networks.stash;
2988 setHdCoin(0xC0C0);
2989 },
2990 },
2991 {
2992 name: "STASH - Stash Testnet",
2993 onSelect: function() {
2994 network = bitcoinjs.bitcoin.networks.stashtn;
2995 setHdCoin(0xCAFE);
2996 },
2997 },
2998 {
2999 name: "STRAT - Stratis",
3000 onSelect: function() {
3001 network = bitcoinjs.bitcoin.networks.stratis;
3002 setHdCoin(105);
3003 },
3004 },
3005 {
3006 name: "TSTRAT - Stratis Testnet",
3007 onSelect: function() {
3008 network = bitcoinjs.bitcoin.networks.stratistest;
3009 setHdCoin(105);
3010 },
3011 },
3012 {
3013 name: "SYS - Syscoin",
3014 onSelect: function() {
3015 network = bitcoinjs.bitcoin.networks.syscoin;
3016 setHdCoin(57);
3017 },
3018 },
3019 {
3020 name: "THC - Hempcoin",
3021 onSelect: function() {
3022 network = bitcoinjs.bitcoin.networks.hempcoin;
3023 setHdCoin(113);
3024 },
3025 },
3026 {
3027 name: "THT - Thought",
3028 onSelect: function() {
3029 network = bitcoinjs.bitcoin.networks.thought;
3030 setHdCoin(1618);
3031 },
3032 },
3033 {
3034 name: "TOA - Toa",
3035 onSelect: function() {
3036 network = bitcoinjs.bitcoin.networks.toa;
3037 setHdCoin(159);
3038 },
3039 },
3040 {
3041 name: "TWINS - TWINS",
3042 onSelect: function() {
3043 network = bitcoinjs.bitcoin.networks.twins;
3044 setHdCoin(970);
3045 },
3046 },
3047 {
3048 name: "TWINS - TWINS Testnet",
3049 onSelect: function() {
3050 network = bitcoinjs.bitcoin.networks.twinstestnet;
3051 setHdCoin(1);
3052 },
3053 },
3054 {
3055 name: "USC - Ultimatesecurecash",
3056 onSelect: function() {
3057 network = bitcoinjs.bitcoin.networks.ultimatesecurecash;
3058 setHdCoin(112);
3059 },
3060 },
3061 {
3062 name: "USNBT - NuBits",
3063 onSelect: function() {
3064 network = bitcoinjs.bitcoin.networks.nubits;
3065 setHdCoin(12);
3066 },
3067 },
3068 {
3069 name: "UNO - Unobtanium",
3070 onSelect: function() {
3071 network = bitcoinjs.bitcoin.networks.unobtanium;
3072 setHdCoin(92);
3073 },
3074 },
3075 {
3076 name: "VASH - Vpncoin",
3077 onSelect: function() {
3078 network = bitcoinjs.bitcoin.networks.vpncoin;
3079 setHdCoin(33);
3080 },
3081 },
3082 {
3083 name: "VET - VeChain",
3084 onSelect: function() {
3085 network = bitcoinjs.bitcoin.networks.bitcoin;
3086 setHdCoin(818);
3087 },
3088 },
3089 {
3090 name: "VIA - Viacoin",
3091 onSelect: function() {
3092 network = bitcoinjs.bitcoin.networks.viacoin;
3093 setHdCoin(14);
3094 },
3095 },
3096 {
3097 name: "VIA - Viacoin Testnet",
3098 onSelect: function() {
3099 network = bitcoinjs.bitcoin.networks.viacointestnet;
3100 setHdCoin(1);
3101 },
3102 },
3103 {
3104 name: "VIVO - Vivo",
3105 onSelect: function() {
3106 network = bitcoinjs.bitcoin.networks.vivo;
3107 setHdCoin(166);
3108 },
3109 },
3110 {
3111 name: "VTC - Vertcoin",
3112 onSelect: function() {
3113 network = bitcoinjs.bitcoin.networks.vertcoin;
3114 setHdCoin(28);
3115 },
3116 },
3117 {
3118 name: "WGR - Wagerr",
3119 onSelect: function() {
3120 network = bitcoinjs.bitcoin.networks.wagerr;
3121 setHdCoin(7825266);
3122 },
3123 },
3124 {
3125 name: "WC - Wincoin",
3126 onSelect: function() {
3127 network = bitcoinjs.bitcoin.networks.wincoin;
3128 setHdCoin(181);
3129 },
3130 },
3131 {
3132 name: "XAX - Artax",
3133 onSelect: function() {
3134 network = bitcoinjs.bitcoin.networks.artax;
3135 setHdCoin(219);
3136 },
3137 },
3138 {
3139 name: "XBC - Bitcoinplus",
3140 onSelect: function() {
3141 network = bitcoinjs.bitcoin.networks.bitcoinplus;
3142 setHdCoin(65);
3143 },
3144 },
3145 {
3146 name: "XLM - Stellar",
3147 onSelect: function() {
3148 network = stellarUtil.dummyNetwork;
3149 setHdCoin(148);
3150 },
3151 },
3152 {
3153 name: "XMY - Myriadcoin",
3154 onSelect: function() {
3155 network = bitcoinjs.bitcoin.networks.myriadcoin;
3156 setHdCoin(90);
3157 },
3158 },
3159 {
3160 name: "XRP - Ripple",
3161 onSelect: function() {
3162 network = bitcoinjs.bitcoin.networks.bitcoin;
3163 setHdCoin(144);
3164 },
3165 },
3166 {
3167 name: "XVC - Vcash",
3168 onSelect: function() {
3169 network = bitcoinjs.bitcoin.networks.vcash;
3170 setHdCoin(127);
3171 },
3172 },
3173 {
3174 name: "XVG - Verge",
3175 onSelect: function() {
3176 network = bitcoinjs.bitcoin.networks.verge;
3177 setHdCoin(77);
3178 },
3179 },
3180 {
3181 name: "XUEZ - Xuez",
3182 segwitAvailable: false,
3183 onSelect: function() {
3184 network = bitcoinjs.bitcoin.networks.xuez;
3185 setHdCoin(225);
3186 },
3187 },
3188 {
3189 name: "XWC - Whitecoin",
3190 onSelect: function() {
3191 network = bitcoinjs.bitcoin.networks.whitecoin;
3192 setHdCoin(155);
3193 },
3194 },
3195 {
3196 name: "XZC - Zcoin",
3197 onSelect: function() {
3198 network = bitcoinjs.bitcoin.networks.zcoin;
3199 setHdCoin(136);
3200 },
3201 },
3202 {
3203 name: "ZCL - Zclassic",
3204 onSelect: function() {
3205 network = bitcoinjs.bitcoin.networks.zclassic;
3206 setHdCoin(147);
3207 },
3208 },
3209 {
3210 name: "ZEC - Zcash",
3211 onSelect: function() {
3212 network = bitcoinjs.bitcoin.networks.zcash;
3213 setHdCoin(133);
3214 },
3215 },
3216 {
3217 name: "ZEN - Horizen",
3218 onSelect: function() {
3219 network = bitcoinjs.bitcoin.networks.zencash;
3220 setHdCoin(121);
3221 },
3222 },
3223 ]
3224
3225 var clients = [
3226 {
3227 name: "Bitcoin Core",
3228 onSelect: function() {
3229 DOM.bip32path.val("m/0'/0'");
3230 DOM.hardenedAddresses.prop('checked', true);
3231 },
3232 },
3233 {
3234 name: "blockchain.info",
3235 onSelect: function() {
3236 DOM.bip32path.val("m/44'/0'/0'");
3237 DOM.hardenedAddresses.prop('checked', false);
3238 },
3239 },
3240 {
3241 name: "MultiBit HD",
3242 onSelect: function() {
3243 DOM.bip32path.val("m/0'/0");
3244 DOM.hardenedAddresses.prop('checked', false);
3245 },
3246 },
3247 {
3248 name: "Coinomi, Ledger",
3249 onSelect: function() {
3250 DOM.bip32path.val("m/44'/"+DOM.bip44coin.val()+"'/0'");
3251 DOM.hardenedAddresses.prop('checked', false);
3252 },
3253 }
3254 ]
3255
3256 // ELA - Elastos functions - begin
3257 function displayBip44InfoForELA() {
3258 if (!isELA()) {
3259 return;
3260 }
3261
3262 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
3263 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
3264
3265 // Calculate the account extended keys
3266 var accountXprv = elastosjs.getAccountExtendedPrivateKey(seed, coin, account);
3267 var accountXpub = elastosjs.getAccountExtendedPublicKey(seed, coin, account);
3268
3269 // Display the extended keys
3270 DOM.bip44accountXprv.val(accountXprv);
3271 DOM.bip44accountXpub.val(accountXpub);
3272 }
3273
3274 function displayBip32InfoForELA() {
3275 if (!isELA()) {
3276 return;
3277 }
3278
3279 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
3280 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
3281 var change = parseIntNoNaN(DOM.bip44change.val(), 0);
3282
3283 DOM.extendedPrivKey.val(elastosjs.getBip32ExtendedPrivateKey(seed, coin, account, change));
3284 DOM.extendedPubKey.val(elastosjs.getBip32ExtendedPublicKey(seed, coin, account, change));
3285
3286 // Display the addresses and privkeys
3287 clearAddressesList();
3288 var initialAddressCount = parseInt(DOM.rowsToAdd.val());
3289 displayAddresses(0, initialAddressCount);
3290 }
3291
3292 function calcAddressForELA(seed, coin, account, change, index) {
3293 if (!isELA()) {
3294 return;
3295 }
3296
3297 var publicKey = elastosjs.getDerivedPublicKey(elastosjs.getMasterPublicKey(seed), change, index);
3298 return {
3299 privateKey: elastosjs.getDerivedPrivateKey(seed, coin, account, change, index),
3300 publicKey: publicKey,
3301 address: elastosjs.getAddress(publicKey.toString('hex'))
3302 };
3303 }
3304 // ELA - Elastos functions - end
3305
3306 init();
3307
3308 })();