INNER CODE UNIT · Python
get_pubkey_from_input
BlockstreamResearch/secp256k1-zkp · tools/tests_silentpayments_generate.py:33
def get_pubkey_from_input(input_data, pubkey_hex):
"""Extract the correct pubkey for an input, handling NUMS_H filtering and format conversion"""
spk = bytes.fromhex(input_data['prevout']['scriptPubKey']['hex'])
pubkey = bytes.fromhex(pubkey_hex)
if is_p2tr(spk): # taproot input
# Check for NUMS_H in witness (should be skipped)
witness = bytes.fromhex(input_data.get('txinwitness', ''))
# Parse witness stack
witness_stack = []
num_witness_items = 0
if len(witness) > 0:
num_witness_items = witness[0]
witness = witness[1:]
for i in range(num_witness_items):
item_len = witness[0]
witness_stack.append(witness[1:item_len+1])
witness = witness[item_len+1:]