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