Merge 38d06e1561 into merged_master (Bitcoin PR bitcoin/bitcoin#26383)

This commit is contained in:
Byron Hambly 2025-03-03 13:44:12 +02:00
commit f0478dd601
2 changed files with 52 additions and 4 deletions

View file

@ -12,7 +12,7 @@ import struct
import unittest
from typing import List, Dict
from .key import TaggedHash, tweak_add_pubkey
from .key import TaggedHash, tweak_add_pubkey, compute_xonly_pubkey
from .messages import (
CTransaction,
@ -1055,7 +1055,7 @@ TaprootInfo = namedtuple("TaprootInfo", "scriptPubKey,internal_pubkey,negflag,tw
# - merklebranch: the merkle branch to use for this leaf (32*N bytes)
TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch,leaf_hash")
def taproot_construct(pubkey, scripts=None):
def taproot_construct(pubkey, scripts=None, treat_internal_as_infinity=False):
"""Construct a tree of Taproot spending conditions
pubkey: a 32-byte xonly pubkey for the internal pubkey (bytes)
@ -1074,7 +1074,10 @@ def taproot_construct(pubkey, scripts=None):
ret, h = taproot_tree_helper(scripts)
tweak = TaggedHash("TapTweak/elements", pubkey + h)
tweaked, negated = tweak_add_pubkey(pubkey, tweak)
if treat_internal_as_infinity:
tweaked, negated = compute_xonly_pubkey(tweak)
else:
tweaked, negated = tweak_add_pubkey(pubkey, tweak)
leaves = dict((name, TaprootLeafInfo(script, version, merklebranch, leaf)) for name, version, script, merklebranch, leaf in ret)
return TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked)