[Wallet] extend CKeyMetadata with HD keypath
Zcash: modified for zip32
This commit is contained in:
parent
9bcf90e2de
commit
b6d1af89f2
|
@ -117,18 +117,21 @@ SaplingPaymentAddress CWallet::GenerateNewSaplingZKey()
|
|||
throw std::runtime_error("CWallet::GenerateNewSaplingZKey(): HD seed not found");
|
||||
|
||||
auto m = libzcash::SaplingExtendedSpendingKey::Master(seed);
|
||||
uint32_t bip44CoinType = Params().BIP44CoinType();
|
||||
|
||||
// We use a fixed keypath scheme of m/32'/coin_type'/account'
|
||||
// Derive m/32'
|
||||
auto m_32h = m.Derive(32 | ZIP32_HARDENED_KEY_LIMIT);
|
||||
// Derive m/32'/coin_type'
|
||||
auto m_32h_cth = m_32h.Derive(Params().BIP44CoinType() | ZIP32_HARDENED_KEY_LIMIT);
|
||||
auto m_32h_cth = m_32h.Derive(bip44CoinType | ZIP32_HARDENED_KEY_LIMIT);
|
||||
|
||||
// Derive account key at next index, skip keys already known to the wallet
|
||||
libzcash::SaplingExtendedSpendingKey xsk;
|
||||
do
|
||||
{
|
||||
xsk = m_32h_cth.Derive(hdChain.saplingAccountCounter | ZIP32_HARDENED_KEY_LIMIT);
|
||||
metadata.hdKeypath = "m/32'/" + std::to_string(bip44CoinType) + "'/" + std::to_string(hdChain.saplingAccountCounter) + "'";
|
||||
metadata.seedFp = hdChain.seedFp;
|
||||
// Increment childkey index
|
||||
hdChain.saplingAccountCounter++;
|
||||
} while (HaveSaplingSpendingKey(xsk.expsk.full_viewing_key()));
|
||||
|
|
|
@ -77,9 +77,13 @@ public:
|
|||
class CKeyMetadata
|
||||
{
|
||||
public:
|
||||
static const int CURRENT_VERSION=1;
|
||||
static const int VERSION_BASIC=1;
|
||||
static const int VERSION_WITH_HDDATA=10;
|
||||
static const int CURRENT_VERSION=VERSION_WITH_HDDATA;
|
||||
int nVersion;
|
||||
int64_t nCreateTime; // 0 means unknown
|
||||
std::string hdKeypath; //optional HD/zip32 keypath
|
||||
uint256 seedFp;
|
||||
|
||||
CKeyMetadata()
|
||||
{
|
||||
|
@ -89,6 +93,7 @@ public:
|
|||
{
|
||||
nVersion = CKeyMetadata::CURRENT_VERSION;
|
||||
nCreateTime = nCreateTime_;
|
||||
hdKeypath.clear();
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
@ -97,12 +102,18 @@ public:
|
|||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(this->nVersion);
|
||||
READWRITE(nCreateTime);
|
||||
if (this->nVersion >= VERSION_WITH_HDDATA)
|
||||
{
|
||||
READWRITE(hdKeypath);
|
||||
READWRITE(seedFp);
|
||||
}
|
||||
}
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
nVersion = CKeyMetadata::CURRENT_VERSION;
|
||||
nCreateTime = 0;
|
||||
hdKeypath.clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue