diff options
author | Ian Coleman <ian@iancoleman.io> | 2019-12-17 11:44:54 +1100 |
---|---|---|
committer | Ian Coleman <ian@iancoleman.io> | 2019-12-17 11:46:07 +1100 |
commit | f7e9fdf002e7355a122a86a8407b470b56bf3f59 (patch) | |
tree | caaa9e0580d04280b40410b76feb3e0e7a7fcc91 | |
parent | 5c203fab6ac25fc76e2b805b7709d9b06ccdd995 (diff) | |
download | BIP39-f7e9fdf002e7355a122a86a8407b470b56bf3f59.tar.gz BIP39-f7e9fdf002e7355a122a86a8407b470b56bf3f59.tar.zst BIP39-f7e9fdf002e7355a122a86a8407b470b56bf3f59.zip |
Generate addresses for P2WSH and P2WSH-P2SH
-rw-r--r-- | src/index.html | 4 | ||||
-rw-r--r-- | src/js/index.js | 15 | ||||
-rw-r--r-- | tests/spec/tests.js | 20 |
3 files changed, 25 insertions, 14 deletions
diff --git a/src/index.html b/src/index.html index 61fe022..64c25f4 100644 --- a/src/index.html +++ b/src/index.html | |||
@@ -509,8 +509,8 @@ | |||
509 | <select class="form-control bip141-semantics"> | 509 | <select class="form-control bip141-semantics"> |
510 | <option value="p2wpkh">P2WPKH</option> | 510 | <option value="p2wpkh">P2WPKH</option> |
511 | <option value="p2wpkh-p2sh" selected>P2WPKH nested in P2SH</option> | 511 | <option value="p2wpkh-p2sh" selected>P2WPKH nested in P2SH</option> |
512 | <option value="p2wsh">P2WSH</option> | 512 | <option value="p2wsh">P2WSH (1-of-1 multisig)</option> |
513 | <option value="p2wsh-p2sh">P2WSH nested in P2SH</option> | 513 | <option value="p2wsh-p2sh">P2WSH nested in P2SH (1-of-1 multisig)</option> |
514 | </select> | 514 | </select> |
515 | </div> | 515 | </div> |
516 | </div> | 516 | </div> |
diff --git a/src/js/index.js b/src/js/index.js index db47412..5fb0c47 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -1152,12 +1152,19 @@ | |||
1152 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) | 1152 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) |
1153 | } | 1153 | } |
1154 | else if (isP2wsh) { | 1154 | else if (isP2wsh) { |
1155 | // TODO | 1155 | // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71 |
1156 | address = ""; | 1156 | // This is a 1-of-1 |
1157 | var witnessScript = bitcoinjs.bitcoin.script.multisig.output.encode(1, [key.getPublicKeyBuffer()]); | ||
1158 | var scriptPubKey = bitcoinjs.bitcoin.script.witnessScriptHash.output.encode(bitcoinjs.bitcoin.crypto.sha256(witnessScript)); | ||
1159 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptPubKey, network); | ||
1157 | } | 1160 | } |
1158 | else if (isP2wshInP2sh) { | 1161 | else if (isP2wshInP2sh) { |
1159 | // TODO | 1162 | // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183 |
1160 | address = ""; | 1163 | // This is a 1-of-1 |
1164 | var witnessScript = bitcoinjs.bitcoin.script.multisig.output.encode(1, [key.getPublicKeyBuffer()]); | ||
1165 | var redeemScript = bitcoinjs.bitcoin.script.witnessScriptHash.output.encode(bitcoinjs.bitcoin.crypto.sha256(witnessScript)); | ||
1166 | var scriptPubKey = bitcoinjs.bitcoin.script.scriptHash.output.encode(bitcoinjs.bitcoin.crypto.hash160(redeemScript)); | ||
1167 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptPubKey, network) | ||
1161 | } | 1168 | } |
1162 | } | 1169 | } |
1163 | 1170 | ||
diff --git a/tests/spec/tests.js b/tests/spec/tests.js index fc71353..bbc1f57 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js | |||
@@ -3701,7 +3701,7 @@ it('Can generate BIP141 addresses with P2WSH semanitcs', function(done) { | |||
3701 | driver.executeScript(function() { | 3701 | driver.executeScript(function() { |
3702 | $(".bip141-semantics option[selected]").removeAttr("selected"); | 3702 | $(".bip141-semantics option[selected]").removeAttr("selected"); |
3703 | $(".bip141-semantics option").filter(function(i,e) { | 3703 | $(".bip141-semantics option").filter(function(i,e) { |
3704 | return $(e).html() == "P2WSH"; | 3704 | return $(e).html() == "P2WSH (1-of-1 multisig)"; |
3705 | }).prop("selected", true); | 3705 | }).prop("selected", true); |
3706 | $(".bip141-semantics").trigger("change"); | 3706 | $(".bip141-semantics").trigger("change"); |
3707 | }); | 3707 | }); |
@@ -3712,8 +3712,10 @@ it('Can generate BIP141 addresses with P2WSH semanitcs', function(done) { | |||
3712 | .getAttribute("value") | 3712 | .getAttribute("value") |
3713 | .then(function(rootKey) { | 3713 | .then(function(rootKey) { |
3714 | expect(rootKey).toBe("ZprvAhadJRUYsNge9uHspaggavxU1BUQ8QwfT4Z9UGq5sKF2mSt1mVy8EckLAaoBdmLHyP5eYDJ3LxtmzMNnLg2MRFe7QN2ueF4NCH4s5PrCDR6"); | 3714 | expect(rootKey).toBe("ZprvAhadJRUYsNge9uHspaggavxU1BUQ8QwfT4Z9UGq5sKF2mSt1mVy8EckLAaoBdmLHyP5eYDJ3LxtmzMNnLg2MRFe7QN2ueF4NCH4s5PrCDR6"); |
3715 | // TODO check first address | 3715 | getFirstAddress(function(address) { |
3716 | done(); | 3716 | expect(address).toBe("bc1q2qhee847pv438tgg8hc7mjy38n8dklleshettn344l0tgs0kj5hskz9p9r"); |
3717 | done(); | ||
3718 | }); | ||
3717 | }) | 3719 | }) |
3718 | }); | 3720 | }); |
3719 | }); | 3721 | }); |
@@ -3725,7 +3727,7 @@ it('Can generate BIP141 addresses with P2WSH-in-P2SH semanitcs', function(done) | |||
3725 | driver.executeScript(function() { | 3727 | driver.executeScript(function() { |
3726 | $(".bip141-semantics option[selected]").removeAttr("selected"); | 3728 | $(".bip141-semantics option[selected]").removeAttr("selected"); |
3727 | $(".bip141-semantics option").filter(function(i,e) { | 3729 | $(".bip141-semantics option").filter(function(i,e) { |
3728 | return $(e).html() == "P2WSH nested in P2SH"; | 3730 | return $(e).html() == "P2WSH nested in P2SH (1-of-1 multisig)"; |
3729 | }).prop("selected", true); | 3731 | }).prop("selected", true); |
3730 | $(".bip141-semantics").trigger("change"); | 3732 | $(".bip141-semantics").trigger("change"); |
3731 | }); | 3733 | }); |
@@ -3736,8 +3738,10 @@ it('Can generate BIP141 addresses with P2WSH-in-P2SH semanitcs', function(done) | |||
3736 | .getAttribute("value") | 3738 | .getAttribute("value") |
3737 | .then(function(rootKey) { | 3739 | .then(function(rootKey) { |
3738 | expect(rootKey).toBe("YprvANkMzkodih9AJc6kzDu4NqrxqDKxBnxAXx2vgswCVJs9iM4nWqoZcZ6C9NqbdrgNZjxqnjhUtJYE74mDcycLd1xWY2LV4LEsvZ1DgqxuAKe"); | 3740 | expect(rootKey).toBe("YprvANkMzkodih9AJc6kzDu4NqrxqDKxBnxAXx2vgswCVJs9iM4nWqoZcZ6C9NqbdrgNZjxqnjhUtJYE74mDcycLd1xWY2LV4LEsvZ1DgqxuAKe"); |
3739 | // TODO check first address | 3741 | getFirstAddress(function(address) { |
3740 | done(); | 3742 | expect(address).toBe("343DLC4vGDyHBbBr9myL8zzZA1MdN9TM1G"); |
3743 | done(); | ||
3744 | }); | ||
3741 | }) | 3745 | }) |
3742 | }); | 3746 | }); |
3743 | }); | 3747 | }); |
@@ -3750,7 +3754,7 @@ it('Uses Vprv for bitcoin testnet p2wsh', function(done) { | |||
3750 | driver.executeScript(function() { | 3754 | driver.executeScript(function() { |
3751 | $(".bip141-semantics option[selected]").removeAttr("selected"); | 3755 | $(".bip141-semantics option[selected]").removeAttr("selected"); |
3752 | $(".bip141-semantics option").filter(function(i,e) { | 3756 | $(".bip141-semantics option").filter(function(i,e) { |
3753 | return $(e).html() == "P2WSH"; | 3757 | return $(e).html() == "P2WSH (1-of-1 multisig)"; |
3754 | }).prop("selected", true); | 3758 | }).prop("selected", true); |
3755 | $(".bip141-semantics").trigger("change"); | 3759 | $(".bip141-semantics").trigger("change"); |
3756 | }); | 3760 | }); |
@@ -3774,7 +3778,7 @@ it('Uses Uprv for bitcoin testnet p2wsh-in-p2sh', function(done) { | |||
3774 | driver.executeScript(function() { | 3778 | driver.executeScript(function() { |
3775 | $(".bip141-semantics option[selected]").removeAttr("selected"); | 3779 | $(".bip141-semantics option[selected]").removeAttr("selected"); |
3776 | $(".bip141-semantics option").filter(function(i,e) { | 3780 | $(".bip141-semantics option").filter(function(i,e) { |
3777 | return $(e).html() == "P2WSH nested in P2SH"; | 3781 | return $(e).html() == "P2WSH nested in P2SH (1-of-1 multisig)"; |
3778 | }).prop("selected", true); | 3782 | }).prop("selected", true); |
3779 | $(".bip141-semantics").trigger("change"); | 3783 | $(".bip141-semantics").trigger("change"); |
3780 | }); | 3784 | }); |