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
.toRawEntropyHex(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
269 function tabChanged() {
271 adjustNetworkForSegwit();
272 var phrase
= DOM
.phrase
.val();
274 // Calculate and display for mnemonic
275 var errorText
= findPhraseErrors(phrase
);
277 showValidationError(errorText
);
280 // Calculate and display
281 var passphrase
= DOM
.passphrase
.val();
282 calcBip32RootKeyFromSeed(phrase
, passphrase
);
285 // Calculate and display for root key
286 var rootKeyBase58
= DOM
.rootKey
.val();
287 var errorText
= validateRootKey(rootKeyBase58
);
289 showValidationError(errorText
);
292 // Calculate and display
293 calcBip32RootKeyFromBase58(rootKeyBase58
);
295 calcForDerivationPath();
298 function delayedEntropyChanged() {
299 hideValidationError();
301 if (entropyChangeTimeoutEvent
!= null) {
302 clearTimeout(entropyChangeTimeoutEvent
);
304 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
307 function entropyChanged() {
308 // If blank entropy, clear mnemonic, addresses, errors
309 if (DOM
.entropy
.val().trim().length
== 0) {
311 clearEntropyFeedback();
313 DOM
.phraseSplit
.val("");
314 showValidationError("Blank entropy");
317 // Get the current phrase to detect changes
318 var phrase
= DOM
.phrase
.val();
319 // Set the phrase from the entropy
320 setMnemonicFromEntropy();
321 // Recalc addresses if the phrase has changed
322 var newPhrase
= DOM
.phrase
.val();
323 if (newPhrase
!= phrase
) {
324 if (newPhrase
.length
== 0) {
336 function delayedRootKeyChanged() {
337 // Warn if there is an existing mnemonic or passphrase.
338 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
339 if (!confirm("This will clear existing mnemonic and passphrase")) {
340 DOM
.rootKey
.val(bip32RootKey
);
344 hideValidationError();
346 // Clear existing mnemonic and passphrase
348 DOM
.phraseSplit
.val("");
349 DOM
.passphrase
.val("");
351 if (rootKeyChangedTimeoutEvent
!= null) {
352 clearTimeout(rootKeyChangedTimeoutEvent
);
354 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
357 function rootKeyChanged() {
359 hideValidationError();
360 var rootKeyBase58
= DOM
.rootKey
.val();
361 var errorText
= validateRootKey(rootKeyBase58
);
363 showValidationError(errorText
);
366 // Calculate and display
367 calcBip32RootKeyFromBase58(rootKeyBase58
);
368 calcForDerivationPath();
371 function litecoinUseLtubChanged() {
372 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
373 if (litecoinUseLtub
) {
374 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
377 network
= bitcoinjs
.bitcoin
.networks
.litecoinXprv
;
382 function calcForDerivationPath() {
384 clearAddressesList();
386 // Don't show segwit if it's selected but network doesn't support it
387 if (segwitSelected() && !networkHasSegwit()) {
388 showSegwitUnavailable();
392 showSegwitAvailable();
393 // Get the derivation path
394 var derivationPath
= getDerivationPath();
395 var errorText
= findDerivationPathErrors(derivationPath
);
397 showValidationError(errorText
);
400 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
401 if (bip44TabSelected()) {
404 else if (bip49TabSelected()) {
407 else if (bip84TabSelected()) {
413 function generateClicked() {
414 if (isUsingOwnEntropy()) {
419 setTimeout(function() {
420 setMnemonicLanguage();
421 var phrase
= generateRandomPhrase();
429 function languageChanged() {
430 setTimeout(function() {
431 setMnemonicLanguage();
432 if (DOM
.phrase
.val().length
> 0) {
433 var newPhrase
= convertPhraseToNewLanguage();
434 DOM
.phrase
.val(newPhrase
);
435 writeSplitPhrase(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
);
496 writeSplitPhrase(words
);
498 var entropyHex
= uint8ArrayToHex(data
);
499 DOM
.entropy
.val(entropyHex
);
500 // ensure entropy fields are consistent with what is being displayed
501 DOM
.entropyMnemonicLength
.val("raw");
505 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
506 seed
= mnemonic
.toSeed(phrase
, passphrase
);
507 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
509 bip32RootKey
= groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
513 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
515 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
518 // try parsing with various segwit network params since this extended
519 // key may be from any one of them.
520 if (networkHasSegwit()) {
522 if ("baseNetwork" in n
) {
523 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
525 // try parsing using base network params
527 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
531 // try parsing using p2wpkh params
534 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
539 // try parsing using p2wpkh-in-p2sh network params
540 if ("p2wpkhInP2sh" in n
) {
542 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
548 // try the network params as currently specified
549 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
552 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
553 // try parsing with various segwit network params since this extended
554 // key may be from any one of them.
555 if (networkHasSegwit()) {
557 if ("baseNetwork" in n
) {
558 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
560 // try parsing using base network params
562 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
566 // try parsing using p2wpkh params
569 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
574 // try parsing using p2wpkh-in-p2sh network params
575 if ("p2wpkhInP2sh" in n
) {
577 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
583 // try the network params as currently specified
584 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
587 function calcBip32ExtendedKey(path
) {
588 // Check there's a root key to derive from
592 var extendedKey
= bip32RootKey
;
593 // Derive the key from the path
594 var pathBits
= path
.split("/");
595 for (var i
=0; i
<pathBits
.length
; i
++) {
596 var bit
= pathBits
[i
];
597 var index
= parseInt(bit
);
601 var hardened
= bit
[bit
.length
-1] == "'";
602 var isPriv
= !(extendedKey
.isNeutered());
603 var invalidDerivationPath
= hardened
&& !isPriv
;
604 if (invalidDerivationPath
) {
608 extendedKey
= extendedKey
.deriveHardened(index
);
611 extendedKey
= extendedKey
.derive(index
);
617 function showValidationError(errorText
) {
623 function hideValidationError() {
629 function findPhraseErrors(phrase
) {
630 // Preprocess the words
631 phrase
= mnemonic
.normalizeString(phrase
);
632 var words
= phraseToWordArray(phrase
);
633 // Detect blank phrase
634 if (words
.length
== 0) {
635 return "Blank mnemonic";
638 for (var i
=0; i
<words
.length
; i
++) {
640 var language
= getLanguage();
641 if (WORDLISTS
[language
].indexOf(word
) == -1) {
642 console
.log("Finding closest match to " + word
);
643 var nearestWord
= findNearestWord(word
);
644 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
647 // Check the words are valid
648 var properPhrase
= wordArrayToPhrase(words
);
649 var isValid
= mnemonic
.check(properPhrase
);
651 return "Invalid mnemonic";
656 function validateRootKey(rootKeyBase58
) {
658 return validateRootKeyGRS(rootKeyBase58
);
660 // try various segwit network params since this extended key may be from
662 if (networkHasSegwit()) {
664 if ("baseNetwork" in n
) {
665 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
667 // try parsing using base network params
669 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
673 // try parsing using p2wpkh params
676 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
681 // try parsing using p2wpkh-in-p2sh network params
682 if ("p2wpkhInP2sh" in n
) {
684 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
690 // try the network params as currently specified
692 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
695 return "Invalid root key";
700 function validateRootKeyGRS(rootKeyBase58
) {
701 // try various segwit network params since this extended key may be from
703 if (networkHasSegwit()) {
705 if ("baseNetwork" in n
) {
706 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
708 // try parsing using base network params
710 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
714 // try parsing using p2wpkh params
717 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
722 // try parsing using p2wpkh-in-p2sh network params
723 if ("p2wpkhInP2sh" in n
) {
725 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
731 // try the network params as currently specified
733 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
736 return "Invalid root key";
741 function getDerivationPath() {
742 if (bip44TabSelected()) {
743 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
744 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
745 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
746 var change
= parseIntNoNaN(DOM
.bip44change
.val(), "");
748 path
+= "/" + purpose
+ "'";
749 path
+= "/" + coin
+ "'";
750 path
+= "/" + account
+ "'";
752 path
+= "/" + change
;
754 DOM
.bip44path
.val(path
);
755 var derivationPath
= DOM
.bip44path
.val();
756 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
757 return derivationPath
;
759 else if (bip49TabSelected()) {
760 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
761 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
762 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
763 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
765 path
+= purpose
+ "'/";
767 path
+= account
+ "'/";
769 DOM
.bip49path
.val(path
);
770 var derivationPath
= DOM
.bip49path
.val();
771 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
772 return derivationPath
;
774 else if (bip84TabSelected()) {
775 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
776 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
777 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
778 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
780 path
+= purpose
+ "'/";
782 path
+= account
+ "'/";
784 DOM
.bip84path
.val(path
);
785 var derivationPath
= DOM
.bip84path
.val();
786 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
787 return derivationPath
;
789 else if (bip32TabSelected()) {
790 var derivationPath
= DOM
.bip32path
.val();
791 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
792 return derivationPath
;
794 else if (bip141TabSelected()) {
795 var derivationPath
= DOM
.bip141path
.val();
796 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
797 return derivationPath
;
800 console
.log("Unknown derivation path");
804 function findDerivationPathErrors(path
) {
805 // TODO is not perfect but is better than nothing
807 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
809 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
810 var maxDepth
= 255; // TODO verify this!!
811 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
812 if (path
[0] != "m") {
813 return "First character must be 'm'";
815 if (path
.length
> 1) {
816 if (path
[1] != "/") {
817 return "Separator must be '/'";
819 var indexes
= path
.split("/");
820 if (indexes
.length
> maxDepth
) {
821 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
823 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
824 var index
= indexes
[depth
];
825 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
826 if (invalidChars
.length
> 0) {
827 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
829 var indexValue
= parseInt(index
.replace("'", ""));
831 return "Invalid number at depth " + depth
;
833 if (indexValue
> maxIndexValue
) {
834 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
838 // Check root key exists or else derivation path is useless!
840 return "No root key";
842 // Check no hardened derivation path when using xpub keys
843 var hardenedPath
= path
.indexOf("'") > -1;
844 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
845 var hardened
= hardenedPath
|| hardenedAddresses
;
846 var isXpubkey
= bip32RootKey
.isNeutered();
847 if (hardened
&& isXpubkey
) {
848 return "Hardened derivation path is invalid with xpub key";
854 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
858 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
861 function displayBip44Info() {
862 // Get the derivation path for the account
863 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
864 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
865 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
867 path
+= purpose
+ "'/";
869 path
+= account
+ "'/";
870 // Calculate the account extended keys
871 var accountExtendedKey
= calcBip32ExtendedKey(path
);
872 var accountXprv
= accountExtendedKey
.toBase58();
873 var accountXpub
= accountExtendedKey
.neutered().toBase58();
875 // Display the extended keys
876 DOM
.bip44accountXprv
.val(accountXprv
);
877 DOM
.bip44accountXpub
.val(accountXpub
);
880 displayBip44InfoForELA();
884 function displayBip49Info() {
885 // Get the derivation path for the account
886 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
887 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
888 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
890 path
+= purpose
+ "'/";
892 path
+= account
+ "'/";
893 // Calculate the account extended keys
894 var accountExtendedKey
= calcBip32ExtendedKey(path
);
895 var accountXprv
= accountExtendedKey
.toBase58();
896 var accountXpub
= accountExtendedKey
.neutered().toBase58();
897 // Display the extended keys
898 DOM
.bip49accountXprv
.val(accountXprv
);
899 DOM
.bip49accountXpub
.val(accountXpub
);
902 function displayBip84Info() {
903 // Get the derivation path for the account
904 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
905 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
906 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
908 path
+= purpose
+ "'/";
910 path
+= account
+ "'/";
911 // Calculate the account extended keys
912 var accountExtendedKey
= calcBip32ExtendedKey(path
);
913 var accountXprv
= accountExtendedKey
.toBase58();
914 var accountXpub
= accountExtendedKey
.neutered().toBase58();
915 // Display the extended keys
916 DOM
.bip84accountXprv
.val(accountXprv
);
917 DOM
.bip84accountXpub
.val(accountXpub
);
920 function displayBip32Info() {
923 var rootKey
= bip32RootKey
.toBase58();
924 DOM
.rootKey
.val(rootKey
);
925 var xprvkeyB58
= "NA";
926 if (!bip32ExtendedKey
.isNeutered()) {
927 xprvkeyB58
= bip32ExtendedKey
.toBase58();
929 var extendedPrivKey
= xprvkeyB58
;
930 DOM
.extendedPrivKey
.val(extendedPrivKey
);
931 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
932 DOM
.extendedPubKey
.val(extendedPubKey
);
933 // Display the addresses and privkeys
934 clearAddressesList();
935 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
936 displayAddresses(0, initialAddressCount
);
939 displayBip32InfoForELA();
943 function displayAddresses(start
, total
) {
944 generationProcesses
.push(new (function() {
948 this.stop = function() {
949 for (var i
=0; i
<rows
.length
; i
++) {
950 rows
[i
].shouldGenerate
= false;
955 for (var i
=0; i
<total
; i
++) {
956 var index
= i
+ start
;
957 var isLast
= i
== total
- 1;
958 rows
.push(new TableRow(index
, isLast
));
964 function segwitSelected() {
965 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
968 function p2wpkhSelected() {
969 return bip84TabSelected() ||
970 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
973 function p2wpkhInP2shSelected() {
974 return bip49TabSelected() ||
975 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
978 function TableRow(index
, isLast
) {
981 this.shouldGenerate
= true;
982 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
983 var useBip38
= DOM
.useBip38
.prop("checked");
984 var bip38password
= DOM
.bip38Password
.val();
985 var isSegwit
= segwitSelected();
986 var segwitAvailable
= networkHasSegwit();
987 var isP2wpkh
= p2wpkhSelected();
988 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
994 function calculateValues() {
995 setTimeout(function() {
996 if (!self
.shouldGenerate
) {
999 // derive HDkey for this row of the table
1001 if (useHardenedAddresses
) {
1002 key
= bip32ExtendedKey
.deriveHardened(index
);
1005 key
= bip32ExtendedKey
.derive(index
);
1007 // bip38 requires uncompressed keys
1008 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1009 var keyPair
= key
.keyPair
;
1010 var useUncompressed
= useBip38
;
1011 if (useUncompressed
) {
1012 keyPair
= new bitcoinjs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1014 keyPair
= new groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1018 var address
= keyPair
.getAddress().toString();
1020 var hasPrivkey
= !key
.isNeutered();
1023 privkey
= keyPair
.toWIF();
1024 // BIP38 encode private key if required
1027 privkey
= groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1028 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1029 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1031 privkey
= bitcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1032 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1037 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1038 var indexText
= getDerivationPath() + "/" + index
;
1039 if (useHardenedAddresses
) {
1040 indexText
= indexText
+ "'";
1042 // Ethereum values are different
1043 if (networkIsEthereum()) {
1044 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1045 privkey
= privKeyBuffer
.toString('hex');
1046 var addressBuffer
= ethUtil
.privateToAddress(privKeyBuffer
);
1047 var hexAddress
= addressBuffer
.toString('hex');
1048 var checksumAddress
= ethUtil
.toChecksumAddress(hexAddress
);
1049 address
= ethUtil
.addHexPrefix(checksumAddress
);
1050 privkey
= ethUtil
.addHexPrefix(privkey
);
1051 pubkey
= ethUtil
.addHexPrefix(pubkey
);
1054 // Stellar is different
1055 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1056 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1057 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1059 path
+= purpose
+ "'/";
1060 path
+= coin
+ "'/" + index
+ "'";
1061 var keypair
= stellarUtil
.getKeypair(path
, seed
);
1063 privkey
= keypair
.secret();
1064 pubkey
= address
= keypair
.publicKey();
1066 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1067 var NasAccount
= require("nebulas-account");
1068 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1069 var nebulasAccount
= new NasAccount();
1070 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1071 address
= nebulasAccount
.getAddressString();
1072 privkey
= nebulasAccount
.getPrivateKeyString();
1073 pubkey
= nebulasAccount
.getPublicKeyString();
1075 // Ripple values are different
1076 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1077 privkey
= convertRipplePriv(privkey
);
1078 address
= convertRippleAdrr(address
);
1080 // CasinoCoin values are different
1081 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1082 privkey
= convertCasinoCoinPriv(privkey
);
1083 address
= convertCasinoCoinAdrr(address
);
1085 // Bitcoin Cash address format may vary
1086 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1087 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1088 if (bchAddrType
== "cashaddr") {
1089 address
= bchaddr
.toCashAddress(address
);
1091 else if (bchAddrType
== "bitpay") {
1092 address
= bchaddr
.toBitpayAddress(address
);
1095 // Bitcoin Cash address format may vary
1096 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1097 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1098 if (bchAddrType
== "cashaddr") {
1099 address
= bchaddr
.toSlpAddress(address
);
1102 // Segwit addresses are different
1104 if (!segwitAvailable
) {
1108 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1109 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1110 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1112 else if (isP2wpkhInP2sh
) {
1113 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1114 var scriptsig
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1115 var addressbytes
= bitcoinjs
.bitcoin
.crypto
.hash160(scriptsig
);
1116 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1117 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1121 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1122 address
= bitcoinjs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1125 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1127 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1128 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1131 //Groestlcoin Addresses are different
1135 if (!segwitAvailable
) {
1139 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1141 else if (isP2wpkhInP2sh
) {
1142 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1145 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1149 let elaAddress
= calcAddressForELA(
1151 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1152 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1153 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1156 address
= elaAddress
.address
;
1157 privkey
= elaAddress
.privateKey
;
1158 pubkey
= elaAddress
.publicKey
;
1161 addAddressToList(indexText
, address
, pubkey
, privkey
);
1173 function showMore() {
1174 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1175 if (isNaN(rowsToAdd
)) {
1177 DOM
.rowsToAdd
.val("20");
1179 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1181 start
= lastIndexInTable() + 1;
1184 var newStart
= start
+ rowsToAdd
;
1185 DOM
.moreRowsStartIndex
.val(newStart
);
1187 if (rowsToAdd
> 200) {
1188 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1189 msg
+= "Do you want to continue?";
1190 if (!confirm(msg
)) {
1194 displayAddresses(start
, rowsToAdd
);
1197 function clearDisplay() {
1198 clearAddressesList();
1200 hideValidationError();
1203 function clearAddressesList() {
1204 DOM
.addresses
.empty();
1209 function stopGenerating() {
1210 while (generationProcesses
.length
> 0) {
1211 var generation
= generationProcesses
.shift();
1216 function clearKeys() {
1221 function clearRootKey() {
1222 DOM
.rootKey
.val("");
1225 function clearDerivedKeys() {
1226 DOM
.extendedPrivKey
.val("");
1227 DOM
.extendedPubKey
.val("");
1228 DOM
.bip44accountXprv
.val("");
1229 DOM
.bip44accountXpub
.val("");
1232 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1233 var row
= $(addressRowTemplate
.html());
1235 var indexCell
= row
.find(".index span");
1236 var addressCell
= row
.find(".address span");
1237 var pubkeyCell
= row
.find(".pubkey span");
1238 var privkeyCell
= row
.find(".privkey span");
1240 indexCell
.text(indexText
);
1241 addressCell
.text(address
);
1242 pubkeyCell
.text(pubkey
);
1243 privkeyCell
.text(privkey
);
1246 indexCell
.addClass("invisible");
1249 addressCell
.addClass("invisible");
1252 pubkeyCell
.addClass("invisible");
1255 privkeyCell
.addClass("invisible");
1257 DOM
.addresses
.append(row
);
1258 var rowShowQrEls
= row
.find("[data-show-qr]");
1259 setQrEvents(rowShowQrEls
);
1262 function hasStrongRandom() {
1263 return 'crypto' in window
&& window
['crypto'] !== null;
1266 function disableForms() {
1267 $("form").on("submit", function(e
) {
1272 function parseIntNoNaN(val
, defaultVal
) {
1273 var v
= parseInt(val
);
1280 function showPending() {
1282 .text("Calculating...")
1286 function findNearestWord(word
) {
1287 var language
= getLanguage();
1288 var words
= WORDLISTS
[language
];
1289 var minDistance
= 99;
1290 var closestWord
= words
[0];
1291 for (var i
=0; i
<words
.length
; i
++) {
1292 var comparedTo
= words
[i
];
1293 if (comparedTo
.indexOf(word
) == 0) {
1296 var distance
= Levenshtein
.get(word
, comparedTo
);
1297 if (distance
< minDistance
) {
1298 closestWord
= comparedTo
;
1299 minDistance
= distance
;
1305 function hidePending() {
1311 function populateNetworkSelect() {
1312 for (var i
=0; i
<networks
.length
; i
++) {
1313 var network
= networks
[i
];
1314 var option
= $("<option>");
1315 option
.attr("value", i
);
1316 option
.text(network
.name
);
1317 if (network
.name
== "BTC - Bitcoin") {
1318 option
.prop("selected", true);
1320 DOM
.phraseNetwork
.append(option
);
1324 function populateClientSelect() {
1325 for (var i
=0; i
<clients
.length
; i
++) {
1326 var client
= clients
[i
];
1327 var option
= $("<option>");
1328 option
.attr("value", i
);
1329 option
.text(client
.name
);
1330 DOM
.bip32Client
.append(option
);
1334 function getLanguage() {
1335 var defaultLanguage
= "english";
1336 // Try to get from existing phrase
1337 var language
= getLanguageFromPhrase();
1338 // Try to get from url if not from phrase
1339 if (language
.length
== 0) {
1340 language
= getLanguageFromUrl();
1342 // Default to English if no other option
1343 if (language
.length
== 0) {
1344 language
= defaultLanguage
;
1349 function getLanguageFromPhrase(phrase
) {
1350 // Check if how many words from existing phrase match a language.
1353 phrase
= DOM
.phrase
.val();
1355 if (phrase
.length
> 0) {
1356 var words
= phraseToWordArray(phrase
);
1357 var languageMatches
= {};
1358 for (l
in WORDLISTS
) {
1359 // Track how many words match in this language
1360 languageMatches
[l
] = 0;
1361 for (var i
=0; i
<words
.length
; i
++) {
1362 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1363 if (wordInLanguage
) {
1364 languageMatches
[l
]++;
1367 // Find languages with most word matches.
1368 // This is made difficult due to commonalities between Chinese
1369 // simplified vs traditional.
1370 var mostMatches
= 0;
1371 var mostMatchedLanguages
= [];
1372 for (var l
in languageMatches
) {
1373 var numMatches
= languageMatches
[l
];
1374 if (numMatches
> mostMatches
) {
1375 mostMatches
= numMatches
;
1376 mostMatchedLanguages
= [l
];
1378 else if (numMatches
== mostMatches
) {
1379 mostMatchedLanguages
.push(l
);
1383 if (mostMatchedLanguages
.length
> 0) {
1384 // Use first language and warn if multiple detected
1385 language
= mostMatchedLanguages
[0];
1386 if (mostMatchedLanguages
.length
> 1) {
1387 console
.warn("Multiple possible languages");
1388 console
.warn(mostMatchedLanguages
);
1395 function getLanguageFromUrl() {
1396 for (var language
in WORDLISTS
) {
1397 if (window
.location
.hash
.indexOf(language
) > -1) {
1404 function setMnemonicLanguage() {
1405 var language
= getLanguage();
1406 // Load the bip39 mnemonic generator for this language if required
1407 if (!(language
in mnemonics
)) {
1408 mnemonics
[language
] = new Mnemonic(language
);
1410 mnemonic
= mnemonics
[language
];
1413 function convertPhraseToNewLanguage() {
1414 var oldLanguage
= getLanguageFromPhrase();
1415 var newLanguage
= getLanguageFromUrl();
1416 var oldPhrase
= DOM
.phrase
.val();
1417 var oldWords
= phraseToWordArray(oldPhrase
);
1419 for (var i
=0; i
<oldWords
.length
; i
++) {
1420 var oldWord
= oldWords
[i
];
1421 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1422 var newWord
= WORDLISTS
[newLanguage
][index
];
1423 newWords
.push(newWord
);
1425 newPhrase
= wordArrayToPhrase(newWords
);
1429 // TODO look at jsbip39 - mnemonic.splitWords
1430 function phraseToWordArray(phrase
) {
1431 var words
= phrase
.split(/\s/g);
1433 for (var i
=0; i
<words
.length
; i
++) {
1434 var word
= words
[i
];
1435 if (word
.length
> 0) {
1436 noBlanks
.push(word
);
1442 // TODO look at jsbip39 - mnemonic.joinWords
1443 function wordArrayToPhrase(words
) {
1444 var phrase
= words
.join(" ");
1445 var language
= getLanguageFromPhrase(phrase
);
1446 if (language
== "japanese") {
1447 phrase
= words
.join("\u3000");
1452 function writeSplitPhrase(phrase
) {
1453 var wordCount
= phrase
.split(/\s/g).length
; //get number of words in phrase
1454 var left
=[]; //initialize array of indexs
1455 for (var i
=0;i
<wordCount
;i
++) left
.push(i
); //add all indexs to array
1456 var group
=[[],[],[]], //make array for 3 groups
1457 groupI
=-1; //initialize group index
1458 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647; //start seed at sudo random value based on hash of words
1459 while (left
.length
>0) { //while indexs left
1460 groupI
=(groupI
+1)%3; //get next group to insert index into
1461 seed
= seed
* 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use)
1462 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646); //get index in left we will use for this group
1463 group
[groupI
].push(left
[selected
]); //add index to group
1464 left
.splice(selected
,1); //remove selected index
1466 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];//make array of cards
1467 for (var i
=0;i
<3;i
++) { //go through each card
1468 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX'; //erase words listed in the group
1469 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]); //combine words on card back to string
1471 DOM
.splitPhrase
.val(cards
.join("\r\n")); //make words visible
1472 var triesPerSecond
=10000000000; //assumed number of tries per second
1473 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
; //get number of bits of unknown data per card
1475 hackTime
="<1 second";
1476 } else if (hackTime
<86400) {
1477 hackTime
=Math
.floor(hackTime
)+" seconds";
1478 } else if(hackTime
<31557600) {
1479 hackTime
=Math
.floor(hackTime
/86400)+" days";
1481 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1483 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1486 function isUsingOwnEntropy() {
1487 return DOM
.useEntropy
.prop("checked");
1490 function setMnemonicFromEntropy() {
1491 clearEntropyFeedback();
1492 // Get entropy value
1493 var entropyStr
= DOM
.entropy
.val();
1494 // Work out minimum base for entropy
1495 var entropy
= Entropy
.fromString(entropyStr
);
1496 if (entropy
.binaryStr
.length
== 0) {
1499 // Show entropy details
1500 showEntropyFeedback(entropy
);
1501 // Use entropy hash if not using raw entropy
1502 var bits
= entropy
.binaryStr
;
1503 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1504 if (mnemonicLength
!= "raw") {
1505 // Get bits by hashing entropy with SHA256
1506 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1507 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1508 bits
= BigInteger
.parse(hex
, 16).toString(2);
1509 while (bits
.length
% 256 != 0) {
1512 // Truncate hash to suit number of words
1513 mnemonicLength
= parseInt(mnemonicLength
);
1514 var numberOfBits
= 32 * mnemonicLength
/ 3;
1515 bits
= bits
.substring(0, numberOfBits
);
1516 // show warning for weak entropy override
1517 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1518 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1521 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1525 // hide warning for weak entropy override
1526 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1528 // Discard trailing entropy
1529 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1530 var start
= bits
.length
- bitsToUse
;
1531 var binaryStr
= bits
.substring(start
);
1532 // Convert entropy string to numeric array
1533 var entropyArr
= [];
1534 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1535 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1536 var entropyByte
= parseInt(byteAsBits
, 2);
1537 entropyArr
.push(entropyByte
)
1539 // Convert entropy array to mnemonic
1540 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1541 // Set the mnemonic in the UI
1542 DOM
.phrase
.val(phrase
);
1543 writeSplitPhrase(phrase
);
1544 // Show the word indexes
1546 // Show the checksum
1550 function clearEntropyFeedback() {
1551 DOM
.entropyCrackTime
.text("...");
1552 DOM
.entropyType
.text("");
1553 DOM
.entropyWordCount
.text("0");
1554 DOM
.entropyEventCount
.text("0");
1555 DOM
.entropyBitsPerEvent
.text("0");
1556 DOM
.entropyBits
.text("0");
1557 DOM
.entropyFiltered
.html(" ");
1558 DOM
.entropyBinary
.html(" ");
1561 function showEntropyFeedback(entropy
) {
1562 var numberOfBits
= entropy
.binaryStr
.length
;
1563 var timeToCrack
= "unknown";
1565 var z
= zxcvbn(entropy
.base
.parts
.join(""));
1566 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1567 if (z
.feedback
.warning
!= "") {
1568 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1572 console
.log("Error detecting entropy strength with zxcvbn:");
1575 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1576 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1577 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1578 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1579 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1580 DOM
.entropyType
.text(entropyTypeStr
);
1581 DOM
.entropyCrackTime
.text(timeToCrack
);
1582 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1583 DOM
.entropyBits
.text(numberOfBits
);
1584 DOM
.entropyWordCount
.text(wordCount
);
1585 DOM
.entropyBinary
.text(spacedBinaryStr
);
1586 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1587 // detect and warn of filtering
1588 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1589 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1590 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1592 DOM
.entropyFilterWarning
.removeClass('hidden');
1595 DOM
.entropyFilterWarning
.addClass('hidden');
1599 function getEntropyTypeStr(entropy
) {
1600 var typeStr
= entropy
.base
.str
;
1601 // Add some detail if these are cards
1602 if (entropy
.base
.asInt
== 52) {
1603 var cardDetail
= []; // array of message strings
1604 // Detect duplicates
1606 var dupeTracker
= {};
1607 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1608 var card
= entropy
.base
.parts
[i
];
1609 var cardUpper
= card
.toUpperCase();
1610 if (cardUpper
in dupeTracker
) {
1613 dupeTracker
[cardUpper
] = true;
1615 if (dupes
.length
> 0) {
1616 var dupeWord
= "duplicates";
1617 if (dupes
.length
== 1) {
1618 dupeWord
= "duplicate";
1620 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1621 if (dupes
.length
> 3) {
1624 cardDetail
.push(msg
);
1627 var uniqueCards
= [];
1628 for (var uniqueCard
in dupeTracker
) {
1629 uniqueCards
.push(uniqueCard
);
1631 if (uniqueCards
.length
== 52) {
1632 cardDetail
.unshift("full deck");
1634 // Detect missing cards
1635 var values
= "A23456789TJQK";
1637 var missingCards
= [];
1638 for (var i
=0; i
<suits
.length
; i
++) {
1639 for (var j
=0; j
<values
.length
; j
++) {
1640 var card
= values
[j
] + suits
[i
];
1641 if (!(card
in dupeTracker
)) {
1642 missingCards
.push(card
);
1646 // Display missing cards if six or less, ie clearly going for full deck
1647 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1648 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1649 if (missingCards
.length
> 3) {
1652 cardDetail
.push(msg
);
1654 // Add card details to typeStr
1655 if (cardDetail
.length
> 0) {
1656 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1662 function setQrEvents(els
) {
1663 els
.on("mouseenter", createQr
);
1664 els
.on("mouseleave", destroyQr
);
1665 els
.on("click", toggleQr
);
1668 function createQr(e
) {
1669 var content
= e
.target
.textContent
|| e
.target
.value
;
1677 DOM
.qrImage
.append(qrEl
);
1679 DOM
.qrHider
.addClass("hidden");
1682 DOM
.qrHider
.removeClass("hidden");
1684 DOM
.qrContainer
.removeClass("hidden");
1688 function destroyQr() {
1689 DOM
.qrImage
.text("");
1690 DOM
.qrContainer
.addClass("hidden");
1693 function toggleQr() {
1695 DOM
.qrHider
.toggleClass("hidden");
1696 DOM
.qrHint
.toggleClass("hidden");
1699 function bip44TabSelected() {
1700 return DOM
.bip44tab
.hasClass("active");
1703 function bip32TabSelected() {
1704 return DOM
.bip32tab
.hasClass("active");
1707 function networkIsEthereum() {
1708 var name
= networks
[DOM
.network
.val()].name
;
1709 return (name
== "ETH - Ethereum")
1710 || (name
== "ETC - Ethereum Classic")
1711 || (name
== "EWT - EnergyWeb")
1712 || (name
== "PIRL - Pirl")
1713 || (name
== "MIX - MIX")
1714 || (name
== "MUSIC - Musicoin")
1715 || (name
== "POA - Poa")
1716 || (name
== "EXP - Expanse")
1717 || (name
== "CLO - Callisto")
1718 || (name
== "DXN - DEXON")
1719 || (name
== "ELLA - Ellaism")
1720 || (name
== "ESN - Ethersocial Network")
1721 || (name
== "VET - VeChain")
1724 function networkHasSegwit() {
1726 if ("baseNetwork" in network
) {
1727 n
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1729 // check if only p2wpkh params are required
1730 if (p2wpkhSelected()) {
1731 return "p2wpkh" in n
;
1733 // check if only p2wpkh-in-p2sh params are required
1734 else if (p2wpkhInP2shSelected()) {
1735 return "p2wpkhInP2sh" in n
;
1737 // require both if it's unclear which params are required
1738 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1741 function bip49TabSelected() {
1742 return DOM
.bip49tab
.hasClass("active");
1745 function bip84TabSelected() {
1746 return DOM
.bip84tab
.hasClass("active");
1749 function bip141TabSelected() {
1750 return DOM
.bip141tab
.hasClass("active");
1753 function setBip44ChangeValue() {
1754 if (isDefaultBip44ChangeValue
) {
1755 if (networkIsEthereum()) {
1756 DOM
.bip44change
.val("");
1758 DOM
.bip44change
.val(0);
1763 function modifiedDefaultBip44ChangeValue() {
1764 isDefaultBip44ChangeValue
= false;
1767 function resetDefaultBip44ChangeValue() {
1768 isDefaultBip44ChangeValue
= true;
1769 setBip44ChangeValue();
1772 function setHdCoin(coinValue
) {
1773 DOM
.bip44coin
.val(coinValue
);
1774 DOM
.bip49coin
.val(coinValue
);
1775 DOM
.bip84coin
.val(coinValue
);
1776 setBip44ChangeValue();
1779 function showSegwitAvailable() {
1780 DOM
.bip49unavailable
.addClass("hidden");
1781 DOM
.bip49available
.removeClass("hidden");
1782 DOM
.bip84unavailable
.addClass("hidden");
1783 DOM
.bip84available
.removeClass("hidden");
1784 DOM
.bip141unavailable
.addClass("hidden");
1785 DOM
.bip141available
.removeClass("hidden");
1788 function showSegwitUnavailable() {
1789 DOM
.bip49available
.addClass("hidden");
1790 DOM
.bip49unavailable
.removeClass("hidden");
1791 DOM
.bip84available
.addClass("hidden");
1792 DOM
.bip84unavailable
.removeClass("hidden");
1793 DOM
.bip141available
.addClass("hidden");
1794 DOM
.bip141unavailable
.removeClass("hidden");
1797 function adjustNetworkForSegwit() {
1798 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1799 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1801 // See https://github.com/iancoleman/bip39/issues/125
1802 var segwitNetworks
= null;
1803 // if a segwit network is alread selected, need to use base network to
1804 // look up new parameters
1805 if ("baseNetwork" in network
) {
1806 network
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1808 // choose the right segwit params
1809 if (p2wpkhSelected() && "p2wpkh" in network
) {
1810 network
= network
.p2wpkh
;
1812 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1813 network
= network
.p2wpkhInP2sh
;
1817 function lastIndexInTable() {
1818 var pathText
= DOM
.addresses
.find(".index").last().text();
1819 var pathBits
= pathText
.split("/");
1820 var lastBit
= pathBits
[pathBits
.length
-1];
1821 var lastBitClean
= lastBit
.replace("'", "");
1822 return parseInt(lastBitClean
);
1825 function uint8ArrayToHex(a
) {
1827 for (var i
=0; i
<a
.length
; i
++) {
1828 var h
= a
[i
].toString(16);
1829 while (h
.length
< 2) {
1837 function showWordIndexes() {
1838 var phrase
= DOM
.phrase
.val();
1839 var words
= phraseToWordArray(phrase
);
1840 var wordIndexes
= [];
1841 var language
= getLanguage();
1842 for (var i
=0; i
<words
.length
; i
++) {
1843 var word
= words
[i
];
1844 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1845 wordIndexes
.push(wordIndex
);
1847 var wordIndexesStr
= wordIndexes
.join(", ");
1848 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1851 function showChecksum() {
1852 var phrase
= DOM
.phrase
.val();
1853 var words
= phraseToWordArray(phrase
);
1854 var checksumBitlength
= words
.length
/ 3;
1857 var language
= getLanguage();
1858 for (var i
=words
.length
-1; i
>=0; i
--) {
1859 var word
= words
[i
];
1860 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1861 var wordBinary
= wordIndex
.toString(2);
1862 while (wordBinary
.length
< 11) {
1863 wordBinary
= "0" + wordBinary
;
1865 var binaryStr
= wordBinary
+ binaryStr
;
1866 if (binaryStr
.length
>= checksumBitlength
) {
1867 var start
= binaryStr
.length
- checksumBitlength
;
1868 var end
= binaryStr
.length
;
1869 checksum
= binaryStr
.substring(start
, end
);
1870 // add spaces so the last group is 11 bits, not the first
1871 checksum
= checksum
.split("").reverse().join("")
1872 checksum
= addSpacesEveryElevenBits(checksum
);
1873 checksum
= checksum
.split("").reverse().join("")
1877 DOM
.entropyChecksum
.text(checksum
);
1880 function updateCsv() {
1881 var tableCsv
= "path,address,public key,private key\n";
1882 var rows
= DOM
.addresses
.find("tr");
1883 for (var i
=0; i
<rows
.length
; i
++) {
1884 var row
= $(rows
[i
]);
1885 var cells
= row
.find("td");
1886 for (var j
=0; j
<cells
.length
; j
++) {
1887 var cell
= $(cells
[j
]);
1888 if (!cell
.children().hasClass("invisible")) {
1889 tableCsv
= tableCsv
+ cell
.text();
1891 if (j
!= cells
.length
- 1) {
1892 tableCsv
= tableCsv
+ ",";
1895 tableCsv
= tableCsv
+ "\n";
1897 DOM
.csv
.val(tableCsv
);
1900 function addSpacesEveryElevenBits(binaryStr
) {
1901 return binaryStr
.match(/.{1,11}/g).join(" ");
1906 name: "AC - Asiacoin",
1907 onSelect: function() {
1908 network
= bitcoinjs
.bitcoin
.networks
.asiacoin
;
1913 name: "ACC - Adcoin",
1914 onSelect: function() {
1915 network
= bitcoinjs
.bitcoin
.networks
.adcoin
;
1920 name: "ARYA - Aryacoin",
1921 onSelect: function() {
1922 network
= bitcoinjs
.bitcoin
.networks
.aryacoin
;
1927 name: "AUR - Auroracoin",
1928 onSelect: function() {
1929 network
= bitcoinjs
.bitcoin
.networks
.auroracoin
;
1935 onSelect: function() {
1936 network
= bitcoinjs
.bitcoin
.networks
.axe
;
1941 name: "ANON - ANON",
1942 onSelect: function() {
1943 network
= bitcoinjs
.bitcoin
.networks
.anon
;
1948 name: "BOLI - Bolivarcoin",
1949 onSelect: function() {
1950 network
= bitcoinjs
.bitcoin
.networks
.bolivarcoin
;
1955 name: "BCA - Bitcoin Atom",
1956 onSelect: function() {
1957 network
= bitcoinjs
.bitcoin
.networks
.atom
;
1962 name: "BCH - Bitcoin Cash",
1963 onSelect: function() {
1964 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
1969 name: "BEET - Beetlecoin",
1970 onSelect: function() {
1971 network
= bitcoinjs
.bitcoin
.networks
.beetlecoin
;
1976 name: "BELA - Belacoin",
1977 onSelect: function() {
1978 network
= bitcoinjs
.bitcoin
.networks
.belacoin
;
1983 name: "BLK - BlackCoin",
1984 onSelect: function() {
1985 network
= bitcoinjs
.bitcoin
.networks
.blackcoin
;
1990 name: "BND - Blocknode",
1991 onSelect: function() {
1992 network
= bitcoinjs
.bitcoin
.networks
.blocknode
;
1997 name: "tBND - Blocknode Testnet",
1998 onSelect: function() {
1999 network
= bitcoinjs
.bitcoin
.networks
.blocknode_testnet
;
2004 name: "BRIT - Britcoin",
2005 onSelect: function() {
2006 network
= bitcoinjs
.bitcoin
.networks
.britcoin
;
2011 name: "BSD - Bitsend",
2012 onSelect: function() {
2013 network
= bitcoinjs
.bitcoin
.networks
.bitsend
;
2018 name: "BST - BlockStamp",
2019 onSelect: function() {
2020 network
= bitcoinjs
.bitcoin
.networks
.blockstamp
;
2026 onSelect: function() {
2027 network
= bitcoinjs
.bitcoin
.networks
.bata
;
2032 name: "BTC - Bitcoin",
2033 onSelect: function() {
2034 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2039 name: "BTC - Bitcoin Testnet",
2040 onSelect: function() {
2041 network
= bitcoinjs
.bitcoin
.networks
.testnet
;
2046 name: "BITG - Bitcoin Green",
2047 onSelect: function() {
2048 network
= bitcoinjs
.bitcoin
.networks
.bitcoingreen
;
2053 name: "BTCP - Bitcoin Private",
2054 onSelect: function() {
2055 network
= bitcoinjs
.bitcoin
.networks
.bitcoinprivate
;
2060 name: "BSV - BitcoinSV",
2061 onSelect: function() {
2062 network
= bitcoinjs
.bitcoin
.networks
.bitcoinsv
;
2067 name: "BTCZ - Bitcoinz",
2068 onSelect: function() {
2069 network
= bitcoinjs
.bitcoin
.networks
.bitcoinz
;
2074 name: "BTDX - BitCloud",
2075 onSelect: function() {
2076 network
= bitcoinjs
.bitcoin
.networks
.bitcloud
;
2081 name: "BTG - Bitcoin Gold",
2082 onSelect: function() {
2083 network
= bitcoinjs
.bitcoin
.networks
.bgold
;
2088 name: "BTX - Bitcore",
2089 onSelect: function() {
2090 network
= bitcoinjs
.bitcoin
.networks
.bitcore
;
2095 name: "CCN - Cannacoin",
2096 onSelect: function() {
2097 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2102 name: "CESC - Cryptoescudo",
2103 onSelect: function() {
2104 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2109 name: "CDN - Canadaecoin",
2110 onSelect: function() {
2111 network
= bitcoinjs
.bitcoin
.networks
.canadaecoin
;
2116 name: "CLAM - Clams",
2117 onSelect: function() {
2118 network
= bitcoinjs
.bitcoin
.networks
.clam
;
2123 name: "CLO - Callisto",
2124 segwitAvailable: false,
2125 onSelect: function() {
2126 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2131 name: "CLUB - Clubcoin",
2132 onSelect: function() {
2133 network
= bitcoinjs
.bitcoin
.networks
.clubcoin
;
2138 name: "CMP - Compcoin",
2139 onSelect: function() {
2140 network
= bitcoinjs
.bitcoin
.networks
.compcoin
;
2145 name: "CPU - CPUchain",
2146 onSelect: function() {
2147 network
= bitcoinjs
.bitcoin
.networks
.cpuchain
;
2152 name: "CRAVE - Crave",
2153 onSelect: function() {
2154 network
= bitcoinjs
.bitcoin
.networks
.crave
;
2159 name: "CRW - Crown (Legacy)",
2160 onSelect: function() {
2161 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2166 name: "CRW - Crown",
2167 onSelect: function() {
2168 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2173 name: "CSC - CasinoCoin",
2174 onSelect: function() {
2175 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2180 name: "DASH - Dash",
2181 onSelect: function() {
2182 network
= bitcoinjs
.bitcoin
.networks
.dash
;
2187 name: "DASH - Dash Testnet",
2188 onSelect: function() {
2189 network
= bitcoinjs
.bitcoin
.networks
.dashtn
;
2194 name: "DFC - Defcoin",
2195 onSelect: function() {
2196 network
= bitcoinjs
.bitcoin
.networks
.defcoin
;
2201 name: "DGB - Digibyte",
2202 onSelect: function() {
2203 network
= bitcoinjs
.bitcoin
.networks
.digibyte
;
2208 name: "DGC - Digitalcoin",
2209 onSelect: function() {
2210 network
= bitcoinjs
.bitcoin
.networks
.digitalcoin
;
2215 name: "DMD - Diamond",
2216 onSelect: function() {
2217 network
= bitcoinjs
.bitcoin
.networks
.diamond
;
2222 name: "DNR - Denarius",
2223 onSelect: function() {
2224 network
= bitcoinjs
.bitcoin
.networks
.denarius
;
2229 name: "DOGE - Dogecoin",
2230 onSelect: function() {
2231 network
= bitcoinjs
.bitcoin
.networks
.dogecoin
;
2236 name: "DOGEt - Dogecoin Testnet",
2237 onSelect: function() {
2238 network
= bitcoinjs
.bitcoin
.networks
.dogecointestnet
;
2243 name: "DXN - DEXON",
2244 onSelect: function() {
2245 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2250 name: "ECN - Ecoin",
2251 onSelect: function() {
2252 network
= bitcoinjs
.bitcoin
.networks
.ecoin
;
2257 name: "EDRC - Edrcoin",
2258 onSelect: function() {
2259 network
= bitcoinjs
.bitcoin
.networks
.edrcoin
;
2264 name: "EFL - Egulden",
2265 onSelect: function() {
2266 network
= bitcoinjs
.bitcoin
.networks
.egulden
;
2271 name: "ELA - Elastos",
2272 onSelect: function () {
2273 network
= bitcoinjs
.bitcoin
.networks
.elastos
;
2278 name: "ELLA - Ellaism",
2279 segwitAvailable: false,
2280 onSelect: function() {
2281 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2286 name: "EMC2 - Einsteinium",
2287 onSelect: function() {
2288 network
= bitcoinjs
.bitcoin
.networks
.einsteinium
;
2293 name: "ERC - Europecoin",
2294 onSelect: function() {
2295 network
= bitcoinjs
.bitcoin
.networks
.europecoin
;
2300 name: "EOS - EOSIO",
2301 onSelect: function() {
2302 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2307 name: "ESN - Ethersocial Network",
2308 segwitAvailable: false,
2309 onSelect: function() {
2310 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2315 name: "ETC - Ethereum Classic",
2316 segwitAvailable: false,
2317 onSelect: function() {
2318 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2323 name: "ETH - Ethereum",
2324 onSelect: function() {
2325 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2330 name: "EWT - EnergyWeb",
2331 onSelect: function() {
2332 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2337 name: "EXCL - Exclusivecoin",
2338 onSelect: function() {
2339 network
= bitcoinjs
.bitcoin
.networks
.exclusivecoin
;
2344 name: "EXCC - ExchangeCoin",
2345 onSelect: function() {
2346 network
= bitcoinjs
.bitcoin
.networks
.exchangecoin
;
2351 name: "EXP - Expanse",
2352 segwitAvailable: false,
2353 onSelect: function() {
2354 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2360 onSelect: function() {
2361 network
= bitcoinjs
.bitcoin
.networks
.fix
;
2366 name: "FIX - FIX Testnet",
2367 onSelect: function() {
2368 network
= bitcoinjs
.bitcoin
.networks
.fixtestnet
;
2373 name: "FJC - Fujicoin",
2374 onSelect: function() {
2375 network
= bitcoinjs
.bitcoin
.networks
.fujicoin
;
2380 name: "FLASH - Flashcoin",
2381 onSelect: function() {
2382 network
= bitcoinjs
.bitcoin
.networks
.flashcoin
;
2387 name: "FRST - Firstcoin",
2388 onSelect: function() {
2389 network
= bitcoinjs
.bitcoin
.networks
.firstcoin
;
2394 name: "FTC - Feathercoin",
2395 onSelect: function() {
2396 network
= bitcoinjs
.bitcoin
.networks
.feathercoin
;
2401 name: "GAME - GameCredits",
2402 onSelect: function() {
2403 network
= bitcoinjs
.bitcoin
.networks
.game
;
2408 name: "GBX - Gobyte",
2409 onSelect: function() {
2410 network
= bitcoinjs
.bitcoin
.networks
.gobyte
;
2415 name: "GCR - GCRCoin",
2416 onSelect: function() {
2417 network
= bitcoinjs
.bitcoin
.networks
.gcr
;
2422 name: "GRC - Gridcoin",
2423 onSelect: function() {
2424 network
= bitcoinjs
.bitcoin
.networks
.gridcoin
;
2429 name: "GRS - Groestlcoin",
2430 onSelect: function() {
2431 network
= bitcoinjs
.bitcoin
.networks
.groestlcoin
;
2436 name: "GRS - Groestlcoin Testnet",
2437 onSelect: function() {
2438 network
= bitcoinjs
.bitcoin
.networks
.groestlcointestnet
;
2443 name: "HNC - Helleniccoin",
2444 onSelect: function() {
2445 network
= bitcoinjs
.bitcoin
.networks
.helleniccoin
;
2450 name: "HUSH - Hush (Legacy)",
2451 onSelect: function() {
2452 network
= bitcoinjs
.bitcoin
.networks
.hush
;
2457 name: "HUSH - Hush3",
2458 onSelect: function() {
2459 network
= bitcoinjs
.bitcoin
.networks
.hush3
;
2464 name: "INSN - Insane",
2465 onSelect: function() {
2466 network
= bitcoinjs
.bitcoin
.networks
.insane
;
2472 onSelect: function() {
2473 network
= bitcoinjs
.bitcoin
.networks
.iop
;
2478 name: "IXC - Ixcoin",
2479 onSelect: function() {
2480 network
= bitcoinjs
.bitcoin
.networks
.ixcoin
;
2485 name: "JBS - Jumbucks",
2486 onSelect: function() {
2487 network
= bitcoinjs
.bitcoin
.networks
.jumbucks
;
2492 name: "KMD - Komodo",
2493 bip49available: false,
2494 onSelect: function() {
2495 network
= bitcoinjs
.bitcoin
.networks
.komodo
;
2500 name: "KOBO - Kobocoin",
2501 bip49available: false,
2502 onSelect: function() {
2503 network
= bitcoinjs
.bitcoin
.networks
.kobocoin
;
2508 name: "LBC - Library Credits",
2509 onSelect: function() {
2510 network
= bitcoinjs
.bitcoin
.networks
.lbry
;
2515 name: "LCC - Litecoincash",
2516 onSelect: function() {
2517 network
= bitcoinjs
.bitcoin
.networks
.litecoincash
;
2522 name: "LDCN - Landcoin",
2523 onSelect: function() {
2524 network
= bitcoinjs
.bitcoin
.networks
.landcoin
;
2529 name: "LINX - Linx",
2530 onSelect: function() {
2531 network
= bitcoinjs
.bitcoin
.networks
.linx
;
2536 name: "LKR - Lkrcoin",
2537 segwitAvailable: false,
2538 onSelect: function() {
2539 network
= bitcoinjs
.bitcoin
.networks
.lkrcoin
;
2544 name: "LTC - Litecoin",
2545 onSelect: function() {
2546 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
2548 DOM
.litecoinLtubContainer
.removeClass("hidden");
2552 name: "LTCt - Litecoin Testnet",
2553 onSelect: function() {
2554 network
= bitcoinjs
.bitcoin
.networks
.litecointestnet
;
2556 DOM
.litecoinLtubContainer
.removeClass("hidden");
2560 name: "LTZ - LitecoinZ",
2561 onSelect: function() {
2562 network
= bitcoinjs
.bitcoin
.networks
.litecoinz
;
2567 name: "LYNX - Lynx",
2568 onSelect: function() {
2569 network
= bitcoinjs
.bitcoin
.networks
.lynx
;
2574 name: "MAZA - Maza",
2575 onSelect: function() {
2576 network
= bitcoinjs
.bitcoin
.networks
.maza
;
2581 name: "MEC - Megacoin",
2582 onSelect: function() {
2583 network
= bitcoinjs
.bitcoin
.networks
.megacoin
;
2589 segwitAvailable: false,
2590 onSelect: function() {
2591 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2596 name: "MNX - Minexcoin",
2597 onSelect: function() {
2598 network
= bitcoinjs
.bitcoin
.networks
.minexcoin
;
2603 name: "MONA - Monacoin",
2604 onSelect: function() {
2605 network
= bitcoinjs
.bitcoin
.networks
.monacoin
,
2610 name: "MONK - Monkey Project",
2611 onSelect: function() {
2612 network
= bitcoinjs
.bitcoin
.networks
.monkeyproject
,
2617 name: "MUSIC - Musicoin",
2618 segwitAvailable: false,
2619 onSelect: function() {
2620 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2625 name: "NAV - Navcoin",
2626 onSelect: function() {
2627 network
= bitcoinjs
.bitcoin
.networks
.navcoin
;
2632 name: "NAS - Nebulas",
2633 onSelect: function() {
2634 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2639 name: "NEBL - Neblio",
2640 onSelect: function() {
2641 network
= bitcoinjs
.bitcoin
.networks
.neblio
;
2646 name: "NEOS - Neoscoin",
2647 onSelect: function() {
2648 network
= bitcoinjs
.bitcoin
.networks
.neoscoin
;
2653 name: "NIX - NIX Platform",
2654 onSelect: function() {
2655 network
= bitcoinjs
.bitcoin
.networks
.nix
;
2660 name: "NLG - Gulden",
2661 onSelect: function() {
2662 network
= bitcoinjs
.bitcoin
.networks
.gulden
;
2667 name: "NMC - Namecoin",
2668 onSelect: function() {
2669 network
= bitcoinjs
.bitcoin
.networks
.namecoin
;
2674 name: "NRG - Energi",
2675 onSelect: function() {
2676 network
= bitcoinjs
.bitcoin
.networks
.energi
;
2681 name: "NRO - Neurocoin",
2682 onSelect: function() {
2683 network
= bitcoinjs
.bitcoin
.networks
.neurocoin
;
2688 name: "NSR - Nushares",
2689 onSelect: function() {
2690 network
= bitcoinjs
.bitcoin
.networks
.nushares
;
2695 name: "NYC - Newyorkc",
2696 onSelect: function() {
2697 network
= bitcoinjs
.bitcoin
.networks
.newyorkc
;
2702 name: "NVC - Novacoin",
2703 onSelect: function() {
2704 network
= bitcoinjs
.bitcoin
.networks
.novacoin
;
2709 name: "OK - Okcash",
2710 onSelect: function() {
2711 network
= bitcoinjs
.bitcoin
.networks
.okcash
;
2716 name: "OMNI - Omnicore",
2717 onSelect: function() {
2718 network
= bitcoinjs
.bitcoin
.networks
.omnicore
;
2723 name: "ONION - DeepOnion",
2724 onSelect: function() {
2725 network
= bitcoinjs
.bitcoin
.networks
.deeponion
;
2730 name: "ONX - Onixcoin",
2731 onSelect: function() {
2732 network
= bitcoinjs
.bitcoin
.networks
.onixcoin
;
2737 name: "PHR - Phore",
2738 onSelect: function() {
2739 network
= bitcoinjs
.bitcoin
.networks
.phore
;
2744 name: "PINK - Pinkcoin",
2745 onSelect: function() {
2746 network
= bitcoinjs
.bitcoin
.networks
.pinkcoin
;
2751 name: "PIRL - Pirl",
2752 segwitAvailable: false,
2753 onSelect: function() {
2754 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2759 name: "PIVX - PIVX",
2760 onSelect: function() {
2761 network
= bitcoinjs
.bitcoin
.networks
.pivx
;
2766 name: "PIVX - PIVX Testnet",
2767 onSelect: function() {
2768 network
= bitcoinjs
.bitcoin
.networks
.pivxtestnet
;
2774 segwitAvailable: false,
2775 onSelect: function() {
2776 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2781 name: "POSW - POSWcoin",
2782 onSelect: function() {
2783 network
= bitcoinjs
.bitcoin
.networks
.poswcoin
;
2788 name: "POT - Potcoin",
2789 onSelect: function() {
2790 network
= bitcoinjs
.bitcoin
.networks
.potcoin
;
2795 name: "PPC - Peercoin",
2796 onSelect: function() {
2797 network
= bitcoinjs
.bitcoin
.networks
.peercoin
;
2802 name: "PRJ - ProjectCoin",
2803 onSelect: function() {
2804 network
= bitcoinjs
.bitcoin
.networks
.projectcoin
;
2809 name: "PSB - Pesobit",
2810 onSelect: function() {
2811 network
= bitcoinjs
.bitcoin
.networks
.pesobit
;
2816 name: "PUT - Putincoin",
2817 onSelect: function() {
2818 network
= bitcoinjs
.bitcoin
.networks
.putincoin
;
2823 name: "RPD - Rapids",
2824 onSelect: function() {
2825 network
= bitcoinjs
.bitcoin
.networks
.rapids
;
2830 name: "RVN - Ravencoin",
2831 onSelect: function() {
2832 network
= bitcoinjs
.bitcoin
.networks
.ravencoin
;
2837 name: "RBY - Rubycoin",
2838 onSelect: function() {
2839 network
= bitcoinjs
.bitcoin
.networks
.rubycoin
;
2844 name: "RDD - Reddcoin",
2845 onSelect: function() {
2846 network
= bitcoinjs
.bitcoin
.networks
.reddcoin
;
2851 name: "RVR - RevolutionVR",
2852 onSelect: function() {
2853 network
= bitcoinjs
.bitcoin
.networks
.revolutionvr
;
2858 name: "SAFE - Safecoin",
2859 onSelect: function() {
2860 network
= bitcoinjs
.bitcoin
.networks
.safecoin
;
2865 name: "SLS - Salus",
2866 onSelect: function() {
2867 network
= bitcoinjs
.bitcoin
.networks
.salus
;
2872 name: "SDC - ShadowCash",
2873 onSelect: function() {
2874 network
= bitcoinjs
.bitcoin
.networks
.shadow
;
2879 name: "SDC - ShadowCash Testnet",
2880 onSelect: function() {
2881 network
= bitcoinjs
.bitcoin
.networks
.shadowtn
;
2886 name: "SLM - Slimcoin",
2887 onSelect: function() {
2888 network
= bitcoinjs
.bitcoin
.networks
.slimcoin
;
2893 name: "SLM - Slimcoin Testnet",
2894 onSelect: function() {
2895 network
= bitcoinjs
.bitcoin
.networks
.slimcointn
;
2900 name: "SLP - Simple Ledger Protocol",
2901 onSelect: function() {
2902 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2907 name: "SLR - Solarcoin",
2908 onSelect: function() {
2909 network
= bitcoinjs
.bitcoin
.networks
.solarcoin
;
2914 name: "SMLY - Smileycoin",
2915 onSelect: function() {
2916 network
= bitcoinjs
.bitcoin
.networks
.smileycoin
;
2921 name: "STASH - Stash",
2922 onSelect: function() {
2923 network
= bitcoinjs
.bitcoin
.networks
.stash
;
2928 name: "STASH - Stash Testnet",
2929 onSelect: function() {
2930 network
= bitcoinjs
.bitcoin
.networks
.stashtn
;
2935 name: "STRAT - Stratis",
2936 onSelect: function() {
2937 network
= bitcoinjs
.bitcoin
.networks
.stratis
;
2942 name: "TSTRAT - Stratis Testnet",
2943 onSelect: function() {
2944 network
= bitcoinjs
.bitcoin
.networks
.stratistest
;
2949 name: "SYS - Syscoin",
2950 onSelect: function() {
2951 network
= bitcoinjs
.bitcoin
.networks
.syscoin
;
2956 name: "THC - Hempcoin",
2957 onSelect: function() {
2958 network
= bitcoinjs
.bitcoin
.networks
.hempcoin
;
2963 name: "THT - Thought",
2964 onSelect: function() {
2965 network
= bitcoinjs
.bitcoin
.networks
.thought
;
2971 onSelect: function() {
2972 network
= bitcoinjs
.bitcoin
.networks
.toa
;
2977 name: "TWINS - TWINS",
2978 onSelect: function() {
2979 network
= bitcoinjs
.bitcoin
.networks
.twins
;
2984 name: "TWINS - TWINS Testnet",
2985 onSelect: function() {
2986 network
= bitcoinjs
.bitcoin
.networks
.twinstestnet
;
2991 name: "USC - Ultimatesecurecash",
2992 onSelect: function() {
2993 network
= bitcoinjs
.bitcoin
.networks
.ultimatesecurecash
;
2998 name: "USNBT - NuBits",
2999 onSelect: function() {
3000 network
= bitcoinjs
.bitcoin
.networks
.nubits
;
3005 name: "UNO - Unobtanium",
3006 onSelect: function() {
3007 network
= bitcoinjs
.bitcoin
.networks
.unobtanium
;
3012 name: "VASH - Vpncoin",
3013 onSelect: function() {
3014 network
= bitcoinjs
.bitcoin
.networks
.vpncoin
;
3019 name: "VET - VeChain",
3020 onSelect: function() {
3021 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3026 name: "VIA - Viacoin",
3027 onSelect: function() {
3028 network
= bitcoinjs
.bitcoin
.networks
.viacoin
;
3033 name: "VIA - Viacoin Testnet",
3034 onSelect: function() {
3035 network
= bitcoinjs
.bitcoin
.networks
.viacointestnet
;
3040 name: "VIVO - Vivo",
3041 onSelect: function() {
3042 network
= bitcoinjs
.bitcoin
.networks
.vivo
;
3047 name: "VTC - Vertcoin",
3048 onSelect: function() {
3049 network
= bitcoinjs
.bitcoin
.networks
.vertcoin
;
3054 name: "WGR - Wagerr",
3055 onSelect: function() {
3056 network
= bitcoinjs
.bitcoin
.networks
.wagerr
;
3061 name: "WC - Wincoin",
3062 onSelect: function() {
3063 network
= bitcoinjs
.bitcoin
.networks
.wincoin
;
3068 name: "XAX - Artax",
3069 onSelect: function() {
3070 network
= bitcoinjs
.bitcoin
.networks
.artax
;
3075 name: "XBC - Bitcoinplus",
3076 onSelect: function() {
3077 network
= bitcoinjs
.bitcoin
.networks
.bitcoinplus
;
3082 name: "XLM - Stellar",
3083 onSelect: function() {
3084 network
= stellarUtil
.dummyNetwork
;
3089 name: "XMY - Myriadcoin",
3090 onSelect: function() {
3091 network
= bitcoinjs
.bitcoin
.networks
.myriadcoin
;
3096 name: "XRP - Ripple",
3097 onSelect: function() {
3098 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3103 name: "XVC - Vcash",
3104 onSelect: function() {
3105 network
= bitcoinjs
.bitcoin
.networks
.vcash
;
3110 name: "XVG - Verge",
3111 onSelect: function() {
3112 network
= bitcoinjs
.bitcoin
.networks
.verge
;
3117 name: "XUEZ - Xuez",
3118 segwitAvailable: false,
3119 onSelect: function() {
3120 network
= bitcoinjs
.bitcoin
.networks
.xuez
;
3125 name: "XWC - Whitecoin",
3126 onSelect: function() {
3127 network
= bitcoinjs
.bitcoin
.networks
.whitecoin
;
3132 name: "XZC - Zcoin",
3133 onSelect: function() {
3134 network
= bitcoinjs
.bitcoin
.networks
.zcoin
;
3139 name: "ZCL - Zclassic",
3140 onSelect: function() {
3141 network
= bitcoinjs
.bitcoin
.networks
.zclassic
;
3146 name: "ZEC - Zcash",
3147 onSelect: function() {
3148 network
= bitcoinjs
.bitcoin
.networks
.zcash
;
3153 name: "ZEN - Horizen",
3154 onSelect: function() {
3155 network
= bitcoinjs
.bitcoin
.networks
.zencash
;
3163 name: "Bitcoin Core",
3164 onSelect: function() {
3165 DOM
.bip32path
.val("m/0'/0'");
3166 DOM
.hardenedAddresses
.prop('checked', true);
3170 name: "blockchain.info",
3171 onSelect: function() {
3172 DOM
.bip32path
.val("m/44'/0'/0'");
3173 DOM
.hardenedAddresses
.prop('checked', false);
3177 name: "MultiBit HD",
3178 onSelect: function() {
3179 DOM
.bip32path
.val("m/0'/0");
3180 DOM
.hardenedAddresses
.prop('checked', false);
3184 name: "Coinomi, Ledger",
3185 onSelect: function() {
3186 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3187 DOM
.hardenedAddresses
.prop('checked', false);
3192 // ELA - Elastos functions - begin
3193 function displayBip44InfoForELA() {
3198 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3199 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3201 // Calculate the account extended keys
3202 var accountXprv
= elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3203 var accountXpub
= elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3205 // Display the extended keys
3206 DOM
.bip44accountXprv
.val(accountXprv
);
3207 DOM
.bip44accountXpub
.val(accountXpub
);
3210 function displayBip32InfoForELA() {
3215 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3216 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3217 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3219 DOM
.extendedPrivKey
.val(elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3220 DOM
.extendedPubKey
.val(elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3222 // Display the addresses and privkeys
3223 clearAddressesList();
3224 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3225 displayAddresses(0, initialAddressCount
);
3228 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3233 var publicKey
= elastosjs
.getDerivedPublicKey(elastosjs
.getMasterPublicKey(seed
), change
, index
);
3235 privateKey: elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3236 publicKey: publicKey
,
3237 address: elastosjs
.getAddress(publicKey
.toString('hex'))
3240 // ELA - Elastos functions - end