4 #include <structs/hash.h> 5 #include <utils/serialize.h> 6 #include <structs/uint256.h> 10 #include <script/standard.h> 33 unsigned char vch[65];
36 unsigned int static GetLen(
unsigned char chHeader)
38 if (chHeader == 2 || chHeader == 3)
40 if (chHeader == 4 || chHeader == 6 || chHeader == 7)
60 void Set(
const T pbegin,
const T pend)
62 int len = pend == pbegin ? 0 : GetLen(pbegin[0]);
63 if (len && len == (pend - pbegin))
64 memcpy(vch, (
unsigned char*)&pbegin[0], len);
77 CPubKey(
const std::vector<unsigned char>& vch)
79 Set(vch.begin(), vch.end());
83 unsigned int size()
const {
return GetLen(vch[0]); }
84 const unsigned char* begin()
const {
return vch; }
85 const unsigned char* end()
const {
return vch +
size(); }
86 const unsigned char& operator[](
unsigned int pos)
const {
return vch[pos]; }
91 return a.vch[0] == b.vch[0] &&
92 memcmp(a.vch, b.vch, a.
size()) == 0;
100 return a.vch[0] < b.vch[0] ||
101 (a.vch[0] == b.vch[0] && memcmp(a.vch, b.vch, a.
size()) < 0);
109 template <
typename Stream>
110 void Serialize(Stream& s,
int nType,
int nVersion)
const 112 unsigned int len =
size();
113 ::WriteCompactSize(s, len);
114 s.write((
char*)vch, len);
116 template <
typename Stream>
117 void Unserialize(Stream& s,
int nType,
int nVersion)
119 unsigned int len = ::ReadCompactSize(s);
121 s.read((
char*)vch, len);
140 return Hash(vch, vch +
size());
166 bool Verify(
const uint256& hash,
const std::vector<unsigned char>& vchSig)
const;
171 static bool CheckLowS(
const std::vector<unsigned char>& vchSig);
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
Definition: pubkey.h:83
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
Definition: pubkey.h:60
static bool CheckLowS(const std::vector< unsigned char > &vchSig)
Definition: pubkey.cpp:249
friend bool operator==(const CPubKey &a, const CPubKey &b)
Comparator implementation.
Definition: pubkey.h:89
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
Definition: pubkey.cpp:184
CPubKey()
Construct an invalid public key.
Definition: pubkey.h:53
uint256 GetHash() const
Get the 256-bit hash of this public key.
Definition: pubkey.h:138
CPubKey(const std::vector< unsigned char > &vch)
Construct a public key from a byte vector.
Definition: pubkey.h:77
bool IsCompressed() const
Check whether this is a compressed public key.
Definition: pubkey.h:157
Definition: uint256.h:294
CPubKey(const T pbegin, const T pend)
Construct a public key using begin/end iterators to byte data.
Definition: pubkey.h:71
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid()) ...
Definition: pubkey.cpp:204
bool Derive(CPubKey &pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child pubkey.
Definition: pubkey.cpp:226
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Definition: pubkey.cpp:163
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:132
unsigned int GetSerializeSize(int nType, int nVersion) const
Implement serialization, as if this was a byte vector.
Definition: pubkey.h:105
bool Decompress()
Turn this public key into an uncompressed public key.
Definition: pubkey.cpp:212