]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - src/js/index.js
Fix NMC scriptHash
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / src / js / index.js
1 (function() {
2
3 // mnemonics is populated as required by getLanguage
4 var mnemonics = { "english": new Mnemonic("english") };
5 var mnemonic = mnemonics["english"];
6 var seed = null;
7 var bip32RootKey = null;
8 var bip32ExtendedKey = null;
9 var network = bitcoinjs.bitcoin.networks.bitcoin;
10 var addressRowTemplate = $("#address-row-template");
11
12 var showIndex = true;
13 var showAddress = true;
14 var showPubKey = true;
15 var showPrivKey = true;
16 var showQr = false;
17 var litecoinUseLtub = true;
18
19 var entropyChangeTimeoutEvent = null;
20 var phraseChangeTimeoutEvent = null;
21 var rootKeyChangedTimeoutEvent = null;
22
23 var generationProcesses = [];
24
25 var DOM = {};
26 DOM.privacyScreenToggle = $(".privacy-screen-toggle");
27 DOM.network = $(".network");
28 DOM.bip32Client = $("#bip32-client");
29 DOM.phraseNetwork = $("#network-phrase");
30 DOM.useEntropy = $(".use-entropy");
31 DOM.entropyContainer = $(".entropy-container");
32 DOM.entropy = $(".entropy");
33 DOM.entropyFiltered = DOM.entropyContainer.find(".filtered");
34 DOM.entropyType = DOM.entropyContainer.find(".type");
35 DOM.entropyCrackTime = DOM.entropyContainer.find(".crack-time");
36 DOM.entropyEventCount = DOM.entropyContainer.find(".event-count");
37 DOM.entropyBits = DOM.entropyContainer.find(".bits");
38 DOM.entropyBitsPerEvent = DOM.entropyContainer.find(".bits-per-event");
39 DOM.entropyWordCount = DOM.entropyContainer.find(".word-count");
40 DOM.entropyBinary = DOM.entropyContainer.find(".binary");
41 DOM.entropyWordIndexes = DOM.entropyContainer.find(".word-indexes");
42 DOM.entropyChecksum = DOM.entropyContainer.find(".checksum");
43 DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length");
44 DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning");
45 DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
46 DOM.phrase = $(".phrase");
47 DOM.passphrase = $(".passphrase");
48 DOM.generateContainer = $(".generate-container");
49 DOM.generate = $(".generate");
50 DOM.seed = $(".seed");
51 DOM.rootKey = $(".root-key");
52 DOM.litecoinLtubContainer = $(".litecoin-ltub-container");
53 DOM.litecoinUseLtub = $(".litecoin-use-ltub");
54 DOM.extendedPrivKey = $(".extended-priv-key");
55 DOM.extendedPubKey = $(".extended-pub-key");
56 DOM.bip32tab = $("#bip32-tab");
57 DOM.bip44tab = $("#bip44-tab");
58 DOM.bip49tab = $("#bip49-tab");
59 DOM.bip84tab = $("#bip84-tab");
60 DOM.bip141tab = $("#bip141-tab");
61 DOM.bip32panel = $("#bip32");
62 DOM.bip44panel = $("#bip44");
63 DOM.bip49panel = $("#bip49");
64 DOM.bip32path = $("#bip32-path");
65 DOM.bip44path = $("#bip44-path");
66 DOM.bip44purpose = $("#bip44 .purpose");
67 DOM.bip44coin = $("#bip44 .coin");
68 DOM.bip44account = $("#bip44 .account");
69 DOM.bip44accountXprv = $("#bip44 .account-xprv");
70 DOM.bip44accountXpub = $("#bip44 .account-xpub");
71 DOM.bip44change = $("#bip44 .change");
72 DOM.bip49unavailable = $("#bip49 .unavailable");
73 DOM.bip49available = $("#bip49 .available");
74 DOM.bip49path = $("#bip49-path");
75 DOM.bip49purpose = $("#bip49 .purpose");
76 DOM.bip49coin = $("#bip49 .coin");
77 DOM.bip49account = $("#bip49 .account");
78 DOM.bip49accountXprv = $("#bip49 .account-xprv");
79 DOM.bip49accountXpub = $("#bip49 .account-xpub");
80 DOM.bip49change = $("#bip49 .change");
81 DOM.bip84unavailable = $("#bip84 .unavailable");
82 DOM.bip84available = $("#bip84 .available");
83 DOM.bip84path = $("#bip84-path");
84 DOM.bip84purpose = $("#bip84 .purpose");
85 DOM.bip84coin = $("#bip84 .coin");
86 DOM.bip84account = $("#bip84 .account");
87 DOM.bip84accountXprv = $("#bip84 .account-xprv");
88 DOM.bip84accountXpub = $("#bip84 .account-xpub");
89 DOM.bip84change = $("#bip84 .change");
90 DOM.bip141unavailable = $("#bip141 .unavailable");
91 DOM.bip141available = $("#bip141 .available");
92 DOM.bip141path = $("#bip141-path");
93 DOM.bip141semantics = $(".bip141-semantics");
94 DOM.generatedStrength = $(".generate-container .strength");
95 DOM.generatedStrengthWarning = $(".generate-container .warning");
96 DOM.hardenedAddresses = $(".hardened-addresses");
97 DOM.bitcoinCashAddressTypeContainer = $(".bch-addr-type-container");
98 DOM.bitcoinCashAddressType = $("[name=bch-addr-type]")
99 DOM.useBip38 = $(".use-bip38");
100 DOM.bip38Password = $(".bip38-password");
101 DOM.addresses = $(".addresses");
102 DOM.csvTab = $("#csv-tab a");
103 DOM.csv = $(".csv");
104 DOM.rowsToAdd = $(".rows-to-add");
105 DOM.more = $(".more");
106 DOM.moreRowsStartIndex = $(".more-rows-start-index");
107 DOM.feedback = $(".feedback");
108 DOM.tab = $(".derivation-type a");
109 DOM.indexToggle = $(".index-toggle");
110 DOM.addressToggle = $(".address-toggle");
111 DOM.publicKeyToggle = $(".public-key-toggle");
112 DOM.privateKeyToggle = $(".private-key-toggle");
113 DOM.languages = $(".languages a");
114 DOM.qrContainer = $(".qr-container");
115 DOM.qrHider = DOM.qrContainer.find(".qr-hider");
116 DOM.qrImage = DOM.qrContainer.find(".qr-image");
117 DOM.qrHint = DOM.qrContainer.find(".qr-hint");
118 DOM.showQrEls = $("[data-show-qr]");
119
120 function init() {
121 // Events
122 DOM.privacyScreenToggle.on("change", privacyScreenToggled);
123 DOM.generatedStrength.on("change", generatedStrengthChanged);
124 DOM.network.on("change", networkChanged);
125 DOM.bip32Client.on("change", bip32ClientChanged);
126 DOM.useEntropy.on("change", setEntropyVisibility);
127 DOM.entropy.on("input", delayedEntropyChanged);
128 DOM.entropyMnemonicLength.on("change", entropyChanged);
129 DOM.phrase.on("input", delayedPhraseChanged);
130 DOM.passphrase.on("input", delayedPhraseChanged);
131 DOM.generate.on("click", generateClicked);
132 DOM.more.on("click", showMore);
133 DOM.rootKey.on("input", delayedRootKeyChanged);
134 DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged);
135 DOM.bip32path.on("input", calcForDerivationPath);
136 DOM.bip44account.on("input", calcForDerivationPath);
137 DOM.bip44change.on("input", calcForDerivationPath);
138 DOM.bip49account.on("input", calcForDerivationPath);
139 DOM.bip49change.on("input", calcForDerivationPath);
140 DOM.bip84account.on("input", calcForDerivationPath);
141 DOM.bip84change.on("input", calcForDerivationPath);
142 DOM.bip141path.on("input", calcForDerivationPath);
143 DOM.bip141semantics.on("change", tabChanged);
144 DOM.tab.on("shown.bs.tab", tabChanged);
145 DOM.hardenedAddresses.on("change", calcForDerivationPath);
146 DOM.useBip38.on("change", calcForDerivationPath);
147 DOM.bip38Password.on("change", calcForDerivationPath);
148 DOM.indexToggle.on("click", toggleIndexes);
149 DOM.addressToggle.on("click", toggleAddresses);
150 DOM.publicKeyToggle.on("click", togglePublicKeys);
151 DOM.privateKeyToggle.on("click", togglePrivateKeys);
152 DOM.csvTab.on("click", updateCsv);
153 DOM.languages.on("click", languageChanged);
154 DOM.bitcoinCashAddressType.on("change", bitcoinCashAddressTypeChange);
155 setQrEvents(DOM.showQrEls);
156 disableForms();
157 hidePending();
158 hideValidationError();
159 populateNetworkSelect();
160 populateClientSelect();
161 }
162
163 // Event handlers
164
165 function generatedStrengthChanged() {
166 var strength = parseInt(DOM.generatedStrength.val());
167 if (strength < 12) {
168 DOM.generatedStrengthWarning.removeClass("hidden");
169 }
170 else {
171 DOM.generatedStrengthWarning.addClass("hidden");
172 }
173 }
174
175 function networkChanged(e) {
176 clearDerivedKeys();
177 clearAddressesList();
178 DOM.litecoinLtubContainer.addClass("hidden");
179 DOM.bitcoinCashAddressTypeContainer.addClass("hidden");
180 var networkIndex = e.target.value;
181 var network = networks[networkIndex];
182 network.onSelect();
183 adjustNetworkForSegwit();
184 if (seed != null) {
185 phraseChanged();
186 }
187 else {
188 rootKeyChanged();
189 }
190 }
191
192 function bip32ClientChanged(e) {
193 var clientIndex = DOM.bip32Client.val();
194 if (clientIndex == "custom") {
195 DOM.bip32path.prop("readonly", false);
196 }
197 else {
198 DOM.bip32path.prop("readonly", true);
199 clients[clientIndex].onSelect();
200 if (seed != null) {
201 phraseChanged();
202 }
203 else {
204 rootKeyChanged();
205 }
206 }
207 }
208
209 function setEntropyVisibility() {
210 if (isUsingOwnEntropy()) {
211 DOM.entropyContainer.removeClass("hidden");
212 DOM.generateContainer.addClass("hidden");
213 DOM.phrase.prop("readonly", true);
214 DOM.entropy.focus();
215 entropyChanged();
216 }
217 else {
218 DOM.entropyContainer.addClass("hidden");
219 DOM.generateContainer.removeClass("hidden");
220 DOM.phrase.prop("readonly", false);
221 hidePending();
222 }
223 }
224
225 function delayedPhraseChanged() {
226 hideValidationError();
227 seed = null;
228 bip32RootKey = null;
229 bip32ExtendedKey = null;
230 clearAddressesList();
231 showPending();
232 if (phraseChangeTimeoutEvent != null) {
233 clearTimeout(phraseChangeTimeoutEvent);
234 }
235 phraseChangeTimeoutEvent = setTimeout(phraseChanged, 400);
236 }
237
238 function phraseChanged() {
239 showPending();
240 setMnemonicLanguage();
241 // Get the mnemonic phrase
242 var phrase = DOM.phrase.val();
243 var errorText = findPhraseErrors(phrase);
244 if (errorText) {
245 showValidationError(errorText);
246 return;
247 }
248 // Calculate and display
249 var passphrase = DOM.passphrase.val();
250 calcBip32RootKeyFromSeed(phrase, passphrase);
251 calcForDerivationPath();
252 // Show the word indexes
253 showWordIndexes();
254 }
255
256 function tabChanged() {
257 showPending();
258 adjustNetworkForSegwit();
259 var phrase = DOM.phrase.val();
260 if (phrase != "") {
261 // Calculate and display for mnemonic
262 var errorText = findPhraseErrors(phrase);
263 if (errorText) {
264 showValidationError(errorText);
265 return;
266 }
267 // Calculate and display
268 var passphrase = DOM.passphrase.val();
269 calcBip32RootKeyFromSeed(phrase, passphrase);
270 }
271 else {
272 // Calculate and display for root key
273 var rootKeyBase58 = DOM.rootKey.val();
274 var errorText = validateRootKey(rootKeyBase58);
275 if (errorText) {
276 showValidationError(errorText);
277 return;
278 }
279 // Calculate and display
280 calcBip32RootKeyFromBase58(rootKeyBase58);
281 }
282 calcForDerivationPath();
283 }
284
285 function delayedEntropyChanged() {
286 hideValidationError();
287 showPending();
288 if (entropyChangeTimeoutEvent != null) {
289 clearTimeout(entropyChangeTimeoutEvent);
290 }
291 entropyChangeTimeoutEvent = setTimeout(entropyChanged, 400);
292 }
293
294 function entropyChanged() {
295 // If blank entropy, clear mnemonic, addresses, errors
296 if (DOM.entropy.val().trim().length == 0) {
297 clearDisplay();
298 clearEntropyFeedback();
299 DOM.phrase.val("");
300 showValidationError("Blank entropy");
301 return;
302 }
303 // Get the current phrase to detect changes
304 var phrase = DOM.phrase.val();
305 // Set the phrase from the entropy
306 setMnemonicFromEntropy();
307 // Recalc addresses if the phrase has changed
308 var newPhrase = DOM.phrase.val();
309 if (newPhrase != phrase) {
310 if (newPhrase.length == 0) {
311 clearDisplay();
312 }
313 else {
314 phraseChanged();
315 }
316 }
317 else {
318 hidePending();
319 }
320 }
321
322 function delayedRootKeyChanged() {
323 // Warn if there is an existing mnemonic or passphrase.
324 if (DOM.phrase.val().length > 0 || DOM.passphrase.val().length > 0) {
325 if (!confirm("This will clear existing mnemonic and passphrase")) {
326 DOM.rootKey.val(bip32RootKey);
327 return
328 }
329 }
330 hideValidationError();
331 showPending();
332 // Clear existing mnemonic and passphrase
333 DOM.phrase.val("");
334 DOM.passphrase.val("");
335 seed = null;
336 if (rootKeyChangedTimeoutEvent != null) {
337 clearTimeout(rootKeyChangedTimeoutEvent);
338 }
339 rootKeyChangedTimeoutEvent = setTimeout(rootKeyChanged, 400);
340 }
341
342 function rootKeyChanged() {
343 showPending();
344 hideValidationError();
345 var rootKeyBase58 = DOM.rootKey.val();
346 var errorText = validateRootKey(rootKeyBase58);
347 if (errorText) {
348 showValidationError(errorText);
349 return;
350 }
351 // Calculate and display
352 calcBip32RootKeyFromBase58(rootKeyBase58);
353 calcForDerivationPath();
354 }
355
356 function litecoinUseLtubChanged() {
357 litecoinUseLtub = DOM.litecoinUseLtub.prop("checked");
358 if (litecoinUseLtub) {
359 network = bitcoinjs.bitcoin.networks.litecoin;
360 }
361 else {
362 network = bitcoinjs.bitcoin.networks.litecoinXprv;
363 }
364 phraseChanged();
365 }
366
367 function calcForDerivationPath() {
368 clearDerivedKeys();
369 clearAddressesList();
370 showPending();
371 // Don't show segwit if it's selected but network doesn't support it
372 if (segwitSelected() && !networkHasSegwit()) {
373 showSegwitUnavailable();
374 hidePending();
375 return;
376 }
377 showSegwitAvailable();
378 // Get the derivation path
379 var derivationPath = getDerivationPath();
380 var errorText = findDerivationPathErrors(derivationPath);
381 if (errorText) {
382 showValidationError(errorText);
383 return;
384 }
385 bip32ExtendedKey = calcBip32ExtendedKey(derivationPath);
386 if (bip44TabSelected()) {
387 displayBip44Info();
388 }
389 else if (bip49TabSelected()) {
390 displayBip49Info();
391 }
392 else if (bip84TabSelected()) {
393 displayBip84Info();
394 }
395 displayBip32Info();
396 }
397
398 function generateClicked() {
399 if (isUsingOwnEntropy()) {
400 return;
401 }
402 clearDisplay();
403 showPending();
404 setTimeout(function() {
405 setMnemonicLanguage();
406 var phrase = generateRandomPhrase();
407 if (!phrase) {
408 return;
409 }
410 phraseChanged();
411 }, 50);
412 }
413
414 function languageChanged() {
415 setTimeout(function() {
416 setMnemonicLanguage();
417 if (DOM.phrase.val().length > 0) {
418 var newPhrase = convertPhraseToNewLanguage();
419 DOM.phrase.val(newPhrase);
420 phraseChanged();
421 }
422 else {
423 DOM.generate.trigger("click");
424 }
425 }, 50);
426 }
427
428 function bitcoinCashAddressTypeChange() {
429 phraseChanged();
430 }
431
432 function toggleIndexes() {
433 showIndex = !showIndex;
434 $("td.index span").toggleClass("invisible");
435 }
436
437 function toggleAddresses() {
438 showAddress = !showAddress;
439 $("td.address span").toggleClass("invisible");
440 }
441
442 function togglePublicKeys() {
443 showPubKey = !showPubKey;
444 $("td.pubkey span").toggleClass("invisible");
445 }
446
447 function togglePrivateKeys() {
448 showPrivKey = !showPrivKey;
449 $("td.privkey span").toggleClass("invisible");
450 }
451
452 function privacyScreenToggled() {
453 // private-data contains elements added to DOM at runtime
454 // so catch all by adding visual privacy class to the root of the DOM
455 if (DOM.privacyScreenToggle.prop("checked")) {
456 $("body").addClass("visual-privacy");
457 }
458 else {
459 $("body").removeClass("visual-privacy");
460 }
461 }
462
463 // Private methods
464
465 function generateRandomPhrase() {
466 if (!hasStrongRandom()) {
467 var errorText = "This browser does not support strong randomness";
468 showValidationError(errorText);
469 return;
470 }
471 // get the amount of entropy to use
472 var numWords = parseInt(DOM.generatedStrength.val());
473 var strength = numWords / 3 * 32;
474 var buffer = new Uint8Array(strength / 8);
475 // create secure entropy
476 var data = crypto.getRandomValues(buffer);
477 // show the words
478 var words = mnemonic.toMnemonic(data);
479 DOM.phrase.val(words);
480 // show the entropy
481 var entropyHex = uint8ArrayToHex(data);
482 DOM.entropy.val(entropyHex);
483 // ensure entropy fields are consistent with what is being displayed
484 DOM.entropyMnemonicLength.val("raw");
485 return words;
486 }
487
488 function calcBip32RootKeyFromSeed(phrase, passphrase) {
489 seed = mnemonic.toSeed(phrase, passphrase);
490 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network);
491 }
492
493 function calcBip32RootKeyFromBase58(rootKeyBase58) {
494 // try parsing with various segwit network params since this extended
495 // key may be from any one of them.
496 if (networkHasSegwit()) {
497 var n = network;
498 if ("baseNetwork" in n) {
499 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
500 }
501 // try parsing using base network params
502 try {
503 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n);
504 return;
505 }
506 catch (e) {}
507 // try parsing using p2wpkh params
508 if ("p2wpkh" in n) {
509 try {
510 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
511 return;
512 }
513 catch (e) {}
514 }
515 // try parsing using p2wpkh-in-p2sh network params
516 if ("p2wpkhInP2sh" in n) {
517 try {
518 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
519 return;
520 }
521 catch (e) {}
522 }
523 }
524 // try the network params as currently specified
525 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
526 }
527
528 function calcBip32ExtendedKey(path) {
529 // Check there's a root key to derive from
530 if (!bip32RootKey) {
531 return bip32RootKey;
532 }
533 var extendedKey = bip32RootKey;
534 // Derive the key from the path
535 var pathBits = path.split("/");
536 for (var i=0; i<pathBits.length; i++) {
537 var bit = pathBits[i];
538 var index = parseInt(bit);
539 if (isNaN(index)) {
540 continue;
541 }
542 var hardened = bit[bit.length-1] == "'";
543 var isPriv = !(extendedKey.isNeutered());
544 var invalidDerivationPath = hardened && !isPriv;
545 if (invalidDerivationPath) {
546 extendedKey = null;
547 }
548 else if (hardened) {
549 extendedKey = extendedKey.deriveHardened(index);
550 }
551 else {
552 extendedKey = extendedKey.derive(index);
553 }
554 }
555 return extendedKey
556 }
557
558 function showValidationError(errorText) {
559 DOM.feedback
560 .text(errorText)
561 .show();
562 }
563
564 function hideValidationError() {
565 DOM.feedback
566 .text("")
567 .hide();
568 }
569
570 function findPhraseErrors(phrase) {
571 // Preprocess the words
572 phrase = mnemonic.normalizeString(phrase);
573 var words = phraseToWordArray(phrase);
574 // Detect blank phrase
575 if (words.length == 0) {
576 return "Blank mnemonic";
577 }
578 // Check each word
579 for (var i=0; i<words.length; i++) {
580 var word = words[i];
581 var language = getLanguage();
582 if (WORDLISTS[language].indexOf(word) == -1) {
583 console.log("Finding closest match to " + word);
584 var nearestWord = findNearestWord(word);
585 return word + " not in wordlist, did you mean " + nearestWord + "?";
586 }
587 }
588 // Check the words are valid
589 var properPhrase = wordArrayToPhrase(words);
590 var isValid = mnemonic.check(properPhrase);
591 if (!isValid) {
592 return "Invalid mnemonic";
593 }
594 return false;
595 }
596
597 function validateRootKey(rootKeyBase58) {
598 // try various segwit network params since this extended key may be from
599 // any one of them.
600 if (networkHasSegwit()) {
601 var n = network;
602 if ("baseNetwork" in n) {
603 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
604 }
605 // try parsing using base network params
606 try {
607 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n);
608 return "";
609 }
610 catch (e) {}
611 // try parsing using p2wpkh params
612 if ("p2wpkh" in n) {
613 try {
614 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
615 return "";
616 }
617 catch (e) {}
618 }
619 // try parsing using p2wpkh-in-p2sh network params
620 if ("p2wpkhInP2sh" in n) {
621 try {
622 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
623 return "";
624 }
625 catch (e) {}
626 }
627 }
628 // try the network params as currently specified
629 try {
630 bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
631 }
632 catch (e) {
633 return "Invalid root key";
634 }
635 return "";
636 }
637
638 function getDerivationPath() {
639 if (bip44TabSelected()) {
640 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
641 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
642 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
643 var change = parseIntNoNaN(DOM.bip44change.val(), 0);
644 var path = "m/";
645 path += purpose + "'/";
646 path += coin + "'/";
647 path += account + "'/";
648 path += change;
649 DOM.bip44path.val(path);
650 var derivationPath = DOM.bip44path.val();
651 console.log("Using derivation path from BIP44 tab: " + derivationPath);
652 return derivationPath;
653 }
654 else if (bip49TabSelected()) {
655 var purpose = parseIntNoNaN(DOM.bip49purpose.val(), 49);
656 var coin = parseIntNoNaN(DOM.bip49coin.val(), 0);
657 var account = parseIntNoNaN(DOM.bip49account.val(), 0);
658 var change = parseIntNoNaN(DOM.bip49change.val(), 0);
659 var path = "m/";
660 path += purpose + "'/";
661 path += coin + "'/";
662 path += account + "'/";
663 path += change;
664 DOM.bip49path.val(path);
665 var derivationPath = DOM.bip49path.val();
666 console.log("Using derivation path from BIP49 tab: " + derivationPath);
667 return derivationPath;
668 }
669 else if (bip84TabSelected()) {
670 var purpose = parseIntNoNaN(DOM.bip84purpose.val(), 84);
671 var coin = parseIntNoNaN(DOM.bip84coin.val(), 0);
672 var account = parseIntNoNaN(DOM.bip84account.val(), 0);
673 var change = parseIntNoNaN(DOM.bip84change.val(), 0);
674 var path = "m/";
675 path += purpose + "'/";
676 path += coin + "'/";
677 path += account + "'/";
678 path += change;
679 DOM.bip84path.val(path);
680 var derivationPath = DOM.bip84path.val();
681 console.log("Using derivation path from BIP84 tab: " + derivationPath);
682 return derivationPath;
683 }
684 else if (bip32TabSelected()) {
685 var derivationPath = DOM.bip32path.val();
686 console.log("Using derivation path from BIP32 tab: " + derivationPath);
687 return derivationPath;
688 }
689 else if (bip141TabSelected()) {
690 var derivationPath = DOM.bip141path.val();
691 console.log("Using derivation path from BIP141 tab: " + derivationPath);
692 return derivationPath;
693 }
694 else {
695 console.log("Unknown derivation path");
696 }
697 }
698
699 function findDerivationPathErrors(path) {
700 // TODO is not perfect but is better than nothing
701 // Inspired by
702 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
703 // and
704 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys
705 var maxDepth = 255; // TODO verify this!!
706 var maxIndexValue = Math.pow(2, 31); // TODO verify this!!
707 if (path[0] != "m") {
708 return "First character must be 'm'";
709 }
710 if (path.length > 1) {
711 if (path[1] != "/") {
712 return "Separator must be '/'";
713 }
714 var indexes = path.split("/");
715 if (indexes.length > maxDepth) {
716 return "Derivation depth is " + indexes.length + ", must be less than " + maxDepth;
717 }
718 for (var depth = 1; depth<indexes.length; depth++) {
719 var index = indexes[depth];
720 var invalidChars = index.replace(/^[0-9]+'?$/g, "")
721 if (invalidChars.length > 0) {
722 return "Invalid characters " + invalidChars + " found at depth " + depth;
723 }
724 var indexValue = parseInt(index.replace("'", ""));
725 if (isNaN(depth)) {
726 return "Invalid number at depth " + depth;
727 }
728 if (indexValue > maxIndexValue) {
729 return "Value of " + indexValue + " at depth " + depth + " must be less than " + maxIndexValue;
730 }
731 }
732 }
733 // Check root key exists or else derivation path is useless!
734 if (!bip32RootKey) {
735 return "No root key";
736 }
737 // Check no hardened derivation path when using xpub keys
738 var hardenedPath = path.indexOf("'") > -1;
739 var hardenedAddresses = bip32TabSelected() && DOM.hardenedAddresses.prop("checked");
740 var hardened = hardenedPath || hardenedAddresses;
741 var isXpubkey = bip32RootKey.isNeutered();
742 if (hardened && isXpubkey) {
743 return "Hardened derivation path is invalid with xpub key";
744 }
745 return false;
746 }
747
748 function displayBip44Info() {
749 // Get the derivation path for the account
750 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
751 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
752 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
753 var path = "m/";
754 path += purpose + "'/";
755 path += coin + "'/";
756 path += account + "'/";
757 // Calculate the account extended keys
758 var accountExtendedKey = calcBip32ExtendedKey(path);
759 var accountXprv = accountExtendedKey.toBase58();
760 var accountXpub = accountExtendedKey.neutered().toBase58();
761 // Display the extended keys
762 DOM.bip44accountXprv.val(accountXprv);
763 DOM.bip44accountXpub.val(accountXpub);
764 }
765
766 function displayBip49Info() {
767 // Get the derivation path for the account
768 var purpose = parseIntNoNaN(DOM.bip49purpose.val(), 49);
769 var coin = parseIntNoNaN(DOM.bip49coin.val(), 0);
770 var account = parseIntNoNaN(DOM.bip49account.val(), 0);
771 var path = "m/";
772 path += purpose + "'/";
773 path += coin + "'/";
774 path += account + "'/";
775 // Calculate the account extended keys
776 var accountExtendedKey = calcBip32ExtendedKey(path);
777 var accountXprv = accountExtendedKey.toBase58();
778 var accountXpub = accountExtendedKey.neutered().toBase58();
779 // Display the extended keys
780 DOM.bip49accountXprv.val(accountXprv);
781 DOM.bip49accountXpub.val(accountXpub);
782 }
783
784 function displayBip84Info() {
785 // Get the derivation path for the account
786 var purpose = parseIntNoNaN(DOM.bip84purpose.val(), 84);
787 var coin = parseIntNoNaN(DOM.bip84coin.val(), 0);
788 var account = parseIntNoNaN(DOM.bip84account.val(), 0);
789 var path = "m/";
790 path += purpose + "'/";
791 path += coin + "'/";
792 path += account + "'/";
793 // Calculate the account extended keys
794 var accountExtendedKey = calcBip32ExtendedKey(path);
795 var accountXprv = accountExtendedKey.toBase58();
796 var accountXpub = accountExtendedKey.neutered().toBase58();
797 // Display the extended keys
798 DOM.bip84accountXprv.val(accountXprv);
799 DOM.bip84accountXpub.val(accountXpub);
800 }
801
802 function displayBip32Info() {
803 // Display the key
804 DOM.seed.val(seed);
805 var rootKey = bip32RootKey.toBase58();
806 DOM.rootKey.val(rootKey);
807 var xprvkeyB58 = "NA";
808 if (!bip32ExtendedKey.isNeutered()) {
809 xprvkeyB58 = bip32ExtendedKey.toBase58();
810 }
811 var extendedPrivKey = xprvkeyB58;
812 DOM.extendedPrivKey.val(extendedPrivKey);
813 var extendedPubKey = bip32ExtendedKey.neutered().toBase58();
814 DOM.extendedPubKey.val(extendedPubKey);
815 // Display the addresses and privkeys
816 clearAddressesList();
817 var initialAddressCount = parseInt(DOM.rowsToAdd.val());
818 displayAddresses(0, initialAddressCount);
819 }
820
821 function displayAddresses(start, total) {
822 generationProcesses.push(new (function() {
823
824 var rows = [];
825
826 this.stop = function() {
827 for (var i=0; i<rows.length; i++) {
828 rows[i].shouldGenerate = false;
829 }
830 hidePending();
831 }
832
833 for (var i=0; i<total; i++) {
834 var index = i + start;
835 var isLast = i == total - 1;
836 rows.push(new TableRow(index, isLast));
837 }
838
839 })());
840 }
841
842 function segwitSelected() {
843 return bip49TabSelected() || bip84TabSelected() || bip141TabSelected();
844 }
845
846 function p2wpkhSelected() {
847 return bip84TabSelected() ||
848 bip141TabSelected() && DOM.bip141semantics.val() == "p2wpkh";
849 }
850
851 function p2wpkhInP2shSelected() {
852 return bip49TabSelected() ||
853 (bip141TabSelected() && DOM.bip141semantics.val() == "p2wpkh-p2sh");
854 }
855
856 function TableRow(index, isLast) {
857
858 var self = this;
859 this.shouldGenerate = true;
860 var useHardenedAddresses = DOM.hardenedAddresses.prop("checked");
861 var useBip38 = DOM.useBip38.prop("checked");
862 var bip38password = DOM.bip38Password.val();
863 var isSegwit = segwitSelected();
864 var segwitAvailable = networkHasSegwit();
865 var isP2wpkh = p2wpkhSelected();
866 var isP2wpkhInP2sh = p2wpkhInP2shSelected();
867
868 function init() {
869 calculateValues();
870 }
871
872 function calculateValues() {
873 setTimeout(function() {
874 if (!self.shouldGenerate) {
875 return;
876 }
877 // derive HDkey for this row of the table
878 var key = "NA";
879 if (useHardenedAddresses) {
880 key = bip32ExtendedKey.deriveHardened(index);
881 }
882 else {
883 key = bip32ExtendedKey.derive(index);
884 }
885 // bip38 requires uncompressed keys
886 // see https://github.com/iancoleman/bip39/issues/140#issuecomment-352164035
887 var keyPair = key.keyPair;
888 var useUncompressed = useBip38;
889 if (useUncompressed) {
890 keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false });
891 }
892 // get address
893 var address = keyPair.getAddress().toString();
894 // get privkey
895 var hasPrivkey = !key.isNeutered();
896 var privkey = "NA";
897 if (hasPrivkey) {
898 privkey = keyPair.toWIF();
899 // BIP38 encode private key if required
900 if (useBip38) {
901 privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
902 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
903 });
904 }
905 }
906 // get pubkey
907 var pubkey = keyPair.getPublicKeyBuffer().toString('hex');
908 var indexText = getDerivationPath() + "/" + index;
909 if (useHardenedAddresses) {
910 indexText = indexText + "'";
911 }
912 // Ethereum values are different
913 if ((networks[DOM.network.val()].name == "ETH - Ethereum")
914 || (networks[DOM.network.val()].name == "ETC - Ethereum Classic")
915 || (networks[DOM.network.val()].name == "PIRL - Pirl")
916 || (networks[DOM.network.val()].name == "MIX - MIX")
917 || (networks[DOM.network.val()].name == "MUSIC - Musicoin")
918 || (networks[DOM.network.val()].name == "POA - Poa")
919 || (networks[DOM.network.val()].name == "EXP - Expanse")
920 || (networks[DOM.network.val()].name == "CLO - Callisto")) {
921 var privKeyBuffer = keyPair.d.toBuffer(32);
922 privkey = privKeyBuffer.toString('hex');
923 var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
924 var hexAddress = addressBuffer.toString('hex');
925 var checksumAddress = ethUtil.toChecksumAddress(hexAddress);
926 address = ethUtil.addHexPrefix(checksumAddress);
927 privkey = ethUtil.addHexPrefix(privkey);
928 pubkey = ethUtil.addHexPrefix(pubkey);
929 }
930 // Ripple values are different
931 if (networks[DOM.network.val()].name == "XRP - Ripple") {
932 privkey = convertRipplePriv(privkey);
933 address = convertRippleAdrr(address);
934 }
935 // Bitcoin Cash address format may vary
936 if (networks[DOM.network.val()].name == "BCH - Bitcoin Cash") {
937 var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val();
938 if (bchAddrType == "cashaddr") {
939 address = bchaddr.toCashAddress(address);
940 }
941 else if (bchAddrType == "bitpay") {
942 address = bchaddr.toBitpayAddress(address);
943 }
944 }
945 // Segwit addresses are different
946 if (isSegwit) {
947 if (!segwitAvailable) {
948 return;
949 }
950 if (isP2wpkh) {
951 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
952 var scriptpubkey = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
953 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
954 }
955 else if (isP2wpkhInP2sh) {
956 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
957 var scriptsig = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
958 var addressbytes = bitcoinjs.bitcoin.crypto.hash160(scriptsig);
959 var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes);
960 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
961 }
962 }
963 addAddressToList(indexText, address, pubkey, privkey);
964 if (isLast) {
965 hidePending();
966 updateCsv();
967 }
968 }, 50)
969 }
970
971 init();
972
973 }
974
975 function showMore() {
976 var rowsToAdd = parseInt(DOM.rowsToAdd.val());
977 if (isNaN(rowsToAdd)) {
978 rowsToAdd = 20;
979 DOM.rowsToAdd.val("20");
980 }
981 var start = parseInt(DOM.moreRowsStartIndex.val())
982 if (isNaN(start)) {
983 start = lastIndexInTable() + 1;
984 }
985 else {
986 var newStart = start + rowsToAdd;
987 DOM.moreRowsStartIndex.val(newStart);
988 }
989 if (rowsToAdd > 200) {
990 var msg = "Generating " + rowsToAdd + " rows could take a while. ";
991 msg += "Do you want to continue?";
992 if (!confirm(msg)) {
993 return;
994 }
995 }
996 displayAddresses(start, rowsToAdd);
997 }
998
999 function clearDisplay() {
1000 clearAddressesList();
1001 clearKeys();
1002 hideValidationError();
1003 }
1004
1005 function clearAddressesList() {
1006 DOM.addresses.empty();
1007 DOM.csv.val("");
1008 stopGenerating();
1009 }
1010
1011 function stopGenerating() {
1012 while (generationProcesses.length > 0) {
1013 var generation = generationProcesses.shift();
1014 generation.stop();
1015 }
1016 }
1017
1018 function clearKeys() {
1019 clearRootKey();
1020 clearDerivedKeys();
1021 }
1022
1023 function clearRootKey() {
1024 DOM.rootKey.val("");
1025 }
1026
1027 function clearDerivedKeys() {
1028 DOM.extendedPrivKey.val("");
1029 DOM.extendedPubKey.val("");
1030 DOM.bip44accountXprv.val("");
1031 DOM.bip44accountXpub.val("");
1032 }
1033
1034 function addAddressToList(indexText, address, pubkey, privkey) {
1035 var row = $(addressRowTemplate.html());
1036 // Elements
1037 var indexCell = row.find(".index span");
1038 var addressCell = row.find(".address span");
1039 var pubkeyCell = row.find(".pubkey span");
1040 var privkeyCell = row.find(".privkey span");
1041 // Content
1042 indexCell.text(indexText);
1043 addressCell.text(address);
1044 pubkeyCell.text(pubkey);
1045 privkeyCell.text(privkey);
1046 // Visibility
1047 if (!showIndex) {
1048 indexCell.addClass("invisible");
1049 }
1050 if (!showAddress) {
1051 addressCell.addClass("invisible");
1052 }
1053 if (!showPubKey) {
1054 pubkeyCell.addClass("invisible");
1055 }
1056 if (!showPrivKey) {
1057 privkeyCell.addClass("invisible");
1058 }
1059 DOM.addresses.append(row);
1060 var rowShowQrEls = row.find("[data-show-qr]");
1061 setQrEvents(rowShowQrEls);
1062 }
1063
1064 function hasStrongRandom() {
1065 return 'crypto' in window && window['crypto'] !== null;
1066 }
1067
1068 function disableForms() {
1069 $("form").on("submit", function(e) {
1070 e.preventDefault();
1071 });
1072 }
1073
1074 function parseIntNoNaN(val, defaultVal) {
1075 var v = parseInt(val);
1076 if (isNaN(v)) {
1077 return defaultVal;
1078 }
1079 return v;
1080 }
1081
1082 function showPending() {
1083 DOM.feedback
1084 .text("Calculating...")
1085 .show();
1086 }
1087
1088 function findNearestWord(word) {
1089 var language = getLanguage();
1090 var words = WORDLISTS[language];
1091 var minDistance = 99;
1092 var closestWord = words[0];
1093 for (var i=0; i<words.length; i++) {
1094 var comparedTo = words[i];
1095 if (comparedTo.indexOf(word) == 0) {
1096 return comparedTo;
1097 }
1098 var distance = Levenshtein.get(word, comparedTo);
1099 if (distance < minDistance) {
1100 closestWord = comparedTo;
1101 minDistance = distance;
1102 }
1103 }
1104 return closestWord;
1105 }
1106
1107 function hidePending() {
1108 DOM.feedback
1109 .text("")
1110 .hide();
1111 }
1112
1113 function populateNetworkSelect() {
1114 for (var i=0; i<networks.length; i++) {
1115 var network = networks[i];
1116 var option = $("<option>");
1117 option.attr("value", i);
1118 option.text(network.name);
1119 if (network.name == "BTC - Bitcoin") {
1120 option.prop("selected", true);
1121 }
1122 DOM.phraseNetwork.append(option);
1123 }
1124 }
1125
1126 function populateClientSelect() {
1127 for (var i=0; i<clients.length; i++) {
1128 var client = clients[i];
1129 var option = $("<option>");
1130 option.attr("value", i);
1131 option.text(client.name);
1132 DOM.bip32Client.append(option);
1133 }
1134 }
1135
1136 function getLanguage() {
1137 var defaultLanguage = "english";
1138 // Try to get from existing phrase
1139 var language = getLanguageFromPhrase();
1140 // Try to get from url if not from phrase
1141 if (language.length == 0) {
1142 language = getLanguageFromUrl();
1143 }
1144 // Default to English if no other option
1145 if (language.length == 0) {
1146 language = defaultLanguage;
1147 }
1148 return language;
1149 }
1150
1151 function getLanguageFromPhrase(phrase) {
1152 // Check if how many words from existing phrase match a language.
1153 var language = "";
1154 if (!phrase) {
1155 phrase = DOM.phrase.val();
1156 }
1157 if (phrase.length > 0) {
1158 var words = phraseToWordArray(phrase);
1159 var languageMatches = {};
1160 for (l in WORDLISTS) {
1161 // Track how many words match in this language
1162 languageMatches[l] = 0;
1163 for (var i=0; i<words.length; i++) {
1164 var wordInLanguage = WORDLISTS[l].indexOf(words[i]) > -1;
1165 if (wordInLanguage) {
1166 languageMatches[l]++;
1167 }
1168 }
1169 // Find languages with most word matches.
1170 // This is made difficult due to commonalities between Chinese
1171 // simplified vs traditional.
1172 var mostMatches = 0;
1173 var mostMatchedLanguages = [];
1174 for (var l in languageMatches) {
1175 var numMatches = languageMatches[l];
1176 if (numMatches > mostMatches) {
1177 mostMatches = numMatches;
1178 mostMatchedLanguages = [l];
1179 }
1180 else if (numMatches == mostMatches) {
1181 mostMatchedLanguages.push(l);
1182 }
1183 }
1184 }
1185 if (mostMatchedLanguages.length > 0) {
1186 // Use first language and warn if multiple detected
1187 language = mostMatchedLanguages[0];
1188 if (mostMatchedLanguages.length > 1) {
1189 console.warn("Multiple possible languages");
1190 console.warn(mostMatchedLanguages);
1191 }
1192 }
1193 }
1194 return language;
1195 }
1196
1197 function getLanguageFromUrl() {
1198 for (var language in WORDLISTS) {
1199 if (window.location.hash.indexOf(language) > -1) {
1200 return language;
1201 }
1202 }
1203 return "";
1204 }
1205
1206 function setMnemonicLanguage() {
1207 var language = getLanguage();
1208 // Load the bip39 mnemonic generator for this language if required
1209 if (!(language in mnemonics)) {
1210 mnemonics[language] = new Mnemonic(language);
1211 }
1212 mnemonic = mnemonics[language];
1213 }
1214
1215 function convertPhraseToNewLanguage() {
1216 var oldLanguage = getLanguageFromPhrase();
1217 var newLanguage = getLanguageFromUrl();
1218 var oldPhrase = DOM.phrase.val();
1219 var oldWords = phraseToWordArray(oldPhrase);
1220 var newWords = [];
1221 for (var i=0; i<oldWords.length; i++) {
1222 var oldWord = oldWords[i];
1223 var index = WORDLISTS[oldLanguage].indexOf(oldWord);
1224 var newWord = WORDLISTS[newLanguage][index];
1225 newWords.push(newWord);
1226 }
1227 newPhrase = wordArrayToPhrase(newWords);
1228 return newPhrase;
1229 }
1230
1231 // TODO look at jsbip39 - mnemonic.splitWords
1232 function phraseToWordArray(phrase) {
1233 var words = phrase.split(/\s/g);
1234 var noBlanks = [];
1235 for (var i=0; i<words.length; i++) {
1236 var word = words[i];
1237 if (word.length > 0) {
1238 noBlanks.push(word);
1239 }
1240 }
1241 return noBlanks;
1242 }
1243
1244 // TODO look at jsbip39 - mnemonic.joinWords
1245 function wordArrayToPhrase(words) {
1246 var phrase = words.join(" ");
1247 var language = getLanguageFromPhrase(phrase);
1248 if (language == "japanese") {
1249 phrase = words.join("\u3000");
1250 }
1251 return phrase;
1252 }
1253
1254 function isUsingOwnEntropy() {
1255 return DOM.useEntropy.prop("checked");
1256 }
1257
1258 function setMnemonicFromEntropy() {
1259 clearEntropyFeedback();
1260 // Get entropy value
1261 var entropyStr = DOM.entropy.val();
1262 // Work out minimum base for entropy
1263 var entropy = Entropy.fromString(entropyStr);
1264 if (entropy.binaryStr.length == 0) {
1265 return;
1266 }
1267 // Show entropy details
1268 showEntropyFeedback(entropy);
1269 // Use entropy hash if not using raw entropy
1270 var bits = entropy.binaryStr;
1271 var mnemonicLength = DOM.entropyMnemonicLength.val();
1272 if (mnemonicLength != "raw") {
1273 // Get bits by hashing entropy with SHA256
1274 var hash = sjcl.hash.sha256.hash(entropy.cleanStr);
1275 var hex = sjcl.codec.hex.fromBits(hash);
1276 bits = BigInteger.parse(hex, 16).toString(2);
1277 while (bits.length % 256 != 0) {
1278 bits = "0" + bits;
1279 }
1280 // Truncate hash to suit number of words
1281 mnemonicLength = parseInt(mnemonicLength);
1282 var numberOfBits = 32 * mnemonicLength / 3;
1283 bits = bits.substring(0, numberOfBits);
1284 // show warning for weak entropy override
1285 if (mnemonicLength / 3 * 32 > entropy.binaryStr.length) {
1286 DOM.entropyWeakEntropyOverrideWarning.removeClass("hidden");
1287 }
1288 else {
1289 DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
1290 }
1291 }
1292 else {
1293 // hide warning for weak entropy override
1294 DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
1295 }
1296 // Discard trailing entropy
1297 var bitsToUse = Math.floor(bits.length / 32) * 32;
1298 var start = bits.length - bitsToUse;
1299 var binaryStr = bits.substring(start);
1300 // Convert entropy string to numeric array
1301 var entropyArr = [];
1302 for (var i=0; i<binaryStr.length / 8; i++) {
1303 var byteAsBits = binaryStr.substring(i*8, i*8+8);
1304 var entropyByte = parseInt(byteAsBits, 2);
1305 entropyArr.push(entropyByte)
1306 }
1307 // Convert entropy array to mnemonic
1308 var phrase = mnemonic.toMnemonic(entropyArr);
1309 // Set the mnemonic in the UI
1310 DOM.phrase.val(phrase);
1311 // Show the word indexes
1312 showWordIndexes();
1313 // Show the checksum
1314 showChecksum();
1315 }
1316
1317 function clearEntropyFeedback() {
1318 DOM.entropyCrackTime.text("...");
1319 DOM.entropyType.text("");
1320 DOM.entropyWordCount.text("0");
1321 DOM.entropyEventCount.text("0");
1322 DOM.entropyBitsPerEvent.text("0");
1323 DOM.entropyBits.text("0");
1324 DOM.entropyFiltered.html("&nbsp;");
1325 DOM.entropyBinary.html("&nbsp;");
1326 }
1327
1328 function showEntropyFeedback(entropy) {
1329 var numberOfBits = entropy.binaryStr.length;
1330 var timeToCrack = "unknown";
1331 try {
1332 var z = zxcvbn(entropy.base.parts.join(""));
1333 timeToCrack = z.crack_times_display.offline_fast_hashing_1e10_per_second;
1334 if (z.feedback.warning != "") {
1335 timeToCrack = timeToCrack + " - " + z.feedback.warning;
1336 };
1337 }
1338 catch (e) {
1339 console.log("Error detecting entropy strength with zxcvbn:");
1340 console.log(e);
1341 }
1342 var entropyTypeStr = getEntropyTypeStr(entropy);
1343 var wordCount = Math.floor(numberOfBits / 32) * 3;
1344 var bitsPerEvent = entropy.bitsPerEvent.toFixed(2);
1345 var spacedBinaryStr = addSpacesEveryElevenBits(entropy.binaryStr);
1346 DOM.entropyFiltered.html(entropy.cleanHtml);
1347 DOM.entropyType.text(entropyTypeStr);
1348 DOM.entropyCrackTime.text(timeToCrack);
1349 DOM.entropyEventCount.text(entropy.base.ints.length);
1350 DOM.entropyBits.text(numberOfBits);
1351 DOM.entropyWordCount.text(wordCount);
1352 DOM.entropyBinary.text(spacedBinaryStr);
1353 DOM.entropyBitsPerEvent.text(bitsPerEvent);
1354 // detect and warn of filtering
1355 var rawNoSpaces = DOM.entropy.val().replace(/\s/g, "");
1356 var cleanNoSpaces = entropy.cleanStr.replace(/\s/g, "");
1357 var isFiltered = rawNoSpaces.length != cleanNoSpaces.length;
1358 if (isFiltered) {
1359 DOM.entropyFilterWarning.removeClass('hidden');
1360 }
1361 else {
1362 DOM.entropyFilterWarning.addClass('hidden');
1363 }
1364 }
1365
1366 function getEntropyTypeStr(entropy) {
1367 var typeStr = entropy.base.str;
1368 // Add some detail if these are cards
1369 if (entropy.base.asInt == 52) {
1370 var cardDetail = []; // array of message strings
1371 // Detect duplicates
1372 var dupes = [];
1373 var dupeTracker = {};
1374 for (var i=0; i<entropy.base.parts.length; i++) {
1375 var card = entropy.base.parts[i];
1376 var cardUpper = card.toUpperCase();
1377 if (cardUpper in dupeTracker) {
1378 dupes.push(card);
1379 }
1380 dupeTracker[cardUpper] = true;
1381 }
1382 if (dupes.length > 0) {
1383 var dupeWord = "duplicates";
1384 if (dupes.length == 1) {
1385 dupeWord = "duplicate";
1386 }
1387 var msg = dupes.length + " " + dupeWord + ": " + dupes.slice(0,3).join(" ");
1388 if (dupes.length > 3) {
1389 msg += "...";
1390 }
1391 cardDetail.push(msg);
1392 }
1393 // Detect full deck
1394 var uniqueCards = [];
1395 for (var uniqueCard in dupeTracker) {
1396 uniqueCards.push(uniqueCard);
1397 }
1398 if (uniqueCards.length == 52) {
1399 cardDetail.unshift("full deck");
1400 }
1401 // Detect missing cards
1402 var values = "A23456789TJQK";
1403 var suits = "CDHS";
1404 var missingCards = [];
1405 for (var i=0; i<suits.length; i++) {
1406 for (var j=0; j<values.length; j++) {
1407 var card = values[j] + suits[i];
1408 if (!(card in dupeTracker)) {
1409 missingCards.push(card);
1410 }
1411 }
1412 }
1413 // Display missing cards if six or less, ie clearly going for full deck
1414 if (missingCards.length > 0 && missingCards.length <= 6) {
1415 var msg = missingCards.length + " missing: " + missingCards.slice(0,3).join(" ");
1416 if (missingCards.length > 3) {
1417 msg += "...";
1418 }
1419 cardDetail.push(msg);
1420 }
1421 // Add card details to typeStr
1422 if (cardDetail.length > 0) {
1423 typeStr += " (" + cardDetail.join(", ") + ")";
1424 }
1425 }
1426 return typeStr;
1427 }
1428
1429 function setQrEvents(els) {
1430 els.on("mouseenter", createQr);
1431 els.on("mouseleave", destroyQr);
1432 els.on("click", toggleQr);
1433 }
1434
1435 function createQr(e) {
1436 var content = e.target.textContent || e.target.value;
1437 if (content) {
1438 var qrEl = kjua({
1439 text: content,
1440 render: "canvas",
1441 size: 310,
1442 ecLevel: 'H',
1443 });
1444 DOM.qrImage.append(qrEl);
1445 if (!showQr) {
1446 DOM.qrHider.addClass("hidden");
1447 }
1448 else {
1449 DOM.qrHider.removeClass("hidden");
1450 }
1451 DOM.qrContainer.removeClass("hidden");
1452 }
1453 }
1454
1455 function destroyQr() {
1456 DOM.qrImage.text("");
1457 DOM.qrContainer.addClass("hidden");
1458 }
1459
1460 function toggleQr() {
1461 showQr = !showQr;
1462 DOM.qrHider.toggleClass("hidden");
1463 DOM.qrHint.toggleClass("hidden");
1464 }
1465
1466 function bip44TabSelected() {
1467 return DOM.bip44tab.hasClass("active");
1468 }
1469
1470 function bip32TabSelected() {
1471 return DOM.bip32tab.hasClass("active");
1472 }
1473
1474 function networkHasSegwit() {
1475 var n = network;
1476 if ("baseNetwork" in network) {
1477 n = bitcoinjs.bitcoin.networks[network.baseNetwork];
1478 }
1479 // check if only p2wpkh params are required
1480 if (p2wpkhSelected()) {
1481 return "p2wpkh" in n;
1482 }
1483 // check if only p2wpkh-in-p2sh params are required
1484 else if (p2wpkhInP2shSelected()) {
1485 return "p2wpkhInP2sh" in n;
1486 }
1487 // require both if it's unclear which params are required
1488 return "p2wpkh" in n && "p2wpkhInP2sh" in n;
1489 }
1490
1491 function bip49TabSelected() {
1492 return DOM.bip49tab.hasClass("active");
1493 }
1494
1495 function bip84TabSelected() {
1496 return DOM.bip84tab.hasClass("active");
1497 }
1498
1499 function bip141TabSelected() {
1500 return DOM.bip141tab.hasClass("active");
1501 }
1502
1503 function setHdCoin(coinValue) {
1504 DOM.bip44coin.val(coinValue);
1505 DOM.bip49coin.val(coinValue);
1506 DOM.bip84coin.val(coinValue);
1507 }
1508
1509 function showSegwitAvailable() {
1510 DOM.bip49unavailable.addClass("hidden");
1511 DOM.bip49available.removeClass("hidden");
1512 DOM.bip84unavailable.addClass("hidden");
1513 DOM.bip84available.removeClass("hidden");
1514 DOM.bip141unavailable.addClass("hidden");
1515 DOM.bip141available.removeClass("hidden");
1516 }
1517
1518 function showSegwitUnavailable() {
1519 DOM.bip49available.addClass("hidden");
1520 DOM.bip49unavailable.removeClass("hidden");
1521 DOM.bip84available.addClass("hidden");
1522 DOM.bip84unavailable.removeClass("hidden");
1523 DOM.bip141available.addClass("hidden");
1524 DOM.bip141unavailable.removeClass("hidden");
1525 }
1526
1527 function adjustNetworkForSegwit() {
1528 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1529 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1530 // wallet.
1531 // See https://github.com/iancoleman/bip39/issues/125
1532 var segwitNetworks = null;
1533 // if a segwit network is alread selected, need to use base network to
1534 // look up new parameters
1535 if ("baseNetwork" in network) {
1536 network = bitcoinjs.bitcoin.networks[network.baseNetwork];
1537 }
1538 // choose the right segwit params
1539 if (p2wpkhSelected() && "p2wpkh" in network) {
1540 network = network.p2wpkh;
1541 }
1542 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network) {
1543 network = network.p2wpkhInP2sh;
1544 }
1545 }
1546
1547 function lastIndexInTable() {
1548 var pathText = DOM.addresses.find(".index").last().text();
1549 var pathBits = pathText.split("/");
1550 var lastBit = pathBits[pathBits.length-1];
1551 var lastBitClean = lastBit.replace("'", "");
1552 return parseInt(lastBitClean);
1553 }
1554
1555 function uint8ArrayToHex(a) {
1556 var s = ""
1557 for (var i=0; i<a.length; i++) {
1558 var h = a[i].toString(16);
1559 while (h.length < 2) {
1560 h = "0" + h;
1561 }
1562 s = s + h;
1563 }
1564 return s;
1565 }
1566
1567 function showWordIndexes() {
1568 var phrase = DOM.phrase.val();
1569 var words = phraseToWordArray(phrase);
1570 var wordIndexes = [];
1571 var language = getLanguage();
1572 for (var i=0; i<words.length; i++) {
1573 var word = words[i];
1574 var wordIndex = WORDLISTS[language].indexOf(word);
1575 wordIndexes.push(wordIndex);
1576 }
1577 var wordIndexesStr = wordIndexes.join(", ");
1578 DOM.entropyWordIndexes.text(wordIndexesStr);
1579 }
1580
1581 function showChecksum() {
1582 var phrase = DOM.phrase.val();
1583 var words = phraseToWordArray(phrase);
1584 var checksumBitlength = words.length / 3;
1585 var checksum = "";
1586 var binaryStr = "";
1587 var language = getLanguage();
1588 for (var i=words.length-1; i>=0; i--) {
1589 var word = words[i];
1590 var wordIndex = WORDLISTS[language].indexOf(word);
1591 var wordBinary = wordIndex.toString(2);
1592 while (wordBinary.length < 11) {
1593 wordBinary = "0" + wordBinary;
1594 }
1595 var binaryStr = wordBinary + binaryStr;
1596 if (binaryStr.length >= checksumBitlength) {
1597 var start = binaryStr.length - checksumBitlength;
1598 var end = binaryStr.length;
1599 checksum = binaryStr.substring(start, end);
1600 // add spaces so the last group is 11 bits, not the first
1601 checksum = checksum.split("").reverse().join("")
1602 checksum = addSpacesEveryElevenBits(checksum);
1603 checksum = checksum.split("").reverse().join("")
1604 break;
1605 }
1606 }
1607 DOM.entropyChecksum.text(checksum);
1608 }
1609
1610 function updateCsv() {
1611 var tableCsv = "path,address,public key,private key\n";
1612 var rows = DOM.addresses.find("tr");
1613 for (var i=0; i<rows.length; i++) {
1614 var row = $(rows[i]);
1615 var cells = row.find("td");
1616 for (var j=0; j<cells.length; j++) {
1617 var cell = $(cells[j]);
1618 if (!cell.children().hasClass("invisible")) {
1619 tableCsv = tableCsv + cell.text();
1620 }
1621 if (j != cells.length - 1) {
1622 tableCsv = tableCsv + ",";
1623 }
1624 }
1625 tableCsv = tableCsv + "\n";
1626 }
1627 DOM.csv.val(tableCsv);
1628 }
1629
1630 function addSpacesEveryElevenBits(binaryStr) {
1631 return binaryStr.match(/.{1,11}/g).join(" ");
1632 }
1633
1634 var networks = [
1635 {
1636 name: "AC - Asiacoin",
1637 onSelect: function() {
1638 network = bitcoinjs.bitcoin.networks.asiacoin;
1639 setHdCoin(51);
1640 },
1641 },
1642 {
1643 name: "ACC - Adcoin",
1644 onSelect: function() {
1645 network = bitcoinjs.bitcoin.networks.adcoin;
1646 setHdCoin(161);
1647 },
1648 },
1649 {
1650 name: "AUR - Auroracoin",
1651 onSelect: function() {
1652 network = bitcoinjs.bitcoin.networks.auroracoin;
1653 setHdCoin(85);
1654 },
1655 },
1656 {
1657 name: "AXE - Axe",
1658 onSelect: function() {
1659 network = bitcoinjs.bitcoin.networks.axe;
1660 setHdCoin(4242);
1661 },
1662 },
1663 {
1664 name: "ANON - ANON",
1665 onSelect: function() {
1666 network = bitcoinjs.bitcoin.networks.anon;
1667 setHdCoin(220);
1668 },
1669 },
1670 {
1671 name: "BCA - Bitcoin Atom",
1672 onSelect: function() {
1673 network = bitcoinjs.bitcoin.networks.atom;
1674 setHdCoin(185);
1675 },
1676 },
1677 {
1678 name: "BCH - Bitcoin Cash",
1679 onSelect: function() {
1680 DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
1681 setHdCoin(145);
1682 },
1683 },
1684 {
1685 name: "BEET - Beetlecoin",
1686 onSelect: function() {
1687 network = bitcoinjs.bitcoin.networks.beetlecoin;
1688 setHdCoin(800);
1689 },
1690 },
1691 {
1692 name: "BELA - Belacoin",
1693 onSelect: function() {
1694 network = bitcoinjs.bitcoin.networks.belacoin;
1695 setHdCoin(73);
1696 },
1697 },
1698 {
1699 name: "BLK - BlackCoin",
1700 onSelect: function() {
1701 network = bitcoinjs.bitcoin.networks.blackcoin;
1702 setHdCoin(10);
1703 },
1704 },
1705 {
1706 name: "BND - Blocknode",
1707 onSelect: function() {
1708 network = bitcoinjs.bitcoin.networks.blocknode;
1709 setHdCoin(2941);
1710 },
1711 },
1712 {
1713 name: "tBND - Blocknode Testnet",
1714 onSelect: function() {
1715 network = bitcoinjs.bitcoin.networks.blocknode_testnet;
1716 setHdCoin(1);
1717 },
1718 },
1719 {
1720 name: "BRIT - Britcoin",
1721 onSelect: function() {
1722 network = bitcoinjs.bitcoin.networks.britcoin;
1723 setHdCoin(70);
1724 },
1725 },
1726 {
1727 name: "BSD - Bitsend",
1728 onSelect: function() {
1729 network = bitcoinjs.bitcoin.networks.bitsend;
1730 setHdCoin(91);
1731 },
1732 },
1733 {
1734 name: "BST - BlockStamp",
1735 onSelect: function() {
1736 network = bitcoinjs.bitcoin.networks.blockstamp;
1737 setHdCoin(254);
1738 },
1739 },
1740 {
1741 name: "BTA - Bata",
1742 onSelect: function() {
1743 network = bitcoinjs.bitcoin.networks.bata;
1744 setHdCoin(89);
1745 },
1746 },
1747 {
1748 name: "BTC - Bitcoin",
1749 onSelect: function() {
1750 network = bitcoinjs.bitcoin.networks.bitcoin;
1751 setHdCoin(0);
1752 },
1753 },
1754 {
1755 name: "BTC - Bitcoin Testnet",
1756 onSelect: function() {
1757 network = bitcoinjs.bitcoin.networks.testnet;
1758 setHdCoin(1);
1759 },
1760 },
1761 {
1762 name: "BITG - Bitcoin Green",
1763 onSelect: function() {
1764 network = bitcoinjs.bitcoin.networks.bitcoingreen;
1765 setHdCoin(222);
1766 },
1767 },
1768 {
1769 name: "BTCP - Bitcoin Private",
1770 onSelect: function() {
1771 network = bitcoinjs.bitcoin.networks.bitcoinprivate;
1772 setHdCoin(183);
1773 },
1774 },
1775 {
1776 name: "BTCZ - Bitcoinz",
1777 onSelect: function() {
1778 network = bitcoinjs.bitcoin.networks.bitcoinz;
1779 setHdCoin(177);
1780 },
1781 },
1782 {
1783 name: "BTDX - BitCloud",
1784 onSelect: function() {
1785 network = bitcoinjs.bitcoin.networks.bitcloud;
1786 setHdCoin(218);
1787 },
1788 },
1789 {
1790 name: "BTG - Bitcoin Gold",
1791 onSelect: function() {
1792 network = bitcoinjs.bitcoin.networks.bgold;
1793 setHdCoin(156);
1794 },
1795 },
1796 {
1797 name: "BTX - Bitcore",
1798 onSelect: function() {
1799 network = bitcoinjs.bitcoin.networks.bitcore;
1800 setHdCoin(160);
1801 },
1802 },
1803 {
1804 name: "CCN - Cannacoin",
1805 onSelect: function() {
1806 network = bitcoinjs.bitcoin.networks.cannacoin;
1807 setHdCoin(19);
1808 },
1809 },
1810 {
1811 name: "CESC - Cryptoescudo",
1812 onSelect: function() {
1813 network = bitcoinjs.bitcoin.networks.cannacoin;
1814 setHdCoin(111);
1815 },
1816 },
1817 {
1818 name: "CDN - Canadaecoin",
1819 onSelect: function() {
1820 network = bitcoinjs.bitcoin.networks.canadaecoin;
1821 setHdCoin(34);
1822 },
1823 },
1824 {
1825 name: "CLAM - Clams",
1826 onSelect: function() {
1827 network = bitcoinjs.bitcoin.networks.clam;
1828 setHdCoin(23);
1829 },
1830 },
1831 {
1832 name: "CLO - Callisto",
1833 segwitAvailable: false,
1834 onSelect: function() {
1835 network = bitcoinjs.bitcoin.networks.bitcoin;
1836 setHdCoin(820);
1837 },
1838 },
1839 {
1840 name: "CLUB - Clubcoin",
1841 onSelect: function() {
1842 network = bitcoinjs.bitcoin.networks.clubcoin;
1843 setHdCoin(79);
1844 },
1845 },
1846 {
1847 name: "CMP - Compcoin",
1848 onSelect: function() {
1849 network = bitcoinjs.bitcoin.networks.compcoin;
1850 setHdCoin(71);
1851 },
1852 },
1853 {
1854 name: "CRAVE - Crave",
1855 onSelect: function() {
1856 network = bitcoinjs.bitcoin.networks.crave;
1857 setHdCoin(186);
1858 },
1859 },
1860 {
1861 name: "CRW - Crown",
1862 onSelect: function() {
1863 network = bitcoinjs.bitcoin.networks.crown;
1864 setHdCoin(72);
1865 },
1866 },
1867 {
1868 name: "DASH - Dash",
1869 onSelect: function() {
1870 network = bitcoinjs.bitcoin.networks.dash;
1871 setHdCoin(5);
1872 },
1873 },
1874 {
1875 name: "DASH - Dash Testnet",
1876 onSelect: function() {
1877 network = bitcoinjs.bitcoin.networks.dashtn;
1878 setHdCoin(1);
1879 },
1880 },
1881 {
1882 name: "DFC - Defcoin",
1883 onSelect: function() {
1884 network = bitcoinjs.bitcoin.networks.defcoin;
1885 setHdCoin(1337);
1886 },
1887 },
1888 {
1889 name: "DGB - Digibyte",
1890 onSelect: function() {
1891 network = bitcoinjs.bitcoin.networks.digibyte;
1892 setHdCoin(20);
1893 },
1894 },
1895 {
1896 name: "DGC - Digitalcoin",
1897 onSelect: function() {
1898 network = bitcoinjs.bitcoin.networks.digitalcoin;
1899 setHdCoin(18);
1900 },
1901 },
1902 {
1903 name: "DMD - Diamond",
1904 onSelect: function() {
1905 network = bitcoinjs.bitcoin.networks.diamond;
1906 setHdCoin(152);
1907 },
1908 },
1909 {
1910 name: "DNR - Denarius",
1911 onSelect: function() {
1912 network = bitcoinjs.bitcoin.networks.denarius;
1913 setHdCoin(116);
1914 },
1915 },
1916 {
1917 name: "DOGE - Dogecoin",
1918 onSelect: function() {
1919 network = bitcoinjs.bitcoin.networks.dogecoin;
1920 setHdCoin(3);
1921 },
1922 },
1923 {
1924 name: "ECN - Ecoin",
1925 onSelect: function() {
1926 network = bitcoinjs.bitcoin.networks.ecoin;
1927 setHdCoin(115);
1928 },
1929 },
1930 {
1931 name: "EDRC - Edrcoin",
1932 onSelect: function() {
1933 network = bitcoinjs.bitcoin.networks.edrcoin;
1934 setHdCoin(56);
1935 },
1936 },
1937 {
1938 name: "EFL - Egulden",
1939 onSelect: function() {
1940 network = bitcoinjs.bitcoin.networks.egulden;
1941 setHdCoin(78);
1942 },
1943 },
1944 {
1945 name: "EMC2 - Einsteinium",
1946 onSelect: function() {
1947 network = bitcoinjs.bitcoin.networks.einsteinium;
1948 setHdCoin(41);
1949 },
1950 },
1951 {
1952 name: "ERC - Europecoin",
1953 onSelect: function() {
1954 network = bitcoinjs.bitcoin.networks.europecoin;
1955 setHdCoin(151);
1956 },
1957 },
1958 {
1959 name: "ETC - Ethereum Classic",
1960 segwitAvailable: false,
1961 onSelect: function() {
1962 network = bitcoinjs.bitcoin.networks.bitcoin;
1963 setHdCoin(61);
1964 },
1965 },
1966 {
1967 name: "ETH - Ethereum",
1968 onSelect: function() {
1969 network = bitcoinjs.bitcoin.networks.bitcoin;
1970 setHdCoin(60);
1971 },
1972 },
1973 {
1974 name: "EXCL - Exclusivecoin",
1975 onSelect: function() {
1976 network = bitcoinjs.bitcoin.networks.exclusivecoin;
1977 setHdCoin(190);
1978 },
1979 },
1980 {
1981 name: "EXCC - ExchangeCoin",
1982 onSelect: function() {
1983 network = bitcoinjs.bitcoin.networks.exchangecoin;
1984 setHdCoin(0);
1985 },
1986 },
1987 {
1988 name: "EXP - Expanse",
1989 segwitAvailable: false,
1990 onSelect: function() {
1991 network = bitcoinjs.bitcoin.networks.bitcoin;
1992 setHdCoin(40);
1993 },
1994 },
1995 {
1996 name: "FJC - Fujicoin",
1997 onSelect: function() {
1998 network = bitcoinjs.bitcoin.networks.fujicoin;
1999 setHdCoin(75);
2000 },
2001 },
2002 {
2003 name: "FLASH - Flashcoin",
2004 onSelect: function() {
2005 network = bitcoinjs.bitcoin.networks.flashcoin;
2006 setHdCoin(120);
2007 },
2008 },
2009 {
2010 name: "FRST - Firstcoin",
2011 onSelect: function() {
2012 network = bitcoinjs.bitcoin.networks.firstcoin;
2013 setHdCoin(167);
2014 },
2015 },
2016 {
2017 name: "FTC - Feathercoin",
2018 onSelect: function() {
2019 network = bitcoinjs.bitcoin.networks.feathercoin;
2020 setHdCoin(8);
2021 },
2022 },
2023 {
2024 name: "GAME - GameCredits",
2025 onSelect: function() {
2026 network = bitcoinjs.bitcoin.networks.game;
2027 setHdCoin(101);
2028 },
2029 },
2030 {
2031 name: "GBX - Gobyte",
2032 onSelect: function() {
2033 network = bitcoinjs.bitcoin.networks.gobyte;
2034 setHdCoin(176);
2035 },
2036 },
2037 {
2038 name: "GCR - GCRCoin",
2039 onSelect: function() {
2040 network = bitcoinjs.bitcoin.networks.gcr;
2041 setHdCoin(79);
2042 },
2043 },
2044 {
2045 name: "GRC - Gridcoin",
2046 onSelect: function() {
2047 network = bitcoinjs.bitcoin.networks.gridcoin;
2048 setHdCoin(84);
2049 },
2050 },
2051 {
2052 name: "HNC - Helleniccoin",
2053 onSelect: function() {
2054 network = bitcoinjs.bitcoin.networks.helleniccoin;
2055 setHdCoin(168);
2056 },
2057 },
2058 {
2059 name: "HUSH - Hush",
2060 onSelect: function() {
2061 network = bitcoinjs.bitcoin.networks.hush;
2062 setHdCoin(197);
2063 },
2064 },
2065 {
2066 name: "INSN - Insane",
2067 onSelect: function() {
2068 network = bitcoinjs.bitcoin.networks.insane;
2069 setHdCoin(68);
2070 },
2071 },
2072 {
2073 name: "IOP - Iop",
2074 onSelect: function() {
2075 network = bitcoinjs.bitcoin.networks.iop;
2076 setHdCoin(66);
2077 },
2078 },
2079 {
2080 name: "IXC - Ixcoin",
2081 onSelect: function() {
2082 network = bitcoinjs.bitcoin.networks.ixcoin;
2083 setHdCoin(86);
2084 },
2085 },
2086 {
2087 name: "JBS - Jumbucks",
2088 onSelect: function() {
2089 network = bitcoinjs.bitcoin.networks.jumbucks;
2090 setHdCoin(26);
2091 },
2092 },
2093 {
2094 name: "KMD - Komodo",
2095 bip49available: false,
2096 onSelect: function() {
2097 network = bitcoinjs.bitcoin.networks.komodo;
2098 setHdCoin(141);
2099 },
2100 },
2101 {
2102 name: "KOBO - Kobocoin",
2103 bip49available: false,
2104 onSelect: function() {
2105 network = bitcoinjs.bitcoin.networks.kobocoin;
2106 setHdCoin(196);
2107 },
2108 },
2109 {
2110 name: "LBC - Library Credits",
2111 onSelect: function() {
2112 network = bitcoinjs.bitcoin.networks.lbry;
2113 setHdCoin(140);
2114 },
2115 },
2116 {
2117 name: "LCC - Litecoincash",
2118 onSelect: function() {
2119 network = bitcoinjs.bitcoin.networks.litecoincash;
2120 setHdCoin(192);
2121 },
2122 },
2123 {
2124 name: "LDCN - Landcoin",
2125 onSelect: function() {
2126 network = bitcoinjs.bitcoin.networks.landcoin;
2127 setHdCoin(63);
2128 },
2129 },
2130 {
2131 name: "LINX - Linx",
2132 onSelect: function() {
2133 network = bitcoinjs.bitcoin.networks.linx;
2134 setHdCoin(114);
2135 },
2136 },
2137 {
2138 name: "LKR - Lkrcoin",
2139 segwitAvailable: false,
2140 onSelect: function() {
2141 network = bitcoinjs.bitcoin.networks.lkrcoin;
2142 setHdCoin(557);
2143 },
2144 },
2145 {
2146 name: "LTC - Litecoin",
2147 onSelect: function() {
2148 network = bitcoinjs.bitcoin.networks.litecoin;
2149 setHdCoin(2);
2150 DOM.litecoinLtubContainer.removeClass("hidden");
2151 },
2152 },
2153 {
2154 name: "LTZ - LitecoinZ",
2155 onSelect: function() {
2156 network = bitcoinjs.bitcoin.networks.litecoinz;
2157 setHdCoin(221);
2158 },
2159 },
2160 {
2161 name: "LYNX - Lynx",
2162 onSelect: function() {
2163 network = bitcoinjs.bitcoin.networks.lynx;
2164 setHdCoin(191);
2165 },
2166 },
2167 {
2168 name: "MAZA - Maza",
2169 onSelect: function() {
2170 network = bitcoinjs.bitcoin.networks.maza;
2171 setHdCoin(13);
2172 },
2173 },
2174 {
2175 name: "MEC - Megacoin",
2176 onSelect: function() {
2177 network = bitcoinjs.bitcoin.networks.megacoin;
2178 setHdCoin(217);
2179 },
2180 },
2181 {
2182 name: "MIX - MIX",
2183 segwitAvailable: false,
2184 onSelect: function() {
2185 network = bitcoinjs.bitcoin.networks.bitcoin;
2186 setHdCoin(76);
2187 },
2188 },
2189 {
2190 name: "MNX - Minexcoin",
2191 onSelect: function() {
2192 network = bitcoinjs.bitcoin.networks.minexcoin;
2193 setHdCoin(182);
2194 },
2195 },
2196 {
2197 name: "MONA - Monacoin",
2198 onSelect: function() {
2199 network = bitcoinjs.bitcoin.networks.monacoin,
2200 setHdCoin(22);
2201 },
2202 },
2203 {
2204 name: "MUSIC - Musicoin",
2205 segwitAvailable: false,
2206 onSelect: function() {
2207 network = bitcoinjs.bitcoin.networks.bitcoin;
2208 setHdCoin(184);
2209 },
2210 },
2211 {
2212 name: "NAV - Navcoin",
2213 onSelect: function() {
2214 network = bitcoinjs.bitcoin.networks.navcoin;
2215 setHdCoin(130);
2216 },
2217 },
2218 {
2219 name: "NEBL - Neblio",
2220 onSelect: function() {
2221 network = bitcoinjs.bitcoin.networks.neblio;
2222 setHdCoin(146);
2223 },
2224 },
2225 {
2226 name: "NEOS - Neoscoin",
2227 onSelect: function() {
2228 network = bitcoinjs.bitcoin.networks.neoscoin;
2229 setHdCoin(25);
2230 },
2231 },
2232 {
2233 name: "NIX - NIX Platform",
2234 onSelect: function() {
2235 network = bitcoinjs.bitcoin.networks.nix;
2236 setHdCoin(400);
2237 },
2238 },
2239 {
2240 name: "NLG - Gulden",
2241 onSelect: function() {
2242 network = bitcoinjs.bitcoin.networks.gulden;
2243 setHdCoin(87);
2244 },
2245 },
2246 {
2247 name: "NMC - Namecoin",
2248 onSelect: function() {
2249 network = bitcoinjs.bitcoin.networks.namecoin;
2250 setHdCoin(7);
2251 },
2252 },
2253 {
2254 name: "NRG - Energi",
2255 onSelect: function() {
2256 network = bitcoinjs.bitcoin.networks.energi;
2257 setHdCoin(204);
2258 },
2259 },
2260 {
2261 name: "NRO - Neurocoin",
2262 onSelect: function() {
2263 network = bitcoinjs.bitcoin.networks.neurocoin;
2264 setHdCoin(110);
2265 },
2266 },
2267 {
2268 name: "NSR - Nushares",
2269 onSelect: function() {
2270 network = bitcoinjs.bitcoin.networks.nushares;
2271 setHdCoin(11);
2272 },
2273 },
2274 {
2275 name: "NYC - Newyorkc",
2276 onSelect: function() {
2277 network = bitcoinjs.bitcoin.networks.newyorkc;
2278 setHdCoin(179);
2279 },
2280 },
2281 {
2282 name: "NVC - Novacoin",
2283 onSelect: function() {
2284 network = bitcoinjs.bitcoin.networks.novacoin;
2285 setHdCoin(50);
2286 },
2287 },
2288 {
2289 name: "OK - Okcash",
2290 onSelect: function() {
2291 network = bitcoinjs.bitcoin.networks.okcash;
2292 setHdCoin(69);
2293 },
2294 },
2295 {
2296 name: "OMNI - Omnicore",
2297 onSelect: function() {
2298 network = bitcoinjs.bitcoin.networks.omnicore;
2299 setHdCoin(200);
2300 },
2301 },
2302 {
2303 name: "ONX - Onixcoin",
2304 onSelect: function() {
2305 network = bitcoinjs.bitcoin.networks.onixcoin;
2306 setHdCoin(174);
2307 },
2308 },
2309 {
2310 name: "PHR - Phore",
2311 onSelect: function() {
2312 network = bitcoinjs.bitcoin.networks.phore;
2313 setHdCoin(444);
2314 },
2315 },
2316 {
2317 name: "PINK - Pinkcoin",
2318 onSelect: function() {
2319 network = bitcoinjs.bitcoin.networks.pinkcoin;
2320 setHdCoin(117);
2321 },
2322 },
2323 {
2324 name: "PIRL - Pirl",
2325 segwitAvailable: false,
2326 onSelect: function() {
2327 network = bitcoinjs.bitcoin.networks.bitcoin;
2328 setHdCoin(164);
2329 },
2330 },
2331 {
2332 name: "PIVX - PIVX",
2333 onSelect: function() {
2334 network = bitcoinjs.bitcoin.networks.pivx;
2335 setHdCoin(119);
2336 },
2337 },
2338 {
2339 name: "PIVX - PIVX Testnet",
2340 onSelect: function() {
2341 network = bitcoinjs.bitcoin.networks.pivxtestnet;
2342 setHdCoin(1);
2343 },
2344 },
2345 {
2346 name: "POA - Poa",
2347 segwitAvailable: false,
2348 onSelect: function() {
2349 network = bitcoinjs.bitcoin.networks.bitcoin;
2350 setHdCoin(178);
2351 },
2352 },
2353 {
2354 name: "POSW - POSWcoin",
2355 onSelect: function() {
2356 network = bitcoinjs.bitcoin.networks.poswcoin;
2357 setHdCoin(47);
2358 },
2359 },
2360 {
2361 name: "POT - Potcoin",
2362 onSelect: function() {
2363 network = bitcoinjs.bitcoin.networks.potcoin;
2364 setHdCoin(81);
2365 },
2366 },
2367 {
2368 name: "PPC - Peercoin",
2369 onSelect: function() {
2370 network = bitcoinjs.bitcoin.networks.peercoin;
2371 setHdCoin(6);
2372 },
2373 },
2374 {
2375 name: "PRJ - ProjectCoin",
2376 onSelect: function() {
2377 network = bitcoinjs.bitcoin.networks.projectcoin;
2378 setHdCoin(533);
2379 },
2380 },
2381 {
2382 name: "PSB - Pesobit",
2383 onSelect: function() {
2384 network = bitcoinjs.bitcoin.networks.pesobit;
2385 setHdCoin(62);
2386 },
2387 },
2388 {
2389 name: "PUT - Putincoin",
2390 onSelect: function() {
2391 network = bitcoinjs.bitcoin.networks.putincoin;
2392 setHdCoin(122);
2393 },
2394 },
2395 {
2396 name: "RVN - Ravencoin",
2397 onSelect: function() {
2398 network = bitcoinjs.bitcoin.networks.ravencoin;
2399 setHdCoin(175);
2400 },
2401 },
2402 {
2403 name: "RBY - Rubycoin",
2404 onSelect: function() {
2405 network = bitcoinjs.bitcoin.networks.rubycoin;
2406 setHdCoin(16);
2407 },
2408 },
2409 {
2410 name: "RDD - Reddcoin",
2411 onSelect: function() {
2412 network = bitcoinjs.bitcoin.networks.reddcoin;
2413 setHdCoin(4);
2414 },
2415 },
2416 {
2417 name: "RVR - RevolutionVR",
2418 onSelect: function() {
2419 network = bitcoinjs.bitcoin.networks.revolutionvr;
2420 setHdCoin(129);
2421 },
2422 },
2423 {
2424 name: "SAFE - Safecoin",
2425 onSelect: function() {
2426 network = bitcoinjs.bitcoin.networks.safecoin;
2427 setHdCoin(19165);
2428 },
2429 },
2430 {
2431 name: "SLS - Salus",
2432 onSelect: function() {
2433 network = bitcoinjs.bitcoin.networks.salus;
2434 setHdCoin(63);
2435 },
2436 },
2437 {
2438 name: "SDC - ShadowCash",
2439 onSelect: function() {
2440 network = bitcoinjs.bitcoin.networks.shadow;
2441 setHdCoin(35);
2442 },
2443 },
2444 {
2445 name: "SDC - ShadowCash Testnet",
2446 onSelect: function() {
2447 network = bitcoinjs.bitcoin.networks.shadowtn;
2448 setHdCoin(1);
2449 },
2450 },
2451 {
2452 name: "SLM - Slimcoin",
2453 onSelect: function() {
2454 network = bitcoinjs.bitcoin.networks.slimcoin;
2455 setHdCoin(63);
2456 },
2457 },
2458 {
2459 name: "SLM - Slimcoin Testnet",
2460 onSelect: function() {
2461 network = bitcoinjs.bitcoin.networks.slimcointn;
2462 setHdCoin(111);
2463 },
2464 },
2465 {
2466 name: "SLR - Solarcoin",
2467 onSelect: function() {
2468 network = bitcoinjs.bitcoin.networks.solarcoin;
2469 setHdCoin(58);
2470 },
2471 },
2472 {
2473 name: "SMLY - Smileycoin",
2474 onSelect: function() {
2475 network = bitcoinjs.bitcoin.networks.smileycoin;
2476 setHdCoin(59);
2477 },
2478 },
2479 {
2480 name: "STASH - Stash",
2481 onSelect: function() {
2482 network = bitcoinjs.bitcoin.networks.stash;
2483 setHdCoin(0xC0C0);
2484 },
2485 },
2486 {
2487 name: "STASH - Stash Testnet",
2488 onSelect: function() {
2489 network = bitcoinjs.bitcoin.networks.stashtn;
2490 setHdCoin(0xCAFE);
2491 },
2492 },
2493 {
2494 name: "STRAT - Stratis",
2495 onSelect: function() {
2496 network = bitcoinjs.bitcoin.networks.stratis;
2497 setHdCoin(105);
2498 },
2499 },
2500 {
2501 name: "TSTRAT - Stratis Testnet",
2502 onSelect: function() {
2503 network = bitcoinjs.bitcoin.networks.stratistest;
2504 setHdCoin(105);
2505 },
2506 },
2507 {
2508 name: "SYS - Syscoin",
2509 onSelect: function() {
2510 network = bitcoinjs.bitcoin.networks.syscoin;
2511 setHdCoin(57);
2512 },
2513 },
2514 {
2515 name: "THC - Hempcoin",
2516 onSelect: function() {
2517 network = bitcoinjs.bitcoin.networks.hempcoin;
2518 setHdCoin(113);
2519 },
2520 },
2521 {
2522 name: "TOA - Toa",
2523 onSelect: function() {
2524 network = bitcoinjs.bitcoin.networks.toa;
2525 setHdCoin(159);
2526 },
2527 },
2528 {
2529 name: "USC - Ultimatesecurecash",
2530 onSelect: function() {
2531 network = bitcoinjs.bitcoin.networks.ultimatesecurecash;
2532 setHdCoin(112);
2533 },
2534 },
2535 {
2536 name: "USNBT - NuBits",
2537 onSelect: function() {
2538 network = bitcoinjs.bitcoin.networks.nubits;
2539 setHdCoin(12);
2540 },
2541 },
2542 {
2543 name: "UNO - Unobtanium",
2544 onSelect: function() {
2545 network = bitcoinjs.bitcoin.networks.unobtanium;
2546 setHdCoin(92);
2547 },
2548 },
2549 {
2550 name: "VASH - Vpncoin",
2551 onSelect: function() {
2552 network = bitcoinjs.bitcoin.networks.vpncoin;
2553 setHdCoin(33);
2554 },
2555 },
2556 {
2557 name: "VIA - Viacoin",
2558 onSelect: function() {
2559 network = bitcoinjs.bitcoin.networks.viacoin;
2560 setHdCoin(14);
2561 },
2562 },
2563 {
2564 name: "VIA - Viacoin Testnet",
2565 onSelect: function() {
2566 network = bitcoinjs.bitcoin.networks.viacointestnet;
2567 setHdCoin(1);
2568 },
2569 },
2570 {
2571 name: "VIVO - Vivo",
2572 onSelect: function() {
2573 network = bitcoinjs.bitcoin.networks.vivo;
2574 setHdCoin(166);
2575 },
2576 },
2577 {
2578 name: "VTC - Vertcoin",
2579 onSelect: function() {
2580 network = bitcoinjs.bitcoin.networks.vertcoin;
2581 setHdCoin(28);
2582 },
2583 },
2584 {
2585 name: "WC - Wincoin",
2586 onSelect: function() {
2587 network = bitcoinjs.bitcoin.networks.wincoin;
2588 setHdCoin(181);
2589 },
2590 },
2591 {
2592 name: "XAX - Artax",
2593 onSelect: function() {
2594 network = bitcoinjs.bitcoin.networks.artax;
2595 setHdCoin(219);
2596 },
2597 },
2598 {
2599 name: "XBC - Bitcoinplus",
2600 onSelect: function() {
2601 network = bitcoinjs.bitcoin.networks.bitcoinplus;
2602 setHdCoin(65);
2603 },
2604 },
2605 {
2606 name: "XMY - Myriadcoin",
2607 onSelect: function() {
2608 network = bitcoinjs.bitcoin.networks.myriadcoin;
2609 setHdCoin(90);
2610 },
2611 },
2612 {
2613 name: "XRP - Ripple",
2614 onSelect: function() {
2615 network = bitcoinjs.bitcoin.networks.bitcoin;
2616 setHdCoin(144);
2617 },
2618 },
2619 {
2620 name: "XVC - Vcash",
2621 onSelect: function() {
2622 network = bitcoinjs.bitcoin.networks.vcash;
2623 setHdCoin(127);
2624 },
2625 },
2626 {
2627 name: "XVG - Verge",
2628 onSelect: function() {
2629 network = bitcoinjs.bitcoin.networks.verge;
2630 setHdCoin(77);
2631 },
2632 },
2633 {
2634 name: "XUEZ - Xuez",
2635 segwitAvailable: false,
2636 onSelect: function() {
2637 network = bitcoinjs.bitcoin.networks.xuez;
2638 setHdCoin(225);
2639 },
2640 },
2641 {
2642 name: "XWC - Whitecoin",
2643 onSelect: function() {
2644 network = bitcoinjs.bitcoin.networks.whitecoin;
2645 setHdCoin(155);
2646 },
2647 },
2648 {
2649 name: "XZC - Zcoin",
2650 onSelect: function() {
2651 network = bitcoinjs.bitcoin.networks.zcoin;
2652 setHdCoin(136);
2653 },
2654 },
2655 {
2656 name: "ZCL - Zclassic",
2657 onSelect: function() {
2658 network = bitcoinjs.bitcoin.networks.zclassic;
2659 setHdCoin(147);
2660 },
2661 },
2662 {
2663 name: "ZEC - Zcash",
2664 onSelect: function() {
2665 network = bitcoinjs.bitcoin.networks.zcash;
2666 setHdCoin(133);
2667 },
2668 },
2669 {
2670 name: "ZEN - Zencash",
2671 onSelect: function() {
2672 network = bitcoinjs.bitcoin.networks.zencash;
2673 setHdCoin(121);
2674 },
2675 },
2676 ]
2677
2678 var clients = [
2679 {
2680 name: "Bitcoin Core",
2681 onSelect: function() {
2682 DOM.bip32path.val("m/0'/0'");
2683 DOM.hardenedAddresses.prop('checked', true);
2684 },
2685 },
2686 {
2687 name: "blockchain.info",
2688 onSelect: function() {
2689 DOM.bip32path.val("m/44'/0'/0'");
2690 DOM.hardenedAddresses.prop('checked', false);
2691 },
2692 },
2693 {
2694 name: "MultiBit HD",
2695 onSelect: function() {
2696 DOM.bip32path.val("m/0'/0");
2697 DOM.hardenedAddresses.prop('checked', false);
2698 },
2699 },
2700 {
2701 name: "Coinomi, Ledger",
2702 onSelect: function() {
2703 DOM.bip32path.val("m/44'/"+DOM.bip44coin.val()+"'/0'");
2704 DOM.hardenedAddresses.prop('checked', false);
2705 },
2706 }
2707 ]
2708
2709 init();
2710
2711 })();