diff options
-rw-r--r-- | bip39-standalone.html | 83 | ||||
-rw-r--r-- | src/js/index.js | 83 |
2 files changed, 74 insertions, 92 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html index a3bedf1..9d975eb 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html | |||
@@ -14649,8 +14649,6 @@ var Mnemonic = function(language) { | |||
14649 | DOM.addressToggle = $(".address-toggle"); | 14649 | DOM.addressToggle = $(".address-toggle"); |
14650 | DOM.privateKeyToggle = $(".private-key-toggle"); | 14650 | DOM.privateKeyToggle = $(".private-key-toggle"); |
14651 | 14651 | ||
14652 | var derivationPath = $(".tab-pane.active .path").val(); | ||
14653 | |||
14654 | function init() { | 14652 | function init() { |
14655 | // Events | 14653 | // Events |
14656 | DOM.network.on("change", networkChanged); | 14654 | DOM.network.on("change", networkChanged); |
@@ -14658,12 +14656,12 @@ var Mnemonic = function(language) { | |||
14658 | DOM.passphrase.on("input", delayedPhraseChanged); | 14656 | DOM.passphrase.on("input", delayedPhraseChanged); |
14659 | DOM.generate.on("click", generateClicked); | 14657 | DOM.generate.on("click", generateClicked); |
14660 | DOM.more.on("click", showMore); | 14658 | DOM.more.on("click", showMore); |
14661 | DOM.bip32path.on("input", bip32Changed); | 14659 | DOM.bip32path.on("input", delayedPhraseChanged); |
14662 | DOM.bip44purpose.on("input", bip44Changed); | 14660 | DOM.bip44purpose.on("input", delayedPhraseChanged); |
14663 | DOM.bip44coin.on("input", bip44Changed); | 14661 | DOM.bip44coin.on("input", delayedPhraseChanged); |
14664 | DOM.bip44account.on("input", bip44Changed); | 14662 | DOM.bip44account.on("input", delayedPhraseChanged); |
14665 | DOM.bip44change.on("input", bip44Changed); | 14663 | DOM.bip44change.on("input", delayedPhraseChanged); |
14666 | DOM.tab.on("click", tabClicked); | 14664 | DOM.tab.on("click", delayedPhraseChanged); |
14667 | DOM.indexToggle.on("click", toggleIndexes); | 14665 | DOM.indexToggle.on("click", toggleIndexes); |
14668 | DOM.addressToggle.on("click", toggleAddresses); | 14666 | DOM.addressToggle.on("click", toggleAddresses); |
14669 | DOM.privateKeyToggle.on("click", togglePrivateKeys); | 14667 | DOM.privateKeyToggle.on("click", togglePrivateKeys); |
@@ -14702,7 +14700,8 @@ var Mnemonic = function(language) { | |||
14702 | return; | 14700 | return; |
14703 | } | 14701 | } |
14704 | // Get the derivation path | 14702 | // Get the derivation path |
14705 | var errorText = findDerivationPathErrors(); | 14703 | var derivationPath = getDerivationPath(); |
14704 | var errorText = findDerivationPathErrors(derivationPath); | ||
14706 | if (errorText) { | 14705 | if (errorText) { |
14707 | showValidationError(errorText); | 14706 | showValidationError(errorText); |
14708 | return; | 14707 | return; |
@@ -14725,26 +14724,6 @@ var Mnemonic = function(language) { | |||
14725 | }, 50); | 14724 | }, 50); |
14726 | } | 14725 | } |
14727 | 14726 | ||
14728 | function tabClicked(e) { | ||
14729 | var activePath = $(e.target.getAttribute("href") + " .path"); | ||
14730 | derivationPath = activePath.val(); | ||
14731 | derivationChanged(); | ||
14732 | } | ||
14733 | |||
14734 | function derivationChanged() { | ||
14735 | delayedPhraseChanged(); | ||
14736 | } | ||
14737 | |||
14738 | function bip32Changed() { | ||
14739 | derivationPath = DOM.bip32path.val(); | ||
14740 | derivationChanged(); | ||
14741 | } | ||
14742 | |||
14743 | function bip44Changed() { | ||
14744 | setBip44DerivationPath(); | ||
14745 | derivationChanged(); | ||
14746 | } | ||
14747 | |||
14748 | function toggleIndexes() { | 14727 | function toggleIndexes() { |
14749 | showIndex = !showIndex; | 14728 | showIndex = !showIndex; |
14750 | $("td.index span").toggleClass("invisible"); | 14729 | $("td.index span").toggleClass("invisible"); |
@@ -14832,6 +14811,32 @@ var Mnemonic = function(language) { | |||
14832 | return false; | 14811 | return false; |
14833 | } | 14812 | } |
14834 | 14813 | ||
14814 | function getDerivationPath() { | ||
14815 | if (DOM.bip44tab.hasClass("active")) { | ||
14816 | var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); | ||
14817 | var coin = parseIntNoNaN(DOM.bip44coin.val(), 0); | ||
14818 | var account = parseIntNoNaN(DOM.bip44account.val(), 0); | ||
14819 | var change = parseIntNoNaN(DOM.bip44change.val(), 0); | ||
14820 | var path = "m/"; | ||
14821 | path += purpose + "'/"; | ||
14822 | path += coin + "'/"; | ||
14823 | path += account + "'/"; | ||
14824 | path += change; | ||
14825 | DOM.bip44path.val(path); | ||
14826 | var derivationPath = DOM.bip44path.val(); | ||
14827 | console.log("Using derivation path from BIP44 tab: " + derivationPath); | ||
14828 | return derivationPath; | ||
14829 | } | ||
14830 | else if (DOM.bip32tab.hasClass("active")) { | ||
14831 | var derivationPath = DOM.bip32path.val(); | ||
14832 | console.log("Using derivation path from BIP32 tab: " + derivationPath); | ||
14833 | return derivationPath; | ||
14834 | } | ||
14835 | else { | ||
14836 | console.log("Unknown derivation path"); | ||
14837 | } | ||
14838 | } | ||
14839 | |||
14835 | function findDerivationPathErrors(path) { | 14840 | function findDerivationPathErrors(path) { |
14836 | // TODO | 14841 | // TODO |
14837 | return false; | 14842 | return false; |
@@ -14869,7 +14874,8 @@ var Mnemonic = function(language) { | |||
14869 | var key = bip32ExtendedKey.derive(index); | 14874 | var key = bip32ExtendedKey.derive(index); |
14870 | var address = key.getAddress().toString(); | 14875 | var address = key.getAddress().toString(); |
14871 | var privkey = key.privKey.toWIF(network); | 14876 | var privkey = key.privKey.toWIF(network); |
14872 | addAddressToList(index, address, privkey); | 14877 | var indexText = getDerivationPath() + "/" + index; |
14878 | addAddressToList(indexText, address, privkey); | ||
14873 | }, 50) | 14879 | }, 50) |
14874 | } | 14880 | } |
14875 | 14881 | ||
@@ -14910,14 +14916,13 @@ var Mnemonic = function(language) { | |||
14910 | DOM.extendedPubKey.val(""); | 14916 | DOM.extendedPubKey.val(""); |
14911 | } | 14917 | } |
14912 | 14918 | ||
14913 | function addAddressToList(index, address, privkey) { | 14919 | function addAddressToList(indexText, address, privkey) { |
14914 | var row = $(addressRowTemplate.html()); | 14920 | var row = $(addressRowTemplate.html()); |
14915 | // Elements | 14921 | // Elements |
14916 | var indexCell = row.find(".index span"); | 14922 | var indexCell = row.find(".index span"); |
14917 | var addressCell = row.find(".address span"); | 14923 | var addressCell = row.find(".address span"); |
14918 | var privkeyCell = row.find(".privkey span"); | 14924 | var privkeyCell = row.find(".privkey span"); |
14919 | // Content | 14925 | // Content |
14920 | var indexText = derivationPath + "/" + index; | ||
14921 | indexCell.text(indexText); | 14926 | indexCell.text(indexText); |
14922 | addressCell.text(address); | 14927 | addressCell.text(address); |
14923 | privkeyCell.text(privkey); | 14928 | privkeyCell.text(privkey); |
@@ -14944,20 +14949,6 @@ var Mnemonic = function(language) { | |||
14944 | }); | 14949 | }); |
14945 | } | 14950 | } |
14946 | 14951 | ||
14947 | function setBip44DerivationPath() { | ||
14948 | var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); | ||
14949 | var coin = parseIntNoNaN(DOM.bip44coin.val(), 0); | ||
14950 | var account = parseIntNoNaN(DOM.bip44account.val(), 0); | ||
14951 | var change = parseIntNoNaN(DOM.bip44change.val(), 0); | ||
14952 | var path = "m/"; | ||
14953 | path += purpose + "'/"; | ||
14954 | path += coin + "'/"; | ||
14955 | path += account + "'/"; | ||
14956 | path += change; | ||
14957 | DOM.bip44path.val(path); | ||
14958 | derivationPath = DOM.bip44path.val(); | ||
14959 | } | ||
14960 | |||
14961 | function parseIntNoNaN(val, defaultVal) { | 14952 | function parseIntNoNaN(val, defaultVal) { |
14962 | var v = parseInt(val); | 14953 | var v = parseInt(val); |
14963 | if (isNaN(v)) { | 14954 | if (isNaN(v)) { |
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)) { |