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 entropyTypeAutoDetect
= true;
20 var entropyChangeTimeoutEvent
= null;
21 var phraseChangeTimeoutEvent
= null;
22 var rootKeyChangedTimeoutEvent
= null;
24 var generationProcesses
= [];
27 DOM
.privacyScreenToggle
= $(".privacy-screen-toggle");
28 DOM
.network
= $(".network");
29 DOM
.bip32Client
= $("#bip32-client");
30 DOM
.phraseNetwork
= $("#network-phrase");
31 DOM
.useEntropy
= $(".use-entropy");
32 DOM
.entropyContainer
= $(".entropy-container");
33 DOM
.entropy
= $(".entropy");
34 DOM
.entropyFiltered
= DOM
.entropyContainer
.find(".filtered");
35 DOM
.entropyType
= DOM
.entropyContainer
.find(".type");
36 DOM
.entropyTypeInputs
= DOM
.entropyContainer
.find("input[name='entropy-type']");
37 DOM
.entropyCrackTime
= DOM
.entropyContainer
.find(".crack-time");
38 DOM
.entropyEventCount
= DOM
.entropyContainer
.find(".event-count");
39 DOM
.entropyBits
= DOM
.entropyContainer
.find(".bits");
40 DOM
.entropyBitsPerEvent
= DOM
.entropyContainer
.find(".bits-per-event");
41 DOM
.entropyWordCount
= DOM
.entropyContainer
.find(".word-count");
42 DOM
.entropyBinary
= DOM
.entropyContainer
.find(".binary");
43 DOM
.entropyWordIndexes
= DOM
.entropyContainer
.find(".word-indexes");
44 DOM
.entropyChecksum
= DOM
.entropyContainer
.find(".checksum");
45 DOM
.entropyMnemonicLength
= DOM
.entropyContainer
.find(".mnemonic-length");
46 DOM
.entropyWeakEntropyOverrideWarning
= DOM
.entropyContainer
.find(".weak-entropy-override-warning");
47 DOM
.entropyFilterWarning
= DOM
.entropyContainer
.find(".filter-warning");
48 DOM
.phrase
= $(".phrase");
49 DOM
.phraseSplit
= $(".phraseSplit");
50 DOM
.phraseSplitWarn
= $(".phraseSplitWarn");
51 DOM
.passphrase
= $(".passphrase");
52 DOM
.generateContainer
= $(".generate-container");
53 DOM
.generate
= $(".generate");
54 DOM
.seed
= $(".seed");
55 DOM
.rootKey
= $(".root-key");
56 DOM
.litecoinLtubContainer
= $(".litecoin-ltub-container");
57 DOM
.litecoinUseLtub
= $(".litecoin-use-ltub");
58 DOM
.extendedPrivKey
= $(".extended-priv-key");
59 DOM
.extendedPubKey
= $(".extended-pub-key");
60 DOM
.bip32tab
= $("#bip32-tab");
61 DOM
.bip44tab
= $("#bip44-tab");
62 DOM
.bip49tab
= $("#bip49-tab");
63 DOM
.bip84tab
= $("#bip84-tab");
64 DOM
.bip141tab
= $("#bip141-tab");
65 DOM
.bip32panel
= $("#bip32");
66 DOM
.bip44panel
= $("#bip44");
67 DOM
.bip49panel
= $("#bip49");
68 DOM
.bip32path
= $("#bip32-path");
69 DOM
.bip44path
= $("#bip44-path");
70 DOM
.bip44purpose
= $("#bip44 .purpose");
71 DOM
.bip44coin
= $("#bip44 .coin");
72 DOM
.bip44account
= $("#bip44 .account");
73 DOM
.bip44accountXprv
= $("#bip44 .account-xprv");
74 DOM
.bip44accountXpub
= $("#bip44 .account-xpub");
75 DOM
.bip44change
= $("#bip44 .change");
76 DOM
.bip49unavailable
= $("#bip49 .unavailable");
77 DOM
.bip49available
= $("#bip49 .available");
78 DOM
.bip49path
= $("#bip49-path");
79 DOM
.bip49purpose
= $("#bip49 .purpose");
80 DOM
.bip49coin
= $("#bip49 .coin");
81 DOM
.bip49account
= $("#bip49 .account");
82 DOM
.bip49accountXprv
= $("#bip49 .account-xprv");
83 DOM
.bip49accountXpub
= $("#bip49 .account-xpub");
84 DOM
.bip49change
= $("#bip49 .change");
85 DOM
.bip84unavailable
= $("#bip84 .unavailable");
86 DOM
.bip84available
= $("#bip84 .available");
87 DOM
.bip84path
= $("#bip84-path");
88 DOM
.bip84purpose
= $("#bip84 .purpose");
89 DOM
.bip84coin
= $("#bip84 .coin");
90 DOM
.bip84account
= $("#bip84 .account");
91 DOM
.bip84accountXprv
= $("#bip84 .account-xprv");
92 DOM
.bip84accountXpub
= $("#bip84 .account-xpub");
93 DOM
.bip84change
= $("#bip84 .change");
94 DOM
.bip141unavailable
= $("#bip141 .unavailable");
95 DOM
.bip141available
= $("#bip141 .available");
96 DOM
.bip141path
= $("#bip141-path");
97 DOM
.bip141semantics
= $(".bip141-semantics");
98 DOM
.generatedStrength
= $(".generate-container .strength");
99 DOM
.generatedStrengthWarning
= $(".generate-container .warning");
100 DOM
.hardenedAddresses
= $(".hardened-addresses");
101 DOM
.bitcoinCashAddressTypeContainer
= $(".bch-addr-type-container");
102 DOM
.bitcoinCashAddressType
= $("[name=bch-addr-type]")
103 DOM
.useBip38
= $(".use-bip38");
104 DOM
.bip38Password
= $(".bip38-password");
105 DOM
.addresses
= $(".addresses");
106 DOM
.csvTab
= $("#csv-tab a");
108 DOM
.rowsToAdd
= $(".rows-to-add");
109 DOM
.more
= $(".more");
110 DOM
.moreRowsStartIndex
= $(".more-rows-start-index");
111 DOM
.feedback
= $(".feedback");
112 DOM
.tab
= $(".derivation-type a");
113 DOM
.indexToggle
= $(".index-toggle");
114 DOM
.addressToggle
= $(".address-toggle");
115 DOM
.publicKeyToggle
= $(".public-key-toggle");
116 DOM
.privateKeyToggle
= $(".private-key-toggle");
117 DOM
.languages
= $(".languages a");
118 DOM
.qrContainer
= $(".qr-container");
119 DOM
.qrHider
= DOM
.qrContainer
.find(".qr-hider");
120 DOM
.qrImage
= DOM
.qrContainer
.find(".qr-image");
121 DOM
.qrHint
= DOM
.qrContainer
.find(".qr-hint");
122 DOM
.showQrEls
= $("[data-show-qr]");
126 DOM
.privacyScreenToggle
.on("change", privacyScreenToggled
);
127 DOM
.generatedStrength
.on("change", generatedStrengthChanged
);
128 DOM
.network
.on("change", networkChanged
);
129 DOM
.bip32Client
.on("change", bip32ClientChanged
);
130 DOM
.useEntropy
.on("change", setEntropyVisibility
);
131 DOM
.entropy
.on("input", delayedEntropyChanged
);
132 DOM
.entropyMnemonicLength
.on("change", entropyChanged
);
133 DOM
.entropyTypeInputs
.on("change", entropyTypeChanged
);
134 DOM
.phrase
.on("input", delayedPhraseChanged
);
135 DOM
.passphrase
.on("input", delayedPhraseChanged
);
136 DOM
.generate
.on("click", generateClicked
);
137 DOM
.more
.on("click", showMore
);
138 DOM
.rootKey
.on("input", delayedRootKeyChanged
);
139 DOM
.litecoinUseLtub
.on("change", litecoinUseLtubChanged
);
140 DOM
.bip32path
.on("input", calcForDerivationPath
);
141 DOM
.bip44account
.on("input", calcForDerivationPath
);
142 DOM
.bip44change
.on("input", calcForDerivationPath
);
143 DOM
.bip49account
.on("input", calcForDerivationPath
);
144 DOM
.bip49change
.on("input", calcForDerivationPath
);
145 DOM
.bip84account
.on("input", calcForDerivationPath
);
146 DOM
.bip84change
.on("input", calcForDerivationPath
);
147 DOM
.bip141path
.on("input", calcForDerivationPath
);
148 DOM
.bip141semantics
.on("change", tabChanged
);
149 DOM
.tab
.on("shown.bs.tab", tabChanged
);
150 DOM
.hardenedAddresses
.on("change", calcForDerivationPath
);
151 DOM
.useBip38
.on("change", calcForDerivationPath
);
152 DOM
.bip38Password
.on("change", calcForDerivationPath
);
153 DOM
.indexToggle
.on("click", toggleIndexes
);
154 DOM
.addressToggle
.on("click", toggleAddresses
);
155 DOM
.publicKeyToggle
.on("click", togglePublicKeys
);
156 DOM
.privateKeyToggle
.on("click", togglePrivateKeys
);
157 DOM
.csvTab
.on("click", updateCsv
);
158 DOM
.languages
.on("click", languageChanged
);
159 DOM
.bitcoinCashAddressType
.on("change", bitcoinCashAddressTypeChange
);
160 setQrEvents(DOM
.showQrEls
);
163 hideValidationError();
164 populateNetworkSelect();
165 populateClientSelect();
170 function generatedStrengthChanged() {
171 var strength
= parseInt(DOM
.generatedStrength
.val());
173 DOM
.generatedStrengthWarning
.removeClass("hidden");
176 DOM
.generatedStrengthWarning
.addClass("hidden");
180 function networkChanged(e
) {
182 clearAddressesList();
183 DOM
.litecoinLtubContainer
.addClass("hidden");
184 DOM
.bitcoinCashAddressTypeContainer
.addClass("hidden");
185 var networkIndex
= e
.target
.value
;
186 var network
= networks
[networkIndex
];
188 adjustNetworkForSegwit();
197 function bip32ClientChanged(e
) {
198 var clientIndex
= DOM
.bip32Client
.val();
199 if (clientIndex
== "custom") {
200 DOM
.bip32path
.prop("readonly", false);
203 DOM
.bip32path
.prop("readonly", true);
204 clients
[clientIndex
].onSelect();
214 function setEntropyVisibility() {
215 if (isUsingOwnEntropy()) {
216 DOM
.entropyContainer
.removeClass("hidden");
217 DOM
.generateContainer
.addClass("hidden");
218 DOM
.phrase
.prop("readonly", true);
223 DOM
.entropyContainer
.addClass("hidden");
224 DOM
.generateContainer
.removeClass("hidden");
225 DOM
.phrase
.prop("readonly", false);
230 function delayedPhraseChanged() {
231 hideValidationError();
234 bip32ExtendedKey
= null;
235 clearAddressesList();
237 if (phraseChangeTimeoutEvent
!= null) {
238 clearTimeout(phraseChangeTimeoutEvent
);
240 phraseChangeTimeoutEvent
= setTimeout(function() {
242 var entropy
= mnemonic
.toRawEntropyHex(DOM
.phrase
.val());
243 if (entropy
!== null) {
244 DOM
.entropyMnemonicLength
.val("raw");
245 DOM
.entropy
.val(entropy
);
246 DOM
.entropyTypeInputs
.filter("[value='hexadecimal']").prop("checked", true);
247 entropyTypeAutoDetect
= false;
252 function phraseChanged() {
254 setMnemonicLanguage();
255 // Get the mnemonic phrase
256 var phrase
= DOM
.phrase
.val();
257 var errorText
= findPhraseErrors(phrase
);
259 showValidationError(errorText
);
262 // Calculate and display
263 var passphrase
= DOM
.passphrase
.val();
264 calcBip32RootKeyFromSeed(phrase
, passphrase
);
265 calcForDerivationPath();
266 // Show the word indexes
268 writeSplitPhrase(phrase
);
271 function tabChanged() {
273 adjustNetworkForSegwit();
274 var phrase
= DOM
.phrase
.val();
276 // Calculate and display for mnemonic
277 var errorText
= findPhraseErrors(phrase
);
279 showValidationError(errorText
);
282 // Calculate and display
283 var passphrase
= DOM
.passphrase
.val();
284 calcBip32RootKeyFromSeed(phrase
, passphrase
);
287 // Calculate and display for root key
288 var rootKeyBase58
= DOM
.rootKey
.val();
289 var errorText
= validateRootKey(rootKeyBase58
);
291 showValidationError(errorText
);
294 // Calculate and display
295 calcBip32RootKeyFromBase58(rootKeyBase58
);
297 calcForDerivationPath();
300 function delayedEntropyChanged() {
301 hideValidationError();
303 if (entropyChangeTimeoutEvent
!= null) {
304 clearTimeout(entropyChangeTimeoutEvent
);
306 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
309 function entropyChanged() {
310 // If blank entropy, clear mnemonic, addresses, errors
311 if (DOM
.entropy
.val().trim().length
== 0) {
313 clearEntropyFeedback();
315 DOM
.phraseSplit
.val("");
316 showValidationError("Blank entropy");
319 // Get the current phrase to detect changes
320 var phrase
= DOM
.phrase
.val();
321 // Set the phrase from the entropy
322 setMnemonicFromEntropy();
323 // Recalc addresses if the phrase has changed
324 var newPhrase
= DOM
.phrase
.val();
325 if (newPhrase
!= phrase
) {
326 if (newPhrase
.length
== 0) {
338 function entropyTypeChanged() {
339 entropyTypeAutoDetect
= false;
343 function delayedRootKeyChanged() {
344 // Warn if there is an existing mnemonic or passphrase.
345 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
346 if (!confirm("This will clear existing mnemonic and passphrase")) {
347 DOM
.rootKey
.val(bip32RootKey
);
351 hideValidationError();
353 // Clear existing mnemonic and passphrase
355 DOM
.phraseSplit
.val("");
356 DOM
.passphrase
.val("");
358 if (rootKeyChangedTimeoutEvent
!= null) {
359 clearTimeout(rootKeyChangedTimeoutEvent
);
361 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
364 function rootKeyChanged() {
366 hideValidationError();
367 var rootKeyBase58
= DOM
.rootKey
.val();
368 var errorText
= validateRootKey(rootKeyBase58
);
370 showValidationError(errorText
);
373 // Calculate and display
374 calcBip32RootKeyFromBase58(rootKeyBase58
);
375 calcForDerivationPath();
378 function litecoinUseLtubChanged() {
379 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
380 if (litecoinUseLtub
) {
381 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
384 network
= bitcoinjs
.bitcoin
.networks
.litecoinXprv
;
389 function calcForDerivationPath() {
391 clearAddressesList();
393 // Don't show segwit if it's selected but network doesn't support it
394 if (segwitSelected() && !networkHasSegwit()) {
395 showSegwitUnavailable();
399 showSegwitAvailable();
400 // Get the derivation path
401 var derivationPath
= getDerivationPath();
402 var errorText
= findDerivationPathErrors(derivationPath
);
404 showValidationError(errorText
);
407 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
408 if (bip44TabSelected()) {
411 else if (bip49TabSelected()) {
414 else if (bip84TabSelected()) {
420 function generateClicked() {
421 if (isUsingOwnEntropy()) {
426 setTimeout(function() {
427 setMnemonicLanguage();
428 var phrase
= generateRandomPhrase();
436 function languageChanged() {
437 setTimeout(function() {
438 setMnemonicLanguage();
439 if (DOM
.phrase
.val().length
> 0) {
440 var newPhrase
= convertPhraseToNewLanguage();
441 DOM
.phrase
.val(newPhrase
);
445 DOM
.generate
.trigger("click");
450 function bitcoinCashAddressTypeChange() {
454 function toggleIndexes() {
455 showIndex
= !showIndex
;
456 $("td.index span").toggleClass("invisible");
459 function toggleAddresses() {
460 showAddress
= !showAddress
;
461 $("td.address span").toggleClass("invisible");
464 function togglePublicKeys() {
465 showPubKey
= !showPubKey
;
466 $("td.pubkey span").toggleClass("invisible");
469 function togglePrivateKeys() {
470 showPrivKey
= !showPrivKey
;
471 $("td.privkey span").toggleClass("invisible");
474 function privacyScreenToggled() {
475 // private-data contains elements added to DOM at runtime
476 // so catch all by adding visual privacy class to the root of the DOM
477 if (DOM
.privacyScreenToggle
.prop("checked")) {
478 $("body").addClass("visual-privacy");
481 $("body").removeClass("visual-privacy");
487 function generateRandomPhrase() {
488 if (!hasStrongRandom()) {
489 var errorText
= "This browser does not support strong randomness";
490 showValidationError(errorText
);
493 // get the amount of entropy to use
494 var numWords
= parseInt(DOM
.generatedStrength
.val());
495 var strength
= numWords
/ 3 * 32;
496 var buffer
= new Uint8Array(strength
/ 8);
497 // create secure entropy
498 var data
= crypto
.getRandomValues(buffer
);
500 var words
= mnemonic
.toMnemonic(data
);
501 DOM
.phrase
.val(words
);
503 var entropyHex
= uint8ArrayToHex(data
);
504 DOM
.entropy
.val(entropyHex
);
505 // ensure entropy fields are consistent with what is being displayed
506 DOM
.entropyMnemonicLength
.val("raw");
510 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
511 seed
= mnemonic
.toSeed(phrase
, passphrase
);
512 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
514 bip32RootKey
= groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
518 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
520 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
523 // try parsing with various segwit network params since this extended
524 // key may be from any one of them.
525 if (networkHasSegwit()) {
527 if ("baseNetwork" in n
) {
528 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
530 // try parsing using base network params
532 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
536 // try parsing using p2wpkh params
539 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
544 // try parsing using p2wpkh-in-p2sh network params
545 if ("p2wpkhInP2sh" in n
) {
547 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
552 // try parsing using p2wsh network params
555 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
560 // try parsing using p2wsh-in-p2sh network params
561 if ("p2wshInP2sh" in n
) {
563 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
569 // try the network params as currently specified
570 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
573 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
574 // try parsing with various segwit network params since this extended
575 // key may be from any one of them.
576 if (networkHasSegwit()) {
578 if ("baseNetwork" in n
) {
579 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
581 // try parsing using base network params
583 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
587 // try parsing using p2wpkh params
590 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
595 // try parsing using p2wpkh-in-p2sh network params
596 if ("p2wpkhInP2sh" in n
) {
598 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
604 // try the network params as currently specified
605 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
608 function calcBip32ExtendedKey(path
) {
609 // Check there's a root key to derive from
613 var extendedKey
= bip32RootKey
;
614 // Derive the key from the path
615 var pathBits
= path
.split("/");
616 for (var i
=0; i
<pathBits
.length
; i
++) {
617 var bit
= pathBits
[i
];
618 var index
= parseInt(bit
);
622 var hardened
= bit
[bit
.length
-1] == "'";
623 var isPriv
= !(extendedKey
.isNeutered());
624 var invalidDerivationPath
= hardened
&& !isPriv
;
625 if (invalidDerivationPath
) {
629 extendedKey
= extendedKey
.deriveHardened(index
);
632 extendedKey
= extendedKey
.derive(index
);
638 function showValidationError(errorText
) {
644 function hideValidationError() {
650 function findPhraseErrors(phrase
) {
651 // Preprocess the words
652 phrase
= mnemonic
.normalizeString(phrase
);
653 var words
= phraseToWordArray(phrase
);
654 // Detect blank phrase
655 if (words
.length
== 0) {
656 return "Blank mnemonic";
659 for (var i
=0; i
<words
.length
; i
++) {
661 var language
= getLanguage();
662 if (WORDLISTS
[language
].indexOf(word
) == -1) {
663 console
.log("Finding closest match to " + word
);
664 var nearestWord
= findNearestWord(word
);
665 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
668 // Check the words are valid
669 var properPhrase
= wordArrayToPhrase(words
);
670 var isValid
= mnemonic
.check(properPhrase
);
672 return "Invalid mnemonic";
677 function validateRootKey(rootKeyBase58
) {
679 return validateRootKeyGRS(rootKeyBase58
);
681 // try various segwit network params since this extended key may be from
683 if (networkHasSegwit()) {
685 if ("baseNetwork" in n
) {
686 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
688 // try parsing using base network params
690 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
694 // try parsing using p2wpkh params
697 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
702 // try parsing using p2wpkh-in-p2sh network params
703 if ("p2wpkhInP2sh" in n
) {
705 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
710 // try parsing using p2wsh network params
713 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
718 // try parsing using p2wsh-in-p2sh network params
719 if ("p2wshInP2sh" in n
) {
721 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
727 // try the network params as currently specified
729 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
732 return "Invalid root key";
737 function validateRootKeyGRS(rootKeyBase58
) {
738 // try various segwit network params since this extended key may be from
740 if (networkHasSegwit()) {
742 if ("baseNetwork" in n
) {
743 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
745 // try parsing using base network params
747 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
751 // try parsing using p2wpkh params
754 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
759 // try parsing using p2wpkh-in-p2sh network params
760 if ("p2wpkhInP2sh" in n
) {
762 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
768 // try the network params as currently specified
770 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
773 return "Invalid root key";
778 function getDerivationPath() {
779 if (bip44TabSelected()) {
780 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
781 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
782 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
783 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
785 path
+= purpose
+ "'/";
787 path
+= account
+ "'/";
789 DOM
.bip44path
.val(path
);
790 var derivationPath
= DOM
.bip44path
.val();
791 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
792 return derivationPath
;
794 else if (bip49TabSelected()) {
795 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
796 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
797 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
798 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
800 path
+= purpose
+ "'/";
802 path
+= account
+ "'/";
804 DOM
.bip49path
.val(path
);
805 var derivationPath
= DOM
.bip49path
.val();
806 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
807 return derivationPath
;
809 else if (bip84TabSelected()) {
810 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
811 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
812 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
813 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
815 path
+= purpose
+ "'/";
817 path
+= account
+ "'/";
819 DOM
.bip84path
.val(path
);
820 var derivationPath
= DOM
.bip84path
.val();
821 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
822 return derivationPath
;
824 else if (bip32TabSelected()) {
825 var derivationPath
= DOM
.bip32path
.val();
826 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
827 return derivationPath
;
829 else if (bip141TabSelected()) {
830 var derivationPath
= DOM
.bip141path
.val();
831 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
832 return derivationPath
;
835 console
.log("Unknown derivation path");
839 function findDerivationPathErrors(path
) {
840 // TODO is not perfect but is better than nothing
842 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
844 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
845 var maxDepth
= 255; // TODO verify this!!
846 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
847 if (path
[0] != "m") {
848 return "First character must be 'm'";
850 if (path
.length
> 1) {
851 if (path
[1] != "/") {
852 return "Separator must be '/'";
854 var indexes
= path
.split("/");
855 if (indexes
.length
> maxDepth
) {
856 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
858 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
859 var index
= indexes
[depth
];
860 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
861 if (invalidChars
.length
> 0) {
862 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
864 var indexValue
= parseInt(index
.replace("'", ""));
866 return "Invalid number at depth " + depth
;
868 if (indexValue
> maxIndexValue
) {
869 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
873 // Check root key exists or else derivation path is useless!
875 return "No root key";
877 // Check no hardened derivation path when using xpub keys
878 var hardenedPath
= path
.indexOf("'") > -1;
879 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
880 var hardened
= hardenedPath
|| hardenedAddresses
;
881 var isXpubkey
= bip32RootKey
.isNeutered();
882 if (hardened
&& isXpubkey
) {
883 return "Hardened derivation path is invalid with xpub key";
889 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
893 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
896 function displayBip44Info() {
897 // Get the derivation path for the account
898 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
899 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
900 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
902 path
+= purpose
+ "'/";
904 path
+= account
+ "'/";
905 // Calculate the account extended keys
906 var accountExtendedKey
= calcBip32ExtendedKey(path
);
907 var accountXprv
= accountExtendedKey
.toBase58();
908 var accountXpub
= accountExtendedKey
.neutered().toBase58();
910 // Display the extended keys
911 DOM
.bip44accountXprv
.val(accountXprv
);
912 DOM
.bip44accountXpub
.val(accountXpub
);
915 displayBip44InfoForELA();
919 function displayBip49Info() {
920 // Get the derivation path for the account
921 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
922 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
923 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
925 path
+= purpose
+ "'/";
927 path
+= account
+ "'/";
928 // Calculate the account extended keys
929 var accountExtendedKey
= calcBip32ExtendedKey(path
);
930 var accountXprv
= accountExtendedKey
.toBase58();
931 var accountXpub
= accountExtendedKey
.neutered().toBase58();
932 // Display the extended keys
933 DOM
.bip49accountXprv
.val(accountXprv
);
934 DOM
.bip49accountXpub
.val(accountXpub
);
937 function displayBip84Info() {
938 // Get the derivation path for the account
939 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
940 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
941 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
943 path
+= purpose
+ "'/";
945 path
+= account
+ "'/";
946 // Calculate the account extended keys
947 var accountExtendedKey
= calcBip32ExtendedKey(path
);
948 var accountXprv
= accountExtendedKey
.toBase58();
949 var accountXpub
= accountExtendedKey
.neutered().toBase58();
950 // Display the extended keys
951 DOM
.bip84accountXprv
.val(accountXprv
);
952 DOM
.bip84accountXpub
.val(accountXpub
);
955 function displayBip32Info() {
958 var rootKey
= bip32RootKey
.toBase58();
959 DOM
.rootKey
.val(rootKey
);
960 var xprvkeyB58
= "NA";
961 if (!bip32ExtendedKey
.isNeutered()) {
962 xprvkeyB58
= bip32ExtendedKey
.toBase58();
964 var extendedPrivKey
= xprvkeyB58
;
965 DOM
.extendedPrivKey
.val(extendedPrivKey
);
966 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
967 DOM
.extendedPubKey
.val(extendedPubKey
);
968 // Display the addresses and privkeys
969 clearAddressesList();
970 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
971 displayAddresses(0, initialAddressCount
);
974 displayBip32InfoForELA();
978 function displayAddresses(start
, total
) {
979 generationProcesses
.push(new (function() {
983 this.stop = function() {
984 for (var i
=0; i
<rows
.length
; i
++) {
985 rows
[i
].shouldGenerate
= false;
990 for (var i
=0; i
<total
; i
++) {
991 var index
= i
+ start
;
992 var isLast
= i
== total
- 1;
993 rows
.push(new TableRow(index
, isLast
));
999 function segwitSelected() {
1000 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
1003 function p2wpkhSelected() {
1004 return bip84TabSelected() ||
1005 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
1008 function p2wpkhInP2shSelected() {
1009 return bip49TabSelected() ||
1010 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
1013 function p2wshSelected() {
1014 return bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh";
1017 function p2wshInP2shSelected() {
1018 return (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh-p2sh");
1021 function TableRow(index
, isLast
) {
1024 this.shouldGenerate
= true;
1025 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
1026 var useBip38
= DOM
.useBip38
.prop("checked");
1027 var bip38password
= DOM
.bip38Password
.val();
1028 var isSegwit
= segwitSelected();
1029 var segwitAvailable
= networkHasSegwit();
1030 var isP2wpkh
= p2wpkhSelected();
1031 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
1032 var isP2wsh
= p2wshSelected();
1033 var isP2wshInP2sh
= p2wshInP2shSelected();
1039 function calculateValues() {
1040 setTimeout(function() {
1041 if (!self
.shouldGenerate
) {
1044 // derive HDkey for this row of the table
1046 if (useHardenedAddresses
) {
1047 key
= bip32ExtendedKey
.deriveHardened(index
);
1050 key
= bip32ExtendedKey
.derive(index
);
1052 // bip38 requires uncompressed keys
1053 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1054 var keyPair
= key
.keyPair
;
1055 var useUncompressed
= useBip38
;
1056 if (useUncompressed
) {
1057 keyPair
= new bitcoinjs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1059 keyPair
= new groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1063 var address
= keyPair
.getAddress().toString();
1065 var hasPrivkey
= !key
.isNeutered();
1068 privkey
= keyPair
.toWIF();
1069 // BIP38 encode private key if required
1072 privkey
= groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1073 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1074 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1076 privkey
= bitcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1077 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1082 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1083 var indexText
= getDerivationPath() + "/" + index
;
1084 if (useHardenedAddresses
) {
1085 indexText
= indexText
+ "'";
1087 // Ethereum values are different
1088 if (networkIsEthereum()) {
1089 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1090 privkey
= privKeyBuffer
.toString('hex');
1091 var addressBuffer
= ethUtil
.privateToAddress(privKeyBuffer
);
1092 var hexAddress
= addressBuffer
.toString('hex');
1093 var checksumAddress
= ethUtil
.toChecksumAddress(hexAddress
);
1094 address
= ethUtil
.addHexPrefix(checksumAddress
);
1095 privkey
= ethUtil
.addHexPrefix(privkey
);
1096 pubkey
= ethUtil
.addHexPrefix(pubkey
);
1099 // Stellar is different
1100 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1101 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1102 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1104 path
+= purpose
+ "'/";
1105 path
+= coin
+ "'/" + index
+ "'";
1106 var keypair
= stellarUtil
.getKeypair(path
, seed
);
1108 privkey
= keypair
.secret();
1109 pubkey
= address
= keypair
.publicKey();
1111 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1112 var NasAccount
= require("nebulas-account");
1113 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1114 var nebulasAccount
= new NasAccount();
1115 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1116 address
= nebulasAccount
.getAddressString();
1117 privkey
= nebulasAccount
.getPrivateKeyString();
1118 pubkey
= nebulasAccount
.getPublicKeyString();
1120 // Ripple values are different
1121 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1122 privkey
= convertRipplePriv(privkey
);
1123 address
= convertRippleAdrr(address
);
1125 // CasinoCoin values are different
1126 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1127 privkey
= convertCasinoCoinPriv(privkey
);
1128 address
= convertCasinoCoinAdrr(address
);
1130 // Bitcoin Cash address format may vary
1131 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1132 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1133 if (bchAddrType
== "cashaddr") {
1134 address
= bchaddr
.toCashAddress(address
);
1136 else if (bchAddrType
== "bitpay") {
1137 address
= bchaddr
.toBitpayAddress(address
);
1140 // Bitcoin Cash address format may vary
1141 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1142 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1143 if (bchAddrType
== "cashaddr") {
1144 address
= bchaddr
.toSlpAddress(address
);
1147 // Segwit addresses are different
1149 if (!segwitAvailable
) {
1153 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1154 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1155 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1157 else if (isP2wpkhInP2sh
) {
1158 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1159 var scriptsig
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1160 var addressbytes
= bitcoinjs
.bitcoin
.crypto
.hash160(scriptsig
);
1161 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1162 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1165 // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71
1167 var witnessScript
= bitcoinjs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1168 var scriptPubKey
= bitcoinjs
.bitcoin
.script
.witnessScriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.sha256(witnessScript
));
1169 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
);
1171 else if (isP2wshInP2sh
) {
1172 // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183
1174 var witnessScript
= bitcoinjs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1175 var redeemScript
= bitcoinjs
.bitcoin
.script
.witnessScriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.sha256(witnessScript
));
1176 var scriptPubKey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.hash160(redeemScript
));
1177 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
)
1181 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1182 address
= bitcoinjs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1185 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1187 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1188 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1191 //Groestlcoin Addresses are different
1195 if (!segwitAvailable
) {
1199 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1201 else if (isP2wpkhInP2sh
) {
1202 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1205 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1209 let elaAddress
= calcAddressForELA(
1211 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1212 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1213 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1216 address
= elaAddress
.address
;
1217 privkey
= elaAddress
.privateKey
;
1218 pubkey
= elaAddress
.publicKey
;
1221 addAddressToList(indexText
, address
, pubkey
, privkey
);
1233 function showMore() {
1234 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1235 if (isNaN(rowsToAdd
)) {
1237 DOM
.rowsToAdd
.val("20");
1239 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1241 start
= lastIndexInTable() + 1;
1244 var newStart
= start
+ rowsToAdd
;
1245 DOM
.moreRowsStartIndex
.val(newStart
);
1247 if (rowsToAdd
> 200) {
1248 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1249 msg
+= "Do you want to continue?";
1250 if (!confirm(msg
)) {
1254 displayAddresses(start
, rowsToAdd
);
1257 function clearDisplay() {
1258 clearAddressesList();
1260 hideValidationError();
1263 function clearAddressesList() {
1264 DOM
.addresses
.empty();
1269 function stopGenerating() {
1270 while (generationProcesses
.length
> 0) {
1271 var generation
= generationProcesses
.shift();
1276 function clearKeys() {
1281 function clearRootKey() {
1282 DOM
.rootKey
.val("");
1285 function clearDerivedKeys() {
1286 DOM
.extendedPrivKey
.val("");
1287 DOM
.extendedPubKey
.val("");
1288 DOM
.bip44accountXprv
.val("");
1289 DOM
.bip44accountXpub
.val("");
1292 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1293 var row
= $(addressRowTemplate
.html());
1295 var indexCell
= row
.find(".index span");
1296 var addressCell
= row
.find(".address span");
1297 var pubkeyCell
= row
.find(".pubkey span");
1298 var privkeyCell
= row
.find(".privkey span");
1300 indexCell
.text(indexText
);
1301 addressCell
.text(address
);
1302 pubkeyCell
.text(pubkey
);
1303 privkeyCell
.text(privkey
);
1306 indexCell
.addClass("invisible");
1309 addressCell
.addClass("invisible");
1312 pubkeyCell
.addClass("invisible");
1315 privkeyCell
.addClass("invisible");
1317 DOM
.addresses
.append(row
);
1318 var rowShowQrEls
= row
.find("[data-show-qr]");
1319 setQrEvents(rowShowQrEls
);
1322 function hasStrongRandom() {
1323 return 'crypto' in window
&& window
['crypto'] !== null;
1326 function disableForms() {
1327 $("form").on("submit", function(e
) {
1332 function parseIntNoNaN(val
, defaultVal
) {
1333 var v
= parseInt(val
);
1340 function showPending() {
1342 .text("Calculating...")
1346 function findNearestWord(word
) {
1347 var language
= getLanguage();
1348 var words
= WORDLISTS
[language
];
1349 var minDistance
= 99;
1350 var closestWord
= words
[0];
1351 for (var i
=0; i
<words
.length
; i
++) {
1352 var comparedTo
= words
[i
];
1353 if (comparedTo
.indexOf(word
) == 0) {
1356 var distance
= Levenshtein
.get(word
, comparedTo
);
1357 if (distance
< minDistance
) {
1358 closestWord
= comparedTo
;
1359 minDistance
= distance
;
1365 function hidePending() {
1371 function populateNetworkSelect() {
1372 for (var i
=0; i
<networks
.length
; i
++) {
1373 var network
= networks
[i
];
1374 var option
= $("<option>");
1375 option
.attr("value", i
);
1376 option
.text(network
.name
);
1377 if (network
.name
== "BTC - Bitcoin") {
1378 option
.prop("selected", true);
1380 DOM
.phraseNetwork
.append(option
);
1384 function populateClientSelect() {
1385 for (var i
=0; i
<clients
.length
; i
++) {
1386 var client
= clients
[i
];
1387 var option
= $("<option>");
1388 option
.attr("value", i
);
1389 option
.text(client
.name
);
1390 DOM
.bip32Client
.append(option
);
1394 function getLanguage() {
1395 var defaultLanguage
= "english";
1396 // Try to get from existing phrase
1397 var language
= getLanguageFromPhrase();
1398 // Try to get from url if not from phrase
1399 if (language
.length
== 0) {
1400 language
= getLanguageFromUrl();
1402 // Default to English if no other option
1403 if (language
.length
== 0) {
1404 language
= defaultLanguage
;
1409 function getLanguageFromPhrase(phrase
) {
1410 // Check if how many words from existing phrase match a language.
1413 phrase
= DOM
.phrase
.val();
1415 if (phrase
.length
> 0) {
1416 var words
= phraseToWordArray(phrase
);
1417 var languageMatches
= {};
1418 for (l
in WORDLISTS
) {
1419 // Track how many words match in this language
1420 languageMatches
[l
] = 0;
1421 for (var i
=0; i
<words
.length
; i
++) {
1422 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1423 if (wordInLanguage
) {
1424 languageMatches
[l
]++;
1427 // Find languages with most word matches.
1428 // This is made difficult due to commonalities between Chinese
1429 // simplified vs traditional.
1430 var mostMatches
= 0;
1431 var mostMatchedLanguages
= [];
1432 for (var l
in languageMatches
) {
1433 var numMatches
= languageMatches
[l
];
1434 if (numMatches
> mostMatches
) {
1435 mostMatches
= numMatches
;
1436 mostMatchedLanguages
= [l
];
1438 else if (numMatches
== mostMatches
) {
1439 mostMatchedLanguages
.push(l
);
1443 if (mostMatchedLanguages
.length
> 0) {
1444 // Use first language and warn if multiple detected
1445 language
= mostMatchedLanguages
[0];
1446 if (mostMatchedLanguages
.length
> 1) {
1447 console
.warn("Multiple possible languages");
1448 console
.warn(mostMatchedLanguages
);
1455 function getLanguageFromUrl() {
1456 for (var language
in WORDLISTS
) {
1457 if (window
.location
.hash
.indexOf(language
) > -1) {
1464 function setMnemonicLanguage() {
1465 var language
= getLanguage();
1466 // Load the bip39 mnemonic generator for this language if required
1467 if (!(language
in mnemonics
)) {
1468 mnemonics
[language
] = new Mnemonic(language
);
1470 mnemonic
= mnemonics
[language
];
1473 function convertPhraseToNewLanguage() {
1474 var oldLanguage
= getLanguageFromPhrase();
1475 var newLanguage
= getLanguageFromUrl();
1476 var oldPhrase
= DOM
.phrase
.val();
1477 var oldWords
= phraseToWordArray(oldPhrase
);
1479 for (var i
=0; i
<oldWords
.length
; i
++) {
1480 var oldWord
= oldWords
[i
];
1481 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1482 var newWord
= WORDLISTS
[newLanguage
][index
];
1483 newWords
.push(newWord
);
1485 newPhrase
= wordArrayToPhrase(newWords
);
1489 // TODO look at jsbip39 - mnemonic.splitWords
1490 function phraseToWordArray(phrase
) {
1491 var words
= phrase
.split(/\s/g);
1493 for (var i
=0; i
<words
.length
; i
++) {
1494 var word
= words
[i
];
1495 if (word
.length
> 0) {
1496 noBlanks
.push(word
);
1502 // TODO look at jsbip39 - mnemonic.joinWords
1503 function wordArrayToPhrase(words
) {
1504 var phrase
= words
.join(" ");
1505 var language
= getLanguageFromPhrase(phrase
);
1506 if (language
== "japanese") {
1507 phrase
= words
.join("\u3000");
1512 function writeSplitPhrase(phrase
) {
1513 var wordCount
= phrase
.split(/\s/g).length
;
1515 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1516 var group
=[[],[],[]],
1518 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1519 while (left
.length
>0) {
1520 groupI
=(groupI
+1)%3;
1521 seed
= seed
* 16807 % 2147483647;
1522 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1523 group
[groupI
].push(left
[selected
]);
1524 left
.splice(selected
,1);
1526 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1527 for (var i
=0;i
<3;i
++) {
1528 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1529 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1531 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1532 var triesPerSecond
=10000000000;
1533 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1534 var displayRedText
= false;
1536 hackTime
="<1 second";
1537 displayRedText
= true;
1538 } else if (hackTime
<86400) {
1539 hackTime
=Math
.floor(hackTime
)+" seconds";
1540 displayRedText
= true;
1541 } else if(hackTime
<31557600) {
1542 hackTime
=Math
.floor(hackTime
/86400)+" days";
1543 displayRedText
= true;
1545 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1547 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1548 if (displayRedText
) {
1549 DOM
.phraseSplitWarn
.addClass("text-danger");
1551 DOM
.phraseSplitWarn
.removeClass("text-danger");
1555 function isUsingOwnEntropy() {
1556 return DOM
.useEntropy
.prop("checked");
1559 function setMnemonicFromEntropy() {
1560 clearEntropyFeedback();
1561 // Get entropy value
1562 var entropyStr
= DOM
.entropy
.val();
1563 // Work out minimum base for entropy
1565 if (entropyTypeAutoDetect
) {
1566 entropy
= Entropy
.fromString(entropyStr
);
1569 let base
= DOM
.entropyTypeInputs
.filter(":checked").val();
1570 entropy
= Entropy
.fromString(entropyStr
, base
);
1572 if (entropy
.binaryStr
.length
== 0) {
1575 // Show entropy details
1576 showEntropyFeedback(entropy
);
1577 // Use entropy hash if not using raw entropy
1578 var bits
= entropy
.binaryStr
;
1579 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1580 if (mnemonicLength
!= "raw") {
1581 // Get bits by hashing entropy with SHA256
1582 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1583 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1584 bits
= BigInteger
.parse(hex
, 16).toString(2);
1585 while (bits
.length
% 256 != 0) {
1588 // Truncate hash to suit number of words
1589 mnemonicLength
= parseInt(mnemonicLength
);
1590 var numberOfBits
= 32 * mnemonicLength
/ 3;
1591 bits
= bits
.substring(0, numberOfBits
);
1592 // show warning for weak entropy override
1593 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1594 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1597 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1601 // hide warning for weak entropy override
1602 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1604 // Discard trailing entropy
1605 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1606 var start
= bits
.length
- bitsToUse
;
1607 var binaryStr
= bits
.substring(start
);
1608 // Convert entropy string to numeric array
1609 var entropyArr
= [];
1610 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1611 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1612 var entropyByte
= parseInt(byteAsBits
, 2);
1613 entropyArr
.push(entropyByte
)
1615 // Convert entropy array to mnemonic
1616 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1617 // Set the mnemonic in the UI
1618 DOM
.phrase
.val(phrase
);
1619 writeSplitPhrase(phrase
);
1620 // Show the word indexes
1622 // Show the checksum
1626 function clearEntropyFeedback() {
1627 DOM
.entropyCrackTime
.text("...");
1628 DOM
.entropyType
.text("");
1629 DOM
.entropyWordCount
.text("0");
1630 DOM
.entropyEventCount
.text("0");
1631 DOM
.entropyBitsPerEvent
.text("0");
1632 DOM
.entropyBits
.text("0");
1633 DOM
.entropyFiltered
.html(" ");
1634 DOM
.entropyBinary
.html(" ");
1637 function showEntropyFeedback(entropy
) {
1638 var numberOfBits
= entropy
.binaryStr
.length
;
1639 var timeToCrack
= "unknown";
1641 var z
= zxcvbn(entropy
.base
.parts
.join(""));
1642 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1643 if (z
.feedback
.warning
!= "") {
1644 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1648 console
.log("Error detecting entropy strength with zxcvbn:");
1651 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1652 DOM
.entropyTypeInputs
.attr("checked", false);
1653 DOM
.entropyTypeInputs
.filter("[value='" + entropyTypeStr
+ "']").attr("checked", true);
1654 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1655 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1656 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1657 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1658 DOM
.entropyType
.text(entropyTypeStr
);
1659 DOM
.entropyCrackTime
.text(timeToCrack
);
1660 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1661 DOM
.entropyBits
.text(numberOfBits
);
1662 DOM
.entropyWordCount
.text(wordCount
);
1663 DOM
.entropyBinary
.text(spacedBinaryStr
);
1664 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1665 // detect and warn of filtering
1666 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1667 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1668 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1670 DOM
.entropyFilterWarning
.removeClass('hidden');
1673 DOM
.entropyFilterWarning
.addClass('hidden');
1677 function getEntropyTypeStr(entropy
) {
1678 var typeStr
= entropy
.base
.str
;
1679 // Add some detail if these are cards
1680 if (entropy
.base
.asInt
== 52) {
1681 var cardDetail
= []; // array of message strings
1682 // Detect duplicates
1684 var dupeTracker
= {};
1685 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1686 var card
= entropy
.base
.parts
[i
];
1687 var cardUpper
= card
.toUpperCase();
1688 if (cardUpper
in dupeTracker
) {
1691 dupeTracker
[cardUpper
] = true;
1693 if (dupes
.length
> 0) {
1694 var dupeWord
= "duplicates";
1695 if (dupes
.length
== 1) {
1696 dupeWord
= "duplicate";
1698 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1699 if (dupes
.length
> 3) {
1702 cardDetail
.push(msg
);
1705 var uniqueCards
= [];
1706 for (var uniqueCard
in dupeTracker
) {
1707 uniqueCards
.push(uniqueCard
);
1709 if (uniqueCards
.length
== 52) {
1710 cardDetail
.unshift("full deck");
1712 // Detect missing cards
1713 var values
= "A23456789TJQK";
1715 var missingCards
= [];
1716 for (var i
=0; i
<suits
.length
; i
++) {
1717 for (var j
=0; j
<values
.length
; j
++) {
1718 var card
= values
[j
] + suits
[i
];
1719 if (!(card
in dupeTracker
)) {
1720 missingCards
.push(card
);
1724 // Display missing cards if six or less, ie clearly going for full deck
1725 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1726 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1727 if (missingCards
.length
> 3) {
1730 cardDetail
.push(msg
);
1732 // Add card details to typeStr
1733 if (cardDetail
.length
> 0) {
1734 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1740 function setQrEvents(els
) {
1741 els
.on("mouseenter", createQr
);
1742 els
.on("mouseleave", destroyQr
);
1743 els
.on("click", toggleQr
);
1746 function createQr(e
) {
1747 var content
= e
.target
.textContent
|| e
.target
.value
;
1755 DOM
.qrImage
.append(qrEl
);
1757 DOM
.qrHider
.addClass("hidden");
1760 DOM
.qrHider
.removeClass("hidden");
1762 DOM
.qrContainer
.removeClass("hidden");
1766 function destroyQr() {
1767 DOM
.qrImage
.text("");
1768 DOM
.qrContainer
.addClass("hidden");
1771 function toggleQr() {
1773 DOM
.qrHider
.toggleClass("hidden");
1774 DOM
.qrHint
.toggleClass("hidden");
1777 function bip44TabSelected() {
1778 return DOM
.bip44tab
.hasClass("active");
1781 function bip32TabSelected() {
1782 return DOM
.bip32tab
.hasClass("active");
1785 function networkIsEthereum() {
1786 var name
= networks
[DOM
.network
.val()].name
;
1787 return (name
== "ETH - Ethereum")
1788 || (name
== "ETC - Ethereum Classic")
1789 || (name
== "EWT - EnergyWeb")
1790 || (name
== "PIRL - Pirl")
1791 || (name
== "MIX - MIX")
1792 || (name
== "MUSIC - Musicoin")
1793 || (name
== "POA - Poa")
1794 || (name
== "EXP - Expanse")
1795 || (name
== "CLO - Callisto")
1796 || (name
== "DXN - DEXON")
1797 || (name
== "ELLA - Ellaism")
1798 || (name
== "ESN - Ethersocial Network")
1799 || (name
== "VET - VeChain")
1802 function networkHasSegwit() {
1804 if ("baseNetwork" in network
) {
1805 n
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1807 // check if only p2wpkh params are required
1808 if (p2wpkhSelected()) {
1809 return "p2wpkh" in n
;
1811 // check if only p2wpkh-in-p2sh params are required
1812 else if (p2wpkhInP2shSelected()) {
1813 return "p2wpkhInP2sh" in n
;
1815 // require both if it's unclear which params are required
1816 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1819 function bip49TabSelected() {
1820 return DOM
.bip49tab
.hasClass("active");
1823 function bip84TabSelected() {
1824 return DOM
.bip84tab
.hasClass("active");
1827 function bip141TabSelected() {
1828 return DOM
.bip141tab
.hasClass("active");
1831 function setHdCoin(coinValue
) {
1832 DOM
.bip44coin
.val(coinValue
);
1833 DOM
.bip49coin
.val(coinValue
);
1834 DOM
.bip84coin
.val(coinValue
);
1837 function showSegwitAvailable() {
1838 DOM
.bip49unavailable
.addClass("hidden");
1839 DOM
.bip49available
.removeClass("hidden");
1840 DOM
.bip84unavailable
.addClass("hidden");
1841 DOM
.bip84available
.removeClass("hidden");
1842 DOM
.bip141unavailable
.addClass("hidden");
1843 DOM
.bip141available
.removeClass("hidden");
1846 function showSegwitUnavailable() {
1847 DOM
.bip49available
.addClass("hidden");
1848 DOM
.bip49unavailable
.removeClass("hidden");
1849 DOM
.bip84available
.addClass("hidden");
1850 DOM
.bip84unavailable
.removeClass("hidden");
1851 DOM
.bip141available
.addClass("hidden");
1852 DOM
.bip141unavailable
.removeClass("hidden");
1855 function adjustNetworkForSegwit() {
1856 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1857 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1859 // See https://github.com/iancoleman/bip39/issues/125
1860 var segwitNetworks
= null;
1861 // if a segwit network is alread selected, need to use base network to
1862 // look up new parameters
1863 if ("baseNetwork" in network
) {
1864 network
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1866 // choose the right segwit params
1867 if (p2wpkhSelected() && "p2wpkh" in network
) {
1868 network
= network
.p2wpkh
;
1870 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1871 network
= network
.p2wpkhInP2sh
;
1873 else if (p2wshSelected() && "p2wsh" in network
) {
1874 network
= network
.p2wsh
;
1876 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network
) {
1877 network
= network
.p2wshInP2sh
;
1881 function lastIndexInTable() {
1882 var pathText
= DOM
.addresses
.find(".index").last().text();
1883 var pathBits
= pathText
.split("/");
1884 var lastBit
= pathBits
[pathBits
.length
-1];
1885 var lastBitClean
= lastBit
.replace("'", "");
1886 return parseInt(lastBitClean
);
1889 function uint8ArrayToHex(a
) {
1891 for (var i
=0; i
<a
.length
; i
++) {
1892 var h
= a
[i
].toString(16);
1893 while (h
.length
< 2) {
1901 function showWordIndexes() {
1902 var phrase
= DOM
.phrase
.val();
1903 var words
= phraseToWordArray(phrase
);
1904 var wordIndexes
= [];
1905 var language
= getLanguage();
1906 for (var i
=0; i
<words
.length
; i
++) {
1907 var word
= words
[i
];
1908 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1909 wordIndexes
.push(wordIndex
);
1911 var wordIndexesStr
= wordIndexes
.join(", ");
1912 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1915 function showChecksum() {
1916 var phrase
= DOM
.phrase
.val();
1917 var words
= phraseToWordArray(phrase
);
1918 var checksumBitlength
= words
.length
/ 3;
1921 var language
= getLanguage();
1922 for (var i
=words
.length
-1; i
>=0; i
--) {
1923 var word
= words
[i
];
1924 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1925 var wordBinary
= wordIndex
.toString(2);
1926 while (wordBinary
.length
< 11) {
1927 wordBinary
= "0" + wordBinary
;
1929 var binaryStr
= wordBinary
+ binaryStr
;
1930 if (binaryStr
.length
>= checksumBitlength
) {
1931 var start
= binaryStr
.length
- checksumBitlength
;
1932 var end
= binaryStr
.length
;
1933 checksum
= binaryStr
.substring(start
, end
);
1934 // add spaces so the last group is 11 bits, not the first
1935 checksum
= checksum
.split("").reverse().join("")
1936 checksum
= addSpacesEveryElevenBits(checksum
);
1937 checksum
= checksum
.split("").reverse().join("")
1941 DOM
.entropyChecksum
.text(checksum
);
1944 function updateCsv() {
1945 var tableCsv
= "path,address,public key,private key\n";
1946 var rows
= DOM
.addresses
.find("tr");
1947 for (var i
=0; i
<rows
.length
; i
++) {
1948 var row
= $(rows
[i
]);
1949 var cells
= row
.find("td");
1950 for (var j
=0; j
<cells
.length
; j
++) {
1951 var cell
= $(cells
[j
]);
1952 if (!cell
.children().hasClass("invisible")) {
1953 tableCsv
= tableCsv
+ cell
.text();
1955 if (j
!= cells
.length
- 1) {
1956 tableCsv
= tableCsv
+ ",";
1959 tableCsv
= tableCsv
+ "\n";
1961 DOM
.csv
.val(tableCsv
);
1964 function addSpacesEveryElevenBits(binaryStr
) {
1965 return binaryStr
.match(/.{1,11}/g).join(" ");
1970 name: "AC - Asiacoin",
1971 onSelect: function() {
1972 network
= bitcoinjs
.bitcoin
.networks
.asiacoin
;
1977 name: "ACC - Adcoin",
1978 onSelect: function() {
1979 network
= bitcoinjs
.bitcoin
.networks
.adcoin
;
1984 name: "ARYA - Aryacoin",
1985 onSelect: function() {
1986 network
= bitcoinjs
.bitcoin
.networks
.aryacoin
;
1991 name: "AUR - Auroracoin",
1992 onSelect: function() {
1993 network
= bitcoinjs
.bitcoin
.networks
.auroracoin
;
1999 onSelect: function() {
2000 network
= bitcoinjs
.bitcoin
.networks
.axe
;
2005 name: "ANON - ANON",
2006 onSelect: function() {
2007 network
= bitcoinjs
.bitcoin
.networks
.anon
;
2012 name: "BOLI - Bolivarcoin",
2013 onSelect: function() {
2014 network
= bitcoinjs
.bitcoin
.networks
.bolivarcoin
;
2019 name: "BCA - Bitcoin Atom",
2020 onSelect: function() {
2021 network
= bitcoinjs
.bitcoin
.networks
.atom
;
2026 name: "BCH - Bitcoin Cash",
2027 onSelect: function() {
2028 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2033 name: "BEET - Beetlecoin",
2034 onSelect: function() {
2035 network
= bitcoinjs
.bitcoin
.networks
.beetlecoin
;
2040 name: "BELA - Belacoin",
2041 onSelect: function() {
2042 network
= bitcoinjs
.bitcoin
.networks
.belacoin
;
2047 name: "BLK - BlackCoin",
2048 onSelect: function() {
2049 network
= bitcoinjs
.bitcoin
.networks
.blackcoin
;
2054 name: "BND - Blocknode",
2055 onSelect: function() {
2056 network
= bitcoinjs
.bitcoin
.networks
.blocknode
;
2061 name: "tBND - Blocknode Testnet",
2062 onSelect: function() {
2063 network
= bitcoinjs
.bitcoin
.networks
.blocknode_testnet
;
2068 name: "BRIT - Britcoin",
2069 onSelect: function() {
2070 network
= bitcoinjs
.bitcoin
.networks
.britcoin
;
2075 name: "BSD - Bitsend",
2076 onSelect: function() {
2077 network
= bitcoinjs
.bitcoin
.networks
.bitsend
;
2082 name: "BST - BlockStamp",
2083 onSelect: function() {
2084 network
= bitcoinjs
.bitcoin
.networks
.blockstamp
;
2090 onSelect: function() {
2091 network
= bitcoinjs
.bitcoin
.networks
.bata
;
2096 name: "BTC - Bitcoin",
2097 onSelect: function() {
2098 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2103 name: "BTC - Bitcoin Testnet",
2104 onSelect: function() {
2105 network
= bitcoinjs
.bitcoin
.networks
.testnet
;
2110 name: "BITG - Bitcoin Green",
2111 onSelect: function() {
2112 network
= bitcoinjs
.bitcoin
.networks
.bitcoingreen
;
2117 name: "BTCP - Bitcoin Private",
2118 onSelect: function() {
2119 network
= bitcoinjs
.bitcoin
.networks
.bitcoinprivate
;
2124 name: "BSV - BitcoinSV",
2125 onSelect: function() {
2126 network
= bitcoinjs
.bitcoin
.networks
.bitcoinsv
;
2131 name: "BTCZ - Bitcoinz",
2132 onSelect: function() {
2133 network
= bitcoinjs
.bitcoin
.networks
.bitcoinz
;
2138 name: "BTDX - BitCloud",
2139 onSelect: function() {
2140 network
= bitcoinjs
.bitcoin
.networks
.bitcloud
;
2145 name: "BTG - Bitcoin Gold",
2146 onSelect: function() {
2147 network
= bitcoinjs
.bitcoin
.networks
.bgold
;
2152 name: "BTX - Bitcore",
2153 onSelect: function() {
2154 network
= bitcoinjs
.bitcoin
.networks
.bitcore
;
2159 name: "CCN - Cannacoin",
2160 onSelect: function() {
2161 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2166 name: "CESC - Cryptoescudo",
2167 onSelect: function() {
2168 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2173 name: "CDN - Canadaecoin",
2174 onSelect: function() {
2175 network
= bitcoinjs
.bitcoin
.networks
.canadaecoin
;
2180 name: "CLAM - Clams",
2181 onSelect: function() {
2182 network
= bitcoinjs
.bitcoin
.networks
.clam
;
2187 name: "CLO - Callisto",
2188 segwitAvailable: false,
2189 onSelect: function() {
2190 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2195 name: "CLUB - Clubcoin",
2196 onSelect: function() {
2197 network
= bitcoinjs
.bitcoin
.networks
.clubcoin
;
2202 name: "CMP - Compcoin",
2203 onSelect: function() {
2204 network
= bitcoinjs
.bitcoin
.networks
.compcoin
;
2209 name: "CPU - CPUchain",
2210 onSelect: function() {
2211 network
= bitcoinjs
.bitcoin
.networks
.cpuchain
;
2216 name: "CRAVE - Crave",
2217 onSelect: function() {
2218 network
= bitcoinjs
.bitcoin
.networks
.crave
;
2223 name: "CRW - Crown (Legacy)",
2224 onSelect: function() {
2225 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2230 name: "CRW - Crown",
2231 onSelect: function() {
2232 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2237 name: "CSC - CasinoCoin",
2238 onSelect: function() {
2239 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2244 name: "DASH - Dash",
2245 onSelect: function() {
2246 network
= bitcoinjs
.bitcoin
.networks
.dash
;
2251 name: "DASH - Dash Testnet",
2252 onSelect: function() {
2253 network
= bitcoinjs
.bitcoin
.networks
.dashtn
;
2258 name: "DFC - Defcoin",
2259 onSelect: function() {
2260 network
= bitcoinjs
.bitcoin
.networks
.defcoin
;
2265 name: "DGB - Digibyte",
2266 onSelect: function() {
2267 network
= bitcoinjs
.bitcoin
.networks
.digibyte
;
2272 name: "DGC - Digitalcoin",
2273 onSelect: function() {
2274 network
= bitcoinjs
.bitcoin
.networks
.digitalcoin
;
2279 name: "DMD - Diamond",
2280 onSelect: function() {
2281 network
= bitcoinjs
.bitcoin
.networks
.diamond
;
2286 name: "DNR - Denarius",
2287 onSelect: function() {
2288 network
= bitcoinjs
.bitcoin
.networks
.denarius
;
2293 name: "DOGE - Dogecoin",
2294 onSelect: function() {
2295 network
= bitcoinjs
.bitcoin
.networks
.dogecoin
;
2300 name: "DOGEt - Dogecoin Testnet",
2301 onSelect: function() {
2302 network
= bitcoinjs
.bitcoin
.networks
.dogecointestnet
;
2307 name: "DXN - DEXON",
2308 onSelect: function() {
2309 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2314 name: "ECN - Ecoin",
2315 onSelect: function() {
2316 network
= bitcoinjs
.bitcoin
.networks
.ecoin
;
2321 name: "EDRC - Edrcoin",
2322 onSelect: function() {
2323 network
= bitcoinjs
.bitcoin
.networks
.edrcoin
;
2328 name: "EFL - Egulden",
2329 onSelect: function() {
2330 network
= bitcoinjs
.bitcoin
.networks
.egulden
;
2335 name: "ELA - Elastos",
2336 onSelect: function () {
2337 network
= bitcoinjs
.bitcoin
.networks
.elastos
;
2342 name: "ELLA - Ellaism",
2343 segwitAvailable: false,
2344 onSelect: function() {
2345 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2350 name: "EMC2 - Einsteinium",
2351 onSelect: function() {
2352 network
= bitcoinjs
.bitcoin
.networks
.einsteinium
;
2357 name: "ERC - Europecoin",
2358 onSelect: function() {
2359 network
= bitcoinjs
.bitcoin
.networks
.europecoin
;
2364 name: "EOS - EOSIO",
2365 onSelect: function() {
2366 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2371 name: "ESN - Ethersocial Network",
2372 segwitAvailable: false,
2373 onSelect: function() {
2374 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2379 name: "ETC - Ethereum Classic",
2380 segwitAvailable: false,
2381 onSelect: function() {
2382 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2387 name: "ETH - Ethereum",
2388 onSelect: function() {
2389 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2394 name: "EWT - EnergyWeb",
2395 onSelect: function() {
2396 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2401 name: "EXCL - Exclusivecoin",
2402 onSelect: function() {
2403 network
= bitcoinjs
.bitcoin
.networks
.exclusivecoin
;
2408 name: "EXCC - ExchangeCoin",
2409 onSelect: function() {
2410 network
= bitcoinjs
.bitcoin
.networks
.exchangecoin
;
2415 name: "EXP - Expanse",
2416 segwitAvailable: false,
2417 onSelect: function() {
2418 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2424 onSelect: function() {
2425 network
= bitcoinjs
.bitcoin
.networks
.fix
;
2430 name: "FIX - FIX Testnet",
2431 onSelect: function() {
2432 network
= bitcoinjs
.bitcoin
.networks
.fixtestnet
;
2437 name: "FJC - Fujicoin",
2438 onSelect: function() {
2439 network
= bitcoinjs
.bitcoin
.networks
.fujicoin
;
2444 name: "FLASH - Flashcoin",
2445 onSelect: function() {
2446 network
= bitcoinjs
.bitcoin
.networks
.flashcoin
;
2451 name: "FRST - Firstcoin",
2452 onSelect: function() {
2453 network
= bitcoinjs
.bitcoin
.networks
.firstcoin
;
2458 name: "FTC - Feathercoin",
2459 onSelect: function() {
2460 network
= bitcoinjs
.bitcoin
.networks
.feathercoin
;
2465 name: "GAME - GameCredits",
2466 onSelect: function() {
2467 network
= bitcoinjs
.bitcoin
.networks
.game
;
2472 name: "GBX - Gobyte",
2473 onSelect: function() {
2474 network
= bitcoinjs
.bitcoin
.networks
.gobyte
;
2479 name: "GCR - GCRCoin",
2480 onSelect: function() {
2481 network
= bitcoinjs
.bitcoin
.networks
.gcr
;
2486 name: "GRC - Gridcoin",
2487 onSelect: function() {
2488 network
= bitcoinjs
.bitcoin
.networks
.gridcoin
;
2493 name: "GRS - Groestlcoin",
2494 onSelect: function() {
2495 network
= bitcoinjs
.bitcoin
.networks
.groestlcoin
;
2500 name: "GRS - Groestlcoin Testnet",
2501 onSelect: function() {
2502 network
= bitcoinjs
.bitcoin
.networks
.groestlcointestnet
;
2507 name: "HNC - Helleniccoin",
2508 onSelect: function() {
2509 network
= bitcoinjs
.bitcoin
.networks
.helleniccoin
;
2514 name: "HUSH - Hush (Legacy)",
2515 onSelect: function() {
2516 network
= bitcoinjs
.bitcoin
.networks
.hush
;
2521 name: "HUSH - Hush3",
2522 onSelect: function() {
2523 network
= bitcoinjs
.bitcoin
.networks
.hush3
;
2528 name: "INSN - Insane",
2529 onSelect: function() {
2530 network
= bitcoinjs
.bitcoin
.networks
.insane
;
2536 onSelect: function() {
2537 network
= bitcoinjs
.bitcoin
.networks
.iop
;
2542 name: "IXC - Ixcoin",
2543 onSelect: function() {
2544 network
= bitcoinjs
.bitcoin
.networks
.ixcoin
;
2549 name: "JBS - Jumbucks",
2550 onSelect: function() {
2551 network
= bitcoinjs
.bitcoin
.networks
.jumbucks
;
2556 name: "KMD - Komodo",
2557 bip49available: false,
2558 onSelect: function() {
2559 network
= bitcoinjs
.bitcoin
.networks
.komodo
;
2564 name: "KOBO - Kobocoin",
2565 bip49available: false,
2566 onSelect: function() {
2567 network
= bitcoinjs
.bitcoin
.networks
.kobocoin
;
2572 name: "LBC - Library Credits",
2573 onSelect: function() {
2574 network
= bitcoinjs
.bitcoin
.networks
.lbry
;
2579 name: "LCC - Litecoincash",
2580 onSelect: function() {
2581 network
= bitcoinjs
.bitcoin
.networks
.litecoincash
;
2586 name: "LDCN - Landcoin",
2587 onSelect: function() {
2588 network
= bitcoinjs
.bitcoin
.networks
.landcoin
;
2593 name: "LINX - Linx",
2594 onSelect: function() {
2595 network
= bitcoinjs
.bitcoin
.networks
.linx
;
2600 name: "LKR - Lkrcoin",
2601 segwitAvailable: false,
2602 onSelect: function() {
2603 network
= bitcoinjs
.bitcoin
.networks
.lkrcoin
;
2608 name: "LTC - Litecoin",
2609 onSelect: function() {
2610 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
2612 DOM
.litecoinLtubContainer
.removeClass("hidden");
2616 name: "LTCt - Litecoin Testnet",
2617 onSelect: function() {
2618 network
= bitcoinjs
.bitcoin
.networks
.litecointestnet
;
2620 DOM
.litecoinLtubContainer
.removeClass("hidden");
2624 name: "LTZ - LitecoinZ",
2625 onSelect: function() {
2626 network
= bitcoinjs
.bitcoin
.networks
.litecoinz
;
2631 name: "LYNX - Lynx",
2632 onSelect: function() {
2633 network
= bitcoinjs
.bitcoin
.networks
.lynx
;
2638 name: "MAZA - Maza",
2639 onSelect: function() {
2640 network
= bitcoinjs
.bitcoin
.networks
.maza
;
2645 name: "MEC - Megacoin",
2646 onSelect: function() {
2647 network
= bitcoinjs
.bitcoin
.networks
.megacoin
;
2653 segwitAvailable: false,
2654 onSelect: function() {
2655 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2660 name: "MNX - Minexcoin",
2661 onSelect: function() {
2662 network
= bitcoinjs
.bitcoin
.networks
.minexcoin
;
2667 name: "MONA - Monacoin",
2668 onSelect: function() {
2669 network
= bitcoinjs
.bitcoin
.networks
.monacoin
,
2674 name: "MONK - Monkey Project",
2675 onSelect: function() {
2676 network
= bitcoinjs
.bitcoin
.networks
.monkeyproject
,
2681 name: "MUSIC - Musicoin",
2682 segwitAvailable: false,
2683 onSelect: function() {
2684 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2689 name: "NAV - Navcoin",
2690 onSelect: function() {
2691 network
= bitcoinjs
.bitcoin
.networks
.navcoin
;
2696 name: "NAS - Nebulas",
2697 onSelect: function() {
2698 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2703 name: "NEBL - Neblio",
2704 onSelect: function() {
2705 network
= bitcoinjs
.bitcoin
.networks
.neblio
;
2710 name: "NEOS - Neoscoin",
2711 onSelect: function() {
2712 network
= bitcoinjs
.bitcoin
.networks
.neoscoin
;
2717 name: "NIX - NIX Platform",
2718 onSelect: function() {
2719 network
= bitcoinjs
.bitcoin
.networks
.nix
;
2724 name: "NLG - Gulden",
2725 onSelect: function() {
2726 network
= bitcoinjs
.bitcoin
.networks
.gulden
;
2731 name: "NMC - Namecoin",
2732 onSelect: function() {
2733 network
= bitcoinjs
.bitcoin
.networks
.namecoin
;
2738 name: "NRG - Energi",
2739 onSelect: function() {
2740 network
= bitcoinjs
.bitcoin
.networks
.energi
;
2745 name: "NRO - Neurocoin",
2746 onSelect: function() {
2747 network
= bitcoinjs
.bitcoin
.networks
.neurocoin
;
2752 name: "NSR - Nushares",
2753 onSelect: function() {
2754 network
= bitcoinjs
.bitcoin
.networks
.nushares
;
2759 name: "NYC - Newyorkc",
2760 onSelect: function() {
2761 network
= bitcoinjs
.bitcoin
.networks
.newyorkc
;
2766 name: "NVC - Novacoin",
2767 onSelect: function() {
2768 network
= bitcoinjs
.bitcoin
.networks
.novacoin
;
2773 name: "OK - Okcash",
2774 onSelect: function() {
2775 network
= bitcoinjs
.bitcoin
.networks
.okcash
;
2780 name: "OMNI - Omnicore",
2781 onSelect: function() {
2782 network
= bitcoinjs
.bitcoin
.networks
.omnicore
;
2787 name: "ONION - DeepOnion",
2788 onSelect: function() {
2789 network
= bitcoinjs
.bitcoin
.networks
.deeponion
;
2794 name: "ONX - Onixcoin",
2795 onSelect: function() {
2796 network
= bitcoinjs
.bitcoin
.networks
.onixcoin
;
2801 name: "PHR - Phore",
2802 onSelect: function() {
2803 network
= bitcoinjs
.bitcoin
.networks
.phore
;
2808 name: "PINK - Pinkcoin",
2809 onSelect: function() {
2810 network
= bitcoinjs
.bitcoin
.networks
.pinkcoin
;
2815 name: "PIRL - Pirl",
2816 segwitAvailable: false,
2817 onSelect: function() {
2818 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2823 name: "PIVX - PIVX",
2824 onSelect: function() {
2825 network
= bitcoinjs
.bitcoin
.networks
.pivx
;
2830 name: "PIVX - PIVX Testnet",
2831 onSelect: function() {
2832 network
= bitcoinjs
.bitcoin
.networks
.pivxtestnet
;
2838 segwitAvailable: false,
2839 onSelect: function() {
2840 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2845 name: "POSW - POSWcoin",
2846 onSelect: function() {
2847 network
= bitcoinjs
.bitcoin
.networks
.poswcoin
;
2852 name: "POT - Potcoin",
2853 onSelect: function() {
2854 network
= bitcoinjs
.bitcoin
.networks
.potcoin
;
2859 name: "PPC - Peercoin",
2860 onSelect: function() {
2861 network
= bitcoinjs
.bitcoin
.networks
.peercoin
;
2866 name: "PRJ - ProjectCoin",
2867 onSelect: function() {
2868 network
= bitcoinjs
.bitcoin
.networks
.projectcoin
;
2873 name: "PSB - Pesobit",
2874 onSelect: function() {
2875 network
= bitcoinjs
.bitcoin
.networks
.pesobit
;
2880 name: "PUT - Putincoin",
2881 onSelect: function() {
2882 network
= bitcoinjs
.bitcoin
.networks
.putincoin
;
2887 name: "RPD - Rapids",
2888 onSelect: function() {
2889 network
= bitcoinjs
.bitcoin
.networks
.rapids
;
2894 name: "RVN - Ravencoin",
2895 onSelect: function() {
2896 network
= bitcoinjs
.bitcoin
.networks
.ravencoin
;
2901 name: "RBY - Rubycoin",
2902 onSelect: function() {
2903 network
= bitcoinjs
.bitcoin
.networks
.rubycoin
;
2908 name: "RDD - Reddcoin",
2909 onSelect: function() {
2910 network
= bitcoinjs
.bitcoin
.networks
.reddcoin
;
2915 name: "RVR - RevolutionVR",
2916 onSelect: function() {
2917 network
= bitcoinjs
.bitcoin
.networks
.revolutionvr
;
2922 name: "SAFE - Safecoin",
2923 onSelect: function() {
2924 network
= bitcoinjs
.bitcoin
.networks
.safecoin
;
2929 name: "SLS - Salus",
2930 onSelect: function() {
2931 network
= bitcoinjs
.bitcoin
.networks
.salus
;
2936 name: "SDC - ShadowCash",
2937 onSelect: function() {
2938 network
= bitcoinjs
.bitcoin
.networks
.shadow
;
2943 name: "SDC - ShadowCash Testnet",
2944 onSelect: function() {
2945 network
= bitcoinjs
.bitcoin
.networks
.shadowtn
;
2950 name: "SLM - Slimcoin",
2951 onSelect: function() {
2952 network
= bitcoinjs
.bitcoin
.networks
.slimcoin
;
2957 name: "SLM - Slimcoin Testnet",
2958 onSelect: function() {
2959 network
= bitcoinjs
.bitcoin
.networks
.slimcointn
;
2964 name: "SLP - Simple Ledger Protocol",
2965 onSelect: function() {
2966 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2971 name: "SLR - Solarcoin",
2972 onSelect: function() {
2973 network
= bitcoinjs
.bitcoin
.networks
.solarcoin
;
2978 name: "SMLY - Smileycoin",
2979 onSelect: function() {
2980 network
= bitcoinjs
.bitcoin
.networks
.smileycoin
;
2985 name: "STASH - Stash",
2986 onSelect: function() {
2987 network
= bitcoinjs
.bitcoin
.networks
.stash
;
2992 name: "STASH - Stash Testnet",
2993 onSelect: function() {
2994 network
= bitcoinjs
.bitcoin
.networks
.stashtn
;
2999 name: "STRAT - Stratis",
3000 onSelect: function() {
3001 network
= bitcoinjs
.bitcoin
.networks
.stratis
;
3006 name: "TSTRAT - Stratis Testnet",
3007 onSelect: function() {
3008 network
= bitcoinjs
.bitcoin
.networks
.stratistest
;
3013 name: "SYS - Syscoin",
3014 onSelect: function() {
3015 network
= bitcoinjs
.bitcoin
.networks
.syscoin
;
3020 name: "THC - Hempcoin",
3021 onSelect: function() {
3022 network
= bitcoinjs
.bitcoin
.networks
.hempcoin
;
3027 name: "THT - Thought",
3028 onSelect: function() {
3029 network
= bitcoinjs
.bitcoin
.networks
.thought
;
3035 onSelect: function() {
3036 network
= bitcoinjs
.bitcoin
.networks
.toa
;
3041 name: "TWINS - TWINS",
3042 onSelect: function() {
3043 network
= bitcoinjs
.bitcoin
.networks
.twins
;
3048 name: "TWINS - TWINS Testnet",
3049 onSelect: function() {
3050 network
= bitcoinjs
.bitcoin
.networks
.twinstestnet
;
3055 name: "USC - Ultimatesecurecash",
3056 onSelect: function() {
3057 network
= bitcoinjs
.bitcoin
.networks
.ultimatesecurecash
;
3062 name: "USNBT - NuBits",
3063 onSelect: function() {
3064 network
= bitcoinjs
.bitcoin
.networks
.nubits
;
3069 name: "UNO - Unobtanium",
3070 onSelect: function() {
3071 network
= bitcoinjs
.bitcoin
.networks
.unobtanium
;
3076 name: "VASH - Vpncoin",
3077 onSelect: function() {
3078 network
= bitcoinjs
.bitcoin
.networks
.vpncoin
;
3083 name: "VET - VeChain",
3084 onSelect: function() {
3085 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3090 name: "VIA - Viacoin",
3091 onSelect: function() {
3092 network
= bitcoinjs
.bitcoin
.networks
.viacoin
;
3097 name: "VIA - Viacoin Testnet",
3098 onSelect: function() {
3099 network
= bitcoinjs
.bitcoin
.networks
.viacointestnet
;
3104 name: "VIVO - Vivo",
3105 onSelect: function() {
3106 network
= bitcoinjs
.bitcoin
.networks
.vivo
;
3111 name: "VTC - Vertcoin",
3112 onSelect: function() {
3113 network
= bitcoinjs
.bitcoin
.networks
.vertcoin
;
3118 name: "WGR - Wagerr",
3119 onSelect: function() {
3120 network
= bitcoinjs
.bitcoin
.networks
.wagerr
;
3125 name: "WC - Wincoin",
3126 onSelect: function() {
3127 network
= bitcoinjs
.bitcoin
.networks
.wincoin
;
3132 name: "XAX - Artax",
3133 onSelect: function() {
3134 network
= bitcoinjs
.bitcoin
.networks
.artax
;
3139 name: "XBC - Bitcoinplus",
3140 onSelect: function() {
3141 network
= bitcoinjs
.bitcoin
.networks
.bitcoinplus
;
3146 name: "XLM - Stellar",
3147 onSelect: function() {
3148 network
= stellarUtil
.dummyNetwork
;
3153 name: "XMY - Myriadcoin",
3154 onSelect: function() {
3155 network
= bitcoinjs
.bitcoin
.networks
.myriadcoin
;
3160 name: "XRP - Ripple",
3161 onSelect: function() {
3162 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3167 name: "XVC - Vcash",
3168 onSelect: function() {
3169 network
= bitcoinjs
.bitcoin
.networks
.vcash
;
3174 name: "XVG - Verge",
3175 onSelect: function() {
3176 network
= bitcoinjs
.bitcoin
.networks
.verge
;
3181 name: "XUEZ - Xuez",
3182 segwitAvailable: false,
3183 onSelect: function() {
3184 network
= bitcoinjs
.bitcoin
.networks
.xuez
;
3189 name: "XWC - Whitecoin",
3190 onSelect: function() {
3191 network
= bitcoinjs
.bitcoin
.networks
.whitecoin
;
3196 name: "XZC - Zcoin",
3197 onSelect: function() {
3198 network
= bitcoinjs
.bitcoin
.networks
.zcoin
;
3203 name: "ZCL - Zclassic",
3204 onSelect: function() {
3205 network
= bitcoinjs
.bitcoin
.networks
.zclassic
;
3210 name: "ZEC - Zcash",
3211 onSelect: function() {
3212 network
= bitcoinjs
.bitcoin
.networks
.zcash
;
3217 name: "ZEN - Horizen",
3218 onSelect: function() {
3219 network
= bitcoinjs
.bitcoin
.networks
.zencash
;
3227 name: "Bitcoin Core",
3228 onSelect: function() {
3229 DOM
.bip32path
.val("m/0'/0'");
3230 DOM
.hardenedAddresses
.prop('checked', true);
3234 name: "blockchain.info",
3235 onSelect: function() {
3236 DOM
.bip32path
.val("m/44'/0'/0'");
3237 DOM
.hardenedAddresses
.prop('checked', false);
3241 name: "MultiBit HD",
3242 onSelect: function() {
3243 DOM
.bip32path
.val("m/0'/0");
3244 DOM
.hardenedAddresses
.prop('checked', false);
3248 name: "Coinomi, Ledger",
3249 onSelect: function() {
3250 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3251 DOM
.hardenedAddresses
.prop('checked', false);
3256 // ELA - Elastos functions - begin
3257 function displayBip44InfoForELA() {
3262 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3263 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3265 // Calculate the account extended keys
3266 var accountXprv
= elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3267 var accountXpub
= elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3269 // Display the extended keys
3270 DOM
.bip44accountXprv
.val(accountXprv
);
3271 DOM
.bip44accountXpub
.val(accountXpub
);
3274 function displayBip32InfoForELA() {
3279 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3280 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3281 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3283 DOM
.extendedPrivKey
.val(elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3284 DOM
.extendedPubKey
.val(elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3286 // Display the addresses and privkeys
3287 clearAddressesList();
3288 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3289 displayAddresses(0, initialAddressCount
);
3292 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3297 var publicKey
= elastosjs
.getDerivedPublicKey(elastosjs
.getMasterPublicKey(seed
), change
, index
);
3299 privateKey: elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3300 publicKey: publicKey
,
3301 address: elastosjs
.getAddress(publicKey
.toString('hex'))
3304 // ELA - Elastos functions - end