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