6#ifndef BITCOIN_SCRIPT_SIGN_H
7#define BITCOIN_SCRIPT_SIGN_H
34 std::vector<uint8_t> &vchSig,
const CKeyID &keyid,
35 const CScript &scriptCode)
const = 0;
52 std::vector<uint8_t> &vchSig,
const CKeyID &keyid,
53 const CScript &scriptCode)
const override;
61typedef std::pair<CPubKey, std::vector<uint8_t>>
SigPair;
95template <
typename Stream,
typename... X>
105template <
typename Stream,
typename... X>
108 size_t remaining_before = s.size();
110 size_t remaining_after = s.size();
111 if (remaining_after + expected_size != remaining_before) {
112 throw std::ios_base::failure(
"Size of value was not the stated size");
117template <
typename Stream>
119 std::map<CPubKey, KeyOriginInfo> &hd_keypaths) {
123 throw std::ios_base::failure(
124 "Size of key was not the expected size for the type BIP32 keypath");
127 CPubKey pubkey(key.begin() + 1, key.end());
129 throw std::ios_base::failure(
"Invalid pubkey");
131 if (hd_keypaths.count(pubkey) > 0) {
132 throw std::ios_base::failure(
133 "Duplicate Key, pubkey derivation path already provided");
138 if (value_len % 4 || value_len == 0) {
139 throw std::ios_base::failure(
"Invalid length for HD key path");
144 for (
unsigned int i = 4; i < value_len; i +=
sizeof(uint32_t)) {
147 keypath.
path.push_back(index);
151 hd_keypaths.emplace(pubkey, std::move(keypath));
155template <
typename Stream>
157 const std::map<CPubKey, KeyOriginInfo> &hd_keypaths,
159 for (
const auto &keypath_pair : hd_keypaths) {
160 if (!keypath_pair.first.IsValid()) {
161 throw std::ios_base::failure(
"Invalid CPubKey being serialized");
166 s << keypath_pair.second.fingerprint;
167 for (
const auto &path : keypath_pair.second.path) {
188 unsigned int nIn,
const CTxOut &txout);
201 const std::map<COutPoint, Coin> &coins,
203 std::map<int, std::string> &input_errors);
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
virtual ~BaseSignatureCreator()=default
An encapsulated secp256k1 private key.
A reference to a CKey: the Hash160 of its serialized public key.
A mutable version of CTransaction.
An encapsulated public key.
static constexpr unsigned int COMPRESSED_SIZE
static constexpr unsigned int SIZE
secp256k1:
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Serialized script, used inside transaction inputs and outputs.
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.
An output of a transaction.
A signature creator for transactions.
MutableTransactionSignatureCreator(const CMutableTransaction &tx LIFETIMEBOUND, unsigned int input_idx, const Amount &amount, SigHashType sig_hash_type=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 BaseSignatureChecker & Checker() const override
const CMutableTransaction & m_txto
const MutableTransactionSignatureChecker checker
Signature hash type wrapper class.
An interface to be implemented by keystores that support signing.
GetSerializeSize implementations
A Span is an object that can refer to a contiguous sequence of objects.
CONSTEXPR_IF_NOT_DEBUG Span< C > first(std::size_t count) const noexcept
void UnserializeMany(Stream &s, Args &&...args)
void WriteCompactSize(SizeComputer &os, uint64_t nSize)
void SerializeMany(Stream &s, const Args &...args)
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
void UnserializeFromVector(Stream &s, X &...args)
void UpdateInput(CTxIn &input, const SignatureData &data)
void SerializeToVector(Stream &s, const X &...args)
bool SignTransaction(CMutableTransaction &mtx, const SigningProvider *provider, const std::map< COutPoint, Coin > &coins, SigHashType sigHashType, std::map< int, std::string > &input_errors)
Sign the CMutableTransaction.
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.
void SerializeHDKeypaths(Stream &s, const std::map< CPubKey, KeyOriginInfo > &hd_keypaths, uint8_t type)
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
void DeserializeHDKeypaths(Stream &s, const std::vector< uint8_t > &key, std::map< CPubKey, KeyOriginInfo > &hd_keypaths)
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &scriptPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
std::pair< CPubKey, std::vector< uint8_t > > SigPair
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.
std::vector< uint32_t > path
uint8_t fingerprint[4]
First 32 bits of the Hash160 of the public key at the root of the path.
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.
SignatureData(const CScript &script)
bool complete
Stores whether the scriptSig are complete.