50 std::map<std::vector<uint8_t>, std::vector<uint8_t>>
unknown;
59 template <
typename Stream>
inline void Serialize(Stream &s)
const {
71 s << sig_pair.second.second;
107 std::set<std::vector<uint8_t>> key_lookup;
110 bool found_sep =
false;
113 std::vector<uint8_t> key;
125 uint8_t type = key[0];
130 if (!key_lookup.emplace(key).second) {
131 throw std::ios_base::failure(
132 "Duplicate Key, input utxo already provided");
133 }
else if (key.size() != 1) {
134 throw std::ios_base::failure(
135 "utxo key is more than one byte type");
143 throw std::ios_base::failure(
144 "Size of key was not the expected size for the "
145 "type partial signature pubkey");
148 CPubKey pubkey(key.begin() + 1, key.end());
150 throw std::ios_base::failure(
"Invalid pubkey");
153 throw std::ios_base::failure(
154 "Duplicate Key, input partial signature for pubkey "
159 std::vector<uint8_t>
sig;
168 if (!key_lookup.emplace(key).second) {
169 throw std::ios_base::failure(
170 "Duplicate Key, input sighash type already "
172 }
else if (key.size() != 1) {
173 throw std::ios_base::failure(
174 "Sighash type key is more than one byte type");
179 if (!key_lookup.emplace(key).second) {
180 throw std::ios_base::failure(
181 "Duplicate Key, input redeemScript already "
183 }
else if (key.size() != 1) {
184 throw std::ios_base::failure(
185 "Input redeemScript key is more than one byte "
196 if (!key_lookup.emplace(key).second) {
197 throw std::ios_base::failure(
198 "Duplicate Key, input final scriptSig already "
200 }
else if (key.size() != 1) {
201 throw std::ios_base::failure(
202 "Final scriptSig key is more than one byte type");
210 throw std::ios_base::failure(
211 "Duplicate Key, key for unknown value already "
215 std::vector<uint8_t> val_bytes;
217 unknown.emplace(std::move(key), std::move(val_bytes));
222 throw std::ios_base::failure(
223 "Separator is missing at the end of an input map");
236 std::map<std::vector<uint8_t>, std::vector<uint8_t>>
unknown;
244 template <
typename Stream>
inline void Serialize(Stream &s)
const {
265 std::set<std::vector<uint8_t>> key_lookup;
268 bool found_sep =
false;
271 std::vector<uint8_t> key;
283 uint8_t type = key[0];
288 if (!key_lookup.emplace(key).second) {
289 throw std::ios_base::failure(
290 "Duplicate Key, output redeemScript already "
292 }
else if (key.size() != 1) {
293 throw std::ios_base::failure(
294 "Output redeemScript key is more than one byte "
307 throw std::ios_base::failure(
308 "Duplicate Key, key for unknown value already "
312 std::vector<uint8_t> val_bytes;
314 unknown.emplace(std::move(key), std::move(val_bytes));
321 throw std::ios_base::failure(
322 "Separator is missing at the end of an output map");
335 std::optional<CMutableTransaction>
tx;
338 std::map<std::vector<uint8_t>, std::vector<uint8_t>>
unknown;
361 template <
typename Stream>
inline void Serialize(Stream &s)
const {
396 throw std::ios_base::failure(
"Invalid PSBT magic bytes");
400 std::set<std::vector<uint8_t>> key_lookup;
403 bool found_sep =
false;
406 std::vector<uint8_t> key;
418 uint8_t type = key[0];
423 if (!key_lookup.emplace(key).second) {
424 throw std::ios_base::failure(
425 "Duplicate Key, unsigned tx already provided");
426 }
else if (key.size() != 1) {
427 throw std::ios_base::failure(
428 "Global unsigned tx key is more than one byte "
435 for (
const CTxIn &txin :
tx->vin) {
437 throw std::ios_base::failure(
438 "Unsigned tx does not have empty scriptSigs.");
446 throw std::ios_base::failure(
447 "Duplicate Key, key for unknown value already "
451 std::vector<uint8_t> val_bytes;
453 unknown.emplace(std::move(key), std::move(val_bytes));
459 throw std::ios_base::failure(
460 "Separator is missing at the end of the global map");
465 throw std::ios_base::failure(
466 "No unsigned transcation was provided");
471 while (!s.empty() && i < tx->vin.size()) {
479 if (
inputs.size() !=
tx->vin.size()) {
480 throw std::ios_base::failure(
"Inputs provided does not match the "
481 "number of inputs in transaction.");
486 while (!s.empty() && i < tx->vout.size()) {
495 throw std::ios_base::failure(
"Outputs provided does not match the "
496 "number of outputs in transaction.");
500 template <
typename Stream>
527 bool use_dummy =
false);
569 const std::vector<PartiallySignedTransaction> &psbtxs);
573 const std::string &base64_psbt,
A mutable version of CTransaction.
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
static constexpr unsigned int COMPRESSED_SIZE
static constexpr unsigned int SIZE
secp256k1:
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Serialized script, used inside transaction inputs and outputs.
An input of a transaction.
An output of a transaction.
Signature hash type wrapper class.
uint32_t getRawSigHashType() const
An interface to be implemented by keystores that support signing.
A Span is an object that can refer to a contiguous sequence of objects.
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
bool error(const char *fmt, const Args &...args)
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, SigHashType sighash=SigHashType(), SignatureData *out_sigdata=nullptr, bool use_dummy=false)
Signs a PSBTInput, verifying that all provided data matches what is being signed.
static constexpr uint8_t PSBT_IN_UTXO
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX
static constexpr uint8_t PSBT_IN_SCRIPTSIG
std::string PSBTRoleName(PSBTRole role)
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT
static constexpr uint8_t PSBT_MAGIC_BYTES[5]
static constexpr uint8_t PSBT_SEPARATOR
static constexpr uint8_t PSBT_IN_BIP32_DERIVATION
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION
bool DecodeRawPSBT(PartiallySignedTransaction &decoded_psbt, Span< const std::byte > raw_psbt, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
static constexpr uint8_t PSBT_IN_REDEEMSCRIPT
bool DecodeBase64PSBT(PartiallySignedTransaction &decoded_psbt, const std::string &base64_psbt, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
static constexpr uint8_t PSBT_IN_PARTIAL_SIG
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
static constexpr uint8_t PSBT_IN_SIGHASH
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
TransactionError CombinePSBTs(PartiallySignedTransaction &out, const std::vector< PartiallySignedTransaction > &psbtxs)
Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial sign...
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
const std::streamsize MAX_FILE_SIZE_PSBT
void UnserializeFromVector(Stream &s, X &...args)
void SerializeToVector(Stream &s, const X &...args)
void SerializeHDKeypaths(Stream &s, const std::map< CPubKey, KeyOriginInfo > &hd_keypaths, uint8_t type)
void DeserializeHDKeypaths(Stream &s, const std::vector< uint8_t > &key, std::map< CPubKey, KeyOriginInfo > &hd_keypaths)
std::pair< CPubKey, std::vector< uint8_t > > SigPair
A structure for PSBTs which contains per output information.
void Merge(const PSBTOutput &output)
void Serialize(Stream &s) const
PSBTOutput(deserialize_type, Stream &s)
std::map< CPubKey, KeyOriginInfo > hd_keypaths
void Unserialize(Stream &s)
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
void FillSignatureData(SignatureData &sigdata) const
void FromSignatureData(const SignatureData &sigdata)
A version of CTransaction with the PSBT format.
bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
PartiallySignedTransaction()
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
std::vector< PSBTInput > inputs
std::optional< CMutableTransaction > tx
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
std::vector< PSBTOutput > outputs
void Serialize(Stream &s) const
PartiallySignedTransaction(deserialize_type, Stream &s)
void Unserialize(Stream &s)
Dummy data type to identify deserializing constructors.