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.addressToggle = $(".address-toggle");
DOM.privateKeyToggle = $(".private-key-toggle");
- 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 n = e.target.value;
+ if (n == "bitcoin") {
+ network = Bitcoin.networks.bitcoin;
+ DOM.bip44coin.val(0);
+ }
+ else if (n == "bitcoin-testnet") {
+ network = Bitcoin.networks.testnet;
+ DOM.bip44coin.val(1);
+ }
+ else if (n == "litecoin") {
+ network = Bitcoin.networks.litecoin;
+ DOM.bip44coin.val(2);
+ }
+ else if (n == "dogecoin") {
+ network = Bitcoin.networks.dogecoin;
+ var UNOFFICIAL_BIP44_COIN = 9999;
+ DOM.bip44coin.val(UNOFFICIAL_BIP44_COIN); // This coin is not in BIP44
+ }
+ 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 calcBip32Seed(phrase, passphrase, path) {
var seed = mnemonic.toSeed(phrase, passphrase);
- var seedHash = Bitcoin.crypto.sha256(seed).toString("hex");
- bip32RootKey = Bitcoin.HDNode.fromSeedHex(seedHash, network);
+ bip32RootKey = Bitcoin.HDNode.fromSeedHex(seed, network);
bip32ExtendedKey = bip32RootKey;
// Derive the key from the path
var pathBits = path.split("/");
function findPhraseErrors(phrase) {
// TODO make this right
// Preprocess the words
+ phrase = mnemonic.normalizeString(phrase);
var parts = phrase.split(" ");
var proper = [];
for (var i=0; i<parts.length; i++) {
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();
- 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);
}