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
);
542 // try parsing using p2wsh network params
545 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
550 // try parsing using p2wsh-in-p2sh network params
551 if ("p2wshInP2sh" in n
) {
553 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
559 // try the network params as currently specified
560 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
563 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
564 // try parsing with various segwit network params since this extended
565 // key may be from any one of them.
566 if (networkHasSegwit()) {
568 if ("baseNetwork" in n
) {
569 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
571 // try parsing using base network params
573 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
577 // try parsing using p2wpkh params
580 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
585 // try parsing using p2wpkh-in-p2sh network params
586 if ("p2wpkhInP2sh" in n
) {
588 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
594 // try the network params as currently specified
595 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
598 function calcBip32ExtendedKey(path
) {
599 // Check there's a root key to derive from
603 var extendedKey
= bip32RootKey
;
604 // Derive the key from the path
605 var pathBits
= path
.split("/");
606 for (var i
=0; i
<pathBits
.length
; i
++) {
607 var bit
= pathBits
[i
];
608 var index
= parseInt(bit
);
612 var hardened
= bit
[bit
.length
-1] == "'";
613 var isPriv
= !(extendedKey
.isNeutered());
614 var invalidDerivationPath
= hardened
&& !isPriv
;
615 if (invalidDerivationPath
) {
619 extendedKey
= extendedKey
.deriveHardened(index
);
622 extendedKey
= extendedKey
.derive(index
);
628 function showValidationError(errorText
) {
634 function hideValidationError() {
640 function findPhraseErrors(phrase
) {
641 // Preprocess the words
642 phrase
= mnemonic
.normalizeString(phrase
);
643 var words
= phraseToWordArray(phrase
);
644 // Detect blank phrase
645 if (words
.length
== 0) {
646 return "Blank mnemonic";
649 for (var i
=0; i
<words
.length
; i
++) {
651 var language
= getLanguage();
652 if (WORDLISTS
[language
].indexOf(word
) == -1) {
653 console
.log("Finding closest match to " + word
);
654 var nearestWord
= findNearestWord(word
);
655 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
658 // Check the words are valid
659 var properPhrase
= wordArrayToPhrase(words
);
660 var isValid
= mnemonic
.check(properPhrase
);
662 return "Invalid mnemonic";
667 function validateRootKey(rootKeyBase58
) {
669 return validateRootKeyGRS(rootKeyBase58
);
671 // try various segwit network params since this extended key may be from
673 if (networkHasSegwit()) {
675 if ("baseNetwork" in n
) {
676 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
678 // try parsing using base network params
680 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
684 // try parsing using p2wpkh params
687 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
692 // try parsing using p2wpkh-in-p2sh network params
693 if ("p2wpkhInP2sh" in n
) {
695 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
700 // try parsing using p2wsh network params
703 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
708 // try parsing using p2wsh-in-p2sh network params
709 if ("p2wshInP2sh" in n
) {
711 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
717 // try the network params as currently specified
719 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
722 return "Invalid root key";
727 function validateRootKeyGRS(rootKeyBase58
) {
728 // try various segwit network params since this extended key may be from
730 if (networkHasSegwit()) {
732 if ("baseNetwork" in n
) {
733 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
735 // try parsing using base network params
737 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
741 // try parsing using p2wpkh params
744 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
749 // try parsing using p2wpkh-in-p2sh network params
750 if ("p2wpkhInP2sh" in n
) {
752 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
758 // try the network params as currently specified
760 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
763 return "Invalid root key";
768 function getDerivationPath() {
769 if (bip44TabSelected()) {
770 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
771 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
772 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
773 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
775 path
+= purpose
+ "'/";
777 path
+= account
+ "'/";
779 DOM
.bip44path
.val(path
);
780 var derivationPath
= DOM
.bip44path
.val();
781 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
782 return derivationPath
;
784 else if (bip49TabSelected()) {
785 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
786 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
787 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
788 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
790 path
+= purpose
+ "'/";
792 path
+= account
+ "'/";
794 DOM
.bip49path
.val(path
);
795 var derivationPath
= DOM
.bip49path
.val();
796 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
797 return derivationPath
;
799 else if (bip84TabSelected()) {
800 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
801 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
802 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
803 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
805 path
+= purpose
+ "'/";
807 path
+= account
+ "'/";
809 DOM
.bip84path
.val(path
);
810 var derivationPath
= DOM
.bip84path
.val();
811 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
812 return derivationPath
;
814 else if (bip32TabSelected()) {
815 var derivationPath
= DOM
.bip32path
.val();
816 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
817 return derivationPath
;
819 else if (bip141TabSelected()) {
820 var derivationPath
= DOM
.bip141path
.val();
821 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
822 return derivationPath
;
825 console
.log("Unknown derivation path");
829 function findDerivationPathErrors(path
) {
830 // TODO is not perfect but is better than nothing
832 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
834 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
835 var maxDepth
= 255; // TODO verify this!!
836 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
837 if (path
[0] != "m") {
838 return "First character must be 'm'";
840 if (path
.length
> 1) {
841 if (path
[1] != "/") {
842 return "Separator must be '/'";
844 var indexes
= path
.split("/");
845 if (indexes
.length
> maxDepth
) {
846 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
848 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
849 var index
= indexes
[depth
];
850 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
851 if (invalidChars
.length
> 0) {
852 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
854 var indexValue
= parseInt(index
.replace("'", ""));
856 return "Invalid number at depth " + depth
;
858 if (indexValue
> maxIndexValue
) {
859 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
863 // Check root key exists or else derivation path is useless!
865 return "No root key";
867 // Check no hardened derivation path when using xpub keys
868 var hardenedPath
= path
.indexOf("'") > -1;
869 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
870 var hardened
= hardenedPath
|| hardenedAddresses
;
871 var isXpubkey
= bip32RootKey
.isNeutered();
872 if (hardened
&& isXpubkey
) {
873 return "Hardened derivation path is invalid with xpub key";
879 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
883 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
886 function displayBip44Info() {
887 // Get the derivation path for the account
888 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
889 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
890 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
892 path
+= purpose
+ "'/";
894 path
+= account
+ "'/";
895 // Calculate the account extended keys
896 var accountExtendedKey
= calcBip32ExtendedKey(path
);
897 var accountXprv
= accountExtendedKey
.toBase58();
898 var accountXpub
= accountExtendedKey
.neutered().toBase58();
900 // Display the extended keys
901 DOM
.bip44accountXprv
.val(accountXprv
);
902 DOM
.bip44accountXpub
.val(accountXpub
);
905 displayBip44InfoForELA();
909 function displayBip49Info() {
910 // Get the derivation path for the account
911 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
912 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
913 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
915 path
+= purpose
+ "'/";
917 path
+= account
+ "'/";
918 // Calculate the account extended keys
919 var accountExtendedKey
= calcBip32ExtendedKey(path
);
920 var accountXprv
= accountExtendedKey
.toBase58();
921 var accountXpub
= accountExtendedKey
.neutered().toBase58();
922 // Display the extended keys
923 DOM
.bip49accountXprv
.val(accountXprv
);
924 DOM
.bip49accountXpub
.val(accountXpub
);
927 function displayBip84Info() {
928 // Get the derivation path for the account
929 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
930 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
931 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
933 path
+= purpose
+ "'/";
935 path
+= account
+ "'/";
936 // Calculate the account extended keys
937 var accountExtendedKey
= calcBip32ExtendedKey(path
);
938 var accountXprv
= accountExtendedKey
.toBase58();
939 var accountXpub
= accountExtendedKey
.neutered().toBase58();
940 // Display the extended keys
941 DOM
.bip84accountXprv
.val(accountXprv
);
942 DOM
.bip84accountXpub
.val(accountXpub
);
945 function displayBip32Info() {
948 var rootKey
= bip32RootKey
.toBase58();
949 DOM
.rootKey
.val(rootKey
);
950 var xprvkeyB58
= "NA";
951 if (!bip32ExtendedKey
.isNeutered()) {
952 xprvkeyB58
= bip32ExtendedKey
.toBase58();
954 var extendedPrivKey
= xprvkeyB58
;
955 DOM
.extendedPrivKey
.val(extendedPrivKey
);
956 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
957 DOM
.extendedPubKey
.val(extendedPubKey
);
958 // Display the addresses and privkeys
959 clearAddressesList();
960 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
961 displayAddresses(0, initialAddressCount
);
964 displayBip32InfoForELA();
968 function displayAddresses(start
, total
) {
969 generationProcesses
.push(new (function() {
973 this.stop = function() {
974 for (var i
=0; i
<rows
.length
; i
++) {
975 rows
[i
].shouldGenerate
= false;
980 for (var i
=0; i
<total
; i
++) {
981 var index
= i
+ start
;
982 var isLast
= i
== total
- 1;
983 rows
.push(new TableRow(index
, isLast
));
989 function segwitSelected() {
990 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
993 function p2wpkhSelected() {
994 return bip84TabSelected() ||
995 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
998 function p2wpkhInP2shSelected() {
999 return bip49TabSelected() ||
1000 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
1003 function p2wshSelected() {
1004 return bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh";
1007 function p2wshInP2shSelected() {
1008 return (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh-p2sh");
1011 function TableRow(index
, isLast
) {
1014 this.shouldGenerate
= true;
1015 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
1016 var useBip38
= DOM
.useBip38
.prop("checked");
1017 var bip38password
= DOM
.bip38Password
.val();
1018 var isSegwit
= segwitSelected();
1019 var segwitAvailable
= networkHasSegwit();
1020 var isP2wpkh
= p2wpkhSelected();
1021 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
1022 var isP2wsh
= p2wshSelected();
1023 var isP2wshInP2sh
= p2wshInP2shSelected();
1029 function calculateValues() {
1030 setTimeout(function() {
1031 if (!self
.shouldGenerate
) {
1034 // derive HDkey for this row of the table
1036 if (useHardenedAddresses
) {
1037 key
= bip32ExtendedKey
.deriveHardened(index
);
1040 key
= bip32ExtendedKey
.derive(index
);
1042 // bip38 requires uncompressed keys
1043 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1044 var keyPair
= key
.keyPair
;
1045 var useUncompressed
= useBip38
;
1046 if (useUncompressed
) {
1047 keyPair
= new bitcoinjs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1049 keyPair
= new groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1053 var address
= keyPair
.getAddress().toString();
1055 var hasPrivkey
= !key
.isNeutered();
1058 privkey
= keyPair
.toWIF();
1059 // BIP38 encode private key if required
1062 privkey
= groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1063 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1064 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1066 privkey
= bitcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1067 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1072 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1073 var indexText
= getDerivationPath() + "/" + index
;
1074 if (useHardenedAddresses
) {
1075 indexText
= indexText
+ "'";
1077 // Ethereum values are different
1078 if (networkIsEthereum()) {
1079 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1080 privkey
= privKeyBuffer
.toString('hex');
1081 var addressBuffer
= ethUtil
.privateToAddress(privKeyBuffer
);
1082 var hexAddress
= addressBuffer
.toString('hex');
1083 var checksumAddress
= ethUtil
.toChecksumAddress(hexAddress
);
1084 address
= ethUtil
.addHexPrefix(checksumAddress
);
1085 privkey
= ethUtil
.addHexPrefix(privkey
);
1086 pubkey
= ethUtil
.addHexPrefix(pubkey
);
1089 // Stellar is different
1090 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1091 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1092 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1094 path
+= purpose
+ "'/";
1095 path
+= coin
+ "'/" + index
+ "'";
1096 var keypair
= stellarUtil
.getKeypair(path
, seed
);
1098 privkey
= keypair
.secret();
1099 pubkey
= address
= keypair
.publicKey();
1101 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1102 var NasAccount
= require("nebulas-account");
1103 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1104 var nebulasAccount
= new NasAccount();
1105 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1106 address
= nebulasAccount
.getAddressString();
1107 privkey
= nebulasAccount
.getPrivateKeyString();
1108 pubkey
= nebulasAccount
.getPublicKeyString();
1110 // Ripple values are different
1111 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1112 privkey
= convertRipplePriv(privkey
);
1113 address
= convertRippleAdrr(address
);
1115 // CasinoCoin values are different
1116 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1117 privkey
= convertCasinoCoinPriv(privkey
);
1118 address
= convertCasinoCoinAdrr(address
);
1120 // Bitcoin Cash address format may vary
1121 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1122 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1123 if (bchAddrType
== "cashaddr") {
1124 address
= bchaddr
.toCashAddress(address
);
1126 else if (bchAddrType
== "bitpay") {
1127 address
= bchaddr
.toBitpayAddress(address
);
1130 // Bitcoin Cash address format may vary
1131 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1132 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1133 if (bchAddrType
== "cashaddr") {
1134 address
= bchaddr
.toSlpAddress(address
);
1137 // Segwit addresses are different
1139 if (!segwitAvailable
) {
1143 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1144 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1145 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1147 else if (isP2wpkhInP2sh
) {
1148 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1149 var scriptsig
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1150 var addressbytes
= bitcoinjs
.bitcoin
.crypto
.hash160(scriptsig
);
1151 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1152 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1158 else if (isP2wshInP2sh
) {
1164 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1165 address
= bitcoinjs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1168 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1170 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1171 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1174 //Groestlcoin Addresses are different
1178 if (!segwitAvailable
) {
1182 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1184 else if (isP2wpkhInP2sh
) {
1185 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1188 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1192 let elaAddress
= calcAddressForELA(
1194 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1195 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1196 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1199 address
= elaAddress
.address
;
1200 privkey
= elaAddress
.privateKey
;
1201 pubkey
= elaAddress
.publicKey
;
1204 addAddressToList(indexText
, address
, pubkey
, privkey
);
1216 function showMore() {
1217 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1218 if (isNaN(rowsToAdd
)) {
1220 DOM
.rowsToAdd
.val("20");
1222 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1224 start
= lastIndexInTable() + 1;
1227 var newStart
= start
+ rowsToAdd
;
1228 DOM
.moreRowsStartIndex
.val(newStart
);
1230 if (rowsToAdd
> 200) {
1231 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1232 msg
+= "Do you want to continue?";
1233 if (!confirm(msg
)) {
1237 displayAddresses(start
, rowsToAdd
);
1240 function clearDisplay() {
1241 clearAddressesList();
1243 hideValidationError();
1246 function clearAddressesList() {
1247 DOM
.addresses
.empty();
1252 function stopGenerating() {
1253 while (generationProcesses
.length
> 0) {
1254 var generation
= generationProcesses
.shift();
1259 function clearKeys() {
1264 function clearRootKey() {
1265 DOM
.rootKey
.val("");
1268 function clearDerivedKeys() {
1269 DOM
.extendedPrivKey
.val("");
1270 DOM
.extendedPubKey
.val("");
1271 DOM
.bip44accountXprv
.val("");
1272 DOM
.bip44accountXpub
.val("");
1275 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1276 var row
= $(addressRowTemplate
.html());
1278 var indexCell
= row
.find(".index span");
1279 var addressCell
= row
.find(".address span");
1280 var pubkeyCell
= row
.find(".pubkey span");
1281 var privkeyCell
= row
.find(".privkey span");
1283 indexCell
.text(indexText
);
1284 addressCell
.text(address
);
1285 pubkeyCell
.text(pubkey
);
1286 privkeyCell
.text(privkey
);
1289 indexCell
.addClass("invisible");
1292 addressCell
.addClass("invisible");
1295 pubkeyCell
.addClass("invisible");
1298 privkeyCell
.addClass("invisible");
1300 DOM
.addresses
.append(row
);
1301 var rowShowQrEls
= row
.find("[data-show-qr]");
1302 setQrEvents(rowShowQrEls
);
1305 function hasStrongRandom() {
1306 return 'crypto' in window
&& window
['crypto'] !== null;
1309 function disableForms() {
1310 $("form").on("submit", function(e
) {
1315 function parseIntNoNaN(val
, defaultVal
) {
1316 var v
= parseInt(val
);
1323 function showPending() {
1325 .text("Calculating...")
1329 function findNearestWord(word
) {
1330 var language
= getLanguage();
1331 var words
= WORDLISTS
[language
];
1332 var minDistance
= 99;
1333 var closestWord
= words
[0];
1334 for (var i
=0; i
<words
.length
; i
++) {
1335 var comparedTo
= words
[i
];
1336 if (comparedTo
.indexOf(word
) == 0) {
1339 var distance
= Levenshtein
.get(word
, comparedTo
);
1340 if (distance
< minDistance
) {
1341 closestWord
= comparedTo
;
1342 minDistance
= distance
;
1348 function hidePending() {
1354 function populateNetworkSelect() {
1355 for (var i
=0; i
<networks
.length
; i
++) {
1356 var network
= networks
[i
];
1357 var option
= $("<option>");
1358 option
.attr("value", i
);
1359 option
.text(network
.name
);
1360 if (network
.name
== "BTC - Bitcoin") {
1361 option
.prop("selected", true);
1363 DOM
.phraseNetwork
.append(option
);
1367 function populateClientSelect() {
1368 for (var i
=0; i
<clients
.length
; i
++) {
1369 var client
= clients
[i
];
1370 var option
= $("<option>");
1371 option
.attr("value", i
);
1372 option
.text(client
.name
);
1373 DOM
.bip32Client
.append(option
);
1377 function getLanguage() {
1378 var defaultLanguage
= "english";
1379 // Try to get from existing phrase
1380 var language
= getLanguageFromPhrase();
1381 // Try to get from url if not from phrase
1382 if (language
.length
== 0) {
1383 language
= getLanguageFromUrl();
1385 // Default to English if no other option
1386 if (language
.length
== 0) {
1387 language
= defaultLanguage
;
1392 function getLanguageFromPhrase(phrase
) {
1393 // Check if how many words from existing phrase match a language.
1396 phrase
= DOM
.phrase
.val();
1398 if (phrase
.length
> 0) {
1399 var words
= phraseToWordArray(phrase
);
1400 var languageMatches
= {};
1401 for (l
in WORDLISTS
) {
1402 // Track how many words match in this language
1403 languageMatches
[l
] = 0;
1404 for (var i
=0; i
<words
.length
; i
++) {
1405 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1406 if (wordInLanguage
) {
1407 languageMatches
[l
]++;
1410 // Find languages with most word matches.
1411 // This is made difficult due to commonalities between Chinese
1412 // simplified vs traditional.
1413 var mostMatches
= 0;
1414 var mostMatchedLanguages
= [];
1415 for (var l
in languageMatches
) {
1416 var numMatches
= languageMatches
[l
];
1417 if (numMatches
> mostMatches
) {
1418 mostMatches
= numMatches
;
1419 mostMatchedLanguages
= [l
];
1421 else if (numMatches
== mostMatches
) {
1422 mostMatchedLanguages
.push(l
);
1426 if (mostMatchedLanguages
.length
> 0) {
1427 // Use first language and warn if multiple detected
1428 language
= mostMatchedLanguages
[0];
1429 if (mostMatchedLanguages
.length
> 1) {
1430 console
.warn("Multiple possible languages");
1431 console
.warn(mostMatchedLanguages
);
1438 function getLanguageFromUrl() {
1439 for (var language
in WORDLISTS
) {
1440 if (window
.location
.hash
.indexOf(language
) > -1) {
1447 function setMnemonicLanguage() {
1448 var language
= getLanguage();
1449 // Load the bip39 mnemonic generator for this language if required
1450 if (!(language
in mnemonics
)) {
1451 mnemonics
[language
] = new Mnemonic(language
);
1453 mnemonic
= mnemonics
[language
];
1456 function convertPhraseToNewLanguage() {
1457 var oldLanguage
= getLanguageFromPhrase();
1458 var newLanguage
= getLanguageFromUrl();
1459 var oldPhrase
= DOM
.phrase
.val();
1460 var oldWords
= phraseToWordArray(oldPhrase
);
1462 for (var i
=0; i
<oldWords
.length
; i
++) {
1463 var oldWord
= oldWords
[i
];
1464 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1465 var newWord
= WORDLISTS
[newLanguage
][index
];
1466 newWords
.push(newWord
);
1468 newPhrase
= wordArrayToPhrase(newWords
);
1472 // TODO look at jsbip39 - mnemonic.splitWords
1473 function phraseToWordArray(phrase
) {
1474 var words
= phrase
.split(/\s/g);
1476 for (var i
=0; i
<words
.length
; i
++) {
1477 var word
= words
[i
];
1478 if (word
.length
> 0) {
1479 noBlanks
.push(word
);
1485 // TODO look at jsbip39 - mnemonic.joinWords
1486 function wordArrayToPhrase(words
) {
1487 var phrase
= words
.join(" ");
1488 var language
= getLanguageFromPhrase(phrase
);
1489 if (language
== "japanese") {
1490 phrase
= words
.join("\u3000");
1495 function writeSplitPhrase(phrase
) {
1496 var wordCount
= phrase
.split(/\s/g).length
;
1498 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1499 var group
=[[],[],[]],
1501 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1502 while (left
.length
>0) {
1503 groupI
=(groupI
+1)%3;
1504 seed
= seed
* 16807 % 2147483647;
1505 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1506 group
[groupI
].push(left
[selected
]);
1507 left
.splice(selected
,1);
1509 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1510 for (var i
=0;i
<3;i
++) {
1511 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1512 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1514 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1515 var triesPerSecond
=10000000000;
1516 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1517 var displayRedText
= false;
1519 hackTime
="<1 second";
1520 displayRedText
= true;
1521 } else if (hackTime
<86400) {
1522 hackTime
=Math
.floor(hackTime
)+" seconds";
1523 displayRedText
= true;
1524 } else if(hackTime
<31557600) {
1525 hackTime
=Math
.floor(hackTime
/86400)+" days";
1526 displayRedText
= true;
1528 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1530 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1531 if (displayRedText
) {
1532 DOM
.phraseSplitWarn
.addClass("text-danger");
1534 DOM
.phraseSplitWarn
.removeClass("text-danger");
1538 function isUsingOwnEntropy() {
1539 return DOM
.useEntropy
.prop("checked");
1542 function setMnemonicFromEntropy() {
1543 clearEntropyFeedback();
1544 // Get entropy value
1545 var entropyStr
= DOM
.entropy
.val();
1546 // Work out minimum base for entropy
1547 var entropy
= Entropy
.fromString(entropyStr
);
1548 if (entropy
.binaryStr
.length
== 0) {
1551 // Show entropy details
1552 showEntropyFeedback(entropy
);
1553 // Use entropy hash if not using raw entropy
1554 var bits
= entropy
.binaryStr
;
1555 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1556 if (mnemonicLength
!= "raw") {
1557 // Get bits by hashing entropy with SHA256
1558 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1559 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1560 bits
= BigInteger
.parse(hex
, 16).toString(2);
1561 while (bits
.length
% 256 != 0) {
1564 // Truncate hash to suit number of words
1565 mnemonicLength
= parseInt(mnemonicLength
);
1566 var numberOfBits
= 32 * mnemonicLength
/ 3;
1567 bits
= bits
.substring(0, numberOfBits
);
1568 // show warning for weak entropy override
1569 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1570 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1573 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1577 // hide warning for weak entropy override
1578 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1580 // Discard trailing entropy
1581 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1582 var start
= bits
.length
- bitsToUse
;
1583 var binaryStr
= bits
.substring(start
);
1584 // Convert entropy string to numeric array
1585 var entropyArr
= [];
1586 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1587 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1588 var entropyByte
= parseInt(byteAsBits
, 2);
1589 entropyArr
.push(entropyByte
)
1591 // Convert entropy array to mnemonic
1592 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1593 // Set the mnemonic in the UI
1594 DOM
.phrase
.val(phrase
);
1595 writeSplitPhrase(phrase
);
1596 // Show the word indexes
1598 // Show the checksum
1602 function clearEntropyFeedback() {
1603 DOM
.entropyCrackTime
.text("...");
1604 DOM
.entropyType
.text("");
1605 DOM
.entropyWordCount
.text("0");
1606 DOM
.entropyEventCount
.text("0");
1607 DOM
.entropyBitsPerEvent
.text("0");
1608 DOM
.entropyBits
.text("0");
1609 DOM
.entropyFiltered
.html(" ");
1610 DOM
.entropyBinary
.html(" ");
1613 function showEntropyFeedback(entropy
) {
1614 var numberOfBits
= entropy
.binaryStr
.length
;
1615 var timeToCrack
= "unknown";
1617 var z
= zxcvbn(entropy
.base
.parts
.join(""));
1618 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1619 if (z
.feedback
.warning
!= "") {
1620 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1624 console
.log("Error detecting entropy strength with zxcvbn:");
1627 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1628 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1629 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1630 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1631 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1632 DOM
.entropyType
.text(entropyTypeStr
);
1633 DOM
.entropyCrackTime
.text(timeToCrack
);
1634 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1635 DOM
.entropyBits
.text(numberOfBits
);
1636 DOM
.entropyWordCount
.text(wordCount
);
1637 DOM
.entropyBinary
.text(spacedBinaryStr
);
1638 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1639 // detect and warn of filtering
1640 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1641 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1642 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1644 DOM
.entropyFilterWarning
.removeClass('hidden');
1647 DOM
.entropyFilterWarning
.addClass('hidden');
1651 function getEntropyTypeStr(entropy
) {
1652 var typeStr
= entropy
.base
.str
;
1653 // Add some detail if these are cards
1654 if (entropy
.base
.asInt
== 52) {
1655 var cardDetail
= []; // array of message strings
1656 // Detect duplicates
1658 var dupeTracker
= {};
1659 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1660 var card
= entropy
.base
.parts
[i
];
1661 var cardUpper
= card
.toUpperCase();
1662 if (cardUpper
in dupeTracker
) {
1665 dupeTracker
[cardUpper
] = true;
1667 if (dupes
.length
> 0) {
1668 var dupeWord
= "duplicates";
1669 if (dupes
.length
== 1) {
1670 dupeWord
= "duplicate";
1672 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1673 if (dupes
.length
> 3) {
1676 cardDetail
.push(msg
);
1679 var uniqueCards
= [];
1680 for (var uniqueCard
in dupeTracker
) {
1681 uniqueCards
.push(uniqueCard
);
1683 if (uniqueCards
.length
== 52) {
1684 cardDetail
.unshift("full deck");
1686 // Detect missing cards
1687 var values
= "A23456789TJQK";
1689 var missingCards
= [];
1690 for (var i
=0; i
<suits
.length
; i
++) {
1691 for (var j
=0; j
<values
.length
; j
++) {
1692 var card
= values
[j
] + suits
[i
];
1693 if (!(card
in dupeTracker
)) {
1694 missingCards
.push(card
);
1698 // Display missing cards if six or less, ie clearly going for full deck
1699 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1700 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1701 if (missingCards
.length
> 3) {
1704 cardDetail
.push(msg
);
1706 // Add card details to typeStr
1707 if (cardDetail
.length
> 0) {
1708 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1714 function setQrEvents(els
) {
1715 els
.on("mouseenter", createQr
);
1716 els
.on("mouseleave", destroyQr
);
1717 els
.on("click", toggleQr
);
1720 function createQr(e
) {
1721 var content
= e
.target
.textContent
|| e
.target
.value
;
1729 DOM
.qrImage
.append(qrEl
);
1731 DOM
.qrHider
.addClass("hidden");
1734 DOM
.qrHider
.removeClass("hidden");
1736 DOM
.qrContainer
.removeClass("hidden");
1740 function destroyQr() {
1741 DOM
.qrImage
.text("");
1742 DOM
.qrContainer
.addClass("hidden");
1745 function toggleQr() {
1747 DOM
.qrHider
.toggleClass("hidden");
1748 DOM
.qrHint
.toggleClass("hidden");
1751 function bip44TabSelected() {
1752 return DOM
.bip44tab
.hasClass("active");
1755 function bip32TabSelected() {
1756 return DOM
.bip32tab
.hasClass("active");
1759 function networkIsEthereum() {
1760 var name
= networks
[DOM
.network
.val()].name
;
1761 return (name
== "ETH - Ethereum")
1762 || (name
== "ETC - Ethereum Classic")
1763 || (name
== "EWT - EnergyWeb")
1764 || (name
== "PIRL - Pirl")
1765 || (name
== "MIX - MIX")
1766 || (name
== "MUSIC - Musicoin")
1767 || (name
== "POA - Poa")
1768 || (name
== "EXP - Expanse")
1769 || (name
== "CLO - Callisto")
1770 || (name
== "DXN - DEXON")
1771 || (name
== "ELLA - Ellaism")
1772 || (name
== "ESN - Ethersocial Network")
1773 || (name
== "VET - VeChain")
1776 function networkHasSegwit() {
1778 if ("baseNetwork" in network
) {
1779 n
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1781 // check if only p2wpkh params are required
1782 if (p2wpkhSelected()) {
1783 return "p2wpkh" in n
;
1785 // check if only p2wpkh-in-p2sh params are required
1786 else if (p2wpkhInP2shSelected()) {
1787 return "p2wpkhInP2sh" in n
;
1789 // require both if it's unclear which params are required
1790 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1793 function bip49TabSelected() {
1794 return DOM
.bip49tab
.hasClass("active");
1797 function bip84TabSelected() {
1798 return DOM
.bip84tab
.hasClass("active");
1801 function bip141TabSelected() {
1802 return DOM
.bip141tab
.hasClass("active");
1805 function setHdCoin(coinValue
) {
1806 DOM
.bip44coin
.val(coinValue
);
1807 DOM
.bip49coin
.val(coinValue
);
1808 DOM
.bip84coin
.val(coinValue
);
1811 function showSegwitAvailable() {
1812 DOM
.bip49unavailable
.addClass("hidden");
1813 DOM
.bip49available
.removeClass("hidden");
1814 DOM
.bip84unavailable
.addClass("hidden");
1815 DOM
.bip84available
.removeClass("hidden");
1816 DOM
.bip141unavailable
.addClass("hidden");
1817 DOM
.bip141available
.removeClass("hidden");
1820 function showSegwitUnavailable() {
1821 DOM
.bip49available
.addClass("hidden");
1822 DOM
.bip49unavailable
.removeClass("hidden");
1823 DOM
.bip84available
.addClass("hidden");
1824 DOM
.bip84unavailable
.removeClass("hidden");
1825 DOM
.bip141available
.addClass("hidden");
1826 DOM
.bip141unavailable
.removeClass("hidden");
1829 function adjustNetworkForSegwit() {
1830 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1831 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1833 // See https://github.com/iancoleman/bip39/issues/125
1834 var segwitNetworks
= null;
1835 // if a segwit network is alread selected, need to use base network to
1836 // look up new parameters
1837 if ("baseNetwork" in network
) {
1838 network
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1840 // choose the right segwit params
1841 if (p2wpkhSelected() && "p2wpkh" in network
) {
1842 network
= network
.p2wpkh
;
1844 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1845 network
= network
.p2wpkhInP2sh
;
1847 else if (p2wshSelected() && "p2wsh" in network
) {
1848 network
= network
.p2wsh
;
1850 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network
) {
1851 network
= network
.p2wshInP2sh
;
1855 function lastIndexInTable() {
1856 var pathText
= DOM
.addresses
.find(".index").last().text();
1857 var pathBits
= pathText
.split("/");
1858 var lastBit
= pathBits
[pathBits
.length
-1];
1859 var lastBitClean
= lastBit
.replace("'", "");
1860 return parseInt(lastBitClean
);
1863 function uint8ArrayToHex(a
) {
1865 for (var i
=0; i
<a
.length
; i
++) {
1866 var h
= a
[i
].toString(16);
1867 while (h
.length
< 2) {
1875 function showWordIndexes() {
1876 var phrase
= DOM
.phrase
.val();
1877 var words
= phraseToWordArray(phrase
);
1878 var wordIndexes
= [];
1879 var language
= getLanguage();
1880 for (var i
=0; i
<words
.length
; i
++) {
1881 var word
= words
[i
];
1882 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1883 wordIndexes
.push(wordIndex
);
1885 var wordIndexesStr
= wordIndexes
.join(", ");
1886 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1889 function showChecksum() {
1890 var phrase
= DOM
.phrase
.val();
1891 var words
= phraseToWordArray(phrase
);
1892 var checksumBitlength
= words
.length
/ 3;
1895 var language
= getLanguage();
1896 for (var i
=words
.length
-1; i
>=0; i
--) {
1897 var word
= words
[i
];
1898 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1899 var wordBinary
= wordIndex
.toString(2);
1900 while (wordBinary
.length
< 11) {
1901 wordBinary
= "0" + wordBinary
;
1903 var binaryStr
= wordBinary
+ binaryStr
;
1904 if (binaryStr
.length
>= checksumBitlength
) {
1905 var start
= binaryStr
.length
- checksumBitlength
;
1906 var end
= binaryStr
.length
;
1907 checksum
= binaryStr
.substring(start
, end
);
1908 // add spaces so the last group is 11 bits, not the first
1909 checksum
= checksum
.split("").reverse().join("")
1910 checksum
= addSpacesEveryElevenBits(checksum
);
1911 checksum
= checksum
.split("").reverse().join("")
1915 DOM
.entropyChecksum
.text(checksum
);
1918 function updateCsv() {
1919 var tableCsv
= "path,address,public key,private key\n";
1920 var rows
= DOM
.addresses
.find("tr");
1921 for (var i
=0; i
<rows
.length
; i
++) {
1922 var row
= $(rows
[i
]);
1923 var cells
= row
.find("td");
1924 for (var j
=0; j
<cells
.length
; j
++) {
1925 var cell
= $(cells
[j
]);
1926 if (!cell
.children().hasClass("invisible")) {
1927 tableCsv
= tableCsv
+ cell
.text();
1929 if (j
!= cells
.length
- 1) {
1930 tableCsv
= tableCsv
+ ",";
1933 tableCsv
= tableCsv
+ "\n";
1935 DOM
.csv
.val(tableCsv
);
1938 function addSpacesEveryElevenBits(binaryStr
) {
1939 return binaryStr
.match(/.{1,11}/g).join(" ");
1944 name: "AC - Asiacoin",
1945 onSelect: function() {
1946 network
= bitcoinjs
.bitcoin
.networks
.asiacoin
;
1951 name: "ACC - Adcoin",
1952 onSelect: function() {
1953 network
= bitcoinjs
.bitcoin
.networks
.adcoin
;
1958 name: "ARYA - Aryacoin",
1959 onSelect: function() {
1960 network
= bitcoinjs
.bitcoin
.networks
.aryacoin
;
1965 name: "AUR - Auroracoin",
1966 onSelect: function() {
1967 network
= bitcoinjs
.bitcoin
.networks
.auroracoin
;
1973 onSelect: function() {
1974 network
= bitcoinjs
.bitcoin
.networks
.axe
;
1979 name: "ANON - ANON",
1980 onSelect: function() {
1981 network
= bitcoinjs
.bitcoin
.networks
.anon
;
1986 name: "BOLI - Bolivarcoin",
1987 onSelect: function() {
1988 network
= bitcoinjs
.bitcoin
.networks
.bolivarcoin
;
1993 name: "BCA - Bitcoin Atom",
1994 onSelect: function() {
1995 network
= bitcoinjs
.bitcoin
.networks
.atom
;
2000 name: "BCH - Bitcoin Cash",
2001 onSelect: function() {
2002 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2007 name: "BEET - Beetlecoin",
2008 onSelect: function() {
2009 network
= bitcoinjs
.bitcoin
.networks
.beetlecoin
;
2014 name: "BELA - Belacoin",
2015 onSelect: function() {
2016 network
= bitcoinjs
.bitcoin
.networks
.belacoin
;
2021 name: "BLK - BlackCoin",
2022 onSelect: function() {
2023 network
= bitcoinjs
.bitcoin
.networks
.blackcoin
;
2028 name: "BND - Blocknode",
2029 onSelect: function() {
2030 network
= bitcoinjs
.bitcoin
.networks
.blocknode
;
2035 name: "tBND - Blocknode Testnet",
2036 onSelect: function() {
2037 network
= bitcoinjs
.bitcoin
.networks
.blocknode_testnet
;
2042 name: "BRIT - Britcoin",
2043 onSelect: function() {
2044 network
= bitcoinjs
.bitcoin
.networks
.britcoin
;
2049 name: "BSD - Bitsend",
2050 onSelect: function() {
2051 network
= bitcoinjs
.bitcoin
.networks
.bitsend
;
2056 name: "BST - BlockStamp",
2057 onSelect: function() {
2058 network
= bitcoinjs
.bitcoin
.networks
.blockstamp
;
2064 onSelect: function() {
2065 network
= bitcoinjs
.bitcoin
.networks
.bata
;
2070 name: "BTC - Bitcoin",
2071 onSelect: function() {
2072 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2077 name: "BTC - Bitcoin Testnet",
2078 onSelect: function() {
2079 network
= bitcoinjs
.bitcoin
.networks
.testnet
;
2084 name: "BITG - Bitcoin Green",
2085 onSelect: function() {
2086 network
= bitcoinjs
.bitcoin
.networks
.bitcoingreen
;
2091 name: "BTCP - Bitcoin Private",
2092 onSelect: function() {
2093 network
= bitcoinjs
.bitcoin
.networks
.bitcoinprivate
;
2098 name: "BSV - BitcoinSV",
2099 onSelect: function() {
2100 network
= bitcoinjs
.bitcoin
.networks
.bitcoinsv
;
2105 name: "BTCZ - Bitcoinz",
2106 onSelect: function() {
2107 network
= bitcoinjs
.bitcoin
.networks
.bitcoinz
;
2112 name: "BTDX - BitCloud",
2113 onSelect: function() {
2114 network
= bitcoinjs
.bitcoin
.networks
.bitcloud
;
2119 name: "BTG - Bitcoin Gold",
2120 onSelect: function() {
2121 network
= bitcoinjs
.bitcoin
.networks
.bgold
;
2126 name: "BTX - Bitcore",
2127 onSelect: function() {
2128 network
= bitcoinjs
.bitcoin
.networks
.bitcore
;
2133 name: "CCN - Cannacoin",
2134 onSelect: function() {
2135 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2140 name: "CESC - Cryptoescudo",
2141 onSelect: function() {
2142 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2147 name: "CDN - Canadaecoin",
2148 onSelect: function() {
2149 network
= bitcoinjs
.bitcoin
.networks
.canadaecoin
;
2154 name: "CLAM - Clams",
2155 onSelect: function() {
2156 network
= bitcoinjs
.bitcoin
.networks
.clam
;
2161 name: "CLO - Callisto",
2162 segwitAvailable: false,
2163 onSelect: function() {
2164 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2169 name: "CLUB - Clubcoin",
2170 onSelect: function() {
2171 network
= bitcoinjs
.bitcoin
.networks
.clubcoin
;
2176 name: "CMP - Compcoin",
2177 onSelect: function() {
2178 network
= bitcoinjs
.bitcoin
.networks
.compcoin
;
2183 name: "CPU - CPUchain",
2184 onSelect: function() {
2185 network
= bitcoinjs
.bitcoin
.networks
.cpuchain
;
2190 name: "CRAVE - Crave",
2191 onSelect: function() {
2192 network
= bitcoinjs
.bitcoin
.networks
.crave
;
2197 name: "CRW - Crown (Legacy)",
2198 onSelect: function() {
2199 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2204 name: "CRW - Crown",
2205 onSelect: function() {
2206 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2211 name: "CSC - CasinoCoin",
2212 onSelect: function() {
2213 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2218 name: "DASH - Dash",
2219 onSelect: function() {
2220 network
= bitcoinjs
.bitcoin
.networks
.dash
;
2225 name: "DASH - Dash Testnet",
2226 onSelect: function() {
2227 network
= bitcoinjs
.bitcoin
.networks
.dashtn
;
2232 name: "DFC - Defcoin",
2233 onSelect: function() {
2234 network
= bitcoinjs
.bitcoin
.networks
.defcoin
;
2239 name: "DGB - Digibyte",
2240 onSelect: function() {
2241 network
= bitcoinjs
.bitcoin
.networks
.digibyte
;
2246 name: "DGC - Digitalcoin",
2247 onSelect: function() {
2248 network
= bitcoinjs
.bitcoin
.networks
.digitalcoin
;
2253 name: "DMD - Diamond",
2254 onSelect: function() {
2255 network
= bitcoinjs
.bitcoin
.networks
.diamond
;
2260 name: "DNR - Denarius",
2261 onSelect: function() {
2262 network
= bitcoinjs
.bitcoin
.networks
.denarius
;
2267 name: "DOGE - Dogecoin",
2268 onSelect: function() {
2269 network
= bitcoinjs
.bitcoin
.networks
.dogecoin
;
2274 name: "DOGEt - Dogecoin Testnet",
2275 onSelect: function() {
2276 network
= bitcoinjs
.bitcoin
.networks
.dogecointestnet
;
2281 name: "DXN - DEXON",
2282 onSelect: function() {
2283 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2288 name: "ECN - Ecoin",
2289 onSelect: function() {
2290 network
= bitcoinjs
.bitcoin
.networks
.ecoin
;
2295 name: "EDRC - Edrcoin",
2296 onSelect: function() {
2297 network
= bitcoinjs
.bitcoin
.networks
.edrcoin
;
2302 name: "EFL - Egulden",
2303 onSelect: function() {
2304 network
= bitcoinjs
.bitcoin
.networks
.egulden
;
2309 name: "ELA - Elastos",
2310 onSelect: function () {
2311 network
= bitcoinjs
.bitcoin
.networks
.elastos
;
2316 name: "ELLA - Ellaism",
2317 segwitAvailable: false,
2318 onSelect: function() {
2319 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2324 name: "EMC2 - Einsteinium",
2325 onSelect: function() {
2326 network
= bitcoinjs
.bitcoin
.networks
.einsteinium
;
2331 name: "ERC - Europecoin",
2332 onSelect: function() {
2333 network
= bitcoinjs
.bitcoin
.networks
.europecoin
;
2338 name: "EOS - EOSIO",
2339 onSelect: function() {
2340 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2345 name: "ESN - Ethersocial Network",
2346 segwitAvailable: false,
2347 onSelect: function() {
2348 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2353 name: "ETC - Ethereum Classic",
2354 segwitAvailable: false,
2355 onSelect: function() {
2356 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2361 name: "ETH - Ethereum",
2362 onSelect: function() {
2363 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2368 name: "EWT - EnergyWeb",
2369 onSelect: function() {
2370 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2375 name: "EXCL - Exclusivecoin",
2376 onSelect: function() {
2377 network
= bitcoinjs
.bitcoin
.networks
.exclusivecoin
;
2382 name: "EXCC - ExchangeCoin",
2383 onSelect: function() {
2384 network
= bitcoinjs
.bitcoin
.networks
.exchangecoin
;
2389 name: "EXP - Expanse",
2390 segwitAvailable: false,
2391 onSelect: function() {
2392 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2398 onSelect: function() {
2399 network
= bitcoinjs
.bitcoin
.networks
.fix
;
2404 name: "FIX - FIX Testnet",
2405 onSelect: function() {
2406 network
= bitcoinjs
.bitcoin
.networks
.fixtestnet
;
2411 name: "FJC - Fujicoin",
2412 onSelect: function() {
2413 network
= bitcoinjs
.bitcoin
.networks
.fujicoin
;
2418 name: "FLASH - Flashcoin",
2419 onSelect: function() {
2420 network
= bitcoinjs
.bitcoin
.networks
.flashcoin
;
2425 name: "FRST - Firstcoin",
2426 onSelect: function() {
2427 network
= bitcoinjs
.bitcoin
.networks
.firstcoin
;
2432 name: "FTC - Feathercoin",
2433 onSelect: function() {
2434 network
= bitcoinjs
.bitcoin
.networks
.feathercoin
;
2439 name: "GAME - GameCredits",
2440 onSelect: function() {
2441 network
= bitcoinjs
.bitcoin
.networks
.game
;
2446 name: "GBX - Gobyte",
2447 onSelect: function() {
2448 network
= bitcoinjs
.bitcoin
.networks
.gobyte
;
2453 name: "GCR - GCRCoin",
2454 onSelect: function() {
2455 network
= bitcoinjs
.bitcoin
.networks
.gcr
;
2460 name: "GRC - Gridcoin",
2461 onSelect: function() {
2462 network
= bitcoinjs
.bitcoin
.networks
.gridcoin
;
2467 name: "GRS - Groestlcoin",
2468 onSelect: function() {
2469 network
= bitcoinjs
.bitcoin
.networks
.groestlcoin
;
2474 name: "GRS - Groestlcoin Testnet",
2475 onSelect: function() {
2476 network
= bitcoinjs
.bitcoin
.networks
.groestlcointestnet
;
2481 name: "HNC - Helleniccoin",
2482 onSelect: function() {
2483 network
= bitcoinjs
.bitcoin
.networks
.helleniccoin
;
2488 name: "HUSH - Hush (Legacy)",
2489 onSelect: function() {
2490 network
= bitcoinjs
.bitcoin
.networks
.hush
;
2495 name: "HUSH - Hush3",
2496 onSelect: function() {
2497 network
= bitcoinjs
.bitcoin
.networks
.hush3
;
2502 name: "INSN - Insane",
2503 onSelect: function() {
2504 network
= bitcoinjs
.bitcoin
.networks
.insane
;
2510 onSelect: function() {
2511 network
= bitcoinjs
.bitcoin
.networks
.iop
;
2516 name: "IXC - Ixcoin",
2517 onSelect: function() {
2518 network
= bitcoinjs
.bitcoin
.networks
.ixcoin
;
2523 name: "JBS - Jumbucks",
2524 onSelect: function() {
2525 network
= bitcoinjs
.bitcoin
.networks
.jumbucks
;
2530 name: "KMD - Komodo",
2531 bip49available: false,
2532 onSelect: function() {
2533 network
= bitcoinjs
.bitcoin
.networks
.komodo
;
2538 name: "KOBO - Kobocoin",
2539 bip49available: false,
2540 onSelect: function() {
2541 network
= bitcoinjs
.bitcoin
.networks
.kobocoin
;
2546 name: "LBC - Library Credits",
2547 onSelect: function() {
2548 network
= bitcoinjs
.bitcoin
.networks
.lbry
;
2553 name: "LCC - Litecoincash",
2554 onSelect: function() {
2555 network
= bitcoinjs
.bitcoin
.networks
.litecoincash
;
2560 name: "LDCN - Landcoin",
2561 onSelect: function() {
2562 network
= bitcoinjs
.bitcoin
.networks
.landcoin
;
2567 name: "LINX - Linx",
2568 onSelect: function() {
2569 network
= bitcoinjs
.bitcoin
.networks
.linx
;
2574 name: "LKR - Lkrcoin",
2575 segwitAvailable: false,
2576 onSelect: function() {
2577 network
= bitcoinjs
.bitcoin
.networks
.lkrcoin
;
2582 name: "LTC - Litecoin",
2583 onSelect: function() {
2584 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
2586 DOM
.litecoinLtubContainer
.removeClass("hidden");
2590 name: "LTCt - Litecoin Testnet",
2591 onSelect: function() {
2592 network
= bitcoinjs
.bitcoin
.networks
.litecointestnet
;
2594 DOM
.litecoinLtubContainer
.removeClass("hidden");
2598 name: "LTZ - LitecoinZ",
2599 onSelect: function() {
2600 network
= bitcoinjs
.bitcoin
.networks
.litecoinz
;
2605 name: "LYNX - Lynx",
2606 onSelect: function() {
2607 network
= bitcoinjs
.bitcoin
.networks
.lynx
;
2612 name: "MAZA - Maza",
2613 onSelect: function() {
2614 network
= bitcoinjs
.bitcoin
.networks
.maza
;
2619 name: "MEC - Megacoin",
2620 onSelect: function() {
2621 network
= bitcoinjs
.bitcoin
.networks
.megacoin
;
2627 segwitAvailable: false,
2628 onSelect: function() {
2629 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2634 name: "MNX - Minexcoin",
2635 onSelect: function() {
2636 network
= bitcoinjs
.bitcoin
.networks
.minexcoin
;
2641 name: "MONA - Monacoin",
2642 onSelect: function() {
2643 network
= bitcoinjs
.bitcoin
.networks
.monacoin
,
2648 name: "MONK - Monkey Project",
2649 onSelect: function() {
2650 network
= bitcoinjs
.bitcoin
.networks
.monkeyproject
,
2655 name: "MUSIC - Musicoin",
2656 segwitAvailable: false,
2657 onSelect: function() {
2658 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2663 name: "NAV - Navcoin",
2664 onSelect: function() {
2665 network
= bitcoinjs
.bitcoin
.networks
.navcoin
;
2670 name: "NAS - Nebulas",
2671 onSelect: function() {
2672 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2677 name: "NEBL - Neblio",
2678 onSelect: function() {
2679 network
= bitcoinjs
.bitcoin
.networks
.neblio
;
2684 name: "NEOS - Neoscoin",
2685 onSelect: function() {
2686 network
= bitcoinjs
.bitcoin
.networks
.neoscoin
;
2691 name: "NIX - NIX Platform",
2692 onSelect: function() {
2693 network
= bitcoinjs
.bitcoin
.networks
.nix
;
2698 name: "NLG - Gulden",
2699 onSelect: function() {
2700 network
= bitcoinjs
.bitcoin
.networks
.gulden
;
2705 name: "NMC - Namecoin",
2706 onSelect: function() {
2707 network
= bitcoinjs
.bitcoin
.networks
.namecoin
;
2712 name: "NRG - Energi",
2713 onSelect: function() {
2714 network
= bitcoinjs
.bitcoin
.networks
.energi
;
2719 name: "NRO - Neurocoin",
2720 onSelect: function() {
2721 network
= bitcoinjs
.bitcoin
.networks
.neurocoin
;
2726 name: "NSR - Nushares",
2727 onSelect: function() {
2728 network
= bitcoinjs
.bitcoin
.networks
.nushares
;
2733 name: "NYC - Newyorkc",
2734 onSelect: function() {
2735 network
= bitcoinjs
.bitcoin
.networks
.newyorkc
;
2740 name: "NVC - Novacoin",
2741 onSelect: function() {
2742 network
= bitcoinjs
.bitcoin
.networks
.novacoin
;
2747 name: "OK - Okcash",
2748 onSelect: function() {
2749 network
= bitcoinjs
.bitcoin
.networks
.okcash
;
2754 name: "OMNI - Omnicore",
2755 onSelect: function() {
2756 network
= bitcoinjs
.bitcoin
.networks
.omnicore
;
2761 name: "ONION - DeepOnion",
2762 onSelect: function() {
2763 network
= bitcoinjs
.bitcoin
.networks
.deeponion
;
2768 name: "ONX - Onixcoin",
2769 onSelect: function() {
2770 network
= bitcoinjs
.bitcoin
.networks
.onixcoin
;
2775 name: "PHR - Phore",
2776 onSelect: function() {
2777 network
= bitcoinjs
.bitcoin
.networks
.phore
;
2782 name: "PINK - Pinkcoin",
2783 onSelect: function() {
2784 network
= bitcoinjs
.bitcoin
.networks
.pinkcoin
;
2789 name: "PIRL - Pirl",
2790 segwitAvailable: false,
2791 onSelect: function() {
2792 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2797 name: "PIVX - PIVX",
2798 onSelect: function() {
2799 network
= bitcoinjs
.bitcoin
.networks
.pivx
;
2804 name: "PIVX - PIVX Testnet",
2805 onSelect: function() {
2806 network
= bitcoinjs
.bitcoin
.networks
.pivxtestnet
;
2812 segwitAvailable: false,
2813 onSelect: function() {
2814 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2819 name: "POSW - POSWcoin",
2820 onSelect: function() {
2821 network
= bitcoinjs
.bitcoin
.networks
.poswcoin
;
2826 name: "POT - Potcoin",
2827 onSelect: function() {
2828 network
= bitcoinjs
.bitcoin
.networks
.potcoin
;
2833 name: "PPC - Peercoin",
2834 onSelect: function() {
2835 network
= bitcoinjs
.bitcoin
.networks
.peercoin
;
2840 name: "PRJ - ProjectCoin",
2841 onSelect: function() {
2842 network
= bitcoinjs
.bitcoin
.networks
.projectcoin
;
2847 name: "PSB - Pesobit",
2848 onSelect: function() {
2849 network
= bitcoinjs
.bitcoin
.networks
.pesobit
;
2854 name: "PUT - Putincoin",
2855 onSelect: function() {
2856 network
= bitcoinjs
.bitcoin
.networks
.putincoin
;
2861 name: "RPD - Rapids",
2862 onSelect: function() {
2863 network
= bitcoinjs
.bitcoin
.networks
.rapids
;
2868 name: "RVN - Ravencoin",
2869 onSelect: function() {
2870 network
= bitcoinjs
.bitcoin
.networks
.ravencoin
;
2875 name: "RBY - Rubycoin",
2876 onSelect: function() {
2877 network
= bitcoinjs
.bitcoin
.networks
.rubycoin
;
2882 name: "RDD - Reddcoin",
2883 onSelect: function() {
2884 network
= bitcoinjs
.bitcoin
.networks
.reddcoin
;
2889 name: "RVR - RevolutionVR",
2890 onSelect: function() {
2891 network
= bitcoinjs
.bitcoin
.networks
.revolutionvr
;
2896 name: "SAFE - Safecoin",
2897 onSelect: function() {
2898 network
= bitcoinjs
.bitcoin
.networks
.safecoin
;
2903 name: "SLS - Salus",
2904 onSelect: function() {
2905 network
= bitcoinjs
.bitcoin
.networks
.salus
;
2910 name: "SDC - ShadowCash",
2911 onSelect: function() {
2912 network
= bitcoinjs
.bitcoin
.networks
.shadow
;
2917 name: "SDC - ShadowCash Testnet",
2918 onSelect: function() {
2919 network
= bitcoinjs
.bitcoin
.networks
.shadowtn
;
2924 name: "SLM - Slimcoin",
2925 onSelect: function() {
2926 network
= bitcoinjs
.bitcoin
.networks
.slimcoin
;
2931 name: "SLM - Slimcoin Testnet",
2932 onSelect: function() {
2933 network
= bitcoinjs
.bitcoin
.networks
.slimcointn
;
2938 name: "SLP - Simple Ledger Protocol",
2939 onSelect: function() {
2940 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2945 name: "SLR - Solarcoin",
2946 onSelect: function() {
2947 network
= bitcoinjs
.bitcoin
.networks
.solarcoin
;
2952 name: "SMLY - Smileycoin",
2953 onSelect: function() {
2954 network
= bitcoinjs
.bitcoin
.networks
.smileycoin
;
2959 name: "STASH - Stash",
2960 onSelect: function() {
2961 network
= bitcoinjs
.bitcoin
.networks
.stash
;
2966 name: "STASH - Stash Testnet",
2967 onSelect: function() {
2968 network
= bitcoinjs
.bitcoin
.networks
.stashtn
;
2973 name: "STRAT - Stratis",
2974 onSelect: function() {
2975 network
= bitcoinjs
.bitcoin
.networks
.stratis
;
2980 name: "TSTRAT - Stratis Testnet",
2981 onSelect: function() {
2982 network
= bitcoinjs
.bitcoin
.networks
.stratistest
;
2987 name: "SYS - Syscoin",
2988 onSelect: function() {
2989 network
= bitcoinjs
.bitcoin
.networks
.syscoin
;
2994 name: "THC - Hempcoin",
2995 onSelect: function() {
2996 network
= bitcoinjs
.bitcoin
.networks
.hempcoin
;
3001 name: "THT - Thought",
3002 onSelect: function() {
3003 network
= bitcoinjs
.bitcoin
.networks
.thought
;
3009 onSelect: function() {
3010 network
= bitcoinjs
.bitcoin
.networks
.toa
;
3015 name: "TWINS - TWINS",
3016 onSelect: function() {
3017 network
= bitcoinjs
.bitcoin
.networks
.twins
;
3022 name: "TWINS - TWINS Testnet",
3023 onSelect: function() {
3024 network
= bitcoinjs
.bitcoin
.networks
.twinstestnet
;
3029 name: "USC - Ultimatesecurecash",
3030 onSelect: function() {
3031 network
= bitcoinjs
.bitcoin
.networks
.ultimatesecurecash
;
3036 name: "USNBT - NuBits",
3037 onSelect: function() {
3038 network
= bitcoinjs
.bitcoin
.networks
.nubits
;
3043 name: "UNO - Unobtanium",
3044 onSelect: function() {
3045 network
= bitcoinjs
.bitcoin
.networks
.unobtanium
;
3050 name: "VASH - Vpncoin",
3051 onSelect: function() {
3052 network
= bitcoinjs
.bitcoin
.networks
.vpncoin
;
3057 name: "VET - VeChain",
3058 onSelect: function() {
3059 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3064 name: "VIA - Viacoin",
3065 onSelect: function() {
3066 network
= bitcoinjs
.bitcoin
.networks
.viacoin
;
3071 name: "VIA - Viacoin Testnet",
3072 onSelect: function() {
3073 network
= bitcoinjs
.bitcoin
.networks
.viacointestnet
;
3078 name: "VIVO - Vivo",
3079 onSelect: function() {
3080 network
= bitcoinjs
.bitcoin
.networks
.vivo
;
3085 name: "VTC - Vertcoin",
3086 onSelect: function() {
3087 network
= bitcoinjs
.bitcoin
.networks
.vertcoin
;
3092 name: "WGR - Wagerr",
3093 onSelect: function() {
3094 network
= bitcoinjs
.bitcoin
.networks
.wagerr
;
3099 name: "WC - Wincoin",
3100 onSelect: function() {
3101 network
= bitcoinjs
.bitcoin
.networks
.wincoin
;
3106 name: "XAX - Artax",
3107 onSelect: function() {
3108 network
= bitcoinjs
.bitcoin
.networks
.artax
;
3113 name: "XBC - Bitcoinplus",
3114 onSelect: function() {
3115 network
= bitcoinjs
.bitcoin
.networks
.bitcoinplus
;
3120 name: "XLM - Stellar",
3121 onSelect: function() {
3122 network
= stellarUtil
.dummyNetwork
;
3127 name: "XMY - Myriadcoin",
3128 onSelect: function() {
3129 network
= bitcoinjs
.bitcoin
.networks
.myriadcoin
;
3134 name: "XRP - Ripple",
3135 onSelect: function() {
3136 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3141 name: "XVC - Vcash",
3142 onSelect: function() {
3143 network
= bitcoinjs
.bitcoin
.networks
.vcash
;
3148 name: "XVG - Verge",
3149 onSelect: function() {
3150 network
= bitcoinjs
.bitcoin
.networks
.verge
;
3155 name: "XUEZ - Xuez",
3156 segwitAvailable: false,
3157 onSelect: function() {
3158 network
= bitcoinjs
.bitcoin
.networks
.xuez
;
3163 name: "XWC - Whitecoin",
3164 onSelect: function() {
3165 network
= bitcoinjs
.bitcoin
.networks
.whitecoin
;
3170 name: "XZC - Zcoin",
3171 onSelect: function() {
3172 network
= bitcoinjs
.bitcoin
.networks
.zcoin
;
3177 name: "ZCL - Zclassic",
3178 onSelect: function() {
3179 network
= bitcoinjs
.bitcoin
.networks
.zclassic
;
3184 name: "ZEC - Zcash",
3185 onSelect: function() {
3186 network
= bitcoinjs
.bitcoin
.networks
.zcash
;
3191 name: "ZEN - Horizen",
3192 onSelect: function() {
3193 network
= bitcoinjs
.bitcoin
.networks
.zencash
;
3201 name: "Bitcoin Core",
3202 onSelect: function() {
3203 DOM
.bip32path
.val("m/0'/0'");
3204 DOM
.hardenedAddresses
.prop('checked', true);
3208 name: "blockchain.info",
3209 onSelect: function() {
3210 DOM
.bip32path
.val("m/44'/0'/0'");
3211 DOM
.hardenedAddresses
.prop('checked', false);
3215 name: "MultiBit HD",
3216 onSelect: function() {
3217 DOM
.bip32path
.val("m/0'/0");
3218 DOM
.hardenedAddresses
.prop('checked', false);
3222 name: "Coinomi, Ledger",
3223 onSelect: function() {
3224 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3225 DOM
.hardenedAddresses
.prop('checked', false);
3230 // ELA - Elastos functions - begin
3231 function displayBip44InfoForELA() {
3236 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3237 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3239 // Calculate the account extended keys
3240 var accountXprv
= elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3241 var accountXpub
= elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3243 // Display the extended keys
3244 DOM
.bip44accountXprv
.val(accountXprv
);
3245 DOM
.bip44accountXpub
.val(accountXpub
);
3248 function displayBip32InfoForELA() {
3253 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3254 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3255 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3257 DOM
.extendedPrivKey
.val(elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3258 DOM
.extendedPubKey
.val(elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3260 // Display the addresses and privkeys
3261 clearAddressesList();
3262 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3263 displayAddresses(0, initialAddressCount
);
3266 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3271 var publicKey
= elastosjs
.getDerivedPublicKey(elastosjs
.getMasterPublicKey(seed
), change
, index
);
3273 privateKey: elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3274 publicKey: publicKey
,
3275 address: elastosjs
.getAddress(publicKey
.toString('hex'))
3278 // ELA - Elastos functions - end