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 // Stellar is different
1144 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1145 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1146 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1148 path
+= purpose
+ "'/";
1149 path
+= coin
+ "'/" + index
+ "'";
1150 var keypair
= libs
.stellarUtil
.getKeypair(path
, seed
);
1152 privkey
= keypair
.secret();
1153 pubkey
= address
= keypair
.publicKey();
1155 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1156 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1157 var nebulasAccount
= libs
.nebulas
.Account
.NewAccount();
1158 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1159 address
= nebulasAccount
.getAddressString();
1160 privkey
= nebulasAccount
.getPrivateKeyString();
1161 pubkey
= nebulasAccount
.getPublicKeyString();
1163 // Ripple values are different
1164 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1165 privkey
= convertRipplePriv(privkey
);
1166 address
= convertRippleAdrr(address
);
1168 // CasinoCoin values are different
1169 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1170 privkey
= convertCasinoCoinPriv(privkey
);
1171 address
= convertCasinoCoinAdrr(address
);
1173 // Bitcoin Cash address format may vary
1174 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1175 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1176 if (bchAddrType
== "cashaddr") {
1177 address
= libs
.bchaddr
.toCashAddress(address
);
1179 else if (bchAddrType
== "bitpay") {
1180 address
= libs
.bchaddr
.toBitpayAddress(address
);
1183 // Bitcoin Cash address format may vary
1184 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1185 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1186 if (bchAddrType
== "cashaddr") {
1187 address
= libs
.bchaddrSlp
.toSlpAddress(address
);
1190 // Segwit addresses are different
1192 if (!segwitAvailable
) {
1196 var keyhash
= libs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1197 var scriptpubkey
= libs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1198 address
= libs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1200 else if (isP2wpkhInP2sh
) {
1201 var keyhash
= libs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1202 var scriptsig
= libs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1203 var addressbytes
= libs
.bitcoin
.crypto
.hash160(scriptsig
);
1204 var scriptpubkey
= libs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1205 address
= libs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1208 // https://github.com/libs.bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71
1210 var witnessScript
= libs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1211 var scriptPubKey
= libs
.bitcoin
.script
.witnessScriptHash
.output
.encode(libs
.bitcoin
.crypto
.sha256(witnessScript
));
1212 address
= libs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
);
1214 else if (isP2wshInP2sh
) {
1215 // https://github.com/libs.bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183
1217 var witnessScript
= libs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1218 var redeemScript
= libs
.bitcoin
.script
.witnessScriptHash
.output
.encode(libs
.bitcoin
.crypto
.sha256(witnessScript
));
1219 var scriptPubKey
= libs
.bitcoin
.script
.scriptHash
.output
.encode(libs
.bitcoin
.crypto
.hash160(redeemScript
));
1220 address
= libs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
)
1224 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1225 address
= libs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1228 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1230 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1231 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1234 //Groestlcoin Addresses are different
1238 if (!segwitAvailable
) {
1242 address
= libs
.groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1244 else if (isP2wpkhInP2sh
) {
1245 address
= libs
.groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1248 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1252 let elaAddress
= calcAddressForELA(
1254 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1255 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1256 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1259 address
= elaAddress
.address
;
1260 privkey
= elaAddress
.privateKey
;
1261 pubkey
= elaAddress
.publicKey
;
1264 addAddressToList(indexText
, address
, pubkey
, privkey
);
1276 function showMore() {
1277 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1278 if (isNaN(rowsToAdd
)) {
1280 DOM
.rowsToAdd
.val("20");
1282 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1284 start
= lastIndexInTable() + 1;
1287 var newStart
= start
+ rowsToAdd
;
1288 DOM
.moreRowsStartIndex
.val(newStart
);
1290 if (rowsToAdd
> 200) {
1291 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1292 msg
+= "Do you want to continue?";
1293 if (!confirm(msg
)) {
1297 displayAddresses(start
, rowsToAdd
);
1300 function clearDisplay() {
1301 clearAddressesList();
1303 hideValidationError();
1306 function clearAddressesList() {
1307 DOM
.addresses
.empty();
1312 function stopGenerating() {
1313 while (generationProcesses
.length
> 0) {
1314 var generation
= generationProcesses
.shift();
1319 function clearKeys() {
1324 function clearRootKey() {
1325 DOM
.rootKey
.val("");
1328 function clearDerivedKeys() {
1329 DOM
.extendedPrivKey
.val("");
1330 DOM
.extendedPubKey
.val("");
1331 DOM
.bip44accountXprv
.val("");
1332 DOM
.bip44accountXpub
.val("");
1335 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1336 var row
= $(addressRowTemplate
.html());
1338 var indexCell
= row
.find(".index span");
1339 var addressCell
= row
.find(".address span");
1340 var pubkeyCell
= row
.find(".pubkey span");
1341 var privkeyCell
= row
.find(".privkey span");
1343 indexCell
.text(indexText
);
1344 addressCell
.text(address
);
1345 pubkeyCell
.text(pubkey
);
1346 privkeyCell
.text(privkey
);
1349 indexCell
.addClass("invisible");
1352 addressCell
.addClass("invisible");
1355 pubkeyCell
.addClass("invisible");
1358 privkeyCell
.addClass("invisible");
1360 DOM
.addresses
.append(row
);
1361 var rowShowQrEls
= row
.find("[data-show-qr]");
1362 setQrEvents(rowShowQrEls
);
1365 function hasStrongRandom() {
1366 return 'crypto' in window
&& window
['crypto'] !== null;
1369 function disableForms() {
1370 $("form").on("submit", function(e
) {
1375 function parseIntNoNaN(val
, defaultVal
) {
1376 var v
= parseInt(val
);
1383 function showPending() {
1385 .text("Calculating...")
1389 function findNearestWord(word
) {
1390 var language
= getLanguage();
1391 var words
= WORDLISTS
[language
];
1392 var minDistance
= 99;
1393 var closestWord
= words
[0];
1394 for (var i
=0; i
<words
.length
; i
++) {
1395 var comparedTo
= words
[i
];
1396 if (comparedTo
.indexOf(word
) == 0) {
1399 var distance
= libs
.levenshtein
.get(word
, comparedTo
);
1400 if (distance
< minDistance
) {
1401 closestWord
= comparedTo
;
1402 minDistance
= distance
;
1408 function hidePending() {
1414 function populateNetworkSelect() {
1415 for (var i
=0; i
<networks
.length
; i
++) {
1416 var network
= networks
[i
];
1417 var option
= $("<option>");
1418 option
.attr("value", i
);
1419 option
.text(network
.name
);
1420 if (network
.name
== "BTC - Bitcoin") {
1421 option
.prop("selected", true);
1423 DOM
.phraseNetwork
.append(option
);
1427 function populateClientSelect() {
1428 for (var i
=0; i
<clients
.length
; i
++) {
1429 var client
= clients
[i
];
1430 var option
= $("<option>");
1431 option
.attr("value", i
);
1432 option
.text(client
.name
);
1433 DOM
.bip32Client
.append(option
);
1437 function getLanguage() {
1438 var defaultLanguage
= "english";
1439 // Try to get from existing phrase
1440 var language
= getLanguageFromPhrase();
1441 // Try to get from url if not from phrase
1442 if (language
.length
== 0) {
1443 language
= getLanguageFromUrl();
1445 // Default to English if no other option
1446 if (language
.length
== 0) {
1447 language
= defaultLanguage
;
1452 function getLanguageFromPhrase(phrase
) {
1453 // Check if how many words from existing phrase match a language.
1456 phrase
= DOM
.phrase
.val();
1458 if (phrase
.length
> 0) {
1459 var words
= phraseToWordArray(phrase
);
1460 var languageMatches
= {};
1461 for (l
in WORDLISTS
) {
1462 // Track how many words match in this language
1463 languageMatches
[l
] = 0;
1464 for (var i
=0; i
<words
.length
; i
++) {
1465 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1466 if (wordInLanguage
) {
1467 languageMatches
[l
]++;
1470 // Find languages with most word matches.
1471 // This is made difficult due to commonalities between Chinese
1472 // simplified vs traditional.
1473 var mostMatches
= 0;
1474 var mostMatchedLanguages
= [];
1475 for (var l
in languageMatches
) {
1476 var numMatches
= languageMatches
[l
];
1477 if (numMatches
> mostMatches
) {
1478 mostMatches
= numMatches
;
1479 mostMatchedLanguages
= [l
];
1481 else if (numMatches
== mostMatches
) {
1482 mostMatchedLanguages
.push(l
);
1486 if (mostMatchedLanguages
.length
> 0) {
1487 // Use first language and warn if multiple detected
1488 language
= mostMatchedLanguages
[0];
1489 if (mostMatchedLanguages
.length
> 1) {
1490 console
.warn("Multiple possible languages");
1491 console
.warn(mostMatchedLanguages
);
1498 function getLanguageFromUrl() {
1499 for (var language
in WORDLISTS
) {
1500 if (window
.location
.hash
.indexOf(language
) > -1) {
1507 function setMnemonicLanguage() {
1508 var language
= getLanguage();
1509 // Load the bip39 mnemonic generator for this language if required
1510 if (!(language
in mnemonics
)) {
1511 mnemonics
[language
] = new Mnemonic(language
);
1513 mnemonic
= mnemonics
[language
];
1516 function convertPhraseToNewLanguage() {
1517 var oldLanguage
= getLanguageFromPhrase();
1518 var newLanguage
= getLanguageFromUrl();
1519 var oldPhrase
= DOM
.phrase
.val();
1520 var oldWords
= phraseToWordArray(oldPhrase
);
1522 for (var i
=0; i
<oldWords
.length
; i
++) {
1523 var oldWord
= oldWords
[i
];
1524 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1525 var newWord
= WORDLISTS
[newLanguage
][index
];
1526 newWords
.push(newWord
);
1528 newPhrase
= wordArrayToPhrase(newWords
);
1532 // TODO look at jsbip39 - mnemonic.splitWords
1533 function phraseToWordArray(phrase
) {
1534 var words
= phrase
.split(/\s/g);
1536 for (var i
=0; i
<words
.length
; i
++) {
1537 var word
= words
[i
];
1538 if (word
.length
> 0) {
1539 noBlanks
.push(word
);
1545 // TODO look at jsbip39 - mnemonic.joinWords
1546 function wordArrayToPhrase(words
) {
1547 var phrase
= words
.join(" ");
1548 var language
= getLanguageFromPhrase(phrase
);
1549 if (language
== "japanese") {
1550 phrase
= words
.join("\u3000");
1555 function writeSplitPhrase(phrase
) {
1556 var wordCount
= phrase
.split(/\s/g).length
;
1558 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1559 var group
=[[],[],[]],
1561 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1562 while (left
.length
>0) {
1563 groupI
=(groupI
+1)%3;
1564 seed
= seed
* 16807 % 2147483647;
1565 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1566 group
[groupI
].push(left
[selected
]);
1567 left
.splice(selected
,1);
1569 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1570 for (var i
=0;i
<3;i
++) {
1571 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1572 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1574 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1575 var triesPerSecond
=10000000000;
1576 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1577 var displayRedText
= false;
1579 hackTime
="<1 second";
1580 displayRedText
= true;
1581 } else if (hackTime
<86400) {
1582 hackTime
=Math
.floor(hackTime
)+" seconds";
1583 displayRedText
= true;
1584 } else if(hackTime
<31557600) {
1585 hackTime
=Math
.floor(hackTime
/86400)+" days";
1586 displayRedText
= true;
1588 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1590 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1591 if (displayRedText
) {
1592 DOM
.phraseSplitWarn
.addClass("text-danger");
1594 DOM
.phraseSplitWarn
.removeClass("text-danger");
1598 function isUsingOwnEntropy() {
1599 return DOM
.useEntropy
.prop("checked");
1602 function setMnemonicFromEntropy() {
1603 clearEntropyFeedback();
1604 // Get entropy value
1605 var entropyStr
= DOM
.entropy
.val();
1606 // Work out minimum base for entropy
1608 if (entropyTypeAutoDetect
) {
1609 entropy
= Entropy
.fromString(entropyStr
);
1612 let base
= DOM
.entropyTypeInputs
.filter(":checked").val();
1613 entropy
= Entropy
.fromString(entropyStr
, base
);
1615 if (entropy
.binaryStr
.length
== 0) {
1618 // Show entropy details
1619 showEntropyFeedback(entropy
);
1620 // Use entropy hash if not using raw entropy
1621 var bits
= entropy
.binaryStr
;
1622 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1623 if (mnemonicLength
!= "raw") {
1624 // Get bits by hashing entropy with SHA256
1625 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1626 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1627 bits
= libs
.BigInteger
.BigInteger
.parse(hex
, 16).toString(2);
1628 while (bits
.length
% 256 != 0) {
1631 // Truncate hash to suit number of words
1632 mnemonicLength
= parseInt(mnemonicLength
);
1633 var numberOfBits
= 32 * mnemonicLength
/ 3;
1634 bits
= bits
.substring(0, numberOfBits
);
1635 // show warning for weak entropy override
1636 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1637 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1640 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1644 // hide warning for weak entropy override
1645 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1647 // Discard trailing entropy
1648 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1649 var start
= bits
.length
- bitsToUse
;
1650 var binaryStr
= bits
.substring(start
);
1651 // Convert entropy string to numeric array
1652 var entropyArr
= [];
1653 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1654 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1655 var entropyByte
= parseInt(byteAsBits
, 2);
1656 entropyArr
.push(entropyByte
)
1658 // Convert entropy array to mnemonic
1659 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1660 // Set the mnemonic in the UI
1661 DOM
.phrase
.val(phrase
);
1662 writeSplitPhrase(phrase
);
1663 // Show the word indexes
1665 // Show the checksum
1669 function clearEntropyFeedback() {
1670 DOM
.entropyCrackTime
.text("...");
1671 DOM
.entropyType
.text("");
1672 DOM
.entropyWordCount
.text("0");
1673 DOM
.entropyEventCount
.text("0");
1674 DOM
.entropyBitsPerEvent
.text("0");
1675 DOM
.entropyBits
.text("0");
1676 DOM
.entropyFiltered
.html(" ");
1677 DOM
.entropyBinary
.html(" ");
1680 function showEntropyFeedback(entropy
) {
1681 var numberOfBits
= entropy
.binaryStr
.length
;
1682 var timeToCrack
= "unknown";
1684 var z
= libs
.zxcvbn(entropy
.base
.parts
.join(""));
1685 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1686 if (z
.feedback
.warning
!= "") {
1687 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1691 console
.log("Error detecting entropy strength with zxcvbn:");
1694 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1695 DOM
.entropyTypeInputs
.attr("checked", false);
1696 DOM
.entropyTypeInputs
.filter("[value='" + entropyTypeStr
+ "']").attr("checked", true);
1697 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1698 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1699 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1700 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1701 DOM
.entropyType
.text(entropyTypeStr
);
1702 DOM
.entropyCrackTime
.text(timeToCrack
);
1703 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1704 DOM
.entropyBits
.text(numberOfBits
);
1705 DOM
.entropyWordCount
.text(wordCount
);
1706 DOM
.entropyBinary
.text(spacedBinaryStr
);
1707 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1708 // detect and warn of filtering
1709 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1710 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1711 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1713 DOM
.entropyFilterWarning
.removeClass('hidden');
1716 DOM
.entropyFilterWarning
.addClass('hidden');
1720 function getEntropyTypeStr(entropy
) {
1721 var typeStr
= entropy
.base
.str
;
1722 // Add some detail if these are cards
1723 if (entropy
.base
.asInt
== 52) {
1724 var cardDetail
= []; // array of message strings
1725 // Detect duplicates
1727 var dupeTracker
= {};
1728 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1729 var card
= entropy
.base
.parts
[i
];
1730 var cardUpper
= card
.toUpperCase();
1731 if (cardUpper
in dupeTracker
) {
1734 dupeTracker
[cardUpper
] = true;
1736 if (dupes
.length
> 0) {
1737 var dupeWord
= "duplicates";
1738 if (dupes
.length
== 1) {
1739 dupeWord
= "duplicate";
1741 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1742 if (dupes
.length
> 3) {
1745 cardDetail
.push(msg
);
1748 var uniqueCards
= [];
1749 for (var uniqueCard
in dupeTracker
) {
1750 uniqueCards
.push(uniqueCard
);
1752 if (uniqueCards
.length
== 52) {
1753 cardDetail
.unshift("full deck");
1755 // Detect missing cards
1756 var values
= "A23456789TJQK";
1758 var missingCards
= [];
1759 for (var i
=0; i
<suits
.length
; i
++) {
1760 for (var j
=0; j
<values
.length
; j
++) {
1761 var card
= values
[j
] + suits
[i
];
1762 if (!(card
in dupeTracker
)) {
1763 missingCards
.push(card
);
1767 // Display missing cards if six or less, ie clearly going for full deck
1768 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1769 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1770 if (missingCards
.length
> 3) {
1773 cardDetail
.push(msg
);
1775 // Add card details to typeStr
1776 if (cardDetail
.length
> 0) {
1777 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1783 function setQrEvents(els
) {
1784 els
.on("mouseenter", createQr
);
1785 els
.on("mouseleave", destroyQr
);
1786 els
.on("click", toggleQr
);
1789 function createQr(e
) {
1790 var content
= e
.target
.textContent
|| e
.target
.value
;
1792 var qrEl
= libs
.kjua({
1798 DOM
.qrImage
.append(qrEl
);
1800 DOM
.qrHider
.addClass("hidden");
1803 DOM
.qrHider
.removeClass("hidden");
1805 DOM
.qrContainer
.removeClass("hidden");
1809 function destroyQr() {
1810 DOM
.qrImage
.text("");
1811 DOM
.qrContainer
.addClass("hidden");
1814 function toggleQr() {
1816 DOM
.qrHider
.toggleClass("hidden");
1817 DOM
.qrHint
.toggleClass("hidden");
1820 function bip44TabSelected() {
1821 return DOM
.bip44tab
.hasClass("active");
1824 function bip32TabSelected() {
1825 return DOM
.bip32tab
.hasClass("active");
1828 function networkIsEthereum() {
1829 var name
= networks
[DOM
.network
.val()].name
;
1830 return (name
== "ETH - Ethereum")
1831 || (name
== "ETC - Ethereum Classic")
1832 || (name
== "EWT - EnergyWeb")
1833 || (name
== "PIRL - Pirl")
1834 || (name
== "MIX - MIX")
1835 || (name
== "MUSIC - Musicoin")
1836 || (name
== "POA - Poa")
1837 || (name
== "EXP - Expanse")
1838 || (name
== "CLO - Callisto")
1839 || (name
== "DXN - DEXON")
1840 || (name
== "ELLA - Ellaism")
1841 || (name
== "ESN - Ethersocial Network")
1842 || (name
== "VET - VeChain")
1843 || (name
== "ERE - EtherCore")
1846 function networkHasSegwit() {
1848 if ("baseNetwork" in network
) {
1849 n
= libs
.bitcoin
.networks
[network
.baseNetwork
];
1851 // check if only p2wpkh params are required
1852 if (p2wpkhSelected()) {
1853 return "p2wpkh" in n
;
1855 // check if only p2wpkh-in-p2sh params are required
1856 else if (p2wpkhInP2shSelected()) {
1857 return "p2wpkhInP2sh" in n
;
1859 // require both if it's unclear which params are required
1860 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1863 function bip49TabSelected() {
1864 return DOM
.bip49tab
.hasClass("active");
1867 function bip84TabSelected() {
1868 return DOM
.bip84tab
.hasClass("active");
1871 function bip141TabSelected() {
1872 return DOM
.bip141tab
.hasClass("active");
1875 function setHdCoin(coinValue
) {
1876 DOM
.bip44coin
.val(coinValue
);
1877 DOM
.bip49coin
.val(coinValue
);
1878 DOM
.bip84coin
.val(coinValue
);
1881 function showSegwitAvailable() {
1882 DOM
.bip49unavailable
.addClass("hidden");
1883 DOM
.bip49available
.removeClass("hidden");
1884 DOM
.bip84unavailable
.addClass("hidden");
1885 DOM
.bip84available
.removeClass("hidden");
1886 DOM
.bip141unavailable
.addClass("hidden");
1887 DOM
.bip141available
.removeClass("hidden");
1890 function showSegwitUnavailable() {
1891 DOM
.bip49available
.addClass("hidden");
1892 DOM
.bip49unavailable
.removeClass("hidden");
1893 DOM
.bip84available
.addClass("hidden");
1894 DOM
.bip84unavailable
.removeClass("hidden");
1895 DOM
.bip141available
.addClass("hidden");
1896 DOM
.bip141unavailable
.removeClass("hidden");
1899 function adjustNetworkForSegwit() {
1900 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1901 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1903 // See https://github.com/iancoleman/bip39/issues/125
1904 var segwitNetworks
= null;
1905 // if a segwit network is alread selected, need to use base network to
1906 // look up new parameters
1907 if ("baseNetwork" in network
) {
1908 network
= libs
.bitcoin
.networks
[network
.baseNetwork
];
1910 // choose the right segwit params
1911 if (p2wpkhSelected() && "p2wpkh" in network
) {
1912 network
= network
.p2wpkh
;
1914 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1915 network
= network
.p2wpkhInP2sh
;
1917 else if (p2wshSelected() && "p2wsh" in network
) {
1918 network
= network
.p2wsh
;
1920 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network
) {
1921 network
= network
.p2wshInP2sh
;
1925 function lastIndexInTable() {
1926 var pathText
= DOM
.addresses
.find(".index").last().text();
1927 var pathBits
= pathText
.split("/");
1928 var lastBit
= pathBits
[pathBits
.length
-1];
1929 var lastBitClean
= lastBit
.replace("'", "");
1930 return parseInt(lastBitClean
);
1933 function uint8ArrayToHex(a
) {
1935 for (var i
=0; i
<a
.length
; i
++) {
1936 var h
= a
[i
].toString(16);
1937 while (h
.length
< 2) {
1945 function showWordIndexes() {
1946 var phrase
= DOM
.phrase
.val();
1947 var words
= phraseToWordArray(phrase
);
1948 var wordIndexes
= [];
1949 var language
= getLanguage();
1950 for (var i
=0; i
<words
.length
; i
++) {
1951 var word
= words
[i
];
1952 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1953 wordIndexes
.push(wordIndex
);
1955 var wordIndexesStr
= wordIndexes
.join(", ");
1956 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1959 function showChecksum() {
1960 var phrase
= DOM
.phrase
.val();
1961 var words
= phraseToWordArray(phrase
);
1962 var checksumBitlength
= words
.length
/ 3;
1965 var language
= getLanguage();
1966 for (var i
=words
.length
-1; i
>=0; i
--) {
1967 var word
= words
[i
];
1968 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1969 var wordBinary
= wordIndex
.toString(2);
1970 while (wordBinary
.length
< 11) {
1971 wordBinary
= "0" + wordBinary
;
1973 var binaryStr
= wordBinary
+ binaryStr
;
1974 if (binaryStr
.length
>= checksumBitlength
) {
1975 var start
= binaryStr
.length
- checksumBitlength
;
1976 var end
= binaryStr
.length
;
1977 checksum
= binaryStr
.substring(start
, end
);
1978 // add spaces so the last group is 11 bits, not the first
1979 checksum
= checksum
.split("").reverse().join("")
1980 checksum
= addSpacesEveryElevenBits(checksum
);
1981 checksum
= checksum
.split("").reverse().join("")
1985 DOM
.entropyChecksum
.text(checksum
);
1988 function updateCsv() {
1989 var tableCsv
= "path,address,public key,private key\n";
1990 var rows
= DOM
.addresses
.find("tr");
1991 for (var i
=0; i
<rows
.length
; i
++) {
1992 var row
= $(rows
[i
]);
1993 var cells
= row
.find("td");
1994 for (var j
=0; j
<cells
.length
; j
++) {
1995 var cell
= $(cells
[j
]);
1996 if (!cell
.children().hasClass("invisible")) {
1997 tableCsv
= tableCsv
+ cell
.text();
1999 if (j
!= cells
.length
- 1) {
2000 tableCsv
= tableCsv
+ ",";
2003 tableCsv
= tableCsv
+ "\n";
2005 DOM
.csv
.val(tableCsv
);
2008 function addSpacesEveryElevenBits(binaryStr
) {
2009 return binaryStr
.match(/.{1,11}/g).join(" ");
2014 name: "AC - Asiacoin",
2015 onSelect: function() {
2016 network
= libs
.bitcoin
.networks
.asiacoin
;
2021 name: "ACC - Adcoin",
2022 onSelect: function() {
2023 network
= libs
.bitcoin
.networks
.adcoin
;
2028 name: "ARYA - Aryacoin",
2029 onSelect: function() {
2030 network
= libs
.bitcoin
.networks
.aryacoin
;
2035 name: "AUR - Auroracoin",
2036 onSelect: function() {
2037 network
= libs
.bitcoin
.networks
.auroracoin
;
2043 onSelect: function() {
2044 network
= libs
.bitcoin
.networks
.axe
;
2049 name: "ANON - ANON",
2050 onSelect: function() {
2051 network
= libs
.bitcoin
.networks
.anon
;
2056 name: "BOLI - Bolivarcoin",
2057 onSelect: function() {
2058 network
= libs
.bitcoin
.networks
.bolivarcoin
;
2063 name: "BCA - Bitcoin Atom",
2064 onSelect: function() {
2065 network
= libs
.bitcoin
.networks
.atom
;
2070 name: "BCH - Bitcoin Cash",
2071 onSelect: function() {
2072 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2077 name: "BEET - Beetlecoin",
2078 onSelect: function() {
2079 network
= libs
.bitcoin
.networks
.beetlecoin
;
2084 name: "BELA - Belacoin",
2085 onSelect: function() {
2086 network
= libs
.bitcoin
.networks
.belacoin
;
2091 name: "BLK - BlackCoin",
2092 onSelect: function() {
2093 network
= libs
.bitcoin
.networks
.blackcoin
;
2098 name: "BND - Blocknode",
2099 onSelect: function() {
2100 network
= libs
.bitcoin
.networks
.blocknode
;
2105 name: "tBND - Blocknode Testnet",
2106 onSelect: function() {
2107 network
= libs
.bitcoin
.networks
.blocknode_testnet
;
2112 name: "BRIT - Britcoin",
2113 onSelect: function() {
2114 network
= libs
.bitcoin
.networks
.britcoin
;
2119 name: "BSD - Bitsend",
2120 onSelect: function() {
2121 network
= libs
.bitcoin
.networks
.bitsend
;
2126 name: "BST - BlockStamp",
2127 onSelect: function() {
2128 network
= libs
.bitcoin
.networks
.blockstamp
;
2134 onSelect: function() {
2135 network
= libs
.bitcoin
.networks
.bata
;
2140 name: "BTC - Bitcoin",
2141 onSelect: function() {
2142 network
= libs
.bitcoin
.networks
.bitcoin
;
2147 name: "BTC - Bitcoin RegTest",
2148 onSelect: function() {
2149 network
= libs
.bitcoin
.networks
.regtest
;
2150 // Using hd coin value 1 based on bip44_coin_type
2151 // https://github.com/chaintope/bitcoinrb/blob/f1014406f6b8f9b4edcecedc18df70c80df06f11/lib/bitcoin/chainparams/regtest.yml
2156 name: "BTC - Bitcoin Testnet",
2157 onSelect: function() {
2158 network
= libs
.bitcoin
.networks
.testnet
;
2163 name: "BITG - Bitcoin Green",
2164 onSelect: function() {
2165 network
= libs
.bitcoin
.networks
.bitcoingreen
;
2170 name: "BTCP - Bitcoin Private",
2171 onSelect: function() {
2172 network
= libs
.bitcoin
.networks
.bitcoinprivate
;
2177 name: "BSV - BitcoinSV",
2178 onSelect: function() {
2179 network
= libs
.bitcoin
.networks
.bitcoinsv
;
2184 name: "BTCZ - Bitcoinz",
2185 onSelect: function() {
2186 network
= libs
.bitcoin
.networks
.bitcoinz
;
2191 name: "BTDX - BitCloud",
2192 onSelect: function() {
2193 network
= libs
.bitcoin
.networks
.bitcloud
;
2198 name: "BTG - Bitcoin Gold",
2199 onSelect: function() {
2200 network
= libs
.bitcoin
.networks
.bgold
;
2205 name: "BTX - Bitcore",
2206 onSelect: function() {
2207 network
= libs
.bitcoin
.networks
.bitcore
;
2212 name: "CCN - Cannacoin",
2213 onSelect: function() {
2214 network
= libs
.bitcoin
.networks
.cannacoin
;
2219 name: "CESC - Cryptoescudo",
2220 onSelect: function() {
2221 network
= libs
.bitcoin
.networks
.cannacoin
;
2226 name: "CDN - Canadaecoin",
2227 onSelect: function() {
2228 network
= libs
.bitcoin
.networks
.canadaecoin
;
2233 name: "CLAM - Clams",
2234 onSelect: function() {
2235 network
= libs
.bitcoin
.networks
.clam
;
2240 name: "CLO - Callisto",
2241 segwitAvailable: false,
2242 onSelect: function() {
2243 network
= libs
.bitcoin
.networks
.bitcoin
;
2248 name: "CLUB - Clubcoin",
2249 onSelect: function() {
2250 network
= libs
.bitcoin
.networks
.clubcoin
;
2255 name: "CMP - Compcoin",
2256 onSelect: function() {
2257 network
= libs
.bitcoin
.networks
.compcoin
;
2262 name: "CPU - CPUchain",
2263 onSelect: function() {
2264 network
= libs
.bitcoin
.networks
.cpuchain
;
2269 name: "CRAVE - Crave",
2270 onSelect: function() {
2271 network
= libs
.bitcoin
.networks
.crave
;
2276 name: "CRW - Crown (Legacy)",
2277 onSelect: function() {
2278 network
= libs
.bitcoin
.networks
.crown
;
2283 name: "CRW - Crown",
2284 onSelect: function() {
2285 network
= libs
.bitcoin
.networks
.crown
;
2290 name: "CSC - CasinoCoin",
2291 onSelect: function() {
2292 network
= libs
.bitcoin
.networks
.bitcoin
;
2297 name: "DASH - Dash",
2298 onSelect: function() {
2299 network
= libs
.bitcoin
.networks
.dash
;
2304 name: "DASH - Dash Testnet",
2305 onSelect: function() {
2306 network
= libs
.bitcoin
.networks
.dashtn
;
2311 name: "DFC - Defcoin",
2312 onSelect: function() {
2313 network
= libs
.bitcoin
.networks
.defcoin
;
2318 name: "DGB - Digibyte",
2319 onSelect: function() {
2320 network
= libs
.bitcoin
.networks
.digibyte
;
2325 name: "DGC - Digitalcoin",
2326 onSelect: function() {
2327 network
= libs
.bitcoin
.networks
.digitalcoin
;
2332 name: "DMD - Diamond",
2333 onSelect: function() {
2334 network
= libs
.bitcoin
.networks
.diamond
;
2339 name: "DNR - Denarius",
2340 onSelect: function() {
2341 network
= libs
.bitcoin
.networks
.denarius
;
2346 name: "DOGE - Dogecoin",
2347 onSelect: function() {
2348 network
= libs
.bitcoin
.networks
.dogecoin
;
2353 name: "DOGEt - Dogecoin Testnet",
2354 onSelect: function() {
2355 network
= libs
.bitcoin
.networks
.dogecointestnet
;
2360 name: "DXN - DEXON",
2361 onSelect: function() {
2362 network
= libs
.bitcoin
.networks
.bitcoin
;
2367 name: "ECN - Ecoin",
2368 onSelect: function() {
2369 network
= libs
.bitcoin
.networks
.ecoin
;
2374 name: "EDRC - Edrcoin",
2375 onSelect: function() {
2376 network
= libs
.bitcoin
.networks
.edrcoin
;
2381 name: "EFL - Egulden",
2382 onSelect: function() {
2383 network
= libs
.bitcoin
.networks
.egulden
;
2388 name: "ELA - Elastos",
2389 onSelect: function () {
2390 network
= libs
.bitcoin
.networks
.elastos
;
2395 name: "ELLA - Ellaism",
2396 segwitAvailable: false,
2397 onSelect: function() {
2398 network
= libs
.bitcoin
.networks
.bitcoin
;
2403 name: "EMC2 - Einsteinium",
2404 onSelect: function() {
2405 network
= libs
.bitcoin
.networks
.einsteinium
;
2410 name: "ERC - Europecoin",
2411 onSelect: function() {
2412 network
= libs
.bitcoin
.networks
.europecoin
;
2417 name: "EOS - EOSIO",
2418 onSelect: function() {
2419 network
= libs
.bitcoin
.networks
.bitcoin
;
2424 name: "ERE - EtherCore",
2425 segwitAvailable: false,
2426 onSelect: function() {
2427 network
= libs
.bitcoin
.networks
.bitcoin
;
2432 name: "ESN - Ethersocial Network",
2433 segwitAvailable: false,
2434 onSelect: function() {
2435 network
= libs
.bitcoin
.networks
.bitcoin
;
2440 name: "ETC - Ethereum Classic",
2441 segwitAvailable: false,
2442 onSelect: function() {
2443 network
= libs
.bitcoin
.networks
.bitcoin
;
2448 name: "ETH - Ethereum",
2449 onSelect: function() {
2450 network
= libs
.bitcoin
.networks
.bitcoin
;
2455 name: "EWT - EnergyWeb",
2456 onSelect: function() {
2457 network
= libs
.bitcoin
.networks
.bitcoin
;
2462 name: "EXCL - Exclusivecoin",
2463 onSelect: function() {
2464 network
= libs
.bitcoin
.networks
.exclusivecoin
;
2469 name: "EXCC - ExchangeCoin",
2470 onSelect: function() {
2471 network
= libs
.bitcoin
.networks
.exchangecoin
;
2476 name: "EXP - Expanse",
2477 segwitAvailable: false,
2478 onSelect: function() {
2479 network
= libs
.bitcoin
.networks
.bitcoin
;
2485 onSelect: function() {
2486 network
= libs
.bitcoin
.networks
.fix
;
2491 name: "FIX - FIX Testnet",
2492 onSelect: function() {
2493 network
= libs
.bitcoin
.networks
.fixtestnet
;
2498 name: "FJC - Fujicoin",
2499 onSelect: function() {
2500 network
= libs
.bitcoin
.networks
.fujicoin
;
2505 name: "FLASH - Flashcoin",
2506 onSelect: function() {
2507 network
= libs
.bitcoin
.networks
.flashcoin
;
2512 name: "FRST - Firstcoin",
2513 onSelect: function() {
2514 network
= libs
.bitcoin
.networks
.firstcoin
;
2519 name: "FTC - Feathercoin",
2520 onSelect: function() {
2521 network
= libs
.bitcoin
.networks
.feathercoin
;
2526 name: "GAME - GameCredits",
2527 onSelect: function() {
2528 network
= libs
.bitcoin
.networks
.game
;
2533 name: "GBX - Gobyte",
2534 onSelect: function() {
2535 network
= libs
.bitcoin
.networks
.gobyte
;
2540 name: "GCR - GCRCoin",
2541 onSelect: function() {
2542 network
= libs
.bitcoin
.networks
.gcr
;
2547 name: "GRC - Gridcoin",
2548 onSelect: function() {
2549 network
= libs
.bitcoin
.networks
.gridcoin
;
2554 name: "GRS - Groestlcoin",
2555 onSelect: function() {
2556 network
= libs
.bitcoin
.networks
.groestlcoin
;
2561 name: "GRS - Groestlcoin Testnet",
2562 onSelect: function() {
2563 network
= libs
.bitcoin
.networks
.groestlcointestnet
;
2568 name: "HNC - Helleniccoin",
2569 onSelect: function() {
2570 network
= libs
.bitcoin
.networks
.helleniccoin
;
2575 name: "HUSH - Hush (Legacy)",
2576 onSelect: function() {
2577 network
= libs
.bitcoin
.networks
.hush
;
2582 name: "HUSH - Hush3",
2583 onSelect: function() {
2584 network
= libs
.bitcoin
.networks
.hush3
;
2589 name: "INSN - Insane",
2590 onSelect: function() {
2591 network
= libs
.bitcoin
.networks
.insane
;
2597 onSelect: function() {
2598 network
= libs
.bitcoin
.networks
.iop
;
2603 name: "IXC - Ixcoin",
2604 onSelect: function() {
2605 network
= libs
.bitcoin
.networks
.ixcoin
;
2610 name: "JBS - Jumbucks",
2611 onSelect: function() {
2612 network
= libs
.bitcoin
.networks
.jumbucks
;
2617 name: "KMD - Komodo",
2618 bip49available: false,
2619 onSelect: function() {
2620 network
= libs
.bitcoin
.networks
.komodo
;
2625 name: "KOBO - Kobocoin",
2626 bip49available: false,
2627 onSelect: function() {
2628 network
= libs
.bitcoin
.networks
.kobocoin
;
2633 name: "LBC - Library Credits",
2634 onSelect: function() {
2635 network
= libs
.bitcoin
.networks
.lbry
;
2640 name: "LCC - Litecoincash",
2641 onSelect: function() {
2642 network
= libs
.bitcoin
.networks
.litecoincash
;
2647 name: "LDCN - Landcoin",
2648 onSelect: function() {
2649 network
= libs
.bitcoin
.networks
.landcoin
;
2654 name: "LINX - Linx",
2655 onSelect: function() {
2656 network
= libs
.bitcoin
.networks
.linx
;
2661 name: "LKR - Lkrcoin",
2662 segwitAvailable: false,
2663 onSelect: function() {
2664 network
= libs
.bitcoin
.networks
.lkrcoin
;
2669 name: "LTC - Litecoin",
2670 onSelect: function() {
2671 network
= libs
.bitcoin
.networks
.litecoin
;
2673 DOM
.litecoinLtubContainer
.removeClass("hidden");
2677 name: "LTCt - Litecoin Testnet",
2678 onSelect: function() {
2679 network
= libs
.bitcoin
.networks
.litecointestnet
;
2681 DOM
.litecoinLtubContainer
.removeClass("hidden");
2685 name: "LTZ - LitecoinZ",
2686 onSelect: function() {
2687 network
= libs
.bitcoin
.networks
.litecoinz
;
2692 name: "LYNX - Lynx",
2693 onSelect: function() {
2694 network
= libs
.bitcoin
.networks
.lynx
;
2699 name: "MAZA - Maza",
2700 onSelect: function() {
2701 network
= libs
.bitcoin
.networks
.maza
;
2706 name: "MEC - Megacoin",
2707 onSelect: function() {
2708 network
= libs
.bitcoin
.networks
.megacoin
;
2714 segwitAvailable: false,
2715 onSelect: function() {
2716 network
= libs
.bitcoin
.networks
.bitcoin
;
2721 name: "MNX - Minexcoin",
2722 onSelect: function() {
2723 network
= libs
.bitcoin
.networks
.minexcoin
;
2728 name: "MONA - Monacoin",
2729 onSelect: function() {
2730 network
= libs
.bitcoin
.networks
.monacoin
,
2735 name: "MONK - Monkey Project",
2736 onSelect: function() {
2737 network
= libs
.bitcoin
.networks
.monkeyproject
,
2742 name: "MUSIC - Musicoin",
2743 segwitAvailable: false,
2744 onSelect: function() {
2745 network
= libs
.bitcoin
.networks
.bitcoin
;
2750 name: "NAV - Navcoin",
2751 onSelect: function() {
2752 network
= libs
.bitcoin
.networks
.navcoin
;
2757 name: "NAS - Nebulas",
2758 onSelect: function() {
2759 network
= libs
.bitcoin
.networks
.bitcoin
;
2764 name: "NEBL - Neblio",
2765 onSelect: function() {
2766 network
= libs
.bitcoin
.networks
.neblio
;
2771 name: "NEOS - Neoscoin",
2772 onSelect: function() {
2773 network
= libs
.bitcoin
.networks
.neoscoin
;
2778 name: "NIX - NIX Platform",
2779 onSelect: function() {
2780 network
= libs
.bitcoin
.networks
.nix
;
2785 name: "NLG - Gulden",
2786 onSelect: function() {
2787 network
= libs
.bitcoin
.networks
.gulden
;
2792 name: "NMC - Namecoin",
2793 onSelect: function() {
2794 network
= libs
.bitcoin
.networks
.namecoin
;
2799 name: "NRG - Energi",
2800 onSelect: function() {
2801 network
= libs
.bitcoin
.networks
.energi
;
2806 name: "NRO - Neurocoin",
2807 onSelect: function() {
2808 network
= libs
.bitcoin
.networks
.neurocoin
;
2813 name: "NSR - Nushares",
2814 onSelect: function() {
2815 network
= libs
.bitcoin
.networks
.nushares
;
2820 name: "NYC - Newyorkc",
2821 onSelect: function() {
2822 network
= libs
.bitcoin
.networks
.newyorkc
;
2827 name: "NVC - Novacoin",
2828 onSelect: function() {
2829 network
= libs
.bitcoin
.networks
.novacoin
;
2834 name: "OK - Okcash",
2835 onSelect: function() {
2836 network
= libs
.bitcoin
.networks
.okcash
;
2841 name: "OMNI - Omnicore",
2842 onSelect: function() {
2843 network
= libs
.bitcoin
.networks
.omnicore
;
2848 name: "ONION - DeepOnion",
2849 onSelect: function() {
2850 network
= libs
.bitcoin
.networks
.deeponion
;
2855 name: "ONX - Onixcoin",
2856 onSelect: function() {
2857 network
= libs
.bitcoin
.networks
.onixcoin
;
2862 name: "PHR - Phore",
2863 onSelect: function() {
2864 network
= libs
.bitcoin
.networks
.phore
;
2869 name: "PINK - Pinkcoin",
2870 onSelect: function() {
2871 network
= libs
.bitcoin
.networks
.pinkcoin
;
2876 name: "PIRL - Pirl",
2877 segwitAvailable: false,
2878 onSelect: function() {
2879 network
= libs
.bitcoin
.networks
.bitcoin
;
2884 name: "PIVX - PIVX",
2885 onSelect: function() {
2886 network
= libs
.bitcoin
.networks
.pivx
;
2891 name: "PIVX - PIVX Testnet",
2892 onSelect: function() {
2893 network
= libs
.bitcoin
.networks
.pivxtestnet
;
2899 segwitAvailable: false,
2900 onSelect: function() {
2901 network
= libs
.bitcoin
.networks
.bitcoin
;
2906 name: "POSW - POSWcoin",
2907 onSelect: function() {
2908 network
= libs
.bitcoin
.networks
.poswcoin
;
2913 name: "POT - Potcoin",
2914 onSelect: function() {
2915 network
= libs
.bitcoin
.networks
.potcoin
;
2920 name: "PPC - Peercoin",
2921 onSelect: function() {
2922 network
= libs
.bitcoin
.networks
.peercoin
;
2927 name: "PRJ - ProjectCoin",
2928 onSelect: function() {
2929 network
= libs
.bitcoin
.networks
.projectcoin
;
2934 name: "PSB - Pesobit",
2935 onSelect: function() {
2936 network
= libs
.bitcoin
.networks
.pesobit
;
2941 name: "PUT - Putincoin",
2942 onSelect: function() {
2943 network
= libs
.bitcoin
.networks
.putincoin
;
2948 name: "RPD - Rapids",
2949 onSelect: function() {
2950 network
= libs
.bitcoin
.networks
.rapids
;
2955 name: "RVN - Ravencoin",
2956 onSelect: function() {
2957 network
= libs
.bitcoin
.networks
.ravencoin
;
2963 onSelect: function() {
2964 network
= libs
.bitcoin
.networks
.rubycoin
;
2969 name: "tRBTC - RSK Testnet",
2970 onSelect: function() {
2971 network
= libs
.bitcoin
.networks
.rubycoin
;
2976 name: "RBY - Rubycoin",
2977 onSelect: function() {
2978 network
= libs
.bitcoin
.networks
.rubycoin
;
2983 name: "RDD - Reddcoin",
2984 onSelect: function() {
2985 network
= libs
.bitcoin
.networks
.reddcoin
;
2990 name: "RVR - RevolutionVR",
2991 onSelect: function() {
2992 network
= libs
.bitcoin
.networks
.revolutionvr
;
2997 name: "SAFE - Safecoin",
2998 onSelect: function() {
2999 network
= libs
.bitcoin
.networks
.safecoin
;
3004 name: "SLS - Salus",
3005 onSelect: function() {
3006 network
= libs
.bitcoin
.networks
.salus
;
3011 name: "SDC - ShadowCash",
3012 onSelect: function() {
3013 network
= libs
.bitcoin
.networks
.shadow
;
3018 name: "SDC - ShadowCash Testnet",
3019 onSelect: function() {
3020 network
= libs
.bitcoin
.networks
.shadowtn
;
3025 name: "SLM - Slimcoin",
3026 onSelect: function() {
3027 network
= libs
.bitcoin
.networks
.slimcoin
;
3032 name: "SLM - Slimcoin Testnet",
3033 onSelect: function() {
3034 network
= libs
.bitcoin
.networks
.slimcointn
;
3039 name: "SLP - Simple Ledger Protocol",
3040 onSelect: function() {
3041 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
3046 name: "SLR - Solarcoin",
3047 onSelect: function() {
3048 network
= libs
.bitcoin
.networks
.solarcoin
;
3053 name: "SMLY - Smileycoin",
3054 onSelect: function() {
3055 network
= libs
.bitcoin
.networks
.smileycoin
;
3060 name: "STASH - Stash",
3061 onSelect: function() {
3062 network
= libs
.bitcoin
.networks
.stash
;
3067 name: "STASH - Stash Testnet",
3068 onSelect: function() {
3069 network
= libs
.bitcoin
.networks
.stashtn
;
3074 name: "STRAT - Stratis",
3075 onSelect: function() {
3076 network
= libs
.bitcoin
.networks
.stratis
;
3081 name: "TSTRAT - Stratis Testnet",
3082 onSelect: function() {
3083 network
= libs
.bitcoin
.networks
.stratistest
;
3088 name: "SYS - Syscoin",
3089 onSelect: function() {
3090 network
= libs
.bitcoin
.networks
.syscoin
;
3095 name: "THC - Hempcoin",
3096 onSelect: function() {
3097 network
= libs
.bitcoin
.networks
.hempcoin
;
3102 name: "THT - Thought",
3103 onSelect: function() {
3104 network
= libs
.bitcoin
.networks
.thought
;
3110 onSelect: function() {
3111 network
= libs
.bitcoin
.networks
.toa
;
3116 name: "TWINS - TWINS",
3117 onSelect: function() {
3118 network
= libs
.bitcoin
.networks
.twins
;
3123 name: "TWINS - TWINS Testnet",
3124 onSelect: function() {
3125 network
= libs
.bitcoin
.networks
.twinstestnet
;
3130 name: "USC - Ultimatesecurecash",
3131 onSelect: function() {
3132 network
= libs
.bitcoin
.networks
.ultimatesecurecash
;
3137 name: "USNBT - NuBits",
3138 onSelect: function() {
3139 network
= libs
.bitcoin
.networks
.nubits
;
3144 name: "UNO - Unobtanium",
3145 onSelect: function() {
3146 network
= libs
.bitcoin
.networks
.unobtanium
;
3151 name: "VASH - Vpncoin",
3152 onSelect: function() {
3153 network
= libs
.bitcoin
.networks
.vpncoin
;
3158 name: "VET - VeChain",
3159 onSelect: function() {
3160 network
= libs
.bitcoin
.networks
.bitcoin
;
3165 name: "VIA - Viacoin",
3166 onSelect: function() {
3167 network
= libs
.bitcoin
.networks
.viacoin
;
3172 name: "VIA - Viacoin Testnet",
3173 onSelect: function() {
3174 network
= libs
.bitcoin
.networks
.viacointestnet
;
3179 name: "VIVO - Vivo",
3180 onSelect: function() {
3181 network
= libs
.bitcoin
.networks
.vivo
;
3186 name: "VTC - Vertcoin",
3187 onSelect: function() {
3188 network
= libs
.bitcoin
.networks
.vertcoin
;
3193 name: "WGR - Wagerr",
3194 onSelect: function() {
3195 network
= libs
.bitcoin
.networks
.wagerr
;
3200 name: "WC - Wincoin",
3201 onSelect: function() {
3202 network
= libs
.bitcoin
.networks
.wincoin
;
3207 name: "XAX - Artax",
3208 onSelect: function() {
3209 network
= libs
.bitcoin
.networks
.artax
;
3214 name: "XBC - Bitcoinplus",
3215 onSelect: function() {
3216 network
= libs
.bitcoin
.networks
.bitcoinplus
;
3221 name: "XLM - Stellar",
3222 onSelect: function() {
3223 network
= libs
.stellarUtil
.dummyNetwork
;
3228 name: "XMY - Myriadcoin",
3229 onSelect: function() {
3230 network
= libs
.bitcoin
.networks
.myriadcoin
;
3235 name: "XRP - Ripple",
3236 onSelect: function() {
3237 network
= libs
.bitcoin
.networks
.bitcoin
;
3242 name: "XVC - Vcash",
3243 onSelect: function() {
3244 network
= libs
.bitcoin
.networks
.vcash
;
3249 name: "XVG - Verge",
3250 onSelect: function() {
3251 network
= libs
.bitcoin
.networks
.verge
;
3256 name: "XUEZ - Xuez",
3257 segwitAvailable: false,
3258 onSelect: function() {
3259 network
= libs
.bitcoin
.networks
.xuez
;
3264 name: "XWC - Whitecoin",
3265 onSelect: function() {
3266 network
= libs
.bitcoin
.networks
.whitecoin
;
3271 name: "XZC - Zcoin",
3272 onSelect: function() {
3273 network
= libs
.bitcoin
.networks
.zcoin
;
3278 name: "ZCL - Zclassic",
3279 onSelect: function() {
3280 network
= libs
.bitcoin
.networks
.zclassic
;
3285 name: "ZEC - Zcash",
3286 onSelect: function() {
3287 network
= libs
.bitcoin
.networks
.zcash
;
3292 name: "ZEN - Horizen",
3293 onSelect: function() {
3294 network
= libs
.bitcoin
.networks
.zencash
;
3302 name: "Bitcoin Core",
3303 onSelect: function() {
3304 DOM
.bip32path
.val("m/0'/0'");
3305 DOM
.hardenedAddresses
.prop('checked', true);
3309 name: "blockchain.info",
3310 onSelect: function() {
3311 DOM
.bip32path
.val("m/44'/0'/0'");
3312 DOM
.hardenedAddresses
.prop('checked', false);
3316 name: "MultiBit HD",
3317 onSelect: function() {
3318 DOM
.bip32path
.val("m/0'/0");
3319 DOM
.hardenedAddresses
.prop('checked', false);
3323 name: "Coinomi, Ledger",
3324 onSelect: function() {
3325 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3326 DOM
.hardenedAddresses
.prop('checked', false);
3331 // ELA - Elastos functions - begin
3332 function displayBip44InfoForELA() {
3337 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3338 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3340 // Calculate the account extended keys
3341 var accountXprv
= libs
.elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3342 var accountXpub
= libs
.elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3344 // Display the extended keys
3345 DOM
.bip44accountXprv
.val(accountXprv
);
3346 DOM
.bip44accountXpub
.val(accountXpub
);
3349 function displayBip32InfoForELA() {
3354 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3355 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3356 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3358 DOM
.extendedPrivKey
.val(libs
.elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3359 DOM
.extendedPubKey
.val(libs
.elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3361 // Display the addresses and privkeys
3362 clearAddressesList();
3363 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3364 displayAddresses(0, initialAddressCount
);
3367 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3372 var publicKey
= libs
.elastosjs
.getDerivedPublicKey(libs
.elastosjs
.getMasterPublicKey(seed
), change
, index
);
3374 privateKey: libs
.elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3375 publicKey: publicKey
,
3376 address: libs
.elastosjs
.getAddress(publicKey
.toString('hex'))
3379 // ELA - Elastos functions - end