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;
18 var isDefaultBip44ChangeValue
= 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
.entropyCrackTime
= DOM
.entropyContainer
.find(".crack-time");
37 DOM
.entropyEventCount
= DOM
.entropyContainer
.find(".event-count");
38 DOM
.entropyBits
= DOM
.entropyContainer
.find(".bits");
39 DOM
.entropyBitsPerEvent
= DOM
.entropyContainer
.find(".bits-per-event");
40 DOM
.entropyWordCount
= DOM
.entropyContainer
.find(".word-count");
41 DOM
.entropyBinary
= DOM
.entropyContainer
.find(".binary");
42 DOM
.entropyWordIndexes
= DOM
.entropyContainer
.find(".word-indexes");
43 DOM
.entropyChecksum
= DOM
.entropyContainer
.find(".checksum");
44 DOM
.entropyMnemonicLength
= DOM
.entropyContainer
.find(".mnemonic-length");
45 DOM
.entropyWeakEntropyOverrideWarning
= DOM
.entropyContainer
.find(".weak-entropy-override-warning");
46 DOM
.entropyFilterWarning
= DOM
.entropyContainer
.find(".filter-warning");
47 DOM
.phrase
= $(".phrase");
48 DOM
.splitPhrase
= $(".phraseSplit");
49 DOM
.phraseSplitWarn
= $(".phraseSplitWarn");
50 DOM
.passphrase
= $(".passphrase");
51 DOM
.generateContainer
= $(".generate-container");
52 DOM
.generate
= $(".generate");
53 DOM
.seed
= $(".seed");
54 DOM
.rootKey
= $(".root-key");
55 DOM
.litecoinLtubContainer
= $(".litecoin-ltub-container");
56 DOM
.litecoinUseLtub
= $(".litecoin-use-ltub");
57 DOM
.extendedPrivKey
= $(".extended-priv-key");
58 DOM
.extendedPubKey
= $(".extended-pub-key");
59 DOM
.bip32tab
= $("#bip32-tab");
60 DOM
.bip44tab
= $("#bip44-tab");
61 DOM
.bip49tab
= $("#bip49-tab");
62 DOM
.bip84tab
= $("#bip84-tab");
63 DOM
.bip141tab
= $("#bip141-tab");
64 DOM
.bip32panel
= $("#bip32");
65 DOM
.bip44panel
= $("#bip44");
66 DOM
.bip49panel
= $("#bip49");
67 DOM
.bip32path
= $("#bip32-path");
68 DOM
.bip44path
= $("#bip44-path");
69 DOM
.bip44purpose
= $("#bip44 .purpose");
70 DOM
.bip44coin
= $("#bip44 .coin");
71 DOM
.bip44account
= $("#bip44 .account");
72 DOM
.bip44accountXprv
= $("#bip44 .account-xprv");
73 DOM
.bip44accountXpub
= $("#bip44 .account-xpub");
74 DOM
.bip44change
= $("#bip44 .change");
75 DOM
.defaultBip44ChangeValue
= $("#bip44 .default-bip44-change-value");
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
.phrase
.on("input", delayedPhraseChanged
);
134 DOM
.passphrase
.on("input", delayedPhraseChanged
);
135 DOM
.generate
.on("click", generateClicked
);
136 DOM
.more
.on("click", showMore
);
137 DOM
.rootKey
.on("input", delayedRootKeyChanged
);
138 DOM
.litecoinUseLtub
.on("change", litecoinUseLtubChanged
);
139 DOM
.bip32path
.on("input", calcForDerivationPath
);
140 DOM
.bip44account
.on("input", calcForDerivationPath
);
141 DOM
.bip44change
.on("input", modifiedDefaultBip44ChangeValue
);
142 DOM
.bip44change
.on("input", calcForDerivationPath
);
143 DOM
.defaultBip44ChangeValue
.on("click", resetDefaultBip44ChangeValue
);
144 DOM
.bip49account
.on("input", calcForDerivationPath
);
145 DOM
.bip49change
.on("input", calcForDerivationPath
);
146 DOM
.bip84account
.on("input", calcForDerivationPath
);
147 DOM
.bip84change
.on("input", calcForDerivationPath
);
148 DOM
.bip141path
.on("input", calcForDerivationPath
);
149 DOM
.bip141semantics
.on("change", tabChanged
);
150 DOM
.tab
.on("shown.bs.tab", tabChanged
);
151 DOM
.hardenedAddresses
.on("change", calcForDerivationPath
);
152 DOM
.useBip38
.on("change", calcForDerivationPath
);
153 DOM
.bip38Password
.on("change", calcForDerivationPath
);
154 DOM
.indexToggle
.on("click", toggleIndexes
);
155 DOM
.addressToggle
.on("click", toggleAddresses
);
156 DOM
.publicKeyToggle
.on("click", togglePublicKeys
);
157 DOM
.privateKeyToggle
.on("click", togglePrivateKeys
);
158 DOM
.csvTab
.on("click", updateCsv
);
159 DOM
.languages
.on("click", languageChanged
);
160 DOM
.bitcoinCashAddressType
.on("change", bitcoinCashAddressTypeChange
);
161 setQrEvents(DOM
.showQrEls
);
164 hideValidationError();
165 populateNetworkSelect();
166 populateClientSelect();
171 function generatedStrengthChanged() {
172 var strength
= parseInt(DOM
.generatedStrength
.val());
174 DOM
.generatedStrengthWarning
.removeClass("hidden");
177 DOM
.generatedStrengthWarning
.addClass("hidden");
181 function networkChanged(e
) {
183 clearAddressesList();
184 DOM
.litecoinLtubContainer
.addClass("hidden");
185 DOM
.bitcoinCashAddressTypeContainer
.addClass("hidden");
186 var networkIndex
= e
.target
.value
;
187 var network
= networks
[networkIndex
];
189 adjustNetworkForSegwit();
198 function bip32ClientChanged(e
) {
199 var clientIndex
= DOM
.bip32Client
.val();
200 if (clientIndex
== "custom") {
201 DOM
.bip32path
.prop("readonly", false);
204 DOM
.bip32path
.prop("readonly", true);
205 clients
[clientIndex
].onSelect();
215 function setEntropyVisibility() {
216 if (isUsingOwnEntropy()) {
217 DOM
.entropyContainer
.removeClass("hidden");
218 DOM
.generateContainer
.addClass("hidden");
219 DOM
.phrase
.prop("readonly", true);
224 DOM
.entropyContainer
.addClass("hidden");
225 DOM
.generateContainer
.removeClass("hidden");
226 DOM
.phrase
.prop("readonly", false);
231 function delayedPhraseChanged() {
232 hideValidationError();
235 bip32ExtendedKey
= null;
236 clearAddressesList();
238 if (phraseChangeTimeoutEvent
!= null) {
239 clearTimeout(phraseChangeTimeoutEvent
);
241 phraseChangeTimeoutEvent
= setTimeout(function() {
243 var entropy
= mnemonic
.toRawEntropyBin(DOM
.phrase
.val());
244 if (entropy
!== null) {
245 DOM
.entropyMnemonicLength
.val("raw");
246 DOM
.entropy
.val(entropy
);
251 function phraseChanged() {
253 setMnemonicLanguage();
254 // Get the mnemonic phrase
255 var phrase
= DOM
.phrase
.val();
256 var errorText
= findPhraseErrors(phrase
);
258 showValidationError(errorText
);
261 // Calculate and display
262 var passphrase
= DOM
.passphrase
.val();
263 calcBip32RootKeyFromSeed(phrase
, passphrase
);
264 calcForDerivationPath();
265 // Show the word indexes
267 writeSplitPhrase(phrase
);
270 function tabChanged() {
272 adjustNetworkForSegwit();
273 var phrase
= DOM
.phrase
.val();
275 // Calculate and display for mnemonic
276 var errorText
= findPhraseErrors(phrase
);
278 showValidationError(errorText
);
281 // Calculate and display
282 var passphrase
= DOM
.passphrase
.val();
283 calcBip32RootKeyFromSeed(phrase
, passphrase
);
286 // Calculate and display for root key
287 var rootKeyBase58
= DOM
.rootKey
.val();
288 var errorText
= validateRootKey(rootKeyBase58
);
290 showValidationError(errorText
);
293 // Calculate and display
294 calcBip32RootKeyFromBase58(rootKeyBase58
);
296 calcForDerivationPath();
299 function delayedEntropyChanged() {
300 hideValidationError();
302 if (entropyChangeTimeoutEvent
!= null) {
303 clearTimeout(entropyChangeTimeoutEvent
);
305 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
308 function entropyChanged() {
309 // If blank entropy, clear mnemonic, addresses, errors
310 if (DOM
.entropy
.val().trim().length
== 0) {
312 clearEntropyFeedback();
314 DOM
.phraseSplit
.val("");
315 showValidationError("Blank entropy");
318 // Get the current phrase to detect changes
319 var phrase
= DOM
.phrase
.val();
320 // Set the phrase from the entropy
321 setMnemonicFromEntropy();
322 // Recalc addresses if the phrase has changed
323 var newPhrase
= DOM
.phrase
.val();
324 if (newPhrase
!= phrase
) {
325 if (newPhrase
.length
== 0) {
337 function delayedRootKeyChanged() {
338 // Warn if there is an existing mnemonic or passphrase.
339 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
340 if (!confirm("This will clear existing mnemonic and passphrase")) {
341 DOM
.rootKey
.val(bip32RootKey
);
345 hideValidationError();
347 // Clear existing mnemonic and passphrase
349 DOM
.phraseSplit
.val("");
350 DOM
.passphrase
.val("");
352 if (rootKeyChangedTimeoutEvent
!= null) {
353 clearTimeout(rootKeyChangedTimeoutEvent
);
355 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
358 function rootKeyChanged() {
360 hideValidationError();
361 var rootKeyBase58
= DOM
.rootKey
.val();
362 var errorText
= validateRootKey(rootKeyBase58
);
364 showValidationError(errorText
);
367 // Calculate and display
368 calcBip32RootKeyFromBase58(rootKeyBase58
);
369 calcForDerivationPath();
372 function litecoinUseLtubChanged() {
373 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
374 if (litecoinUseLtub
) {
375 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
378 network
= bitcoinjs
.bitcoin
.networks
.litecoinXprv
;
383 function calcForDerivationPath() {
385 clearAddressesList();
387 // Don't show segwit if it's selected but network doesn't support it
388 if (segwitSelected() && !networkHasSegwit()) {
389 showSegwitUnavailable();
393 showSegwitAvailable();
394 // Get the derivation path
395 var derivationPath
= getDerivationPath();
396 var errorText
= findDerivationPathErrors(derivationPath
);
398 showValidationError(errorText
);
401 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
402 if (bip44TabSelected()) {
405 else if (bip49TabSelected()) {
408 else if (bip84TabSelected()) {
414 function generateClicked() {
415 if (isUsingOwnEntropy()) {
420 setTimeout(function() {
421 setMnemonicLanguage();
422 var phrase
= generateRandomPhrase();
430 function languageChanged() {
431 setTimeout(function() {
432 setMnemonicLanguage();
433 if (DOM
.phrase
.val().length
> 0) {
434 var newPhrase
= convertPhraseToNewLanguage();
435 DOM
.phrase
.val(newPhrase
);
439 DOM
.generate
.trigger("click");
444 function bitcoinCashAddressTypeChange() {
448 function toggleIndexes() {
449 showIndex
= !showIndex
;
450 $("td.index span").toggleClass("invisible");
453 function toggleAddresses() {
454 showAddress
= !showAddress
;
455 $("td.address span").toggleClass("invisible");
458 function togglePublicKeys() {
459 showPubKey
= !showPubKey
;
460 $("td.pubkey span").toggleClass("invisible");
463 function togglePrivateKeys() {
464 showPrivKey
= !showPrivKey
;
465 $("td.privkey span").toggleClass("invisible");
468 function privacyScreenToggled() {
469 // private-data contains elements added to DOM at runtime
470 // so catch all by adding visual privacy class to the root of the DOM
471 if (DOM
.privacyScreenToggle
.prop("checked")) {
472 $("body").addClass("visual-privacy");
475 $("body").removeClass("visual-privacy");
481 function generateRandomPhrase() {
482 if (!hasStrongRandom()) {
483 var errorText
= "This browser does not support strong randomness";
484 showValidationError(errorText
);
487 // get the amount of entropy to use
488 var numWords
= parseInt(DOM
.generatedStrength
.val());
489 var strength
= numWords
/ 3 * 32;
490 var buffer
= new Uint8Array(strength
/ 8);
491 // create secure entropy
492 var data
= crypto
.getRandomValues(buffer
);
494 var words
= mnemonic
.toMnemonic(data
);
495 DOM
.phrase
.val(words
);
497 var entropyHex
= uint8ArrayToHex(data
);
498 DOM
.entropy
.val(entropyHex
);
499 // ensure entropy fields are consistent with what is being displayed
500 DOM
.entropyMnemonicLength
.val("raw");
504 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
505 seed
= mnemonic
.toSeed(phrase
, passphrase
);
506 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
508 bip32RootKey
= groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
512 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
514 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
517 // try parsing with various segwit network params since this extended
518 // key may be from any one of them.
519 if (networkHasSegwit()) {
521 if ("baseNetwork" in n
) {
522 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
524 // try parsing using base network params
526 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
530 // try parsing using p2wpkh params
533 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
538 // try parsing using p2wpkh-in-p2sh network params
539 if ("p2wpkhInP2sh" in n
) {
541 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
547 // try the network params as currently specified
548 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
551 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
552 // try parsing with various segwit network params since this extended
553 // key may be from any one of them.
554 if (networkHasSegwit()) {
556 if ("baseNetwork" in n
) {
557 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
559 // try parsing using base network params
561 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
565 // try parsing using p2wpkh params
568 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
573 // try parsing using p2wpkh-in-p2sh network params
574 if ("p2wpkhInP2sh" in n
) {
576 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
582 // try the network params as currently specified
583 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
586 function calcBip32ExtendedKey(path
) {
587 // Check there's a root key to derive from
591 var extendedKey
= bip32RootKey
;
592 // Derive the key from the path
593 var pathBits
= path
.split("/");
594 for (var i
=0; i
<pathBits
.length
; i
++) {
595 var bit
= pathBits
[i
];
596 var index
= parseInt(bit
);
600 var hardened
= bit
[bit
.length
-1] == "'";
601 var isPriv
= !(extendedKey
.isNeutered());
602 var invalidDerivationPath
= hardened
&& !isPriv
;
603 if (invalidDerivationPath
) {
607 extendedKey
= extendedKey
.deriveHardened(index
);
610 extendedKey
= extendedKey
.derive(index
);
616 function showValidationError(errorText
) {
622 function hideValidationError() {
628 function findPhraseErrors(phrase
) {
629 // Preprocess the words
630 phrase
= mnemonic
.normalizeString(phrase
);
631 var words
= phraseToWordArray(phrase
);
632 // Detect blank phrase
633 if (words
.length
== 0) {
634 return "Blank mnemonic";
637 for (var i
=0; i
<words
.length
; i
++) {
639 var language
= getLanguage();
640 if (WORDLISTS
[language
].indexOf(word
) == -1) {
641 console
.log("Finding closest match to " + word
);
642 var nearestWord
= findNearestWord(word
);
643 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
646 // Check the words are valid
647 var properPhrase
= wordArrayToPhrase(words
);
648 var isValid
= mnemonic
.check(properPhrase
);
650 return "Invalid mnemonic";
655 function validateRootKey(rootKeyBase58
) {
657 return validateRootKeyGRS(rootKeyBase58
);
659 // try various segwit network params since this extended key may be from
661 if (networkHasSegwit()) {
663 if ("baseNetwork" in n
) {
664 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
666 // try parsing using base network params
668 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
672 // try parsing using p2wpkh params
675 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
680 // try parsing using p2wpkh-in-p2sh network params
681 if ("p2wpkhInP2sh" in n
) {
683 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
689 // try the network params as currently specified
691 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
694 return "Invalid root key";
699 function validateRootKeyGRS(rootKeyBase58
) {
700 // try various segwit network params since this extended key may be from
702 if (networkHasSegwit()) {
704 if ("baseNetwork" in n
) {
705 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
707 // try parsing using base network params
709 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
713 // try parsing using p2wpkh params
716 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
721 // try parsing using p2wpkh-in-p2sh network params
722 if ("p2wpkhInP2sh" in n
) {
724 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
730 // try the network params as currently specified
732 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
735 return "Invalid root key";
740 function getDerivationPath() {
741 if (bip44TabSelected()) {
742 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
743 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
744 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
745 var change
= parseIntNoNaN(DOM
.bip44change
.val(), "");
747 path
+= "/" + purpose
+ "'";
748 path
+= "/" + coin
+ "'";
749 path
+= "/" + account
+ "'";
751 path
+= "/" + change
;
753 DOM
.bip44path
.val(path
);
754 var derivationPath
= DOM
.bip44path
.val();
755 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
756 return derivationPath
;
758 else if (bip49TabSelected()) {
759 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
760 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
761 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
762 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
764 path
+= purpose
+ "'/";
766 path
+= account
+ "'/";
768 DOM
.bip49path
.val(path
);
769 var derivationPath
= DOM
.bip49path
.val();
770 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
771 return derivationPath
;
773 else if (bip84TabSelected()) {
774 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
775 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
776 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
777 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
779 path
+= purpose
+ "'/";
781 path
+= account
+ "'/";
783 DOM
.bip84path
.val(path
);
784 var derivationPath
= DOM
.bip84path
.val();
785 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
786 return derivationPath
;
788 else if (bip32TabSelected()) {
789 var derivationPath
= DOM
.bip32path
.val();
790 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
791 return derivationPath
;
793 else if (bip141TabSelected()) {
794 var derivationPath
= DOM
.bip141path
.val();
795 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
796 return derivationPath
;
799 console
.log("Unknown derivation path");
803 function findDerivationPathErrors(path
) {
804 // TODO is not perfect but is better than nothing
806 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
808 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
809 var maxDepth
= 255; // TODO verify this!!
810 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
811 if (path
[0] != "m") {
812 return "First character must be 'm'";
814 if (path
.length
> 1) {
815 if (path
[1] != "/") {
816 return "Separator must be '/'";
818 var indexes
= path
.split("/");
819 if (indexes
.length
> maxDepth
) {
820 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
822 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
823 var index
= indexes
[depth
];
824 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
825 if (invalidChars
.length
> 0) {
826 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
828 var indexValue
= parseInt(index
.replace("'", ""));
830 return "Invalid number at depth " + depth
;
832 if (indexValue
> maxIndexValue
) {
833 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
837 // Check root key exists or else derivation path is useless!
839 return "No root key";
841 // Check no hardened derivation path when using xpub keys
842 var hardenedPath
= path
.indexOf("'") > -1;
843 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
844 var hardened
= hardenedPath
|| hardenedAddresses
;
845 var isXpubkey
= bip32RootKey
.isNeutered();
846 if (hardened
&& isXpubkey
) {
847 return "Hardened derivation path is invalid with xpub key";
853 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
857 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
860 function displayBip44Info() {
861 // Get the derivation path for the account
862 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
863 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
864 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
866 path
+= purpose
+ "'/";
868 path
+= account
+ "'/";
869 // Calculate the account extended keys
870 var accountExtendedKey
= calcBip32ExtendedKey(path
);
871 var accountXprv
= accountExtendedKey
.toBase58();
872 var accountXpub
= accountExtendedKey
.neutered().toBase58();
874 // Display the extended keys
875 DOM
.bip44accountXprv
.val(accountXprv
);
876 DOM
.bip44accountXpub
.val(accountXpub
);
879 displayBip44InfoForELA();
883 function displayBip49Info() {
884 // Get the derivation path for the account
885 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
886 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
887 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
889 path
+= purpose
+ "'/";
891 path
+= account
+ "'/";
892 // Calculate the account extended keys
893 var accountExtendedKey
= calcBip32ExtendedKey(path
);
894 var accountXprv
= accountExtendedKey
.toBase58();
895 var accountXpub
= accountExtendedKey
.neutered().toBase58();
896 // Display the extended keys
897 DOM
.bip49accountXprv
.val(accountXprv
);
898 DOM
.bip49accountXpub
.val(accountXpub
);
901 function displayBip84Info() {
902 // Get the derivation path for the account
903 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
904 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
905 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
907 path
+= purpose
+ "'/";
909 path
+= account
+ "'/";
910 // Calculate the account extended keys
911 var accountExtendedKey
= calcBip32ExtendedKey(path
);
912 var accountXprv
= accountExtendedKey
.toBase58();
913 var accountXpub
= accountExtendedKey
.neutered().toBase58();
914 // Display the extended keys
915 DOM
.bip84accountXprv
.val(accountXprv
);
916 DOM
.bip84accountXpub
.val(accountXpub
);
919 function displayBip32Info() {
922 var rootKey
= bip32RootKey
.toBase58();
923 DOM
.rootKey
.val(rootKey
);
924 var xprvkeyB58
= "NA";
925 if (!bip32ExtendedKey
.isNeutered()) {
926 xprvkeyB58
= bip32ExtendedKey
.toBase58();
928 var extendedPrivKey
= xprvkeyB58
;
929 DOM
.extendedPrivKey
.val(extendedPrivKey
);
930 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
931 DOM
.extendedPubKey
.val(extendedPubKey
);
932 // Display the addresses and privkeys
933 clearAddressesList();
934 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
935 displayAddresses(0, initialAddressCount
);
938 displayBip32InfoForELA();
942 function displayAddresses(start
, total
) {
943 generationProcesses
.push(new (function() {
947 this.stop = function() {
948 for (var i
=0; i
<rows
.length
; i
++) {
949 rows
[i
].shouldGenerate
= false;
954 for (var i
=0; i
<total
; i
++) {
955 var index
= i
+ start
;
956 var isLast
= i
== total
- 1;
957 rows
.push(new TableRow(index
, isLast
));
963 function segwitSelected() {
964 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
967 function p2wpkhSelected() {
968 return bip84TabSelected() ||
969 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
972 function p2wpkhInP2shSelected() {
973 return bip49TabSelected() ||
974 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
977 function TableRow(index
, isLast
) {
980 this.shouldGenerate
= true;
981 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
982 var useBip38
= DOM
.useBip38
.prop("checked");
983 var bip38password
= DOM
.bip38Password
.val();
984 var isSegwit
= segwitSelected();
985 var segwitAvailable
= networkHasSegwit();
986 var isP2wpkh
= p2wpkhSelected();
987 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
993 function calculateValues() {
994 setTimeout(function() {
995 if (!self
.shouldGenerate
) {
998 // derive HDkey for this row of the table
1000 if (useHardenedAddresses
) {
1001 key
= bip32ExtendedKey
.deriveHardened(index
);
1004 key
= bip32ExtendedKey
.derive(index
);
1006 // bip38 requires uncompressed keys
1007 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1008 var keyPair
= key
.keyPair
;
1009 var useUncompressed
= useBip38
;
1010 if (useUncompressed
) {
1011 keyPair
= new bitcoinjs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1013 keyPair
= new groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1017 var address
= keyPair
.getAddress().toString();
1019 var hasPrivkey
= !key
.isNeutered();
1022 privkey
= keyPair
.toWIF();
1023 // BIP38 encode private key if required
1026 privkey
= groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1027 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1028 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1030 privkey
= bitcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1031 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1036 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1037 var indexText
= getDerivationPath() + "/" + index
;
1038 if (useHardenedAddresses
) {
1039 indexText
= indexText
+ "'";
1041 // Ethereum values are different
1042 if (networkIsEthereum()) {
1043 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1044 privkey
= privKeyBuffer
.toString('hex');
1045 var addressBuffer
= ethUtil
.privateToAddress(privKeyBuffer
);
1046 var hexAddress
= addressBuffer
.toString('hex');
1047 var checksumAddress
= ethUtil
.toChecksumAddress(hexAddress
);
1048 address
= ethUtil
.addHexPrefix(checksumAddress
);
1049 privkey
= ethUtil
.addHexPrefix(privkey
);
1050 pubkey
= ethUtil
.addHexPrefix(pubkey
);
1053 // Stellar is different
1054 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1055 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1056 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1058 path
+= purpose
+ "'/";
1059 path
+= coin
+ "'/" + index
+ "'";
1060 var keypair
= stellarUtil
.getKeypair(path
, seed
);
1062 privkey
= keypair
.secret();
1063 pubkey
= address
= keypair
.publicKey();
1065 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1066 var NasAccount
= require("nebulas-account");
1067 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1068 var nebulasAccount
= new NasAccount();
1069 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1070 address
= nebulasAccount
.getAddressString();
1071 privkey
= nebulasAccount
.getPrivateKeyString();
1072 pubkey
= nebulasAccount
.getPublicKeyString();
1074 // Ripple values are different
1075 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1076 privkey
= convertRipplePriv(privkey
);
1077 address
= convertRippleAdrr(address
);
1079 // CasinoCoin values are different
1080 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1081 privkey
= convertCasinoCoinPriv(privkey
);
1082 address
= convertCasinoCoinAdrr(address
);
1084 // Bitcoin Cash address format may vary
1085 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1086 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1087 if (bchAddrType
== "cashaddr") {
1088 address
= bchaddr
.toCashAddress(address
);
1090 else if (bchAddrType
== "bitpay") {
1091 address
= bchaddr
.toBitpayAddress(address
);
1094 // Bitcoin Cash address format may vary
1095 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1096 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1097 if (bchAddrType
== "cashaddr") {
1098 address
= bchaddr
.toSlpAddress(address
);
1101 // Segwit addresses are different
1103 if (!segwitAvailable
) {
1107 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1108 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1109 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1111 else if (isP2wpkhInP2sh
) {
1112 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1113 var scriptsig
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1114 var addressbytes
= bitcoinjs
.bitcoin
.crypto
.hash160(scriptsig
);
1115 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1116 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1120 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1121 address
= bitcoinjs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1124 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1126 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1127 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1130 //Groestlcoin Addresses are different
1134 if (!segwitAvailable
) {
1138 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1140 else if (isP2wpkhInP2sh
) {
1141 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1144 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1148 let elaAddress
= calcAddressForELA(
1150 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1151 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1152 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1155 address
= elaAddress
.address
;
1156 privkey
= elaAddress
.privateKey
;
1157 pubkey
= elaAddress
.publicKey
;
1160 addAddressToList(indexText
, address
, pubkey
, privkey
);
1172 function showMore() {
1173 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1174 if (isNaN(rowsToAdd
)) {
1176 DOM
.rowsToAdd
.val("20");
1178 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1180 start
= lastIndexInTable() + 1;
1183 var newStart
= start
+ rowsToAdd
;
1184 DOM
.moreRowsStartIndex
.val(newStart
);
1186 if (rowsToAdd
> 200) {
1187 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1188 msg
+= "Do you want to continue?";
1189 if (!confirm(msg
)) {
1193 displayAddresses(start
, rowsToAdd
);
1196 function clearDisplay() {
1197 clearAddressesList();
1199 hideValidationError();
1202 function clearAddressesList() {
1203 DOM
.addresses
.empty();
1208 function stopGenerating() {
1209 while (generationProcesses
.length
> 0) {
1210 var generation
= generationProcesses
.shift();
1215 function clearKeys() {
1220 function clearRootKey() {
1221 DOM
.rootKey
.val("");
1224 function clearDerivedKeys() {
1225 DOM
.extendedPrivKey
.val("");
1226 DOM
.extendedPubKey
.val("");
1227 DOM
.bip44accountXprv
.val("");
1228 DOM
.bip44accountXpub
.val("");
1231 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1232 var row
= $(addressRowTemplate
.html());
1234 var indexCell
= row
.find(".index span");
1235 var addressCell
= row
.find(".address span");
1236 var pubkeyCell
= row
.find(".pubkey span");
1237 var privkeyCell
= row
.find(".privkey span");
1239 indexCell
.text(indexText
);
1240 addressCell
.text(address
);
1241 pubkeyCell
.text(pubkey
);
1242 privkeyCell
.text(privkey
);
1245 indexCell
.addClass("invisible");
1248 addressCell
.addClass("invisible");
1251 pubkeyCell
.addClass("invisible");
1254 privkeyCell
.addClass("invisible");
1256 DOM
.addresses
.append(row
);
1257 var rowShowQrEls
= row
.find("[data-show-qr]");
1258 setQrEvents(rowShowQrEls
);
1261 function hasStrongRandom() {
1262 return 'crypto' in window
&& window
['crypto'] !== null;
1265 function disableForms() {
1266 $("form").on("submit", function(e
) {
1271 function parseIntNoNaN(val
, defaultVal
) {
1272 var v
= parseInt(val
);
1279 function showPending() {
1281 .text("Calculating...")
1285 function findNearestWord(word
) {
1286 var language
= getLanguage();
1287 var words
= WORDLISTS
[language
];
1288 var minDistance
= 99;
1289 var closestWord
= words
[0];
1290 for (var i
=0; i
<words
.length
; i
++) {
1291 var comparedTo
= words
[i
];
1292 if (comparedTo
.indexOf(word
) == 0) {
1295 var distance
= Levenshtein
.get(word
, comparedTo
);
1296 if (distance
< minDistance
) {
1297 closestWord
= comparedTo
;
1298 minDistance
= distance
;
1304 function hidePending() {
1310 function populateNetworkSelect() {
1311 for (var i
=0; i
<networks
.length
; i
++) {
1312 var network
= networks
[i
];
1313 var option
= $("<option>");
1314 option
.attr("value", i
);
1315 option
.text(network
.name
);
1316 if (network
.name
== "BTC - Bitcoin") {
1317 option
.prop("selected", true);
1319 DOM
.phraseNetwork
.append(option
);
1323 function populateClientSelect() {
1324 for (var i
=0; i
<clients
.length
; i
++) {
1325 var client
= clients
[i
];
1326 var option
= $("<option>");
1327 option
.attr("value", i
);
1328 option
.text(client
.name
);
1329 DOM
.bip32Client
.append(option
);
1333 function getLanguage() {
1334 var defaultLanguage
= "english";
1335 // Try to get from existing phrase
1336 var language
= getLanguageFromPhrase();
1337 // Try to get from url if not from phrase
1338 if (language
.length
== 0) {
1339 language
= getLanguageFromUrl();
1341 // Default to English if no other option
1342 if (language
.length
== 0) {
1343 language
= defaultLanguage
;
1348 function getLanguageFromPhrase(phrase
) {
1349 // Check if how many words from existing phrase match a language.
1352 phrase
= DOM
.phrase
.val();
1354 if (phrase
.length
> 0) {
1355 var words
= phraseToWordArray(phrase
);
1356 var languageMatches
= {};
1357 for (l
in WORDLISTS
) {
1358 // Track how many words match in this language
1359 languageMatches
[l
] = 0;
1360 for (var i
=0; i
<words
.length
; i
++) {
1361 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1362 if (wordInLanguage
) {
1363 languageMatches
[l
]++;
1366 // Find languages with most word matches.
1367 // This is made difficult due to commonalities between Chinese
1368 // simplified vs traditional.
1369 var mostMatches
= 0;
1370 var mostMatchedLanguages
= [];
1371 for (var l
in languageMatches
) {
1372 var numMatches
= languageMatches
[l
];
1373 if (numMatches
> mostMatches
) {
1374 mostMatches
= numMatches
;
1375 mostMatchedLanguages
= [l
];
1377 else if (numMatches
== mostMatches
) {
1378 mostMatchedLanguages
.push(l
);
1382 if (mostMatchedLanguages
.length
> 0) {
1383 // Use first language and warn if multiple detected
1384 language
= mostMatchedLanguages
[0];
1385 if (mostMatchedLanguages
.length
> 1) {
1386 console
.warn("Multiple possible languages");
1387 console
.warn(mostMatchedLanguages
);
1394 function getLanguageFromUrl() {
1395 for (var language
in WORDLISTS
) {
1396 if (window
.location
.hash
.indexOf(language
) > -1) {
1403 function setMnemonicLanguage() {
1404 var language
= getLanguage();
1405 // Load the bip39 mnemonic generator for this language if required
1406 if (!(language
in mnemonics
)) {
1407 mnemonics
[language
] = new Mnemonic(language
);
1409 mnemonic
= mnemonics
[language
];
1412 function convertPhraseToNewLanguage() {
1413 var oldLanguage
= getLanguageFromPhrase();
1414 var newLanguage
= getLanguageFromUrl();
1415 var oldPhrase
= DOM
.phrase
.val();
1416 var oldWords
= phraseToWordArray(oldPhrase
);
1418 for (var i
=0; i
<oldWords
.length
; i
++) {
1419 var oldWord
= oldWords
[i
];
1420 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1421 var newWord
= WORDLISTS
[newLanguage
][index
];
1422 newWords
.push(newWord
);
1424 newPhrase
= wordArrayToPhrase(newWords
);
1428 // TODO look at jsbip39 - mnemonic.splitWords
1429 function phraseToWordArray(phrase
) {
1430 var words
= phrase
.split(/\s/g);
1432 for (var i
=0; i
<words
.length
; i
++) {
1433 var word
= words
[i
];
1434 if (word
.length
> 0) {
1435 noBlanks
.push(word
);
1441 // TODO look at jsbip39 - mnemonic.joinWords
1442 function wordArrayToPhrase(words
) {
1443 var phrase
= words
.join(" ");
1444 var language
= getLanguageFromPhrase(phrase
);
1445 if (language
== "japanese") {
1446 phrase
= words
.join("\u3000");
1451 function writeSplitPhrase(phrase
) {
1452 var wordCount
= phrase
.split(/\s/g).length
;
1454 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1455 var group
=[[],[],[]],
1457 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1458 while (left
.length
>0) {
1459 groupI
=(groupI
+1)%3;
1460 seed
= seed
* 16807 % 2147483647;
1461 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1462 group
[groupI
].push(left
[selected
]);
1463 left
.splice(selected
,1);
1465 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1466 for (var i
=0;i
<3;i
++) {
1467 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1468 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1470 DOM
.splitPhrase
.val(cards
.join("\r\n"));
1471 var triesPerSecond
=10000000000;
1472 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1474 hackTime
="<1 second";
1475 } else if (hackTime
<86400) {
1476 hackTime
=Math
.floor(hackTime
)+" seconds";
1477 } else if(hackTime
<31557600) {
1478 hackTime
=Math
.floor(hackTime
/86400)+" days";
1480 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1482 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1485 function isUsingOwnEntropy() {
1486 return DOM
.useEntropy
.prop("checked");
1489 function setMnemonicFromEntropy() {
1490 clearEntropyFeedback();
1491 // Get entropy value
1492 var entropyStr
= DOM
.entropy
.val();
1493 // Work out minimum base for entropy
1494 var entropy
= Entropy
.fromString(entropyStr
);
1495 if (entropy
.binaryStr
.length
== 0) {
1498 // Show entropy details
1499 showEntropyFeedback(entropy
);
1500 // Use entropy hash if not using raw entropy
1501 var bits
= entropy
.binaryStr
;
1502 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1503 if (mnemonicLength
!= "raw") {
1504 // Get bits by hashing entropy with SHA256
1505 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1506 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1507 bits
= BigInteger
.parse(hex
, 16).toString(2);
1508 while (bits
.length
% 256 != 0) {
1511 // Truncate hash to suit number of words
1512 mnemonicLength
= parseInt(mnemonicLength
);
1513 var numberOfBits
= 32 * mnemonicLength
/ 3;
1514 bits
= bits
.substring(0, numberOfBits
);
1515 // show warning for weak entropy override
1516 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1517 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1520 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1524 // hide warning for weak entropy override
1525 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1527 // Discard trailing entropy
1528 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1529 var start
= bits
.length
- bitsToUse
;
1530 var binaryStr
= bits
.substring(start
);
1531 // Convert entropy string to numeric array
1532 var entropyArr
= [];
1533 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1534 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1535 var entropyByte
= parseInt(byteAsBits
, 2);
1536 entropyArr
.push(entropyByte
)
1538 // Convert entropy array to mnemonic
1539 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1540 // Set the mnemonic in the UI
1541 DOM
.phrase
.val(phrase
);
1542 writeSplitPhrase(phrase
);
1543 // Show the word indexes
1545 // Show the checksum
1549 function clearEntropyFeedback() {
1550 DOM
.entropyCrackTime
.text("...");
1551 DOM
.entropyType
.text("");
1552 DOM
.entropyWordCount
.text("0");
1553 DOM
.entropyEventCount
.text("0");
1554 DOM
.entropyBitsPerEvent
.text("0");
1555 DOM
.entropyBits
.text("0");
1556 DOM
.entropyFiltered
.html(" ");
1557 DOM
.entropyBinary
.html(" ");
1560 function showEntropyFeedback(entropy
) {
1561 var numberOfBits
= entropy
.binaryStr
.length
;
1562 var timeToCrack
= "unknown";
1564 var z
= zxcvbn(entropy
.base
.parts
.join(""));
1565 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1566 if (z
.feedback
.warning
!= "") {
1567 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1571 console
.log("Error detecting entropy strength with zxcvbn:");
1574 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1575 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1576 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1577 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1578 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1579 DOM
.entropyType
.text(entropyTypeStr
);
1580 DOM
.entropyCrackTime
.text(timeToCrack
);
1581 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1582 DOM
.entropyBits
.text(numberOfBits
);
1583 DOM
.entropyWordCount
.text(wordCount
);
1584 DOM
.entropyBinary
.text(spacedBinaryStr
);
1585 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1586 // detect and warn of filtering
1587 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1588 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1589 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1591 DOM
.entropyFilterWarning
.removeClass('hidden');
1594 DOM
.entropyFilterWarning
.addClass('hidden');
1598 function getEntropyTypeStr(entropy
) {
1599 var typeStr
= entropy
.base
.str
;
1600 // Add some detail if these are cards
1601 if (entropy
.base
.asInt
== 52) {
1602 var cardDetail
= []; // array of message strings
1603 // Detect duplicates
1605 var dupeTracker
= {};
1606 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1607 var card
= entropy
.base
.parts
[i
];
1608 var cardUpper
= card
.toUpperCase();
1609 if (cardUpper
in dupeTracker
) {
1612 dupeTracker
[cardUpper
] = true;
1614 if (dupes
.length
> 0) {
1615 var dupeWord
= "duplicates";
1616 if (dupes
.length
== 1) {
1617 dupeWord
= "duplicate";
1619 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1620 if (dupes
.length
> 3) {
1623 cardDetail
.push(msg
);
1626 var uniqueCards
= [];
1627 for (var uniqueCard
in dupeTracker
) {
1628 uniqueCards
.push(uniqueCard
);
1630 if (uniqueCards
.length
== 52) {
1631 cardDetail
.unshift("full deck");
1633 // Detect missing cards
1634 var values
= "A23456789TJQK";
1636 var missingCards
= [];
1637 for (var i
=0; i
<suits
.length
; i
++) {
1638 for (var j
=0; j
<values
.length
; j
++) {
1639 var card
= values
[j
] + suits
[i
];
1640 if (!(card
in dupeTracker
)) {
1641 missingCards
.push(card
);
1645 // Display missing cards if six or less, ie clearly going for full deck
1646 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1647 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1648 if (missingCards
.length
> 3) {
1651 cardDetail
.push(msg
);
1653 // Add card details to typeStr
1654 if (cardDetail
.length
> 0) {
1655 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1661 function setQrEvents(els
) {
1662 els
.on("mouseenter", createQr
);
1663 els
.on("mouseleave", destroyQr
);
1664 els
.on("click", toggleQr
);
1667 function createQr(e
) {
1668 var content
= e
.target
.textContent
|| e
.target
.value
;
1676 DOM
.qrImage
.append(qrEl
);
1678 DOM
.qrHider
.addClass("hidden");
1681 DOM
.qrHider
.removeClass("hidden");
1683 DOM
.qrContainer
.removeClass("hidden");
1687 function destroyQr() {
1688 DOM
.qrImage
.text("");
1689 DOM
.qrContainer
.addClass("hidden");
1692 function toggleQr() {
1694 DOM
.qrHider
.toggleClass("hidden");
1695 DOM
.qrHint
.toggleClass("hidden");
1698 function bip44TabSelected() {
1699 return DOM
.bip44tab
.hasClass("active");
1702 function bip32TabSelected() {
1703 return DOM
.bip32tab
.hasClass("active");
1706 function networkIsEthereum() {
1707 var name
= networks
[DOM
.network
.val()].name
;
1708 return (name
== "ETH - Ethereum")
1709 || (name
== "ETC - Ethereum Classic")
1710 || (name
== "EWT - EnergyWeb")
1711 || (name
== "PIRL - Pirl")
1712 || (name
== "MIX - MIX")
1713 || (name
== "MUSIC - Musicoin")
1714 || (name
== "POA - Poa")
1715 || (name
== "EXP - Expanse")
1716 || (name
== "CLO - Callisto")
1717 || (name
== "DXN - DEXON")
1718 || (name
== "ELLA - Ellaism")
1719 || (name
== "ESN - Ethersocial Network")
1720 || (name
== "VET - VeChain")
1723 function networkHasSegwit() {
1725 if ("baseNetwork" in network
) {
1726 n
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1728 // check if only p2wpkh params are required
1729 if (p2wpkhSelected()) {
1730 return "p2wpkh" in n
;
1732 // check if only p2wpkh-in-p2sh params are required
1733 else if (p2wpkhInP2shSelected()) {
1734 return "p2wpkhInP2sh" in n
;
1736 // require both if it's unclear which params are required
1737 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1740 function bip49TabSelected() {
1741 return DOM
.bip49tab
.hasClass("active");
1744 function bip84TabSelected() {
1745 return DOM
.bip84tab
.hasClass("active");
1748 function bip141TabSelected() {
1749 return DOM
.bip141tab
.hasClass("active");
1752 function setBip44ChangeValue() {
1753 if (isDefaultBip44ChangeValue
) {
1754 if (networkIsEthereum()) {
1755 DOM
.bip44change
.val("");
1757 DOM
.bip44change
.val(0);
1762 function modifiedDefaultBip44ChangeValue() {
1763 isDefaultBip44ChangeValue
= false;
1766 function resetDefaultBip44ChangeValue() {
1767 isDefaultBip44ChangeValue
= true;
1768 setBip44ChangeValue();
1771 function setHdCoin(coinValue
) {
1772 DOM
.bip44coin
.val(coinValue
);
1773 DOM
.bip49coin
.val(coinValue
);
1774 DOM
.bip84coin
.val(coinValue
);
1775 setBip44ChangeValue();
1778 function showSegwitAvailable() {
1779 DOM
.bip49unavailable
.addClass("hidden");
1780 DOM
.bip49available
.removeClass("hidden");
1781 DOM
.bip84unavailable
.addClass("hidden");
1782 DOM
.bip84available
.removeClass("hidden");
1783 DOM
.bip141unavailable
.addClass("hidden");
1784 DOM
.bip141available
.removeClass("hidden");
1787 function showSegwitUnavailable() {
1788 DOM
.bip49available
.addClass("hidden");
1789 DOM
.bip49unavailable
.removeClass("hidden");
1790 DOM
.bip84available
.addClass("hidden");
1791 DOM
.bip84unavailable
.removeClass("hidden");
1792 DOM
.bip141available
.addClass("hidden");
1793 DOM
.bip141unavailable
.removeClass("hidden");
1796 function adjustNetworkForSegwit() {
1797 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1798 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1800 // See https://github.com/iancoleman/bip39/issues/125
1801 var segwitNetworks
= null;
1802 // if a segwit network is alread selected, need to use base network to
1803 // look up new parameters
1804 if ("baseNetwork" in network
) {
1805 network
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1807 // choose the right segwit params
1808 if (p2wpkhSelected() && "p2wpkh" in network
) {
1809 network
= network
.p2wpkh
;
1811 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1812 network
= network
.p2wpkhInP2sh
;
1816 function lastIndexInTable() {
1817 var pathText
= DOM
.addresses
.find(".index").last().text();
1818 var pathBits
= pathText
.split("/");
1819 var lastBit
= pathBits
[pathBits
.length
-1];
1820 var lastBitClean
= lastBit
.replace("'", "");
1821 return parseInt(lastBitClean
);
1824 function uint8ArrayToHex(a
) {
1826 for (var i
=0; i
<a
.length
; i
++) {
1827 var h
= a
[i
].toString(16);
1828 while (h
.length
< 2) {
1836 function showWordIndexes() {
1837 var phrase
= DOM
.phrase
.val();
1838 var words
= phraseToWordArray(phrase
);
1839 var wordIndexes
= [];
1840 var language
= getLanguage();
1841 for (var i
=0; i
<words
.length
; i
++) {
1842 var word
= words
[i
];
1843 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1844 wordIndexes
.push(wordIndex
);
1846 var wordIndexesStr
= wordIndexes
.join(", ");
1847 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1850 function showChecksum() {
1851 var phrase
= DOM
.phrase
.val();
1852 var words
= phraseToWordArray(phrase
);
1853 var checksumBitlength
= words
.length
/ 3;
1856 var language
= getLanguage();
1857 for (var i
=words
.length
-1; i
>=0; i
--) {
1858 var word
= words
[i
];
1859 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1860 var wordBinary
= wordIndex
.toString(2);
1861 while (wordBinary
.length
< 11) {
1862 wordBinary
= "0" + wordBinary
;
1864 var binaryStr
= wordBinary
+ binaryStr
;
1865 if (binaryStr
.length
>= checksumBitlength
) {
1866 var start
= binaryStr
.length
- checksumBitlength
;
1867 var end
= binaryStr
.length
;
1868 checksum
= binaryStr
.substring(start
, end
);
1869 // add spaces so the last group is 11 bits, not the first
1870 checksum
= checksum
.split("").reverse().join("")
1871 checksum
= addSpacesEveryElevenBits(checksum
);
1872 checksum
= checksum
.split("").reverse().join("")
1876 DOM
.entropyChecksum
.text(checksum
);
1879 function updateCsv() {
1880 var tableCsv
= "path,address,public key,private key\n";
1881 var rows
= DOM
.addresses
.find("tr");
1882 for (var i
=0; i
<rows
.length
; i
++) {
1883 var row
= $(rows
[i
]);
1884 var cells
= row
.find("td");
1885 for (var j
=0; j
<cells
.length
; j
++) {
1886 var cell
= $(cells
[j
]);
1887 if (!cell
.children().hasClass("invisible")) {
1888 tableCsv
= tableCsv
+ cell
.text();
1890 if (j
!= cells
.length
- 1) {
1891 tableCsv
= tableCsv
+ ",";
1894 tableCsv
= tableCsv
+ "\n";
1896 DOM
.csv
.val(tableCsv
);
1899 function addSpacesEveryElevenBits(binaryStr
) {
1900 return binaryStr
.match(/.{1,11}/g).join(" ");
1905 name: "AC - Asiacoin",
1906 onSelect: function() {
1907 network
= bitcoinjs
.bitcoin
.networks
.asiacoin
;
1912 name: "ACC - Adcoin",
1913 onSelect: function() {
1914 network
= bitcoinjs
.bitcoin
.networks
.adcoin
;
1919 name: "ARYA - Aryacoin",
1920 onSelect: function() {
1921 network
= bitcoinjs
.bitcoin
.networks
.aryacoin
;
1926 name: "AUR - Auroracoin",
1927 onSelect: function() {
1928 network
= bitcoinjs
.bitcoin
.networks
.auroracoin
;
1934 onSelect: function() {
1935 network
= bitcoinjs
.bitcoin
.networks
.axe
;
1940 name: "ANON - ANON",
1941 onSelect: function() {
1942 network
= bitcoinjs
.bitcoin
.networks
.anon
;
1947 name: "BOLI - Bolivarcoin",
1948 onSelect: function() {
1949 network
= bitcoinjs
.bitcoin
.networks
.bolivarcoin
;
1954 name: "BCA - Bitcoin Atom",
1955 onSelect: function() {
1956 network
= bitcoinjs
.bitcoin
.networks
.atom
;
1961 name: "BCH - Bitcoin Cash",
1962 onSelect: function() {
1963 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
1968 name: "BEET - Beetlecoin",
1969 onSelect: function() {
1970 network
= bitcoinjs
.bitcoin
.networks
.beetlecoin
;
1975 name: "BELA - Belacoin",
1976 onSelect: function() {
1977 network
= bitcoinjs
.bitcoin
.networks
.belacoin
;
1982 name: "BLK - BlackCoin",
1983 onSelect: function() {
1984 network
= bitcoinjs
.bitcoin
.networks
.blackcoin
;
1989 name: "BND - Blocknode",
1990 onSelect: function() {
1991 network
= bitcoinjs
.bitcoin
.networks
.blocknode
;
1996 name: "tBND - Blocknode Testnet",
1997 onSelect: function() {
1998 network
= bitcoinjs
.bitcoin
.networks
.blocknode_testnet
;
2003 name: "BRIT - Britcoin",
2004 onSelect: function() {
2005 network
= bitcoinjs
.bitcoin
.networks
.britcoin
;
2010 name: "BSD - Bitsend",
2011 onSelect: function() {
2012 network
= bitcoinjs
.bitcoin
.networks
.bitsend
;
2017 name: "BST - BlockStamp",
2018 onSelect: function() {
2019 network
= bitcoinjs
.bitcoin
.networks
.blockstamp
;
2025 onSelect: function() {
2026 network
= bitcoinjs
.bitcoin
.networks
.bata
;
2031 name: "BTC - Bitcoin",
2032 onSelect: function() {
2033 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2038 name: "BTC - Bitcoin Testnet",
2039 onSelect: function() {
2040 network
= bitcoinjs
.bitcoin
.networks
.testnet
;
2045 name: "BITG - Bitcoin Green",
2046 onSelect: function() {
2047 network
= bitcoinjs
.bitcoin
.networks
.bitcoingreen
;
2052 name: "BTCP - Bitcoin Private",
2053 onSelect: function() {
2054 network
= bitcoinjs
.bitcoin
.networks
.bitcoinprivate
;
2059 name: "BSV - BitcoinSV",
2060 onSelect: function() {
2061 network
= bitcoinjs
.bitcoin
.networks
.bitcoinsv
;
2066 name: "BTCZ - Bitcoinz",
2067 onSelect: function() {
2068 network
= bitcoinjs
.bitcoin
.networks
.bitcoinz
;
2073 name: "BTDX - BitCloud",
2074 onSelect: function() {
2075 network
= bitcoinjs
.bitcoin
.networks
.bitcloud
;
2080 name: "BTG - Bitcoin Gold",
2081 onSelect: function() {
2082 network
= bitcoinjs
.bitcoin
.networks
.bgold
;
2087 name: "BTX - Bitcore",
2088 onSelect: function() {
2089 network
= bitcoinjs
.bitcoin
.networks
.bitcore
;
2094 name: "CCN - Cannacoin",
2095 onSelect: function() {
2096 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2101 name: "CESC - Cryptoescudo",
2102 onSelect: function() {
2103 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2108 name: "CDN - Canadaecoin",
2109 onSelect: function() {
2110 network
= bitcoinjs
.bitcoin
.networks
.canadaecoin
;
2115 name: "CLAM - Clams",
2116 onSelect: function() {
2117 network
= bitcoinjs
.bitcoin
.networks
.clam
;
2122 name: "CLO - Callisto",
2123 segwitAvailable: false,
2124 onSelect: function() {
2125 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2130 name: "CLUB - Clubcoin",
2131 onSelect: function() {
2132 network
= bitcoinjs
.bitcoin
.networks
.clubcoin
;
2137 name: "CMP - Compcoin",
2138 onSelect: function() {
2139 network
= bitcoinjs
.bitcoin
.networks
.compcoin
;
2144 name: "CPU - CPUchain",
2145 onSelect: function() {
2146 network
= bitcoinjs
.bitcoin
.networks
.cpuchain
;
2151 name: "CRAVE - Crave",
2152 onSelect: function() {
2153 network
= bitcoinjs
.bitcoin
.networks
.crave
;
2158 name: "CRW - Crown (Legacy)",
2159 onSelect: function() {
2160 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2165 name: "CRW - Crown",
2166 onSelect: function() {
2167 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2172 name: "CSC - CasinoCoin",
2173 onSelect: function() {
2174 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2179 name: "DASH - Dash",
2180 onSelect: function() {
2181 network
= bitcoinjs
.bitcoin
.networks
.dash
;
2186 name: "DASH - Dash Testnet",
2187 onSelect: function() {
2188 network
= bitcoinjs
.bitcoin
.networks
.dashtn
;
2193 name: "DFC - Defcoin",
2194 onSelect: function() {
2195 network
= bitcoinjs
.bitcoin
.networks
.defcoin
;
2200 name: "DGB - Digibyte",
2201 onSelect: function() {
2202 network
= bitcoinjs
.bitcoin
.networks
.digibyte
;
2207 name: "DGC - Digitalcoin",
2208 onSelect: function() {
2209 network
= bitcoinjs
.bitcoin
.networks
.digitalcoin
;
2214 name: "DMD - Diamond",
2215 onSelect: function() {
2216 network
= bitcoinjs
.bitcoin
.networks
.diamond
;
2221 name: "DNR - Denarius",
2222 onSelect: function() {
2223 network
= bitcoinjs
.bitcoin
.networks
.denarius
;
2228 name: "DOGE - Dogecoin",
2229 onSelect: function() {
2230 network
= bitcoinjs
.bitcoin
.networks
.dogecoin
;
2235 name: "DOGEt - Dogecoin Testnet",
2236 onSelect: function() {
2237 network
= bitcoinjs
.bitcoin
.networks
.dogecointestnet
;
2242 name: "DXN - DEXON",
2243 onSelect: function() {
2244 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2249 name: "ECN - Ecoin",
2250 onSelect: function() {
2251 network
= bitcoinjs
.bitcoin
.networks
.ecoin
;
2256 name: "EDRC - Edrcoin",
2257 onSelect: function() {
2258 network
= bitcoinjs
.bitcoin
.networks
.edrcoin
;
2263 name: "EFL - Egulden",
2264 onSelect: function() {
2265 network
= bitcoinjs
.bitcoin
.networks
.egulden
;
2270 name: "ELA - Elastos",
2271 onSelect: function () {
2272 network
= bitcoinjs
.bitcoin
.networks
.elastos
;
2277 name: "ELLA - Ellaism",
2278 segwitAvailable: false,
2279 onSelect: function() {
2280 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2285 name: "EMC2 - Einsteinium",
2286 onSelect: function() {
2287 network
= bitcoinjs
.bitcoin
.networks
.einsteinium
;
2292 name: "ERC - Europecoin",
2293 onSelect: function() {
2294 network
= bitcoinjs
.bitcoin
.networks
.europecoin
;
2299 name: "EOS - EOSIO",
2300 onSelect: function() {
2301 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2306 name: "ESN - Ethersocial Network",
2307 segwitAvailable: false,
2308 onSelect: function() {
2309 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2314 name: "ETC - Ethereum Classic",
2315 segwitAvailable: false,
2316 onSelect: function() {
2317 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2322 name: "ETH - Ethereum",
2323 onSelect: function() {
2324 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2329 name: "EWT - EnergyWeb",
2330 onSelect: function() {
2331 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2336 name: "EXCL - Exclusivecoin",
2337 onSelect: function() {
2338 network
= bitcoinjs
.bitcoin
.networks
.exclusivecoin
;
2343 name: "EXCC - ExchangeCoin",
2344 onSelect: function() {
2345 network
= bitcoinjs
.bitcoin
.networks
.exchangecoin
;
2350 name: "EXP - Expanse",
2351 segwitAvailable: false,
2352 onSelect: function() {
2353 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2359 onSelect: function() {
2360 network
= bitcoinjs
.bitcoin
.networks
.fix
;
2365 name: "FIX - FIX Testnet",
2366 onSelect: function() {
2367 network
= bitcoinjs
.bitcoin
.networks
.fixtestnet
;
2372 name: "FJC - Fujicoin",
2373 onSelect: function() {
2374 network
= bitcoinjs
.bitcoin
.networks
.fujicoin
;
2379 name: "FLASH - Flashcoin",
2380 onSelect: function() {
2381 network
= bitcoinjs
.bitcoin
.networks
.flashcoin
;
2386 name: "FRST - Firstcoin",
2387 onSelect: function() {
2388 network
= bitcoinjs
.bitcoin
.networks
.firstcoin
;
2393 name: "FTC - Feathercoin",
2394 onSelect: function() {
2395 network
= bitcoinjs
.bitcoin
.networks
.feathercoin
;
2400 name: "GAME - GameCredits",
2401 onSelect: function() {
2402 network
= bitcoinjs
.bitcoin
.networks
.game
;
2407 name: "GBX - Gobyte",
2408 onSelect: function() {
2409 network
= bitcoinjs
.bitcoin
.networks
.gobyte
;
2414 name: "GCR - GCRCoin",
2415 onSelect: function() {
2416 network
= bitcoinjs
.bitcoin
.networks
.gcr
;
2421 name: "GRC - Gridcoin",
2422 onSelect: function() {
2423 network
= bitcoinjs
.bitcoin
.networks
.gridcoin
;
2428 name: "GRS - Groestlcoin",
2429 onSelect: function() {
2430 network
= bitcoinjs
.bitcoin
.networks
.groestlcoin
;
2435 name: "GRS - Groestlcoin Testnet",
2436 onSelect: function() {
2437 network
= bitcoinjs
.bitcoin
.networks
.groestlcointestnet
;
2442 name: "HNC - Helleniccoin",
2443 onSelect: function() {
2444 network
= bitcoinjs
.bitcoin
.networks
.helleniccoin
;
2449 name: "HUSH - Hush (Legacy)",
2450 onSelect: function() {
2451 network
= bitcoinjs
.bitcoin
.networks
.hush
;
2456 name: "HUSH - Hush3",
2457 onSelect: function() {
2458 network
= bitcoinjs
.bitcoin
.networks
.hush3
;
2463 name: "INSN - Insane",
2464 onSelect: function() {
2465 network
= bitcoinjs
.bitcoin
.networks
.insane
;
2471 onSelect: function() {
2472 network
= bitcoinjs
.bitcoin
.networks
.iop
;
2477 name: "IXC - Ixcoin",
2478 onSelect: function() {
2479 network
= bitcoinjs
.bitcoin
.networks
.ixcoin
;
2484 name: "JBS - Jumbucks",
2485 onSelect: function() {
2486 network
= bitcoinjs
.bitcoin
.networks
.jumbucks
;
2491 name: "KMD - Komodo",
2492 bip49available: false,
2493 onSelect: function() {
2494 network
= bitcoinjs
.bitcoin
.networks
.komodo
;
2499 name: "KOBO - Kobocoin",
2500 bip49available: false,
2501 onSelect: function() {
2502 network
= bitcoinjs
.bitcoin
.networks
.kobocoin
;
2507 name: "LBC - Library Credits",
2508 onSelect: function() {
2509 network
= bitcoinjs
.bitcoin
.networks
.lbry
;
2514 name: "LCC - Litecoincash",
2515 onSelect: function() {
2516 network
= bitcoinjs
.bitcoin
.networks
.litecoincash
;
2521 name: "LDCN - Landcoin",
2522 onSelect: function() {
2523 network
= bitcoinjs
.bitcoin
.networks
.landcoin
;
2528 name: "LINX - Linx",
2529 onSelect: function() {
2530 network
= bitcoinjs
.bitcoin
.networks
.linx
;
2535 name: "LKR - Lkrcoin",
2536 segwitAvailable: false,
2537 onSelect: function() {
2538 network
= bitcoinjs
.bitcoin
.networks
.lkrcoin
;
2543 name: "LTC - Litecoin",
2544 onSelect: function() {
2545 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
2547 DOM
.litecoinLtubContainer
.removeClass("hidden");
2551 name: "LTCt - Litecoin Testnet",
2552 onSelect: function() {
2553 network
= bitcoinjs
.bitcoin
.networks
.litecointestnet
;
2555 DOM
.litecoinLtubContainer
.removeClass("hidden");
2559 name: "LTZ - LitecoinZ",
2560 onSelect: function() {
2561 network
= bitcoinjs
.bitcoin
.networks
.litecoinz
;
2566 name: "LYNX - Lynx",
2567 onSelect: function() {
2568 network
= bitcoinjs
.bitcoin
.networks
.lynx
;
2573 name: "MAZA - Maza",
2574 onSelect: function() {
2575 network
= bitcoinjs
.bitcoin
.networks
.maza
;
2580 name: "MEC - Megacoin",
2581 onSelect: function() {
2582 network
= bitcoinjs
.bitcoin
.networks
.megacoin
;
2588 segwitAvailable: false,
2589 onSelect: function() {
2590 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2595 name: "MNX - Minexcoin",
2596 onSelect: function() {
2597 network
= bitcoinjs
.bitcoin
.networks
.minexcoin
;
2602 name: "MONA - Monacoin",
2603 onSelect: function() {
2604 network
= bitcoinjs
.bitcoin
.networks
.monacoin
,
2609 name: "MONK - Monkey Project",
2610 onSelect: function() {
2611 network
= bitcoinjs
.bitcoin
.networks
.monkeyproject
,
2616 name: "MUSIC - Musicoin",
2617 segwitAvailable: false,
2618 onSelect: function() {
2619 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2624 name: "NAV - Navcoin",
2625 onSelect: function() {
2626 network
= bitcoinjs
.bitcoin
.networks
.navcoin
;
2631 name: "NAS - Nebulas",
2632 onSelect: function() {
2633 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2638 name: "NEBL - Neblio",
2639 onSelect: function() {
2640 network
= bitcoinjs
.bitcoin
.networks
.neblio
;
2645 name: "NEOS - Neoscoin",
2646 onSelect: function() {
2647 network
= bitcoinjs
.bitcoin
.networks
.neoscoin
;
2652 name: "NIX - NIX Platform",
2653 onSelect: function() {
2654 network
= bitcoinjs
.bitcoin
.networks
.nix
;
2659 name: "NLG - Gulden",
2660 onSelect: function() {
2661 network
= bitcoinjs
.bitcoin
.networks
.gulden
;
2666 name: "NMC - Namecoin",
2667 onSelect: function() {
2668 network
= bitcoinjs
.bitcoin
.networks
.namecoin
;
2673 name: "NRG - Energi",
2674 onSelect: function() {
2675 network
= bitcoinjs
.bitcoin
.networks
.energi
;
2680 name: "NRO - Neurocoin",
2681 onSelect: function() {
2682 network
= bitcoinjs
.bitcoin
.networks
.neurocoin
;
2687 name: "NSR - Nushares",
2688 onSelect: function() {
2689 network
= bitcoinjs
.bitcoin
.networks
.nushares
;
2694 name: "NYC - Newyorkc",
2695 onSelect: function() {
2696 network
= bitcoinjs
.bitcoin
.networks
.newyorkc
;
2701 name: "NVC - Novacoin",
2702 onSelect: function() {
2703 network
= bitcoinjs
.bitcoin
.networks
.novacoin
;
2708 name: "OK - Okcash",
2709 onSelect: function() {
2710 network
= bitcoinjs
.bitcoin
.networks
.okcash
;
2715 name: "OMNI - Omnicore",
2716 onSelect: function() {
2717 network
= bitcoinjs
.bitcoin
.networks
.omnicore
;
2722 name: "ONION - DeepOnion",
2723 onSelect: function() {
2724 network
= bitcoinjs
.bitcoin
.networks
.deeponion
;
2729 name: "ONX - Onixcoin",
2730 onSelect: function() {
2731 network
= bitcoinjs
.bitcoin
.networks
.onixcoin
;
2736 name: "PHR - Phore",
2737 onSelect: function() {
2738 network
= bitcoinjs
.bitcoin
.networks
.phore
;
2743 name: "PINK - Pinkcoin",
2744 onSelect: function() {
2745 network
= bitcoinjs
.bitcoin
.networks
.pinkcoin
;
2750 name: "PIRL - Pirl",
2751 segwitAvailable: false,
2752 onSelect: function() {
2753 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2758 name: "PIVX - PIVX",
2759 onSelect: function() {
2760 network
= bitcoinjs
.bitcoin
.networks
.pivx
;
2765 name: "PIVX - PIVX Testnet",
2766 onSelect: function() {
2767 network
= bitcoinjs
.bitcoin
.networks
.pivxtestnet
;
2773 segwitAvailable: false,
2774 onSelect: function() {
2775 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2780 name: "POSW - POSWcoin",
2781 onSelect: function() {
2782 network
= bitcoinjs
.bitcoin
.networks
.poswcoin
;
2787 name: "POT - Potcoin",
2788 onSelect: function() {
2789 network
= bitcoinjs
.bitcoin
.networks
.potcoin
;
2794 name: "PPC - Peercoin",
2795 onSelect: function() {
2796 network
= bitcoinjs
.bitcoin
.networks
.peercoin
;
2801 name: "PRJ - ProjectCoin",
2802 onSelect: function() {
2803 network
= bitcoinjs
.bitcoin
.networks
.projectcoin
;
2808 name: "PSB - Pesobit",
2809 onSelect: function() {
2810 network
= bitcoinjs
.bitcoin
.networks
.pesobit
;
2815 name: "PUT - Putincoin",
2816 onSelect: function() {
2817 network
= bitcoinjs
.bitcoin
.networks
.putincoin
;
2822 name: "RPD - Rapids",
2823 onSelect: function() {
2824 network
= bitcoinjs
.bitcoin
.networks
.rapids
;
2829 name: "RVN - Ravencoin",
2830 onSelect: function() {
2831 network
= bitcoinjs
.bitcoin
.networks
.ravencoin
;
2836 name: "RBY - Rubycoin",
2837 onSelect: function() {
2838 network
= bitcoinjs
.bitcoin
.networks
.rubycoin
;
2843 name: "RDD - Reddcoin",
2844 onSelect: function() {
2845 network
= bitcoinjs
.bitcoin
.networks
.reddcoin
;
2850 name: "RVR - RevolutionVR",
2851 onSelect: function() {
2852 network
= bitcoinjs
.bitcoin
.networks
.revolutionvr
;
2857 name: "SAFE - Safecoin",
2858 onSelect: function() {
2859 network
= bitcoinjs
.bitcoin
.networks
.safecoin
;
2864 name: "SLS - Salus",
2865 onSelect: function() {
2866 network
= bitcoinjs
.bitcoin
.networks
.salus
;
2871 name: "SDC - ShadowCash",
2872 onSelect: function() {
2873 network
= bitcoinjs
.bitcoin
.networks
.shadow
;
2878 name: "SDC - ShadowCash Testnet",
2879 onSelect: function() {
2880 network
= bitcoinjs
.bitcoin
.networks
.shadowtn
;
2885 name: "SLM - Slimcoin",
2886 onSelect: function() {
2887 network
= bitcoinjs
.bitcoin
.networks
.slimcoin
;
2892 name: "SLM - Slimcoin Testnet",
2893 onSelect: function() {
2894 network
= bitcoinjs
.bitcoin
.networks
.slimcointn
;
2899 name: "SLP - Simple Ledger Protocol",
2900 onSelect: function() {
2901 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2906 name: "SLR - Solarcoin",
2907 onSelect: function() {
2908 network
= bitcoinjs
.bitcoin
.networks
.solarcoin
;
2913 name: "SMLY - Smileycoin",
2914 onSelect: function() {
2915 network
= bitcoinjs
.bitcoin
.networks
.smileycoin
;
2920 name: "STASH - Stash",
2921 onSelect: function() {
2922 network
= bitcoinjs
.bitcoin
.networks
.stash
;
2927 name: "STASH - Stash Testnet",
2928 onSelect: function() {
2929 network
= bitcoinjs
.bitcoin
.networks
.stashtn
;
2934 name: "STRAT - Stratis",
2935 onSelect: function() {
2936 network
= bitcoinjs
.bitcoin
.networks
.stratis
;
2941 name: "TSTRAT - Stratis Testnet",
2942 onSelect: function() {
2943 network
= bitcoinjs
.bitcoin
.networks
.stratistest
;
2948 name: "SYS - Syscoin",
2949 onSelect: function() {
2950 network
= bitcoinjs
.bitcoin
.networks
.syscoin
;
2955 name: "THC - Hempcoin",
2956 onSelect: function() {
2957 network
= bitcoinjs
.bitcoin
.networks
.hempcoin
;
2962 name: "THT - Thought",
2963 onSelect: function() {
2964 network
= bitcoinjs
.bitcoin
.networks
.thought
;
2970 onSelect: function() {
2971 network
= bitcoinjs
.bitcoin
.networks
.toa
;
2976 name: "TWINS - TWINS",
2977 onSelect: function() {
2978 network
= bitcoinjs
.bitcoin
.networks
.twins
;
2983 name: "TWINS - TWINS Testnet",
2984 onSelect: function() {
2985 network
= bitcoinjs
.bitcoin
.networks
.twinstestnet
;
2990 name: "USC - Ultimatesecurecash",
2991 onSelect: function() {
2992 network
= bitcoinjs
.bitcoin
.networks
.ultimatesecurecash
;
2997 name: "USNBT - NuBits",
2998 onSelect: function() {
2999 network
= bitcoinjs
.bitcoin
.networks
.nubits
;
3004 name: "UNO - Unobtanium",
3005 onSelect: function() {
3006 network
= bitcoinjs
.bitcoin
.networks
.unobtanium
;
3011 name: "VASH - Vpncoin",
3012 onSelect: function() {
3013 network
= bitcoinjs
.bitcoin
.networks
.vpncoin
;
3018 name: "VET - VeChain",
3019 onSelect: function() {
3020 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3025 name: "VIA - Viacoin",
3026 onSelect: function() {
3027 network
= bitcoinjs
.bitcoin
.networks
.viacoin
;
3032 name: "VIA - Viacoin Testnet",
3033 onSelect: function() {
3034 network
= bitcoinjs
.bitcoin
.networks
.viacointestnet
;
3039 name: "VIVO - Vivo",
3040 onSelect: function() {
3041 network
= bitcoinjs
.bitcoin
.networks
.vivo
;
3046 name: "VTC - Vertcoin",
3047 onSelect: function() {
3048 network
= bitcoinjs
.bitcoin
.networks
.vertcoin
;
3053 name: "WGR - Wagerr",
3054 onSelect: function() {
3055 network
= bitcoinjs
.bitcoin
.networks
.wagerr
;
3060 name: "WC - Wincoin",
3061 onSelect: function() {
3062 network
= bitcoinjs
.bitcoin
.networks
.wincoin
;
3067 name: "XAX - Artax",
3068 onSelect: function() {
3069 network
= bitcoinjs
.bitcoin
.networks
.artax
;
3074 name: "XBC - Bitcoinplus",
3075 onSelect: function() {
3076 network
= bitcoinjs
.bitcoin
.networks
.bitcoinplus
;
3081 name: "XLM - Stellar",
3082 onSelect: function() {
3083 network
= stellarUtil
.dummyNetwork
;
3088 name: "XMY - Myriadcoin",
3089 onSelect: function() {
3090 network
= bitcoinjs
.bitcoin
.networks
.myriadcoin
;
3095 name: "XRP - Ripple",
3096 onSelect: function() {
3097 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3102 name: "XVC - Vcash",
3103 onSelect: function() {
3104 network
= bitcoinjs
.bitcoin
.networks
.vcash
;
3109 name: "XVG - Verge",
3110 onSelect: function() {
3111 network
= bitcoinjs
.bitcoin
.networks
.verge
;
3116 name: "XUEZ - Xuez",
3117 segwitAvailable: false,
3118 onSelect: function() {
3119 network
= bitcoinjs
.bitcoin
.networks
.xuez
;
3124 name: "XWC - Whitecoin",
3125 onSelect: function() {
3126 network
= bitcoinjs
.bitcoin
.networks
.whitecoin
;
3131 name: "XZC - Zcoin",
3132 onSelect: function() {
3133 network
= bitcoinjs
.bitcoin
.networks
.zcoin
;
3138 name: "ZCL - Zclassic",
3139 onSelect: function() {
3140 network
= bitcoinjs
.bitcoin
.networks
.zclassic
;
3145 name: "ZEC - Zcash",
3146 onSelect: function() {
3147 network
= bitcoinjs
.bitcoin
.networks
.zcash
;
3152 name: "ZEN - Horizen",
3153 onSelect: function() {
3154 network
= bitcoinjs
.bitcoin
.networks
.zencash
;
3162 name: "Bitcoin Core",
3163 onSelect: function() {
3164 DOM
.bip32path
.val("m/0'/0'");
3165 DOM
.hardenedAddresses
.prop('checked', true);
3169 name: "blockchain.info",
3170 onSelect: function() {
3171 DOM
.bip32path
.val("m/44'/0'/0'");
3172 DOM
.hardenedAddresses
.prop('checked', false);
3176 name: "MultiBit HD",
3177 onSelect: function() {
3178 DOM
.bip32path
.val("m/0'/0");
3179 DOM
.hardenedAddresses
.prop('checked', false);
3183 name: "Coinomi, Ledger",
3184 onSelect: function() {
3185 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3186 DOM
.hardenedAddresses
.prop('checked', false);
3191 // ELA - Elastos functions - begin
3192 function displayBip44InfoForELA() {
3197 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3198 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3200 // Calculate the account extended keys
3201 var accountXprv
= elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3202 var accountXpub
= elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3204 // Display the extended keys
3205 DOM
.bip44accountXprv
.val(accountXprv
);
3206 DOM
.bip44accountXpub
.val(accountXpub
);
3209 function displayBip32InfoForELA() {
3214 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3215 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3216 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3218 DOM
.extendedPrivKey
.val(elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3219 DOM
.extendedPubKey
.val(elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3221 // Display the addresses and privkeys
3222 clearAddressesList();
3223 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3224 displayAddresses(0, initialAddressCount
);
3227 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3232 var publicKey
= elastosjs
.getDerivedPublicKey(elastosjs
.getMasterPublicKey(seed
), change
, index
);
3234 privateKey: elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3235 publicKey: publicKey
,
3236 address: elastosjs
.getAddress(publicKey
.toString('hex'))
3239 // ELA - Elastos functions - end