Changeset View
Changeset View
Standalone View
Standalone View
src/pubkey.h
Show First 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | friend bool operator==(const CExtPubKey &a, const CExtPubKey &b) { | ||||
a.nChild == b.nChild && a.chaincode == b.chaincode && | a.nChild == b.nChild && a.chaincode == b.chaincode && | ||||
a.pubkey == b.pubkey; | a.pubkey == b.pubkey; | ||||
} | } | ||||
void Encode(uint8_t code[BIP32_EXTKEY_SIZE]) const; | void Encode(uint8_t code[BIP32_EXTKEY_SIZE]) const; | ||||
void Decode(const uint8_t code[BIP32_EXTKEY_SIZE]); | void Decode(const uint8_t code[BIP32_EXTKEY_SIZE]); | ||||
bool Derive(CExtPubKey &out, unsigned int nChild) const; | bool Derive(CExtPubKey &out, unsigned int nChild) const; | ||||
void Serialize(CSizeComputer &s) const { | |||||
// Optimized implementation for ::GetSerializeSize that avoids copying. | |||||
// add one byte for the size (compact int) | |||||
s.seek(BIP32_EXTKEY_SIZE + 1); | |||||
} | |||||
template <typename Stream> void Serialize(Stream &s) const { | |||||
unsigned int len = BIP32_EXTKEY_SIZE; | |||||
::WriteCompactSize(s, len); | |||||
uint8_t code[BIP32_EXTKEY_SIZE]; | |||||
Encode(code); | |||||
s.write((const char *)&code[0], len); | |||||
} | |||||
template <typename Stream> void Unserialize(Stream &s) { | |||||
unsigned int len = ::ReadCompactSize(s); | |||||
if (len != BIP32_EXTKEY_SIZE) { | |||||
throw std::runtime_error("Invalid extended key size\n"); | |||||
} | |||||
uint8_t code[BIP32_EXTKEY_SIZE]; | |||||
s.read((char *)&code[0], len); | |||||
Decode(code); | |||||
} | |||||
CExtPubKey() = default; | CExtPubKey() = default; | ||||
}; | }; | ||||
/** | /** | ||||
* Users of this module must hold an ECCVerifyHandle. The constructor and | * Users of this module must hold an ECCVerifyHandle. The constructor and | ||||
* destructor of these are not allowed to run in parallel, though. | * destructor of these are not allowed to run in parallel, though. | ||||
*/ | */ | ||||
class ECCVerifyHandle { | class ECCVerifyHandle { | ||||
static int refcount; | static int refcount; | ||||
public: | public: | ||||
ECCVerifyHandle(); | ECCVerifyHandle(); | ||||
~ECCVerifyHandle(); | ~ECCVerifyHandle(); | ||||
}; | }; | ||||
#endif // BITCOIN_PUBKEY_H | #endif // BITCOIN_PUBKEY_H |