X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=c8ab28467195b71d7fd2e36c6015635e6c341094;hb=e3a9508cc0bcd22cde34036e4d4524e9fa8c731d;hp=f8b67616c530af1ae84c873a7302f6d59781ac20;hpb=a8c454871dafb83d47f65367ef46e64e4e47589f;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index f8b6761..c8ab284 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -3,18 +3,28 @@ var mnemonic = new Mnemonic("english"); var bip32RootKey = null; var bip32ExtendedKey = null; - var network = Bitcoin.networks.bitcoin; + var network = bitcoin.networks.bitcoin; var addressRowTemplate = $("#address-row-template"); + var showIndex = true; + var showAddress = true; + var showPrivKey = true; + var phraseChangeTimeoutEvent = null; var DOM = {}; + DOM.network = $(".network"); + DOM.phraseNetwork = $("#network-phrase"); DOM.phrase = $(".phrase"); DOM.passphrase = $(".passphrase"); DOM.generate = $(".generate"); DOM.rootKey = $(".root-key"); DOM.extendedPrivKey = $(".extended-priv-key"); DOM.extendedPubKey = $(".extended-pub-key"); + DOM.bip32tab = $("#bip32-tab"); + DOM.bip44tab = $("#bip44-tab"); + DOM.bip32panel = $("#bip32"); + DOM.bip44panel = $("#bip44"); DOM.bip32path = $("#bip32-path"); DOM.bip44path = $("#bip44-path"); DOM.bip44purpose = $("#bip44 .purpose"); @@ -30,11 +40,13 @@ DOM.indexToggle = $(".index-toggle"); DOM.addressToggle = $(".address-toggle"); DOM.privateKeyToggle = $(".private-key-toggle"); + DOM.myceliumPath = $("#mycelium-path"); - var derivationPath = DOM.bip44path.val(); + var derivationPath = $(".tab-pane.active .path").val(); function init() { // Events + DOM.network.on("change", networkChanged); DOM.phrase.on("input", delayedPhraseChanged); DOM.passphrase.on("input", delayedPhraseChanged); DOM.generate.on("click", generateClicked); @@ -51,10 +63,18 @@ disableForms(); hidePending(); hideValidationError(); + populateNetworkSelect(); } // Event handlers + function networkChanged(e) { + var network = e.target.value; + networks[network].onSelect(); + setBip44DerivationPath(); + delayedPhraseChanged(); + } + function delayedPhraseChanged() { hideValidationError(); showPending(); @@ -121,14 +141,17 @@ } function toggleIndexes() { + showIndex = !showIndex; $("td.index span").toggleClass("invisible"); } function toggleAddresses() { + showAddress = !showAddress; $("td.address span").toggleClass("invisible"); } function togglePrivateKeys() { + showPrivKey = !showPrivKey; $("td.privkey span").toggleClass("invisible"); } @@ -164,7 +187,7 @@ function calcBip32Seed(phrase, passphrase, path) { var seed = mnemonic.toSeed(phrase, passphrase); - bip32RootKey = Bitcoin.HDNode.fromSeedHex(seed, network); + bip32RootKey = bitcoin.HDNode.fromSeedHex(seed, network); bip32ExtendedKey = bip32RootKey; // Derive the key from the path var pathBits = path.split("/"); @@ -298,9 +321,24 @@ function addAddressToList(index, address, privkey) { var row = $(addressRowTemplate.html()); - row.find(".index span").text(index); - row.find(".address span").text(address); - row.find(".privkey span").text(privkey); + // Elements + var indexCell = row.find(".index span"); + var addressCell = row.find(".address span"); + var privkeyCell = row.find(".privkey span"); + // Content + indexCell.text(index); + addressCell.text(address); + privkeyCell.text(privkey); + // Visibility + if (!showIndex) { + indexCell.addClass("invisible"); + } + if (!showAddress) { + addressCell.addClass("invisible"); + } + if (!showPrivKey) { + privkeCell.addClass("invisible"); + } DOM.addresses.append(row); } @@ -347,6 +385,63 @@ .hide(); } + function populateNetworkSelect() { + for (var i=0; i"); + option.attr("value", i); + option.text(network.name); + DOM.phraseNetwork.append(option); + } + } + + var networks = [ + { + name: "Bitcoin", + onSelect: function() { + network = bitcoin.networks.bitcoin; + DOM.bip44coin.val(0); + DOM.myceliumPath.val("m/44'/0'/0'/0"); + }, + }, + { + name: "Bitcoin Testnet", + onSelect: function() { + network = bitcoin.networks.testnet; + DOM.bip44coin.val(1); + DOM.myceliumPath.val("m/44'/1'/0'/0"); + }, + }, + { + name: "Litecoin", + onSelect: function() { + network = bitcoin.networks.litecoin; + DOM.bip44coin.val(2); + }, + }, + { + name: "Dogecoin", + onSelect: function() { + network = bitcoin.networks.dogecoin; + DOM.bip44coin.val(3); + }, + }, + { + name: "ShadowCash", + onSelect: function() { + network = bitcoin.networks.shadow; + DOM.bip44coin.val(35); + }, + }, + { + name: "ShadowCash Testnet", + onSelect: function() { + network = bitcoin.networks.shadowtn; + DOM.bip44coin.val(1); + }, + }, + ] + init(); })();