mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-26 20:30:41 +00:00
Derivation Path global replaced with function
This commit is contained in:
+37
-46
@@ -14649,8 +14649,6 @@ var Mnemonic = function(language) {
|
|||||||
DOM.addressToggle = $(".address-toggle");
|
DOM.addressToggle = $(".address-toggle");
|
||||||
DOM.privateKeyToggle = $(".private-key-toggle");
|
DOM.privateKeyToggle = $(".private-key-toggle");
|
||||||
|
|
||||||
var derivationPath = $(".tab-pane.active .path").val();
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
// Events
|
// Events
|
||||||
DOM.network.on("change", networkChanged);
|
DOM.network.on("change", networkChanged);
|
||||||
@@ -14658,12 +14656,12 @@ var Mnemonic = function(language) {
|
|||||||
DOM.passphrase.on("input", delayedPhraseChanged);
|
DOM.passphrase.on("input", delayedPhraseChanged);
|
||||||
DOM.generate.on("click", generateClicked);
|
DOM.generate.on("click", generateClicked);
|
||||||
DOM.more.on("click", showMore);
|
DOM.more.on("click", showMore);
|
||||||
DOM.bip32path.on("input", bip32Changed);
|
DOM.bip32path.on("input", delayedPhraseChanged);
|
||||||
DOM.bip44purpose.on("input", bip44Changed);
|
DOM.bip44purpose.on("input", delayedPhraseChanged);
|
||||||
DOM.bip44coin.on("input", bip44Changed);
|
DOM.bip44coin.on("input", delayedPhraseChanged);
|
||||||
DOM.bip44account.on("input", bip44Changed);
|
DOM.bip44account.on("input", delayedPhraseChanged);
|
||||||
DOM.bip44change.on("input", bip44Changed);
|
DOM.bip44change.on("input", delayedPhraseChanged);
|
||||||
DOM.tab.on("click", tabClicked);
|
DOM.tab.on("click", delayedPhraseChanged);
|
||||||
DOM.indexToggle.on("click", toggleIndexes);
|
DOM.indexToggle.on("click", toggleIndexes);
|
||||||
DOM.addressToggle.on("click", toggleAddresses);
|
DOM.addressToggle.on("click", toggleAddresses);
|
||||||
DOM.privateKeyToggle.on("click", togglePrivateKeys);
|
DOM.privateKeyToggle.on("click", togglePrivateKeys);
|
||||||
@@ -14702,7 +14700,8 @@ var Mnemonic = function(language) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Get the derivation path
|
// Get the derivation path
|
||||||
var errorText = findDerivationPathErrors();
|
var derivationPath = getDerivationPath();
|
||||||
|
var errorText = findDerivationPathErrors(derivationPath);
|
||||||
if (errorText) {
|
if (errorText) {
|
||||||
showValidationError(errorText);
|
showValidationError(errorText);
|
||||||
return;
|
return;
|
||||||
@@ -14725,26 +14724,6 @@ var Mnemonic = function(language) {
|
|||||||
}, 50);
|
}, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tabClicked(e) {
|
|
||||||
var activePath = $(e.target.getAttribute("href") + " .path");
|
|
||||||
derivationPath = activePath.val();
|
|
||||||
derivationChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
function derivationChanged() {
|
|
||||||
delayedPhraseChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
function bip32Changed() {
|
|
||||||
derivationPath = DOM.bip32path.val();
|
|
||||||
derivationChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
function bip44Changed() {
|
|
||||||
setBip44DerivationPath();
|
|
||||||
derivationChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleIndexes() {
|
function toggleIndexes() {
|
||||||
showIndex = !showIndex;
|
showIndex = !showIndex;
|
||||||
$("td.index span").toggleClass("invisible");
|
$("td.index span").toggleClass("invisible");
|
||||||
@@ -14832,6 +14811,32 @@ var Mnemonic = function(language) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDerivationPath() {
|
||||||
|
if (DOM.bip44tab.hasClass("active")) {
|
||||||
|
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
||||||
|
var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
|
||||||
|
var account = parseIntNoNaN(DOM.bip44account.val(), 0);
|
||||||
|
var change = parseIntNoNaN(DOM.bip44change.val(), 0);
|
||||||
|
var path = "m/";
|
||||||
|
path += purpose + "'/";
|
||||||
|
path += coin + "'/";
|
||||||
|
path += account + "'/";
|
||||||
|
path += change;
|
||||||
|
DOM.bip44path.val(path);
|
||||||
|
var derivationPath = DOM.bip44path.val();
|
||||||
|
console.log("Using derivation path from BIP44 tab: " + derivationPath);
|
||||||
|
return derivationPath;
|
||||||
|
}
|
||||||
|
else if (DOM.bip32tab.hasClass("active")) {
|
||||||
|
var derivationPath = DOM.bip32path.val();
|
||||||
|
console.log("Using derivation path from BIP32 tab: " + derivationPath);
|
||||||
|
return derivationPath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Unknown derivation path");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function findDerivationPathErrors(path) {
|
function findDerivationPathErrors(path) {
|
||||||
// TODO
|
// TODO
|
||||||
return false;
|
return false;
|
||||||
@@ -14869,7 +14874,8 @@ var Mnemonic = function(language) {
|
|||||||
var key = bip32ExtendedKey.derive(index);
|
var key = bip32ExtendedKey.derive(index);
|
||||||
var address = key.getAddress().toString();
|
var address = key.getAddress().toString();
|
||||||
var privkey = key.privKey.toWIF(network);
|
var privkey = key.privKey.toWIF(network);
|
||||||
addAddressToList(index, address, privkey);
|
var indexText = getDerivationPath() + "/" + index;
|
||||||
|
addAddressToList(indexText, address, privkey);
|
||||||
}, 50)
|
}, 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14910,14 +14916,13 @@ var Mnemonic = function(language) {
|
|||||||
DOM.extendedPubKey.val("");
|
DOM.extendedPubKey.val("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAddressToList(index, address, privkey) {
|
function addAddressToList(indexText, address, privkey) {
|
||||||
var row = $(addressRowTemplate.html());
|
var row = $(addressRowTemplate.html());
|
||||||
// Elements
|
// Elements
|
||||||
var indexCell = row.find(".index span");
|
var indexCell = row.find(".index span");
|
||||||
var addressCell = row.find(".address span");
|
var addressCell = row.find(".address span");
|
||||||
var privkeyCell = row.find(".privkey span");
|
var privkeyCell = row.find(".privkey span");
|
||||||
// Content
|
// Content
|
||||||
var indexText = derivationPath + "/" + index;
|
|
||||||
indexCell.text(indexText);
|
indexCell.text(indexText);
|
||||||
addressCell.text(address);
|
addressCell.text(address);
|
||||||
privkeyCell.text(privkey);
|
privkeyCell.text(privkey);
|
||||||
@@ -14944,20 +14949,6 @@ var Mnemonic = function(language) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBip44DerivationPath() {
|
|
||||||
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
|
||||||
var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
|
|
||||||
var account = parseIntNoNaN(DOM.bip44account.val(), 0);
|
|
||||||
var change = parseIntNoNaN(DOM.bip44change.val(), 0);
|
|
||||||
var path = "m/";
|
|
||||||
path += purpose + "'/";
|
|
||||||
path += coin + "'/";
|
|
||||||
path += account + "'/";
|
|
||||||
path += change;
|
|
||||||
DOM.bip44path.val(path);
|
|
||||||
derivationPath = DOM.bip44path.val();
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseIntNoNaN(val, defaultVal) {
|
function parseIntNoNaN(val, defaultVal) {
|
||||||
var v = parseInt(val);
|
var v = parseInt(val);
|
||||||
if (isNaN(v)) {
|
if (isNaN(v)) {
|
||||||
|
|||||||
+37
-46
@@ -43,8 +43,6 @@
|
|||||||
DOM.addressToggle = $(".address-toggle");
|
DOM.addressToggle = $(".address-toggle");
|
||||||
DOM.privateKeyToggle = $(".private-key-toggle");
|
DOM.privateKeyToggle = $(".private-key-toggle");
|
||||||
|
|
||||||
var derivationPath = $(".tab-pane.active .path").val();
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
// Events
|
// Events
|
||||||
DOM.network.on("change", networkChanged);
|
DOM.network.on("change", networkChanged);
|
||||||
@@ -52,12 +50,12 @@
|
|||||||
DOM.passphrase.on("input", delayedPhraseChanged);
|
DOM.passphrase.on("input", delayedPhraseChanged);
|
||||||
DOM.generate.on("click", generateClicked);
|
DOM.generate.on("click", generateClicked);
|
||||||
DOM.more.on("click", showMore);
|
DOM.more.on("click", showMore);
|
||||||
DOM.bip32path.on("input", bip32Changed);
|
DOM.bip32path.on("input", delayedPhraseChanged);
|
||||||
DOM.bip44purpose.on("input", bip44Changed);
|
DOM.bip44purpose.on("input", delayedPhraseChanged);
|
||||||
DOM.bip44coin.on("input", bip44Changed);
|
DOM.bip44coin.on("input", delayedPhraseChanged);
|
||||||
DOM.bip44account.on("input", bip44Changed);
|
DOM.bip44account.on("input", delayedPhraseChanged);
|
||||||
DOM.bip44change.on("input", bip44Changed);
|
DOM.bip44change.on("input", delayedPhraseChanged);
|
||||||
DOM.tab.on("click", tabClicked);
|
DOM.tab.on("click", delayedPhraseChanged);
|
||||||
DOM.indexToggle.on("click", toggleIndexes);
|
DOM.indexToggle.on("click", toggleIndexes);
|
||||||
DOM.addressToggle.on("click", toggleAddresses);
|
DOM.addressToggle.on("click", toggleAddresses);
|
||||||
DOM.privateKeyToggle.on("click", togglePrivateKeys);
|
DOM.privateKeyToggle.on("click", togglePrivateKeys);
|
||||||
@@ -96,7 +94,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Get the derivation path
|
// Get the derivation path
|
||||||
var errorText = findDerivationPathErrors();
|
var derivationPath = getDerivationPath();
|
||||||
|
var errorText = findDerivationPathErrors(derivationPath);
|
||||||
if (errorText) {
|
if (errorText) {
|
||||||
showValidationError(errorText);
|
showValidationError(errorText);
|
||||||
return;
|
return;
|
||||||
@@ -119,26 +118,6 @@
|
|||||||
}, 50);
|
}, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tabClicked(e) {
|
|
||||||
var activePath = $(e.target.getAttribute("href") + " .path");
|
|
||||||
derivationPath = activePath.val();
|
|
||||||
derivationChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
function derivationChanged() {
|
|
||||||
delayedPhraseChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
function bip32Changed() {
|
|
||||||
derivationPath = DOM.bip32path.val();
|
|
||||||
derivationChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
function bip44Changed() {
|
|
||||||
setBip44DerivationPath();
|
|
||||||
derivationChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleIndexes() {
|
function toggleIndexes() {
|
||||||
showIndex = !showIndex;
|
showIndex = !showIndex;
|
||||||
$("td.index span").toggleClass("invisible");
|
$("td.index span").toggleClass("invisible");
|
||||||
@@ -226,6 +205,32 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDerivationPath() {
|
||||||
|
if (DOM.bip44tab.hasClass("active")) {
|
||||||
|
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
||||||
|
var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
|
||||||
|
var account = parseIntNoNaN(DOM.bip44account.val(), 0);
|
||||||
|
var change = parseIntNoNaN(DOM.bip44change.val(), 0);
|
||||||
|
var path = "m/";
|
||||||
|
path += purpose + "'/";
|
||||||
|
path += coin + "'/";
|
||||||
|
path += account + "'/";
|
||||||
|
path += change;
|
||||||
|
DOM.bip44path.val(path);
|
||||||
|
var derivationPath = DOM.bip44path.val();
|
||||||
|
console.log("Using derivation path from BIP44 tab: " + derivationPath);
|
||||||
|
return derivationPath;
|
||||||
|
}
|
||||||
|
else if (DOM.bip32tab.hasClass("active")) {
|
||||||
|
var derivationPath = DOM.bip32path.val();
|
||||||
|
console.log("Using derivation path from BIP32 tab: " + derivationPath);
|
||||||
|
return derivationPath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Unknown derivation path");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function findDerivationPathErrors(path) {
|
function findDerivationPathErrors(path) {
|
||||||
// TODO
|
// TODO
|
||||||
return false;
|
return false;
|
||||||
@@ -263,7 +268,8 @@
|
|||||||
var key = bip32ExtendedKey.derive(index);
|
var key = bip32ExtendedKey.derive(index);
|
||||||
var address = key.getAddress().toString();
|
var address = key.getAddress().toString();
|
||||||
var privkey = key.privKey.toWIF(network);
|
var privkey = key.privKey.toWIF(network);
|
||||||
addAddressToList(index, address, privkey);
|
var indexText = getDerivationPath() + "/" + index;
|
||||||
|
addAddressToList(indexText, address, privkey);
|
||||||
}, 50)
|
}, 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,14 +310,13 @@
|
|||||||
DOM.extendedPubKey.val("");
|
DOM.extendedPubKey.val("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAddressToList(index, address, privkey) {
|
function addAddressToList(indexText, address, privkey) {
|
||||||
var row = $(addressRowTemplate.html());
|
var row = $(addressRowTemplate.html());
|
||||||
// Elements
|
// Elements
|
||||||
var indexCell = row.find(".index span");
|
var indexCell = row.find(".index span");
|
||||||
var addressCell = row.find(".address span");
|
var addressCell = row.find(".address span");
|
||||||
var privkeyCell = row.find(".privkey span");
|
var privkeyCell = row.find(".privkey span");
|
||||||
// Content
|
// Content
|
||||||
var indexText = derivationPath + "/" + index;
|
|
||||||
indexCell.text(indexText);
|
indexCell.text(indexText);
|
||||||
addressCell.text(address);
|
addressCell.text(address);
|
||||||
privkeyCell.text(privkey);
|
privkeyCell.text(privkey);
|
||||||
@@ -338,20 +343,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBip44DerivationPath() {
|
|
||||||
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
|
|
||||||
var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
|
|
||||||
var account = parseIntNoNaN(DOM.bip44account.val(), 0);
|
|
||||||
var change = parseIntNoNaN(DOM.bip44change.val(), 0);
|
|
||||||
var path = "m/";
|
|
||||||
path += purpose + "'/";
|
|
||||||
path += coin + "'/";
|
|
||||||
path += account + "'/";
|
|
||||||
path += change;
|
|
||||||
DOM.bip44path.val(path);
|
|
||||||
derivationPath = DOM.bip44path.val();
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseIntNoNaN(val, defaultVal) {
|
function parseIntNoNaN(val, defaultVal) {
|
||||||
var v = parseInt(val);
|
var v = parseInt(val);
|
||||||
if (isNaN(v)) {
|
if (isNaN(v)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user