]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blob - src/js/index.js
FIX LKRcoin wif private key header
[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 || (networks[DOM.network.val()].name == "DXN - DEXON")) {
922 var privKeyBuffer = keyPair.d.toBuffer(32);
923 privkey = privKeyBuffer.toString('hex');
924 var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
925 var hexAddress = addressBuffer.toString('hex');
926 var checksumAddress = ethUtil.toChecksumAddress(hexAddress);
927 address = ethUtil.addHexPrefix(checksumAddress);
928 privkey = ethUtil.addHexPrefix(privkey);
929 pubkey = ethUtil.addHexPrefix(pubkey);
930 }
931 if ((networks[DOM.network.val()].name == "NAS - Nebulas")) {
932 var NasAccount = require("nebulas-account");
933 var privKeyBuffer = keyPair.d.toBuffer(32);
934 var nebulasAccount = new NasAccount();
935 nebulasAccount.setPrivateKey(privKeyBuffer);
936 address = nebulasAccount.getAddressString();
937 privkey = nebulasAccount.getPrivateKeyString();
938 pubkey = nebulasAccount.getPublicKeyString();
939 }
940 // Ripple values are different
941 if (networks[DOM.network.val()].name == "XRP - Ripple") {
942 privkey = convertRipplePriv(privkey);
943 address = convertRippleAdrr(address);
944 }
945 // Bitcoin Cash address format may vary
946 if (networks[DOM.network.val()].name == "BCH - Bitcoin Cash") {
947 var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val();
948 if (bchAddrType == "cashaddr") {
949 address = bchaddr.toCashAddress(address);
950 }
951 else if (bchAddrType == "bitpay") {
952 address = bchaddr.toBitpayAddress(address);
953 }
954 }
955 // Segwit addresses are different
956 if (isSegwit) {
957 if (!segwitAvailable) {
958 return;
959 }
960 if (isP2wpkh) {
961 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
962 var scriptpubkey = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
963 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
964 }
965 else if (isP2wpkhInP2sh) {
966 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
967 var scriptsig = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
968 var addressbytes = bitcoinjs.bitcoin.crypto.hash160(scriptsig);
969 var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes);
970 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
971 }
972 }
973 addAddressToList(indexText, address, pubkey, privkey);
974 if (isLast) {
975 hidePending();
976 updateCsv();
977 }
978 }, 50)
979 }
980
981 init();
982
983 }
984
985 function showMore() {
986 var rowsToAdd = parseInt(DOM.rowsToAdd.val());
987 if (isNaN(rowsToAdd)) {
988 rowsToAdd = 20;
989 DOM.rowsToAdd.val("20");
990 }
991 var start = parseInt(DOM.moreRowsStartIndex.val())
992 if (isNaN(start)) {
993 start = lastIndexInTable() + 1;
994 }
995 else {
996 var newStart = start + rowsToAdd;
997 DOM.moreRowsStartIndex.val(newStart);
998 }
999 if (rowsToAdd > 200) {
1000 var msg = "Generating " + rowsToAdd + " rows could take a while. ";
1001 msg += "Do you want to continue?";
1002 if (!confirm(msg)) {
1003 return;
1004 }
1005 }
1006 displayAddresses(start, rowsToAdd);
1007 }
1008
1009 function clearDisplay() {
1010 clearAddressesList();
1011 clearKeys();
1012 hideValidationError();
1013 }
1014
1015 function clearAddressesList() {
1016 DOM.addresses.empty();
1017 DOM.csv.val("");
1018 stopGenerating();
1019 }
1020
1021 function stopGenerating() {
1022 while (generationProcesses.length > 0) {
1023 var generation = generationProcesses.shift();
1024 generation.stop();
1025 }
1026 }
1027
1028 function clearKeys() {
1029 clearRootKey();
1030 clearDerivedKeys();
1031 }
1032
1033 function clearRootKey() {
1034 DOM.rootKey.val("");
1035 }
1036
1037 function clearDerivedKeys() {
1038 DOM.extendedPrivKey.val("");
1039 DOM.extendedPubKey.val("");
1040 DOM.bip44accountXprv.val("");
1041 DOM.bip44accountXpub.val("");
1042 }
1043
1044 function addAddressToList(indexText, address, pubkey, privkey) {
1045 var row = $(addressRowTemplate.html());
1046 // Elements
1047 var indexCell = row.find(".index span");
1048 var addressCell = row.find(".address span");
1049 var pubkeyCell = row.find(".pubkey span");
1050 var privkeyCell = row.find(".privkey span");
1051 // Content
1052 indexCell.text(indexText);
1053 addressCell.text(address);
1054 pubkeyCell.text(pubkey);
1055 privkeyCell.text(privkey);
1056 // Visibility
1057 if (!showIndex) {
1058 indexCell.addClass("invisible");
1059 }
1060 if (!showAddress) {
1061 addressCell.addClass("invisible");
1062 }
1063 if (!showPubKey) {
1064 pubkeyCell.addClass("invisible");
1065 }
1066 if (!showPrivKey) {
1067 privkeyCell.addClass("invisible");
1068 }
1069 DOM.addresses.append(row);
1070 var rowShowQrEls = row.find("[data-show-qr]");
1071 setQrEvents(rowShowQrEls);
1072 }
1073
1074 function hasStrongRandom() {
1075 return 'crypto' in window && window['crypto'] !== null;
1076 }
1077
1078 function disableForms() {
1079 $("form").on("submit", function(e) {
1080 e.preventDefault();
1081 });
1082 }
1083
1084 function parseIntNoNaN(val, defaultVal) {
1085 var v = parseInt(val);
1086 if (isNaN(v)) {
1087 return defaultVal;
1088 }
1089 return v;
1090 }
1091
1092 function showPending() {
1093 DOM.feedback
1094 .text("Calculating...")
1095 .show();
1096 }
1097
1098 function findNearestWord(word) {
1099 var language = getLanguage();
1100 var words = WORDLISTS[language];
1101 var minDistance = 99;
1102 var closestWord = words[0];
1103 for (var i=0; i<words.length; i++) {
1104 var comparedTo = words[i];
1105 if (comparedTo.indexOf(word) == 0) {
1106 return comparedTo;
1107 }
1108 var distance = Levenshtein.get(word, comparedTo);
1109 if (distance < minDistance) {
1110 closestWord = comparedTo;
1111 minDistance = distance;
1112 }
1113 }
1114 return closestWord;
1115 }
1116
1117 function hidePending() {
1118 DOM.feedback
1119 .text("")
1120 .hide();
1121 }
1122
1123 function populateNetworkSelect() {
1124 for (var i=0; i<networks.length; i++) {
1125 var network = networks[i];
1126 var option = $("<option>");
1127 option.attr("value", i);
1128 option.text(network.name);
1129 if (network.name == "BTC - Bitcoin") {
1130 option.prop("selected", true);
1131 }
1132 DOM.phraseNetwork.append(option);
1133 }
1134 }
1135
1136 function populateClientSelect() {
1137 for (var i=0; i<clients.length; i++) {
1138 var client = clients[i];
1139 var option = $("<option>");
1140 option.attr("value", i);
1141 option.text(client.name);
1142 DOM.bip32Client.append(option);
1143 }
1144 }
1145
1146 function getLanguage() {
1147 var defaultLanguage = "english";
1148 // Try to get from existing phrase
1149 var language = getLanguageFromPhrase();
1150 // Try to get from url if not from phrase
1151 if (language.length == 0) {
1152 language = getLanguageFromUrl();
1153 }
1154 // Default to English if no other option
1155 if (language.length == 0) {
1156 language = defaultLanguage;
1157 }
1158 return language;
1159 }
1160
1161 function getLanguageFromPhrase(phrase) {
1162 // Check if how many words from existing phrase match a language.
1163 var language = "";
1164 if (!phrase) {
1165 phrase = DOM.phrase.val();
1166 }
1167 if (phrase.length > 0) {
1168 var words = phraseToWordArray(phrase);
1169 var languageMatches = {};
1170 for (l in WORDLISTS) {
1171 // Track how many words match in this language
1172 languageMatches[l] = 0;
1173 for (var i=0; i<words.length; i++) {
1174 var wordInLanguage = WORDLISTS[l].indexOf(words[i]) > -1;
1175 if (wordInLanguage) {
1176 languageMatches[l]++;
1177 }
1178 }
1179 // Find languages with most word matches.
1180 // This is made difficult due to commonalities between Chinese
1181 // simplified vs traditional.
1182 var mostMatches = 0;
1183 var mostMatchedLanguages = [];
1184 for (var l in languageMatches) {
1185 var numMatches = languageMatches[l];
1186 if (numMatches > mostMatches) {
1187 mostMatches = numMatches;
1188 mostMatchedLanguages = [l];
1189 }
1190 else if (numMatches == mostMatches) {
1191 mostMatchedLanguages.push(l);
1192 }
1193 }
1194 }
1195 if (mostMatchedLanguages.length > 0) {
1196 // Use first language and warn if multiple detected
1197 language = mostMatchedLanguages[0];
1198 if (mostMatchedLanguages.length > 1) {
1199 console.warn("Multiple possible languages");
1200 console.warn(mostMatchedLanguages);
1201 }
1202 }
1203 }
1204 return language;
1205 }
1206
1207 function getLanguageFromUrl() {
1208 for (var language in WORDLISTS) {
1209 if (window.location.hash.indexOf(language) > -1) {
1210 return language;
1211 }
1212 }
1213 return "";
1214 }
1215
1216 function setMnemonicLanguage() {
1217 var language = getLanguage();
1218 // Load the bip39 mnemonic generator for this language if required
1219 if (!(language in mnemonics)) {
1220 mnemonics[language] = new Mnemonic(language);
1221 }
1222 mnemonic = mnemonics[language];
1223 }
1224
1225 function convertPhraseToNewLanguage() {
1226 var oldLanguage = getLanguageFromPhrase();
1227 var newLanguage = getLanguageFromUrl();
1228 var oldPhrase = DOM.phrase.val();
1229 var oldWords = phraseToWordArray(oldPhrase);
1230 var newWords = [];
1231 for (var i=0; i<oldWords.length; i++) {
1232 var oldWord = oldWords[i];
1233 var index = WORDLISTS[oldLanguage].indexOf(oldWord);
1234 var newWord = WORDLISTS[newLanguage][index];
1235 newWords.push(newWord);
1236 }
1237 newPhrase = wordArrayToPhrase(newWords);
1238 return newPhrase;
1239 }
1240
1241 // TODO look at jsbip39 - mnemonic.splitWords
1242 function phraseToWordArray(phrase) {
1243 var words = phrase.split(/\s/g);
1244 var noBlanks = [];
1245 for (var i=0; i<words.length; i++) {
1246 var word = words[i];
1247 if (word.length > 0) {
1248 noBlanks.push(word);
1249 }
1250 }
1251 return noBlanks;
1252 }
1253
1254 // TODO look at jsbip39 - mnemonic.joinWords
1255 function wordArrayToPhrase(words) {
1256 var phrase = words.join(" ");
1257 var language = getLanguageFromPhrase(phrase);
1258 if (language == "japanese") {
1259 phrase = words.join("\u3000");
1260 }
1261 return phrase;
1262 }
1263
1264 function isUsingOwnEntropy() {
1265 return DOM.useEntropy.prop("checked");
1266 }
1267
1268 function setMnemonicFromEntropy() {
1269 clearEntropyFeedback();
1270 // Get entropy value
1271 var entropyStr = DOM.entropy.val();
1272 // Work out minimum base for entropy
1273 var entropy = Entropy.fromString(entropyStr);
1274 if (entropy.binaryStr.length == 0) {
1275 return;
1276 }
1277 // Show entropy details
1278 showEntropyFeedback(entropy);
1279 // Use entropy hash if not using raw entropy
1280 var bits = entropy.binaryStr;
1281 var mnemonicLength = DOM.entropyMnemonicLength.val();
1282 if (mnemonicLength != "raw") {
1283 // Get bits by hashing entropy with SHA256
1284 var hash = sjcl.hash.sha256.hash(entropy.cleanStr);
1285 var hex = sjcl.codec.hex.fromBits(hash);
1286 bits = BigInteger.parse(hex, 16).toString(2);
1287 while (bits.length % 256 != 0) {
1288 bits = "0" + bits;
1289 }
1290 // Truncate hash to suit number of words
1291 mnemonicLength = parseInt(mnemonicLength);
1292 var numberOfBits = 32 * mnemonicLength / 3;
1293 bits = bits.substring(0, numberOfBits);
1294 // show warning for weak entropy override
1295 if (mnemonicLength / 3 * 32 > entropy.binaryStr.length) {
1296 DOM.entropyWeakEntropyOverrideWarning.removeClass("hidden");
1297 }
1298 else {
1299 DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
1300 }
1301 }
1302 else {
1303 // hide warning for weak entropy override
1304 DOM.entropyWeakEntropyOverrideWarning.addClass("hidden");
1305 }
1306 // Discard trailing entropy
1307 var bitsToUse = Math.floor(bits.length / 32) * 32;
1308 var start = bits.length - bitsToUse;
1309 var binaryStr = bits.substring(start);
1310 // Convert entropy string to numeric array
1311 var entropyArr = [];
1312 for (var i=0; i<binaryStr.length / 8; i++) {
1313 var byteAsBits = binaryStr.substring(i*8, i*8+8);
1314 var entropyByte = parseInt(byteAsBits, 2);
1315 entropyArr.push(entropyByte)
1316 }
1317 // Convert entropy array to mnemonic
1318 var phrase = mnemonic.toMnemonic(entropyArr);
1319 // Set the mnemonic in the UI
1320 DOM.phrase.val(phrase);
1321 // Show the word indexes
1322 showWordIndexes();
1323 // Show the checksum
1324 showChecksum();
1325 }
1326
1327 function clearEntropyFeedback() {
1328 DOM.entropyCrackTime.text("...");
1329 DOM.entropyType.text("");
1330 DOM.entropyWordCount.text("0");
1331 DOM.entropyEventCount.text("0");
1332 DOM.entropyBitsPerEvent.text("0");
1333 DOM.entropyBits.text("0");
1334 DOM.entropyFiltered.html("&nbsp;");
1335 DOM.entropyBinary.html("&nbsp;");
1336 }
1337
1338 function showEntropyFeedback(entropy) {
1339 var numberOfBits = entropy.binaryStr.length;
1340 var timeToCrack = "unknown";
1341 try {
1342 var z = zxcvbn(entropy.base.parts.join(""));
1343 timeToCrack = z.crack_times_display.offline_fast_hashing_1e10_per_second;
1344 if (z.feedback.warning != "") {
1345 timeToCrack = timeToCrack + " - " + z.feedback.warning;
1346 };
1347 }
1348 catch (e) {
1349 console.log("Error detecting entropy strength with zxcvbn:");
1350 console.log(e);
1351 }
1352 var entropyTypeStr = getEntropyTypeStr(entropy);
1353 var wordCount = Math.floor(numberOfBits / 32) * 3;
1354 var bitsPerEvent = entropy.bitsPerEvent.toFixed(2);
1355 var spacedBinaryStr = addSpacesEveryElevenBits(entropy.binaryStr);
1356 DOM.entropyFiltered.html(entropy.cleanHtml);
1357 DOM.entropyType.text(entropyTypeStr);
1358 DOM.entropyCrackTime.text(timeToCrack);
1359 DOM.entropyEventCount.text(entropy.base.ints.length);
1360 DOM.entropyBits.text(numberOfBits);
1361 DOM.entropyWordCount.text(wordCount);
1362 DOM.entropyBinary.text(spacedBinaryStr);
1363 DOM.entropyBitsPerEvent.text(bitsPerEvent);
1364 // detect and warn of filtering
1365 var rawNoSpaces = DOM.entropy.val().replace(/\s/g, "");
1366 var cleanNoSpaces = entropy.cleanStr.replace(/\s/g, "");
1367 var isFiltered = rawNoSpaces.length != cleanNoSpaces.length;
1368 if (isFiltered) {
1369 DOM.entropyFilterWarning.removeClass('hidden');
1370 }
1371 else {
1372 DOM.entropyFilterWarning.addClass('hidden');
1373 }
1374 }
1375
1376 function getEntropyTypeStr(entropy) {
1377 var typeStr = entropy.base.str;
1378 // Add some detail if these are cards
1379 if (entropy.base.asInt == 52) {
1380 var cardDetail = []; // array of message strings
1381 // Detect duplicates
1382 var dupes = [];
1383 var dupeTracker = {};
1384 for (var i=0; i<entropy.base.parts.length; i++) {
1385 var card = entropy.base.parts[i];
1386 var cardUpper = card.toUpperCase();
1387 if (cardUpper in dupeTracker) {
1388 dupes.push(card);
1389 }
1390 dupeTracker[cardUpper] = true;
1391 }
1392 if (dupes.length > 0) {
1393 var dupeWord = "duplicates";
1394 if (dupes.length == 1) {
1395 dupeWord = "duplicate";
1396 }
1397 var msg = dupes.length + " " + dupeWord + ": " + dupes.slice(0,3).join(" ");
1398 if (dupes.length > 3) {
1399 msg += "...";
1400 }
1401 cardDetail.push(msg);
1402 }
1403 // Detect full deck
1404 var uniqueCards = [];
1405 for (var uniqueCard in dupeTracker) {
1406 uniqueCards.push(uniqueCard);
1407 }
1408 if (uniqueCards.length == 52) {
1409 cardDetail.unshift("full deck");
1410 }
1411 // Detect missing cards
1412 var values = "A23456789TJQK";
1413 var suits = "CDHS";
1414 var missingCards = [];
1415 for (var i=0; i<suits.length; i++) {
1416 for (var j=0; j<values.length; j++) {
1417 var card = values[j] + suits[i];
1418 if (!(card in dupeTracker)) {
1419 missingCards.push(card);
1420 }
1421 }
1422 }
1423 // Display missing cards if six or less, ie clearly going for full deck
1424 if (missingCards.length > 0 && missingCards.length <= 6) {
1425 var msg = missingCards.length + " missing: " + missingCards.slice(0,3).join(" ");
1426 if (missingCards.length > 3) {
1427 msg += "...";
1428 }
1429 cardDetail.push(msg);
1430 }
1431 // Add card details to typeStr
1432 if (cardDetail.length > 0) {
1433 typeStr += " (" + cardDetail.join(", ") + ")";
1434 }
1435 }
1436 return typeStr;
1437 }
1438
1439 function setQrEvents(els) {
1440 els.on("mouseenter", createQr);
1441 els.on("mouseleave", destroyQr);
1442 els.on("click", toggleQr);
1443 }
1444
1445 function createQr(e) {
1446 var content = e.target.textContent || e.target.value;
1447 if (content) {
1448 var qrEl = kjua({
1449 text: content,
1450 render: "canvas",
1451 size: 310,
1452 ecLevel: 'H',
1453 });
1454 DOM.qrImage.append(qrEl);
1455 if (!showQr) {
1456 DOM.qrHider.addClass("hidden");
1457 }
1458 else {
1459 DOM.qrHider.removeClass("hidden");
1460 }
1461 DOM.qrContainer.removeClass("hidden");
1462 }
1463 }
1464
1465 function destroyQr() {
1466 DOM.qrImage.text("");
1467 DOM.qrContainer.addClass("hidden");
1468 }
1469
1470 function toggleQr() {
1471 showQr = !showQr;
1472 DOM.qrHider.toggleClass("hidden");
1473 DOM.qrHint.toggleClass("hidden");
1474 }
1475
1476 function bip44TabSelected() {
1477 return DOM.bip44tab.hasClass("active");
1478 }
1479
1480 function bip32TabSelected() {
1481 return DOM.bip32tab.hasClass("active");
1482 }
1483
1484 function networkHasSegwit() {
1485 var n = network;
1486 if ("baseNetwork" in network) {
1487 n = bitcoinjs.bitcoin.networks[network.baseNetwork];
1488 }
1489 // check if only p2wpkh params are required
1490 if (p2wpkhSelected()) {
1491 return "p2wpkh" in n;
1492 }
1493 // check if only p2wpkh-in-p2sh params are required
1494 else if (p2wpkhInP2shSelected()) {
1495 return "p2wpkhInP2sh" in n;
1496 }
1497 // require both if it's unclear which params are required
1498 return "p2wpkh" in n && "p2wpkhInP2sh" in n;
1499 }
1500
1501 function bip49TabSelected() {
1502 return DOM.bip49tab.hasClass("active");
1503 }
1504
1505 function bip84TabSelected() {
1506 return DOM.bip84tab.hasClass("active");
1507 }
1508
1509 function bip141TabSelected() {
1510 return DOM.bip141tab.hasClass("active");
1511 }
1512
1513 function setHdCoin(coinValue) {
1514 DOM.bip44coin.val(coinValue);
1515 DOM.bip49coin.val(coinValue);
1516 DOM.bip84coin.val(coinValue);
1517 }
1518
1519 function showSegwitAvailable() {
1520 DOM.bip49unavailable.addClass("hidden");
1521 DOM.bip49available.removeClass("hidden");
1522 DOM.bip84unavailable.addClass("hidden");
1523 DOM.bip84available.removeClass("hidden");
1524 DOM.bip141unavailable.addClass("hidden");
1525 DOM.bip141available.removeClass("hidden");
1526 }
1527
1528 function showSegwitUnavailable() {
1529 DOM.bip49available.addClass("hidden");
1530 DOM.bip49unavailable.removeClass("hidden");
1531 DOM.bip84available.addClass("hidden");
1532 DOM.bip84unavailable.removeClass("hidden");
1533 DOM.bip141available.addClass("hidden");
1534 DOM.bip141unavailable.removeClass("hidden");
1535 }
1536
1537 function adjustNetworkForSegwit() {
1538 // If segwit is selected the xpub/xprv prefixes need to be adjusted
1539 // to avoid accidentally importing BIP49 xpub to BIP44 watch only
1540 // wallet.
1541 // See https://github.com/iancoleman/bip39/issues/125
1542 var segwitNetworks = null;
1543 // if a segwit network is alread selected, need to use base network to
1544 // look up new parameters
1545 if ("baseNetwork" in network) {
1546 network = bitcoinjs.bitcoin.networks[network.baseNetwork];
1547 }
1548 // choose the right segwit params
1549 if (p2wpkhSelected() && "p2wpkh" in network) {
1550 network = network.p2wpkh;
1551 }
1552 else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network) {
1553 network = network.p2wpkhInP2sh;
1554 }
1555 }
1556
1557 function lastIndexInTable() {
1558 var pathText = DOM.addresses.find(".index").last().text();
1559 var pathBits = pathText.split("/");
1560 var lastBit = pathBits[pathBits.length-1];
1561 var lastBitClean = lastBit.replace("'", "");
1562 return parseInt(lastBitClean);
1563 }
1564
1565 function uint8ArrayToHex(a) {
1566 var s = ""
1567 for (var i=0; i<a.length; i++) {
1568 var h = a[i].toString(16);
1569 while (h.length < 2) {
1570 h = "0" + h;
1571 }
1572 s = s + h;
1573 }
1574 return s;
1575 }
1576
1577 function showWordIndexes() {
1578 var phrase = DOM.phrase.val();
1579 var words = phraseToWordArray(phrase);
1580 var wordIndexes = [];
1581 var language = getLanguage();
1582 for (var i=0; i<words.length; i++) {
1583 var word = words[i];
1584 var wordIndex = WORDLISTS[language].indexOf(word);
1585 wordIndexes.push(wordIndex);
1586 }
1587 var wordIndexesStr = wordIndexes.join(", ");
1588 DOM.entropyWordIndexes.text(wordIndexesStr);
1589 }
1590
1591 function showChecksum() {
1592 var phrase = DOM.phrase.val();
1593 var words = phraseToWordArray(phrase);
1594 var checksumBitlength = words.length / 3;
1595 var checksum = "";
1596 var binaryStr = "";
1597 var language = getLanguage();
1598 for (var i=words.length-1; i>=0; i--) {
1599 var word = words[i];
1600 var wordIndex = WORDLISTS[language].indexOf(word);
1601 var wordBinary = wordIndex.toString(2);
1602 while (wordBinary.length < 11) {
1603 wordBinary = "0" + wordBinary;
1604 }
1605 var binaryStr = wordBinary + binaryStr;
1606 if (binaryStr.length >= checksumBitlength) {
1607 var start = binaryStr.length - checksumBitlength;
1608 var end = binaryStr.length;
1609 checksum = binaryStr.substring(start, end);
1610 // add spaces so the last group is 11 bits, not the first
1611 checksum = checksum.split("").reverse().join("")
1612 checksum = addSpacesEveryElevenBits(checksum);
1613 checksum = checksum.split("").reverse().join("")
1614 break;
1615 }
1616 }
1617 DOM.entropyChecksum.text(checksum);
1618 }
1619
1620 function updateCsv() {
1621 var tableCsv = "path,address,public key,private key\n";
1622 var rows = DOM.addresses.find("tr");
1623 for (var i=0; i<rows.length; i++) {
1624 var row = $(rows[i]);
1625 var cells = row.find("td");
1626 for (var j=0; j<cells.length; j++) {
1627 var cell = $(cells[j]);
1628 if (!cell.children().hasClass("invisible")) {
1629 tableCsv = tableCsv + cell.text();
1630 }
1631 if (j != cells.length - 1) {
1632 tableCsv = tableCsv + ",";
1633 }
1634 }
1635 tableCsv = tableCsv + "\n";
1636 }
1637 DOM.csv.val(tableCsv);
1638 }
1639
1640 function addSpacesEveryElevenBits(binaryStr) {
1641 return binaryStr.match(/.{1,11}/g).join(" ");
1642 }
1643
1644 var networks = [
1645 {
1646 name: "AC - Asiacoin",
1647 onSelect: function() {
1648 network = bitcoinjs.bitcoin.networks.asiacoin;
1649 setHdCoin(51);
1650 },
1651 },
1652 {
1653 name: "ACC - Adcoin",
1654 onSelect: function() {
1655 network = bitcoinjs.bitcoin.networks.adcoin;
1656 setHdCoin(161);
1657 },
1658 },
1659 {
1660 name: "AUR - Auroracoin",
1661 onSelect: function() {
1662 network = bitcoinjs.bitcoin.networks.auroracoin;
1663 setHdCoin(85);
1664 },
1665 },
1666 {
1667 name: "AXE - Axe",
1668 onSelect: function() {
1669 network = bitcoinjs.bitcoin.networks.axe;
1670 setHdCoin(4242);
1671 },
1672 },
1673 {
1674 name: "ANON - ANON",
1675 onSelect: function() {
1676 network = bitcoinjs.bitcoin.networks.anon;
1677 setHdCoin(220);
1678 },
1679 },
1680 {
1681 name: "BCA - Bitcoin Atom",
1682 onSelect: function() {
1683 network = bitcoinjs.bitcoin.networks.atom;
1684 setHdCoin(185);
1685 },
1686 },
1687 {
1688 name: "BCH - Bitcoin Cash",
1689 onSelect: function() {
1690 DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
1691 setHdCoin(145);
1692 },
1693 },
1694 {
1695 name: "BEET - Beetlecoin",
1696 onSelect: function() {
1697 network = bitcoinjs.bitcoin.networks.beetlecoin;
1698 setHdCoin(800);
1699 },
1700 },
1701 {
1702 name: "BELA - Belacoin",
1703 onSelect: function() {
1704 network = bitcoinjs.bitcoin.networks.belacoin;
1705 setHdCoin(73);
1706 },
1707 },
1708 {
1709 name: "BLK - BlackCoin",
1710 onSelect: function() {
1711 network = bitcoinjs.bitcoin.networks.blackcoin;
1712 setHdCoin(10);
1713 },
1714 },
1715 {
1716 name: "BND - Blocknode",
1717 onSelect: function() {
1718 network = bitcoinjs.bitcoin.networks.blocknode;
1719 setHdCoin(2941);
1720 },
1721 },
1722 {
1723 name: "tBND - Blocknode Testnet",
1724 onSelect: function() {
1725 network = bitcoinjs.bitcoin.networks.blocknode_testnet;
1726 setHdCoin(1);
1727 },
1728 },
1729 {
1730 name: "BRIT - Britcoin",
1731 onSelect: function() {
1732 network = bitcoinjs.bitcoin.networks.britcoin;
1733 setHdCoin(70);
1734 },
1735 },
1736 {
1737 name: "BSD - Bitsend",
1738 onSelect: function() {
1739 network = bitcoinjs.bitcoin.networks.bitsend;
1740 setHdCoin(91);
1741 },
1742 },
1743 {
1744 name: "BST - BlockStamp",
1745 onSelect: function() {
1746 network = bitcoinjs.bitcoin.networks.blockstamp;
1747 setHdCoin(254);
1748 },
1749 },
1750 {
1751 name: "BTA - Bata",
1752 onSelect: function() {
1753 network = bitcoinjs.bitcoin.networks.bata;
1754 setHdCoin(89);
1755 },
1756 },
1757 {
1758 name: "BTC - Bitcoin",
1759 onSelect: function() {
1760 network = bitcoinjs.bitcoin.networks.bitcoin;
1761 setHdCoin(0);
1762 },
1763 },
1764 {
1765 name: "BTC - Bitcoin Testnet",
1766 onSelect: function() {
1767 network = bitcoinjs.bitcoin.networks.testnet;
1768 setHdCoin(1);
1769 },
1770 },
1771 {
1772 name: "BITG - Bitcoin Green",
1773 onSelect: function() {
1774 network = bitcoinjs.bitcoin.networks.bitcoingreen;
1775 setHdCoin(222);
1776 },
1777 },
1778 {
1779 name: "BTCP - Bitcoin Private",
1780 onSelect: function() {
1781 network = bitcoinjs.bitcoin.networks.bitcoinprivate;
1782 setHdCoin(183);
1783 },
1784 },
1785 {
1786 name: "BTCZ - Bitcoinz",
1787 onSelect: function() {
1788 network = bitcoinjs.bitcoin.networks.bitcoinz;
1789 setHdCoin(177);
1790 },
1791 },
1792 {
1793 name: "BTDX - BitCloud",
1794 onSelect: function() {
1795 network = bitcoinjs.bitcoin.networks.bitcloud;
1796 setHdCoin(218);
1797 },
1798 },
1799 {
1800 name: "BTG - Bitcoin Gold",
1801 onSelect: function() {
1802 network = bitcoinjs.bitcoin.networks.bgold;
1803 setHdCoin(156);
1804 },
1805 },
1806 {
1807 name: "BTX - Bitcore",
1808 onSelect: function() {
1809 network = bitcoinjs.bitcoin.networks.bitcore;
1810 setHdCoin(160);
1811 },
1812 },
1813 {
1814 name: "CCN - Cannacoin",
1815 onSelect: function() {
1816 network = bitcoinjs.bitcoin.networks.cannacoin;
1817 setHdCoin(19);
1818 },
1819 },
1820 {
1821 name: "CESC - Cryptoescudo",
1822 onSelect: function() {
1823 network = bitcoinjs.bitcoin.networks.cannacoin;
1824 setHdCoin(111);
1825 },
1826 },
1827 {
1828 name: "CDN - Canadaecoin",
1829 onSelect: function() {
1830 network = bitcoinjs.bitcoin.networks.canadaecoin;
1831 setHdCoin(34);
1832 },
1833 },
1834 {
1835 name: "CLAM - Clams",
1836 onSelect: function() {
1837 network = bitcoinjs.bitcoin.networks.clam;
1838 setHdCoin(23);
1839 },
1840 },
1841 {
1842 name: "CLO - Callisto",
1843 segwitAvailable: false,
1844 onSelect: function() {
1845 network = bitcoinjs.bitcoin.networks.bitcoin;
1846 setHdCoin(820);
1847 },
1848 },
1849 {
1850 name: "CLUB - Clubcoin",
1851 onSelect: function() {
1852 network = bitcoinjs.bitcoin.networks.clubcoin;
1853 setHdCoin(79);
1854 },
1855 },
1856 {
1857 name: "CMP - Compcoin",
1858 onSelect: function() {
1859 network = bitcoinjs.bitcoin.networks.compcoin;
1860 setHdCoin(71);
1861 },
1862 },
1863 {
1864 name: "CRAVE - Crave",
1865 onSelect: function() {
1866 network = bitcoinjs.bitcoin.networks.crave;
1867 setHdCoin(186);
1868 },
1869 },
1870 {
1871 name: "CRW - Crown",
1872 onSelect: function() {
1873 network = bitcoinjs.bitcoin.networks.crown;
1874 setHdCoin(72);
1875 },
1876 },
1877 {
1878 name: "DASH - Dash",
1879 onSelect: function() {
1880 network = bitcoinjs.bitcoin.networks.dash;
1881 setHdCoin(5);
1882 },
1883 },
1884 {
1885 name: "DASH - Dash Testnet",
1886 onSelect: function() {
1887 network = bitcoinjs.bitcoin.networks.dashtn;
1888 setHdCoin(1);
1889 },
1890 },
1891 {
1892 name: "DFC - Defcoin",
1893 onSelect: function() {
1894 network = bitcoinjs.bitcoin.networks.defcoin;
1895 setHdCoin(1337);
1896 },
1897 },
1898 {
1899 name: "DGB - Digibyte",
1900 onSelect: function() {
1901 network = bitcoinjs.bitcoin.networks.digibyte;
1902 setHdCoin(20);
1903 },
1904 },
1905 {
1906 name: "DGC - Digitalcoin",
1907 onSelect: function() {
1908 network = bitcoinjs.bitcoin.networks.digitalcoin;
1909 setHdCoin(18);
1910 },
1911 },
1912 {
1913 name: "DMD - Diamond",
1914 onSelect: function() {
1915 network = bitcoinjs.bitcoin.networks.diamond;
1916 setHdCoin(152);
1917 },
1918 },
1919 {
1920 name: "DNR - Denarius",
1921 onSelect: function() {
1922 network = bitcoinjs.bitcoin.networks.denarius;
1923 setHdCoin(116);
1924 },
1925 },
1926 {
1927 name: "DOGE - Dogecoin",
1928 onSelect: function() {
1929 network = bitcoinjs.bitcoin.networks.dogecoin;
1930 setHdCoin(3);
1931 },
1932 },
1933 {
1934 name: "DXN - DEXON",
1935 onSelect: function() {
1936 network = bitcoinjs.bitcoin.networks.bitcoin;
1937 setHdCoin(237);
1938 },
1939 },
1940 {
1941 name: "ECN - Ecoin",
1942 onSelect: function() {
1943 network = bitcoinjs.bitcoin.networks.ecoin;
1944 setHdCoin(115);
1945 },
1946 },
1947 {
1948 name: "EDRC - Edrcoin",
1949 onSelect: function() {
1950 network = bitcoinjs.bitcoin.networks.edrcoin;
1951 setHdCoin(56);
1952 },
1953 },
1954 {
1955 name: "EFL - Egulden",
1956 onSelect: function() {
1957 network = bitcoinjs.bitcoin.networks.egulden;
1958 setHdCoin(78);
1959 },
1960 },
1961 {
1962 name: "EMC2 - Einsteinium",
1963 onSelect: function() {
1964 network = bitcoinjs.bitcoin.networks.einsteinium;
1965 setHdCoin(41);
1966 },
1967 },
1968 {
1969 name: "ERC - Europecoin",
1970 onSelect: function() {
1971 network = bitcoinjs.bitcoin.networks.europecoin;
1972 setHdCoin(151);
1973 },
1974 },
1975 {
1976 name: "ETC - Ethereum Classic",
1977 segwitAvailable: false,
1978 onSelect: function() {
1979 network = bitcoinjs.bitcoin.networks.bitcoin;
1980 setHdCoin(61);
1981 },
1982 },
1983 {
1984 name: "ETH - Ethereum",
1985 onSelect: function() {
1986 network = bitcoinjs.bitcoin.networks.bitcoin;
1987 setHdCoin(60);
1988 },
1989 },
1990 {
1991 name: "EXCL - Exclusivecoin",
1992 onSelect: function() {
1993 network = bitcoinjs.bitcoin.networks.exclusivecoin;
1994 setHdCoin(190);
1995 },
1996 },
1997 {
1998 name: "EXCC - ExchangeCoin",
1999 onSelect: function() {
2000 network = bitcoinjs.bitcoin.networks.exchangecoin;
2001 setHdCoin(0);
2002 },
2003 },
2004 {
2005 name: "EXP - Expanse",
2006 segwitAvailable: false,
2007 onSelect: function() {
2008 network = bitcoinjs.bitcoin.networks.bitcoin;
2009 setHdCoin(40);
2010 },
2011 },
2012 {
2013 name: "FJC - Fujicoin",
2014 onSelect: function() {
2015 network = bitcoinjs.bitcoin.networks.fujicoin;
2016 setHdCoin(75);
2017 },
2018 },
2019 {
2020 name: "FLASH - Flashcoin",
2021 onSelect: function() {
2022 network = bitcoinjs.bitcoin.networks.flashcoin;
2023 setHdCoin(120);
2024 },
2025 },
2026 {
2027 name: "FRST - Firstcoin",
2028 onSelect: function() {
2029 network = bitcoinjs.bitcoin.networks.firstcoin;
2030 setHdCoin(167);
2031 },
2032 },
2033 {
2034 name: "FTC - Feathercoin",
2035 onSelect: function() {
2036 network = bitcoinjs.bitcoin.networks.feathercoin;
2037 setHdCoin(8);
2038 },
2039 },
2040 {
2041 name: "GAME - GameCredits",
2042 onSelect: function() {
2043 network = bitcoinjs.bitcoin.networks.game;
2044 setHdCoin(101);
2045 },
2046 },
2047 {
2048 name: "GBX - Gobyte",
2049 onSelect: function() {
2050 network = bitcoinjs.bitcoin.networks.gobyte;
2051 setHdCoin(176);
2052 },
2053 },
2054 {
2055 name: "GCR - GCRCoin",
2056 onSelect: function() {
2057 network = bitcoinjs.bitcoin.networks.gcr;
2058 setHdCoin(79);
2059 },
2060 },
2061 {
2062 name: "GRC - Gridcoin",
2063 onSelect: function() {
2064 network = bitcoinjs.bitcoin.networks.gridcoin;
2065 setHdCoin(84);
2066 },
2067 },
2068 {
2069 name: "HNC - Helleniccoin",
2070 onSelect: function() {
2071 network = bitcoinjs.bitcoin.networks.helleniccoin;
2072 setHdCoin(168);
2073 },
2074 },
2075 {
2076 name: "HUSH - Hush",
2077 onSelect: function() {
2078 network = bitcoinjs.bitcoin.networks.hush;
2079 setHdCoin(197);
2080 },
2081 },
2082 {
2083 name: "INSN - Insane",
2084 onSelect: function() {
2085 network = bitcoinjs.bitcoin.networks.insane;
2086 setHdCoin(68);
2087 },
2088 },
2089 {
2090 name: "IOP - Iop",
2091 onSelect: function() {
2092 network = bitcoinjs.bitcoin.networks.iop;
2093 setHdCoin(66);
2094 },
2095 },
2096 {
2097 name: "IXC - Ixcoin",
2098 onSelect: function() {
2099 network = bitcoinjs.bitcoin.networks.ixcoin;
2100 setHdCoin(86);
2101 },
2102 },
2103 {
2104 name: "JBS - Jumbucks",
2105 onSelect: function() {
2106 network = bitcoinjs.bitcoin.networks.jumbucks;
2107 setHdCoin(26);
2108 },
2109 },
2110 {
2111 name: "KMD - Komodo",
2112 bip49available: false,
2113 onSelect: function() {
2114 network = bitcoinjs.bitcoin.networks.komodo;
2115 setHdCoin(141);
2116 },
2117 },
2118 {
2119 name: "KOBO - Kobocoin",
2120 bip49available: false,
2121 onSelect: function() {
2122 network = bitcoinjs.bitcoin.networks.kobocoin;
2123 setHdCoin(196);
2124 },
2125 },
2126 {
2127 name: "LBC - Library Credits",
2128 onSelect: function() {
2129 network = bitcoinjs.bitcoin.networks.lbry;
2130 setHdCoin(140);
2131 },
2132 },
2133 {
2134 name: "LCC - Litecoincash",
2135 onSelect: function() {
2136 network = bitcoinjs.bitcoin.networks.litecoincash;
2137 setHdCoin(192);
2138 },
2139 },
2140 {
2141 name: "LDCN - Landcoin",
2142 onSelect: function() {
2143 network = bitcoinjs.bitcoin.networks.landcoin;
2144 setHdCoin(63);
2145 },
2146 },
2147 {
2148 name: "LINX - Linx",
2149 onSelect: function() {
2150 network = bitcoinjs.bitcoin.networks.linx;
2151 setHdCoin(114);
2152 },
2153 },
2154 {
2155 name: "LKR - Lkrcoin",
2156 segwitAvailable: false,
2157 onSelect: function() {
2158 network = bitcoinjs.bitcoin.networks.lkrcoin;
2159 setHdCoin(557);
2160 },
2161 },
2162 {
2163 name: "LTC - Litecoin",
2164 onSelect: function() {
2165 network = bitcoinjs.bitcoin.networks.litecoin;
2166 setHdCoin(2);
2167 DOM.litecoinLtubContainer.removeClass("hidden");
2168 },
2169 },
2170 {
2171 name: "LTZ - LitecoinZ",
2172 onSelect: function() {
2173 network = bitcoinjs.bitcoin.networks.litecoinz;
2174 setHdCoin(221);
2175 },
2176 },
2177 {
2178 name: "LYNX - Lynx",
2179 onSelect: function() {
2180 network = bitcoinjs.bitcoin.networks.lynx;
2181 setHdCoin(191);
2182 },
2183 },
2184 {
2185 name: "MAZA - Maza",
2186 onSelect: function() {
2187 network = bitcoinjs.bitcoin.networks.maza;
2188 setHdCoin(13);
2189 },
2190 },
2191 {
2192 name: "MEC - Megacoin",
2193 onSelect: function() {
2194 network = bitcoinjs.bitcoin.networks.megacoin;
2195 setHdCoin(217);
2196 },
2197 },
2198 {
2199 name: "MIX - MIX",
2200 segwitAvailable: false,
2201 onSelect: function() {
2202 network = bitcoinjs.bitcoin.networks.bitcoin;
2203 setHdCoin(76);
2204 },
2205 },
2206 {
2207 name: "MNX - Minexcoin",
2208 onSelect: function() {
2209 network = bitcoinjs.bitcoin.networks.minexcoin;
2210 setHdCoin(182);
2211 },
2212 },
2213 {
2214 name: "MONA - Monacoin",
2215 onSelect: function() {
2216 network = bitcoinjs.bitcoin.networks.monacoin,
2217 setHdCoin(22);
2218 },
2219 },
2220 {
2221 name: "MUSIC - Musicoin",
2222 segwitAvailable: false,
2223 onSelect: function() {
2224 network = bitcoinjs.bitcoin.networks.bitcoin;
2225 setHdCoin(184);
2226 },
2227 },
2228 {
2229 name: "NAV - Navcoin",
2230 onSelect: function() {
2231 network = bitcoinjs.bitcoin.networks.navcoin;
2232 setHdCoin(130);
2233 },
2234 },
2235 {
2236 name: "NAS - Nebulas",
2237 onSelect: function() {
2238 network = bitcoinjs.bitcoin.networks.bitcoin;
2239 setHdCoin(2718);
2240 },
2241 },
2242 {
2243 name: "NEBL - Neblio",
2244 onSelect: function() {
2245 network = bitcoinjs.bitcoin.networks.neblio;
2246 setHdCoin(146);
2247 },
2248 },
2249 {
2250 name: "NEOS - Neoscoin",
2251 onSelect: function() {
2252 network = bitcoinjs.bitcoin.networks.neoscoin;
2253 setHdCoin(25);
2254 },
2255 },
2256 {
2257 name: "NIX - NIX Platform",
2258 onSelect: function() {
2259 network = bitcoinjs.bitcoin.networks.nix;
2260 setHdCoin(400);
2261 },
2262 },
2263 {
2264 name: "NLG - Gulden",
2265 onSelect: function() {
2266 network = bitcoinjs.bitcoin.networks.gulden;
2267 setHdCoin(87);
2268 },
2269 },
2270 {
2271 name: "NMC - Namecoin",
2272 onSelect: function() {
2273 network = bitcoinjs.bitcoin.networks.namecoin;
2274 setHdCoin(7);
2275 },
2276 },
2277 {
2278 name: "NRG - Energi",
2279 onSelect: function() {
2280 network = bitcoinjs.bitcoin.networks.energi;
2281 setHdCoin(204);
2282 },
2283 },
2284 {
2285 name: "NRO - Neurocoin",
2286 onSelect: function() {
2287 network = bitcoinjs.bitcoin.networks.neurocoin;
2288 setHdCoin(110);
2289 },
2290 },
2291 {
2292 name: "NSR - Nushares",
2293 onSelect: function() {
2294 network = bitcoinjs.bitcoin.networks.nushares;
2295 setHdCoin(11);
2296 },
2297 },
2298 {
2299 name: "NYC - Newyorkc",
2300 onSelect: function() {
2301 network = bitcoinjs.bitcoin.networks.newyorkc;
2302 setHdCoin(179);
2303 },
2304 },
2305 {
2306 name: "NVC - Novacoin",
2307 onSelect: function() {
2308 network = bitcoinjs.bitcoin.networks.novacoin;
2309 setHdCoin(50);
2310 },
2311 },
2312 {
2313 name: "OK - Okcash",
2314 onSelect: function() {
2315 network = bitcoinjs.bitcoin.networks.okcash;
2316 setHdCoin(69);
2317 },
2318 },
2319 {
2320 name: "OMNI - Omnicore",
2321 onSelect: function() {
2322 network = bitcoinjs.bitcoin.networks.omnicore;
2323 setHdCoin(200);
2324 },
2325 },
2326 {
2327 name: "ONX - Onixcoin",
2328 onSelect: function() {
2329 network = bitcoinjs.bitcoin.networks.onixcoin;
2330 setHdCoin(174);
2331 },
2332 },
2333 {
2334 name: "PHR - Phore",
2335 onSelect: function() {
2336 network = bitcoinjs.bitcoin.networks.phore;
2337 setHdCoin(444);
2338 },
2339 },
2340 {
2341 name: "PINK - Pinkcoin",
2342 onSelect: function() {
2343 network = bitcoinjs.bitcoin.networks.pinkcoin;
2344 setHdCoin(117);
2345 },
2346 },
2347 {
2348 name: "PIRL - Pirl",
2349 segwitAvailable: false,
2350 onSelect: function() {
2351 network = bitcoinjs.bitcoin.networks.bitcoin;
2352 setHdCoin(164);
2353 },
2354 },
2355 {
2356 name: "PIVX - PIVX",
2357 onSelect: function() {
2358 network = bitcoinjs.bitcoin.networks.pivx;
2359 setHdCoin(119);
2360 },
2361 },
2362 {
2363 name: "PIVX - PIVX Testnet",
2364 onSelect: function() {
2365 network = bitcoinjs.bitcoin.networks.pivxtestnet;
2366 setHdCoin(1);
2367 },
2368 },
2369 {
2370 name: "POA - Poa",
2371 segwitAvailable: false,
2372 onSelect: function() {
2373 network = bitcoinjs.bitcoin.networks.bitcoin;
2374 setHdCoin(178);
2375 },
2376 },
2377 {
2378 name: "POSW - POSWcoin",
2379 onSelect: function() {
2380 network = bitcoinjs.bitcoin.networks.poswcoin;
2381 setHdCoin(47);
2382 },
2383 },
2384 {
2385 name: "POT - Potcoin",
2386 onSelect: function() {
2387 network = bitcoinjs.bitcoin.networks.potcoin;
2388 setHdCoin(81);
2389 },
2390 },
2391 {
2392 name: "PPC - Peercoin",
2393 onSelect: function() {
2394 network = bitcoinjs.bitcoin.networks.peercoin;
2395 setHdCoin(6);
2396 },
2397 },
2398 {
2399 name: "PRJ - ProjectCoin",
2400 onSelect: function() {
2401 network = bitcoinjs.bitcoin.networks.projectcoin;
2402 setHdCoin(533);
2403 },
2404 },
2405 {
2406 name: "PSB - Pesobit",
2407 onSelect: function() {
2408 network = bitcoinjs.bitcoin.networks.pesobit;
2409 setHdCoin(62);
2410 },
2411 },
2412 {
2413 name: "PUT - Putincoin",
2414 onSelect: function() {
2415 network = bitcoinjs.bitcoin.networks.putincoin;
2416 setHdCoin(122);
2417 },
2418 },
2419 {
2420 name: "RVN - Ravencoin",
2421 onSelect: function() {
2422 network = bitcoinjs.bitcoin.networks.ravencoin;
2423 setHdCoin(175);
2424 },
2425 },
2426 {
2427 name: "RBY - Rubycoin",
2428 onSelect: function() {
2429 network = bitcoinjs.bitcoin.networks.rubycoin;
2430 setHdCoin(16);
2431 },
2432 },
2433 {
2434 name: "RDD - Reddcoin",
2435 onSelect: function() {
2436 network = bitcoinjs.bitcoin.networks.reddcoin;
2437 setHdCoin(4);
2438 },
2439 },
2440 {
2441 name: "RVR - RevolutionVR",
2442 onSelect: function() {
2443 network = bitcoinjs.bitcoin.networks.revolutionvr;
2444 setHdCoin(129);
2445 },
2446 },
2447 {
2448 name: "SAFE - Safecoin",
2449 onSelect: function() {
2450 network = bitcoinjs.bitcoin.networks.safecoin;
2451 setHdCoin(19165);
2452 },
2453 },
2454 {
2455 name: "SLS - Salus",
2456 onSelect: function() {
2457 network = bitcoinjs.bitcoin.networks.salus;
2458 setHdCoin(63);
2459 },
2460 },
2461 {
2462 name: "SDC - ShadowCash",
2463 onSelect: function() {
2464 network = bitcoinjs.bitcoin.networks.shadow;
2465 setHdCoin(35);
2466 },
2467 },
2468 {
2469 name: "SDC - ShadowCash Testnet",
2470 onSelect: function() {
2471 network = bitcoinjs.bitcoin.networks.shadowtn;
2472 setHdCoin(1);
2473 },
2474 },
2475 {
2476 name: "SLM - Slimcoin",
2477 onSelect: function() {
2478 network = bitcoinjs.bitcoin.networks.slimcoin;
2479 setHdCoin(63);
2480 },
2481 },
2482 {
2483 name: "SLM - Slimcoin Testnet",
2484 onSelect: function() {
2485 network = bitcoinjs.bitcoin.networks.slimcointn;
2486 setHdCoin(111);
2487 },
2488 },
2489 {
2490 name: "SLR - Solarcoin",
2491 onSelect: function() {
2492 network = bitcoinjs.bitcoin.networks.solarcoin;
2493 setHdCoin(58);
2494 },
2495 },
2496 {
2497 name: "SMLY - Smileycoin",
2498 onSelect: function() {
2499 network = bitcoinjs.bitcoin.networks.smileycoin;
2500 setHdCoin(59);
2501 },
2502 },
2503 {
2504 name: "STASH - Stash",
2505 onSelect: function() {
2506 network = bitcoinjs.bitcoin.networks.stash;
2507 setHdCoin(0xC0C0);
2508 },
2509 },
2510 {
2511 name: "STASH - Stash Testnet",
2512 onSelect: function() {
2513 network = bitcoinjs.bitcoin.networks.stashtn;
2514 setHdCoin(0xCAFE);
2515 },
2516 },
2517 {
2518 name: "STRAT - Stratis",
2519 onSelect: function() {
2520 network = bitcoinjs.bitcoin.networks.stratis;
2521 setHdCoin(105);
2522 },
2523 },
2524 {
2525 name: "TSTRAT - Stratis Testnet",
2526 onSelect: function() {
2527 network = bitcoinjs.bitcoin.networks.stratistest;
2528 setHdCoin(105);
2529 },
2530 },
2531 {
2532 name: "SYS - Syscoin",
2533 onSelect: function() {
2534 network = bitcoinjs.bitcoin.networks.syscoin;
2535 setHdCoin(57);
2536 },
2537 },
2538 {
2539 name: "THC - Hempcoin",
2540 onSelect: function() {
2541 network = bitcoinjs.bitcoin.networks.hempcoin;
2542 setHdCoin(113);
2543 },
2544 },
2545 {
2546 name: "TOA - Toa",
2547 onSelect: function() {
2548 network = bitcoinjs.bitcoin.networks.toa;
2549 setHdCoin(159);
2550 },
2551 },
2552 {
2553 name: "USC - Ultimatesecurecash",
2554 onSelect: function() {
2555 network = bitcoinjs.bitcoin.networks.ultimatesecurecash;
2556 setHdCoin(112);
2557 },
2558 },
2559 {
2560 name: "USNBT - NuBits",
2561 onSelect: function() {
2562 network = bitcoinjs.bitcoin.networks.nubits;
2563 setHdCoin(12);
2564 },
2565 },
2566 {
2567 name: "UNO - Unobtanium",
2568 onSelect: function() {
2569 network = bitcoinjs.bitcoin.networks.unobtanium;
2570 setHdCoin(92);
2571 },
2572 },
2573 {
2574 name: "VASH - Vpncoin",
2575 onSelect: function() {
2576 network = bitcoinjs.bitcoin.networks.vpncoin;
2577 setHdCoin(33);
2578 },
2579 },
2580 {
2581 name: "VIA - Viacoin",
2582 onSelect: function() {
2583 network = bitcoinjs.bitcoin.networks.viacoin;
2584 setHdCoin(14);
2585 },
2586 },
2587 {
2588 name: "VIA - Viacoin Testnet",
2589 onSelect: function() {
2590 network = bitcoinjs.bitcoin.networks.viacointestnet;
2591 setHdCoin(1);
2592 },
2593 },
2594 {
2595 name: "VIVO - Vivo",
2596 onSelect: function() {
2597 network = bitcoinjs.bitcoin.networks.vivo;
2598 setHdCoin(166);
2599 },
2600 },
2601 {
2602 name: "VTC - Vertcoin",
2603 onSelect: function() {
2604 network = bitcoinjs.bitcoin.networks.vertcoin;
2605 setHdCoin(28);
2606 },
2607 },
2608 {
2609 name: "WC - Wincoin",
2610 onSelect: function() {
2611 network = bitcoinjs.bitcoin.networks.wincoin;
2612 setHdCoin(181);
2613 },
2614 },
2615 {
2616 name: "XAX - Artax",
2617 onSelect: function() {
2618 network = bitcoinjs.bitcoin.networks.artax;
2619 setHdCoin(219);
2620 },
2621 },
2622 {
2623 name: "XBC - Bitcoinplus",
2624 onSelect: function() {
2625 network = bitcoinjs.bitcoin.networks.bitcoinplus;
2626 setHdCoin(65);
2627 },
2628 },
2629 {
2630 name: "XMY - Myriadcoin",
2631 onSelect: function() {
2632 network = bitcoinjs.bitcoin.networks.myriadcoin;
2633 setHdCoin(90);
2634 },
2635 },
2636 {
2637 name: "XRP - Ripple",
2638 onSelect: function() {
2639 network = bitcoinjs.bitcoin.networks.bitcoin;
2640 setHdCoin(144);
2641 },
2642 },
2643 {
2644 name: "XVC - Vcash",
2645 onSelect: function() {
2646 network = bitcoinjs.bitcoin.networks.vcash;
2647 setHdCoin(127);
2648 },
2649 },
2650 {
2651 name: "XVG - Verge",
2652 onSelect: function() {
2653 network = bitcoinjs.bitcoin.networks.verge;
2654 setHdCoin(77);
2655 },
2656 },
2657 {
2658 name: "XUEZ - Xuez",
2659 segwitAvailable: false,
2660 onSelect: function() {
2661 network = bitcoinjs.bitcoin.networks.xuez;
2662 setHdCoin(225);
2663 },
2664 },
2665 {
2666 name: "XWC - Whitecoin",
2667 onSelect: function() {
2668 network = bitcoinjs.bitcoin.networks.whitecoin;
2669 setHdCoin(155);
2670 },
2671 },
2672 {
2673 name: "XZC - Zcoin",
2674 onSelect: function() {
2675 network = bitcoinjs.bitcoin.networks.zcoin;
2676 setHdCoin(136);
2677 },
2678 },
2679 {
2680 name: "ZCL - Zclassic",
2681 onSelect: function() {
2682 network = bitcoinjs.bitcoin.networks.zclassic;
2683 setHdCoin(147);
2684 },
2685 },
2686 {
2687 name: "ZEC - Zcash",
2688 onSelect: function() {
2689 network = bitcoinjs.bitcoin.networks.zcash;
2690 setHdCoin(133);
2691 },
2692 },
2693 {
2694 name: "ZEN - Zencash",
2695 onSelect: function() {
2696 network = bitcoinjs.bitcoin.networks.zencash;
2697 setHdCoin(121);
2698 },
2699 },
2700 ]
2701
2702 var clients = [
2703 {
2704 name: "Bitcoin Core",
2705 onSelect: function() {
2706 DOM.bip32path.val("m/0'/0'");
2707 DOM.hardenedAddresses.prop('checked', true);
2708 },
2709 },
2710 {
2711 name: "blockchain.info",
2712 onSelect: function() {
2713 DOM.bip32path.val("m/44'/0'/0'");
2714 DOM.hardenedAddresses.prop('checked', false);
2715 },
2716 },
2717 {
2718 name: "MultiBit HD",
2719 onSelect: function() {
2720 DOM.bip32path.val("m/0'/0");
2721 DOM.hardenedAddresses.prop('checked', false);
2722 },
2723 },
2724 {
2725 name: "Coinomi, Ledger",
2726 onSelect: function() {
2727 DOM.bip32path.val("m/44'/"+DOM.bip44coin.val()+"'/0'");
2728 DOM.hardenedAddresses.prop('checked', false);
2729 },
2730 }
2731 ]
2732
2733 init();
2734
2735 })();