add bip32 pubkey serialization
CExtPubKey should be serializable like CPubKey
This commit is contained in:
committed by
Jack Grigg
parent
d2fb34fb7c
commit
6cbe2c482c
30
src/pubkey.h
30
src/pubkey.h
@@ -14,6 +14,8 @@
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
const unsigned int BIP32_EXTKEY_SIZE = 74;
|
||||
|
||||
/** A reference to a CKey: the Hash160 of its serialized public key */
|
||||
class CKeyID : public uint160
|
||||
{
|
||||
@@ -212,9 +214,33 @@ struct CExtPubKey {
|
||||
a.chaincode == b.chaincode && a.pubkey == b.pubkey;
|
||||
}
|
||||
|
||||
void Encode(unsigned char code[74]) const;
|
||||
void Decode(const unsigned char code[74]);
|
||||
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const;
|
||||
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
|
||||
bool Derive(CExtPubKey& out, unsigned int nChild) const;
|
||||
|
||||
unsigned int GetSerializeSize(int nType, int nVersion) const
|
||||
{
|
||||
return BIP32_EXTKEY_SIZE+1; //add one byte for the size (compact int)
|
||||
}
|
||||
template <typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const
|
||||
{
|
||||
unsigned int len = BIP32_EXTKEY_SIZE;
|
||||
::WriteCompactSize(s, len);
|
||||
unsigned char code[BIP32_EXTKEY_SIZE];
|
||||
Encode(code);
|
||||
s.write((const char *)&code[0], len);
|
||||
}
|
||||
template <typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion)
|
||||
{
|
||||
unsigned int len = ::ReadCompactSize(s);
|
||||
unsigned char code[BIP32_EXTKEY_SIZE];
|
||||
if (len != BIP32_EXTKEY_SIZE)
|
||||
throw std::runtime_error("Invalid extended key size\n");
|
||||
s.read((char *)&code[0], len);
|
||||
Decode(code);
|
||||
}
|
||||
};
|
||||
|
||||
/** Users of this module must hold an ECCVerifyHandle. The constructor and
|
||||
|
||||
Reference in New Issue
Block a user