3 // mnemonics is populated as required by getLanguage
4 var mnemonics
= { "english": new Mnemonic("english") };
5 var mnemonic
= mnemonics
["english"];
7 var bip32RootKey
= null;
8 var bip32ExtendedKey
= null;
9 var network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
10 var addressRowTemplate
= $("#address-row-template");
13 var showAddress
= true;
14 var showPubKey
= true;
15 var showPrivKey
= true;
17 var litecoinUseLtub
= true;
19 var entropyChangeTimeoutEvent
= null;
20 var phraseChangeTimeoutEvent
= null;
21 var rootKeyChangedTimeoutEvent
= null;
23 var generationProcesses
= [];
26 DOM
.privacyScreenToggle
= $(".privacy-screen-toggle");
27 DOM
.network
= $(".network");
28 DOM
.bip32Client
= $("#bip32-client");
29 DOM
.phraseNetwork
= $("#network-phrase");
30 DOM
.useEntropy
= $(".use-entropy");
31 DOM
.entropyContainer
= $(".entropy-container");
32 DOM
.entropy
= $(".entropy");
33 DOM
.entropyFiltered
= DOM
.entropyContainer
.find(".filtered");
34 DOM
.entropyType
= DOM
.entropyContainer
.find(".type");
35 DOM
.entropyCrackTime
= DOM
.entropyContainer
.find(".crack-time");
36 DOM
.entropyEventCount
= DOM
.entropyContainer
.find(".event-count");
37 DOM
.entropyBits
= DOM
.entropyContainer
.find(".bits");
38 DOM
.entropyBitsPerEvent
= DOM
.entropyContainer
.find(".bits-per-event");
39 DOM
.entropyWordCount
= DOM
.entropyContainer
.find(".word-count");
40 DOM
.entropyBinary
= DOM
.entropyContainer
.find(".binary");
41 DOM
.entropyWordIndexes
= DOM
.entropyContainer
.find(".word-indexes");
42 DOM
.entropyChecksum
= DOM
.entropyContainer
.find(".checksum");
43 DOM
.entropyMnemonicLength
= DOM
.entropyContainer
.find(".mnemonic-length");
44 DOM
.entropyWeakEntropyOverrideWarning
= DOM
.entropyContainer
.find(".weak-entropy-override-warning");
45 DOM
.entropyFilterWarning
= DOM
.entropyContainer
.find(".filter-warning");
46 DOM
.phrase
= $(".phrase");
47 DOM
.phraseSplit
= $(".phraseSplit");
48 DOM
.phraseSplitWarn
= $(".phraseSplitWarn");
49 DOM
.passphrase
= $(".passphrase");
50 DOM
.generateContainer
= $(".generate-container");
51 DOM
.generate
= $(".generate");
52 DOM
.seed
= $(".seed");
53 DOM
.rootKey
= $(".root-key");
54 DOM
.litecoinLtubContainer
= $(".litecoin-ltub-container");
55 DOM
.litecoinUseLtub
= $(".litecoin-use-ltub");
56 DOM
.extendedPrivKey
= $(".extended-priv-key");
57 DOM
.extendedPubKey
= $(".extended-pub-key");
58 DOM
.bip32tab
= $("#bip32-tab");
59 DOM
.bip44tab
= $("#bip44-tab");
60 DOM
.bip49tab
= $("#bip49-tab");
61 DOM
.bip84tab
= $("#bip84-tab");
62 DOM
.bip141tab
= $("#bip141-tab");
63 DOM
.bip32panel
= $("#bip32");
64 DOM
.bip44panel
= $("#bip44");
65 DOM
.bip49panel
= $("#bip49");
66 DOM
.bip32path
= $("#bip32-path");
67 DOM
.bip44path
= $("#bip44-path");
68 DOM
.bip44purpose
= $("#bip44 .purpose");
69 DOM
.bip44coin
= $("#bip44 .coin");
70 DOM
.bip44account
= $("#bip44 .account");
71 DOM
.bip44accountXprv
= $("#bip44 .account-xprv");
72 DOM
.bip44accountXpub
= $("#bip44 .account-xpub");
73 DOM
.bip44change
= $("#bip44 .change");
74 DOM
.bip49unavailable
= $("#bip49 .unavailable");
75 DOM
.bip49available
= $("#bip49 .available");
76 DOM
.bip49path
= $("#bip49-path");
77 DOM
.bip49purpose
= $("#bip49 .purpose");
78 DOM
.bip49coin
= $("#bip49 .coin");
79 DOM
.bip49account
= $("#bip49 .account");
80 DOM
.bip49accountXprv
= $("#bip49 .account-xprv");
81 DOM
.bip49accountXpub
= $("#bip49 .account-xpub");
82 DOM
.bip49change
= $("#bip49 .change");
83 DOM
.bip84unavailable
= $("#bip84 .unavailable");
84 DOM
.bip84available
= $("#bip84 .available");
85 DOM
.bip84path
= $("#bip84-path");
86 DOM
.bip84purpose
= $("#bip84 .purpose");
87 DOM
.bip84coin
= $("#bip84 .coin");
88 DOM
.bip84account
= $("#bip84 .account");
89 DOM
.bip84accountXprv
= $("#bip84 .account-xprv");
90 DOM
.bip84accountXpub
= $("#bip84 .account-xpub");
91 DOM
.bip84change
= $("#bip84 .change");
92 DOM
.bip141unavailable
= $("#bip141 .unavailable");
93 DOM
.bip141available
= $("#bip141 .available");
94 DOM
.bip141path
= $("#bip141-path");
95 DOM
.bip141semantics
= $(".bip141-semantics");
96 DOM
.generatedStrength
= $(".generate-container .strength");
97 DOM
.generatedStrengthWarning
= $(".generate-container .warning");
98 DOM
.hardenedAddresses
= $(".hardened-addresses");
99 DOM
.bitcoinCashAddressTypeContainer
= $(".bch-addr-type-container");
100 DOM
.bitcoinCashAddressType
= $("[name=bch-addr-type]")
101 DOM
.useBip38
= $(".use-bip38");
102 DOM
.bip38Password
= $(".bip38-password");
103 DOM
.addresses
= $(".addresses");
104 DOM
.csvTab
= $("#csv-tab a");
106 DOM
.rowsToAdd
= $(".rows-to-add");
107 DOM
.more
= $(".more");
108 DOM
.moreRowsStartIndex
= $(".more-rows-start-index");
109 DOM
.feedback
= $(".feedback");
110 DOM
.tab
= $(".derivation-type a");
111 DOM
.indexToggle
= $(".index-toggle");
112 DOM
.addressToggle
= $(".address-toggle");
113 DOM
.publicKeyToggle
= $(".public-key-toggle");
114 DOM
.privateKeyToggle
= $(".private-key-toggle");
115 DOM
.languages
= $(".languages a");
116 DOM
.qrContainer
= $(".qr-container");
117 DOM
.qrHider
= DOM
.qrContainer
.find(".qr-hider");
118 DOM
.qrImage
= DOM
.qrContainer
.find(".qr-image");
119 DOM
.qrHint
= DOM
.qrContainer
.find(".qr-hint");
120 DOM
.showQrEls
= $("[data-show-qr]");
124 DOM
.privacyScreenToggle
.on("change", privacyScreenToggled
);
125 DOM
.generatedStrength
.on("change", generatedStrengthChanged
);
126 DOM
.network
.on("change", networkChanged
);
127 DOM
.bip32Client
.on("change", bip32ClientChanged
);
128 DOM
.useEntropy
.on("change", setEntropyVisibility
);
129 DOM
.entropy
.on("input", delayedEntropyChanged
);
130 DOM
.entropyMnemonicLength
.on("change", entropyChanged
);
131 DOM
.phrase
.on("input", delayedPhraseChanged
);
132 DOM
.passphrase
.on("input", delayedPhraseChanged
);
133 DOM
.generate
.on("click", generateClicked
);
134 DOM
.more
.on("click", showMore
);
135 DOM
.rootKey
.on("input", delayedRootKeyChanged
);
136 DOM
.litecoinUseLtub
.on("change", litecoinUseLtubChanged
);
137 DOM
.bip32path
.on("input", calcForDerivationPath
);
138 DOM
.bip44account
.on("input", calcForDerivationPath
);
139 DOM
.bip44change
.on("input", calcForDerivationPath
);
140 DOM
.bip49account
.on("input", calcForDerivationPath
);
141 DOM
.bip49change
.on("input", calcForDerivationPath
);
142 DOM
.bip84account
.on("input", calcForDerivationPath
);
143 DOM
.bip84change
.on("input", calcForDerivationPath
);
144 DOM
.bip141path
.on("input", calcForDerivationPath
);
145 DOM
.bip141semantics
.on("change", tabChanged
);
146 DOM
.tab
.on("shown.bs.tab", tabChanged
);
147 DOM
.hardenedAddresses
.on("change", calcForDerivationPath
);
148 DOM
.useBip38
.on("change", calcForDerivationPath
);
149 DOM
.bip38Password
.on("change", calcForDerivationPath
);
150 DOM
.indexToggle
.on("click", toggleIndexes
);
151 DOM
.addressToggle
.on("click", toggleAddresses
);
152 DOM
.publicKeyToggle
.on("click", togglePublicKeys
);
153 DOM
.privateKeyToggle
.on("click", togglePrivateKeys
);
154 DOM
.csvTab
.on("click", updateCsv
);
155 DOM
.languages
.on("click", languageChanged
);
156 DOM
.bitcoinCashAddressType
.on("change", bitcoinCashAddressTypeChange
);
157 setQrEvents(DOM
.showQrEls
);
160 hideValidationError();
161 populateNetworkSelect();
162 populateClientSelect();
167 function generatedStrengthChanged() {
168 var strength
= parseInt(DOM
.generatedStrength
.val());
170 DOM
.generatedStrengthWarning
.removeClass("hidden");
173 DOM
.generatedStrengthWarning
.addClass("hidden");
177 function networkChanged(e
) {
179 clearAddressesList();
180 DOM
.litecoinLtubContainer
.addClass("hidden");
181 DOM
.bitcoinCashAddressTypeContainer
.addClass("hidden");
182 var networkIndex
= e
.target
.value
;
183 var network
= networks
[networkIndex
];
185 adjustNetworkForSegwit();
194 function bip32ClientChanged(e
) {
195 var clientIndex
= DOM
.bip32Client
.val();
196 if (clientIndex
== "custom") {
197 DOM
.bip32path
.prop("readonly", false);
200 DOM
.bip32path
.prop("readonly", true);
201 clients
[clientIndex
].onSelect();
211 function setEntropyVisibility() {
212 if (isUsingOwnEntropy()) {
213 DOM
.entropyContainer
.removeClass("hidden");
214 DOM
.generateContainer
.addClass("hidden");
215 DOM
.phrase
.prop("readonly", true);
220 DOM
.entropyContainer
.addClass("hidden");
221 DOM
.generateContainer
.removeClass("hidden");
222 DOM
.phrase
.prop("readonly", false);
227 function delayedPhraseChanged() {
228 hideValidationError();
231 bip32ExtendedKey
= null;
232 clearAddressesList();
234 if (phraseChangeTimeoutEvent
!= null) {
235 clearTimeout(phraseChangeTimeoutEvent
);
237 phraseChangeTimeoutEvent
= setTimeout(function() {
239 var entropy
= mnemonic
.toRawEntropyBin(DOM
.phrase
.val());
240 if (entropy
!== null) {
241 DOM
.entropyMnemonicLength
.val("raw");
242 DOM
.entropy
.val(entropy
);
247 function phraseChanged() {
249 setMnemonicLanguage();
250 // Get the mnemonic phrase
251 var phrase
= DOM
.phrase
.val();
252 var errorText
= findPhraseErrors(phrase
);
254 showValidationError(errorText
);
257 // Calculate and display
258 var passphrase
= DOM
.passphrase
.val();
259 calcBip32RootKeyFromSeed(phrase
, passphrase
);
260 calcForDerivationPath();
261 // Show the word indexes
263 writeSplitPhrase(phrase
);
266 function tabChanged() {
268 adjustNetworkForSegwit();
269 var phrase
= DOM
.phrase
.val();
271 // Calculate and display for mnemonic
272 var errorText
= findPhraseErrors(phrase
);
274 showValidationError(errorText
);
277 // Calculate and display
278 var passphrase
= DOM
.passphrase
.val();
279 calcBip32RootKeyFromSeed(phrase
, passphrase
);
282 // Calculate and display for root key
283 var rootKeyBase58
= DOM
.rootKey
.val();
284 var errorText
= validateRootKey(rootKeyBase58
);
286 showValidationError(errorText
);
289 // Calculate and display
290 calcBip32RootKeyFromBase58(rootKeyBase58
);
292 calcForDerivationPath();
295 function delayedEntropyChanged() {
296 hideValidationError();
298 if (entropyChangeTimeoutEvent
!= null) {
299 clearTimeout(entropyChangeTimeoutEvent
);
301 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
304 function entropyChanged() {
305 // If blank entropy, clear mnemonic, addresses, errors
306 if (DOM
.entropy
.val().trim().length
== 0) {
308 clearEntropyFeedback();
310 DOM
.phraseSplit
.val("");
311 showValidationError("Blank entropy");
314 // Get the current phrase to detect changes
315 var phrase
= DOM
.phrase
.val();
316 // Set the phrase from the entropy
317 setMnemonicFromEntropy();
318 // Recalc addresses if the phrase has changed
319 var newPhrase
= DOM
.phrase
.val();
320 if (newPhrase
!= phrase
) {
321 if (newPhrase
.length
== 0) {
333 function delayedRootKeyChanged() {
334 // Warn if there is an existing mnemonic or passphrase.
335 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
336 if (!confirm("This will clear existing mnemonic and passphrase")) {
337 DOM
.rootKey
.val(bip32RootKey
);
341 hideValidationError();
343 // Clear existing mnemonic and passphrase
345 DOM
.phraseSplit
.val("");
346 DOM
.passphrase
.val("");
348 if (rootKeyChangedTimeoutEvent
!= null) {
349 clearTimeout(rootKeyChangedTimeoutEvent
);
351 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
354 function rootKeyChanged() {
356 hideValidationError();
357 var rootKeyBase58
= DOM
.rootKey
.val();
358 var errorText
= validateRootKey(rootKeyBase58
);
360 showValidationError(errorText
);
363 // Calculate and display
364 calcBip32RootKeyFromBase58(rootKeyBase58
);
365 calcForDerivationPath();
368 function litecoinUseLtubChanged() {
369 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
370 if (litecoinUseLtub
) {
371 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
374 network
= bitcoinjs
.bitcoin
.networks
.litecoinXprv
;
379 function calcForDerivationPath() {
381 clearAddressesList();
383 // Don't show segwit if it's selected but network doesn't support it
384 if (segwitSelected() && !networkHasSegwit()) {
385 showSegwitUnavailable();
389 showSegwitAvailable();
390 // Get the derivation path
391 var derivationPath
= getDerivationPath();
392 var errorText
= findDerivationPathErrors(derivationPath
);
394 showValidationError(errorText
);
397 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
398 if (bip44TabSelected()) {
401 else if (bip49TabSelected()) {
404 else if (bip84TabSelected()) {
410 function generateClicked() {
411 if (isUsingOwnEntropy()) {
416 setTimeout(function() {
417 setMnemonicLanguage();
418 var phrase
= generateRandomPhrase();
426 function languageChanged() {
427 setTimeout(function() {
428 setMnemonicLanguage();
429 if (DOM
.phrase
.val().length
> 0) {
430 var newPhrase
= convertPhraseToNewLanguage();
431 DOM
.phrase
.val(newPhrase
);
435 DOM
.generate
.trigger("click");
440 function bitcoinCashAddressTypeChange() {
444 function toggleIndexes() {
445 showIndex
= !showIndex
;
446 $("td.index span").toggleClass("invisible");
449 function toggleAddresses() {
450 showAddress
= !showAddress
;
451 $("td.address span").toggleClass("invisible");
454 function togglePublicKeys() {
455 showPubKey
= !showPubKey
;
456 $("td.pubkey span").toggleClass("invisible");
459 function togglePrivateKeys() {
460 showPrivKey
= !showPrivKey
;
461 $("td.privkey span").toggleClass("invisible");
464 function privacyScreenToggled() {
465 // private-data contains elements added to DOM at runtime
466 // so catch all by adding visual privacy class to the root of the DOM
467 if (DOM
.privacyScreenToggle
.prop("checked")) {
468 $("body").addClass("visual-privacy");
471 $("body").removeClass("visual-privacy");
477 function generateRandomPhrase() {
478 if (!hasStrongRandom()) {
479 var errorText
= "This browser does not support strong randomness";
480 showValidationError(errorText
);
483 // get the amount of entropy to use
484 var numWords
= parseInt(DOM
.generatedStrength
.val());
485 var strength
= numWords
/ 3 * 32;
486 var buffer
= new Uint8Array(strength
/ 8);
487 // create secure entropy
488 var data
= crypto
.getRandomValues(buffer
);
490 var words
= mnemonic
.toMnemonic(data
);
491 DOM
.phrase
.val(words
);
493 var entropyHex
= uint8ArrayToHex(data
);
494 DOM
.entropy
.val(entropyHex
);
495 // ensure entropy fields are consistent with what is being displayed
496 DOM
.entropyMnemonicLength
.val("raw");
500 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
501 seed
= mnemonic
.toSeed(phrase
, passphrase
);
502 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
504 bip32RootKey
= groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
508 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
510 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
513 // try parsing with various segwit network params since this extended
514 // key may be from any one of them.
515 if (networkHasSegwit()) {
517 if ("baseNetwork" in n
) {
518 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
520 // try parsing using base network params
522 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
526 // try parsing using p2wpkh params
529 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
534 // try parsing using p2wpkh-in-p2sh network params
535 if ("p2wpkhInP2sh" in n
) {
537 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
542 // try parsing using p2wsh network params
545 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
550 // try parsing using p2wsh-in-p2sh network params
551 if ("p2wshInP2sh" in n
) {
553 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
559 // try the network params as currently specified
560 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
563 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
564 // try parsing with various segwit network params since this extended
565 // key may be from any one of them.
566 if (networkHasSegwit()) {
568 if ("baseNetwork" in n
) {
569 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
571 // try parsing using base network params
573 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
577 // try parsing using p2wpkh params
580 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
585 // try parsing using p2wpkh-in-p2sh network params
586 if ("p2wpkhInP2sh" in n
) {
588 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
594 // try the network params as currently specified
595 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
598 function calcBip32ExtendedKey(path
) {
599 // Check there's a root key to derive from
603 var extendedKey
= bip32RootKey
;
604 // Derive the key from the path
605 var pathBits
= path
.split("/");
606 for (var i
=0; i
<pathBits
.length
; i
++) {
607 var bit
= pathBits
[i
];
608 var index
= parseInt(bit
);
612 var hardened
= bit
[bit
.length
-1] == "'";
613 var isPriv
= !(extendedKey
.isNeutered());
614 var invalidDerivationPath
= hardened
&& !isPriv
;
615 if (invalidDerivationPath
) {
619 extendedKey
= extendedKey
.deriveHardened(index
);
622 extendedKey
= extendedKey
.derive(index
);
628 function showValidationError(errorText
) {
634 function hideValidationError() {
640 function findPhraseErrors(phrase
) {
641 // Preprocess the words
642 phrase
= mnemonic
.normalizeString(phrase
);
643 var words
= phraseToWordArray(phrase
);
644 // Detect blank phrase
645 if (words
.length
== 0) {
646 return "Blank mnemonic";
649 for (var i
=0; i
<words
.length
; i
++) {
651 var language
= getLanguage();
652 if (WORDLISTS
[language
].indexOf(word
) == -1) {
653 console
.log("Finding closest match to " + word
);
654 var nearestWord
= findNearestWord(word
);
655 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
658 // Check the words are valid
659 var properPhrase
= wordArrayToPhrase(words
);
660 var isValid
= mnemonic
.check(properPhrase
);
662 return "Invalid mnemonic";
667 function validateRootKey(rootKeyBase58
) {
669 return validateRootKeyGRS(rootKeyBase58
);
671 // try various segwit network params since this extended key may be from
673 if (networkHasSegwit()) {
675 if ("baseNetwork" in n
) {
676 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
678 // try parsing using base network params
680 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
684 // try parsing using p2wpkh params
687 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
692 // try parsing using p2wpkh-in-p2sh network params
693 if ("p2wpkhInP2sh" in n
) {
695 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
700 // try parsing using p2wsh network params
703 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
708 // try parsing using p2wsh-in-p2sh network params
709 if ("p2wshInP2sh" in n
) {
711 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
717 // try the network params as currently specified
719 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
722 return "Invalid root key";
727 function validateRootKeyGRS(rootKeyBase58
) {
728 // try various segwit network params since this extended key may be from
730 if (networkHasSegwit()) {
732 if ("baseNetwork" in n
) {
733 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
735 // try parsing using base network params
737 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
741 // try parsing using p2wpkh params
744 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
749 // try parsing using p2wpkh-in-p2sh network params
750 if ("p2wpkhInP2sh" in n
) {
752 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
758 // try the network params as currently specified
760 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
763 return "Invalid root key";
768 function getDerivationPath() {
769 if (bip44TabSelected()) {
770 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
771 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
772 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
773 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
775 path
+= purpose
+ "'/";
777 path
+= account
+ "'/";
779 DOM
.bip44path
.val(path
);
780 var derivationPath
= DOM
.bip44path
.val();
781 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
782 return derivationPath
;
784 else if (bip49TabSelected()) {
785 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
786 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
787 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
788 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
790 path
+= purpose
+ "'/";
792 path
+= account
+ "'/";
794 DOM
.bip49path
.val(path
);
795 var derivationPath
= DOM
.bip49path
.val();
796 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
797 return derivationPath
;
799 else if (bip84TabSelected()) {
800 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
801 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
802 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
803 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
805 path
+= purpose
+ "'/";
807 path
+= account
+ "'/";
809 DOM
.bip84path
.val(path
);
810 var derivationPath
= DOM
.bip84path
.val();
811 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
812 return derivationPath
;
814 else if (bip32TabSelected()) {
815 var derivationPath
= DOM
.bip32path
.val();
816 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
817 return derivationPath
;
819 else if (bip141TabSelected()) {
820 var derivationPath
= DOM
.bip141path
.val();
821 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
822 return derivationPath
;
825 console
.log("Unknown derivation path");
829 function findDerivationPathErrors(path
) {
830 // TODO is not perfect but is better than nothing
832 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
834 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
835 var maxDepth
= 255; // TODO verify this!!
836 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
837 if (path
[0] != "m") {
838 return "First character must be 'm'";
840 if (path
.length
> 1) {
841 if (path
[1] != "/") {
842 return "Separator must be '/'";
844 var indexes
= path
.split("/");
845 if (indexes
.length
> maxDepth
) {
846 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
848 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
849 var index
= indexes
[depth
];
850 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
851 if (invalidChars
.length
> 0) {
852 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
854 var indexValue
= parseInt(index
.replace("'", ""));
856 return "Invalid number at depth " + depth
;
858 if (indexValue
> maxIndexValue
) {
859 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
863 // Check root key exists or else derivation path is useless!
865 return "No root key";
867 // Check no hardened derivation path when using xpub keys
868 var hardenedPath
= path
.indexOf("'") > -1;
869 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
870 var hardened
= hardenedPath
|| hardenedAddresses
;
871 var isXpubkey
= bip32RootKey
.isNeutered();
872 if (hardened
&& isXpubkey
) {
873 return "Hardened derivation path is invalid with xpub key";
879 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
883 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
886 function displayBip44Info() {
887 // Get the derivation path for the account
888 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
889 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
890 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
892 path
+= purpose
+ "'/";
894 path
+= account
+ "'/";
895 // Calculate the account extended keys
896 var accountExtendedKey
= calcBip32ExtendedKey(path
);
897 var accountXprv
= accountExtendedKey
.toBase58();
898 var accountXpub
= accountExtendedKey
.neutered().toBase58();
900 // Display the extended keys
901 DOM
.bip44accountXprv
.val(accountXprv
);
902 DOM
.bip44accountXpub
.val(accountXpub
);
905 displayBip44InfoForELA();
909 function displayBip49Info() {
910 // Get the derivation path for the account
911 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
912 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
913 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
915 path
+= purpose
+ "'/";
917 path
+= account
+ "'/";
918 // Calculate the account extended keys
919 var accountExtendedKey
= calcBip32ExtendedKey(path
);
920 var accountXprv
= accountExtendedKey
.toBase58();
921 var accountXpub
= accountExtendedKey
.neutered().toBase58();
922 // Display the extended keys
923 DOM
.bip49accountXprv
.val(accountXprv
);
924 DOM
.bip49accountXpub
.val(accountXpub
);
927 function displayBip84Info() {
928 // Get the derivation path for the account
929 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
930 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
931 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
933 path
+= purpose
+ "'/";
935 path
+= account
+ "'/";
936 // Calculate the account extended keys
937 var accountExtendedKey
= calcBip32ExtendedKey(path
);
938 var accountXprv
= accountExtendedKey
.toBase58();
939 var accountXpub
= accountExtendedKey
.neutered().toBase58();
940 // Display the extended keys
941 DOM
.bip84accountXprv
.val(accountXprv
);
942 DOM
.bip84accountXpub
.val(accountXpub
);
945 function displayBip32Info() {
948 var rootKey
= bip32RootKey
.toBase58();
949 DOM
.rootKey
.val(rootKey
);
950 var xprvkeyB58
= "NA";
951 if (!bip32ExtendedKey
.isNeutered()) {
952 xprvkeyB58
= bip32ExtendedKey
.toBase58();
954 var extendedPrivKey
= xprvkeyB58
;
955 DOM
.extendedPrivKey
.val(extendedPrivKey
);
956 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
957 DOM
.extendedPubKey
.val(extendedPubKey
);
958 // Display the addresses and privkeys
959 clearAddressesList();
960 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
961 displayAddresses(0, initialAddressCount
);
964 displayBip32InfoForELA();
968 function displayAddresses(start
, total
) {
969 generationProcesses
.push(new (function() {
973 this.stop = function() {
974 for (var i
=0; i
<rows
.length
; i
++) {
975 rows
[i
].shouldGenerate
= false;
980 for (var i
=0; i
<total
; i
++) {
981 var index
= i
+ start
;
982 var isLast
= i
== total
- 1;
983 rows
.push(new TableRow(index
, isLast
));
989 function segwitSelected() {
990 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
993 function p2wpkhSelected() {
994 return bip84TabSelected() ||
995 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
998 function p2wpkhInP2shSelected() {
999 return bip49TabSelected() ||
1000 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
1003 function p2wshSelected() {
1004 return bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh";
1007 function p2wshInP2shSelected() {
1008 return (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh-p2sh");
1011 function TableRow(index
, isLast
) {
1014 this.shouldGenerate
= true;
1015 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
1016 var useBip38
= DOM
.useBip38
.prop("checked");
1017 var bip38password
= DOM
.bip38Password
.val();
1018 var isSegwit
= segwitSelected();
1019 var segwitAvailable
= networkHasSegwit();
1020 var isP2wpkh
= p2wpkhSelected();
1021 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
1022 var isP2wsh
= p2wshSelected();
1023 var isP2wshInP2sh
= p2wshInP2shSelected();
1029 function calculateValues() {
1030 setTimeout(function() {
1031 if (!self
.shouldGenerate
) {
1034 // derive HDkey for this row of the table
1036 if (useHardenedAddresses
) {
1037 key
= bip32ExtendedKey
.deriveHardened(index
);
1040 key
= bip32ExtendedKey
.derive(index
);
1042 // bip38 requires uncompressed keys
1043 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1044 var keyPair
= key
.keyPair
;
1045 var useUncompressed
= useBip38
;
1046 if (useUncompressed
) {
1047 keyPair
= new bitcoinjs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1049 keyPair
= new groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1053 var address
= keyPair
.getAddress().toString();
1055 var hasPrivkey
= !key
.isNeutered();
1058 privkey
= keyPair
.toWIF();
1059 // BIP38 encode private key if required
1062 privkey
= groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1063 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1064 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1066 privkey
= bitcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1067 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1072 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1073 var indexText
= getDerivationPath() + "/" + index
;
1074 if (useHardenedAddresses
) {
1075 indexText
= indexText
+ "'";
1077 // Ethereum values are different
1078 if (networkIsEthereum()) {
1079 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1080 privkey
= privKeyBuffer
.toString('hex');
1081 var addressBuffer
= ethUtil
.privateToAddress(privKeyBuffer
);
1082 var hexAddress
= addressBuffer
.toString('hex');
1083 var checksumAddress
= ethUtil
.toChecksumAddress(hexAddress
);
1084 address
= ethUtil
.addHexPrefix(checksumAddress
);
1085 privkey
= ethUtil
.addHexPrefix(privkey
);
1086 pubkey
= ethUtil
.addHexPrefix(pubkey
);
1089 // Stellar is different
1090 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1091 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1092 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1094 path
+= purpose
+ "'/";
1095 path
+= coin
+ "'/" + index
+ "'";
1096 var keypair
= stellarUtil
.getKeypair(path
, seed
);
1098 privkey
= keypair
.secret();
1099 pubkey
= address
= keypair
.publicKey();
1101 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1102 var NasAccount
= require("nebulas-account");
1103 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1104 var nebulasAccount
= new NasAccount();
1105 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1106 address
= nebulasAccount
.getAddressString();
1107 privkey
= nebulasAccount
.getPrivateKeyString();
1108 pubkey
= nebulasAccount
.getPublicKeyString();
1110 // Ripple values are different
1111 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1112 privkey
= convertRipplePriv(privkey
);
1113 address
= convertRippleAdrr(address
);
1115 // CasinoCoin values are different
1116 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1117 privkey
= convertCasinoCoinPriv(privkey
);
1118 address
= convertCasinoCoinAdrr(address
);
1120 // Bitcoin Cash address format may vary
1121 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1122 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1123 if (bchAddrType
== "cashaddr") {
1124 address
= bchaddr
.toCashAddress(address
);
1126 else if (bchAddrType
== "bitpay") {
1127 address
= bchaddr
.toBitpayAddress(address
);
1130 // Bitcoin Cash address format may vary
1131 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1132 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1133 if (bchAddrType
== "cashaddr") {
1134 address
= bchaddr
.toSlpAddress(address
);
1137 // Segwit addresses are different
1139 if (!segwitAvailable
) {
1143 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1144 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1145 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1147 else if (isP2wpkhInP2sh
) {
1148 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1149 var scriptsig
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1150 var addressbytes
= bitcoinjs
.bitcoin
.crypto
.hash160(scriptsig
);
1151 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1152 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1155 // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71
1157 var witnessScript
= bitcoinjs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1158 var scriptPubKey
= bitcoinjs
.bitcoin
.script
.witnessScriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.sha256(witnessScript
));
1159 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
);
1161 else if (isP2wshInP2sh
) {
1162 // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183
1164 var witnessScript
= bitcoinjs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1165 var redeemScript
= bitcoinjs
.bitcoin
.script
.witnessScriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.sha256(witnessScript
));
1166 var scriptPubKey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.hash160(redeemScript
));
1167 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
)
1171 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1172 address
= bitcoinjs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1175 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1177 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1178 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1181 //Groestlcoin Addresses are different
1185 if (!segwitAvailable
) {
1189 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1191 else if (isP2wpkhInP2sh
) {
1192 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1195 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1199 let elaAddress
= calcAddressForELA(
1201 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1202 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1203 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1206 address
= elaAddress
.address
;
1207 privkey
= elaAddress
.privateKey
;
1208 pubkey
= elaAddress
.publicKey
;
1211 addAddressToList(indexText
, address
, pubkey
, privkey
);
1223 function showMore() {
1224 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1225 if (isNaN(rowsToAdd
)) {
1227 DOM
.rowsToAdd
.val("20");
1229 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1231 start
= lastIndexInTable() + 1;
1234 var newStart
= start
+ rowsToAdd
;
1235 DOM
.moreRowsStartIndex
.val(newStart
);
1237 if (rowsToAdd
> 200) {
1238 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1239 msg
+= "Do you want to continue?";
1240 if (!confirm(msg
)) {
1244 displayAddresses(start
, rowsToAdd
);
1247 function clearDisplay() {
1248 clearAddressesList();
1250 hideValidationError();
1253 function clearAddressesList() {
1254 DOM
.addresses
.empty();
1259 function stopGenerating() {
1260 while (generationProcesses
.length
> 0) {
1261 var generation
= generationProcesses
.shift();
1266 function clearKeys() {
1271 function clearRootKey() {
1272 DOM
.rootKey
.val("");
1275 function clearDerivedKeys() {
1276 DOM
.extendedPrivKey
.val("");
1277 DOM
.extendedPubKey
.val("");
1278 DOM
.bip44accountXprv
.val("");
1279 DOM
.bip44accountXpub
.val("");
1282 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1283 var row
= $(addressRowTemplate
.html());
1285 var indexCell
= row
.find(".index span");
1286 var addressCell
= row
.find(".address span");
1287 var pubkeyCell
= row
.find(".pubkey span");
1288 var privkeyCell
= row
.find(".privkey span");
1290 indexCell
.text(indexText
);
1291 addressCell
.text(address
);
1292 pubkeyCell
.text(pubkey
);
1293 privkeyCell
.text(privkey
);
1296 indexCell
.addClass("invisible");
1299 addressCell
.addClass("invisible");
1302 pubkeyCell
.addClass("invisible");
1305 privkeyCell
.addClass("invisible");
1307 DOM
.addresses
.append(row
);
1308 var rowShowQrEls
= row
.find("[data-show-qr]");
1309 setQrEvents(rowShowQrEls
);
1312 function hasStrongRandom() {
1313 return 'crypto' in window
&& window
['crypto'] !== null;
1316 function disableForms() {
1317 $("form").on("submit", function(e
) {
1322 function parseIntNoNaN(val
, defaultVal
) {
1323 var v
= parseInt(val
);
1330 function showPending() {
1332 .text("Calculating...")
1336 function findNearestWord(word
) {
1337 var language
= getLanguage();
1338 var words
= WORDLISTS
[language
];
1339 var minDistance
= 99;
1340 var closestWord
= words
[0];
1341 for (var i
=0; i
<words
.length
; i
++) {
1342 var comparedTo
= words
[i
];
1343 if (comparedTo
.indexOf(word
) == 0) {
1346 var distance
= Levenshtein
.get(word
, comparedTo
);
1347 if (distance
< minDistance
) {
1348 closestWord
= comparedTo
;
1349 minDistance
= distance
;
1355 function hidePending() {
1361 function populateNetworkSelect() {
1362 for (var i
=0; i
<networks
.length
; i
++) {
1363 var network
= networks
[i
];
1364 var option
= $("<option>");
1365 option
.attr("value", i
);
1366 option
.text(network
.name
);
1367 if (network
.name
== "BTC - Bitcoin") {
1368 option
.prop("selected", true);
1370 DOM
.phraseNetwork
.append(option
);
1374 function populateClientSelect() {
1375 for (var i
=0; i
<clients
.length
; i
++) {
1376 var client
= clients
[i
];
1377 var option
= $("<option>");
1378 option
.attr("value", i
);
1379 option
.text(client
.name
);
1380 DOM
.bip32Client
.append(option
);
1384 function getLanguage() {
1385 var defaultLanguage
= "english";
1386 // Try to get from existing phrase
1387 var language
= getLanguageFromPhrase();
1388 // Try to get from url if not from phrase
1389 if (language
.length
== 0) {
1390 language
= getLanguageFromUrl();
1392 // Default to English if no other option
1393 if (language
.length
== 0) {
1394 language
= defaultLanguage
;
1399 function getLanguageFromPhrase(phrase
) {
1400 // Check if how many words from existing phrase match a language.
1403 phrase
= DOM
.phrase
.val();
1405 if (phrase
.length
> 0) {
1406 var words
= phraseToWordArray(phrase
);
1407 var languageMatches
= {};
1408 for (l
in WORDLISTS
) {
1409 // Track how many words match in this language
1410 languageMatches
[l
] = 0;
1411 for (var i
=0; i
<words
.length
; i
++) {
1412 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1413 if (wordInLanguage
) {
1414 languageMatches
[l
]++;
1417 // Find languages with most word matches.
1418 // This is made difficult due to commonalities between Chinese
1419 // simplified vs traditional.
1420 var mostMatches
= 0;
1421 var mostMatchedLanguages
= [];
1422 for (var l
in languageMatches
) {
1423 var numMatches
= languageMatches
[l
];
1424 if (numMatches
> mostMatches
) {
1425 mostMatches
= numMatches
;
1426 mostMatchedLanguages
= [l
];
1428 else if (numMatches
== mostMatches
) {
1429 mostMatchedLanguages
.push(l
);
1433 if (mostMatchedLanguages
.length
> 0) {
1434 // Use first language and warn if multiple detected
1435 language
= mostMatchedLanguages
[0];
1436 if (mostMatchedLanguages
.length
> 1) {
1437 console
.warn("Multiple possible languages");
1438 console
.warn(mostMatchedLanguages
);
1445 function getLanguageFromUrl() {
1446 for (var language
in WORDLISTS
) {
1447 if (window
.location
.hash
.indexOf(language
) > -1) {
1454 function setMnemonicLanguage() {
1455 var language
= getLanguage();
1456 // Load the bip39 mnemonic generator for this language if required
1457 if (!(language
in mnemonics
)) {
1458 mnemonics
[language
] = new Mnemonic(language
);
1460 mnemonic
= mnemonics
[language
];
1463 function convertPhraseToNewLanguage() {
1464 var oldLanguage
= getLanguageFromPhrase();
1465 var newLanguage
= getLanguageFromUrl();
1466 var oldPhrase
= DOM
.phrase
.val();
1467 var oldWords
= phraseToWordArray(oldPhrase
);
1469 for (var i
=0; i
<oldWords
.length
; i
++) {
1470 var oldWord
= oldWords
[i
];
1471 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1472 var newWord
= WORDLISTS
[newLanguage
][index
];
1473 newWords
.push(newWord
);
1475 newPhrase
= wordArrayToPhrase(newWords
);
1479 // TODO look at jsbip39 - mnemonic.splitWords
1480 function phraseToWordArray(phrase
) {
1481 var words
= phrase
.split(/\s/g);
1483 for (var i
=0; i
<words
.length
; i
++) {
1484 var word
= words
[i
];
1485 if (word
.length
> 0) {
1486 noBlanks
.push(word
);
1492 // TODO look at jsbip39 - mnemonic.joinWords
1493 function wordArrayToPhrase(words
) {
1494 var phrase
= words
.join(" ");
1495 var language
= getLanguageFromPhrase(phrase
);
1496 if (language
== "japanese") {
1497 phrase
= words
.join("\u3000");
1502 function writeSplitPhrase(phrase
) {
1503 var wordCount
= phrase
.split(/\s/g).length
;
1505 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1506 var group
=[[],[],[]],
1508 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1509 while (left
.length
>0) {
1510 groupI
=(groupI
+1)%3;
1511 seed
= seed
* 16807 % 2147483647;
1512 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1513 group
[groupI
].push(left
[selected
]);
1514 left
.splice(selected
,1);
1516 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1517 for (var i
=0;i
<3;i
++) {
1518 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1519 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1521 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1522 var triesPerSecond
=10000000000;
1523 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1524 var displayRedText
= false;
1526 hackTime
="<1 second";
1527 displayRedText
= true;
1528 } else if (hackTime
<86400) {
1529 hackTime
=Math
.floor(hackTime
)+" seconds";
1530 displayRedText
= true;
1531 } else if(hackTime
<31557600) {
1532 hackTime
=Math
.floor(hackTime
/86400)+" days";
1533 displayRedText
= true;
1535 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1537 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1538 if (displayRedText
) {
1539 DOM
.phraseSplitWarn
.addClass("text-danger");
1541 DOM
.phraseSplitWarn
.removeClass("text-danger");
1545 function isUsingOwnEntropy() {
1546 return DOM
.useEntropy
.prop("checked");
1549 function setMnemonicFromEntropy() {
1550 clearEntropyFeedback();
1551 // Get entropy value
1552 var entropyStr
= DOM
.entropy
.val();
1553 // Work out minimum base for entropy
1554 var entropy
= Entropy
.fromString(entropyStr
);
1555 if (entropy
.binaryStr
.length
== 0) {
1558 // Show entropy details
1559 showEntropyFeedback(entropy
);
1560 // Use entropy hash if not using raw entropy
1561 var bits
= entropy
.binaryStr
;
1562 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1563 if (mnemonicLength
!= "raw") {
1564 // Get bits by hashing entropy with SHA256
1565 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1566 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1567 bits
= BigInteger
.parse(hex
, 16).toString(2);
1568 while (bits
.length
% 256 != 0) {
1571 // Truncate hash to suit number of words
1572 mnemonicLength
= parseInt(mnemonicLength
);
1573 var numberOfBits
= 32 * mnemonicLength
/ 3;
1574 bits
= bits
.substring(0, numberOfBits
);
1575 // show warning for weak entropy override
1576 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1577 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1580 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1584 // hide warning for weak entropy override
1585 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1587 // Discard trailing entropy
1588 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1589 var start
= bits
.length
- bitsToUse
;
1590 var binaryStr
= bits
.substring(start
);
1591 // Convert entropy string to numeric array
1592 var entropyArr
= [];
1593 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1594 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1595 var entropyByte
= parseInt(byteAsBits
, 2);
1596 entropyArr
.push(entropyByte
)
1598 // Convert entropy array to mnemonic
1599 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1600 // Set the mnemonic in the UI
1601 DOM
.phrase
.val(phrase
);
1602 writeSplitPhrase(phrase
);
1603 // Show the word indexes
1605 // Show the checksum
1609 function clearEntropyFeedback() {
1610 DOM
.entropyCrackTime
.text("...");
1611 DOM
.entropyType
.text("");
1612 DOM
.entropyWordCount
.text("0");
1613 DOM
.entropyEventCount
.text("0");
1614 DOM
.entropyBitsPerEvent
.text("0");
1615 DOM
.entropyBits
.text("0");
1616 DOM
.entropyFiltered
.html(" ");
1617 DOM
.entropyBinary
.html(" ");
1620 function showEntropyFeedback(entropy
) {
1621 var numberOfBits
= entropy
.binaryStr
.length
;
1622 var timeToCrack
= "unknown";
1624 var z
= zxcvbn(entropy
.base
.parts
.join(""));
1625 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1626 if (z
.feedback
.warning
!= "") {
1627 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1631 console
.log("Error detecting entropy strength with zxcvbn:");
1634 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1635 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1636 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1637 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1638 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1639 DOM
.entropyType
.text(entropyTypeStr
);
1640 DOM
.entropyCrackTime
.text(timeToCrack
);
1641 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1642 DOM
.entropyBits
.text(numberOfBits
);
1643 DOM
.entropyWordCount
.text(wordCount
);
1644 DOM
.entropyBinary
.text(spacedBinaryStr
);
1645 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1646 // detect and warn of filtering
1647 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1648 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1649 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1651 DOM
.entropyFilterWarning
.removeClass('hidden');
1654 DOM
.entropyFilterWarning
.addClass('hidden');
1658 function getEntropyTypeStr(entropy
) {
1659 var typeStr
= entropy
.base
.str
;
1660 // Add some detail if these are cards
1661 if (entropy
.base
.asInt
== 52) {
1662 var cardDetail
= []; // array of message strings
1663 // Detect duplicates
1665 var dupeTracker
= {};
1666 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1667 var card
= entropy
.base
.parts
[i
];
1668 var cardUpper
= card
.toUpperCase();
1669 if (cardUpper
in dupeTracker
) {
1672 dupeTracker
[cardUpper
] = true;
1674 if (dupes
.length
> 0) {
1675 var dupeWord
= "duplicates";
1676 if (dupes
.length
== 1) {
1677 dupeWord
= "duplicate";
1679 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1680 if (dupes
.length
> 3) {
1683 cardDetail
.push(msg
);
1686 var uniqueCards
= [];
1687 for (var uniqueCard
in dupeTracker
) {
1688 uniqueCards
.push(uniqueCard
);
1690 if (uniqueCards
.length
== 52) {
1691 cardDetail
.unshift("full deck");
1693 // Detect missing cards
1694 var values
= "A23456789TJQK";
1696 var missingCards
= [];
1697 for (var i
=0; i
<suits
.length
; i
++) {
1698 for (var j
=0; j
<values
.length
; j
++) {
1699 var card
= values
[j
] + suits
[i
];
1700 if (!(card
in dupeTracker
)) {
1701 missingCards
.push(card
);
1705 // Display missing cards if six or less, ie clearly going for full deck
1706 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1707 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1708 if (missingCards
.length
> 3) {
1711 cardDetail
.push(msg
);
1713 // Add card details to typeStr
1714 if (cardDetail
.length
> 0) {
1715 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1721 function setQrEvents(els
) {
1722 els
.on("mouseenter", createQr
);
1723 els
.on("mouseleave", destroyQr
);
1724 els
.on("click", toggleQr
);
1727 function createQr(e
) {
1728 var content
= e
.target
.textContent
|| e
.target
.value
;
1736 DOM
.qrImage
.append(qrEl
);
1738 DOM
.qrHider
.addClass("hidden");
1741 DOM
.qrHider
.removeClass("hidden");
1743 DOM
.qrContainer
.removeClass("hidden");
1747 function destroyQr() {
1748 DOM
.qrImage
.text("");
1749 DOM
.qrContainer
.addClass("hidden");
1752 function toggleQr() {
1754 DOM
.qrHider
.toggleClass("hidden");
1755 DOM
.qrHint
.toggleClass("hidden");
1758 function bip44TabSelected() {
1759 return DOM
.bip44tab
.hasClass("active");
1762 function bip32TabSelected() {
1763 return DOM
.bip32tab
.hasClass("active");
1766 function networkIsEthereum() {
1767 var name
= networks
[DOM
.network
.val()].name
;
1768 return (name
== "ETH - Ethereum")
1769 || (name
== "ETC - Ethereum Classic")
1770 || (name
== "EWT - EnergyWeb")
1771 || (name
== "PIRL - Pirl")
1772 || (name
== "MIX - MIX")
1773 || (name
== "MUSIC - Musicoin")
1774 || (name
== "POA - Poa")
1775 || (name
== "EXP - Expanse")
1776 || (name
== "CLO - Callisto")
1777 || (name
== "DXN - DEXON")
1778 || (name
== "ELLA - Ellaism")
1779 || (name
== "ESN - Ethersocial Network")
1780 || (name
== "VET - VeChain")
1783 function networkHasSegwit() {
1785 if ("baseNetwork" in network
) {
1786 n
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1788 // check if only p2wpkh params are required
1789 if (p2wpkhSelected()) {
1790 return "p2wpkh" in n
;
1792 // check if only p2wpkh-in-p2sh params are required
1793 else if (p2wpkhInP2shSelected()) {
1794 return "p2wpkhInP2sh" in n
;
1796 // require both if it's unclear which params are required
1797 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1800 function bip49TabSelected() {
1801 return DOM
.bip49tab
.hasClass("active");
1804 function bip84TabSelected() {
1805 return DOM
.bip84tab
.hasClass("active");
1808 function bip141TabSelected() {
1809 return DOM
.bip141tab
.hasClass("active");
1812 function setHdCoin(coinValue
) {
1813 DOM
.bip44coin
.val(coinValue
);
1814 DOM
.bip49coin
.val(coinValue
);
1815 DOM
.bip84coin
.val(coinValue
);
1818 function showSegwitAvailable() {
1819 DOM
.bip49unavailable
.addClass("hidden");
1820 DOM
.bip49available
.removeClass("hidden");
1821 DOM
.bip84unavailable
.addClass("hidden");
1822 DOM
.bip84available
.removeClass("hidden");
1823 DOM
.bip141unavailable
.addClass("hidden");
1824 DOM
.bip141available
.removeClass("hidden");
1827 function showSegwitUnavailable() {
1828 DOM
.bip49available
.addClass("hidden");
1829 DOM
.bip49unavailable
.removeClass("hidden");
1830 DOM
.bip84available
.addClass("hidden");
1831 DOM
.bip84unavailable
.removeClass("hidden");
1832 DOM
.bip141available
.addClass("hidden");
1833 DOM
.bip141unavailable
.removeClass("hidden");
1836 function adjustNetworkForSegwit() {
1837 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1838 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1840 // See https://github.com/iancoleman/bip39/issues/125
1841 var segwitNetworks
= null;
1842 // if a segwit network is alread selected, need to use base network to
1843 // look up new parameters
1844 if ("baseNetwork" in network
) {
1845 network
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1847 // choose the right segwit params
1848 if (p2wpkhSelected() && "p2wpkh" in network
) {
1849 network
= network
.p2wpkh
;
1851 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1852 network
= network
.p2wpkhInP2sh
;
1854 else if (p2wshSelected() && "p2wsh" in network
) {
1855 network
= network
.p2wsh
;
1857 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network
) {
1858 network
= network
.p2wshInP2sh
;
1862 function lastIndexInTable() {
1863 var pathText
= DOM
.addresses
.find(".index").last().text();
1864 var pathBits
= pathText
.split("/");
1865 var lastBit
= pathBits
[pathBits
.length
-1];
1866 var lastBitClean
= lastBit
.replace("'", "");
1867 return parseInt(lastBitClean
);
1870 function uint8ArrayToHex(a
) {
1872 for (var i
=0; i
<a
.length
; i
++) {
1873 var h
= a
[i
].toString(16);
1874 while (h
.length
< 2) {
1882 function showWordIndexes() {
1883 var phrase
= DOM
.phrase
.val();
1884 var words
= phraseToWordArray(phrase
);
1885 var wordIndexes
= [];
1886 var language
= getLanguage();
1887 for (var i
=0; i
<words
.length
; i
++) {
1888 var word
= words
[i
];
1889 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1890 wordIndexes
.push(wordIndex
);
1892 var wordIndexesStr
= wordIndexes
.join(", ");
1893 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1896 function showChecksum() {
1897 var phrase
= DOM
.phrase
.val();
1898 var words
= phraseToWordArray(phrase
);
1899 var checksumBitlength
= words
.length
/ 3;
1902 var language
= getLanguage();
1903 for (var i
=words
.length
-1; i
>=0; i
--) {
1904 var word
= words
[i
];
1905 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1906 var wordBinary
= wordIndex
.toString(2);
1907 while (wordBinary
.length
< 11) {
1908 wordBinary
= "0" + wordBinary
;
1910 var binaryStr
= wordBinary
+ binaryStr
;
1911 if (binaryStr
.length
>= checksumBitlength
) {
1912 var start
= binaryStr
.length
- checksumBitlength
;
1913 var end
= binaryStr
.length
;
1914 checksum
= binaryStr
.substring(start
, end
);
1915 // add spaces so the last group is 11 bits, not the first
1916 checksum
= checksum
.split("").reverse().join("")
1917 checksum
= addSpacesEveryElevenBits(checksum
);
1918 checksum
= checksum
.split("").reverse().join("")
1922 DOM
.entropyChecksum
.text(checksum
);
1925 function updateCsv() {
1926 var tableCsv
= "path,address,public key,private key\n";
1927 var rows
= DOM
.addresses
.find("tr");
1928 for (var i
=0; i
<rows
.length
; i
++) {
1929 var row
= $(rows
[i
]);
1930 var cells
= row
.find("td");
1931 for (var j
=0; j
<cells
.length
; j
++) {
1932 var cell
= $(cells
[j
]);
1933 if (!cell
.children().hasClass("invisible")) {
1934 tableCsv
= tableCsv
+ cell
.text();
1936 if (j
!= cells
.length
- 1) {
1937 tableCsv
= tableCsv
+ ",";
1940 tableCsv
= tableCsv
+ "\n";
1942 DOM
.csv
.val(tableCsv
);
1945 function addSpacesEveryElevenBits(binaryStr
) {
1946 return binaryStr
.match(/.{1,11}/g).join(" ");
1951 name: "AC - Asiacoin",
1952 onSelect: function() {
1953 network
= bitcoinjs
.bitcoin
.networks
.asiacoin
;
1958 name: "ACC - Adcoin",
1959 onSelect: function() {
1960 network
= bitcoinjs
.bitcoin
.networks
.adcoin
;
1965 name: "ARYA - Aryacoin",
1966 onSelect: function() {
1967 network
= bitcoinjs
.bitcoin
.networks
.aryacoin
;
1972 name: "AUR - Auroracoin",
1973 onSelect: function() {
1974 network
= bitcoinjs
.bitcoin
.networks
.auroracoin
;
1980 onSelect: function() {
1981 network
= bitcoinjs
.bitcoin
.networks
.axe
;
1986 name: "ANON - ANON",
1987 onSelect: function() {
1988 network
= bitcoinjs
.bitcoin
.networks
.anon
;
1993 name: "BOLI - Bolivarcoin",
1994 onSelect: function() {
1995 network
= bitcoinjs
.bitcoin
.networks
.bolivarcoin
;
2000 name: "BCA - Bitcoin Atom",
2001 onSelect: function() {
2002 network
= bitcoinjs
.bitcoin
.networks
.atom
;
2007 name: "BCH - Bitcoin Cash",
2008 onSelect: function() {
2009 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2014 name: "BEET - Beetlecoin",
2015 onSelect: function() {
2016 network
= bitcoinjs
.bitcoin
.networks
.beetlecoin
;
2021 name: "BELA - Belacoin",
2022 onSelect: function() {
2023 network
= bitcoinjs
.bitcoin
.networks
.belacoin
;
2028 name: "BLK - BlackCoin",
2029 onSelect: function() {
2030 network
= bitcoinjs
.bitcoin
.networks
.blackcoin
;
2035 name: "BND - Blocknode",
2036 onSelect: function() {
2037 network
= bitcoinjs
.bitcoin
.networks
.blocknode
;
2042 name: "tBND - Blocknode Testnet",
2043 onSelect: function() {
2044 network
= bitcoinjs
.bitcoin
.networks
.blocknode_testnet
;
2049 name: "BRIT - Britcoin",
2050 onSelect: function() {
2051 network
= bitcoinjs
.bitcoin
.networks
.britcoin
;
2056 name: "BSD - Bitsend",
2057 onSelect: function() {
2058 network
= bitcoinjs
.bitcoin
.networks
.bitsend
;
2063 name: "BST - BlockStamp",
2064 onSelect: function() {
2065 network
= bitcoinjs
.bitcoin
.networks
.blockstamp
;
2071 onSelect: function() {
2072 network
= bitcoinjs
.bitcoin
.networks
.bata
;
2077 name: "BTC - Bitcoin",
2078 onSelect: function() {
2079 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2084 name: "BTC - Bitcoin Testnet",
2085 onSelect: function() {
2086 network
= bitcoinjs
.bitcoin
.networks
.testnet
;
2091 name: "BITG - Bitcoin Green",
2092 onSelect: function() {
2093 network
= bitcoinjs
.bitcoin
.networks
.bitcoingreen
;
2098 name: "BTCP - Bitcoin Private",
2099 onSelect: function() {
2100 network
= bitcoinjs
.bitcoin
.networks
.bitcoinprivate
;
2105 name: "BSV - BitcoinSV",
2106 onSelect: function() {
2107 network
= bitcoinjs
.bitcoin
.networks
.bitcoinsv
;
2112 name: "BTCZ - Bitcoinz",
2113 onSelect: function() {
2114 network
= bitcoinjs
.bitcoin
.networks
.bitcoinz
;
2119 name: "BTDX - BitCloud",
2120 onSelect: function() {
2121 network
= bitcoinjs
.bitcoin
.networks
.bitcloud
;
2126 name: "BTG - Bitcoin Gold",
2127 onSelect: function() {
2128 network
= bitcoinjs
.bitcoin
.networks
.bgold
;
2133 name: "BTX - Bitcore",
2134 onSelect: function() {
2135 network
= bitcoinjs
.bitcoin
.networks
.bitcore
;
2140 name: "CCN - Cannacoin",
2141 onSelect: function() {
2142 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2147 name: "CESC - Cryptoescudo",
2148 onSelect: function() {
2149 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2154 name: "CDN - Canadaecoin",
2155 onSelect: function() {
2156 network
= bitcoinjs
.bitcoin
.networks
.canadaecoin
;
2161 name: "CLAM - Clams",
2162 onSelect: function() {
2163 network
= bitcoinjs
.bitcoin
.networks
.clam
;
2168 name: "CLO - Callisto",
2169 segwitAvailable: false,
2170 onSelect: function() {
2171 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2176 name: "CLUB - Clubcoin",
2177 onSelect: function() {
2178 network
= bitcoinjs
.bitcoin
.networks
.clubcoin
;
2183 name: "CMP - Compcoin",
2184 onSelect: function() {
2185 network
= bitcoinjs
.bitcoin
.networks
.compcoin
;
2190 name: "CPU - CPUchain",
2191 onSelect: function() {
2192 network
= bitcoinjs
.bitcoin
.networks
.cpuchain
;
2197 name: "CRAVE - Crave",
2198 onSelect: function() {
2199 network
= bitcoinjs
.bitcoin
.networks
.crave
;
2204 name: "CRW - Crown (Legacy)",
2205 onSelect: function() {
2206 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2211 name: "CRW - Crown",
2212 onSelect: function() {
2213 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2218 name: "CSC - CasinoCoin",
2219 onSelect: function() {
2220 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2225 name: "DASH - Dash",
2226 onSelect: function() {
2227 network
= bitcoinjs
.bitcoin
.networks
.dash
;
2232 name: "DASH - Dash Testnet",
2233 onSelect: function() {
2234 network
= bitcoinjs
.bitcoin
.networks
.dashtn
;
2239 name: "DFC - Defcoin",
2240 onSelect: function() {
2241 network
= bitcoinjs
.bitcoin
.networks
.defcoin
;
2246 name: "DGB - Digibyte",
2247 onSelect: function() {
2248 network
= bitcoinjs
.bitcoin
.networks
.digibyte
;
2253 name: "DGC - Digitalcoin",
2254 onSelect: function() {
2255 network
= bitcoinjs
.bitcoin
.networks
.digitalcoin
;
2260 name: "DMD - Diamond",
2261 onSelect: function() {
2262 network
= bitcoinjs
.bitcoin
.networks
.diamond
;
2267 name: "DNR - Denarius",
2268 onSelect: function() {
2269 network
= bitcoinjs
.bitcoin
.networks
.denarius
;
2274 name: "DOGE - Dogecoin",
2275 onSelect: function() {
2276 network
= bitcoinjs
.bitcoin
.networks
.dogecoin
;
2281 name: "DOGEt - Dogecoin Testnet",
2282 onSelect: function() {
2283 network
= bitcoinjs
.bitcoin
.networks
.dogecointestnet
;
2288 name: "DXN - DEXON",
2289 onSelect: function() {
2290 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2295 name: "ECN - Ecoin",
2296 onSelect: function() {
2297 network
= bitcoinjs
.bitcoin
.networks
.ecoin
;
2302 name: "EDRC - Edrcoin",
2303 onSelect: function() {
2304 network
= bitcoinjs
.bitcoin
.networks
.edrcoin
;
2309 name: "EFL - Egulden",
2310 onSelect: function() {
2311 network
= bitcoinjs
.bitcoin
.networks
.egulden
;
2316 name: "ELA - Elastos",
2317 onSelect: function () {
2318 network
= bitcoinjs
.bitcoin
.networks
.elastos
;
2323 name: "ELLA - Ellaism",
2324 segwitAvailable: false,
2325 onSelect: function() {
2326 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2331 name: "EMC2 - Einsteinium",
2332 onSelect: function() {
2333 network
= bitcoinjs
.bitcoin
.networks
.einsteinium
;
2338 name: "ERC - Europecoin",
2339 onSelect: function() {
2340 network
= bitcoinjs
.bitcoin
.networks
.europecoin
;
2345 name: "EOS - EOSIO",
2346 onSelect: function() {
2347 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2352 name: "ESN - Ethersocial Network",
2353 segwitAvailable: false,
2354 onSelect: function() {
2355 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2360 name: "ETC - Ethereum Classic",
2361 segwitAvailable: false,
2362 onSelect: function() {
2363 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2368 name: "ETH - Ethereum",
2369 onSelect: function() {
2370 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2375 name: "EWT - EnergyWeb",
2376 onSelect: function() {
2377 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2382 name: "EXCL - Exclusivecoin",
2383 onSelect: function() {
2384 network
= bitcoinjs
.bitcoin
.networks
.exclusivecoin
;
2389 name: "EXCC - ExchangeCoin",
2390 onSelect: function() {
2391 network
= bitcoinjs
.bitcoin
.networks
.exchangecoin
;
2396 name: "EXP - Expanse",
2397 segwitAvailable: false,
2398 onSelect: function() {
2399 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2405 onSelect: function() {
2406 network
= bitcoinjs
.bitcoin
.networks
.fix
;
2411 name: "FIX - FIX Testnet",
2412 onSelect: function() {
2413 network
= bitcoinjs
.bitcoin
.networks
.fixtestnet
;
2418 name: "FJC - Fujicoin",
2419 onSelect: function() {
2420 network
= bitcoinjs
.bitcoin
.networks
.fujicoin
;
2425 name: "FLASH - Flashcoin",
2426 onSelect: function() {
2427 network
= bitcoinjs
.bitcoin
.networks
.flashcoin
;
2432 name: "FRST - Firstcoin",
2433 onSelect: function() {
2434 network
= bitcoinjs
.bitcoin
.networks
.firstcoin
;
2439 name: "FTC - Feathercoin",
2440 onSelect: function() {
2441 network
= bitcoinjs
.bitcoin
.networks
.feathercoin
;
2446 name: "GAME - GameCredits",
2447 onSelect: function() {
2448 network
= bitcoinjs
.bitcoin
.networks
.game
;
2453 name: "GBX - Gobyte",
2454 onSelect: function() {
2455 network
= bitcoinjs
.bitcoin
.networks
.gobyte
;
2460 name: "GCR - GCRCoin",
2461 onSelect: function() {
2462 network
= bitcoinjs
.bitcoin
.networks
.gcr
;
2467 name: "GRC - Gridcoin",
2468 onSelect: function() {
2469 network
= bitcoinjs
.bitcoin
.networks
.gridcoin
;
2474 name: "GRS - Groestlcoin",
2475 onSelect: function() {
2476 network
= bitcoinjs
.bitcoin
.networks
.groestlcoin
;
2481 name: "GRS - Groestlcoin Testnet",
2482 onSelect: function() {
2483 network
= bitcoinjs
.bitcoin
.networks
.groestlcointestnet
;
2488 name: "HNC - Helleniccoin",
2489 onSelect: function() {
2490 network
= bitcoinjs
.bitcoin
.networks
.helleniccoin
;
2495 name: "HUSH - Hush (Legacy)",
2496 onSelect: function() {
2497 network
= bitcoinjs
.bitcoin
.networks
.hush
;
2502 name: "HUSH - Hush3",
2503 onSelect: function() {
2504 network
= bitcoinjs
.bitcoin
.networks
.hush3
;
2509 name: "INSN - Insane",
2510 onSelect: function() {
2511 network
= bitcoinjs
.bitcoin
.networks
.insane
;
2517 onSelect: function() {
2518 network
= bitcoinjs
.bitcoin
.networks
.iop
;
2523 name: "IXC - Ixcoin",
2524 onSelect: function() {
2525 network
= bitcoinjs
.bitcoin
.networks
.ixcoin
;
2530 name: "JBS - Jumbucks",
2531 onSelect: function() {
2532 network
= bitcoinjs
.bitcoin
.networks
.jumbucks
;
2537 name: "KMD - Komodo",
2538 bip49available: false,
2539 onSelect: function() {
2540 network
= bitcoinjs
.bitcoin
.networks
.komodo
;
2545 name: "KOBO - Kobocoin",
2546 bip49available: false,
2547 onSelect: function() {
2548 network
= bitcoinjs
.bitcoin
.networks
.kobocoin
;
2553 name: "LBC - Library Credits",
2554 onSelect: function() {
2555 network
= bitcoinjs
.bitcoin
.networks
.lbry
;
2560 name: "LCC - Litecoincash",
2561 onSelect: function() {
2562 network
= bitcoinjs
.bitcoin
.networks
.litecoincash
;
2567 name: "LDCN - Landcoin",
2568 onSelect: function() {
2569 network
= bitcoinjs
.bitcoin
.networks
.landcoin
;
2574 name: "LINX - Linx",
2575 onSelect: function() {
2576 network
= bitcoinjs
.bitcoin
.networks
.linx
;
2581 name: "LKR - Lkrcoin",
2582 segwitAvailable: false,
2583 onSelect: function() {
2584 network
= bitcoinjs
.bitcoin
.networks
.lkrcoin
;
2589 name: "LTC - Litecoin",
2590 onSelect: function() {
2591 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
2593 DOM
.litecoinLtubContainer
.removeClass("hidden");
2597 name: "LTCt - Litecoin Testnet",
2598 onSelect: function() {
2599 network
= bitcoinjs
.bitcoin
.networks
.litecointestnet
;
2601 DOM
.litecoinLtubContainer
.removeClass("hidden");
2605 name: "LTZ - LitecoinZ",
2606 onSelect: function() {
2607 network
= bitcoinjs
.bitcoin
.networks
.litecoinz
;
2612 name: "LYNX - Lynx",
2613 onSelect: function() {
2614 network
= bitcoinjs
.bitcoin
.networks
.lynx
;
2619 name: "MAZA - Maza",
2620 onSelect: function() {
2621 network
= bitcoinjs
.bitcoin
.networks
.maza
;
2626 name: "MEC - Megacoin",
2627 onSelect: function() {
2628 network
= bitcoinjs
.bitcoin
.networks
.megacoin
;
2634 segwitAvailable: false,
2635 onSelect: function() {
2636 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2641 name: "MNX - Minexcoin",
2642 onSelect: function() {
2643 network
= bitcoinjs
.bitcoin
.networks
.minexcoin
;
2648 name: "MONA - Monacoin",
2649 onSelect: function() {
2650 network
= bitcoinjs
.bitcoin
.networks
.monacoin
,
2655 name: "MONK - Monkey Project",
2656 onSelect: function() {
2657 network
= bitcoinjs
.bitcoin
.networks
.monkeyproject
,
2662 name: "MUSIC - Musicoin",
2663 segwitAvailable: false,
2664 onSelect: function() {
2665 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2670 name: "NAV - Navcoin",
2671 onSelect: function() {
2672 network
= bitcoinjs
.bitcoin
.networks
.navcoin
;
2677 name: "NAS - Nebulas",
2678 onSelect: function() {
2679 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2684 name: "NEBL - Neblio",
2685 onSelect: function() {
2686 network
= bitcoinjs
.bitcoin
.networks
.neblio
;
2691 name: "NEOS - Neoscoin",
2692 onSelect: function() {
2693 network
= bitcoinjs
.bitcoin
.networks
.neoscoin
;
2698 name: "NIX - NIX Platform",
2699 onSelect: function() {
2700 network
= bitcoinjs
.bitcoin
.networks
.nix
;
2705 name: "NLG - Gulden",
2706 onSelect: function() {
2707 network
= bitcoinjs
.bitcoin
.networks
.gulden
;
2712 name: "NMC - Namecoin",
2713 onSelect: function() {
2714 network
= bitcoinjs
.bitcoin
.networks
.namecoin
;
2719 name: "NRG - Energi",
2720 onSelect: function() {
2721 network
= bitcoinjs
.bitcoin
.networks
.energi
;
2726 name: "NRO - Neurocoin",
2727 onSelect: function() {
2728 network
= bitcoinjs
.bitcoin
.networks
.neurocoin
;
2733 name: "NSR - Nushares",
2734 onSelect: function() {
2735 network
= bitcoinjs
.bitcoin
.networks
.nushares
;
2740 name: "NYC - Newyorkc",
2741 onSelect: function() {
2742 network
= bitcoinjs
.bitcoin
.networks
.newyorkc
;
2747 name: "NVC - Novacoin",
2748 onSelect: function() {
2749 network
= bitcoinjs
.bitcoin
.networks
.novacoin
;
2754 name: "OK - Okcash",
2755 onSelect: function() {
2756 network
= bitcoinjs
.bitcoin
.networks
.okcash
;
2761 name: "OMNI - Omnicore",
2762 onSelect: function() {
2763 network
= bitcoinjs
.bitcoin
.networks
.omnicore
;
2768 name: "ONION - DeepOnion",
2769 onSelect: function() {
2770 network
= bitcoinjs
.bitcoin
.networks
.deeponion
;
2775 name: "ONX - Onixcoin",
2776 onSelect: function() {
2777 network
= bitcoinjs
.bitcoin
.networks
.onixcoin
;
2782 name: "PHR - Phore",
2783 onSelect: function() {
2784 network
= bitcoinjs
.bitcoin
.networks
.phore
;
2789 name: "PINK - Pinkcoin",
2790 onSelect: function() {
2791 network
= bitcoinjs
.bitcoin
.networks
.pinkcoin
;
2796 name: "PIRL - Pirl",
2797 segwitAvailable: false,
2798 onSelect: function() {
2799 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2804 name: "PIVX - PIVX",
2805 onSelect: function() {
2806 network
= bitcoinjs
.bitcoin
.networks
.pivx
;
2811 name: "PIVX - PIVX Testnet",
2812 onSelect: function() {
2813 network
= bitcoinjs
.bitcoin
.networks
.pivxtestnet
;
2819 segwitAvailable: false,
2820 onSelect: function() {
2821 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2826 name: "POSW - POSWcoin",
2827 onSelect: function() {
2828 network
= bitcoinjs
.bitcoin
.networks
.poswcoin
;
2833 name: "POT - Potcoin",
2834 onSelect: function() {
2835 network
= bitcoinjs
.bitcoin
.networks
.potcoin
;
2840 name: "PPC - Peercoin",
2841 onSelect: function() {
2842 network
= bitcoinjs
.bitcoin
.networks
.peercoin
;
2847 name: "PRJ - ProjectCoin",
2848 onSelect: function() {
2849 network
= bitcoinjs
.bitcoin
.networks
.projectcoin
;
2854 name: "PSB - Pesobit",
2855 onSelect: function() {
2856 network
= bitcoinjs
.bitcoin
.networks
.pesobit
;
2861 name: "PUT - Putincoin",
2862 onSelect: function() {
2863 network
= bitcoinjs
.bitcoin
.networks
.putincoin
;
2868 name: "RPD - Rapids",
2869 onSelect: function() {
2870 network
= bitcoinjs
.bitcoin
.networks
.rapids
;
2875 name: "RVN - Ravencoin",
2876 onSelect: function() {
2877 network
= bitcoinjs
.bitcoin
.networks
.ravencoin
;
2882 name: "RBY - Rubycoin",
2883 onSelect: function() {
2884 network
= bitcoinjs
.bitcoin
.networks
.rubycoin
;
2889 name: "RDD - Reddcoin",
2890 onSelect: function() {
2891 network
= bitcoinjs
.bitcoin
.networks
.reddcoin
;
2896 name: "RVR - RevolutionVR",
2897 onSelect: function() {
2898 network
= bitcoinjs
.bitcoin
.networks
.revolutionvr
;
2903 name: "SAFE - Safecoin",
2904 onSelect: function() {
2905 network
= bitcoinjs
.bitcoin
.networks
.safecoin
;
2910 name: "SLS - Salus",
2911 onSelect: function() {
2912 network
= bitcoinjs
.bitcoin
.networks
.salus
;
2917 name: "SDC - ShadowCash",
2918 onSelect: function() {
2919 network
= bitcoinjs
.bitcoin
.networks
.shadow
;
2924 name: "SDC - ShadowCash Testnet",
2925 onSelect: function() {
2926 network
= bitcoinjs
.bitcoin
.networks
.shadowtn
;
2931 name: "SLM - Slimcoin",
2932 onSelect: function() {
2933 network
= bitcoinjs
.bitcoin
.networks
.slimcoin
;
2938 name: "SLM - Slimcoin Testnet",
2939 onSelect: function() {
2940 network
= bitcoinjs
.bitcoin
.networks
.slimcointn
;
2945 name: "SLP - Simple Ledger Protocol",
2946 onSelect: function() {
2947 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2952 name: "SLR - Solarcoin",
2953 onSelect: function() {
2954 network
= bitcoinjs
.bitcoin
.networks
.solarcoin
;
2959 name: "SMLY - Smileycoin",
2960 onSelect: function() {
2961 network
= bitcoinjs
.bitcoin
.networks
.smileycoin
;
2966 name: "STASH - Stash",
2967 onSelect: function() {
2968 network
= bitcoinjs
.bitcoin
.networks
.stash
;
2973 name: "STASH - Stash Testnet",
2974 onSelect: function() {
2975 network
= bitcoinjs
.bitcoin
.networks
.stashtn
;
2980 name: "STRAT - Stratis",
2981 onSelect: function() {
2982 network
= bitcoinjs
.bitcoin
.networks
.stratis
;
2987 name: "TSTRAT - Stratis Testnet",
2988 onSelect: function() {
2989 network
= bitcoinjs
.bitcoin
.networks
.stratistest
;
2994 name: "SYS - Syscoin",
2995 onSelect: function() {
2996 network
= bitcoinjs
.bitcoin
.networks
.syscoin
;
3001 name: "THC - Hempcoin",
3002 onSelect: function() {
3003 network
= bitcoinjs
.bitcoin
.networks
.hempcoin
;
3008 name: "THT - Thought",
3009 onSelect: function() {
3010 network
= bitcoinjs
.bitcoin
.networks
.thought
;
3016 onSelect: function() {
3017 network
= bitcoinjs
.bitcoin
.networks
.toa
;
3022 name: "TWINS - TWINS",
3023 onSelect: function() {
3024 network
= bitcoinjs
.bitcoin
.networks
.twins
;
3029 name: "TWINS - TWINS Testnet",
3030 onSelect: function() {
3031 network
= bitcoinjs
.bitcoin
.networks
.twinstestnet
;
3036 name: "USC - Ultimatesecurecash",
3037 onSelect: function() {
3038 network
= bitcoinjs
.bitcoin
.networks
.ultimatesecurecash
;
3043 name: "USNBT - NuBits",
3044 onSelect: function() {
3045 network
= bitcoinjs
.bitcoin
.networks
.nubits
;
3050 name: "UNO - Unobtanium",
3051 onSelect: function() {
3052 network
= bitcoinjs
.bitcoin
.networks
.unobtanium
;
3057 name: "VASH - Vpncoin",
3058 onSelect: function() {
3059 network
= bitcoinjs
.bitcoin
.networks
.vpncoin
;
3064 name: "VET - VeChain",
3065 onSelect: function() {
3066 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3071 name: "VIA - Viacoin",
3072 onSelect: function() {
3073 network
= bitcoinjs
.bitcoin
.networks
.viacoin
;
3078 name: "VIA - Viacoin Testnet",
3079 onSelect: function() {
3080 network
= bitcoinjs
.bitcoin
.networks
.viacointestnet
;
3085 name: "VIVO - Vivo",
3086 onSelect: function() {
3087 network
= bitcoinjs
.bitcoin
.networks
.vivo
;
3092 name: "VTC - Vertcoin",
3093 onSelect: function() {
3094 network
= bitcoinjs
.bitcoin
.networks
.vertcoin
;
3099 name: "WGR - Wagerr",
3100 onSelect: function() {
3101 network
= bitcoinjs
.bitcoin
.networks
.wagerr
;
3106 name: "WC - Wincoin",
3107 onSelect: function() {
3108 network
= bitcoinjs
.bitcoin
.networks
.wincoin
;
3113 name: "XAX - Artax",
3114 onSelect: function() {
3115 network
= bitcoinjs
.bitcoin
.networks
.artax
;
3120 name: "XBC - Bitcoinplus",
3121 onSelect: function() {
3122 network
= bitcoinjs
.bitcoin
.networks
.bitcoinplus
;
3127 name: "XLM - Stellar",
3128 onSelect: function() {
3129 network
= stellarUtil
.dummyNetwork
;
3134 name: "XMY - Myriadcoin",
3135 onSelect: function() {
3136 network
= bitcoinjs
.bitcoin
.networks
.myriadcoin
;
3141 name: "XRP - Ripple",
3142 onSelect: function() {
3143 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3148 name: "XVC - Vcash",
3149 onSelect: function() {
3150 network
= bitcoinjs
.bitcoin
.networks
.vcash
;
3155 name: "XVG - Verge",
3156 onSelect: function() {
3157 network
= bitcoinjs
.bitcoin
.networks
.verge
;
3162 name: "XUEZ - Xuez",
3163 segwitAvailable: false,
3164 onSelect: function() {
3165 network
= bitcoinjs
.bitcoin
.networks
.xuez
;
3170 name: "XWC - Whitecoin",
3171 onSelect: function() {
3172 network
= bitcoinjs
.bitcoin
.networks
.whitecoin
;
3177 name: "XZC - Zcoin",
3178 onSelect: function() {
3179 network
= bitcoinjs
.bitcoin
.networks
.zcoin
;
3184 name: "ZCL - Zclassic",
3185 onSelect: function() {
3186 network
= bitcoinjs
.bitcoin
.networks
.zclassic
;
3191 name: "ZEC - Zcash",
3192 onSelect: function() {
3193 network
= bitcoinjs
.bitcoin
.networks
.zcash
;
3198 name: "ZEN - Horizen",
3199 onSelect: function() {
3200 network
= bitcoinjs
.bitcoin
.networks
.zencash
;
3208 name: "Bitcoin Core",
3209 onSelect: function() {
3210 DOM
.bip32path
.val("m/0'/0'");
3211 DOM
.hardenedAddresses
.prop('checked', true);
3215 name: "blockchain.info",
3216 onSelect: function() {
3217 DOM
.bip32path
.val("m/44'/0'/0'");
3218 DOM
.hardenedAddresses
.prop('checked', false);
3222 name: "MultiBit HD",
3223 onSelect: function() {
3224 DOM
.bip32path
.val("m/0'/0");
3225 DOM
.hardenedAddresses
.prop('checked', false);
3229 name: "Coinomi, Ledger",
3230 onSelect: function() {
3231 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3232 DOM
.hardenedAddresses
.prop('checked', false);
3237 // ELA - Elastos functions - begin
3238 function displayBip44InfoForELA() {
3243 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3244 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3246 // Calculate the account extended keys
3247 var accountXprv
= elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3248 var accountXpub
= elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3250 // Display the extended keys
3251 DOM
.bip44accountXprv
.val(accountXprv
);
3252 DOM
.bip44accountXpub
.val(accountXpub
);
3255 function displayBip32InfoForELA() {
3260 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3261 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3262 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3264 DOM
.extendedPrivKey
.val(elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3265 DOM
.extendedPubKey
.val(elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3267 // Display the addresses and privkeys
3268 clearAddressesList();
3269 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3270 displayAddresses(0, initialAddressCount
);
3273 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3278 var publicKey
= elastosjs
.getDerivedPublicKey(elastosjs
.getMasterPublicKey(seed
), change
, index
);
3280 privateKey: elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3281 publicKey: publicKey
,
3282 address: elastosjs
.getAddress(publicKey
.toString('hex'))
3285 // ELA - Elastos functions - end