]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - src/js/index.js
Merge pull request #319 from energywebfoundation/master
[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 == "EWT - EnergyWeb")
1027 || (networks[DOM.network.val()].name == "PIRL - Pirl")
1028 || (networks[DOM.network.val()].name == "MIX - MIX")
1029 || (networks[DOM.network.val()].name == "MUSIC - Musicoin")
1030 || (networks[DOM.network.val()].name == "POA - Poa")
1031 || (networks[DOM.network.val()].name == "EXP - Expanse")
1032 || (networks[DOM.network.val()].name == "CLO - Callisto")
1033 || (networks[DOM.network.val()].name == "DXN - DEXON")
1034 || (networks[DOM.network.val()].name == "ELLA - Ellaism")
1035 || (networks[DOM.network.val()].name == "ESN - Ethersocial Network")
1036 || (networks[DOM.network.val()].name == "VET - VeChain")
1037 ) {
1038 var privKeyBuffer = keyPair.d.toBuffer(32);
1039 privkey = privKeyBuffer.toString('hex');
1040 var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
1041 var hexAddress = addressBuffer.toString('hex');
1042 var checksumAddress = ethUtil.toChecksumAddress(hexAddress);
1043 address = ethUtil.addHexPrefix(checksumAddress);
1044 privkey = ethUtil.addHexPrefix(privkey);
1045 pubkey = ethUtil.addHexPrefix(pubkey);
1046 }
1047
1048 // Stellar is different
1049 if (networks[DOM.network.val()].name == "XLM - Stellar") {
1050 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
1051 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
1052 var path = "m/";
1053 path += purpose + "'/";
1054 path += coin + "'/" + index + "'";
1055 var keypair = stellarUtil.getKeypair(path, seed);
1056 indexText = path;
1057 privkey = keypair.secret();
1058 pubkey = address = keypair.publicKey();
1059 }
1060 if ((networks[DOM.network.val()].name == "NAS - Nebulas")) {
1061 var NasAccount = require("nebulas-account");
1062 var privKeyBuffer = keyPair.d.toBuffer(32);
1063 var nebulasAccount = new NasAccount();
1064 nebulasAccount.setPrivateKey(privKeyBuffer);
1065 address = nebulasAccount.getAddressString();
1066 privkey = nebulasAccount.getPrivateKeyString();
1067 pubkey = nebulasAccount.getPublicKeyString();
1068 }
1069 // Ripple values are different
1070 if (networks[DOM.network.val()].name == "XRP - Ripple") {
1071 privkey = convertRipplePriv(privkey);
1072 address = convertRippleAdrr(address);
1073 }
1074 // CasinoCoin values are different
1075 if (networks[DOM.network.val()].name == "CSC - CasinoCoin") {
1076 privkey = convertCasinoCoinPriv(privkey);
1077 address = convertCasinoCoinAdrr(address);
1078 }
1079 // Bitcoin Cash address format may vary
1080 if (networks[DOM.network.val()].name == "BCH - Bitcoin Cash") {
1081 var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val();
1082 if (bchAddrType == "cashaddr") {
1083 address = bchaddr.toCashAddress(address);
1084 }
1085 else if (bchAddrType == "bitpay") {
1086 address = bchaddr.toBitpayAddress(address);
1087 }
1088 }
1089 // Bitcoin Cash address format may vary
1090 if (networks[DOM.network.val()].name == "SLP - Simple Ledger Protocol") {
1091 var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val();
1092 if (bchAddrType == "cashaddr") {
1093 address = bchaddr.toSlpAddress(address);
1094 }
1095 }
1096 // Segwit addresses are different
1097 if (isSegwit) {
1098 if (!segwitAvailable) {
1099 return;
1100 }
1101 if (isP2wpkh) {
1102 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
1103 var scriptpubkey = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
1104 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
1105 }
1106 else if (isP2wpkhInP2sh) {
1107 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
1108 var scriptsig = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
1109 var addressbytes = bitcoinjs.bitcoin.crypto.hash160(scriptsig);
1110 var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes);
1111 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
1112 }
1113 }
1114
1115 if ((networks[DOM.network.val()].name == "CRW - Crown")) {
1116 address = bitcoinjs.bitcoin.networks.crown.toNewAddress(address);
1117 }
1118
1119 if (networks[DOM.network.val()].name == "EOS - EOSIO") {
1120 address = ""
1121 pubkey = eosUtil.bufferToPublic(keyPair.getPublicKeyBuffer());
1122 privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32));
1123 }
1124
1125 //Groestlcoin Addresses are different
1126 if(isGRS()) {
1127
1128 if (isSegwit) {
1129 if (!segwitAvailable) {
1130 return;
1131 }
1132 if (isP2wpkh) {
1133 address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
1134 }
1135 else if (isP2wpkhInP2sh) {
1136 address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
1137 }
1138 }
1139 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1140 }
1141
1142 addAddressToList(indexText, address, pubkey, privkey);
1143 if (isLast) {
1144 hidePending();
1145 updateCsv();
1146 }
1147 }, 50)
1148 }
1149
1150 init();
1151
1152 }
1153
1154 function showMore() {
1155 var rowsToAdd = parseInt(DOM.rowsToAdd.val());
1156 if (isNaN(rowsToAdd)) {
1157 rowsToAdd = 20;
1158 DOM.rowsToAdd.val("20");
1159 }
1160 var start = parseInt(DOM.moreRowsStartIndex.val())
1161 if (isNaN(start)) {
1162 start = lastIndexInTable() + 1;
1163 }
1164 else {
1165 var newStart = start + rowsToAdd;
1166 DOM.moreRowsStartIndex.val(newStart);
1167 }
1168 if (rowsToAdd > 200) {
1169 var msg = "Generating " + rowsToAdd + " rows could take a while. ";
1170 msg += "Do you want to continue?";
1171 if (!confirm(msg)) {
1172 return;
1173 }
1174 }
1175 displayAddresses(start, rowsToAdd);
1176 }
1177
1178 function clearDisplay() {
1179 clearAddressesList();
1180 clearKeys();
1181 hideValidationError();
1182 }
1183
1184 function clearAddressesList() {
1185 DOM.addresses.empty();
1186 DOM.csv.val("");
1187 stopGenerating();
1188 }
1189
1190 function stopGenerating() {
1191 while (generationProcesses.length > 0) {
1192 var generation = generationProcesses.shift();
1193 generation.stop();
1194 }
1195 }
1196
1197 function clearKeys() {
1198 clearRootKey();
1199 clearDerivedKeys();
1200 }
1201
1202 function clearRootKey() {
1203 DOM.rootKey.val("");
1204 }
1205
1206 function clearDerivedKeys() {
1207 DOM.extendedPrivKey.val("");
1208 DOM.extendedPubKey.val("");
1209 DOM.bip44accountXprv.val("");
1210 DOM.bip44accountXpub.val("");
1211 }
1212
1213 function addAddressToList(indexText, address, pubkey, privkey) {
1214 var row = $(addressRowTemplate.html());
1215 // Elements
1216 var indexCell = row.find(".index span");
1217 var addressCell = row.find(".address span");
1218 var pubkeyCell = row.find(".pubkey span");
1219 var privkeyCell = row.find(".privkey span");
1220 // Content
1221 indexCell.text(indexText);
1222 addressCell.text(address);
1223 pubkeyCell.text(pubkey);
1224 privkeyCell.text(privkey);
1225 // Visibility
1226 if (!showIndex) {
1227 indexCell.addClass("invisible");
1228 }
1229 if (!showAddress) {
1230 addressCell.addClass("invisible");
1231 }
1232 if (!showPubKey) {
1233 pubkeyCell.addClass("invisible");
1234 }
1235 if (!showPrivKey) {
1236 privkeyCell.addClass("invisible");
1237 }
1238 DOM.addresses.append(row);
1239 var rowShowQrEls = row.find("[data-show-qr]");
1240 setQrEvents(rowShowQrEls);
1241 }
1242
1243 function hasStrongRandom() {
1244 return 'crypto' in window && window['crypto'] !== null;
1245 }
1246
1247 function disableForms() {
1248 $("form").on("submit", function(e) {
1249 e.preventDefault();
1250 });
1251 }
1252
1253 function parseIntNoNaN(val, defaultVal) {
1254 var v = parseInt(val);
1255 if (isNaN(v)) {
1256 return defaultVal;
1257 }
1258 return v;
1259 }
1260
1261 function showPending() {
1262 DOM.feedback
1263 .text("Calculating...")
1264 .show();
1265 }
1266
1267 function findNearestWord(word) {
1268 var language = getLanguage();
1269 var words = WORDLISTS[language];
1270 var minDistance = 99;
1271 var closestWord = words[0];
1272 for (var i=0; i<words.length; i++) {
1273 var comparedTo = words[i];
1274 if (comparedTo.indexOf(word) == 0) {
1275 return comparedTo;
1276 }
1277 var distance = Levenshtein.get(word, comparedTo);
1278 if (distance < minDistance) {
1279 closestWord = comparedTo;
1280 minDistance = distance;
1281 }
1282 }
1283 return closestWord;
1284 }
1285
1286 function hidePending() {
1287 DOM.feedback
1288 .text("")
1289 .hide();
1290 }
1291
1292 function populateNetworkSelect() {
1293 for (var i=0; i<networks.length; i++) {
1294 var network = networks[i];
1295 var option = $("<option>");
1296 option.attr("value", i);
1297 option.text(network.name);
1298 if (network.name == "BTC - Bitcoin") {
1299 option.prop("selected", true);
1300 }
1301 DOM.phraseNetwork.append(option);
1302 }
1303 }
1304
1305 function populateClientSelect() {
1306 for (var i=0; i<clients.length; i++) {
1307 var client = clients[i];
1308 var option = $("<option>");
1309 option.attr("value", i);
1310 option.text(client.name);
1311 DOM.bip32Client.append(option);
1312 }
1313 }
1314
1315 function getLanguage() {
1316 var defaultLanguage = "english";
1317 // Try to get from existing phrase
1318 var language = getLanguageFromPhrase();
1319 // Try to get from url if not from phrase
1320 if (language.length == 0) {
1321 language = getLanguageFromUrl();
1322 }
1323 // Default to English if no other option
1324 if (language.length == 0) {
1325 language = defaultLanguage;
1326 }
1327 return language;
1328 }
1329
1330 function getLanguageFromPhrase(phrase) {
1331 // Check if how many words from existing phrase match a language.
1332 var language = "";
1333 if (!phrase) {
1334 phrase = DOM.phrase.val();
1335 }
1336 if (phrase.length > 0) {
1337 var words = phraseToWordArray(phrase);
1338 var languageMatches = {};
1339 for (l in WORDLISTS) {
1340 // Track how many words match in this language
1341 languageMatches[l] = 0;
1342 for (var i=0; i<words.length; i++) {
1343 var wordInLanguage = WORDLISTS[l].indexOf(words[i]) > -1;
1344 if (wordInLanguage) {
1345 languageMatches[l]++;
1346 }
1347 }
1348 // Find languages with most word matches.
1349 // This is made difficult due to commonalities between Chinese
1350 // simplified vs traditional.
1351 var mostMatches = 0;
1352 var mostMatchedLanguages = [];
1353 for (var l in languageMatches) {
1354 var numMatches = languageMatches[l];
1355 if (numMatches > mostMatches) {
1356 mostMatches = numMatches;
1357 mostMatchedLanguages = [l];
1358 }
1359 else if (numMatches == mostMatches) {
1360 mostMatchedLanguages.push(l);
1361 }
1362 }
1363 }
1364 if (mostMatchedLanguages.length > 0) {
1365 // Use first language and warn if multiple detected
1366 language = mostMatchedLanguages[0];
1367 if (mostMatchedLanguages.length > 1) {
1368 console.warn("Multiple possible languages");
1369 console.warn(mostMatchedLanguages);
1370 }
1371 }
1372 }
1373 return language;
1374 }
1375
1376 function getLanguageFromUrl() {
1377 for (var language in WORDLISTS) {
1378 if (window.location.hash.indexOf(language) > -1) {
1379 return language;
1380 }
1381 }
1382 return "";
1383 }
1384
1385 function setMnemonicLanguage() {
1386 var language = getLanguage();
1387 // Load the bip39 mnemonic generator for this language if required
1388 if (!(language in mnemonics)) {
1389 mnemonics[language] = new Mnemonic(language);
1390 }
1391 mnemonic = mnemonics[language];
1392 }
1393
1394 function convertPhraseToNewLanguage() {
1395 var oldLanguage = getLanguageFromPhrase();
1396 var newLanguage = getLanguageFromUrl();
1397 var oldPhrase = DOM.phrase.val();
1398 var oldWords = phraseToWordArray(oldPhrase);
1399 var newWords = [];
1400 for (var i=0; i<oldWords.length; i++) {
1401 var oldWord = oldWords[i];
1402 var index = WORDLISTS[oldLanguage].indexOf(oldWord);
1403 var newWord = WORDLISTS[newLanguage][index];
1404 newWords.push(newWord);
1405 }
1406 newPhrase = wordArrayToPhrase(newWords);
1407 return newPhrase;
1408 }
1409
1410 // TODO look at jsbip39 - mnemonic.splitWords
1411 function phraseToWordArray(phrase) {
1412 var words = phrase.split(/\s/g);
1413 var noBlanks = [];
1414 for (var i=0; i<words.length; i++) {
1415 var word = words[i];
1416 if (word.length > 0) {
1417 noBlanks.push(word);
1418 }
1419 }
1420 return noBlanks;
1421 }
1422
1423 // TODO look at jsbip39 - mnemonic.joinWords
1424 function wordArrayToPhrase(words) {
1425 var phrase = words.join(" ");
1426 var language = getLanguageFromPhrase(phrase);
1427 if (language == "japanese") {
1428 phrase = words.join("\u3000");
1429 }
1430 return phrase;
1431 }
1432
1433 function writeSplitPhrase(phrase) {
1434 var wordCount = phrase.split(/\s/g).length; //get number of words in phrase
1435 var left=[]; //initialize array of indexs
1436 for (var i=0;i<wordCount;i++) left.push(i); //add all indexs to array
1437 var group=[[],[],[]], //make array for 3 groups
1438 groupI=-1; //initialize group index
1439 var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647; //start seed at sudo random value based on hash of words
1440 while (left.length>0) { //while indexs left
1441 groupI=(groupI+1)%3; //get next group to insert index into
1442 seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use)
1443 var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group
1444 group[groupI].push(left[selected]); //add index to group
1445 left.splice(selected,1); //remove selected index
1446 }
1447 var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards
1448 for (var i=0;i<3;i++) { //go through each card
1449 for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX'; //erase words listed in the group
1450 cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]); //combine words on card back to string
1451 }
1452 DOM.splitPhrase.val(cards.join("\r\n")); //make words visible
1453 var triesPerSecond=10000000000; //assumed number of tries per second
1454 var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond; //get number of bits of unknown data per card
1455 if (hackTime<1) {
1456 hackTime="<1 second";
1457 } else if (hackTime<86400) {
1458 hackTime=Math.floor(hackTime)+" seconds";
1459 } else if(hackTime<31557600) {
1460 hackTime=Math.floor(hackTime/86400)+" days";
1461 } else {
1462 hackTime=Math.floor(hackTime/31557600)+" years";
1463 }
1464 DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime);
1465 }
1466
1467 function isUsingOwnEntropy() {
1468 return DOM.useEntropy.prop("checked");
1469 }
1470
1471 function setMnemonicFromEntropy() {
1472 clearEntropyFeedback();
1473 // Get entropy value
1474 var entropyStr = DOM.entropy.val();
1475 // Work out minimum base for entropy
1476 var entropy = Entropy.fromString(entropyStr);
1477 if (entropy.binaryStr.length == 0) {
1478 return;
1479 }
1480 // Show entropy details
1481 showEntropyFeedback(entropy);
1482 // Use entropy hash if not using raw entropy
1483 var bits = entropy.binaryStr;
1484 var mnemonicLength = DOM.entropyMnemonicLength.val();
1485 if (mnemonicLength != "raw") {
1486 // Get bits by hashing entropy with SHA256
1487 var hash = sjcl.hash.sha256.hash(entropy.cleanStr);
1488 var hex = sjcl.codec.hex.fromBits(hash);
1489 bits = BigInteger.parse(hex, 16).toString(2);
1490 while (bits.length % 256 != 0) {
1491 bits = "0" + bits;
1492 }
1493 // Truncate hash to suit number of words
1494 mnemonicLength = parseInt(mnemonicLength);
1495 var numberOfBits = 32 * mnemonicLength / 3;
1496 bits = bits.substring(0, numberOfBits);
1497 // show warning for weak entropy override
1498 if (mnemonicLength / 3 * 32 > entropy.binaryStr.length) {
1499 DOM.entropyWeakEntropyOverrideWarning.removeClass("hidden");
1500 }
1501 else {
1502 DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
1503 }
1504 }
1505 else {
1506 // hide warning for weak entropy override
1507 DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
1508 }
1509 // Discard trailing entropy
1510 var bitsToUse = Math.floor(bits.length / 32) * 32;
1511 var start = bits.length - bitsToUse;
1512 var binaryStr = bits.substring(start);
1513 // Convert entropy string to numeric array
1514 var entropyArr = [];
1515 for (var i=0; i<binaryStr.length / 8; i++) {
1516 var byteAsBits = binaryStr.substring(i*8, i*8+8);
1517 var entropyByte = parseInt(byteAsBits, 2);
1518 entropyArr.push(entropyByte)
1519 }
1520 // Convert entropy array to mnemonic
1521 var phrase = mnemonic.toMnemonic(entropyArr);
1522 // Set the mnemonic in the UI
1523 DOM.phrase.val(phrase);
1524 writeSplitPhrase(phrase);
1525 // Show the word indexes
1526 showWordIndexes();
1527 // Show the checksum
1528 showChecksum();
1529 }
1530
1531 function clearEntropyFeedback() {
1532 DOM.entropyCrackTime.text("...");
1533 DOM.entropyType.text("");
1534 DOM.entropyWordCount.text("0");
1535 DOM.entropyEventCount.text("0");
1536 DOM.entropyBitsPerEvent.text("0");
1537 DOM.entropyBits.text("0");
1538 DOM.entropyFiltered.html("&nbsp;");
1539 DOM.entropyBinary.html("&nbsp;");
1540 }
1541
1542 function showEntropyFeedback(entropy) {
1543 var numberOfBits = entropy.binaryStr.length;
1544 var timeToCrack = "unknown";
1545 try {
1546 var z = zxcvbn(entropy.base.parts.join(""));
1547 timeToCrack = z.crack_times_display.offline_fast_hashing_1e10_per_second;
1548 if (z.feedback.warning != "") {
1549 timeToCrack = timeToCrack + " - " + z.feedback.warning;
1550 };
1551 }
1552 catch (e) {
1553 console.log("Error detecting entropy strength with zxcvbn:");
1554 console.log(e);
1555 }
1556 var entropyTypeStr = getEntropyTypeStr(entropy);
1557 var wordCount = Math.floor(numberOfBits / 32) * 3;
1558 var bitsPerEvent = entropy.bitsPerEvent.toFixed(2);
1559 var spacedBinaryStr = addSpacesEveryElevenBits(entropy.binaryStr);
1560 DOM.entropyFiltered.html(entropy.cleanHtml);
1561 DOM.entropyType.text(entropyTypeStr);
1562 DOM.entropyCrackTime.text(timeToCrack);
1563 DOM.entropyEventCount.text(entropy.base.ints.length);
1564 DOM.entropyBits.text(numberOfBits);
1565 DOM.entropyWordCount.text(wordCount);
1566 DOM.entropyBinary.text(spacedBinaryStr);
1567 DOM.entropyBitsPerEvent.text(bitsPerEvent);
1568 // detect and warn of filtering
1569 var rawNoSpaces = DOM.entropy.val().replace(/\s/g, "");
1570 var cleanNoSpaces = entropy.cleanStr.replace(/\s/g, "");
1571 var isFiltered = rawNoSpaces.length != cleanNoSpaces.length;
1572 if (isFiltered) {
1573 DOM.entropyFilterWarning.removeClass('hidden');
1574 }
1575 else {
1576 DOM.entropyFilterWarning.addClass('hidden');
1577 }
1578 }
1579
1580 function getEntropyTypeStr(entropy) {
1581 var typeStr = entropy.base.str;
1582 // Add some detail if these are cards
1583 if (entropy.base.asInt == 52) {
1584 var cardDetail = []; // array of message strings
1585 // Detect duplicates
1586 var dupes = [];
1587 var dupeTracker = {};
1588 for (var i=0; i<entropy.base.parts.length; i++) {
1589 var card = entropy.base.parts[i];
1590 var cardUpper = card.toUpperCase();
1591 if (cardUpper in dupeTracker) {
1592 dupes.push(card);
1593 }
1594 dupeTracker[cardUpper] = true;
1595 }
1596 if (dupes.length > 0) {
1597 var dupeWord = "duplicates";
1598 if (dupes.length == 1) {
1599 dupeWord = "duplicate";
1600 }
1601 var msg = dupes.length + " " + dupeWord + ": " + dupes.slice(0,3).join(" ");
1602 if (dupes.length > 3) {
1603 msg += "...";
1604 }
1605 cardDetail.push(msg);
1606 }
1607 // Detect full deck
1608 var uniqueCards = [];
1609 for (var uniqueCard in dupeTracker) {
1610 uniqueCards.push(uniqueCard);
1611 }
1612 if (uniqueCards.length == 52) {
1613 cardDetail.unshift("full deck");
1614 }
1615 // Detect missing cards
1616 var values = "A23456789TJQK";
1617 var suits = "CDHS";
1618 var missingCards = [];
1619 for (var i=0; i<suits.length; i++) {
1620 for (var j=0; j<values.length; j++) {
1621 var card = values[j] + suits[i];
1622 if (!(card in dupeTracker)) {
1623 missingCards.push(card);
1624 }
1625 }
1626 }
1627 // Display missing cards if six or less, ie clearly going for full deck
1628 if (missingCards.length > 0 && missingCards.length <= 6) {
1629 var msg = missingCards.length + " missing: " + missingCards.slice(0,3).join(" ");
1630 if (missingCards.length > 3) {
1631 msg += "...";
1632 }
1633 cardDetail.push(msg);
1634 }
1635 // Add card details to typeStr
1636 if (cardDetail.length > 0) {
1637 typeStr += " (" + cardDetail.join(", ") + ")";
1638 }
1639 }
1640 return typeStr;
1641 }
1642
1643 function setQrEvents(els) {
1644 els.on("mouseenter", createQr);
1645 els.on("mouseleave", destroyQr);
1646 els.on("click", toggleQr);
1647 }
1648
1649 function createQr(e) {
1650 var content = e.target.textContent || e.target.value;
1651 if (content) {
1652 var qrEl = kjua({
1653 text: content,
1654 render: "canvas",
1655 size: 310,
1656 ecLevel: 'H',
1657 });
1658 DOM.qrImage.append(qrEl);
1659 if (!showQr) {
1660 DOM.qrHider.addClass("hidden");
1661 }
1662 else {
1663 DOM.qrHider.removeClass("hidden");
1664 }
1665 DOM.qrContainer.removeClass("hidden");
1666 }
1667 }
1668
1669 function destroyQr() {
1670 DOM.qrImage.text("");
1671 DOM.qrContainer.addClass("hidden");
1672 }
1673
1674 function toggleQr() {
1675 showQr = !showQr;
1676 DOM.qrHider.toggleClass("hidden");
1677 DOM.qrHint.toggleClass("hidden");
1678 }
1679
1680 function bip44TabSelected() {
1681 return DOM.bip44tab.hasClass("active");
1682 }
1683
1684 function bip32TabSelected() {
1685 return DOM.bip32tab.hasClass("active");
1686 }
1687
1688 function networkHasSegwit() {
1689 var n = network;
1690 if ("baseNetwork" in network) {
1691 n = bitcoinjs.bitcoin.networks[network.baseNetwork];
1692 }
1693 // check if only p2wpkh params are required
1694 if (p2wpkhSelected()) {
1695 return "p2wpkh" in n;
1696 }
1697 // check if only p2wpkh-in-p2sh params are required
1698 else if (p2wpkhInP2shSelected()) {
1699 return "p2wpkhInP2sh" in n;
1700 }
1701 // require both if it's unclear which params are required
1702 return "p2wpkh" in n && "p2wpkhInP2sh" in n;
1703 }
1704
1705 function bip49TabSelected() {
1706 return DOM.bip49tab.hasClass("active");
1707 }
1708
1709 function bip84TabSelected() {
1710 return DOM.bip84tab.hasClass("active");
1711 }
1712
1713 function bip141TabSelected() {
1714 return DOM.bip141tab.hasClass("active");
1715 }
1716
1717 function setHdCoin(coinValue) {
1718 DOM.bip44coin.val(coinValue);
1719 DOM.bip49coin.val(coinValue);
1720 DOM.bip84coin.val(coinValue);
1721 }
1722
1723 function showSegwitAvailable() {
1724 DOM.bip49unavailable.addClass("hidden");
1725 DOM.bip49available.removeClass("hidden");
1726 DOM.bip84unavailable.addClass("hidden");
1727 DOM.bip84available.removeClass("hidden");
1728 DOM.bip141unavailable.addClass("hidden");
1729 DOM.bip141available.removeClass("hidden");
1730 }
1731
1732 function showSegwitUnavailable() {
1733 DOM.bip49available.addClass("hidden");
1734 DOM.bip49unavailable.removeClass("hidden");
1735 DOM.bip84available.addClass("hidden");
1736 DOM.bip84unavailable.removeClass("hidden");
1737 DOM.bip141available.addClass("hidden");
1738 DOM.bip141unavailable.removeClass("hidden");
1739 }
1740
1741 function adjustNetworkForSegwit() {
1742 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1743 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1744 // wallet.
1745 // See https://github.com/iancoleman/bip39/issues/125
1746 var segwitNetworks = null;
1747 // if a segwit network is alread selected, need to use base network to
1748 // look up new parameters
1749 if ("baseNetwork" in network) {
1750 network = bitcoinjs.bitcoin.networks[network.baseNetwork];
1751 }
1752 // choose the right segwit params
1753 if (p2wpkhSelected() && "p2wpkh" in network) {
1754 network = network.p2wpkh;
1755 }
1756 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network) {
1757 network = network.p2wpkhInP2sh;
1758 }
1759 }
1760
1761 function lastIndexInTable() {
1762 var pathText = DOM.addresses.find(".index").last().text();
1763 var pathBits = pathText.split("/");
1764 var lastBit = pathBits[pathBits.length-1];
1765 var lastBitClean = lastBit.replace("'", "");
1766 return parseInt(lastBitClean);
1767 }
1768
1769 function uint8ArrayToHex(a) {
1770 var s = ""
1771 for (var i=0; i<a.length; i++) {
1772 var h = a[i].toString(16);
1773 while (h.length < 2) {
1774 h = "0" + h;
1775 }
1776 s = s + h;
1777 }
1778 return s;
1779 }
1780
1781 function showWordIndexes() {
1782 var phrase = DOM.phrase.val();
1783 var words = phraseToWordArray(phrase);
1784 var wordIndexes = [];
1785 var language = getLanguage();
1786 for (var i=0; i<words.length; i++) {
1787 var word = words[i];
1788 var wordIndex = WORDLISTS[language].indexOf(word);
1789 wordIndexes.push(wordIndex);
1790 }
1791 var wordIndexesStr = wordIndexes.join(", ");
1792 DOM.entropyWordIndexes.text(wordIndexesStr);
1793 }
1794
1795 function showChecksum() {
1796 var phrase = DOM.phrase.val();
1797 var words = phraseToWordArray(phrase);
1798 var checksumBitlength = words.length / 3;
1799 var checksum = "";
1800 var binaryStr = "";
1801 var language = getLanguage();
1802 for (var i=words.length-1; i>=0; i--) {
1803 var word = words[i];
1804 var wordIndex = WORDLISTS[language].indexOf(word);
1805 var wordBinary = wordIndex.toString(2);
1806 while (wordBinary.length < 11) {
1807 wordBinary = "0" + wordBinary;
1808 }
1809 var binaryStr = wordBinary + binaryStr;
1810 if (binaryStr.length >= checksumBitlength) {
1811 var start = binaryStr.length - checksumBitlength;
1812 var end = binaryStr.length;
1813 checksum = binaryStr.substring(start, end);
1814 // add spaces so the last group is 11 bits, not the first
1815 checksum = checksum.split("").reverse().join("")
1816 checksum = addSpacesEveryElevenBits(checksum);
1817 checksum = checksum.split("").reverse().join("")
1818 break;
1819 }
1820 }
1821 DOM.entropyChecksum.text(checksum);
1822 }
1823
1824 function updateCsv() {
1825 var tableCsv = "path,address,public key,private key\n";
1826 var rows = DOM.addresses.find("tr");
1827 for (var i=0; i<rows.length; i++) {
1828 var row = $(rows[i]);
1829 var cells = row.find("td");
1830 for (var j=0; j<cells.length; j++) {
1831 var cell = $(cells[j]);
1832 if (!cell.children().hasClass("invisible")) {
1833 tableCsv = tableCsv + cell.text();
1834 }
1835 if (j != cells.length - 1) {
1836 tableCsv = tableCsv + ",";
1837 }
1838 }
1839 tableCsv = tableCsv + "\n";
1840 }
1841 DOM.csv.val(tableCsv);
1842 }
1843
1844 function addSpacesEveryElevenBits(binaryStr) {
1845 return binaryStr.match(/.{1,11}/g).join(" ");
1846 }
1847
1848 var networks = [
1849 {
1850 name: "AC - Asiacoin",
1851 onSelect: function() {
1852 network = bitcoinjs.bitcoin.networks.asiacoin;
1853 setHdCoin(51);
1854 },
1855 },
1856 {
1857 name: "ACC - Adcoin",
1858 onSelect: function() {
1859 network = bitcoinjs.bitcoin.networks.adcoin;
1860 setHdCoin(161);
1861 },
1862 },
1863 {
1864 name: "ARYA - Aryacoin",
1865 onSelect: function() {
1866 network = bitcoinjs.bitcoin.networks.aryacoin;
1867 setHdCoin(357);
1868 },
1869 },
1870 {
1871 name: "AUR - Auroracoin",
1872 onSelect: function() {
1873 network = bitcoinjs.bitcoin.networks.auroracoin;
1874 setHdCoin(85);
1875 },
1876 },
1877 {
1878 name: "AXE - Axe",
1879 onSelect: function() {
1880 network = bitcoinjs.bitcoin.networks.axe;
1881 setHdCoin(4242);
1882 },
1883 },
1884 {
1885 name: "ANON - ANON",
1886 onSelect: function() {
1887 network = bitcoinjs.bitcoin.networks.anon;
1888 setHdCoin(220);
1889 },
1890 },
1891 {
1892 name: "BOLI - Bolivarcoin",
1893 onSelect: function() {
1894 network = bitcoinjs.bitcoin.networks.bolivarcoin;
1895 setHdCoin(278);
1896 },
1897 },
1898 {
1899 name: "BCA - Bitcoin Atom",
1900 onSelect: function() {
1901 network = bitcoinjs.bitcoin.networks.atom;
1902 setHdCoin(185);
1903 },
1904 },
1905 {
1906 name: "BCH - Bitcoin Cash",
1907 onSelect: function() {
1908 DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
1909 setHdCoin(145);
1910 },
1911 },
1912 {
1913 name: "BEET - Beetlecoin",
1914 onSelect: function() {
1915 network = bitcoinjs.bitcoin.networks.beetlecoin;
1916 setHdCoin(800);
1917 },
1918 },
1919 {
1920 name: "BELA - Belacoin",
1921 onSelect: function() {
1922 network = bitcoinjs.bitcoin.networks.belacoin;
1923 setHdCoin(73);
1924 },
1925 },
1926 {
1927 name: "BLK - BlackCoin",
1928 onSelect: function() {
1929 network = bitcoinjs.bitcoin.networks.blackcoin;
1930 setHdCoin(10);
1931 },
1932 },
1933 {
1934 name: "BND - Blocknode",
1935 onSelect: function() {
1936 network = bitcoinjs.bitcoin.networks.blocknode;
1937 setHdCoin(2941);
1938 },
1939 },
1940 {
1941 name: "tBND - Blocknode Testnet",
1942 onSelect: function() {
1943 network = bitcoinjs.bitcoin.networks.blocknode_testnet;
1944 setHdCoin(1);
1945 },
1946 },
1947 {
1948 name: "BRIT - Britcoin",
1949 onSelect: function() {
1950 network = bitcoinjs.bitcoin.networks.britcoin;
1951 setHdCoin(70);
1952 },
1953 },
1954 {
1955 name: "BSD - Bitsend",
1956 onSelect: function() {
1957 network = bitcoinjs.bitcoin.networks.bitsend;
1958 setHdCoin(91);
1959 },
1960 },
1961 {
1962 name: "BST - BlockStamp",
1963 onSelect: function() {
1964 network = bitcoinjs.bitcoin.networks.blockstamp;
1965 setHdCoin(254);
1966 },
1967 },
1968 {
1969 name: "BTA - Bata",
1970 onSelect: function() {
1971 network = bitcoinjs.bitcoin.networks.bata;
1972 setHdCoin(89);
1973 },
1974 },
1975 {
1976 name: "BTC - Bitcoin",
1977 onSelect: function() {
1978 network = bitcoinjs.bitcoin.networks.bitcoin;
1979 setHdCoin(0);
1980 },
1981 },
1982 {
1983 name: "BTC - Bitcoin Testnet",
1984 onSelect: function() {
1985 network = bitcoinjs.bitcoin.networks.testnet;
1986 setHdCoin(1);
1987 },
1988 },
1989 {
1990 name: "BITG - Bitcoin Green",
1991 onSelect: function() {
1992 network = bitcoinjs.bitcoin.networks.bitcoingreen;
1993 setHdCoin(222);
1994 },
1995 },
1996 {
1997 name: "BTCP - Bitcoin Private",
1998 onSelect: function() {
1999 network = bitcoinjs.bitcoin.networks.bitcoinprivate;
2000 setHdCoin(183);
2001 },
2002 },
2003 {
2004 name: "BSV - BitcoinSV",
2005 onSelect: function() {
2006 network = bitcoinjs.bitcoin.networks.bitcoinsv;
2007 setHdCoin(236);
2008 },
2009 },
2010 {
2011 name: "BTCZ - Bitcoinz",
2012 onSelect: function() {
2013 network = bitcoinjs.bitcoin.networks.bitcoinz;
2014 setHdCoin(177);
2015 },
2016 },
2017 {
2018 name: "BTDX - BitCloud",
2019 onSelect: function() {
2020 network = bitcoinjs.bitcoin.networks.bitcloud;
2021 setHdCoin(218);
2022 },
2023 },
2024 {
2025 name: "BTG - Bitcoin Gold",
2026 onSelect: function() {
2027 network = bitcoinjs.bitcoin.networks.bgold;
2028 setHdCoin(156);
2029 },
2030 },
2031 {
2032 name: "BTX - Bitcore",
2033 onSelect: function() {
2034 network = bitcoinjs.bitcoin.networks.bitcore;
2035 setHdCoin(160);
2036 },
2037 },
2038 {
2039 name: "CCN - Cannacoin",
2040 onSelect: function() {
2041 network = bitcoinjs.bitcoin.networks.cannacoin;
2042 setHdCoin(19);
2043 },
2044 },
2045 {
2046 name: "CESC - Cryptoescudo",
2047 onSelect: function() {
2048 network = bitcoinjs.bitcoin.networks.cannacoin;
2049 setHdCoin(111);
2050 },
2051 },
2052 {
2053 name: "CDN - Canadaecoin",
2054 onSelect: function() {
2055 network = bitcoinjs.bitcoin.networks.canadaecoin;
2056 setHdCoin(34);
2057 },
2058 },
2059 {
2060 name: "CLAM - Clams",
2061 onSelect: function() {
2062 network = bitcoinjs.bitcoin.networks.clam;
2063 setHdCoin(23);
2064 },
2065 },
2066 {
2067 name: "CLO - Callisto",
2068 segwitAvailable: false,
2069 onSelect: function() {
2070 network = bitcoinjs.bitcoin.networks.bitcoin;
2071 setHdCoin(820);
2072 },
2073 },
2074 {
2075 name: "CLUB - Clubcoin",
2076 onSelect: function() {
2077 network = bitcoinjs.bitcoin.networks.clubcoin;
2078 setHdCoin(79);
2079 },
2080 },
2081 {
2082 name: "CMP - Compcoin",
2083 onSelect: function() {
2084 network = bitcoinjs.bitcoin.networks.compcoin;
2085 setHdCoin(71);
2086 },
2087 },
2088 {
2089 name: "CPU - CPUchain",
2090 onSelect: function() {
2091 network = bitcoinjs.bitcoin.networks.cpuchain;
2092 setHdCoin(363);
2093 },
2094 },
2095 {
2096 name: "CRAVE - Crave",
2097 onSelect: function() {
2098 network = bitcoinjs.bitcoin.networks.crave;
2099 setHdCoin(186);
2100 },
2101 },
2102 {
2103 name: "CRW - Crown (Legacy)",
2104 onSelect: function() {
2105 network = bitcoinjs.bitcoin.networks.crown;
2106 setHdCoin(72);
2107 },
2108 },
2109 {
2110 name: "CRW - Crown",
2111 onSelect: function() {
2112 network = bitcoinjs.bitcoin.networks.crown;
2113 setHdCoin(72);
2114 },
2115 },
2116 {
2117 name: "CSC - CasinoCoin",
2118 onSelect: function() {
2119 network = bitcoinjs.bitcoin.networks.bitcoin;
2120 setHdCoin(359);
2121 },
2122 },
2123 {
2124 name: "DASH - Dash",
2125 onSelect: function() {
2126 network = bitcoinjs.bitcoin.networks.dash;
2127 setHdCoin(5);
2128 },
2129 },
2130 {
2131 name: "DASH - Dash Testnet",
2132 onSelect: function() {
2133 network = bitcoinjs.bitcoin.networks.dashtn;
2134 setHdCoin(1);
2135 },
2136 },
2137 {
2138 name: "DFC - Defcoin",
2139 onSelect: function() {
2140 network = bitcoinjs.bitcoin.networks.defcoin;
2141 setHdCoin(1337);
2142 },
2143 },
2144 {
2145 name: "DGB - Digibyte",
2146 onSelect: function() {
2147 network = bitcoinjs.bitcoin.networks.digibyte;
2148 setHdCoin(20);
2149 },
2150 },
2151 {
2152 name: "DGC - Digitalcoin",
2153 onSelect: function() {
2154 network = bitcoinjs.bitcoin.networks.digitalcoin;
2155 setHdCoin(18);
2156 },
2157 },
2158 {
2159 name: "DMD - Diamond",
2160 onSelect: function() {
2161 network = bitcoinjs.bitcoin.networks.diamond;
2162 setHdCoin(152);
2163 },
2164 },
2165 {
2166 name: "DNR - Denarius",
2167 onSelect: function() {
2168 network = bitcoinjs.bitcoin.networks.denarius;
2169 setHdCoin(116);
2170 },
2171 },
2172 {
2173 name: "DOGE - Dogecoin",
2174 onSelect: function() {
2175 network = bitcoinjs.bitcoin.networks.dogecoin;
2176 setHdCoin(3);
2177 },
2178 },
2179 {
2180 name: "DOGEt - Dogecoin Testnet",
2181 onSelect: function() {
2182 network = bitcoinjs.bitcoin.networks.dogecointestnet;
2183 setHdCoin(1);
2184 },
2185 },
2186 {
2187 name: "DXN - DEXON",
2188 onSelect: function() {
2189 network = bitcoinjs.bitcoin.networks.bitcoin;
2190 setHdCoin(237);
2191 },
2192 },
2193 {
2194 name: "ECN - Ecoin",
2195 onSelect: function() {
2196 network = bitcoinjs.bitcoin.networks.ecoin;
2197 setHdCoin(115);
2198 },
2199 },
2200 {
2201 name: "EDRC - Edrcoin",
2202 onSelect: function() {
2203 network = bitcoinjs.bitcoin.networks.edrcoin;
2204 setHdCoin(56);
2205 },
2206 },
2207 {
2208 name: "EFL - Egulden",
2209 onSelect: function() {
2210 network = bitcoinjs.bitcoin.networks.egulden;
2211 setHdCoin(78);
2212 },
2213 },
2214 {
2215 name: "ELLA - Ellaism",
2216 segwitAvailable: false,
2217 onSelect: function() {
2218 network = bitcoinjs.bitcoin.networks.bitcoin;
2219 setHdCoin(163);
2220 },
2221 },
2222 {
2223 name: "EMC2 - Einsteinium",
2224 onSelect: function() {
2225 network = bitcoinjs.bitcoin.networks.einsteinium;
2226 setHdCoin(41);
2227 },
2228 },
2229 {
2230 name: "ERC - Europecoin",
2231 onSelect: function() {
2232 network = bitcoinjs.bitcoin.networks.europecoin;
2233 setHdCoin(151);
2234 },
2235 },
2236 {
2237 name: "EOS - EOSIO",
2238 onSelect: function() {
2239 network = bitcoinjs.bitcoin.networks.bitcoin;
2240 setHdCoin(194);
2241 },
2242 },
2243 {
2244 name: "ESN - Ethersocial Network",
2245 segwitAvailable: false,
2246 onSelect: function() {
2247 network = bitcoinjs.bitcoin.networks.bitcoin;
2248 setHdCoin(31102);
2249 },
2250 },
2251 {
2252 name: "ETC - Ethereum Classic",
2253 segwitAvailable: false,
2254 onSelect: function() {
2255 network = bitcoinjs.bitcoin.networks.bitcoin;
2256 setHdCoin(61);
2257 },
2258 },
2259 {
2260 name: "ETH - Ethereum",
2261 onSelect: function() {
2262 network = bitcoinjs.bitcoin.networks.bitcoin;
2263 setHdCoin(60);
2264 },
2265 },
2266 {
2267 name: "EWT - EnergyWeb",
2268 onSelect: function() {
2269 network = bitcoinjs.bitcoin.networks.bitcoin;
2270 setHdCoin(246);
2271 },
2272 },
2273 {
2274 name: "EXCL - Exclusivecoin",
2275 onSelect: function() {
2276 network = bitcoinjs.bitcoin.networks.exclusivecoin;
2277 setHdCoin(190);
2278 },
2279 },
2280 {
2281 name: "EXCC - ExchangeCoin",
2282 onSelect: function() {
2283 network = bitcoinjs.bitcoin.networks.exchangecoin;
2284 setHdCoin(0);
2285 },
2286 },
2287 {
2288 name: "EXP - Expanse",
2289 segwitAvailable: false,
2290 onSelect: function() {
2291 network = bitcoinjs.bitcoin.networks.bitcoin;
2292 setHdCoin(40);
2293 },
2294 },
2295 {
2296 name: "FIX - FIX",
2297 onSelect: function() {
2298 network = bitcoinjs.bitcoin.networks.fix;
2299 setHdCoin(336);
2300 },
2301 },
2302 {
2303 name: "FIX - FIX Testnet",
2304 onSelect: function() {
2305 network = bitcoinjs.bitcoin.networks.fixtestnet;
2306 setHdCoin(1);
2307 },
2308 },
2309 {
2310 name: "FJC - Fujicoin",
2311 onSelect: function() {
2312 network = bitcoinjs.bitcoin.networks.fujicoin;
2313 setHdCoin(75);
2314 },
2315 },
2316 {
2317 name: "FLASH - Flashcoin",
2318 onSelect: function() {
2319 network = bitcoinjs.bitcoin.networks.flashcoin;
2320 setHdCoin(120);
2321 },
2322 },
2323 {
2324 name: "FRST - Firstcoin",
2325 onSelect: function() {
2326 network = bitcoinjs.bitcoin.networks.firstcoin;
2327 setHdCoin(167);
2328 },
2329 },
2330 {
2331 name: "FTC - Feathercoin",
2332 onSelect: function() {
2333 network = bitcoinjs.bitcoin.networks.feathercoin;
2334 setHdCoin(8);
2335 },
2336 },
2337 {
2338 name: "GAME - GameCredits",
2339 onSelect: function() {
2340 network = bitcoinjs.bitcoin.networks.game;
2341 setHdCoin(101);
2342 },
2343 },
2344 {
2345 name: "GBX - Gobyte",
2346 onSelect: function() {
2347 network = bitcoinjs.bitcoin.networks.gobyte;
2348 setHdCoin(176);
2349 },
2350 },
2351 {
2352 name: "GCR - GCRCoin",
2353 onSelect: function() {
2354 network = bitcoinjs.bitcoin.networks.gcr;
2355 setHdCoin(79);
2356 },
2357 },
2358 {
2359 name: "GRC - Gridcoin",
2360 onSelect: function() {
2361 network = bitcoinjs.bitcoin.networks.gridcoin;
2362 setHdCoin(84);
2363 },
2364 },
2365 {
2366 name: "GRS - Groestlcoin",
2367 onSelect: function() {
2368 network = bitcoinjs.bitcoin.networks.groestlcoin;
2369 setHdCoin(17);
2370 },
2371 },
2372 {
2373 name: "GRS - Groestlcoin Testnet",
2374 onSelect: function() {
2375 network = bitcoinjs.bitcoin.networks.groestlcointestnet;
2376 setHdCoin(1);
2377 },
2378 },
2379 {
2380 name: "HNC - Helleniccoin",
2381 onSelect: function() {
2382 network = bitcoinjs.bitcoin.networks.helleniccoin;
2383 setHdCoin(168);
2384 },
2385 },
2386 {
2387 name: "HUSH - Hush (Legacy)",
2388 onSelect: function() {
2389 network = bitcoinjs.bitcoin.networks.hush;
2390 setHdCoin(197);
2391 },
2392 },
2393 {
2394 name: "HUSH - Hush3",
2395 onSelect: function() {
2396 network = bitcoinjs.bitcoin.networks.hush3;
2397 setHdCoin(197);
2398 },
2399 },
2400 {
2401 name: "INSN - Insane",
2402 onSelect: function() {
2403 network = bitcoinjs.bitcoin.networks.insane;
2404 setHdCoin(68);
2405 },
2406 },
2407 {
2408 name: "IOP - Iop",
2409 onSelect: function() {
2410 network = bitcoinjs.bitcoin.networks.iop;
2411 setHdCoin(66);
2412 },
2413 },
2414 {
2415 name: "IXC - Ixcoin",
2416 onSelect: function() {
2417 network = bitcoinjs.bitcoin.networks.ixcoin;
2418 setHdCoin(86);
2419 },
2420 },
2421 {
2422 name: "JBS - Jumbucks",
2423 onSelect: function() {
2424 network = bitcoinjs.bitcoin.networks.jumbucks;
2425 setHdCoin(26);
2426 },
2427 },
2428 {
2429 name: "KMD - Komodo",
2430 bip49available: false,
2431 onSelect: function() {
2432 network = bitcoinjs.bitcoin.networks.komodo;
2433 setHdCoin(141);
2434 },
2435 },
2436 {
2437 name: "KOBO - Kobocoin",
2438 bip49available: false,
2439 onSelect: function() {
2440 network = bitcoinjs.bitcoin.networks.kobocoin;
2441 setHdCoin(196);
2442 },
2443 },
2444 {
2445 name: "LBC - Library Credits",
2446 onSelect: function() {
2447 network = bitcoinjs.bitcoin.networks.lbry;
2448 setHdCoin(140);
2449 },
2450 },
2451 {
2452 name: "LCC - Litecoincash",
2453 onSelect: function() {
2454 network = bitcoinjs.bitcoin.networks.litecoincash;
2455 setHdCoin(192);
2456 },
2457 },
2458 {
2459 name: "LDCN - Landcoin",
2460 onSelect: function() {
2461 network = bitcoinjs.bitcoin.networks.landcoin;
2462 setHdCoin(63);
2463 },
2464 },
2465 {
2466 name: "LINX - Linx",
2467 onSelect: function() {
2468 network = bitcoinjs.bitcoin.networks.linx;
2469 setHdCoin(114);
2470 },
2471 },
2472 {
2473 name: "LKR - Lkrcoin",
2474 segwitAvailable: false,
2475 onSelect: function() {
2476 network = bitcoinjs.bitcoin.networks.lkrcoin;
2477 setHdCoin(557);
2478 },
2479 },
2480 {
2481 name: "LTC - Litecoin",
2482 onSelect: function() {
2483 network = bitcoinjs.bitcoin.networks.litecoin;
2484 setHdCoin(2);
2485 DOM.litecoinLtubContainer.removeClass("hidden");
2486 },
2487 },
2488 {
2489 name: "LTCt - Litecoin Testnet",
2490 onSelect: function() {
2491 network = bitcoinjs.bitcoin.networks.litecointestnet;
2492 setHdCoin(1);
2493 DOM.litecoinLtubContainer.removeClass("hidden");
2494 },
2495 },
2496 {
2497 name: "LTZ - LitecoinZ",
2498 onSelect: function() {
2499 network = bitcoinjs.bitcoin.networks.litecoinz;
2500 setHdCoin(221);
2501 },
2502 },
2503 {
2504 name: "LYNX - Lynx",
2505 onSelect: function() {
2506 network = bitcoinjs.bitcoin.networks.lynx;
2507 setHdCoin(191);
2508 },
2509 },
2510 {
2511 name: "MAZA - Maza",
2512 onSelect: function() {
2513 network = bitcoinjs.bitcoin.networks.maza;
2514 setHdCoin(13);
2515 },
2516 },
2517 {
2518 name: "MEC - Megacoin",
2519 onSelect: function() {
2520 network = bitcoinjs.bitcoin.networks.megacoin;
2521 setHdCoin(217);
2522 },
2523 },
2524 {
2525 name: "MIX - MIX",
2526 segwitAvailable: false,
2527 onSelect: function() {
2528 network = bitcoinjs.bitcoin.networks.bitcoin;
2529 setHdCoin(76);
2530 },
2531 },
2532 {
2533 name: "MNX - Minexcoin",
2534 onSelect: function() {
2535 network = bitcoinjs.bitcoin.networks.minexcoin;
2536 setHdCoin(182);
2537 },
2538 },
2539 {
2540 name: "MONA - Monacoin",
2541 onSelect: function() {
2542 network = bitcoinjs.bitcoin.networks.monacoin,
2543 setHdCoin(22);
2544 },
2545 },
2546 {
2547 name: "MONK - Monkey Project",
2548 onSelect: function() {
2549 network = bitcoinjs.bitcoin.networks.monkeyproject,
2550 setHdCoin(214);
2551 },
2552 },
2553 {
2554 name: "MUSIC - Musicoin",
2555 segwitAvailable: false,
2556 onSelect: function() {
2557 network = bitcoinjs.bitcoin.networks.bitcoin;
2558 setHdCoin(184);
2559 },
2560 },
2561 {
2562 name: "NAV - Navcoin",
2563 onSelect: function() {
2564 network = bitcoinjs.bitcoin.networks.navcoin;
2565 setHdCoin(130);
2566 },
2567 },
2568 {
2569 name: "NAS - Nebulas",
2570 onSelect: function() {
2571 network = bitcoinjs.bitcoin.networks.bitcoin;
2572 setHdCoin(2718);
2573 },
2574 },
2575 {
2576 name: "NEBL - Neblio",
2577 onSelect: function() {
2578 network = bitcoinjs.bitcoin.networks.neblio;
2579 setHdCoin(146);
2580 },
2581 },
2582 {
2583 name: "NEOS - Neoscoin",
2584 onSelect: function() {
2585 network = bitcoinjs.bitcoin.networks.neoscoin;
2586 setHdCoin(25);
2587 },
2588 },
2589 {
2590 name: "NIX - NIX Platform",
2591 onSelect: function() {
2592 network = bitcoinjs.bitcoin.networks.nix;
2593 setHdCoin(400);
2594 },
2595 },
2596 {
2597 name: "NLG - Gulden",
2598 onSelect: function() {
2599 network = bitcoinjs.bitcoin.networks.gulden;
2600 setHdCoin(87);
2601 },
2602 },
2603 {
2604 name: "NMC - Namecoin",
2605 onSelect: function() {
2606 network = bitcoinjs.bitcoin.networks.namecoin;
2607 setHdCoin(7);
2608 },
2609 },
2610 {
2611 name: "NRG - Energi",
2612 onSelect: function() {
2613 network = bitcoinjs.bitcoin.networks.energi;
2614 setHdCoin(204);
2615 },
2616 },
2617 {
2618 name: "NRO - Neurocoin",
2619 onSelect: function() {
2620 network = bitcoinjs.bitcoin.networks.neurocoin;
2621 setHdCoin(110);
2622 },
2623 },
2624 {
2625 name: "NSR - Nushares",
2626 onSelect: function() {
2627 network = bitcoinjs.bitcoin.networks.nushares;
2628 setHdCoin(11);
2629 },
2630 },
2631 {
2632 name: "NYC - Newyorkc",
2633 onSelect: function() {
2634 network = bitcoinjs.bitcoin.networks.newyorkc;
2635 setHdCoin(179);
2636 },
2637 },
2638 {
2639 name: "NVC - Novacoin",
2640 onSelect: function() {
2641 network = bitcoinjs.bitcoin.networks.novacoin;
2642 setHdCoin(50);
2643 },
2644 },
2645 {
2646 name: "OK - Okcash",
2647 onSelect: function() {
2648 network = bitcoinjs.bitcoin.networks.okcash;
2649 setHdCoin(69);
2650 },
2651 },
2652 {
2653 name: "OMNI - Omnicore",
2654 onSelect: function() {
2655 network = bitcoinjs.bitcoin.networks.omnicore;
2656 setHdCoin(200);
2657 },
2658 },
2659 {
2660 name: "ONION - DeepOnion",
2661 onSelect: function() {
2662 network = bitcoinjs.bitcoin.networks.deeponion;
2663 setHdCoin(305);
2664 },
2665 },
2666 {
2667 name: "ONX - Onixcoin",
2668 onSelect: function() {
2669 network = bitcoinjs.bitcoin.networks.onixcoin;
2670 setHdCoin(174);
2671 },
2672 },
2673 {
2674 name: "PHR - Phore",
2675 onSelect: function() {
2676 network = bitcoinjs.bitcoin.networks.phore;
2677 setHdCoin(444);
2678 },
2679 },
2680 {
2681 name: "PINK - Pinkcoin",
2682 onSelect: function() {
2683 network = bitcoinjs.bitcoin.networks.pinkcoin;
2684 setHdCoin(117);
2685 },
2686 },
2687 {
2688 name: "PIRL - Pirl",
2689 segwitAvailable: false,
2690 onSelect: function() {
2691 network = bitcoinjs.bitcoin.networks.bitcoin;
2692 setHdCoin(164);
2693 },
2694 },
2695 {
2696 name: "PIVX - PIVX",
2697 onSelect: function() {
2698 network = bitcoinjs.bitcoin.networks.pivx;
2699 setHdCoin(119);
2700 },
2701 },
2702 {
2703 name: "PIVX - PIVX Testnet",
2704 onSelect: function() {
2705 network = bitcoinjs.bitcoin.networks.pivxtestnet;
2706 setHdCoin(1);
2707 },
2708 },
2709 {
2710 name: "POA - Poa",
2711 segwitAvailable: false,
2712 onSelect: function() {
2713 network = bitcoinjs.bitcoin.networks.bitcoin;
2714 setHdCoin(178);
2715 },
2716 },
2717 {
2718 name: "POSW - POSWcoin",
2719 onSelect: function() {
2720 network = bitcoinjs.bitcoin.networks.poswcoin;
2721 setHdCoin(47);
2722 },
2723 },
2724 {
2725 name: "POT - Potcoin",
2726 onSelect: function() {
2727 network = bitcoinjs.bitcoin.networks.potcoin;
2728 setHdCoin(81);
2729 },
2730 },
2731 {
2732 name: "PPC - Peercoin",
2733 onSelect: function() {
2734 network = bitcoinjs.bitcoin.networks.peercoin;
2735 setHdCoin(6);
2736 },
2737 },
2738 {
2739 name: "PRJ - ProjectCoin",
2740 onSelect: function() {
2741 network = bitcoinjs.bitcoin.networks.projectcoin;
2742 setHdCoin(533);
2743 },
2744 },
2745 {
2746 name: "PSB - Pesobit",
2747 onSelect: function() {
2748 network = bitcoinjs.bitcoin.networks.pesobit;
2749 setHdCoin(62);
2750 },
2751 },
2752 {
2753 name: "PUT - Putincoin",
2754 onSelect: function() {
2755 network = bitcoinjs.bitcoin.networks.putincoin;
2756 setHdCoin(122);
2757 },
2758 },
2759 {
2760 name: "RPD - Rapids",
2761 onSelect: function() {
2762 network = bitcoinjs.bitcoin.networks.rapids;
2763 setHdCoin(320);
2764 },
2765 },
2766 {
2767 name: "RVN - Ravencoin",
2768 onSelect: function() {
2769 network = bitcoinjs.bitcoin.networks.ravencoin;
2770 setHdCoin(175);
2771 },
2772 },
2773 {
2774 name: "RBY - Rubycoin",
2775 onSelect: function() {
2776 network = bitcoinjs.bitcoin.networks.rubycoin;
2777 setHdCoin(16);
2778 },
2779 },
2780 {
2781 name: "RDD - Reddcoin",
2782 onSelect: function() {
2783 network = bitcoinjs.bitcoin.networks.reddcoin;
2784 setHdCoin(4);
2785 },
2786 },
2787 {
2788 name: "RVR - RevolutionVR",
2789 onSelect: function() {
2790 network = bitcoinjs.bitcoin.networks.revolutionvr;
2791 setHdCoin(129);
2792 },
2793 },
2794 {
2795 name: "SAFE - Safecoin",
2796 onSelect: function() {
2797 network = bitcoinjs.bitcoin.networks.safecoin;
2798 setHdCoin(19165);
2799 },
2800 },
2801 {
2802 name: "SLS - Salus",
2803 onSelect: function() {
2804 network = bitcoinjs.bitcoin.networks.salus;
2805 setHdCoin(63);
2806 },
2807 },
2808 {
2809 name: "SDC - ShadowCash",
2810 onSelect: function() {
2811 network = bitcoinjs.bitcoin.networks.shadow;
2812 setHdCoin(35);
2813 },
2814 },
2815 {
2816 name: "SDC - ShadowCash Testnet",
2817 onSelect: function() {
2818 network = bitcoinjs.bitcoin.networks.shadowtn;
2819 setHdCoin(1);
2820 },
2821 },
2822 {
2823 name: "SLM - Slimcoin",
2824 onSelect: function() {
2825 network = bitcoinjs.bitcoin.networks.slimcoin;
2826 setHdCoin(63);
2827 },
2828 },
2829 {
2830 name: "SLM - Slimcoin Testnet",
2831 onSelect: function() {
2832 network = bitcoinjs.bitcoin.networks.slimcointn;
2833 setHdCoin(111);
2834 },
2835 },
2836 {
2837 name: "SLP - Simple Ledger Protocol",
2838 onSelect: function() {
2839 DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
2840 setHdCoin(245);
2841 },
2842 },
2843 {
2844 name: "SLR - Solarcoin",
2845 onSelect: function() {
2846 network = bitcoinjs.bitcoin.networks.solarcoin;
2847 setHdCoin(58);
2848 },
2849 },
2850 {
2851 name: "SMLY - Smileycoin",
2852 onSelect: function() {
2853 network = bitcoinjs.bitcoin.networks.smileycoin;
2854 setHdCoin(59);
2855 },
2856 },
2857 {
2858 name: "STASH - Stash",
2859 onSelect: function() {
2860 network = bitcoinjs.bitcoin.networks.stash;
2861 setHdCoin(0xC0C0);
2862 },
2863 },
2864 {
2865 name: "STASH - Stash Testnet",
2866 onSelect: function() {
2867 network = bitcoinjs.bitcoin.networks.stashtn;
2868 setHdCoin(0xCAFE);
2869 },
2870 },
2871 {
2872 name: "STRAT - Stratis",
2873 onSelect: function() {
2874 network = bitcoinjs.bitcoin.networks.stratis;
2875 setHdCoin(105);
2876 },
2877 },
2878 {
2879 name: "TSTRAT - Stratis Testnet",
2880 onSelect: function() {
2881 network = bitcoinjs.bitcoin.networks.stratistest;
2882 setHdCoin(105);
2883 },
2884 },
2885 {
2886 name: "SYS - Syscoin",
2887 onSelect: function() {
2888 network = bitcoinjs.bitcoin.networks.syscoin;
2889 setHdCoin(57);
2890 },
2891 },
2892 {
2893 name: "THC - Hempcoin",
2894 onSelect: function() {
2895 network = bitcoinjs.bitcoin.networks.hempcoin;
2896 setHdCoin(113);
2897 },
2898 },
2899 {
2900 name: "TOA - Toa",
2901 onSelect: function() {
2902 network = bitcoinjs.bitcoin.networks.toa;
2903 setHdCoin(159);
2904 },
2905 },
2906 {
2907 name: "TWINS - TWINS",
2908 onSelect: function() {
2909 network = bitcoinjs.bitcoin.networks.twins;
2910 setHdCoin(970);
2911 },
2912 },
2913 {
2914 name: "TWINS - TWINS Testnet",
2915 onSelect: function() {
2916 network = bitcoinjs.bitcoin.networks.twinstestnet;
2917 setHdCoin(1);
2918 },
2919 },
2920 {
2921 name: "USC - Ultimatesecurecash",
2922 onSelect: function() {
2923 network = bitcoinjs.bitcoin.networks.ultimatesecurecash;
2924 setHdCoin(112);
2925 },
2926 },
2927 {
2928 name: "USNBT - NuBits",
2929 onSelect: function() {
2930 network = bitcoinjs.bitcoin.networks.nubits;
2931 setHdCoin(12);
2932 },
2933 },
2934 {
2935 name: "UNO - Unobtanium",
2936 onSelect: function() {
2937 network = bitcoinjs.bitcoin.networks.unobtanium;
2938 setHdCoin(92);
2939 },
2940 },
2941 {
2942 name: "VASH - Vpncoin",
2943 onSelect: function() {
2944 network = bitcoinjs.bitcoin.networks.vpncoin;
2945 setHdCoin(33);
2946 },
2947 },
2948 {
2949 name: "VET - VeChain",
2950 onSelect: function() {
2951 network = bitcoinjs.bitcoin.networks.bitcoin;
2952 setHdCoin(818);
2953 },
2954 },
2955 {
2956 name: "VIA - Viacoin",
2957 onSelect: function() {
2958 network = bitcoinjs.bitcoin.networks.viacoin;
2959 setHdCoin(14);
2960 },
2961 },
2962 {
2963 name: "VIA - Viacoin Testnet",
2964 onSelect: function() {
2965 network = bitcoinjs.bitcoin.networks.viacointestnet;
2966 setHdCoin(1);
2967 },
2968 },
2969 {
2970 name: "VIVO - Vivo",
2971 onSelect: function() {
2972 network = bitcoinjs.bitcoin.networks.vivo;
2973 setHdCoin(166);
2974 },
2975 },
2976 {
2977 name: "VTC - Vertcoin",
2978 onSelect: function() {
2979 network = bitcoinjs.bitcoin.networks.vertcoin;
2980 setHdCoin(28);
2981 },
2982 },
2983 {
2984 name: "WGR - Wagerr",
2985 onSelect: function() {
2986 network = bitcoinjs.bitcoin.networks.wagerr;
2987 setHdCoin(7825266);
2988 },
2989 },
2990 {
2991 name: "WC - Wincoin",
2992 onSelect: function() {
2993 network = bitcoinjs.bitcoin.networks.wincoin;
2994 setHdCoin(181);
2995 },
2996 },
2997 {
2998 name: "XAX - Artax",
2999 onSelect: function() {
3000 network = bitcoinjs.bitcoin.networks.artax;
3001 setHdCoin(219);
3002 },
3003 },
3004 {
3005 name: "XBC - Bitcoinplus",
3006 onSelect: function() {
3007 network = bitcoinjs.bitcoin.networks.bitcoinplus;
3008 setHdCoin(65);
3009 },
3010 },
3011 {
3012 name: "XLM - Stellar",
3013 onSelect: function() {
3014 network = stellarUtil.dummyNetwork;
3015 setHdCoin(148);
3016 },
3017 },
3018 {
3019 name: "XMY - Myriadcoin",
3020 onSelect: function() {
3021 network = bitcoinjs.bitcoin.networks.myriadcoin;
3022 setHdCoin(90);
3023 },
3024 },
3025 {
3026 name: "XRP - Ripple",
3027 onSelect: function() {
3028 network = bitcoinjs.bitcoin.networks.bitcoin;
3029 setHdCoin(144);
3030 },
3031 },
3032 {
3033 name: "XVC - Vcash",
3034 onSelect: function() {
3035 network = bitcoinjs.bitcoin.networks.vcash;
3036 setHdCoin(127);
3037 },
3038 },
3039 {
3040 name: "XVG - Verge",
3041 onSelect: function() {
3042 network = bitcoinjs.bitcoin.networks.verge;
3043 setHdCoin(77);
3044 },
3045 },
3046 {
3047 name: "XUEZ - Xuez",
3048 segwitAvailable: false,
3049 onSelect: function() {
3050 network = bitcoinjs.bitcoin.networks.xuez;
3051 setHdCoin(225);
3052 },
3053 },
3054 {
3055 name: "XWC - Whitecoin",
3056 onSelect: function() {
3057 network = bitcoinjs.bitcoin.networks.whitecoin;
3058 setHdCoin(155);
3059 },
3060 },
3061 {
3062 name: "XZC - Zcoin",
3063 onSelect: function() {
3064 network = bitcoinjs.bitcoin.networks.zcoin;
3065 setHdCoin(136);
3066 },
3067 },
3068 {
3069 name: "ZCL - Zclassic",
3070 onSelect: function() {
3071 network = bitcoinjs.bitcoin.networks.zclassic;
3072 setHdCoin(147);
3073 },
3074 },
3075 {
3076 name: "ZEC - Zcash",
3077 onSelect: function() {
3078 network = bitcoinjs.bitcoin.networks.zcash;
3079 setHdCoin(133);
3080 },
3081 },
3082 {
3083 name: "ZEN - Horizen",
3084 onSelect: function() {
3085 network = bitcoinjs.bitcoin.networks.zencash;
3086 setHdCoin(121);
3087 },
3088 },
3089 ]
3090
3091 var clients = [
3092 {
3093 name: "Bitcoin Core",
3094 onSelect: function() {
3095 DOM.bip32path.val("m/0'/0'");
3096 DOM.hardenedAddresses.prop('checked', true);
3097 },
3098 },
3099 {
3100 name: "blockchain.info",
3101 onSelect: function() {
3102 DOM.bip32path.val("m/44'/0'/0'");
3103 DOM.hardenedAddresses.prop('checked', false);
3104 },
3105 },
3106 {
3107 name: "MultiBit HD",
3108 onSelect: function() {
3109 DOM.bip32path.val("m/0'/0");
3110 DOM.hardenedAddresses.prop('checked', false);
3111 },
3112 },
3113 {
3114 name: "Coinomi, Ledger",
3115 onSelect: function() {
3116 DOM.bip32path.val("m/44'/"+DOM.bip44coin.val()+"'/0'");
3117 DOM.hardenedAddresses.prop('checked', false);
3118 },
3119 }
3120 ]
3121
3122 init();
3123
3124 })();