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