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