51 std::map<std::vector<uint8_t>, std::vector<uint8_t>>
unknown;
60 template <
typename Stream>
inline void Serialize(Stream &s)
const {
72 s << sig_pair.second.second;
108 std::set<std::vector<uint8_t>> key_lookup;
111 bool found_sep =
false;
114 std::vector<uint8_t> key;
126 uint8_t type = key[0];
131 if (!key_lookup.emplace(key).second) {
132 throw std::ios_base::failure(
133 "Duplicate Key, input utxo already provided");
134 }
else if (key.size() != 1) {
135 throw std::ios_base::failure(
136 "utxo key is more than one byte type");
144 throw std::ios_base::failure(
145 "Size of key was not the expected size for the "
146 "type partial signature pubkey");
149 CPubKey pubkey(key.begin() + 1, key.end());
151 throw std::ios_base::failure(
"Invalid pubkey");
154 throw std::ios_base::failure(
155 "Duplicate Key, input partial signature for pubkey "
160 std::vector<uint8_t>
sig;
169 if (!key_lookup.emplace(key).second) {
170 throw std::ios_base::failure(
171 "Duplicate Key, input sighash type already "
173 }
else if (key.size() != 1) {
174 throw std::ios_base::failure(
175 "Sighash type key is more than one byte type");
180 if (!key_lookup.emplace(key).second) {
181 throw std::ios_base::failure(
182 "Duplicate Key, input redeemScript already "
184 }
else if (key.size() != 1) {
185 throw std::ios_base::failure(
186 "Input redeemScript key is more than one byte "
197 if (!key_lookup.emplace(key).second) {
198 throw std::ios_base::failure(
199 "Duplicate Key, input final scriptSig already "
201 }
else if (key.size() != 1) {
202 throw std::ios_base::failure(
203 "Final scriptSig key is more than one byte type");
211 throw std::ios_base::failure(
212 "Duplicate Key, key for unknown value already "
216 std::vector<uint8_t> val_bytes;
218 unknown.emplace(std::move(key), std::move(val_bytes));
223 throw std::ios_base::failure(
224 "Separator is missing at the end of an input map");
237 std::map<std::vector<uint8_t>, std::vector<uint8_t>>
unknown;
245 template <
typename Stream>
inline void Serialize(Stream &s)
const {
266 std::set<std::vector<uint8_t>> key_lookup;
269 bool found_sep =
false;
272 std::vector<uint8_t> key;
284 uint8_t type = key[0];
289 if (!key_lookup.emplace(key).second) {
290 throw std::ios_base::failure(
291 "Duplicate Key, output redeemScript already "
293 }
else if (key.size() != 1) {
294 throw std::ios_base::failure(
295 "Output redeemScript key is more than one byte "
308 throw std::ios_base::failure(
309 "Duplicate Key, key for unknown value already "
313 std::vector<uint8_t> val_bytes;
315 unknown.emplace(std::move(key), std::move(val_bytes));
322 throw std::ios_base::failure(
323 "Separator is missing at the end of an output map");
336 std::optional<CMutableTransaction>
tx;
339 std::map<std::vector<uint8_t>, std::vector<uint8_t>>
unknown;
362 template <
typename Stream>
inline void Serialize(Stream &s)
const {
397 throw std::ios_base::failure(
"Invalid PSBT magic bytes");
401 std::set<std::vector<uint8_t>> key_lookup;
404 bool found_sep =
false;
407 std::vector<uint8_t> key;
419 uint8_t type = key[0];
424 if (!key_lookup.emplace(key).second) {
425 throw std::ios_base::failure(
426 "Duplicate Key, unsigned tx already provided");
427 }
else if (key.size() != 1) {
428 throw std::ios_base::failure(
429 "Global unsigned tx key is more than one byte "
436 for (
const CTxIn &txin :
tx->vin) {
438 throw std::ios_base::failure(
439 "Unsigned tx does not have empty scriptSigs.");
447 throw std::ios_base::failure(
448 "Duplicate Key, key for unknown value already "
452 std::vector<uint8_t> val_bytes;
454 unknown.emplace(std::move(key), std::move(val_bytes));
460 throw std::ios_base::failure(
461 "Separator is missing at the end of the global map");
466 throw std::ios_base::failure(
467 "No unsigned transcation was provided");
472 while (!s.empty() && i < tx->vin.size()) {
480 if (
inputs.size() !=
tx->vin.size()) {
481 throw std::ios_base::failure(
"Inputs provided does not match the "
482 "number of inputs in transaction.");
487 while (!s.empty() && i < tx->vout.size()) {
496 throw std::ios_base::failure(
"Outputs provided does not match the "
497 "number of outputs in transaction.");
501 template <
typename Stream>
528 bool use_dummy =
false);
570 const std::vector<PartiallySignedTransaction> &psbtxs);
574 const std::string &base64_psbt,
578 const std::string &raw_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.
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, const std::string &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
constexpr Span< A > MakeSpan(A(&a)[N])
MakeSpan for arrays:
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.
bool error(const char *fmt, const Args &...args)