btclib.psbt package

Submodules

btclib.psbt.psbt module

Partially Signed Bitcoin Transaction (Psbt) dataclass and functions.

https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki

class btclib.psbt.psbt.Psbt(tx: btclib.tx.tx.Tx, inputs: Sequence[btclib.psbt.psbt_in.PsbtIn], outputs: Sequence[btclib.psbt.psbt_out.PsbtOut], version: int, hd_key_paths: Mapping[Union[bytes, str], btclib.bip32.key_origin.BIP32KeyOrigin], unknown: Union[Mapping[Union[bytes, str], Union[bytes, str]], NoneType] = None, check_validity: bool = True)

Bases: object

assert_signable() None
assert_valid() None

Assert logical self-consistency.

classmethod b64decode(psbt_str: Union[bytes, str], check_validity: bool = True) Psbt
b64encode(check_validity: bool = True) str
classmethod from_dict(dict_: Mapping[str, Any], check_validity: bool = True) Psbt
classmethod from_tx(tx: Tx, check_validity: bool = True) Psbt
hd_key_paths: Dict[bytes, BIP32KeyOrigin]
inputs: List[PsbtIn]
outputs: List[PsbtOut]
classmethod parse(psbt_bin: Union[bytes, str], check_validity: bool = True) Psbt

Return a Psbt by parsing binary data.

serialize(check_validity: bool = True) bytes
to_dict(check_validity: bool = True) Dict[str, Any]
tx: Tx
unknown: Dict[bytes, bytes]
version: int
btclib.psbt.psbt.combine_psbts(psbts: Sequence[Psbt]) Psbt
btclib.psbt.psbt.extract_tx(psbt: Psbt, check_validity: bool = True) Tx

Extract the Tx fro the Psbt

The Transaction Extractor must only accept a PSBT. It checks whether all inputs have complete scriptSigs and scriptWitnesses by checking for the presence of 0x07 Finalized scriptSig and 0x08 Finalized scriptWitness typed records.

If they do, the Transaction Extractor should construct complete scriptSigs and scriptWitnesses and encode them into network serialized transactions. Otherwise the Extractor must not modify the PSBT.

The Extractor should produce a fully valid, network serialized transaction if all inputs are complete.

The Transaction Extractor does not need to know how to interpret scripts in order to extract the network serialized transaction. However it may be able to in order to validate the network serialized transaction at the same time.

btclib.psbt.psbt.finalize_psbt(psbt: Psbt) Psbt

Finalize the Psbt.

The Input Finalizer must only accept a PSBT.

For each input, the Input Finalizer determines if the input has enough data to pass validation. If it does, it must construct the 0x07 Finalized scriptSig and 0x08 Finalized scriptWitness and place them into the input key-value map.

All other data except the UTXO and unknown fields in the input key-value map should be cleared from the PSBT. The UTXO should be kept to allow Transaction Extractors to verify the final network serialized transaction.

btclib.psbt.psbt_in module

Partially Signed Bitcoin Transaction Input (PsbtIn) dataclass and functions.

https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki

class btclib.psbt.psbt_in.PsbtIn(non_witness_utxo: Union[btclib.tx.tx.Tx, NoneType] = None, witness_utxo: Union[btclib.tx.tx_out.TxOut, NoneType] = None, partial_sigs: Union[Mapping[Union[bytes, str], Union[bytes, str]], NoneType] = None, sig_hash_type: Union[int, NoneType] = None, redeem_script: Union[bytes, str] = b'', witness_script: Union[bytes, str] = b'', hd_key_paths: Union[Mapping[Union[bytes, str], btclib.bip32.key_origin.BIP32KeyOrigin], NoneType] = None, final_script_sig: Union[bytes, str] = b'', final_script_witness: btclib.script.witness.Witness = Witness(stack=[]), ripemd160_preimages: Union[Mapping[Union[bytes, str], Union[bytes, str]], NoneType] = None, sha256_preimages: Union[Mapping[Union[bytes, str], Union[bytes, str]], NoneType] = None, hash160_preimages: Union[Mapping[Union[bytes, str], Union[bytes, str]], NoneType] = None, hash256_preimages: Union[Mapping[Union[bytes, str], Union[bytes, str]], NoneType] = None, unknown: Union[Mapping[Union[bytes, str], Union[bytes, str]], NoneType] = None, check_validity: bool = True)

Bases: object

assert_valid() None

Assert logical self-consistency.

final_script_sig: bytes
final_script_witness: Witness
classmethod from_dict(dict_: Mapping[str, Any], check_validity: bool = True) PsbtIn
hash160_preimages: Dict[bytes, bytes]
hash256_preimages: Dict[bytes, bytes]
hd_key_paths: Dict[bytes, BIP32KeyOrigin]
non_witness_utxo: Optional[Tx]
classmethod parse(input_map: Mapping[bytes, bytes], check_validity: bool = True) PsbtIn

Return a PsbtIn by parsing binary data.

partial_sigs: Dict[bytes, bytes]
redeem_script: bytes
ripemd160_preimages: Dict[bytes, bytes]
serialize(check_validity: bool = True) bytes
sha256_preimages: Dict[bytes, bytes]
property sig_hash: int

Return the sig_hash int for compatibility with PartiallySignedInput.

sig_hash_type: Optional[int]
to_dict(check_validity: bool = True) Dict[str, Any]
unknown: Dict[bytes, bytes]
witness_script: bytes
witness_utxo: Optional[TxOut]

btclib.psbt.psbt_out module

Partially Signed Bitcoin Transaction Output (PsbtOut) dataclass and functions.

https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki

class btclib.psbt.psbt_out.PsbtOut(redeem_script: Union[bytes, str] = b'', witness_script: Union[bytes, str] = b'', hd_key_paths: Union[Mapping[Union[bytes, str], btclib.bip32.key_origin.BIP32KeyOrigin], NoneType] = None, unknown: Union[Mapping[Union[bytes, str], Union[bytes, str]], NoneType] = None, check_validity: bool = True)

Bases: object

assert_valid() None

Assert logical self-consistency.

classmethod from_dict(dict_: Mapping[str, Any], check_validity: bool = True) PsbtOut
hd_key_paths: Dict[bytes, BIP32KeyOrigin]
classmethod parse(output_map: Mapping[bytes, bytes], check_validity: bool = True) PsbtOut

Return a PsbtOut by parsing binary data.

redeem_script: bytes
serialize(check_validity: bool = True) bytes
to_dict(check_validity: bool = True) Dict[str, Any]
unknown: Dict[bytes, bytes]
witness_script: bytes

btclib.psbt.psbt_utils module

Partially Signed Bitcoin Transaction (Psbt) helper functions.

https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki

btclib.psbt.psbt_utils.assert_valid_redeem_script(redeem_script: bytes) None

Raise an exception if the dataclass element is not valid.

btclib.psbt.psbt_utils.assert_valid_unknown(data: Mapping[bytes, bytes]) None

Raise an exception if the dataclass element is not valid.

btclib.psbt.psbt_utils.assert_valid_witness_script(witness_script: bytes) None

Raise an exception if the dataclass element is not valid.

btclib.psbt.psbt_utils.decode_dict_bytes_bytes(map_: Optional[Mapping[Union[bytes, str], Union[bytes, str]]]) Dict[bytes, bytes]

Return the dataclass element from its json representation.

btclib.psbt.psbt_utils.deserialize_bytes(k: bytes, v: bytes, type_: str) bytes

Return the dataclass element from its binary representation.

btclib.psbt.psbt_utils.deserialize_int(k: bytes, v: bytes, type_: str) int

Return the dataclass element from its binary representation.

btclib.psbt.psbt_utils.deserialize_map(data: Union[BytesIO, bytes, str]) Tuple[Dict[bytes, bytes], BytesIO]
btclib.psbt.psbt_utils.deserialize_tx(k: bytes, v: bytes, type_: str, include_witness: Optional[bool] = True) Tx

Return the dataclass element from its binary representation.

btclib.psbt.psbt_utils.encode_dict_bytes_bytes(dict_: Mapping[bytes, bytes]) Dict[str, str]

Return the json representation of the dataclass element.

btclib.psbt.psbt_utils.serialize_bytes(type_: bytes, value: bytes) bytes

Return the binary representation of the dataclass element.

btclib.psbt.psbt_utils.serialize_dict_bytes_bytes(type_: bytes, dictionary: Mapping[bytes, bytes]) bytes

Return the binary representation of the dataclass element.

btclib.psbt.psbt_utils.serialize_hd_key_paths(type_: bytes, hd_key_paths: Mapping[bytes, BIP32KeyOrigin]) bytes

Return the binary representation of the dataclass element.

Module contents

btclib.psbt submodule.