aboutsummaryrefslogtreecommitdiff
path: root/src/key.h
diff options
context:
space:
mode:
authorJonas Schnelli <jonas.schnelli@include7.ch>2015-06-01 16:35:19 +0200
committerJonas Schnelli <dev@jonasschnelli.ch>2016-04-14 20:56:33 +0200
commit90604f16af63ec066d6561337f476ccd8acec326 (patch)
tree5cca6f0af2f22330bbf7d7a913b3e10cbcafe868 /src/key.h
parente6a4d48a9bff0bdbcca3a13de59b5e6e683a6aac (diff)
add bip32 pubkey serialization
CExtPubKey should be serializable like CPubKey
Diffstat (limited to 'src/key.h')
-rw-r--r--src/key.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/key.h b/src/key.h
index 6c820d49cd..b4f48d59f5 100644
--- a/src/key.h
+++ b/src/key.h
@@ -164,11 +164,28 @@ struct CExtKey {
a.chaincode == b.chaincode && a.key == b.key;
}
- 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(CExtKey& out, unsigned int nChild) const;
CExtPubKey Neuter() const;
void SetMaster(const unsigned char* seed, unsigned int nSeedLen);
+ 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];
+ s.read((char *)&code[0], len);
+ Decode(code);
+ }
};
/** Initialize the elliptic curve support. May not be called twice without calling ECC_Stop first. */