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))
89 if (!Sign1(keyID, creator, scriptPubKey, ret, sigversion))
100 if (!Sign1(keyID, creator, scriptPubKey, ret, sigversion))
112 if (!Sign1(keyID, creator, scriptPubKey, ret, sigversion))
124 return Sign1(keyID, creator, scriptPubKey, ret, sigversion);
127 if (!Sign1(keyID, creator, scriptPubKey, ret, sigversion))
138 ret.push_back(std::vector<unsigned char>(scriptRet.
begin(), scriptRet.
end()));
145 return (SignN(vSolutions, creator, scriptPubKey, ret, sigversion));
148 ret.push_back(vSolutions[0]);
154 ret.push_back(std::vector<unsigned char>(scriptRet.
begin(), scriptRet.
end()));
164 static CScript PushAll(
const std::vector<valtype>& values)
167 for (
const valtype& v : values) {
170 }
else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
182 std::vector<valtype> result;
184 bool solved = SignStep(creator, script, result, whichType,
SIGVERSION_BASE);
194 script = subscript =
CScript(result[0].begin(), result[0].end());
210 CScript witnessscript(result[0].begin(), result[0].end());
213 result.push_back(std::vector<unsigned char>(witnessscript.
begin(), witnessscript.
end()));
219 result.push_back(std::vector<unsigned char>(subscript.
begin(), subscript.
end()));
230 assert(tx.
vin.size() >
nIn);
238 assert(tx.
vin.size() >
nIn);
245 assert(nIn < txTo.
vin.size());
258 assert(nIn < txTo.
vin.size());
260 assert(txin.prevout.n < txFrom.
vout.size());
261 const CTxOut& txout = txFrom.
vout[txin.prevout.n];
263 return SignSignature(keystore, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType);
267 const std::vector<valtype>& vSolutions,
268 const std::vector<valtype>& sigs1,
const std::vector<valtype>& sigs2,
SigVersion sigversion)
271 std::set<valtype> allsigs;
284 assert(vSolutions.size() > 1);
285 unsigned int nSigsRequired = vSolutions.front()[0];
286 unsigned int nPubKeys = vSolutions.size()-2;
287 std::map<valtype, valtype> sigs;
288 for (
const valtype& sig : allsigs)
290 for (
unsigned int i = 0; i < nPubKeys; i++)
292 const valtype& pubkey = vSolutions[i+1];
293 if (sigs.count(pubkey))
296 if (checker.
CheckSig(sig, pubkey, scriptPubKey, sigversion))
304 unsigned int nSigsHave = 0;
305 std::vector<valtype> result; result.push_back(
valtype());
306 for (
unsigned int i = 0; i < nPubKeys && nSigsHave < nSigsRequired; i++)
308 if (sigs.count(vSolutions[i+1]))
310 result.push_back(sigs[vSolutions[i+1]]);
315 for (
unsigned int i = nSigsHave; i < nSigsRequired; i++)
325 std::vector<valtype> script;
326 std::vector<valtype> witness;
329 explicit Stacks(
const std::vector<valtype>& scriptSigStack_) : script(scriptSigStack_), witness() {}
344 const txnouttype txType,
const std::vector<valtype>& vSolutions,
345 Stacks sigs1, Stacks sigs2,
SigVersion sigversion)
352 if (sigs1.script.size() >= sigs2.script.size())
357 if (sigs1.script.size() >= sigs2.script.size())
363 if (sigs1.script.empty() || sigs1.script[0].empty())
368 if (sigs1.witness.empty() || sigs1.witness[0].empty())
372 if (sigs1.script.empty() || sigs1.script.back().empty())
374 else if (sigs2.script.empty() || sigs2.script.back().empty())
379 valtype spk = sigs1.script.back();
380 CScript pubKey2(spk.begin(), spk.end());
383 std::vector<std::vector<unsigned char> > vSolutions2;
384 Solver(pubKey2, txType2, vSolutions2);
385 sigs1.script.pop_back();
386 sigs2.script.pop_back();
387 Stacks result =
CombineSignatures(pubKey2, checker, txType2, vSolutions2, sigs1, sigs2, sigversion);
388 result.script.push_back(spk);
392 return Stacks(CombineMultisig(scriptPubKey, checker, vSolutions, sigs1.script, sigs2.script, sigversion));
394 if (sigs1.witness.empty() || sigs1.witness.back().empty())
396 else if (sigs2.witness.empty() || sigs2.witness.back().empty())
401 CScript pubKey2(sigs1.witness.back().begin(), sigs1.witness.back().end());
403 std::vector<valtype> vSolutions2;
404 Solver(pubKey2, txType2, vSolutions2);
405 sigs1.witness.pop_back();
406 sigs1.script = sigs1.witness;
407 sigs1.witness.clear();
408 sigs2.witness.pop_back();
409 sigs2.script = sigs2.witness;
410 sigs2.witness.clear();
412 result.witness = result.script;
413 result.script.clear();
414 result.witness.push_back(
valtype(pubKey2.begin(), pubKey2.end()));
419 if (sigs1.script.empty() || sigs1.script[0].empty())
424 if (sigs1.script.empty() || sigs1.script[0].empty())
429 if (sigs1.script.empty() || sigs1.script[0].empty())
442 std::vector<std::vector<unsigned char> > vSolutions;
443 Solver(scriptPubKey, txType, vSolutions);
453 DummySignatureChecker() {}
455 bool CheckSig(
const std::vector<unsigned char>& scriptSig,
const std::vector<unsigned char>& vchPubKey,
const CScript& scriptCode,
SigVersion sigversion)
const override 460 const DummySignatureChecker dummyChecker;
471 vchSig.assign(72,
'\000');
477 vchSig[4 + 33] = 0x02;
479 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.
unspendable OP_RETURN script that carries data
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)
Virtual base class for signature creators.
A signature creator for transactions.
std::vector< std::vector< unsigned char > > stack
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const
Create a DER-serialized signature.
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 corbies (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)
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.
const CKeyStore & KeyStore() const
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 IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
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
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
const TransactionSignatureChecker checker
CRIPEMD160 & Write(const unsigned char *data, size_t len)
static opcodetype EncodeOP_N(int n)
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.
virtual bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
std::vector< unsigned char > valtype
std::vector< unsigned char > valtype
A mutable version of CTransaction.
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.
const CTransaction * txTo
unspendable OP_RAVEN_ASSET script that carries data
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)