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