Construct a tree of Taproot spending conditions pubkey: a 32-byte xonly pubkey for the internal pubkey (bytes) scripts: a list of items; each item is either: - a (name, CScript or bytes, leaf version) tuple - a (name, CScript or bytes) tuple (defaulting to leaf ver
(pubkey, scripts=None, treat_internal_as_infinity=False)
| 915 | TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch,leaf_hash") |
| 916 | |
| 917 | def taproot_construct(pubkey, scripts=None, treat_internal_as_infinity=False): |
| 918 | """Construct a tree of Taproot spending conditions |
| 919 | |
| 920 | pubkey: a 32-byte xonly pubkey for the internal pubkey (bytes) |
| 921 | scripts: a list of items; each item is either: |
| 922 | - a (name, CScript or bytes, leaf version) tuple |
| 923 | - a (name, CScript or bytes) tuple (defaulting to leaf version 0xc0) |
| 924 | - another list of items (with the same structure) |
| 925 | - a list of two items; the first of which is an item itself, and the |
| 926 | second is a function. The function takes as input the Merkle root of the |
| 927 | first item, and produces a (fictitious) partner to hash with. |
| 928 | |
| 929 | Returns: a TaprootInfo object |
| 930 | """ |
| 931 | if scripts is None: |
| 932 | scripts = [] |
| 933 | |
| 934 | ret, h = taproot_tree_helper(scripts) |
| 935 | tweak = TaggedHash("TapTweak", pubkey + h) |
| 936 | if treat_internal_as_infinity: |
| 937 | tweaked, negated = compute_xonly_pubkey(tweak) |
| 938 | else: |
| 939 | tweaked, negated = tweak_add_pubkey(pubkey, tweak) |
| 940 | leaves = dict((name, TaprootLeafInfo(script, version, merklebranch, leaf)) for name, version, script, merklebranch, leaf in ret) |
| 941 | return TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked) |
| 942 | |
| 943 | def is_op_success(o): |
| 944 | return o == 0x50 or o == 0x62 or o == 0x89 or o == 0x8a or o == 0x8d or o == 0x8e or (o >= 0x7e and o <= 0x81) or (o >= 0x83 and o <= 0x86) or (o >= 0x95 and o <= 0x99) or (o >= 0xbb and o <= 0xfe) |
no test coverage detected