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 entropyTypeAutoDetect
= true;
20 var entropyChangeTimeoutEvent
= null;
21 var phraseChangeTimeoutEvent
= null;
22 var rootKeyChangedTimeoutEvent
= null;
24 var generationProcesses
= [];
27 DOM
.privacyScreenToggle
= $(".privacy-screen-toggle");
28 DOM
.network
= $(".network");
29 DOM
.bip32Client
= $("#bip32-client");
30 DOM
.phraseNetwork
= $("#network-phrase");
31 DOM
.useEntropy
= $(".use-entropy");
32 DOM
.entropyContainer
= $(".entropy-container");
33 DOM
.entropy
= $(".entropy");
34 DOM
.entropyFiltered
= DOM
.entropyContainer
.find(".filtered");
35 DOM
.entropyType
= DOM
.entropyContainer
.find(".type");
36 DOM
.entropyTypeInputs
= DOM
.entropyContainer
.find("input[name='entropy-type']");
37 DOM
.entropyCrackTime
= DOM
.entropyContainer
.find(".crack-time");
38 DOM
.entropyEventCount
= DOM
.entropyContainer
.find(".event-count");
39 DOM
.entropyBits
= DOM
.entropyContainer
.find(".bits");
40 DOM
.entropyBitsPerEvent
= DOM
.entropyContainer
.find(".bits-per-event");
41 DOM
.entropyWordCount
= DOM
.entropyContainer
.find(".word-count");
42 DOM
.entropyBinary
= DOM
.entropyContainer
.find(".binary");
43 DOM
.entropyWordIndexes
= DOM
.entropyContainer
.find(".word-indexes");
44 DOM
.entropyChecksum
= DOM
.entropyContainer
.find(".checksum");
45 DOM
.entropyMnemonicLength
= DOM
.entropyContainer
.find(".mnemonic-length");
46 DOM
.entropyWeakEntropyOverrideWarning
= DOM
.entropyContainer
.find(".weak-entropy-override-warning");
47 DOM
.entropyFilterWarning
= DOM
.entropyContainer
.find(".filter-warning");
48 DOM
.phrase
= $(".phrase");
49 DOM
.phraseSplit
= $(".phraseSplit");
50 DOM
.phraseSplitWarn
= $(".phraseSplitWarn");
51 DOM
.passphrase
= $(".passphrase");
52 DOM
.generateContainer
= $(".generate-container");
53 DOM
.generate
= $(".generate");
54 DOM
.seed
= $(".seed");
55 DOM
.rootKey
= $(".root-key");
56 DOM
.litecoinLtubContainer
= $(".litecoin-ltub-container");
57 DOM
.litecoinUseLtub
= $(".litecoin-use-ltub");
58 DOM
.extendedPrivKey
= $(".extended-priv-key");
59 DOM
.extendedPubKey
= $(".extended-pub-key");
60 DOM
.bip32tab
= $("#bip32-tab");
61 DOM
.bip44tab
= $("#bip44-tab");
62 DOM
.bip49tab
= $("#bip49-tab");
63 DOM
.bip84tab
= $("#bip84-tab");
64 DOM
.bip141tab
= $("#bip141-tab");
65 DOM
.bip32panel
= $("#bip32");
66 DOM
.bip44panel
= $("#bip44");
67 DOM
.bip49panel
= $("#bip49");
68 DOM
.bip32path
= $("#bip32-path");
69 DOM
.bip44path
= $("#bip44-path");
70 DOM
.bip44purpose
= $("#bip44 .purpose");
71 DOM
.bip44coin
= $("#bip44 .coin");
72 DOM
.bip44account
= $("#bip44 .account");
73 DOM
.bip44accountXprv
= $("#bip44 .account-xprv");
74 DOM
.bip44accountXpub
= $("#bip44 .account-xpub");
75 DOM
.bip44change
= $("#bip44 .change");
76 DOM
.bip49unavailable
= $("#bip49 .unavailable");
77 DOM
.bip49available
= $("#bip49 .available");
78 DOM
.bip49path
= $("#bip49-path");
79 DOM
.bip49purpose
= $("#bip49 .purpose");
80 DOM
.bip49coin
= $("#bip49 .coin");
81 DOM
.bip49account
= $("#bip49 .account");
82 DOM
.bip49accountXprv
= $("#bip49 .account-xprv");
83 DOM
.bip49accountXpub
= $("#bip49 .account-xpub");
84 DOM
.bip49change
= $("#bip49 .change");
85 DOM
.bip84unavailable
= $("#bip84 .unavailable");
86 DOM
.bip84available
= $("#bip84 .available");
87 DOM
.bip84path
= $("#bip84-path");
88 DOM
.bip84purpose
= $("#bip84 .purpose");
89 DOM
.bip84coin
= $("#bip84 .coin");
90 DOM
.bip84account
= $("#bip84 .account");
91 DOM
.bip84accountXprv
= $("#bip84 .account-xprv");
92 DOM
.bip84accountXpub
= $("#bip84 .account-xpub");
93 DOM
.bip84change
= $("#bip84 .change");
94 DOM
.bip141unavailable
= $("#bip141 .unavailable");
95 DOM
.bip141available
= $("#bip141 .available");
96 DOM
.bip141path
= $("#bip141-path");
97 DOM
.bip141semantics
= $(".bip141-semantics");
98 DOM
.generatedStrength
= $(".generate-container .strength");
99 DOM
.generatedStrengthWarning
= $(".generate-container .warning");
100 DOM
.hardenedAddresses
= $(".hardened-addresses");
101 DOM
.bitcoinCashAddressTypeContainer
= $(".bch-addr-type-container");
102 DOM
.bitcoinCashAddressType
= $("[name=bch-addr-type]")
103 DOM
.useBip38
= $(".use-bip38");
104 DOM
.bip38Password
= $(".bip38-password");
105 DOM
.addresses
= $(".addresses");
106 DOM
.csvTab
= $("#csv-tab a");
108 DOM
.rowsToAdd
= $(".rows-to-add");
109 DOM
.more
= $(".more");
110 DOM
.moreRowsStartIndex
= $(".more-rows-start-index");
111 DOM
.feedback
= $(".feedback");
112 DOM
.tab
= $(".derivation-type a");
113 DOM
.indexToggle
= $(".index-toggle");
114 DOM
.addressToggle
= $(".address-toggle");
115 DOM
.publicKeyToggle
= $(".public-key-toggle");
116 DOM
.privateKeyToggle
= $(".private-key-toggle");
117 DOM
.languages
= $(".languages a");
118 DOM
.qrContainer
= $(".qr-container");
119 DOM
.qrHider
= DOM
.qrContainer
.find(".qr-hider");
120 DOM
.qrImage
= DOM
.qrContainer
.find(".qr-image");
121 DOM
.qrHint
= DOM
.qrContainer
.find(".qr-hint");
122 DOM
.showQrEls
= $("[data-show-qr]");
126 DOM
.privacyScreenToggle
.on("change", privacyScreenToggled
);
127 DOM
.generatedStrength
.on("change", generatedStrengthChanged
);
128 DOM
.network
.on("change", networkChanged
);
129 DOM
.bip32Client
.on("change", bip32ClientChanged
);
130 DOM
.useEntropy
.on("change", setEntropyVisibility
);
131 DOM
.entropy
.on("input", delayedEntropyChanged
);
132 DOM
.entropyMnemonicLength
.on("change", entropyChanged
);
133 DOM
.entropyTypeInputs
.on("change", entropyTypeChanged
);
134 DOM
.phrase
.on("input", delayedPhraseChanged
);
135 DOM
.passphrase
.on("input", delayedPhraseChanged
);
136 DOM
.generate
.on("click", generateClicked
);
137 DOM
.more
.on("click", showMore
);
138 DOM
.rootKey
.on("input", delayedRootKeyChanged
);
139 DOM
.litecoinUseLtub
.on("change", litecoinUseLtubChanged
);
140 DOM
.bip32path
.on("input", calcForDerivationPath
);
141 DOM
.bip44account
.on("input", calcForDerivationPath
);
142 DOM
.bip44change
.on("input", calcForDerivationPath
);
143 DOM
.bip49account
.on("input", calcForDerivationPath
);
144 DOM
.bip49change
.on("input", calcForDerivationPath
);
145 DOM
.bip84account
.on("input", calcForDerivationPath
);
146 DOM
.bip84change
.on("input", calcForDerivationPath
);
147 DOM
.bip141path
.on("input", calcForDerivationPath
);
148 DOM
.bip141semantics
.on("change", tabChanged
);
149 DOM
.tab
.on("shown.bs.tab", tabChanged
);
150 DOM
.hardenedAddresses
.on("change", calcForDerivationPath
);
151 DOM
.useBip38
.on("change", calcForDerivationPath
);
152 DOM
.bip38Password
.on("change", calcForDerivationPath
);
153 DOM
.indexToggle
.on("click", toggleIndexes
);
154 DOM
.addressToggle
.on("click", toggleAddresses
);
155 DOM
.publicKeyToggle
.on("click", togglePublicKeys
);
156 DOM
.privateKeyToggle
.on("click", togglePrivateKeys
);
157 DOM
.csvTab
.on("click", updateCsv
);
158 DOM
.languages
.on("click", languageChanged
);
159 DOM
.bitcoinCashAddressType
.on("change", bitcoinCashAddressTypeChange
);
160 setQrEvents(DOM
.showQrEls
);
163 hideValidationError();
164 populateNetworkSelect();
165 populateClientSelect();
170 function generatedStrengthChanged() {
171 var strength
= parseInt(DOM
.generatedStrength
.val());
173 DOM
.generatedStrengthWarning
.removeClass("hidden");
176 DOM
.generatedStrengthWarning
.addClass("hidden");
180 function networkChanged(e
) {
182 clearAddressesList();
183 DOM
.litecoinLtubContainer
.addClass("hidden");
184 DOM
.bitcoinCashAddressTypeContainer
.addClass("hidden");
185 var networkIndex
= e
.target
.value
;
186 var network
= networks
[networkIndex
];
188 adjustNetworkForSegwit();
197 function bip32ClientChanged(e
) {
198 var clientIndex
= DOM
.bip32Client
.val();
199 if (clientIndex
== "custom") {
200 DOM
.bip32path
.prop("readonly", false);
203 DOM
.bip32path
.prop("readonly", true);
204 clients
[clientIndex
].onSelect();
214 function setEntropyVisibility() {
215 if (isUsingOwnEntropy()) {
216 DOM
.entropyContainer
.removeClass("hidden");
217 DOM
.generateContainer
.addClass("hidden");
218 DOM
.phrase
.prop("readonly", true);
223 DOM
.entropyContainer
.addClass("hidden");
224 DOM
.generateContainer
.removeClass("hidden");
225 DOM
.phrase
.prop("readonly", false);
230 function delayedPhraseChanged() {
231 hideValidationError();
234 bip32ExtendedKey
= null;
235 clearAddressesList();
237 if (phraseChangeTimeoutEvent
!= null) {
238 clearTimeout(phraseChangeTimeoutEvent
);
240 phraseChangeTimeoutEvent
= setTimeout(function() {
242 var entropy
= mnemonic
.toRawEntropyBin(DOM
.phrase
.val());
243 if (entropy
!== null) {
244 DOM
.entropyMnemonicLength
.val("raw");
245 DOM
.entropy
.val(entropy
);
250 function phraseChanged() {
252 setMnemonicLanguage();
253 // Get the mnemonic phrase
254 var phrase
= DOM
.phrase
.val();
255 var errorText
= findPhraseErrors(phrase
);
257 showValidationError(errorText
);
260 // Calculate and display
261 var passphrase
= DOM
.passphrase
.val();
262 calcBip32RootKeyFromSeed(phrase
, passphrase
);
263 calcForDerivationPath();
264 // Show the word indexes
266 writeSplitPhrase(phrase
);
269 function tabChanged() {
271 adjustNetworkForSegwit();
272 var phrase
= DOM
.phrase
.val();
274 // Calculate and display for mnemonic
275 var errorText
= findPhraseErrors(phrase
);
277 showValidationError(errorText
);
280 // Calculate and display
281 var passphrase
= DOM
.passphrase
.val();
282 calcBip32RootKeyFromSeed(phrase
, passphrase
);
285 // Calculate and display for root key
286 var rootKeyBase58
= DOM
.rootKey
.val();
287 var errorText
= validateRootKey(rootKeyBase58
);
289 showValidationError(errorText
);
292 // Calculate and display
293 calcBip32RootKeyFromBase58(rootKeyBase58
);
295 calcForDerivationPath();
298 function delayedEntropyChanged() {
299 hideValidationError();
301 if (entropyChangeTimeoutEvent
!= null) {
302 clearTimeout(entropyChangeTimeoutEvent
);
304 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
307 function entropyChanged() {
308 // If blank entropy, clear mnemonic, addresses, errors
309 if (DOM
.entropy
.val().trim().length
== 0) {
311 clearEntropyFeedback();
313 DOM
.phraseSplit
.val("");
314 showValidationError("Blank entropy");
317 // Get the current phrase to detect changes
318 var phrase
= DOM
.phrase
.val();
319 // Set the phrase from the entropy
320 setMnemonicFromEntropy();
321 // Recalc addresses if the phrase has changed
322 var newPhrase
= DOM
.phrase
.val();
323 if (newPhrase
!= phrase
) {
324 if (newPhrase
.length
== 0) {
336 function entropyTypeChanged() {
337 entropyTypeAutoDetect
= false;
341 function delayedRootKeyChanged() {
342 // Warn if there is an existing mnemonic or passphrase.
343 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
344 if (!confirm("This will clear existing mnemonic and passphrase")) {
345 DOM
.rootKey
.val(bip32RootKey
);
349 hideValidationError();
351 // Clear existing mnemonic and passphrase
353 DOM
.phraseSplit
.val("");
354 DOM
.passphrase
.val("");
356 if (rootKeyChangedTimeoutEvent
!= null) {
357 clearTimeout(rootKeyChangedTimeoutEvent
);
359 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
362 function rootKeyChanged() {
364 hideValidationError();
365 var rootKeyBase58
= DOM
.rootKey
.val();
366 var errorText
= validateRootKey(rootKeyBase58
);
368 showValidationError(errorText
);
371 // Calculate and display
372 calcBip32RootKeyFromBase58(rootKeyBase58
);
373 calcForDerivationPath();
376 function litecoinUseLtubChanged() {
377 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
378 if (litecoinUseLtub
) {
379 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
382 network
= bitcoinjs
.bitcoin
.networks
.litecoinXprv
;
387 function calcForDerivationPath() {
389 clearAddressesList();
391 // Don't show segwit if it's selected but network doesn't support it
392 if (segwitSelected() && !networkHasSegwit()) {
393 showSegwitUnavailable();
397 showSegwitAvailable();
398 // Get the derivation path
399 var derivationPath
= getDerivationPath();
400 var errorText
= findDerivationPathErrors(derivationPath
);
402 showValidationError(errorText
);
405 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
406 if (bip44TabSelected()) {
409 else if (bip49TabSelected()) {
412 else if (bip84TabSelected()) {
418 function generateClicked() {
419 if (isUsingOwnEntropy()) {
424 setTimeout(function() {
425 setMnemonicLanguage();
426 var phrase
= generateRandomPhrase();
434 function languageChanged() {
435 setTimeout(function() {
436 setMnemonicLanguage();
437 if (DOM
.phrase
.val().length
> 0) {
438 var newPhrase
= convertPhraseToNewLanguage();
439 DOM
.phrase
.val(newPhrase
);
443 DOM
.generate
.trigger("click");
448 function bitcoinCashAddressTypeChange() {
452 function toggleIndexes() {
453 showIndex
= !showIndex
;
454 $("td.index span").toggleClass("invisible");
457 function toggleAddresses() {
458 showAddress
= !showAddress
;
459 $("td.address span").toggleClass("invisible");
462 function togglePublicKeys() {
463 showPubKey
= !showPubKey
;
464 $("td.pubkey span").toggleClass("invisible");
467 function togglePrivateKeys() {
468 showPrivKey
= !showPrivKey
;
469 $("td.privkey span").toggleClass("invisible");
472 function privacyScreenToggled() {
473 // private-data contains elements added to DOM at runtime
474 // so catch all by adding visual privacy class to the root of the DOM
475 if (DOM
.privacyScreenToggle
.prop("checked")) {
476 $("body").addClass("visual-privacy");
479 $("body").removeClass("visual-privacy");
485 function generateRandomPhrase() {
486 if (!hasStrongRandom()) {
487 var errorText
= "This browser does not support strong randomness";
488 showValidationError(errorText
);
491 // get the amount of entropy to use
492 var numWords
= parseInt(DOM
.generatedStrength
.val());
493 var strength
= numWords
/ 3 * 32;
494 var buffer
= new Uint8Array(strength
/ 8);
495 // create secure entropy
496 var data
= crypto
.getRandomValues(buffer
);
498 var words
= mnemonic
.toMnemonic(data
);
499 DOM
.phrase
.val(words
);
501 var entropyHex
= uint8ArrayToHex(data
);
502 DOM
.entropy
.val(entropyHex
);
503 // ensure entropy fields are consistent with what is being displayed
504 DOM
.entropyMnemonicLength
.val("raw");
508 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
509 seed
= mnemonic
.toSeed(phrase
, passphrase
);
510 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
512 bip32RootKey
= groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
516 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
518 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
521 // try parsing with various segwit network params since this extended
522 // key may be from any one of them.
523 if (networkHasSegwit()) {
525 if ("baseNetwork" in n
) {
526 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
528 // try parsing using base network params
530 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
534 // try parsing using p2wpkh params
537 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
542 // try parsing using p2wpkh-in-p2sh network params
543 if ("p2wpkhInP2sh" in n
) {
545 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
550 // try parsing using p2wsh network params
553 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
558 // try parsing using p2wsh-in-p2sh network params
559 if ("p2wshInP2sh" in n
) {
561 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
567 // try the network params as currently specified
568 bip32RootKey
= bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
571 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
572 // try parsing with various segwit network params since this extended
573 // key may be from any one of them.
574 if (networkHasSegwit()) {
576 if ("baseNetwork" in n
) {
577 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
579 // try parsing using base network params
581 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
585 // try parsing using p2wpkh params
588 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
593 // try parsing using p2wpkh-in-p2sh network params
594 if ("p2wpkhInP2sh" in n
) {
596 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
602 // try the network params as currently specified
603 bip32RootKey
= groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
606 function calcBip32ExtendedKey(path
) {
607 // Check there's a root key to derive from
611 var extendedKey
= bip32RootKey
;
612 // Derive the key from the path
613 var pathBits
= path
.split("/");
614 for (var i
=0; i
<pathBits
.length
; i
++) {
615 var bit
= pathBits
[i
];
616 var index
= parseInt(bit
);
620 var hardened
= bit
[bit
.length
-1] == "'";
621 var isPriv
= !(extendedKey
.isNeutered());
622 var invalidDerivationPath
= hardened
&& !isPriv
;
623 if (invalidDerivationPath
) {
627 extendedKey
= extendedKey
.deriveHardened(index
);
630 extendedKey
= extendedKey
.derive(index
);
636 function showValidationError(errorText
) {
642 function hideValidationError() {
648 function findPhraseErrors(phrase
) {
649 // Preprocess the words
650 phrase
= mnemonic
.normalizeString(phrase
);
651 var words
= phraseToWordArray(phrase
);
652 // Detect blank phrase
653 if (words
.length
== 0) {
654 return "Blank mnemonic";
657 for (var i
=0; i
<words
.length
; i
++) {
659 var language
= getLanguage();
660 if (WORDLISTS
[language
].indexOf(word
) == -1) {
661 console
.log("Finding closest match to " + word
);
662 var nearestWord
= findNearestWord(word
);
663 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
666 // Check the words are valid
667 var properPhrase
= wordArrayToPhrase(words
);
668 var isValid
= mnemonic
.check(properPhrase
);
670 return "Invalid mnemonic";
675 function validateRootKey(rootKeyBase58
) {
677 return validateRootKeyGRS(rootKeyBase58
);
679 // try various segwit network params since this extended key may be from
681 if (networkHasSegwit()) {
683 if ("baseNetwork" in n
) {
684 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
686 // try parsing using base network params
688 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
692 // try parsing using p2wpkh params
695 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
700 // try parsing using p2wpkh-in-p2sh network params
701 if ("p2wpkhInP2sh" in n
) {
703 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
708 // try parsing using p2wsh network params
711 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
716 // try parsing using p2wsh-in-p2sh network params
717 if ("p2wshInP2sh" in n
) {
719 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
725 // try the network params as currently specified
727 bitcoinjs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
730 return "Invalid root key";
735 function validateRootKeyGRS(rootKeyBase58
) {
736 // try various segwit network params since this extended key may be from
738 if (networkHasSegwit()) {
740 if ("baseNetwork" in n
) {
741 n
= bitcoinjs
.bitcoin
.networks
[n
.baseNetwork
];
743 // try parsing using base network params
745 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
749 // try parsing using p2wpkh params
752 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
757 // try parsing using p2wpkh-in-p2sh network params
758 if ("p2wpkhInP2sh" in n
) {
760 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
766 // try the network params as currently specified
768 groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
771 return "Invalid root key";
776 function getDerivationPath() {
777 if (bip44TabSelected()) {
778 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
779 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
780 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
781 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
783 path
+= purpose
+ "'/";
785 path
+= account
+ "'/";
787 DOM
.bip44path
.val(path
);
788 var derivationPath
= DOM
.bip44path
.val();
789 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
790 return derivationPath
;
792 else if (bip49TabSelected()) {
793 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
794 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
795 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
796 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
798 path
+= purpose
+ "'/";
800 path
+= account
+ "'/";
802 DOM
.bip49path
.val(path
);
803 var derivationPath
= DOM
.bip49path
.val();
804 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
805 return derivationPath
;
807 else if (bip84TabSelected()) {
808 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
809 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
810 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
811 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
813 path
+= purpose
+ "'/";
815 path
+= account
+ "'/";
817 DOM
.bip84path
.val(path
);
818 var derivationPath
= DOM
.bip84path
.val();
819 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
820 return derivationPath
;
822 else if (bip32TabSelected()) {
823 var derivationPath
= DOM
.bip32path
.val();
824 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
825 return derivationPath
;
827 else if (bip141TabSelected()) {
828 var derivationPath
= DOM
.bip141path
.val();
829 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
830 return derivationPath
;
833 console
.log("Unknown derivation path");
837 function findDerivationPathErrors(path
) {
838 // TODO is not perfect but is better than nothing
840 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
842 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
843 var maxDepth
= 255; // TODO verify this!!
844 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
845 if (path
[0] != "m") {
846 return "First character must be 'm'";
848 if (path
.length
> 1) {
849 if (path
[1] != "/") {
850 return "Separator must be '/'";
852 var indexes
= path
.split("/");
853 if (indexes
.length
> maxDepth
) {
854 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
856 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
857 var index
= indexes
[depth
];
858 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
859 if (invalidChars
.length
> 0) {
860 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
862 var indexValue
= parseInt(index
.replace("'", ""));
864 return "Invalid number at depth " + depth
;
866 if (indexValue
> maxIndexValue
) {
867 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
871 // Check root key exists or else derivation path is useless!
873 return "No root key";
875 // Check no hardened derivation path when using xpub keys
876 var hardenedPath
= path
.indexOf("'") > -1;
877 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
878 var hardened
= hardenedPath
|| hardenedAddresses
;
879 var isXpubkey
= bip32RootKey
.isNeutered();
880 if (hardened
&& isXpubkey
) {
881 return "Hardened derivation path is invalid with xpub key";
887 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
891 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
894 function displayBip44Info() {
895 // Get the derivation path for the account
896 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
897 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
898 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
900 path
+= purpose
+ "'/";
902 path
+= account
+ "'/";
903 // Calculate the account extended keys
904 var accountExtendedKey
= calcBip32ExtendedKey(path
);
905 var accountXprv
= accountExtendedKey
.toBase58();
906 var accountXpub
= accountExtendedKey
.neutered().toBase58();
908 // Display the extended keys
909 DOM
.bip44accountXprv
.val(accountXprv
);
910 DOM
.bip44accountXpub
.val(accountXpub
);
913 displayBip44InfoForELA();
917 function displayBip49Info() {
918 // Get the derivation path for the account
919 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
920 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
921 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
923 path
+= purpose
+ "'/";
925 path
+= account
+ "'/";
926 // Calculate the account extended keys
927 var accountExtendedKey
= calcBip32ExtendedKey(path
);
928 var accountXprv
= accountExtendedKey
.toBase58();
929 var accountXpub
= accountExtendedKey
.neutered().toBase58();
930 // Display the extended keys
931 DOM
.bip49accountXprv
.val(accountXprv
);
932 DOM
.bip49accountXpub
.val(accountXpub
);
935 function displayBip84Info() {
936 // Get the derivation path for the account
937 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
938 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
939 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
941 path
+= purpose
+ "'/";
943 path
+= account
+ "'/";
944 // Calculate the account extended keys
945 var accountExtendedKey
= calcBip32ExtendedKey(path
);
946 var accountXprv
= accountExtendedKey
.toBase58();
947 var accountXpub
= accountExtendedKey
.neutered().toBase58();
948 // Display the extended keys
949 DOM
.bip84accountXprv
.val(accountXprv
);
950 DOM
.bip84accountXpub
.val(accountXpub
);
953 function displayBip32Info() {
956 var rootKey
= bip32RootKey
.toBase58();
957 DOM
.rootKey
.val(rootKey
);
958 var xprvkeyB58
= "NA";
959 if (!bip32ExtendedKey
.isNeutered()) {
960 xprvkeyB58
= bip32ExtendedKey
.toBase58();
962 var extendedPrivKey
= xprvkeyB58
;
963 DOM
.extendedPrivKey
.val(extendedPrivKey
);
964 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
965 DOM
.extendedPubKey
.val(extendedPubKey
);
966 // Display the addresses and privkeys
967 clearAddressesList();
968 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
969 displayAddresses(0, initialAddressCount
);
972 displayBip32InfoForELA();
976 function displayAddresses(start
, total
) {
977 generationProcesses
.push(new (function() {
981 this.stop = function() {
982 for (var i
=0; i
<rows
.length
; i
++) {
983 rows
[i
].shouldGenerate
= false;
988 for (var i
=0; i
<total
; i
++) {
989 var index
= i
+ start
;
990 var isLast
= i
== total
- 1;
991 rows
.push(new TableRow(index
, isLast
));
997 function segwitSelected() {
998 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
1001 function p2wpkhSelected() {
1002 return bip84TabSelected() ||
1003 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
1006 function p2wpkhInP2shSelected() {
1007 return bip49TabSelected() ||
1008 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
1011 function p2wshSelected() {
1012 return bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh";
1015 function p2wshInP2shSelected() {
1016 return (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh-p2sh");
1019 function TableRow(index
, isLast
) {
1022 this.shouldGenerate
= true;
1023 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
1024 var useBip38
= DOM
.useBip38
.prop("checked");
1025 var bip38password
= DOM
.bip38Password
.val();
1026 var isSegwit
= segwitSelected();
1027 var segwitAvailable
= networkHasSegwit();
1028 var isP2wpkh
= p2wpkhSelected();
1029 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
1030 var isP2wsh
= p2wshSelected();
1031 var isP2wshInP2sh
= p2wshInP2shSelected();
1037 function calculateValues() {
1038 setTimeout(function() {
1039 if (!self
.shouldGenerate
) {
1042 // derive HDkey for this row of the table
1044 if (useHardenedAddresses
) {
1045 key
= bip32ExtendedKey
.deriveHardened(index
);
1048 key
= bip32ExtendedKey
.derive(index
);
1050 // bip38 requires uncompressed keys
1051 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1052 var keyPair
= key
.keyPair
;
1053 var useUncompressed
= useBip38
;
1054 if (useUncompressed
) {
1055 keyPair
= new bitcoinjs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1057 keyPair
= new groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1061 var address
= keyPair
.getAddress().toString();
1063 var hasPrivkey
= !key
.isNeutered();
1066 privkey
= keyPair
.toWIF();
1067 // BIP38 encode private key if required
1070 privkey
= groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1071 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1072 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1074 privkey
= bitcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1075 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1080 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1081 var indexText
= getDerivationPath() + "/" + index
;
1082 if (useHardenedAddresses
) {
1083 indexText
= indexText
+ "'";
1085 // Ethereum values are different
1086 if (networkIsEthereum()) {
1087 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1088 privkey
= privKeyBuffer
.toString('hex');
1089 var addressBuffer
= ethUtil
.privateToAddress(privKeyBuffer
);
1090 var hexAddress
= addressBuffer
.toString('hex');
1091 var checksumAddress
= ethUtil
.toChecksumAddress(hexAddress
);
1092 address
= ethUtil
.addHexPrefix(checksumAddress
);
1093 privkey
= ethUtil
.addHexPrefix(privkey
);
1094 pubkey
= ethUtil
.addHexPrefix(pubkey
);
1097 // Stellar is different
1098 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1099 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1100 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1102 path
+= purpose
+ "'/";
1103 path
+= coin
+ "'/" + index
+ "'";
1104 var keypair
= stellarUtil
.getKeypair(path
, seed
);
1106 privkey
= keypair
.secret();
1107 pubkey
= address
= keypair
.publicKey();
1109 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1110 var NasAccount
= require("nebulas-account");
1111 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1112 var nebulasAccount
= new NasAccount();
1113 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1114 address
= nebulasAccount
.getAddressString();
1115 privkey
= nebulasAccount
.getPrivateKeyString();
1116 pubkey
= nebulasAccount
.getPublicKeyString();
1118 // Ripple values are different
1119 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1120 privkey
= convertRipplePriv(privkey
);
1121 address
= convertRippleAdrr(address
);
1123 // CasinoCoin values are different
1124 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1125 privkey
= convertCasinoCoinPriv(privkey
);
1126 address
= convertCasinoCoinAdrr(address
);
1128 // Bitcoin Cash address format may vary
1129 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1130 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1131 if (bchAddrType
== "cashaddr") {
1132 address
= bchaddr
.toCashAddress(address
);
1134 else if (bchAddrType
== "bitpay") {
1135 address
= bchaddr
.toBitpayAddress(address
);
1138 // Bitcoin Cash address format may vary
1139 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1140 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1141 if (bchAddrType
== "cashaddr") {
1142 address
= bchaddr
.toSlpAddress(address
);
1145 // Segwit addresses are different
1147 if (!segwitAvailable
) {
1151 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1152 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1153 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1155 else if (isP2wpkhInP2sh
) {
1156 var keyhash
= bitcoinjs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1157 var scriptsig
= bitcoinjs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1158 var addressbytes
= bitcoinjs
.bitcoin
.crypto
.hash160(scriptsig
);
1159 var scriptpubkey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1160 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1163 // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71
1165 var witnessScript
= bitcoinjs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1166 var scriptPubKey
= bitcoinjs
.bitcoin
.script
.witnessScriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.sha256(witnessScript
));
1167 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
);
1169 else if (isP2wshInP2sh
) {
1170 // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183
1172 var witnessScript
= bitcoinjs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1173 var redeemScript
= bitcoinjs
.bitcoin
.script
.witnessScriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.sha256(witnessScript
));
1174 var scriptPubKey
= bitcoinjs
.bitcoin
.script
.scriptHash
.output
.encode(bitcoinjs
.bitcoin
.crypto
.hash160(redeemScript
));
1175 address
= bitcoinjs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
)
1179 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1180 address
= bitcoinjs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1183 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1185 pubkey
= eosUtil
.bufferToPublic(keyPair
.getPublicKeyBuffer());
1186 privkey
= eosUtil
.bufferToPrivate(keyPair
.d
.toBuffer(32));
1189 //Groestlcoin Addresses are different
1193 if (!segwitAvailable
) {
1197 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1199 else if (isP2wpkhInP2sh
) {
1200 address
= groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1203 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1207 let elaAddress
= calcAddressForELA(
1209 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1210 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1211 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1214 address
= elaAddress
.address
;
1215 privkey
= elaAddress
.privateKey
;
1216 pubkey
= elaAddress
.publicKey
;
1219 addAddressToList(indexText
, address
, pubkey
, privkey
);
1231 function showMore() {
1232 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1233 if (isNaN(rowsToAdd
)) {
1235 DOM
.rowsToAdd
.val("20");
1237 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1239 start
= lastIndexInTable() + 1;
1242 var newStart
= start
+ rowsToAdd
;
1243 DOM
.moreRowsStartIndex
.val(newStart
);
1245 if (rowsToAdd
> 200) {
1246 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1247 msg
+= "Do you want to continue?";
1248 if (!confirm(msg
)) {
1252 displayAddresses(start
, rowsToAdd
);
1255 function clearDisplay() {
1256 clearAddressesList();
1258 hideValidationError();
1261 function clearAddressesList() {
1262 DOM
.addresses
.empty();
1267 function stopGenerating() {
1268 while (generationProcesses
.length
> 0) {
1269 var generation
= generationProcesses
.shift();
1274 function clearKeys() {
1279 function clearRootKey() {
1280 DOM
.rootKey
.val("");
1283 function clearDerivedKeys() {
1284 DOM
.extendedPrivKey
.val("");
1285 DOM
.extendedPubKey
.val("");
1286 DOM
.bip44accountXprv
.val("");
1287 DOM
.bip44accountXpub
.val("");
1290 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1291 var row
= $(addressRowTemplate
.html());
1293 var indexCell
= row
.find(".index span");
1294 var addressCell
= row
.find(".address span");
1295 var pubkeyCell
= row
.find(".pubkey span");
1296 var privkeyCell
= row
.find(".privkey span");
1298 indexCell
.text(indexText
);
1299 addressCell
.text(address
);
1300 pubkeyCell
.text(pubkey
);
1301 privkeyCell
.text(privkey
);
1304 indexCell
.addClass("invisible");
1307 addressCell
.addClass("invisible");
1310 pubkeyCell
.addClass("invisible");
1313 privkeyCell
.addClass("invisible");
1315 DOM
.addresses
.append(row
);
1316 var rowShowQrEls
= row
.find("[data-show-qr]");
1317 setQrEvents(rowShowQrEls
);
1320 function hasStrongRandom() {
1321 return 'crypto' in window
&& window
['crypto'] !== null;
1324 function disableForms() {
1325 $("form").on("submit", function(e
) {
1330 function parseIntNoNaN(val
, defaultVal
) {
1331 var v
= parseInt(val
);
1338 function showPending() {
1340 .text("Calculating...")
1344 function findNearestWord(word
) {
1345 var language
= getLanguage();
1346 var words
= WORDLISTS
[language
];
1347 var minDistance
= 99;
1348 var closestWord
= words
[0];
1349 for (var i
=0; i
<words
.length
; i
++) {
1350 var comparedTo
= words
[i
];
1351 if (comparedTo
.indexOf(word
) == 0) {
1354 var distance
= Levenshtein
.get(word
, comparedTo
);
1355 if (distance
< minDistance
) {
1356 closestWord
= comparedTo
;
1357 minDistance
= distance
;
1363 function hidePending() {
1369 function populateNetworkSelect() {
1370 for (var i
=0; i
<networks
.length
; i
++) {
1371 var network
= networks
[i
];
1372 var option
= $("<option>");
1373 option
.attr("value", i
);
1374 option
.text(network
.name
);
1375 if (network
.name
== "BTC - Bitcoin") {
1376 option
.prop("selected", true);
1378 DOM
.phraseNetwork
.append(option
);
1382 function populateClientSelect() {
1383 for (var i
=0; i
<clients
.length
; i
++) {
1384 var client
= clients
[i
];
1385 var option
= $("<option>");
1386 option
.attr("value", i
);
1387 option
.text(client
.name
);
1388 DOM
.bip32Client
.append(option
);
1392 function getLanguage() {
1393 var defaultLanguage
= "english";
1394 // Try to get from existing phrase
1395 var language
= getLanguageFromPhrase();
1396 // Try to get from url if not from phrase
1397 if (language
.length
== 0) {
1398 language
= getLanguageFromUrl();
1400 // Default to English if no other option
1401 if (language
.length
== 0) {
1402 language
= defaultLanguage
;
1407 function getLanguageFromPhrase(phrase
) {
1408 // Check if how many words from existing phrase match a language.
1411 phrase
= DOM
.phrase
.val();
1413 if (phrase
.length
> 0) {
1414 var words
= phraseToWordArray(phrase
);
1415 var languageMatches
= {};
1416 for (l
in WORDLISTS
) {
1417 // Track how many words match in this language
1418 languageMatches
[l
] = 0;
1419 for (var i
=0; i
<words
.length
; i
++) {
1420 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1421 if (wordInLanguage
) {
1422 languageMatches
[l
]++;
1425 // Find languages with most word matches.
1426 // This is made difficult due to commonalities between Chinese
1427 // simplified vs traditional.
1428 var mostMatches
= 0;
1429 var mostMatchedLanguages
= [];
1430 for (var l
in languageMatches
) {
1431 var numMatches
= languageMatches
[l
];
1432 if (numMatches
> mostMatches
) {
1433 mostMatches
= numMatches
;
1434 mostMatchedLanguages
= [l
];
1436 else if (numMatches
== mostMatches
) {
1437 mostMatchedLanguages
.push(l
);
1441 if (mostMatchedLanguages
.length
> 0) {
1442 // Use first language and warn if multiple detected
1443 language
= mostMatchedLanguages
[0];
1444 if (mostMatchedLanguages
.length
> 1) {
1445 console
.warn("Multiple possible languages");
1446 console
.warn(mostMatchedLanguages
);
1453 function getLanguageFromUrl() {
1454 for (var language
in WORDLISTS
) {
1455 if (window
.location
.hash
.indexOf(language
) > -1) {
1462 function setMnemonicLanguage() {
1463 var language
= getLanguage();
1464 // Load the bip39 mnemonic generator for this language if required
1465 if (!(language
in mnemonics
)) {
1466 mnemonics
[language
] = new Mnemonic(language
);
1468 mnemonic
= mnemonics
[language
];
1471 function convertPhraseToNewLanguage() {
1472 var oldLanguage
= getLanguageFromPhrase();
1473 var newLanguage
= getLanguageFromUrl();
1474 var oldPhrase
= DOM
.phrase
.val();
1475 var oldWords
= phraseToWordArray(oldPhrase
);
1477 for (var i
=0; i
<oldWords
.length
; i
++) {
1478 var oldWord
= oldWords
[i
];
1479 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1480 var newWord
= WORDLISTS
[newLanguage
][index
];
1481 newWords
.push(newWord
);
1483 newPhrase
= wordArrayToPhrase(newWords
);
1487 // TODO look at jsbip39 - mnemonic.splitWords
1488 function phraseToWordArray(phrase
) {
1489 var words
= phrase
.split(/\s/g);
1491 for (var i
=0; i
<words
.length
; i
++) {
1492 var word
= words
[i
];
1493 if (word
.length
> 0) {
1494 noBlanks
.push(word
);
1500 // TODO look at jsbip39 - mnemonic.joinWords
1501 function wordArrayToPhrase(words
) {
1502 var phrase
= words
.join(" ");
1503 var language
= getLanguageFromPhrase(phrase
);
1504 if (language
== "japanese") {
1505 phrase
= words
.join("\u3000");
1510 function writeSplitPhrase(phrase
) {
1511 var wordCount
= phrase
.split(/\s/g).length
;
1513 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1514 var group
=[[],[],[]],
1516 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1517 while (left
.length
>0) {
1518 groupI
=(groupI
+1)%3;
1519 seed
= seed
* 16807 % 2147483647;
1520 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1521 group
[groupI
].push(left
[selected
]);
1522 left
.splice(selected
,1);
1524 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1525 for (var i
=0;i
<3;i
++) {
1526 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1527 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1529 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1530 var triesPerSecond
=10000000000;
1531 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1532 var displayRedText
= false;
1534 hackTime
="<1 second";
1535 displayRedText
= true;
1536 } else if (hackTime
<86400) {
1537 hackTime
=Math
.floor(hackTime
)+" seconds";
1538 displayRedText
= true;
1539 } else if(hackTime
<31557600) {
1540 hackTime
=Math
.floor(hackTime
/86400)+" days";
1541 displayRedText
= true;
1543 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1545 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1546 if (displayRedText
) {
1547 DOM
.phraseSplitWarn
.addClass("text-danger");
1549 DOM
.phraseSplitWarn
.removeClass("text-danger");
1553 function isUsingOwnEntropy() {
1554 return DOM
.useEntropy
.prop("checked");
1557 function setMnemonicFromEntropy() {
1558 clearEntropyFeedback();
1559 // Get entropy value
1560 var entropyStr
= DOM
.entropy
.val();
1561 // Work out minimum base for entropy
1563 if (entropyTypeAutoDetect
) {
1564 entropy
= Entropy
.fromString(entropyStr
);
1567 let base
= DOM
.entropyTypeInputs
.filter(":checked").val();
1568 entropy
= Entropy
.fromString(entropyStr
, base
);
1570 if (entropy
.binaryStr
.length
== 0) {
1573 // Show entropy details
1574 showEntropyFeedback(entropy
);
1575 // Use entropy hash if not using raw entropy
1576 var bits
= entropy
.binaryStr
;
1577 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1578 if (mnemonicLength
!= "raw") {
1579 // Get bits by hashing entropy with SHA256
1580 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1581 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1582 bits
= BigInteger
.parse(hex
, 16).toString(2);
1583 while (bits
.length
% 256 != 0) {
1586 // Truncate hash to suit number of words
1587 mnemonicLength
= parseInt(mnemonicLength
);
1588 var numberOfBits
= 32 * mnemonicLength
/ 3;
1589 bits
= bits
.substring(0, numberOfBits
);
1590 // show warning for weak entropy override
1591 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1592 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1595 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1599 // hide warning for weak entropy override
1600 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1602 // Discard trailing entropy
1603 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1604 var start
= bits
.length
- bitsToUse
;
1605 var binaryStr
= bits
.substring(start
);
1606 // Convert entropy string to numeric array
1607 var entropyArr
= [];
1608 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1609 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1610 var entropyByte
= parseInt(byteAsBits
, 2);
1611 entropyArr
.push(entropyByte
)
1613 // Convert entropy array to mnemonic
1614 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1615 // Set the mnemonic in the UI
1616 DOM
.phrase
.val(phrase
);
1617 writeSplitPhrase(phrase
);
1618 // Show the word indexes
1620 // Show the checksum
1624 function clearEntropyFeedback() {
1625 DOM
.entropyCrackTime
.text("...");
1626 DOM
.entropyType
.text("");
1627 DOM
.entropyWordCount
.text("0");
1628 DOM
.entropyEventCount
.text("0");
1629 DOM
.entropyBitsPerEvent
.text("0");
1630 DOM
.entropyBits
.text("0");
1631 DOM
.entropyFiltered
.html(" ");
1632 DOM
.entropyBinary
.html(" ");
1635 function showEntropyFeedback(entropy
) {
1636 var numberOfBits
= entropy
.binaryStr
.length
;
1637 var timeToCrack
= "unknown";
1639 var z
= zxcvbn(entropy
.base
.parts
.join(""));
1640 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1641 if (z
.feedback
.warning
!= "") {
1642 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1646 console
.log("Error detecting entropy strength with zxcvbn:");
1649 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1650 DOM
.entropyTypeInputs
.attr("checked", false);
1651 DOM
.entropyTypeInputs
.filter("[value='" + entropyTypeStr
+ "']").attr("checked", true);
1652 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1653 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1654 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1655 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1656 DOM
.entropyType
.text(entropyTypeStr
);
1657 DOM
.entropyCrackTime
.text(timeToCrack
);
1658 DOM
.entropyEventCount
.text(entropy
.base
.ints
.length
);
1659 DOM
.entropyBits
.text(numberOfBits
);
1660 DOM
.entropyWordCount
.text(wordCount
);
1661 DOM
.entropyBinary
.text(spacedBinaryStr
);
1662 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1663 // detect and warn of filtering
1664 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1665 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1666 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1668 DOM
.entropyFilterWarning
.removeClass('hidden');
1671 DOM
.entropyFilterWarning
.addClass('hidden');
1675 function getEntropyTypeStr(entropy
) {
1676 var typeStr
= entropy
.base
.str
;
1677 // Add some detail if these are cards
1678 if (entropy
.base
.asInt
== 52) {
1679 var cardDetail
= []; // array of message strings
1680 // Detect duplicates
1682 var dupeTracker
= {};
1683 for (var i
=0; i
<entropy
.base
.parts
.length
; i
++) {
1684 var card
= entropy
.base
.parts
[i
];
1685 var cardUpper
= card
.toUpperCase();
1686 if (cardUpper
in dupeTracker
) {
1689 dupeTracker
[cardUpper
] = true;
1691 if (dupes
.length
> 0) {
1692 var dupeWord
= "duplicates";
1693 if (dupes
.length
== 1) {
1694 dupeWord
= "duplicate";
1696 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1697 if (dupes
.length
> 3) {
1700 cardDetail
.push(msg
);
1703 var uniqueCards
= [];
1704 for (var uniqueCard
in dupeTracker
) {
1705 uniqueCards
.push(uniqueCard
);
1707 if (uniqueCards
.length
== 52) {
1708 cardDetail
.unshift("full deck");
1710 // Detect missing cards
1711 var values
= "A23456789TJQK";
1713 var missingCards
= [];
1714 for (var i
=0; i
<suits
.length
; i
++) {
1715 for (var j
=0; j
<values
.length
; j
++) {
1716 var card
= values
[j
] + suits
[i
];
1717 if (!(card
in dupeTracker
)) {
1718 missingCards
.push(card
);
1722 // Display missing cards if six or less, ie clearly going for full deck
1723 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1724 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1725 if (missingCards
.length
> 3) {
1728 cardDetail
.push(msg
);
1730 // Add card details to typeStr
1731 if (cardDetail
.length
> 0) {
1732 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1738 function setQrEvents(els
) {
1739 els
.on("mouseenter", createQr
);
1740 els
.on("mouseleave", destroyQr
);
1741 els
.on("click", toggleQr
);
1744 function createQr(e
) {
1745 var content
= e
.target
.textContent
|| e
.target
.value
;
1753 DOM
.qrImage
.append(qrEl
);
1755 DOM
.qrHider
.addClass("hidden");
1758 DOM
.qrHider
.removeClass("hidden");
1760 DOM
.qrContainer
.removeClass("hidden");
1764 function destroyQr() {
1765 DOM
.qrImage
.text("");
1766 DOM
.qrContainer
.addClass("hidden");
1769 function toggleQr() {
1771 DOM
.qrHider
.toggleClass("hidden");
1772 DOM
.qrHint
.toggleClass("hidden");
1775 function bip44TabSelected() {
1776 return DOM
.bip44tab
.hasClass("active");
1779 function bip32TabSelected() {
1780 return DOM
.bip32tab
.hasClass("active");
1783 function networkIsEthereum() {
1784 var name
= networks
[DOM
.network
.val()].name
;
1785 return (name
== "ETH - Ethereum")
1786 || (name
== "ETC - Ethereum Classic")
1787 || (name
== "EWT - EnergyWeb")
1788 || (name
== "PIRL - Pirl")
1789 || (name
== "MIX - MIX")
1790 || (name
== "MUSIC - Musicoin")
1791 || (name
== "POA - Poa")
1792 || (name
== "EXP - Expanse")
1793 || (name
== "CLO - Callisto")
1794 || (name
== "DXN - DEXON")
1795 || (name
== "ELLA - Ellaism")
1796 || (name
== "ESN - Ethersocial Network")
1797 || (name
== "VET - VeChain")
1800 function networkHasSegwit() {
1802 if ("baseNetwork" in network
) {
1803 n
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1805 // check if only p2wpkh params are required
1806 if (p2wpkhSelected()) {
1807 return "p2wpkh" in n
;
1809 // check if only p2wpkh-in-p2sh params are required
1810 else if (p2wpkhInP2shSelected()) {
1811 return "p2wpkhInP2sh" in n
;
1813 // require both if it's unclear which params are required
1814 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
1817 function bip49TabSelected() {
1818 return DOM
.bip49tab
.hasClass("active");
1821 function bip84TabSelected() {
1822 return DOM
.bip84tab
.hasClass("active");
1825 function bip141TabSelected() {
1826 return DOM
.bip141tab
.hasClass("active");
1829 function setHdCoin(coinValue
) {
1830 DOM
.bip44coin
.val(coinValue
);
1831 DOM
.bip49coin
.val(coinValue
);
1832 DOM
.bip84coin
.val(coinValue
);
1835 function showSegwitAvailable() {
1836 DOM
.bip49unavailable
.addClass("hidden");
1837 DOM
.bip49available
.removeClass("hidden");
1838 DOM
.bip84unavailable
.addClass("hidden");
1839 DOM
.bip84available
.removeClass("hidden");
1840 DOM
.bip141unavailable
.addClass("hidden");
1841 DOM
.bip141available
.removeClass("hidden");
1844 function showSegwitUnavailable() {
1845 DOM
.bip49available
.addClass("hidden");
1846 DOM
.bip49unavailable
.removeClass("hidden");
1847 DOM
.bip84available
.addClass("hidden");
1848 DOM
.bip84unavailable
.removeClass("hidden");
1849 DOM
.bip141available
.addClass("hidden");
1850 DOM
.bip141unavailable
.removeClass("hidden");
1853 function adjustNetworkForSegwit() {
1854 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1855 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1857 // See https://github.com/iancoleman/bip39/issues/125
1858 var segwitNetworks
= null;
1859 // if a segwit network is alread selected, need to use base network to
1860 // look up new parameters
1861 if ("baseNetwork" in network
) {
1862 network
= bitcoinjs
.bitcoin
.networks
[network
.baseNetwork
];
1864 // choose the right segwit params
1865 if (p2wpkhSelected() && "p2wpkh" in network
) {
1866 network
= network
.p2wpkh
;
1868 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
1869 network
= network
.p2wpkhInP2sh
;
1871 else if (p2wshSelected() && "p2wsh" in network
) {
1872 network
= network
.p2wsh
;
1874 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network
) {
1875 network
= network
.p2wshInP2sh
;
1879 function lastIndexInTable() {
1880 var pathText
= DOM
.addresses
.find(".index").last().text();
1881 var pathBits
= pathText
.split("/");
1882 var lastBit
= pathBits
[pathBits
.length
-1];
1883 var lastBitClean
= lastBit
.replace("'", "");
1884 return parseInt(lastBitClean
);
1887 function uint8ArrayToHex(a
) {
1889 for (var i
=0; i
<a
.length
; i
++) {
1890 var h
= a
[i
].toString(16);
1891 while (h
.length
< 2) {
1899 function showWordIndexes() {
1900 var phrase
= DOM
.phrase
.val();
1901 var words
= phraseToWordArray(phrase
);
1902 var wordIndexes
= [];
1903 var language
= getLanguage();
1904 for (var i
=0; i
<words
.length
; i
++) {
1905 var word
= words
[i
];
1906 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1907 wordIndexes
.push(wordIndex
);
1909 var wordIndexesStr
= wordIndexes
.join(", ");
1910 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
1913 function showChecksum() {
1914 var phrase
= DOM
.phrase
.val();
1915 var words
= phraseToWordArray(phrase
);
1916 var checksumBitlength
= words
.length
/ 3;
1919 var language
= getLanguage();
1920 for (var i
=words
.length
-1; i
>=0; i
--) {
1921 var word
= words
[i
];
1922 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
1923 var wordBinary
= wordIndex
.toString(2);
1924 while (wordBinary
.length
< 11) {
1925 wordBinary
= "0" + wordBinary
;
1927 var binaryStr
= wordBinary
+ binaryStr
;
1928 if (binaryStr
.length
>= checksumBitlength
) {
1929 var start
= binaryStr
.length
- checksumBitlength
;
1930 var end
= binaryStr
.length
;
1931 checksum
= binaryStr
.substring(start
, end
);
1932 // add spaces so the last group is 11 bits, not the first
1933 checksum
= checksum
.split("").reverse().join("")
1934 checksum
= addSpacesEveryElevenBits(checksum
);
1935 checksum
= checksum
.split("").reverse().join("")
1939 DOM
.entropyChecksum
.text(checksum
);
1942 function updateCsv() {
1943 var tableCsv
= "path,address,public key,private key\n";
1944 var rows
= DOM
.addresses
.find("tr");
1945 for (var i
=0; i
<rows
.length
; i
++) {
1946 var row
= $(rows
[i
]);
1947 var cells
= row
.find("td");
1948 for (var j
=0; j
<cells
.length
; j
++) {
1949 var cell
= $(cells
[j
]);
1950 if (!cell
.children().hasClass("invisible")) {
1951 tableCsv
= tableCsv
+ cell
.text();
1953 if (j
!= cells
.length
- 1) {
1954 tableCsv
= tableCsv
+ ",";
1957 tableCsv
= tableCsv
+ "\n";
1959 DOM
.csv
.val(tableCsv
);
1962 function addSpacesEveryElevenBits(binaryStr
) {
1963 return binaryStr
.match(/.{1,11}/g).join(" ");
1968 name: "AC - Asiacoin",
1969 onSelect: function() {
1970 network
= bitcoinjs
.bitcoin
.networks
.asiacoin
;
1975 name: "ACC - Adcoin",
1976 onSelect: function() {
1977 network
= bitcoinjs
.bitcoin
.networks
.adcoin
;
1982 name: "ARYA - Aryacoin",
1983 onSelect: function() {
1984 network
= bitcoinjs
.bitcoin
.networks
.aryacoin
;
1989 name: "AUR - Auroracoin",
1990 onSelect: function() {
1991 network
= bitcoinjs
.bitcoin
.networks
.auroracoin
;
1997 onSelect: function() {
1998 network
= bitcoinjs
.bitcoin
.networks
.axe
;
2003 name: "ANON - ANON",
2004 onSelect: function() {
2005 network
= bitcoinjs
.bitcoin
.networks
.anon
;
2010 name: "BOLI - Bolivarcoin",
2011 onSelect: function() {
2012 network
= bitcoinjs
.bitcoin
.networks
.bolivarcoin
;
2017 name: "BCA - Bitcoin Atom",
2018 onSelect: function() {
2019 network
= bitcoinjs
.bitcoin
.networks
.atom
;
2024 name: "BCH - Bitcoin Cash",
2025 onSelect: function() {
2026 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2031 name: "BEET - Beetlecoin",
2032 onSelect: function() {
2033 network
= bitcoinjs
.bitcoin
.networks
.beetlecoin
;
2038 name: "BELA - Belacoin",
2039 onSelect: function() {
2040 network
= bitcoinjs
.bitcoin
.networks
.belacoin
;
2045 name: "BLK - BlackCoin",
2046 onSelect: function() {
2047 network
= bitcoinjs
.bitcoin
.networks
.blackcoin
;
2052 name: "BND - Blocknode",
2053 onSelect: function() {
2054 network
= bitcoinjs
.bitcoin
.networks
.blocknode
;
2059 name: "tBND - Blocknode Testnet",
2060 onSelect: function() {
2061 network
= bitcoinjs
.bitcoin
.networks
.blocknode_testnet
;
2066 name: "BRIT - Britcoin",
2067 onSelect: function() {
2068 network
= bitcoinjs
.bitcoin
.networks
.britcoin
;
2073 name: "BSD - Bitsend",
2074 onSelect: function() {
2075 network
= bitcoinjs
.bitcoin
.networks
.bitsend
;
2080 name: "BST - BlockStamp",
2081 onSelect: function() {
2082 network
= bitcoinjs
.bitcoin
.networks
.blockstamp
;
2088 onSelect: function() {
2089 network
= bitcoinjs
.bitcoin
.networks
.bata
;
2094 name: "BTC - Bitcoin",
2095 onSelect: function() {
2096 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2101 name: "BTC - Bitcoin Testnet",
2102 onSelect: function() {
2103 network
= bitcoinjs
.bitcoin
.networks
.testnet
;
2108 name: "BITG - Bitcoin Green",
2109 onSelect: function() {
2110 network
= bitcoinjs
.bitcoin
.networks
.bitcoingreen
;
2115 name: "BTCP - Bitcoin Private",
2116 onSelect: function() {
2117 network
= bitcoinjs
.bitcoin
.networks
.bitcoinprivate
;
2122 name: "BSV - BitcoinSV",
2123 onSelect: function() {
2124 network
= bitcoinjs
.bitcoin
.networks
.bitcoinsv
;
2129 name: "BTCZ - Bitcoinz",
2130 onSelect: function() {
2131 network
= bitcoinjs
.bitcoin
.networks
.bitcoinz
;
2136 name: "BTDX - BitCloud",
2137 onSelect: function() {
2138 network
= bitcoinjs
.bitcoin
.networks
.bitcloud
;
2143 name: "BTG - Bitcoin Gold",
2144 onSelect: function() {
2145 network
= bitcoinjs
.bitcoin
.networks
.bgold
;
2150 name: "BTX - Bitcore",
2151 onSelect: function() {
2152 network
= bitcoinjs
.bitcoin
.networks
.bitcore
;
2157 name: "CCN - Cannacoin",
2158 onSelect: function() {
2159 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2164 name: "CESC - Cryptoescudo",
2165 onSelect: function() {
2166 network
= bitcoinjs
.bitcoin
.networks
.cannacoin
;
2171 name: "CDN - Canadaecoin",
2172 onSelect: function() {
2173 network
= bitcoinjs
.bitcoin
.networks
.canadaecoin
;
2178 name: "CLAM - Clams",
2179 onSelect: function() {
2180 network
= bitcoinjs
.bitcoin
.networks
.clam
;
2185 name: "CLO - Callisto",
2186 segwitAvailable: false,
2187 onSelect: function() {
2188 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2193 name: "CLUB - Clubcoin",
2194 onSelect: function() {
2195 network
= bitcoinjs
.bitcoin
.networks
.clubcoin
;
2200 name: "CMP - Compcoin",
2201 onSelect: function() {
2202 network
= bitcoinjs
.bitcoin
.networks
.compcoin
;
2207 name: "CPU - CPUchain",
2208 onSelect: function() {
2209 network
= bitcoinjs
.bitcoin
.networks
.cpuchain
;
2214 name: "CRAVE - Crave",
2215 onSelect: function() {
2216 network
= bitcoinjs
.bitcoin
.networks
.crave
;
2221 name: "CRW - Crown (Legacy)",
2222 onSelect: function() {
2223 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2228 name: "CRW - Crown",
2229 onSelect: function() {
2230 network
= bitcoinjs
.bitcoin
.networks
.crown
;
2235 name: "CSC - CasinoCoin",
2236 onSelect: function() {
2237 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2242 name: "DASH - Dash",
2243 onSelect: function() {
2244 network
= bitcoinjs
.bitcoin
.networks
.dash
;
2249 name: "DASH - Dash Testnet",
2250 onSelect: function() {
2251 network
= bitcoinjs
.bitcoin
.networks
.dashtn
;
2256 name: "DFC - Defcoin",
2257 onSelect: function() {
2258 network
= bitcoinjs
.bitcoin
.networks
.defcoin
;
2263 name: "DGB - Digibyte",
2264 onSelect: function() {
2265 network
= bitcoinjs
.bitcoin
.networks
.digibyte
;
2270 name: "DGC - Digitalcoin",
2271 onSelect: function() {
2272 network
= bitcoinjs
.bitcoin
.networks
.digitalcoin
;
2277 name: "DMD - Diamond",
2278 onSelect: function() {
2279 network
= bitcoinjs
.bitcoin
.networks
.diamond
;
2284 name: "DNR - Denarius",
2285 onSelect: function() {
2286 network
= bitcoinjs
.bitcoin
.networks
.denarius
;
2291 name: "DOGE - Dogecoin",
2292 onSelect: function() {
2293 network
= bitcoinjs
.bitcoin
.networks
.dogecoin
;
2298 name: "DOGEt - Dogecoin Testnet",
2299 onSelect: function() {
2300 network
= bitcoinjs
.bitcoin
.networks
.dogecointestnet
;
2305 name: "DXN - DEXON",
2306 onSelect: function() {
2307 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2312 name: "ECN - Ecoin",
2313 onSelect: function() {
2314 network
= bitcoinjs
.bitcoin
.networks
.ecoin
;
2319 name: "EDRC - Edrcoin",
2320 onSelect: function() {
2321 network
= bitcoinjs
.bitcoin
.networks
.edrcoin
;
2326 name: "EFL - Egulden",
2327 onSelect: function() {
2328 network
= bitcoinjs
.bitcoin
.networks
.egulden
;
2333 name: "ELA - Elastos",
2334 onSelect: function () {
2335 network
= bitcoinjs
.bitcoin
.networks
.elastos
;
2340 name: "ELLA - Ellaism",
2341 segwitAvailable: false,
2342 onSelect: function() {
2343 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2348 name: "EMC2 - Einsteinium",
2349 onSelect: function() {
2350 network
= bitcoinjs
.bitcoin
.networks
.einsteinium
;
2355 name: "ERC - Europecoin",
2356 onSelect: function() {
2357 network
= bitcoinjs
.bitcoin
.networks
.europecoin
;
2362 name: "EOS - EOSIO",
2363 onSelect: function() {
2364 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2369 name: "ESN - Ethersocial Network",
2370 segwitAvailable: false,
2371 onSelect: function() {
2372 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2377 name: "ETC - Ethereum Classic",
2378 segwitAvailable: false,
2379 onSelect: function() {
2380 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2385 name: "ETH - Ethereum",
2386 onSelect: function() {
2387 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2392 name: "EWT - EnergyWeb",
2393 onSelect: function() {
2394 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2399 name: "EXCL - Exclusivecoin",
2400 onSelect: function() {
2401 network
= bitcoinjs
.bitcoin
.networks
.exclusivecoin
;
2406 name: "EXCC - ExchangeCoin",
2407 onSelect: function() {
2408 network
= bitcoinjs
.bitcoin
.networks
.exchangecoin
;
2413 name: "EXP - Expanse",
2414 segwitAvailable: false,
2415 onSelect: function() {
2416 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2422 onSelect: function() {
2423 network
= bitcoinjs
.bitcoin
.networks
.fix
;
2428 name: "FIX - FIX Testnet",
2429 onSelect: function() {
2430 network
= bitcoinjs
.bitcoin
.networks
.fixtestnet
;
2435 name: "FJC - Fujicoin",
2436 onSelect: function() {
2437 network
= bitcoinjs
.bitcoin
.networks
.fujicoin
;
2442 name: "FLASH - Flashcoin",
2443 onSelect: function() {
2444 network
= bitcoinjs
.bitcoin
.networks
.flashcoin
;
2449 name: "FRST - Firstcoin",
2450 onSelect: function() {
2451 network
= bitcoinjs
.bitcoin
.networks
.firstcoin
;
2456 name: "FTC - Feathercoin",
2457 onSelect: function() {
2458 network
= bitcoinjs
.bitcoin
.networks
.feathercoin
;
2463 name: "GAME - GameCredits",
2464 onSelect: function() {
2465 network
= bitcoinjs
.bitcoin
.networks
.game
;
2470 name: "GBX - Gobyte",
2471 onSelect: function() {
2472 network
= bitcoinjs
.bitcoin
.networks
.gobyte
;
2477 name: "GCR - GCRCoin",
2478 onSelect: function() {
2479 network
= bitcoinjs
.bitcoin
.networks
.gcr
;
2484 name: "GRC - Gridcoin",
2485 onSelect: function() {
2486 network
= bitcoinjs
.bitcoin
.networks
.gridcoin
;
2491 name: "GRS - Groestlcoin",
2492 onSelect: function() {
2493 network
= bitcoinjs
.bitcoin
.networks
.groestlcoin
;
2498 name: "GRS - Groestlcoin Testnet",
2499 onSelect: function() {
2500 network
= bitcoinjs
.bitcoin
.networks
.groestlcointestnet
;
2505 name: "HNC - Helleniccoin",
2506 onSelect: function() {
2507 network
= bitcoinjs
.bitcoin
.networks
.helleniccoin
;
2512 name: "HUSH - Hush (Legacy)",
2513 onSelect: function() {
2514 network
= bitcoinjs
.bitcoin
.networks
.hush
;
2519 name: "HUSH - Hush3",
2520 onSelect: function() {
2521 network
= bitcoinjs
.bitcoin
.networks
.hush3
;
2526 name: "INSN - Insane",
2527 onSelect: function() {
2528 network
= bitcoinjs
.bitcoin
.networks
.insane
;
2534 onSelect: function() {
2535 network
= bitcoinjs
.bitcoin
.networks
.iop
;
2540 name: "IXC - Ixcoin",
2541 onSelect: function() {
2542 network
= bitcoinjs
.bitcoin
.networks
.ixcoin
;
2547 name: "JBS - Jumbucks",
2548 onSelect: function() {
2549 network
= bitcoinjs
.bitcoin
.networks
.jumbucks
;
2554 name: "KMD - Komodo",
2555 bip49available: false,
2556 onSelect: function() {
2557 network
= bitcoinjs
.bitcoin
.networks
.komodo
;
2562 name: "KOBO - Kobocoin",
2563 bip49available: false,
2564 onSelect: function() {
2565 network
= bitcoinjs
.bitcoin
.networks
.kobocoin
;
2570 name: "LBC - Library Credits",
2571 onSelect: function() {
2572 network
= bitcoinjs
.bitcoin
.networks
.lbry
;
2577 name: "LCC - Litecoincash",
2578 onSelect: function() {
2579 network
= bitcoinjs
.bitcoin
.networks
.litecoincash
;
2584 name: "LDCN - Landcoin",
2585 onSelect: function() {
2586 network
= bitcoinjs
.bitcoin
.networks
.landcoin
;
2591 name: "LINX - Linx",
2592 onSelect: function() {
2593 network
= bitcoinjs
.bitcoin
.networks
.linx
;
2598 name: "LKR - Lkrcoin",
2599 segwitAvailable: false,
2600 onSelect: function() {
2601 network
= bitcoinjs
.bitcoin
.networks
.lkrcoin
;
2606 name: "LTC - Litecoin",
2607 onSelect: function() {
2608 network
= bitcoinjs
.bitcoin
.networks
.litecoin
;
2610 DOM
.litecoinLtubContainer
.removeClass("hidden");
2614 name: "LTCt - Litecoin Testnet",
2615 onSelect: function() {
2616 network
= bitcoinjs
.bitcoin
.networks
.litecointestnet
;
2618 DOM
.litecoinLtubContainer
.removeClass("hidden");
2622 name: "LTZ - LitecoinZ",
2623 onSelect: function() {
2624 network
= bitcoinjs
.bitcoin
.networks
.litecoinz
;
2629 name: "LYNX - Lynx",
2630 onSelect: function() {
2631 network
= bitcoinjs
.bitcoin
.networks
.lynx
;
2636 name: "MAZA - Maza",
2637 onSelect: function() {
2638 network
= bitcoinjs
.bitcoin
.networks
.maza
;
2643 name: "MEC - Megacoin",
2644 onSelect: function() {
2645 network
= bitcoinjs
.bitcoin
.networks
.megacoin
;
2651 segwitAvailable: false,
2652 onSelect: function() {
2653 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2658 name: "MNX - Minexcoin",
2659 onSelect: function() {
2660 network
= bitcoinjs
.bitcoin
.networks
.minexcoin
;
2665 name: "MONA - Monacoin",
2666 onSelect: function() {
2667 network
= bitcoinjs
.bitcoin
.networks
.monacoin
,
2672 name: "MONK - Monkey Project",
2673 onSelect: function() {
2674 network
= bitcoinjs
.bitcoin
.networks
.monkeyproject
,
2679 name: "MUSIC - Musicoin",
2680 segwitAvailable: false,
2681 onSelect: function() {
2682 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2687 name: "NAV - Navcoin",
2688 onSelect: function() {
2689 network
= bitcoinjs
.bitcoin
.networks
.navcoin
;
2694 name: "NAS - Nebulas",
2695 onSelect: function() {
2696 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2701 name: "NEBL - Neblio",
2702 onSelect: function() {
2703 network
= bitcoinjs
.bitcoin
.networks
.neblio
;
2708 name: "NEOS - Neoscoin",
2709 onSelect: function() {
2710 network
= bitcoinjs
.bitcoin
.networks
.neoscoin
;
2715 name: "NIX - NIX Platform",
2716 onSelect: function() {
2717 network
= bitcoinjs
.bitcoin
.networks
.nix
;
2722 name: "NLG - Gulden",
2723 onSelect: function() {
2724 network
= bitcoinjs
.bitcoin
.networks
.gulden
;
2729 name: "NMC - Namecoin",
2730 onSelect: function() {
2731 network
= bitcoinjs
.bitcoin
.networks
.namecoin
;
2736 name: "NRG - Energi",
2737 onSelect: function() {
2738 network
= bitcoinjs
.bitcoin
.networks
.energi
;
2743 name: "NRO - Neurocoin",
2744 onSelect: function() {
2745 network
= bitcoinjs
.bitcoin
.networks
.neurocoin
;
2750 name: "NSR - Nushares",
2751 onSelect: function() {
2752 network
= bitcoinjs
.bitcoin
.networks
.nushares
;
2757 name: "NYC - Newyorkc",
2758 onSelect: function() {
2759 network
= bitcoinjs
.bitcoin
.networks
.newyorkc
;
2764 name: "NVC - Novacoin",
2765 onSelect: function() {
2766 network
= bitcoinjs
.bitcoin
.networks
.novacoin
;
2771 name: "OK - Okcash",
2772 onSelect: function() {
2773 network
= bitcoinjs
.bitcoin
.networks
.okcash
;
2778 name: "OMNI - Omnicore",
2779 onSelect: function() {
2780 network
= bitcoinjs
.bitcoin
.networks
.omnicore
;
2785 name: "ONION - DeepOnion",
2786 onSelect: function() {
2787 network
= bitcoinjs
.bitcoin
.networks
.deeponion
;
2792 name: "ONX - Onixcoin",
2793 onSelect: function() {
2794 network
= bitcoinjs
.bitcoin
.networks
.onixcoin
;
2799 name: "PHR - Phore",
2800 onSelect: function() {
2801 network
= bitcoinjs
.bitcoin
.networks
.phore
;
2806 name: "PINK - Pinkcoin",
2807 onSelect: function() {
2808 network
= bitcoinjs
.bitcoin
.networks
.pinkcoin
;
2813 name: "PIRL - Pirl",
2814 segwitAvailable: false,
2815 onSelect: function() {
2816 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2821 name: "PIVX - PIVX",
2822 onSelect: function() {
2823 network
= bitcoinjs
.bitcoin
.networks
.pivx
;
2828 name: "PIVX - PIVX Testnet",
2829 onSelect: function() {
2830 network
= bitcoinjs
.bitcoin
.networks
.pivxtestnet
;
2836 segwitAvailable: false,
2837 onSelect: function() {
2838 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
2843 name: "POSW - POSWcoin",
2844 onSelect: function() {
2845 network
= bitcoinjs
.bitcoin
.networks
.poswcoin
;
2850 name: "POT - Potcoin",
2851 onSelect: function() {
2852 network
= bitcoinjs
.bitcoin
.networks
.potcoin
;
2857 name: "PPC - Peercoin",
2858 onSelect: function() {
2859 network
= bitcoinjs
.bitcoin
.networks
.peercoin
;
2864 name: "PRJ - ProjectCoin",
2865 onSelect: function() {
2866 network
= bitcoinjs
.bitcoin
.networks
.projectcoin
;
2871 name: "PSB - Pesobit",
2872 onSelect: function() {
2873 network
= bitcoinjs
.bitcoin
.networks
.pesobit
;
2878 name: "PUT - Putincoin",
2879 onSelect: function() {
2880 network
= bitcoinjs
.bitcoin
.networks
.putincoin
;
2885 name: "RPD - Rapids",
2886 onSelect: function() {
2887 network
= bitcoinjs
.bitcoin
.networks
.rapids
;
2892 name: "RVN - Ravencoin",
2893 onSelect: function() {
2894 network
= bitcoinjs
.bitcoin
.networks
.ravencoin
;
2899 name: "RBY - Rubycoin",
2900 onSelect: function() {
2901 network
= bitcoinjs
.bitcoin
.networks
.rubycoin
;
2906 name: "RDD - Reddcoin",
2907 onSelect: function() {
2908 network
= bitcoinjs
.bitcoin
.networks
.reddcoin
;
2913 name: "RVR - RevolutionVR",
2914 onSelect: function() {
2915 network
= bitcoinjs
.bitcoin
.networks
.revolutionvr
;
2920 name: "SAFE - Safecoin",
2921 onSelect: function() {
2922 network
= bitcoinjs
.bitcoin
.networks
.safecoin
;
2927 name: "SLS - Salus",
2928 onSelect: function() {
2929 network
= bitcoinjs
.bitcoin
.networks
.salus
;
2934 name: "SDC - ShadowCash",
2935 onSelect: function() {
2936 network
= bitcoinjs
.bitcoin
.networks
.shadow
;
2941 name: "SDC - ShadowCash Testnet",
2942 onSelect: function() {
2943 network
= bitcoinjs
.bitcoin
.networks
.shadowtn
;
2948 name: "SLM - Slimcoin",
2949 onSelect: function() {
2950 network
= bitcoinjs
.bitcoin
.networks
.slimcoin
;
2955 name: "SLM - Slimcoin Testnet",
2956 onSelect: function() {
2957 network
= bitcoinjs
.bitcoin
.networks
.slimcointn
;
2962 name: "SLP - Simple Ledger Protocol",
2963 onSelect: function() {
2964 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2969 name: "SLR - Solarcoin",
2970 onSelect: function() {
2971 network
= bitcoinjs
.bitcoin
.networks
.solarcoin
;
2976 name: "SMLY - Smileycoin",
2977 onSelect: function() {
2978 network
= bitcoinjs
.bitcoin
.networks
.smileycoin
;
2983 name: "STASH - Stash",
2984 onSelect: function() {
2985 network
= bitcoinjs
.bitcoin
.networks
.stash
;
2990 name: "STASH - Stash Testnet",
2991 onSelect: function() {
2992 network
= bitcoinjs
.bitcoin
.networks
.stashtn
;
2997 name: "STRAT - Stratis",
2998 onSelect: function() {
2999 network
= bitcoinjs
.bitcoin
.networks
.stratis
;
3004 name: "TSTRAT - Stratis Testnet",
3005 onSelect: function() {
3006 network
= bitcoinjs
.bitcoin
.networks
.stratistest
;
3011 name: "SYS - Syscoin",
3012 onSelect: function() {
3013 network
= bitcoinjs
.bitcoin
.networks
.syscoin
;
3018 name: "THC - Hempcoin",
3019 onSelect: function() {
3020 network
= bitcoinjs
.bitcoin
.networks
.hempcoin
;
3025 name: "THT - Thought",
3026 onSelect: function() {
3027 network
= bitcoinjs
.bitcoin
.networks
.thought
;
3033 onSelect: function() {
3034 network
= bitcoinjs
.bitcoin
.networks
.toa
;
3039 name: "TWINS - TWINS",
3040 onSelect: function() {
3041 network
= bitcoinjs
.bitcoin
.networks
.twins
;
3046 name: "TWINS - TWINS Testnet",
3047 onSelect: function() {
3048 network
= bitcoinjs
.bitcoin
.networks
.twinstestnet
;
3053 name: "USC - Ultimatesecurecash",
3054 onSelect: function() {
3055 network
= bitcoinjs
.bitcoin
.networks
.ultimatesecurecash
;
3060 name: "USNBT - NuBits",
3061 onSelect: function() {
3062 network
= bitcoinjs
.bitcoin
.networks
.nubits
;
3067 name: "UNO - Unobtanium",
3068 onSelect: function() {
3069 network
= bitcoinjs
.bitcoin
.networks
.unobtanium
;
3074 name: "VASH - Vpncoin",
3075 onSelect: function() {
3076 network
= bitcoinjs
.bitcoin
.networks
.vpncoin
;
3081 name: "VET - VeChain",
3082 onSelect: function() {
3083 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3088 name: "VIA - Viacoin",
3089 onSelect: function() {
3090 network
= bitcoinjs
.bitcoin
.networks
.viacoin
;
3095 name: "VIA - Viacoin Testnet",
3096 onSelect: function() {
3097 network
= bitcoinjs
.bitcoin
.networks
.viacointestnet
;
3102 name: "VIVO - Vivo",
3103 onSelect: function() {
3104 network
= bitcoinjs
.bitcoin
.networks
.vivo
;
3109 name: "VTC - Vertcoin",
3110 onSelect: function() {
3111 network
= bitcoinjs
.bitcoin
.networks
.vertcoin
;
3116 name: "WGR - Wagerr",
3117 onSelect: function() {
3118 network
= bitcoinjs
.bitcoin
.networks
.wagerr
;
3123 name: "WC - Wincoin",
3124 onSelect: function() {
3125 network
= bitcoinjs
.bitcoin
.networks
.wincoin
;
3130 name: "XAX - Artax",
3131 onSelect: function() {
3132 network
= bitcoinjs
.bitcoin
.networks
.artax
;
3137 name: "XBC - Bitcoinplus",
3138 onSelect: function() {
3139 network
= bitcoinjs
.bitcoin
.networks
.bitcoinplus
;
3144 name: "XLM - Stellar",
3145 onSelect: function() {
3146 network
= stellarUtil
.dummyNetwork
;
3151 name: "XMY - Myriadcoin",
3152 onSelect: function() {
3153 network
= bitcoinjs
.bitcoin
.networks
.myriadcoin
;
3158 name: "XRP - Ripple",
3159 onSelect: function() {
3160 network
= bitcoinjs
.bitcoin
.networks
.bitcoin
;
3165 name: "XVC - Vcash",
3166 onSelect: function() {
3167 network
= bitcoinjs
.bitcoin
.networks
.vcash
;
3172 name: "XVG - Verge",
3173 onSelect: function() {
3174 network
= bitcoinjs
.bitcoin
.networks
.verge
;
3179 name: "XUEZ - Xuez",
3180 segwitAvailable: false,
3181 onSelect: function() {
3182 network
= bitcoinjs
.bitcoin
.networks
.xuez
;
3187 name: "XWC - Whitecoin",
3188 onSelect: function() {
3189 network
= bitcoinjs
.bitcoin
.networks
.whitecoin
;
3194 name: "XZC - Zcoin",
3195 onSelect: function() {
3196 network
= bitcoinjs
.bitcoin
.networks
.zcoin
;
3201 name: "ZCL - Zclassic",
3202 onSelect: function() {
3203 network
= bitcoinjs
.bitcoin
.networks
.zclassic
;
3208 name: "ZEC - Zcash",
3209 onSelect: function() {
3210 network
= bitcoinjs
.bitcoin
.networks
.zcash
;
3215 name: "ZEN - Horizen",
3216 onSelect: function() {
3217 network
= bitcoinjs
.bitcoin
.networks
.zencash
;
3225 name: "Bitcoin Core",
3226 onSelect: function() {
3227 DOM
.bip32path
.val("m/0'/0'");
3228 DOM
.hardenedAddresses
.prop('checked', true);
3232 name: "blockchain.info",
3233 onSelect: function() {
3234 DOM
.bip32path
.val("m/44'/0'/0'");
3235 DOM
.hardenedAddresses
.prop('checked', false);
3239 name: "MultiBit HD",
3240 onSelect: function() {
3241 DOM
.bip32path
.val("m/0'/0");
3242 DOM
.hardenedAddresses
.prop('checked', false);
3246 name: "Coinomi, Ledger",
3247 onSelect: function() {
3248 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3249 DOM
.hardenedAddresses
.prop('checked', false);
3254 // ELA - Elastos functions - begin
3255 function displayBip44InfoForELA() {
3260 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3261 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3263 // Calculate the account extended keys
3264 var accountXprv
= elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3265 var accountXpub
= elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3267 // Display the extended keys
3268 DOM
.bip44accountXprv
.val(accountXprv
);
3269 DOM
.bip44accountXpub
.val(accountXpub
);
3272 function displayBip32InfoForELA() {
3277 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3278 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3279 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3281 DOM
.extendedPrivKey
.val(elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3282 DOM
.extendedPubKey
.val(elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3284 // Display the addresses and privkeys
3285 clearAddressesList();
3286 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3287 displayAddresses(0, initialAddressCount
);
3290 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3295 var publicKey
= elastosjs
.getDerivedPublicKey(elastosjs
.getMasterPublicKey(seed
), change
, index
);
3297 privateKey: elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3298 publicKey: publicKey
,
3299 address: elastosjs
.getAddress(publicKey
.toString('hex'))
3302 // ELA - Elastos functions - end