]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - src/js/index.js
Add bitcoin regtest params
[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 RegTest",
2104 onSelect: function() {
2105 network = bitcoinjs.bitcoin.networks.regtest;
2106 // Using hd coin value 1 based on bip44_coin_type
2107 // https://github.com/chaintope/bitcoinrb/blob/f1014406f6b8f9b4edcecedc18df70c80df06f11/lib/bitcoin/chainparams/regtest.yml
2108 setHdCoin(1);
2109 },
2110 },
2111 {
2112 name: "BTC - Bitcoin Testnet",
2113 onSelect: function() {
2114 network = bitcoinjs.bitcoin.networks.testnet;
2115 setHdCoin(1);
2116 },
2117 },
2118 {
2119 name: "BITG - Bitcoin Green",
2120 onSelect: function() {
2121 network = bitcoinjs.bitcoin.networks.bitcoingreen;
2122 setHdCoin(222);
2123 },
2124 },
2125 {
2126 name: "BTCP - Bitcoin Private",
2127 onSelect: function() {
2128 network = bitcoinjs.bitcoin.networks.bitcoinprivate;
2129 setHdCoin(183);
2130 },
2131 },
2132 {
2133 name: "BSV - BitcoinSV",
2134 onSelect: function() {
2135 network = bitcoinjs.bitcoin.networks.bitcoinsv;
2136 setHdCoin(236);
2137 },
2138 },
2139 {
2140 name: "BTCZ - Bitcoinz",
2141 onSelect: function() {
2142 network = bitcoinjs.bitcoin.networks.bitcoinz;
2143 setHdCoin(177);
2144 },
2145 },
2146 {
2147 name: "BTDX - BitCloud",
2148 onSelect: function() {
2149 network = bitcoinjs.bitcoin.networks.bitcloud;
2150 setHdCoin(218);
2151 },
2152 },
2153 {
2154 name: "BTG - Bitcoin Gold",
2155 onSelect: function() {
2156 network = bitcoinjs.bitcoin.networks.bgold;
2157 setHdCoin(156);
2158 },
2159 },
2160 {
2161 name: "BTX - Bitcore",
2162 onSelect: function() {
2163 network = bitcoinjs.bitcoin.networks.bitcore;
2164 setHdCoin(160);
2165 },
2166 },
2167 {
2168 name: "CCN - Cannacoin",
2169 onSelect: function() {
2170 network = bitcoinjs.bitcoin.networks.cannacoin;
2171 setHdCoin(19);
2172 },
2173 },
2174 {
2175 name: "CESC - Cryptoescudo",
2176 onSelect: function() {
2177 network = bitcoinjs.bitcoin.networks.cannacoin;
2178 setHdCoin(111);
2179 },
2180 },
2181 {
2182 name: "CDN - Canadaecoin",
2183 onSelect: function() {
2184 network = bitcoinjs.bitcoin.networks.canadaecoin;
2185 setHdCoin(34);
2186 },
2187 },
2188 {
2189 name: "CLAM - Clams",
2190 onSelect: function() {
2191 network = bitcoinjs.bitcoin.networks.clam;
2192 setHdCoin(23);
2193 },
2194 },
2195 {
2196 name: "CLO - Callisto",
2197 segwitAvailable: false,
2198 onSelect: function() {
2199 network = bitcoinjs.bitcoin.networks.bitcoin;
2200 setHdCoin(820);
2201 },
2202 },
2203 {
2204 name: "CLUB - Clubcoin",
2205 onSelect: function() {
2206 network = bitcoinjs.bitcoin.networks.clubcoin;
2207 setHdCoin(79);
2208 },
2209 },
2210 {
2211 name: "CMP - Compcoin",
2212 onSelect: function() {
2213 network = bitcoinjs.bitcoin.networks.compcoin;
2214 setHdCoin(71);
2215 },
2216 },
2217 {
2218 name: "CPU - CPUchain",
2219 onSelect: function() {
2220 network = bitcoinjs.bitcoin.networks.cpuchain;
2221 setHdCoin(363);
2222 },
2223 },
2224 {
2225 name: "CRAVE - Crave",
2226 onSelect: function() {
2227 network = bitcoinjs.bitcoin.networks.crave;
2228 setHdCoin(186);
2229 },
2230 },
2231 {
2232 name: "CRW - Crown (Legacy)",
2233 onSelect: function() {
2234 network = bitcoinjs.bitcoin.networks.crown;
2235 setHdCoin(72);
2236 },
2237 },
2238 {
2239 name: "CRW - Crown",
2240 onSelect: function() {
2241 network = bitcoinjs.bitcoin.networks.crown;
2242 setHdCoin(72);
2243 },
2244 },
2245 {
2246 name: "CSC - CasinoCoin",
2247 onSelect: function() {
2248 network = bitcoinjs.bitcoin.networks.bitcoin;
2249 setHdCoin(359);
2250 },
2251 },
2252 {
2253 name: "DASH - Dash",
2254 onSelect: function() {
2255 network = bitcoinjs.bitcoin.networks.dash;
2256 setHdCoin(5);
2257 },
2258 },
2259 {
2260 name: "DASH - Dash Testnet",
2261 onSelect: function() {
2262 network = bitcoinjs.bitcoin.networks.dashtn;
2263 setHdCoin(1);
2264 },
2265 },
2266 {
2267 name: "DFC - Defcoin",
2268 onSelect: function() {
2269 network = bitcoinjs.bitcoin.networks.defcoin;
2270 setHdCoin(1337);
2271 },
2272 },
2273 {
2274 name: "DGB - Digibyte",
2275 onSelect: function() {
2276 network = bitcoinjs.bitcoin.networks.digibyte;
2277 setHdCoin(20);
2278 },
2279 },
2280 {
2281 name: "DGC - Digitalcoin",
2282 onSelect: function() {
2283 network = bitcoinjs.bitcoin.networks.digitalcoin;
2284 setHdCoin(18);
2285 },
2286 },
2287 {
2288 name: "DMD - Diamond",
2289 onSelect: function() {
2290 network = bitcoinjs.bitcoin.networks.diamond;
2291 setHdCoin(152);
2292 },
2293 },
2294 {
2295 name: "DNR - Denarius",
2296 onSelect: function() {
2297 network = bitcoinjs.bitcoin.networks.denarius;
2298 setHdCoin(116);
2299 },
2300 },
2301 {
2302 name: "DOGE - Dogecoin",
2303 onSelect: function() {
2304 network = bitcoinjs.bitcoin.networks.dogecoin;
2305 setHdCoin(3);
2306 },
2307 },
2308 {
2309 name: "DOGEt - Dogecoin Testnet",
2310 onSelect: function() {
2311 network = bitcoinjs.bitcoin.networks.dogecointestnet;
2312 setHdCoin(1);
2313 },
2314 },
2315 {
2316 name: "DXN - DEXON",
2317 onSelect: function() {
2318 network = bitcoinjs.bitcoin.networks.bitcoin;
2319 setHdCoin(237);
2320 },
2321 },
2322 {
2323 name: "ECN - Ecoin",
2324 onSelect: function() {
2325 network = bitcoinjs.bitcoin.networks.ecoin;
2326 setHdCoin(115);
2327 },
2328 },
2329 {
2330 name: "EDRC - Edrcoin",
2331 onSelect: function() {
2332 network = bitcoinjs.bitcoin.networks.edrcoin;
2333 setHdCoin(56);
2334 },
2335 },
2336 {
2337 name: "EFL - Egulden",
2338 onSelect: function() {
2339 network = bitcoinjs.bitcoin.networks.egulden;
2340 setHdCoin(78);
2341 },
2342 },
2343 {
2344 name: "ELA - Elastos",
2345 onSelect: function () {
2346 network = bitcoinjs.bitcoin.networks.elastos;
2347 setHdCoin(2305);
2348 },
2349 },
2350 {
2351 name: "ELLA - Ellaism",
2352 segwitAvailable: false,
2353 onSelect: function() {
2354 network = bitcoinjs.bitcoin.networks.bitcoin;
2355 setHdCoin(163);
2356 },
2357 },
2358 {
2359 name: "EMC2 - Einsteinium",
2360 onSelect: function() {
2361 network = bitcoinjs.bitcoin.networks.einsteinium;
2362 setHdCoin(41);
2363 },
2364 },
2365 {
2366 name: "ERC - Europecoin",
2367 onSelect: function() {
2368 network = bitcoinjs.bitcoin.networks.europecoin;
2369 setHdCoin(151);
2370 },
2371 },
2372 {
2373 name: "EOS - EOSIO",
2374 onSelect: function() {
2375 network = bitcoinjs.bitcoin.networks.bitcoin;
2376 setHdCoin(194);
2377 },
2378 },
2379 {
2380 name: "ESN - Ethersocial Network",
2381 segwitAvailable: false,
2382 onSelect: function() {
2383 network = bitcoinjs.bitcoin.networks.bitcoin;
2384 setHdCoin(31102);
2385 },
2386 },
2387 {
2388 name: "ETC - Ethereum Classic",
2389 segwitAvailable: false,
2390 onSelect: function() {
2391 network = bitcoinjs.bitcoin.networks.bitcoin;
2392 setHdCoin(61);
2393 },
2394 },
2395 {
2396 name: "ETH - Ethereum",
2397 onSelect: function() {
2398 network = bitcoinjs.bitcoin.networks.bitcoin;
2399 setHdCoin(60);
2400 },
2401 },
2402 {
2403 name: "EWT - EnergyWeb",
2404 onSelect: function() {
2405 network = bitcoinjs.bitcoin.networks.bitcoin;
2406 setHdCoin(246);
2407 },
2408 },
2409 {
2410 name: "EXCL - Exclusivecoin",
2411 onSelect: function() {
2412 network = bitcoinjs.bitcoin.networks.exclusivecoin;
2413 setHdCoin(190);
2414 },
2415 },
2416 {
2417 name: "EXCC - ExchangeCoin",
2418 onSelect: function() {
2419 network = bitcoinjs.bitcoin.networks.exchangecoin;
2420 setHdCoin(0);
2421 },
2422 },
2423 {
2424 name: "EXP - Expanse",
2425 segwitAvailable: false,
2426 onSelect: function() {
2427 network = bitcoinjs.bitcoin.networks.bitcoin;
2428 setHdCoin(40);
2429 },
2430 },
2431 {
2432 name: "FIX - FIX",
2433 onSelect: function() {
2434 network = bitcoinjs.bitcoin.networks.fix;
2435 setHdCoin(336);
2436 },
2437 },
2438 {
2439 name: "FIX - FIX Testnet",
2440 onSelect: function() {
2441 network = bitcoinjs.bitcoin.networks.fixtestnet;
2442 setHdCoin(1);
2443 },
2444 },
2445 {
2446 name: "FJC - Fujicoin",
2447 onSelect: function() {
2448 network = bitcoinjs.bitcoin.networks.fujicoin;
2449 setHdCoin(75);
2450 },
2451 },
2452 {
2453 name: "FLASH - Flashcoin",
2454 onSelect: function() {
2455 network = bitcoinjs.bitcoin.networks.flashcoin;
2456 setHdCoin(120);
2457 },
2458 },
2459 {
2460 name: "FRST - Firstcoin",
2461 onSelect: function() {
2462 network = bitcoinjs.bitcoin.networks.firstcoin;
2463 setHdCoin(167);
2464 },
2465 },
2466 {
2467 name: "FTC - Feathercoin",
2468 onSelect: function() {
2469 network = bitcoinjs.bitcoin.networks.feathercoin;
2470 setHdCoin(8);
2471 },
2472 },
2473 {
2474 name: "GAME - GameCredits",
2475 onSelect: function() {
2476 network = bitcoinjs.bitcoin.networks.game;
2477 setHdCoin(101);
2478 },
2479 },
2480 {
2481 name: "GBX - Gobyte",
2482 onSelect: function() {
2483 network = bitcoinjs.bitcoin.networks.gobyte;
2484 setHdCoin(176);
2485 },
2486 },
2487 {
2488 name: "GCR - GCRCoin",
2489 onSelect: function() {
2490 network = bitcoinjs.bitcoin.networks.gcr;
2491 setHdCoin(79);
2492 },
2493 },
2494 {
2495 name: "GRC - Gridcoin",
2496 onSelect: function() {
2497 network = bitcoinjs.bitcoin.networks.gridcoin;
2498 setHdCoin(84);
2499 },
2500 },
2501 {
2502 name: "GRS - Groestlcoin",
2503 onSelect: function() {
2504 network = bitcoinjs.bitcoin.networks.groestlcoin;
2505 setHdCoin(17);
2506 },
2507 },
2508 {
2509 name: "GRS - Groestlcoin Testnet",
2510 onSelect: function() {
2511 network = bitcoinjs.bitcoin.networks.groestlcointestnet;
2512 setHdCoin(1);
2513 },
2514 },
2515 {
2516 name: "HNC - Helleniccoin",
2517 onSelect: function() {
2518 network = bitcoinjs.bitcoin.networks.helleniccoin;
2519 setHdCoin(168);
2520 },
2521 },
2522 {
2523 name: "HUSH - Hush (Legacy)",
2524 onSelect: function() {
2525 network = bitcoinjs.bitcoin.networks.hush;
2526 setHdCoin(197);
2527 },
2528 },
2529 {
2530 name: "HUSH - Hush3",
2531 onSelect: function() {
2532 network = bitcoinjs.bitcoin.networks.hush3;
2533 setHdCoin(197);
2534 },
2535 },
2536 {
2537 name: "INSN - Insane",
2538 onSelect: function() {
2539 network = bitcoinjs.bitcoin.networks.insane;
2540 setHdCoin(68);
2541 },
2542 },
2543 {
2544 name: "IOP - Iop",
2545 onSelect: function() {
2546 network = bitcoinjs.bitcoin.networks.iop;
2547 setHdCoin(66);
2548 },
2549 },
2550 {
2551 name: "IXC - Ixcoin",
2552 onSelect: function() {
2553 network = bitcoinjs.bitcoin.networks.ixcoin;
2554 setHdCoin(86);
2555 },
2556 },
2557 {
2558 name: "JBS - Jumbucks",
2559 onSelect: function() {
2560 network = bitcoinjs.bitcoin.networks.jumbucks;
2561 setHdCoin(26);
2562 },
2563 },
2564 {
2565 name: "KMD - Komodo",
2566 bip49available: false,
2567 onSelect: function() {
2568 network = bitcoinjs.bitcoin.networks.komodo;
2569 setHdCoin(141);
2570 },
2571 },
2572 {
2573 name: "KOBO - Kobocoin",
2574 bip49available: false,
2575 onSelect: function() {
2576 network = bitcoinjs.bitcoin.networks.kobocoin;
2577 setHdCoin(196);
2578 },
2579 },
2580 {
2581 name: "LBC - Library Credits",
2582 onSelect: function() {
2583 network = bitcoinjs.bitcoin.networks.lbry;
2584 setHdCoin(140);
2585 },
2586 },
2587 {
2588 name: "LCC - Litecoincash",
2589 onSelect: function() {
2590 network = bitcoinjs.bitcoin.networks.litecoincash;
2591 setHdCoin(192);
2592 },
2593 },
2594 {
2595 name: "LDCN - Landcoin",
2596 onSelect: function() {
2597 network = bitcoinjs.bitcoin.networks.landcoin;
2598 setHdCoin(63);
2599 },
2600 },
2601 {
2602 name: "LINX - Linx",
2603 onSelect: function() {
2604 network = bitcoinjs.bitcoin.networks.linx;
2605 setHdCoin(114);
2606 },
2607 },
2608 {
2609 name: "LKR - Lkrcoin",
2610 segwitAvailable: false,
2611 onSelect: function() {
2612 network = bitcoinjs.bitcoin.networks.lkrcoin;
2613 setHdCoin(557);
2614 },
2615 },
2616 {
2617 name: "LTC - Litecoin",
2618 onSelect: function() {
2619 network = bitcoinjs.bitcoin.networks.litecoin;
2620 setHdCoin(2);
2621 DOM.litecoinLtubContainer.removeClass("hidden");
2622 },
2623 },
2624 {
2625 name: "LTCt - Litecoin Testnet",
2626 onSelect: function() {
2627 network = bitcoinjs.bitcoin.networks.litecointestnet;
2628 setHdCoin(1);
2629 DOM.litecoinLtubContainer.removeClass("hidden");
2630 },
2631 },
2632 {
2633 name: "LTZ - LitecoinZ",
2634 onSelect: function() {
2635 network = bitcoinjs.bitcoin.networks.litecoinz;
2636 setHdCoin(221);
2637 },
2638 },
2639 {
2640 name: "LYNX - Lynx",
2641 onSelect: function() {
2642 network = bitcoinjs.bitcoin.networks.lynx;
2643 setHdCoin(191);
2644 },
2645 },
2646 {
2647 name: "MAZA - Maza",
2648 onSelect: function() {
2649 network = bitcoinjs.bitcoin.networks.maza;
2650 setHdCoin(13);
2651 },
2652 },
2653 {
2654 name: "MEC - Megacoin",
2655 onSelect: function() {
2656 network = bitcoinjs.bitcoin.networks.megacoin;
2657 setHdCoin(217);
2658 },
2659 },
2660 {
2661 name: "MIX - MIX",
2662 segwitAvailable: false,
2663 onSelect: function() {
2664 network = bitcoinjs.bitcoin.networks.bitcoin;
2665 setHdCoin(76);
2666 },
2667 },
2668 {
2669 name: "MNX - Minexcoin",
2670 onSelect: function() {
2671 network = bitcoinjs.bitcoin.networks.minexcoin;
2672 setHdCoin(182);
2673 },
2674 },
2675 {
2676 name: "MONA - Monacoin",
2677 onSelect: function() {
2678 network = bitcoinjs.bitcoin.networks.monacoin,
2679 setHdCoin(22);
2680 },
2681 },
2682 {
2683 name: "MONK - Monkey Project",
2684 onSelect: function() {
2685 network = bitcoinjs.bitcoin.networks.monkeyproject,
2686 setHdCoin(214);
2687 },
2688 },
2689 {
2690 name: "MUSIC - Musicoin",
2691 segwitAvailable: false,
2692 onSelect: function() {
2693 network = bitcoinjs.bitcoin.networks.bitcoin;
2694 setHdCoin(184);
2695 },
2696 },
2697 {
2698 name: "NAV - Navcoin",
2699 onSelect: function() {
2700 network = bitcoinjs.bitcoin.networks.navcoin;
2701 setHdCoin(130);
2702 },
2703 },
2704 {
2705 name: "NAS - Nebulas",
2706 onSelect: function() {
2707 network = bitcoinjs.bitcoin.networks.bitcoin;
2708 setHdCoin(2718);
2709 },
2710 },
2711 {
2712 name: "NEBL - Neblio",
2713 onSelect: function() {
2714 network = bitcoinjs.bitcoin.networks.neblio;
2715 setHdCoin(146);
2716 },
2717 },
2718 {
2719 name: "NEOS - Neoscoin",
2720 onSelect: function() {
2721 network = bitcoinjs.bitcoin.networks.neoscoin;
2722 setHdCoin(25);
2723 },
2724 },
2725 {
2726 name: "NIX - NIX Platform",
2727 onSelect: function() {
2728 network = bitcoinjs.bitcoin.networks.nix;
2729 setHdCoin(400);
2730 },
2731 },
2732 {
2733 name: "NLG - Gulden",
2734 onSelect: function() {
2735 network = bitcoinjs.bitcoin.networks.gulden;
2736 setHdCoin(87);
2737 },
2738 },
2739 {
2740 name: "NMC - Namecoin",
2741 onSelect: function() {
2742 network = bitcoinjs.bitcoin.networks.namecoin;
2743 setHdCoin(7);
2744 },
2745 },
2746 {
2747 name: "NRG - Energi",
2748 onSelect: function() {
2749 network = bitcoinjs.bitcoin.networks.energi;
2750 setHdCoin(204);
2751 },
2752 },
2753 {
2754 name: "NRO - Neurocoin",
2755 onSelect: function() {
2756 network = bitcoinjs.bitcoin.networks.neurocoin;
2757 setHdCoin(110);
2758 },
2759 },
2760 {
2761 name: "NSR - Nushares",
2762 onSelect: function() {
2763 network = bitcoinjs.bitcoin.networks.nushares;
2764 setHdCoin(11);
2765 },
2766 },
2767 {
2768 name: "NYC - Newyorkc",
2769 onSelect: function() {
2770 network = bitcoinjs.bitcoin.networks.newyorkc;
2771 setHdCoin(179);
2772 },
2773 },
2774 {
2775 name: "NVC - Novacoin",
2776 onSelect: function() {
2777 network = bitcoinjs.bitcoin.networks.novacoin;
2778 setHdCoin(50);
2779 },
2780 },
2781 {
2782 name: "OK - Okcash",
2783 onSelect: function() {
2784 network = bitcoinjs.bitcoin.networks.okcash;
2785 setHdCoin(69);
2786 },
2787 },
2788 {
2789 name: "OMNI - Omnicore",
2790 onSelect: function() {
2791 network = bitcoinjs.bitcoin.networks.omnicore;
2792 setHdCoin(200);
2793 },
2794 },
2795 {
2796 name: "ONION - DeepOnion",
2797 onSelect: function() {
2798 network = bitcoinjs.bitcoin.networks.deeponion;
2799 setHdCoin(305);
2800 },
2801 },
2802 {
2803 name: "ONX - Onixcoin",
2804 onSelect: function() {
2805 network = bitcoinjs.bitcoin.networks.onixcoin;
2806 setHdCoin(174);
2807 },
2808 },
2809 {
2810 name: "PHR - Phore",
2811 onSelect: function() {
2812 network = bitcoinjs.bitcoin.networks.phore;
2813 setHdCoin(444);
2814 },
2815 },
2816 {
2817 name: "PINK - Pinkcoin",
2818 onSelect: function() {
2819 network = bitcoinjs.bitcoin.networks.pinkcoin;
2820 setHdCoin(117);
2821 },
2822 },
2823 {
2824 name: "PIRL - Pirl",
2825 segwitAvailable: false,
2826 onSelect: function() {
2827 network = bitcoinjs.bitcoin.networks.bitcoin;
2828 setHdCoin(164);
2829 },
2830 },
2831 {
2832 name: "PIVX - PIVX",
2833 onSelect: function() {
2834 network = bitcoinjs.bitcoin.networks.pivx;
2835 setHdCoin(119);
2836 },
2837 },
2838 {
2839 name: "PIVX - PIVX Testnet",
2840 onSelect: function() {
2841 network = bitcoinjs.bitcoin.networks.pivxtestnet;
2842 setHdCoin(1);
2843 },
2844 },
2845 {
2846 name: "POA - Poa",
2847 segwitAvailable: false,
2848 onSelect: function() {
2849 network = bitcoinjs.bitcoin.networks.bitcoin;
2850 setHdCoin(178);
2851 },
2852 },
2853 {
2854 name: "POSW - POSWcoin",
2855 onSelect: function() {
2856 network = bitcoinjs.bitcoin.networks.poswcoin;
2857 setHdCoin(47);
2858 },
2859 },
2860 {
2861 name: "POT - Potcoin",
2862 onSelect: function() {
2863 network = bitcoinjs.bitcoin.networks.potcoin;
2864 setHdCoin(81);
2865 },
2866 },
2867 {
2868 name: "PPC - Peercoin",
2869 onSelect: function() {
2870 network = bitcoinjs.bitcoin.networks.peercoin;
2871 setHdCoin(6);
2872 },
2873 },
2874 {
2875 name: "PRJ - ProjectCoin",
2876 onSelect: function() {
2877 network = bitcoinjs.bitcoin.networks.projectcoin;
2878 setHdCoin(533);
2879 },
2880 },
2881 {
2882 name: "PSB - Pesobit",
2883 onSelect: function() {
2884 network = bitcoinjs.bitcoin.networks.pesobit;
2885 setHdCoin(62);
2886 },
2887 },
2888 {
2889 name: "PUT - Putincoin",
2890 onSelect: function() {
2891 network = bitcoinjs.bitcoin.networks.putincoin;
2892 setHdCoin(122);
2893 },
2894 },
2895 {
2896 name: "RPD - Rapids",
2897 onSelect: function() {
2898 network = bitcoinjs.bitcoin.networks.rapids;
2899 setHdCoin(320);
2900 },
2901 },
2902 {
2903 name: "RVN - Ravencoin",
2904 onSelect: function() {
2905 network = bitcoinjs.bitcoin.networks.ravencoin;
2906 setHdCoin(175);
2907 },
2908 },
2909 {
2910 name: "RBY - Rubycoin",
2911 onSelect: function() {
2912 network = bitcoinjs.bitcoin.networks.rubycoin;
2913 setHdCoin(16);
2914 },
2915 },
2916 {
2917 name: "RDD - Reddcoin",
2918 onSelect: function() {
2919 network = bitcoinjs.bitcoin.networks.reddcoin;
2920 setHdCoin(4);
2921 },
2922 },
2923 {
2924 name: "RVR - RevolutionVR",
2925 onSelect: function() {
2926 network = bitcoinjs.bitcoin.networks.revolutionvr;
2927 setHdCoin(129);
2928 },
2929 },
2930 {
2931 name: "SAFE - Safecoin",
2932 onSelect: function() {
2933 network = bitcoinjs.bitcoin.networks.safecoin;
2934 setHdCoin(19165);
2935 },
2936 },
2937 {
2938 name: "SLS - Salus",
2939 onSelect: function() {
2940 network = bitcoinjs.bitcoin.networks.salus;
2941 setHdCoin(63);
2942 },
2943 },
2944 {
2945 name: "SDC - ShadowCash",
2946 onSelect: function() {
2947 network = bitcoinjs.bitcoin.networks.shadow;
2948 setHdCoin(35);
2949 },
2950 },
2951 {
2952 name: "SDC - ShadowCash Testnet",
2953 onSelect: function() {
2954 network = bitcoinjs.bitcoin.networks.shadowtn;
2955 setHdCoin(1);
2956 },
2957 },
2958 {
2959 name: "SLM - Slimcoin",
2960 onSelect: function() {
2961 network = bitcoinjs.bitcoin.networks.slimcoin;
2962 setHdCoin(63);
2963 },
2964 },
2965 {
2966 name: "SLM - Slimcoin Testnet",
2967 onSelect: function() {
2968 network = bitcoinjs.bitcoin.networks.slimcointn;
2969 setHdCoin(111);
2970 },
2971 },
2972 {
2973 name: "SLP - Simple Ledger Protocol",
2974 onSelect: function() {
2975 DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
2976 setHdCoin(245);
2977 },
2978 },
2979 {
2980 name: "SLR - Solarcoin",
2981 onSelect: function() {
2982 network = bitcoinjs.bitcoin.networks.solarcoin;
2983 setHdCoin(58);
2984 },
2985 },
2986 {
2987 name: "SMLY - Smileycoin",
2988 onSelect: function() {
2989 network = bitcoinjs.bitcoin.networks.smileycoin;
2990 setHdCoin(59);
2991 },
2992 },
2993 {
2994 name: "STASH - Stash",
2995 onSelect: function() {
2996 network = bitcoinjs.bitcoin.networks.stash;
2997 setHdCoin(0xC0C0);
2998 },
2999 },
3000 {
3001 name: "STASH - Stash Testnet",
3002 onSelect: function() {
3003 network = bitcoinjs.bitcoin.networks.stashtn;
3004 setHdCoin(0xCAFE);
3005 },
3006 },
3007 {
3008 name: "STRAT - Stratis",
3009 onSelect: function() {
3010 network = bitcoinjs.bitcoin.networks.stratis;
3011 setHdCoin(105);
3012 },
3013 },
3014 {
3015 name: "TSTRAT - Stratis Testnet",
3016 onSelect: function() {
3017 network = bitcoinjs.bitcoin.networks.stratistest;
3018 setHdCoin(105);
3019 },
3020 },
3021 {
3022 name: "SYS - Syscoin",
3023 onSelect: function() {
3024 network = bitcoinjs.bitcoin.networks.syscoin;
3025 setHdCoin(57);
3026 },
3027 },
3028 {
3029 name: "THC - Hempcoin",
3030 onSelect: function() {
3031 network = bitcoinjs.bitcoin.networks.hempcoin;
3032 setHdCoin(113);
3033 },
3034 },
3035 {
3036 name: "THT - Thought",
3037 onSelect: function() {
3038 network = bitcoinjs.bitcoin.networks.thought;
3039 setHdCoin(1618);
3040 },
3041 },
3042 {
3043 name: "TOA - Toa",
3044 onSelect: function() {
3045 network = bitcoinjs.bitcoin.networks.toa;
3046 setHdCoin(159);
3047 },
3048 },
3049 {
3050 name: "TWINS - TWINS",
3051 onSelect: function() {
3052 network = bitcoinjs.bitcoin.networks.twins;
3053 setHdCoin(970);
3054 },
3055 },
3056 {
3057 name: "TWINS - TWINS Testnet",
3058 onSelect: function() {
3059 network = bitcoinjs.bitcoin.networks.twinstestnet;
3060 setHdCoin(1);
3061 },
3062 },
3063 {
3064 name: "USC - Ultimatesecurecash",
3065 onSelect: function() {
3066 network = bitcoinjs.bitcoin.networks.ultimatesecurecash;
3067 setHdCoin(112);
3068 },
3069 },
3070 {
3071 name: "USNBT - NuBits",
3072 onSelect: function() {
3073 network = bitcoinjs.bitcoin.networks.nubits;
3074 setHdCoin(12);
3075 },
3076 },
3077 {
3078 name: "UNO - Unobtanium",
3079 onSelect: function() {
3080 network = bitcoinjs.bitcoin.networks.unobtanium;
3081 setHdCoin(92);
3082 },
3083 },
3084 {
3085 name: "VASH - Vpncoin",
3086 onSelect: function() {
3087 network = bitcoinjs.bitcoin.networks.vpncoin;
3088 setHdCoin(33);
3089 },
3090 },
3091 {
3092 name: "VET - VeChain",
3093 onSelect: function() {
3094 network = bitcoinjs.bitcoin.networks.bitcoin;
3095 setHdCoin(818);
3096 },
3097 },
3098 {
3099 name: "VIA - Viacoin",
3100 onSelect: function() {
3101 network = bitcoinjs.bitcoin.networks.viacoin;
3102 setHdCoin(14);
3103 },
3104 },
3105 {
3106 name: "VIA - Viacoin Testnet",
3107 onSelect: function() {
3108 network = bitcoinjs.bitcoin.networks.viacointestnet;
3109 setHdCoin(1);
3110 },
3111 },
3112 {
3113 name: "VIVO - Vivo",
3114 onSelect: function() {
3115 network = bitcoinjs.bitcoin.networks.vivo;
3116 setHdCoin(166);
3117 },
3118 },
3119 {
3120 name: "VTC - Vertcoin",
3121 onSelect: function() {
3122 network = bitcoinjs.bitcoin.networks.vertcoin;
3123 setHdCoin(28);
3124 },
3125 },
3126 {
3127 name: "WGR - Wagerr",
3128 onSelect: function() {
3129 network = bitcoinjs.bitcoin.networks.wagerr;
3130 setHdCoin(7825266);
3131 },
3132 },
3133 {
3134 name: "WC - Wincoin",
3135 onSelect: function() {
3136 network = bitcoinjs.bitcoin.networks.wincoin;
3137 setHdCoin(181);
3138 },
3139 },
3140 {
3141 name: "XAX - Artax",
3142 onSelect: function() {
3143 network = bitcoinjs.bitcoin.networks.artax;
3144 setHdCoin(219);
3145 },
3146 },
3147 {
3148 name: "XBC - Bitcoinplus",
3149 onSelect: function() {
3150 network = bitcoinjs.bitcoin.networks.bitcoinplus;
3151 setHdCoin(65);
3152 },
3153 },
3154 {
3155 name: "XLM - Stellar",
3156 onSelect: function() {
3157 network = stellarUtil.dummyNetwork;
3158 setHdCoin(148);
3159 },
3160 },
3161 {
3162 name: "XMY - Myriadcoin",
3163 onSelect: function() {
3164 network = bitcoinjs.bitcoin.networks.myriadcoin;
3165 setHdCoin(90);
3166 },
3167 },
3168 {
3169 name: "XRP - Ripple",
3170 onSelect: function() {
3171 network = bitcoinjs.bitcoin.networks.bitcoin;
3172 setHdCoin(144);
3173 },
3174 },
3175 {
3176 name: "XVC - Vcash",
3177 onSelect: function() {
3178 network = bitcoinjs.bitcoin.networks.vcash;
3179 setHdCoin(127);
3180 },
3181 },
3182 {
3183 name: "XVG - Verge",
3184 onSelect: function() {
3185 network = bitcoinjs.bitcoin.networks.verge;
3186 setHdCoin(77);
3187 },
3188 },
3189 {
3190 name: "XUEZ - Xuez",
3191 segwitAvailable: false,
3192 onSelect: function() {
3193 network = bitcoinjs.bitcoin.networks.xuez;
3194 setHdCoin(225);
3195 },
3196 },
3197 {
3198 name: "XWC - Whitecoin",
3199 onSelect: function() {
3200 network = bitcoinjs.bitcoin.networks.whitecoin;
3201 setHdCoin(155);
3202 },
3203 },
3204 {
3205 name: "XZC - Zcoin",
3206 onSelect: function() {
3207 network = bitcoinjs.bitcoin.networks.zcoin;
3208 setHdCoin(136);
3209 },
3210 },
3211 {
3212 name: "ZCL - Zclassic",
3213 onSelect: function() {
3214 network = bitcoinjs.bitcoin.networks.zclassic;
3215 setHdCoin(147);
3216 },
3217 },
3218 {
3219 name: "ZEC - Zcash",
3220 onSelect: function() {
3221 network = bitcoinjs.bitcoin.networks.zcash;
3222 setHdCoin(133);
3223 },
3224 },
3225 {
3226 name: "ZEN - Horizen",
3227 onSelect: function() {
3228 network = bitcoinjs.bitcoin.networks.zencash;
3229 setHdCoin(121);
3230 },
3231 },
3232 ]
3233
3234 var clients = [
3235 {
3236 name: "Bitcoin Core",
3237 onSelect: function() {
3238 DOM.bip32path.val("m/0'/0'");
3239 DOM.hardenedAddresses.prop('checked', true);
3240 },
3241 },
3242 {
3243 name: "blockchain.info",
3244 onSelect: function() {
3245 DOM.bip32path.val("m/44'/0'/0'");
3246 DOM.hardenedAddresses.prop('checked', false);
3247 },
3248 },
3249 {
3250 name: "MultiBit HD",
3251 onSelect: function() {
3252 DOM.bip32path.val("m/0'/0");
3253 DOM.hardenedAddresses.prop('checked', false);
3254 },
3255 },
3256 {
3257 name: "Coinomi, Ledger",
3258 onSelect: function() {
3259 DOM.bip32path.val("m/44'/"+DOM.bip44coin.val()+"'/0'");
3260 DOM.hardenedAddresses.prop('checked', false);
3261 },
3262 }
3263 ]
3264
3265 // ELA - Elastos functions - begin
3266 function displayBip44InfoForELA() {
3267 if (!isELA()) {
3268 return;
3269 }
3270
3271 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
3272 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
3273
3274 // Calculate the account extended keys
3275 var accountXprv = elastosjs.getAccountExtendedPrivateKey(seed, coin, account);
3276 var accountXpub = elastosjs.getAccountExtendedPublicKey(seed, coin, account);
3277
3278 // Display the extended keys
3279 DOM.bip44accountXprv.val(accountXprv);
3280 DOM.bip44accountXpub.val(accountXpub);
3281 }
3282
3283 function displayBip32InfoForELA() {
3284 if (!isELA()) {
3285 return;
3286 }
3287
3288 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
3289 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
3290 var change = parseIntNoNaN(DOM.bip44change.val(), 0);
3291
3292 DOM.extendedPrivKey.val(elastosjs.getBip32ExtendedPrivateKey(seed, coin, account, change));
3293 DOM.extendedPubKey.val(elastosjs.getBip32ExtendedPublicKey(seed, coin, account, change));
3294
3295 // Display the addresses and privkeys
3296 clearAddressesList();
3297 var initialAddressCount = parseInt(DOM.rowsToAdd.val());
3298 displayAddresses(0, initialAddressCount);
3299 }
3300
3301 function calcAddressForELA(seed, coin, account, change, index) {
3302 if (!isELA()) {
3303 return;
3304 }
3305
3306 var publicKey = elastosjs.getDerivedPublicKey(elastosjs.getMasterPublicKey(seed), change, index);
3307 return {
3308 privateKey: elastosjs.getDerivedPrivateKey(seed, coin, account, change, index),
3309 publicKey: publicKey,
3310 address: elastosjs.getAddress(publicKey.toString('hex'))
3311 };
3312 }
3313 // ELA - Elastos functions - end
3314
3315 init();
3316
3317 })();