17 typedef std::vector<unsigned char>
valtype;
19 TransactionSignatureCreator::TransactionSignatureCreator(
const CKeyStore* keystoreIn,
const CTransaction* txToIn,
unsigned int nInIn,
const CAmount& amountIn,
int nHashTypeIn) :
BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
32 if (!key.
Sign(hash, vchSig))
34 vchSig.push_back((
unsigned char)
nHashType);
40 std::vector<unsigned char> vchSig;
41 if (!creator.
CreateSig(vchSig, address, scriptCode, sigversion))
43 ret.push_back(vchSig);
50 int nRequired = multisigdata.front()[0];
51 for (
unsigned int i = 1; i < multisigdata.size()-1 && nSigned < nRequired; i++)
53 const valtype& pubkey = multisigdata[i];
55 if (Sign1(keyID, creator, scriptCode, ret, sigversion))
58 return nSigned==nRequired;
74 std::vector<valtype> vSolutions;
75 if (!
Solver(scriptPubKey, whichTypeRet, vSolutions))
86 return Sign1(keyID, creator, scriptPubKey, ret, sigversion);
89 if (!Sign1(keyID, creator, scriptPubKey, ret, sigversion))
100 ret.push_back(std::vector<unsigned char>(scriptRet.
begin(), scriptRet.
end()));
107 return (SignN(vSolutions, creator, scriptPubKey, ret, sigversion));
110 ret.push_back(vSolutions[0]);
116 ret.push_back(std::vector<unsigned char>(scriptRet.
begin(), scriptRet.
end()));
126 static CScript PushAll(
const std::vector<valtype>& values)
129 for (
const valtype& v : values) {
132 }
else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
144 std::vector<valtype> result;
146 bool solved = SignStep(creator, script, result, whichType,
SIGVERSION_BASE);
156 script = subscript =
CScript(result[0].begin(), result[0].end());
172 CScript witnessscript(result[0].begin(), result[0].end());
175 result.push_back(std::vector<unsigned char>(witnessscript.
begin(), witnessscript.
end()));
181 result.push_back(std::vector<unsigned char>(subscript.
begin(), subscript.
end()));
223 const CTxOut& txout = txFrom.
vout[txin.prevout.n];
225 return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType);
245 const std::vector<valtype>& vSolutions,
246 const std::vector<valtype>& sigs1,
const std::vector<valtype>& sigs2,
SigVersion sigversion)
249 std::set<valtype> allsigs;
262 assert(vSolutions.size() > 1);
263 unsigned int nSigsRequired = vSolutions.front()[0];
264 unsigned int nPubKeys = vSolutions.size()-2;
265 std::map<valtype, valtype> sigs;
266 for (
const valtype& sig : allsigs)
268 for (
unsigned int i = 0; i < nPubKeys; i++)
270 const valtype& pubkey = vSolutions[i+1];
271 if (sigs.count(pubkey))
274 if (checker.
CheckSig(sig, pubkey, scriptPubKey, sigversion))
282 unsigned int nSigsHave = 0;
283 std::vector<valtype> result; result.push_back(
valtype());
284 for (
unsigned int i = 0; i < nPubKeys && nSigsHave < nSigsRequired; i++)
286 if (sigs.count(vSolutions[i+1]))
288 result.push_back(sigs[vSolutions[i+1]]);
293 for (
unsigned int i = nSigsHave; i < nSigsRequired; i++)
303 std::vector<valtype> script;
304 std::vector<valtype> witness;
307 explicit Stacks(
const std::vector<valtype>& scriptSigStack_) : script(scriptSigStack_), witness() {}
322 const txnouttype txType,
const std::vector<valtype>& vSolutions,
323 Stacks sigs1, Stacks sigs2,
SigVersion sigversion)
330 if (sigs1.script.size() >= sigs2.script.size())
336 if (sigs1.script.empty() || sigs1.script[0].empty())
341 if (sigs1.witness.empty() || sigs1.witness[0].empty())
345 if (sigs1.script.empty() || sigs1.script.back().empty())
347 else if (sigs2.script.empty() || sigs2.script.back().empty())
352 valtype spk = sigs1.script.back();
353 CScript pubKey2(spk.begin(), spk.end());
356 std::vector<std::vector<unsigned char> > vSolutions2;
357 Solver(pubKey2, txType2, vSolutions2);
358 sigs1.script.pop_back();
359 sigs2.script.pop_back();
360 Stacks result =
CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, sigversion);
361 result.script.push_back(spk);
365 return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, sigversion));
367 if (sigs1.witness.empty() || sigs1.witness.back().empty())
369 else if (sigs2.witness.empty() || sigs2.witness.back().empty())
374 CScript pubKey2(sigs1.witness.back().begin(), sigs1.witness.back().end());
376 std::vector<valtype> vSolutions2;
377 Solver(pubKey2, txType2, vSolutions2);
378 sigs1.witness.pop_back();
379 sigs1.script = sigs1.witness;
380 sigs1.witness.clear();
381 sigs2.witness.pop_back();
382 sigs2.script = sigs2.witness;
383 sigs2.witness.clear();
385 result.witness = result.script;
386 result.script.clear();
387 result.witness.push_back(
valtype(pubKey2.begin(), pubKey2.end()));
399 std::vector<std::vector<unsigned char> > vSolutions;
400 Solver(scriptPubKey, txType, vSolutions);
410 DummySignatureChecker() {}
412 bool CheckSig(
const std::vector<unsigned char>& scriptSig,
const std::vector<unsigned char>& vchPubKey,
const CScript& scriptCode,
SigVersion sigversion)
const override 417 const DummySignatureChecker dummyChecker;
428 vchSig.assign(72,
'\000');
434 vchSig[4 + 33] = 0x02;
436 vchSig[6 + 33] = 0x01;
void UpdateTransaction(CMutableTransaction &tx, unsigned int nIn, const SignatureData &data)
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn)
Extract signature data from a transaction, and insert it.
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet, bool contractConsensus)
Return public keys or hashes from scriptPubKey, for 'standard' transaction types. ...
bool SignSignature(const CKeyStore &keystore, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType)
Produce a script signature for a transaction.
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
const CKeyStore & KeyStore() const
Virtual base class for signature creators.
CTxOut out
unspent transaction output
A signature creator for transactions.
std::vector< std::vector< unsigned char > > stack
assert(len-trim+(2 *lenIndices)<=WIDTH)
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
const std::vector< CTxIn > vin
SignatureData CombineSignatures(const CScript &scriptPubKey, const BaseSignatureChecker &checker, const SignatureData &scriptSig1, const SignatureData &scriptSig2)
Combine two script signatures using a generic signature checker, intelligently, possibly with OP_0 pl...
int64_t CAmount
Amount in lius (Can be negative)
const CKeyStore * keystore
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache)
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
const BaseSignatureChecker & Checker() const override
An input of a transaction.
virtual bool CreateSig(std::vector< unsigned char > &vchSig, const CKeyID &keyid, const CScript &scriptCode, SigVersion sigversion) const =0
Create a singular (non-script) signature.
An encapsulated public key.
const std::vector< CTxOut > vout
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const =0
TransactionSignatureCreator(const CKeyStore *keystoreIn, const CTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn, int nHashTypeIn=SIGHASH_ALL)
bool CreateSig(std::vector< unsigned char > &vchSig, const CKeyID &keyid, const CScript &scriptCode, SigVersion sigversion) const override
Create a singular (non-script) signature.
An output of a transaction.
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror)
CScriptWitness scriptWitness
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const =0
const TransactionSignatureChecker checker
CRIPEMD160 & Write(const unsigned char *data, size_t len)
static opcodetype EncodeOP_N(int n)
uint8_t const size_t const size
Serialized script, used inside transaction inputs and outputs.
A virtual base class for key stores.
A reference to a CKey: the Hash160 of its serialized public key.
std::vector< unsigned char > valtype
bool VerifySignature(const Coin &coin, const uint256 txFromHash, const CTransaction &txTo, unsigned int nIn, unsigned int flags)
A mutable version of CTransaction.
std::vector< unsigned char > valtype
struct evm_uint160be address(struct evm_env *env)
An encapsulated private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
void Finalize(unsigned char hash[OUTPUT_SIZE])
bool CreateSig(std::vector< unsigned char > &vchSig, const CKeyID &keyid, const CScript &scriptCode, SigVersion sigversion) const override
Create a singular (non-script) signature.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
const CTransaction * txTo
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const
Create a DER-serialized signature.
virtual bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const =0
A hasher class for RIPEMD-160.
virtual const BaseSignatureChecker & Checker() const =0
std::vector< unsigned char > ToByteVector(const T &in)