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