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
.passphrase
= $(".passphrase");
48 DOM
.generateContainer
= $(".generate-container");
49 DOM
.generate
= $(".generate");
50 DOM
.seed
= $(".seed");
51 DOM
.rootKey
= $(".root-key");
52 DOM
.litecoinLtubContainer
= $(".litecoin-ltub-container");
53 DOM
.litecoinUseLtub
= $(".litecoin-use-ltub");
54 DOM
.extendedPrivKey
= $(".extended-priv-key");
55 DOM
.extendedPubKey
= $(".extended-pub-key");
56 DOM
.bip32tab
= $("#bip32-tab");
57 DOM
.bip44tab
= $("#bip44-tab");
58 DOM
.bip49tab
= $("#bip49-tab");
59 DOM
.bip84tab
= $("#bip84-tab");
60 DOM
.bip141tab
= $("#bip141-tab");
61 DOM
.bip32panel
= $("#bip32");
62 DOM
.bip44panel
= $("#bip44");
63 DOM
.bip49panel
= $("#bip49");
64 DOM
.bip32path
= $("#bip32-path");
65 DOM
.bip44path
= $("#bip44-path");
66 DOM
.bip44purpose
= $("#bip44 .purpose");
67 DOM
.bip44coin
= $("#bip44 .coin");
68 DOM
.bip44account
= $("#bip44 .account");
69 DOM
.bip44accountXprv
= $("#bip44 .account-xprv");
70 DOM
.bip44accountXpub
= $("#bip44 .account-xpub");
71 DOM
.bip44change
= $("#bip44 .change");
72 DOM
.bip49unavailable
= $("#bip49 .unavailable");
73 DOM
.bip49available
= $("#bip49 .available");
74 DOM
.bip49path
= $("#bip49-path");
75 DOM
.bip49purpose
= $("#bip49 .purpose");
76 DOM
.bip49coin
= $("#bip49 .coin");
77 DOM
.bip49account
= $("#bip49 .account");
78 DOM
.bip49accountXprv
= $("#bip49 .account-xprv");
79 DOM
.bip49accountXpub
= $("#bip49 .account-xpub");
80 DOM
.bip49change
= $("#bip49 .change");
81 DOM
.bip84unavailable
= $("#bip84 .unavailable");
82 DOM
.bip84available
= $("#bip84 .available");
83 DOM
.bip84path
= $("#bip84-path");
84 DOM
.bip84purpose
= $("#bip84 .purpose");
85 DOM
.bip84coin
= $("#bip84 .coin");
86 DOM
.bip84account
= $("#bip84 .account");
87 DOM
.bip84accountXprv
= $("#bip84 .account-xprv");
88 DOM
.bip84accountXpub
= $("#bip84 .account-xpub");
89 DOM
.bip84change
= $("#bip84 .change");
90 DOM
.bip141unavailable
= $("#bip141 .unavailable");
91 DOM
.bip141available
= $("#bip141 .available");
92 DOM
.bip141path
= $("#bip141-path");
93 DOM
.bip141semantics
= $(".bip141-semantics");
94 DOM
.generatedStrength
= $(".generate-container .strength");
95 DOM
.generatedStrengthWarning
= $(".generate-container .warning");
96 DOM
.hardenedAddresses
= $(".hardened-addresses");
97 DOM
.bitcoinCashAddressTypeContainer
= $(".bch-addr-type-container");
98 DOM
.bitcoinCashAddressType
= $("[name=bch-addr-type]")
99 DOM
.useBip38
= $(".use-bip38");
100 DOM
.bip38Password
= $(".bip38-password");
101 DOM
.addresses
= $(".addresses");
102 DOM
.csvTab
= $("#csv-tab a");
104 DOM
.rowsToAdd
= $(".rows-to-add");
105 DOM
.more
= $(".more");
106 DOM
.moreRowsStartIndex
= $(".more-rows-start-index");
107 DOM
.feedback
= $(".feedback");
108 DOM
.tab
= $(".derivation-type a");
109 DOM
.indexToggle
= $(".index-toggle");
110 DOM
.addressToggle
= $(".address-toggle");
111 DOM
.publicKeyToggle
= $(".public-key-toggle");
112 DOM
.privateKeyToggle
= $(".private-key-toggle");
113 DOM
.languages
= $(".languages a");
114 DOM
.qrContainer
= $(".qr-container");
115 DOM
.qrHider
= DOM
.qrContainer
.find(".qr-hider");
116 DOM
.qrImage
= DOM
.qrContainer
.find(".qr-image");
117 DOM
.qrHint
= DOM
.qrContainer
.find(".qr-hint");
118 DOM
.showQrEls
= $("[data-show-qr]");
122 DOM
.privacyScreenToggle
.on("change", privacyScreenToggled
);
123 DOM
.generatedStrength
.on("change", generatedStrengthChanged
);
124 DOM
.network
.on("change", networkChanged
);
125 DOM
.bip32Client
.on("change", bip32ClientChanged
);
126 DOM
.useEntropy
.on("change", setEntropyVisibility
);
127 DOM
.entropy
.on("input", delayedEntropyChanged
);
128 DOM
.entropyMnemonicLength
.on("change", entropyChanged
);
129 DOM
.phrase
.on("input", delayedPhraseChanged
);
130 DOM
.passphrase
.on("input", delayedPhraseChanged
);
131 DOM
.generate
.on("click", generateClicked
);
132 DOM
.more
.on("click", showMore
);
133 DOM
.rootKey
.on("input", delayedRootKeyChanged
);
134 DOM
.litecoinUseLtub
.on("change", litecoinUseLtubChanged
);
135 DOM
.bip32path
.on("input", calcForDerivationPath
);
136 DOM
.bip44account
.on("input", calcForDerivationPath
);
137 DOM
.bip44change
.on("input", calcForDerivationPath
);
138 DOM
.bip49account
.on("input", calcForDerivationPath
);
139 DOM
.bip49change
.on("input", calcForDerivationPath
);
140 DOM
.bip84account
.on("input", calcForDerivationPath
);
141 DOM
.bip84change
.on("input", calcForDerivationPath
);
142 DOM
.bip141path
.on("input", calcForDerivationPath
);
143 DOM
.bip141semantics
.on("change", tabChanged
);
144 DOM
.tab
.on("shown.bs.tab", tabChanged
);
145 DOM
.hardenedAddresses
.on("change", calcForDerivationPath
);
146 DOM
.useBip38
.on("change", calcForDerivationPath
);
147 DOM
.bip38Password
.on("change", calcForDerivationPath
);
148 DOM
.indexToggle
.on("click", toggleIndexes
);
149 DOM
.addressToggle
.on("click", toggleAddresses
);
150 DOM
.publicKeyToggle
.on("click", togglePublicKeys
);
151 DOM
.privateKeyToggle
.on("click", togglePrivateKeys
);
152 DOM
.csvTab
.on("click", updateCsv
);
153 DOM
.languages
.on("click", languageChanged
);
154 DOM
.bitcoinCashAddressType
.on("change", bitcoinCashAddressTypeChange
);
155 setQrEvents(DOM
.showQrEls
);
158 hideValidationError();
159 populateNetworkSelect();
160 populateClientSelect();
165 function generatedStrengthChanged() {
166 var strength
= parseInt(DOM
.generatedStrength
.val());
168 DOM
.generatedStrengthWarning
.removeClass("hidden");
171 DOM
.generatedStrengthWarning
.addClass("hidden");
175 function networkChanged(e
) {
177 clearAddressesList();
178 DOM
.litecoinLtubContainer
.addClass("hidden");
179 DOM
.bitcoinCashAddressTypeContainer
.addClass("hidden");
180 var networkIndex
= e
.target
.value
;
181 var network
= networks
[networkIndex
];
183 adjustNetworkForSegwit();
192 function bip32ClientChanged(e
) {
193 var clientIndex
= DOM
.bip32Client
.val();
194 if (clientIndex
== "custom") {
195 DOM
.bip32path
.prop("readonly", false);
198 DOM
.bip32path
.prop("readonly", true);
199 clients
[clientIndex
].onSelect();
209 function setEntropyVisibility() {
210 if (isUsingOwnEntropy()) {
211 DOM
.entropyContainer
.removeClass("hidden");
212 DOM
.generateContainer
.addClass("hidden");
213 DOM
.phrase
.prop("readonly", true);
218 DOM
.entropyContainer
.addClass("hidden");
219 DOM
.generateContainer
.removeClass("hidden");
220 DOM
.phrase
.prop("readonly", false);
225 function delayedPhraseChanged() {
226 hideValidationError();
229 bip32ExtendedKey
= null;
230 clearAddressesList();
232 if (phraseChangeTimeoutEvent
!= null) {
233 clearTimeout(phraseChangeTimeoutEvent
);
235 phraseChangeTimeoutEvent
= setTimeout(phraseChanged
, 400);
238 function phraseChanged() {
240 setMnemonicLanguage();
241 // Get the mnemonic phrase
242 var phrase
= DOM
.phrase
.val();
243 var errorText
= findPhraseErrors(phrase
);
245 showValidationError(errorText
);
248 // Calculate and display
249 var passphrase
= DOM
.passphrase
.val();
250 calcBip32RootKeyFromSeed(phrase
, passphrase
);
251 calcForDerivationPath();
252 // Show the word indexes
256 function tabChanged() {
258 adjustNetworkForSegwit();
259 var phrase
= DOM
.phrase
.val();
261 // Calculate and display for mnemonic
262 var errorText
= findPhraseErrors(phrase
);
264 showValidationError(errorText
);
267 // Calculate and display
268 var passphrase
= DOM
.passphrase
.val();
269 calcBip32RootKeyFromSeed(phrase
, passphrase
);
272 // Calculate and display for root key
273 var rootKeyBase58
= DOM
.rootKey
.val();
274 var errorText
= validateRootKey(rootKeyBase58
);
276 showValidationError(errorText
);
279 // Calculate and display
280 calcBip32RootKeyFromBase58(rootKeyBase58
);
282 calcForDerivationPath();
285 function delayedEntropyChanged() {
286 hideValidationError();
288 if (entropyChangeTimeoutEvent
!= null) {
289 clearTimeout(entropyChangeTimeoutEvent
);
291 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
294 function entropyChanged() {
295 // If blank entropy, clear mnemonic, addresses, errors
296 if (DOM
.entropy
.val().trim().length
== 0) {
298 clearEntropyFeedback();
300 showValidationError("Blank entropy");
303 // Get the current phrase to detect changes
304 var phrase
= DOM
.phrase
.val();
305 // Set the phrase from the entropy
306 setMnemonicFromEntropy();
307 // Recalc addresses if the phrase has changed
308 var newPhrase
= DOM
.phrase
.val();
309 if (newPhrase
!= phrase
) {
310 if (newPhrase
.length
== 0) {
322 function delayedRootKeyChanged() {
323 // Warn if there is an existing mnemonic or passphrase.
324 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
325 if (!confirm("This will clear existing mnemonic and passphrase")) {
326 DOM
.rootKey
.val(bip32RootKey
);
330 hideValidationError();
332 // Clear existing mnemonic and passphrase
334 DOM
.passphrase
.val("");
336 if (rootKeyChangedTimeoutEvent
!= null) {
337 clearTimeout(rootKeyChangedTimeoutEvent
);
339 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
342 function rootKeyChanged() {
344 hideValidationError();
345 var rootKeyBase58
= DOM
.rootKey
.val();
346 var errorText
= validateRootKey(rootKeyBase58
);
348 showValidationError(errorText
);
351 // Calculate and display
352 calcBip32RootKeyFromBase58(rootKeyBase58
);
353 calcForDerivationPath();
356 function litecoinUseLtubChanged() {
357 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
358 if (litecoinUseLtub
) {
359 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
362 network
= bitcoinjs
.bitcoin
.networks
.litecoinXprv
;
367 function calcForDerivationPath() {
369 clearAddressesList();
371 // Don't show segwit if it's selected but network doesn't support it
372 if (segwitSelected() && !networkHasSegwit()) {
373 showSegwitUnavailable();
377 showSegwitAvailable();
378 // Get the derivation path
379 var derivationPath
= getDerivationPath();
380 var errorText
= findDerivationPathErrors(derivationPath
);
382 showValidationError(errorText
);
385 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
386 if (bip44TabSelected()) {
389 else if (bip49TabSelected()) {
392 else if (bip84TabSelected()) {
398 function generateClicked() {
399 if (isUsingOwnEntropy()) {
404 setTimeout(function() {
405 setMnemonicLanguage();
406 var phrase
= generateRandomPhrase();
414 function languageChanged() {
415 setTimeout(function() {
416 setMnemonicLanguage();
417 if (DOM
.phrase
.val().length
> 0) {
418 var newPhrase
= convertPhraseToNewLanguage();
419 DOM
.phrase
.val(newPhrase
);
423 DOM
.generate
.trigger("click");
428 function bitcoinCashAddressTypeChange() {
432 function toggleIndexes() {
433 showIndex
= !showIndex
;
434 $("td.index span").toggleClass("invisible");
437 function toggleAddresses() {
438 showAddress
= !showAddress
;
439 $("td.address span").toggleClass("invisible");
442 function togglePublicKeys() {
443 showPubKey
= !showPubKey
;
444 $("td.pubkey span").toggleClass("invisible");
447 function togglePrivateKeys() {
448 showPrivKey
= !showPrivKey
;
449 $("td.privkey span").toggleClass("invisible");
452 function privacyScreenToggled() {
453 // private-data contains elements added to DOM at runtime
454 // so catch all by adding visual privacy class to the root of the DOM
455 if (DOM
.privacyScreenToggle
.prop("checked")) {
456 $("body").addClass("visual-privacy");
459 $("body").removeClass("visual-privacy");
465 function generateRandomPhrase() {
466 if (!hasStrongRandom()) {
467 var errorText
= "This browser does not support strong randomness";
468 showValidationError(errorText
);
471 // get the amount of entropy to use
472 var numWords
= parseInt(DOM
.generatedStrength
.val());
473 var strength
= numWords
/ 3 * 32;
474 var buffer
= new Uint8Array(strength
/ 8);
475 // create secure entropy
476 var data
= crypto
.getRandomValues(buffer
);
478 var words
= mnemonic
.toMnemonic(data
);
479 DOM
.phrase
.val(words
);
481 var entropyHex
= uint8ArrayToHex(data
);
482 DOM
.entropy
.val(entropyHex
);
483 // ensure entropy fields are consistent with what is being displayed
484 DOM
.entropyMnemonicLength
.val("raw");
488 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
489 seed
= mnemonic
.toSeed(phrase
, passphrase
);
490 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
492 bip32RootKey
= groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
496 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
498 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
501 // try parsing with various segwit network params since this extended
502 // key may be from any one of them.
503 if (networkHasSegwit()) {
505 if ("baseNetwork" in n
) {
506 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
508 // try parsing using base network params
510 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
514 // try parsing using p2wpkh params
517 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
522 // try parsing using p2wpkh-in-p2sh network params
523 if ("p2wpkhInP2sh" in n
) {
525 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
531 // try the network params as currently specified
532 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
535 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
536 // try parsing with various segwit network params since this extended
537 // key may be from any one of them.
538 if (networkHasSegwit()) {
540 if ("baseNetwork" in n
) {
541 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
543 // try parsing using base network params
545 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
549 // try parsing using p2wpkh params
552 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
557 // try parsing using p2wpkh-in-p2sh network params
558 if ("p2wpkhInP2sh" in n
) {
560 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
566 // try the network params as currently specified
567 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
570 function calcBip32ExtendedKey(path
) {
571 // Check there's a root key to derive from
575 var extendedKey
= bip32RootKey
;
576 // Derive the key from the path
577 var pathBits
= path
.split("/");
578 for (var i
=0; i
<pathBits
.length
; i
++) {
579 var bit
= pathBits
[i
];
580 var index
= parseInt(bit
);
584 var hardened
= bit
[bit
.length
-1] == "'";
585 var isPriv
= !(extendedKey
.isNeutered());
586 var invalidDerivationPath
= hardened
&& !isPriv
;
587 if (invalidDerivationPath
) {
591 extendedKey
= extendedKey
.deriveHardened(index
);
594 extendedKey
= extendedKey
.derive(index
);
600 function showValidationError(errorText
) {
606 function hideValidationError() {
612 function findPhraseErrors(phrase
) {
613 // Preprocess the words
614 phrase
= mnemonic
.normalizeString(phrase
);
615 var words
= phraseToWordArray(phrase
);
616 // Detect blank phrase
617 if (words
.length
== 0) {
618 return "Blank mnemonic";
621 for (var i
=0; i
<words
.length
; i
++) {
623 var language
= getLanguage();
624 if (WORDLISTS
[language
].indexOf(word
) == -1) {
625 console
.log("Finding closest match to " + word
);
626 var nearestWord
= findNearestWord(word
);
627 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
630 // Check the words are valid
631 var properPhrase
= wordArrayToPhrase(words
);
632 var isValid
= mnemonic
.check(properPhrase
);
634 return "Invalid mnemonic";
639 function validateRootKey(rootKeyBase58
) {
641 return validateRootKeyGRS(rootKeyBase58
);
643 // try various segwit network params since this extended key may be from
645 if (networkHasSegwit()) {
647 if ("baseNetwork" in n
) {
648 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
650 // try parsing using base network params
652 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
656 // try parsing using p2wpkh params
659 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
664 // try parsing using p2wpkh-in-p2sh network params
665 if ("p2wpkhInP2sh" in n
) {
667 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
673 // try the network params as currently specified
675 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
678 return "Invalid root key";
683 function validateRootKeyGRS(rootKeyBase58
) {
684 // try various segwit network params since this extended key may be from
686 if (networkHasSegwit()) {
688 if ("baseNetwork" in n
) {
689 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
691 // try parsing using base network params
693 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
697 // try parsing using p2wpkh params
700 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
705 // try parsing using p2wpkh-in-p2sh network params
706 if ("p2wpkhInP2sh" in n
) {
708 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
714 // try the network params as currently specified
716 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
719 return "Invalid root key";
724 function getDerivationPath() {
725 if (bip44TabSelected()) {
726 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
727 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
728 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
729 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
731 path
+= purpose
+ "'/";
733 path
+= account
+ "'/";
735 DOM
.bip44path
.val(path
);
736 var derivationPath
= DOM
.bip44path
.val();
737 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
738 return derivationPath
;
740 else if (bip49TabSelected()) {
741 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
742 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
743 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
744 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
746 path
+= purpose
+ "'/";
748 path
+= account
+ "'/";
750 DOM
.bip49path
.val(path
);
751 var derivationPath
= DOM
.bip49path
.val();
752 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
753 return derivationPath
;
755 else if (bip84TabSelected()) {
756 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
757 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
758 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
759 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
761 path
+= purpose
+ "'/";
763 path
+= account
+ "'/";
765 DOM
.bip84path
.val(path
);
766 var derivationPath
= DOM
.bip84path
.val();
767 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
768 return derivationPath
;
770 else if (bip32TabSelected()) {
771 var derivationPath
= DOM
.bip32path
.val();
772 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
773 return derivationPath
;
775 else if (bip141TabSelected()) {
776 var derivationPath
= DOM
.bip141path
.val();
777 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
778 return derivationPath
;
781 console
.log("Unknown derivation path");
785 function findDerivationPathErrors(path
) {
786 // TODO is not perfect but is better than nothing
788 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
790 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
791 var maxDepth
= 255; // TODO verify this!!
792 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
793 if (path
[0] != "m") {
794 return "First character must be 'm'";
796 if (path
.length
> 1) {
797 if (path
[1] != "/") {
798 return "Separator must be '/'";
800 var indexes
= path
.split("/");
801 if (indexes
.length
> maxDepth
) {
802 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
804 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
805 var index
= indexes
[depth
];
806 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
807 if (invalidChars
.length
> 0) {
808 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
810 var indexValue
= parseInt(index
.replace("'", ""));
812 return "Invalid number at depth " + depth
;
814 if (indexValue
> maxIndexValue
) {
815 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
819 // Check root key exists or else derivation path is useless!
821 return "No root key";
823 // Check no hardened derivation path when using xpub keys
824 var hardenedPath
= path
.indexOf("'") > -1;
825 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
826 var hardened
= hardenedPath
|| hardenedAddresses
;
827 var isXpubkey
= bip32RootKey
.isNeutered();
828 if (hardened
&& isXpubkey
) {
829 return "Hardened derivation path is invalid with xpub key";
835 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
839 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
842 function displayBip44Info() {
843 // Get the derivation path for the account
844 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
845 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
846 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
848 path
+= purpose
+ "'/";
850 path
+= account
+ "'/";
851 // Calculate the account extended keys
852 var accountExtendedKey
= calcBip32ExtendedKey(path
);
853 var accountXprv
= accountExtendedKey
.toBase58();
854 var accountXpub
= accountExtendedKey
.neutered().toBase58();
856 // Display the extended keys
857 DOM
.bip44accountXprv
.val(accountXprv
);
858 DOM
.bip44accountXpub
.val(accountXpub
);
861 displayBip44InfoForELA();
865 function displayBip49Info() {
866 // Get the derivation path for the account
867 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
868 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
869 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
871 path
+= purpose
+ "'/";
873 path
+= account
+ "'/";
874 // Calculate the account extended keys
875 var accountExtendedKey
= calcBip32ExtendedKey(path
);
876 var accountXprv
= accountExtendedKey
.toBase58();
877 var accountXpub
= accountExtendedKey
.neutered().toBase58();
878 // Display the extended keys
879 DOM
.bip49accountXprv
.val(accountXprv
);
880 DOM
.bip49accountXpub
.val(accountXpub
);
883 function displayBip84Info() {
884 // Get the derivation path for the account
885 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
886 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
887 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
889 path
+= purpose
+ "'/";
891 path
+= account
+ "'/";
892 // Calculate the account extended keys
893 var accountExtendedKey
= calcBip32ExtendedKey(path
);
894 var accountXprv
= accountExtendedKey
.toBase58();
895 var accountXpub
= accountExtendedKey
.neutered().toBase58();
896 // Display the extended keys
897 DOM
.bip84accountXprv
.val(accountXprv
);
898 DOM
.bip84accountXpub
.val(accountXpub
);
901 function displayBip32Info() {
904 var rootKey
= bip32RootKey
.toBase58();
905 DOM
.rootKey
.val(rootKey
);
906 var xprvkeyB58
= "NA";
907 if (!bip32ExtendedKey
.isNeutered()) {
908 xprvkeyB58
= bip32ExtendedKey
.toBase58();
910 var extendedPrivKey
= xprvkeyB58
;
911 DOM
.extendedPrivKey
.val(extendedPrivKey
);
912 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
913 DOM
.extendedPubKey
.val(extendedPubKey
);
914 // Display the addresses and privkeys
915 clearAddressesList();
916 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
917 displayAddresses(0, initialAddressCount
);
920 displayBip32InfoForELA();
924 function displayAddresses(start
, total
) {
925 generationProcesses
.push(new (function() {
929 this.stop = function() {
930 for (var i
=0; i
<rows
.length
; i
++) {
931 rows
[i
].shouldGenerate
= false;
936 for (var i
=0; i
<total
; i
++) {
937 var index
= i
+ start
;
938 var isLast
= i
== total
- 1;
939 rows
.push(new TableRow(index
, isLast
));
945 function segwitSelected() {
946 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
949 function p2wpkhSelected() {
950 return bip84TabSelected() ||
951 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
954 function p2wpkhInP2shSelected() {
955 return bip49TabSelected() ||
956 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
959 function TableRow(index
, isLast
) {
962 this.shouldGenerate
= true;
963 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
964 var useBip38
= DOM
.useBip38
.prop("checked");
965 var bip38password
= DOM
.bip38Password
.val();
966 var isSegwit
= segwitSelected();
967 var segwitAvailable
= networkHasSegwit();
968 var isP2wpkh
= p2wpkhSelected();
969 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
975 function calculateValues() {
976 setTimeout(function() {
977 if (!self
.shouldGenerate
) {
980 // derive HDkey for this row of the table
982 if (useHardenedAddresses
) {
983 key
= bip32ExtendedKey
.deriveHardened(index
);
986 key
= bip32ExtendedKey
.derive(index
);
988 // bip38 requires uncompressed keys
989 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
990 var keyPair
= key
.keyPair
;
991 var useUncompressed
= useBip38
;
992 if (useUncompressed
) {
993 keyPair
= new bitcoinjs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
995 keyPair
= new groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
999 var address
= keyPair
.getAddress().toString();
1001 var hasPrivkey
= !key
.isNeutered();
1004 privkey
= keyPair
.toWIF();
1005 // BIP38 encode private key if required
1008 privkey
= groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1009 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1010 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1012 privkey
= bitcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1013 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1018 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1019 var indexText
= getDerivationPath() + "/" + index
;
1020 if (useHardenedAddresses
) {
1021 indexText
= indexText
+ "'";
1023 // Ethereum values are different
1024 if ((networks
[DOM
.network
.val()].name
== "ETH - Ethereum")
1025 || (networks
[DOM
.network
.val()].name
== "ETC - Ethereum Classic")
1026 || (networks
[DOM
.network
.val()].name
== "PIRL - Pirl")
1027 || (networks
[DOM
.network
.val()].name
== "MIX - MIX")
1028 || (networks
[DOM
.network
.val()].name
== "MUSIC - Musicoin")
1029 || (networks
[DOM
.network
.val()].name
== "POA - Poa")
1030 || (networks
[DOM
.network
.val()].name
== "EXP - Expanse")
1031 || (networks
[DOM
.network
.val()].name
== "CLO - Callisto")
1032 || (networks
[DOM
.network
.val()].name
== "DXN - DEXON")
1033 || (networks
[DOM
.network
.val()].name
== "ELLA - Ellaism")
1034 || (networks
[DOM
.network
.val()].name
== "ESN - Ethersocial Network")
1035 || (networks
[DOM
.network
.val()].name
== "VET - VeChain")
1037 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1038 privkey
= privKeyBuffer
.toString('hex');
1039 var addressBuffer
= ethUtil
.privateToAddress(privKeyBuffer
);
1040 var hexAddress
= addressBuffer
.toString('hex');
1041 var checksumAddress
= ethUtil
.toChecksumAddress(hexAddress
);
1042 address
= ethUtil
.addHexPrefix(checksumAddress
);
1043 privkey
= ethUtil
.addHexPrefix(privkey
);
1044 pubkey
= ethUtil
.addHexPrefix(pubkey
);
1047 // Stellar is different
1048 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1049 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1050 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1052 path
+= purpose
+ "'/";
1053 path
+= coin
+ "'/" + index
+ "'";
1054 var keypair
= stellarUtil
.getKeypair(path
, seed
);
1056 privkey
= keypair
.secret();
1057 pubkey
= address
= keypair
.publicKey();
1059 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1060 var NasAccount
= require("nebulas-account");
1061 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1062 var nebulasAccount
= new NasAccount();
1063 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1064 address
= nebulasAccount
.getAddressString();
1065 privkey
= nebulasAccount
.getPrivateKeyString();
1066 pubkey
= nebulasAccount
.getPublicKeyString();
1068 // Ripple values are different
1069 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1070 privkey
= convertRipplePriv(privkey
);
1071 address
= convertRippleAdrr(address
);
1073 // CasinoCoin values are different
1074 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1075 privkey
= convertCasinoCoinPriv(privkey
);
1076 address
= convertCasinoCoinAdrr(address
);
1078 // Bitcoin Cash address format may vary
1079 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1080 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1081 if (bchAddrType
== "cashaddr") {
1082 address
= bchaddr
.toCashAddress(address
);
1084 else if (bchAddrType
== "bitpay") {
1085 address
= bchaddr
.toBitpayAddress(address
);
1088 // Bitcoin Cash address format may vary
1089 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1090 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1091 if (bchAddrType
== "cashaddr") {
1092 address
= bchaddr
.toSlpAddress(address
);
1095 // Segwit addresses are different
1097 if (!segwitAvailable
) {
1101 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1102 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1103 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1105 else if (isP2wpkhInP2sh
) {
1106 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1107 var scriptsig
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1108 var addressbytes
= bitcoinjs
.bitcoin
.crypto
.hash160(scriptsig
);
1109 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1110 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1114 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1115 address
= bitcoinjs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1118 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1120 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1121 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1124 //Groestlcoin Addresses are different
1128 if (!segwitAvailable
) {
1132 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1134 else if (isP2wpkhInP2sh
) {
1135 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1138 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1142 let elaAddress
= calcAddressForELA(
1144 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1145 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1146 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1149 address
= elaAddress
.address
;
1150 privkey
= elaAddress
.privateKey
;
1151 pubkey
= elaAddress
.publicKey
;
1154 addAddressToList(indexText
, address
, pubkey
, privkey
);
1166 function showMore() {
1167 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1168 if (isNaN(rowsToAdd
)) {
1170 DOM
.rowsToAdd
.val("20");
1172 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1174 start
= lastIndexInTable() + 1;
1177 var newStart
= start
+ rowsToAdd
;
1178 DOM
.moreRowsStartIndex
.val(newStart
);
1180 if (rowsToAdd
> 200) {
1181 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1182 msg
+= "Do you want to continue?";
1183 if (!confirm(msg
)) {
1187 displayAddresses(start
, rowsToAdd
);
1190 function clearDisplay() {
1191 clearAddressesList();
1193 hideValidationError();
1196 function clearAddressesList() {
1197 DOM
.addresses
.empty();
1202 function stopGenerating() {
1203 while (generationProcesses
.length
> 0) {
1204 var generation
= generationProcesses
.shift();
1209 function clearKeys() {
1214 function clearRootKey() {
1215 DOM
.rootKey
.val("");
1218 function clearDerivedKeys() {
1219 DOM
.extendedPrivKey
.val("");
1220 DOM
.extendedPubKey
.val("");
1221 DOM
.bip44accountXprv
.val("");
1222 DOM
.bip44accountXpub
.val("");
1225 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1226 var row
= $(addressRowTemplate
.html());
1228 var indexCell
= row
.find(".index span");
1229 var addressCell
= row
.find(".address span");
1230 var pubkeyCell
= row
.find(".pubkey span");
1231 var privkeyCell
= row
.find(".privkey span");
1233 indexCell
.text(indexText
);
1234 addressCell
.text(address
);
1235 pubkeyCell
.text(pubkey
);
1236 privkeyCell
.text(privkey
);
1239 indexCell
.addClass("invisible");
1242 addressCell
.addClass("invisible");
1245 pubkeyCell
.addClass("invisible");
1248 privkeyCell
.addClass("invisible");
1250 DOM
.addresses
.append(row
);
1251 var rowShowQrEls
= row
.find("[data-show-qr]");
1252 setQrEvents(rowShowQrEls
);
1255 function hasStrongRandom() {
1256 return 'crypto' in window
&& window
['crypto'] !== null;
1259 function disableForms() {
1260 $("form").on("submit", function(e
) {
1265 function parseIntNoNaN(val
, defaultVal
) {
1266 var v
= parseInt(val
);
1273 function showPending() {
1275 .text("Calculating...")
1279 function findNearestWord(word
) {
1280 var language
= getLanguage();
1281 var words
= WORDLISTS
[language
];
1282 var minDistance
= 99;
1283 var closestWord
= words
[0];
1284 for (var i
=0; i
<words
.length
; i
++) {
1285 var comparedTo
= words
[i
];
1286 if (comparedTo
.indexOf(word
) == 0) {
1289 var distance
= Levenshtein
.get(word
, comparedTo
);
1290 if (distance
< minDistance
) {
1291 closestWord
= comparedTo
;
1292 minDistance
= distance
;
1298 function hidePending() {
1304 function populateNetworkSelect() {
1305 for (var i
=0; i
<networks
.length
; i
++) {
1306 var network
= networks
[i
];
1307 var option
= $("<option>");
1308 option
.attr("value", i
);
1309 option
.text(network
.name
);
1310 if (network
.name
== "BTC - Bitcoin") {
1311 option
.prop("selected", true);
1313 DOM
.phraseNetwork
.append(option
);
1317 function populateClientSelect() {
1318 for (var i
=0; i
<clients
.length
; i
++) {
1319 var client
= clients
[i
];
1320 var option
= $("<option>");
1321 option
.attr("value", i
);
1322 option
.text(client
.name
);
1323 DOM
.bip32Client
.append(option
);
1327 function getLanguage() {
1328 var defaultLanguage
= "english";
1329 // Try to get from existing phrase
1330 var language
= getLanguageFromPhrase();
1331 // Try to get from url if not from phrase
1332 if (language
.length
== 0) {
1333 language
= getLanguageFromUrl();
1335 // Default to English if no other option
1336 if (language
.length
== 0) {
1337 language
= defaultLanguage
;
1342 function getLanguageFromPhrase(phrase
) {
1343 // Check if how many words from existing phrase match a language.
1346 phrase
= DOM
.phrase
.val();
1348 if (phrase
.length
> 0) {
1349 var words
= phraseToWordArray(phrase
);
1350 var languageMatches
= {};
1351 for (l
in WORDLISTS
) {
1352 // Track how many words match in this language
1353 languageMatches
[l
] = 0;
1354 for (var i
=0; i
<words
.length
; i
++) {
1355 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1356 if (wordInLanguage
) {
1357 languageMatches
[l
]++;
1360 // Find languages with most word matches.
1361 // This is made difficult due to commonalities between Chinese
1362 // simplified vs traditional.
1363 var mostMatches
= 0;
1364 var mostMatchedLanguages
= [];
1365 for (var l
in languageMatches
) {
1366 var numMatches
= languageMatches
[l
];
1367 if (numMatches
> mostMatches
) {
1368 mostMatches
= numMatches
;
1369 mostMatchedLanguages
= [l
];
1371 else if (numMatches
== mostMatches
) {
1372 mostMatchedLanguages
.push(l
);
1376 if (mostMatchedLanguages
.length
> 0) {
1377 // Use first language and warn if multiple detected
1378 language
= mostMatchedLanguages
[0];
1379 if (mostMatchedLanguages
.length
> 1) {
1380 console
.warn("Multiple possible languages");
1381 console
.warn(mostMatchedLanguages
);
1388 function getLanguageFromUrl() {
1389 for (var language
in WORDLISTS
) {
1390 if (window
.location
.hash
.indexOf(language
) > -1) {
1397 function setMnemonicLanguage() {
1398 var language
= getLanguage();
1399 // Load the bip39 mnemonic generator for this language if required
1400 if (!(language
in mnemonics
)) {
1401 mnemonics
[language
] = new Mnemonic(language
);
1403 mnemonic
= mnemonics
[language
];
1406 function convertPhraseToNewLanguage() {
1407 var oldLanguage
= getLanguageFromPhrase();
1408 var newLanguage
= getLanguageFromUrl();
1409 var oldPhrase
= DOM
.phrase
.val();
1410 var oldWords
= phraseToWordArray(oldPhrase
);
1412 for (var i
=0; i
<oldWords
.length
; i
++) {
1413 var oldWord
= oldWords
[i
];
1414 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1415 var newWord
= WORDLISTS
[newLanguage
][index
];
1416 newWords
.push(newWord
);
1418 newPhrase
= wordArrayToPhrase(newWords
);
1422 // TODO look at jsbip39 - mnemonic.splitWords
1423 function phraseToWordArray(phrase
) {
1424 var words
= phrase
.split(/\s/g);
1426 for (var i
=0; i
<words
.length
; i
++) {
1427 var word
= words
[i
];
1428 if (word
.length
> 0) {
1429 noBlanks
.push(word
);
1435 // TODO look at jsbip39 - mnemonic.joinWords
1436 function wordArrayToPhrase(words
) {
1437 var phrase
= words
.join(" ");
1438 var language
= getLanguageFromPhrase(phrase
);
1439 if (language
== "japanese") {
1440 phrase
= words
.join("\u3000");
1445 function isUsingOwnEntropy() {
1446 return DOM
.useEntropy
.prop("checked");
1449 function setMnemonicFromEntropy() {
1450 clearEntropyFeedback();
1451 // Get entropy value
1452 var entropyStr
= DOM
.entropy
.val();
1453 // Work out minimum base for entropy
1454 var entropy
= Entropy
.fromString(entropyStr
);
1455 if (entropy
.binaryStr
.length
== 0) {
1458 // Show entropy details
1459 showEntropyFeedback(entropy
);
1460 // Use entropy hash if not using raw entropy
1461 var bits
= entropy
.binaryStr
;
1462 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1463 if (mnemonicLength
!= "raw") {
1464 // Get bits by hashing entropy with SHA256
1465 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1466 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1467 bits
= BigInteger
.parse(hex
, 16).toString(2);
1468 while (bits
.length
% 256 != 0) {
1471 // Truncate hash to suit number of words
1472 mnemonicLength
= parseInt(mnemonicLength
);
1473 var numberOfBits
= 32 * mnemonicLength
/ 3;
1474 bits
= bits
.substring(0, numberOfBits
);
1475 // show warning for weak entropy override
1476 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1477 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1480 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1484 // hide warning for weak entropy override
1485 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1487 // Discard trailing entropy
1488 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1489 var start
= bits
.length
- bitsToUse
;
1490 var binaryStr
= bits
.substring(start
);
1491 // Convert entropy string to numeric array
1492 var entropyArr
= [];
1493 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1494 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1495 var entropyByte
= parseInt(byteAsBits
, 2);
1496 entropyArr
.push(entropyByte
)
1498 // Convert entropy array to mnemonic
1499 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1500 // Set the mnemonic in the UI
1501 DOM
.phrase
.val(phrase
);
1502 // Show the word indexes
1504 // Show the checksum
1508 function clearEntropyFeedback() {
1509 DOM
.entropyCrackTime
.text("...");
1510 DOM
.entropyType
.text("");
1511 DOM
.entropyWordCount
.text("0");
1512 DOM
.entropyEventCount
.text("0");
1513 DOM
.entropyBitsPerEvent
.text("0");
1514 DOM
.entropyBits
.text("0");
1515 DOM
.entropyFiltered
.html(" ");
1516 DOM
.entropyBinary
.html(" ");
1519 function showEntropyFeedback(entropy
) {
1520 var numberOfBits
= entropy
.binaryStr
.length
;
1521 var timeToCrack
= "unknown";
1523 var z
= zxcvbn(entropy
.base
.parts
.join(""));
1524 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1525 if (z
.feedback
.warning
!= "") {
1526 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1530 console
.log("Error detecting entropy strength with zxcvbn:");
1533 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1534 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1535 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1536 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1537 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1538 DOM
.entropyType
.text(entropyTypeStr
);
1539 DOM
.entropyCrackTime
.text(timeToCrack
);
1540 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1541 DOM
.entropyBits
.text(numberOfBits
);
1542 DOM
.entropyWordCount
.text(wordCount
);
1543 DOM
.entropyBinary
.text(spacedBinaryStr
);
1544 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1545 // detect and warn of filtering
1546 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1547 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1548 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1550 DOM
.entropyFilterWarning
.removeClass('hidden');
1553 DOM
.entropyFilterWarning
.addClass('hidden');
1557 function getEntropyTypeStr(entropy
) {
1558 var typeStr
= entropy
.base
.str
;
1559 // Add some detail if these are cards
1560 if (entropy
.base
.asInt
== 52) {
1561 var cardDetail
= []; // array of message strings
1562 // Detect duplicates
1564 var dupeTracker
= {};
1565 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1566 var card
= entropy
.base
.parts
[i
];
1567 var cardUpper
= card
.toUpperCase();
1568 if (cardUpper
in dupeTracker
) {
1571 dupeTracker
[cardUpper
] = true;
1573 if (dupes
.length
> 0) {
1574 var dupeWord
= "duplicates";
1575 if (dupes
.length
== 1) {
1576 dupeWord
= "duplicate";
1578 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1579 if (dupes
.length
> 3) {
1582 cardDetail
.push(msg
);
1585 var uniqueCards
= [];
1586 for (var uniqueCard
in dupeTracker
) {
1587 uniqueCards
.push(uniqueCard
);
1589 if (uniqueCards
.length
== 52) {
1590 cardDetail
.unshift("full deck");
1592 // Detect missing cards
1593 var values
= "A23456789TJQK";
1595 var missingCards
= [];
1596 for (var i
=0; i
<suits
.length
; i
++) {
1597 for (var j
=0; j
<values
.length
; j
++) {
1598 var card
= values
[j
] + suits
[i
];
1599 if (!(card
in dupeTracker
)) {
1600 missingCards
.push(card
);
1604 // Display missing cards if six or less, ie clearly going for full deck
1605 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1606 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1607 if (missingCards
.length
> 3) {
1610 cardDetail
.push(msg
);
1612 // Add card details to typeStr
1613 if (cardDetail
.length
> 0) {
1614 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1620 function setQrEvents(els
) {
1621 els
.on("mouseenter", createQr
);
1622 els
.on("mouseleave", destroyQr
);
1623 els
.on("click", toggleQr
);
1626 function createQr(e
) {
1627 var content
= e
.target
.textContent
|| e
.target
.value
;
1635 DOM
.qrImage
.append(qrEl
);
1637 DOM
.qrHider
.addClass("hidden");
1640 DOM
.qrHider
.removeClass("hidden");
1642 DOM
.qrContainer
.removeClass("hidden");
1646 function destroyQr() {
1647 DOM
.qrImage
.text("");
1648 DOM
.qrContainer
.addClass("hidden");
1651 function toggleQr() {
1653 DOM
.qrHider
.toggleClass("hidden");
1654 DOM
.qrHint
.toggleClass("hidden");
1657 function bip44TabSelected() {
1658 return DOM
.bip44tab
.hasClass("active");
1661 function bip32TabSelected() {
1662 return DOM
.bip32tab
.hasClass("active");
1665 function networkHasSegwit() {
1667 if ("baseNetwork" in network
) {
1668 n
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1670 // check if only p2wpkh params are required
1671 if (p2wpkhSelected()) {
1672 return "p2wpkh" in n
;
1674 // check if only p2wpkh-in-p2sh params are required
1675 else if (p2wpkhInP2shSelected()) {
1676 return "p2wpkhInP2sh" in n
;
1678 // require both if it's unclear which params are required
1679 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1682 function bip49TabSelected() {
1683 return DOM
.bip49tab
.hasClass("active");
1686 function bip84TabSelected() {
1687 return DOM
.bip84tab
.hasClass("active");
1690 function bip141TabSelected() {
1691 return DOM
.bip141tab
.hasClass("active");
1694 function setHdCoin(coinValue
) {
1695 DOM
.bip44coin
.val(coinValue
);
1696 DOM
.bip49coin
.val(coinValue
);
1697 DOM
.bip84coin
.val(coinValue
);
1700 function showSegwitAvailable() {
1701 DOM
.bip49unavailable
.addClass("hidden");
1702 DOM
.bip49available
.removeClass("hidden");
1703 DOM
.bip84unavailable
.addClass("hidden");
1704 DOM
.bip84available
.removeClass("hidden");
1705 DOM
.bip141unavailable
.addClass("hidden");
1706 DOM
.bip141available
.removeClass("hidden");
1709 function showSegwitUnavailable() {
1710 DOM
.bip49available
.addClass("hidden");
1711 DOM
.bip49unavailable
.removeClass("hidden");
1712 DOM
.bip84available
.addClass("hidden");
1713 DOM
.bip84unavailable
.removeClass("hidden");
1714 DOM
.bip141available
.addClass("hidden");
1715 DOM
.bip141unavailable
.removeClass("hidden");
1718 function adjustNetworkForSegwit() {
1719 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1720 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1722 // See https://github.com/iancoleman/bip39/issues/125
1723 var segwitNetworks
= null;
1724 // if a segwit network is alread selected, need to use base network to
1725 // look up new parameters
1726 if ("baseNetwork" in network
) {
1727 network
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1729 // choose the right segwit params
1730 if (p2wpkhSelected() && "p2wpkh" in network
) {
1731 network
= network
.p2wpkh
;
1733 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1734 network
= network
.p2wpkhInP2sh
;
1738 function lastIndexInTable() {
1739 var pathText
= DOM
.addresses
.find(".index").last().text();
1740 var pathBits
= pathText
.split("/");
1741 var lastBit
= pathBits
[pathBits
.length
-1];
1742 var lastBitClean
= lastBit
.replace("'", "");
1743 return parseInt(lastBitClean
);
1746 function uint8ArrayToHex(a
) {
1748 for (var i
=0; i
<a
.length
; i
++) {
1749 var h
= a
[i
].toString(16);
1750 while (h
.length
< 2) {
1758 function showWordIndexes() {
1759 var phrase
= DOM
.phrase
.val();
1760 var words
= phraseToWordArray(phrase
);
1761 var wordIndexes
= [];
1762 var language
= getLanguage();
1763 for (var i
=0; i
<words
.length
; i
++) {
1764 var word
= words
[i
];
1765 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1766 wordIndexes
.push(wordIndex
);
1768 var wordIndexesStr
= wordIndexes
.join(", ");
1769 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1772 function showChecksum() {
1773 var phrase
= DOM
.phrase
.val();
1774 var words
= phraseToWordArray(phrase
);
1775 var checksumBitlength
= words
.length
/ 3;
1778 var language
= getLanguage();
1779 for (var i
=words
.length
-1; i
>=0; i
--) {
1780 var word
= words
[i
];
1781 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1782 var wordBinary
= wordIndex
.toString(2);
1783 while (wordBinary
.length
< 11) {
1784 wordBinary
= "0" + wordBinary
;
1786 var binaryStr
= wordBinary
+ binaryStr
;
1787 if (binaryStr
.length
>= checksumBitlength
) {
1788 var start
= binaryStr
.length
- checksumBitlength
;
1789 var end
= binaryStr
.length
;
1790 checksum
= binaryStr
.substring(start
, end
);
1791 // add spaces so the last group is 11 bits, not the first
1792 checksum
= checksum
.split("").reverse().join("")
1793 checksum
= addSpacesEveryElevenBits(checksum
);
1794 checksum
= checksum
.split("").reverse().join("")
1798 DOM
.entropyChecksum
.text(checksum
);
1801 function updateCsv() {
1802 var tableCsv
= "path,address,public key,private key\n";
1803 var rows
= DOM
.addresses
.find("tr");
1804 for (var i
=0; i
<rows
.length
; i
++) {
1805 var row
= $(rows
[i
]);
1806 var cells
= row
.find("td");
1807 for (var j
=0; j
<cells
.length
; j
++) {
1808 var cell
= $(cells
[j
]);
1809 if (!cell
.children().hasClass("invisible")) {
1810 tableCsv
= tableCsv
+ cell
.text();
1812 if (j
!= cells
.length
- 1) {
1813 tableCsv
= tableCsv
+ ",";
1816 tableCsv
= tableCsv
+ "\n";
1818 DOM
.csv
.val(tableCsv
);
1821 function addSpacesEveryElevenBits(binaryStr
) {
1822 return binaryStr
.match(/.{1,11}/g).join(" ");
1827 name: "AC - Asiacoin",
1828 onSelect: function() {
1829 network
= bitcoinjs
.bitcoin
.networks
.asiacoin
;
1834 name: "ACC - Adcoin",
1835 onSelect: function() {
1836 network
= bitcoinjs
.bitcoin
.networks
.adcoin
;
1841 name: "ARYA - Aryacoin",
1842 onSelect: function() {
1843 network
= bitcoinjs
.bitcoin
.networks
.aryacoin
;
1848 name: "AUR - Auroracoin",
1849 onSelect: function() {
1850 network
= bitcoinjs
.bitcoin
.networks
.auroracoin
;
1856 onSelect: function() {
1857 network
= bitcoinjs
.bitcoin
.networks
.axe
;
1862 name: "ANON - ANON",
1863 onSelect: function() {
1864 network
= bitcoinjs
.bitcoin
.networks
.anon
;
1869 name: "BOLI - Bolivarcoin",
1870 onSelect: function() {
1871 network
= bitcoinjs
.bitcoin
.networks
.bolivarcoin
;
1876 name: "BCA - Bitcoin Atom",
1877 onSelect: function() {
1878 network
= bitcoinjs
.bitcoin
.networks
.atom
;
1883 name: "BCH - Bitcoin Cash",
1884 onSelect: function() {
1885 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
1890 name: "BEET - Beetlecoin",
1891 onSelect: function() {
1892 network
= bitcoinjs
.bitcoin
.networks
.beetlecoin
;
1897 name: "BELA - Belacoin",
1898 onSelect: function() {
1899 network
= bitcoinjs
.bitcoin
.networks
.belacoin
;
1904 name: "BLK - BlackCoin",
1905 onSelect: function() {
1906 network
= bitcoinjs
.bitcoin
.networks
.blackcoin
;
1911 name: "BND - Blocknode",
1912 onSelect: function() {
1913 network
= bitcoinjs
.bitcoin
.networks
.blocknode
;
1918 name: "tBND - Blocknode Testnet",
1919 onSelect: function() {
1920 network
= bitcoinjs
.bitcoin
.networks
.blocknode_testnet
;
1925 name: "BRIT - Britcoin",
1926 onSelect: function() {
1927 network
= bitcoinjs
.bitcoin
.networks
.britcoin
;
1932 name: "BSD - Bitsend",
1933 onSelect: function() {
1934 network
= bitcoinjs
.bitcoin
.networks
.bitsend
;
1939 name: "BST - BlockStamp",
1940 onSelect: function() {
1941 network
= bitcoinjs
.bitcoin
.networks
.blockstamp
;
1947 onSelect: function() {
1948 network
= bitcoinjs
.bitcoin
.networks
.bata
;
1953 name: "BTC - Bitcoin",
1954 onSelect: function() {
1955 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
1960 name: "BTC - Bitcoin Testnet",
1961 onSelect: function() {
1962 network
= bitcoinjs
.bitcoin
.networks
.testnet
;
1967 name: "BITG - Bitcoin Green",
1968 onSelect: function() {
1969 network
= bitcoinjs
.bitcoin
.networks
.bitcoingreen
;
1974 name: "BTCP - Bitcoin Private",
1975 onSelect: function() {
1976 network
= bitcoinjs
.bitcoin
.networks
.bitcoinprivate
;
1981 name: "BSV - BitcoinSV",
1982 onSelect: function() {
1983 network
= bitcoinjs
.bitcoin
.networks
.bitcoinsv
;
1988 name: "BTCZ - Bitcoinz",
1989 onSelect: function() {
1990 network
= bitcoinjs
.bitcoin
.networks
.bitcoinz
;
1995 name: "BTDX - BitCloud",
1996 onSelect: function() {
1997 network
= bitcoinjs
.bitcoin
.networks
.bitcloud
;
2002 name: "BTG - Bitcoin Gold",
2003 onSelect: function() {
2004 network
= bitcoinjs
.bitcoin
.networks
.bgold
;
2009 name: "BTX - Bitcore",
2010 onSelect: function() {
2011 network
= bitcoinjs
.bitcoin
.networks
.bitcore
;
2016 name: "CCN - Cannacoin",
2017 onSelect: function() {
2018 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2023 name: "CESC - Cryptoescudo",
2024 onSelect: function() {
2025 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2030 name: "CDN - Canadaecoin",
2031 onSelect: function() {
2032 network
= bitcoinjs
.bitcoin
.networks
.canadaecoin
;
2037 name: "CLAM - Clams",
2038 onSelect: function() {
2039 network
= bitcoinjs
.bitcoin
.networks
.clam
;
2044 name: "CLO - Callisto",
2045 segwitAvailable: false,
2046 onSelect: function() {
2047 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2052 name: "CLUB - Clubcoin",
2053 onSelect: function() {
2054 network
= bitcoinjs
.bitcoin
.networks
.clubcoin
;
2059 name: "CMP - Compcoin",
2060 onSelect: function() {
2061 network
= bitcoinjs
.bitcoin
.networks
.compcoin
;
2066 name: "CPU - CPUchain",
2067 onSelect: function() {
2068 network
= bitcoinjs
.bitcoin
.networks
.cpuchain
;
2073 name: "CRAVE - Crave",
2074 onSelect: function() {
2075 network
= bitcoinjs
.bitcoin
.networks
.crave
;
2080 name: "CRW - Crown (Legacy)",
2081 onSelect: function() {
2082 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2087 name: "CRW - Crown",
2088 onSelect: function() {
2089 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2094 name: "CSC - CasinoCoin",
2095 onSelect: function() {
2096 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2101 name: "DASH - Dash",
2102 onSelect: function() {
2103 network
= bitcoinjs
.bitcoin
.networks
.dash
;
2108 name: "DASH - Dash Testnet",
2109 onSelect: function() {
2110 network
= bitcoinjs
.bitcoin
.networks
.dashtn
;
2115 name: "DFC - Defcoin",
2116 onSelect: function() {
2117 network
= bitcoinjs
.bitcoin
.networks
.defcoin
;
2122 name: "DGB - Digibyte",
2123 onSelect: function() {
2124 network
= bitcoinjs
.bitcoin
.networks
.digibyte
;
2129 name: "DGC - Digitalcoin",
2130 onSelect: function() {
2131 network
= bitcoinjs
.bitcoin
.networks
.digitalcoin
;
2136 name: "DMD - Diamond",
2137 onSelect: function() {
2138 network
= bitcoinjs
.bitcoin
.networks
.diamond
;
2143 name: "DNR - Denarius",
2144 onSelect: function() {
2145 network
= bitcoinjs
.bitcoin
.networks
.denarius
;
2150 name: "DOGE - Dogecoin",
2151 onSelect: function() {
2152 network
= bitcoinjs
.bitcoin
.networks
.dogecoin
;
2157 name: "DOGEt - Dogecoin Testnet",
2158 onSelect: function() {
2159 network
= bitcoinjs
.bitcoin
.networks
.dogecointestnet
;
2164 name: "DXN - DEXON",
2165 onSelect: function() {
2166 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2171 name: "ECN - Ecoin",
2172 onSelect: function() {
2173 network
= bitcoinjs
.bitcoin
.networks
.ecoin
;
2178 name: "EDRC - Edrcoin",
2179 onSelect: function() {
2180 network
= bitcoinjs
.bitcoin
.networks
.edrcoin
;
2185 name: "EFL - Egulden",
2186 onSelect: function() {
2187 network
= bitcoinjs
.bitcoin
.networks
.egulden
;
2192 name: "ELA - Elastos",
2193 onSelect: function () {
2194 network
= bitcoinjs
.bitcoin
.networks
.elastos
;
2199 name: "ELLA - Ellaism",
2200 segwitAvailable: false,
2201 onSelect: function() {
2202 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2207 name: "EMC2 - Einsteinium",
2208 onSelect: function() {
2209 network
= bitcoinjs
.bitcoin
.networks
.einsteinium
;
2214 name: "ERC - Europecoin",
2215 onSelect: function() {
2216 network
= bitcoinjs
.bitcoin
.networks
.europecoin
;
2221 name: "EOS - EOSIO",
2222 onSelect: function() {
2223 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2228 name: "ESN - Ethersocial Network",
2229 segwitAvailable: false,
2230 onSelect: function() {
2231 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2236 name: "ETC - Ethereum Classic",
2237 segwitAvailable: false,
2238 onSelect: function() {
2239 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2244 name: "ETH - Ethereum",
2245 onSelect: function() {
2246 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2251 name: "EXCL - Exclusivecoin",
2252 onSelect: function() {
2253 network
= bitcoinjs
.bitcoin
.networks
.exclusivecoin
;
2258 name: "EXCC - ExchangeCoin",
2259 onSelect: function() {
2260 network
= bitcoinjs
.bitcoin
.networks
.exchangecoin
;
2265 name: "EXP - Expanse",
2266 segwitAvailable: false,
2267 onSelect: function() {
2268 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2274 onSelect: function() {
2275 network
= bitcoinjs
.bitcoin
.networks
.fix
;
2280 name: "FIX - FIX Testnet",
2281 onSelect: function() {
2282 network
= bitcoinjs
.bitcoin
.networks
.fixtestnet
;
2287 name: "FJC - Fujicoin",
2288 onSelect: function() {
2289 network
= bitcoinjs
.bitcoin
.networks
.fujicoin
;
2294 name: "FLASH - Flashcoin",
2295 onSelect: function() {
2296 network
= bitcoinjs
.bitcoin
.networks
.flashcoin
;
2301 name: "FRST - Firstcoin",
2302 onSelect: function() {
2303 network
= bitcoinjs
.bitcoin
.networks
.firstcoin
;
2308 name: "FTC - Feathercoin",
2309 onSelect: function() {
2310 network
= bitcoinjs
.bitcoin
.networks
.feathercoin
;
2315 name: "GAME - GameCredits",
2316 onSelect: function() {
2317 network
= bitcoinjs
.bitcoin
.networks
.game
;
2322 name: "GBX - Gobyte",
2323 onSelect: function() {
2324 network
= bitcoinjs
.bitcoin
.networks
.gobyte
;
2329 name: "GCR - GCRCoin",
2330 onSelect: function() {
2331 network
= bitcoinjs
.bitcoin
.networks
.gcr
;
2336 name: "GRC - Gridcoin",
2337 onSelect: function() {
2338 network
= bitcoinjs
.bitcoin
.networks
.gridcoin
;
2343 name: "GRS - Groestlcoin",
2344 onSelect: function() {
2345 network
= bitcoinjs
.bitcoin
.networks
.groestlcoin
;
2350 name: "GRS - Groestlcoin Testnet",
2351 onSelect: function() {
2352 network
= bitcoinjs
.bitcoin
.networks
.groestlcointestnet
;
2357 name: "HNC - Helleniccoin",
2358 onSelect: function() {
2359 network
= bitcoinjs
.bitcoin
.networks
.helleniccoin
;
2364 name: "HUSH - Hush (Legacy)",
2365 onSelect: function() {
2366 network
= bitcoinjs
.bitcoin
.networks
.hush
;
2371 name: "HUSH - Hush3",
2372 onSelect: function() {
2373 network
= bitcoinjs
.bitcoin
.networks
.hush3
;
2378 name: "INSN - Insane",
2379 onSelect: function() {
2380 network
= bitcoinjs
.bitcoin
.networks
.insane
;
2386 onSelect: function() {
2387 network
= bitcoinjs
.bitcoin
.networks
.iop
;
2392 name: "IXC - Ixcoin",
2393 onSelect: function() {
2394 network
= bitcoinjs
.bitcoin
.networks
.ixcoin
;
2399 name: "JBS - Jumbucks",
2400 onSelect: function() {
2401 network
= bitcoinjs
.bitcoin
.networks
.jumbucks
;
2406 name: "KMD - Komodo",
2407 bip49available: false,
2408 onSelect: function() {
2409 network
= bitcoinjs
.bitcoin
.networks
.komodo
;
2414 name: "KOBO - Kobocoin",
2415 bip49available: false,
2416 onSelect: function() {
2417 network
= bitcoinjs
.bitcoin
.networks
.kobocoin
;
2422 name: "LBC - Library Credits",
2423 onSelect: function() {
2424 network
= bitcoinjs
.bitcoin
.networks
.lbry
;
2429 name: "LCC - Litecoincash",
2430 onSelect: function() {
2431 network
= bitcoinjs
.bitcoin
.networks
.litecoincash
;
2436 name: "LDCN - Landcoin",
2437 onSelect: function() {
2438 network
= bitcoinjs
.bitcoin
.networks
.landcoin
;
2443 name: "LINX - Linx",
2444 onSelect: function() {
2445 network
= bitcoinjs
.bitcoin
.networks
.linx
;
2450 name: "LKR - Lkrcoin",
2451 segwitAvailable: false,
2452 onSelect: function() {
2453 network
= bitcoinjs
.bitcoin
.networks
.lkrcoin
;
2458 name: "LTC - Litecoin",
2459 onSelect: function() {
2460 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
2462 DOM
.litecoinLtubContainer
.removeClass("hidden");
2466 name: "LTCt - Litecoin Testnet",
2467 onSelect: function() {
2468 network
= bitcoinjs
.bitcoin
.networks
.litecointestnet
;
2470 DOM
.litecoinLtubContainer
.removeClass("hidden");
2474 name: "LTZ - LitecoinZ",
2475 onSelect: function() {
2476 network
= bitcoinjs
.bitcoin
.networks
.litecoinz
;
2481 name: "LYNX - Lynx",
2482 onSelect: function() {
2483 network
= bitcoinjs
.bitcoin
.networks
.lynx
;
2488 name: "MAZA - Maza",
2489 onSelect: function() {
2490 network
= bitcoinjs
.bitcoin
.networks
.maza
;
2495 name: "MEC - Megacoin",
2496 onSelect: function() {
2497 network
= bitcoinjs
.bitcoin
.networks
.megacoin
;
2503 segwitAvailable: false,
2504 onSelect: function() {
2505 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2510 name: "MNX - Minexcoin",
2511 onSelect: function() {
2512 network
= bitcoinjs
.bitcoin
.networks
.minexcoin
;
2517 name: "MONA - Monacoin",
2518 onSelect: function() {
2519 network
= bitcoinjs
.bitcoin
.networks
.monacoin
,
2524 name: "MONK - Monkey Project",
2525 onSelect: function() {
2526 network
= bitcoinjs
.bitcoin
.networks
.monkeyproject
,
2531 name: "MUSIC - Musicoin",
2532 segwitAvailable: false,
2533 onSelect: function() {
2534 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2539 name: "NAV - Navcoin",
2540 onSelect: function() {
2541 network
= bitcoinjs
.bitcoin
.networks
.navcoin
;
2546 name: "NAS - Nebulas",
2547 onSelect: function() {
2548 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2553 name: "NEBL - Neblio",
2554 onSelect: function() {
2555 network
= bitcoinjs
.bitcoin
.networks
.neblio
;
2560 name: "NEOS - Neoscoin",
2561 onSelect: function() {
2562 network
= bitcoinjs
.bitcoin
.networks
.neoscoin
;
2567 name: "NIX - NIX Platform",
2568 onSelect: function() {
2569 network
= bitcoinjs
.bitcoin
.networks
.nix
;
2574 name: "NLG - Gulden",
2575 onSelect: function() {
2576 network
= bitcoinjs
.bitcoin
.networks
.gulden
;
2581 name: "NMC - Namecoin",
2582 onSelect: function() {
2583 network
= bitcoinjs
.bitcoin
.networks
.namecoin
;
2588 name: "NRG - Energi",
2589 onSelect: function() {
2590 network
= bitcoinjs
.bitcoin
.networks
.energi
;
2595 name: "NRO - Neurocoin",
2596 onSelect: function() {
2597 network
= bitcoinjs
.bitcoin
.networks
.neurocoin
;
2602 name: "NSR - Nushares",
2603 onSelect: function() {
2604 network
= bitcoinjs
.bitcoin
.networks
.nushares
;
2609 name: "NYC - Newyorkc",
2610 onSelect: function() {
2611 network
= bitcoinjs
.bitcoin
.networks
.newyorkc
;
2616 name: "NVC - Novacoin",
2617 onSelect: function() {
2618 network
= bitcoinjs
.bitcoin
.networks
.novacoin
;
2623 name: "OK - Okcash",
2624 onSelect: function() {
2625 network
= bitcoinjs
.bitcoin
.networks
.okcash
;
2630 name: "OMNI - Omnicore",
2631 onSelect: function() {
2632 network
= bitcoinjs
.bitcoin
.networks
.omnicore
;
2637 name: "ONION - DeepOnion",
2638 onSelect: function() {
2639 network
= bitcoinjs
.bitcoin
.networks
.deeponion
;
2644 name: "ONX - Onixcoin",
2645 onSelect: function() {
2646 network
= bitcoinjs
.bitcoin
.networks
.onixcoin
;
2651 name: "PHR - Phore",
2652 onSelect: function() {
2653 network
= bitcoinjs
.bitcoin
.networks
.phore
;
2658 name: "PINK - Pinkcoin",
2659 onSelect: function() {
2660 network
= bitcoinjs
.bitcoin
.networks
.pinkcoin
;
2665 name: "PIRL - Pirl",
2666 segwitAvailable: false,
2667 onSelect: function() {
2668 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2673 name: "PIVX - PIVX",
2674 onSelect: function() {
2675 network
= bitcoinjs
.bitcoin
.networks
.pivx
;
2680 name: "PIVX - PIVX Testnet",
2681 onSelect: function() {
2682 network
= bitcoinjs
.bitcoin
.networks
.pivxtestnet
;
2688 segwitAvailable: false,
2689 onSelect: function() {
2690 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2695 name: "POSW - POSWcoin",
2696 onSelect: function() {
2697 network
= bitcoinjs
.bitcoin
.networks
.poswcoin
;
2702 name: "POT - Potcoin",
2703 onSelect: function() {
2704 network
= bitcoinjs
.bitcoin
.networks
.potcoin
;
2709 name: "PPC - Peercoin",
2710 onSelect: function() {
2711 network
= bitcoinjs
.bitcoin
.networks
.peercoin
;
2716 name: "PRJ - ProjectCoin",
2717 onSelect: function() {
2718 network
= bitcoinjs
.bitcoin
.networks
.projectcoin
;
2723 name: "PSB - Pesobit",
2724 onSelect: function() {
2725 network
= bitcoinjs
.bitcoin
.networks
.pesobit
;
2730 name: "PUT - Putincoin",
2731 onSelect: function() {
2732 network
= bitcoinjs
.bitcoin
.networks
.putincoin
;
2737 name: "RPD - Rapids",
2738 onSelect: function() {
2739 network
= bitcoinjs
.bitcoin
.networks
.rapids
;
2744 name: "RVN - Ravencoin",
2745 onSelect: function() {
2746 network
= bitcoinjs
.bitcoin
.networks
.ravencoin
;
2751 name: "RBY - Rubycoin",
2752 onSelect: function() {
2753 network
= bitcoinjs
.bitcoin
.networks
.rubycoin
;
2758 name: "RDD - Reddcoin",
2759 onSelect: function() {
2760 network
= bitcoinjs
.bitcoin
.networks
.reddcoin
;
2765 name: "RVR - RevolutionVR",
2766 onSelect: function() {
2767 network
= bitcoinjs
.bitcoin
.networks
.revolutionvr
;
2772 name: "SAFE - Safecoin",
2773 onSelect: function() {
2774 network
= bitcoinjs
.bitcoin
.networks
.safecoin
;
2779 name: "SLS - Salus",
2780 onSelect: function() {
2781 network
= bitcoinjs
.bitcoin
.networks
.salus
;
2786 name: "SDC - ShadowCash",
2787 onSelect: function() {
2788 network
= bitcoinjs
.bitcoin
.networks
.shadow
;
2793 name: "SDC - ShadowCash Testnet",
2794 onSelect: function() {
2795 network
= bitcoinjs
.bitcoin
.networks
.shadowtn
;
2800 name: "SLM - Slimcoin",
2801 onSelect: function() {
2802 network
= bitcoinjs
.bitcoin
.networks
.slimcoin
;
2807 name: "SLM - Slimcoin Testnet",
2808 onSelect: function() {
2809 network
= bitcoinjs
.bitcoin
.networks
.slimcointn
;
2814 name: "SLP - Simple Ledger Protocol",
2815 onSelect: function() {
2816 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2821 name: "SLR - Solarcoin",
2822 onSelect: function() {
2823 network
= bitcoinjs
.bitcoin
.networks
.solarcoin
;
2828 name: "SMLY - Smileycoin",
2829 onSelect: function() {
2830 network
= bitcoinjs
.bitcoin
.networks
.smileycoin
;
2835 name: "STASH - Stash",
2836 onSelect: function() {
2837 network
= bitcoinjs
.bitcoin
.networks
.stash
;
2842 name: "STASH - Stash Testnet",
2843 onSelect: function() {
2844 network
= bitcoinjs
.bitcoin
.networks
.stashtn
;
2849 name: "STRAT - Stratis",
2850 onSelect: function() {
2851 network
= bitcoinjs
.bitcoin
.networks
.stratis
;
2856 name: "TSTRAT - Stratis Testnet",
2857 onSelect: function() {
2858 network
= bitcoinjs
.bitcoin
.networks
.stratistest
;
2863 name: "SYS - Syscoin",
2864 onSelect: function() {
2865 network
= bitcoinjs
.bitcoin
.networks
.syscoin
;
2870 name: "THC - Hempcoin",
2871 onSelect: function() {
2872 network
= bitcoinjs
.bitcoin
.networks
.hempcoin
;
2878 onSelect: function() {
2879 network
= bitcoinjs
.bitcoin
.networks
.toa
;
2884 name: "TWINS - TWINS",
2885 onSelect: function() {
2886 network
= bitcoinjs
.bitcoin
.networks
.twins
;
2891 name: "TWINS - TWINS Testnet",
2892 onSelect: function() {
2893 network
= bitcoinjs
.bitcoin
.networks
.twinstestnet
;
2898 name: "USC - Ultimatesecurecash",
2899 onSelect: function() {
2900 network
= bitcoinjs
.bitcoin
.networks
.ultimatesecurecash
;
2905 name: "USNBT - NuBits",
2906 onSelect: function() {
2907 network
= bitcoinjs
.bitcoin
.networks
.nubits
;
2912 name: "UNO - Unobtanium",
2913 onSelect: function() {
2914 network
= bitcoinjs
.bitcoin
.networks
.unobtanium
;
2919 name: "VASH - Vpncoin",
2920 onSelect: function() {
2921 network
= bitcoinjs
.bitcoin
.networks
.vpncoin
;
2926 name: "VET - VeChain",
2927 onSelect: function() {
2928 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2933 name: "VIA - Viacoin",
2934 onSelect: function() {
2935 network
= bitcoinjs
.bitcoin
.networks
.viacoin
;
2940 name: "VIA - Viacoin Testnet",
2941 onSelect: function() {
2942 network
= bitcoinjs
.bitcoin
.networks
.viacointestnet
;
2947 name: "VIVO - Vivo",
2948 onSelect: function() {
2949 network
= bitcoinjs
.bitcoin
.networks
.vivo
;
2954 name: "VTC - Vertcoin",
2955 onSelect: function() {
2956 network
= bitcoinjs
.bitcoin
.networks
.vertcoin
;
2961 name: "WGR - Wagerr",
2962 onSelect: function() {
2963 network
= bitcoinjs
.bitcoin
.networks
.wagerr
;
2968 name: "WC - Wincoin",
2969 onSelect: function() {
2970 network
= bitcoinjs
.bitcoin
.networks
.wincoin
;
2975 name: "XAX - Artax",
2976 onSelect: function() {
2977 network
= bitcoinjs
.bitcoin
.networks
.artax
;
2982 name: "XBC - Bitcoinplus",
2983 onSelect: function() {
2984 network
= bitcoinjs
.bitcoin
.networks
.bitcoinplus
;
2989 name: "XLM - Stellar",
2990 onSelect: function() {
2991 network
= stellarUtil
.dummyNetwork
;
2996 name: "XMY - Myriadcoin",
2997 onSelect: function() {
2998 network
= bitcoinjs
.bitcoin
.networks
.myriadcoin
;
3003 name: "XRP - Ripple",
3004 onSelect: function() {
3005 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3010 name: "XVC - Vcash",
3011 onSelect: function() {
3012 network
= bitcoinjs
.bitcoin
.networks
.vcash
;
3017 name: "XVG - Verge",
3018 onSelect: function() {
3019 network
= bitcoinjs
.bitcoin
.networks
.verge
;
3024 name: "XUEZ - Xuez",
3025 segwitAvailable: false,
3026 onSelect: function() {
3027 network
= bitcoinjs
.bitcoin
.networks
.xuez
;
3032 name: "XWC - Whitecoin",
3033 onSelect: function() {
3034 network
= bitcoinjs
.bitcoin
.networks
.whitecoin
;
3039 name: "XZC - Zcoin",
3040 onSelect: function() {
3041 network
= bitcoinjs
.bitcoin
.networks
.zcoin
;
3046 name: "ZCL - Zclassic",
3047 onSelect: function() {
3048 network
= bitcoinjs
.bitcoin
.networks
.zclassic
;
3053 name: "ZEC - Zcash",
3054 onSelect: function() {
3055 network
= bitcoinjs
.bitcoin
.networks
.zcash
;
3060 name: "ZEN - Horizen",
3061 onSelect: function() {
3062 network
= bitcoinjs
.bitcoin
.networks
.zencash
;
3070 name: "Bitcoin Core",
3071 onSelect: function() {
3072 DOM
.bip32path
.val("m/0'/0'");
3073 DOM
.hardenedAddresses
.prop('checked', true);
3077 name: "blockchain.info",
3078 onSelect: function() {
3079 DOM
.bip32path
.val("m/44'/0'/0'");
3080 DOM
.hardenedAddresses
.prop('checked', false);
3084 name: "MultiBit HD",
3085 onSelect: function() {
3086 DOM
.bip32path
.val("m/0'/0");
3087 DOM
.hardenedAddresses
.prop('checked', false);
3091 name: "Coinomi, Ledger",
3092 onSelect: function() {
3093 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3094 DOM
.hardenedAddresses
.prop('checked', false);
3099 // ELA - Elastos functions - begin
3100 function displayBip44InfoForELA() {
3105 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3106 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3108 // Calculate the account extended keys
3109 var accountXprv
= elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3110 var accountXpub
= elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3112 // Display the extended keys
3113 DOM
.bip44accountXprv
.val(accountXprv
);
3114 DOM
.bip44accountXpub
.val(accountXpub
);
3117 function displayBip32InfoForELA() {
3122 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3123 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3124 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3126 DOM
.extendedPrivKey
.val(elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3127 DOM
.extendedPubKey
.val(elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3129 // Display the addresses and privkeys
3130 clearAddressesList();
3131 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3132 displayAddresses(0, initialAddressCount
);
3135 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3140 var publicKey
= elastosjs
.getDerivedPublicKey(elastosjs
.getMasterPublicKey(seed
), change
, index
);
3142 privateKey: elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3143 publicKey: publicKey
,
3144 address: elastosjs
.getAddress(publicKey
.toString('hex'))
3147 // ELA - Elastos functions - end