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");
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);
// Event handlers
+ function networkChanged(e) {
+ var network = e.target.value;
+ if (network in networks) {
+ networks[network].onSelect();
+ }
+ else {
+ // TODO
+ }
+ setBip44DerivationPath();
+ delayedPhraseChanged();
+ }
+
function delayedPhraseChanged() {
hideValidationError();
showPending();
}
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");
}
function displayAddresses(start, total) {
for (var i=0; i<total; i++) {
- var index = i+ start;
- var key = bip32ExtendedKey.derive(index);
- var address = key.getAddress().toString();
- var privkey = key.privKey.toWIF(network);
- addAddressToList(index, address, privkey);
+ var index = i + start;
+ new TableRow(index);
+ }
+ }
+
+ function TableRow(index) {
+
+ function init() {
+ calculateValues();
+ }
+
+ function calculateValues() {
+ setTimeout(function() {
+ var key = bip32ExtendedKey.derive(index);
+ var address = key.getAddress().toString();
+ var privkey = key.privKey.toWIF(network);
+ addAddressToList(index, address, privkey);
+ }, 50)
}
+
+ init();
+
}
function showMore() {
return;
}
}
- showPending();
- setTimeout(function() {
displayAddresses(start, rowsToAdd);
- hidePending();
- }, 50);
}
function clearDisplay() {
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);
}
.hide();
}
+ var networks = {
+ "bitcoin": {
+ name: "Bitcoin",
+ onSelect: function() {
+ network = Bitcoin.networks.bitcoin;
+ DOM.bip44coin.val(0);
+ DOM.myceliumPath.val("m/44'/0'/0'/0");
+ },
+ },
+ "bitcoin-testnet": {
+ name: "Bitcoin Testnet",
+ onSelect: function() {
+ network = Bitcoin.networks.testnet;
+ DOM.bip44coin.val(1);
+ DOM.myceliumPath.val("m/44'/1'/0'/0");
+ },
+ },
+ "litecoin": {
+ name: "Litecoin",
+ onSelect: function() {
+ network = Bitcoin.networks.litecoin;
+ DOM.bip44coin.val(2);
+ },
+ },
+ "dogecoin": {
+ name: "Dogecoin",
+ onSelect: function() {
+ network = Bitcoin.networks.dogecoin;
+ DOM.bip44coin.val(3);
+ },
+ },
+ }
+
init();
})();