7 #ifndef BITCOIN_PUBKEY_H 8 #define BITCOIN_PUBKEY_H 46 "COMPRESSED_PUBLIC_KEY_SIZE is larger than PUBLIC_KEY_SIZE");
57 unsigned int static GetLen(
unsigned char chHeader)
59 if (chHeader == 2 || chHeader == 3)
61 if (chHeader == 4 || chHeader == 6 || chHeader == 7)
86 void Set(
const T pbegin,
const T pend)
88 int len = pend == pbegin ? 0 :
GetLen(pbegin[0]);
89 if (len && len == (pend - pbegin))
90 memcpy(
vch, (
unsigned char*)&pbegin[0], len);
103 explicit CPubKey(
const std::vector<unsigned char>& _vch)
105 Set(_vch.begin(), _vch.end());
110 const unsigned char*
data()
const {
return vch; }
113 const unsigned char&
operator[](
unsigned int pos)
const {
return vch[pos]; }
118 return a.
vch[0] == b.
vch[0] &&
127 return a.
vch[0] < b.
vch[0] ||
132 template <
typename Stream>
135 unsigned int len =
size();
137 s.write((
char*)
vch, len);
139 template <
typename Stream>
144 s.read((
char*)
vch, len);
189 bool Verify(
const uint256& hash,
const std::vector<unsigned char>& vchSig)
const;
194 static bool CheckLowS(
const std::vector<unsigned char>& vchSig);
231 template <
typename Stream>
238 s.write((
const char *)&code[0], len);
240 template <
typename Stream>
246 throw std::runtime_error(
"Invalid extended key size\n");
247 s.read((
char *)&code[0], len);
263 #endif // BITCOIN_PUBKEY_H unsigned int nChild
Definition: pubkey.h:209
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])
Definition: pubkey.cpp:258
uint256 ChainCode
Definition: pubkey.h:27
bool Derive(CPubKey &pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child pubkey.
Definition: pubkey.cpp:227
const unsigned char & operator[](unsigned int pos) const
Definition: pubkey.h:113
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:109
uint64_t ReadCompactSize(Stream &is)
Definition: serialize.h:289
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
Definition: serialize.h:986
friend bool operator!=(const CPubKey &a, const CPubKey &b)
Definition: pubkey.h:121
void Serialize(Stream &s) const
Definition: pubkey.h:232
uint256 GetHash() const
Get the 256-bit hash of this public key.
Definition: pubkey.h:161
void Unserialize(Stream &s)
Definition: pubkey.h:241
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Definition: pubkey.cpp:206
struct anonymous_namespace{qrc_bitcoin.cpp}::initializer dummy
CKeyID()
Definition: pubkey.h:23
static constexpr unsigned int COMPRESSED_PUBLIC_KEY_SIZE
Definition: pubkey.h:37
uint160 Hash160(const T1 pbegin, const T1 pend)
Definition: hash.h:94
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:155
void Invalidate()
Set this key data to be invalid.
Definition: pubkey.h:67
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
Definition: pubkey.cpp:186
bool Decompress()
Turn this public key into an uncompressed public key.
Definition: pubkey.cpp:213
void Unserialize(Stream &s)
Definition: pubkey.h:140
static constexpr unsigned int PUBLIC_KEY_SIZE
Definition: pubkey.h:36
unsigned static int GetLen(unsigned char chHeader)
Compute the length of a pubkey with a given first byte.
Definition: pubkey.h:57
const unsigned char * begin() const
Definition: pubkey.h:111
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
Definition: pubkey.cpp:248
void Serialize(CSizeComputer &s) const
Definition: pubkey.h:226
bool Derive(CExtPubKey &out, unsigned int nChild) const
Definition: pubkey.cpp:266
ChainCode chaincode
Definition: pubkey.h:210
ECCVerifyHandle()
Definition: pubkey.cpp:284
static constexpr unsigned int SIGNATURE_SIZE
Definition: pubkey.h:38
unsigned char vchFingerprint[4]
Definition: pubkey.h:208
void seek(size_t _nSize)
Definition: serialize.h:925
uint256 Hash(const T1 pbegin, const T1 pend)
Definition: hash.h:71
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Definition: pubkey.cpp:169
const unsigned char * end() const
Definition: pubkey.h:112
friend bool operator<(const CPubKey &a, const CPubKey &b)
Definition: pubkey.h:125
CPubKey(const std::vector< unsigned char > &_vch)
Construct a public key from a byte vector.
Definition: pubkey.h:103
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
Definition: pubkey.h:86
CPubKey(const T pbegin, const T pend)
Construct a public key using begin/end iterators to byte data.
Definition: pubkey.h:97
Definition: uint256.h:121
void Serialize(Stream &s) const
Implement serialization, as if this was a byte vector.
Definition: pubkey.h:133
CPubKey pubkey
Definition: pubkey.h:211
static int refcount
Definition: pubkey.h:256
Definition: serialize.h:910
static constexpr unsigned int COMPACT_SIGNATURE_SIZE
Definition: pubkey.h:39
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:180
CKeyID(const uint160 &in)
Definition: pubkey.h:24
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:18
~ECCVerifyHandle()
Definition: pubkey.cpp:294
static bool ValidSize(const std::vector< unsigned char > &vch)
Definition: pubkey.h:74
const unsigned int BIP32_EXTKEY_SIZE
Definition: pubkey.h:17
unsigned char vch[PUBLIC_KEY_SIZE]
Definition: pubkey.h:46
Definition: uint256.h:110
bool IsValid() const
Definition: pubkey.h:171
friend bool operator==(const CPubKey &a, const CPubKey &b)
Comparator implementation.
Definition: pubkey.h:116
CPubKey()
Construct an invalid public key.
Definition: pubkey.h:79
unsigned char nDepth
Definition: pubkey.h:207
static bool CheckLowS(const std::vector< unsigned char > &vchSig)
Definition: pubkey.cpp:274
const unsigned char * data() const
Definition: pubkey.h:110
friend bool operator==(const CExtPubKey &a, const CExtPubKey &b)
Definition: pubkey.h:213