aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-08-15 15:39:09 +1000
committerIan Coleman <coleman.ian@gmail.com>2016-08-15 15:39:09 +1000
commit38523d36dcce2c11baaf8dd742d02b94c41c7b23 (patch)
tree19a1ff3eb1d085421e9b82cecc98d56bfd4c1996 /src/js
parent47a56d9d973fc0847d0beba41a059558a96b6ee6 (diff)
downloadBIP39-38523d36dcce2c11baaf8dd742d02b94c41c7b23.tar.gz
BIP39-38523d36dcce2c11baaf8dd742d02b94c41c7b23.tar.zst
BIP39-38523d36dcce2c11baaf8dd742d02b94c41c7b23.zip
Derivation Path global replaced with function
Diffstat (limited to 'src/js')
-rw-r--r--src/js/index.js83
1 files changed, 37 insertions, 46 deletions
diff --git a/src/js/index.js b/src/js/index.js
index d72e70b..f131e01 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -43,8 +43,6 @@
43 DOM.addressToggle = $(".address-toggle"); 43 DOM.addressToggle = $(".address-toggle");
44 DOM.privateKeyToggle = $(".private-key-toggle"); 44 DOM.privateKeyToggle = $(".private-key-toggle");
45 45
46 var derivationPath = $(".tab-pane.active .path").val();
47
48 function init() { 46 function init() {
49 // Events 47 // Events
50 DOM.network.on("change", networkChanged); 48 DOM.network.on("change", networkChanged);
@@ -52,12 +50,12 @@
52 DOM.passphrase.on("input", delayedPhraseChanged); 50 DOM.passphrase.on("input", delayedPhraseChanged);
53 DOM.generate.on("click", generateClicked); 51 DOM.generate.on("click", generateClicked);
54 DOM.more.on("click", showMore); 52 DOM.more.on("click", showMore);
55 DOM.bip32path.on("input", bip32Changed); 53 DOM.bip32path.on("input", delayedPhraseChanged);
56 DOM.bip44purpose.on("input", bip44Changed); 54 DOM.bip44purpose.on("input", delayedPhraseChanged);
57 DOM.bip44coin.on("input", bip44Changed); 55 DOM.bip44coin.on("input", delayedPhraseChanged);
58 DOM.bip44account.on("input", bip44Changed); 56 DOM.bip44account.on("input", delayedPhraseChanged);
59 DOM.bip44change.on("input", bip44Changed); 57 DOM.bip44change.on("input", delayedPhraseChanged);
60 DOM.tab.on("click", tabClicked); 58 DOM.tab.on("click", delayedPhraseChanged);
61 DOM.indexToggle.on("click", toggleIndexes); 59 DOM.indexToggle.on("click", toggleIndexes);
62 DOM.addressToggle.on("click", toggleAddresses); 60 DOM.addressToggle.on("click", toggleAddresses);
63 DOM.privateKeyToggle.on("click", togglePrivateKeys); 61 DOM.privateKeyToggle.on("click", togglePrivateKeys);
@@ -96,7 +94,8 @@
96 return; 94 return;
97 } 95 }
98 // Get the derivation path 96 // Get the derivation path
99 var errorText = findDerivationPathErrors(); 97 var derivationPath = getDerivationPath();
98 var errorText = findDerivationPathErrors(derivationPath);
100 if (errorText) { 99 if (errorText) {
101 showValidationError(errorText); 100 showValidationError(errorText);
102 return; 101 return;
@@ -119,26 +118,6 @@
119 }, 50); 118 }, 50);
120 } 119 }
121 120
122 function tabClicked(e) {
123 var activePath = $(e.target.getAttribute("href") + " .path");
124 derivationPath = activePath.val();
125 derivationChanged();
126 }
127
128 function derivationChanged() {
129 delayedPhraseChanged();
130 }
131
132 function bip32Changed() {
133 derivationPath = DOM.bip32path.val();
134 derivationChanged();
135 }
136
137 function bip44Changed() {
138 setBip44DerivationPath();
139 derivationChanged();
140 }
141
142 function toggleIndexes() { 121 function toggleIndexes() {
143 showIndex = !showIndex; 122 showIndex = !showIndex;
144 $("td.index span").toggleClass("invisible"); 123 $("td.index span").toggleClass("invisible");
@@ -226,6 +205,32 @@
226 return false; 205 return false;
227 } 206 }
228 207
208 function getDerivationPath() {
209 if (DOM.bip44tab.hasClass("active")) {
210 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
211 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
212 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
213 var change = parseIntNoNaN(DOM.bip44change.val(), 0);
214 var path = "m/";
215 path += purpose + "'/";
216 path += coin + "'/";
217 path += account + "'/";
218 path += change;
219 DOM.bip44path.val(path);
220 var derivationPath = DOM.bip44path.val();
221 console.log("Using derivation path from BIP44 tab: " + derivationPath);
222 return derivationPath;
223 }
224 else if (DOM.bip32tab.hasClass("active")) {
225 var derivationPath = DOM.bip32path.val();
226 console.log("Using derivation path from BIP32 tab: " + derivationPath);
227 return derivationPath;
228 }
229 else {
230 console.log("Unknown derivation path");
231 }
232 }
233
229 function findDerivationPathErrors(path) { 234 function findDerivationPathErrors(path) {
230 // TODO 235 // TODO
231 return false; 236 return false;
@@ -263,7 +268,8 @@
263 var key = bip32ExtendedKey.derive(index); 268 var key = bip32ExtendedKey.derive(index);
264 var address = key.getAddress().toString(); 269 var address = key.getAddress().toString();
265 var privkey = key.privKey.toWIF(network); 270 var privkey = key.privKey.toWIF(network);
266 addAddressToList(index, address, privkey); 271 var indexText = getDerivationPath() + "/" + index;
272 addAddressToList(indexText, address, privkey);
267 }, 50) 273 }, 50)
268 } 274 }
269 275
@@ -304,14 +310,13 @@
304 DOM.extendedPubKey.val(""); 310 DOM.extendedPubKey.val("");
305 } 311 }
306 312
307 function addAddressToList(index, address, privkey) { 313 function addAddressToList(indexText, address, privkey) {
308 var row = $(addressRowTemplate.html()); 314 var row = $(addressRowTemplate.html());
309 // Elements 315 // Elements
310 var indexCell = row.find(".index span"); 316 var indexCell = row.find(".index span");
311 var addressCell = row.find(".address span"); 317 var addressCell = row.find(".address span");
312 var privkeyCell = row.find(".privkey span"); 318 var privkeyCell = row.find(".privkey span");
313 // Content 319 // Content
314 var indexText = derivationPath + "/" + index;
315 indexCell.text(indexText); 320 indexCell.text(indexText);
316 addressCell.text(address); 321 addressCell.text(address);
317 privkeyCell.text(privkey); 322 privkeyCell.text(privkey);
@@ -338,20 +343,6 @@
338 }); 343 });
339 } 344 }
340 345
341 function setBip44DerivationPath() {
342 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
343 var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
344 var account = parseIntNoNaN(DOM.bip44account.val(), 0);
345 var change = parseIntNoNaN(DOM.bip44change.val(), 0);
346 var path = "m/";
347 path += purpose + "'/";
348 path += coin + "'/";
349 path += account + "'/";
350 path += change;
351 DOM.bip44path.val(path);
352 derivationPath = DOM.bip44path.val();
353 }
354
355 function parseIntNoNaN(val, defaultVal) { 346 function parseIntNoNaN(val, defaultVal) {
356 var v = parseInt(val); 347 var v = parseInt(val);
357 if (isNaN(v)) { 348 if (isNaN(v)) {