7#ifndef BITCOIN_PUBKEY_H
8#define BITCOIN_PUBKEY_H
14#include <boost/range/adaptor/sliced.hpp>
36 static constexpr unsigned int SIZE = 65;
46 "COMPRESSED_SIZE is larger than SIZE");
78 template <
typename T>
void Set(
const T
pbegin,
const T pend) {
106 return a.vch[0] ==
b.vch[0] &&
memcmp(
a.vch,
b.vch,
a.size()) == 0;
112 return a.vch[0] <
b.vch[0] ||
113 (
a.vch[0] ==
b.vch[0] &&
memcmp(
a.vch,
b.vch,
a.size()) < 0);
161 const std::vector<uint8_t> &
vchSig)
const;
168 const std::array<uint8_t, SCHNORR_SIZE> &
sig)
const;
170 const std::vector<uint8_t> &
vchSig)
const;
176 CheckLowS(
const boost::sliced_range<
const std::vector<uint8_t>> &
vchSig);
183 const std::vector<uint8_t> &
vchSig);
201 return a.nDepth ==
b.nDepth &&
202 memcmp(
a.vchFingerprint,
b.vchFingerprint,
204 a.nChild ==
b.nChild &&
a.chaincode ==
b.chaincode &&
205 a.pubkey ==
b.pubkey;
A reference to a CKey: the Hash160 of its serialized public key.
CKeyID(const uint160 &in)
An encapsulated public key.
bool IsCompressed() const
Check whether this is a compressed public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
static constexpr unsigned int SCHNORR_SIZE
static constexpr unsigned int COMPRESSED_SIZE
uint8_t vch[SIZE]
see www.keylength.com script supports up to 75 for single byte push
bool VerifySchnorr(const uint256 &hash, const std::array< uint8_t, SCHNORR_SIZE > &sig) const
Verify a Schnorr signature (=64 bytes).
const uint8_t * end() const
static bool CheckLowS(const std::vector< uint8_t > &vchSig)
CPubKey()
Construct an invalid public key.
bool VerifyECDSA(const uint256 &hash, const std::vector< uint8_t > &vchSig) const
Verify a DER-serialized ECDSA signature (~72 bytes).
bool Decompress()
Turn this public key into an uncompressed public key.
static constexpr unsigned int SIZE
secp256k1:
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
friend bool operator==(const CPubKey &a, const CPubKey &b)
Comparator implementation.
void Serialize(Stream &s) const
Implement serialization, as if this was a byte vector.
static bool ValidSize(const std::vector< uint8_t > &vch)
CPubKey(const T pbegin, const T pend)
Construct a public key using begin/end iterators to byte data.
const uint8_t * data() const
bool RecoverCompact(const uint256 &hash, const std::vector< uint8_t > &vchSig)
Recover a public key from a compact ECDSA signature.
void Invalidate()
Set this key data to be invalid.
CPubKey(Span< const uint8_t > _vch)
Construct a public key from a byte vector.
void Unserialize(Stream &s)
const uint8_t * begin() const
uint256 GetHash() const
Get the 256-bit hash of this public key.
static bool CheckLowS(const boost::sliced_range< const std::vector< uint8_t > > &vchSig)
Check whether a DER-serialized ECDSA signature is normalized (lower-S).
bool Derive(CPubKey &pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child pubkey.
const uint8_t & operator[](unsigned int pos) const
static constexpr unsigned int SIGNATURE_SIZE
static unsigned int GetLen(uint8_t chHeader)
Compute the length of a pubkey with a given first byte.
static constexpr unsigned int COMPACT_SIGNATURE_SIZE
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
friend bool operator!=(const CPubKey &a, const CPubKey &b)
friend bool operator<(const CPubKey &a, const CPubKey &b)
Users of this module must hold an ECCVerifyHandle.
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
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
const unsigned int BIP32_EXTKEY_SIZE
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
Span< std::byte > AsWritableBytes(Span< T > s) noexcept
Span< const std::byte > AsBytes(Span< T > s) noexcept
void Encode(uint8_t code[BIP32_EXTKEY_SIZE]) const
friend bool operator==(const CExtPubKey &a, const CExtPubKey &b)
bool Derive(CExtPubKey &out, unsigned int nChild) const
uint8_t vchFingerprint[4]
void Decode(const uint8_t code[BIP32_EXTKEY_SIZE])
friend bool operator!=(const CExtPubKey &a, const CExtPubKey &b)