 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
6 #ifndef BITCOIN_PUBKEY_H
7 #define BITCOIN_PUBKEY_H
44 unsigned char vch[65];
47 unsigned int static GetLen(
unsigned char chHeader)
49 if (chHeader == 2 || chHeader == 3)
51 if (chHeader == 4 || chHeader == 6 || chHeader == 7)
71 void Set(
const T pbegin,
const T pend)
73 int len = pend == pbegin ? 0 :
GetLen(pbegin[0]);
74 if (len && len == (pend - pbegin))
75 memcpy(
vch, (
unsigned char*)&pbegin[0], len);
95 const unsigned char*
begin()
const {
return vch; }
96 const unsigned char*
end()
const {
return vch +
size(); }
97 const unsigned char&
operator[](
unsigned int pos)
const {
return vch[pos]; }
102 return a.
vch[0] ==
b.vch[0] &&
103 memcmp(a.
vch,
b.vch, a.
size()) == 0;
111 return a.
vch[0] <
b.vch[0] ||
112 (a.
vch[0] ==
b.vch[0] && memcmp(a.
vch,
b.vch, a.
size()) < 0);
120 template <
typename Stream>
121 void Serialize(Stream& s,
int nType,
int nVersion)
const
123 unsigned int len =
size();
125 s.write((
char*)
vch, len);
127 template <
typename Stream>
132 s.read((
char*)
vch, len);
177 bool Verify(
const uint256& hash,
const std::vector<unsigned char>& vchSig)
const;
186 bool Derive(
CPubKey& pubkeyChild,
unsigned char ccChild[32],
unsigned int nChild,
const unsigned char cc[32])
const;
188 std::vector<unsigned char>
Raw()
const
190 return std::vector<unsigned char>(
vch,
vch +
size());
195 unsigned int sz =
size();
196 char psz[sz * 2 + 1];
197 for (
unsigned int i = 0; i < sz; i++)
198 sprintf(psz + i * 2,
"%02x",
vch[sz - i - 1]);
199 return std::string(psz, psz + sz * 2);
218 void Encode(
unsigned char code[74])
const;
219 void Decode(
const unsigned char code[74]);
222 template <
typename Stream>
223 void Serialize(Stream& s,
int nType,
int nVersion)
const
229 s.write((
const char *)&code[0], len);
231 template <
typename Stream>
237 throw std::runtime_error(
"Invalid extended key size\n");
238 s.read((
char *)&code[0], len);
243 #endif // BITCOIN_PUBKEY_H
const unsigned int BIP32_EXTKEY_SIZE
secp256k1: const unsigned int PRIVATE_KEY_SIZE = 279; const unsigned int PUBLIC_KEY_SIZE = 65; const ...
uint64_t ReadCompactSize(Stream &is)
void Unserialize(Stream &s, int nType, int nVersion)
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.
uint160 Hash160(const T1 pbegin, const T1 pend)
Compute the 160-bit hash an object.
void * memcpy(void *a, const void *b, size_t c)
bool Decompress()
Turn this public key into an uncompressed public key.
void WriteCompactSize(Stream &os, uint64_t nSize)
void Serialize(Stream &s, int nType, int nVersion) const
A reference to a CKey: the Hash160 of its serialized public key.
bool Derive(CExtPubKey &out, unsigned int nChild) const
CPubKey(const std::vector< unsigned char > &vch)
Construct a public key from a byte vector.
std::string GetHex() const
const unsigned char * begin() const
friend bool operator==(const CExtPubKey &a, const CExtPubKey &b)
unsigned static int GetLen(unsigned char chHeader)
Compute the length of a pubkey with a given first byte.
unsigned char vchFingerprint[4]
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
const unsigned char * end() const
unsigned char vchChainCode[32]
uint256 GetHash() const
Get the 256-bit hash of this public key.
void Serialize(Stream &s, int nType, int nVersion) const
CPubKey()
Construct an invalid public key.
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
256-bit unsigned big integer.
std::vector< unsigned char > Raw() const
unsigned int GetSerializeSize(int nType, int nVersion) const
Implement serialization, as if this was a byte vector.
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
bool Derive(CPubKey &pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const
Derive BIP32 child pubkey.
void Decode(const unsigned char code[74])
bool IsCompressed() const
Check whether this is a compressed public key.
friend bool operator==(const CPubKey &a, const CPubKey &b)
Comparator implementation.
160-bit unsigned big integer.
An encapsulated public key.
friend bool operator<(const CPubKey &a, const CPubKey &b)
void Unserialize(Stream &s, int nType, int nVersion)
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
CPubKey(const T pbegin, const T pend)
Construct a public key using begin/end iterators to byte data.
CKeyID(const uint160 &in)
std::string Hash(std::string input)
Compute the 256-bit hash of a std::string.
unsigned char vch[65]
Just store the serialized data.
const unsigned char & operator[](unsigned int pos) const
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
friend bool operator!=(const CPubKey &a, const CPubKey &b)
void Encode(unsigned char code[74]) const