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");
56 static unsigned int GetLen(uint8_t chHeader) {
57 if (chHeader == 2 || chHeader == 3) {
60 if (chHeader == 4 || chHeader == 6 || chHeader == 7) {
78 template <
typename T>
void Set(
const T pbegin,
const T pend) {
79 int len = pend == pbegin ? 0 :
GetLen(pbegin[0]);
80 if (len && len == (pend - pbegin)) {
81 memcpy(
vch, (uint8_t *)&pbegin[0], len);
88 template <
typename T>
CPubKey(
const T pbegin,
const T pend) {
99 const uint8_t *
data()
const {
return vch; }
112 return a.
vch[0] < b.
vch[0] ||
117 template <
typename Stream>
void Serialize(Stream &s)
const {
118 unsigned int len =
size();
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);
177 static bool CheckLowS(
const std::vector<uint8_t> &vchSig) {
178 return CheckLowS(vchSig | boost::adaptors::sliced(0, vchSig.size()));
183 const std::vector<uint8_t> &vchSig);
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.
constexpr C * begin() const noexcept
constexpr C * end() 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
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)