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