7 #ifndef BITCOIN_PUBKEY_H 8 #define BITCOIN_PUBKEY_H 37 static constexpr
unsigned int SIZE = 65;
38 static constexpr
unsigned int COMPRESSED_SIZE = 33;
39 static constexpr
unsigned int SIGNATURE_SIZE = 72;
40 static constexpr
unsigned int COMPACT_SIGNATURE_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)
61 return COMPRESSED_SIZE;
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);
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] &&
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);
190 bool IsFullyValid()
const;
195 return size() == COMPRESSED_SIZE;
202 bool Verify(
const uint256& hash,
const std::vector<unsigned char>& vchSig)
const;
207 static bool CheckLowS(
const std::vector<unsigned char>& vchSig);
210 bool RecoverCompact(
const uint256& hash,
const std::vector<unsigned char>& vchSig);
233 bool CheckPayToContract(
const XOnlyPubKey& base,
const uint256& hash,
bool parity)
const;
236 const unsigned char*
data()
const {
return m_keydata.
begin(); }
242 unsigned char vchFingerprint[4];
262 void Decode(
const unsigned char code[BIP32_EXTKEY_SIZE]);
263 bool Derive(
CExtPubKey& out,
unsigned int nChild)
const;
277 #endif // BITCOIN_PUBKEY_H
unsigned char vchFingerprint[4]
unsigned static int GetLen(unsigned char chHeader)
Compute the length of a pubkey with a given first byte.
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.
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
uint256 GetHash() const
Get the 256-bit hash of this public key.
const unsigned char & operator[](unsigned int pos) const
void Unserialize(Stream &s)
friend bool operator==(const CPubKey &a, const CPubKey &b)
Comparator implementation.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
const unsigned char * begin() const
void Serialize(Stream &s) const
Implement serialization, as if this was a byte vector.
static bool ValidSize(const std::vector< unsigned char > &vch)
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)
const unsigned char * end() const
CPubKey()
Construct an invalid public key.
An encapsulated public key.
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
unsigned int size() const
std::pair< std::string, data > Decode(const std::string &str)
Decode a Bech32 string.
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.
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.
const unsigned char & operator[](int pos) const
const unsigned char * data() const
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.
std::string Encode(const std::string &hrp, const data &values)
Encode a Bech32 string.
friend bool operator!=(const CPubKey &a, const CPubKey &b)
Span< A > constexpr MakeSpan(A(&a)[N])
MakeSpan for arrays:
bool IsCompressed() const
Check whether this is a compressed public key.
const unsigned char * data() const