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