diff options
author | Ian Coleman <coleman.ian@gmail.com> | 2017-09-01 12:27:38 +1000 |
---|---|---|
committer | Ian Coleman <coleman.ian@gmail.com> | 2017-09-01 12:28:27 +1000 |
commit | 88311463c74f022177a21c5d88f8928dc8007d8b (patch) | |
tree | fd1273a0074f4c12387335af29d58e8fc6e91faf | |
parent | cd7c8327b110ee2fc2010d1e88f5009f859cd981 (diff) | |
download | BIP39-88311463c74f022177a21c5d88f8928dc8007d8b.tar.gz BIP39-88311463c74f022177a21c5d88f8928dc8007d8b.tar.zst BIP39-88311463c74f022177a21c5d88f8928dc8007d8b.zip |
Allow P2WPKH nested in P2SH addresses on BIP32 tab
-rw-r--r-- | src/index.html | 7 | ||||
-rw-r--r-- | src/js/index.js | 11 | ||||
-rw-r--r-- | tests.js | 39 |
3 files changed, 56 insertions, 1 deletions
diff --git a/src/index.html b/src/index.html index e204095..905f9ea 100644 --- a/src/index.html +++ b/src/index.html | |||
@@ -409,6 +409,13 @@ | |||
409 | </label> | 409 | </label> |
410 | </div> | 410 | </div> |
411 | <div class="form-group"> | 411 | <div class="form-group"> |
412 | <div class="col-sm-2"></div> | ||
413 | <label class="col-sm-10"> | ||
414 | <input class="p2wpkh-nested-in-p2sh" type="checkbox"> | ||
415 | <span data-translate>Use SegWit addresses (ie P2WPKH Nested In P2SH)</span> | ||
416 | </label> | ||
417 | </div> | ||
418 | <div class="form-group"> | ||
412 | <label for="core-path" class="col-sm-2 control-label" data-translate>Bitcoin Core</label> | 419 | <label for="core-path" class="col-sm-2 control-label" data-translate>Bitcoin Core</label> |
413 | <div class="col-sm-10"> | 420 | <div class="col-sm-10"> |
414 | <p class="form-control no-border" data-translate-html> | 421 | <p class="form-control no-border" data-translate-html> |
diff --git a/src/js/index.js b/src/js/index.js index 80e6609..9bd77b9 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -73,6 +73,7 @@ | |||
73 | DOM.bip49change = $("#bip49 .change"); | 73 | DOM.bip49change = $("#bip49 .change"); |
74 | DOM.generatedStrength = $(".generate-container .strength"); | 74 | DOM.generatedStrength = $(".generate-container .strength"); |
75 | DOM.hardenedAddresses = $(".hardened-addresses"); | 75 | DOM.hardenedAddresses = $(".hardened-addresses"); |
76 | DOM.useP2wpkhNestedInP2sh = $(".p2wpkh-nested-in-p2sh"); | ||
76 | DOM.addresses = $(".addresses"); | 77 | DOM.addresses = $(".addresses"); |
77 | DOM.rowsToAdd = $(".rows-to-add"); | 78 | DOM.rowsToAdd = $(".rows-to-add"); |
78 | DOM.more = $(".more"); | 79 | DOM.more = $(".more"); |
@@ -109,6 +110,7 @@ | |||
109 | DOM.bip49change.on("input", calcForDerivationPath); | 110 | DOM.bip49change.on("input", calcForDerivationPath); |
110 | DOM.tab.on("shown.bs.tab", calcForDerivationPath); | 111 | DOM.tab.on("shown.bs.tab", calcForDerivationPath); |
111 | DOM.hardenedAddresses.on("change", calcForDerivationPath); | 112 | DOM.hardenedAddresses.on("change", calcForDerivationPath); |
113 | DOM.useP2wpkhNestedInP2sh.on("change", calcForDerivationPath); | ||
112 | DOM.indexToggle.on("click", toggleIndexes); | 114 | DOM.indexToggle.on("click", toggleIndexes); |
113 | DOM.addressToggle.on("click", toggleAddresses); | 115 | DOM.addressToggle.on("click", toggleAddresses); |
114 | DOM.publicKeyToggle.on("click", togglePublicKeys); | 116 | DOM.publicKeyToggle.on("click", togglePublicKeys); |
@@ -637,7 +639,7 @@ | |||
637 | var self = this; | 639 | var self = this; |
638 | this.shouldGenerate = true; | 640 | this.shouldGenerate = true; |
639 | var useHardenedAddresses = DOM.hardenedAddresses.prop("checked"); | 641 | var useHardenedAddresses = DOM.hardenedAddresses.prop("checked"); |
640 | var isP2wpkhNestedInP2sh = bip49TabSelected(); | 642 | var isP2wpkhNestedInP2sh = bip49TabSelected() || (bip32TabSelected() && useP2wpkhNestedInP2sh()); |
641 | var p2wpkhNestedInP2shAvailable = networkHasBip49(); | 643 | var p2wpkhNestedInP2shAvailable = networkHasBip49(); |
642 | 644 | ||
643 | function init() { | 645 | function init() { |
@@ -1164,6 +1166,10 @@ | |||
1164 | return DOM.bip32tab.hasClass("active"); | 1166 | return DOM.bip32tab.hasClass("active"); |
1165 | } | 1167 | } |
1166 | 1168 | ||
1169 | function useP2wpkhNestedInP2sh() { | ||
1170 | return DOM.useP2wpkhNestedInP2sh.prop("checked"); | ||
1171 | } | ||
1172 | |||
1167 | function networkHasBip49() { | 1173 | function networkHasBip49() { |
1168 | return networks[DOM.network.val()].p2wpkhNestedInP2shAvailable; | 1174 | return networks[DOM.network.val()].p2wpkhNestedInP2shAvailable; |
1169 | } | 1175 | } |
@@ -1180,11 +1186,14 @@ | |||
1180 | function showP2wpkhNestedInP2shAvailable() { | 1186 | function showP2wpkhNestedInP2shAvailable() { |
1181 | DOM.bip49unavailable.addClass("hidden"); | 1187 | DOM.bip49unavailable.addClass("hidden"); |
1182 | DOM.bip49available.removeClass("hidden"); | 1188 | DOM.bip49available.removeClass("hidden"); |
1189 | DOM.useP2wpkhNestedInP2sh.prop("disabled", false); | ||
1183 | } | 1190 | } |
1184 | 1191 | ||
1185 | function showP2wpkhNestedInP2shUnavailable() { | 1192 | function showP2wpkhNestedInP2shUnavailable() { |
1186 | DOM.bip49available.addClass("hidden"); | 1193 | DOM.bip49available.addClass("hidden"); |
1187 | DOM.bip49unavailable.removeClass("hidden"); | 1194 | DOM.bip49unavailable.removeClass("hidden"); |
1195 | DOM.useP2wpkhNestedInP2sh.prop("disabled", true); | ||
1196 | DOM.useP2wpkhNestedInP2sh.prop("checked", false); | ||
1188 | } | 1197 | } |
1189 | 1198 | ||
1190 | var networks = [ | 1199 | var networks = [ |
@@ -4267,6 +4267,45 @@ page.open(url, function(status) { | |||
4267 | }); | 4267 | }); |
4268 | }, | 4268 | }, |
4269 | 4269 | ||
4270 | // BIP32 tab can use P2WPKH Nested In P2SH | ||
4271 | // github issue 91 part 2 | ||
4272 | // https://github.com/iancoleman/bip39/issues/91 | ||
4273 | // generate new addresses from xpub? | ||
4274 | function() { | ||
4275 | page.open(url, function(status) { | ||
4276 | // set the xpub and coin and select bip32 tab with p2wpkh addresses | ||
4277 | page.evaluate(function() { | ||
4278 | // use p2wpkh addresses | ||
4279 | $(".p2wpkh-nested-in-p2sh").prop("checked", true); | ||
4280 | // use bip32 tab | ||
4281 | $("#bip32-tab a").click(); | ||
4282 | // use testnet | ||
4283 | $(".network option[selected]").removeAttr("selected"); | ||
4284 | $(".network option").filter(function() { | ||
4285 | return $(this).html() == "BTC - Bitcoin Testnet"; | ||
4286 | }).prop("selected", true); | ||
4287 | $(".network").trigger("change"); | ||
4288 | // Set root xpub to BIP49 official test vector account 0 | ||
4289 | $(".root-key").val("tpubDD7tXK8KeQ3YY83yWq755fHY2JW8Ha8Q765tknUM5rSvjPcGWfUppDFMpQ1ScziKfW3ZNtZvAD7M3u7bSs7HofjTD3KP3YxPK7X6hwV8Rk2"); | ||
4290 | $(".root-key").trigger("input"); | ||
4291 | }); | ||
4292 | // check the address is generated correctly | ||
4293 | waitForGenerate(function() { | ||
4294 | var expected = "2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2"; | ||
4295 | var actual = page.evaluate(function() { | ||
4296 | return $(".address:first").text(); | ||
4297 | }); | ||
4298 | if (actual != expected) { | ||
4299 | console.log("BIP32 tab cannot generate P2WPKH Nested In P2SH addresses"); | ||
4300 | console.log("Expected: " + expected); | ||
4301 | console.log("Actual: " + actual); | ||
4302 | fail(); | ||
4303 | } | ||
4304 | next(); | ||
4305 | }); | ||
4306 | }); | ||
4307 | }, | ||
4308 | |||
4270 | // If you wish to add more tests, do so here... | 4309 | // If you wish to add more tests, do so here... |
4271 | 4310 | ||
4272 | // Here is a blank test template | 4311 | // Here is a blank test template |