@@ -805,20 +805,20 @@ def taproot_tree_helper(scripts):
805
805
h = TaggedHash ("TapLeaf" , bytes ([version ]) + ser_string (code ))
806
806
if name is None :
807
807
return ([], h )
808
- return ([(name , version , code , bytes ())], h )
808
+ return ([(name , version , code , bytes (), h )], h )
809
809
elif len (scripts ) == 2 and callable (scripts [1 ]):
810
810
# Two entries, and the right one is a function
811
811
left , left_h = taproot_tree_helper (scripts [0 :1 ])
812
812
right_h = scripts [1 ](left_h )
813
- left = [(name , version , script , control + right_h ) for name , version , script , control in left ]
813
+ left = [(name , version , script , control + right_h , leaf ) for name , version , script , control , leaf in left ]
814
814
right = []
815
815
else :
816
816
# Two or more entries: descend into each side
817
817
split_pos = len (scripts ) // 2
818
818
left , left_h = taproot_tree_helper (scripts [0 :split_pos ])
819
819
right , right_h = taproot_tree_helper (scripts [split_pos :])
820
- left = [(name , version , script , control + right_h ) for name , version , script , control in left ]
821
- right = [(name , version , script , control + left_h ) for name , version , script , control in right ]
820
+ left = [(name , version , script , control + right_h , leaf ) for name , version , script , control , leaf in left ]
821
+ right = [(name , version , script , control + left_h , leaf ) for name , version , script , control , leaf in right ]
822
822
if right_h < left_h :
823
823
right_h , left_h = left_h , right_h
824
824
h = TaggedHash ("TapBranch" , left_h + right_h )
@@ -830,13 +830,14 @@ def taproot_tree_helper(scripts):
830
830
# - negflag: whether the pubkey in the scriptPubKey was negated from internal_pubkey+tweak*G (bool).
831
831
# - tweak: the tweak (32 bytes)
832
832
# - leaves: a dict of name -> TaprootLeafInfo objects for all known leaves
833
- TaprootInfo = namedtuple ("TaprootInfo" , "scriptPubKey,internal_pubkey,negflag,tweak,leaves" )
833
+ # - merkle_root: the script tree's Merkle root, or bytes() if no leaves are present
834
+ TaprootInfo = namedtuple ("TaprootInfo" , "scriptPubKey,internal_pubkey,negflag,tweak,leaves,merkle_root,output_pubkey" )
834
835
835
836
# A TaprootLeafInfo object has the following fields:
836
837
# - script: the leaf script (CScript or bytes)
837
838
# - version: the leaf version (0xc0 for BIP342 tapscript)
838
839
# - merklebranch: the merkle branch to use for this leaf (32*N bytes)
839
- TaprootLeafInfo = namedtuple ("TaprootLeafInfo" , "script,version,merklebranch" )
840
+ TaprootLeafInfo = namedtuple ("TaprootLeafInfo" , "script,version,merklebranch,leaf_hash " )
840
841
841
842
def taproot_construct (pubkey , scripts = None ):
842
843
"""Construct a tree of Taproot spending conditions
@@ -858,8 +859,8 @@ def taproot_construct(pubkey, scripts=None):
858
859
ret , h = taproot_tree_helper (scripts )
859
860
tweak = TaggedHash ("TapTweak" , pubkey + h )
860
861
tweaked , negated = tweak_add_pubkey (pubkey , tweak )
861
- leaves = dict ((name , TaprootLeafInfo (script , version , merklebranch )) for name , version , script , merklebranch in ret )
862
- return TaprootInfo (CScript ([OP_1 , tweaked ]), pubkey , negated + 0 , tweak , leaves )
862
+ leaves = dict ((name , TaprootLeafInfo (script , version , merklebranch , leaf )) for name , version , script , merklebranch , leaf in ret )
863
+ return TaprootInfo (CScript ([OP_1 , tweaked ]), pubkey , negated + 0 , tweak , leaves , h , tweaked )
863
864
864
865
def is_op_success (o ):
865
866
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 )
0 commit comments