-
Notifications
You must be signed in to change notification settings - Fork 2
P2mr #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
P2mr #17
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d97a08f
Implement P2MR script and associated address handling
mohanson 1c4323f
Add tests for p2mr address generation with various leaf and branch co…
mohanson 602059a
Add example for P2MR script creation in README
mohanson 31b9dcb
Refactor test_address_p2mr to use consistent variable naming for TapL…
mohanson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import pabtc | ||
|
|
||
| # This example shows how to create a P2MR script with two unlock conditions: p2pk and p2ms. | ||
|
|
||
|
|
||
| # Here created two scripts, one of which is a p2pk script, which requires that it can only be unlocked by private key 2, | ||
| # and the other is an 2-of-2 multisig script. | ||
| mast = pabtc.core.TapBranch( | ||
| pabtc.core.TapLeaf(pabtc.core.TapScript.p2pk(pabtc.core.PriKey(2).pubkey())), | ||
| pabtc.core.TapLeaf(pabtc.core.TapScript.p2ms(2, [pabtc.core.PriKey(3).pubkey(), pabtc.core.PriKey(4).pubkey()])), | ||
| ) | ||
| root = mast.hash | ||
|
|
||
|
|
||
| class Signerp2mrp2pk(pabtc.wallet.Signer): | ||
| def __init__(self) -> None: | ||
| self.script = pabtc.core.ScriptPubKey.p2mr(root) | ||
| # In p2tr, the least significant bit is the parity bit of the output public key's y-coordinate, which can be | ||
| # either 0 or 1. In p2mr, which has no internal key/key path cost, this bit is always 1. | ||
| self.prefix = 0xc0 + 1 | ||
| self.addr = pabtc.core.Address.p2mr(root) | ||
|
|
||
| def sign(self, tx: pabtc.core.Transaction) -> None: | ||
| assert isinstance(mast.l, pabtc.core.TapLeaf) | ||
| for i, e in enumerate(tx.vin): | ||
| m = tx.digest_segwit_v1(i, pabtc.core.sighash_all, mast.l.script) | ||
| e.witness = [ | ||
| pabtc.core.PriKey(2).sign_schnorr(m) + bytearray([pabtc.core.sighash_all]), | ||
| mast.l.script, | ||
| bytearray([self.prefix]) + mast.r.hash, | ||
| ] | ||
|
|
||
|
|
||
| class Signerp2mrp2ms(pabtc.wallet.Signer): | ||
| def __init__(self) -> None: | ||
| self.script = pabtc.core.ScriptPubKey.p2mr(root) | ||
| # In p2tr, the least significant bit is the parity bit of the output public key's y-coordinate, which can be | ||
| # either 0 or 1. In p2mr, which has no internal key/key path cost, this bit is always 1. | ||
| self.prefix = 0xc0 + 1 | ||
| self.addr = pabtc.core.Address.p2mr(root) | ||
|
|
||
|
mohanson marked this conversation as resolved.
|
||
| def sign(self, tx: pabtc.core.Transaction) -> None: | ||
| assert isinstance(mast.r, pabtc.core.TapLeaf) | ||
| for i, e in enumerate(tx.vin): | ||
| m = tx.digest_segwit_v1(i, pabtc.core.sighash_all, mast.r.script) | ||
| e.witness = [ | ||
| pabtc.core.PriKey(4).sign_schnorr(m) + bytearray([pabtc.core.sighash_all]), | ||
| pabtc.core.PriKey(3).sign_schnorr(m) + bytearray([pabtc.core.sighash_all]), | ||
| mast.r.script, | ||
| bytearray([self.prefix]) + mast.l.hash, | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.