20 : txTo(txToIn), nIn(nInIn), amount(amountIn), sigHashType(sigHashTypeIn),
21 checker(txTo, nIn, amountIn) {}
27 if (!provider.
GetKey(address, key)) {
58 const auto it = sigdata.
signatures.find(address);
60 pubkey = it->second.first;
66 pubkey = pk_it->second.first;
70 return provider.
GetPubKey(address, pubkey);
75 std::vector<uint8_t> &sig_out,
const CPubKey &pubkey,
78 const auto it = sigdata.
signatures.find(keyid);
80 sig_out = it->second.second;
86 std::make_pair(pubkey, std::move(info)));
88 if (creator.
CreateSig(provider, sig_out, keyid, scriptcode)) {
107 const CScript &scriptPubKey, std::vector<valtype> &ret,
112 std::vector<uint8_t>
sig;
114 std::vector<valtype> vSolutions;
115 whichTypeRet =
Solver(scriptPubKey, vSolutions);
117 switch (whichTypeRet) {
122 if (!
CreateSig(creator, sigdata, provider, sig,
123 CPubKey(vSolutions[0]), scriptPubKey)) {
126 ret.push_back(std::move(sig));
131 if (!
GetPubKey(provider, sigdata, keyID, pubkey)) {
136 if (!
CreateSig(creator, sigdata, provider, sig, pubkey,
140 ret.push_back(std::move(sig));
146 if (
GetCScript(provider, sigdata, h160, scriptRet)) {
148 std::vector<uint8_t>(scriptRet.
begin(), scriptRet.
end()));
155 size_t required = vSolutions.front()[0];
158 for (
size_t i = 1; i < vSolutions.size() - 1; ++i) {
164 if (
CreateSig(creator, sigdata, provider, sig, pubkey,
166 if (ret.size() < required + 1) {
167 ret.push_back(std::move(sig));
171 bool ok = ret.size() == required + 1;
172 for (
size_t i = 0; i + ret.size() < required + 1; ++i) {
184 for (
const valtype &v : values) {
187 }
else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
204 std::vector<valtype> result;
207 SignStep(provider, creator, fromPubKey, result, whichType, sigdata);
214 subscript =
CScript(result[0].begin(), result[0].end());
218 SignStep(provider, creator, subscript, result, whichType,
222 std::vector<uint8_t>(subscript.
begin(), subscript.
end()));
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)) {
259 std::vector<valtype> script;
262 Stacks(
const Stacks &) =
delete;
277 assert(tx.
vin.size() >
nIn);
283 SignatureExtractorChecker extractor_checker(data, tx_checker);
291 std::vector<std::vector<uint8_t>> solutions;
296 !stack.script.back().empty()) {
298 CScript redeem_script(stack.script.back().begin(),
299 stack.script.back().end());
301 next_script = std::move(redeem_script);
304 script_type =
Solver(next_script, solutions);
305 stack.script.pop_back();
307 if (script_type ==
TX_MULTISIG && !stack.script.empty()) {
309 assert(solutions.size() > 1);
310 unsigned int num_pubkeys = solutions.size() - 2;
311 unsigned int last_success_key = 0;
313 for (
unsigned int i = last_success_key; i < num_pubkeys; ++i) {
314 const valtype &pubkey = solutions[i + 1];
318 extractor_checker.CheckSig(sig, pubkey, next_script,
320 last_success_key = i + 1;
339 *
this = std::move(sigdata);
346 std::make_move_iterator(sigdata.
signatures.end()));
352 assert(nIn < txTo.
vin.size());
365 assert(nIn < txTo.
vin.size());
367 assert(txin.prevout.GetN() < txFrom.
vout.size());
368 const CTxOut &txout = txFrom.
vout[txin.prevout.GetN()];
370 return SignSignature(provider, txout.scriptPubKey, txTo, nIn, txout.nValue,
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 {
385 const DummySignatureChecker DUMMY_CHECKER;
393 DummySignatureCreator(
char r_len,
char s_len)
394 : m_r_len(r_len), m_s_len(s_len) {}
396 return DUMMY_CHECKER;
399 std::vector<uint8_t> &vchSig,
const CKeyID &keyid,
400 const CScript &scriptCode)
const override {
402 vchSig.assign(m_r_len + m_s_len + 7,
'\000');
404 vchSig[1] = m_r_len + m_s_len + 4;
408 vchSig[4 + m_r_len] = 0x02;
409 vchSig[5 + m_r_len] = m_s_len;
410 vchSig[6 + m_r_len] = 0x01;
419 DummySignatureCreator(32, 32);
421 DummySignatureCreator(33, 32);
441 const std::map<COutPoint, Coin> &coins,
443 std::map<int, std::string> &input_errors) {
448 for (
size_t i = 0; i < mtx.
vin.size(); 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";
455 const CScript &prevPubKey = coin->second.GetTxOut().scriptPubKey;
462 (i < mtx.
vout.size())) {
466 prevPubKey, sigdata);
473 input_errors[i] =
"Missing amount";
484 input_errors[i] =
"Unable to sign input, invalid stack size " 485 "(possibly missing key)";
491 input_errors.erase(i);
494 return input_errors.empty();
txnouttype Solver(const CScript &scriptPubKey, std::vector< std::vector< uint8_t >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
MutableTransactionSignatureCreator(const CMutableTransaction *txToIn, unsigned int nInIn, const Amount &amountIn, SigHashType sigHashTypeIn=SigHashType())
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.
std::array< uint8_t, 64 > sig
bool EvalScript(std::vector< valtype > &stack, const CScript &script, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metrics, ScriptError *serror)
iterator insert(iterator pos, const T &value)
uint32_t getRawSigHashType() const
const MutableTransactionSignatureChecker checker
CScript scriptSig
The scriptSig of an input.
BaseSigHashType getBaseType() const
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
Interface for signature creators.
virtual bool CheckSig(const std::vector< uint8_t > &vchSigIn, const std::vector< uint8_t > &vchPubKey, const CScript &scriptCode, uint32_t flags) const
static CScript PushAll(const std::vector< valtype > &values)
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
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.
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.
const BaseSignatureChecker & Checker() const override
const BaseSignatureCreator & DUMMY_MAXIMUM_SIGNATURE_CREATOR
A signature creator that just produces 72-byte empty signatures.
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, SigHashType sigHashType, const Amount amount, const PrecomputedTransactionData *cache, uint32_t flags)
static const Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
std::vector< CTxOut > vout
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
A signature creator for transactions.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
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.
const char * ScriptErrorString(const ScriptError serror)
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
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.
An input of a transaction.
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
bool IsPushOnly(const_iterator pc) const
Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
An encapsulated public key.
const std::vector< CTxOut > vout
static bool GetCScript(const SigningProvider &provider, const SignatureData &sigdata, const CScriptID &scriptid, CScript &script)
static bool SignStep(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &scriptPubKey, std::vector< valtype > &ret, txnouttype &whichTypeRet, SignatureData &sigdata)
Sign scriptPubKey using signature made with creator.
std::vector< uint8_t > ToByteVector(const T &in)
An output of a transaction.
void MergeSignatureData(SignatureData sigdata)
std::pair< CPubKey, std::vector< uint8_t > > SigPair
std::vector< uint8_t > valtype
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
virtual bool GetKey(const CKeyID &address, CKey &key) const
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...
bool CreateSig(const SigningProvider &provider, std::vector< uint8_t > &vchSig, const CKeyID &keyid, const CScript &scriptCode) const override
Create a singular (non-script) signature.
An interface to be implemented by keystores that support signing.
static opcodetype EncodeOP_N(int n)
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
Serialized script, used inside transaction inputs and outputs.
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
A mutable version of CTransaction.
A reference to a CKey: the Hash160 of its serialized public key.
void UpdateInput(CTxIn &input, const SignatureData &data)
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
A reference to a CScript: the Hash160 of its serialization (see script.h)
static constexpr uint32_t STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
An encapsulated secp256k1 private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
bool complete
Stores whether the scriptSig are complete.
CScript redeem_script
The redeemScript (if any) for the input.
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input.
Signature hash type wrapper class.
virtual const BaseSignatureChecker & Checker() const =0
std::vector< uint8_t > valtype
const CMutableTransaction * txTo