7 #ifndef BITCOIN_PUBKEY_H
8 #define BITCOIN_PUBKEY_H
37 static constexpr
unsigned int SIZE = 65;
46 SIZE >= COMPRESSED_SIZE,
47 "COMPRESSED_SIZE is larger than SIZE");
55 unsigned char vch[
SIZE];
58 unsigned int static GetLen(
unsigned char chHeader)
60 if (chHeader == 2 || chHeader == 3)
62 if (chHeader == 4 || chHeader == 6 || chHeader == 7)
75 bool static ValidSize(
const std::vector<unsigned char> &vch) {
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);
98 CPubKey(
const T pbegin,
const T pend)
104 explicit CPubKey(
const std::vector<unsigned char>& _vch)
106 Set(_vch.begin(), _vch.end());
110 unsigned int size()
const {
return GetLen(vch[0]); }
111 const unsigned char* data()
const {
return vch; }
112 const unsigned char* begin()
const {
return vch; }
113 const unsigned char* end()
const {
return vch + size(); }
114 const unsigned char& operator[](
unsigned int pos)
const {
return vch[pos]; }
119 return a.vch[0] == b.vch[0] &&
120 memcmp(a.vch, b.vch, a.size()) == 0;
128 return a.vch[0] < b.vch[0] ||
129 (a.vch[0] == b.vch[0] && memcmp(a.vch, b.vch, a.size()) < 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);
181 bool IsFullyValid()
const;
184 bool IsCompressed()
const
193 bool Verify(
const uint256& hash,
const std::vector<unsigned char>& vchSig)
const;
198 static bool CheckLowS(
const std::vector<unsigned char>& vchSig);
201 bool RecoverCompact(
const uint256& hash,
const std::vector<unsigned char>& vchSig);
227 const unsigned char*
data()
const {
return m_keydata.
begin(); }
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]
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
bool operator==(const CNetAddr &a, const CNetAddr &b)
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)
bool Derive(CExtPubKey &out, unsigned int nChild) const
void Serialize(Stream &s, char a)
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])
An encapsulated public key.
XOnlyPubKey(Span< const unsigned char > bytes)
Construct an x-only pubkey from exactly 32 bytes.
static constexpr unsigned int COMPACT_SIGNATURE_SIZE
bool VerifySchnorr(const uint256 &msg, Span< const unsigned char > sigbytes) const
Verify a Schnorr signature against this public key.
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
bool operator<(const CNetAddr &a, const CNetAddr &b)
void * memcpy(void *a, const void *b, size_t c)
const unsigned int BIP32_EXTKEY_SIZE
A reference to a CKey: the Hash160 of its serialized public key.
void Unserialize(Stream &s, char &a)
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
static constexpr unsigned int SIGNATURE_SIZE
unsigned int size() const
Span< A > constexpr MakeSpan(A(&a)[N])
MakeSpan for arrays: