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