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 privKeyBuffer
= keyPair
.d
.toBuffer(32);
1132 privkey
= privKeyBuffer
.toString('hex');
1133 var addressBuffer
= libs
.ethUtil
.privateToAddress(privKeyBuffer
);
1134 var hexAddress
= addressBuffer
.toString('hex');
1135 var checksumAddress
= libs
.ethUtil
.toChecksumAddress(hexAddress
);
1136 address
= libs
.ethUtil
.addHexPrefix(checksumAddress
);
1137 privkey
= libs
.ethUtil
.addHexPrefix(privkey
);
1138 pubkey
= libs
.ethUtil
.addHexPrefix(pubkey
);
1141 // Stellar is different
1142 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1143 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1144 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1146 path
+= purpose
+ "'/";
1147 path
+= coin
+ "'/" + index
+ "'";
1148 var keypair
= libs
.stellarUtil
.getKeypair(path
, seed
);
1150 privkey
= keypair
.secret();
1151 pubkey
= address
= keypair
.publicKey();
1153 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1154 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1155 var nebulasAccount
= libs
.nebulas
.Account
.NewAccount();
1156 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1157 address
= nebulasAccount
.getAddressString();
1158 privkey
= nebulasAccount
.getPrivateKeyString();
1159 pubkey
= nebulasAccount
.getPublicKeyString();
1161 // Ripple values are different
1162 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1163 privkey
= convertRipplePriv(privkey
);
1164 address
= convertRippleAdrr(address
);
1166 // CasinoCoin values are different
1167 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1168 privkey
= convertCasinoCoinPriv(privkey
);
1169 address
= convertCasinoCoinAdrr(address
);
1171 // Bitcoin Cash address format may vary
1172 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1173 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1174 if (bchAddrType
== "cashaddr") {
1175 address
= libs
.bchaddr
.toCashAddress(address
);
1177 else if (bchAddrType
== "bitpay") {
1178 address
= libs
.bchaddr
.toBitpayAddress(address
);
1181 // Bitcoin Cash address format may vary
1182 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1183 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1184 if (bchAddrType
== "cashaddr") {
1185 address
= libs
.bchaddrSlp
.toSlpAddress(address
);
1188 // Segwit addresses are different
1190 if (!segwitAvailable
) {
1194 var keyhash
= libs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1195 var scriptpubkey
= libs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1196 address
= libs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1198 else if (isP2wpkhInP2sh
) {
1199 var keyhash
= libs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1200 var scriptsig
= libs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1201 var addressbytes
= libs
.bitcoin
.crypto
.hash160(scriptsig
);
1202 var scriptpubkey
= libs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1203 address
= libs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1206 // https://github.com/libs.bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71
1208 var witnessScript
= libs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1209 var scriptPubKey
= libs
.bitcoin
.script
.witnessScriptHash
.output
.encode(libs
.bitcoin
.crypto
.sha256(witnessScript
));
1210 address
= libs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
);
1212 else if (isP2wshInP2sh
) {
1213 // https://github.com/libs.bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183
1215 var witnessScript
= libs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1216 var redeemScript
= libs
.bitcoin
.script
.witnessScriptHash
.output
.encode(libs
.bitcoin
.crypto
.sha256(witnessScript
));
1217 var scriptPubKey
= libs
.bitcoin
.script
.scriptHash
.output
.encode(libs
.bitcoin
.crypto
.hash160(redeemScript
));
1218 address
= libs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
)
1222 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1223 address
= libs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1226 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1228 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1229 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1232 //Groestlcoin Addresses are different
1236 if (!segwitAvailable
) {
1240 address
= libs
.groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1242 else if (isP2wpkhInP2sh
) {
1243 address
= libs
.groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1246 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1250 let elaAddress
= calcAddressForELA(
1252 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1253 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1254 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1257 address
= elaAddress
.address
;
1258 privkey
= elaAddress
.privateKey
;
1259 pubkey
= elaAddress
.publicKey
;
1262 addAddressToList(indexText
, address
, pubkey
, privkey
);
1274 function showMore() {
1275 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1276 if (isNaN(rowsToAdd
)) {
1278 DOM
.rowsToAdd
.val("20");
1280 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1282 start
= lastIndexInTable() + 1;
1285 var newStart
= start
+ rowsToAdd
;
1286 DOM
.moreRowsStartIndex
.val(newStart
);
1288 if (rowsToAdd
> 200) {
1289 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1290 msg
+= "Do you want to continue?";
1291 if (!confirm(msg
)) {
1295 displayAddresses(start
, rowsToAdd
);
1298 function clearDisplay() {
1299 clearAddressesList();
1301 hideValidationError();
1304 function clearAddressesList() {
1305 DOM
.addresses
.empty();
1310 function stopGenerating() {
1311 while (generationProcesses
.length
> 0) {
1312 var generation
= generationProcesses
.shift();
1317 function clearKeys() {
1322 function clearRootKey() {
1323 DOM
.rootKey
.val("");
1326 function clearDerivedKeys() {
1327 DOM
.extendedPrivKey
.val("");
1328 DOM
.extendedPubKey
.val("");
1329 DOM
.bip44accountXprv
.val("");
1330 DOM
.bip44accountXpub
.val("");
1333 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1334 var row
= $(addressRowTemplate
.html());
1336 var indexCell
= row
.find(".index span");
1337 var addressCell
= row
.find(".address span");
1338 var pubkeyCell
= row
.find(".pubkey span");
1339 var privkeyCell
= row
.find(".privkey span");
1341 indexCell
.text(indexText
);
1342 addressCell
.text(address
);
1343 pubkeyCell
.text(pubkey
);
1344 privkeyCell
.text(privkey
);
1347 indexCell
.addClass("invisible");
1350 addressCell
.addClass("invisible");
1353 pubkeyCell
.addClass("invisible");
1356 privkeyCell
.addClass("invisible");
1358 DOM
.addresses
.append(row
);
1359 var rowShowQrEls
= row
.find("[data-show-qr]");
1360 setQrEvents(rowShowQrEls
);
1363 function hasStrongRandom() {
1364 return 'crypto' in window
&& window
['crypto'] !== null;
1367 function disableForms() {
1368 $("form").on("submit", function(e
) {
1373 function parseIntNoNaN(val
, defaultVal
) {
1374 var v
= parseInt(val
);
1381 function showPending() {
1383 .text("Calculating...")
1387 function findNearestWord(word
) {
1388 var language
= getLanguage();
1389 var words
= WORDLISTS
[language
];
1390 var minDistance
= 99;
1391 var closestWord
= words
[0];
1392 for (var i
=0; i
<words
.length
; i
++) {
1393 var comparedTo
= words
[i
];
1394 if (comparedTo
.indexOf(word
) == 0) {
1397 var distance
= libs
.levenshtein
.get(word
, comparedTo
);
1398 if (distance
< minDistance
) {
1399 closestWord
= comparedTo
;
1400 minDistance
= distance
;
1406 function hidePending() {
1412 function populateNetworkSelect() {
1413 for (var i
=0; i
<networks
.length
; i
++) {
1414 var network
= networks
[i
];
1415 var option
= $("<option>");
1416 option
.attr("value", i
);
1417 option
.text(network
.name
);
1418 if (network
.name
== "BTC - Bitcoin") {
1419 option
.prop("selected", true);
1421 DOM
.phraseNetwork
.append(option
);
1425 function populateClientSelect() {
1426 for (var i
=0; i
<clients
.length
; i
++) {
1427 var client
= clients
[i
];
1428 var option
= $("<option>");
1429 option
.attr("value", i
);
1430 option
.text(client
.name
);
1431 DOM
.bip32Client
.append(option
);
1435 function getLanguage() {
1436 var defaultLanguage
= "english";
1437 // Try to get from existing phrase
1438 var language
= getLanguageFromPhrase();
1439 // Try to get from url if not from phrase
1440 if (language
.length
== 0) {
1441 language
= getLanguageFromUrl();
1443 // Default to English if no other option
1444 if (language
.length
== 0) {
1445 language
= defaultLanguage
;
1450 function getLanguageFromPhrase(phrase
) {
1451 // Check if how many words from existing phrase match a language.
1454 phrase
= DOM
.phrase
.val();
1456 if (phrase
.length
> 0) {
1457 var words
= phraseToWordArray(phrase
);
1458 var languageMatches
= {};
1459 for (l
in WORDLISTS
) {
1460 // Track how many words match in this language
1461 languageMatches
[l
] = 0;
1462 for (var i
=0; i
<words
.length
; i
++) {
1463 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1464 if (wordInLanguage
) {
1465 languageMatches
[l
]++;
1468 // Find languages with most word matches.
1469 // This is made difficult due to commonalities between Chinese
1470 // simplified vs traditional.
1471 var mostMatches
= 0;
1472 var mostMatchedLanguages
= [];
1473 for (var l
in languageMatches
) {
1474 var numMatches
= languageMatches
[l
];
1475 if (numMatches
> mostMatches
) {
1476 mostMatches
= numMatches
;
1477 mostMatchedLanguages
= [l
];
1479 else if (numMatches
== mostMatches
) {
1480 mostMatchedLanguages
.push(l
);
1484 if (mostMatchedLanguages
.length
> 0) {
1485 // Use first language and warn if multiple detected
1486 language
= mostMatchedLanguages
[0];
1487 if (mostMatchedLanguages
.length
> 1) {
1488 console
.warn("Multiple possible languages");
1489 console
.warn(mostMatchedLanguages
);
1496 function getLanguageFromUrl() {
1497 for (var language
in WORDLISTS
) {
1498 if (window
.location
.hash
.indexOf(language
) > -1) {
1505 function setMnemonicLanguage() {
1506 var language
= getLanguage();
1507 // Load the bip39 mnemonic generator for this language if required
1508 if (!(language
in mnemonics
)) {
1509 mnemonics
[language
] = new Mnemonic(language
);
1511 mnemonic
= mnemonics
[language
];
1514 function convertPhraseToNewLanguage() {
1515 var oldLanguage
= getLanguageFromPhrase();
1516 var newLanguage
= getLanguageFromUrl();
1517 var oldPhrase
= DOM
.phrase
.val();
1518 var oldWords
= phraseToWordArray(oldPhrase
);
1520 for (var i
=0; i
<oldWords
.length
; i
++) {
1521 var oldWord
= oldWords
[i
];
1522 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1523 var newWord
= WORDLISTS
[newLanguage
][index
];
1524 newWords
.push(newWord
);
1526 newPhrase
= wordArrayToPhrase(newWords
);
1530 // TODO look at jsbip39 - mnemonic.splitWords
1531 function phraseToWordArray(phrase
) {
1532 var words
= phrase
.split(/\s/g);
1534 for (var i
=0; i
<words
.length
; i
++) {
1535 var word
= words
[i
];
1536 if (word
.length
> 0) {
1537 noBlanks
.push(word
);
1543 // TODO look at jsbip39 - mnemonic.joinWords
1544 function wordArrayToPhrase(words
) {
1545 var phrase
= words
.join(" ");
1546 var language
= getLanguageFromPhrase(phrase
);
1547 if (language
== "japanese") {
1548 phrase
= words
.join("\u3000");
1553 function writeSplitPhrase(phrase
) {
1554 var wordCount
= phrase
.split(/\s/g).length
;
1556 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1557 var group
=[[],[],[]],
1559 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1560 while (left
.length
>0) {
1561 groupI
=(groupI
+1)%3;
1562 seed
= seed
* 16807 % 2147483647;
1563 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1564 group
[groupI
].push(left
[selected
]);
1565 left
.splice(selected
,1);
1567 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1568 for (var i
=0;i
<3;i
++) {
1569 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1570 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1572 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1573 var triesPerSecond
=10000000000;
1574 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1575 var displayRedText
= false;
1577 hackTime
="<1 second";
1578 displayRedText
= true;
1579 } else if (hackTime
<86400) {
1580 hackTime
=Math
.floor(hackTime
)+" seconds";
1581 displayRedText
= true;
1582 } else if(hackTime
<31557600) {
1583 hackTime
=Math
.floor(hackTime
/86400)+" days";
1584 displayRedText
= true;
1586 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1588 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1589 if (displayRedText
) {
1590 DOM
.phraseSplitWarn
.addClass("text-danger");
1592 DOM
.phraseSplitWarn
.removeClass("text-danger");
1596 function isUsingOwnEntropy() {
1597 return DOM
.useEntropy
.prop("checked");
1600 function setMnemonicFromEntropy() {
1601 clearEntropyFeedback();
1602 // Get entropy value
1603 var entropyStr
= DOM
.entropy
.val();
1604 // Work out minimum base for entropy
1606 if (entropyTypeAutoDetect
) {
1607 entropy
= Entropy
.fromString(entropyStr
);
1610 let base
= DOM
.entropyTypeInputs
.filter(":checked").val();
1611 entropy
= Entropy
.fromString(entropyStr
, base
);
1613 if (entropy
.binaryStr
.length
== 0) {
1616 // Show entropy details
1617 showEntropyFeedback(entropy
);
1618 // Use entropy hash if not using raw entropy
1619 var bits
= entropy
.binaryStr
;
1620 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1621 if (mnemonicLength
!= "raw") {
1622 // Get bits by hashing entropy with SHA256
1623 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1624 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1625 bits
= libs
.BigInteger
.BigInteger
.parse(hex
, 16).toString(2);
1626 while (bits
.length
% 256 != 0) {
1629 // Truncate hash to suit number of words
1630 mnemonicLength
= parseInt(mnemonicLength
);
1631 var numberOfBits
= 32 * mnemonicLength
/ 3;
1632 bits
= bits
.substring(0, numberOfBits
);
1633 // show warning for weak entropy override
1634 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1635 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1638 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1642 // hide warning for weak entropy override
1643 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1645 // Discard trailing entropy
1646 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1647 var start
= bits
.length
- bitsToUse
;
1648 var binaryStr
= bits
.substring(start
);
1649 // Convert entropy string to numeric array
1650 var entropyArr
= [];
1651 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1652 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1653 var entropyByte
= parseInt(byteAsBits
, 2);
1654 entropyArr
.push(entropyByte
)
1656 // Convert entropy array to mnemonic
1657 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1658 // Set the mnemonic in the UI
1659 DOM
.phrase
.val(phrase
);
1660 writeSplitPhrase(phrase
);
1661 // Show the word indexes
1663 // Show the checksum
1667 function clearEntropyFeedback() {
1668 DOM
.entropyCrackTime
.text("...");
1669 DOM
.entropyType
.text("");
1670 DOM
.entropyWordCount
.text("0");
1671 DOM
.entropyEventCount
.text("0");
1672 DOM
.entropyBitsPerEvent
.text("0");
1673 DOM
.entropyBits
.text("0");
1674 DOM
.entropyFiltered
.html(" ");
1675 DOM
.entropyBinary
.html(" ");
1678 function showEntropyFeedback(entropy
) {
1679 var numberOfBits
= entropy
.binaryStr
.length
;
1680 var timeToCrack
= "unknown";
1682 var z
= libs
.zxcvbn(entropy
.base
.parts
.join(""));
1683 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1684 if (z
.feedback
.warning
!= "") {
1685 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1689 console
.log("Error detecting entropy strength with zxcvbn:");
1692 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1693 DOM
.entropyTypeInputs
.attr("checked", false);
1694 DOM
.entropyTypeInputs
.filter("[value='" + entropyTypeStr
+ "']").attr("checked", true);
1695 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1696 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1697 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1698 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1699 DOM
.entropyType
.text(entropyTypeStr
);
1700 DOM
.entropyCrackTime
.text(timeToCrack
);
1701 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1702 DOM
.entropyBits
.text(numberOfBits
);
1703 DOM
.entropyWordCount
.text(wordCount
);
1704 DOM
.entropyBinary
.text(spacedBinaryStr
);
1705 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1706 // detect and warn of filtering
1707 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1708 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1709 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1711 DOM
.entropyFilterWarning
.removeClass('hidden');
1714 DOM
.entropyFilterWarning
.addClass('hidden');
1718 function getEntropyTypeStr(entropy
) {
1719 var typeStr
= entropy
.base
.str
;
1720 // Add some detail if these are cards
1721 if (entropy
.base
.asInt
== 52) {
1722 var cardDetail
= []; // array of message strings
1723 // Detect duplicates
1725 var dupeTracker
= {};
1726 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1727 var card
= entropy
.base
.parts
[i
];
1728 var cardUpper
= card
.toUpperCase();
1729 if (cardUpper
in dupeTracker
) {
1732 dupeTracker
[cardUpper
] = true;
1734 if (dupes
.length
> 0) {
1735 var dupeWord
= "duplicates";
1736 if (dupes
.length
== 1) {
1737 dupeWord
= "duplicate";
1739 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1740 if (dupes
.length
> 3) {
1743 cardDetail
.push(msg
);
1746 var uniqueCards
= [];
1747 for (var uniqueCard
in dupeTracker
) {
1748 uniqueCards
.push(uniqueCard
);
1750 if (uniqueCards
.length
== 52) {
1751 cardDetail
.unshift("full deck");
1753 // Detect missing cards
1754 var values
= "A23456789TJQK";
1756 var missingCards
= [];
1757 for (var i
=0; i
<suits
.length
; i
++) {
1758 for (var j
=0; j
<values
.length
; j
++) {
1759 var card
= values
[j
] + suits
[i
];
1760 if (!(card
in dupeTracker
)) {
1761 missingCards
.push(card
);
1765 // Display missing cards if six or less, ie clearly going for full deck
1766 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1767 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1768 if (missingCards
.length
> 3) {
1771 cardDetail
.push(msg
);
1773 // Add card details to typeStr
1774 if (cardDetail
.length
> 0) {
1775 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1781 function setQrEvents(els
) {
1782 els
.on("mouseenter", createQr
);
1783 els
.on("mouseleave", destroyQr
);
1784 els
.on("click", toggleQr
);
1787 function createQr(e
) {
1788 var content
= e
.target
.textContent
|| e
.target
.value
;
1790 var qrEl
= libs
.kjua({
1796 DOM
.qrImage
.append(qrEl
);
1798 DOM
.qrHider
.addClass("hidden");
1801 DOM
.qrHider
.removeClass("hidden");
1803 DOM
.qrContainer
.removeClass("hidden");
1807 function destroyQr() {
1808 DOM
.qrImage
.text("");
1809 DOM
.qrContainer
.addClass("hidden");
1812 function toggleQr() {
1814 DOM
.qrHider
.toggleClass("hidden");
1815 DOM
.qrHint
.toggleClass("hidden");
1818 function bip44TabSelected() {
1819 return DOM
.bip44tab
.hasClass("active");
1822 function bip32TabSelected() {
1823 return DOM
.bip32tab
.hasClass("active");
1826 function networkIsEthereum() {
1827 var name
= networks
[DOM
.network
.val()].name
;
1828 return (name
== "ETH - Ethereum")
1829 || (name
== "ETC - Ethereum Classic")
1830 || (name
== "EWT - EnergyWeb")
1831 || (name
== "PIRL - Pirl")
1832 || (name
== "MIX - MIX")
1833 || (name
== "MUSIC - Musicoin")
1834 || (name
== "POA - Poa")
1835 || (name
== "EXP - Expanse")
1836 || (name
== "CLO - Callisto")
1837 || (name
== "DXN - DEXON")
1838 || (name
== "ELLA - Ellaism")
1839 || (name
== "ESN - Ethersocial Network")
1840 || (name
== "VET - VeChain")
1843 function networkHasSegwit() {
1845 if ("baseNetwork" in network
) {
1846 n
= libs
.bitcoin
.networks
[network
.baseNetwork
];
1848 // check if only p2wpkh params are required
1849 if (p2wpkhSelected()) {
1850 return "p2wpkh" in n
;
1852 // check if only p2wpkh-in-p2sh params are required
1853 else if (p2wpkhInP2shSelected()) {
1854 return "p2wpkhInP2sh" in n
;
1856 // require both if it's unclear which params are required
1857 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1860 function bip49TabSelected() {
1861 return DOM
.bip49tab
.hasClass("active");
1864 function bip84TabSelected() {
1865 return DOM
.bip84tab
.hasClass("active");
1868 function bip141TabSelected() {
1869 return DOM
.bip141tab
.hasClass("active");
1872 function setHdCoin(coinValue
) {
1873 DOM
.bip44coin
.val(coinValue
);
1874 DOM
.bip49coin
.val(coinValue
);
1875 DOM
.bip84coin
.val(coinValue
);
1878 function showSegwitAvailable() {
1879 DOM
.bip49unavailable
.addClass("hidden");
1880 DOM
.bip49available
.removeClass("hidden");
1881 DOM
.bip84unavailable
.addClass("hidden");
1882 DOM
.bip84available
.removeClass("hidden");
1883 DOM
.bip141unavailable
.addClass("hidden");
1884 DOM
.bip141available
.removeClass("hidden");
1887 function showSegwitUnavailable() {
1888 DOM
.bip49available
.addClass("hidden");
1889 DOM
.bip49unavailable
.removeClass("hidden");
1890 DOM
.bip84available
.addClass("hidden");
1891 DOM
.bip84unavailable
.removeClass("hidden");
1892 DOM
.bip141available
.addClass("hidden");
1893 DOM
.bip141unavailable
.removeClass("hidden");
1896 function adjustNetworkForSegwit() {
1897 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1898 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1900 // See https://github.com/iancoleman/bip39/issues/125
1901 var segwitNetworks
= null;
1902 // if a segwit network is alread selected, need to use base network to
1903 // look up new parameters
1904 if ("baseNetwork" in network
) {
1905 network
= libs
.bitcoin
.networks
[network
.baseNetwork
];
1907 // choose the right segwit params
1908 if (p2wpkhSelected() && "p2wpkh" in network
) {
1909 network
= network
.p2wpkh
;
1911 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1912 network
= network
.p2wpkhInP2sh
;
1914 else if (p2wshSelected() && "p2wsh" in network
) {
1915 network
= network
.p2wsh
;
1917 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network
) {
1918 network
= network
.p2wshInP2sh
;
1922 function lastIndexInTable() {
1923 var pathText
= DOM
.addresses
.find(".index").last().text();
1924 var pathBits
= pathText
.split("/");
1925 var lastBit
= pathBits
[pathBits
.length
-1];
1926 var lastBitClean
= lastBit
.replace("'", "");
1927 return parseInt(lastBitClean
);
1930 function uint8ArrayToHex(a
) {
1932 for (var i
=0; i
<a
.length
; i
++) {
1933 var h
= a
[i
].toString(16);
1934 while (h
.length
< 2) {
1942 function showWordIndexes() {
1943 var phrase
= DOM
.phrase
.val();
1944 var words
= phraseToWordArray(phrase
);
1945 var wordIndexes
= [];
1946 var language
= getLanguage();
1947 for (var i
=0; i
<words
.length
; i
++) {
1948 var word
= words
[i
];
1949 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1950 wordIndexes
.push(wordIndex
);
1952 var wordIndexesStr
= wordIndexes
.join(", ");
1953 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1956 function showChecksum() {
1957 var phrase
= DOM
.phrase
.val();
1958 var words
= phraseToWordArray(phrase
);
1959 var checksumBitlength
= words
.length
/ 3;
1962 var language
= getLanguage();
1963 for (var i
=words
.length
-1; i
>=0; i
--) {
1964 var word
= words
[i
];
1965 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1966 var wordBinary
= wordIndex
.toString(2);
1967 while (wordBinary
.length
< 11) {
1968 wordBinary
= "0" + wordBinary
;
1970 var binaryStr
= wordBinary
+ binaryStr
;
1971 if (binaryStr
.length
>= checksumBitlength
) {
1972 var start
= binaryStr
.length
- checksumBitlength
;
1973 var end
= binaryStr
.length
;
1974 checksum
= binaryStr
.substring(start
, end
);
1975 // add spaces so the last group is 11 bits, not the first
1976 checksum
= checksum
.split("").reverse().join("")
1977 checksum
= addSpacesEveryElevenBits(checksum
);
1978 checksum
= checksum
.split("").reverse().join("")
1982 DOM
.entropyChecksum
.text(checksum
);
1985 function updateCsv() {
1986 var tableCsv
= "path,address,public key,private key\n";
1987 var rows
= DOM
.addresses
.find("tr");
1988 for (var i
=0; i
<rows
.length
; i
++) {
1989 var row
= $(rows
[i
]);
1990 var cells
= row
.find("td");
1991 for (var j
=0; j
<cells
.length
; j
++) {
1992 var cell
= $(cells
[j
]);
1993 if (!cell
.children().hasClass("invisible")) {
1994 tableCsv
= tableCsv
+ cell
.text();
1996 if (j
!= cells
.length
- 1) {
1997 tableCsv
= tableCsv
+ ",";
2000 tableCsv
= tableCsv
+ "\n";
2002 DOM
.csv
.val(tableCsv
);
2005 function addSpacesEveryElevenBits(binaryStr
) {
2006 return binaryStr
.match(/.{1,11}/g).join(" ");
2011 name: "AC - Asiacoin",
2012 onSelect: function() {
2013 network
= libs
.bitcoin
.networks
.asiacoin
;
2018 name: "ACC - Adcoin",
2019 onSelect: function() {
2020 network
= libs
.bitcoin
.networks
.adcoin
;
2025 name: "ARYA - Aryacoin",
2026 onSelect: function() {
2027 network
= libs
.bitcoin
.networks
.aryacoin
;
2032 name: "AUR - Auroracoin",
2033 onSelect: function() {
2034 network
= libs
.bitcoin
.networks
.auroracoin
;
2040 onSelect: function() {
2041 network
= libs
.bitcoin
.networks
.axe
;
2046 name: "ANON - ANON",
2047 onSelect: function() {
2048 network
= libs
.bitcoin
.networks
.anon
;
2053 name: "BOLI - Bolivarcoin",
2054 onSelect: function() {
2055 network
= libs
.bitcoin
.networks
.bolivarcoin
;
2060 name: "BCA - Bitcoin Atom",
2061 onSelect: function() {
2062 network
= libs
.bitcoin
.networks
.atom
;
2067 name: "BCH - Bitcoin Cash",
2068 onSelect: function() {
2069 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2074 name: "BEET - Beetlecoin",
2075 onSelect: function() {
2076 network
= libs
.bitcoin
.networks
.beetlecoin
;
2081 name: "BELA - Belacoin",
2082 onSelect: function() {
2083 network
= libs
.bitcoin
.networks
.belacoin
;
2088 name: "BLK - BlackCoin",
2089 onSelect: function() {
2090 network
= libs
.bitcoin
.networks
.blackcoin
;
2095 name: "BND - Blocknode",
2096 onSelect: function() {
2097 network
= libs
.bitcoin
.networks
.blocknode
;
2102 name: "tBND - Blocknode Testnet",
2103 onSelect: function() {
2104 network
= libs
.bitcoin
.networks
.blocknode_testnet
;
2109 name: "BRIT - Britcoin",
2110 onSelect: function() {
2111 network
= libs
.bitcoin
.networks
.britcoin
;
2116 name: "BSD - Bitsend",
2117 onSelect: function() {
2118 network
= libs
.bitcoin
.networks
.bitsend
;
2123 name: "BST - BlockStamp",
2124 onSelect: function() {
2125 network
= libs
.bitcoin
.networks
.blockstamp
;
2131 onSelect: function() {
2132 network
= libs
.bitcoin
.networks
.bata
;
2137 name: "BTC - Bitcoin",
2138 onSelect: function() {
2139 network
= libs
.bitcoin
.networks
.bitcoin
;
2144 name: "BTC - Bitcoin RegTest",
2145 onSelect: function() {
2146 network
= libs
.bitcoin
.networks
.regtest
;
2147 // Using hd coin value 1 based on bip44_coin_type
2148 // https://github.com/chaintope/bitcoinrb/blob/f1014406f6b8f9b4edcecedc18df70c80df06f11/lib/bitcoin/chainparams/regtest.yml
2153 name: "BTC - Bitcoin Testnet",
2154 onSelect: function() {
2155 network
= libs
.bitcoin
.networks
.testnet
;
2160 name: "BITG - Bitcoin Green",
2161 onSelect: function() {
2162 network
= libs
.bitcoin
.networks
.bitcoingreen
;
2167 name: "BTCP - Bitcoin Private",
2168 onSelect: function() {
2169 network
= libs
.bitcoin
.networks
.bitcoinprivate
;
2174 name: "BSV - BitcoinSV",
2175 onSelect: function() {
2176 network
= libs
.bitcoin
.networks
.bitcoinsv
;
2181 name: "BTCZ - Bitcoinz",
2182 onSelect: function() {
2183 network
= libs
.bitcoin
.networks
.bitcoinz
;
2188 name: "BTDX - BitCloud",
2189 onSelect: function() {
2190 network
= libs
.bitcoin
.networks
.bitcloud
;
2195 name: "BTG - Bitcoin Gold",
2196 onSelect: function() {
2197 network
= libs
.bitcoin
.networks
.bgold
;
2202 name: "BTX - Bitcore",
2203 onSelect: function() {
2204 network
= libs
.bitcoin
.networks
.bitcore
;
2209 name: "CCN - Cannacoin",
2210 onSelect: function() {
2211 network
= libs
.bitcoin
.networks
.cannacoin
;
2216 name: "CESC - Cryptoescudo",
2217 onSelect: function() {
2218 network
= libs
.bitcoin
.networks
.cannacoin
;
2223 name: "CDN - Canadaecoin",
2224 onSelect: function() {
2225 network
= libs
.bitcoin
.networks
.canadaecoin
;
2230 name: "CLAM - Clams",
2231 onSelect: function() {
2232 network
= libs
.bitcoin
.networks
.clam
;
2237 name: "CLO - Callisto",
2238 segwitAvailable: false,
2239 onSelect: function() {
2240 network
= libs
.bitcoin
.networks
.bitcoin
;
2245 name: "CLUB - Clubcoin",
2246 onSelect: function() {
2247 network
= libs
.bitcoin
.networks
.clubcoin
;
2252 name: "CMP - Compcoin",
2253 onSelect: function() {
2254 network
= libs
.bitcoin
.networks
.compcoin
;
2259 name: "CPU - CPUchain",
2260 onSelect: function() {
2261 network
= libs
.bitcoin
.networks
.cpuchain
;
2266 name: "CRAVE - Crave",
2267 onSelect: function() {
2268 network
= libs
.bitcoin
.networks
.crave
;
2273 name: "CRW - Crown (Legacy)",
2274 onSelect: function() {
2275 network
= libs
.bitcoin
.networks
.crown
;
2280 name: "CRW - Crown",
2281 onSelect: function() {
2282 network
= libs
.bitcoin
.networks
.crown
;
2287 name: "CSC - CasinoCoin",
2288 onSelect: function() {
2289 network
= libs
.bitcoin
.networks
.bitcoin
;
2294 name: "DASH - Dash",
2295 onSelect: function() {
2296 network
= libs
.bitcoin
.networks
.dash
;
2301 name: "DASH - Dash Testnet",
2302 onSelect: function() {
2303 network
= libs
.bitcoin
.networks
.dashtn
;
2308 name: "DFC - Defcoin",
2309 onSelect: function() {
2310 network
= libs
.bitcoin
.networks
.defcoin
;
2315 name: "DGB - Digibyte",
2316 onSelect: function() {
2317 network
= libs
.bitcoin
.networks
.digibyte
;
2322 name: "DGC - Digitalcoin",
2323 onSelect: function() {
2324 network
= libs
.bitcoin
.networks
.digitalcoin
;
2329 name: "DMD - Diamond",
2330 onSelect: function() {
2331 network
= libs
.bitcoin
.networks
.diamond
;
2336 name: "DNR - Denarius",
2337 onSelect: function() {
2338 network
= libs
.bitcoin
.networks
.denarius
;
2343 name: "DOGE - Dogecoin",
2344 onSelect: function() {
2345 network
= libs
.bitcoin
.networks
.dogecoin
;
2350 name: "DOGEt - Dogecoin Testnet",
2351 onSelect: function() {
2352 network
= libs
.bitcoin
.networks
.dogecointestnet
;
2357 name: "DXN - DEXON",
2358 onSelect: function() {
2359 network
= libs
.bitcoin
.networks
.bitcoin
;
2364 name: "ECN - Ecoin",
2365 onSelect: function() {
2366 network
= libs
.bitcoin
.networks
.ecoin
;
2371 name: "EDRC - Edrcoin",
2372 onSelect: function() {
2373 network
= libs
.bitcoin
.networks
.edrcoin
;
2378 name: "EFL - Egulden",
2379 onSelect: function() {
2380 network
= libs
.bitcoin
.networks
.egulden
;
2385 name: "ELA - Elastos",
2386 onSelect: function () {
2387 network
= libs
.bitcoin
.networks
.elastos
;
2392 name: "ELLA - Ellaism",
2393 segwitAvailable: false,
2394 onSelect: function() {
2395 network
= libs
.bitcoin
.networks
.bitcoin
;
2400 name: "EMC2 - Einsteinium",
2401 onSelect: function() {
2402 network
= libs
.bitcoin
.networks
.einsteinium
;
2407 name: "ERC - Europecoin",
2408 onSelect: function() {
2409 network
= libs
.bitcoin
.networks
.europecoin
;
2414 name: "EOS - EOSIO",
2415 onSelect: function() {
2416 network
= libs
.bitcoin
.networks
.bitcoin
;
2421 name: "ESN - Ethersocial Network",
2422 segwitAvailable: false,
2423 onSelect: function() {
2424 network
= libs
.bitcoin
.networks
.bitcoin
;
2429 name: "ETC - Ethereum Classic",
2430 segwitAvailable: false,
2431 onSelect: function() {
2432 network
= libs
.bitcoin
.networks
.bitcoin
;
2437 name: "ETH - Ethereum",
2438 onSelect: function() {
2439 network
= libs
.bitcoin
.networks
.bitcoin
;
2444 name: "EWT - EnergyWeb",
2445 onSelect: function() {
2446 network
= libs
.bitcoin
.networks
.bitcoin
;
2451 name: "EXCL - Exclusivecoin",
2452 onSelect: function() {
2453 network
= libs
.bitcoin
.networks
.exclusivecoin
;
2458 name: "EXCC - ExchangeCoin",
2459 onSelect: function() {
2460 network
= libs
.bitcoin
.networks
.exchangecoin
;
2465 name: "EXP - Expanse",
2466 segwitAvailable: false,
2467 onSelect: function() {
2468 network
= libs
.bitcoin
.networks
.bitcoin
;
2474 onSelect: function() {
2475 network
= libs
.bitcoin
.networks
.fix
;
2480 name: "FIX - FIX Testnet",
2481 onSelect: function() {
2482 network
= libs
.bitcoin
.networks
.fixtestnet
;
2487 name: "FJC - Fujicoin",
2488 onSelect: function() {
2489 network
= libs
.bitcoin
.networks
.fujicoin
;
2494 name: "FLASH - Flashcoin",
2495 onSelect: function() {
2496 network
= libs
.bitcoin
.networks
.flashcoin
;
2501 name: "FRST - Firstcoin",
2502 onSelect: function() {
2503 network
= libs
.bitcoin
.networks
.firstcoin
;
2508 name: "FTC - Feathercoin",
2509 onSelect: function() {
2510 network
= libs
.bitcoin
.networks
.feathercoin
;
2515 name: "GAME - GameCredits",
2516 onSelect: function() {
2517 network
= libs
.bitcoin
.networks
.game
;
2522 name: "GBX - Gobyte",
2523 onSelect: function() {
2524 network
= libs
.bitcoin
.networks
.gobyte
;
2529 name: "GCR - GCRCoin",
2530 onSelect: function() {
2531 network
= libs
.bitcoin
.networks
.gcr
;
2536 name: "GRC - Gridcoin",
2537 onSelect: function() {
2538 network
= libs
.bitcoin
.networks
.gridcoin
;
2543 name: "GRS - Groestlcoin",
2544 onSelect: function() {
2545 network
= libs
.bitcoin
.networks
.groestlcoin
;
2550 name: "GRS - Groestlcoin Testnet",
2551 onSelect: function() {
2552 network
= libs
.bitcoin
.networks
.groestlcointestnet
;
2557 name: "HNC - Helleniccoin",
2558 onSelect: function() {
2559 network
= libs
.bitcoin
.networks
.helleniccoin
;
2564 name: "HUSH - Hush (Legacy)",
2565 onSelect: function() {
2566 network
= libs
.bitcoin
.networks
.hush
;
2571 name: "HUSH - Hush3",
2572 onSelect: function() {
2573 network
= libs
.bitcoin
.networks
.hush3
;
2578 name: "INSN - Insane",
2579 onSelect: function() {
2580 network
= libs
.bitcoin
.networks
.insane
;
2586 onSelect: function() {
2587 network
= libs
.bitcoin
.networks
.iop
;
2592 name: "IXC - Ixcoin",
2593 onSelect: function() {
2594 network
= libs
.bitcoin
.networks
.ixcoin
;
2599 name: "JBS - Jumbucks",
2600 onSelect: function() {
2601 network
= libs
.bitcoin
.networks
.jumbucks
;
2606 name: "KMD - Komodo",
2607 bip49available: false,
2608 onSelect: function() {
2609 network
= libs
.bitcoin
.networks
.komodo
;
2614 name: "KOBO - Kobocoin",
2615 bip49available: false,
2616 onSelect: function() {
2617 network
= libs
.bitcoin
.networks
.kobocoin
;
2622 name: "LBC - Library Credits",
2623 onSelect: function() {
2624 network
= libs
.bitcoin
.networks
.lbry
;
2629 name: "LCC - Litecoincash",
2630 onSelect: function() {
2631 network
= libs
.bitcoin
.networks
.litecoincash
;
2636 name: "LDCN - Landcoin",
2637 onSelect: function() {
2638 network
= libs
.bitcoin
.networks
.landcoin
;
2643 name: "LINX - Linx",
2644 onSelect: function() {
2645 network
= libs
.bitcoin
.networks
.linx
;
2650 name: "LKR - Lkrcoin",
2651 segwitAvailable: false,
2652 onSelect: function() {
2653 network
= libs
.bitcoin
.networks
.lkrcoin
;
2658 name: "LTC - Litecoin",
2659 onSelect: function() {
2660 network
= libs
.bitcoin
.networks
.litecoin
;
2662 DOM
.litecoinLtubContainer
.removeClass("hidden");
2666 name: "LTCt - Litecoin Testnet",
2667 onSelect: function() {
2668 network
= libs
.bitcoin
.networks
.litecointestnet
;
2670 DOM
.litecoinLtubContainer
.removeClass("hidden");
2674 name: "LTZ - LitecoinZ",
2675 onSelect: function() {
2676 network
= libs
.bitcoin
.networks
.litecoinz
;
2681 name: "LYNX - Lynx",
2682 onSelect: function() {
2683 network
= libs
.bitcoin
.networks
.lynx
;
2688 name: "MAZA - Maza",
2689 onSelect: function() {
2690 network
= libs
.bitcoin
.networks
.maza
;
2695 name: "MEC - Megacoin",
2696 onSelect: function() {
2697 network
= libs
.bitcoin
.networks
.megacoin
;
2703 segwitAvailable: false,
2704 onSelect: function() {
2705 network
= libs
.bitcoin
.networks
.bitcoin
;
2710 name: "MNX - Minexcoin",
2711 onSelect: function() {
2712 network
= libs
.bitcoin
.networks
.minexcoin
;
2717 name: "MONA - Monacoin",
2718 onSelect: function() {
2719 network
= libs
.bitcoin
.networks
.monacoin
,
2724 name: "MONK - Monkey Project",
2725 onSelect: function() {
2726 network
= libs
.bitcoin
.networks
.monkeyproject
,
2731 name: "MUSIC - Musicoin",
2732 segwitAvailable: false,
2733 onSelect: function() {
2734 network
= libs
.bitcoin
.networks
.bitcoin
;
2739 name: "NAV - Navcoin",
2740 onSelect: function() {
2741 network
= libs
.bitcoin
.networks
.navcoin
;
2746 name: "NAS - Nebulas",
2747 onSelect: function() {
2748 network
= libs
.bitcoin
.networks
.bitcoin
;
2753 name: "NEBL - Neblio",
2754 onSelect: function() {
2755 network
= libs
.bitcoin
.networks
.neblio
;
2760 name: "NEOS - Neoscoin",
2761 onSelect: function() {
2762 network
= libs
.bitcoin
.networks
.neoscoin
;
2767 name: "NIX - NIX Platform",
2768 onSelect: function() {
2769 network
= libs
.bitcoin
.networks
.nix
;
2774 name: "NLG - Gulden",
2775 onSelect: function() {
2776 network
= libs
.bitcoin
.networks
.gulden
;
2781 name: "NMC - Namecoin",
2782 onSelect: function() {
2783 network
= libs
.bitcoin
.networks
.namecoin
;
2788 name: "NRG - Energi",
2789 onSelect: function() {
2790 network
= libs
.bitcoin
.networks
.energi
;
2795 name: "NRO - Neurocoin",
2796 onSelect: function() {
2797 network
= libs
.bitcoin
.networks
.neurocoin
;
2802 name: "NSR - Nushares",
2803 onSelect: function() {
2804 network
= libs
.bitcoin
.networks
.nushares
;
2809 name: "NYC - Newyorkc",
2810 onSelect: function() {
2811 network
= libs
.bitcoin
.networks
.newyorkc
;
2816 name: "NVC - Novacoin",
2817 onSelect: function() {
2818 network
= libs
.bitcoin
.networks
.novacoin
;
2823 name: "OK - Okcash",
2824 onSelect: function() {
2825 network
= libs
.bitcoin
.networks
.okcash
;
2830 name: "OMNI - Omnicore",
2831 onSelect: function() {
2832 network
= libs
.bitcoin
.networks
.omnicore
;
2837 name: "ONION - DeepOnion",
2838 onSelect: function() {
2839 network
= libs
.bitcoin
.networks
.deeponion
;
2844 name: "ONX - Onixcoin",
2845 onSelect: function() {
2846 network
= libs
.bitcoin
.networks
.onixcoin
;
2851 name: "PHR - Phore",
2852 onSelect: function() {
2853 network
= libs
.bitcoin
.networks
.phore
;
2858 name: "PINK - Pinkcoin",
2859 onSelect: function() {
2860 network
= libs
.bitcoin
.networks
.pinkcoin
;
2865 name: "PIRL - Pirl",
2866 segwitAvailable: false,
2867 onSelect: function() {
2868 network
= libs
.bitcoin
.networks
.bitcoin
;
2873 name: "PIVX - PIVX",
2874 onSelect: function() {
2875 network
= libs
.bitcoin
.networks
.pivx
;
2880 name: "PIVX - PIVX Testnet",
2881 onSelect: function() {
2882 network
= libs
.bitcoin
.networks
.pivxtestnet
;
2888 segwitAvailable: false,
2889 onSelect: function() {
2890 network
= libs
.bitcoin
.networks
.bitcoin
;
2895 name: "POSW - POSWcoin",
2896 onSelect: function() {
2897 network
= libs
.bitcoin
.networks
.poswcoin
;
2902 name: "POT - Potcoin",
2903 onSelect: function() {
2904 network
= libs
.bitcoin
.networks
.potcoin
;
2909 name: "PPC - Peercoin",
2910 onSelect: function() {
2911 network
= libs
.bitcoin
.networks
.peercoin
;
2916 name: "PRJ - ProjectCoin",
2917 onSelect: function() {
2918 network
= libs
.bitcoin
.networks
.projectcoin
;
2923 name: "PSB - Pesobit",
2924 onSelect: function() {
2925 network
= libs
.bitcoin
.networks
.pesobit
;
2930 name: "PUT - Putincoin",
2931 onSelect: function() {
2932 network
= libs
.bitcoin
.networks
.putincoin
;
2937 name: "RPD - Rapids",
2938 onSelect: function() {
2939 network
= libs
.bitcoin
.networks
.rapids
;
2944 name: "RVN - Ravencoin",
2945 onSelect: function() {
2946 network
= libs
.bitcoin
.networks
.ravencoin
;
2951 name: "RBY - Rubycoin",
2952 onSelect: function() {
2953 network
= libs
.bitcoin
.networks
.rubycoin
;
2958 name: "RDD - Reddcoin",
2959 onSelect: function() {
2960 network
= libs
.bitcoin
.networks
.reddcoin
;
2965 name: "RVR - RevolutionVR",
2966 onSelect: function() {
2967 network
= libs
.bitcoin
.networks
.revolutionvr
;
2972 name: "SAFE - Safecoin",
2973 onSelect: function() {
2974 network
= libs
.bitcoin
.networks
.safecoin
;
2979 name: "SLS - Salus",
2980 onSelect: function() {
2981 network
= libs
.bitcoin
.networks
.salus
;
2986 name: "SDC - ShadowCash",
2987 onSelect: function() {
2988 network
= libs
.bitcoin
.networks
.shadow
;
2993 name: "SDC - ShadowCash Testnet",
2994 onSelect: function() {
2995 network
= libs
.bitcoin
.networks
.shadowtn
;
3000 name: "SLM - Slimcoin",
3001 onSelect: function() {
3002 network
= libs
.bitcoin
.networks
.slimcoin
;
3007 name: "SLM - Slimcoin Testnet",
3008 onSelect: function() {
3009 network
= libs
.bitcoin
.networks
.slimcointn
;
3014 name: "SLP - Simple Ledger Protocol",
3015 onSelect: function() {
3016 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
3021 name: "SLR - Solarcoin",
3022 onSelect: function() {
3023 network
= libs
.bitcoin
.networks
.solarcoin
;
3028 name: "SMLY - Smileycoin",
3029 onSelect: function() {
3030 network
= libs
.bitcoin
.networks
.smileycoin
;
3035 name: "STASH - Stash",
3036 onSelect: function() {
3037 network
= libs
.bitcoin
.networks
.stash
;
3042 name: "STASH - Stash Testnet",
3043 onSelect: function() {
3044 network
= libs
.bitcoin
.networks
.stashtn
;
3049 name: "STRAT - Stratis",
3050 onSelect: function() {
3051 network
= libs
.bitcoin
.networks
.stratis
;
3056 name: "TSTRAT - Stratis Testnet",
3057 onSelect: function() {
3058 network
= libs
.bitcoin
.networks
.stratistest
;
3063 name: "SYS - Syscoin",
3064 onSelect: function() {
3065 network
= libs
.bitcoin
.networks
.syscoin
;
3070 name: "THC - Hempcoin",
3071 onSelect: function() {
3072 network
= libs
.bitcoin
.networks
.hempcoin
;
3077 name: "THT - Thought",
3078 onSelect: function() {
3079 network
= libs
.bitcoin
.networks
.thought
;
3085 onSelect: function() {
3086 network
= libs
.bitcoin
.networks
.toa
;
3091 name: "TWINS - TWINS",
3092 onSelect: function() {
3093 network
= libs
.bitcoin
.networks
.twins
;
3098 name: "TWINS - TWINS Testnet",
3099 onSelect: function() {
3100 network
= libs
.bitcoin
.networks
.twinstestnet
;
3105 name: "USC - Ultimatesecurecash",
3106 onSelect: function() {
3107 network
= libs
.bitcoin
.networks
.ultimatesecurecash
;
3112 name: "USNBT - NuBits",
3113 onSelect: function() {
3114 network
= libs
.bitcoin
.networks
.nubits
;
3119 name: "UNO - Unobtanium",
3120 onSelect: function() {
3121 network
= libs
.bitcoin
.networks
.unobtanium
;
3126 name: "VASH - Vpncoin",
3127 onSelect: function() {
3128 network
= libs
.bitcoin
.networks
.vpncoin
;
3133 name: "VET - VeChain",
3134 onSelect: function() {
3135 network
= libs
.bitcoin
.networks
.bitcoin
;
3140 name: "VIA - Viacoin",
3141 onSelect: function() {
3142 network
= libs
.bitcoin
.networks
.viacoin
;
3147 name: "VIA - Viacoin Testnet",
3148 onSelect: function() {
3149 network
= libs
.bitcoin
.networks
.viacointestnet
;
3154 name: "VIVO - Vivo",
3155 onSelect: function() {
3156 network
= libs
.bitcoin
.networks
.vivo
;
3161 name: "VTC - Vertcoin",
3162 onSelect: function() {
3163 network
= libs
.bitcoin
.networks
.vertcoin
;
3168 name: "WGR - Wagerr",
3169 onSelect: function() {
3170 network
= libs
.bitcoin
.networks
.wagerr
;
3175 name: "WC - Wincoin",
3176 onSelect: function() {
3177 network
= libs
.bitcoin
.networks
.wincoin
;
3182 name: "XAX - Artax",
3183 onSelect: function() {
3184 network
= libs
.bitcoin
.networks
.artax
;
3189 name: "XBC - Bitcoinplus",
3190 onSelect: function() {
3191 network
= libs
.bitcoin
.networks
.bitcoinplus
;
3196 name: "XLM - Stellar",
3197 onSelect: function() {
3198 network
= libs
.stellarUtil
.dummyNetwork
;
3203 name: "XMY - Myriadcoin",
3204 onSelect: function() {
3205 network
= libs
.bitcoin
.networks
.myriadcoin
;
3210 name: "XRP - Ripple",
3211 onSelect: function() {
3212 network
= libs
.bitcoin
.networks
.bitcoin
;
3217 name: "XVC - Vcash",
3218 onSelect: function() {
3219 network
= libs
.bitcoin
.networks
.vcash
;
3224 name: "XVG - Verge",
3225 onSelect: function() {
3226 network
= libs
.bitcoin
.networks
.verge
;
3231 name: "XUEZ - Xuez",
3232 segwitAvailable: false,
3233 onSelect: function() {
3234 network
= libs
.bitcoin
.networks
.xuez
;
3239 name: "XWC - Whitecoin",
3240 onSelect: function() {
3241 network
= libs
.bitcoin
.networks
.whitecoin
;
3246 name: "XZC - Zcoin",
3247 onSelect: function() {
3248 network
= libs
.bitcoin
.networks
.zcoin
;
3253 name: "ZCL - Zclassic",
3254 onSelect: function() {
3255 network
= libs
.bitcoin
.networks
.zclassic
;
3260 name: "ZEC - Zcash",
3261 onSelect: function() {
3262 network
= libs
.bitcoin
.networks
.zcash
;
3267 name: "ZEN - Horizen",
3268 onSelect: function() {
3269 network
= libs
.bitcoin
.networks
.zencash
;
3277 name: "Bitcoin Core",
3278 onSelect: function() {
3279 DOM
.bip32path
.val("m/0'/0'");
3280 DOM
.hardenedAddresses
.prop('checked', true);
3284 name: "blockchain.info",
3285 onSelect: function() {
3286 DOM
.bip32path
.val("m/44'/0'/0'");
3287 DOM
.hardenedAddresses
.prop('checked', false);
3291 name: "MultiBit HD",
3292 onSelect: function() {
3293 DOM
.bip32path
.val("m/0'/0");
3294 DOM
.hardenedAddresses
.prop('checked', false);
3298 name: "Coinomi, Ledger",
3299 onSelect: function() {
3300 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3301 DOM
.hardenedAddresses
.prop('checked', false);
3306 // ELA - Elastos functions - begin
3307 function displayBip44InfoForELA() {
3312 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3313 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3315 // Calculate the account extended keys
3316 var accountXprv
= libs
.elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3317 var accountXpub
= libs
.elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3319 // Display the extended keys
3320 DOM
.bip44accountXprv
.val(accountXprv
);
3321 DOM
.bip44accountXpub
.val(accountXpub
);
3324 function displayBip32InfoForELA() {
3329 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3330 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3331 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3333 DOM
.extendedPrivKey
.val(libs
.elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3334 DOM
.extendedPubKey
.val(libs
.elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3336 // Display the addresses and privkeys
3337 clearAddressesList();
3338 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3339 displayAddresses(0, initialAddressCount
);
3342 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3347 var publicKey
= libs
.elastosjs
.getDerivedPublicKey(libs
.elastosjs
.getMasterPublicKey(seed
), change
, index
);
3349 privateKey: libs
.elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3350 publicKey: publicKey
,
3351 address: libs
.elastosjs
.getAddress(publicKey
.toString('hex'))
3354 // ELA - Elastos functions - end