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");
181 if (!key_lookup.emplace(key).second) {
182 throw std::ios_base::failure(
183 "Duplicate Key, input redeemScript already "
185 }
else if (key.size() != 1) {
186 throw std::ios_base::failure(
187 "Input redeemScript key is more than one byte "
198 if (!key_lookup.emplace(key).second) {
199 throw std::ios_base::failure(
200 "Duplicate Key, input final scriptSig already "
202 }
else if (key.size() != 1) {
203 throw std::ios_base::failure(
204 "Final scriptSig key is more than one byte type");
212 throw std::ios_base::failure(
213 "Duplicate Key, key for unknown value already "
217 std::vector<uint8_t> val_bytes;
219 unknown.emplace(std::move(key), std::move(val_bytes));
224 throw std::ios_base::failure(
225 "Separator is missing at the end of an input map");
238 std::map<std::vector<uint8_t>, std::vector<uint8_t>>
unknown;
246 template <
typename Stream>
inline void Serialize(Stream &s)
const {
267 std::set<std::vector<uint8_t>> key_lookup;
270 bool found_sep =
false;
273 std::vector<uint8_t> key;
285 uint8_t type = key[0];
290 if (!key_lookup.emplace(key).second) {
291 throw std::ios_base::failure(
292 "Duplicate Key, output redeemScript already "
294 }
else if (key.size() != 1) {
295 throw std::ios_base::failure(
296 "Output redeemScript key is more than one byte "
309 throw std::ios_base::failure(
310 "Duplicate Key, key for unknown value already "
314 std::vector<uint8_t> val_bytes;
316 unknown.emplace(std::move(key), std::move(val_bytes));
323 throw std::ios_base::failure(
324 "Separator is missing at the end of an output map");
337 std::optional<CMutableTransaction>
tx;
340 std::map<std::vector<uint8_t>, std::vector<uint8_t>>
unknown;
363 template <
typename Stream>
inline void Serialize(Stream &s)
const {
398 throw std::ios_base::failure(
"Invalid PSBT magic bytes");
402 std::set<std::vector<uint8_t>> key_lookup;
405 bool found_sep =
false;
408 std::vector<uint8_t> key;
420 uint8_t type = key[0];
425 if (!key_lookup.emplace(key).second) {
426 throw std::ios_base::failure(
427 "Duplicate Key, unsigned tx already provided");
428 }
else if (key.size() != 1) {
429 throw std::ios_base::failure(
430 "Global unsigned tx key is more than one byte "
437 for (
const CTxIn &txin :
tx->vin) {
439 throw std::ios_base::failure(
440 "Unsigned tx does not have empty scriptSigs.");
448 throw std::ios_base::failure(
449 "Duplicate Key, key for unknown value already "
453 std::vector<uint8_t> val_bytes;
455 unknown.emplace(std::move(key), std::move(val_bytes));
461 throw std::ios_base::failure(
462 "Separator is missing at the end of the global map");
467 throw std::ios_base::failure(
468 "No unsigned transcation was provided");
473 while (!s.empty() && i < tx->vin.size()) {
481 if (
inputs.size() !=
tx->vin.size()) {
482 throw std::ios_base::failure(
"Inputs provided does not match the "
483 "number of inputs in transaction.");
488 while (!s.empty() && i < tx->vout.size()) {
497 throw std::ios_base::failure(
"Outputs provided does not match the "
498 "number of outputs in transaction.");
502 template <
typename Stream>
528 SignatureData *out_sigdata =
nullptr,
bool use_dummy =
false,
529 bool finalize =
true);
571 const std::vector<PartiallySignedTransaction> &psbtxs);
575 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.
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
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
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, SigHashType sighash=SigHashType(), SignatureData *out_sigdata=nullptr, bool use_dummy=false, bool finalize=true)
Signs a PSBTInput, verifying that all provided data matches what is being signed.
static constexpr uint8_t PSBT_IN_SCRIPTSIG
std::string PSBTRoleName(PSBTRole role)
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT
bool CombinePSBTs(PartiallySignedTransaction &out, const std::vector< PartiallySignedTransaction > &psbtxs)
Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial sign...
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.
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.
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
PartiallySignedTransaction()=default
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.