87 std::vector<unsigned char>
key;
88 std::vector<unsigned char>
value;
100template<
typename Stream,
typename...
X>
110template<
typename Stream,
typename...
X>
114 size_t remaining_before =
s.size();
116 size_t remaining_after =
s.size();
117 if (remaining_after + expected_size != remaining_before) {
118 throw std::ios_base::failure(
"Size of value was not the stated size");
123template<
typename Stream>
127 if (length % 4 || length == 0) {
128 throw std::ios_base::failure(
"Invalid length for HD key path");
133 for (
unsigned int i = 4; i < length; i +=
sizeof(uint32_t)) {
136 hd_keypath.
path.push_back(index);
142template<
typename Stream>
149template<
typename Stream>
150void DeserializeHDKeypaths(Stream&
s,
const std::vector<unsigned char>& key, std::map<CPubKey, KeyOriginInfo>& hd_keypaths)
154 throw std::ios_base::failure(
"Size of key was not the expected size for the type BIP32 keypath");
157 CPubKey pubkey(key.begin() + 1, key.end());
159 throw std::ios_base::failure(
"Invalid pubkey");
161 if (hd_keypaths.contains(pubkey)) {
162 throw std::ios_base::failure(
"Duplicate Key, pubkey derivation path already provided");
169 hd_keypaths.emplace(pubkey, std::move(keypath));
173template<
typename Stream>
177 for (
const auto& path : hd_keypath.
path) {
183template<
typename Stream>
191template<
typename Stream>
194 for (
const auto& keypath_pair : hd_keypaths) {
195 if (!keypath_pair.first.IsValid()) {
196 throw std::ios_base::failure(
"Invalid CPubKey being serialized");
204template<
typename Stream>
207 std::array<unsigned char, CPubKey::COMPRESSED_SIZE> agg_pubkey_bytes;
208 skey >> std::as_writable_bytes(std::span{agg_pubkey_bytes});
209 CPubKey agg_pubkey(agg_pubkey_bytes);
210 if (!agg_pubkey.IsFullyValid()) {
211 throw std::ios_base::failure(context +
" musig2 aggregate pubkey is invalid");
214 std::vector<CPubKey> participants;
215 std::vector<unsigned char> val;
219 std::array<unsigned char, CPubKey::COMPRESSED_SIZE> part_pubkey_bytes;
220 s_val >> std::as_writable_bytes(std::span{part_pubkey_bytes});
221 CPubKey participant(part_pubkey_bytes);
222 if (!participant.IsFullyValid()) {
223 throw std::ios_base::failure(context +
" musig2 participant pubkey is invalid");
225 participants.push_back(participant);
227 if (!s_val.empty()) {
228 throw std::ios_base::failure(context +
" musig2 participants pubkeys value size is not a multiple of 33");
231 out.emplace(agg_pubkey, participants);
236template<
typename Stream>
241 std::array<unsigned char, CPubKey::COMPRESSED_SIZE> part_pubkey_bytes;
242 std::array<unsigned char, CPubKey::COMPRESSED_SIZE> agg_pubkey_bytes;
244 skey >> std::as_writable_bytes(std::span{part_pubkey_bytes}) >> std::as_writable_bytes(std::span{agg_pubkey_bytes});
245 agg_pub.
Set(agg_pubkey_bytes.begin(), agg_pubkey_bytes.end());
247 throw std::ios_base::failure(
"musig2 aggregate pubkey is invalid");
250 part_pub.
Set(part_pubkey_bytes.begin(), part_pubkey_bytes.end());
252 throw std::ios_base::failure(
"musig2 participant pubkey is invalid");
291 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
301 template <
typename Stream>
317 s << sig_pair.second.second;
373 const auto& [xonly, leaf_hash] = pubkey_leaf;
380 const auto& [
script, leaf_ver] = leaf;
381 for (
const auto& control_block : control_blocks) {
383 std::vector<unsigned char> value_v(
script.begin(),
script.end());
384 value_v.push_back((uint8_t)leaf_ver);
391 const auto& [leaf_hashes, origin] = leaf_origin;
393 std::vector<unsigned char> value;
395 s_value << leaf_hashes;
415 std::vector<unsigned char> value;
417 for (
auto&
pk : part_pubs) {
418 s_value << std::span{
pk};
425 const auto& [agg_pubkey, leaf_hash] = agg_pubkey_leaf_hash;
426 for (
const auto& [part_pubkey, pubnonce] : pubnonces) {
427 if (leaf_hash.IsNull()) {
438 const auto& [agg_pubkey, leaf_hash] = agg_pubkey_leaf_hash;
439 for (
const auto& [pubkey, psig] : psigs) {
440 if (leaf_hash.IsNull()) {
477 template <
typename Stream>
480 std::set<std::vector<unsigned char>> key_lookup;
483 bool found_sep =
false;
487 std::vector<unsigned char> key;
507 if (!key_lookup.emplace(key).second) {
508 throw std::ios_base::failure(
"Duplicate Key, input non-witness utxo already provided");
509 }
else if (key.size() != 1) {
510 throw std::ios_base::failure(
"Non-witness utxo key is more than one byte type");
517 if (!key_lookup.emplace(key).second) {
518 throw std::ios_base::failure(
"Duplicate Key, input witness utxo already provided");
519 }
else if (key.size() != 1) {
520 throw std::ios_base::failure(
"Witness utxo key is more than one byte type");
528 throw std::ios_base::failure(
"Size of key was not the expected size for the type partial signature pubkey");
531 CPubKey pubkey(key.begin() + 1, key.end());
533 throw std::ios_base::failure(
"Invalid pubkey");
536 throw std::ios_base::failure(
"Duplicate Key, input partial signature for pubkey already provided");
540 std::vector<unsigned char> sig;
545 throw std::ios_base::failure(
"Signature is not a valid encoding");
553 if (!key_lookup.emplace(key).second) {
554 throw std::ios_base::failure(
"Duplicate Key, input sighash type already provided");
555 }
else if (key.size() != 1) {
556 throw std::ios_base::failure(
"Sighash type key is more than one byte type");
564 if (!key_lookup.emplace(key).second) {
565 throw std::ios_base::failure(
"Duplicate Key, input redeemScript already provided");
566 }
else if (key.size() != 1) {
567 throw std::ios_base::failure(
"Input redeemScript key is more than one byte type");
574 if (!key_lookup.emplace(key).second) {
575 throw std::ios_base::failure(
"Duplicate Key, input witnessScript already provided");
576 }
else if (key.size() != 1) {
577 throw std::ios_base::failure(
"Input witnessScript key is more than one byte type");
589 if (!key_lookup.emplace(key).second) {
590 throw std::ios_base::failure(
"Duplicate Key, input final scriptSig already provided");
591 }
else if (key.size() != 1) {
592 throw std::ios_base::failure(
"Final scriptSig key is more than one byte type");
599 if (!key_lookup.emplace(key).second) {
600 throw std::ios_base::failure(
"Duplicate Key, input final scriptWitness already provided");
601 }
else if (key.size() != 1) {
602 throw std::ios_base::failure(
"Final scriptWitness key is more than one byte type");
611 throw std::ios_base::failure(
"Size of key was not the expected size for the type ripemd160 preimage");
614 std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
617 throw std::ios_base::failure(
"Duplicate Key, input ripemd160 preimage already provided");
621 std::vector<unsigned char> preimage;
632 throw std::ios_base::failure(
"Size of key was not the expected size for the type sha256 preimage");
635 std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
638 throw std::ios_base::failure(
"Duplicate Key, input sha256 preimage already provided");
642 std::vector<unsigned char> preimage;
653 throw std::ios_base::failure(
"Size of key was not the expected size for the type hash160 preimage");
656 std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
659 throw std::ios_base::failure(
"Duplicate Key, input hash160 preimage already provided");
663 std::vector<unsigned char> preimage;
674 throw std::ios_base::failure(
"Size of key was not the expected size for the type hash256 preimage");
677 std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
680 throw std::ios_base::failure(
"Duplicate Key, input hash256 preimage already provided");
684 std::vector<unsigned char> preimage;
693 if (!key_lookup.emplace(key).second) {
694 throw std::ios_base::failure(
"Duplicate Key, input Taproot key signature already provided");
695 }
else if (key.size() != 1) {
696 throw std::ios_base::failure(
"Input Taproot key signature key is more than one byte type");
700 throw std::ios_base::failure(
"Input Taproot key path signature is shorter than 64 bytes");
702 throw std::ios_base::failure(
"Input Taproot key path signature is longer than 65 bytes");
708 if (!key_lookup.emplace(key).second) {
709 throw std::ios_base::failure(
"Duplicate Key, input Taproot script signature already provided");
710 }
else if (key.size() != 65) {
711 throw std::ios_base::failure(
"Input Taproot script signature key is not 65 bytes");
718 std::vector<unsigned char> sig;
720 if (sig.size() < 64) {
721 throw std::ios_base::failure(
"Input Taproot script path signature is shorter than 64 bytes");
722 }
else if (sig.size() > 65) {
723 throw std::ios_base::failure(
"Input Taproot script path signature is longer than 65 bytes");
730 if (!key_lookup.emplace(key).second) {
731 throw std::ios_base::failure(
"Duplicate Key, input Taproot leaf script already provided");
732 }
else if (key.size() < 34) {
733 throw std::ios_base::failure(
"Taproot leaf script key is not at least 34 bytes");
734 }
else if ((key.size() - 2) % 32 != 0) {
735 throw std::ios_base::failure(
"Input Taproot leaf script key's control block size is not valid");
737 std::vector<unsigned char> script_v;
739 if (script_v.empty()) {
740 throw std::ios_base::failure(
"Input Taproot leaf script must be at least 1 byte");
742 uint8_t leaf_ver = script_v.back();
744 const auto leaf_script = std::make_pair(script_v, (
int)leaf_ver);
745 m_tap_scripts[leaf_script].insert(std::vector<unsigned char>(key.begin() + 1, key.end()));
750 if (!key_lookup.emplace(key).second) {
751 throw std::ios_base::failure(
"Duplicate Key, input Taproot BIP32 keypath already provided");
752 }
else if (key.size() != 33) {
753 throw std::ios_base::failure(
"Input Taproot BIP32 keypath key is not at 33 bytes");
758 std::set<uint256> leaf_hashes;
760 size_t before_hashes =
s.size();
762 size_t after_hashes =
s.size();
763 size_t hashes_len = before_hashes - after_hashes;
764 if (hashes_len > value_len) {
765 throw std::ios_base::failure(
"Input Taproot BIP32 keypath has an invalid length");
767 size_t origin_len = value_len - hashes_len;
773 if (!key_lookup.emplace(key).second) {
774 throw std::ios_base::failure(
"Duplicate Key, input Taproot internal key already provided");
775 }
else if (key.size() != 1) {
776 throw std::ios_base::failure(
"Input Taproot internal key key is more than one byte type");
783 if (!key_lookup.emplace(key).second) {
784 throw std::ios_base::failure(
"Duplicate Key, input Taproot merkle root already provided");
785 }
else if (key.size() != 1) {
786 throw std::ios_base::failure(
"Input Taproot merkle root key is more than one byte type");
793 if (!key_lookup.emplace(key).second) {
794 throw std::ios_base::failure(
"Duplicate Key, input participant pubkeys for an aggregate key already provided");
796 throw std::ios_base::failure(
"Input musig2 participants pubkeys aggregate key is not 34 bytes");
803 if (!key_lookup.emplace(key).second) {
804 throw std::ios_base::failure(
"Duplicate Key, input musig2 pubnonce already provided");
806 throw std::ios_base::failure(
"Input musig2 pubnonce key is not expected size of 67 or 99 bytes");
812 std::vector<uint8_t> pubnonce;
815 throw std::ios_base::failure(
"Input musig2 pubnonce value is not 66 bytes");
823 if (!key_lookup.emplace(key).second) {
824 throw std::ios_base::failure(
"Duplicate Key, input musig2 partial sig already provided");
826 throw std::ios_base::failure(
"Input musig2 partial sig key is not expected size of 67 or 99 bytes");
846 throw std::ios_base::failure(
"Duplicate Key, proprietary key already found");
855 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
858 std::vector<unsigned char> val_bytes;
860 unknown.emplace(std::move(key), std::move(val_bytes));
866 throw std::ios_base::failure(
"Separator is missing at the end of an input map");
870 template <
typename Stream>
883 std::vector<std::tuple<uint8_t, uint8_t, std::vector<unsigned char>>>
m_tap_tree;
886 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
895 template <
typename Stream>
927 std::vector<unsigned char> value;
939 const auto& [leaf_hashes, origin] = leaf;
941 std::vector<unsigned char> value;
943 s_value << leaf_hashes;
951 std::vector<unsigned char> value;
953 for (
auto&
pk : part_pubs) {
954 s_value << std::span{
pk};
969 template <
typename Stream>
972 std::set<std::vector<unsigned char>> key_lookup;
975 bool found_sep =
false;
979 std::vector<unsigned char> key;
999 if (!key_lookup.emplace(key).second) {
1000 throw std::ios_base::failure(
"Duplicate Key, output redeemScript already provided");
1001 }
else if (key.size() != 1) {
1002 throw std::ios_base::failure(
"Output redeemScript key is more than one byte type");
1009 if (!key_lookup.emplace(key).second) {
1010 throw std::ios_base::failure(
"Duplicate Key, output witnessScript already provided");
1011 }
else if (key.size() != 1) {
1012 throw std::ios_base::failure(
"Output witnessScript key is more than one byte type");
1024 if (!key_lookup.emplace(key).second) {
1025 throw std::ios_base::failure(
"Duplicate Key, output Taproot internal key already provided");
1026 }
else if (key.size() != 1) {
1027 throw std::ios_base::failure(
"Output Taproot internal key key is more than one byte type");
1034 if (!key_lookup.emplace(key).second) {
1035 throw std::ios_base::failure(
"Duplicate Key, output Taproot tree already provided");
1036 }
else if (key.size() != 1) {
1037 throw std::ios_base::failure(
"Output Taproot tree key is more than one byte type");
1039 std::vector<unsigned char> tree_v;
1042 if (s_tree.empty()) {
1043 throw std::ios_base::failure(
"Output Taproot tree must not be empty");
1046 while (!s_tree.empty()) {
1049 std::vector<unsigned char>
script;
1054 throw std::ios_base::failure(
"Output Taproot tree has as leaf greater than Taproot maximum depth");
1057 throw std::ios_base::failure(
"Output Taproot tree has a leaf with an invalid leaf version");
1060 builder.
Add((
int)depth,
script, (
int)leaf_ver,
true);
1063 throw std::ios_base::failure(
"Output Taproot tree is malformed");
1069 if (!key_lookup.emplace(key).second) {
1070 throw std::ios_base::failure(
"Duplicate Key, output Taproot BIP32 keypath already provided");
1071 }
else if (key.size() != 33) {
1072 throw std::ios_base::failure(
"Output Taproot BIP32 keypath key is not at 33 bytes");
1075 std::set<uint256> leaf_hashes;
1077 size_t before_hashes =
s.size();
1079 size_t after_hashes =
s.size();
1080 size_t hashes_len = before_hashes - after_hashes;
1081 if (hashes_len > value_len) {
1082 throw std::ios_base::failure(
"Output Taproot BIP32 keypath has an invalid length");
1084 size_t origin_len = value_len - hashes_len;
1090 if (!key_lookup.emplace(key).second) {
1091 throw std::ios_base::failure(
"Duplicate Key, output participant pubkeys for an aggregate key already provided");
1093 throw std::ios_base::failure(
"Output musig2 participants pubkeys aggregate key is not 34 bytes");
1103 this_prop.
key = key;
1106 throw std::ios_base::failure(
"Duplicate Key, proprietary key already found");
1115 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
1118 std::vector<unsigned char> val_bytes;
1120 unknown.emplace(std::move(key), std::move(val_bytes));
1127 throw std::ios_base::failure(
"Separator is missing at the end of an output map");
1131 template <
typename Stream>
1140 std::optional<CMutableTransaction>
tx;
1143 std::map<KeyOriginInfo, std::set<CExtPubKey>>
m_xpubs;
1146 std::map<std::vector<unsigned char>, std::vector<unsigned char>>
unknown;
1169 template <
typename Stream>
1182 for (
const auto& xpub_pair :
m_xpubs) {
1183 for (
const auto& xpub : xpub_pair.second) {
1185 xpub.EncodeWithVersion(ser_xpub);
1225 template <
typename Stream>
1231 throw std::ios_base::failure(
"Invalid PSBT magic bytes");
1235 std::set<std::vector<unsigned char>> key_lookup;
1238 std::set<CExtPubKey> global_xpubs;
1241 bool found_sep =
false;
1245 std::vector<unsigned char> key;
1265 if (!key_lookup.emplace(key).second) {
1266 throw std::ios_base::failure(
"Duplicate Key, unsigned tx already provided");
1267 }
else if (key.size() != 1) {
1268 throw std::ios_base::failure(
"Global unsigned tx key is more than one byte type");
1273 tx = std::move(mtx);
1275 for (
const CTxIn& txin :
tx->vin) {
1277 throw std::ios_base::failure(
"Unsigned tx does not have empty scriptSigs and scriptWitnesses.");
1285 throw std::ios_base::failure(
"Size of key was not the expected size for the type global xpub");
1291 throw std::ios_base::failure(
"Invalid pubkey");
1293 if (global_xpubs.contains(xpub)) {
1294 throw std::ios_base::failure(
"Duplicate key, global xpub already provided");
1296 global_xpubs.insert(xpub);
1303 if (!
m_xpubs.contains(keypath)) {
1308 m_xpubs[keypath].insert(xpub);
1315 throw std::ios_base::failure(
"Duplicate Key, version already provided");
1316 }
else if (key.size() != 1) {
1317 throw std::ios_base::failure(
"Global version key is more than one byte type");
1323 throw std::ios_base::failure(
"Unsupported version number");
1332 this_prop.
key = key;
1335 throw std::ios_base::failure(
"Duplicate Key, proprietary key already found");
1344 throw std::ios_base::failure(
"Duplicate Key, key for unknown value already provided");
1347 std::vector<unsigned char> val_bytes;
1349 unknown.emplace(std::move(key), std::move(val_bytes));
1355 throw std::ios_base::failure(
"Separator is missing at the end of the global map");
1360 throw std::ios_base::failure(
"No unsigned transaction was provided");
1365 while (!
s.empty() && i < tx->vin.size()) {
1373 throw std::ios_base::failure(
"Non-witness UTXO does not match outpoint hash");
1376 throw std::ios_base::failure(
"Input specifies output index that does not exist");
1382 if (
inputs.size() !=
tx->vin.size()) {
1383 throw std::ios_base::failure(
"Inputs provided does not match the number of inputs in transaction.");
1388 while (!
s.empty() && i < tx->vout.size()) {
1395 if (
outputs.size() !=
tx->vout.size()) {
1396 throw std::ios_base::failure(
"Outputs provided does not match the number of outputs in transaction.");
1400 template <
typename Stream>
static const size_t OUTPUT_SIZE
static const size_t OUTPUT_SIZE
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())
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
static const size_t OUTPUT_SIZE
static const size_t OUTPUT_SIZE
Serialized script, used inside transaction inputs and outputs.
An input of a transaction.
CScriptWitness scriptWitness
Only serialized through CTransaction.
An output of a transaction.
An interface to be implemented by keystores that support signing.
Minimal stream for reading from an existing byte array by std::span.
Utility class to construct Taproot outputs from internal key and script tree.
bool IsComplete() const
Return whether there were either no leaves, or the leaves form a Huffman tree.
TaprootBuilder & Add(int depth, std::span< const unsigned char > script, int leaf_version, bool track=true)
Add a new script at a certain depth in the tree.
bool IsNull() const
Test whether this is the 0 key (the result of default construction).
constexpr bool IsNull() const
is a home for simple enum and struct type definitions that can be used internally by functions in the...
bool CheckSignatureEncoding(const std::vector< unsigned char > &vchSig, script_verify_flags flags, ScriptError *serror)
static constexpr uint8_t TAPROOT_LEAF_MASK
static constexpr size_t TAPROOT_CONTROL_MAX_NODE_COUNT
@ SCRIPT_VERIFY_STRICTENC
constexpr size_t MUSIG2_PUBNONCE_SIZE
static constexpr TransactionSerParams TX_NO_WITNESS
static constexpr TransactionSerParams TX_WITH_WITNESS
std::shared_ptr< const CTransaction > CTransactionRef
void SerializeToVector(Stream &s, const X &... args)
static constexpr uint8_t PSBT_IN_RIPEMD160
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
static constexpr uint8_t PSBT_IN_HASH256
static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX
static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO
static constexpr uint8_t PSBT_IN_TAP_KEY_SIG
void UnserializeFromVector(Stream &s, X &&... args)
static constexpr uint8_t PSBT_IN_SCRIPTSIG
static constexpr uint8_t PSBT_IN_WITNESSSCRIPT
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.
std::string PSBTRoleName(PSBTRole role)
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT
static constexpr uint8_t PSBT_GLOBAL_VERSION
static constexpr uint8_t PSBT_IN_TAP_LEAF_SCRIPT
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_OUT_PROPRIETARY
static constexpr uint8_t PSBT_MAGIC_BYTES[5]
static constexpr uint32_t PSBT_HIGHEST_VERSION
static constexpr uint8_t PSBT_SEPARATOR
static constexpr uint8_t PSBT_IN_BIP32_DERIVATION
void DeserializeMuSig2ParticipantPubkeys(Stream &s, SpanReader &skey, std::map< CPubKey, std::vector< CPubKey > > &out, std::string context)
static constexpr uint8_t PSBT_IN_SCRIPTWITNESS
static constexpr uint8_t PSBT_OUT_TAP_TREE
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION
static constexpr uint8_t PSBT_GLOBAL_PROPRIETARY
void RemoveUnnecessaryTransactions(PartiallySignedTransaction &psbtx)
Reduces the size of the PSBT by dropping unnecessary non_witness_utxos (i.e.
static constexpr uint8_t PSBT_IN_PROPRIETARY
KeyOriginInfo DeserializeKeyOrigin(Stream &s, uint64_t length)
PSBTError SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, const PrecomputedTransactionData *txdata, std::optional< int > sighash=std::nullopt, SignatureData *out_sigdata=nullptr, bool finalize=true)
Signs a PSBTInput, verifying that all provided data matches what is being signed.
void DeserializeMuSig2ParticipantDataIdentifier(Stream &skey, CPubKey &agg_pub, CPubKey &part_pub, uint256 &leaf_hash)
static constexpr uint8_t PSBT_IN_TAP_SCRIPT_SIG
static constexpr uint8_t PSBT_IN_MUSIG2_PUB_NONCE
void SerializeHDKeypaths(Stream &s, const std::map< CPubKey, KeyOriginInfo > &hd_keypaths, CompactSizeWriter type)
static constexpr uint8_t PSBT_IN_TAP_BIP32_DERIVATION
static constexpr uint8_t PSBT_IN_HASH160
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_OUT_WITNESSSCRIPT
static constexpr uint8_t PSBT_GLOBAL_XPUB
static constexpr uint8_t PSBT_OUT_MUSIG2_PARTICIPANT_PUBKEYS
static constexpr uint8_t PSBT_OUT_TAP_BIP32_DERIVATION
static constexpr uint8_t PSBT_IN_PARTIAL_SIG
static constexpr uint8_t PSBT_IN_TAP_INTERNAL_KEY
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
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_OUT_TAP_INTERNAL_KEY
bool DecodeRawPSBT(PartiallySignedTransaction &decoded_psbt, std::span< const std::byte > raw_psbt, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
static constexpr uint8_t PSBT_IN_TAP_MERKLE_ROOT
void SerializeKeyOrigin(Stream &s, KeyOriginInfo hd_keypath)
void DeserializeHDKeypaths(Stream &s, const std::vector< unsigned char > &key, std::map< CPubKey, KeyOriginInfo > &hd_keypaths)
static constexpr uint8_t PSBT_IN_SIGHASH
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed by checking for non-null finalized fields.
static constexpr uint8_t PSBT_IN_MUSIG2_PARTICIPANT_PUBKEYS
void SerializeHDKeypath(Stream &s, KeyOriginInfo hd_keypath)
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.
void DeserializeHDKeypath(Stream &s, KeyOriginInfo &hd_keypath)
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
const std::streamsize MAX_FILE_SIZE_PSBT
static constexpr uint8_t PSBT_IN_WITNESS_UTXO
static constexpr uint8_t PSBT_IN_MUSIG2_PARTIAL_SIG
static constexpr uint8_t PSBT_IN_SHA256
const unsigned int BIP32_EXTKEY_WITH_VERSION_SIZE
std::vector< unsigned char > ToByteVector(const T &in)
void SerializeMany(Stream &s, const Args &... args)
Support for (un)serializing many things at once.
void UnserializeMany(Stream &s, Args &&... args)
void WriteCompactSize(SizeComputer &os, uint64_t nSize)
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
std::pair< CPubKey, std::vector< unsigned char > > SigPair
void DecodeWithVersion(const unsigned char code[BIP32_EXTKEY_WITH_VERSION_SIZE])
A mutable version of CTransaction.
std::vector< std::vector< unsigned char > > stack
unsigned char fingerprint[4]
First 32 bits of the Hash160 of the public key at the root of the path.
std::vector< uint32_t > path
A structure for PSBTs which contains per output information.
std::map< CPubKey, std::vector< CPubKey > > m_musig2_participants
XOnlyPubKey m_tap_internal_key
std::map< XOnlyPubKey, std::pair< std::set< uint256 >, KeyOriginInfo > > m_tap_bip32_paths
void Merge(const PSBTOutput &output)
std::set< PSBTProprietary > m_proprietary
void Serialize(Stream &s) const
PSBTOutput(deserialize_type, Stream &s)
std::map< CPubKey, KeyOriginInfo > hd_keypaths
std::vector< std::tuple< uint8_t, uint8_t, std::vector< unsigned char > > > m_tap_tree
void Unserialize(Stream &s)
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
void FillSignatureData(SignatureData &sigdata) const
void FromSignatureData(const SignatureData &sigdata)
A structure for PSBT proprietary types.
std::vector< unsigned char > value
bool operator<(const PSBTProprietary &b) const
std::vector< unsigned char > identifier
std::vector< unsigned char > key
bool operator==(const PSBTProprietary &b) const
A version of CTransaction with the PSBT format.
uint32_t GetVersion() const
bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
std::map< KeyOriginInfo, std::set< CExtPubKey > > m_xpubs
std::optional< uint32_t > m_version
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
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
std::set< PSBTProprietary > m_proprietary
void Serialize(Stream &s) const
PartiallySignedTransaction(deserialize_type, Stream &s)
void Unserialize(Stream &s)
Dummy data type to identify deserializing constructors.