CExtPubKey should be serializable like CPubKey.
EDIT: This would allow storing extended private and public key to support BIP32/HD wallets. Related to #6265
CExtPubKey should be serializable like CPubKey.
EDIT: This would allow storing extended private and public key to support BIP32/HD wallets. Related to #6265
Why?
This is a valid question. I'm working on a new wallet and i'm trying to split of and create PRs for everything which could be used independent and might reduce the diff-size when merging a bigger wallet change later. [1] https://github.com/jonasschnelli/bitcoin/tree/2015/05/corewallet
Because there is already unused bip32 stuff in bitcoin core, why not complete it with things which would be necessary in case of a full bip32 support.
Oh, I guess this might be useful for storing watch-only HD seeds in the wallet file?
Exactly!.
Too many naked constants (74, 75) without a named constant, IMO
Agreed. Factored out the ext keysize of 74 bytes to a constant.
ACK, with comment
Force push fixed: replace magic number 74 bytes into BIP32_EXTKEY_SIZE in base58.h
Added serializing/deserializing of a bip32 extended private key. Followed @jgarzik advice of checking the serialized output by deserialize again and compare the keys (bytes).
Ping, reviewers
utACK
utACK (retracted for now, see below)
224 | + template <typename Stream> 225 | + void Unserialize(Stream& s, int nType, int nVersion) 226 | + { 227 | + unsigned int len = ::ReadCompactSize(s); 228 | + unsigned char code[BIP32_EXTKEY_SIZE]; 229 | + s.read((char *)&code[0], len);
This looks like a potential buffer overflow: you read len bytes into a fixed buffer. Please check that len == BIP32_EXTKEY_SIZE
Agreed. Added a len check assertion.
224 | + template <typename Stream> 225 | + void Unserialize(Stream& s, int nType, int nVersion) 226 | + { 227 | + unsigned int len = ::ReadCompactSize(s); 228 | + unsigned char code[BIP32_EXTKEY_SIZE]; 229 | + assert(len == BIP32_EXTKEY_SIZE);
IMO it'd be better to throw an exception (serialization framework seems to prefer std::ios_base::failure, see here and here ) which can at least be caught instead of killing the program immediately.
Of course we don't expect to deserialize these from the network, otherwise someone may crash the application, but it may be better to be consistent.
CExtPubKey should be serializable like CPubKey
Fixed @laanwj nit. Rebased & squashed.