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
= bitcoinjs
.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 entropyChangeTimeoutEvent
= null;
20 var phraseChangeTimeoutEvent
= null;
21 var rootKeyChangedTimeoutEvent
= null;
23 var generationProcesses
= [];
26 DOM
.privacyScreenToggle
= $(".privacy-screen-toggle");
27 DOM
.network
= $(".network");
28 DOM
.bip32Client
= $("#bip32-client");
29 DOM
.phraseNetwork
= $("#network-phrase");
30 DOM
.useEntropy
= $(".use-entropy");
31 DOM
.entropyContainer
= $(".entropy-container");
32 DOM
.entropy
= $(".entropy");
33 DOM
.entropyFiltered
= DOM
.entropyContainer
.find(".filtered");
34 DOM
.entropyType
= DOM
.entropyContainer
.find(".type");
35 DOM
.entropyCrackTime
= DOM
.entropyContainer
.find(".crack-time");
36 DOM
.entropyEventCount
= DOM
.entropyContainer
.find(".event-count");
37 DOM
.entropyBits
= DOM
.entropyContainer
.find(".bits");
38 DOM
.entropyBitsPerEvent
= DOM
.entropyContainer
.find(".bits-per-event");
39 DOM
.entropyWordCount
= DOM
.entropyContainer
.find(".word-count");
40 DOM
.entropyBinary
= DOM
.entropyContainer
.find(".binary");
41 DOM
.entropyWordIndexes
= DOM
.entropyContainer
.find(".word-indexes");
42 DOM
.entropyChecksum
= DOM
.entropyContainer
.find(".checksum");
43 DOM
.entropyMnemonicLength
= DOM
.entropyContainer
.find(".mnemonic-length");
44 DOM
.entropyWeakEntropyOverrideWarning
= DOM
.entropyContainer
.find(".weak-entropy-override-warning");
45 DOM
.entropyFilterWarning
= DOM
.entropyContainer
.find(".filter-warning");
46 DOM
.phrase
= $(".phrase");
47 DOM
.phraseSplit
= $(".phraseSplit");
48 DOM
.phraseSplitWarn
= $(".phraseSplitWarn");
49 DOM
.passphrase
= $(".passphrase");
50 DOM
.generateContainer
= $(".generate-container");
51 DOM
.generate
= $(".generate");
52 DOM
.seed
= $(".seed");
53 DOM
.rootKey
= $(".root-key");
54 DOM
.litecoinLtubContainer
= $(".litecoin-ltub-container");
55 DOM
.litecoinUseLtub
= $(".litecoin-use-ltub");
56 DOM
.extendedPrivKey
= $(".extended-priv-key");
57 DOM
.extendedPubKey
= $(".extended-pub-key");
58 DOM
.bip32tab
= $("#bip32-tab");
59 DOM
.bip44tab
= $("#bip44-tab");
60 DOM
.bip49tab
= $("#bip49-tab");
61 DOM
.bip84tab
= $("#bip84-tab");
62 DOM
.bip141tab
= $("#bip141-tab");
63 DOM
.bip32panel
= $("#bip32");
64 DOM
.bip44panel
= $("#bip44");
65 DOM
.bip49panel
= $("#bip49");
66 DOM
.bip32path
= $("#bip32-path");
67 DOM
.bip44path
= $("#bip44-path");
68 DOM
.bip44purpose
= $("#bip44 .purpose");
69 DOM
.bip44coin
= $("#bip44 .coin");
70 DOM
.bip44account
= $("#bip44 .account");
71 DOM
.bip44accountXprv
= $("#bip44 .account-xprv");
72 DOM
.bip44accountXpub
= $("#bip44 .account-xpub");
73 DOM
.bip44change
= $("#bip44 .change");
74 DOM
.bip49unavailable
= $("#bip49 .unavailable");
75 DOM
.bip49available
= $("#bip49 .available");
76 DOM
.bip49path
= $("#bip49-path");
77 DOM
.bip49purpose
= $("#bip49 .purpose");
78 DOM
.bip49coin
= $("#bip49 .coin");
79 DOM
.bip49account
= $("#bip49 .account");
80 DOM
.bip49accountXprv
= $("#bip49 .account-xprv");
81 DOM
.bip49accountXpub
= $("#bip49 .account-xpub");
82 DOM
.bip49change
= $("#bip49 .change");
83 DOM
.bip84unavailable
= $("#bip84 .unavailable");
84 DOM
.bip84available
= $("#bip84 .available");
85 DOM
.bip84path
= $("#bip84-path");
86 DOM
.bip84purpose
= $("#bip84 .purpose");
87 DOM
.bip84coin
= $("#bip84 .coin");
88 DOM
.bip84account
= $("#bip84 .account");
89 DOM
.bip84accountXprv
= $("#bip84 .account-xprv");
90 DOM
.bip84accountXpub
= $("#bip84 .account-xpub");
91 DOM
.bip84change
= $("#bip84 .change");
92 DOM
.bip141unavailable
= $("#bip141 .unavailable");
93 DOM
.bip141available
= $("#bip141 .available");
94 DOM
.bip141path
= $("#bip141-path");
95 DOM
.bip141semantics
= $(".bip141-semantics");
96 DOM
.generatedStrength
= $(".generate-container .strength");
97 DOM
.generatedStrengthWarning
= $(".generate-container .warning");
98 DOM
.hardenedAddresses
= $(".hardened-addresses");
99 DOM
.bitcoinCashAddressTypeContainer
= $(".bch-addr-type-container");
100 DOM
.bitcoinCashAddressType
= $("[name=bch-addr-type]")
101 DOM
.useBip38
= $(".use-bip38");
102 DOM
.bip38Password
= $(".bip38-password");
103 DOM
.addresses
= $(".addresses");
104 DOM
.csvTab
= $("#csv-tab a");
106 DOM
.rowsToAdd
= $(".rows-to-add");
107 DOM
.more
= $(".more");
108 DOM
.moreRowsStartIndex
= $(".more-rows-start-index");
109 DOM
.feedback
= $(".feedback");
110 DOM
.tab
= $(".derivation-type a");
111 DOM
.indexToggle
= $(".index-toggle");
112 DOM
.addressToggle
= $(".address-toggle");
113 DOM
.publicKeyToggle
= $(".public-key-toggle");
114 DOM
.privateKeyToggle
= $(".private-key-toggle");
115 DOM
.languages
= $(".languages a");
116 DOM
.qrContainer
= $(".qr-container");
117 DOM
.qrHider
= DOM
.qrContainer
.find(".qr-hider");
118 DOM
.qrImage
= DOM
.qrContainer
.find(".qr-image");
119 DOM
.qrHint
= DOM
.qrContainer
.find(".qr-hint");
120 DOM
.showQrEls
= $("[data-show-qr]");
124 DOM
.privacyScreenToggle
.on("change", privacyScreenToggled
);
125 DOM
.generatedStrength
.on("change", generatedStrengthChanged
);
126 DOM
.network
.on("change", networkChanged
);
127 DOM
.bip32Client
.on("change", bip32ClientChanged
);
128 DOM
.useEntropy
.on("change", setEntropyVisibility
);
129 DOM
.entropy
.on("input", delayedEntropyChanged
);
130 DOM
.entropyMnemonicLength
.on("change", entropyChanged
);
131 DOM
.phrase
.on("input", delayedPhraseChanged
);
132 DOM
.passphrase
.on("input", delayedPhraseChanged
);
133 DOM
.generate
.on("click", generateClicked
);
134 DOM
.more
.on("click", showMore
);
135 DOM
.rootKey
.on("input", delayedRootKeyChanged
);
136 DOM
.litecoinUseLtub
.on("change", litecoinUseLtubChanged
);
137 DOM
.bip32path
.on("input", calcForDerivationPath
);
138 DOM
.bip44account
.on("input", calcForDerivationPath
);
139 DOM
.bip44change
.on("input", calcForDerivationPath
);
140 DOM
.bip49account
.on("input", calcForDerivationPath
);
141 DOM
.bip49change
.on("input", calcForDerivationPath
);
142 DOM
.bip84account
.on("input", calcForDerivationPath
);
143 DOM
.bip84change
.on("input", calcForDerivationPath
);
144 DOM
.bip141path
.on("input", calcForDerivationPath
);
145 DOM
.bip141semantics
.on("change", tabChanged
);
146 DOM
.tab
.on("shown.bs.tab", tabChanged
);
147 DOM
.hardenedAddresses
.on("change", calcForDerivationPath
);
148 DOM
.useBip38
.on("change", calcForDerivationPath
);
149 DOM
.bip38Password
.on("change", calcForDerivationPath
);
150 DOM
.indexToggle
.on("click", toggleIndexes
);
151 DOM
.addressToggle
.on("click", toggleAddresses
);
152 DOM
.publicKeyToggle
.on("click", togglePublicKeys
);
153 DOM
.privateKeyToggle
.on("click", togglePrivateKeys
);
154 DOM
.csvTab
.on("click", updateCsv
);
155 DOM
.languages
.on("click", languageChanged
);
156 DOM
.bitcoinCashAddressType
.on("change", bitcoinCashAddressTypeChange
);
157 setQrEvents(DOM
.showQrEls
);
160 hideValidationError();
161 populateNetworkSelect();
162 populateClientSelect();
167 function generatedStrengthChanged() {
168 var strength
= parseInt(DOM
.generatedStrength
.val());
170 DOM
.generatedStrengthWarning
.removeClass("hidden");
173 DOM
.generatedStrengthWarning
.addClass("hidden");
177 function networkChanged(e
) {
179 clearAddressesList();
180 DOM
.litecoinLtubContainer
.addClass("hidden");
181 DOM
.bitcoinCashAddressTypeContainer
.addClass("hidden");
182 var networkIndex
= e
.target
.value
;
183 var network
= networks
[networkIndex
];
185 adjustNetworkForSegwit();
194 function bip32ClientChanged(e
) {
195 var clientIndex
= DOM
.bip32Client
.val();
196 if (clientIndex
== "custom") {
197 DOM
.bip32path
.prop("readonly", false);
200 DOM
.bip32path
.prop("readonly", true);
201 clients
[clientIndex
].onSelect();
211 function setEntropyVisibility() {
212 if (isUsingOwnEntropy()) {
213 DOM
.entropyContainer
.removeClass("hidden");
214 DOM
.generateContainer
.addClass("hidden");
215 DOM
.phrase
.prop("readonly", true);
220 DOM
.entropyContainer
.addClass("hidden");
221 DOM
.generateContainer
.removeClass("hidden");
222 DOM
.phrase
.prop("readonly", false);
227 function delayedPhraseChanged() {
228 hideValidationError();
231 bip32ExtendedKey
= null;
232 clearAddressesList();
234 if (phraseChangeTimeoutEvent
!= null) {
235 clearTimeout(phraseChangeTimeoutEvent
);
237 phraseChangeTimeoutEvent
= setTimeout(function() {
239 var entropy
= mnemonic
.toRawEntropyBin(DOM
.phrase
.val());
240 if (entropy
!== null) {
241 DOM
.entropyMnemonicLength
.val("raw");
242 DOM
.entropy
.val(entropy
);
247 function phraseChanged() {
249 setMnemonicLanguage();
250 // Get the mnemonic phrase
251 var phrase
= DOM
.phrase
.val();
252 var errorText
= findPhraseErrors(phrase
);
254 showValidationError(errorText
);
257 // Calculate and display
258 var passphrase
= DOM
.passphrase
.val();
259 calcBip32RootKeyFromSeed(phrase
, passphrase
);
260 calcForDerivationPath();
261 // Show the word indexes
263 writeSplitPhrase(phrase
);
266 function tabChanged() {
268 adjustNetworkForSegwit();
269 var phrase
= DOM
.phrase
.val();
271 // Calculate and display for mnemonic
272 var errorText
= findPhraseErrors(phrase
);
274 showValidationError(errorText
);
277 // Calculate and display
278 var passphrase
= DOM
.passphrase
.val();
279 calcBip32RootKeyFromSeed(phrase
, passphrase
);
282 // Calculate and display for root key
283 var rootKeyBase58
= DOM
.rootKey
.val();
284 var errorText
= validateRootKey(rootKeyBase58
);
286 showValidationError(errorText
);
289 // Calculate and display
290 calcBip32RootKeyFromBase58(rootKeyBase58
);
292 calcForDerivationPath();
295 function delayedEntropyChanged() {
296 hideValidationError();
298 if (entropyChangeTimeoutEvent
!= null) {
299 clearTimeout(entropyChangeTimeoutEvent
);
301 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
304 function entropyChanged() {
305 // If blank entropy, clear mnemonic, addresses, errors
306 if (DOM
.entropy
.val().trim().length
== 0) {
308 clearEntropyFeedback();
310 DOM
.phraseSplit
.val("");
311 showValidationError("Blank entropy");
314 // Get the current phrase to detect changes
315 var phrase
= DOM
.phrase
.val();
316 // Set the phrase from the entropy
317 setMnemonicFromEntropy();
318 // Recalc addresses if the phrase has changed
319 var newPhrase
= DOM
.phrase
.val();
320 if (newPhrase
!= phrase
) {
321 if (newPhrase
.length
== 0) {
333 function delayedRootKeyChanged() {
334 // Warn if there is an existing mnemonic or passphrase.
335 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
336 if (!confirm("This will clear existing mnemonic and passphrase")) {
337 DOM
.rootKey
.val(bip32RootKey
);
341 hideValidationError();
343 // Clear existing mnemonic and passphrase
345 DOM
.phraseSplit
.val("");
346 DOM
.passphrase
.val("");
348 if (rootKeyChangedTimeoutEvent
!= null) {
349 clearTimeout(rootKeyChangedTimeoutEvent
);
351 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
354 function rootKeyChanged() {
356 hideValidationError();
357 var rootKeyBase58
= DOM
.rootKey
.val();
358 var errorText
= validateRootKey(rootKeyBase58
);
360 showValidationError(errorText
);
363 // Calculate and display
364 calcBip32RootKeyFromBase58(rootKeyBase58
);
365 calcForDerivationPath();
368 function litecoinUseLtubChanged() {
369 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
370 if (litecoinUseLtub
) {
371 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
374 network
= bitcoinjs
.bitcoin
.networks
.litecoinXprv
;
379 function calcForDerivationPath() {
381 clearAddressesList();
383 // Don't show segwit if it's selected but network doesn't support it
384 if (segwitSelected() && !networkHasSegwit()) {
385 showSegwitUnavailable();
389 showSegwitAvailable();
390 // Get the derivation path
391 var derivationPath
= getDerivationPath();
392 var errorText
= findDerivationPathErrors(derivationPath
);
394 showValidationError(errorText
);
397 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
398 if (bip44TabSelected()) {
401 else if (bip49TabSelected()) {
404 else if (bip84TabSelected()) {
410 function generateClicked() {
411 if (isUsingOwnEntropy()) {
416 setTimeout(function() {
417 setMnemonicLanguage();
418 var phrase
= generateRandomPhrase();
426 function languageChanged() {
427 setTimeout(function() {
428 setMnemonicLanguage();
429 if (DOM
.phrase
.val().length
> 0) {
430 var newPhrase
= convertPhraseToNewLanguage();
431 DOM
.phrase
.val(newPhrase
);
435 DOM
.generate
.trigger("click");
440 function bitcoinCashAddressTypeChange() {
444 function toggleIndexes() {
445 showIndex
= !showIndex
;
446 $("td.index span").toggleClass("invisible");
449 function toggleAddresses() {
450 showAddress
= !showAddress
;
451 $("td.address span").toggleClass("invisible");
454 function togglePublicKeys() {
455 showPubKey
= !showPubKey
;
456 $("td.pubkey span").toggleClass("invisible");
459 function togglePrivateKeys() {
460 showPrivKey
= !showPrivKey
;
461 $("td.privkey span").toggleClass("invisible");
464 function privacyScreenToggled() {
465 // private-data contains elements added to DOM at runtime
466 // so catch all by adding visual privacy class to the root of the DOM
467 if (DOM
.privacyScreenToggle
.prop("checked")) {
468 $("body").addClass("visual-privacy");
471 $("body").removeClass("visual-privacy");
477 function generateRandomPhrase() {
478 if (!hasStrongRandom()) {
479 var errorText
= "This browser does not support strong randomness";
480 showValidationError(errorText
);
483 // get the amount of entropy to use
484 var numWords
= parseInt(DOM
.generatedStrength
.val());
485 var strength
= numWords
/ 3 * 32;
486 var buffer
= new Uint8Array(strength
/ 8);
487 // create secure entropy
488 var data
= crypto
.getRandomValues(buffer
);
490 var words
= mnemonic
.toMnemonic(data
);
491 DOM
.phrase
.val(words
);
493 var entropyHex
= uint8ArrayToHex(data
);
494 DOM
.entropy
.val(entropyHex
);
495 // ensure entropy fields are consistent with what is being displayed
496 DOM
.entropyMnemonicLength
.val("raw");
500 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
501 seed
= mnemonic
.toSeed(phrase
, passphrase
);
502 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
504 bip32RootKey
= groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
508 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
510 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
513 // try parsing with various segwit network params since this extended
514 // key may be from any one of them.
515 if (networkHasSegwit()) {
517 if ("baseNetwork" in n
) {
518 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
520 // try parsing using base network params
522 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
526 // try parsing using p2wpkh params
529 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
534 // try parsing using p2wpkh-in-p2sh network params
535 if ("p2wpkhInP2sh" in n
) {
537 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
543 // try the network params as currently specified
544 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
547 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
548 // try parsing with various segwit network params since this extended
549 // key may be from any one of them.
550 if (networkHasSegwit()) {
552 if ("baseNetwork" in n
) {
553 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
555 // try parsing using base network params
557 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
561 // try parsing using p2wpkh params
564 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
569 // try parsing using p2wpkh-in-p2sh network params
570 if ("p2wpkhInP2sh" in n
) {
572 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
578 // try the network params as currently specified
579 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
582 function calcBip32ExtendedKey(path
) {
583 // Check there's a root key to derive from
587 var extendedKey
= bip32RootKey
;
588 // Derive the key from the path
589 var pathBits
= path
.split("/");
590 for (var i
=0; i
<pathBits
.length
; i
++) {
591 var bit
= pathBits
[i
];
592 var index
= parseInt(bit
);
596 var hardened
= bit
[bit
.length
-1] == "'";
597 var isPriv
= !(extendedKey
.isNeutered());
598 var invalidDerivationPath
= hardened
&& !isPriv
;
599 if (invalidDerivationPath
) {
603 extendedKey
= extendedKey
.deriveHardened(index
);
606 extendedKey
= extendedKey
.derive(index
);
612 function showValidationError(errorText
) {
618 function hideValidationError() {
624 function findPhraseErrors(phrase
) {
625 // Preprocess the words
626 phrase
= mnemonic
.normalizeString(phrase
);
627 var words
= phraseToWordArray(phrase
);
628 // Detect blank phrase
629 if (words
.length
== 0) {
630 return "Blank mnemonic";
633 for (var i
=0; i
<words
.length
; i
++) {
635 var language
= getLanguage();
636 if (WORDLISTS
[language
].indexOf(word
) == -1) {
637 console
.log("Finding closest match to " + word
);
638 var nearestWord
= findNearestWord(word
);
639 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
642 // Check the words are valid
643 var properPhrase
= wordArrayToPhrase(words
);
644 var isValid
= mnemonic
.check(properPhrase
);
646 return "Invalid mnemonic";
651 function validateRootKey(rootKeyBase58
) {
653 return validateRootKeyGRS(rootKeyBase58
);
655 // try various segwit network params since this extended key may be from
657 if (networkHasSegwit()) {
659 if ("baseNetwork" in n
) {
660 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
662 // try parsing using base network params
664 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
668 // try parsing using p2wpkh params
671 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
676 // try parsing using p2wpkh-in-p2sh network params
677 if ("p2wpkhInP2sh" in n
) {
679 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
685 // try the network params as currently specified
687 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
690 return "Invalid root key";
695 function validateRootKeyGRS(rootKeyBase58
) {
696 // try various segwit network params since this extended key may be from
698 if (networkHasSegwit()) {
700 if ("baseNetwork" in n
) {
701 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
703 // try parsing using base network params
705 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
709 // try parsing using p2wpkh params
712 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
717 // try parsing using p2wpkh-in-p2sh network params
718 if ("p2wpkhInP2sh" in n
) {
720 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
726 // try the network params as currently specified
728 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
731 return "Invalid root key";
736 function getDerivationPath() {
737 if (bip44TabSelected()) {
738 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
739 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
740 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
741 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
743 path
+= purpose
+ "'/";
745 path
+= account
+ "'/";
747 DOM
.bip44path
.val(path
);
748 var derivationPath
= DOM
.bip44path
.val();
749 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
750 return derivationPath
;
752 else if (bip49TabSelected()) {
753 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
754 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
755 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
756 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
758 path
+= purpose
+ "'/";
760 path
+= account
+ "'/";
762 DOM
.bip49path
.val(path
);
763 var derivationPath
= DOM
.bip49path
.val();
764 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
765 return derivationPath
;
767 else if (bip84TabSelected()) {
768 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
769 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
770 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
771 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
773 path
+= purpose
+ "'/";
775 path
+= account
+ "'/";
777 DOM
.bip84path
.val(path
);
778 var derivationPath
= DOM
.bip84path
.val();
779 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
780 return derivationPath
;
782 else if (bip32TabSelected()) {
783 var derivationPath
= DOM
.bip32path
.val();
784 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
785 return derivationPath
;
787 else if (bip141TabSelected()) {
788 var derivationPath
= DOM
.bip141path
.val();
789 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
790 return derivationPath
;
793 console
.log("Unknown derivation path");
797 function findDerivationPathErrors(path
) {
798 // TODO is not perfect but is better than nothing
800 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
802 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
803 var maxDepth
= 255; // TODO verify this!!
804 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
805 if (path
[0] != "m") {
806 return "First character must be 'm'";
808 if (path
.length
> 1) {
809 if (path
[1] != "/") {
810 return "Separator must be '/'";
812 var indexes
= path
.split("/");
813 if (indexes
.length
> maxDepth
) {
814 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
816 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
817 var index
= indexes
[depth
];
818 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
819 if (invalidChars
.length
> 0) {
820 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
822 var indexValue
= parseInt(index
.replace("'", ""));
824 return "Invalid number at depth " + depth
;
826 if (indexValue
> maxIndexValue
) {
827 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
831 // Check root key exists or else derivation path is useless!
833 return "No root key";
835 // Check no hardened derivation path when using xpub keys
836 var hardenedPath
= path
.indexOf("'") > -1;
837 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
838 var hardened
= hardenedPath
|| hardenedAddresses
;
839 var isXpubkey
= bip32RootKey
.isNeutered();
840 if (hardened
&& isXpubkey
) {
841 return "Hardened derivation path is invalid with xpub key";
847 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
851 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
854 function displayBip44Info() {
855 // Get the derivation path for the account
856 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
857 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
858 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
860 path
+= purpose
+ "'/";
862 path
+= account
+ "'/";
863 // Calculate the account extended keys
864 var accountExtendedKey
= calcBip32ExtendedKey(path
);
865 var accountXprv
= accountExtendedKey
.toBase58();
866 var accountXpub
= accountExtendedKey
.neutered().toBase58();
868 // Display the extended keys
869 DOM
.bip44accountXprv
.val(accountXprv
);
870 DOM
.bip44accountXpub
.val(accountXpub
);
873 displayBip44InfoForELA();
877 function displayBip49Info() {
878 // Get the derivation path for the account
879 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
880 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
881 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
883 path
+= purpose
+ "'/";
885 path
+= account
+ "'/";
886 // Calculate the account extended keys
887 var accountExtendedKey
= calcBip32ExtendedKey(path
);
888 var accountXprv
= accountExtendedKey
.toBase58();
889 var accountXpub
= accountExtendedKey
.neutered().toBase58();
890 // Display the extended keys
891 DOM
.bip49accountXprv
.val(accountXprv
);
892 DOM
.bip49accountXpub
.val(accountXpub
);
895 function displayBip84Info() {
896 // Get the derivation path for the account
897 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
898 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
899 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
901 path
+= purpose
+ "'/";
903 path
+= account
+ "'/";
904 // Calculate the account extended keys
905 var accountExtendedKey
= calcBip32ExtendedKey(path
);
906 var accountXprv
= accountExtendedKey
.toBase58();
907 var accountXpub
= accountExtendedKey
.neutered().toBase58();
908 // Display the extended keys
909 DOM
.bip84accountXprv
.val(accountXprv
);
910 DOM
.bip84accountXpub
.val(accountXpub
);
913 function displayBip32Info() {
916 var rootKey
= bip32RootKey
.toBase58();
917 DOM
.rootKey
.val(rootKey
);
918 var xprvkeyB58
= "NA";
919 if (!bip32ExtendedKey
.isNeutered()) {
920 xprvkeyB58
= bip32ExtendedKey
.toBase58();
922 var extendedPrivKey
= xprvkeyB58
;
923 DOM
.extendedPrivKey
.val(extendedPrivKey
);
924 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
925 DOM
.extendedPubKey
.val(extendedPubKey
);
926 // Display the addresses and privkeys
927 clearAddressesList();
928 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
929 displayAddresses(0, initialAddressCount
);
932 displayBip32InfoForELA();
936 function displayAddresses(start
, total
) {
937 generationProcesses
.push(new (function() {
941 this.stop = function() {
942 for (var i
=0; i
<rows
.length
; i
++) {
943 rows
[i
].shouldGenerate
= false;
948 for (var i
=0; i
<total
; i
++) {
949 var index
= i
+ start
;
950 var isLast
= i
== total
- 1;
951 rows
.push(new TableRow(index
, isLast
));
957 function segwitSelected() {
958 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
961 function p2wpkhSelected() {
962 return bip84TabSelected() ||
963 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
966 function p2wpkhInP2shSelected() {
967 return bip49TabSelected() ||
968 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
971 function TableRow(index
, isLast
) {
974 this.shouldGenerate
= true;
975 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
976 var useBip38
= DOM
.useBip38
.prop("checked");
977 var bip38password
= DOM
.bip38Password
.val();
978 var isSegwit
= segwitSelected();
979 var segwitAvailable
= networkHasSegwit();
980 var isP2wpkh
= p2wpkhSelected();
981 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
987 function calculateValues() {
988 setTimeout(function() {
989 if (!self
.shouldGenerate
) {
992 // derive HDkey for this row of the table
994 if (useHardenedAddresses
) {
995 key
= bip32ExtendedKey
.deriveHardened(index
);
998 key
= bip32ExtendedKey
.derive(index
);
1000 // bip38 requires uncompressed keys
1001 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1002 var keyPair
= key
.keyPair
;
1003 var useUncompressed
= useBip38
;
1004 if (useUncompressed
) {
1005 keyPair
= new bitcoinjs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1007 keyPair
= new groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1011 var address
= keyPair
.getAddress().toString();
1013 var hasPrivkey
= !key
.isNeutered();
1016 privkey
= keyPair
.toWIF();
1017 // BIP38 encode private key if required
1020 privkey
= groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1021 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1022 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1024 privkey
= bitcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1025 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1030 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1031 var indexText
= getDerivationPath() + "/" + index
;
1032 if (useHardenedAddresses
) {
1033 indexText
= indexText
+ "'";
1035 // Ethereum values are different
1036 if (networkIsEthereum()) {
1037 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1038 privkey
= privKeyBuffer
.toString('hex');
1039 var addressBuffer
= ethUtil
.privateToAddress(privKeyBuffer
);
1040 var hexAddress
= addressBuffer
.toString('hex');
1041 var checksumAddress
= ethUtil
.toChecksumAddress(hexAddress
);
1042 address
= ethUtil
.addHexPrefix(checksumAddress
);
1043 privkey
= ethUtil
.addHexPrefix(privkey
);
1044 pubkey
= ethUtil
.addHexPrefix(pubkey
);
1047 // Stellar is different
1048 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1049 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1050 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1052 path
+= purpose
+ "'/";
1053 path
+= coin
+ "'/" + index
+ "'";
1054 var keypair
= stellarUtil
.getKeypair(path
, seed
);
1056 privkey
= keypair
.secret();
1057 pubkey
= address
= keypair
.publicKey();
1059 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1060 var NasAccount
= require("nebulas-account");
1061 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1062 var nebulasAccount
= new NasAccount();
1063 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1064 address
= nebulasAccount
.getAddressString();
1065 privkey
= nebulasAccount
.getPrivateKeyString();
1066 pubkey
= nebulasAccount
.getPublicKeyString();
1068 // Ripple values are different
1069 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1070 privkey
= convertRipplePriv(privkey
);
1071 address
= convertRippleAdrr(address
);
1073 // CasinoCoin values are different
1074 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1075 privkey
= convertCasinoCoinPriv(privkey
);
1076 address
= convertCasinoCoinAdrr(address
);
1078 // Bitcoin Cash address format may vary
1079 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1080 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1081 if (bchAddrType
== "cashaddr") {
1082 address
= bchaddr
.toCashAddress(address
);
1084 else if (bchAddrType
== "bitpay") {
1085 address
= bchaddr
.toBitpayAddress(address
);
1088 // Bitcoin Cash address format may vary
1089 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1090 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1091 if (bchAddrType
== "cashaddr") {
1092 address
= bchaddr
.toSlpAddress(address
);
1095 // Segwit addresses are different
1097 if (!segwitAvailable
) {
1101 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1102 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1103 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1105 else if (isP2wpkhInP2sh
) {
1106 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1107 var scriptsig
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1108 var addressbytes
= bitcoinjs
.bitcoin
.crypto
.hash160(scriptsig
);
1109 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1110 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1114 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1115 address
= bitcoinjs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1118 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1120 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1121 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1124 //Groestlcoin Addresses are different
1128 if (!segwitAvailable
) {
1132 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1134 else if (isP2wpkhInP2sh
) {
1135 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1138 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1142 let elaAddress
= calcAddressForELA(
1144 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1145 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1146 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1149 address
= elaAddress
.address
;
1150 privkey
= elaAddress
.privateKey
;
1151 pubkey
= elaAddress
.publicKey
;
1154 addAddressToList(indexText
, address
, pubkey
, privkey
);
1166 function showMore() {
1167 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1168 if (isNaN(rowsToAdd
)) {
1170 DOM
.rowsToAdd
.val("20");
1172 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1174 start
= lastIndexInTable() + 1;
1177 var newStart
= start
+ rowsToAdd
;
1178 DOM
.moreRowsStartIndex
.val(newStart
);
1180 if (rowsToAdd
> 200) {
1181 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1182 msg
+= "Do you want to continue?";
1183 if (!confirm(msg
)) {
1187 displayAddresses(start
, rowsToAdd
);
1190 function clearDisplay() {
1191 clearAddressesList();
1193 hideValidationError();
1196 function clearAddressesList() {
1197 DOM
.addresses
.empty();
1202 function stopGenerating() {
1203 while (generationProcesses
.length
> 0) {
1204 var generation
= generationProcesses
.shift();
1209 function clearKeys() {
1214 function clearRootKey() {
1215 DOM
.rootKey
.val("");
1218 function clearDerivedKeys() {
1219 DOM
.extendedPrivKey
.val("");
1220 DOM
.extendedPubKey
.val("");
1221 DOM
.bip44accountXprv
.val("");
1222 DOM
.bip44accountXpub
.val("");
1225 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1226 var row
= $(addressRowTemplate
.html());
1228 var indexCell
= row
.find(".index span");
1229 var addressCell
= row
.find(".address span");
1230 var pubkeyCell
= row
.find(".pubkey span");
1231 var privkeyCell
= row
.find(".privkey span");
1233 indexCell
.text(indexText
);
1234 addressCell
.text(address
);
1235 pubkeyCell
.text(pubkey
);
1236 privkeyCell
.text(privkey
);
1239 indexCell
.addClass("invisible");
1242 addressCell
.addClass("invisible");
1245 pubkeyCell
.addClass("invisible");
1248 privkeyCell
.addClass("invisible");
1250 DOM
.addresses
.append(row
);
1251 var rowShowQrEls
= row
.find("[data-show-qr]");
1252 setQrEvents(rowShowQrEls
);
1255 function hasStrongRandom() {
1256 return 'crypto' in window
&& window
['crypto'] !== null;
1259 function disableForms() {
1260 $("form").on("submit", function(e
) {
1265 function parseIntNoNaN(val
, defaultVal
) {
1266 var v
= parseInt(val
);
1273 function showPending() {
1275 .text("Calculating...")
1279 function findNearestWord(word
) {
1280 var language
= getLanguage();
1281 var words
= WORDLISTS
[language
];
1282 var minDistance
= 99;
1283 var closestWord
= words
[0];
1284 for (var i
=0; i
<words
.length
; i
++) {
1285 var comparedTo
= words
[i
];
1286 if (comparedTo
.indexOf(word
) == 0) {
1289 var distance
= Levenshtein
.get(word
, comparedTo
);
1290 if (distance
< minDistance
) {
1291 closestWord
= comparedTo
;
1292 minDistance
= distance
;
1298 function hidePending() {
1304 function populateNetworkSelect() {
1305 for (var i
=0; i
<networks
.length
; i
++) {
1306 var network
= networks
[i
];
1307 var option
= $("<option>");
1308 option
.attr("value", i
);
1309 option
.text(network
.name
);
1310 if (network
.name
== "BTC - Bitcoin") {
1311 option
.prop("selected", true);
1313 DOM
.phraseNetwork
.append(option
);
1317 function populateClientSelect() {
1318 for (var i
=0; i
<clients
.length
; i
++) {
1319 var client
= clients
[i
];
1320 var option
= $("<option>");
1321 option
.attr("value", i
);
1322 option
.text(client
.name
);
1323 DOM
.bip32Client
.append(option
);
1327 function getLanguage() {
1328 var defaultLanguage
= "english";
1329 // Try to get from existing phrase
1330 var language
= getLanguageFromPhrase();
1331 // Try to get from url if not from phrase
1332 if (language
.length
== 0) {
1333 language
= getLanguageFromUrl();
1335 // Default to English if no other option
1336 if (language
.length
== 0) {
1337 language
= defaultLanguage
;
1342 function getLanguageFromPhrase(phrase
) {
1343 // Check if how many words from existing phrase match a language.
1346 phrase
= DOM
.phrase
.val();
1348 if (phrase
.length
> 0) {
1349 var words
= phraseToWordArray(phrase
);
1350 var languageMatches
= {};
1351 for (l
in WORDLISTS
) {
1352 // Track how many words match in this language
1353 languageMatches
[l
] = 0;
1354 for (var i
=0; i
<words
.length
; i
++) {
1355 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1356 if (wordInLanguage
) {
1357 languageMatches
[l
]++;
1360 // Find languages with most word matches.
1361 // This is made difficult due to commonalities between Chinese
1362 // simplified vs traditional.
1363 var mostMatches
= 0;
1364 var mostMatchedLanguages
= [];
1365 for (var l
in languageMatches
) {
1366 var numMatches
= languageMatches
[l
];
1367 if (numMatches
> mostMatches
) {
1368 mostMatches
= numMatches
;
1369 mostMatchedLanguages
= [l
];
1371 else if (numMatches
== mostMatches
) {
1372 mostMatchedLanguages
.push(l
);
1376 if (mostMatchedLanguages
.length
> 0) {
1377 // Use first language and warn if multiple detected
1378 language
= mostMatchedLanguages
[0];
1379 if (mostMatchedLanguages
.length
> 1) {
1380 console
.warn("Multiple possible languages");
1381 console
.warn(mostMatchedLanguages
);
1388 function getLanguageFromUrl() {
1389 for (var language
in WORDLISTS
) {
1390 if (window
.location
.hash
.indexOf(language
) > -1) {
1397 function setMnemonicLanguage() {
1398 var language
= getLanguage();
1399 // Load the bip39 mnemonic generator for this language if required
1400 if (!(language
in mnemonics
)) {
1401 mnemonics
[language
] = new Mnemonic(language
);
1403 mnemonic
= mnemonics
[language
];
1406 function convertPhraseToNewLanguage() {
1407 var oldLanguage
= getLanguageFromPhrase();
1408 var newLanguage
= getLanguageFromUrl();
1409 var oldPhrase
= DOM
.phrase
.val();
1410 var oldWords
= phraseToWordArray(oldPhrase
);
1412 for (var i
=0; i
<oldWords
.length
; i
++) {
1413 var oldWord
= oldWords
[i
];
1414 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1415 var newWord
= WORDLISTS
[newLanguage
][index
];
1416 newWords
.push(newWord
);
1418 newPhrase
= wordArrayToPhrase(newWords
);
1422 // TODO look at jsbip39 - mnemonic.splitWords
1423 function phraseToWordArray(phrase
) {
1424 var words
= phrase
.split(/\s/g);
1426 for (var i
=0; i
<words
.length
; i
++) {
1427 var word
= words
[i
];
1428 if (word
.length
> 0) {
1429 noBlanks
.push(word
);
1435 // TODO look at jsbip39 - mnemonic.joinWords
1436 function wordArrayToPhrase(words
) {
1437 var phrase
= words
.join(" ");
1438 var language
= getLanguageFromPhrase(phrase
);
1439 if (language
== "japanese") {
1440 phrase
= words
.join("\u3000");
1445 function writeSplitPhrase(phrase
) {
1446 var wordCount
= phrase
.split(/\s/g).length
;
1448 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1449 var group
=[[],[],[]],
1451 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1452 while (left
.length
>0) {
1453 groupI
=(groupI
+1)%3;
1454 seed
= seed
* 16807 % 2147483647;
1455 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1456 group
[groupI
].push(left
[selected
]);
1457 left
.splice(selected
,1);
1459 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1460 for (var i
=0;i
<3;i
++) {
1461 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1462 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1464 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1465 var triesPerSecond
=10000000000;
1466 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1467 var displayRedText
= false;
1469 hackTime
="<1 second";
1470 displayRedText
= true;
1471 } else if (hackTime
<86400) {
1472 hackTime
=Math
.floor(hackTime
)+" seconds";
1473 displayRedText
= true;
1474 } else if(hackTime
<31557600) {
1475 hackTime
=Math
.floor(hackTime
/86400)+" days";
1476 displayRedText
= true;
1478 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1480 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1481 if (displayRedText
) {
1482 DOM
.phraseSplitWarn
.addClass("text-danger");
1484 DOM
.phraseSplitWarn
.removeClass("text-danger");
1488 function isUsingOwnEntropy() {
1489 return DOM
.useEntropy
.prop("checked");
1492 function setMnemonicFromEntropy() {
1493 clearEntropyFeedback();
1494 // Get entropy value
1495 var entropyStr
= DOM
.entropy
.val();
1496 // Work out minimum base for entropy
1497 var entropy
= Entropy
.fromString(entropyStr
);
1498 if (entropy
.binaryStr
.length
== 0) {
1501 // Show entropy details
1502 showEntropyFeedback(entropy
);
1503 // Use entropy hash if not using raw entropy
1504 var bits
= entropy
.binaryStr
;
1505 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1506 if (mnemonicLength
!= "raw") {
1507 // Get bits by hashing entropy with SHA256
1508 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1509 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1510 bits
= BigInteger
.parse(hex
, 16).toString(2);
1511 while (bits
.length
% 256 != 0) {
1514 // Truncate hash to suit number of words
1515 mnemonicLength
= parseInt(mnemonicLength
);
1516 var numberOfBits
= 32 * mnemonicLength
/ 3;
1517 bits
= bits
.substring(0, numberOfBits
);
1518 // show warning for weak entropy override
1519 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1520 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1523 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1527 // hide warning for weak entropy override
1528 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1530 // Discard trailing entropy
1531 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1532 var start
= bits
.length
- bitsToUse
;
1533 var binaryStr
= bits
.substring(start
);
1534 // Convert entropy string to numeric array
1535 var entropyArr
= [];
1536 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1537 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1538 var entropyByte
= parseInt(byteAsBits
, 2);
1539 entropyArr
.push(entropyByte
)
1541 // Convert entropy array to mnemonic
1542 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1543 // Set the mnemonic in the UI
1544 DOM
.phrase
.val(phrase
);
1545 writeSplitPhrase(phrase
);
1546 // Show the word indexes
1548 // Show the checksum
1552 function clearEntropyFeedback() {
1553 DOM
.entropyCrackTime
.text("...");
1554 DOM
.entropyType
.text("");
1555 DOM
.entropyWordCount
.text("0");
1556 DOM
.entropyEventCount
.text("0");
1557 DOM
.entropyBitsPerEvent
.text("0");
1558 DOM
.entropyBits
.text("0");
1559 DOM
.entropyFiltered
.html(" ");
1560 DOM
.entropyBinary
.html(" ");
1563 function showEntropyFeedback(entropy
) {
1564 var numberOfBits
= entropy
.binaryStr
.length
;
1565 var timeToCrack
= "unknown";
1567 var z
= zxcvbn(entropy
.base
.parts
.join(""));
1568 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1569 if (z
.feedback
.warning
!= "") {
1570 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1574 console
.log("Error detecting entropy strength with zxcvbn:");
1577 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1578 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1579 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1580 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1581 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1582 DOM
.entropyType
.text(entropyTypeStr
);
1583 DOM
.entropyCrackTime
.text(timeToCrack
);
1584 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1585 DOM
.entropyBits
.text(numberOfBits
);
1586 DOM
.entropyWordCount
.text(wordCount
);
1587 DOM
.entropyBinary
.text(spacedBinaryStr
);
1588 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1589 // detect and warn of filtering
1590 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1591 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1592 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1594 DOM
.entropyFilterWarning
.removeClass('hidden');
1597 DOM
.entropyFilterWarning
.addClass('hidden');
1601 function getEntropyTypeStr(entropy
) {
1602 var typeStr
= entropy
.base
.str
;
1603 // Add some detail if these are cards
1604 if (entropy
.base
.asInt
== 52) {
1605 var cardDetail
= []; // array of message strings
1606 // Detect duplicates
1608 var dupeTracker
= {};
1609 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1610 var card
= entropy
.base
.parts
[i
];
1611 var cardUpper
= card
.toUpperCase();
1612 if (cardUpper
in dupeTracker
) {
1615 dupeTracker
[cardUpper
] = true;
1617 if (dupes
.length
> 0) {
1618 var dupeWord
= "duplicates";
1619 if (dupes
.length
== 1) {
1620 dupeWord
= "duplicate";
1622 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1623 if (dupes
.length
> 3) {
1626 cardDetail
.push(msg
);
1629 var uniqueCards
= [];
1630 for (var uniqueCard
in dupeTracker
) {
1631 uniqueCards
.push(uniqueCard
);
1633 if (uniqueCards
.length
== 52) {
1634 cardDetail
.unshift("full deck");
1636 // Detect missing cards
1637 var values
= "A23456789TJQK";
1639 var missingCards
= [];
1640 for (var i
=0; i
<suits
.length
; i
++) {
1641 for (var j
=0; j
<values
.length
; j
++) {
1642 var card
= values
[j
] + suits
[i
];
1643 if (!(card
in dupeTracker
)) {
1644 missingCards
.push(card
);
1648 // Display missing cards if six or less, ie clearly going for full deck
1649 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1650 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1651 if (missingCards
.length
> 3) {
1654 cardDetail
.push(msg
);
1656 // Add card details to typeStr
1657 if (cardDetail
.length
> 0) {
1658 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1664 function setQrEvents(els
) {
1665 els
.on("mouseenter", createQr
);
1666 els
.on("mouseleave", destroyQr
);
1667 els
.on("click", toggleQr
);
1670 function createQr(e
) {
1671 var content
= e
.target
.textContent
|| e
.target
.value
;
1679 DOM
.qrImage
.append(qrEl
);
1681 DOM
.qrHider
.addClass("hidden");
1684 DOM
.qrHider
.removeClass("hidden");
1686 DOM
.qrContainer
.removeClass("hidden");
1690 function destroyQr() {
1691 DOM
.qrImage
.text("");
1692 DOM
.qrContainer
.addClass("hidden");
1695 function toggleQr() {
1697 DOM
.qrHider
.toggleClass("hidden");
1698 DOM
.qrHint
.toggleClass("hidden");
1701 function bip44TabSelected() {
1702 return DOM
.bip44tab
.hasClass("active");
1705 function bip32TabSelected() {
1706 return DOM
.bip32tab
.hasClass("active");
1709 function networkIsEthereum() {
1710 var name
= networks
[DOM
.network
.val()].name
;
1711 return (name
== "ETH - Ethereum")
1712 || (name
== "ETC - Ethereum Classic")
1713 || (name
== "EWT - EnergyWeb")
1714 || (name
== "PIRL - Pirl")
1715 || (name
== "MIX - MIX")
1716 || (name
== "MUSIC - Musicoin")
1717 || (name
== "POA - Poa")
1718 || (name
== "EXP - Expanse")
1719 || (name
== "CLO - Callisto")
1720 || (name
== "DXN - DEXON")
1721 || (name
== "ELLA - Ellaism")
1722 || (name
== "ESN - Ethersocial Network")
1723 || (name
== "VET - VeChain")
1726 function networkHasSegwit() {
1728 if ("baseNetwork" in network
) {
1729 n
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1731 // check if only p2wpkh params are required
1732 if (p2wpkhSelected()) {
1733 return "p2wpkh" in n
;
1735 // check if only p2wpkh-in-p2sh params are required
1736 else if (p2wpkhInP2shSelected()) {
1737 return "p2wpkhInP2sh" in n
;
1739 // require both if it's unclear which params are required
1740 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1743 function bip49TabSelected() {
1744 return DOM
.bip49tab
.hasClass("active");
1747 function bip84TabSelected() {
1748 return DOM
.bip84tab
.hasClass("active");
1751 function bip141TabSelected() {
1752 return DOM
.bip141tab
.hasClass("active");
1755 function setHdCoin(coinValue
) {
1756 DOM
.bip44coin
.val(coinValue
);
1757 DOM
.bip49coin
.val(coinValue
);
1758 DOM
.bip84coin
.val(coinValue
);
1761 function showSegwitAvailable() {
1762 DOM
.bip49unavailable
.addClass("hidden");
1763 DOM
.bip49available
.removeClass("hidden");
1764 DOM
.bip84unavailable
.addClass("hidden");
1765 DOM
.bip84available
.removeClass("hidden");
1766 DOM
.bip141unavailable
.addClass("hidden");
1767 DOM
.bip141available
.removeClass("hidden");
1770 function showSegwitUnavailable() {
1771 DOM
.bip49available
.addClass("hidden");
1772 DOM
.bip49unavailable
.removeClass("hidden");
1773 DOM
.bip84available
.addClass("hidden");
1774 DOM
.bip84unavailable
.removeClass("hidden");
1775 DOM
.bip141available
.addClass("hidden");
1776 DOM
.bip141unavailable
.removeClass("hidden");
1779 function adjustNetworkForSegwit() {
1780 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1781 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1783 // See https://github.com/iancoleman/bip39/issues/125
1784 var segwitNetworks
= null;
1785 // if a segwit network is alread selected, need to use base network to
1786 // look up new parameters
1787 if ("baseNetwork" in network
) {
1788 network
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1790 // choose the right segwit params
1791 if (p2wpkhSelected() && "p2wpkh" in network
) {
1792 network
= network
.p2wpkh
;
1794 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1795 network
= network
.p2wpkhInP2sh
;
1799 function lastIndexInTable() {
1800 var pathText
= DOM
.addresses
.find(".index").last().text();
1801 var pathBits
= pathText
.split("/");
1802 var lastBit
= pathBits
[pathBits
.length
-1];
1803 var lastBitClean
= lastBit
.replace("'", "");
1804 return parseInt(lastBitClean
);
1807 function uint8ArrayToHex(a
) {
1809 for (var i
=0; i
<a
.length
; i
++) {
1810 var h
= a
[i
].toString(16);
1811 while (h
.length
< 2) {
1819 function showWordIndexes() {
1820 var phrase
= DOM
.phrase
.val();
1821 var words
= phraseToWordArray(phrase
);
1822 var wordIndexes
= [];
1823 var language
= getLanguage();
1824 for (var i
=0; i
<words
.length
; i
++) {
1825 var word
= words
[i
];
1826 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1827 wordIndexes
.push(wordIndex
);
1829 var wordIndexesStr
= wordIndexes
.join(", ");
1830 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1833 function showChecksum() {
1834 var phrase
= DOM
.phrase
.val();
1835 var words
= phraseToWordArray(phrase
);
1836 var checksumBitlength
= words
.length
/ 3;
1839 var language
= getLanguage();
1840 for (var i
=words
.length
-1; i
>=0; i
--) {
1841 var word
= words
[i
];
1842 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1843 var wordBinary
= wordIndex
.toString(2);
1844 while (wordBinary
.length
< 11) {
1845 wordBinary
= "0" + wordBinary
;
1847 var binaryStr
= wordBinary
+ binaryStr
;
1848 if (binaryStr
.length
>= checksumBitlength
) {
1849 var start
= binaryStr
.length
- checksumBitlength
;
1850 var end
= binaryStr
.length
;
1851 checksum
= binaryStr
.substring(start
, end
);
1852 // add spaces so the last group is 11 bits, not the first
1853 checksum
= checksum
.split("").reverse().join("")
1854 checksum
= addSpacesEveryElevenBits(checksum
);
1855 checksum
= checksum
.split("").reverse().join("")
1859 DOM
.entropyChecksum
.text(checksum
);
1862 function updateCsv() {
1863 var tableCsv
= "path,address,public key,private key\n";
1864 var rows
= DOM
.addresses
.find("tr");
1865 for (var i
=0; i
<rows
.length
; i
++) {
1866 var row
= $(rows
[i
]);
1867 var cells
= row
.find("td");
1868 for (var j
=0; j
<cells
.length
; j
++) {
1869 var cell
= $(cells
[j
]);
1870 if (!cell
.children().hasClass("invisible")) {
1871 tableCsv
= tableCsv
+ cell
.text();
1873 if (j
!= cells
.length
- 1) {
1874 tableCsv
= tableCsv
+ ",";
1877 tableCsv
= tableCsv
+ "\n";
1879 DOM
.csv
.val(tableCsv
);
1882 function addSpacesEveryElevenBits(binaryStr
) {
1883 return binaryStr
.match(/.{1,11}/g).join(" ");
1888 name: "AC - Asiacoin",
1889 onSelect: function() {
1890 network
= bitcoinjs
.bitcoin
.networks
.asiacoin
;
1895 name: "ACC - Adcoin",
1896 onSelect: function() {
1897 network
= bitcoinjs
.bitcoin
.networks
.adcoin
;
1902 name: "ARYA - Aryacoin",
1903 onSelect: function() {
1904 network
= bitcoinjs
.bitcoin
.networks
.aryacoin
;
1909 name: "AUR - Auroracoin",
1910 onSelect: function() {
1911 network
= bitcoinjs
.bitcoin
.networks
.auroracoin
;
1917 onSelect: function() {
1918 network
= bitcoinjs
.bitcoin
.networks
.axe
;
1923 name: "ANON - ANON",
1924 onSelect: function() {
1925 network
= bitcoinjs
.bitcoin
.networks
.anon
;
1930 name: "BOLI - Bolivarcoin",
1931 onSelect: function() {
1932 network
= bitcoinjs
.bitcoin
.networks
.bolivarcoin
;
1937 name: "BCA - Bitcoin Atom",
1938 onSelect: function() {
1939 network
= bitcoinjs
.bitcoin
.networks
.atom
;
1944 name: "BCH - Bitcoin Cash",
1945 onSelect: function() {
1946 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
1951 name: "BEET - Beetlecoin",
1952 onSelect: function() {
1953 network
= bitcoinjs
.bitcoin
.networks
.beetlecoin
;
1958 name: "BELA - Belacoin",
1959 onSelect: function() {
1960 network
= bitcoinjs
.bitcoin
.networks
.belacoin
;
1965 name: "BLK - BlackCoin",
1966 onSelect: function() {
1967 network
= bitcoinjs
.bitcoin
.networks
.blackcoin
;
1972 name: "BND - Blocknode",
1973 onSelect: function() {
1974 network
= bitcoinjs
.bitcoin
.networks
.blocknode
;
1979 name: "tBND - Blocknode Testnet",
1980 onSelect: function() {
1981 network
= bitcoinjs
.bitcoin
.networks
.blocknode_testnet
;
1986 name: "BRIT - Britcoin",
1987 onSelect: function() {
1988 network
= bitcoinjs
.bitcoin
.networks
.britcoin
;
1993 name: "BSD - Bitsend",
1994 onSelect: function() {
1995 network
= bitcoinjs
.bitcoin
.networks
.bitsend
;
2000 name: "BST - BlockStamp",
2001 onSelect: function() {
2002 network
= bitcoinjs
.bitcoin
.networks
.blockstamp
;
2008 onSelect: function() {
2009 network
= bitcoinjs
.bitcoin
.networks
.bata
;
2014 name: "BTC - Bitcoin",
2015 onSelect: function() {
2016 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2021 name: "BTC - Bitcoin Testnet",
2022 onSelect: function() {
2023 network
= bitcoinjs
.bitcoin
.networks
.testnet
;
2028 name: "BITG - Bitcoin Green",
2029 onSelect: function() {
2030 network
= bitcoinjs
.bitcoin
.networks
.bitcoingreen
;
2035 name: "BTCP - Bitcoin Private",
2036 onSelect: function() {
2037 network
= bitcoinjs
.bitcoin
.networks
.bitcoinprivate
;
2042 name: "BSV - BitcoinSV",
2043 onSelect: function() {
2044 network
= bitcoinjs
.bitcoin
.networks
.bitcoinsv
;
2049 name: "BTCZ - Bitcoinz",
2050 onSelect: function() {
2051 network
= bitcoinjs
.bitcoin
.networks
.bitcoinz
;
2056 name: "BTDX - BitCloud",
2057 onSelect: function() {
2058 network
= bitcoinjs
.bitcoin
.networks
.bitcloud
;
2063 name: "BTG - Bitcoin Gold",
2064 onSelect: function() {
2065 network
= bitcoinjs
.bitcoin
.networks
.bgold
;
2070 name: "BTX - Bitcore",
2071 onSelect: function() {
2072 network
= bitcoinjs
.bitcoin
.networks
.bitcore
;
2077 name: "CCN - Cannacoin",
2078 onSelect: function() {
2079 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2084 name: "CESC - Cryptoescudo",
2085 onSelect: function() {
2086 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2091 name: "CDN - Canadaecoin",
2092 onSelect: function() {
2093 network
= bitcoinjs
.bitcoin
.networks
.canadaecoin
;
2098 name: "CLAM - Clams",
2099 onSelect: function() {
2100 network
= bitcoinjs
.bitcoin
.networks
.clam
;
2105 name: "CLO - Callisto",
2106 segwitAvailable: false,
2107 onSelect: function() {
2108 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2113 name: "CLUB - Clubcoin",
2114 onSelect: function() {
2115 network
= bitcoinjs
.bitcoin
.networks
.clubcoin
;
2120 name: "CMP - Compcoin",
2121 onSelect: function() {
2122 network
= bitcoinjs
.bitcoin
.networks
.compcoin
;
2127 name: "CPU - CPUchain",
2128 onSelect: function() {
2129 network
= bitcoinjs
.bitcoin
.networks
.cpuchain
;
2134 name: "CRAVE - Crave",
2135 onSelect: function() {
2136 network
= bitcoinjs
.bitcoin
.networks
.crave
;
2141 name: "CRW - Crown (Legacy)",
2142 onSelect: function() {
2143 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2148 name: "CRW - Crown",
2149 onSelect: function() {
2150 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2155 name: "CSC - CasinoCoin",
2156 onSelect: function() {
2157 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2162 name: "DASH - Dash",
2163 onSelect: function() {
2164 network
= bitcoinjs
.bitcoin
.networks
.dash
;
2169 name: "DASH - Dash Testnet",
2170 onSelect: function() {
2171 network
= bitcoinjs
.bitcoin
.networks
.dashtn
;
2176 name: "DFC - Defcoin",
2177 onSelect: function() {
2178 network
= bitcoinjs
.bitcoin
.networks
.defcoin
;
2183 name: "DGB - Digibyte",
2184 onSelect: function() {
2185 network
= bitcoinjs
.bitcoin
.networks
.digibyte
;
2190 name: "DGC - Digitalcoin",
2191 onSelect: function() {
2192 network
= bitcoinjs
.bitcoin
.networks
.digitalcoin
;
2197 name: "DMD - Diamond",
2198 onSelect: function() {
2199 network
= bitcoinjs
.bitcoin
.networks
.diamond
;
2204 name: "DNR - Denarius",
2205 onSelect: function() {
2206 network
= bitcoinjs
.bitcoin
.networks
.denarius
;
2211 name: "DOGE - Dogecoin",
2212 onSelect: function() {
2213 network
= bitcoinjs
.bitcoin
.networks
.dogecoin
;
2218 name: "DOGEt - Dogecoin Testnet",
2219 onSelect: function() {
2220 network
= bitcoinjs
.bitcoin
.networks
.dogecointestnet
;
2225 name: "DXN - DEXON",
2226 onSelect: function() {
2227 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2232 name: "ECN - Ecoin",
2233 onSelect: function() {
2234 network
= bitcoinjs
.bitcoin
.networks
.ecoin
;
2239 name: "EDRC - Edrcoin",
2240 onSelect: function() {
2241 network
= bitcoinjs
.bitcoin
.networks
.edrcoin
;
2246 name: "EFL - Egulden",
2247 onSelect: function() {
2248 network
= bitcoinjs
.bitcoin
.networks
.egulden
;
2253 name: "ELA - Elastos",
2254 onSelect: function () {
2255 network
= bitcoinjs
.bitcoin
.networks
.elastos
;
2260 name: "ELLA - Ellaism",
2261 segwitAvailable: false,
2262 onSelect: function() {
2263 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2268 name: "EMC2 - Einsteinium",
2269 onSelect: function() {
2270 network
= bitcoinjs
.bitcoin
.networks
.einsteinium
;
2275 name: "ERC - Europecoin",
2276 onSelect: function() {
2277 network
= bitcoinjs
.bitcoin
.networks
.europecoin
;
2282 name: "EOS - EOSIO",
2283 onSelect: function() {
2284 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2289 name: "ESN - Ethersocial Network",
2290 segwitAvailable: false,
2291 onSelect: function() {
2292 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2297 name: "ETC - Ethereum Classic",
2298 segwitAvailable: false,
2299 onSelect: function() {
2300 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2305 name: "ETH - Ethereum",
2306 onSelect: function() {
2307 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2312 name: "EWT - EnergyWeb",
2313 onSelect: function() {
2314 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2319 name: "EXCL - Exclusivecoin",
2320 onSelect: function() {
2321 network
= bitcoinjs
.bitcoin
.networks
.exclusivecoin
;
2326 name: "EXCC - ExchangeCoin",
2327 onSelect: function() {
2328 network
= bitcoinjs
.bitcoin
.networks
.exchangecoin
;
2333 name: "EXP - Expanse",
2334 segwitAvailable: false,
2335 onSelect: function() {
2336 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2342 onSelect: function() {
2343 network
= bitcoinjs
.bitcoin
.networks
.fix
;
2348 name: "FIX - FIX Testnet",
2349 onSelect: function() {
2350 network
= bitcoinjs
.bitcoin
.networks
.fixtestnet
;
2355 name: "FJC - Fujicoin",
2356 onSelect: function() {
2357 network
= bitcoinjs
.bitcoin
.networks
.fujicoin
;
2362 name: "FLASH - Flashcoin",
2363 onSelect: function() {
2364 network
= bitcoinjs
.bitcoin
.networks
.flashcoin
;
2369 name: "FRST - Firstcoin",
2370 onSelect: function() {
2371 network
= bitcoinjs
.bitcoin
.networks
.firstcoin
;
2376 name: "FTC - Feathercoin",
2377 onSelect: function() {
2378 network
= bitcoinjs
.bitcoin
.networks
.feathercoin
;
2383 name: "GAME - GameCredits",
2384 onSelect: function() {
2385 network
= bitcoinjs
.bitcoin
.networks
.game
;
2390 name: "GBX - Gobyte",
2391 onSelect: function() {
2392 network
= bitcoinjs
.bitcoin
.networks
.gobyte
;
2397 name: "GCR - GCRCoin",
2398 onSelect: function() {
2399 network
= bitcoinjs
.bitcoin
.networks
.gcr
;
2404 name: "GRC - Gridcoin",
2405 onSelect: function() {
2406 network
= bitcoinjs
.bitcoin
.networks
.gridcoin
;
2411 name: "GRS - Groestlcoin",
2412 onSelect: function() {
2413 network
= bitcoinjs
.bitcoin
.networks
.groestlcoin
;
2418 name: "GRS - Groestlcoin Testnet",
2419 onSelect: function() {
2420 network
= bitcoinjs
.bitcoin
.networks
.groestlcointestnet
;
2425 name: "HNC - Helleniccoin",
2426 onSelect: function() {
2427 network
= bitcoinjs
.bitcoin
.networks
.helleniccoin
;
2432 name: "HUSH - Hush (Legacy)",
2433 onSelect: function() {
2434 network
= bitcoinjs
.bitcoin
.networks
.hush
;
2439 name: "HUSH - Hush3",
2440 onSelect: function() {
2441 network
= bitcoinjs
.bitcoin
.networks
.hush3
;
2446 name: "INSN - Insane",
2447 onSelect: function() {
2448 network
= bitcoinjs
.bitcoin
.networks
.insane
;
2454 onSelect: function() {
2455 network
= bitcoinjs
.bitcoin
.networks
.iop
;
2460 name: "IXC - Ixcoin",
2461 onSelect: function() {
2462 network
= bitcoinjs
.bitcoin
.networks
.ixcoin
;
2467 name: "JBS - Jumbucks",
2468 onSelect: function() {
2469 network
= bitcoinjs
.bitcoin
.networks
.jumbucks
;
2474 name: "KMD - Komodo",
2475 bip49available: false,
2476 onSelect: function() {
2477 network
= bitcoinjs
.bitcoin
.networks
.komodo
;
2482 name: "KOBO - Kobocoin",
2483 bip49available: false,
2484 onSelect: function() {
2485 network
= bitcoinjs
.bitcoin
.networks
.kobocoin
;
2490 name: "LBC - Library Credits",
2491 onSelect: function() {
2492 network
= bitcoinjs
.bitcoin
.networks
.lbry
;
2497 name: "LCC - Litecoincash",
2498 onSelect: function() {
2499 network
= bitcoinjs
.bitcoin
.networks
.litecoincash
;
2504 name: "LDCN - Landcoin",
2505 onSelect: function() {
2506 network
= bitcoinjs
.bitcoin
.networks
.landcoin
;
2511 name: "LINX - Linx",
2512 onSelect: function() {
2513 network
= bitcoinjs
.bitcoin
.networks
.linx
;
2518 name: "LKR - Lkrcoin",
2519 segwitAvailable: false,
2520 onSelect: function() {
2521 network
= bitcoinjs
.bitcoin
.networks
.lkrcoin
;
2526 name: "LTC - Litecoin",
2527 onSelect: function() {
2528 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
2530 DOM
.litecoinLtubContainer
.removeClass("hidden");
2534 name: "LTCt - Litecoin Testnet",
2535 onSelect: function() {
2536 network
= bitcoinjs
.bitcoin
.networks
.litecointestnet
;
2538 DOM
.litecoinLtubContainer
.removeClass("hidden");
2542 name: "LTZ - LitecoinZ",
2543 onSelect: function() {
2544 network
= bitcoinjs
.bitcoin
.networks
.litecoinz
;
2549 name: "LYNX - Lynx",
2550 onSelect: function() {
2551 network
= bitcoinjs
.bitcoin
.networks
.lynx
;
2556 name: "MAZA - Maza",
2557 onSelect: function() {
2558 network
= bitcoinjs
.bitcoin
.networks
.maza
;
2563 name: "MEC - Megacoin",
2564 onSelect: function() {
2565 network
= bitcoinjs
.bitcoin
.networks
.megacoin
;
2571 segwitAvailable: false,
2572 onSelect: function() {
2573 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2578 name: "MNX - Minexcoin",
2579 onSelect: function() {
2580 network
= bitcoinjs
.bitcoin
.networks
.minexcoin
;
2585 name: "MONA - Monacoin",
2586 onSelect: function() {
2587 network
= bitcoinjs
.bitcoin
.networks
.monacoin
,
2592 name: "MONK - Monkey Project",
2593 onSelect: function() {
2594 network
= bitcoinjs
.bitcoin
.networks
.monkeyproject
,
2599 name: "MUSIC - Musicoin",
2600 segwitAvailable: false,
2601 onSelect: function() {
2602 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2607 name: "NAV - Navcoin",
2608 onSelect: function() {
2609 network
= bitcoinjs
.bitcoin
.networks
.navcoin
;
2614 name: "NAS - Nebulas",
2615 onSelect: function() {
2616 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2621 name: "NEBL - Neblio",
2622 onSelect: function() {
2623 network
= bitcoinjs
.bitcoin
.networks
.neblio
;
2628 name: "NEOS - Neoscoin",
2629 onSelect: function() {
2630 network
= bitcoinjs
.bitcoin
.networks
.neoscoin
;
2635 name: "NIX - NIX Platform",
2636 onSelect: function() {
2637 network
= bitcoinjs
.bitcoin
.networks
.nix
;
2642 name: "NLG - Gulden",
2643 onSelect: function() {
2644 network
= bitcoinjs
.bitcoin
.networks
.gulden
;
2649 name: "NMC - Namecoin",
2650 onSelect: function() {
2651 network
= bitcoinjs
.bitcoin
.networks
.namecoin
;
2656 name: "NRG - Energi",
2657 onSelect: function() {
2658 network
= bitcoinjs
.bitcoin
.networks
.energi
;
2663 name: "NRO - Neurocoin",
2664 onSelect: function() {
2665 network
= bitcoinjs
.bitcoin
.networks
.neurocoin
;
2670 name: "NSR - Nushares",
2671 onSelect: function() {
2672 network
= bitcoinjs
.bitcoin
.networks
.nushares
;
2677 name: "NYC - Newyorkc",
2678 onSelect: function() {
2679 network
= bitcoinjs
.bitcoin
.networks
.newyorkc
;
2684 name: "NVC - Novacoin",
2685 onSelect: function() {
2686 network
= bitcoinjs
.bitcoin
.networks
.novacoin
;
2691 name: "OK - Okcash",
2692 onSelect: function() {
2693 network
= bitcoinjs
.bitcoin
.networks
.okcash
;
2698 name: "OMNI - Omnicore",
2699 onSelect: function() {
2700 network
= bitcoinjs
.bitcoin
.networks
.omnicore
;
2705 name: "ONION - DeepOnion",
2706 onSelect: function() {
2707 network
= bitcoinjs
.bitcoin
.networks
.deeponion
;
2712 name: "ONX - Onixcoin",
2713 onSelect: function() {
2714 network
= bitcoinjs
.bitcoin
.networks
.onixcoin
;
2719 name: "PHR - Phore",
2720 onSelect: function() {
2721 network
= bitcoinjs
.bitcoin
.networks
.phore
;
2726 name: "PINK - Pinkcoin",
2727 onSelect: function() {
2728 network
= bitcoinjs
.bitcoin
.networks
.pinkcoin
;
2733 name: "PIRL - Pirl",
2734 segwitAvailable: false,
2735 onSelect: function() {
2736 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2741 name: "PIVX - PIVX",
2742 onSelect: function() {
2743 network
= bitcoinjs
.bitcoin
.networks
.pivx
;
2748 name: "PIVX - PIVX Testnet",
2749 onSelect: function() {
2750 network
= bitcoinjs
.bitcoin
.networks
.pivxtestnet
;
2756 segwitAvailable: false,
2757 onSelect: function() {
2758 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2763 name: "POSW - POSWcoin",
2764 onSelect: function() {
2765 network
= bitcoinjs
.bitcoin
.networks
.poswcoin
;
2770 name: "POT - Potcoin",
2771 onSelect: function() {
2772 network
= bitcoinjs
.bitcoin
.networks
.potcoin
;
2777 name: "PPC - Peercoin",
2778 onSelect: function() {
2779 network
= bitcoinjs
.bitcoin
.networks
.peercoin
;
2784 name: "PRJ - ProjectCoin",
2785 onSelect: function() {
2786 network
= bitcoinjs
.bitcoin
.networks
.projectcoin
;
2791 name: "PSB - Pesobit",
2792 onSelect: function() {
2793 network
= bitcoinjs
.bitcoin
.networks
.pesobit
;
2798 name: "PUT - Putincoin",
2799 onSelect: function() {
2800 network
= bitcoinjs
.bitcoin
.networks
.putincoin
;
2805 name: "RPD - Rapids",
2806 onSelect: function() {
2807 network
= bitcoinjs
.bitcoin
.networks
.rapids
;
2812 name: "RVN - Ravencoin",
2813 onSelect: function() {
2814 network
= bitcoinjs
.bitcoin
.networks
.ravencoin
;
2819 name: "RBY - Rubycoin",
2820 onSelect: function() {
2821 network
= bitcoinjs
.bitcoin
.networks
.rubycoin
;
2826 name: "RDD - Reddcoin",
2827 onSelect: function() {
2828 network
= bitcoinjs
.bitcoin
.networks
.reddcoin
;
2833 name: "RVR - RevolutionVR",
2834 onSelect: function() {
2835 network
= bitcoinjs
.bitcoin
.networks
.revolutionvr
;
2840 name: "SAFE - Safecoin",
2841 onSelect: function() {
2842 network
= bitcoinjs
.bitcoin
.networks
.safecoin
;
2847 name: "SLS - Salus",
2848 onSelect: function() {
2849 network
= bitcoinjs
.bitcoin
.networks
.salus
;
2854 name: "SDC - ShadowCash",
2855 onSelect: function() {
2856 network
= bitcoinjs
.bitcoin
.networks
.shadow
;
2861 name: "SDC - ShadowCash Testnet",
2862 onSelect: function() {
2863 network
= bitcoinjs
.bitcoin
.networks
.shadowtn
;
2868 name: "SLM - Slimcoin",
2869 onSelect: function() {
2870 network
= bitcoinjs
.bitcoin
.networks
.slimcoin
;
2875 name: "SLM - Slimcoin Testnet",
2876 onSelect: function() {
2877 network
= bitcoinjs
.bitcoin
.networks
.slimcointn
;
2882 name: "SLP - Simple Ledger Protocol",
2883 onSelect: function() {
2884 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2889 name: "SLR - Solarcoin",
2890 onSelect: function() {
2891 network
= bitcoinjs
.bitcoin
.networks
.solarcoin
;
2896 name: "SMLY - Smileycoin",
2897 onSelect: function() {
2898 network
= bitcoinjs
.bitcoin
.networks
.smileycoin
;
2903 name: "STASH - Stash",
2904 onSelect: function() {
2905 network
= bitcoinjs
.bitcoin
.networks
.stash
;
2910 name: "STASH - Stash Testnet",
2911 onSelect: function() {
2912 network
= bitcoinjs
.bitcoin
.networks
.stashtn
;
2917 name: "STRAT - Stratis",
2918 onSelect: function() {
2919 network
= bitcoinjs
.bitcoin
.networks
.stratis
;
2924 name: "TSTRAT - Stratis Testnet",
2925 onSelect: function() {
2926 network
= bitcoinjs
.bitcoin
.networks
.stratistest
;
2931 name: "SYS - Syscoin",
2932 onSelect: function() {
2933 network
= bitcoinjs
.bitcoin
.networks
.syscoin
;
2938 name: "THC - Hempcoin",
2939 onSelect: function() {
2940 network
= bitcoinjs
.bitcoin
.networks
.hempcoin
;
2945 name: "THT - Thought",
2946 onSelect: function() {
2947 network
= bitcoinjs
.bitcoin
.networks
.thought
;
2953 onSelect: function() {
2954 network
= bitcoinjs
.bitcoin
.networks
.toa
;
2959 name: "TWINS - TWINS",
2960 onSelect: function() {
2961 network
= bitcoinjs
.bitcoin
.networks
.twins
;
2966 name: "TWINS - TWINS Testnet",
2967 onSelect: function() {
2968 network
= bitcoinjs
.bitcoin
.networks
.twinstestnet
;
2973 name: "USC - Ultimatesecurecash",
2974 onSelect: function() {
2975 network
= bitcoinjs
.bitcoin
.networks
.ultimatesecurecash
;
2980 name: "USNBT - NuBits",
2981 onSelect: function() {
2982 network
= bitcoinjs
.bitcoin
.networks
.nubits
;
2987 name: "UNO - Unobtanium",
2988 onSelect: function() {
2989 network
= bitcoinjs
.bitcoin
.networks
.unobtanium
;
2994 name: "VASH - Vpncoin",
2995 onSelect: function() {
2996 network
= bitcoinjs
.bitcoin
.networks
.vpncoin
;
3001 name: "VET - VeChain",
3002 onSelect: function() {
3003 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3008 name: "VIA - Viacoin",
3009 onSelect: function() {
3010 network
= bitcoinjs
.bitcoin
.networks
.viacoin
;
3015 name: "VIA - Viacoin Testnet",
3016 onSelect: function() {
3017 network
= bitcoinjs
.bitcoin
.networks
.viacointestnet
;
3022 name: "VIVO - Vivo",
3023 onSelect: function() {
3024 network
= bitcoinjs
.bitcoin
.networks
.vivo
;
3029 name: "VTC - Vertcoin",
3030 onSelect: function() {
3031 network
= bitcoinjs
.bitcoin
.networks
.vertcoin
;
3036 name: "WGR - Wagerr",
3037 onSelect: function() {
3038 network
= bitcoinjs
.bitcoin
.networks
.wagerr
;
3043 name: "WC - Wincoin",
3044 onSelect: function() {
3045 network
= bitcoinjs
.bitcoin
.networks
.wincoin
;
3050 name: "XAX - Artax",
3051 onSelect: function() {
3052 network
= bitcoinjs
.bitcoin
.networks
.artax
;
3057 name: "XBC - Bitcoinplus",
3058 onSelect: function() {
3059 network
= bitcoinjs
.bitcoin
.networks
.bitcoinplus
;
3064 name: "XLM - Stellar",
3065 onSelect: function() {
3066 network
= stellarUtil
.dummyNetwork
;
3071 name: "XMY - Myriadcoin",
3072 onSelect: function() {
3073 network
= bitcoinjs
.bitcoin
.networks
.myriadcoin
;
3078 name: "XRP - Ripple",
3079 onSelect: function() {
3080 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3085 name: "XVC - Vcash",
3086 onSelect: function() {
3087 network
= bitcoinjs
.bitcoin
.networks
.vcash
;
3092 name: "XVG - Verge",
3093 onSelect: function() {
3094 network
= bitcoinjs
.bitcoin
.networks
.verge
;
3099 name: "XUEZ - Xuez",
3100 segwitAvailable: false,
3101 onSelect: function() {
3102 network
= bitcoinjs
.bitcoin
.networks
.xuez
;
3107 name: "XWC - Whitecoin",
3108 onSelect: function() {
3109 network
= bitcoinjs
.bitcoin
.networks
.whitecoin
;
3114 name: "XZC - Zcoin",
3115 onSelect: function() {
3116 network
= bitcoinjs
.bitcoin
.networks
.zcoin
;
3121 name: "ZCL - Zclassic",
3122 onSelect: function() {
3123 network
= bitcoinjs
.bitcoin
.networks
.zclassic
;
3128 name: "ZEC - Zcash",
3129 onSelect: function() {
3130 network
= bitcoinjs
.bitcoin
.networks
.zcash
;
3135 name: "ZEN - Horizen",
3136 onSelect: function() {
3137 network
= bitcoinjs
.bitcoin
.networks
.zencash
;
3145 name: "Bitcoin Core",
3146 onSelect: function() {
3147 DOM
.bip32path
.val("m/0'/0'");
3148 DOM
.hardenedAddresses
.prop('checked', true);
3152 name: "blockchain.info",
3153 onSelect: function() {
3154 DOM
.bip32path
.val("m/44'/0'/0'");
3155 DOM
.hardenedAddresses
.prop('checked', false);
3159 name: "MultiBit HD",
3160 onSelect: function() {
3161 DOM
.bip32path
.val("m/0'/0");
3162 DOM
.hardenedAddresses
.prop('checked', false);
3166 name: "Coinomi, Ledger",
3167 onSelect: function() {
3168 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3169 DOM
.hardenedAddresses
.prop('checked', false);
3174 // ELA - Elastos functions - begin
3175 function displayBip44InfoForELA() {
3180 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3181 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3183 // Calculate the account extended keys
3184 var accountXprv
= elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3185 var accountXpub
= elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3187 // Display the extended keys
3188 DOM
.bip44accountXprv
.val(accountXprv
);
3189 DOM
.bip44accountXpub
.val(accountXpub
);
3192 function displayBip32InfoForELA() {
3197 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3198 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3199 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3201 DOM
.extendedPrivKey
.val(elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3202 DOM
.extendedPubKey
.val(elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3204 // Display the addresses and privkeys
3205 clearAddressesList();
3206 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3207 displayAddresses(0, initialAddressCount
);
3210 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3215 var publicKey
= elastosjs
.getDerivedPublicKey(elastosjs
.getMasterPublicKey(seed
), change
, index
);
3217 privateKey: elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3218 publicKey: publicKey
,
3219 address: elastosjs
.getAddress(publicKey
.toString('hex'))
3222 // ELA - Elastos functions - end