23typedef std::vector<unsigned char>
valtype;
26 : m_txto{tx}, nIn{input_idx}, nHashType{hash_type}, amount{amount}, checker{&m_txto, nIn, amount,
MissingDataBehavior::
FAIL},
32 : m_txto{tx}, nIn{input_idx}, nHashType{hash_type}, amount{amount},
44 if (!provider.
GetKey(address, key))
58 if (!key.
Sign(hash, vchSig))
60 vchSig.push_back((
unsigned char)hashtype);
79 if (!leaf_hash)
return std::nullopt;
96 if (!hash.has_value())
return false;
100 if (!key.
SignSchnorr(*hash, sig, merkle_root, {}))
return false;
111 if (!provider.
GetKey(part_pubkey.
GetID(), key))
return {};
116 const std::vector<CPubKey>& pubkeys = it->second;
117 if (std::find(pubkeys.begin(), pubkeys.end(), part_pubkey) == pubkeys.end())
return {};
121 if (!sighash.has_value())
return {};
124 std::vector<uint8_t>
out = key.
CreateMuSig2Nonce(secnonce, *sighash, aggregate_pubkey, pubkeys);
125 if (
out.empty())
return {};
139 if (!provider.
GetKey(part_pubkey.
GetID(), key))
return false;
144 const std::vector<CPubKey>& pubkeys = it->second;
145 if (std::find(pubkeys.begin(), pubkeys.end(), part_pubkey) == pubkeys.end())
return {};
148 auto this_leaf_aggkey = std::make_pair(script_pubkey, leaf_hash ? *leaf_hash :
uint256());
151 const std::map<CPubKey, std::vector<uint8_t>>& pubnonces = pubnonce_it->second;
154 if (pubnonces.size() != pubkeys.size())
return false;
158 if (!sighash.has_value())
return false;
162 std::optional<std::reference_wrapper<MuSig2SecNonce>> secnonce = provider.
GetMuSig2SecNonce(session_id);
163 if (!secnonce || !secnonce->get().IsValid())
return false;
166 std::optional<uint256> sig = key.
CreateMuSig2PartialSig(*sighash, aggregate_pubkey, pubkeys, pubnonces, *secnonce, tweaks);
167 if (!sig)
return false;
168 partial_sig = std::move(*sig);
171 assert(!secnonce->get().IsValid());
180 if (!participants.size())
return false;
183 auto this_leaf_aggkey = std::make_pair(script_pubkey, leaf_hash ? *leaf_hash :
uint256());
186 const std::map<CPubKey, std::vector<uint8_t>>& pubnonces = pubnonce_it->second;
189 const std::map<CPubKey, uint256>& partial_sigs = partial_sigs_it->second;
192 if (pubnonces.size() != participants.size())
return false;
193 if (partial_sigs.size() != participants.size())
return false;
197 if (!sighash.has_value())
return false;
199 std::optional<std::vector<uint8_t>> res =
::CreateMuSig2AggregateSig(participants, aggregate_pubkey, tweaks, *sighash, pubnonces, partial_sigs);
200 if (!res)
return false;
226 const auto it = sigdata.
signatures.find(address);
228 pubkey = it->second.first;
234 pubkey = pk_it->second.first;
237 const auto& tap_pk_it = sigdata.
tap_pubkeys.find(address);
239 pubkey = tap_pk_it->second.GetEvenCorrespondingCPubKey();
243 return provider.
GetPubKey(address, pubkey);
249 const auto it = sigdata.
signatures.find(keyid);
251 sig_out = it->second.second;
256 sigdata.
misc_pubkeys.emplace(keyid, std::make_pair(pubkey, std::move(info)));
258 if (creator.
CreateSig(provider, sig_out, keyid, scriptcode, sigversion)) {
276 agg_info = misc_pk_it->second.second;
280 if (part_pks.empty())
continue;
283 for (
const auto& part_pk : part_pks) {
285 if (provider.
GetKeyOrigin(part_pk.GetID(), part_info)) {
289 it = sigdata.
taproot_misc_pubkeys.emplace(xonly_part, std::make_pair(std::set<uint256>(), part_info)).first;
291 if (leaf_hash) it->second.first.insert(*leaf_hash);
297 std::vector<std::pair<uint256, bool>> tweaks;
300 if (agg_info.
path.empty())
continue;
302 CKeyID keyid = agg_pub.GetID();
308 for (
const int i : agg_info.
path) {
309 auto& [
t, xonly] = tweaks.emplace_back();
311 if (!extpub.
Derive(extpub, i, &
t)) {
316 plain_pub = extpub.
pubkey;
322 std::optional<std::pair<XOnlyPubKey, bool>> tweaked = script_pubkey.
CreateTapTweak(merkle_root->
IsNull() ?
nullptr : merkle_root);
323 if (!
Assume(tweaked))
return false;
324 plain_pub = tweaked->first.GetCPubKeys().at(tweaked->second ? 1 : 0);
328 if (creator.
CreateMuSig2AggregateSig(part_pks, sig_out, agg_pub, plain_pub, leaf_hash, tweaks, sigversion, sigdata)) {
332 auto lookup_key = std::make_pair(script_pubkey, leaf_hash ? *leaf_hash :
uint256());
338 auto pub_key_leaf_hash = std::make_pair(plain_pub, leaf_hash ? *leaf_hash :
uint256());
339 for (
const CPubKey& part_pk : part_pks) {
347 if (partial_sigs_it != sigdata.
musig2_partial_sigs.end() && !partial_sigs_it->second.empty()) {
351 std::map<CPubKey, std::vector<uint8_t>>& pubnonces = sigdata.
musig2_pubnonces[pub_key_leaf_hash];
352 for (
const CPubKey& part_pk : part_pks) {
353 if (pubnonces.contains(part_pk))
continue;
354 std::vector<uint8_t> pubnonce = creator.
CreateMuSig2Nonce(provider, agg_pub, plain_pub, part_pk, leaf_hash, merkle_root, sigversion, sigdata);
355 if (pubnonce.empty())
continue;
356 pubnonces[part_pk] = std::move(pubnonce);
368 sigdata.
taproot_misc_pubkeys.emplace(pubkey, std::make_pair(std::set<uint256>({leaf_hash}), info));
370 it->second.first.insert(leaf_hash);
374 auto lookup_key = std::make_pair(pubkey, leaf_hash);
377 sig_out = it->second;
381 if (creator.
CreateSchnorrSig(provider, sig_out, pubkey, &leaf_hash,
nullptr, sigversion)) {
383 }
else if (!
SignMuSig2(creator, sigdata, provider, sig_out, pubkey,
nullptr, &leaf_hash, sigversion)) {
390template<
typename M,
typename K,
typename V>
393 auto it = map.find(key);
394 if (it != map.end()) {
432 assert(last - first == 20);
435 std::copy(first, last, key_id.
begin());
442 std::vector<unsigned char>
ToPKBytes(
const Key& key)
const {
return {key.begin(), key.end()}; }
474 template <
typename I>
477 if (pubkey.IsValid())
return pubkey;
507 template <
typename I>
509 if (last - first != 32)
return {};
511 std::copy(first, last, pubkey.
begin());
575 sigdata.
taproot_misc_pubkeys.emplace(output, std::make_pair(std::set<uint256>(), output_key_info));
580 std::vector<unsigned char> sig;
594 make_keypath_sig(output,
nullptr);
603 std::vector<std::vector<unsigned char>> smallest_result_stack;
605 const auto& [
script, leaf_ver] = key;
606 std::vector<std::vector<unsigned char>> result_stack;
608 result_stack.emplace_back(std::begin(
script), std::end(
script));
609 result_stack.push_back(*control_blocks.begin());
610 if (smallest_result_stack.size() == 0 ||
612 smallest_result_stack = std::move(result_stack);
616 if (smallest_result_stack.size() != 0) {
617 result = std::move(smallest_result_stack);
635 std::vector<unsigned char> sig;
637 std::vector<valtype> vSolutions;
638 whichTypeRet =
Solver(scriptPubKey, vSolutions);
640 switch (whichTypeRet) {
646 if (!
CreateSig(creator, sigdata, provider, sig,
CPubKey(vSolutions[0]), scriptPubKey, sigversion))
return false;
647 ret.push_back(std::move(sig));
652 if (!
GetPubKey(provider, sigdata, keyID, pubkey)) {
657 if (!
CreateSig(creator, sigdata, provider, sig, pubkey, scriptPubKey, sigversion))
return false;
658 ret.push_back(std::move(sig));
665 ret.emplace_back(scriptRet.
begin(), scriptRet.
end());
673 size_t required = vSolutions.front()[0];
675 for (
size_t i = 1; i < vSolutions.size() - 1; ++i) {
680 if (
CreateSig(creator, sigdata, provider, sig, pubkey, scriptPubKey, sigversion)) {
681 if (
ret.size() < required + 1) {
682 ret.push_back(std::move(sig));
686 bool ok =
ret.size() == required + 1;
687 for (
size_t i = 0; i +
ret.size() < required + 1; ++i) {
693 ret.push_back(vSolutions[0]);
698 ret.emplace_back(scriptRet.
begin(), scriptRet.
end());
720 }
else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
722 }
else if (v.size() == 1 && v[0] == 0x81) {
735 std::vector<valtype> result;
746 subscript =
CScript(result[0].begin(), result[0].end());
764 CScript witnessscript(result[0].begin(), result[0].end());
774 if (!solved && result.empty()) {
775 WshSatisfier ms_satisfier{provider, sigdata, creator, witnessscript};
779 result.emplace_back(witnessscript.
begin(), witnessscript.
end());
796 result.emplace_back(subscript.
begin(), subscript.
end());
814 bool CheckECDSASignature(
const std::vector<unsigned char>& scriptSig,
const std::vector<unsigned char>& vchPubKey,
const CScript& scriptCode,
SigVersion sigversion)
const override
816 if (m_checker.CheckECDSASignature(scriptSig, vchPubKey, scriptCode, sigversion)) {
827 std::vector<valtype>
script;
828 std::vector<valtype> witness;
831 Stacks(
const Stacks&) =
delete;
843 data.scriptSig = tx.
vin[nIn].scriptSig;
844 data.scriptWitness = tx.
vin[nIn].scriptWitness;
849 SignatureExtractorChecker extractor_checker(
data, tx_checker);
851 data.complete =
true;
856 std::vector<std::vector<unsigned char>> solutions;
863 CScript redeem_script(stack.script.back().begin(), stack.script.back().end());
864 data.redeem_script = redeem_script;
865 next_script = std::move(redeem_script);
868 script_type =
Solver(next_script, solutions);
869 stack.script.pop_back();
873 CScript witness_script(stack.witness.back().begin(), stack.witness.back().end());
874 data.witness_script = witness_script;
875 next_script = std::move(witness_script);
878 script_type =
Solver(next_script, solutions);
879 stack.witness.pop_back();
880 stack.script = std::move(stack.witness);
881 stack.witness.clear();
886 assert(solutions.size() > 1);
888 unsigned int last_success_key = 0;
889 for (
const valtype& sig : stack.script) {
890 for (
unsigned int i = last_success_key; i <
num_pubkeys; ++i) {
891 const valtype& pubkey = solutions[i+1];
893 if (
data.signatures.count(
CPubKey(pubkey).GetID()) || extractor_checker.CheckECDSASignature(sig, pubkey, next_script, sigversion)) {
894 last_success_key = i + 1;
914 *
this = std::move(sigdata);
931 DummySignatureChecker() =
default;
932 bool CheckECDSASignature(
const std::vector<unsigned char>& sig,
const std::vector<unsigned char>& vchPubKey,
const CScript& scriptCode,
SigVersion sigversion)
const override {
return sig.size() != 0; }
947 DummySignatureCreator(
char r_len,
char s_len) : m_r_len(r_len), m_s_len(s_len) {}
952 vchSig.assign(m_r_len + m_s_len + 7,
'\000');
954 vchSig[1] = m_r_len + m_s_len + 4;
958 vchSig[4 + m_r_len] = 0x02;
959 vchSig[5 + m_r_len] = m_s_len;
960 vchSig[6 + m_r_len] = 0x01;
966 sig.assign(64,
'\000');
971 std::vector<uint8_t>
out;
982 sig.assign(64,
'\000');
996 if (
script.IsWitnessProgram(version, program))
return true;
997 if (
script.IsPayToScriptHash()) {
998 std::vector<valtype> solutions;
1001 auto h160 =
uint160(solutions[0]);
1013 bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) ==
SIGHASH_SINGLE);
1020 std::vector<CTxOut> spent_outputs;
1021 for (
unsigned int i = 0; i < mtx.
vin.size(); ++i) {
1023 auto coin = coins.find(txin.
prevout);
1024 if (coin == coins.end() || coin->second.IsSpent()) {
1025 txdata.
Init(txConst, {},
true);
1028 spent_outputs.emplace_back(coin->second.out.nValue, coin->second.out.scriptPubKey);
1031 if (spent_outputs.size() == mtx.
vin.size()) {
1032 txdata.
Init(txConst, std::move(spent_outputs),
true);
1036 for (
unsigned int i = 0; i < mtx.
vin.size(); ++i) {
1038 auto coin = coins.find(txin.
prevout);
1039 if (coin == coins.end() || coin->second.IsSpent()) {
1040 input_errors[i] =
_(
"Input not found or already spent");
1043 const CScript& prevPubKey = coin->second.out.scriptPubKey;
1044 const CAmount& amount = coin->second.out.nValue;
1048 if (!fHashSingle || (i < mtx.
vout.size())) {
1056 input_errors[i] =
_(
"Missing amount");
1064 input_errors[i] =
Untranslated(
"Unable to sign input, invalid stack size (possibly missing key)");
1067 input_errors[i] =
Untranslated(
"CHECK(MULTI)SIG failing with non-zero signature (possibly need more signatures)");
1073 input_errors.erase(i);
1076 return input_errors.empty();
std::vector< unsigned char > valtype
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assert(val)
Identity function.
#define Assume(val)
Assume is the identity function.
virtual bool CheckLockTime(const CScriptNum &nLockTime) const
virtual bool CheckSchnorrSignature(std::span< const unsigned char > sig, std::span< const unsigned char > pubkey, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror=nullptr) const
virtual bool CheckSequence(const CScriptNum &nSequence) const
virtual bool CheckECDSASignature(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
Interface for signature creators.
virtual const BaseSignatureChecker & Checker() const =0
virtual bool CreateSchnorrSig(const SigningProvider &provider, std::vector< unsigned char > &sig, const XOnlyPubKey &pubkey, const uint256 *leaf_hash, const uint256 *merkle_root, SigVersion sigversion) const =0
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.
virtual bool CreateMuSig2AggregateSig(const std::vector< CPubKey > &participants, std::vector< uint8_t > &sig, const CPubKey &aggregate_pubkey, const CPubKey &script_pubkey, const uint256 *leaf_hash, const std::vector< std::pair< uint256, bool > > &tweaks, SigVersion sigversion, const SignatureData &sigdata) const =0
virtual bool CreateMuSig2PartialSig(const SigningProvider &provider, uint256 &partial_sig, const CPubKey &aggregate_pubkey, const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 *leaf_hash, const std::vector< std::pair< uint256, bool > > &tweaks, SigVersion sigversion, const SignatureData &sigdata) const =0
virtual std::vector< uint8_t > CreateMuSig2Nonce(const SigningProvider &provider, const CPubKey &aggregate_pubkey, const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 *leaf_hash, const uint256 *merkle_root, SigVersion sigversion, const SignatureData &sigdata) const =0
An encapsulated private key.
bool SignSchnorr(const uint256 &hash, std::span< unsigned char > sig, const uint256 *merkle_root, const uint256 &aux) const
Create a BIP-340 Schnorr signature, for the xonly-pubkey corresponding to *this, optionally tweaked b...
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, bool grind=true, uint32_t test_case=0) const
Create a DER-serialized signature.
std::optional< uint256 > CreateMuSig2PartialSig(const uint256 &hash, const CPubKey &aggregate_pubkey, const std::vector< CPubKey > &pubkeys, const std::map< CPubKey, std::vector< uint8_t > > &pubnonces, MuSig2SecNonce &secnonce, const std::vector< std::pair< uint256, bool > > &tweaks)
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
std::vector< uint8_t > CreateMuSig2Nonce(MuSig2SecNonce &secnonce, const uint256 &sighash, const CPubKey &aggregate_pubkey, const std::vector< CPubKey > &pubkeys)
A reference to a CKey: the Hash160 of its serialized public key.
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 IsWitnessProgram(int &version, std::vector< unsigned char > &program) const
static opcodetype EncodeOP_N(int n)
A reference to a CScript: the Hash160 of its serialization.
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
CScriptWitness scriptWitness
Only serialized through CTransaction.
An output of a transaction.
bool CheckECDSASignature(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const override
MuSig2SecNonce encapsulates a secret nonce in use in a MuSig2 signing session.
A signature creator for transactions.
std::vector< uint8_t > CreateMuSig2Nonce(const SigningProvider &provider, const CPubKey &aggregate_pubkey, const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 *leaf_hash, const uint256 *merkle_root, SigVersion sigversion, const SignatureData &sigdata) const override
bool CreateSchnorrSig(const SigningProvider &provider, std::vector< unsigned char > &sig, const XOnlyPubKey &pubkey, const uint256 *leaf_hash, const uint256 *merkle_root, SigVersion sigversion) const override
bool CreateMuSig2AggregateSig(const std::vector< CPubKey > &participants, std::vector< uint8_t > &sig, const CPubKey &aggregate_pubkey, const CPubKey &script_pubkey, const uint256 *leaf_hash, const std::vector< std::pair< uint256, bool > > &tweaks, SigVersion sigversion, const SignatureData &sigdata) const override
MutableTransactionSignatureCreator(const CMutableTransaction &tx LIFETIMEBOUND, unsigned int input_idx, const CAmount &amount, int hash_type)
std::optional< uint256 > ComputeSchnorrSignatureHash(const uint256 *leaf_hash, SigVersion sigversion) const
const CMutableTransaction & m_txto
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.
const PrecomputedTransactionData * m_txdata
bool CreateMuSig2PartialSig(const SigningProvider &provider, uint256 &partial_sig, const CPubKey &aggregate_pubkey, const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 *leaf_hash, const std::vector< std::pair< uint256, bool > > &tweaks, SigVersion sigversion, const SignatureData &sigdata) const override
An interface to be implemented by keystores that support signing.
virtual std::optional< std::reference_wrapper< MuSig2SecNonce > > GetMuSig2SecNonce(const uint256 &session_id) const
virtual bool GetCScript(const CScriptID &scriptid, CScript &script) const
virtual bool GetTaprootSpendData(const XOnlyPubKey &output_key, TaprootSpendData &spenddata) const
bool GetKeyByXOnly(const XOnlyPubKey &pubkey, CKey &key) const
virtual bool GetPubKey(const CKeyID &address, CPubKey &pubkey) const
virtual void SetMuSig2SecNonce(const uint256 &id, MuSig2SecNonce &&nonce) const
bool GetKeyOriginByXOnly(const XOnlyPubKey &pubkey, KeyOriginInfo &info) const
virtual void DeleteMuSig2Session(const uint256 &session_id) const
virtual bool GetTaprootBuilder(const XOnlyPubKey &output_key, TaprootBuilder &builder) const
virtual bool GetKey(const CKeyID &address, CKey &key) const
virtual bool GetKeyOrigin(const CKeyID &keyid, KeyOriginInfo &info) const
virtual std::map< CPubKey, std::vector< CPubKey > > GetAllMuSig2ParticipantPubkeys() const
Utility class to construct Taproot outputs from internal key and script tree.
const unsigned char * begin() const
std::optional< std::pair< XOnlyPubKey, bool > > CreateTapTweak(const uint256 *merkle_root) const
Construct a Taproot tweaked output point with this point as internal key.
uint256 ComputeTapTweakHash(const uint256 *merkle_root) const
Compute the Taproot tweak as specified in BIP341, with *this as internal key:
constexpr bool IsNull() const
constexpr unsigned char * begin()
constexpr const unsigned char * data() const
uint160 RIPEMD160(std::span< const unsigned char > data)
Compute the 160-bit RIPEMD-160 hash of an array.
bool SignatureHashSchnorr(uint256 &hash_out, ScriptExecutionData &execdata, const T &tx_to, uint32_t in_pos, uint8_t hash_type, SigVersion sigversion, const PrecomputedTransactionData &cache, MissingDataBehavior mdb)
uint256 ComputeTapleafHash(uint8_t leaf_version, std::span< const unsigned char > script)
Compute the BIP341 tapleaf hash from leaf version & script.
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, script_verify_flags flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror)
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int32_t nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache, SigHashCache *sighash_cache)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror)
@ TAPROOT
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, key path spending; see BIP 341.
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ TAPSCRIPT
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, script path spending, leaf version 0xc0; see...
@ WITNESS_V0
Witness v0 (P2WPKH and P2WSH); see BIP 141.
static constexpr uint8_t TAPROOT_LEAF_TAPSCRIPT
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
MissingDataBehavior
Enum to specify what *TransactionSignatureChecker's behavior should be when dealing with missing tran...
@ FAIL
Just act as if the signature was invalid.
@ SCRIPT_VERIFY_STRICTENC
static int tweak(const secp256k1_context *ctx, secp256k1_xonly_pubkey *agg_pk, secp256k1_musig_keyagg_cache *cache)
CExtPubKey CreateMuSig2SyntheticXpub(const CPubKey &pubkey)
Construct the BIP 328 synthetic xpub for a pubkey.
uint256 MuSig2SessionID(const CPubKey &script_pubkey, const CPubKey &part_pubkey, const uint256 &sighash)
constexpr size_t MUSIG2_PUBNONCE_SIZE
NodeRef< typename Ctx::Key > FromScript(const CScript &script, const Ctx &ctx)
static constexpr script_verify_flags STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
std::vector< unsigned char > ToByteVector(const T &in)
std::string ScriptErrorString(const ScriptError serror)
enum ScriptError_t ScriptError
@ SCRIPT_ERR_INVALID_STACK_OPERATION
@ SCRIPT_ERR_SIG_NULLFAIL
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
size_t GetSerializeSize(const T &t)
static bool SignStep(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &scriptPubKey, std::vector< valtype > &ret, TxoutType &whichTypeRet, SigVersion sigversion, SignatureData &sigdata)
Sign scriptPubKey using signature made with creator.
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
static bool SignTaprootScript(const SigningProvider &provider, const BaseSignatureCreator &creator, SignatureData &sigdata, int leaf_version, std::span< const unsigned char > script_bytes, std::vector< valtype > &result)
static bool CreateTaprootScriptSig(const BaseSignatureCreator &creator, SignatureData &sigdata, const SigningProvider &provider, std::vector< unsigned char > &sig_out, const XOnlyPubKey &pubkey, const uint256 &leaf_hash, SigVersion sigversion)
void UpdateInput(CTxIn &input, const SignatureData &data)
bool IsSegWitOutput(const SigningProvider &provider, const CScript &script)
Check whether a scriptPubKey is known to be segwit.
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)
std::vector< unsigned char > valtype
static bool SignTaproot(const SigningProvider &provider, const BaseSignatureCreator &creator, const WitnessV1Taproot &output, SignatureData &sigdata, std::vector< valtype > &result)
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)
static bool SignMuSig2(const BaseSignatureCreator &creator, SignatureData &sigdata, const SigningProvider &provider, std::vector< unsigned char > &sig_out, const XOnlyPubKey &script_pubkey, const uint256 *merkle_root, const uint256 *leaf_hash, SigVersion sigversion)
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
const BaseSignatureChecker & DUMMY_CHECKER
A signature checker that accepts all signatures.
bool SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, int nHashType, std::map< int, bilingual_str > &input_errors)
Sign the CMutableTransaction.
static CScript PushAll(const std::vector< valtype > &values)
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
miniscript::Availability MsLookupHelper(const M &map, const K &key, V &value)
static bool GetCScript(const SigningProvider &provider, const SignatureData &sigdata, const CScriptID &scriptid, CScript &script)
std::pair< CPubKey, std::vector< unsigned char > > SigPair
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
@ WITNESS_UNKNOWN
Only for Witness versions not already defined above.
@ ANCHOR
anyone can spend script
@ NULL_DATA
unspendable OP_RETURN script that carries data
bool Derive(CExtPubKey &out, unsigned int nChild, uint256 *bip32_tweak_out=nullptr) const
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::vector< std::vector< unsigned char > > stack
unsigned char fingerprint[4]
First 32 bits of the Hash160 of the public key at the root of the path.
std::vector< uint32_t > path
void Init(const T &tx, std::vector< CTxOut > &&spent_outputs, bool force=false)
Initialize this PrecomputedTransactionData with transaction data.
bool m_bip341_taproot_ready
Whether the 5 fields above are initialized.
bool m_spent_outputs_ready
Whether m_spent_outputs is initialized.
std::optional< CPubKey > CPubFromPKHBytes(I first, I last) const
Get a CPubKey from a key hash. Note the key hash may be of an xonly pubkey.
const BaseSignatureCreator & m_creator
miniscript::Availability SatRIPEMD160(const std::vector< unsigned char > &hash, std::vector< unsigned char > &preimage) const
bool CheckAfter(uint32_t value) const
Time lock satisfactions.
const miniscript::MiniscriptContext m_script_ctx
The context of the script we are satisfying (either P2WSH or Tapscript).
std::vector< unsigned char > ToPKBytes(const Key &key) const
Conversion to raw public key.
miniscript::Availability SatSHA256(const std::vector< unsigned char > &hash, std::vector< unsigned char > &preimage) const
Hash preimage satisfactions.
miniscript::Availability SatHASH256(const std::vector< unsigned char > &hash, std::vector< unsigned char > &preimage) const
const SigningProvider & m_provider
Satisfier(const SigningProvider &provider LIFETIMEBOUND, SignatureData &sig_data LIFETIMEBOUND, const BaseSignatureCreator &creator LIFETIMEBOUND, const CScript &witscript LIFETIMEBOUND, miniscript::MiniscriptContext script_ctx)
miniscript::Availability SatHASH160(const std::vector< unsigned char > &hash, std::vector< unsigned char > &preimage) const
SignatureData & m_sig_data
bool CheckOlder(uint32_t value) const
static bool KeyCompare(const Key &a, const Key &b)
miniscript::MiniscriptContext MsContext() const
const CScript & m_witness_script
uint256 m_tapleaf_hash
The tapleaf hash.
bool m_annex_present
Whether an annex is present.
bool m_annex_init
Whether m_annex_present and (when needed) m_annex_hash are initialized.
bool m_codeseparator_pos_init
Whether m_codeseparator_pos is initialized.
bool m_tapleaf_hash_init
Whether m_tapleaf_hash is initialized.
uint32_t m_codeseparator_pos
Opcode position of the last executed OP_CODESEPARATOR (or 0xFFFFFFFF if none executed).
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.
std::map< std::vector< uint8_t >, std::vector< uint8_t > > ripemd160_preimages
Mapping from a RIPEMD160 hash to its preimage provided to solve a Script.
void MergeSignatureData(SignatureData sigdata)
std::map< CKeyID, XOnlyPubKey > tap_pubkeys
Misc Taproot pubkeys involved in this input, by hash. (Equivalent of misc_pubkeys but for Taproot....
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a ...
TaprootSpendData tr_spenddata
Taproot spending data.
bool witness
Stores whether the input this SigData corresponds to is a witness input.
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
std::optional< TaprootBuilder > tr_builder
Taproot tree used to build tr_spenddata.
CScript scriptSig
The scriptSig of an input. Contains complete signatures or the traditional partial signatures format.
std::map< std::vector< uint8_t >, std::vector< uint8_t > > sha256_preimages
Mapping from a SHA256 hash to its preimage provided to solve a Script.
std::vector< unsigned char > taproot_key_path_sig
std::map< std::pair< CPubKey, uint256 >, std::map< CPubKey, std::vector< uint8_t > > > musig2_pubnonces
Mapping from pair of MuSig2 aggregate pubkey, and tapleaf hash to map of MuSig2 participant pubkeys t...
std::map< std::pair< XOnlyPubKey, uint256 >, std::vector< unsigned char > > taproot_script_sigs
Schnorr signature for key path spending.
std::map< XOnlyPubKey, std::pair< std::set< uint256 >, KeyOriginInfo > > taproot_misc_pubkeys
Miscellaneous Taproot pubkeys involved in this input along with their leaf script hashes and key orig...
std::map< std::vector< uint8_t >, std::vector< uint8_t > > hash256_preimages
Mapping from a HASH256 hash to its preimage provided to solve a Script.
CScript redeem_script
The redeemScript (if any) for the input.
std::map< std::pair< CPubKey, uint256 >, std::map< CPubKey, uint256 > > musig2_partial_sigs
Mapping from pair of MuSig2 aggregate pubkey, and tapleaf hash to map of MuSig2 participant pubkeys t...
uint256 missing_witness_script
SHA256 of the missing witnessScript (if any)
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
CScript witness_script
The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
std::map< CPubKey, std::vector< CPubKey > > musig2_pubkeys
Map MuSig2 aggregate pubkeys to its participants.
CScriptWitness scriptWitness
The scriptWitness of an input. Contains complete signatures or the traditional partial signatures for...
bool complete
Stores whether the scriptSig and scriptWitness are complete.
std::map< std::vector< uint8_t >, std::vector< uint8_t > > hash160_preimages
Mapping from a HASH160 hash to its preimage provided to solve a Script.
Miniscript satisfier specific to Tapscript context.
std::optional< XOnlyPubKey > FromPKHBytes(I first, I last) const
Conversion from a raw xonly public key hash.
const uint256 & m_leaf_hash
miniscript::Availability Sign(const XOnlyPubKey &key, std::vector< unsigned char > &sig) const
Satisfy a BIP340 signature check.
std::optional< XOnlyPubKey > FromPKBytes(I first, I last) const
Conversion from a raw xonly public key.
TapSatisfier(const SigningProvider &provider LIFETIMEBOUND, SignatureData &sig_data LIFETIMEBOUND, const BaseSignatureCreator &creator LIFETIMEBOUND, const CScript &script LIFETIMEBOUND, const uint256 &leaf_hash LIFETIMEBOUND)
uint256 merkle_root
The Merkle root of the script tree (0 if no scripts).
std::map< std::pair< std::vector< unsigned char >, int >, std::set< std::vector< unsigned char >, ShortestVectorFirstComparator > > scripts
Map from (script, leaf_version) to (sets of) control blocks.
void Merge(TaprootSpendData other)
Merge other TaprootSpendData (for the same scriptPubKey) into this.
XOnlyPubKey internal_key
The BIP341 internal key.
Miniscript satisfier specific to P2WSH context.
WshSatisfier(const SigningProvider &provider LIFETIMEBOUND, SignatureData &sig_data LIFETIMEBOUND, const BaseSignatureCreator &creator LIFETIMEBOUND, const CScript &witscript LIFETIMEBOUND)
std::optional< CPubKey > FromPKBytes(I first, I last) const
Conversion from a raw compressed public key.
std::optional< CPubKey > FromPKHBytes(I first, I last) const
Conversion from a raw compressed public key hash.
miniscript::Availability Sign(const CPubKey &key, std::vector< unsigned char > &sig) const
Satisfy an ECDSA signature check.
consteval auto _(util::TranslatedLiteral str)
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
std::vector< std::common_type_t< Args... > > Vector(Args &&... args)
Construct a vector with the specified elements.