6#ifndef BITCOIN_SCRIPT_SIGN_H
7#define BITCOIN_SCRIPT_SIGN_H
33 std::vector<uint8_t> &vchSig,
const CKeyID &keyid,
34 const CScript &scriptCode)
const = 0;
51 std::vector<uint8_t> &vchSig,
const CKeyID &keyid,
52 const CScript &scriptCode)
const override;
60typedef std::pair<CPubKey, std::vector<uint8_t>>
SigPair;
94template <
typename Stream,
typename... X>
102template <
typename Stream,
typename... X>
105 size_t remaining_before = s.size();
107 size_t remaining_after = s.size();
108 if (remaining_after + expected_size != remaining_before) {
109 throw std::ios_base::failure(
"Size of value was not the stated size");
114template <
typename Stream>
116 std::map<CPubKey, KeyOriginInfo> &hd_keypaths) {
120 throw std::ios_base::failure(
121 "Size of key was not the expected size for the type BIP32 keypath");
124 CPubKey pubkey(key.begin() + 1, key.end());
126 throw std::ios_base::failure(
"Invalid pubkey");
128 if (hd_keypaths.count(pubkey) > 0) {
129 throw std::ios_base::failure(
130 "Duplicate Key, pubkey derivation path already provided");
135 if (value_len % 4 || value_len == 0) {
136 throw std::ios_base::failure(
"Invalid length for HD key path");
141 for (
unsigned int i = 4; i < value_len; i +=
sizeof(uint32_t)) {
144 keypath.
path.push_back(index);
148 hd_keypaths.emplace(pubkey, std::move(keypath));
152template <
typename Stream>
154 const std::map<CPubKey, KeyOriginInfo> &hd_keypaths,
156 for (
auto keypath_pair : hd_keypaths) {
157 if (!keypath_pair.first.IsValid()) {
158 throw std::ios_base::failure(
"Invalid CPubKey being serialized");
163 s << keypath_pair.second.fingerprint;
164 for (
const auto &path : keypath_pair.second.path) {
185 unsigned int nIn,
const CTxOut &txout);
198 const std::map<COutPoint, Coin> &coins,
200 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()
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 (see script.h)
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 *txToIn, unsigned int nInIn, const Amount &amountIn, SigHashType sigHashTypeIn=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 * txTo
const MutableTransactionSignatureChecker checker
Signature hash type wrapper class.
An interface to be implemented by keystores that support signing.
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 SerializeMany(Stream &s)
size_t GetSerializeSizeMany(int nVersion, const T &...t)
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
void UnserializeMany(Stream &s)
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
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.