mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
[Wallet] extend CKeyMetadata with HD keypath
This commit is contained in:
parent
67caef6730
commit
5b95dd2c25
@ -126,6 +126,8 @@ CPubKey CWallet::GenerateNewKey()
|
|||||||
// childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened child-index-range
|
// childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened child-index-range
|
||||||
// example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649
|
// example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649
|
||||||
externalChainChildKey.Derive(childKey, hdChain.nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
|
externalChainChildKey.Derive(childKey, hdChain.nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
|
||||||
|
metadata.hdKeypath = "m/0'/0'/"+std::to_string(hdChain.nExternalChainCounter)+"'";
|
||||||
|
metadata.hdMasterKeyID = hdChain.masterKeyID;
|
||||||
// increment childkey index
|
// increment childkey index
|
||||||
hdChain.nExternalChainCounter++;
|
hdChain.nExternalChainCounter++;
|
||||||
} while(HaveKey(childKey.key.GetPubKey().GetID()));
|
} while(HaveKey(childKey.key.GetPubKey().GetID()));
|
||||||
|
@ -73,9 +73,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/bip32 keypath
|
||||||
|
CKeyID hdMasterKeyID; //id of the hd masterkey used to derive this key
|
||||||
|
|
||||||
CKeyMetadata()
|
CKeyMetadata()
|
||||||
{
|
{
|
||||||
@ -85,6 +89,7 @@ public:
|
|||||||
{
|
{
|
||||||
nVersion = CKeyMetadata::CURRENT_VERSION;
|
nVersion = CKeyMetadata::CURRENT_VERSION;
|
||||||
nCreateTime = nCreateTime_;
|
nCreateTime = nCreateTime_;
|
||||||
|
hdKeypath.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
@ -94,12 +99,18 @@ public:
|
|||||||
READWRITE(this->nVersion);
|
READWRITE(this->nVersion);
|
||||||
nVersion = this->nVersion;
|
nVersion = this->nVersion;
|
||||||
READWRITE(nCreateTime);
|
READWRITE(nCreateTime);
|
||||||
|
if (this->nVersion >= VERSION_WITH_HDDATA)
|
||||||
|
{
|
||||||
|
READWRITE(hdKeypath);
|
||||||
|
READWRITE(hdMasterKeyID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNull()
|
void SetNull()
|
||||||
{
|
{
|
||||||
nVersion = CKeyMetadata::CURRENT_VERSION;
|
nVersion = CKeyMetadata::CURRENT_VERSION;
|
||||||
nCreateTime = 0;
|
nCreateTime = 0;
|
||||||
|
hdKeypath.clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user