21 : txTo(txToIn), nIn(nInIn), amount(amountIn), sigHashType(sigHashTypeIn),
22 checker(txTo, nIn, amountIn) {}
28 if (!provider.
GetKey(address, key)) {
59 const auto it = sigdata.
signatures.find(address);
61 pubkey = it->second.first;
67 pubkey = pk_it->second.first;
71 return provider.
GetPubKey(address, pubkey);
76 std::vector<uint8_t> &sig_out,
const CPubKey &pubkey,
79 const auto it = sigdata.
signatures.find(keyid);
81 sig_out = it->second.second;
87 std::make_pair(pubkey, std::move(info)));
89 if (creator.
CreateSig(provider, sig_out, keyid, scriptcode)) {
108 const CScript &scriptPubKey, std::vector<valtype> &ret,
113 std::vector<uint8_t>
sig;
115 std::vector<valtype> vSolutions;
116 whichTypeRet =
Solver(scriptPubKey, vSolutions);
118 switch (whichTypeRet) {
124 CPubKey(vSolutions[0]), scriptPubKey)) {
127 ret.push_back(std::move(
sig));
132 if (!
GetPubKey(provider, sigdata, keyID, pubkey)) {
141 ret.push_back(std::move(
sig));
149 std::vector<uint8_t>(scriptRet.
begin(), scriptRet.
end()));
156 size_t required = vSolutions.front()[0];
159 for (
size_t i = 1; i < vSolutions.size() - 1; ++i) {
167 if (ret.size() < required + 1) {
168 ret.push_back(std::move(
sig));
172 bool ok = ret.size() == required + 1;
173 for (
size_t i = 0; i + ret.size() < required + 1; ++i) {
185 for (
const valtype &v : values) {
188 }
else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
205 std::vector<valtype> result;
208 SignStep(provider, creator, fromPubKey, result, whichType, sigdata);
215 subscript =
CScript(result[0].begin(), result[0].end());
219 SignStep(provider, creator, subscript, result, whichType,
223 std::vector<uint8_t>(subscript.
begin(), subscript.
end()));
244 : sigdata(sigdata_), checker(checker_) {}
245 bool CheckSig(
const std::vector<uint8_t> &scriptSig,
246 const std::vector<uint8_t> &vchPubKey,
247 const CScript &scriptCode, uint32_t
flags)
const override {
248 if (checker.
CheckSig(scriptSig, vchPubKey, scriptCode,
flags)) {
260 std::vector<valtype> script;
263 Stacks(
const Stacks &) =
delete;
276 unsigned int nIn,
const CTxOut &txout) {
284 SignatureExtractorChecker extractor_checker(data, tx_checker);
292 std::vector<std::vector<uint8_t>> solutions;
297 !stack.script.back().empty()) {
299 CScript redeem_script(stack.script.back().begin(),
300 stack.script.back().end());
302 next_script = std::move(redeem_script);
305 script_type =
Solver(next_script, solutions);
306 stack.script.pop_back();
310 assert(solutions.size() > 1);
311 unsigned int num_pubkeys = solutions.size() - 2;
312 unsigned int last_success_key = 0;
314 for (
unsigned int i = last_success_key; i < num_pubkeys; ++i) {
315 const valtype &pubkey = solutions[i + 1];
319 extractor_checker.CheckSig(
sig, pubkey, next_script,
321 last_success_key = i + 1;
340 *
this = std::move(sigdata);
347 std::make_move_iterator(sigdata.
signatures.end()));
379 DummySignatureChecker() {}
380 bool CheckSig(
const std::vector<uint8_t> &scriptSig,
381 const std::vector<uint8_t> &vchPubKey,
382 const CScript &scriptCode, uint32_t
flags)
const override {
386const DummySignatureChecker DUMMY_CHECKER;
394 DummySignatureCreator(
char r_len,
char s_len)
395 : m_r_len(r_len), m_s_len(s_len) {}
397 return DUMMY_CHECKER;
400 std::vector<uint8_t> &vchSig,
const CKeyID &keyid,
401 const CScript &scriptCode)
const override {
403 vchSig.assign(m_r_len + m_s_len + 7,
'\000');
405 vchSig[1] = m_r_len + m_s_len + 4;
409 vchSig[4 + m_r_len] = 0x02;
410 vchSig[5 + m_r_len] = m_s_len;
411 vchSig[6 + m_r_len] = 0x01;
420 DummySignatureCreator(32, 32);
422 DummySignatureCreator(33, 32);
442 const std::map<COutPoint, Coin> &coins,
444 std::map<int, std::string> &input_errors) {
449 for (
size_t i = 0; i < mtx.
vin.size(); i++) {
451 auto coin = coins.find(txin.
prevout);
452 if (coin == coins.end() || coin->second.IsSpent()) {
453 input_errors[i] =
"Input not found or already spent";
456 const CScript &prevPubKey = coin->second.GetTxOut().scriptPubKey;
457 const Amount amount = coin->second.GetTxOut().nValue;
463 (i < mtx.
vout.size())) {
467 prevPubKey, sigdata);
474 input_errors[i] =
"Missing amount";
485 input_errors[i] =
"Unable to sign input, invalid stack size "
486 "(possibly missing key)";
492 input_errors.erase(i);
495 return input_errors.empty();
static constexpr Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
virtual bool CheckSig(const std::vector< uint8_t > &vchSigIn, const std::vector< uint8_t > &vchPubKey, const CScript &scriptCode, uint32_t flags) const
Interface for signature creators.
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.
virtual const BaseSignatureChecker & Checker() const =0
An encapsulated secp256k1 private key.
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.
A reference to a CKey: the Hash160 of its serialized public key.
A mutable version of CTransaction.
std::vector< CTxOut > vout
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
bool IsPushOnly(const_iterator pc) const
Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
static opcodetype EncodeOP_N(int n)
A reference to a CScript: the Hash160 of its serialization (see script.h)
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
An input of a transaction.
An output of a transaction.
A signature creator for transactions.
MutableTransactionSignatureCreator(const CMutableTransaction *txToIn, unsigned int nInIn, const Amount &amountIn, SigHashType sigHashTypeIn=SigHashType())
bool CreateSig(const SigningProvider &provider, std::vector< uint8_t > &vchSig, const CKeyID &keyid, const CScript &scriptCode) const override
Create a singular (non-script) signature.
const CMutableTransaction * txTo
Signature hash type wrapper class.
uint32_t getRawSigHashType() const
BaseSigHashType getBaseType() const
An interface to be implemented by keystores that support signing.
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
virtual bool GetKey(const CKeyID &address, CKey &key) const
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, SigHashType sigHashType, const Amount amount, const PrecomputedTransactionData *cache, uint32_t flags)
bool EvalScript(std::vector< valtype > &stack, const CScript &script, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metrics, ScriptError *serror)
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.
static constexpr uint32_t STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
std::vector< uint8_t > ToByteVector(const T &in)
std::string ScriptErrorString(const ScriptError serror)
@ INVALID_STACK_OPERATION
std::vector< uint8_t > valtype
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
std::vector< uint8_t > valtype
void UpdateInput(CTxIn &input, const SignatureData &data)
static bool CreateSig(const BaseSignatureCreator &creator, SignatureData &sigdata, const SigningProvider &provider, std::vector< uint8_t > &sig_out, const CPubKey &pubkey, const CScript &scriptcode)
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.
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.
const BaseSignatureCreator & DUMMY_MAXIMUM_SIGNATURE_CREATOR
A signature creator that just produces 72-byte empty signatures.
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
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.
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
static CScript PushAll(const std::vector< valtype > &values)
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
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.
static bool GetCScript(const SigningProvider &provider, const SignatureData &sigdata, const CScriptID &scriptid, CScript &script)
std::pair< CPubKey, std::vector< uint8_t > > SigPair
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
void MergeSignatureData(SignatureData sigdata)
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input.
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
CScript scriptSig
The scriptSig of an input.
CScript redeem_script
The redeemScript (if any) for the input.
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
bool complete
Stores whether the scriptSig are complete.