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
= libs
.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 seedChangedTimeoutEvent
= null;
23 var rootKeyChangedTimeoutEvent
= null;
25 var generationProcesses
= [];
28 DOM
.privacyScreenToggle
= $(".privacy-screen-toggle");
29 DOM
.network
= $(".network");
30 DOM
.bip32Client
= $("#bip32-client");
31 DOM
.phraseNetwork
= $("#network-phrase");
32 DOM
.useEntropy
= $(".use-entropy");
33 DOM
.entropyContainer
= $(".entropy-container");
34 DOM
.entropy
= $(".entropy");
35 DOM
.entropyFiltered
= DOM
.entropyContainer
.find(".filtered");
36 DOM
.entropyType
= DOM
.entropyContainer
.find(".type");
37 DOM
.entropyTypeInputs
= DOM
.entropyContainer
.find("input[name='entropy-type']");
38 DOM
.entropyCrackTime
= DOM
.entropyContainer
.find(".crack-time");
39 DOM
.entropyEventCount
= DOM
.entropyContainer
.find(".event-count");
40 DOM
.entropyBits
= DOM
.entropyContainer
.find(".bits");
41 DOM
.entropyBitsPerEvent
= DOM
.entropyContainer
.find(".bits-per-event");
42 DOM
.entropyWordCount
= DOM
.entropyContainer
.find(".word-count");
43 DOM
.entropyBinary
= DOM
.entropyContainer
.find(".binary");
44 DOM
.entropyWordIndexes
= DOM
.entropyContainer
.find(".word-indexes");
45 DOM
.entropyChecksum
= DOM
.entropyContainer
.find(".checksum");
46 DOM
.entropyMnemonicLength
= DOM
.entropyContainer
.find(".mnemonic-length");
47 DOM
.entropyWeakEntropyOverrideWarning
= DOM
.entropyContainer
.find(".weak-entropy-override-warning");
48 DOM
.entropyFilterWarning
= DOM
.entropyContainer
.find(".filter-warning");
49 DOM
.phrase
= $(".phrase");
50 DOM
.splitMnemonic
= $(".splitMnemonic");
51 DOM
.showSplitMnemonic
= $(".showSplitMnemonic");
52 DOM
.phraseSplit
= $(".phraseSplit");
53 DOM
.phraseSplitWarn
= $(".phraseSplitWarn");
54 DOM
.passphrase
= $(".passphrase");
55 DOM
.generateContainer
= $(".generate-container");
56 DOM
.generate
= $(".generate");
57 DOM
.seed
= $(".seed");
58 DOM
.rootKey
= $(".root-key");
59 DOM
.litecoinLtubContainer
= $(".litecoin-ltub-container");
60 DOM
.litecoinUseLtub
= $(".litecoin-use-ltub");
61 DOM
.extendedPrivKey
= $(".extended-priv-key");
62 DOM
.extendedPubKey
= $(".extended-pub-key");
63 DOM
.bip32tab
= $("#bip32-tab");
64 DOM
.bip44tab
= $("#bip44-tab");
65 DOM
.bip49tab
= $("#bip49-tab");
66 DOM
.bip84tab
= $("#bip84-tab");
67 DOM
.bip141tab
= $("#bip141-tab");
68 DOM
.bip32panel
= $("#bip32");
69 DOM
.bip44panel
= $("#bip44");
70 DOM
.bip49panel
= $("#bip49");
71 DOM
.bip32path
= $("#bip32-path");
72 DOM
.bip44path
= $("#bip44-path");
73 DOM
.bip44purpose
= $("#bip44 .purpose");
74 DOM
.bip44coin
= $("#bip44 .coin");
75 DOM
.bip44account
= $("#bip44 .account");
76 DOM
.bip44accountXprv
= $("#bip44 .account-xprv");
77 DOM
.bip44accountXpub
= $("#bip44 .account-xpub");
78 DOM
.bip44change
= $("#bip44 .change");
79 DOM
.bip49unavailable
= $("#bip49 .unavailable");
80 DOM
.bip49available
= $("#bip49 .available");
81 DOM
.bip49path
= $("#bip49-path");
82 DOM
.bip49purpose
= $("#bip49 .purpose");
83 DOM
.bip49coin
= $("#bip49 .coin");
84 DOM
.bip49account
= $("#bip49 .account");
85 DOM
.bip49accountXprv
= $("#bip49 .account-xprv");
86 DOM
.bip49accountXpub
= $("#bip49 .account-xpub");
87 DOM
.bip49change
= $("#bip49 .change");
88 DOM
.bip84unavailable
= $("#bip84 .unavailable");
89 DOM
.bip84available
= $("#bip84 .available");
90 DOM
.bip84path
= $("#bip84-path");
91 DOM
.bip84purpose
= $("#bip84 .purpose");
92 DOM
.bip84coin
= $("#bip84 .coin");
93 DOM
.bip84account
= $("#bip84 .account");
94 DOM
.bip84accountXprv
= $("#bip84 .account-xprv");
95 DOM
.bip84accountXpub
= $("#bip84 .account-xpub");
96 DOM
.bip84change
= $("#bip84 .change");
97 DOM
.bip85
= $('.bip85');
98 DOM
.showBip85
= $('.showBip85');
99 DOM
.bip85Field
= $('.bip85Field');
100 DOM
.bip85application
= $('#bip85-application');
101 DOM
.bip85mnemonicLanguage
= $('#bip85-mnemonic-language');
102 DOM
.bip85mnemonicLanguageInput
= $('.bip85-mnemonic-language-input');
103 DOM
.bip85mnemonicLength
= $('#bip85-mnemonic-length');
104 DOM
.bip85mnemonicLengthInput
= $('.bip85-mnemonic-length-input');
105 DOM
.bip85index
= $('#bip85-index');
106 DOM
.bip85indexInput
= $('.bip85-index-input');
107 DOM
.bip85bytes
= $('#bip85-bytes');
108 DOM
.bip85bytesInput
= $('.bip85-bytes-input');
109 DOM
.bip141unavailable
= $("#bip141 .unavailable");
110 DOM
.bip141available
= $("#bip141 .available");
111 DOM
.bip141path
= $("#bip141-path");
112 DOM
.bip141semantics
= $(".bip141-semantics");
113 DOM
.generatedStrength
= $(".generate-container .strength");
114 DOM
.generatedStrengthWarning
= $(".generate-container .warning");
115 DOM
.hardenedAddresses
= $(".hardened-addresses");
116 DOM
.bitcoinCashAddressTypeContainer
= $(".bch-addr-type-container");
117 DOM
.bitcoinCashAddressType
= $("[name=bch-addr-type]")
118 DOM
.useBip38
= $(".use-bip38");
119 DOM
.bip38Password
= $(".bip38-password");
120 DOM
.addresses
= $(".addresses");
121 DOM
.csvTab
= $("#csv-tab a");
123 DOM
.rowsToAdd
= $(".rows-to-add");
124 DOM
.more
= $(".more");
125 DOM
.moreRowsStartIndex
= $(".more-rows-start-index");
126 DOM
.feedback
= $(".feedback");
127 DOM
.tab
= $(".derivation-type a");
128 DOM
.indexToggle
= $(".index-toggle");
129 DOM
.addressToggle
= $(".address-toggle");
130 DOM
.publicKeyToggle
= $(".public-key-toggle");
131 DOM
.privateKeyToggle
= $(".private-key-toggle");
132 DOM
.languages
= $(".languages a");
133 DOM
.qrContainer
= $(".qr-container");
134 DOM
.qrHider
= DOM
.qrContainer
.find(".qr-hider");
135 DOM
.qrImage
= DOM
.qrContainer
.find(".qr-image");
136 DOM
.qrHint
= DOM
.qrContainer
.find(".qr-hint");
137 DOM
.showQrEls
= $("[data-show-qr]");
141 DOM
.privacyScreenToggle
.on("change", privacyScreenToggled
);
142 DOM
.generatedStrength
.on("change", generatedStrengthChanged
);
143 DOM
.network
.on("change", networkChanged
);
144 DOM
.bip32Client
.on("change", bip32ClientChanged
);
145 DOM
.useEntropy
.on("change", setEntropyVisibility
);
146 DOM
.entropy
.on("input", delayedEntropyChanged
);
147 DOM
.entropyMnemonicLength
.on("change", entropyChanged
);
148 DOM
.entropyTypeInputs
.on("change", entropyTypeChanged
);
149 DOM
.phrase
.on("input", delayedPhraseChanged
);
150 DOM
.showSplitMnemonic
.on("change", toggleSplitMnemonic
);
151 DOM
.passphrase
.on("input", delayedPhraseChanged
);
152 DOM
.generate
.on("click", generateClicked
);
153 DOM
.more
.on("click", showMore
);
154 DOM
.seed
.on("input", delayedSeedChanged
);
155 DOM
.rootKey
.on("input", delayedRootKeyChanged
);
156 DOM
.showBip85
.on('change', toggleBip85
);
157 DOM
.litecoinUseLtub
.on("change", litecoinUseLtubChanged
);
158 DOM
.bip32path
.on("input", calcForDerivationPath
);
159 DOM
.bip44account
.on("input", calcForDerivationPath
);
160 DOM
.bip44change
.on("input", calcForDerivationPath
);
161 DOM
.bip49account
.on("input", calcForDerivationPath
);
162 DOM
.bip49change
.on("input", calcForDerivationPath
);
163 DOM
.bip84account
.on("input", calcForDerivationPath
);
164 DOM
.bip84change
.on("input", calcForDerivationPath
);
165 DOM
.bip85application
.on('input', calcBip85
);
166 DOM
.bip85mnemonicLanguage
.on('change', calcBip85
);
167 DOM
.bip85mnemonicLength
.on('change', calcBip85
);
168 DOM
.bip85index
.on('input', calcBip85
);
169 DOM
.bip85bytes
.on('input', calcBip85
);
170 DOM
.bip141path
.on("input", calcForDerivationPath
);
171 DOM
.bip141semantics
.on("change", tabChanged
);
172 DOM
.tab
.on("shown.bs.tab", tabChanged
);
173 DOM
.hardenedAddresses
.on("change", calcForDerivationPath
);
174 DOM
.useBip38
.on("change", calcForDerivationPath
);
175 DOM
.bip38Password
.on("change", calcForDerivationPath
);
176 DOM
.indexToggle
.on("click", toggleIndexes
);
177 DOM
.addressToggle
.on("click", toggleAddresses
);
178 DOM
.publicKeyToggle
.on("click", togglePublicKeys
);
179 DOM
.privateKeyToggle
.on("click", togglePrivateKeys
);
180 DOM
.csvTab
.on("click", updateCsv
);
181 DOM
.languages
.on("click", languageChanged
);
182 DOM
.bitcoinCashAddressType
.on("change", bitcoinCashAddressTypeChange
);
183 setQrEvents(DOM
.showQrEls
);
186 hideValidationError();
187 populateNetworkSelect();
188 populateClientSelect();
193 function generatedStrengthChanged() {
194 var strength
= parseInt(DOM
.generatedStrength
.val());
196 DOM
.generatedStrengthWarning
.removeClass("hidden");
199 DOM
.generatedStrengthWarning
.addClass("hidden");
203 function networkChanged(e
) {
205 clearAddressesList();
206 DOM
.litecoinLtubContainer
.addClass("hidden");
207 DOM
.bitcoinCashAddressTypeContainer
.addClass("hidden");
208 var networkIndex
= e
.target
.value
;
209 var network
= networks
[networkIndex
];
211 adjustNetworkForSegwit();
220 function bip32ClientChanged(e
) {
221 var clientIndex
= DOM
.bip32Client
.val();
222 if (clientIndex
== "custom") {
223 DOM
.bip32path
.prop("readonly", false);
226 DOM
.bip32path
.prop("readonly", true);
227 clients
[clientIndex
].onSelect();
237 function setEntropyVisibility() {
238 if (isUsingOwnEntropy()) {
239 DOM
.entropyContainer
.removeClass("hidden");
240 DOM
.generateContainer
.addClass("hidden");
241 DOM
.phrase
.prop("readonly", true);
246 DOM
.entropyContainer
.addClass("hidden");
247 DOM
.generateContainer
.removeClass("hidden");
248 DOM
.phrase
.prop("readonly", false);
253 function delayedPhraseChanged() {
254 hideValidationError();
257 bip32ExtendedKey
= null;
258 clearAddressesList();
260 if (phraseChangeTimeoutEvent
!= null) {
261 clearTimeout(phraseChangeTimeoutEvent
);
263 phraseChangeTimeoutEvent
= setTimeout(function() {
265 var entropy
= mnemonic
.toRawEntropyHex(DOM
.phrase
.val());
266 if (entropy
!== null) {
267 DOM
.entropyMnemonicLength
.val("raw");
268 DOM
.entropy
.val(entropy
);
269 DOM
.entropyTypeInputs
.filter("[value='hexadecimal']").prop("checked", true);
270 entropyTypeAutoDetect
= false;
275 function phraseChanged() {
277 setMnemonicLanguage();
278 // Get the mnemonic phrase
279 var phrase
= DOM
.phrase
.val();
280 var errorText
= findPhraseErrors(phrase
);
282 showValidationError(errorText
);
285 // Calculate and display
286 var passphrase
= DOM
.passphrase
.val();
287 calcBip32RootKeyFromSeed(phrase
, passphrase
);
288 calcForDerivationPath();
290 // Show the word indexes
292 writeSplitPhrase(phrase
);
295 function tabChanged() {
297 adjustNetworkForSegwit();
298 var phrase
= DOM
.phrase
.val();
300 // Calculate and display for mnemonic
301 var errorText
= findPhraseErrors(phrase
);
303 showValidationError(errorText
);
306 // Calculate and display
307 var passphrase
= DOM
.passphrase
.val();
308 calcBip32RootKeyFromSeed(phrase
, passphrase
);
311 // Calculate and display for root key
312 var rootKeyBase58
= DOM
.rootKey
.val();
313 var errorText
= validateRootKey(rootKeyBase58
);
315 showValidationError(errorText
);
318 // Calculate and display
319 calcBip32RootKeyFromBase58(rootKeyBase58
);
321 calcForDerivationPath();
324 function delayedEntropyChanged() {
325 hideValidationError();
327 if (entropyChangeTimeoutEvent
!= null) {
328 clearTimeout(entropyChangeTimeoutEvent
);
330 entropyChangeTimeoutEvent
= setTimeout(entropyChanged
, 400);
333 function entropyChanged() {
334 // If blank entropy, clear mnemonic, addresses, errors
335 if (DOM
.entropy
.val().trim().length
== 0) {
337 clearEntropyFeedback();
339 DOM
.phraseSplit
.val("");
340 showValidationError("Blank entropy");
343 // Get the current phrase to detect changes
344 var phrase
= DOM
.phrase
.val();
345 // Set the phrase from the entropy
346 setMnemonicFromEntropy();
347 // Recalc addresses if the phrase has changed
348 var newPhrase
= DOM
.phrase
.val();
349 if (newPhrase
!= phrase
) {
350 if (newPhrase
.length
== 0) {
362 function entropyTypeChanged() {
363 entropyTypeAutoDetect
= false;
367 function delayedSeedChanged() {
368 // Warn if there is an existing mnemonic or passphrase.
369 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
370 if (!confirm("This will clear existing mnemonic and passphrase")) {
375 hideValidationError();
377 // Clear existing mnemonic and passphrase
379 DOM
.phraseSplit
.val("");
380 DOM
.passphrase
.val("");
382 clearAddressesList();
385 if (seedChangedTimeoutEvent
!= null) {
386 clearTimeout(seedChangedTimeoutEvent
);
388 seedChangedTimeoutEvent
= setTimeout(seedChanged
, 400);
391 function delayedRootKeyChanged() {
392 // Warn if there is an existing mnemonic or passphrase.
393 if (DOM
.phrase
.val().length
> 0 || DOM
.passphrase
.val().length
> 0) {
394 if (!confirm("This will clear existing mnemonic and passphrase")) {
395 DOM
.rootKey
.val(bip32RootKey
);
399 hideValidationError();
401 // Clear existing mnemonic and passphrase
403 DOM
.phraseSplit
.val("");
404 DOM
.passphrase
.val("");
406 if (rootKeyChangedTimeoutEvent
!= null) {
407 clearTimeout(rootKeyChangedTimeoutEvent
);
409 rootKeyChangedTimeoutEvent
= setTimeout(rootKeyChanged
, 400);
412 function seedChanged() {
414 hideValidationError();
415 seed
= DOM
.seed
.val();
416 bip32RootKey
= libs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
417 var rootKeyBase58
= bip32RootKey
.toBase58();
418 DOM
.rootKey
.val(rootKeyBase58
);
419 var errorText
= validateRootKey(rootKeyBase58
);
421 showValidationError(errorText
);
424 // Calculate and display
425 calcForDerivationPath();
429 function rootKeyChanged() {
431 hideValidationError();
432 var rootKeyBase58
= DOM
.rootKey
.val();
433 var errorText
= validateRootKey(rootKeyBase58
);
435 showValidationError(errorText
);
438 // Calculate and display
439 calcBip32RootKeyFromBase58(rootKeyBase58
);
440 calcForDerivationPath();
444 function litecoinUseLtubChanged() {
445 litecoinUseLtub
= DOM
.litecoinUseLtub
.prop("checked");
446 if (litecoinUseLtub
) {
447 network
= libs
.bitcoin
.networks
.litecoin
;
450 network
= libs
.bitcoin
.networks
.litecoinXprv
;
455 function toggleSplitMnemonic() {
456 if (DOM
.showSplitMnemonic
.prop("checked")) {
457 DOM
.splitMnemonic
.removeClass("hidden");
460 DOM
.splitMnemonic
.addClass("hidden");
464 function toggleBip85() {
465 if (DOM
.showBip85
.prop('checked')) {
466 DOM
.bip85
.removeClass('hidden');
469 DOM
.bip85
.addClass('hidden');
473 function toggleBip85Fields() {
474 if (DOM
.showBip85
.prop('checked')) {
475 DOM
.bip85mnemonicLanguageInput
.addClass('hidden');
476 DOM
.bip85mnemonicLengthInput
.addClass('hidden');
477 DOM
.bip85bytesInput
.addClass('hidden');
479 var app
= DOM
.bip85application
.val();
480 if (app
=== 'bip39') {
481 DOM
.bip85mnemonicLanguageInput
.removeClass('hidden');
482 DOM
.bip85mnemonicLengthInput
.removeClass('hidden');
483 } else if (app
=== 'hex') {
484 DOM
.bip85bytesInput
.removeClass('hidden');
489 function calcBip85() {
492 var app
= DOM
.bip85application
.val();
494 var phrase
= DOM
.phrase
.val();
495 var passphrase
= DOM
.passphrase
.val();
500 var master
= libs
.bip85
.BIP85
.fromMnemonic(phrase
, passphrase
);
504 const index
= parseInt(DOM
.bip85index
.val(), 10);
506 if (app
=== 'bip39') {
507 const language
= parseInt(DOM
.bip85mnemonicLanguage
.val(), 10);
508 const length
= parseInt(DOM
.bip85mnemonicLength
.val(), 10);
510 result
= master
.deriveBIP39(language
, length
, index
).toMnemonic();
511 } else if (app
=== 'wif') {
512 result
= master
.deriveWIF(index
).toWIF();
513 } else if (app
=== 'xprv') {
514 result
= master
.deriveXPRV(index
).toXPRV();
515 } else if (app
=== 'hex') {
516 const bytes
= parseInt(DOM
.bip85bytes
.val(), 10);
518 result
= master
.deriveHex(bytes
, index
).toEntropy();
521 hideValidationError();
522 DOM
.bip85Field
.val(result
);
524 showValidationError('BIP85: ' + e
.message
);
525 DOM
.bip85Field
.val('');
529 function calcForDerivationPath() {
531 clearAddressesList();
533 // Don't show segwit if it's selected but network doesn't support it
534 if (segwitSelected() && !networkHasSegwit()) {
535 showSegwitUnavailable();
539 showSegwitAvailable();
540 // Get the derivation path
541 var derivationPath
= getDerivationPath();
542 var errorText
= findDerivationPathErrors(derivationPath
);
544 showValidationError(errorText
);
547 bip32ExtendedKey
= calcBip32ExtendedKey(derivationPath
);
548 if (bip44TabSelected()) {
551 else if (bip49TabSelected()) {
554 else if (bip84TabSelected()) {
560 function generateClicked() {
561 if (isUsingOwnEntropy()) {
566 setTimeout(function() {
567 setMnemonicLanguage();
568 var phrase
= generateRandomPhrase();
576 function languageChanged() {
577 setTimeout(function() {
578 setMnemonicLanguage();
579 if (DOM
.phrase
.val().length
> 0) {
580 var newPhrase
= convertPhraseToNewLanguage();
581 DOM
.phrase
.val(newPhrase
);
585 DOM
.generate
.trigger("click");
590 function bitcoinCashAddressTypeChange() {
594 function toggleIndexes() {
595 showIndex
= !showIndex
;
596 $("td.index span").toggleClass("invisible");
599 function toggleAddresses() {
600 showAddress
= !showAddress
;
601 $("td.address span").toggleClass("invisible");
604 function togglePublicKeys() {
605 showPubKey
= !showPubKey
;
606 $("td.pubkey span").toggleClass("invisible");
609 function togglePrivateKeys() {
610 showPrivKey
= !showPrivKey
;
611 $("td.privkey span").toggleClass("invisible");
614 function privacyScreenToggled() {
615 // private-data contains elements added to DOM at runtime
616 // so catch all by adding visual privacy class to the root of the DOM
617 if (DOM
.privacyScreenToggle
.prop("checked")) {
618 $("body").addClass("visual-privacy");
621 $("body").removeClass("visual-privacy");
627 function generateRandomPhrase() {
628 if (!hasStrongRandom()) {
629 var errorText
= "This browser does not support strong randomness";
630 showValidationError(errorText
);
633 // get the amount of entropy to use
634 var numWords
= parseInt(DOM
.generatedStrength
.val());
635 var strength
= numWords
/ 3 * 32;
636 var buffer
= new Uint8Array(strength
/ 8);
637 // create secure entropy
638 var data
= crypto
.getRandomValues(buffer
);
640 var words
= mnemonic
.toMnemonic(data
);
641 DOM
.phrase
.val(words
);
643 var entropyHex
= uint8ArrayToHex(data
);
644 DOM
.entropy
.val(entropyHex
);
645 // ensure entropy fields are consistent with what is being displayed
646 DOM
.entropyMnemonicLength
.val("raw");
650 function calcBip32RootKeyFromSeed(phrase
, passphrase
) {
651 seed
= mnemonic
.toSeed(phrase
, passphrase
);
652 bip32RootKey
= libs
.bitcoin
.HDNode
.fromSeedHex(seed
, network
);
654 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromSeedHex(seed
, network
);
658 function calcBip32RootKeyFromBase58(rootKeyBase58
) {
660 calcBip32RootKeyFromBase58GRS(rootKeyBase58
);
663 // try parsing with various segwit network params since this extended
664 // key may be from any one of them.
665 if (networkHasSegwit()) {
667 if ("baseNetwork" in n
) {
668 n
= libs
.bitcoin
.networks
[n
.baseNetwork
];
670 // try parsing using base network params
672 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
676 // try parsing using p2wpkh params
679 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
684 // try parsing using p2wpkh-in-p2sh network params
685 if ("p2wpkhInP2sh" in n
) {
687 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
692 // try parsing using p2wsh network params
695 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
700 // try parsing using p2wsh-in-p2sh network params
701 if ("p2wshInP2sh" in n
) {
703 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
709 // try the network params as currently specified
710 bip32RootKey
= libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
713 function calcBip32RootKeyFromBase58GRS(rootKeyBase58
) {
714 // try parsing with various segwit network params since this extended
715 // key may be from any one of them.
716 if (networkHasSegwit()) {
718 if ("baseNetwork" in n
) {
719 n
= libs
.bitcoin
.networks
[n
.baseNetwork
];
721 // try parsing using base network params
723 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
727 // try parsing using p2wpkh params
730 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
735 // try parsing using p2wpkh-in-p2sh network params
736 if ("p2wpkhInP2sh" in n
) {
738 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
744 // try the network params as currently specified
745 bip32RootKey
= libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
748 function calcBip32ExtendedKey(path
) {
749 // Check there's a root key to derive from
753 var extendedKey
= bip32RootKey
;
754 // Derive the key from the path
755 var pathBits
= path
.split("/");
756 for (var i
=0; i
<pathBits
.length
; i
++) {
757 var bit
= pathBits
[i
];
758 var index
= parseInt(bit
);
762 var hardened
= bit
[bit
.length
-1] == "'";
763 var isPriv
= !(extendedKey
.isNeutered());
764 var invalidDerivationPath
= hardened
&& !isPriv
;
765 if (invalidDerivationPath
) {
769 extendedKey
= extendedKey
.deriveHardened(index
);
772 extendedKey
= extendedKey
.derive(index
);
778 function showValidationError(errorText
) {
784 function hideValidationError() {
790 function findPhraseErrors(phrase
) {
791 // Preprocess the words
792 phrase
= mnemonic
.normalizeString(phrase
);
793 var words
= phraseToWordArray(phrase
);
794 // Detect blank phrase
795 if (words
.length
== 0) {
796 return "Blank mnemonic";
799 for (var i
=0; i
<words
.length
; i
++) {
801 var language
= getLanguage();
802 if (WORDLISTS
[language
].indexOf(word
) == -1) {
803 console
.log("Finding closest match to " + word
);
804 var nearestWord
= findNearestWord(word
);
805 return word
+ " not in wordlist, did you mean " + nearestWord
+ "?";
808 // Check the words are valid
809 var properPhrase
= wordArrayToPhrase(words
);
810 var isValid
= mnemonic
.check(properPhrase
);
812 return "Invalid mnemonic";
817 function validateRootKey(rootKeyBase58
) {
819 return validateRootKeyGRS(rootKeyBase58
);
821 // try various segwit network params since this extended key may be from
823 if (networkHasSegwit()) {
825 if ("baseNetwork" in n
) {
826 n
= libs
.bitcoin
.networks
[n
.baseNetwork
];
828 // try parsing using base network params
830 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
);
834 // try parsing using p2wpkh params
837 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
842 // try parsing using p2wpkh-in-p2sh network params
843 if ("p2wpkhInP2sh" in n
) {
845 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
850 // try parsing using p2wsh network params
853 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wsh
);
858 // try parsing using p2wsh-in-p2sh network params
859 if ("p2wshInP2sh" in n
) {
861 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wshInP2sh
);
867 // try the network params as currently specified
869 libs
.bitcoin
.HDNode
.fromBase58(rootKeyBase58
, network
);
872 return "Invalid root key";
877 function validateRootKeyGRS(rootKeyBase58
) {
878 // try various segwit network params since this extended key may be from
880 if (networkHasSegwit()) {
882 if ("baseNetwork" in n
) {
883 n
= libs
.bitcoin
.networks
[n
.baseNetwork
];
885 // try parsing using base network params
887 libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
);
891 // try parsing using p2wpkh params
894 libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkh
);
899 // try parsing using p2wpkh-in-p2sh network params
900 if ("p2wpkhInP2sh" in n
) {
902 libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, n
.p2wpkhInP2sh
);
908 // try the network params as currently specified
910 libs
.groestlcoinjs
.HDNode
.fromBase58(rootKeyBase58
, network
);
913 return "Invalid root key";
918 function getDerivationPath() {
919 if (bip44TabSelected()) {
920 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
921 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
922 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
923 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
925 path
+= purpose
+ "'/";
927 path
+= account
+ "'/";
929 DOM
.bip44path
.val(path
);
930 var derivationPath
= DOM
.bip44path
.val();
931 console
.log("Using derivation path from BIP44 tab: " + derivationPath
);
932 return derivationPath
;
934 else if (bip49TabSelected()) {
935 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
936 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
937 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
938 var change
= parseIntNoNaN(DOM
.bip49change
.val(), 0);
940 path
+= purpose
+ "'/";
942 path
+= account
+ "'/";
944 DOM
.bip49path
.val(path
);
945 var derivationPath
= DOM
.bip49path
.val();
946 console
.log("Using derivation path from BIP49 tab: " + derivationPath
);
947 return derivationPath
;
949 else if (bip84TabSelected()) {
950 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
951 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
952 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
953 var change
= parseIntNoNaN(DOM
.bip84change
.val(), 0);
955 path
+= purpose
+ "'/";
957 path
+= account
+ "'/";
959 DOM
.bip84path
.val(path
);
960 var derivationPath
= DOM
.bip84path
.val();
961 console
.log("Using derivation path from BIP84 tab: " + derivationPath
);
962 return derivationPath
;
964 else if (bip32TabSelected()) {
965 var derivationPath
= DOM
.bip32path
.val();
966 console
.log("Using derivation path from BIP32 tab: " + derivationPath
);
967 return derivationPath
;
969 else if (bip141TabSelected()) {
970 var derivationPath
= DOM
.bip141path
.val();
971 console
.log("Using derivation path from BIP141 tab: " + derivationPath
);
972 return derivationPath
;
975 console
.log("Unknown derivation path");
979 function findDerivationPathErrors(path
) {
980 // TODO is not perfect but is better than nothing
982 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
984 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
985 var maxDepth
= 255; // TODO verify this!!
986 var maxIndexValue
= Math
.pow(2, 31); // TODO verify this!!
987 if (path
[0] != "m") {
988 return "First character must be 'm'";
990 if (path
.length
> 1) {
991 if (path
[1] != "/") {
992 return "Separator must be '/'";
994 var indexes
= path
.split("/");
995 if (indexes
.length
> maxDepth
) {
996 return "Derivation depth is " + indexes
.length
+ ", must be less than " + maxDepth
;
998 for (var depth
= 1; depth
<indexes
.length
; depth
++) {
999 var index
= indexes
[depth
];
1000 var invalidChars
= index
.replace(/^[0-9]+'?$/g, "")
1001 if (invalidChars
.length
> 0) {
1002 return "Invalid characters " + invalidChars
+ " found at depth " + depth
;
1004 var indexValue
= parseInt(index
.replace("'", ""));
1006 return "Invalid number at depth " + depth
;
1008 if (indexValue
> maxIndexValue
) {
1009 return "Value of " + indexValue
+ " at depth " + depth
+ " must be less than " + maxIndexValue
;
1013 // Check root key exists or else derivation path is useless!
1014 if (!bip32RootKey
) {
1015 return "No root key";
1017 // Check no hardened derivation path when using xpub keys
1018 var hardenedPath
= path
.indexOf("'") > -1;
1019 var hardenedAddresses
= bip32TabSelected() && DOM
.hardenedAddresses
.prop("checked");
1020 var hardened
= hardenedPath
|| hardenedAddresses
;
1021 var isXpubkey
= bip32RootKey
.isNeutered();
1022 if (hardened
&& isXpubkey
) {
1023 return "Hardened derivation path is invalid with xpub key";
1029 return networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin" || networks
[DOM
.network
.val()].name
== "GRS - Groestlcoin Testnet";
1033 return networks
[DOM
.network
.val()].name
== "ELA - Elastos"
1036 function displayBip44Info() {
1037 // Get the derivation path for the account
1038 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1039 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1040 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
1042 path
+= purpose
+ "'/";
1043 path
+= coin
+ "'/";
1044 path
+= account
+ "'/";
1045 // Calculate the account extended keys
1046 var accountExtendedKey
= calcBip32ExtendedKey(path
);
1047 var accountXprv
= accountExtendedKey
.toBase58();
1048 var accountXpub
= accountExtendedKey
.neutered().toBase58();
1050 // Display the extended keys
1051 DOM
.bip44accountXprv
.val(accountXprv
);
1052 DOM
.bip44accountXpub
.val(accountXpub
);
1055 displayBip44InfoForELA();
1059 function displayBip49Info() {
1060 // Get the derivation path for the account
1061 var purpose
= parseIntNoNaN(DOM
.bip49purpose
.val(), 49);
1062 var coin
= parseIntNoNaN(DOM
.bip49coin
.val(), 0);
1063 var account
= parseIntNoNaN(DOM
.bip49account
.val(), 0);
1065 path
+= purpose
+ "'/";
1066 path
+= coin
+ "'/";
1067 path
+= account
+ "'/";
1068 // Calculate the account extended keys
1069 var accountExtendedKey
= calcBip32ExtendedKey(path
);
1070 var accountXprv
= accountExtendedKey
.toBase58();
1071 var accountXpub
= accountExtendedKey
.neutered().toBase58();
1072 // Display the extended keys
1073 DOM
.bip49accountXprv
.val(accountXprv
);
1074 DOM
.bip49accountXpub
.val(accountXpub
);
1077 function displayBip84Info() {
1078 // Get the derivation path for the account
1079 var purpose
= parseIntNoNaN(DOM
.bip84purpose
.val(), 84);
1080 var coin
= parseIntNoNaN(DOM
.bip84coin
.val(), 0);
1081 var account
= parseIntNoNaN(DOM
.bip84account
.val(), 0);
1083 path
+= purpose
+ "'/";
1084 path
+= coin
+ "'/";
1085 path
+= account
+ "'/";
1086 // Calculate the account extended keys
1087 var accountExtendedKey
= calcBip32ExtendedKey(path
);
1088 var accountXprv
= accountExtendedKey
.toBase58();
1089 var accountXpub
= accountExtendedKey
.neutered().toBase58();
1090 // Display the extended keys
1091 DOM
.bip84accountXprv
.val(accountXprv
);
1092 DOM
.bip84accountXpub
.val(accountXpub
);
1095 function displayBip32Info() {
1098 var rootKey
= bip32RootKey
.toBase58();
1099 DOM
.rootKey
.val(rootKey
);
1100 var xprvkeyB58
= "NA";
1101 if (!bip32ExtendedKey
.isNeutered()) {
1102 xprvkeyB58
= bip32ExtendedKey
.toBase58();
1104 var extendedPrivKey
= xprvkeyB58
;
1105 DOM
.extendedPrivKey
.val(extendedPrivKey
);
1106 var extendedPubKey
= bip32ExtendedKey
.neutered().toBase58();
1107 DOM
.extendedPubKey
.val(extendedPubKey
);
1108 // Display the addresses and privkeys
1109 clearAddressesList();
1110 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
1111 displayAddresses(0, initialAddressCount
);
1114 displayBip32InfoForELA();
1118 function displayAddresses(start
, total
) {
1119 generationProcesses
.push(new (function() {
1123 this.stop = function() {
1124 for (var i
=0; i
<rows
.length
; i
++) {
1125 rows
[i
].shouldGenerate
= false;
1130 for (var i
=0; i
<total
; i
++) {
1131 var index
= i
+ start
;
1132 var isLast
= i
== total
- 1;
1133 rows
.push(new TableRow(index
, isLast
));
1139 function segwitSelected() {
1140 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
1143 function p2wpkhSelected() {
1144 return bip84TabSelected() ||
1145 bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh";
1148 function p2wpkhInP2shSelected() {
1149 return bip49TabSelected() ||
1150 (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wpkh-p2sh");
1153 function p2wshSelected() {
1154 return bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh";
1157 function p2wshInP2shSelected() {
1158 return (bip141TabSelected() && DOM
.bip141semantics
.val() == "p2wsh-p2sh");
1161 function TableRow(index
, isLast
) {
1164 this.shouldGenerate
= true;
1165 var useHardenedAddresses
= DOM
.hardenedAddresses
.prop("checked");
1166 var useBip38
= DOM
.useBip38
.prop("checked");
1167 var bip38password
= DOM
.bip38Password
.val();
1168 var isSegwit
= segwitSelected();
1169 var segwitAvailable
= networkHasSegwit();
1170 var isP2wpkh
= p2wpkhSelected();
1171 var isP2wpkhInP2sh
= p2wpkhInP2shSelected();
1172 var isP2wsh
= p2wshSelected();
1173 var isP2wshInP2sh
= p2wshInP2shSelected();
1179 function calculateValues() {
1180 setTimeout(function() {
1181 if (!self
.shouldGenerate
) {
1184 // derive HDkey for this row of the table
1186 if (useHardenedAddresses
) {
1187 key
= bip32ExtendedKey
.deriveHardened(index
);
1190 key
= bip32ExtendedKey
.derive(index
);
1192 // bip38 requires uncompressed keys
1193 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
1194 var keyPair
= key
.keyPair
;
1195 var useUncompressed
= useBip38
;
1196 if (useUncompressed
) {
1197 keyPair
= new libs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1199 keyPair
= new libs
.groestlcoinjs
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1203 var address
= keyPair
.getAddress().toString();
1205 var hasPrivkey
= !key
.isNeutered();
1208 privkey
= keyPair
.toWIF();
1209 // BIP38 encode private key if required
1212 privkey
= libs
.groestlcoinjsBip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1213 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1214 }, null, networks
[DOM
.network
.val()].name
.includes("Testnet"));
1216 privkey
= libs
.bip38
.encrypt(keyPair
.d
.toBuffer(), false, bip38password
, function(p
) {
1217 console
.log("Progressed " + p
.percent
.toFixed(1) + "% for index " + index
);
1222 var pubkey
= keyPair
.getPublicKeyBuffer().toString('hex');
1223 var indexText
= getDerivationPath() + "/" + index
;
1224 if (useHardenedAddresses
) {
1225 indexText
= indexText
+ "'";
1227 // Ethereum values are different
1228 if (networkIsEthereum()) {
1229 var pubkeyBuffer
= keyPair
.getPublicKeyBuffer();
1230 var ethPubkey
= libs
.ethUtil
.importPublic(pubkeyBuffer
);
1231 var addressBuffer
= libs
.ethUtil
.publicToAddress(ethPubkey
);
1232 var hexAddress
= addressBuffer
.toString('hex');
1233 var checksumAddress
= libs
.ethUtil
.toChecksumAddress(hexAddress
);
1234 address
= libs
.ethUtil
.addHexPrefix(checksumAddress
);
1235 pubkey
= libs
.ethUtil
.addHexPrefix(pubkey
);
1237 privkey
= libs
.ethUtil
.bufferToHex(keyPair
.d
.toBuffer());
1241 if (networks
[DOM
.network
.val()].name
== "TRX - Tron") {
1242 keyPair
= new libs
.bitcoin
.ECPair(keyPair
.d
, null, { network: network
, compressed: false });
1243 var pubkeyBuffer
= keyPair
.getPublicKeyBuffer();
1244 var ethPubkey
= libs
.ethUtil
.importPublic(pubkeyBuffer
);
1245 var addressBuffer
= libs
.ethUtil
.publicToAddress(ethPubkey
);
1246 address
= libs
.bitcoin
.address
.toBase58Check(addressBuffer
, 0x41);
1248 privkey
= keyPair
.d
.toBuffer().toString('hex');
1252 // RSK values are different
1253 if (networkIsRsk()) {
1254 var pubkeyBuffer
= keyPair
.getPublicKeyBuffer();
1255 var ethPubkey
= libs
.ethUtil
.importPublic(pubkeyBuffer
);
1256 var addressBuffer
= libs
.ethUtil
.publicToAddress(ethPubkey
);
1257 var hexAddress
= addressBuffer
.toString('hex');
1258 // Use chainId based on selected network
1259 // Ref: https://developers.rsk.co/rsk/architecture/account-based/#chainid
1261 var rskNetworkName
= networks
[DOM
.network
.val()].name
;
1262 switch (rskNetworkName
) {
1266 case "tR-BTC - RSK Testnet":
1272 var checksumAddress
= toChecksumAddressForRsk(hexAddress
, chainId
);
1273 address
= libs
.ethUtil
.addHexPrefix(checksumAddress
);
1274 pubkey
= libs
.ethUtil
.addHexPrefix(pubkey
);
1276 privkey
= libs
.ethUtil
.bufferToHex(keyPair
.d
.toBuffer());
1280 // Handshake values are different
1281 if (networks
[DOM
.network
.val()].name
== "HNS - Handshake") {
1282 var ring
= libs
.handshake
.KeyRing
.fromPublic(keyPair
.getPublicKeyBuffer())
1283 address
= ring
.getAddress().toString();
1286 // Stellar is different
1287 if (networks
[DOM
.network
.val()].name
== "XLM - Stellar") {
1288 var purpose
= parseIntNoNaN(DOM
.bip44purpose
.val(), 44);
1289 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
1291 path
+= purpose
+ "'/";
1292 path
+= coin
+ "'/" + index
+ "'";
1293 var keypair
= libs
.stellarUtil
.getKeypair(path
, seed
);
1295 privkey
= keypair
.secret();
1296 pubkey
= address
= keypair
.publicKey();
1300 if (networks
[DOM
.network
.val()].name
== "NANO - Nano") {
1301 var nanoKeypair
= libs
.nanoUtil
.getKeypair(index
, seed
);
1302 privkey
= nanoKeypair
.privKey
;
1303 pubkey
= nanoKeypair
.pubKey
;
1304 address
= nanoKeypair
.address
;
1307 if ((networks
[DOM
.network
.val()].name
== "NAS - Nebulas")) {
1308 var privKeyBuffer
= keyPair
.d
.toBuffer(32);
1309 var nebulasAccount
= libs
.nebulas
.Account
.NewAccount();
1310 nebulasAccount
.setPrivateKey(privKeyBuffer
);
1311 address
= nebulasAccount
.getAddressString();
1312 privkey
= nebulasAccount
.getPrivateKeyString();
1313 pubkey
= nebulasAccount
.getPublicKeyString();
1315 // Ripple values are different
1316 if (networks
[DOM
.network
.val()].name
== "XRP - Ripple") {
1317 privkey
= convertRipplePriv(privkey
);
1318 address
= convertRippleAdrr(address
);
1320 // Jingtum values are different
1321 if (networks
[DOM
.network
.val()].name
== "SWTC - Jingtum") {
1322 privkey
= convertJingtumPriv(privkey
);
1323 address
= convertJingtumAdrr(address
);
1325 // CasinoCoin values are different
1326 if (networks
[DOM
.network
.val()].name
== "CSC - CasinoCoin") {
1327 privkey
= convertCasinoCoinPriv(privkey
);
1328 address
= convertCasinoCoinAdrr(address
);
1330 // Bitcoin Cash address format may vary
1331 if (networks
[DOM
.network
.val()].name
== "BCH - Bitcoin Cash") {
1332 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1333 if (bchAddrType
== "cashaddr") {
1334 address
= libs
.bchaddr
.toCashAddress(address
);
1336 else if (bchAddrType
== "bitpay") {
1337 address
= libs
.bchaddr
.toBitpayAddress(address
);
1340 // Bitcoin Cash address format may vary
1341 if (networks
[DOM
.network
.val()].name
== "SLP - Simple Ledger Protocol") {
1342 var bchAddrType
= DOM
.bitcoinCashAddressType
.filter(":checked").val();
1343 if (bchAddrType
== "cashaddr") {
1344 address
= libs
.bchaddrSlp
.toSlpAddress(address
);
1347 // Segwit addresses are different
1349 if (!segwitAvailable
) {
1353 var keyhash
= libs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1354 var scriptpubkey
= libs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1355 address
= libs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1357 else if (isP2wpkhInP2sh
) {
1358 var keyhash
= libs
.bitcoin
.crypto
.hash160(key
.getPublicKeyBuffer());
1359 var scriptsig
= libs
.bitcoin
.script
.witnessPubKeyHash
.output
.encode(keyhash
);
1360 var addressbytes
= libs
.bitcoin
.crypto
.hash160(scriptsig
);
1361 var scriptpubkey
= libs
.bitcoin
.script
.scriptHash
.output
.encode(addressbytes
);
1362 address
= libs
.bitcoin
.address
.fromOutputScript(scriptpubkey
, network
)
1365 // https://github.com/libs.bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71
1367 var witnessScript
= libs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1368 var scriptPubKey
= libs
.bitcoin
.script
.witnessScriptHash
.output
.encode(libs
.bitcoin
.crypto
.sha256(witnessScript
));
1369 address
= libs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
);
1371 else if (isP2wshInP2sh
) {
1372 // https://github.com/libs.bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183
1374 var witnessScript
= libs
.bitcoin
.script
.multisig
.output
.encode(1, [key
.getPublicKeyBuffer()]);
1375 var redeemScript
= libs
.bitcoin
.script
.witnessScriptHash
.output
.encode(libs
.bitcoin
.crypto
.sha256(witnessScript
));
1376 var scriptPubKey
= libs
.bitcoin
.script
.scriptHash
.output
.encode(libs
.bitcoin
.crypto
.hash160(redeemScript
));
1377 address
= libs
.bitcoin
.address
.fromOutputScript(scriptPubKey
, network
)
1381 if ((networks
[DOM
.network
.val()].name
== "CRW - Crown")) {
1382 address
= libs
.bitcoin
.networks
.crown
.toNewAddress(address
);
1385 if (networks
[DOM
.network
.val()].name
== "EOS - EOSIO") {
1387 pubkey
= EOSbufferToPublic(keyPair
.getPublicKeyBuffer());
1388 privkey
= EOSbufferToPrivate(keyPair
.d
.toBuffer(32));
1391 if (networks
[DOM
.network
.val()].name
== "FIO - Foundation for Interwallet Operability") {
1393 pubkey
= FIObufferToPublic(keyPair
.getPublicKeyBuffer());
1394 privkey
= FIObufferToPrivate(keyPair
.d
.toBuffer(32));
1397 //Groestlcoin Addresses are different
1401 if (!segwitAvailable
) {
1405 address
= libs
.groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1407 else if (isP2wpkhInP2sh
) {
1408 address
= libs
.groestlcoinjs
.address
.fromOutputScript(scriptpubkey
, network
)
1411 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1415 let elaAddress
= calcAddressForELA(
1417 parseIntNoNaN(DOM
.bip44coin
.val(), 0),
1418 parseIntNoNaN(DOM
.bip44account
.val(), 0),
1419 parseIntNoNaN(DOM
.bip44change
.val(), 0),
1422 address
= elaAddress
.address
;
1423 privkey
= elaAddress
.privateKey
;
1424 pubkey
= elaAddress
.publicKey
;
1427 addAddressToList(indexText
, address
, pubkey
, privkey
);
1439 function showMore() {
1440 var rowsToAdd
= parseInt(DOM
.rowsToAdd
.val());
1441 if (isNaN(rowsToAdd
)) {
1443 DOM
.rowsToAdd
.val("20");
1445 var start
= parseInt(DOM
.moreRowsStartIndex
.val())
1447 start
= lastIndexInTable() + 1;
1450 var newStart
= start
+ rowsToAdd
;
1451 DOM
.moreRowsStartIndex
.val(newStart
);
1453 if (rowsToAdd
> 200) {
1454 var msg
= "Generating " + rowsToAdd
+ " rows could take a while. ";
1455 msg
+= "Do you want to continue?";
1456 if (!confirm(msg
)) {
1460 displayAddresses(start
, rowsToAdd
);
1463 function clearDisplay() {
1464 clearAddressesList();
1466 hideValidationError();
1469 function clearAddressesList() {
1470 DOM
.addresses
.empty();
1475 function stopGenerating() {
1476 while (generationProcesses
.length
> 0) {
1477 var generation
= generationProcesses
.shift();
1482 function clearKeys() {
1487 function clearRootKey() {
1488 DOM
.rootKey
.val("");
1491 function clearDerivedKeys() {
1492 DOM
.extendedPrivKey
.val("");
1493 DOM
.extendedPubKey
.val("");
1494 DOM
.bip44accountXprv
.val("");
1495 DOM
.bip44accountXpub
.val("");
1498 function addAddressToList(indexText
, address
, pubkey
, privkey
) {
1499 var row
= $(addressRowTemplate
.html());
1501 var indexCell
= row
.find(".index span");
1502 var addressCell
= row
.find(".address span");
1503 var pubkeyCell
= row
.find(".pubkey span");
1504 var privkeyCell
= row
.find(".privkey span");
1506 indexCell
.text(indexText
);
1507 addressCell
.text(address
);
1508 pubkeyCell
.text(pubkey
);
1509 privkeyCell
.text(privkey
);
1512 indexCell
.addClass("invisible");
1515 addressCell
.addClass("invisible");
1518 pubkeyCell
.addClass("invisible");
1521 privkeyCell
.addClass("invisible");
1523 DOM
.addresses
.append(row
);
1524 var rowShowQrEls
= row
.find("[data-show-qr]");
1525 setQrEvents(rowShowQrEls
);
1528 function hasStrongRandom() {
1529 return 'crypto' in window
&& window
['crypto'] !== null;
1532 function disableForms() {
1533 $("form").on("submit", function(e
) {
1538 function parseIntNoNaN(val
, defaultVal
) {
1539 var v
= parseInt(val
);
1546 function showPending() {
1548 .text("Calculating...")
1552 function findNearestWord(word
) {
1553 var language
= getLanguage();
1554 var words
= WORDLISTS
[language
];
1555 var minDistance
= 99;
1556 var closestWord
= words
[0];
1557 for (var i
=0; i
<words
.length
; i
++) {
1558 var comparedTo
= words
[i
];
1559 if (comparedTo
.indexOf(word
) == 0) {
1562 var distance
= libs
.levenshtein
.get(word
, comparedTo
);
1563 if (distance
< minDistance
) {
1564 closestWord
= comparedTo
;
1565 minDistance
= distance
;
1571 function hidePending() {
1577 function populateNetworkSelect() {
1578 for (var i
=0; i
<networks
.length
; i
++) {
1579 var network
= networks
[i
];
1580 var option
= $("<option>");
1581 option
.attr("value", i
);
1582 option
.text(network
.name
);
1583 if (network
.name
== "BTC - Bitcoin") {
1584 option
.prop("selected", true);
1586 DOM
.phraseNetwork
.append(option
);
1590 function populateClientSelect() {
1591 for (var i
=0; i
<clients
.length
; i
++) {
1592 var client
= clients
[i
];
1593 var option
= $("<option>");
1594 option
.attr("value", i
);
1595 option
.text(client
.name
);
1596 DOM
.bip32Client
.append(option
);
1600 function getLanguage() {
1601 var defaultLanguage
= "english";
1602 // Try to get from existing phrase
1603 var language
= getLanguageFromPhrase();
1604 // Try to get from url if not from phrase
1605 if (language
.length
== 0) {
1606 language
= getLanguageFromUrl();
1608 // Default to English if no other option
1609 if (language
.length
== 0) {
1610 language
= defaultLanguage
;
1615 function getLanguageFromPhrase(phrase
) {
1616 // Check if how many words from existing phrase match a language.
1619 phrase
= DOM
.phrase
.val();
1621 if (phrase
.length
> 0) {
1622 var words
= phraseToWordArray(phrase
);
1623 var languageMatches
= {};
1624 for (l
in WORDLISTS
) {
1625 // Track how many words match in this language
1626 languageMatches
[l
] = 0;
1627 for (var i
=0; i
<words
.length
; i
++) {
1628 var wordInLanguage
= WORDLISTS
[l
].indexOf(words
[i
]) > -1;
1629 if (wordInLanguage
) {
1630 languageMatches
[l
]++;
1633 // Find languages with most word matches.
1634 // This is made difficult due to commonalities between Chinese
1635 // simplified vs traditional.
1636 var mostMatches
= 0;
1637 var mostMatchedLanguages
= [];
1638 for (var l
in languageMatches
) {
1639 var numMatches
= languageMatches
[l
];
1640 if (numMatches
> mostMatches
) {
1641 mostMatches
= numMatches
;
1642 mostMatchedLanguages
= [l
];
1644 else if (numMatches
== mostMatches
) {
1645 mostMatchedLanguages
.push(l
);
1649 if (mostMatchedLanguages
.length
> 0) {
1650 // Use first language and warn if multiple detected
1651 language
= mostMatchedLanguages
[0];
1652 if (mostMatchedLanguages
.length
> 1) {
1653 console
.warn("Multiple possible languages");
1654 console
.warn(mostMatchedLanguages
);
1661 function getLanguageFromUrl() {
1662 for (var language
in WORDLISTS
) {
1663 if (window
.location
.hash
.indexOf(language
) > -1) {
1670 function setMnemonicLanguage() {
1671 var language
= getLanguage();
1672 // Load the bip39 mnemonic generator for this language if required
1673 if (!(language
in mnemonics
)) {
1674 mnemonics
[language
] = new Mnemonic(language
);
1676 mnemonic
= mnemonics
[language
];
1679 function convertPhraseToNewLanguage() {
1680 var oldLanguage
= getLanguageFromPhrase();
1681 var newLanguage
= getLanguageFromUrl();
1682 var oldPhrase
= DOM
.phrase
.val();
1683 var oldWords
= phraseToWordArray(oldPhrase
);
1685 for (var i
=0; i
<oldWords
.length
; i
++) {
1686 var oldWord
= oldWords
[i
];
1687 var index
= WORDLISTS
[oldLanguage
].indexOf(oldWord
);
1688 var newWord
= WORDLISTS
[newLanguage
][index
];
1689 newWords
.push(newWord
);
1691 newPhrase
= wordArrayToPhrase(newWords
);
1695 // TODO look at jsbip39 - mnemonic.splitWords
1696 function phraseToWordArray(phrase
) {
1697 var words
= phrase
.split(/\s/g);
1699 for (var i
=0; i
<words
.length
; i
++) {
1700 var word
= words
[i
];
1701 if (word
.length
> 0) {
1702 noBlanks
.push(word
);
1708 // TODO look at jsbip39 - mnemonic.joinWords
1709 function wordArrayToPhrase(words
) {
1710 var phrase
= words
.join(" ");
1711 var language
= getLanguageFromPhrase(phrase
);
1712 if (language
== "japanese") {
1713 phrase
= words
.join("\u3000");
1718 function writeSplitPhrase(phrase
) {
1719 var wordCount
= phrase
.split(/\s/g).length
;
1721 for (var i
=0;i
<wordCount
;i
++) left
.push(i
);
1722 var group
=[[],[],[]],
1724 var seed
= Math
.abs(sjcl
.hash
.sha256
.hash(phrase
)[0])% 2147483647;
1725 while (left
.length
>0) {
1726 groupI
=(groupI
+1)%3;
1727 seed
= seed
* 16807 % 2147483647;
1728 var selected
=Math
.floor(left
.length
*(seed
- 1) / 2147483646);
1729 group
[groupI
].push(left
[selected
]);
1730 left
.splice(selected
,1);
1732 var cards
=[phrase
.split(/\s/g),phrase
.split(/\s/g),phrase
.split(/\s/g)];
1733 for (var i
=0;i
<3;i
++) {
1734 for (var ii
=0;ii
<wordCount
/3;ii
++) cards
[i
][group
[i
][ii
]]='XXXX';
1735 cards
[i
]='Card '+(i
+1)+': '+wordArrayToPhrase(cards
[i
]);
1737 DOM
.phraseSplit
.val(cards
.join("\r\n"));
1738 var triesPerSecond
=10000000000;
1739 var hackTime
=Math
.pow(2,wordCount
*10/3)/triesPerSecond
;
1740 var displayRedText
= false;
1742 hackTime
="<1 second";
1743 displayRedText
= true;
1744 } else if (hackTime
<86400) {
1745 hackTime
=Math
.floor(hackTime
)+" seconds";
1746 displayRedText
= true;
1747 } else if(hackTime
<31557600) {
1748 hackTime
=Math
.floor(hackTime
/86400)+" days";
1749 displayRedText
= true;
1751 hackTime
=Math
.floor(hackTime
/31557600)+" years";
1753 DOM
.phraseSplitWarn
.html("Time to hack with only one card: "+hackTime
);
1754 if (displayRedText
) {
1755 DOM
.phraseSplitWarn
.addClass("text-danger");
1757 DOM
.phraseSplitWarn
.removeClass("text-danger");
1761 function isUsingOwnEntropy() {
1762 return DOM
.useEntropy
.prop("checked");
1765 function setMnemonicFromEntropy() {
1766 clearEntropyFeedback();
1767 // Get entropy value
1768 var entropyStr
= DOM
.entropy
.val();
1769 // Work out minimum base for entropy
1771 if (entropyTypeAutoDetect
) {
1772 entropy
= Entropy
.fromString(entropyStr
);
1775 let base
= DOM
.entropyTypeInputs
.filter(":checked").val();
1776 entropy
= Entropy
.fromString(entropyStr
, base
);
1778 if (entropy
.binaryStr
.length
== 0) {
1781 // Show entropy details
1782 showEntropyFeedback(entropy
);
1783 // Use entropy hash if not using raw entropy
1784 var bits
= entropy
.binaryStr
;
1785 var mnemonicLength
= DOM
.entropyMnemonicLength
.val();
1786 if (mnemonicLength
!= "raw") {
1787 // Get bits by hashing entropy with SHA256
1788 var hash
= sjcl
.hash
.sha256
.hash(entropy
.cleanStr
);
1789 var hex
= sjcl
.codec
.hex
.fromBits(hash
);
1790 bits
= libs
.BigInteger
.BigInteger
.parse(hex
, 16).toString(2);
1791 while (bits
.length
% 256 != 0) {
1794 // Truncate hash to suit number of words
1795 mnemonicLength
= parseInt(mnemonicLength
);
1796 var numberOfBits
= 32 * mnemonicLength
/ 3;
1797 bits
= bits
.substring(0, numberOfBits
);
1798 // show warning for weak entropy override
1799 if (mnemonicLength
/ 3 * 32 > entropy
.binaryStr
.length
) {
1800 DOM
.entropyWeakEntropyOverrideWarning
.removeClass("hidden");
1803 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1807 // hide warning for weak entropy override
1808 DOM
.entropyWeakEntropyOverrideWarning
.addClass("hidden");
1810 // Discard trailing entropy
1811 var bitsToUse
= Math
.floor(bits
.length
/ 32) * 32;
1812 var start
= bits
.length
- bitsToUse
;
1813 var binaryStr
= bits
.substring(start
);
1814 // Convert entropy string to numeric array
1815 var entropyArr
= [];
1816 for (var i
=0; i
<binaryStr
.length
/ 8; i
++) {
1817 var byteAsBits
= binaryStr
.substring(i
*8, i
*8+8);
1818 var entropyByte
= parseInt(byteAsBits
, 2);
1819 entropyArr
.push(entropyByte
)
1821 // Convert entropy array to mnemonic
1822 var phrase
= mnemonic
.toMnemonic(entropyArr
);
1823 // Set the mnemonic in the UI
1824 DOM
.phrase
.val(phrase
);
1825 writeSplitPhrase(phrase
);
1826 // Show the word indexes
1828 // Show the checksum
1832 function clearEntropyFeedback() {
1833 DOM
.entropyCrackTime
.text("...");
1834 DOM
.entropyType
.text("");
1835 DOM
.entropyWordCount
.text("0");
1836 DOM
.entropyEventCount
.text("0");
1837 DOM
.entropyBitsPerEvent
.text("0");
1838 DOM
.entropyBits
.text("0");
1839 DOM
.entropyFiltered
.html(" ");
1840 DOM
.entropyBinary
.html(" ");
1843 function showEntropyFeedback(entropy
) {
1844 var numberOfBits
= entropy
.binaryStr
.length
;
1845 var timeToCrack
= "unknown";
1847 var z
= libs
.zxcvbn(entropy
.base
.events
.join(""));
1848 timeToCrack
= z
.crack_times_display
.offline_fast_hashing_1e10_per_second
;
1849 if (z
.feedback
.warning
!= "") {
1850 timeToCrack
= timeToCrack
+ " - " + z
.feedback
.warning
;
1854 console
.log("Error detecting entropy strength with zxcvbn:");
1857 var entropyTypeStr
= getEntropyTypeStr(entropy
);
1858 DOM
.entropyTypeInputs
.attr("checked", false);
1859 DOM
.entropyTypeInputs
.filter("[value='" + entropyTypeStr
+ "']").attr("checked", true);
1860 var wordCount
= Math
.floor(numberOfBits
/ 32) * 3;
1861 var bitsPerEvent
= entropy
.bitsPerEvent
.toFixed(2);
1862 var spacedBinaryStr
= addSpacesEveryElevenBits(entropy
.binaryStr
);
1863 DOM
.entropyFiltered
.html(entropy
.cleanHtml
);
1864 DOM
.entropyType
.text(entropyTypeStr
);
1865 DOM
.entropyCrackTime
.text(timeToCrack
);
1866 DOM
.entropyEventCount
.text(entropy
.base
.events
.length
);
1867 DOM
.entropyBits
.text(numberOfBits
);
1868 DOM
.entropyWordCount
.text(wordCount
);
1869 DOM
.entropyBinary
.text(spacedBinaryStr
);
1870 DOM
.entropyBitsPerEvent
.text(bitsPerEvent
);
1871 // detect and warn of filtering
1872 var rawNoSpaces
= DOM
.entropy
.val().replace(/\s/g, "");
1873 var cleanNoSpaces
= entropy
.cleanStr
.replace(/\s/g, "");
1874 var isFiltered
= rawNoSpaces
.length
!= cleanNoSpaces
.length
;
1876 DOM
.entropyFilterWarning
.removeClass('hidden');
1879 DOM
.entropyFilterWarning
.addClass('hidden');
1883 function getEntropyTypeStr(entropy
) {
1884 var typeStr
= entropy
.base
.str
;
1885 // Add some detail if these are cards
1886 if (entropy
.base
.asInt
== 52) {
1887 var cardDetail
= []; // array of message strings
1888 // Detect duplicates
1890 var dupeTracker
= {};
1891 for (var i
=0; i
<entropy
.base
.events
.length
; i
++) {
1892 var card
= entropy
.base
.events
[i
];
1893 var cardUpper
= card
.toUpperCase();
1894 if (cardUpper
in dupeTracker
) {
1897 dupeTracker
[cardUpper
] = true;
1899 if (dupes
.length
> 0) {
1900 var dupeWord
= "duplicates";
1901 if (dupes
.length
== 1) {
1902 dupeWord
= "duplicate";
1904 var msg
= dupes
.length
+ " " + dupeWord
+ ": " + dupes
.slice(0,3).join(" ");
1905 if (dupes
.length
> 3) {
1908 cardDetail
.push(msg
);
1911 var uniqueCards
= [];
1912 for (var uniqueCard
in dupeTracker
) {
1913 uniqueCards
.push(uniqueCard
);
1915 if (uniqueCards
.length
== 52) {
1916 cardDetail
.unshift("full deck");
1918 // Detect missing cards
1919 var values
= "A23456789TJQK";
1921 var missingCards
= [];
1922 for (var i
=0; i
<suits
.length
; i
++) {
1923 for (var j
=0; j
<values
.length
; j
++) {
1924 var card
= values
[j
] + suits
[i
];
1925 if (!(card
in dupeTracker
)) {
1926 missingCards
.push(card
);
1930 // Display missing cards if six or less, ie clearly going for full deck
1931 if (missingCards
.length
> 0 && missingCards
.length
<= 6) {
1932 var msg
= missingCards
.length
+ " missing: " + missingCards
.slice(0,3).join(" ");
1933 if (missingCards
.length
> 3) {
1936 cardDetail
.push(msg
);
1938 // Add card details to typeStr
1939 if (cardDetail
.length
> 0) {
1940 typeStr
+= " (" + cardDetail
.join(", ") + ")";
1946 function setQrEvents(els
) {
1947 els
.on("mouseenter", createQr
);
1948 els
.on("mouseleave", destroyQr
);
1949 els
.on("click", toggleQr
);
1952 function createQr(e
) {
1953 var content
= e
.target
.textContent
|| e
.target
.value
;
1955 var qrEl
= libs
.kjua({
1961 DOM
.qrImage
.append(qrEl
);
1963 DOM
.qrHider
.addClass("hidden");
1966 DOM
.qrHider
.removeClass("hidden");
1968 DOM
.qrContainer
.removeClass("hidden");
1972 function destroyQr() {
1973 DOM
.qrImage
.text("");
1974 DOM
.qrContainer
.addClass("hidden");
1977 function toggleQr() {
1979 DOM
.qrHider
.toggleClass("hidden");
1980 DOM
.qrHint
.toggleClass("hidden");
1983 function bip44TabSelected() {
1984 return DOM
.bip44tab
.hasClass("active");
1987 function bip32TabSelected() {
1988 return DOM
.bip32tab
.hasClass("active");
1991 function networkIsEthereum() {
1992 var name
= networks
[DOM
.network
.val()].name
;
1993 return (name
== "ETH - Ethereum")
1994 || (name
== "ETC - Ethereum Classic")
1995 || (name
== "EWT - EnergyWeb")
1996 || (name
== "PIRL - Pirl")
1997 || (name
== "MIX - MIX")
1998 || (name
== "MOAC - MOAC")
1999 || (name
== "MUSIC - Musicoin")
2000 || (name
== "POA - Poa")
2001 || (name
== "EXP - Expanse")
2002 || (name
== "CLO - Callisto")
2003 || (name
== "DXN - DEXON")
2004 || (name
== "ELLA - Ellaism")
2005 || (name
== "ESN - Ethersocial Network")
2006 || (name
== "VET - VeChain")
2007 || (name
== "ERE - EtherCore")
2008 || (name
== "BSC - Binance Smart Chain")
2011 function networkIsRsk() {
2012 var name
= networks
[DOM
.network
.val()].name
;
2013 return (name
== "R-BTC - RSK")
2014 || (name
== "tR-BTC - RSK Testnet");
2017 function networkHasSegwit() {
2019 if ("baseNetwork" in network
) {
2020 n
= libs
.bitcoin
.networks
[network
.baseNetwork
];
2022 // check if only p2wpkh params are required
2023 if (p2wpkhSelected()) {
2024 return "p2wpkh" in n
;
2026 // check if only p2wpkh-in-p2sh params are required
2027 else if (p2wpkhInP2shSelected()) {
2028 return "p2wpkhInP2sh" in n
;
2030 // require both if it's unclear which params are required
2031 return "p2wpkh" in n
&& "p2wpkhInP2sh" in n
;
2034 function bip49TabSelected() {
2035 return DOM
.bip49tab
.hasClass("active");
2038 function bip84TabSelected() {
2039 return DOM
.bip84tab
.hasClass("active");
2042 function bip141TabSelected() {
2043 return DOM
.bip141tab
.hasClass("active");
2046 function setHdCoin(coinValue
) {
2047 DOM
.bip44coin
.val(coinValue
);
2048 DOM
.bip49coin
.val(coinValue
);
2049 DOM
.bip84coin
.val(coinValue
);
2052 function showSegwitAvailable() {
2053 DOM
.bip49unavailable
.addClass("hidden");
2054 DOM
.bip49available
.removeClass("hidden");
2055 DOM
.bip84unavailable
.addClass("hidden");
2056 DOM
.bip84available
.removeClass("hidden");
2057 DOM
.bip141unavailable
.addClass("hidden");
2058 DOM
.bip141available
.removeClass("hidden");
2061 function showSegwitUnavailable() {
2062 DOM
.bip49available
.addClass("hidden");
2063 DOM
.bip49unavailable
.removeClass("hidden");
2064 DOM
.bip84available
.addClass("hidden");
2065 DOM
.bip84unavailable
.removeClass("hidden");
2066 DOM
.bip141available
.addClass("hidden");
2067 DOM
.bip141unavailable
.removeClass("hidden");
2070 function adjustNetworkForSegwit() {
2071 // If segwit is selected the xpub/xprv prefixes need to be adjusted
2072 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
2074 // See https://github.com/iancoleman/bip39/issues/125
2075 var segwitNetworks
= null;
2076 // if a segwit network is alread selected, need to use base network to
2077 // look up new parameters
2078 if ("baseNetwork" in network
) {
2079 network
= libs
.bitcoin
.networks
[network
.baseNetwork
];
2081 // choose the right segwit params
2082 if (p2wpkhSelected() && "p2wpkh" in network
) {
2083 network
= network
.p2wpkh
;
2085 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network
) {
2086 network
= network
.p2wpkhInP2sh
;
2088 else if (p2wshSelected() && "p2wsh" in network
) {
2089 network
= network
.p2wsh
;
2091 else if (p2wshInP2shSelected() && "p2wshInP2sh" in network
) {
2092 network
= network
.p2wshInP2sh
;
2096 function lastIndexInTable() {
2097 var pathText
= DOM
.addresses
.find(".index").last().text();
2098 var pathBits
= pathText
.split("/");
2099 var lastBit
= pathBits
[pathBits
.length
-1];
2100 var lastBitClean
= lastBit
.replace("'", "");
2101 return parseInt(lastBitClean
);
2104 function uint8ArrayToHex(a
) {
2106 for (var i
=0; i
<a
.length
; i
++) {
2107 var h
= a
[i
].toString(16);
2108 while (h
.length
< 2) {
2116 function showWordIndexes() {
2117 var phrase
= DOM
.phrase
.val();
2118 var words
= phraseToWordArray(phrase
);
2119 var wordIndexes
= [];
2120 var language
= getLanguage();
2121 for (var i
=0; i
<words
.length
; i
++) {
2122 var word
= words
[i
];
2123 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
2124 wordIndexes
.push(wordIndex
);
2126 var wordIndexesStr
= wordIndexes
.join(", ");
2127 DOM
.entropyWordIndexes
.text(wordIndexesStr
);
2130 function showChecksum() {
2131 var phrase
= DOM
.phrase
.val();
2132 var words
= phraseToWordArray(phrase
);
2133 var checksumBitlength
= words
.length
/ 3;
2136 var language
= getLanguage();
2137 for (var i
=words
.length
-1; i
>=0; i
--) {
2138 var word
= words
[i
];
2139 var wordIndex
= WORDLISTS
[language
].indexOf(word
);
2140 var wordBinary
= wordIndex
.toString(2);
2141 while (wordBinary
.length
< 11) {
2142 wordBinary
= "0" + wordBinary
;
2144 var binaryStr
= wordBinary
+ binaryStr
;
2145 if (binaryStr
.length
>= checksumBitlength
) {
2146 var start
= binaryStr
.length
- checksumBitlength
;
2147 var end
= binaryStr
.length
;
2148 checksum
= binaryStr
.substring(start
, end
);
2149 // add spaces so the last group is 11 bits, not the first
2150 checksum
= checksum
.split("").reverse().join("")
2151 checksum
= addSpacesEveryElevenBits(checksum
);
2152 checksum
= checksum
.split("").reverse().join("")
2156 DOM
.entropyChecksum
.text(checksum
);
2159 function updateCsv() {
2160 var tableCsv
= "path,address,public key,private key\n";
2161 var rows
= DOM
.addresses
.find("tr");
2162 for (var i
=0; i
<rows
.length
; i
++) {
2163 var row
= $(rows
[i
]);
2164 var cells
= row
.find("td");
2165 for (var j
=0; j
<cells
.length
; j
++) {
2166 var cell
= $(cells
[j
]);
2167 if (!cell
.children().hasClass("invisible")) {
2168 tableCsv
= tableCsv
+ cell
.text();
2170 if (j
!= cells
.length
- 1) {
2171 tableCsv
= tableCsv
+ ",";
2174 tableCsv
= tableCsv
+ "\n";
2176 DOM
.csv
.val(tableCsv
);
2179 function addSpacesEveryElevenBits(binaryStr
) {
2180 return binaryStr
.match(/.{1,11}/g).join(" ");
2185 name: "AC - Asiacoin",
2186 onSelect: function() {
2187 network
= libs
.bitcoin
.networks
.asiacoin
;
2192 name: "ACC - Adcoin",
2193 onSelect: function() {
2194 network
= libs
.bitcoin
.networks
.adcoin
;
2199 name: "AGM - Argoneum",
2200 onSelect: function() {
2201 network
= libs
.bitcoin
.networks
.argoneum
;
2206 name: "ARYA - Aryacoin",
2207 onSelect: function() {
2208 network
= libs
.bitcoin
.networks
.aryacoin
;
2213 name: "AUR - Auroracoin",
2214 onSelect: function() {
2215 network
= libs
.bitcoin
.networks
.auroracoin
;
2221 onSelect: function() {
2222 network
= libs
.bitcoin
.networks
.axe
;
2227 name: "ANON - ANON",
2228 onSelect: function() {
2229 network
= libs
.bitcoin
.networks
.anon
;
2234 name: "BOLI - Bolivarcoin",
2235 onSelect: function() {
2236 network
= libs
.bitcoin
.networks
.bolivarcoin
;
2241 name: "BCA - Bitcoin Atom",
2242 onSelect: function() {
2243 network
= libs
.bitcoin
.networks
.atom
;
2248 name: "BCH - Bitcoin Cash",
2249 onSelect: function() {
2250 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
2255 name: "BEET - Beetlecoin",
2256 onSelect: function() {
2257 network
= libs
.bitcoin
.networks
.beetlecoin
;
2262 name: "BELA - Belacoin",
2263 onSelect: function() {
2264 network
= libs
.bitcoin
.networks
.belacoin
;
2269 name: "BLK - BlackCoin",
2270 onSelect: function() {
2271 network
= libs
.bitcoin
.networks
.blackcoin
;
2276 name: "BND - Blocknode",
2277 onSelect: function() {
2278 network
= libs
.bitcoin
.networks
.blocknode
;
2283 name: "tBND - Blocknode Testnet",
2284 onSelect: function() {
2285 network
= libs
.bitcoin
.networks
.blocknode_testnet
;
2290 name: "BRIT - Britcoin",
2291 onSelect: function() {
2292 network
= libs
.bitcoin
.networks
.britcoin
;
2297 name: "BSD - Bitsend",
2298 onSelect: function() {
2299 network
= libs
.bitcoin
.networks
.bitsend
;
2304 name: "BST - BlockStamp",
2305 onSelect: function() {
2306 network
= libs
.bitcoin
.networks
.blockstamp
;
2312 onSelect: function() {
2313 network
= libs
.bitcoin
.networks
.bata
;
2318 name: "BTC - Bitcoin",
2319 onSelect: function() {
2320 network
= libs
.bitcoin
.networks
.bitcoin
;
2325 name: "BTC - Bitcoin RegTest",
2326 onSelect: function() {
2327 network
= libs
.bitcoin
.networks
.regtest
;
2328 // Using hd coin value 1 based on bip44_coin_type
2329 // https://github.com/chaintope/bitcoinrb/blob/f1014406f6b8f9b4edcecedc18df70c80df06f11/lib/bitcoin/chainparams/regtest.yml
2334 name: "BTC - Bitcoin Testnet",
2335 onSelect: function() {
2336 network
= libs
.bitcoin
.networks
.testnet
;
2341 name: "BITG - Bitcoin Green",
2342 onSelect: function() {
2343 network
= libs
.bitcoin
.networks
.bitcoingreen
;
2348 name: "BTCP - Bitcoin Private",
2349 onSelect: function() {
2350 network
= libs
.bitcoin
.networks
.bitcoinprivate
;
2355 name: "BSC - Binance Smart Chain",
2356 onSelect: function() {
2357 network
= libs
.bitcoin
.networks
.bitcoin
;
2362 name: "BSV - BitcoinSV",
2363 onSelect: function() {
2364 network
= libs
.bitcoin
.networks
.bitcoinsv
;
2369 name: "BTCZ - Bitcoinz",
2370 onSelect: function() {
2371 network
= libs
.bitcoin
.networks
.bitcoinz
;
2376 name: "BTDX - BitCloud",
2377 onSelect: function() {
2378 network
= libs
.bitcoin
.networks
.bitcloud
;
2383 name: "BTG - Bitcoin Gold",
2384 onSelect: function() {
2385 network
= libs
.bitcoin
.networks
.bgold
;
2390 name: "BTX - Bitcore",
2391 onSelect: function() {
2392 network
= libs
.bitcoin
.networks
.bitcore
;
2397 name: "CCN - Cannacoin",
2398 onSelect: function() {
2399 network
= libs
.bitcoin
.networks
.cannacoin
;
2404 name: "CESC - Cryptoescudo",
2405 onSelect: function() {
2406 network
= libs
.bitcoin
.networks
.cannacoin
;
2411 name: "CDN - Canadaecoin",
2412 onSelect: function() {
2413 network
= libs
.bitcoin
.networks
.canadaecoin
;
2418 name: "CLAM - Clams",
2419 onSelect: function() {
2420 network
= libs
.bitcoin
.networks
.clam
;
2425 name: "CLO - Callisto",
2426 segwitAvailable: false,
2427 onSelect: function() {
2428 network
= libs
.bitcoin
.networks
.bitcoin
;
2433 name: "CLUB - Clubcoin",
2434 onSelect: function() {
2435 network
= libs
.bitcoin
.networks
.clubcoin
;
2440 name: "CMP - Compcoin",
2441 onSelect: function() {
2442 network
= libs
.bitcoin
.networks
.compcoin
;
2447 name: "CPU - CPUchain",
2448 onSelect: function() {
2449 network
= libs
.bitcoin
.networks
.cpuchain
;
2454 name: "CRAVE - Crave",
2455 onSelect: function() {
2456 network
= libs
.bitcoin
.networks
.crave
;
2461 name: "CRP - CranePay",
2462 onSelect: function() {
2463 network
= libs
.bitcoin
.networks
.cranepay
;
2469 name: "CRW - Crown (Legacy)",
2470 onSelect: function() {
2471 network
= libs
.bitcoin
.networks
.crown
;
2476 name: "CRW - Crown",
2477 onSelect: function() {
2478 network
= libs
.bitcoin
.networks
.crown
;
2483 name: "CSC - CasinoCoin",
2484 onSelect: function() {
2485 network
= libs
.bitcoin
.networks
.bitcoin
;
2490 name: "DASH - Dash",
2491 onSelect: function() {
2492 network
= libs
.bitcoin
.networks
.dash
;
2497 name: "DASH - Dash Testnet",
2498 onSelect: function() {
2499 network
= libs
.bitcoin
.networks
.dashtn
;
2504 name: "DFC - Defcoin",
2505 onSelect: function() {
2506 network
= libs
.bitcoin
.networks
.defcoin
;
2511 name: "DGB - Digibyte",
2512 onSelect: function() {
2513 network
= libs
.bitcoin
.networks
.digibyte
;
2518 name: "DGC - Digitalcoin",
2519 onSelect: function() {
2520 network
= libs
.bitcoin
.networks
.digitalcoin
;
2525 name: "DMD - Diamond",
2526 onSelect: function() {
2527 network
= libs
.bitcoin
.networks
.diamond
;
2532 name: "DNR - Denarius",
2533 onSelect: function() {
2534 network
= libs
.bitcoin
.networks
.denarius
;
2539 name: "DOGE - Dogecoin",
2540 onSelect: function() {
2541 network
= libs
.bitcoin
.networks
.dogecoin
;
2546 name: "DOGEt - Dogecoin Testnet",
2547 onSelect: function() {
2548 network
= libs
.bitcoin
.networks
.dogecointestnet
;
2553 name: "DXN - DEXON",
2554 onSelect: function() {
2555 network
= libs
.bitcoin
.networks
.bitcoin
;
2560 name: "ECN - Ecoin",
2561 onSelect: function() {
2562 network
= libs
.bitcoin
.networks
.ecoin
;
2567 name: "EDRC - Edrcoin",
2568 onSelect: function() {
2569 network
= libs
.bitcoin
.networks
.edrcoin
;
2574 name: "EFL - Egulden",
2575 onSelect: function() {
2576 network
= libs
.bitcoin
.networks
.egulden
;
2581 name: "ELA - Elastos",
2582 onSelect: function () {
2583 network
= libs
.bitcoin
.networks
.elastos
;
2588 name: "ELLA - Ellaism",
2589 segwitAvailable: false,
2590 onSelect: function() {
2591 network
= libs
.bitcoin
.networks
.bitcoin
;
2596 name: "EMC2 - Einsteinium",
2597 onSelect: function() {
2598 network
= libs
.bitcoin
.networks
.einsteinium
;
2603 name: "ERC - Europecoin",
2604 onSelect: function() {
2605 network
= libs
.bitcoin
.networks
.europecoin
;
2610 name: "EOS - EOSIO",
2611 onSelect: function() {
2612 network
= libs
.bitcoin
.networks
.bitcoin
;
2617 name: "ERE - EtherCore",
2618 segwitAvailable: false,
2619 onSelect: function() {
2620 network
= libs
.bitcoin
.networks
.bitcoin
;
2625 name: "ESN - Ethersocial Network",
2626 segwitAvailable: false,
2627 onSelect: function() {
2628 network
= libs
.bitcoin
.networks
.bitcoin
;
2633 name: "ETC - Ethereum Classic",
2634 segwitAvailable: false,
2635 onSelect: function() {
2636 network
= libs
.bitcoin
.networks
.bitcoin
;
2641 name: "ETH - Ethereum",
2642 onSelect: function() {
2643 network
= libs
.bitcoin
.networks
.bitcoin
;
2648 name: "EWT - EnergyWeb",
2649 onSelect: function() {
2650 network
= libs
.bitcoin
.networks
.bitcoin
;
2655 name: "EXCL - Exclusivecoin",
2656 onSelect: function() {
2657 network
= libs
.bitcoin
.networks
.exclusivecoin
;
2662 name: "EXCC - ExchangeCoin",
2663 onSelect: function() {
2664 network
= libs
.bitcoin
.networks
.exchangecoin
;
2669 name: "EXP - Expanse",
2670 segwitAvailable: false,
2671 onSelect: function() {
2672 network
= libs
.bitcoin
.networks
.bitcoin
;
2677 name: "FIO - Foundation for Interwallet Operability",
2678 onSelect: function() {
2679 network
= libs
.bitcoin
.networks
.bitcoin
;
2685 onSelect: function() {
2686 network
= libs
.bitcoin
.networks
.fix
;
2691 name: "FIX - FIX Testnet",
2692 onSelect: function() {
2693 network
= libs
.bitcoin
.networks
.fixtestnet
;
2698 name: "FJC - Fujicoin",
2699 onSelect: function() {
2700 network
= libs
.bitcoin
.networks
.fujicoin
;
2705 name: "FLASH - Flashcoin",
2706 onSelect: function() {
2707 network
= libs
.bitcoin
.networks
.flashcoin
;
2712 name: "FRST - Firstcoin",
2713 onSelect: function() {
2714 network
= libs
.bitcoin
.networks
.firstcoin
;
2719 name: "FTC - Feathercoin",
2720 onSelect: function() {
2721 network
= libs
.bitcoin
.networks
.feathercoin
;
2726 name: "GAME - GameCredits",
2727 onSelect: function() {
2728 network
= libs
.bitcoin
.networks
.game
;
2733 name: "GBX - Gobyte",
2734 onSelect: function() {
2735 network
= libs
.bitcoin
.networks
.gobyte
;
2740 name: "GCR - GCRCoin",
2741 onSelect: function() {
2742 network
= libs
.bitcoin
.networks
.gcr
;
2747 name: "GRC - Gridcoin",
2748 onSelect: function() {
2749 network
= libs
.bitcoin
.networks
.gridcoin
;
2754 name: "GRS - Groestlcoin",
2755 onSelect: function() {
2756 network
= libs
.bitcoin
.networks
.groestlcoin
;
2761 name: "GRS - Groestlcoin Testnet",
2762 onSelect: function() {
2763 network
= libs
.bitcoin
.networks
.groestlcointestnet
;
2768 name: "HNS - Handshake",
2769 onSelect: function() {
2774 name: "HNC - Helleniccoin",
2775 onSelect: function() {
2776 network
= libs
.bitcoin
.networks
.helleniccoin
;
2781 name: "HUSH - Hush (Legacy)",
2782 onSelect: function() {
2783 network
= libs
.bitcoin
.networks
.hush
;
2788 name: "HUSH - Hush3",
2789 onSelect: function() {
2790 network
= libs
.bitcoin
.networks
.hush3
;
2795 name: "INSN - Insane",
2796 onSelect: function() {
2797 network
= libs
.bitcoin
.networks
.insane
;
2803 onSelect: function() {
2804 network
= libs
.bitcoin
.networks
.iop
;
2809 name: "IXC - Ixcoin",
2810 onSelect: function() {
2811 network
= libs
.bitcoin
.networks
.ixcoin
;
2816 name: "JBS - Jumbucks",
2817 onSelect: function() {
2818 network
= libs
.bitcoin
.networks
.jumbucks
;
2823 name: "KMD - Komodo",
2824 bip49available: false,
2825 onSelect: function() {
2826 network
= libs
.bitcoin
.networks
.komodo
;
2831 name: "KOBO - Kobocoin",
2832 bip49available: false,
2833 onSelect: function() {
2834 network
= libs
.bitcoin
.networks
.kobocoin
;
2839 name: "LBC - Library Credits",
2840 onSelect: function() {
2841 network
= libs
.bitcoin
.networks
.lbry
;
2846 name: "LCC - Litecoincash",
2847 onSelect: function() {
2848 network
= libs
.bitcoin
.networks
.litecoincash
;
2853 name: "LDCN - Landcoin",
2854 onSelect: function() {
2855 network
= libs
.bitcoin
.networks
.landcoin
;
2860 name: "LINX - Linx",
2861 onSelect: function() {
2862 network
= libs
.bitcoin
.networks
.linx
;
2867 name: "LKR - Lkrcoin",
2868 segwitAvailable: false,
2869 onSelect: function() {
2870 network
= libs
.bitcoin
.networks
.lkrcoin
;
2875 name: "LTC - Litecoin",
2876 onSelect: function() {
2877 network
= libs
.bitcoin
.networks
.litecoin
;
2879 DOM
.litecoinLtubContainer
.removeClass("hidden");
2883 name: "LTCt - Litecoin Testnet",
2884 onSelect: function() {
2885 network
= libs
.bitcoin
.networks
.litecointestnet
;
2887 DOM
.litecoinLtubContainer
.removeClass("hidden");
2891 name: "LTZ - LitecoinZ",
2892 onSelect: function() {
2893 network
= libs
.bitcoin
.networks
.litecoinz
;
2898 name: "LYNX - Lynx",
2899 onSelect: function() {
2900 network
= libs
.bitcoin
.networks
.lynx
;
2905 name: "MAZA - Maza",
2906 onSelect: function() {
2907 network
= libs
.bitcoin
.networks
.maza
;
2912 name: "MEC - Megacoin",
2913 onSelect: function() {
2914 network
= libs
.bitcoin
.networks
.megacoin
;
2920 segwitAvailable: false,
2921 onSelect: function() {
2922 network
= libs
.bitcoin
.networks
.bitcoin
;
2927 name: "MNX - Minexcoin",
2928 onSelect: function() {
2929 network
= libs
.bitcoin
.networks
.minexcoin
;
2934 name: "MONA - Monacoin",
2935 onSelect: function() {
2936 network
= libs
.bitcoin
.networks
.monacoin
,
2941 name: "MONK - Monkey Project",
2942 onSelect: function() {
2943 network
= libs
.bitcoin
.networks
.monkeyproject
,
2948 name: "MOAC - MOAC",
2949 segwitAvailable: false,
2950 onSelect: function() {
2951 network
= libs
.bitcoin
.networks
.bitcoin
;
2956 name: "MUSIC - Musicoin",
2957 segwitAvailable: false,
2958 onSelect: function() {
2959 network
= libs
.bitcoin
.networks
.bitcoin
;
2964 name: "NANO - Nano",
2965 onSelect: function() {
2966 network
= network
= libs
.nanoUtil
.dummyNetwork
;
2971 name: "NAV - Navcoin",
2972 onSelect: function() {
2973 network
= libs
.bitcoin
.networks
.navcoin
;
2978 name: "NAS - Nebulas",
2979 onSelect: function() {
2980 network
= libs
.bitcoin
.networks
.bitcoin
;
2985 name: "NEBL - Neblio",
2986 onSelect: function() {
2987 network
= libs
.bitcoin
.networks
.neblio
;
2992 name: "NEOS - Neoscoin",
2993 onSelect: function() {
2994 network
= libs
.bitcoin
.networks
.neoscoin
;
2999 name: "NIX - NIX Platform",
3000 onSelect: function() {
3001 network
= libs
.bitcoin
.networks
.nix
;
3006 name: "NLG - Gulden",
3007 onSelect: function() {
3008 network
= libs
.bitcoin
.networks
.gulden
;
3013 name: "NMC - Namecoin",
3014 onSelect: function() {
3015 network
= libs
.bitcoin
.networks
.namecoin
;
3020 name: "NRG - Energi",
3021 onSelect: function() {
3022 network
= libs
.bitcoin
.networks
.energi
;
3027 name: "NRO - Neurocoin",
3028 onSelect: function() {
3029 network
= libs
.bitcoin
.networks
.neurocoin
;
3034 name: "NSR - Nushares",
3035 onSelect: function() {
3036 network
= libs
.bitcoin
.networks
.nushares
;
3041 name: "NYC - Newyorkc",
3042 onSelect: function() {
3043 network
= libs
.bitcoin
.networks
.newyorkc
;
3048 name: "NVC - Novacoin",
3049 onSelect: function() {
3050 network
= libs
.bitcoin
.networks
.novacoin
;
3055 name: "OK - Okcash",
3056 onSelect: function() {
3057 network
= libs
.bitcoin
.networks
.okcash
;
3062 name: "OMNI - Omnicore",
3063 onSelect: function() {
3064 network
= libs
.bitcoin
.networks
.omnicore
;
3069 name: "ONION - DeepOnion",
3070 onSelect: function() {
3071 network
= libs
.bitcoin
.networks
.deeponion
;
3076 name: "ONX - Onixcoin",
3077 onSelect: function() {
3078 network
= libs
.bitcoin
.networks
.onixcoin
;
3083 name: "PHR - Phore",
3084 onSelect: function() {
3085 network
= libs
.bitcoin
.networks
.phore
;
3090 name: "PINK - Pinkcoin",
3091 onSelect: function() {
3092 network
= libs
.bitcoin
.networks
.pinkcoin
;
3097 name: "PIRL - Pirl",
3098 segwitAvailable: false,
3099 onSelect: function() {
3100 network
= libs
.bitcoin
.networks
.bitcoin
;
3105 name: "PIVX - PIVX",
3106 onSelect: function() {
3107 network
= libs
.bitcoin
.networks
.pivx
;
3112 name: "PIVX - PIVX Testnet",
3113 onSelect: function() {
3114 network
= libs
.bitcoin
.networks
.pivxtestnet
;
3120 segwitAvailable: false,
3121 onSelect: function() {
3122 network
= libs
.bitcoin
.networks
.bitcoin
;
3127 name: "POSW - POSWcoin",
3128 onSelect: function() {
3129 network
= libs
.bitcoin
.networks
.poswcoin
;
3134 name: "POT - Potcoin",
3135 onSelect: function() {
3136 network
= libs
.bitcoin
.networks
.potcoin
;
3141 name: "PPC - Peercoin",
3142 onSelect: function() {
3143 network
= libs
.bitcoin
.networks
.peercoin
;
3148 name: "PRJ - ProjectCoin",
3149 onSelect: function() {
3150 network
= libs
.bitcoin
.networks
.projectcoin
;
3155 name: "PSB - Pesobit",
3156 onSelect: function() {
3157 network
= libs
.bitcoin
.networks
.pesobit
;
3162 name: "PUT - Putincoin",
3163 onSelect: function() {
3164 network
= libs
.bitcoin
.networks
.putincoin
;
3169 name: "RPD - Rapids",
3170 onSelect: function() {
3171 network
= libs
.bitcoin
.networks
.rapids
;
3176 name: "RVN - Ravencoin",
3177 onSelect: function() {
3178 network
= libs
.bitcoin
.networks
.ravencoin
;
3183 name: "R-BTC - RSK",
3184 onSelect: function() {
3185 network
= libs
.bitcoin
.networks
.rsk
;
3190 name: "tR-BTC - RSK Testnet",
3191 onSelect: function() {
3192 network
= libs
.bitcoin
.networks
.rsktestnet
;
3197 name: "RBY - Rubycoin",
3198 onSelect: function() {
3199 network
= libs
.bitcoin
.networks
.rubycoin
;
3204 name: "RDD - Reddcoin",
3205 onSelect: function() {
3206 network
= libs
.bitcoin
.networks
.reddcoin
;
3211 name: "RVR - RevolutionVR",
3212 onSelect: function() {
3213 network
= libs
.bitcoin
.networks
.revolutionvr
;
3218 name: "SAFE - Safecoin",
3219 onSelect: function() {
3220 network
= libs
.bitcoin
.networks
.safecoin
;
3225 name: "SCRIBE - Scribe",
3226 onSelect: function() {
3227 network
= libs
.bitcoin
.networks
.scribe
;
3232 name: "SLS - Salus",
3233 onSelect: function() {
3234 network
= libs
.bitcoin
.networks
.salus
;
3239 name: "SDC - ShadowCash",
3240 onSelect: function() {
3241 network
= libs
.bitcoin
.networks
.shadow
;
3246 name: "SDC - ShadowCash Testnet",
3247 onSelect: function() {
3248 network
= libs
.bitcoin
.networks
.shadowtn
;
3253 name: "SLM - Slimcoin",
3254 onSelect: function() {
3255 network
= libs
.bitcoin
.networks
.slimcoin
;
3260 name: "SLM - Slimcoin Testnet",
3261 onSelect: function() {
3262 network
= libs
.bitcoin
.networks
.slimcointn
;
3267 name: "SLP - Simple Ledger Protocol",
3268 onSelect: function() {
3269 DOM
.bitcoinCashAddressTypeContainer
.removeClass("hidden");
3274 name: "SLR - Solarcoin",
3275 onSelect: function() {
3276 network
= libs
.bitcoin
.networks
.solarcoin
;
3281 name: "SMLY - Smileycoin",
3282 onSelect: function() {
3283 network
= libs
.bitcoin
.networks
.smileycoin
;
3288 name: "STASH - Stash",
3289 onSelect: function() {
3290 network
= libs
.bitcoin
.networks
.stash
;
3295 name: "STASH - Stash Testnet",
3296 onSelect: function() {
3297 network
= libs
.bitcoin
.networks
.stashtn
;
3302 name: "STRAT - Stratis",
3303 onSelect: function() {
3304 network
= libs
.bitcoin
.networks
.stratis
;
3309 name: "SUGAR - Sugarchain",
3310 onSelect: function() {
3311 network
= libs
.bitcoin
.networks
.sugarchain
;
3316 name: "TUGAR - Sugarchain Testnet",
3317 onSelect: function() {
3318 network
= libs
.bitcoin
.networks
.sugarchaintestnet
;
3323 name: "SWTC - Jingtum",
3324 onSelect: function() {
3325 network
= libs
.bitcoin
.networks
.bitcoin
;
3330 name: "TSTRAT - Stratis Testnet",
3331 onSelect: function() {
3332 network
= libs
.bitcoin
.networks
.stratistest
;
3337 name: "SYS - Syscoin",
3338 onSelect: function() {
3339 network
= libs
.bitcoin
.networks
.syscoin
;
3344 name: "THC - Hempcoin",
3345 onSelect: function() {
3346 network
= libs
.bitcoin
.networks
.hempcoin
;
3351 name: "THT - Thought",
3352 onSelect: function() {
3353 network
= libs
.bitcoin
.networks
.thought
;
3359 onSelect: function() {
3360 network
= libs
.bitcoin
.networks
.toa
;
3366 onSelect: function() {
3371 name: "TWINS - TWINS",
3372 onSelect: function() {
3373 network
= libs
.bitcoin
.networks
.twins
;
3378 name: "TWINS - TWINS Testnet",
3379 onSelect: function() {
3380 network
= libs
.bitcoin
.networks
.twinstestnet
;
3385 name: "USC - Ultimatesecurecash",
3386 onSelect: function() {
3387 network
= libs
.bitcoin
.networks
.ultimatesecurecash
;
3392 name: "USNBT - NuBits",
3393 onSelect: function() {
3394 network
= libs
.bitcoin
.networks
.nubits
;
3399 name: "UNO - Unobtanium",
3400 onSelect: function() {
3401 network
= libs
.bitcoin
.networks
.unobtanium
;
3406 name: "VASH - Vpncoin",
3407 onSelect: function() {
3408 network
= libs
.bitcoin
.networks
.vpncoin
;
3413 name: "VET - VeChain",
3414 onSelect: function() {
3415 network
= libs
.bitcoin
.networks
.bitcoin
;
3420 name: "VIA - Viacoin",
3421 onSelect: function() {
3422 network
= libs
.bitcoin
.networks
.viacoin
;
3427 name: "VIA - Viacoin Testnet",
3428 onSelect: function() {
3429 network
= libs
.bitcoin
.networks
.viacointestnet
;
3434 name: "VIVO - Vivo",
3435 onSelect: function() {
3436 network
= libs
.bitcoin
.networks
.vivo
;
3441 name: "VTC - Vertcoin",
3442 onSelect: function() {
3443 network
= libs
.bitcoin
.networks
.vertcoin
;
3448 name: "WGR - Wagerr",
3449 onSelect: function() {
3450 network
= libs
.bitcoin
.networks
.wagerr
;
3455 name: "WC - Wincoin",
3456 onSelect: function() {
3457 network
= libs
.bitcoin
.networks
.wincoin
;
3462 name: "XAX - Artax",
3463 onSelect: function() {
3464 network
= libs
.bitcoin
.networks
.artax
;
3469 name: "XBC - Bitcoinplus",
3470 onSelect: function() {
3471 network
= libs
.bitcoin
.networks
.bitcoinplus
;
3476 name: "XLM - Stellar",
3477 onSelect: function() {
3478 network
= libs
.stellarUtil
.dummyNetwork
;
3483 name: "XMY - Myriadcoin",
3484 onSelect: function() {
3485 network
= libs
.bitcoin
.networks
.myriadcoin
;
3490 name: "XRP - Ripple",
3491 onSelect: function() {
3492 network
= libs
.bitcoin
.networks
.bitcoin
;
3497 name: "XVC - Vcash",
3498 onSelect: function() {
3499 network
= libs
.bitcoin
.networks
.vcash
;
3504 name: "XVG - Verge",
3505 onSelect: function() {
3506 network
= libs
.bitcoin
.networks
.verge
;
3511 name: "XUEZ - Xuez",
3512 segwitAvailable: false,
3513 onSelect: function() {
3514 network
= libs
.bitcoin
.networks
.xuez
;
3519 name: "XWC - Whitecoin",
3520 onSelect: function() {
3521 network
= libs
.bitcoin
.networks
.whitecoin
;
3526 name: "XZC - Zcoin",
3527 onSelect: function() {
3528 network
= libs
.bitcoin
.networks
.zcoin
;
3533 name: "ZCL - Zclassic",
3534 onSelect: function() {
3535 network
= libs
.bitcoin
.networks
.zclassic
;
3540 name: "ZEC - Zcash",
3541 onSelect: function() {
3542 network
= libs
.bitcoin
.networks
.zcash
;
3547 name: "ZEN - Horizen",
3548 onSelect: function() {
3549 network
= libs
.bitcoin
.networks
.zencash
;
3557 name: "Bitcoin Core",
3558 onSelect: function() {
3559 DOM
.bip32path
.val("m/0'/0'");
3560 DOM
.hardenedAddresses
.prop('checked', true);
3564 name: "blockchain.info",
3565 onSelect: function() {
3566 DOM
.bip32path
.val("m/44'/0'/0'");
3567 DOM
.hardenedAddresses
.prop('checked', false);
3571 name: "MultiBit HD",
3572 onSelect: function() {
3573 DOM
.bip32path
.val("m/0'/0");
3574 DOM
.hardenedAddresses
.prop('checked', false);
3578 name: "Coinomi, Ledger",
3579 onSelect: function() {
3580 DOM
.bip32path
.val("m/44'/"+DOM
.bip44coin
.val()+"'/0'");
3581 DOM
.hardenedAddresses
.prop('checked', false);
3586 // RSK - RSK functions - begin
3587 function stripHexPrefix(address
) {
3588 if (typeof address
!== "string") {
3589 throw new Error("address parameter should be a string.");
3592 var hasPrefix
= (address
.substring(0, 2) === "0x" ||
3593 address
.substring(0, 2) === "0X");
3595 return hasPrefix
? address
.slice(2) : address
;
3598 function toChecksumAddressForRsk(address
, chainId
= null) {
3599 if (typeof address
!== "string") {
3600 throw new Error("address parameter should be a string.");
3603 if (!/^(0x)?[0-9a-f]{40}$/i.test(address
)) {
3604 throw new Error("Given address is not a valid RSK address: " + address
);
3607 var stripAddress
= stripHexPrefix(address
).toLowerCase();
3608 var prefix
= chainId
!= null ? chainId
.toString() + "0x" : "";
3609 var keccakHash
= libs
.ethUtil
.keccak256(prefix
+ stripAddress
)
3611 .replace(/^0x/i, "");
3612 var checksumAddress
= "0x";
3614 for (var i
= 0; i
< stripAddress
.length
; i
++) {
3616 parseInt(keccakHash
[i
], 16) >= 8 ?
3617 stripAddress
[i
].toUpperCase() :
3621 return checksumAddress
;
3624 // RSK - RSK functions - end
3626 // ELA - Elastos functions - begin
3627 function displayBip44InfoForELA() {
3632 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3633 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3635 // Calculate the account extended keys
3636 var accountXprv
= libs
.elastosjs
.getAccountExtendedPrivateKey(seed
, coin
, account
);
3637 var accountXpub
= libs
.elastosjs
.getAccountExtendedPublicKey(seed
, coin
, account
);
3639 // Display the extended keys
3640 DOM
.bip44accountXprv
.val(accountXprv
);
3641 DOM
.bip44accountXpub
.val(accountXpub
);
3644 function displayBip32InfoForELA() {
3649 var coin
= parseIntNoNaN(DOM
.bip44coin
.val(), 0);
3650 var account
= parseIntNoNaN(DOM
.bip44account
.val(), 0);
3651 var change
= parseIntNoNaN(DOM
.bip44change
.val(), 0);
3653 DOM
.extendedPrivKey
.val(libs
.elastosjs
.getBip32ExtendedPrivateKey(seed
, coin
, account
, change
));
3654 DOM
.extendedPubKey
.val(libs
.elastosjs
.getBip32ExtendedPublicKey(seed
, coin
, account
, change
));
3656 // Display the addresses and privkeys
3657 clearAddressesList();
3658 var initialAddressCount
= parseInt(DOM
.rowsToAdd
.val());
3659 displayAddresses(0, initialAddressCount
);
3662 function calcAddressForELA(seed
, coin
, account
, change
, index
) {
3667 var publicKey
= libs
.elastosjs
.getDerivedPublicKey(libs
.elastosjs
.getMasterPublicKey(seed
), change
, index
);
3669 privateKey: libs
.elastosjs
.getDerivedPrivateKey(seed
, coin
, account
, change
, index
),
3670 publicKey: publicKey
,
3671 address: libs
.elastosjs
.getAddress(publicKey
.toString('hex'))
3674 // ELA - Elastos functions - end