7 #ifndef BITCOIN_PUBKEY_H
8 #define BITCOIN_PUBKEY_H
37 static constexpr
unsigned int SIZE = 65;
47 "COMPRESSED_SIZE is larger than SIZE");
58 unsigned int static GetLen(
unsigned char chHeader)
60 if (chHeader == 2 || chHeader == 3)
62 if (chHeader == 4 || chHeader == 6 || chHeader == 7)
76 return vch.size() > 0 &&
GetLen(vch[0]) == vch.size();
87 void Set(
const T pbegin,
const T pend)
89 int len = pend == pbegin ? 0 :
GetLen(pbegin[0]);
90 if (len && len == (pend - pbegin))
91 memcpy(
vch, (
unsigned char*)&pbegin[0], len);
104 explicit CPubKey(
const std::vector<unsigned char>& _vch)
106 Set(_vch.begin(), _vch.end());
111 const unsigned char*
data()
const {
return vch; }
114 const unsigned char&
operator[](
unsigned int pos)
const {
return vch[pos]; }
119 return a.
vch[0] == b.
vch[0] &&
128 return a.
vch[0] < b.
vch[0] ||
133 template <
typename Stream>
136 unsigned int len =
size();
138 s.write((
char*)
vch, len);
140 template <
typename Stream>
145 s.read((
char*)
vch, len);
193 bool Verify(
const uint256& hash,
const std::vector<unsigned char>& vchSig)
const;
198 static bool CheckLowS(
const std::vector<unsigned char>& vchSig);
268 #endif // BITCOIN_PUBKEY_H
bool CheckPayToContract(const XOnlyPubKey &base, const uint256 &hash, bool parity) const
static constexpr unsigned int SIZE
secp256k1:
unsigned char vchFingerprint[4]
unsigned static int GetLen(unsigned char chHeader)
Compute the length of a pubkey with a given first byte.
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
friend bool operator<(const CPubKey &a, const CPubKey &b)
unsigned char vch[SIZE]
see www.keylength.com script supports up to 75 for single byte push
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
CKeyID(const uint160 &in)
void Invalidate()
Set this key data to be invalid.
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
static bool CheckLowS(const std::vector< unsigned char > &vchSig)
Check whether a signature is normalized (lower-S).
void Unserialize(Stream &s)
friend bool operator==(const CPubKey &a, const CPubKey &b)
Comparator implementation.
bool Derive(CExtPubKey &out, unsigned int nChild) const
static bool ValidSize(const std::vector< unsigned char > &vch)
const unsigned char & operator[](int pos) const
Users of this module must hold an ECCVerifyHandle.
friend bool operator==(const CExtPubKey &a, const CExtPubKey &b)
friend bool operator!=(const CExtPubKey &a, const CExtPubKey &b)
static constexpr unsigned int COMPRESSED_SIZE
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])
void Serialize(Stream &s) const
Implement serialization, as if this was a byte vector.
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
CPubKey()
Construct an invalid public key.
An encapsulated public key.
const unsigned char & operator[](unsigned int pos) const
XOnlyPubKey(Span< const unsigned char > bytes)
Construct an x-only pubkey from exactly 32 bytes.
uint256 GetHash() const
Get the 256-bit hash of this public key.
static constexpr unsigned int COMPACT_SIGNATURE_SIZE
const unsigned char * data() const
bool VerifySchnorr(const uint256 &msg, Span< const unsigned char > sigbytes) const
Verify a Schnorr signature against this public key.
const unsigned char * begin() const
CPubKey(const std::vector< unsigned char > &_vch)
Construct a public key from a byte vector.
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
bool IsCompressed() const
Check whether this is a compressed public key.
void * memcpy(void *a, const void *b, size_t c)
const unsigned int BIP32_EXTKEY_SIZE
CPubKey(const T pbegin, const T pend)
Construct a public key using begin/end iterators to byte data.
A reference to a CKey: the Hash160 of its serialized public key.
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid()) ...
bool Derive(CPubKey &pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child pubkey.
A Span is an object that can refer to a contiguous sequence of objects.
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
const unsigned char * data() const
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
static constexpr unsigned int SIGNATURE_SIZE
friend bool operator!=(const CPubKey &a, const CPubKey &b)
const unsigned char * end() const
bool Decompress()
Turn this public key into an uncompressed public key.
unsigned int size() const
Span< A > constexpr MakeSpan(A(&a)[N])
MakeSpan for arrays: