6 #ifndef BITCOIN_PUBKEY_H 7 #define BITCOIN_PUBKEY_H 45 unsigned char vch[65];
48 unsigned int static GetLen(
unsigned char chHeader)
50 if (chHeader == 2 || chHeader == 3)
52 if (chHeader == 4 || chHeader == 6 || chHeader == 7)
72 void Set(
const T pbegin,
const T pend)
74 int len = pend == pbegin ? 0 :
GetLen(pbegin[0]);
75 if (len && len == (pend - pbegin))
76 memcpy(
vch, (
unsigned char*)&pbegin[0], len);
96 const unsigned char*
begin()
const {
return vch; }
97 const unsigned char*
end()
const {
return vch +
size(); }
98 const unsigned char&
operator[](
unsigned int pos)
const {
return vch[pos]; }
103 return a.
vch[0] == b.
vch[0] &&
112 return a.
vch[0] < b.
vch[0] ||
121 template <
typename Stream>
122 void Serialize(Stream& s,
int nType,
int nVersion)
const 124 unsigned int len =
size();
126 s.write((
char*)
vch, len);
128 template <
typename Stream>
133 s.read((
char*)
vch, len);
178 bool Verify(
const uint256& hash,
const std::vector<unsigned char>& vchSig)
const;
183 static bool CheckLowS(
const std::vector<unsigned char>& vchSig);
208 void Encode(
unsigned char code[74])
const;
209 void Decode(
const unsigned char code[74]);
216 template <
typename Stream>
217 void Serialize(Stream& s,
int nType,
int nVersion)
const 219 unsigned int len = 74;
221 unsigned char code[74];
223 s.write((
const char *)&code[0], len);
225 template <
typename Stream>
229 unsigned char code[74];
231 throw std::runtime_error(
"Invalid extended key size\n");
232 s.read((
char *)&code[0], len);
248 #endif // BITCOIN_PUBKEY_H void Decode(const unsigned char code[74])
unsigned int GetSerializeSize(int nType, int nVersion) const
bool Derive(CPubKey &pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child pubkey.
unsigned int GetSerializeSize(int nType, int nVersion) const
Implement serialization, as if this was a byte vector.
const unsigned char & operator[](unsigned int pos) const
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
void Serialize(Stream &s, int nType, int nVersion) const
uint64_t ReadCompactSize(Stream &is)
friend bool operator!=(const CPubKey &a, const CPubKey &b)
uint256 GetHash() const
Get the 256-bit hash of this public key.
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid()) ...
uint160 Hash160(const T1 pbegin, const T1 pend)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
void Invalidate()
Set this key data to be invalid.
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
bool Decompress()
Turn this public key into an uncompressed public key.
unsigned static int GetLen(unsigned char chHeader)
Compute the length of a pubkey with a given first byte.
const unsigned char * begin() const
void Unserialize(Stream &s, int nType, int nVersion)
void Encode(unsigned char code[74]) const
bool Derive(CExtPubKey &out, unsigned int nChild) const
unsigned char vchFingerprint[4]
uint256 Hash(const T1 pbegin, const T1 pend)
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
const unsigned char * end() const
friend bool operator<(const CPubKey &a, const CPubKey &b)
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
CPubKey(const T pbegin, const T pend)
Construct a public key using begin/end iterators to byte data.
bool IsCompressed() const
Check whether this is a compressed public key.
CKeyID(const uint160 &in)
void * memcpy(void *a, const void *b, size_t c)
void Serialize(Stream &s, int nType, int nVersion) const
CPubKey(const std::vector< unsigned char > &vch)
Construct a public key from a byte vector.
friend bool operator==(const CPubKey &a, const CPubKey &b)
Comparator implementation.
CPubKey()
Construct an invalid public key.
void WriteCompactSize(Stream &os, uint64_t nSize)
static bool CheckLowS(const std::vector< unsigned char > &vchSig)
friend bool operator==(const CExtPubKey &a, const CExtPubKey &b)
void Unserialize(Stream &s, int nType, int nVersion)