Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Namespaces | Enumerations | Functions | Variables
psbt.h File Reference
#include <node/transaction.h>
#include <policy/feerate.h>
#include <primitives/transaction.h>
#include <pubkey.h>
#include <script/keyorigin.h>
#include <script/sign.h>
#include <script/signingprovider.h>
#include <span.h>
#include <streams.h>
#include <optional>
Include dependency graph for psbt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PSBTProprietary
 A structure for PSBT proprietary types. More...
 
struct  PSBTInput
 A structure for PSBTs which contain per-input information. More...
 
struct  PSBTOutput
 A structure for PSBTs which contains per output information. More...
 
struct  PartiallySignedTransaction
 A version of CTransaction with the PSBT format. More...
 

Namespaces

namespace  node
 

Enumerations

enum class  PSBTRole {
  CREATOR , UPDATER , SIGNER , FINALIZER ,
  EXTRACTOR
}
 

Functions

template<typename Stream , typename... X>
void SerializeToVector (Stream &s, const X &... args)
 
template<typename Stream , typename... X>
void UnserializeFromVector (Stream &s, X &&... args)
 
template<typename Stream >
KeyOriginInfo DeserializeKeyOrigin (Stream &s, uint64_t length)
 
template<typename Stream >
void DeserializeHDKeypath (Stream &s, KeyOriginInfo &hd_keypath)
 
template<typename Stream >
void DeserializeHDKeypaths (Stream &s, const std::vector< unsigned char > &key, std::map< CPubKey, KeyOriginInfo > &hd_keypaths)
 
template<typename Stream >
void SerializeKeyOrigin (Stream &s, KeyOriginInfo hd_keypath)
 
template<typename Stream >
void SerializeHDKeypath (Stream &s, KeyOriginInfo hd_keypath)
 
template<typename Stream >
void SerializeHDKeypaths (Stream &s, const std::map< CPubKey, KeyOriginInfo > &hd_keypaths, CompactSizeWriter type)
 
std::string PSBTRoleName (PSBTRole role)
 
PrecomputedTransactionData PrecomputePSBTData (const PartiallySignedTransaction &psbt)
 Compute a PrecomputedTransactionData object from a psbt. More...
 
bool PSBTInputSigned (const PSBTInput &input)
 Checks whether a PSBTInput is already signed by checking for non-null finalized fields. More...
 
bool PSBTInputSignedAndVerified (const PartiallySignedTransaction psbt, unsigned int input_index, const PrecomputedTransactionData *txdata)
 Checks whether a PSBTInput is already signed by doing script verification using final fields. More...
 
bool SignPSBTInput (const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, const PrecomputedTransactionData *txdata, int sighash=SIGHASH_ALL, SignatureData *out_sigdata=nullptr, bool finalize=true)
 Signs a PSBTInput, verifying that all provided data matches what is being signed. More...
 
void RemoveUnnecessaryTransactions (PartiallySignedTransaction &psbtx, const int &sighash_type)
 Reduces the size of the PSBT by dropping unnecessary non_witness_utxos (i.e. More...
 
size_t CountPSBTUnsignedInputs (const PartiallySignedTransaction &psbt)
 Counts the unsigned inputs of a PSBT. More...
 
void UpdatePSBTOutput (const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
 Updates a PSBTOutput with information from provider. More...
 
bool FinalizePSBT (PartiallySignedTransaction &psbtx)
 Finalizes a PSBT if possible, combining partial signatures. More...
 
bool FinalizeAndExtractPSBT (PartiallySignedTransaction &psbtx, CMutableTransaction &result)
 Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized. More...
 
bool CombinePSBTs (PartiallySignedTransaction &out, const std::vector< PartiallySignedTransaction > &psbtxs)
 Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial signatures from each input. More...
 
bool DecodeBase64PSBT (PartiallySignedTransaction &decoded_psbt, const std::string &base64_psbt, std::string &error)
 Decode a base64ed PSBT into a PartiallySignedTransaction. More...
 
bool DecodeRawPSBT (PartiallySignedTransaction &decoded_psbt, Span< const std::byte > raw_psbt, std::string &error)
 Decode a raw (binary blob) PSBT into a PartiallySignedTransaction. More...
 

Variables

static constexpr uint8_t PSBT_MAGIC_BYTES [5] = {'p', 's', 'b', 't', 0xff}
 
static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX = 0x00
 
static constexpr uint8_t PSBT_GLOBAL_XPUB = 0x01
 
static constexpr uint8_t PSBT_GLOBAL_VERSION = 0xFB
 
static constexpr uint8_t PSBT_GLOBAL_PROPRIETARY = 0xFC
 
static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO = 0x00
 
static constexpr uint8_t PSBT_IN_WITNESS_UTXO = 0x01
 
static constexpr uint8_t PSBT_IN_PARTIAL_SIG = 0x02
 
static constexpr uint8_t PSBT_IN_SIGHASH = 0x03
 
static constexpr uint8_t PSBT_IN_REDEEMSCRIPT = 0x04
 
static constexpr uint8_t PSBT_IN_WITNESSSCRIPT = 0x05
 
static constexpr uint8_t PSBT_IN_BIP32_DERIVATION = 0x06
 
static constexpr uint8_t PSBT_IN_SCRIPTSIG = 0x07
 
static constexpr uint8_t PSBT_IN_SCRIPTWITNESS = 0x08
 
static constexpr uint8_t PSBT_IN_RIPEMD160 = 0x0A
 
static constexpr uint8_t PSBT_IN_SHA256 = 0x0B
 
static constexpr uint8_t PSBT_IN_HASH160 = 0x0C
 
static constexpr uint8_t PSBT_IN_HASH256 = 0x0D
 
static constexpr uint8_t PSBT_IN_TAP_KEY_SIG = 0x13
 
static constexpr uint8_t PSBT_IN_TAP_SCRIPT_SIG = 0x14
 
static constexpr uint8_t PSBT_IN_TAP_LEAF_SCRIPT = 0x15
 
static constexpr uint8_t PSBT_IN_TAP_BIP32_DERIVATION = 0x16
 
static constexpr uint8_t PSBT_IN_TAP_INTERNAL_KEY = 0x17
 
static constexpr uint8_t PSBT_IN_TAP_MERKLE_ROOT = 0x18
 
static constexpr uint8_t PSBT_IN_PROPRIETARY = 0xFC
 
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00
 
static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT = 0x01
 
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02
 
static constexpr uint8_t PSBT_OUT_TAP_INTERNAL_KEY = 0x05
 
static constexpr uint8_t PSBT_OUT_TAP_TREE = 0x06
 
static constexpr uint8_t PSBT_OUT_TAP_BIP32_DERIVATION = 0x07
 
static constexpr uint8_t PSBT_OUT_PROPRIETARY = 0xFC
 
static constexpr uint8_t PSBT_SEPARATOR = 0x00
 
const std::streamsize MAX_FILE_SIZE_PSBT = 100000000
 
static constexpr uint32_t PSBT_HIGHEST_VERSION = 0
 

Enumeration Type Documentation

◆ PSBTRole

enum class PSBTRole
strong
Enumerator
CREATOR 
UPDATER 
SIGNER 
FINALIZER 
EXTRACTOR 

Definition at line 1215 of file psbt.h.

Function Documentation

◆ CombinePSBTs()

bool CombinePSBTs ( PartiallySignedTransaction out,
const std::vector< PartiallySignedTransaction > &  psbtxs 
)

Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial signatures from each input.

Parameters
[out]outthe combined PSBT, if successful
[in]psbtxsthe PSBTs to combine
Returns
True if we successfully combined the transactions, false if they were not compatible

Definition at line 511 of file psbt.cpp.

Here is the caller graph for this function:

◆ CountPSBTUnsignedInputs()

size_t CountPSBTUnsignedInputs ( const PartiallySignedTransaction psbt)

Counts the unsigned inputs of a PSBT.

Definition at line 327 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DecodeBase64PSBT()

bool DecodeBase64PSBT ( PartiallySignedTransaction decoded_psbt,
const std::string &  base64_psbt,
std::string &  error 
)

Decode a base64ed PSBT into a PartiallySignedTransaction.

Definition at line 536 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DecodeRawPSBT()

bool DecodeRawPSBT ( PartiallySignedTransaction decoded_psbt,
Span< const std::byte >  raw_psbt,
std::string &  error 
)

Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.

Definition at line 546 of file psbt.cpp.

Here is the caller graph for this function:

◆ DeserializeHDKeypath()

template<typename Stream >
void DeserializeHDKeypath ( Stream &  s,
KeyOriginInfo hd_keypath 
)

Definition at line 136 of file psbt.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeserializeHDKeypaths()

template<typename Stream >
void DeserializeHDKeypaths ( Stream &  s,
const std::vector< unsigned char > &  key,
std::map< CPubKey, KeyOriginInfo > &  hd_keypaths 
)

Definition at line 143 of file psbt.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeserializeKeyOrigin()

template<typename Stream >
KeyOriginInfo DeserializeKeyOrigin ( Stream &  s,
uint64_t  length 
)

Definition at line 117 of file psbt.h.

Here is the caller graph for this function:

◆ FinalizeAndExtractPSBT()

bool FinalizeAndExtractPSBT ( PartiallySignedTransaction psbtx,
CMutableTransaction result 
)

Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.

Parameters
[in]psbtxPartiallySignedTransaction
[out]resultCMutableTransaction representing the complete transaction, if successful
Returns
True if we successfully extracted the transaction, false otherwise

Definition at line 495 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FinalizePSBT()

bool FinalizePSBT ( PartiallySignedTransaction psbtx)

Finalizes a PSBT if possible, combining partial signatures.

Parameters
[in,out]psbtxPartiallySignedTransaction to finalize return True if the PSBT is now complete, false otherwise

Definition at line 480 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrecomputePSBTData()

PrecomputedTransactionData PrecomputePSBTData ( const PartiallySignedTransaction psbt)

Compute a PrecomputedTransactionData object from a psbt.

Definition at line 358 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PSBTInputSigned()

bool PSBTInputSigned ( const PSBTInput input)

Checks whether a PSBTInput is already signed by checking for non-null finalized fields.

Definition at line 293 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PSBTInputSignedAndVerified()

bool PSBTInputSignedAndVerified ( const PartiallySignedTransaction  psbt,
unsigned int  input_index,
const PrecomputedTransactionData txdata 
)

Checks whether a PSBTInput is already signed by doing script verification using final fields.

Definition at line 298 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PSBTRoleName()

std::string PSBTRoleName ( PSBTRole  role)

Definition at line 524 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveUnnecessaryTransactions()

void RemoveUnnecessaryTransactions ( PartiallySignedTransaction psbtx,
const int &  sighash_type 
)

Reduces the size of the PSBT by dropping unnecessary non_witness_utxos (i.e.

complete previous transactions) from a psbt when all inputs are segwit v1.

Definition at line 448 of file psbt.cpp.

Here is the caller graph for this function:

◆ SerializeHDKeypath()

template<typename Stream >
void SerializeHDKeypath ( Stream &  s,
KeyOriginInfo  hd_keypath 
)

Definition at line 177 of file psbt.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SerializeHDKeypaths()

template<typename Stream >
void SerializeHDKeypaths ( Stream &  s,
const std::map< CPubKey, KeyOriginInfo > &  hd_keypaths,
CompactSizeWriter  type 
)

Definition at line 185 of file psbt.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SerializeKeyOrigin()

template<typename Stream >
void SerializeKeyOrigin ( Stream &  s,
KeyOriginInfo  hd_keypath 
)

Definition at line 167 of file psbt.h.

Here is the caller graph for this function:

◆ SerializeToVector()

template<typename Stream , typename... X>
void SerializeToVector ( Stream &  s,
const X &...  args 
)

Definition at line 94 of file psbt.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SignPSBTInput()

bool SignPSBTInput ( const SigningProvider provider,
PartiallySignedTransaction psbt,
int  index,
const PrecomputedTransactionData txdata,
int  sighash = SIGHASH_ALL,
SignatureData out_sigdata = nullptr,
bool  finalize = true 
)

Signs a PSBTInput, verifying that all provided data matches what is being signed.

txdata should be the output of PrecomputePSBTData (which can be shared across multiple SignPSBTInput calls). If it is nullptr, a dummy signature will be created.

Definition at line 375 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnserializeFromVector()

template<typename Stream , typename... X>
void UnserializeFromVector ( Stream &  s,
X &&...  args 
)

Definition at line 104 of file psbt.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdatePSBTOutput()

void UpdatePSBTOutput ( const SigningProvider provider,
PartiallySignedTransaction psbt,
int  index 
)

Updates a PSBTOutput with information from provider.

This fills in the redeem_script, witness_script, and hd_keypaths where possible.

Definition at line 338 of file psbt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ MAX_FILE_SIZE_PSBT

const std::streamsize MAX_FILE_SIZE_PSBT = 100000000

Definition at line 70 of file psbt.h.

◆ PSBT_GLOBAL_PROPRIETARY

constexpr uint8_t PSBT_GLOBAL_PROPRIETARY = 0xFC
staticconstexpr

Definition at line 31 of file psbt.h.

◆ PSBT_GLOBAL_UNSIGNED_TX

constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX = 0x00
staticconstexpr

Definition at line 28 of file psbt.h.

◆ PSBT_GLOBAL_VERSION

constexpr uint8_t PSBT_GLOBAL_VERSION = 0xFB
staticconstexpr

Definition at line 30 of file psbt.h.

◆ PSBT_GLOBAL_XPUB

constexpr uint8_t PSBT_GLOBAL_XPUB = 0x01
staticconstexpr

Definition at line 29 of file psbt.h.

◆ PSBT_HIGHEST_VERSION

constexpr uint32_t PSBT_HIGHEST_VERSION = 0
staticconstexpr

Definition at line 73 of file psbt.h.

◆ PSBT_IN_BIP32_DERIVATION

constexpr uint8_t PSBT_IN_BIP32_DERIVATION = 0x06
staticconstexpr

Definition at line 40 of file psbt.h.

◆ PSBT_IN_HASH160

constexpr uint8_t PSBT_IN_HASH160 = 0x0C
staticconstexpr

Definition at line 45 of file psbt.h.

◆ PSBT_IN_HASH256

constexpr uint8_t PSBT_IN_HASH256 = 0x0D
staticconstexpr

Definition at line 46 of file psbt.h.

◆ PSBT_IN_NON_WITNESS_UTXO

constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO = 0x00
staticconstexpr

Definition at line 34 of file psbt.h.

◆ PSBT_IN_PARTIAL_SIG

constexpr uint8_t PSBT_IN_PARTIAL_SIG = 0x02
staticconstexpr

Definition at line 36 of file psbt.h.

◆ PSBT_IN_PROPRIETARY

constexpr uint8_t PSBT_IN_PROPRIETARY = 0xFC
staticconstexpr

Definition at line 53 of file psbt.h.

◆ PSBT_IN_REDEEMSCRIPT

constexpr uint8_t PSBT_IN_REDEEMSCRIPT = 0x04
staticconstexpr

Definition at line 38 of file psbt.h.

◆ PSBT_IN_RIPEMD160

constexpr uint8_t PSBT_IN_RIPEMD160 = 0x0A
staticconstexpr

Definition at line 43 of file psbt.h.

◆ PSBT_IN_SCRIPTSIG

constexpr uint8_t PSBT_IN_SCRIPTSIG = 0x07
staticconstexpr

Definition at line 41 of file psbt.h.

◆ PSBT_IN_SCRIPTWITNESS

constexpr uint8_t PSBT_IN_SCRIPTWITNESS = 0x08
staticconstexpr

Definition at line 42 of file psbt.h.

◆ PSBT_IN_SHA256

constexpr uint8_t PSBT_IN_SHA256 = 0x0B
staticconstexpr

Definition at line 44 of file psbt.h.

◆ PSBT_IN_SIGHASH

constexpr uint8_t PSBT_IN_SIGHASH = 0x03
staticconstexpr

Definition at line 37 of file psbt.h.

◆ PSBT_IN_TAP_BIP32_DERIVATION

constexpr uint8_t PSBT_IN_TAP_BIP32_DERIVATION = 0x16
staticconstexpr

Definition at line 50 of file psbt.h.

◆ PSBT_IN_TAP_INTERNAL_KEY

constexpr uint8_t PSBT_IN_TAP_INTERNAL_KEY = 0x17
staticconstexpr

Definition at line 51 of file psbt.h.

◆ PSBT_IN_TAP_KEY_SIG

constexpr uint8_t PSBT_IN_TAP_KEY_SIG = 0x13
staticconstexpr

Definition at line 47 of file psbt.h.

◆ PSBT_IN_TAP_LEAF_SCRIPT

constexpr uint8_t PSBT_IN_TAP_LEAF_SCRIPT = 0x15
staticconstexpr

Definition at line 49 of file psbt.h.

◆ PSBT_IN_TAP_MERKLE_ROOT

constexpr uint8_t PSBT_IN_TAP_MERKLE_ROOT = 0x18
staticconstexpr

Definition at line 52 of file psbt.h.

◆ PSBT_IN_TAP_SCRIPT_SIG

constexpr uint8_t PSBT_IN_TAP_SCRIPT_SIG = 0x14
staticconstexpr

Definition at line 48 of file psbt.h.

◆ PSBT_IN_WITNESS_UTXO

constexpr uint8_t PSBT_IN_WITNESS_UTXO = 0x01
staticconstexpr

Definition at line 35 of file psbt.h.

◆ PSBT_IN_WITNESSSCRIPT

constexpr uint8_t PSBT_IN_WITNESSSCRIPT = 0x05
staticconstexpr

Definition at line 39 of file psbt.h.

◆ PSBT_MAGIC_BYTES

constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff}
staticconstexpr

Definition at line 25 of file psbt.h.

◆ PSBT_OUT_BIP32_DERIVATION

constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02
staticconstexpr

Definition at line 58 of file psbt.h.

◆ PSBT_OUT_PROPRIETARY

constexpr uint8_t PSBT_OUT_PROPRIETARY = 0xFC
staticconstexpr

Definition at line 62 of file psbt.h.

◆ PSBT_OUT_REDEEMSCRIPT

constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00
staticconstexpr

Definition at line 56 of file psbt.h.

◆ PSBT_OUT_TAP_BIP32_DERIVATION

constexpr uint8_t PSBT_OUT_TAP_BIP32_DERIVATION = 0x07
staticconstexpr

Definition at line 61 of file psbt.h.

◆ PSBT_OUT_TAP_INTERNAL_KEY

constexpr uint8_t PSBT_OUT_TAP_INTERNAL_KEY = 0x05
staticconstexpr

Definition at line 59 of file psbt.h.

◆ PSBT_OUT_TAP_TREE

constexpr uint8_t PSBT_OUT_TAP_TREE = 0x06
staticconstexpr

Definition at line 60 of file psbt.h.

◆ PSBT_OUT_WITNESSSCRIPT

constexpr uint8_t PSBT_OUT_WITNESSSCRIPT = 0x01
staticconstexpr

Definition at line 57 of file psbt.h.

◆ PSBT_SEPARATOR

constexpr uint8_t PSBT_SEPARATOR = 0x00
staticconstexpr

Definition at line 66 of file psbt.h.