Bitcoin ABC  0.24.7
P2P Digital Currency
sign.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <script/sign.h>
7 
8 #include <key.h>
9 #include <policy/policy.h>
10 #include <primitives/transaction.h>
11 #include <script/signingprovider.h>
12 #include <script/standard.h>
13 #include <uint256.h>
14 
15 typedef std::vector<uint8_t> valtype;
16 
18  const CMutableTransaction *txToIn, unsigned int nInIn,
19  const Amount &amountIn, SigHashType sigHashTypeIn)
20  : txTo(txToIn), nIn(nInIn), amount(amountIn), sigHashType(sigHashTypeIn),
21  checker(txTo, nIn, amountIn) {}
22 
24  const SigningProvider &provider, std::vector<uint8_t> &vchSig,
25  const CKeyID &address, const CScript &scriptCode) const {
26  CKey key;
27  if (!provider.GetKey(address, key)) {
28  return false;
29  }
30 
31  uint256 hash = SignatureHash(scriptCode, *txTo, nIn, sigHashType, amount);
32  if (!key.SignECDSA(hash, vchSig)) {
33  return false;
34  }
35 
36  vchSig.push_back(uint8_t(sigHashType.getRawSigHashType()));
37  return true;
38 }
39 
40 static bool GetCScript(const SigningProvider &provider,
41  const SignatureData &sigdata, const CScriptID &scriptid,
42  CScript &script) {
43  if (provider.GetCScript(scriptid, script)) {
44  return true;
45  }
46  // Look for scripts in SignatureData
47  if (CScriptID(sigdata.redeem_script) == scriptid) {
48  script = sigdata.redeem_script;
49  return true;
50  }
51  return false;
52 }
53 
54 static bool GetPubKey(const SigningProvider &provider,
55  const SignatureData &sigdata, const CKeyID &address,
56  CPubKey &pubkey) {
57  // Look for pubkey in all partial sigs
58  const auto it = sigdata.signatures.find(address);
59  if (it != sigdata.signatures.end()) {
60  pubkey = it->second.first;
61  return true;
62  }
63  // Look for pubkey in pubkey list
64  const auto &pk_it = sigdata.misc_pubkeys.find(address);
65  if (pk_it != sigdata.misc_pubkeys.end()) {
66  pubkey = pk_it->second.first;
67  return true;
68  }
69  // Query the underlying provider
70  return provider.GetPubKey(address, pubkey);
71 }
72 
73 static bool CreateSig(const BaseSignatureCreator &creator,
74  SignatureData &sigdata, const SigningProvider &provider,
75  std::vector<uint8_t> &sig_out, const CPubKey &pubkey,
76  const CScript &scriptcode) {
77  CKeyID keyid = pubkey.GetID();
78  const auto it = sigdata.signatures.find(keyid);
79  if (it != sigdata.signatures.end()) {
80  sig_out = it->second.second;
81  return true;
82  }
83  KeyOriginInfo info;
84  if (provider.GetKeyOrigin(keyid, info)) {
85  sigdata.misc_pubkeys.emplace(keyid,
86  std::make_pair(pubkey, std::move(info)));
87  }
88  if (creator.CreateSig(provider, sig_out, keyid, scriptcode)) {
89  auto i = sigdata.signatures.emplace(keyid, SigPair(pubkey, sig_out));
90  assert(i.second);
91  return true;
92  }
93  // Could not make signature or signature not found, add keyid to missing
94  sigdata.missing_sigs.push_back(keyid);
95  return false;
96 }
97 
105 static bool SignStep(const SigningProvider &provider,
106  const BaseSignatureCreator &creator,
107  const CScript &scriptPubKey, std::vector<valtype> &ret,
108  TxoutType &whichTypeRet, SignatureData &sigdata) {
109  CScript scriptRet;
110  uint160 h160;
111  ret.clear();
112  std::vector<uint8_t> sig;
113 
114  std::vector<valtype> vSolutions;
115  whichTypeRet = Solver(scriptPubKey, vSolutions);
116 
117  switch (whichTypeRet) {
120  return false;
121  case TxoutType::PUBKEY:
122  if (!CreateSig(creator, sigdata, provider, sig,
123  CPubKey(vSolutions[0]), scriptPubKey)) {
124  return false;
125  }
126  ret.push_back(std::move(sig));
127  return true;
128  case TxoutType::PUBKEYHASH: {
129  CKeyID keyID = CKeyID(uint160(vSolutions[0]));
130  CPubKey pubkey;
131  if (!GetPubKey(provider, sigdata, keyID, pubkey)) {
132  // Pubkey could not be found, add to missing
133  sigdata.missing_pubkeys.push_back(keyID);
134  return false;
135  }
136  if (!CreateSig(creator, sigdata, provider, sig, pubkey,
137  scriptPubKey)) {
138  return false;
139  }
140  ret.push_back(std::move(sig));
141  ret.push_back(ToByteVector(pubkey));
142  return true;
143  }
145  h160 = uint160(vSolutions[0]);
146  if (GetCScript(provider, sigdata, CScriptID{h160}, scriptRet)) {
147  ret.push_back(
148  std::vector<uint8_t>(scriptRet.begin(), scriptRet.end()));
149  return true;
150  }
151  // Could not find redeemScript, add to missing
152  sigdata.missing_redeem_script = h160;
153  return false;
154  case TxoutType::MULTISIG: {
155  size_t required = vSolutions.front()[0];
156  // workaround CHECKMULTISIG bug
157  ret.push_back(valtype());
158  for (size_t i = 1; i < vSolutions.size() - 1; ++i) {
159  CPubKey pubkey = CPubKey(vSolutions[i]);
160  // We need to always call CreateSig in order to fill sigdata
161  // with all possible signatures that we can create. This will
162  // allow further PSBT processing to work as it needs all
163  // possible signature and pubkey pairs
164  if (CreateSig(creator, sigdata, provider, sig, pubkey,
165  scriptPubKey)) {
166  if (ret.size() < required + 1) {
167  ret.push_back(std::move(sig));
168  }
169  }
170  }
171  bool ok = ret.size() == required + 1;
172  for (size_t i = 0; i + ret.size() < required + 1; ++i) {
173  ret.push_back(valtype());
174  }
175  return ok;
176  }
177  default:
178  return false;
179  }
180 }
181 
182 static CScript PushAll(const std::vector<valtype> &values) {
183  CScript result;
184  for (const valtype &v : values) {
185  if (v.size() == 0) {
186  result << OP_0;
187  } else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
188  result << CScript::EncodeOP_N(v[0]);
189  } else {
190  result << v;
191  }
192  }
193 
194  return result;
195 }
196 
197 bool ProduceSignature(const SigningProvider &provider,
198  const BaseSignatureCreator &creator,
199  const CScript &fromPubKey, SignatureData &sigdata) {
200  if (sigdata.complete) {
201  return true;
202  }
203 
204  std::vector<valtype> result;
205  TxoutType whichType;
206  bool solved =
207  SignStep(provider, creator, fromPubKey, result, whichType, sigdata);
208  CScript subscript;
209 
210  if (solved && whichType == TxoutType::SCRIPTHASH) {
211  // Solver returns the subscript that needs to be evaluated; the final
212  // scriptSig is the signatures from that and then the serialized
213  // subscript:
214  subscript = CScript(result[0].begin(), result[0].end());
215  sigdata.redeem_script = subscript;
216 
217  solved = solved &&
218  SignStep(provider, creator, subscript, result, whichType,
219  sigdata) &&
220  whichType != TxoutType::SCRIPTHASH;
221  result.push_back(
222  std::vector<uint8_t>(subscript.begin(), subscript.end()));
223  }
224 
225  sigdata.scriptSig = PushAll(result);
226 
227  // Test solution
228  sigdata.complete =
229  solved && VerifyScript(sigdata.scriptSig, fromPubKey,
231  return sigdata.complete;
232 }
233 
234 namespace {
235 class SignatureExtractorChecker final : public BaseSignatureChecker {
236 private:
237  SignatureData &sigdata;
238  BaseSignatureChecker &checker;
239 
240 public:
241  SignatureExtractorChecker(SignatureData &sigdata_,
242  BaseSignatureChecker &checker_)
243  : sigdata(sigdata_), checker(checker_) {}
244  bool CheckSig(const std::vector<uint8_t> &scriptSig,
245  const std::vector<uint8_t> &vchPubKey,
246  const CScript &scriptCode, uint32_t flags) const override {
247  if (checker.CheckSig(scriptSig, vchPubKey, scriptCode, flags)) {
248  CPubKey pubkey(vchPubKey);
249 
250  sigdata.signatures.emplace(pubkey.GetID(),
251  SigPair(pubkey, scriptSig));
252  return true;
253  }
254  return false;
255  }
256 };
257 
258 struct Stacks {
259  std::vector<valtype> script;
260 
261  Stacks() = delete;
262  Stacks(const Stacks &) = delete;
263  explicit Stacks(const SignatureData &data) {
264  if (data.scriptSig.IsPushOnly()) {
267  }
268  }
269 };
270 } // namespace
271 
272 // Extracts signatures and scripts from incomplete scriptSigs. Please do not
273 // extend this, use PSBT instead
275  unsigned int nIn, const CTxOut &txout) {
276  SignatureData data;
277  assert(tx.vin.size() > nIn);
278  data.scriptSig = tx.vin[nIn].scriptSig;
279  Stacks stack(data);
280 
281  // Get signatures
282  MutableTransactionSignatureChecker tx_checker(&tx, nIn, txout.nValue);
283  SignatureExtractorChecker extractor_checker(data, tx_checker);
284  if (VerifyScript(data.scriptSig, txout.scriptPubKey,
285  STANDARD_SCRIPT_VERIFY_FLAGS, extractor_checker)) {
286  data.complete = true;
287  return data;
288  }
289 
290  // Get scripts
291  std::vector<std::vector<uint8_t>> solutions;
292  TxoutType script_type = Solver(txout.scriptPubKey, solutions);
293  CScript next_script = txout.scriptPubKey;
294 
295  if (script_type == TxoutType::SCRIPTHASH && !stack.script.empty() &&
296  !stack.script.back().empty()) {
297  // Get the redeemScript
298  CScript redeem_script(stack.script.back().begin(),
299  stack.script.back().end());
300  data.redeem_script = redeem_script;
301  next_script = std::move(redeem_script);
302 
303  // Get redeemScript type
304  script_type = Solver(next_script, solutions);
305  stack.script.pop_back();
306  }
307  if (script_type == TxoutType::MULTISIG && !stack.script.empty()) {
308  // Build a map of pubkey -> signature by matching sigs to pubkeys:
309  assert(solutions.size() > 1);
310  unsigned int num_pubkeys = solutions.size() - 2;
311  unsigned int last_success_key = 0;
312  for (const valtype &sig : stack.script) {
313  for (unsigned int i = last_success_key; i < num_pubkeys; ++i) {
314  const valtype &pubkey = solutions[i + 1];
315  // We either have a signature for this pubkey, or we have found
316  // a signature and it is valid
317  if (data.signatures.count(CPubKey(pubkey).GetID()) ||
318  extractor_checker.CheckSig(sig, pubkey, next_script,
320  last_success_key = i + 1;
321  break;
322  }
323  }
324  }
325  }
326 
327  return data;
328 }
329 
330 void UpdateInput(CTxIn &input, const SignatureData &data) {
331  input.scriptSig = data.scriptSig;
332 }
333 
335  if (complete) {
336  return;
337  }
338  if (sigdata.complete) {
339  *this = std::move(sigdata);
340  return;
341  }
342  if (redeem_script.empty() && !sigdata.redeem_script.empty()) {
343  redeem_script = sigdata.redeem_script;
344  }
345  signatures.insert(std::make_move_iterator(sigdata.signatures.begin()),
346  std::make_move_iterator(sigdata.signatures.end()));
347 }
348 
349 bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey,
350  CMutableTransaction &txTo, unsigned int nIn,
351  const Amount amount, SigHashType sigHashType) {
352  assert(nIn < txTo.vin.size());
353 
354  MutableTransactionSignatureCreator creator(&txTo, nIn, amount, sigHashType);
355 
356  SignatureData sigdata;
357  bool ret = ProduceSignature(provider, creator, fromPubKey, sigdata);
358  UpdateInput(txTo.vin.at(nIn), sigdata);
359  return ret;
360 }
361 
362 bool SignSignature(const SigningProvider &provider, const CTransaction &txFrom,
363  CMutableTransaction &txTo, unsigned int nIn,
364  SigHashType sigHashType) {
365  assert(nIn < txTo.vin.size());
366  CTxIn &txin = txTo.vin[nIn];
367  assert(txin.prevout.GetN() < txFrom.vout.size());
368  const CTxOut &txout = txFrom.vout[txin.prevout.GetN()];
369 
370  return SignSignature(provider, txout.scriptPubKey, txTo, nIn, txout.nValue,
371  sigHashType);
372 }
373 
374 namespace {
376 class DummySignatureChecker final : public BaseSignatureChecker {
377 public:
378  DummySignatureChecker() {}
379  bool CheckSig(const std::vector<uint8_t> &scriptSig,
380  const std::vector<uint8_t> &vchPubKey,
381  const CScript &scriptCode, uint32_t flags) const override {
382  return true;
383  }
384 };
385 const DummySignatureChecker DUMMY_CHECKER;
386 
387 class DummySignatureCreator final : public BaseSignatureCreator {
388 private:
389  char m_r_len = 32;
390  char m_s_len = 32;
391 
392 public:
393  DummySignatureCreator(char r_len, char s_len)
394  : m_r_len(r_len), m_s_len(s_len) {}
395  const BaseSignatureChecker &Checker() const override {
396  return DUMMY_CHECKER;
397  }
398  bool CreateSig(const SigningProvider &provider,
399  std::vector<uint8_t> &vchSig, const CKeyID &keyid,
400  const CScript &scriptCode) const override {
401  // Create a dummy signature that is a valid DER-encoding
402  vchSig.assign(m_r_len + m_s_len + 7, '\000');
403  vchSig[0] = 0x30;
404  vchSig[1] = m_r_len + m_s_len + 4;
405  vchSig[2] = 0x02;
406  vchSig[3] = m_r_len;
407  vchSig[4] = 0x01;
408  vchSig[4 + m_r_len] = 0x02;
409  vchSig[5 + m_r_len] = m_s_len;
410  vchSig[6 + m_r_len] = 0x01;
411  vchSig[6 + m_r_len + m_s_len] = SIGHASH_ALL | SIGHASH_FORKID;
412  return true;
413  }
414 };
415 
416 } // namespace
417 
419  DummySignatureCreator(32, 32);
421  DummySignatureCreator(33, 32);
422 
423 bool IsSolvable(const SigningProvider &provider, const CScript &script) {
424  // This check is to make sure that the script we created can actually be
425  // solved for and signed by us if we were to have the private keys. This is
426  // just to make sure that the script is valid and that, if found in a
427  // transaction, we would still accept and relay that transaction.
428  SignatureData sigs;
429  if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
430  // VerifyScript check is just defensive, and should never fail.
431  bool verified =
433  DUMMY_CHECKER);
434  assert(verified);
435  return true;
436  }
437  return false;
438 }
439 
441  const std::map<COutPoint, Coin> &coins,
442  SigHashType sigHashType,
443  std::map<int, std::string> &input_errors) {
444  // Use CTransaction for the constant parts of the
445  // transaction to avoid rehashing.
446  const CTransaction txConst(mtx);
447  // Sign what we can:
448  for (size_t i = 0; i < mtx.vin.size(); i++) {
449  CTxIn &txin = mtx.vin[i];
450  auto coin = coins.find(txin.prevout);
451  if (coin == coins.end() || coin->second.IsSpent()) {
452  input_errors[i] = "Input not found or already spent";
453  continue;
454  }
455  const CScript &prevPubKey = coin->second.GetTxOut().scriptPubKey;
456  const Amount amount = coin->second.GetTxOut().nValue;
457 
458  SignatureData sigdata =
459  DataFromTransaction(mtx, i, coin->second.GetTxOut());
460  // Only sign SIGHASH_SINGLE if there's a corresponding output:
461  if ((sigHashType.getBaseType() != BaseSigHashType::SINGLE) ||
462  (i < mtx.vout.size())) {
463  ProduceSignature(*keystore,
464  MutableTransactionSignatureCreator(&mtx, i, amount,
465  sigHashType),
466  prevPubKey, sigdata);
467  }
468 
469  UpdateInput(txin, sigdata);
470 
471  // amount must be specified for valid signature
472  if (amount == MAX_MONEY) {
473  input_errors[i] = "Missing amount";
474  continue;
475  }
476 
477  ScriptError serror = ScriptError::OK;
478  if (!VerifyScript(
479  txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS,
480  TransactionSignatureChecker(&txConst, i, amount), &serror)) {
481  if (serror == ScriptError::INVALID_STACK_OPERATION) {
482  // Unable to sign input and verification failed (possible
483  // attempt to partially sign).
484  input_errors[i] = "Unable to sign input, invalid stack size "
485  "(possibly missing key)";
486  } else {
487  input_errors[i] = ScriptErrorString(serror);
488  }
489  } else {
490  // If this input succeeds, make sure there is no error set for it
491  input_errors.erase(i);
492  }
493  }
494  return input_errors.empty();
495 }
ScriptErrorString
std::string ScriptErrorString(const ScriptError serror)
Definition: script_error.cpp:10
CreateSig
static bool CreateSig(const BaseSignatureCreator &creator, SignatureData &sigdata, const SigningProvider &provider, std::vector< uint8_t > &sig_out, const CPubKey &pubkey, const CScript &scriptcode)
Definition: sign.cpp:73
CTxIn
An input of a transaction.
Definition: transaction.h:61
policy.h
OP_0
@ OP_0
Definition: script.h:48
BaseSignatureChecker::CheckSig
virtual bool CheckSig(const std::vector< uint8_t > &vchSigIn, const std::vector< uint8_t > &vchPubKey, const CScript &scriptCode, uint32_t flags) const
Definition: interpreter.h:37
CTxOut::nValue
Amount nValue
Definition: transaction.h:132
ScriptError
ScriptError
Definition: script_error.h:11
MutableTransactionSignatureCreator::amount
Amount amount
Definition: sign.h:41
SignatureData::missing_redeem_script
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
Definition: sign.h:83
SignatureHash
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, SigHashType sigHashType, const Amount amount, const PrecomputedTransactionData *cache, uint32_t flags)
Definition: interpreter.cpp:1566
TxoutType
TxoutType
Definition: standard.h:85
flags
int flags
Definition: bitcoin-tx.cpp:532
ScriptError::OK
@ OK
TxoutType::NONSTANDARD
@ NONSTANDARD
DUMMY_SIGNATURE_CREATOR
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
Definition: sign.cpp:418
SignatureData::MergeSignatureData
void MergeSignatureData(SignatureData sigdata)
Definition: sign.cpp:334
SignSignature
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const Amount amount, SigHashType sigHashType)
Produce a script signature for a transaction.
Definition: sign.cpp:349
transaction.h
uint256.h
GenericTransactionSignatureChecker
Definition: interpreter.h:55
SIGHASH_ALL
@ SIGHASH_ALL
Definition: sighashtype.h:15
SigningProvider
An interface to be implemented by keystores that support signing.
Definition: signingprovider.h:20
MutableTransactionSignatureCreator
A signature creator for transactions.
Definition: sign.h:38
MutableTransactionSignatureCreator::nIn
unsigned int nIn
Definition: sign.h:40
CScript::EncodeOP_N
static opcodetype EncodeOP_N(int n)
Definition: script.h:519
BaseSignatureChecker
Definition: interpreter.h:31
EvalScript
bool EvalScript(std::vector< valtype > &stack, const CScript &script, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metrics, ScriptError *serror)
Definition: interpreter.cpp:203
VerifyScript
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metricsOut, ScriptError *serror)
Execute an unlocking and locking script together.
Definition: interpreter.cpp:1777
CKeyID
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:22
SigningProvider::GetPubKey
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
Definition: signingprovider.h:27
SigPair
std::pair< CPubKey, std::vector< uint8_t > > SigPair
Definition: sign.h:60
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
CScript::IsPushOnly
bool IsPushOnly(const_iterator pc) const
Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
Definition: script.cpp:425
signingprovider.h
prevector::end
iterator end()
Definition: prevector.h:392
sig
SchnorrSig sig
Definition: processor.cpp:322
PushAll
static CScript PushAll(const std::vector< valtype > &values)
Definition: sign.cpp:182
TxoutType::PUBKEY
@ PUBKEY
DUMMY_MAXIMUM_SIGNATURE_CREATOR
const BaseSignatureCreator & DUMMY_MAXIMUM_SIGNATURE_CREATOR
A signature creator that just produces 72-byte empty signatures.
Definition: sign.cpp:420
SignatureData
Definition: sign.h:66
BaseSignatureCreator::CreateSig
virtual bool CreateSig(const SigningProvider &provider, std::vector< uint8_t > &vchSig, const CKeyID &keyid, const CScript &scriptCode) const =0
Create a singular (non-script) signature.
SigningProvider::GetKeyOrigin
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
Definition: signingprovider.h:34
CTxOut
An output of a transaction.
Definition: transaction.h:130
CTransaction::vout
const std::vector< CTxOut > vout
Definition: transaction.h:211
CTxOut::scriptPubKey
CScript scriptPubKey
Definition: transaction.h:133
valtype
std::vector< uint8_t > valtype
Definition: sign.cpp:15
Solver
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
Definition: standard.cpp:111
MutableTransactionSignatureCreator::sigHashType
SigHashType sigHashType
Definition: sign.h:42
SignatureData::redeem_script
CScript redeem_script
The redeemScript (if any) for the input.
Definition: sign.h:73
SignatureData::scriptSig
CScript scriptSig
The scriptSig of an input.
Definition: sign.h:71
sign.h
standard.h
SigHashType
Signature hash type wrapper class.
Definition: sighashtype.h:37
SignTransaction
bool SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, SigHashType sigHashType, std::map< int, std::string > &input_errors)
Sign the CMutableTransaction.
Definition: sign.cpp:440
SignatureData::signatures
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input.
Definition: sign.h:76
SignStep
static bool SignStep(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &scriptPubKey, std::vector< valtype > &ret, TxoutType &whichTypeRet, SignatureData &sigdata)
Sign scriptPubKey using signature made with creator.
Definition: sign.cpp:105
SignatureData::missing_sigs
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
Definition: sign.h:81
TxoutType::SCRIPTHASH
@ SCRIPTHASH
SignatureData::complete
bool complete
Stores whether the scriptSig are complete.
Definition: sign.h:68
uint256
256-bit opaque blob.
Definition: uint256.h:127
SigningProvider::GetCScript
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
Definition: signingprovider.h:23
Amount
Definition: amount.h:19
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
valtype
std::vector< uint8_t > valtype
Definition: sigencoding.h:16
SigHashType::getRawSigHashType
uint32_t getRawSigHashType() const
Definition: sighashtype.h:83
TxoutType::NULL_DATA
@ NULL_DATA
MutableTransactionSignatureCreator::CreateSig
bool CreateSig(const SigningProvider &provider, std::vector< uint8_t > &vchSig, const CKeyID &keyid, const CScript &scriptCode) const override
Create a singular (non-script) signature.
Definition: sign.cpp:23
TxoutType::PUBKEYHASH
@ PUBKEYHASH
ProduceSignature
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:197
MutableTransactionSignatureCreator::txTo
const CMutableTransaction * txTo
Definition: sign.h:39
SignatureData::missing_pubkeys
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
Definition: sign.h:79
SIGHASH_FORKID
@ SIGHASH_FORKID
Definition: sighashtype.h:18
key.h
uint160
160-bit opaque blob.
Definition: uint256.h:115
ScriptError::INVALID_STACK_OPERATION
@ INVALID_STACK_OPERATION
MutableTransactionSignatureCreator::MutableTransactionSignatureCreator
MutableTransactionSignatureCreator(const CMutableTransaction *txToIn, unsigned int nInIn, const Amount &amountIn, SigHashType sigHashTypeIn=SigHashType())
Definition: sign.cpp:17
CPubKey
An encapsulated public key.
Definition: pubkey.h:31
STANDARD_SCRIPT_VERIFY_FLAGS
static constexpr uint32_t STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
Definition: policy.h:91
CKey
An encapsulated secp256k1 private key.
Definition: key.h:28
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:281
IsSolvable
bool IsSolvable(const SigningProvider &provider, const CScript &script)
Check whether we know how to sign for an output like this, assuming we have all private keys.
Definition: sign.cpp:423
GetCScript
static bool GetCScript(const SigningProvider &provider, const SignatureData &sigdata, const CScriptID &scriptid, CScript &script)
Definition: sign.cpp:40
SignatureData::misc_pubkeys
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
Definition: sign.h:77
ToByteVector
std::vector< uint8_t > ToByteVector(const T &in)
Definition: script.h:41
CTxIn::prevout
COutPoint prevout
Definition: transaction.h:63
CTxIn::scriptSig
CScript scriptSig
Definition: transaction.h:64
prevector::begin
iterator begin()
Definition: prevector.h:390
TxoutType::MULTISIG
@ MULTISIG
SigningProvider::GetKey
virtual bool GetKey(const CKeyID &address, CKey &key) const
Definition: signingprovider.h:30
prevector::empty
bool empty() const
Definition: prevector.h:388
BaseSignatureCreator::Checker
virtual const BaseSignatureChecker & Checker() const =0
BaseSigHashType::SINGLE
@ SINGLE
SigHashType::getBaseType
BaseSigHashType getBaseType() const
Definition: sighashtype.h:64
COutPoint::GetN
uint32_t GetN() const
Definition: transaction.h:38
UpdateInput
void UpdateInput(CTxIn &input, const SignatureData &data)
Definition: sign.cpp:330
MAX_MONEY
static const Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:175
BaseSignatureCreator
Interface for signature creators.
Definition: sign.h:26
CScriptID
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:65
DataFromTransaction
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
Definition: sign.cpp:274
GetPubKey
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
Definition: sign.cpp:54
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:280
SCRIPT_VERIFY_NONE
@ SCRIPT_VERIFY_NONE
Definition: script_flags.h:12
KeyOriginInfo
Definition: keyorigin.h:11
CPubKey::GetID
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:140
CKey::SignECDSA
bool SignECDSA(const uint256 &hash, std::vector< uint8_t > &vchSig, bool grind=true, uint32_t test_case=0) const
Create a DER-serialized ECDSA signature.
Definition: key.cpp:242
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:278