3 // mnemonics is populated as required by getLanguage
4 var mnemonics
= { "english": new Mnemonic("english") };
5 var mnemonic
= mnemonics
["english"];
7 var bip32RootKey
= null;
8 var bip32ExtendedKey
= null;
9 var network
= libs
.bitcoin
.networks
.bitcoin
;
10 var addressRowTemplate
= $("#address-row-template");
13 var showAddress
= true;
14 var showPubKey
= true;
15 var showPrivKey
= true;
17 var litecoinUseLtub
= true;
19 var entropyTypeAutoDetect
= true;
20 var entropyChangeTimeoutEvent
= null;
21 var phraseChangeTimeoutEvent
= null;
22 var seedChangedTimeoutEvent
= null;
23 var rootKeyChangedTimeoutEvent
= null;
25 var generationProcesses
= [];
28 DOM
.privacyScreenToggle
= $(".privacy-screen-toggle");
29 DOM
.network
= $(".network");
30 DOM
.bip32Client
= $("#bip32-client");
31 DOM
.phraseNetwork
= $("#network-phrase");
32 DOM
.useEntropy
= $(".use-entropy");
33 DOM
.entropyContainer
= $(".entropy-container");
34 DOM
.entropy
= $(".entropy");
35 DOM
.entropyFiltered
= DOM
.entropyContainer
.find(".filtered");
36 DOM
.entropyType
= DOM
.entropyContainer
.find(".type");
37 DOM
.entropyTypeInputs
= DOM
.entropyContainer
.find("input[name='entropy-type']");
38 DOM
.entropyCrackTime
= DOM
.entropyContainer
.find(".crack-time");
39 DOM
.entropyEventCount
= DOM
.entropyContainer
.find(".event-count");
40 DOM
.entropyBits
= DOM
.entropyContainer
.find(".bits");
41 DOM
.entropyBitsPerEvent
= DOM
.entropyContainer
.find(".bits-per-event");
42 DOM
.entropyWordCount
= DOM
.entropyContainer
.find(".word-count");
43 DOM
.entropyBinary
= DOM
.entropyContainer
.find(".binary");
44 DOM
.entropyWordIndexes
= DOM
.entropyContainer
.find(".word-indexes");
45 DOM
.entropyChecksum
= DOM
.entropyContainer
.find(".checksum");
46 DOM
.entropyMnemonicLength
= DOM
.entropyContainer
.find(".mnemonic-length");
47 DOM
.entropyWeakEntropyOverrideWarning
= DOM
.entropyContainer
.find(".weak-entropy-override-warning");
48 DOM
.entropyFilterWarning
= DOM
.entropyContainer
.find(".filter-warning");
49 DOM
.phrase
= $(".phrase");
50 DOM
.phraseSplit
= $(".phraseSplit");
51 DOM
.phraseSplitWarn
= $(".phraseSplitWarn");
52 DOM
.passphrase
= $(".passphrase");
53 DOM
.generateContainer
= $(".generate-container");
54 DOM
.generate
= $(".generate");
55 DOM
.seed
= $(".seed");
56 DOM
.rootKey
= $(".root-key");
57 DOM
.litecoinLtubContainer
= $(".litecoin-ltub-container");
58 DOM
.litecoinUseLtub
= $(".litecoin-use-ltub");
59 DOM
.extendedPrivKey
= $(".extended-priv-key");
60 DOM
.extendedPubKey
= $(".extended-pub-key");
61 DOM
.bip32tab
= $("#bip32-tab");
62 DOM
.bip44tab
= $("#bip44-tab");
63 DOM
.bip49tab
= $("#bip49-tab");
64 DOM
.bip84tab
= $("#bip84-tab");
65 DOM
.bip141tab
= $("#bip141-tab");
66 DOM
.bip32panel
= $("#bip32");
67 DOM
.bip44panel
= $("#bip44");
68 DOM
.bip49panel
= $("#bip49");
69 DOM
.bip32path
= $("#bip32-path");
70 DOM
.bip44path
= $("#bip44-path");
71 DOM
.bip44purpose
= $("#bip44 .purpose");
72 DOM
.bip44coin
= $("#bip44 .coin");
73 DOM
.bip44account
= $("#bip44 .account");
74 DOM
.bip44accountXprv
= $("#bip44 .account-xprv");
75 DOM
.bip44accountXpub
= $("#bip44 .account-xpub");
76 DOM
.bip44change
= $("#bip44 .change");
77 DOM
.bip49unavailable
= $("#bip49 .unavailable");
78 DOM
.bip49available
= $("#bip49 .available");
79 DOM
.bip49path
= $("#bip49-path");
80 DOM
.bip49purpose
= $("#bip49 .purpose");
81 DOM
.bip49coin
= $("#bip49 .coin");
82 DOM
.bip49account
= $("#bip49 .account");
83 DOM
.bip49accountXprv
= $("#bip49 .account-xprv");
84 DOM
.bip49accountXpub
= $("#bip49 .account-xpub");
85 DOM
.bip49change
= $("#bip49 .change");
86 DOM
.bip84unavailable
= $("#bip84 .unavailable");
87 DOM
.bip84available
= $("#bip84 .available");
88 DOM
.bip84path
= $("#bip84-path");
89 DOM
.bip84purpose
= $("#bip84 .purpose");
90 DOM
.bip84coin
= $("#bip84 .coin");
91 DOM
.bip84account
= $("#bip84 .account");
92 DOM
.bip84accountXprv
= $("#bip84 .account-xprv");
93 DOM
.bip84accountXpub
= $("#bip84 .account-xpub");
94 DOM
.bip84change
= $("#bip84 .change");
95 DOM
.bip141unavailable
= $("#bip141 .unavailable");
96 DOM
.bip141available
= $("#bip141 .available");
97 DOM
.bip141path
= $("#bip141-path");
98 DOM
.bip141semantics
= $(".bip141-semantics");
99 DOM
.generatedStrength
= $(".generate-container .strength");
100 DOM
.generatedStrengthWarning
= $(".generate-container .warning");
101 DOM
.hardenedAddresses
= $(".hardened-addresses");
102 DOM
.bitcoinCashAddressTypeContainer
= $(".bch-addr-type-container");
103 DOM
.bitcoinCashAddressType
= $("[name=bch-addr-type]")
104 DOM
.useBip38
= $(".use-bip38");
105 DOM
.bip38Password
= $(".bip38-password");
106 DOM
.addresses
= $(".addresses");
107 DOM
.csvTab
= $("#csv-tab a");
109 DOM
.rowsToAdd
= $(".rows-to-add");
110 DOM
.more
= $(".more");
111 DOM
.moreRowsStartIndex
= $(".more-rows-start-index");
112 DOM
.feedback
= $(".feedback");
113 DOM
.tab
= $(".derivation-type a");
114 DOM
.indexToggle
= $(".index-toggle");
115 DOM
.addressToggle
= $(".address-toggle");
116 DOM
.publicKeyToggle
= $(".public-key-toggle");
117 DOM
.privateKeyToggle
= $(".private-key-toggle");
118 DOM
.languages
= $(".languages a");
119 DOM
.qrContainer
= $(".qr-container");
120 DOM
.qrHider
= DOM
.qrContainer
.find(".qr-hider");
121 DOM
.qrImage
= DOM
.qrContainer
.find(".qr-image");
122 DOM
.qrHint
= DOM
.qrContainer
.find(".qr-hint");
123 DOM
.showQrEls
= $("[data-show-qr]");
127 DOM
.privacyScreenToggle
.on("change", privacyScreenToggled
);
128 DOM
.generatedStrength
.on("change", generatedStrengthChanged
);
129 DOM
.network
.on("change", networkChanged
);
130 DOM
.bip32Client
.on("change", bip32ClientChanged
);
131 DOM
.useEntropy
.on("change", setEntropyVisibility
);
132 DOM
.entropy
.on("input", delayedEntropyChanged
);
133 DOM
.entropyMnemonicLength
.on("change", entropyChanged
);
134 DOM
.entropyTypeInputs
.on("change", entropyTypeChanged
);
135 DOM
.phrase
.on("input", delayedPhraseChanged
);
136 DOM
.passphrase
.on("input", delayedPhraseChanged
);
137 DOM
.generate
.on("click", generateClicked
);
138 DOM
.more
.on("click", showMore
);
139 DOM
.seed
.on("input", delayedSeedChanged
);
140 DOM
.rootKey
.on("input", delayedRootKeyChanged
);
141 DOM
.litecoinUseLtub
.on("change", litecoinUseLtubChanged
);
142 DOM
.bip32path
.on("input", calcForDerivationPath
);
143 DOM
.bip44account
.on("input", calcForDerivationPath
);
144 DOM
.bip44change
.on("input", calcForDerivationPath
);
145 DOM
.bip49account
.on("input", calcForDerivationPath
);
146 DOM
.bip49change
.on("input", calcForDerivationPath
);
147 DOM
.bip84account
.on("input", calcForDerivationPath
);
148 DOM
.bip84change
.on("input", calcForDerivationPath
);
149 DOM
.bip141path
.on("input", calcForDerivationPath
);
150 DOM
.bip141semantics
.on("change", tabChanged
);
151 DOM
.tab
.on("shown.bs.tab", tabChanged
);
152 DOM
.hardenedAddresses
.on("change", calcForDerivationPath
);
153 DOM
.useBip38
.on("change", calcForDerivationPath
);
154 DOM
.bip38Password
.on("change", calcForDerivationPath
);
155 DOM
.indexToggle
.on("click", toggleIndexes
);
156 DOM
.addressToggle
.on("click", toggleAddresses
);
157 DOM
.publicKeyToggle
.on("click", togglePublicKeys
);
158 DOM
.privateKeyToggle
.on("click", togglePrivateKeys
);
159 DOM
.csvTab
.on("click", updateCsv
);
160 DOM
.languages
.on("click", languageChanged
);
161 DOM
.bitcoinCashAddressType
.on("change", bitcoinCashAddressTypeChange
);
162 setQrEvents(DOM
.showQrEls
);
165 hideValidationError();
166 populateNetworkSelect();
167 populateClientSelect();
172 function generatedStrengthChanged() {
173 var strength
= parseInt(DOM
.generatedStrength
.val());
175 DOM
.generatedStrengthWarning
.removeClass("hidden");
178 DOM
.generatedStrengthWarning
.addClass("hidden");
182 function networkChanged(e
) {
184 clearAddressesList();
185 DOM
.litecoinLtubContainer
.addClass("hidden");
186 DOM
.bitcoinCashAddressTypeContainer
.addClass("hidden");
187 var networkIndex
= e
.target
.value
;
188 var network
= networks
[networkIndex
];
190 adjustNetworkForSegwit();
199 function bip32ClientChanged(e
) {
200 var clientIndex
= DOM
.bip32Client
.val();
201 if (clientIndex
== "custom") {
202 DOM
.bip32path
.prop("readonly", false);
205 DOM
.bip32path
.prop("readonly", true);
206 clients
[clientIndex
].onSelect();
216 function setEntropyVisibility() {
217 if (isUsingOwnEntropy()) {
218 DOM
.entropyContainer
.removeClass("hidden");
219 DOM
.generateContainer
.addClass("hidden");
220 DOM
.phrase
.prop("readonly", true);
225 DOM
.entropyContainer
.addClass("hidden");
226 DOM
.generateContainer
.removeClass("hidden");
227 DOM
.phrase
.prop("readonly", false);
232 function delayedPhraseChanged() {
233 hideValidationError();
236 bip32ExtendedKey
= null;
237 clearAddressesList();
239 if (phraseChangeTimeoutEvent
!= null) {
240 clearTimeout(phraseChangeTimeoutEvent
);
242 phraseChangeTimeoutEvent
= setTimeout(function() {
244 var entropy
= mnemonic
.toRawEntropyHex(DOM
.phrase
.val());
245 if (entropy
!== null) {
246 DOM
.entropyMnemonicLength
.val("raw");
247 DOM
.entropy
.val(entropy
);
248 DOM
.entropyTypeInputs
.filter("[value='hexadecimal']").prop("checked", true);
249 entropyTypeAutoDetect
= false;
254 function phraseChanged() {
256 setMnemonicLanguage();
257 // Get the mnemonic phrase
258 var phrase
= DOM
.phrase
.val();
259 var errorText
= findPhraseErrors(phrase
);
261 showValidationError(errorText
);
264 // Calculate and display
265 var passphrase
= DOM
.passphrase
.val();
266 calcBip32RootKeyFromSeed(phrase
, passphrase
);
267 calcForDerivationPath();
268 // Show the word indexes
270 writeSplitPhrase(phrase
);
273 function tabChanged() {
275 adjustNetworkForSegwit();
276 var phrase
= DOM
.phrase
.val();
278 // Calculate and display for mnemonic
279 var errorText
= findPhraseErrors(phrase
);
281 showValidationError(errorText
);
284 // Calculate and display
285 var passphrase
= DOM
.passphrase
.val();
286 calcBip32RootKeyFromSeed(phrase
, passphrase
);
289 // Calculate and display for root key
290 var rootKeyBase58
= DOM
.rootKey
.val();
291 var errorText
= validateRootKey(rootKeyBase58
);
293 showValidationError(errorText
);
296 // Calculate and display
297 calcBip32RootKeyFromBase58(rootKeyBase58
);
299 calcForDerivationPath();
302 function delayedEntropyChanged() {
303 hideValidationError();
305 if (entropyChangeTimeoutEvent
!= null) {
306 clearTimeout(entropyChangeTimeoutEvent
);
308 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
311 function entropyChanged() {
312 // If blank entropy, clear mnemonic, addresses, errors
313 if (DOM
.entropy
.val().trim().length
== 0) {
315 clearEntropyFeedback();
317 DOM
.phraseSplit
.val("");
318 showValidationError("Blank entropy");
321 // Get the current phrase to detect changes
322 var phrase
= DOM
.phrase
.val();
323 // Set the phrase from the entropy
324 setMnemonicFromEntropy();
325 // Recalc addresses if the phrase has changed
326 var newPhrase
= DOM
.phrase
.val();
327 if (newPhrase
!= phrase
) {
328 if (newPhrase
.length
== 0) {
340 function entropyTypeChanged() {
341 entropyTypeAutoDetect
= false;
345 function delayedSeedChanged() {
346 // Warn if there is an existing mnemonic or passphrase.
347 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
348 if (!confirm("This will clear existing mnemonic and passphrase")) {
353 hideValidationError();
355 // Clear existing mnemonic and passphrase
357 DOM
.phraseSplit
.val("");
358 DOM
.passphrase
.val("");
360 clearAddressesList();
363 if (seedChangedTimeoutEvent
!= null) {
364 clearTimeout(seedChangedTimeoutEvent
);
366 seedChangedTimeoutEvent
= setTimeout(seedChanged
, 400);
369 function delayedRootKeyChanged() {
370 // Warn if there is an existing mnemonic or passphrase.
371 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
372 if (!confirm("This will clear existing mnemonic and passphrase")) {
373 DOM
.rootKey
.val(bip32RootKey
);
377 hideValidationError();
379 // Clear existing mnemonic and passphrase
381 DOM
.phraseSplit
.val("");
382 DOM
.passphrase
.val("");
384 if (rootKeyChangedTimeoutEvent
!= null) {
385 clearTimeout(rootKeyChangedTimeoutEvent
);
387 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
390 function seedChanged() {
392 hideValidationError();
393 seed
= DOM
.seed
.val();
394 bip32RootKey
= libs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
395 var rootKeyBase58
= bip32RootKey
.toBase58();
396 DOM
.rootKey
.val(rootKeyBase58
);
397 var errorText
= validateRootKey(rootKeyBase58
);
399 showValidationError(errorText
);
402 // Calculate and display
403 calcForDerivationPath();
406 function rootKeyChanged() {
408 hideValidationError();
409 var rootKeyBase58
= DOM
.rootKey
.val();
410 var errorText
= validateRootKey(rootKeyBase58
);
412 showValidationError(errorText
);
415 // Calculate and display
416 calcBip32RootKeyFromBase58(rootKeyBase58
);
417 calcForDerivationPath();
420 function litecoinUseLtubChanged() {
421 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
422 if (litecoinUseLtub
) {
423 network
= libs
.bitcoin
.networks
.litecoin
;
426 network
= libs
.bitcoin
.networks
.litecoinXprv
;
431 function calcForDerivationPath() {
433 clearAddressesList();
435 // Don't show segwit if it's selected but network doesn't support it
436 if (segwitSelected() && !networkHasSegwit()) {
437 showSegwitUnavailable();
441 showSegwitAvailable();
442 // Get the derivation path
443 var derivationPath
= getDerivationPath();
444 var errorText
= findDerivationPathErrors(derivationPath
);
446 showValidationError(errorText
);
449 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
450 if (bip44TabSelected()) {
453 else if (bip49TabSelected()) {
456 else if (bip84TabSelected()) {
462 function generateClicked() {
463 if (isUsingOwnEntropy()) {
468 setTimeout(function() {
469 setMnemonicLanguage();
470 var phrase
= generateRandomPhrase();
478 function languageChanged() {
479 setTimeout(function() {
480 setMnemonicLanguage();
481 if (DOM
.phrase
.val().length
> 0) {
482 var newPhrase
= convertPhraseToNewLanguage();
483 DOM
.phrase
.val(newPhrase
);
487 DOM
.generate
.trigger("click");
492 function bitcoinCashAddressTypeChange() {
496 function toggleIndexes() {
497 showIndex
= !showIndex
;
498 $("td.index span").toggleClass("invisible");
501 function toggleAddresses() {
502 showAddress
= !showAddress
;
503 $("td.address span").toggleClass("invisible");
506 function togglePublicKeys() {
507 showPubKey
= !showPubKey
;
508 $("td.pubkey span").toggleClass("invisible");
511 function togglePrivateKeys() {
512 showPrivKey
= !showPrivKey
;
513 $("td.privkey span").toggleClass("invisible");
516 function privacyScreenToggled() {
517 // private-data contains elements added to DOM at runtime
518 // so catch all by adding visual privacy class to the root of the DOM
519 if (DOM
.privacyScreenToggle
.prop("checked")) {
520 $("body").addClass("visual-privacy");
523 $("body").removeClass("visual-privacy");
529 function generateRandomPhrase() {
530 if (!hasStrongRandom()) {
531 var errorText
= "This browser does not support strong randomness";
532 showValidationError(errorText
);
535 // get the amount of entropy to use
536 var numWords
= parseInt(DOM
.generatedStrength
.val());
537 var strength
= numWords
/ 3 * 32;
538 var buffer
= new Uint8Array(strength
/ 8);
539 // create secure entropy
540 var data
= crypto
.getRandomValues(buffer
);
542 var words
= mnemonic
.toMnemonic(data
);
543 DOM
.phrase
.val(words
);
545 var entropyHex
= uint8ArrayToHex(data
);
546 DOM
.entropy
.val(entropyHex
);
547 // ensure entropy fields are consistent with what is being displayed
548 DOM
.entropyMnemonicLength
.val("raw");
552 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
553 seed
= mnemonic
.toSeed(phrase
, passphrase
);
554 bip32RootKey
= libs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
556 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
560 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
562 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
565 // try parsing with various segwit network params since this extended
566 // key may be from any one of them.
567 if (networkHasSegwit()) {
569 if ("baseNetwork" in n
) {
570 n
= libs
.bitcoin
.networks
[n
.baseNetwork
];
572 // try parsing using base network params
574 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
578 // try parsing using p2wpkh params
581 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
586 // try parsing using p2wpkh-in-p2sh network params
587 if ("p2wpkhInP2sh" in n
) {
589 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
594 // try parsing using p2wsh network params
597 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
602 // try parsing using p2wsh-in-p2sh network params
603 if ("p2wshInP2sh" in n
) {
605 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
611 // try the network params as currently specified
612 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
615 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
616 // try parsing with various segwit network params since this extended
617 // key may be from any one of them.
618 if (networkHasSegwit()) {
620 if ("baseNetwork" in n
) {
621 n
= libs
.bitcoin
.networks
[n
.baseNetwork
];
623 // try parsing using base network params
625 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
629 // try parsing using p2wpkh params
632 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
637 // try parsing using p2wpkh-in-p2sh network params
638 if ("p2wpkhInP2sh" in n
) {
640 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
646 // try the network params as currently specified
647 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
650 function calcBip32ExtendedKey(path
) {
651 // Check there's a root key to derive from
655 var extendedKey
= bip32RootKey
;
656 // Derive the key from the path
657 var pathBits
= path
.split("/");
658 for (var i
=0; i
<pathBits
.length
; i
++) {
659 var bit
= pathBits
[i
];
660 var index
= parseInt(bit
);
664 var hardened
= bit
[bit
.length
-1] == "'";
665 var isPriv
= !(extendedKey
.isNeutered());
666 var invalidDerivationPath
= hardened
&& !isPriv
;
667 if (invalidDerivationPath
) {
671 extendedKey
= extendedKey
.deriveHardened(index
);
674 extendedKey
= extendedKey
.derive(index
);
680 function showValidationError(errorText
) {
686 function hideValidationError() {
692 function findPhraseErrors(phrase
) {
693 // Preprocess the words
694 phrase
= mnemonic
.normalizeString(phrase
);
695 var words
= phraseToWordArray(phrase
);
696 // Detect blank phrase
697 if (words
.length
== 0) {
698 return "Blank mnemonic";
701 for (var i
=0; i
<words
.length
; i
++) {
703 var language
= getLanguage();
704 if (WORDLISTS
[language
].indexOf(word
) == -1) {
705 console
.log("Finding closest match to " + word
);
706 var nearestWord
= findNearestWord(word
);
707 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
710 // Check the words are valid
711 var properPhrase
= wordArrayToPhrase(words
);
712 var isValid
= mnemonic
.check(properPhrase
);
714 return "Invalid mnemonic";
719 function validateRootKey(rootKeyBase58
) {
721 return validateRootKeyGRS(rootKeyBase58
);
723 // try various segwit network params since this extended key may be from
725 if (networkHasSegwit()) {
727 if ("baseNetwork" in n
) {
728 n
= libs
.bitcoin
.networks
[n
.baseNetwork
];
730 // try parsing using base network params
732 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
736 // try parsing using p2wpkh params
739 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
744 // try parsing using p2wpkh-in-p2sh network params
745 if ("p2wpkhInP2sh" in n
) {
747 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
752 // try parsing using p2wsh network params
755 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
760 // try parsing using p2wsh-in-p2sh network params
761 if ("p2wshInP2sh" in n
) {
763 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
769 // try the network params as currently specified
771 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
774 return "Invalid root key";
779 function validateRootKeyGRS(rootKeyBase58
) {
780 // try various segwit network params since this extended key may be from
782 if (networkHasSegwit()) {
784 if ("baseNetwork" in n
) {
785 n
= libs
.bitcoin
.networks
[n
.baseNetwork
];
787 // try parsing using base network params
789 libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
793 // try parsing using p2wpkh params
796 libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
801 // try parsing using p2wpkh-in-p2sh network params
802 if ("p2wpkhInP2sh" in n
) {
804 libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
810 // try the network params as currently specified
812 libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
815 return "Invalid root key";
820 function getDerivationPath() {
821 if (bip44TabSelected()) {
822 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
823 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
824 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
825 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
827 path
+= purpose
+ "'/";
829 path
+= account
+ "'/";
831 DOM
.bip44path
.val(path
);
832 var derivationPath
= DOM
.bip44path
.val();
833 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
834 return derivationPath
;
836 else if (bip49TabSelected()) {
837 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
838 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
839 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
840 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
842 path
+= purpose
+ "'/";
844 path
+= account
+ "'/";
846 DOM
.bip49path
.val(path
);
847 var derivationPath
= DOM
.bip49path
.val();
848 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
849 return derivationPath
;
851 else if (bip84TabSelected()) {
852 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
853 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
854 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
855 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
857 path
+= purpose
+ "'/";
859 path
+= account
+ "'/";
861 DOM
.bip84path
.val(path
);
862 var derivationPath
= DOM
.bip84path
.val();
863 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
864 return derivationPath
;
866 else if (bip32TabSelected()) {
867 var derivationPath
= DOM
.bip32path
.val();
868 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
869 return derivationPath
;
871 else if (bip141TabSelected()) {
872 var derivationPath
= DOM
.bip141path
.val();
873 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
874 return derivationPath
;
877 console
.log("Unknown derivation path");
881 function findDerivationPathErrors(path
) {
882 // TODO is not perfect but is better than nothing
884 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
886 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
887 var maxDepth
= 255; // TODO verify this!!
888 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
889 if (path
[0] != "m") {
890 return "First character must be 'm'";
892 if (path
.length
> 1) {
893 if (path
[1] != "/") {
894 return "Separator must be '/'";
896 var indexes
= path
.split("/");
897 if (indexes
.length
> maxDepth
) {
898 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
900 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
901 var index
= indexes
[depth
];
902 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
903 if (invalidChars
.length
> 0) {
904 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
906 var indexValue
= parseInt(index
.replace("'", ""));
908 return "Invalid number at depth " + depth
;
910 if (indexValue
> maxIndexValue
) {
911 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
915 // Check root key exists or else derivation path is useless!
917 return "No root key";
919 // Check no hardened derivation path when using xpub keys
920 var hardenedPath
= path
.indexOf("'") > -1;
921 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
922 var hardened
= hardenedPath
|| hardenedAddresses
;
923 var isXpubkey
= bip32RootKey
.isNeutered();
924 if (hardened
&& isXpubkey
) {
925 return "Hardened derivation path is invalid with xpub key";
931 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
935 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
938 function displayBip44Info() {
939 // Get the derivation path for the account
940 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
941 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
942 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
944 path
+= purpose
+ "'/";
946 path
+= account
+ "'/";
947 // Calculate the account extended keys
948 var accountExtendedKey
= calcBip32ExtendedKey(path
);
949 var accountXprv
= accountExtendedKey
.toBase58();
950 var accountXpub
= accountExtendedKey
.neutered().toBase58();
952 // Display the extended keys
953 DOM
.bip44accountXprv
.val(accountXprv
);
954 DOM
.bip44accountXpub
.val(accountXpub
);
957 displayBip44InfoForELA();
961 function displayBip49Info() {
962 // Get the derivation path for the account
963 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
964 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
965 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
967 path
+= purpose
+ "'/";
969 path
+= account
+ "'/";
970 // Calculate the account extended keys
971 var accountExtendedKey
= calcBip32ExtendedKey(path
);
972 var accountXprv
= accountExtendedKey
.toBase58();
973 var accountXpub
= accountExtendedKey
.neutered().toBase58();
974 // Display the extended keys
975 DOM
.bip49accountXprv
.val(accountXprv
);
976 DOM
.bip49accountXpub
.val(accountXpub
);
979 function displayBip84Info() {
980 // Get the derivation path for the account
981 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
982 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
983 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
985 path
+= purpose
+ "'/";
987 path
+= account
+ "'/";
988 // Calculate the account extended keys
989 var accountExtendedKey
= calcBip32ExtendedKey(path
);
990 var accountXprv
= accountExtendedKey
.toBase58();
991 var accountXpub
= accountExtendedKey
.neutered().toBase58();
992 // Display the extended keys
993 DOM
.bip84accountXprv
.val(accountXprv
);
994 DOM
.bip84accountXpub
.val(accountXpub
);
997 function displayBip32Info() {
1000 var rootKey
= bip32RootKey
.toBase58();
1001 DOM
.rootKey
.val(rootKey
);
1002 var xprvkeyB58
= "NA";
1003 if (!bip32ExtendedKey
.isNeutered()) {
1004 xprvkeyB58
= bip32ExtendedKey
.toBase58();
1006 var extendedPrivKey
= xprvkeyB58
;
1007 DOM
.extendedPrivKey
.val(extendedPrivKey
);
1008 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
1009 DOM
.extendedPubKey
.val(extendedPubKey
);
1010 // Display the addresses and privkeys
1011 clearAddressesList();
1012 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
1013 displayAddresses(0, initialAddressCount
);
1016 displayBip32InfoForELA();
1020 function displayAddresses(start
, total
) {
1021 generationProcesses
.push(new (function() {
1025 this.stop = function() {
1026 for (var i
=0; i
<rows
.length
; i
++) {
1027 rows
[i
].shouldGenerate
= false;
1032 for (var i
=0; i
<total
; i
++) {
1033 var index
= i
+ start
;
1034 var isLast
= i
== total
- 1;
1035 rows
.push(new TableRow(index
, isLast
));
1041 function segwitSelected() {
1042 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
1045 function p2wpkhSelected() {
1046 return bip84TabSelected() ||
1047 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
1050 function p2wpkhInP2shSelected() {
1051 return bip49TabSelected() ||
1052 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
1055 function p2wshSelected() {
1056 return bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh";
1059 function p2wshInP2shSelected() {
1060 return (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh-p2sh");
1063 function TableRow(index
, isLast
) {
1066 this.shouldGenerate
= true;
1067 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
1068 var useBip38
= DOM
.useBip38
.prop("checked");
1069 var bip38password
= DOM
.bip38Password
.val();
1070 var isSegwit
= segwitSelected();
1071 var segwitAvailable
= networkHasSegwit();
1072 var isP2wpkh
= p2wpkhSelected();
1073 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
1074 var isP2wsh
= p2wshSelected();
1075 var isP2wshInP2sh
= p2wshInP2shSelected();
1081 function calculateValues() {
1082 setTimeout(function() {
1083 if (!self
.shouldGenerate
) {
1086 // derive HDkey for this row of the table
1088 if (useHardenedAddresses
) {
1089 key
= bip32ExtendedKey
.deriveHardened(index
);
1092 key
= bip32ExtendedKey
.derive(index
);
1094 // bip38 requires uncompressed keys
1095 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1096 var keyPair
= key
.keyPair
;
1097 var useUncompressed
= useBip38
;
1098 if (useUncompressed
) {
1099 keyPair
= new libs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1101 keyPair
= new libs
.groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1105 var address
= keyPair
.getAddress().toString();
1107 var hasPrivkey
= !key
.isNeutered();
1110 privkey
= keyPair
.toWIF();
1111 // BIP38 encode private key if required
1114 privkey
= libs
.groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1115 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1116 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1118 privkey
= libs
.bip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1119 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1124 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1125 var indexText
= getDerivationPath() + "/" + index
;
1126 if (useHardenedAddresses
) {
1127 indexText
= indexText
+ "'";
1129 // Ethereum values are different
1130 if (networkIsEthereum()) {
1131 var pubkeyBuffer
= keyPair
.getPublicKeyBuffer();
1132 var ethPubkey
= libs
.ethUtil
.importPublic(pubkeyBuffer
);
1133 var addressBuffer
= libs
.ethUtil
.publicToAddress(ethPubkey
);
1134 var hexAddress
= addressBuffer
.toString('hex');
1135 var checksumAddress
= libs
.ethUtil
.toChecksumAddress(hexAddress
);
1136 address
= libs
.ethUtil
.addHexPrefix(checksumAddress
);
1137 pubkey
= libs
.ethUtil
.addHexPrefix(pubkey
);
1139 privkey
= libs
.ethUtil
.bufferToHex(keyPair
.d
.toBuffer());
1143 // RSK values are different
1144 if (networkIsRsk()) {
1145 var pubkeyBuffer
= keyPair
.getPublicKeyBuffer();
1146 var ethPubkey
= libs
.ethUtil
.importPublic(pubkeyBuffer
);
1147 var addressBuffer
= libs
.ethUtil
.publicToAddress(ethPubkey
);
1148 var hexAddress
= addressBuffer
.toString('hex');
1149 // Use chainId based on selected network
1150 // Ref: https://developers.rsk.co/rsk/architecture/account-based/#chainid
1152 var rskNetworkName
= networks
[DOM
.network
.val()].name
;
1153 switch (rskNetworkName
) {
1157 case "tR-BTC - RSK Testnet":
1163 var checksumAddress
= toChecksumAddressForRsk(hexAddress
, chainId
);
1164 address
= libs
.ethUtil
.addHexPrefix(checksumAddress
);
1165 pubkey
= libs
.ethUtil
.addHexPrefix(pubkey
);
1167 privkey
= libs
.ethUtil
.bufferToHex(keyPair
.d
.toBuffer());
1171 // Handshake values are different
1172 if (networks
[DOM
.network
.val()].name
== "HNS - Handshake") {
1173 var ring
= libs
.handshake
.KeyRing
.fromPublic(keyPair
.getPublicKeyBuffer())
1174 address
= ring
.getAddress().toString();
1177 // Stellar is different
1178 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1179 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1180 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1182 path
+= purpose
+ "'/";
1183 path
+= coin
+ "'/" + index
+ "'";
1184 var keypair
= libs
.stellarUtil
.getKeypair(path
, seed
);
1186 privkey
= keypair
.secret();
1187 pubkey
= address
= keypair
.publicKey();
1191 if (networks
[DOM
.network
.val()].name
== "NANO - Nano") {
1192 var nanoKeypair
= libs
.nanoUtil
.getKeypair(index
, seed
);
1193 privkey
= nanoKeypair
.privKey
;
1194 pubkey
= nanoKeypair
.pubKey
;
1195 address
= nanoKeypair
.address
;
1198 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1199 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1200 var nebulasAccount
= libs
.nebulas
.Account
.NewAccount();
1201 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1202 address
= nebulasAccount
.getAddressString();
1203 privkey
= nebulasAccount
.getPrivateKeyString();
1204 pubkey
= nebulasAccount
.getPublicKeyString();
1206 // Ripple values are different
1207 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1208 privkey
= convertRipplePriv(privkey
);
1209 address
= convertRippleAdrr(address
);
1211 // Jingtum values are different
1212 if (networks
[DOM
.network
.val()].name
== "SWTC - Jingtum") {
1213 privkey
= convertJingtumPriv(privkey
);
1214 address
= convertJingtumAdrr(address
);
1216 // CasinoCoin values are different
1217 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1218 privkey
= convertCasinoCoinPriv(privkey
);
1219 address
= convertCasinoCoinAdrr(address
);
1221 // Bitcoin Cash address format may vary
1222 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1223 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1224 if (bchAddrType
== "cashaddr") {
1225 address
= libs
.bchaddr
.toCashAddress(address
);
1227 else if (bchAddrType
== "bitpay") {
1228 address
= libs
.bchaddr
.toBitpayAddress(address
);
1231 // Bitcoin Cash address format may vary
1232 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1233 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1234 if (bchAddrType
== "cashaddr") {
1235 address
= libs
.bchaddrSlp
.toSlpAddress(address
);
1238 // Segwit addresses are different
1240 if (!segwitAvailable
) {
1244 var keyhash
= libs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1245 var scriptpubkey
= libs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1246 address
= libs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1248 else if (isP2wpkhInP2sh
) {
1249 var keyhash
= libs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1250 var scriptsig
= libs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1251 var addressbytes
= libs
.bitcoin
.crypto
.hash160(scriptsig
);
1252 var scriptpubkey
= libs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1253 address
= libs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1256 // https://github.com/libs.bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71
1258 var witnessScript
= libs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1259 var scriptPubKey
= libs
.bitcoin
.script
.witnessScriptHash
.output
.encode(libs
.bitcoin
.crypto
.sha256(witnessScript
));
1260 address
= libs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
);
1262 else if (isP2wshInP2sh
) {
1263 // https://github.com/libs.bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183
1265 var witnessScript
= libs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1266 var redeemScript
= libs
.bitcoin
.script
.witnessScriptHash
.output
.encode(libs
.bitcoin
.crypto
.sha256(witnessScript
));
1267 var scriptPubKey
= libs
.bitcoin
.script
.scriptHash
.output
.encode(libs
.bitcoin
.crypto
.hash160(redeemScript
));
1268 address
= libs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
)
1272 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1273 address
= libs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1276 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1278 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1279 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1282 if (networks
[DOM
.network
.val()].name
== "FIO - Foundation for Interwallet Operability") {
1284 pubkey
= FIObufferToPublic(keyPair
.getPublicKeyBuffer());
1285 privkey
= FIObufferToPrivate(keyPair
.d
.toBuffer(32));
1288 //Groestlcoin Addresses are different
1292 if (!segwitAvailable
) {
1296 address
= libs
.groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1298 else if (isP2wpkhInP2sh
) {
1299 address
= libs
.groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1302 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1306 let elaAddress
= calcAddressForELA(
1308 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1309 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1310 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1313 address
= elaAddress
.address
;
1314 privkey
= elaAddress
.privateKey
;
1315 pubkey
= elaAddress
.publicKey
;
1318 addAddressToList(indexText
, address
, pubkey
, privkey
);
1330 function showMore() {
1331 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1332 if (isNaN(rowsToAdd
)) {
1334 DOM
.rowsToAdd
.val("20");
1336 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1338 start
= lastIndexInTable() + 1;
1341 var newStart
= start
+ rowsToAdd
;
1342 DOM
.moreRowsStartIndex
.val(newStart
);
1344 if (rowsToAdd
> 200) {
1345 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1346 msg
+= "Do you want to continue?";
1347 if (!confirm(msg
)) {
1351 displayAddresses(start
, rowsToAdd
);
1354 function clearDisplay() {
1355 clearAddressesList();
1357 hideValidationError();
1360 function clearAddressesList() {
1361 DOM
.addresses
.empty();
1366 function stopGenerating() {
1367 while (generationProcesses
.length
> 0) {
1368 var generation
= generationProcesses
.shift();
1373 function clearKeys() {
1378 function clearRootKey() {
1379 DOM
.rootKey
.val("");
1382 function clearDerivedKeys() {
1383 DOM
.extendedPrivKey
.val("");
1384 DOM
.extendedPubKey
.val("");
1385 DOM
.bip44accountXprv
.val("");
1386 DOM
.bip44accountXpub
.val("");
1389 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1390 var row
= $(addressRowTemplate
.html());
1392 var indexCell
= row
.find(".index span");
1393 var addressCell
= row
.find(".address span");
1394 var pubkeyCell
= row
.find(".pubkey span");
1395 var privkeyCell
= row
.find(".privkey span");
1397 indexCell
.text(indexText
);
1398 addressCell
.text(address
);
1399 pubkeyCell
.text(pubkey
);
1400 privkeyCell
.text(privkey
);
1403 indexCell
.addClass("invisible");
1406 addressCell
.addClass("invisible");
1409 pubkeyCell
.addClass("invisible");
1412 privkeyCell
.addClass("invisible");
1414 DOM
.addresses
.append(row
);
1415 var rowShowQrEls
= row
.find("[data-show-qr]");
1416 setQrEvents(rowShowQrEls
);
1419 function hasStrongRandom() {
1420 return 'crypto' in window
&& window
['crypto'] !== null;
1423 function disableForms() {
1424 $("form").on("submit", function(e
) {
1429 function parseIntNoNaN(val
, defaultVal
) {
1430 var v
= parseInt(val
);
1437 function showPending() {
1439 .text("Calculating...")
1443 function findNearestWord(word
) {
1444 var language
= getLanguage();
1445 var words
= WORDLISTS
[language
];
1446 var minDistance
= 99;
1447 var closestWord
= words
[0];
1448 for (var i
=0; i
<words
.length
; i
++) {
1449 var comparedTo
= words
[i
];
1450 if (comparedTo
.indexOf(word
) == 0) {
1453 var distance
= libs
.levenshtein
.get(word
, comparedTo
);
1454 if (distance
< minDistance
) {
1455 closestWord
= comparedTo
;
1456 minDistance
= distance
;
1462 function hidePending() {
1468 function populateNetworkSelect() {
1469 for (var i
=0; i
<networks
.length
; i
++) {
1470 var network
= networks
[i
];
1471 var option
= $("<option>");
1472 option
.attr("value", i
);
1473 option
.text(network
.name
);
1474 if (network
.name
== "BTC - Bitcoin") {
1475 option
.prop("selected", true);
1477 DOM
.phraseNetwork
.append(option
);
1481 function populateClientSelect() {
1482 for (var i
=0; i
<clients
.length
; i
++) {
1483 var client
= clients
[i
];
1484 var option
= $("<option>");
1485 option
.attr("value", i
);
1486 option
.text(client
.name
);
1487 DOM
.bip32Client
.append(option
);
1491 function getLanguage() {
1492 var defaultLanguage
= "english";
1493 // Try to get from existing phrase
1494 var language
= getLanguageFromPhrase();
1495 // Try to get from url if not from phrase
1496 if (language
.length
== 0) {
1497 language
= getLanguageFromUrl();
1499 // Default to English if no other option
1500 if (language
.length
== 0) {
1501 language
= defaultLanguage
;
1506 function getLanguageFromPhrase(phrase
) {
1507 // Check if how many words from existing phrase match a language.
1510 phrase
= DOM
.phrase
.val();
1512 if (phrase
.length
> 0) {
1513 var words
= phraseToWordArray(phrase
);
1514 var languageMatches
= {};
1515 for (l
in WORDLISTS
) {
1516 // Track how many words match in this language
1517 languageMatches
[l
] = 0;
1518 for (var i
=0; i
<words
.length
; i
++) {
1519 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1520 if (wordInLanguage
) {
1521 languageMatches
[l
]++;
1524 // Find languages with most word matches.
1525 // This is made difficult due to commonalities between Chinese
1526 // simplified vs traditional.
1527 var mostMatches
= 0;
1528 var mostMatchedLanguages
= [];
1529 for (var l
in languageMatches
) {
1530 var numMatches
= languageMatches
[l
];
1531 if (numMatches
> mostMatches
) {
1532 mostMatches
= numMatches
;
1533 mostMatchedLanguages
= [l
];
1535 else if (numMatches
== mostMatches
) {
1536 mostMatchedLanguages
.push(l
);
1540 if (mostMatchedLanguages
.length
> 0) {
1541 // Use first language and warn if multiple detected
1542 language
= mostMatchedLanguages
[0];
1543 if (mostMatchedLanguages
.length
> 1) {
1544 console
.warn("Multiple possible languages");
1545 console
.warn(mostMatchedLanguages
);
1552 function getLanguageFromUrl() {
1553 for (var language
in WORDLISTS
) {
1554 if (window
.location
.hash
.indexOf(language
) > -1) {
1561 function setMnemonicLanguage() {
1562 var language
= getLanguage();
1563 // Load the bip39 mnemonic generator for this language if required
1564 if (!(language
in mnemonics
)) {
1565 mnemonics
[language
] = new Mnemonic(language
);
1567 mnemonic
= mnemonics
[language
];
1570 function convertPhraseToNewLanguage() {
1571 var oldLanguage
= getLanguageFromPhrase();
1572 var newLanguage
= getLanguageFromUrl();
1573 var oldPhrase
= DOM
.phrase
.val();
1574 var oldWords
= phraseToWordArray(oldPhrase
);
1576 for (var i
=0; i
<oldWords
.length
; i
++) {
1577 var oldWord
= oldWords
[i
];
1578 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1579 var newWord
= WORDLISTS
[newLanguage
][index
];
1580 newWords
.push(newWord
);
1582 newPhrase
= wordArrayToPhrase(newWords
);
1586 // TODO look at jsbip39 - mnemonic.splitWords
1587 function phraseToWordArray(phrase
) {
1588 var words
= phrase
.split(/\s/g);
1590 for (var i
=0; i
<words
.length
; i
++) {
1591 var word
= words
[i
];
1592 if (word
.length
> 0) {
1593 noBlanks
.push(word
);
1599 // TODO look at jsbip39 - mnemonic.joinWords
1600 function wordArrayToPhrase(words
) {
1601 var phrase
= words
.join(" ");
1602 var language
= getLanguageFromPhrase(phrase
);
1603 if (language
== "japanese") {
1604 phrase
= words
.join("\u3000");
1609 function writeSplitPhrase(phrase
) {
1610 var wordCount
= phrase
.split(/\s/g).length
;
1612 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1613 var group
=[[],[],[]],
1615 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1616 while (left
.length
>0) {
1617 groupI
=(groupI
+1)%3;
1618 seed
= seed
* 16807 % 2147483647;
1619 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1620 group
[groupI
].push(left
[selected
]);
1621 left
.splice(selected
,1);
1623 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1624 for (var i
=0;i
<3;i
++) {
1625 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1626 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1628 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1629 var triesPerSecond
=10000000000;
1630 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1631 var displayRedText
= false;
1633 hackTime
="<1 second";
1634 displayRedText
= true;
1635 } else if (hackTime
<86400) {
1636 hackTime
=Math
.floor(hackTime
)+" seconds";
1637 displayRedText
= true;
1638 } else if(hackTime
<31557600) {
1639 hackTime
=Math
.floor(hackTime
/86400)+" days";
1640 displayRedText
= true;
1642 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1644 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1645 if (displayRedText
) {
1646 DOM
.phraseSplitWarn
.addClass("text-danger");
1648 DOM
.phraseSplitWarn
.removeClass("text-danger");
1652 function isUsingOwnEntropy() {
1653 return DOM
.useEntropy
.prop("checked");
1656 function setMnemonicFromEntropy() {
1657 clearEntropyFeedback();
1658 // Get entropy value
1659 var entropyStr
= DOM
.entropy
.val();
1660 // Work out minimum base for entropy
1662 if (entropyTypeAutoDetect
) {
1663 entropy
= Entropy
.fromString(entropyStr
);
1666 let base
= DOM
.entropyTypeInputs
.filter(":checked").val();
1667 entropy
= Entropy
.fromString(entropyStr
, base
);
1669 if (entropy
.binaryStr
.length
== 0) {
1672 // Show entropy details
1673 showEntropyFeedback(entropy
);
1674 // Use entropy hash if not using raw entropy
1675 var bits
= entropy
.binaryStr
;
1676 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1677 if (mnemonicLength
!= "raw") {
1678 // Get bits by hashing entropy with SHA256
1679 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1680 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1681 bits
= libs
.BigInteger
.BigInteger
.parse(hex
, 16).toString(2);
1682 while (bits
.length
% 256 != 0) {
1685 // Truncate hash to suit number of words
1686 mnemonicLength
= parseInt(mnemonicLength
);
1687 var numberOfBits
= 32 * mnemonicLength
/ 3;
1688 bits
= bits
.substring(0, numberOfBits
);
1689 // show warning for weak entropy override
1690 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1691 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1694 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1698 // hide warning for weak entropy override
1699 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1701 // Discard trailing entropy
1702 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1703 var start
= bits
.length
- bitsToUse
;
1704 var binaryStr
= bits
.substring(start
);
1705 // Convert entropy string to numeric array
1706 var entropyArr
= [];
1707 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1708 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1709 var entropyByte
= parseInt(byteAsBits
, 2);
1710 entropyArr
.push(entropyByte
)
1712 // Convert entropy array to mnemonic
1713 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1714 // Set the mnemonic in the UI
1715 DOM
.phrase
.val(phrase
);
1716 writeSplitPhrase(phrase
);
1717 // Show the word indexes
1719 // Show the checksum
1723 function clearEntropyFeedback() {
1724 DOM
.entropyCrackTime
.text("...");
1725 DOM
.entropyType
.text("");
1726 DOM
.entropyWordCount
.text("0");
1727 DOM
.entropyEventCount
.text("0");
1728 DOM
.entropyBitsPerEvent
.text("0");
1729 DOM
.entropyBits
.text("0");
1730 DOM
.entropyFiltered
.html(" ");
1731 DOM
.entropyBinary
.html(" ");
1734 function showEntropyFeedback(entropy
) {
1735 var numberOfBits
= entropy
.binaryStr
.length
;
1736 var timeToCrack
= "unknown";
1738 var z
= libs
.zxcvbn(entropy
.base
.parts
.join(""));
1739 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1740 if (z
.feedback
.warning
!= "") {
1741 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1745 console
.log("Error detecting entropy strength with zxcvbn:");
1748 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1749 DOM
.entropyTypeInputs
.attr("checked", false);
1750 DOM
.entropyTypeInputs
.filter("[value='" + entropyTypeStr
+ "']").attr("checked", true);
1751 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1752 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1753 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1754 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1755 DOM
.entropyType
.text(entropyTypeStr
);
1756 DOM
.entropyCrackTime
.text(timeToCrack
);
1757 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1758 DOM
.entropyBits
.text(numberOfBits
);
1759 DOM
.entropyWordCount
.text(wordCount
);
1760 DOM
.entropyBinary
.text(spacedBinaryStr
);
1761 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1762 // detect and warn of filtering
1763 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1764 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1765 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1767 DOM
.entropyFilterWarning
.removeClass('hidden');
1770 DOM
.entropyFilterWarning
.addClass('hidden');
1774 function getEntropyTypeStr(entropy
) {
1775 var typeStr
= entropy
.base
.str
;
1776 // Add some detail if these are cards
1777 if (entropy
.base
.asInt
== 52) {
1778 var cardDetail
= []; // array of message strings
1779 // Detect duplicates
1781 var dupeTracker
= {};
1782 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1783 var card
= entropy
.base
.parts
[i
];
1784 var cardUpper
= card
.toUpperCase();
1785 if (cardUpper
in dupeTracker
) {
1788 dupeTracker
[cardUpper
] = true;
1790 if (dupes
.length
> 0) {
1791 var dupeWord
= "duplicates";
1792 if (dupes
.length
== 1) {
1793 dupeWord
= "duplicate";
1795 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1796 if (dupes
.length
> 3) {
1799 cardDetail
.push(msg
);
1802 var uniqueCards
= [];
1803 for (var uniqueCard
in dupeTracker
) {
1804 uniqueCards
.push(uniqueCard
);
1806 if (uniqueCards
.length
== 52) {
1807 cardDetail
.unshift("full deck");
1809 // Detect missing cards
1810 var values
= "A23456789TJQK";
1812 var missingCards
= [];
1813 for (var i
=0; i
<suits
.length
; i
++) {
1814 for (var j
=0; j
<values
.length
; j
++) {
1815 var card
= values
[j
] + suits
[i
];
1816 if (!(card
in dupeTracker
)) {
1817 missingCards
.push(card
);
1821 // Display missing cards if six or less, ie clearly going for full deck
1822 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1823 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1824 if (missingCards
.length
> 3) {
1827 cardDetail
.push(msg
);
1829 // Add card details to typeStr
1830 if (cardDetail
.length
> 0) {
1831 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1837 function setQrEvents(els
) {
1838 els
.on("mouseenter", createQr
);
1839 els
.on("mouseleave", destroyQr
);
1840 els
.on("click", toggleQr
);
1843 function createQr(e
) {
1844 var content
= e
.target
.textContent
|| e
.target
.value
;
1846 var qrEl
= libs
.kjua({
1852 DOM
.qrImage
.append(qrEl
);
1854 DOM
.qrHider
.addClass("hidden");
1857 DOM
.qrHider
.removeClass("hidden");
1859 DOM
.qrContainer
.removeClass("hidden");
1863 function destroyQr() {
1864 DOM
.qrImage
.text("");
1865 DOM
.qrContainer
.addClass("hidden");
1868 function toggleQr() {
1870 DOM
.qrHider
.toggleClass("hidden");
1871 DOM
.qrHint
.toggleClass("hidden");
1874 function bip44TabSelected() {
1875 return DOM
.bip44tab
.hasClass("active");
1878 function bip32TabSelected() {
1879 return DOM
.bip32tab
.hasClass("active");
1882 function networkIsEthereum() {
1883 var name
= networks
[DOM
.network
.val()].name
;
1884 return (name
== "ETH - Ethereum")
1885 || (name
== "ETC - Ethereum Classic")
1886 || (name
== "EWT - EnergyWeb")
1887 || (name
== "PIRL - Pirl")
1888 || (name
== "MIX - MIX")
1889 || (name
== "MOAC - MOAC")
1890 || (name
== "MUSIC - Musicoin")
1891 || (name
== "POA - Poa")
1892 || (name
== "EXP - Expanse")
1893 || (name
== "CLO - Callisto")
1894 || (name
== "DXN - DEXON")
1895 || (name
== "ELLA - Ellaism")
1896 || (name
== "ESN - Ethersocial Network")
1897 || (name
== "VET - VeChain")
1898 || (name
== "ERE - EtherCore")
1901 function networkIsRsk() {
1902 var name
= networks
[DOM
.network
.val()].name
;
1903 return (name
== "R-BTC - RSK")
1904 || (name
== "tR-BTC - RSK Testnet");
1907 function networkHasSegwit() {
1909 if ("baseNetwork" in network
) {
1910 n
= libs
.bitcoin
.networks
[network
.baseNetwork
];
1912 // check if only p2wpkh params are required
1913 if (p2wpkhSelected()) {
1914 return "p2wpkh" in n
;
1916 // check if only p2wpkh-in-p2sh params are required
1917 else if (p2wpkhInP2shSelected()) {
1918 return "p2wpkhInP2sh" in n
;
1920 // require both if it's unclear which params are required
1921 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1924 function bip49TabSelected() {
1925 return DOM
.bip49tab
.hasClass("active");
1928 function bip84TabSelected() {
1929 return DOM
.bip84tab
.hasClass("active");
1932 function bip141TabSelected() {
1933 return DOM
.bip141tab
.hasClass("active");
1936 function setHdCoin(coinValue
) {
1937 DOM
.bip44coin
.val(coinValue
);
1938 DOM
.bip49coin
.val(coinValue
);
1939 DOM
.bip84coin
.val(coinValue
);
1942 function showSegwitAvailable() {
1943 DOM
.bip49unavailable
.addClass("hidden");
1944 DOM
.bip49available
.removeClass("hidden");
1945 DOM
.bip84unavailable
.addClass("hidden");
1946 DOM
.bip84available
.removeClass("hidden");
1947 DOM
.bip141unavailable
.addClass("hidden");
1948 DOM
.bip141available
.removeClass("hidden");
1951 function showSegwitUnavailable() {
1952 DOM
.bip49available
.addClass("hidden");
1953 DOM
.bip49unavailable
.removeClass("hidden");
1954 DOM
.bip84available
.addClass("hidden");
1955 DOM
.bip84unavailable
.removeClass("hidden");
1956 DOM
.bip141available
.addClass("hidden");
1957 DOM
.bip141unavailable
.removeClass("hidden");
1960 function adjustNetworkForSegwit() {
1961 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1962 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1964 // See https://github.com/iancoleman/bip39/issues/125
1965 var segwitNetworks
= null;
1966 // if a segwit network is alread selected, need to use base network to
1967 // look up new parameters
1968 if ("baseNetwork" in network
) {
1969 network
= libs
.bitcoin
.networks
[network
.baseNetwork
];
1971 // choose the right segwit params
1972 if (p2wpkhSelected() && "p2wpkh" in network
) {
1973 network
= network
.p2wpkh
;
1975 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1976 network
= network
.p2wpkhInP2sh
;
1978 else if (p2wshSelected() && "p2wsh" in network
) {
1979 network
= network
.p2wsh
;
1981 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network
) {
1982 network
= network
.p2wshInP2sh
;
1986 function lastIndexInTable() {
1987 var pathText
= DOM
.addresses
.find(".index").last().text();
1988 var pathBits
= pathText
.split("/");
1989 var lastBit
= pathBits
[pathBits
.length
-1];
1990 var lastBitClean
= lastBit
.replace("'", "");
1991 return parseInt(lastBitClean
);
1994 function uint8ArrayToHex(a
) {
1996 for (var i
=0; i
<a
.length
; i
++) {
1997 var h
= a
[i
].toString(16);
1998 while (h
.length
< 2) {
2006 function showWordIndexes() {
2007 var phrase
= DOM
.phrase
.val();
2008 var words
= phraseToWordArray(phrase
);
2009 var wordIndexes
= [];
2010 var language
= getLanguage();
2011 for (var i
=0; i
<words
.length
; i
++) {
2012 var word
= words
[i
];
2013 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
2014 wordIndexes
.push(wordIndex
);
2016 var wordIndexesStr
= wordIndexes
.join(", ");
2017 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
2020 function showChecksum() {
2021 var phrase
= DOM
.phrase
.val();
2022 var words
= phraseToWordArray(phrase
);
2023 var checksumBitlength
= words
.length
/ 3;
2026 var language
= getLanguage();
2027 for (var i
=words
.length
-1; i
>=0; i
--) {
2028 var word
= words
[i
];
2029 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
2030 var wordBinary
= wordIndex
.toString(2);
2031 while (wordBinary
.length
< 11) {
2032 wordBinary
= "0" + wordBinary
;
2034 var binaryStr
= wordBinary
+ binaryStr
;
2035 if (binaryStr
.length
>= checksumBitlength
) {
2036 var start
= binaryStr
.length
- checksumBitlength
;
2037 var end
= binaryStr
.length
;
2038 checksum
= binaryStr
.substring(start
, end
);
2039 // add spaces so the last group is 11 bits, not the first
2040 checksum
= checksum
.split("").reverse().join("")
2041 checksum
= addSpacesEveryElevenBits(checksum
);
2042 checksum
= checksum
.split("").reverse().join("")
2046 DOM
.entropyChecksum
.text(checksum
);
2049 function updateCsv() {
2050 var tableCsv
= "path,address,public key,private key\n";
2051 var rows
= DOM
.addresses
.find("tr");
2052 for (var i
=0; i
<rows
.length
; i
++) {
2053 var row
= $(rows
[i
]);
2054 var cells
= row
.find("td");
2055 for (var j
=0; j
<cells
.length
; j
++) {
2056 var cell
= $(cells
[j
]);
2057 if (!cell
.children().hasClass("invisible")) {
2058 tableCsv
= tableCsv
+ cell
.text();
2060 if (j
!= cells
.length
- 1) {
2061 tableCsv
= tableCsv
+ ",";
2064 tableCsv
= tableCsv
+ "\n";
2066 DOM
.csv
.val(tableCsv
);
2069 function addSpacesEveryElevenBits(binaryStr
) {
2070 return binaryStr
.match(/.{1,11}/g).join(" ");
2075 name: "AC - Asiacoin",
2076 onSelect: function() {
2077 network
= libs
.bitcoin
.networks
.asiacoin
;
2082 name: "ACC - Adcoin",
2083 onSelect: function() {
2084 network
= libs
.bitcoin
.networks
.adcoin
;
2089 name: "AGM - Argoneum",
2090 onSelect: function() {
2091 network
= libs
.bitcoin
.networks
.argoneum
;
2096 name: "ARYA - Aryacoin",
2097 onSelect: function() {
2098 network
= libs
.bitcoin
.networks
.aryacoin
;
2103 name: "AUR - Auroracoin",
2104 onSelect: function() {
2105 network
= libs
.bitcoin
.networks
.auroracoin
;
2111 onSelect: function() {
2112 network
= libs
.bitcoin
.networks
.axe
;
2117 name: "ANON - ANON",
2118 onSelect: function() {
2119 network
= libs
.bitcoin
.networks
.anon
;
2124 name: "BOLI - Bolivarcoin",
2125 onSelect: function() {
2126 network
= libs
.bitcoin
.networks
.bolivarcoin
;
2131 name: "BCA - Bitcoin Atom",
2132 onSelect: function() {
2133 network
= libs
.bitcoin
.networks
.atom
;
2138 name: "BCH - Bitcoin Cash",
2139 onSelect: function() {
2140 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2145 name: "BEET - Beetlecoin",
2146 onSelect: function() {
2147 network
= libs
.bitcoin
.networks
.beetlecoin
;
2152 name: "BELA - Belacoin",
2153 onSelect: function() {
2154 network
= libs
.bitcoin
.networks
.belacoin
;
2159 name: "BLK - BlackCoin",
2160 onSelect: function() {
2161 network
= libs
.bitcoin
.networks
.blackcoin
;
2166 name: "BND - Blocknode",
2167 onSelect: function() {
2168 network
= libs
.bitcoin
.networks
.blocknode
;
2173 name: "tBND - Blocknode Testnet",
2174 onSelect: function() {
2175 network
= libs
.bitcoin
.networks
.blocknode_testnet
;
2180 name: "BRIT - Britcoin",
2181 onSelect: function() {
2182 network
= libs
.bitcoin
.networks
.britcoin
;
2187 name: "BSD - Bitsend",
2188 onSelect: function() {
2189 network
= libs
.bitcoin
.networks
.bitsend
;
2194 name: "BST - BlockStamp",
2195 onSelect: function() {
2196 network
= libs
.bitcoin
.networks
.blockstamp
;
2202 onSelect: function() {
2203 network
= libs
.bitcoin
.networks
.bata
;
2208 name: "BTC - Bitcoin",
2209 onSelect: function() {
2210 network
= libs
.bitcoin
.networks
.bitcoin
;
2215 name: "BTC - Bitcoin RegTest",
2216 onSelect: function() {
2217 network
= libs
.bitcoin
.networks
.regtest
;
2218 // Using hd coin value 1 based on bip44_coin_type
2219 // https://github.com/chaintope/bitcoinrb/blob/f1014406f6b8f9b4edcecedc18df70c80df06f11/lib/bitcoin/chainparams/regtest.yml
2224 name: "BTC - Bitcoin Testnet",
2225 onSelect: function() {
2226 network
= libs
.bitcoin
.networks
.testnet
;
2231 name: "BITG - Bitcoin Green",
2232 onSelect: function() {
2233 network
= libs
.bitcoin
.networks
.bitcoingreen
;
2238 name: "BTCP - Bitcoin Private",
2239 onSelect: function() {
2240 network
= libs
.bitcoin
.networks
.bitcoinprivate
;
2245 name: "BSV - BitcoinSV",
2246 onSelect: function() {
2247 network
= libs
.bitcoin
.networks
.bitcoinsv
;
2252 name: "BTCZ - Bitcoinz",
2253 onSelect: function() {
2254 network
= libs
.bitcoin
.networks
.bitcoinz
;
2259 name: "BTDX - BitCloud",
2260 onSelect: function() {
2261 network
= libs
.bitcoin
.networks
.bitcloud
;
2266 name: "BTG - Bitcoin Gold",
2267 onSelect: function() {
2268 network
= libs
.bitcoin
.networks
.bgold
;
2273 name: "BTX - Bitcore",
2274 onSelect: function() {
2275 network
= libs
.bitcoin
.networks
.bitcore
;
2280 name: "CCN - Cannacoin",
2281 onSelect: function() {
2282 network
= libs
.bitcoin
.networks
.cannacoin
;
2287 name: "CESC - Cryptoescudo",
2288 onSelect: function() {
2289 network
= libs
.bitcoin
.networks
.cannacoin
;
2294 name: "CDN - Canadaecoin",
2295 onSelect: function() {
2296 network
= libs
.bitcoin
.networks
.canadaecoin
;
2301 name: "CLAM - Clams",
2302 onSelect: function() {
2303 network
= libs
.bitcoin
.networks
.clam
;
2308 name: "CLO - Callisto",
2309 segwitAvailable: false,
2310 onSelect: function() {
2311 network
= libs
.bitcoin
.networks
.bitcoin
;
2316 name: "CLUB - Clubcoin",
2317 onSelect: function() {
2318 network
= libs
.bitcoin
.networks
.clubcoin
;
2323 name: "CMP - Compcoin",
2324 onSelect: function() {
2325 network
= libs
.bitcoin
.networks
.compcoin
;
2330 name: "CPU - CPUchain",
2331 onSelect: function() {
2332 network
= libs
.bitcoin
.networks
.cpuchain
;
2337 name: "CRAVE - Crave",
2338 onSelect: function() {
2339 network
= libs
.bitcoin
.networks
.crave
;
2344 name: "CRP - CranePay",
2345 onSelect: function() {
2346 network
= libs
.bitcoin
.networks
.cranepay
;
2352 name: "CRW - Crown (Legacy)",
2353 onSelect: function() {
2354 network
= libs
.bitcoin
.networks
.crown
;
2359 name: "CRW - Crown",
2360 onSelect: function() {
2361 network
= libs
.bitcoin
.networks
.crown
;
2366 name: "CSC - CasinoCoin",
2367 onSelect: function() {
2368 network
= libs
.bitcoin
.networks
.bitcoin
;
2373 name: "DASH - Dash",
2374 onSelect: function() {
2375 network
= libs
.bitcoin
.networks
.dash
;
2380 name: "DASH - Dash Testnet",
2381 onSelect: function() {
2382 network
= libs
.bitcoin
.networks
.dashtn
;
2387 name: "DFC - Defcoin",
2388 onSelect: function() {
2389 network
= libs
.bitcoin
.networks
.defcoin
;
2394 name: "DGB - Digibyte",
2395 onSelect: function() {
2396 network
= libs
.bitcoin
.networks
.digibyte
;
2401 name: "DGC - Digitalcoin",
2402 onSelect: function() {
2403 network
= libs
.bitcoin
.networks
.digitalcoin
;
2408 name: "DMD - Diamond",
2409 onSelect: function() {
2410 network
= libs
.bitcoin
.networks
.diamond
;
2415 name: "DNR - Denarius",
2416 onSelect: function() {
2417 network
= libs
.bitcoin
.networks
.denarius
;
2422 name: "DOGE - Dogecoin",
2423 onSelect: function() {
2424 network
= libs
.bitcoin
.networks
.dogecoin
;
2429 name: "DOGEt - Dogecoin Testnet",
2430 onSelect: function() {
2431 network
= libs
.bitcoin
.networks
.dogecointestnet
;
2436 name: "DXN - DEXON",
2437 onSelect: function() {
2438 network
= libs
.bitcoin
.networks
.bitcoin
;
2443 name: "ECN - Ecoin",
2444 onSelect: function() {
2445 network
= libs
.bitcoin
.networks
.ecoin
;
2450 name: "EDRC - Edrcoin",
2451 onSelect: function() {
2452 network
= libs
.bitcoin
.networks
.edrcoin
;
2457 name: "EFL - Egulden",
2458 onSelect: function() {
2459 network
= libs
.bitcoin
.networks
.egulden
;
2464 name: "ELA - Elastos",
2465 onSelect: function () {
2466 network
= libs
.bitcoin
.networks
.elastos
;
2471 name: "ELLA - Ellaism",
2472 segwitAvailable: false,
2473 onSelect: function() {
2474 network
= libs
.bitcoin
.networks
.bitcoin
;
2479 name: "EMC2 - Einsteinium",
2480 onSelect: function() {
2481 network
= libs
.bitcoin
.networks
.einsteinium
;
2486 name: "ERC - Europecoin",
2487 onSelect: function() {
2488 network
= libs
.bitcoin
.networks
.europecoin
;
2493 name: "EOS - EOSIO",
2494 onSelect: function() {
2495 network
= libs
.bitcoin
.networks
.bitcoin
;
2500 name: "ERE - EtherCore",
2501 segwitAvailable: false,
2502 onSelect: function() {
2503 network
= libs
.bitcoin
.networks
.bitcoin
;
2508 name: "ESN - Ethersocial Network",
2509 segwitAvailable: false,
2510 onSelect: function() {
2511 network
= libs
.bitcoin
.networks
.bitcoin
;
2516 name: "ETC - Ethereum Classic",
2517 segwitAvailable: false,
2518 onSelect: function() {
2519 network
= libs
.bitcoin
.networks
.bitcoin
;
2524 name: "ETH - Ethereum",
2525 onSelect: function() {
2526 network
= libs
.bitcoin
.networks
.bitcoin
;
2531 name: "EWT - EnergyWeb",
2532 onSelect: function() {
2533 network
= libs
.bitcoin
.networks
.bitcoin
;
2538 name: "EXCL - Exclusivecoin",
2539 onSelect: function() {
2540 network
= libs
.bitcoin
.networks
.exclusivecoin
;
2545 name: "EXCC - ExchangeCoin",
2546 onSelect: function() {
2547 network
= libs
.bitcoin
.networks
.exchangecoin
;
2552 name: "EXP - Expanse",
2553 segwitAvailable: false,
2554 onSelect: function() {
2555 network
= libs
.bitcoin
.networks
.bitcoin
;
2560 name: "FIO - Foundation for Interwallet Operability",
2561 onSelect: function() {
2562 network
= libs
.bitcoin
.networks
.bitcoin
;
2568 onSelect: function() {
2569 network
= libs
.bitcoin
.networks
.fix
;
2574 name: "FIX - FIX Testnet",
2575 onSelect: function() {
2576 network
= libs
.bitcoin
.networks
.fixtestnet
;
2581 name: "FJC - Fujicoin",
2582 onSelect: function() {
2583 network
= libs
.bitcoin
.networks
.fujicoin
;
2588 name: "FLASH - Flashcoin",
2589 onSelect: function() {
2590 network
= libs
.bitcoin
.networks
.flashcoin
;
2595 name: "FRST - Firstcoin",
2596 onSelect: function() {
2597 network
= libs
.bitcoin
.networks
.firstcoin
;
2602 name: "FTC - Feathercoin",
2603 onSelect: function() {
2604 network
= libs
.bitcoin
.networks
.feathercoin
;
2609 name: "GAME - GameCredits",
2610 onSelect: function() {
2611 network
= libs
.bitcoin
.networks
.game
;
2616 name: "GBX - Gobyte",
2617 onSelect: function() {
2618 network
= libs
.bitcoin
.networks
.gobyte
;
2623 name: "GCR - GCRCoin",
2624 onSelect: function() {
2625 network
= libs
.bitcoin
.networks
.gcr
;
2630 name: "GRC - Gridcoin",
2631 onSelect: function() {
2632 network
= libs
.bitcoin
.networks
.gridcoin
;
2637 name: "GRS - Groestlcoin",
2638 onSelect: function() {
2639 network
= libs
.bitcoin
.networks
.groestlcoin
;
2644 name: "GRS - Groestlcoin Testnet",
2645 onSelect: function() {
2646 network
= libs
.bitcoin
.networks
.groestlcointestnet
;
2651 name: "HNS - Handshake",
2652 onSelect: function() {
2657 name: "HNC - Helleniccoin",
2658 onSelect: function() {
2659 network
= libs
.bitcoin
.networks
.helleniccoin
;
2664 name: "HUSH - Hush (Legacy)",
2665 onSelect: function() {
2666 network
= libs
.bitcoin
.networks
.hush
;
2671 name: "HUSH - Hush3",
2672 onSelect: function() {
2673 network
= libs
.bitcoin
.networks
.hush3
;
2678 name: "INSN - Insane",
2679 onSelect: function() {
2680 network
= libs
.bitcoin
.networks
.insane
;
2686 onSelect: function() {
2687 network
= libs
.bitcoin
.networks
.iop
;
2692 name: "IXC - Ixcoin",
2693 onSelect: function() {
2694 network
= libs
.bitcoin
.networks
.ixcoin
;
2699 name: "JBS - Jumbucks",
2700 onSelect: function() {
2701 network
= libs
.bitcoin
.networks
.jumbucks
;
2706 name: "KMD - Komodo",
2707 bip49available: false,
2708 onSelect: function() {
2709 network
= libs
.bitcoin
.networks
.komodo
;
2714 name: "KOBO - Kobocoin",
2715 bip49available: false,
2716 onSelect: function() {
2717 network
= libs
.bitcoin
.networks
.kobocoin
;
2722 name: "LBC - Library Credits",
2723 onSelect: function() {
2724 network
= libs
.bitcoin
.networks
.lbry
;
2729 name: "LCC - Litecoincash",
2730 onSelect: function() {
2731 network
= libs
.bitcoin
.networks
.litecoincash
;
2736 name: "LDCN - Landcoin",
2737 onSelect: function() {
2738 network
= libs
.bitcoin
.networks
.landcoin
;
2743 name: "LINX - Linx",
2744 onSelect: function() {
2745 network
= libs
.bitcoin
.networks
.linx
;
2750 name: "LKR - Lkrcoin",
2751 segwitAvailable: false,
2752 onSelect: function() {
2753 network
= libs
.bitcoin
.networks
.lkrcoin
;
2758 name: "LTC - Litecoin",
2759 onSelect: function() {
2760 network
= libs
.bitcoin
.networks
.litecoin
;
2762 DOM
.litecoinLtubContainer
.removeClass("hidden");
2766 name: "LTCt - Litecoin Testnet",
2767 onSelect: function() {
2768 network
= libs
.bitcoin
.networks
.litecointestnet
;
2770 DOM
.litecoinLtubContainer
.removeClass("hidden");
2774 name: "LTZ - LitecoinZ",
2775 onSelect: function() {
2776 network
= libs
.bitcoin
.networks
.litecoinz
;
2781 name: "LYNX - Lynx",
2782 onSelect: function() {
2783 network
= libs
.bitcoin
.networks
.lynx
;
2788 name: "MAZA - Maza",
2789 onSelect: function() {
2790 network
= libs
.bitcoin
.networks
.maza
;
2795 name: "MEC - Megacoin",
2796 onSelect: function() {
2797 network
= libs
.bitcoin
.networks
.megacoin
;
2803 segwitAvailable: false,
2804 onSelect: function() {
2805 network
= libs
.bitcoin
.networks
.bitcoin
;
2810 name: "MNX - Minexcoin",
2811 onSelect: function() {
2812 network
= libs
.bitcoin
.networks
.minexcoin
;
2817 name: "MONA - Monacoin",
2818 onSelect: function() {
2819 network
= libs
.bitcoin
.networks
.monacoin
,
2824 name: "MONK - Monkey Project",
2825 onSelect: function() {
2826 network
= libs
.bitcoin
.networks
.monkeyproject
,
2831 name: "MOAC - MOAC",
2832 segwitAvailable: false,
2833 onSelect: function() {
2834 network
= libs
.bitcoin
.networks
.bitcoin
;
2839 name: "MUSIC - Musicoin",
2840 segwitAvailable: false,
2841 onSelect: function() {
2842 network
= libs
.bitcoin
.networks
.bitcoin
;
2847 name: "NANO - Nano",
2848 onSelect: function() {
2849 network
= network
= libs
.nanoUtil
.dummyNetwork
;
2854 name: "NAV - Navcoin",
2855 onSelect: function() {
2856 network
= libs
.bitcoin
.networks
.navcoin
;
2861 name: "NAS - Nebulas",
2862 onSelect: function() {
2863 network
= libs
.bitcoin
.networks
.bitcoin
;
2868 name: "NEBL - Neblio",
2869 onSelect: function() {
2870 network
= libs
.bitcoin
.networks
.neblio
;
2875 name: "NEOS - Neoscoin",
2876 onSelect: function() {
2877 network
= libs
.bitcoin
.networks
.neoscoin
;
2882 name: "NIX - NIX Platform",
2883 onSelect: function() {
2884 network
= libs
.bitcoin
.networks
.nix
;
2889 name: "NLG - Gulden",
2890 onSelect: function() {
2891 network
= libs
.bitcoin
.networks
.gulden
;
2896 name: "NMC - Namecoin",
2897 onSelect: function() {
2898 network
= libs
.bitcoin
.networks
.namecoin
;
2903 name: "NRG - Energi",
2904 onSelect: function() {
2905 network
= libs
.bitcoin
.networks
.energi
;
2910 name: "NRO - Neurocoin",
2911 onSelect: function() {
2912 network
= libs
.bitcoin
.networks
.neurocoin
;
2917 name: "NSR - Nushares",
2918 onSelect: function() {
2919 network
= libs
.bitcoin
.networks
.nushares
;
2924 name: "NYC - Newyorkc",
2925 onSelect: function() {
2926 network
= libs
.bitcoin
.networks
.newyorkc
;
2931 name: "NVC - Novacoin",
2932 onSelect: function() {
2933 network
= libs
.bitcoin
.networks
.novacoin
;
2938 name: "OK - Okcash",
2939 onSelect: function() {
2940 network
= libs
.bitcoin
.networks
.okcash
;
2945 name: "OMNI - Omnicore",
2946 onSelect: function() {
2947 network
= libs
.bitcoin
.networks
.omnicore
;
2952 name: "ONION - DeepOnion",
2953 onSelect: function() {
2954 network
= libs
.bitcoin
.networks
.deeponion
;
2959 name: "ONX - Onixcoin",
2960 onSelect: function() {
2961 network
= libs
.bitcoin
.networks
.onixcoin
;
2966 name: "PHR - Phore",
2967 onSelect: function() {
2968 network
= libs
.bitcoin
.networks
.phore
;
2973 name: "PINK - Pinkcoin",
2974 onSelect: function() {
2975 network
= libs
.bitcoin
.networks
.pinkcoin
;
2980 name: "PIRL - Pirl",
2981 segwitAvailable: false,
2982 onSelect: function() {
2983 network
= libs
.bitcoin
.networks
.bitcoin
;
2988 name: "PIVX - PIVX",
2989 onSelect: function() {
2990 network
= libs
.bitcoin
.networks
.pivx
;
2995 name: "PIVX - PIVX Testnet",
2996 onSelect: function() {
2997 network
= libs
.bitcoin
.networks
.pivxtestnet
;
3003 segwitAvailable: false,
3004 onSelect: function() {
3005 network
= libs
.bitcoin
.networks
.bitcoin
;
3010 name: "POSW - POSWcoin",
3011 onSelect: function() {
3012 network
= libs
.bitcoin
.networks
.poswcoin
;
3017 name: "POT - Potcoin",
3018 onSelect: function() {
3019 network
= libs
.bitcoin
.networks
.potcoin
;
3024 name: "PPC - Peercoin",
3025 onSelect: function() {
3026 network
= libs
.bitcoin
.networks
.peercoin
;
3031 name: "PRJ - ProjectCoin",
3032 onSelect: function() {
3033 network
= libs
.bitcoin
.networks
.projectcoin
;
3038 name: "PSB - Pesobit",
3039 onSelect: function() {
3040 network
= libs
.bitcoin
.networks
.pesobit
;
3045 name: "PUT - Putincoin",
3046 onSelect: function() {
3047 network
= libs
.bitcoin
.networks
.putincoin
;
3052 name: "RPD - Rapids",
3053 onSelect: function() {
3054 network
= libs
.bitcoin
.networks
.rapids
;
3059 name: "RVN - Ravencoin",
3060 onSelect: function() {
3061 network
= libs
.bitcoin
.networks
.ravencoin
;
3066 name: "R-BTC - RSK",
3067 onSelect: function() {
3068 network
= libs
.bitcoin
.networks
.rsk
;
3073 name: "tR-BTC - RSK Testnet",
3074 onSelect: function() {
3075 network
= libs
.bitcoin
.networks
.rsktestnet
;
3080 name: "RBY - Rubycoin",
3081 onSelect: function() {
3082 network
= libs
.bitcoin
.networks
.rubycoin
;
3087 name: "RDD - Reddcoin",
3088 onSelect: function() {
3089 network
= libs
.bitcoin
.networks
.reddcoin
;
3094 name: "RVR - RevolutionVR",
3095 onSelect: function() {
3096 network
= libs
.bitcoin
.networks
.revolutionvr
;
3101 name: "SAFE - Safecoin",
3102 onSelect: function() {
3103 network
= libs
.bitcoin
.networks
.safecoin
;
3108 name: "SCRIBE - Scribe",
3109 onSelect: function() {
3110 network
= libs
.bitcoin
.networks
.scribe
;
3115 name: "SLS - Salus",
3116 onSelect: function() {
3117 network
= libs
.bitcoin
.networks
.salus
;
3122 name: "SDC - ShadowCash",
3123 onSelect: function() {
3124 network
= libs
.bitcoin
.networks
.shadow
;
3129 name: "SDC - ShadowCash Testnet",
3130 onSelect: function() {
3131 network
= libs
.bitcoin
.networks
.shadowtn
;
3136 name: "SLM - Slimcoin",
3137 onSelect: function() {
3138 network
= libs
.bitcoin
.networks
.slimcoin
;
3143 name: "SLM - Slimcoin Testnet",
3144 onSelect: function() {
3145 network
= libs
.bitcoin
.networks
.slimcointn
;
3150 name: "SLP - Simple Ledger Protocol",
3151 onSelect: function() {
3152 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
3157 name: "SLR - Solarcoin",
3158 onSelect: function() {
3159 network
= libs
.bitcoin
.networks
.solarcoin
;
3164 name: "SMLY - Smileycoin",
3165 onSelect: function() {
3166 network
= libs
.bitcoin
.networks
.smileycoin
;
3171 name: "STASH - Stash",
3172 onSelect: function() {
3173 network
= libs
.bitcoin
.networks
.stash
;
3178 name: "STASH - Stash Testnet",
3179 onSelect: function() {
3180 network
= libs
.bitcoin
.networks
.stashtn
;
3185 name: "STRAT - Stratis",
3186 onSelect: function() {
3187 network
= libs
.bitcoin
.networks
.stratis
;
3192 name: "SUGAR - Sugarchain",
3193 onSelect: function() {
3194 network
= libs
.bitcoin
.networks
.sugarchain
;
3199 name: "TUGAR - Sugarchain Testnet",
3200 onSelect: function() {
3201 network
= libs
.bitcoin
.networks
.sugarchaintestnet
;
3206 name: "SWTC - Jingtum",
3207 onSelect: function() {
3208 network
= libs
.bitcoin
.networks
.bitcoin
;
3213 name: "TSTRAT - Stratis Testnet",
3214 onSelect: function() {
3215 network
= libs
.bitcoin
.networks
.stratistest
;
3220 name: "SYS - Syscoin",
3221 onSelect: function() {
3222 network
= libs
.bitcoin
.networks
.syscoin
;
3227 name: "THC - Hempcoin",
3228 onSelect: function() {
3229 network
= libs
.bitcoin
.networks
.hempcoin
;
3234 name: "THT - Thought",
3235 onSelect: function() {
3236 network
= libs
.bitcoin
.networks
.thought
;
3242 onSelect: function() {
3243 network
= libs
.bitcoin
.networks
.toa
;
3248 name: "TWINS - TWINS",
3249 onSelect: function() {
3250 network
= libs
.bitcoin
.networks
.twins
;
3255 name: "TWINS - TWINS Testnet",
3256 onSelect: function() {
3257 network
= libs
.bitcoin
.networks
.twinstestnet
;
3262 name: "USC - Ultimatesecurecash",
3263 onSelect: function() {
3264 network
= libs
.bitcoin
.networks
.ultimatesecurecash
;
3269 name: "USNBT - NuBits",
3270 onSelect: function() {
3271 network
= libs
.bitcoin
.networks
.nubits
;
3276 name: "UNO - Unobtanium",
3277 onSelect: function() {
3278 network
= libs
.bitcoin
.networks
.unobtanium
;
3283 name: "VASH - Vpncoin",
3284 onSelect: function() {
3285 network
= libs
.bitcoin
.networks
.vpncoin
;
3290 name: "VET - VeChain",
3291 onSelect: function() {
3292 network
= libs
.bitcoin
.networks
.bitcoin
;
3297 name: "VIA - Viacoin",
3298 onSelect: function() {
3299 network
= libs
.bitcoin
.networks
.viacoin
;
3304 name: "VIA - Viacoin Testnet",
3305 onSelect: function() {
3306 network
= libs
.bitcoin
.networks
.viacointestnet
;
3311 name: "VIVO - Vivo",
3312 onSelect: function() {
3313 network
= libs
.bitcoin
.networks
.vivo
;
3318 name: "VTC - Vertcoin",
3319 onSelect: function() {
3320 network
= libs
.bitcoin
.networks
.vertcoin
;
3325 name: "WGR - Wagerr",
3326 onSelect: function() {
3327 network
= libs
.bitcoin
.networks
.wagerr
;
3332 name: "WC - Wincoin",
3333 onSelect: function() {
3334 network
= libs
.bitcoin
.networks
.wincoin
;
3339 name: "XAX - Artax",
3340 onSelect: function() {
3341 network
= libs
.bitcoin
.networks
.artax
;
3346 name: "XBC - Bitcoinplus",
3347 onSelect: function() {
3348 network
= libs
.bitcoin
.networks
.bitcoinplus
;
3353 name: "XLM - Stellar",
3354 onSelect: function() {
3355 network
= libs
.stellarUtil
.dummyNetwork
;
3360 name: "XMY - Myriadcoin",
3361 onSelect: function() {
3362 network
= libs
.bitcoin
.networks
.myriadcoin
;
3367 name: "XRP - Ripple",
3368 onSelect: function() {
3369 network
= libs
.bitcoin
.networks
.bitcoin
;
3374 name: "XVC - Vcash",
3375 onSelect: function() {
3376 network
= libs
.bitcoin
.networks
.vcash
;
3381 name: "XVG - Verge",
3382 onSelect: function() {
3383 network
= libs
.bitcoin
.networks
.verge
;
3388 name: "XUEZ - Xuez",
3389 segwitAvailable: false,
3390 onSelect: function() {
3391 network
= libs
.bitcoin
.networks
.xuez
;
3396 name: "XWC - Whitecoin",
3397 onSelect: function() {
3398 network
= libs
.bitcoin
.networks
.whitecoin
;
3403 name: "XZC - Zcoin",
3404 onSelect: function() {
3405 network
= libs
.bitcoin
.networks
.zcoin
;
3410 name: "ZCL - Zclassic",
3411 onSelect: function() {
3412 network
= libs
.bitcoin
.networks
.zclassic
;
3417 name: "ZEC - Zcash",
3418 onSelect: function() {
3419 network
= libs
.bitcoin
.networks
.zcash
;
3424 name: "ZEN - Horizen",
3425 onSelect: function() {
3426 network
= libs
.bitcoin
.networks
.zencash
;
3434 name: "Bitcoin Core",
3435 onSelect: function() {
3436 DOM
.bip32path
.val("m/0'/0'");
3437 DOM
.hardenedAddresses
.prop('checked', true);
3441 name: "blockchain.info",
3442 onSelect: function() {
3443 DOM
.bip32path
.val("m/44'/0'/0'");
3444 DOM
.hardenedAddresses
.prop('checked', false);
3448 name: "MultiBit HD",
3449 onSelect: function() {
3450 DOM
.bip32path
.val("m/0'/0");
3451 DOM
.hardenedAddresses
.prop('checked', false);
3455 name: "Coinomi, Ledger",
3456 onSelect: function() {
3457 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3458 DOM
.hardenedAddresses
.prop('checked', false);
3463 // RSK - RSK functions - begin
3464 function stripHexPrefix(address
) {
3465 if (typeof address
!== "string") {
3466 throw new Error("address parameter should be a string.");
3469 var hasPrefix
= (address
.substring(0, 2) === "0x" ||
3470 address
.substring(0, 2) === "0X");
3472 return hasPrefix
? address
.slice(2) : address
;
3475 function toChecksumAddressForRsk(address
, chainId
= null) {
3476 if (typeof address
!== "string") {
3477 throw new Error("address parameter should be a string.");
3480 if (!/^(0x)?[0-9a-f]{40}$/i.test(address
)) {
3481 throw new Error("Given address is not a valid RSK address: " + address
);
3484 var stripAddress
= stripHexPrefix(address
).toLowerCase();
3485 var prefix
= chainId
!= null ? chainId
.toString() + "0x" : "";
3486 var keccakHash
= libs
.ethUtil
.keccak256(prefix
+ stripAddress
)
3488 .replace(/^0x/i, "");
3489 var checksumAddress
= "0x";
3491 for (var i
= 0; i
< stripAddress
.length
; i
++) {
3493 parseInt(keccakHash
[i
], 16) >= 8 ?
3494 stripAddress
[i
].toUpperCase() :
3498 return checksumAddress
;
3501 // RSK - RSK functions - end
3503 // ELA - Elastos functions - begin
3504 function displayBip44InfoForELA() {
3509 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3510 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3512 // Calculate the account extended keys
3513 var accountXprv
= libs
.elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3514 var accountXpub
= libs
.elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3516 // Display the extended keys
3517 DOM
.bip44accountXprv
.val(accountXprv
);
3518 DOM
.bip44accountXpub
.val(accountXpub
);
3521 function displayBip32InfoForELA() {
3526 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3527 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3528 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3530 DOM
.extendedPrivKey
.val(libs
.elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3531 DOM
.extendedPubKey
.val(libs
.elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3533 // Display the addresses and privkeys
3534 clearAddressesList();
3535 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3536 displayAddresses(0, initialAddressCount
);
3539 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3544 var publicKey
= libs
.elastosjs
.getDerivedPublicKey(libs
.elastosjs
.getMasterPublicKey(seed
), change
, index
);
3546 privateKey: libs
.elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3547 publicKey: publicKey
,
3548 address: libs
.elastosjs
.getAddress(publicKey
.toString('hex'))
3551 // ELA - Elastos functions - end