59 "COMPRESSED_PUBLIC_KEY_SIZE is larger than PUBLIC_KEY_SIZE");
69 unsigned int static GetLen(
unsigned char chHeader)
71 if (chHeader == 2 || chHeader == 3)
73 if (chHeader == 4 || chHeader == 6 || chHeader == 7)
98 void Set(
const T pbegin,
const T pend)
100 int len = pend == pbegin ? 0 :
GetLen(pbegin[0]);
101 if (len && len == (pend - pbegin))
102 memcpy(
vch, (
unsigned char*)&pbegin[0], len);
108 template <
typename T>
115 explicit CPubKey(
const std::vector<unsigned char>& _vch)
117 Set(_vch.begin(), _vch.end());
122 const unsigned char*
data()
const {
return vch; }
125 const unsigned char&
operator[](
unsigned int pos)
const {
return vch[pos]; }
130 return a.
vch[0] == b.
vch[0] &&
139 return a.
vch[0] < b.
vch[0] ||
144 template <
typename Stream>
147 unsigned int len =
size();
149 s.write((
char*)
vch, len);
151 template <
typename Stream>
156 s.read((
char*)
vch, len);
201 bool Verify(
const uint256& hash,
const std::vector<unsigned char>& vchSig)
const;
206 static bool CheckLowS(
const std::vector<unsigned char>& vchSig);
217 std::vector<unsigned char>
Raw()
const
219 return std::vector<unsigned char>(
vch,
vch +
size());
249 template <
typename Stream>
256 s.write((
const char *)&code[0], len);
258 template <
typename Stream>
264 throw std::runtime_error(
"Invalid extended key size\n");
265 s.read((
char *)&code[0], len);
A reference to a CKey: the Hash160 of its serialized public key, special case for exchange key.
CExchangeKeyID(const uint160 &in)
A reference to a CKey: the Hash160 of its serialized public key.
CKeyID(const uint160 &in)
An encapsulated public key.
std::vector< unsigned char > Raw() const
bool RecoverCompact(const uint256 &hash, const std::vector< unsigned char > &vchSig)
Recover a public key from a compact signature.
const unsigned char * end() const
bool IsCompressed() const
Check whether this is a compressed public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
CPubKey()
Construct an invalid public key.
static bool CheckLowS(const std::vector< unsigned char > &vchSig)
Check whether a signature is normalized (lower-S).
bool Decompress()
Turn this public key into an uncompressed public key.
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
unsigned int size() const
Simple read-only vector-like interface to the pubkey data.
static bool ValidSize(const std::vector< unsigned char > &vch)
unsigned static int GetLen(unsigned char chHeader)
Compute the length of a pubkey with a given first byte.
const unsigned char * begin() const
friend bool operator==(const CPubKey &a, const CPubKey &b)
Comparator implementation.
void Serialize(Stream &s) const
Implement serialization, as if this was a byte vector.
CPubKey(const T pbegin, const T pend)
Construct a public key using begin/end iterators to byte data.
void Invalidate()
Set this key data to be invalid.
unsigned char vch[PUBLIC_KEY_SIZE]
see www.keylength.com script supports up to 75 for single byte push
void Unserialize(Stream &s)
uint256 GetHash() const
Get the 256-bit hash of this public key.
static constexpr unsigned int PUBLIC_KEY_SIZE
secp256k1:
const unsigned char & operator[](unsigned int pos) const
const unsigned char * data() const
bool Derive(CPubKey &pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode &cc) const
Derive BIP32 child pubkey.
CPubKey(const std::vector< unsigned char > &_vch)
Construct a public key from a byte vector.
static constexpr unsigned int SIGNATURE_SIZE
static constexpr unsigned int COMPRESSED_PUBLIC_KEY_SIZE
static constexpr unsigned int COMPACT_SIGNATURE_SIZE
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
friend bool operator!=(const CPubKey &a, const CPubKey &b)
friend bool operator<(const CPubKey &a, const CPubKey &b)
void seek(size_t _nSize)
Pretend _nSize bytes are written, without specifying them.
Users of this module must hold an ECCVerifyHandle.
void * memcpy(void *a, const void *b, size_t c)
uint160 Hash160(const T1 pbegin, const T1 pend)
Compute the 160-bit hash an object.
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
#define T(expected, seed, data)
const unsigned int BIP32_EXTKEY_SIZE
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
friend bool operator==(const CExtPubKey &a, const CExtPubKey &b)
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const
bool Derive(CExtPubKey &out, unsigned int nChild) const
unsigned char vchFingerprint[4]
void Serialize(CSizeComputer &s) const
void Serialize(Stream &s) const
void Unserialize(Stream &s)
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE])