Bitcoin Core  24.99.0
P2P Digital Currency
psbt.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2022 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 #include <psbt.h>
6 
7 #include <policy/policy.h>
8 #include <util/check.h>
9 #include <util/strencodings.h>
10 
11 
13 {
14  inputs.resize(tx.vin.size());
15  outputs.resize(tx.vout.size());
16 }
17 
19 {
20  return !tx && inputs.empty() && outputs.empty() && unknown.empty();
21 }
22 
24 {
25  // Prohibited to merge two PSBTs over different transactions
26  if (tx->GetHash() != psbt.tx->GetHash()) {
27  return false;
28  }
29 
30  for (unsigned int i = 0; i < inputs.size(); ++i) {
31  inputs[i].Merge(psbt.inputs[i]);
32  }
33  for (unsigned int i = 0; i < outputs.size(); ++i) {
34  outputs[i].Merge(psbt.outputs[i]);
35  }
36  for (auto& xpub_pair : psbt.m_xpubs) {
37  if (m_xpubs.count(xpub_pair.first) == 0) {
38  m_xpubs[xpub_pair.first] = xpub_pair.second;
39  } else {
40  m_xpubs[xpub_pair.first].insert(xpub_pair.second.begin(), xpub_pair.second.end());
41  }
42  }
43  unknown.insert(psbt.unknown.begin(), psbt.unknown.end());
44 
45  return true;
46 }
47 
49 {
50  if (std::find(tx->vin.begin(), tx->vin.end(), txin) != tx->vin.end()) {
51  return false;
52  }
53  tx->vin.push_back(txin);
54  psbtin.partial_sigs.clear();
55  psbtin.final_script_sig.clear();
57  inputs.push_back(psbtin);
58  return true;
59 }
60 
61 bool PartiallySignedTransaction::AddOutput(const CTxOut& txout, const PSBTOutput& psbtout)
62 {
63  tx->vout.push_back(txout);
64  outputs.push_back(psbtout);
65  return true;
66 }
67 
68 bool PartiallySignedTransaction::GetInputUTXO(CTxOut& utxo, int input_index) const
69 {
70  const PSBTInput& input = inputs[input_index];
71  uint32_t prevout_index = tx->vin[input_index].prevout.n;
72  if (input.non_witness_utxo) {
73  if (prevout_index >= input.non_witness_utxo->vout.size()) {
74  return false;
75  }
76  if (input.non_witness_utxo->GetHash() != tx->vin[input_index].prevout.hash) {
77  return false;
78  }
79  utxo = input.non_witness_utxo->vout[prevout_index];
80  } else if (!input.witness_utxo.IsNull()) {
81  utxo = input.witness_utxo;
82  } else {
83  return false;
84  }
85  return true;
86 }
87 
88 bool PSBTInput::IsNull() const
89 {
90  return !non_witness_utxo && witness_utxo.IsNull() && partial_sigs.empty() && unknown.empty() && hd_keypaths.empty() && redeem_script.empty() && witness_script.empty();
91 }
92 
94 {
95  if (!final_script_sig.empty()) {
96  sigdata.scriptSig = final_script_sig;
97  sigdata.complete = true;
98  }
101  sigdata.complete = true;
102  }
103  if (sigdata.complete) {
104  return;
105  }
106 
107  sigdata.signatures.insert(partial_sigs.begin(), partial_sigs.end());
108  if (!redeem_script.empty()) {
109  sigdata.redeem_script = redeem_script;
110  }
111  if (!witness_script.empty()) {
112  sigdata.witness_script = witness_script;
113  }
114  for (const auto& key_pair : hd_keypaths) {
115  sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
116  }
117  if (!m_tap_key_sig.empty()) {
119  }
120  for (const auto& [pubkey_leaf, sig] : m_tap_script_sigs) {
121  sigdata.taproot_script_sigs.emplace(pubkey_leaf, sig);
122  }
123  if (!m_tap_internal_key.IsNull()) {
125  }
126  if (!m_tap_merkle_root.IsNull()) {
128  }
129  for (const auto& [leaf_script, control_block] : m_tap_scripts) {
130  sigdata.tr_spenddata.scripts.emplace(leaf_script, control_block);
131  }
132  for (const auto& [pubkey, leaf_origin] : m_tap_bip32_paths) {
133  sigdata.taproot_misc_pubkeys.emplace(pubkey, leaf_origin);
134  }
135 }
136 
138 {
139  if (sigdata.complete) {
140  partial_sigs.clear();
141  hd_keypaths.clear();
144 
145  if (!sigdata.scriptSig.empty()) {
146  final_script_sig = sigdata.scriptSig;
147  }
148  if (!sigdata.scriptWitness.IsNull()) {
150  }
151  return;
152  }
153 
154  partial_sigs.insert(sigdata.signatures.begin(), sigdata.signatures.end());
155  if (redeem_script.empty() && !sigdata.redeem_script.empty()) {
156  redeem_script = sigdata.redeem_script;
157  }
158  if (witness_script.empty() && !sigdata.witness_script.empty()) {
159  witness_script = sigdata.witness_script;
160  }
161  for (const auto& entry : sigdata.misc_pubkeys) {
162  hd_keypaths.emplace(entry.second);
163  }
164  if (!sigdata.taproot_key_path_sig.empty()) {
166  }
167  for (const auto& [pubkey_leaf, sig] : sigdata.taproot_script_sigs) {
168  m_tap_script_sigs.emplace(pubkey_leaf, sig);
169  }
170  if (!sigdata.tr_spenddata.internal_key.IsNull()) {
172  }
173  if (!sigdata.tr_spenddata.merkle_root.IsNull()) {
175  }
176  for (const auto& [leaf_script, control_block] : sigdata.tr_spenddata.scripts) {
177  m_tap_scripts.emplace(leaf_script, control_block);
178  }
179  for (const auto& [pubkey, leaf_origin] : sigdata.taproot_misc_pubkeys) {
180  m_tap_bip32_paths.emplace(pubkey, leaf_origin);
181  }
182 }
183 
184 void PSBTInput::Merge(const PSBTInput& input)
185 {
187  if (witness_utxo.IsNull() && !input.witness_utxo.IsNull()) {
188  witness_utxo = input.witness_utxo;
189  }
190 
191  partial_sigs.insert(input.partial_sigs.begin(), input.partial_sigs.end());
192  ripemd160_preimages.insert(input.ripemd160_preimages.begin(), input.ripemd160_preimages.end());
193  sha256_preimages.insert(input.sha256_preimages.begin(), input.sha256_preimages.end());
194  hash160_preimages.insert(input.hash160_preimages.begin(), input.hash160_preimages.end());
195  hash256_preimages.insert(input.hash256_preimages.begin(), input.hash256_preimages.end());
196  hd_keypaths.insert(input.hd_keypaths.begin(), input.hd_keypaths.end());
197  unknown.insert(input.unknown.begin(), input.unknown.end());
198  m_tap_script_sigs.insert(input.m_tap_script_sigs.begin(), input.m_tap_script_sigs.end());
199  m_tap_scripts.insert(input.m_tap_scripts.begin(), input.m_tap_scripts.end());
200  m_tap_bip32_paths.insert(input.m_tap_bip32_paths.begin(), input.m_tap_bip32_paths.end());
201 
206  if (m_tap_key_sig.empty() && !input.m_tap_key_sig.empty()) m_tap_key_sig = input.m_tap_key_sig;
209 }
210 
212 {
213  if (!redeem_script.empty()) {
214  sigdata.redeem_script = redeem_script;
215  }
216  if (!witness_script.empty()) {
217  sigdata.witness_script = witness_script;
218  }
219  for (const auto& key_pair : hd_keypaths) {
220  sigdata.misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
221  }
222  if (!m_tap_tree.empty() && m_tap_internal_key.IsFullyValid()) {
223  TaprootBuilder builder;
224  for (const auto& [depth, leaf_ver, script] : m_tap_tree) {
225  builder.Add((int)depth, script, (int)leaf_ver, /*track=*/true);
226  }
227  assert(builder.IsComplete());
228  builder.Finalize(m_tap_internal_key);
229  TaprootSpendData spenddata = builder.GetSpendData();
230 
232  sigdata.tr_spenddata.Merge(spenddata);
233  }
234  for (const auto& [pubkey, leaf_origin] : m_tap_bip32_paths) {
235  sigdata.taproot_misc_pubkeys.emplace(pubkey, leaf_origin);
236  }
237 }
238 
240 {
241  if (redeem_script.empty() && !sigdata.redeem_script.empty()) {
242  redeem_script = sigdata.redeem_script;
243  }
244  if (witness_script.empty() && !sigdata.witness_script.empty()) {
245  witness_script = sigdata.witness_script;
246  }
247  for (const auto& entry : sigdata.misc_pubkeys) {
248  hd_keypaths.emplace(entry.second);
249  }
250  if (!sigdata.tr_spenddata.internal_key.IsNull()) {
252  }
253  if (sigdata.tr_builder.has_value() && sigdata.tr_builder->HasScripts()) {
254  m_tap_tree = sigdata.tr_builder->GetTreeTuples();
255  }
256  for (const auto& [pubkey, leaf_origin] : sigdata.taproot_misc_pubkeys) {
257  m_tap_bip32_paths.emplace(pubkey, leaf_origin);
258  }
259 }
260 
261 bool PSBTOutput::IsNull() const
262 {
263  return redeem_script.empty() && witness_script.empty() && hd_keypaths.empty() && unknown.empty();
264 }
265 
266 void PSBTOutput::Merge(const PSBTOutput& output)
267 {
268  hd_keypaths.insert(output.hd_keypaths.begin(), output.hd_keypaths.end());
269  unknown.insert(output.unknown.begin(), output.unknown.end());
270  m_tap_bip32_paths.insert(output.m_tap_bip32_paths.begin(), output.m_tap_bip32_paths.end());
271 
272  if (redeem_script.empty() && !output.redeem_script.empty()) redeem_script = output.redeem_script;
275  if (m_tap_tree.empty() && !output.m_tap_tree.empty()) m_tap_tree = output.m_tap_tree;
276 }
277 
278 bool PSBTInputSigned(const PSBTInput& input)
279 {
280  return !input.final_script_sig.empty() || !input.final_script_witness.IsNull();
281 }
282 
283 bool PSBTInputSignedAndVerified(const PartiallySignedTransaction psbt, unsigned int input_index, const PrecomputedTransactionData* txdata)
284 {
285  CTxOut utxo;
286  assert(psbt.inputs.size() >= input_index);
287  const PSBTInput& input = psbt.inputs[input_index];
288 
289  if (input.non_witness_utxo) {
290  // If we're taking our information from a non-witness UTXO, verify that it matches the prevout.
291  COutPoint prevout = psbt.tx->vin[input_index].prevout;
292  if (prevout.n >= input.non_witness_utxo->vout.size()) {
293  return false;
294  }
295  if (input.non_witness_utxo->GetHash() != prevout.hash) {
296  return false;
297  }
298  utxo = input.non_witness_utxo->vout[prevout.n];
299  } else if (!input.witness_utxo.IsNull()) {
300  utxo = input.witness_utxo;
301  } else {
302  return false;
303  }
304 
305  if (txdata) {
306  return VerifyScript(input.final_script_sig, utxo.scriptPubKey, &input.final_script_witness, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker{&(*psbt.tx), input_index, utxo.nValue, *txdata, MissingDataBehavior::FAIL});
307  } else {
308  return VerifyScript(input.final_script_sig, utxo.scriptPubKey, &input.final_script_witness, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker{&(*psbt.tx), input_index, utxo.nValue, MissingDataBehavior::FAIL});
309  }
310 }
311 
313  size_t count = 0;
314  for (const auto& input : psbt.inputs) {
315  if (!PSBTInputSigned(input)) {
316  count++;
317  }
318  }
319 
320  return count;
321 }
322 
323 void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index)
324 {
325  CMutableTransaction& tx = *Assert(psbt.tx);
326  const CTxOut& out = tx.vout.at(index);
327  PSBTOutput& psbt_out = psbt.outputs.at(index);
328 
329  // Fill a SignatureData with output info
330  SignatureData sigdata;
331  psbt_out.FillSignatureData(sigdata);
332 
333  // Construct a would-be spend of this output, to update sigdata with.
334  // Note that ProduceSignature is used to fill in metadata (not actual signatures),
335  // so provider does not need to provide any private keys (it can be a HidingSigningProvider).
336  MutableTransactionSignatureCreator creator(tx, /*input_idx=*/0, out.nValue, SIGHASH_ALL);
337  ProduceSignature(provider, creator, out.scriptPubKey, sigdata);
338 
339  // Put redeem_script, witness_script, key paths, into PSBTOutput.
340  psbt_out.FromSignatureData(sigdata);
341 }
342 
344 {
345  const CMutableTransaction& tx = *psbt.tx;
346  bool have_all_spent_outputs = true;
347  std::vector<CTxOut> utxos(tx.vin.size());
348  for (size_t idx = 0; idx < tx.vin.size(); ++idx) {
349  if (!psbt.GetInputUTXO(utxos[idx], idx)) have_all_spent_outputs = false;
350  }
352  if (have_all_spent_outputs) {
353  txdata.Init(tx, std::move(utxos), true);
354  } else {
355  txdata.Init(tx, {}, true);
356  }
357  return txdata;
358 }
359 
360 bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, const PrecomputedTransactionData* txdata, int sighash, SignatureData* out_sigdata, bool finalize)
361 {
362  PSBTInput& input = psbt.inputs.at(index);
363  const CMutableTransaction& tx = *psbt.tx;
364 
365  if (PSBTInputSignedAndVerified(psbt, index, txdata)) {
366  return true;
367  }
368 
369  // Fill SignatureData with input info
370  SignatureData sigdata;
371  input.FillSignatureData(sigdata);
372 
373  // Get UTXO
374  bool require_witness_sig = false;
375  CTxOut utxo;
376 
377  if (input.non_witness_utxo) {
378  // If we're taking our information from a non-witness UTXO, verify that it matches the prevout.
379  COutPoint prevout = tx.vin[index].prevout;
380  if (prevout.n >= input.non_witness_utxo->vout.size()) {
381  return false;
382  }
383  if (input.non_witness_utxo->GetHash() != prevout.hash) {
384  return false;
385  }
386  utxo = input.non_witness_utxo->vout[prevout.n];
387  } else if (!input.witness_utxo.IsNull()) {
388  utxo = input.witness_utxo;
389  // When we're taking our information from a witness UTXO, we can't verify it is actually data from
390  // the output being spent. This is safe in case a witness signature is produced (which includes this
391  // information directly in the hash), but not for non-witness signatures. Remember that we require
392  // a witness signature in this situation.
393  require_witness_sig = true;
394  } else {
395  return false;
396  }
397 
398  sigdata.witness = false;
399  bool sig_complete;
400  if (txdata == nullptr) {
401  sig_complete = ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, utxo.scriptPubKey, sigdata);
402  } else {
403  MutableTransactionSignatureCreator creator(tx, index, utxo.nValue, txdata, sighash);
404  sig_complete = ProduceSignature(provider, creator, utxo.scriptPubKey, sigdata);
405  }
406  // Verify that a witness signature was produced in case one was required.
407  if (require_witness_sig && !sigdata.witness) return false;
408 
409  // If we are not finalizing, set sigdata.complete to false to not set the scriptWitness
410  if (!finalize && sigdata.complete) sigdata.complete = false;
411 
412  input.FromSignatureData(sigdata);
413 
414  // If we have a witness signature, put a witness UTXO.
415  if (sigdata.witness) {
416  input.witness_utxo = utxo;
417  // We can remove the non_witness_utxo if and only if there are no non-segwit or segwit v0
418  // inputs in this transaction. Since this requires inspecting the entire transaction, this
419  // is something for the caller to deal with (i.e. FillPSBT).
420  }
421 
422  // Fill in the missing info
423  if (out_sigdata) {
424  out_sigdata->missing_pubkeys = sigdata.missing_pubkeys;
425  out_sigdata->missing_sigs = sigdata.missing_sigs;
426  out_sigdata->missing_redeem_script = sigdata.missing_redeem_script;
427  out_sigdata->missing_witness_script = sigdata.missing_witness_script;
428  }
429 
430  return sig_complete;
431 }
432 
434 {
435  // Finalize input signatures -- in case we have partial signatures that add up to a complete
436  // signature, but have not combined them yet (e.g. because the combiner that created this
437  // PartiallySignedTransaction did not understand them), this will combine them into a final
438  // script.
439  bool complete = true;
440  const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx);
441  for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) {
442  complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, &txdata, SIGHASH_ALL, nullptr, true);
443  }
444 
445  return complete;
446 }
447 
449 {
450  // It's not safe to extract a PSBT that isn't finalized, and there's no easy way to check
451  // whether a PSBT is finalized without finalizing it, so we just do this.
452  if (!FinalizePSBT(psbtx)) {
453  return false;
454  }
455 
456  result = *psbtx.tx;
457  for (unsigned int i = 0; i < result.vin.size(); ++i) {
458  result.vin[i].scriptSig = psbtx.inputs[i].final_script_sig;
459  result.vin[i].scriptWitness = psbtx.inputs[i].final_script_witness;
460  }
461  return true;
462 }
463 
464 TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs)
465 {
466  out = psbtxs[0]; // Copy the first one
467 
468  // Merge
469  for (auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) {
470  if (!out.Merge(*it)) {
472  }
473  }
474  return TransactionError::OK;
475 }
476 
477 std::string PSBTRoleName(PSBTRole role) {
478  switch (role) {
479  case PSBTRole::CREATOR: return "creator";
480  case PSBTRole::UPDATER: return "updater";
481  case PSBTRole::SIGNER: return "signer";
482  case PSBTRole::FINALIZER: return "finalizer";
483  case PSBTRole::EXTRACTOR: return "extractor";
484  // no default case, so the compiler can warn about missing cases
485  }
486  assert(false);
487 }
488 
489 bool DecodeBase64PSBT(PartiallySignedTransaction& psbt, const std::string& base64_tx, std::string& error)
490 {
491  auto tx_data = DecodeBase64(base64_tx);
492  if (!tx_data) {
493  error = "invalid base64";
494  return false;
495  }
496  return DecodeRawPSBT(psbt, MakeByteSpan(*tx_data), error);
497 }
498 
500 {
501  CDataStream ss_data(tx_data, SER_NETWORK, PROTOCOL_VERSION);
502  try {
503  ss_data >> psbt;
504  if (!ss_data.empty()) {
505  error = "extra data after PSBT";
506  return false;
507  }
508  } catch (const std::exception& e) {
509  error = e.what();
510  return false;
511  }
512  return true;
513 }
514 
516 {
517  if (m_version != std::nullopt) {
518  return *m_version;
519  }
520  return 0;
521 }
#define Assert(val)
Identity function.
Definition: check.h:73
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
uint32_t n
Definition: transaction.h:39
uint256 hash
Definition: transaction.h:38
void clear()
Definition: script.h:554
An input of a transaction.
Definition: transaction.h:75
An output of a transaction.
Definition: transaction.h:158
CScript scriptPubKey
Definition: transaction.h:161
CAmount nValue
Definition: transaction.h:160
bool IsNull() const
Definition: transaction.h:178
bool empty() const
Definition: streams.h:221
A signature creator for transactions.
Definition: sign.h:40
An interface to be implemented by keystores that support signing.
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:97
Utility class to construct Taproot outputs from internal key and script tree.
Definition: standard.h:227
TaprootSpendData GetSpendData() const
Compute spending data (after Finalize()).
Definition: standard.cpp:477
bool IsComplete() const
Return whether there were either no leaves, or the leaves form a Huffman tree.
Definition: standard.h:309
TaprootBuilder & Add(int depth, Span< const unsigned char > script, int leaf_version, bool track=true)
Add a new script at a certain depth in the tree.
Definition: standard.cpp:441
TaprootBuilder & Finalize(const XOnlyPubKey &internal_key)
Finalize the construction.
Definition: standard.cpp:464
bool IsNull() const
Test whether this is the 0 key (the result of default construction).
Definition: pubkey.h:243
bool IsFullyValid() const
Determine if this pubkey is fully valid.
Definition: pubkey.cpp:206
bool IsNull() const
Definition: uint256.h:34
bool empty() const
Definition: prevector.h:288
TransactionError
Definition: error.h:22
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
@ SIGHASH_ALL
Definition: interpreter.h:28
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
Definition: policy.h:77
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:489
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
Definition: psbt.cpp:323
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.
Definition: psbt.cpp:283
std::string PSBTRoleName(PSBTRole role)
Definition: psbt.cpp:477
size_t CountPSBTUnsignedInputs(const PartiallySignedTransaction &psbt)
Counts the unsigned inputs of a PSBT.
Definition: psbt.cpp:312
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:448
bool DecodeRawPSBT(PartiallySignedTransaction &psbt, Span< const std::byte > tx_data, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:499
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, const PrecomputedTransactionData *txdata, int sighash, SignatureData *out_sigdata, bool finalize)
Signs a PSBTInput, verifying that all provided data matches what is being signed.
Definition: psbt.cpp:360
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed by checking for non-null finalized fields.
Definition: psbt.cpp:278
PrecomputedTransactionData PrecomputePSBTData(const PartiallySignedTransaction &psbt)
Compute a PrecomputedTransactionData object from a psbt.
Definition: psbt.cpp:343
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:464
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
Definition: psbt.cpp:433
PSBTRole
Definition: psbt.h:1208
@ SER_NETWORK
Definition: serialize.h:131
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:383
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
Definition: sign.cpp:633
const SigningProvider & DUMMY_SIGNING_PROVIDER
Span< const std::byte > MakeByteSpan(V &&v) noexcept
Definition: span.h:264
A mutable version of CTransaction.
Definition: transaction.h:380
std::vector< CTxOut > vout
Definition: transaction.h:382
std::vector< CTxIn > vin
Definition: transaction.h:381
bool IsNull() const
Definition: script.h:571
void SetNull()
Definition: script.h:573
A structure for PSBTs which contain per-input information.
Definition: psbt.h:192
std::vector< unsigned char > m_tap_key_sig
Definition: psbt.h:207
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:199
std::map< uint256, std::vector< unsigned char > > hash256_preimages
Definition: psbt.h:204
CScriptWitness final_script_witness
Definition: psbt.h:198
std::map< std::pair< std::vector< unsigned char >, int >, std::set< std::vector< unsigned char >, ShortestVectorFirstComparator > > m_tap_scripts
Definition: psbt.h:209
CTransactionRef non_witness_utxo
Definition: psbt.h:193
std::map< CKeyID, SigPair > partial_sigs
Definition: psbt.h:200
std::map< std::pair< XOnlyPubKey, uint256 >, std::vector< unsigned char > > m_tap_script_sigs
Definition: psbt.h:208
uint256 m_tap_merkle_root
Definition: psbt.h:212
std::map< uint256, std::vector< unsigned char > > sha256_preimages
Definition: psbt.h:202
void FillSignatureData(SignatureData &sigdata) const
Definition: psbt.cpp:93
std::map< uint160, std::vector< unsigned char > > hash160_preimages
Definition: psbt.h:203
bool IsNull() const
Definition: psbt.cpp:88
void Merge(const PSBTInput &input)
Definition: psbt.cpp:184
CScript redeem_script
Definition: psbt.h:195
CScript final_script_sig
Definition: psbt.h:197
void FromSignatureData(const SignatureData &sigdata)
Definition: psbt.cpp:137
XOnlyPubKey m_tap_internal_key
Definition: psbt.h:211
std::map< XOnlyPubKey, std::pair< std::set< uint256 >, KeyOriginInfo > > m_tap_bip32_paths
Definition: psbt.h:210
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:214
std::map< uint160, std::vector< unsigned char > > ripemd160_preimages
Definition: psbt.h:201
CTxOut witness_utxo
Definition: psbt.h:194
CScript witness_script
Definition: psbt.h:196
A structure for PSBTs which contains per output information.
Definition: psbt.h:711
XOnlyPubKey m_tap_internal_key
Definition: psbt.h:715
std::map< XOnlyPubKey, std::pair< std::set< uint256 >, KeyOriginInfo > > m_tap_bip32_paths
Definition: psbt.h:717
CScript witness_script
Definition: psbt.h:713
bool IsNull() const
Definition: psbt.cpp:261
void Merge(const PSBTOutput &output)
Definition: psbt.cpp:266
CScript redeem_script
Definition: psbt.h:712
std::map< CPubKey, KeyOriginInfo > hd_keypaths
Definition: psbt.h:714
std::vector< std::tuple< uint8_t, uint8_t, std::vector< unsigned char > > > m_tap_tree
Definition: psbt.h:716
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:718
void FillSignatureData(SignatureData &sigdata) const
Definition: psbt.cpp:211
void FromSignatureData(const SignatureData &sigdata)
Definition: psbt.cpp:239
A version of CTransaction with the PSBT format.
Definition: psbt.h:947
uint32_t GetVersion() const
Definition: psbt.cpp:515
bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
Definition: psbt.cpp:23
std::map< KeyOriginInfo, std::set< CExtPubKey > > m_xpubs
Definition: psbt.h:951
std::optional< uint32_t > m_version
Definition: psbt.h:955
bool IsNull() const
Definition: psbt.cpp:18
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
Definition: psbt.cpp:68
std::map< std::vector< unsigned char >, std::vector< unsigned char > > unknown
Definition: psbt.h:954
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
Definition: psbt.cpp:61
std::vector< PSBTInput > inputs
Definition: psbt.h:952
std::optional< CMutableTransaction > tx
Definition: psbt.h:948
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
Definition: psbt.cpp:48
std::vector< PSBTOutput > outputs
Definition: psbt.h:953
void Init(const T &tx, std::vector< CTxOut > &&spent_outputs, bool force=false)
Initialize this PrecomputedTransactionData with transaction data.
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
Definition: sign.h:84
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
Definition: sign.h:83
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a ...
Definition: sign.h:77
TaprootSpendData tr_spenddata
Taproot spending data.
Definition: sign.h:75
bool witness
Stores whether the input this SigData corresponds to is a witness input.
Definition: sign.h:70
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
Definition: sign.h:78
std::optional< TaprootBuilder > tr_builder
Taproot tree used to build tr_spenddata.
Definition: sign.h:76
CScript scriptSig
The scriptSig of an input. Contains complete signatures or the traditional partial signatures format.
Definition: sign.h:71
std::vector< unsigned char > taproot_key_path_sig
Definition: sign.h:79
std::map< std::pair< XOnlyPubKey, uint256 >, std::vector< unsigned char > > taproot_script_sigs
Schnorr signature for key path spending.
Definition: sign.h:80
std::map< XOnlyPubKey, std::pair< std::set< uint256 >, KeyOriginInfo > > taproot_misc_pubkeys
Miscellaneous Taproot pubkeys involved in this input along with their leaf script hashes and key orig...
Definition: sign.h:81
CScript redeem_script
The redeemScript (if any) for the input.
Definition: sign.h:72
uint256 missing_witness_script
SHA256 of the missing witnessScript (if any)
Definition: sign.h:85
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
Definition: sign.h:82
CScript witness_script
The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
Definition: sign.h:73
CScriptWitness scriptWitness
The scriptWitness of an input. Contains complete signatures or the traditional partial signatures for...
Definition: sign.h:74
bool complete
Stores whether the scriptSig and scriptWitness are complete.
Definition: sign.h:69
uint256 merkle_root
The Merkle root of the script tree (0 if no scripts).
Definition: standard.h:213
std::map< std::pair< std::vector< unsigned char >, int >, std::set< std::vector< unsigned char >, ShortestVectorFirstComparator > > scripts
Map from (script, leaf_version) to (sets of) control blocks.
Definition: standard.h:220
void Merge(TaprootSpendData other)
Merge other TaprootSpendData (for the same scriptPubKey) into this.
Definition: standard.cpp:377
XOnlyPubKey internal_key
The BIP341 internal key.
Definition: standard.h:211
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
static int count
Definition: tests.c:34
std::optional< std::vector< unsigned char > > DecodeBase64(std::string_view str)
assert(!tx.IsCoinBase())
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12