X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=b1559ef8fbac65e01d047c70a57c026e4327abba;hb=fe8f2d140d9c9e260ebeab7135aa5197b27df406;hp=a12e4422b2a8711b958fc6bee60238c350e27f7e;hpb=7b742f87d3b17fa73e8fcdfda19bc8d08405f7cc;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index a12e442..b1559ef 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -14,6 +14,7 @@ var showPubKey = true; var showPrivKey = true; var showQr = false; + var litecoinUseLtub = false; var entropyChangeTimeoutEvent = null; var phraseChangeTimeoutEvent = null; @@ -37,12 +38,15 @@ DOM.entropyWordCount = DOM.entropyContainer.find(".word-count"); DOM.entropyBinary = DOM.entropyContainer.find(".binary"); DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length"); + DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); DOM.phrase = $(".phrase"); DOM.passphrase = $(".passphrase"); DOM.generateContainer = $(".generate-container"); DOM.generate = $(".generate"); DOM.seed = $(".seed"); DOM.rootKey = $(".root-key"); + DOM.litecoinLtubContainer = $(".litecoin-ltub-container"); + DOM.litecoinUseLtub = $(".litecoin-use-ltub"); DOM.extendedPrivKey = $(".extended-priv-key"); DOM.extendedPubKey = $(".extended-pub-key"); DOM.bip32tab = $("#bip32-tab"); @@ -70,6 +74,9 @@ DOM.bip49change = $("#bip49 .change"); DOM.generatedStrength = $(".generate-container .strength"); DOM.hardenedAddresses = $(".hardened-addresses"); + DOM.useP2wpkhNestedInP2sh = $(".p2wpkh-nested-in-p2sh"); + DOM.useBitpayAddressesContainer = $(".use-bitpay-addresses-container"); + DOM.useBitpayAddresses = $(".use-bitpay-addresses"); DOM.addresses = $(".addresses"); DOM.rowsToAdd = $(".rows-to-add"); DOM.more = $(".more"); @@ -98,6 +105,7 @@ DOM.generate.on("click", generateClicked); DOM.more.on("click", showMore); DOM.rootKey.on("input", delayedRootKeyChanged); + DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged); DOM.bip32path.on("input", calcForDerivationPath); DOM.bip44account.on("input", calcForDerivationPath); DOM.bip44change.on("input", calcForDerivationPath); @@ -105,11 +113,13 @@ DOM.bip49change.on("input", calcForDerivationPath); DOM.tab.on("shown.bs.tab", calcForDerivationPath); DOM.hardenedAddresses.on("change", calcForDerivationPath); + DOM.useP2wpkhNestedInP2sh.on("change", calcForDerivationPath); DOM.indexToggle.on("click", toggleIndexes); DOM.addressToggle.on("click", toggleAddresses); DOM.publicKeyToggle.on("click", togglePublicKeys); DOM.privateKeyToggle.on("click", togglePrivateKeys); DOM.languages.on("click", languageChanged); + DOM.useBitpayAddresses.on("change", useBitpayAddressesChange); setQrEvents(DOM.showQrEls); disableForms(); hidePending(); @@ -123,14 +133,16 @@ function networkChanged(e) { clearDerivedKeys(); clearAddressesList(); + DOM.litecoinLtubContainer.addClass("hidden"); + DOM.useBitpayAddressesContainer.addClass("hidden"); var networkIndex = e.target.value; var network = networks[networkIndex]; network.onSelect(); - if (network.bip49available) { - showBip49(); + if (network.p2wpkhNestedInP2shAvailable) { + showP2wpkhNestedInP2shAvailable(); } else { - hideBip49(); + showP2wpkhNestedInP2shUnavailable(); } if (seed != null) { phraseChanged(); @@ -175,6 +187,10 @@ function delayedPhraseChanged() { hideValidationError(); + seed = null; + bip32RootKey = null; + bip32ExtendedKey = null; + clearAddressesList(); showPending(); if (phraseChangeTimeoutEvent != null) { clearTimeout(phraseChangeTimeoutEvent); @@ -184,7 +200,6 @@ function phraseChanged() { showPending(); - hideValidationError(); setMnemonicLanguage(); // Get the mnemonic phrase var phrase = DOM.phrase.val(); @@ -197,7 +212,6 @@ var passphrase = DOM.passphrase.val(); calcBip32RootKeyFromSeed(phrase, passphrase); calcForDerivationPath(); - hidePending(); } function delayedEntropyChanged() { @@ -260,7 +274,6 @@ function rootKeyChanged() { showPending(); hideValidationError(); - // Validate the root key TODO var rootKeyBase58 = DOM.rootKey.val(); var errorText = validateRootKey(rootKeyBase58); if (errorText) { @@ -272,11 +285,21 @@ calcForDerivationPath(); } + function litecoinUseLtubChanged() { + litecoinUseLtub = DOM.litecoinUseLtub.prop("checked"); + if (litecoinUseLtub) { + network = bitcoinjs.bitcoin.networks.litecoinLtub; + } + else { + network = bitcoinjs.bitcoin.networks.litecoin; + } + phraseChanged(); + } + function calcForDerivationPath() { - showPending(); clearDerivedKeys(); clearAddressesList(); - hideValidationError(); + showPending(); // Don't show bip49 if it's selected but network doesn't support it if (bip49TabSelected() && !networkHasBip49()) { return; @@ -296,7 +319,6 @@ displayBip49Info(); } displayBip32Info(); - hidePending(); } function generateClicked() { @@ -329,6 +351,11 @@ }, 50); } + function useBitpayAddressesChange() { + setBitcoinCashNetworkValues(); + phraseChanged(); + } + function toggleIndexes() { showIndex = !showIndex; $("td.index span").toggleClass("invisible"); @@ -444,7 +471,7 @@ function validateRootKey(rootKeyBase58) { try { - bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58); + bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network); } catch (e) { return "Invalid root key"; @@ -532,7 +559,9 @@ return "No root key"; } // Check no hardened derivation path when using xpub keys - var hardened = path.indexOf("'") > -1; + var hardenedPath = path.indexOf("'") > -1; + var hardenedAddresses = bip32TabSelected() && DOM.hardenedAddresses.prop("checked"); + var hardened = hardenedPath || hardenedAddresses; var isXpubkey = bip32RootKey.isNeutered(); if (hardened && isXpubkey) { return "Hardened derivation path is invalid with xpub key"; @@ -603,23 +632,25 @@ for (var i=0; i