# (c) Copyright 2018 by Coinkite Inc. This file is part of Coldcard # and is covered by GPLv3 license found in COPYING. # # psbt.py - yet another PSBT parser/serializer but used only for test cases. # import pytest, io, struct from binascii import b2a_hex as _b2a_hex from binascii import a2b_hex as _a2b_hex from collections import namedtuple from base64 import b64encode from pycoin.tx.Tx import Tx from pycoin.tx.TxOut import TxOut from binascii import b2a_hex, a2b_hex b2a_hex = lambda a: str(_b2a_hex(a), 'ascii') # BIP-174 aka PSBT defined values # PSBT_GLOBAL_UNSIGNED_TX = (0) PSBT_IN_NON_WITNESS_UTXO = (0) PSBT_IN_WITNESS_UTXO = (1) PSBT_IN_PARTIAL_SIG = (2) PSBT_IN_SIGHASH_TYPE = (3) PSBT_IN_REDEEM_SCRIPT = (4) PSBT_IN_WITNESS_SCRIPT = (5) PSBT_IN_BIP32_DERIVATION = (6) PSBT_IN_FINAL_SCRIPTSIG = (7) PSBT_IN_FINAL_SCRIPTWITNESS = (8) PSBT_OUT_REDEEM_SCRIPT = (0) PSBT_OUT_WITNESS_SCRIPT = (1) PSBT_OUT_BIP32_DERIVATION = (2) # Serialization/deserialization tools def ser_compact_size(l): r = b"" if l < 253: r = struct.pack("B", l) elif l < 0x10000: r = struct.pack("