Bitcoin Core  0.18.99
P2P Digital Currency
sign.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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<unsigned char> valtype;
16 
17 MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
18 
19 bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& address, const CScript& scriptCode, SigVersion sigversion) const
20 {
21  CKey key;
22  if (!provider.GetKey(address, key))
23  return false;
24 
25  // Signing with uncompressed keys is disabled in witness scripts
26  if (sigversion == SigVersion::WITNESS_V0 && !key.IsCompressed())
27  return false;
28 
29  uint256 hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion);
30  if (!key.Sign(hash, vchSig))
31  return false;
32  vchSig.push_back((unsigned char)nHashType);
33  return true;
34 }
35 
36 static bool GetCScript(const SigningProvider& provider, const SignatureData& sigdata, const CScriptID& scriptid, CScript& script)
37 {
38  if (provider.GetCScript(scriptid, script)) {
39  return true;
40  }
41  // Look for scripts in SignatureData
42  if (CScriptID(sigdata.redeem_script) == scriptid) {
43  script = sigdata.redeem_script;
44  return true;
45  } else if (CScriptID(sigdata.witness_script) == scriptid) {
46  script = sigdata.witness_script;
47  return true;
48  }
49  return false;
50 }
51 
52 static bool GetPubKey(const SigningProvider& provider, const SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey)
53 {
54  // Look for pubkey in all partial sigs
55  const auto it = sigdata.signatures.find(address);
56  if (it != sigdata.signatures.end()) {
57  pubkey = it->second.first;
58  return true;
59  }
60  // Look for pubkey in pubkey list
61  const auto& pk_it = sigdata.misc_pubkeys.find(address);
62  if (pk_it != sigdata.misc_pubkeys.end()) {
63  pubkey = pk_it->second.first;
64  return true;
65  }
66  // Query the underlying provider
67  return provider.GetPubKey(address, pubkey);
68 }
69 
70 static bool CreateSig(const BaseSignatureCreator& creator, SignatureData& sigdata, const SigningProvider& provider, std::vector<unsigned char>& sig_out, const CPubKey& pubkey, const CScript& scriptcode, SigVersion sigversion)
71 {
72  CKeyID keyid = pubkey.GetID();
73  const auto it = sigdata.signatures.find(keyid);
74  if (it != sigdata.signatures.end()) {
75  sig_out = it->second.second;
76  return true;
77  }
78  KeyOriginInfo info;
79  if (provider.GetKeyOrigin(keyid, info)) {
80  sigdata.misc_pubkeys.emplace(keyid, std::make_pair(pubkey, std::move(info)));
81  }
82  if (creator.CreateSig(provider, sig_out, keyid, scriptcode, sigversion)) {
83  auto i = sigdata.signatures.emplace(keyid, SigPair(pubkey, sig_out));
84  assert(i.second);
85  return true;
86  }
87  // Could not make signature or signature not found, add keyid to missing
88  sigdata.missing_sigs.push_back(keyid);
89  return false;
90 }
91 
98 static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator& creator, const CScript& scriptPubKey,
99  std::vector<valtype>& ret, txnouttype& whichTypeRet, SigVersion sigversion, SignatureData& sigdata)
100 {
101  CScript scriptRet;
102  uint160 h160;
103  ret.clear();
104  std::vector<unsigned char> sig;
105 
106  std::vector<valtype> vSolutions;
107  whichTypeRet = Solver(scriptPubKey, vSolutions);
108 
109  switch (whichTypeRet)
110  {
111  case TX_NONSTANDARD:
112  case TX_NULL_DATA:
113  case TX_WITNESS_UNKNOWN:
114  return false;
115  case TX_PUBKEY:
116  if (!CreateSig(creator, sigdata, provider, sig, CPubKey(vSolutions[0]), scriptPubKey, sigversion)) return false;
117  ret.push_back(std::move(sig));
118  return true;
119  case TX_PUBKEYHASH: {
120  CKeyID keyID = CKeyID(uint160(vSolutions[0]));
121  CPubKey pubkey;
122  if (!GetPubKey(provider, sigdata, keyID, pubkey)) {
123  // Pubkey could not be found, add to missing
124  sigdata.missing_pubkeys.push_back(keyID);
125  return false;
126  }
127  if (!CreateSig(creator, sigdata, provider, sig, pubkey, scriptPubKey, sigversion)) return false;
128  ret.push_back(std::move(sig));
129  ret.push_back(ToByteVector(pubkey));
130  return true;
131  }
132  case TX_SCRIPTHASH:
133  h160 = uint160(vSolutions[0]);
134  if (GetCScript(provider, sigdata, h160, scriptRet)) {
135  ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
136  return true;
137  }
138  // Could not find redeemScript, add to missing
139  sigdata.missing_redeem_script = h160;
140  return false;
141 
142  case TX_MULTISIG: {
143  size_t required = vSolutions.front()[0];
144  ret.push_back(valtype()); // workaround CHECKMULTISIG bug
145  for (size_t i = 1; i < vSolutions.size() - 1; ++i) {
146  CPubKey pubkey = CPubKey(vSolutions[i]);
147  if (ret.size() < required + 1 && CreateSig(creator, sigdata, provider, sig, pubkey, scriptPubKey, sigversion)) {
148  ret.push_back(std::move(sig));
149  }
150  }
151  bool ok = ret.size() == required + 1;
152  for (size_t i = 0; i + ret.size() < required + 1; ++i) {
153  ret.push_back(valtype());
154  }
155  return ok;
156  }
158  ret.push_back(vSolutions[0]);
159  return true;
160 
162  CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(h160.begin());
163  if (GetCScript(provider, sigdata, h160, scriptRet)) {
164  ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
165  return true;
166  }
167  // Could not find witnessScript, add to missing
168  sigdata.missing_witness_script = uint256(vSolutions[0]);
169  return false;
170 
171  default:
172  return false;
173  }
174 }
175 
176 static CScript PushAll(const std::vector<valtype>& values)
177 {
178  CScript result;
179  for (const valtype& v : values) {
180  if (v.size() == 0) {
181  result << OP_0;
182  } else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
183  result << CScript::EncodeOP_N(v[0]);
184  } else {
185  result << v;
186  }
187  }
188  return result;
189 }
190 
191 bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreator& creator, const CScript& fromPubKey, SignatureData& sigdata)
192 {
193  if (sigdata.complete) return true;
194 
195  std::vector<valtype> result;
196  txnouttype whichType;
197  bool solved = SignStep(provider, creator, fromPubKey, result, whichType, SigVersion::BASE, sigdata);
198  bool P2SH = false;
199  CScript subscript;
200  sigdata.scriptWitness.stack.clear();
201 
202  if (solved && whichType == TX_SCRIPTHASH)
203  {
204  // Solver returns the subscript that needs to be evaluated;
205  // the final scriptSig is the signatures from that
206  // and then the serialized subscript:
207  subscript = CScript(result[0].begin(), result[0].end());
208  sigdata.redeem_script = subscript;
209  solved = solved && SignStep(provider, creator, subscript, result, whichType, SigVersion::BASE, sigdata) && whichType != TX_SCRIPTHASH;
210  P2SH = true;
211  }
212 
213  if (solved && whichType == TX_WITNESS_V0_KEYHASH)
214  {
215  CScript witnessscript;
216  witnessscript << OP_DUP << OP_HASH160 << ToByteVector(result[0]) << OP_EQUALVERIFY << OP_CHECKSIG;
217  txnouttype subType;
218  solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata);
219  sigdata.scriptWitness.stack = result;
220  sigdata.witness = true;
221  result.clear();
222  }
223  else if (solved && whichType == TX_WITNESS_V0_SCRIPTHASH)
224  {
225  CScript witnessscript(result[0].begin(), result[0].end());
226  sigdata.witness_script = witnessscript;
227  txnouttype subType;
228  solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata) && subType != TX_SCRIPTHASH && subType != TX_WITNESS_V0_SCRIPTHASH && subType != TX_WITNESS_V0_KEYHASH;
229  result.push_back(std::vector<unsigned char>(witnessscript.begin(), witnessscript.end()));
230  sigdata.scriptWitness.stack = result;
231  sigdata.witness = true;
232  result.clear();
233  } else if (solved && whichType == TX_WITNESS_UNKNOWN) {
234  sigdata.witness = true;
235  }
236 
237  if (P2SH) {
238  result.push_back(std::vector<unsigned char>(subscript.begin(), subscript.end()));
239  }
240  sigdata.scriptSig = PushAll(result);
241 
242  // Test solution
243  sigdata.complete = solved && VerifyScript(sigdata.scriptSig, fromPubKey, &sigdata.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker());
244  return sigdata.complete;
245 }
246 
248 {
249 private:
252 
253 public:
254  SignatureExtractorChecker(SignatureData& sigdata, BaseSignatureChecker& checker) : sigdata(sigdata), checker(checker) {}
255  bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override;
256 };
257 
258 bool SignatureExtractorChecker::CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
259 {
260  if (checker.CheckSig(scriptSig, vchPubKey, scriptCode, sigversion)) {
261  CPubKey pubkey(vchPubKey);
262  sigdata.signatures.emplace(pubkey.GetID(), SigPair(pubkey, scriptSig));
263  return true;
264  }
265  return false;
266 }
267 
268 namespace
269 {
270 struct Stacks
271 {
272  std::vector<valtype> script;
273  std::vector<valtype> witness;
274 
275  Stacks() = delete;
276  Stacks(const Stacks&) = delete;
277  explicit Stacks(const SignatureData& data) : witness(data.scriptWitness.stack) {
279  }
280 };
281 }
282 
283 // Extracts signatures and scripts from incomplete scriptSigs. Please do not extend this, use PSBT instead
284 SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout)
285 {
286  SignatureData data;
287  assert(tx.vin.size() > nIn);
288  data.scriptSig = tx.vin[nIn].scriptSig;
289  data.scriptWitness = tx.vin[nIn].scriptWitness;
290  Stacks stack(data);
291 
292  // Get signatures
293  MutableTransactionSignatureChecker tx_checker(&tx, nIn, txout.nValue);
294  SignatureExtractorChecker extractor_checker(data, tx_checker);
295  if (VerifyScript(data.scriptSig, txout.scriptPubKey, &data.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, extractor_checker)) {
296  data.complete = true;
297  return data;
298  }
299 
300  // Get scripts
301  std::vector<std::vector<unsigned char>> solutions;
302  txnouttype script_type = Solver(txout.scriptPubKey, solutions);
303  SigVersion sigversion = SigVersion::BASE;
304  CScript next_script = txout.scriptPubKey;
305 
306  if (script_type == TX_SCRIPTHASH && !stack.script.empty() && !stack.script.back().empty()) {
307  // Get the redeemScript
308  CScript redeem_script(stack.script.back().begin(), stack.script.back().end());
309  data.redeem_script = redeem_script;
310  next_script = std::move(redeem_script);
311 
312  // Get redeemScript type
313  script_type = Solver(next_script, solutions);
314  stack.script.pop_back();
315  }
316  if (script_type == TX_WITNESS_V0_SCRIPTHASH && !stack.witness.empty() && !stack.witness.back().empty()) {
317  // Get the witnessScript
318  CScript witness_script(stack.witness.back().begin(), stack.witness.back().end());
319  data.witness_script = witness_script;
320  next_script = std::move(witness_script);
321 
322  // Get witnessScript type
323  script_type = Solver(next_script, solutions);
324  stack.witness.pop_back();
325  stack.script = std::move(stack.witness);
326  stack.witness.clear();
327  sigversion = SigVersion::WITNESS_V0;
328  }
329  if (script_type == TX_MULTISIG && !stack.script.empty()) {
330  // Build a map of pubkey -> signature by matching sigs to pubkeys:
331  assert(solutions.size() > 1);
332  unsigned int num_pubkeys = solutions.size()-2;
333  unsigned int last_success_key = 0;
334  for (const valtype& sig : stack.script) {
335  for (unsigned int i = last_success_key; i < num_pubkeys; ++i) {
336  const valtype& pubkey = solutions[i+1];
337  // We either have a signature for this pubkey, or we have found a signature and it is valid
338  if (data.signatures.count(CPubKey(pubkey).GetID()) || extractor_checker.CheckSig(sig, pubkey, next_script, sigversion)) {
339  last_success_key = i + 1;
340  break;
341  }
342  }
343  }
344  }
345 
346  return data;
347 }
348 
349 void UpdateInput(CTxIn& input, const SignatureData& data)
350 {
351  input.scriptSig = data.scriptSig;
352  input.scriptWitness = data.scriptWitness;
353 }
354 
356 {
357  if (complete) return;
358  if (sigdata.complete) {
359  *this = std::move(sigdata);
360  return;
361  }
362  if (redeem_script.empty() && !sigdata.redeem_script.empty()) {
363  redeem_script = sigdata.redeem_script;
364  }
365  if (witness_script.empty() && !sigdata.witness_script.empty()) {
366  witness_script = sigdata.witness_script;
367  }
368  signatures.insert(std::make_move_iterator(sigdata.signatures.begin()), std::make_move_iterator(sigdata.signatures.end()));
369 }
370 
371 bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType)
372 {
373  assert(nIn < txTo.vin.size());
374 
375  MutableTransactionSignatureCreator creator(&txTo, nIn, amount, nHashType);
376 
377  SignatureData sigdata;
378  bool ret = ProduceSignature(provider, creator, fromPubKey, sigdata);
379  UpdateInput(txTo.vin.at(nIn), sigdata);
380  return ret;
381 }
382 
383 bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType)
384 {
385  assert(nIn < txTo.vin.size());
386  CTxIn& txin = txTo.vin[nIn];
387  assert(txin.prevout.n < txFrom.vout.size());
388  const CTxOut& txout = txFrom.vout[txin.prevout.n];
389 
390  return SignSignature(provider, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType);
391 }
392 
393 namespace {
395 class DummySignatureChecker final : public BaseSignatureChecker
396 {
397 public:
398  DummySignatureChecker() {}
399  bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override { return true; }
400 };
401 const DummySignatureChecker DUMMY_CHECKER;
402 
403 class DummySignatureCreator final : public BaseSignatureCreator {
404 private:
405  char m_r_len = 32;
406  char m_s_len = 32;
407 public:
408  DummySignatureCreator(char r_len, char s_len) : m_r_len(r_len), m_s_len(s_len) {}
409  const BaseSignatureChecker& Checker() const override { return DUMMY_CHECKER; }
410  bool CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override
411  {
412  // Create a dummy signature that is a valid DER-encoding
413  vchSig.assign(m_r_len + m_s_len + 7, '\000');
414  vchSig[0] = 0x30;
415  vchSig[1] = m_r_len + m_s_len + 4;
416  vchSig[2] = 0x02;
417  vchSig[3] = m_r_len;
418  vchSig[4] = 0x01;
419  vchSig[4 + m_r_len] = 0x02;
420  vchSig[5 + m_r_len] = m_s_len;
421  vchSig[6 + m_r_len] = 0x01;
422  vchSig[6 + m_r_len + m_s_len] = SIGHASH_ALL;
423  return true;
424  }
425 };
426 
427 }
428 
429 const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator(32, 32);
430 const BaseSignatureCreator& DUMMY_MAXIMUM_SIGNATURE_CREATOR = DummySignatureCreator(33, 32);
431 
432 bool IsSolvable(const SigningProvider& provider, const CScript& script)
433 {
434  // This check is to make sure that the script we created can actually be solved for and signed by us
435  // if we were to have the private keys. This is just to make sure that the script is valid and that,
436  // if found in a transaction, we would still accept and relay that transaction. In particular,
437  // it will reject witness outputs that require signing with an uncompressed public key.
438  SignatureData sigs;
439  // Make sure that STANDARD_SCRIPT_VERIFY_FLAGS includes SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, the most
440  // important property this function is designed to test for.
441  static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE");
442  if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
443  // VerifyScript check is just defensive, and should never fail.
444  bool verified = VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER);
445  assert(verified);
446  return true;
447  }
448  return false;
449 }
450 
451 bool IsSegWitOutput(const SigningProvider& provider, const CScript& script)
452 {
453  std::vector<valtype> solutions;
454  auto whichtype = Solver(script, solutions);
455  if (whichtype == TX_WITNESS_V0_SCRIPTHASH || whichtype == TX_WITNESS_V0_KEYHASH || whichtype == TX_WITNESS_UNKNOWN) return true;
456  if (whichtype == TX_SCRIPTHASH) {
457  auto h160 = uint160(solutions[0]);
458  CScript subscript;
459  if (provider.GetCScript(h160, subscript)) {
460  whichtype = Solver(subscript, solutions);
461  if (whichtype == TX_WITNESS_V0_SCRIPTHASH || whichtype == TX_WITNESS_V0_KEYHASH || whichtype == TX_WITNESS_UNKNOWN) return true;
462  }
463  }
464  return false;
465 }
CAmount nValue
Definition: transaction.h:136
bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const override
Definition: sign.cpp:258
unspendable OP_RETURN script that carries data
Definition: standard.h:64
CScript scriptPubKey
Definition: transaction.h:137
CScript witness_script
The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
Definition: sign.h:64
iterator insert(iterator pos, const T &value)
Definition: prevector.h:342
virtual bool CreateSig(const SigningProvider &provider, std::vector< unsigned char > &vchSig, const CKeyID &keyid, const CScript &scriptCode, SigVersion sigversion) const =0
Create a singular (non-script) signature.
const MutableTransactionSignatureChecker checker
Definition: sign.h:41
BaseSignatureChecker & checker
Definition: sign.cpp:251
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
CScript scriptSig
The scriptSig of an input. Contains complete signatures or the traditional partial signatures format...
Definition: sign.h:62
std::vector< CTxIn > vin
Definition: transaction.h:368
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:69
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
Definition: sign.h:69
Interface for signature creators.
Definition: sign.h:26
static CScript PushAll(const std::vector< valtype > &values)
Definition: sign.cpp:176
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
Definition: sign.h:68
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
Definition: sign.cpp:429
const BaseSignatureChecker & Checker() const override
Definition: sign.h:45
std::vector< std::vector< unsigned char > > stack
Definition: script.h:574
const BaseSignatureCreator & DUMMY_MAXIMUM_SIGNATURE_CREATOR
A signature creator that just produces 72-byte empty signatures.
Definition: sign.cpp:430
txnouttype Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
Definition: standard.cpp:91
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
Definition: sign.h:67
A signature creator for transactions.
Definition: sign.h:36
uint256 missing_witness_script
SHA256 of the missing witnessScript (if any)
Definition: sign.h:71
unsigned char * begin()
Definition: uint256.h:55
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
Definition: policy.h:56
bool IsSegWitOutput(const SigningProvider &provider, const CScript &script)
Check whether a scriptPubKey is known to be segwit.
Definition: sign.cpp:451
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:155
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType)
Produce a script signature for a transaction.
Definition: sign.cpp:371
bool CreateSig(const SigningProvider &provider, std::vector< unsigned char > &vchSig, const CKeyID &keyid, const CScript &scriptCode, SigVersion sigversion) const override
Create a singular (non-script) signature.
Definition: sign.cpp:19
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, bool grind=true, uint32_t test_case=0) const
Create a DER-serialized signature.
Definition: key.cpp:210
iterator end()
Definition: prevector.h:287
SignatureExtractorChecker(SignatureData &sigdata, BaseSignatureChecker &checker)
Definition: sign.cpp:254
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
Definition: sign.h:70
Only for Witness versions not already defined above.
Definition: standard.h:67
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
An input of a transaction.
Definition: transaction.h:63
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
An encapsulated public key.
Definition: pubkey.h:30
std::pair< CPubKey, std::vector< unsigned char > > SigPair
Definition: sign.h:54
const std::vector< CTxOut > vout
Definition: transaction.h:288
static bool GetCScript(const SigningProvider &provider, const SignatureData &sigdata, const CScriptID &scriptid, CScript &script)
Definition: sign.cpp:36
bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const override
An output of a transaction.
Definition: transaction.h:133
void MergeSignatureData(SignatureData sigdata)
Definition: sign.cpp:355
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
Definition: key.h:96
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror)
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
CScriptWitness scriptWitness
The scriptWitness of an input. Contains complete signatures or the traditional partial signatures for...
Definition: sign.h:65
virtual bool GetKey(const CKeyID &address, CKey &key) const
bool IsSolvable(const SigningProvider &provider, const CScript &script)
Definition: sign.cpp:432
CRIPEMD160 & Write(const unsigned char *data, size_t len)
Definition: ripemd160.cpp:247
P2SH redeemScript.
CScript scriptSig
Definition: transaction.h:67
txnouttype
Definition: standard.h:56
256-bit opaque blob.
Definition: uint256.h:121
static bool SignStep(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &scriptPubKey, std::vector< valtype > &ret, txnouttype &whichTypeRet, SigVersion sigversion, SignatureData &sigdata)
Sign scriptPubKey using signature made with creator.
Definition: sign.cpp:98
SignatureData & sigdata
Definition: sign.cpp:250
An interface to be implemented by keystores that support signing.
static opcodetype EncodeOP_N(int n)
Definition: script.h:518
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
Definition: sign.cpp:284
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:390
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
Definition: sign.cpp:52
bool empty() const
Definition: prevector.h:281
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
void UpdateInput(CTxIn &input, const SignatureData &data)
Definition: sign.cpp:349
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
160-bit opaque blob.
Definition: uint256.h:110
std::vector< unsigned char > valtype
Definition: interpreter.cpp:15
std::vector< unsigned char > valtype
Definition: sign.cpp:15
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:191
iterator begin()
Definition: prevector.h:285
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:22
A mutable version of CTransaction.
Definition: transaction.h:366
An encapsulated private key.
Definition: key.h:27
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
MutableTransactionSignatureCreator(const CMutableTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn, int nHashTypeIn=SIGHASH_ALL)
Definition: sign.cpp:17
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: ripemd160.cpp:273
bool complete
Stores whether the scriptSig and scriptWitness are complete.
Definition: sign.h:60
auto it
Definition: validation.cpp:366
Definition: script.h:57
CScript redeem_script
The redeemScript (if any) for the input.
Definition: sign.h:63
bool witness
Stores whether the input this SigData corresponds to is a witness input.
Definition: sign.h:61
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a ...
Definition: sign.h:66
A hasher class for RIPEMD-160.
Definition: ripemd160.h:12
Definition: script.h:106
virtual const BaseSignatureChecker & Checker() const =0
const CMutableTransaction * txTo
Definition: sign.h:37
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:48
SigVersion
Definition: interpreter.h:131