Bitcoin Core  22.99.0
P2P Digital Currency
psbt.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_PSBT_H
6 #define BITCOIN_PSBT_H
7 
8 #include <attributes.h>
9 #include <node/transaction.h>
10 #include <policy/feerate.h>
11 #include <primitives/transaction.h>
12 #include <pubkey.h>
13 #include <script/keyorigin.h>
14 #include <script/sign.h>
15 #include <script/signingprovider.h>
16 #include <span.h>
17 #include <streams.h>
18 
19 #include <optional>
20 
21 // Magic bytes
22 static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff};
23 
24 // Global types
25 static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX = 0x00;
26 static constexpr uint8_t PSBT_GLOBAL_XPUB = 0x01;
27 static constexpr uint8_t PSBT_GLOBAL_VERSION = 0xFB;
28 static constexpr uint8_t PSBT_GLOBAL_PROPRIETARY = 0xFC;
29 
30 // Input types
31 static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO = 0x00;
32 static constexpr uint8_t PSBT_IN_WITNESS_UTXO = 0x01;
33 static constexpr uint8_t PSBT_IN_PARTIAL_SIG = 0x02;
34 static constexpr uint8_t PSBT_IN_SIGHASH = 0x03;
35 static constexpr uint8_t PSBT_IN_REDEEMSCRIPT = 0x04;
36 static constexpr uint8_t PSBT_IN_WITNESSSCRIPT = 0x05;
37 static constexpr uint8_t PSBT_IN_BIP32_DERIVATION = 0x06;
38 static constexpr uint8_t PSBT_IN_SCRIPTSIG = 0x07;
39 static constexpr uint8_t PSBT_IN_SCRIPTWITNESS = 0x08;
40 static constexpr uint8_t PSBT_IN_RIPEMD160 = 0x0A;
41 static constexpr uint8_t PSBT_IN_SHA256 = 0x0B;
42 static constexpr uint8_t PSBT_IN_HASH160 = 0x0C;
43 static constexpr uint8_t PSBT_IN_HASH256 = 0x0D;
44 static constexpr uint8_t PSBT_IN_PROPRIETARY = 0xFC;
45 
46 // Output types
47 static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT = 0x00;
48 static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT = 0x01;
49 static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02;
50 static constexpr uint8_t PSBT_OUT_PROPRIETARY = 0xFC;
51 
52 // The separator is 0x00. Reading this in means that the unserializer can interpret it
53 // as a 0 length key which indicates that this is the separator. The separator has no value.
54 static constexpr uint8_t PSBT_SEPARATOR = 0x00;
55 
56 // BIP 174 does not specify a maximum file size, but we set a limit anyway
57 // to prevent reading a stream indefinitely and running out of memory.
58 const std::streamsize MAX_FILE_SIZE_PSBT = 100000000; // 100 MiB
59 
60 // PSBT version number
61 static constexpr uint32_t PSBT_HIGHEST_VERSION = 0;
62 
65 {
66  uint64_t subtype;
67  std::vector<unsigned char> identifier;
68  std::vector<unsigned char> key;
69  std::vector<unsigned char> value;
70 
71  bool operator<(const PSBTProprietary &b) const {
72  return key < b.key;
73  }
74  bool operator==(const PSBTProprietary &b) const {
75  return key == b.key;
76  }
77 };
78 
79 // Takes a stream and multiple arguments and serializes them as if first serialized into a vector and then into the stream
80 // The resulting output into the stream has the total serialized length of all of the objects followed by all objects concatenated with each other.
81 template<typename Stream, typename... X>
82 void SerializeToVector(Stream& s, const X&... args)
83 {
84  WriteCompactSize(s, GetSerializeSizeMany(s.GetVersion(), args...));
85  SerializeMany(s, args...);
86 }
87 
88 // Takes a stream and multiple arguments and unserializes them first as a vector then each object individually in the order provided in the arguments
89 template<typename Stream, typename... X>
90 void UnserializeFromVector(Stream& s, X&... args)
91 {
92  size_t expected_size = ReadCompactSize(s);
93  size_t remaining_before = s.size();
94  UnserializeMany(s, args...);
95  size_t remaining_after = s.size();
96  if (remaining_after + expected_size != remaining_before) {
97  throw std::ios_base::failure("Size of value was not the stated size");
98  }
99 }
100 
101 // Deserialize an individual HD keypath to a stream
102 template<typename Stream>
103 void DeserializeHDKeypath(Stream& s, KeyOriginInfo& hd_keypath)
104 {
105  // Read in key path
106  uint64_t value_len = ReadCompactSize(s);
107  if (value_len % 4 || value_len == 0) {
108  throw std::ios_base::failure("Invalid length for HD key path");
109  }
110 
111  s >> hd_keypath.fingerprint;
112  for (unsigned int i = 4; i < value_len; i += sizeof(uint32_t)) {
113  uint32_t index;
114  s >> index;
115  hd_keypath.path.push_back(index);
116  }
117 }
118 
119 // Deserialize HD keypaths into a map
120 template<typename Stream>
121 void DeserializeHDKeypaths(Stream& s, const std::vector<unsigned char>& key, std::map<CPubKey, KeyOriginInfo>& hd_keypaths)
122 {
123  // Make sure that the key is the size of pubkey + 1
124  if (key.size() != CPubKey::SIZE + 1 && key.size() != CPubKey::COMPRESSED_SIZE + 1) {
125  throw std::ios_base::failure("Size of key was not the expected size for the type BIP32 keypath");
126  }
127  // Read in the pubkey from key
128  CPubKey pubkey(key.begin() + 1, key.end());
129  if (!pubkey.IsFullyValid()) {
130  throw std::ios_base::failure("Invalid pubkey");
131  }
132  if (hd_keypaths.count(pubkey) > 0) {
133  throw std::ios_base::failure("Duplicate Key, pubkey derivation path already provided");
134  }
135 
136  KeyOriginInfo keypath;
137  DeserializeHDKeypath(s, keypath);
138 
139  // Add to map
140  hd_keypaths.emplace(pubkey, std::move(keypath));
141 }
142 
143 // Serialize an individual HD keypath to a stream
144 template<typename Stream>
145 void SerializeHDKeypath(Stream& s, KeyOriginInfo hd_keypath)
146 {
147  WriteCompactSize(s, (hd_keypath.path.size() + 1) * sizeof(uint32_t));
148  s << hd_keypath.fingerprint;
149  for (const auto& path : hd_keypath.path) {
150  s << path;
151  }
152 }
153 
154 // Serialize HD keypaths to a stream from a map
155 template<typename Stream>
156 void SerializeHDKeypaths(Stream& s, const std::map<CPubKey, KeyOriginInfo>& hd_keypaths, CompactSizeWriter type)
157 {
158  for (auto keypath_pair : hd_keypaths) {
159  if (!keypath_pair.first.IsValid()) {
160  throw std::ios_base::failure("Invalid CPubKey being serialized");
161  }
162  SerializeToVector(s, type, Span{keypath_pair.first});
163  SerializeHDKeypath(s, keypath_pair.second);
164  }
165 }
166 
168 struct PSBTInput
169 {
176  std::map<CPubKey, KeyOriginInfo> hd_keypaths;
177  std::map<CKeyID, SigPair> partial_sigs;
178  std::map<uint160, std::vector<unsigned char>> ripemd160_preimages;
179  std::map<uint256, std::vector<unsigned char>> sha256_preimages;
180  std::map<uint160, std::vector<unsigned char>> hash160_preimages;
181  std::map<uint256, std::vector<unsigned char>> hash256_preimages;
182  std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
183  std::set<PSBTProprietary> m_proprietary;
184  std::optional<int> sighash_type;
185 
186  bool IsNull() const;
187  void FillSignatureData(SignatureData& sigdata) const;
188  void FromSignatureData(const SignatureData& sigdata);
189  void Merge(const PSBTInput& input);
191 
192  template <typename Stream>
193  inline void Serialize(Stream& s) const {
194  // Write the utxo
195  if (non_witness_utxo) {
197  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
199  }
200  if (!witness_utxo.IsNull()) {
203  }
204 
206  // Write any partial signatures
207  for (auto sig_pair : partial_sigs) {
209  s << sig_pair.second.second;
210  }
211 
212  // Write the sighash type
213  if (sighash_type != std::nullopt) {
216  }
217 
218  // Write the redeem script
219  if (!redeem_script.empty()) {
221  s << redeem_script;
222  }
223 
224  // Write the witness script
225  if (!witness_script.empty()) {
227  s << witness_script;
228  }
229 
230  // Write any hd keypaths
232 
233  // Write any ripemd160 preimage
234  for (const auto& [hash, preimage] : ripemd160_preimages) {
236  s << preimage;
237  }
238 
239  // Write any sha256 preimage
240  for (const auto& [hash, preimage] : sha256_preimages) {
242  s << preimage;
243  }
244 
245  // Write any hash160 preimage
246  for (const auto& [hash, preimage] : hash160_preimages) {
248  s << preimage;
249  }
250 
251  // Write any hash256 preimage
252  for (const auto& [hash, preimage] : hash256_preimages) {
254  s << preimage;
255  }
256  }
257 
258  // Write script sig
259  if (!final_script_sig.empty()) {
261  s << final_script_sig;
262  }
263  // write script witness
264  if (!final_script_witness.IsNull()) {
267  }
268 
269  // Write proprietary things
270  for (const auto& entry : m_proprietary) {
271  s << entry.key;
272  s << entry.value;
273  }
274 
275  // Write unknown things
276  for (auto& entry : unknown) {
277  s << entry.first;
278  s << entry.second;
279  }
280 
281  s << PSBT_SEPARATOR;
282  }
283 
284 
285  template <typename Stream>
286  inline void Unserialize(Stream& s) {
287  // Used for duplicate key detection
288  std::set<std::vector<unsigned char>> key_lookup;
289 
290  // Read loop
291  bool found_sep = false;
292  while(!s.empty()) {
293  // Read
294  std::vector<unsigned char> key;
295  s >> key;
296 
297  // the key is empty if that was actually a separator byte
298  // This is a special case for key lengths 0 as those are not allowed (except for separator)
299  if (key.empty()) {
300  found_sep = true;
301  break;
302  }
303 
304  // Type is compact size uint at beginning of key
305  SpanReader skey(s.GetType(), s.GetVersion(), key);
306  uint64_t type = ReadCompactSize(skey);
307 
308  // Do stuff based on type
309  switch(type) {
311  {
312  if (!key_lookup.emplace(key).second) {
313  throw std::ios_base::failure("Duplicate Key, input non-witness utxo already provided");
314  } else if (key.size() != 1) {
315  throw std::ios_base::failure("Non-witness utxo key is more than one byte type");
316  }
317  // Set the stream to unserialize with witness since this is always a valid network transaction
318  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() & ~SERIALIZE_TRANSACTION_NO_WITNESS);
320  break;
321  }
323  if (!key_lookup.emplace(key).second) {
324  throw std::ios_base::failure("Duplicate Key, input witness utxo already provided");
325  } else if (key.size() != 1) {
326  throw std::ios_base::failure("Witness utxo key is more than one byte type");
327  }
329  break;
330  case PSBT_IN_PARTIAL_SIG:
331  {
332  // Make sure that the key is the size of pubkey + 1
333  if (key.size() != CPubKey::SIZE + 1 && key.size() != CPubKey::COMPRESSED_SIZE + 1) {
334  throw std::ios_base::failure("Size of key was not the expected size for the type partial signature pubkey");
335  }
336  // Read in the pubkey from key
337  CPubKey pubkey(key.begin() + 1, key.end());
338  if (!pubkey.IsFullyValid()) {
339  throw std::ios_base::failure("Invalid pubkey");
340  }
341  if (partial_sigs.count(pubkey.GetID()) > 0) {
342  throw std::ios_base::failure("Duplicate Key, input partial signature for pubkey already provided");
343  }
344 
345  // Read in the signature from value
346  std::vector<unsigned char> sig;
347  s >> sig;
348 
349  // Add to list
350  partial_sigs.emplace(pubkey.GetID(), SigPair(pubkey, std::move(sig)));
351  break;
352  }
353  case PSBT_IN_SIGHASH:
354  if (!key_lookup.emplace(key).second) {
355  throw std::ios_base::failure("Duplicate Key, input sighash type already provided");
356  } else if (key.size() != 1) {
357  throw std::ios_base::failure("Sighash type key is more than one byte type");
358  }
359  int sighash;
360  UnserializeFromVector(s, sighash);
361  sighash_type = sighash;
362  break;
364  {
365  if (!key_lookup.emplace(key).second) {
366  throw std::ios_base::failure("Duplicate Key, input redeemScript already provided");
367  } else if (key.size() != 1) {
368  throw std::ios_base::failure("Input redeemScript key is more than one byte type");
369  }
370  s >> redeem_script;
371  break;
372  }
374  {
375  if (!key_lookup.emplace(key).second) {
376  throw std::ios_base::failure("Duplicate Key, input witnessScript already provided");
377  } else if (key.size() != 1) {
378  throw std::ios_base::failure("Input witnessScript key is more than one byte type");
379  }
380  s >> witness_script;
381  break;
382  }
384  {
386  break;
387  }
388  case PSBT_IN_SCRIPTSIG:
389  {
390  if (!key_lookup.emplace(key).second) {
391  throw std::ios_base::failure("Duplicate Key, input final scriptSig already provided");
392  } else if (key.size() != 1) {
393  throw std::ios_base::failure("Final scriptSig key is more than one byte type");
394  }
395  s >> final_script_sig;
396  break;
397  }
399  {
400  if (!key_lookup.emplace(key).second) {
401  throw std::ios_base::failure("Duplicate Key, input final scriptWitness already provided");
402  } else if (key.size() != 1) {
403  throw std::ios_base::failure("Final scriptWitness key is more than one byte type");
404  }
406  break;
407  }
408  case PSBT_IN_RIPEMD160:
409  {
410  // Make sure that the key is the size of a ripemd160 hash + 1
411  if (key.size() != CRIPEMD160::OUTPUT_SIZE + 1) {
412  throw std::ios_base::failure("Size of key was not the expected size for the type ripemd160 preimage");
413  }
414  // Read in the hash from key
415  std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
416  uint160 hash(hash_vec);
417  if (ripemd160_preimages.count(hash) > 0) {
418  throw std::ios_base::failure("Duplicate Key, input ripemd160 preimage already provided");
419  }
420 
421  // Read in the preimage from value
422  std::vector<unsigned char> preimage;
423  s >> preimage;
424 
425  // Add to preimages list
426  ripemd160_preimages.emplace(hash, std::move(preimage));
427  break;
428  }
429  case PSBT_IN_SHA256:
430  {
431  // Make sure that the key is the size of a sha256 hash + 1
432  if (key.size() != CSHA256::OUTPUT_SIZE + 1) {
433  throw std::ios_base::failure("Size of key was not the expected size for the type sha256 preimage");
434  }
435  // Read in the hash from key
436  std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
437  uint256 hash(hash_vec);
438  if (sha256_preimages.count(hash) > 0) {
439  throw std::ios_base::failure("Duplicate Key, input sha256 preimage already provided");
440  }
441 
442  // Read in the preimage from value
443  std::vector<unsigned char> preimage;
444  s >> preimage;
445 
446  // Add to preimages list
447  sha256_preimages.emplace(hash, std::move(preimage));
448  break;
449  }
450  case PSBT_IN_HASH160:
451  {
452  // Make sure that the key is the size of a hash160 hash + 1
453  if (key.size() != CHash160::OUTPUT_SIZE + 1) {
454  throw std::ios_base::failure("Size of key was not the expected size for the type hash160 preimage");
455  }
456  // Read in the hash from key
457  std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
458  uint160 hash(hash_vec);
459  if (hash160_preimages.count(hash) > 0) {
460  throw std::ios_base::failure("Duplicate Key, input hash160 preimage already provided");
461  }
462 
463  // Read in the preimage from value
464  std::vector<unsigned char> preimage;
465  s >> preimage;
466 
467  // Add to preimages list
468  hash160_preimages.emplace(hash, std::move(preimage));
469  break;
470  }
471  case PSBT_IN_HASH256:
472  {
473  // Make sure that the key is the size of a hash256 hash + 1
474  if (key.size() != CHash256::OUTPUT_SIZE + 1) {
475  throw std::ios_base::failure("Size of key was not the expected size for the type hash256 preimage");
476  }
477  // Read in the hash from key
478  std::vector<unsigned char> hash_vec(key.begin() + 1, key.end());
479  uint256 hash(hash_vec);
480  if (hash256_preimages.count(hash) > 0) {
481  throw std::ios_base::failure("Duplicate Key, input hash256 preimage already provided");
482  }
483 
484  // Read in the preimage from value
485  std::vector<unsigned char> preimage;
486  s >> preimage;
487 
488  // Add to preimages list
489  hash256_preimages.emplace(hash, std::move(preimage));
490  break;
491  }
492  case PSBT_IN_PROPRIETARY:
493  {
494  PSBTProprietary this_prop;
495  skey >> this_prop.identifier;
496  this_prop.subtype = ReadCompactSize(skey);
497  this_prop.key = key;
498 
499  if (m_proprietary.count(this_prop) > 0) {
500  throw std::ios_base::failure("Duplicate Key, proprietary key already found");
501  }
502  s >> this_prop.value;
503  m_proprietary.insert(this_prop);
504  break;
505  }
506  // Unknown stuff
507  default:
508  if (unknown.count(key) > 0) {
509  throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
510  }
511  // Read in the value
512  std::vector<unsigned char> val_bytes;
513  s >> val_bytes;
514  unknown.emplace(std::move(key), std::move(val_bytes));
515  break;
516  }
517  }
518 
519  if (!found_sep) {
520  throw std::ios_base::failure("Separator is missing at the end of an input map");
521  }
522  }
523 
524  template <typename Stream>
526  Unserialize(s);
527  }
528 };
529 
532 {
535  std::map<CPubKey, KeyOriginInfo> hd_keypaths;
536  std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
537  std::set<PSBTProprietary> m_proprietary;
538 
539  bool IsNull() const;
540  void FillSignatureData(SignatureData& sigdata) const;
541  void FromSignatureData(const SignatureData& sigdata);
542  void Merge(const PSBTOutput& output);
544 
545  template <typename Stream>
546  inline void Serialize(Stream& s) const {
547  // Write the redeem script
548  if (!redeem_script.empty()) {
550  s << redeem_script;
551  }
552 
553  // Write the witness script
554  if (!witness_script.empty()) {
556  s << witness_script;
557  }
558 
559  // Write any hd keypaths
561 
562  // Write proprietary things
563  for (const auto& entry : m_proprietary) {
564  s << entry.key;
565  s << entry.value;
566  }
567 
568  // Write unknown things
569  for (auto& entry : unknown) {
570  s << entry.first;
571  s << entry.second;
572  }
573 
574  s << PSBT_SEPARATOR;
575  }
576 
577 
578  template <typename Stream>
579  inline void Unserialize(Stream& s) {
580  // Used for duplicate key detection
581  std::set<std::vector<unsigned char>> key_lookup;
582 
583  // Read loop
584  bool found_sep = false;
585  while(!s.empty()) {
586  // Read
587  std::vector<unsigned char> key;
588  s >> key;
589 
590  // the key is empty if that was actually a separator byte
591  // This is a special case for key lengths 0 as those are not allowed (except for separator)
592  if (key.empty()) {
593  found_sep = true;
594  break;
595  }
596 
597  // Type is compact size uint at beginning of key
598  SpanReader skey(s.GetType(), s.GetVersion(), key);
599  uint64_t type = ReadCompactSize(skey);
600 
601  // Do stuff based on type
602  switch(type) {
604  {
605  if (!key_lookup.emplace(key).second) {
606  throw std::ios_base::failure("Duplicate Key, output redeemScript already provided");
607  } else if (key.size() != 1) {
608  throw std::ios_base::failure("Output redeemScript key is more than one byte type");
609  }
610  s >> redeem_script;
611  break;
612  }
614  {
615  if (!key_lookup.emplace(key).second) {
616  throw std::ios_base::failure("Duplicate Key, output witnessScript already provided");
617  } else if (key.size() != 1) {
618  throw std::ios_base::failure("Output witnessScript key is more than one byte type");
619  }
620  s >> witness_script;
621  break;
622  }
624  {
626  break;
627  }
629  {
630  PSBTProprietary this_prop;
631  skey >> this_prop.identifier;
632  this_prop.subtype = ReadCompactSize(skey);
633  this_prop.key = key;
634 
635  if (m_proprietary.count(this_prop) > 0) {
636  throw std::ios_base::failure("Duplicate Key, proprietary key already found");
637  }
638  s >> this_prop.value;
639  m_proprietary.insert(this_prop);
640  break;
641  }
642  // Unknown stuff
643  default: {
644  if (unknown.count(key) > 0) {
645  throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
646  }
647  // Read in the value
648  std::vector<unsigned char> val_bytes;
649  s >> val_bytes;
650  unknown.emplace(std::move(key), std::move(val_bytes));
651  break;
652  }
653  }
654  }
655 
656  if (!found_sep) {
657  throw std::ios_base::failure("Separator is missing at the end of an output map");
658  }
659  }
660 
661  template <typename Stream>
663  Unserialize(s);
664  }
665 };
666 
669 {
670  std::optional<CMutableTransaction> tx;
671  // We use a vector of CExtPubKey in the event that there happens to be the same KeyOriginInfos for different CExtPubKeys
672  // Note that this map swaps the key and values from the serialization
673  std::map<KeyOriginInfo, std::set<CExtPubKey>> m_xpubs;
674  std::vector<PSBTInput> inputs;
675  std::vector<PSBTOutput> outputs;
676  std::map<std::vector<unsigned char>, std::vector<unsigned char>> unknown;
677  std::optional<uint32_t> m_version;
678  std::set<PSBTProprietary> m_proprietary;
679 
680  bool IsNull() const;
681  uint32_t GetVersion() const;
682 
685  [[nodiscard]] bool Merge(const PartiallySignedTransaction& psbt);
686  bool AddInput(const CTxIn& txin, PSBTInput& psbtin);
687  bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout);
697  bool GetInputUTXO(CTxOut& utxo, int input_index) const;
698 
699  template <typename Stream>
700  inline void Serialize(Stream& s) const {
701 
702  // magic bytes
703  s << PSBT_MAGIC_BYTES;
704 
705  // unsigned tx flag
707 
708  // Write serialized tx to a stream
709  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
710  SerializeToVector(os, *tx);
711 
712  // Write xpubs
713  for (const auto& xpub_pair : m_xpubs) {
714  for (const auto& xpub : xpub_pair.second) {
715  unsigned char ser_xpub[BIP32_EXTKEY_WITH_VERSION_SIZE];
716  xpub.EncodeWithVersion(ser_xpub);
717  // Note that the serialization swaps the key and value
718  // The xpub is the key (for uniqueness) while the path is the value
719  SerializeToVector(s, PSBT_GLOBAL_XPUB, ser_xpub);
720  SerializeHDKeypath(s, xpub_pair.first);
721  }
722  }
723 
724  // PSBT version
725  if (GetVersion() > 0) {
728  }
729 
730  // Write proprietary things
731  for (const auto& entry : m_proprietary) {
732  s << entry.key;
733  s << entry.value;
734  }
735 
736  // Write the unknown things
737  for (auto& entry : unknown) {
738  s << entry.first;
739  s << entry.second;
740  }
741 
742  // Separator
743  s << PSBT_SEPARATOR;
744 
745  // Write inputs
746  for (const PSBTInput& input : inputs) {
747  s << input;
748  }
749  // Write outputs
750  for (const PSBTOutput& output : outputs) {
751  s << output;
752  }
753  }
754 
755 
756  template <typename Stream>
757  inline void Unserialize(Stream& s) {
758  // Read the magic bytes
759  uint8_t magic[5];
760  s >> magic;
761  if (!std::equal(magic, magic + 5, PSBT_MAGIC_BYTES)) {
762  throw std::ios_base::failure("Invalid PSBT magic bytes");
763  }
764 
765  // Used for duplicate key detection
766  std::set<std::vector<unsigned char>> key_lookup;
767 
768  // Track the global xpubs we have already seen. Just for sanity checking
769  std::set<CExtPubKey> global_xpubs;
770 
771  // Read global data
772  bool found_sep = false;
773  while(!s.empty()) {
774  // Read
775  std::vector<unsigned char> key;
776  s >> key;
777 
778  // the key is empty if that was actually a separator byte
779  // This is a special case for key lengths 0 as those are not allowed (except for separator)
780  if (key.empty()) {
781  found_sep = true;
782  break;
783  }
784 
785  // Type is compact size uint at beginning of key
786  SpanReader skey(s.GetType(), s.GetVersion(), key);
787  uint64_t type = ReadCompactSize(skey);
788 
789  // Do stuff based on type
790  switch(type) {
792  {
793  if (!key_lookup.emplace(key).second) {
794  throw std::ios_base::failure("Duplicate Key, unsigned tx already provided");
795  } else if (key.size() != 1) {
796  throw std::ios_base::failure("Global unsigned tx key is more than one byte type");
797  }
799  // Set the stream to serialize with non-witness since this should always be non-witness
800  OverrideStream<Stream> os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS);
801  UnserializeFromVector(os, mtx);
802  tx = std::move(mtx);
803  // Make sure that all scriptSigs and scriptWitnesses are empty
804  for (const CTxIn& txin : tx->vin) {
805  if (!txin.scriptSig.empty() || !txin.scriptWitness.IsNull()) {
806  throw std::ios_base::failure("Unsigned tx does not have empty scriptSigs and scriptWitnesses.");
807  }
808  }
809  break;
810  }
811  case PSBT_GLOBAL_XPUB:
812  {
813  if (key.size() != BIP32_EXTKEY_WITH_VERSION_SIZE + 1) {
814  throw std::ios_base::failure("Size of key was not the expected size for the type global xpub");
815  }
816  // Read in the xpub from key
817  CExtPubKey xpub;
818  xpub.DecodeWithVersion(&key.data()[1]);
819  if (!xpub.pubkey.IsFullyValid()) {
820  throw std::ios_base::failure("Invalid pubkey");
821  }
822  if (global_xpubs.count(xpub) > 0) {
823  throw std::ios_base::failure("Duplicate key, global xpub already provided");
824  }
825  global_xpubs.insert(xpub);
826  // Read in the keypath from stream
827  KeyOriginInfo keypath;
828  DeserializeHDKeypath(s, keypath);
829 
830  // Note that we store these swapped to make searches faster.
831  // Serialization uses xpub -> keypath to enqure key uniqueness
832  if (m_xpubs.count(keypath) == 0) {
833  // Make a new set to put the xpub in
834  m_xpubs[keypath] = {xpub};
835  } else {
836  // Insert xpub into existing set
837  m_xpubs[keypath].insert(xpub);
838  }
839  break;
840  }
841  case PSBT_GLOBAL_VERSION:
842  {
843  if (m_version) {
844  throw std::ios_base::failure("Duplicate Key, version already provided");
845  } else if (key.size() != 1) {
846  throw std::ios_base::failure("Global version key is more than one byte type");
847  }
848  uint32_t v;
849  UnserializeFromVector(s, v);
850  m_version = v;
852  throw std::ios_base::failure("Unsupported version number");
853  }
854  break;
855  }
857  {
858  PSBTProprietary this_prop;
859  skey >> this_prop.identifier;
860  this_prop.subtype = ReadCompactSize(skey);
861  this_prop.key = key;
862 
863  if (m_proprietary.count(this_prop) > 0) {
864  throw std::ios_base::failure("Duplicate Key, proprietary key already found");
865  }
866  s >> this_prop.value;
867  m_proprietary.insert(this_prop);
868  break;
869  }
870  // Unknown stuff
871  default: {
872  if (unknown.count(key) > 0) {
873  throw std::ios_base::failure("Duplicate Key, key for unknown value already provided");
874  }
875  // Read in the value
876  std::vector<unsigned char> val_bytes;
877  s >> val_bytes;
878  unknown.emplace(std::move(key), std::move(val_bytes));
879  }
880  }
881  }
882 
883  if (!found_sep) {
884  throw std::ios_base::failure("Separator is missing at the end of the global map");
885  }
886 
887  // Make sure that we got an unsigned tx
888  if (!tx) {
889  throw std::ios_base::failure("No unsigned transcation was provided");
890  }
891 
892  // Read input data
893  unsigned int i = 0;
894  while (!s.empty() && i < tx->vin.size()) {
895  PSBTInput input;
896  s >> input;
897  inputs.push_back(input);
898 
899  // Make sure the non-witness utxo matches the outpoint
900  if (input.non_witness_utxo && input.non_witness_utxo->GetHash() != tx->vin[i].prevout.hash) {
901  throw std::ios_base::failure("Non-witness UTXO does not match outpoint hash");
902  }
903  ++i;
904  }
905  // Make sure that the number of inputs matches the number of inputs in the transaction
906  if (inputs.size() != tx->vin.size()) {
907  throw std::ios_base::failure("Inputs provided does not match the number of inputs in transaction.");
908  }
909 
910  // Read output data
911  i = 0;
912  while (!s.empty() && i < tx->vout.size()) {
913  PSBTOutput output;
914  s >> output;
915  outputs.push_back(output);
916  ++i;
917  }
918  // Make sure that the number of outputs matches the number of outputs in the transaction
919  if (outputs.size() != tx->vout.size()) {
920  throw std::ios_base::failure("Outputs provided does not match the number of outputs in transaction.");
921  }
922  }
923 
924  template <typename Stream>
926  Unserialize(s);
927  }
928 };
929 
930 enum class PSBTRole {
931  CREATOR,
932  UPDATER,
933  SIGNER,
934  FINALIZER,
935  EXTRACTOR
936 };
937 
938 std::string PSBTRoleName(PSBTRole role);
939 
942 
944 bool PSBTInputSigned(const PSBTInput& input);
945 
951 bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, const PrecomputedTransactionData* txdata, int sighash = SIGHASH_ALL, SignatureData* out_sigdata = nullptr, bool finalize = true);
952 
955 
960 void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index);
961 
969 
978 
986 [[nodiscard]] TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);
987 
989 [[nodiscard]] bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
991 [[nodiscard]] bool DecodeRawPSBT(PartiallySignedTransaction& decoded_psbt, const std::string& raw_psbt, std::string& error);
992 
993 #endif // BITCOIN_PSBT_H
CTxIn
An input of a transaction.
Definition: transaction.h:65
deserialize_type
Dummy data type to identify deserializing constructors.
Definition: serialize.h:47
CScriptWitness::IsNull
bool IsNull() const
Definition: script.h:566
feerate.h
PartiallySignedTransaction::GetVersion
uint32_t GetVersion() const
Definition: psbt.cpp:416
PSBTInput::non_witness_utxo
CTransactionRef non_witness_utxo
Definition: psbt.h:170
PSBT_IN_SCRIPTWITNESS
static constexpr uint8_t PSBT_IN_SCRIPTWITNESS
Definition: psbt.h:39
DecodeRawPSBT
bool DecodeRawPSBT(PartiallySignedTransaction &decoded_psbt, const std::string &raw_psbt, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:400
PSBTInput::partial_sigs
std::map< CKeyID, SigPair > partial_sigs
Definition: psbt.h:177
FinalizePSBT
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
Definition: psbt.cpp:333
streams.h
PSBT_IN_PROPRIETARY
static constexpr uint8_t PSBT_IN_PROPRIETARY
Definition: psbt.h:44
PSBTInput::PSBTInput
PSBTInput()
Definition: psbt.h:190
PSBTProprietary::key
std::vector< unsigned char > key
Definition: psbt.h:68
PartiallySignedTransaction::IsNull
bool IsNull() const
Definition: psbt.cpp:17
transaction.h
PSBTOutput::PSBTOutput
PSBTOutput()
Definition: psbt.h:543
PSBTOutput::FillSignatureData
void FillSignatureData(SignatureData &sigdata) const
Definition: psbt.cpp:169
CombinePSBTs
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...
Definition: psbt.cpp:364
CPubKey::SIZE
static constexpr unsigned int SIZE
secp256k1:
Definition: pubkey.h:39
PSBT_IN_REDEEMSCRIPT
static constexpr uint8_t PSBT_IN_REDEEMSCRIPT
Definition: psbt.h:35
PSBTRole::UPDATER
@ UPDATER
PartiallySignedTransaction::inputs
std::vector< PSBTInput > inputs
Definition: psbt.h:674
GetSerializeSizeMany
size_t GetSerializeSizeMany(int nVersion, const T &... t)
Definition: serialize.h:1099
PSBTInput::witness_script
CScript witness_script
Definition: psbt.h:173
PartiallySignedTransaction::AddInput
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
Definition: psbt.cpp:47
PSBT_GLOBAL_UNSIGNED_TX
static constexpr uint8_t PSBT_GLOBAL_UNSIGNED_TX
Definition: psbt.h:25
SigningProvider
An interface to be implemented by keystores that support signing.
Definition: signingprovider.h:17
PSBT_IN_HASH256
static constexpr uint8_t PSBT_IN_HASH256
Definition: psbt.h:43
PSBTOutput::redeem_script
CScript redeem_script
Definition: psbt.h:533
CRIPEMD160::OUTPUT_SIZE
static const size_t OUTPUT_SIZE
Definition: ripemd160.h:20
PSBTOutput::Unserialize
void Unserialize(Stream &s)
Definition: psbt.h:579
PSBT_IN_NON_WITNESS_UTXO
static constexpr uint8_t PSBT_IN_NON_WITNESS_UTXO
Definition: psbt.h:31
PSBTInput::hash256_preimages
std::map< uint256, std::vector< unsigned char > > hash256_preimages
Definition: psbt.h:181
PSBT_IN_HASH160
static constexpr uint8_t PSBT_IN_HASH160
Definition: psbt.h:42
DeserializeHDKeypaths
void DeserializeHDKeypaths(Stream &s, const std::vector< unsigned char > &key, std::map< CPubKey, KeyOriginInfo > &hd_keypaths)
Definition: psbt.h:121
PSBTInputSigned
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
Definition: psbt.cpp:208
ReadCompactSize
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
Definition: serialize.h:282
pubkey.h
PartiallySignedTransaction::m_version
std::optional< uint32_t > m_version
Definition: psbt.h:677
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
PSBTOutput::witness_script
CScript witness_script
Definition: psbt.h:534
PSBTOutput::PSBTOutput
PSBTOutput(deserialize_type, Stream &s)
Definition: psbt.h:662
PSBT_IN_SIGHASH
static constexpr uint8_t PSBT_IN_SIGHASH
Definition: psbt.h:34
UpdatePSBTOutput
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
Definition: psbt.cpp:224
CScriptWitness
Definition: script.h:557
DeserializeHDKeypath
void DeserializeHDKeypath(Stream &s, KeyOriginInfo &hd_keypath)
Definition: psbt.h:103
DecodeBase64PSBT
bool DecodeBase64PSBT(PartiallySignedTransaction &decoded_psbt, const std::string &base64_psbt, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:389
transaction.h
CTxIn::scriptWitness
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:71
Span
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:96
signingprovider.h
SigPair
std::pair< CPubKey, std::vector< unsigned char > > SigPair
Definition: sign.h:58
CTxOut::IsNull
bool IsNull() const
Definition: transaction.h:149
PSBT_MAGIC_BYTES
static constexpr uint8_t PSBT_MAGIC_BYTES[5]
Definition: psbt.h:22
TransactionError
TransactionError
Definition: error.h:22
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.
Definition: psbt.cpp:261
PartiallySignedTransaction::PartiallySignedTransaction
PartiallySignedTransaction()
Definition: psbt.h:688
PSBTInput::final_script_sig
CScript final_script_sig
Definition: psbt.h:174
PSBTOutput::m_proprietary
std::set< PSBTProprietary > m_proprietary
Definition: psbt.h:537
SignatureData
Definition: sign.h:63
PSBT_HIGHEST_VERSION
static constexpr uint32_t PSBT_HIGHEST_VERSION
Definition: psbt.h:61
PartiallySignedTransaction::Merge
bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
Definition: psbt.cpp:22
BIP32_EXTKEY_WITH_VERSION_SIZE
const unsigned int BIP32_EXTKEY_WITH_VERSION_SIZE
Definition: pubkey.h:20
PSBTInput::hd_keypaths
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:176
CTxOut
An output of a transaction.
Definition: transaction.h:128
PartiallySignedTransaction::Unserialize
void Unserialize(Stream &s)
Definition: psbt.h:757
PSBTInput::Unserialize
void Unserialize(Stream &s)
Definition: psbt.h:286
PSBTRole::SIGNER
@ SIGNER
CHash256::OUTPUT_SIZE
static const size_t OUTPUT_SIZE
Definition: hash.h:28
PSBT_IN_PARTIAL_SIG
static constexpr uint8_t PSBT_IN_PARTIAL_SIG
Definition: psbt.h:33
PartiallySignedTransaction::GetInputUTXO
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
Definition: psbt.cpp:67
PSBTInput::final_script_witness
CScriptWitness final_script_witness
Definition: psbt.h:175
WriteCompactSize
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
Definition: serialize.h:1087
span.h
PSBTRole::CREATOR
@ CREATOR
PSBTRoleName
std::string PSBTRoleName(PSBTRole role)
Definition: psbt.cpp:377
PSBTOutput::IsNull
bool IsNull() const
Definition: psbt.cpp:195
PSBT_IN_WITNESS_UTXO
static constexpr uint8_t PSBT_IN_WITNESS_UTXO
Definition: psbt.h:32
PSBTProprietary
A structure for PSBT proprietary types.
Definition: psbt.h:64
sign.h
PartiallySignedTransaction::tx
std::optional< CMutableTransaction > tx
Definition: psbt.h:670
PSBTInput::Merge
void Merge(const PSBTInput &input)
Definition: psbt.cpp:147
SERIALIZE_TRANSACTION_NO_WITNESS
static const int SERIALIZE_TRANSACTION_NO_WITNESS
A flag that is ORed into the protocol version to designate that a transaction should be (un)serialize...
Definition: transaction.h:23
SpanReader
Minimal stream for reading from an existing byte array by Span.
Definition: streams.h:133
PSBTProprietary::identifier
std::vector< unsigned char > identifier
Definition: psbt.h:67
PSBTOutput
A structure for PSBTs which contains per output information.
Definition: psbt.h:531
PrecomputedTransactionData
Definition: interpreter.h:150
PartiallySignedTransaction::m_xpubs
std::map< KeyOriginInfo, std::set< CExtPubKey > > m_xpubs
Definition: psbt.h:673
UnserializeMany
void UnserializeMany(Stream &s)
Definition: serialize.h:1036
SerializeMany
void SerializeMany(Stream &s)
Definition: serialize.h:1024
CPubKey::COMPRESSED_SIZE
static constexpr unsigned int COMPRESSED_SIZE
Definition: pubkey.h:40
uint256
256-bit opaque blob.
Definition: uint256.h:124
PSBTInput::unknown
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:182
PSBT_OUT_BIP32_DERIVATION
static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION
Definition: psbt.h:49
PSBT_GLOBAL_VERSION
static constexpr uint8_t PSBT_GLOBAL_VERSION
Definition: psbt.h:27
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
PartiallySignedTransaction::AddOutput
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
Definition: psbt.cpp:60
PSBT_IN_BIP32_DERIVATION
static constexpr uint8_t PSBT_IN_BIP32_DERIVATION
Definition: psbt.h:37
CountPSBTUnsignedInputs
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
Definition: psbt.cpp:213
PSBTInput::m_proprietary
std::set< PSBTProprietary > m_proprietary
Definition: psbt.h:183
PSBTRole::EXTRACTOR
@ EXTRACTOR
FinalizeAndExtractPSBT
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized.
Definition: psbt.cpp:348
SerializeHDKeypaths
void SerializeHDKeypaths(Stream &s, const std::map< CPubKey, KeyOriginInfo > &hd_keypaths, CompactSizeWriter type)
Definition: psbt.h:156
attributes.h
PSBTInput::sighash_type
std::optional< int > sighash_type
Definition: psbt.h:184
CSHA256::OUTPUT_SIZE
static const size_t OUTPUT_SIZE
Definition: sha256.h:21
OverrideStream
Definition: streams.h:26
PSBT_IN_SHA256
static constexpr uint8_t PSBT_IN_SHA256
Definition: psbt.h:41
PSBT_IN_SCRIPTSIG
static constexpr uint8_t PSBT_IN_SCRIPTSIG
Definition: psbt.h:38
PSBTInput::FillSignatureData
void FillSignatureData(SignatureData &sigdata) const
Definition: psbt.cpp:92
PSBTOutput::Merge
void Merge(const PSBTOutput &output)
Definition: psbt.cpp:200
SerializeHDKeypath
void SerializeHDKeypath(Stream &s, KeyOriginInfo hd_keypath)
Definition: psbt.h:145
SIGHASH_ALL
@ SIGHASH_ALL
Definition: interpreter.h:27
uint160
160-bit opaque blob.
Definition: uint256.h:113
CPubKey
An encapsulated public key.
Definition: pubkey.h:33
CExtPubKey::DecodeWithVersion
void DecodeWithVersion(const unsigned char code[BIP32_EXTKEY_WITH_VERSION_SIZE])
Definition: pubkey.cpp:361
PSBTInput
A structure for PSBTs which contain per-input information.
Definition: psbt.h:168
PSBTRole::FINALIZER
@ FINALIZER
PSBTInput::FromSignatureData
void FromSignatureData(const SignatureData &sigdata)
Definition: psbt.cpp:118
PSBT_OUT_WITNESSSCRIPT
static constexpr uint8_t PSBT_OUT_WITNESSSCRIPT
Definition: psbt.h:48
PSBT_GLOBAL_PROPRIETARY
static constexpr uint8_t PSBT_GLOBAL_PROPRIETARY
Definition: psbt.h:28
PSBTInput::hash160_preimages
std::map< uint160, std::vector< unsigned char > > hash160_preimages
Definition: psbt.h:180
X
#define X(name)
Definition: net.cpp:575
PartiallySignedTransaction
A version of CTransaction with the PSBT format.
Definition: psbt.h:668
PSBTOutput::Serialize
void Serialize(Stream &s) const
Definition: psbt.h:546
PSBT_OUT_PROPRIETARY
static constexpr uint8_t PSBT_OUT_PROPRIETARY
Definition: psbt.h:50
PSBT_OUT_REDEEMSCRIPT
static constexpr uint8_t PSBT_OUT_REDEEMSCRIPT
Definition: psbt.h:47
PSBTInput::PSBTInput
PSBTInput(deserialize_type, Stream &s)
Definition: psbt.h:525
PSBTRole
PSBTRole
Definition: psbt.h:930
CTxIn::scriptSig
CScript scriptSig
Definition: transaction.h:69
PSBTProprietary::subtype
uint64_t subtype
Definition: psbt.h:66
PartiallySignedTransaction::outputs
std::vector< PSBTOutput > outputs
Definition: psbt.h:675
CPubKey::IsFullyValid
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Definition: pubkey.cpp:292
PSBTInput::Serialize
void Serialize(Stream &s) const
Definition: psbt.h:193
PartiallySignedTransaction::m_proprietary
std::set< PSBTProprietary > m_proprietary
Definition: psbt.h:678
PSBTInput::ripemd160_preimages
std::map< uint160, std::vector< unsigned char > > ripemd160_preimages
Definition: psbt.h:178
prevector::empty
bool empty() const
Definition: prevector.h:286
PartiallySignedTransaction::PartiallySignedTransaction
PartiallySignedTransaction(deserialize_type, Stream &s)
Definition: psbt.h:925
MAX_FILE_SIZE_PSBT
const std::streamsize MAX_FILE_SIZE_PSBT
Definition: psbt.h:58
KeyOriginInfo::path
std::vector< uint32_t > path
Definition: keyorigin.h:14
PSBTProprietary::operator==
bool operator==(const PSBTProprietary &b) const
Definition: psbt.h:74
PSBTProprietary::operator<
bool operator<(const PSBTProprietary &b) const
Definition: psbt.h:71
PSBT_SEPARATOR
static constexpr uint8_t PSBT_SEPARATOR
Definition: psbt.h:54
PSBTInput::redeem_script
CScript redeem_script
Definition: psbt.h:172
PSBTProprietary::value
std::vector< unsigned char > value
Definition: psbt.h:69
Span::first
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
Definition: span.h:204
PSBT_GLOBAL_XPUB
static constexpr uint8_t PSBT_GLOBAL_XPUB
Definition: psbt.h:26
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
CExtPubKey::pubkey
CPubKey pubkey
Definition: pubkey.h:297
PrecomputePSBTData
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.
Definition: psbt.cpp:244
keyorigin.h
PSBTInput::IsNull
bool IsNull() const
Definition: psbt.cpp:87
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:344
PSBTInput::sha256_preimages
std::map< uint256, std::vector< unsigned char > > sha256_preimages
Definition: psbt.h:179
PSBTOutput::FromSignatureData
void FromSignatureData(const SignatureData &sigdata)
Definition: psbt.cpp:182
PSBTInput::witness_utxo
CTxOut witness_utxo
Definition: psbt.h:171
KeyOriginInfo::fingerprint
unsigned char fingerprint[4]
First 32 bits of the Hash160 of the public key at the root of the path.
Definition: keyorigin.h:13
CExtPubKey
Definition: pubkey.h:291
CHash160::OUTPUT_SIZE
static const size_t OUTPUT_SIZE
Definition: hash.h:53
CompactSizeWriter
Definition: serialize.h:530
PSBTOutput::hd_keypaths
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:535
UnserializeFromVector
void UnserializeFromVector(Stream &s, X &... args)
Definition: psbt.h:90
PartiallySignedTransaction::Serialize
void Serialize(Stream &s) const
Definition: psbt.h:700
KeyOriginInfo
Definition: keyorigin.h:11
CScriptWitness::stack
std::vector< std::vector< unsigned char > > stack
Definition: script.h:561
PSBT_IN_WITNESSSCRIPT
static constexpr uint8_t PSBT_IN_WITNESSSCRIPT
Definition: psbt.h:36
CPubKey::GetID
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:164
PartiallySignedTransaction::unknown
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:676
PSBTOutput::unknown
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:536
args
ArgsManager args
Definition: notifications.cpp:36
SerializeToVector
void SerializeToVector(Stream &s, const X &... args)
Definition: psbt.h:82
PSBT_IN_RIPEMD160
static constexpr uint8_t PSBT_IN_RIPEMD160
Definition: psbt.h:40