Skip to content

Commit 5b95dd2

Browse files
committed
[Wallet] extend CKeyMetadata with HD keypath
1 parent 67caef6 commit 5b95dd2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ CPubKey CWallet::GenerateNewKey()
126126
// childIndex | BIP32_HARDENED_KEY_LIMIT = derive childIndex in hardened child-index-range
127127
// example: 1 | BIP32_HARDENED_KEY_LIMIT == 0x80000001 == 2147483649
128128
externalChainChildKey.Derive(childKey, hdChain.nExternalChainCounter | BIP32_HARDENED_KEY_LIMIT);
129+
metadata.hdKeypath = "m/0'/0'/"+std::to_string(hdChain.nExternalChainCounter)+"'";
130+
metadata.hdMasterKeyID = hdChain.masterKeyID;
129131
// increment childkey index
130132
hdChain.nExternalChainCounter++;
131133
} while(HaveKey(childKey.key.GetPubKey().GetID()));

src/wallet/walletdb.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ class CHDChain
7373
class CKeyMetadata
7474
{
7575
public:
76-
static const int CURRENT_VERSION=1;
76+
static const int VERSION_BASIC=1;
77+
static const int VERSION_WITH_HDDATA=10;
78+
static const int CURRENT_VERSION=VERSION_WITH_HDDATA;
7779
int nVersion;
7880
int64_t nCreateTime; // 0 means unknown
81+
std::string hdKeypath; //optional HD/bip32 keypath
82+
CKeyID hdMasterKeyID; //id of the hd masterkey used to derive this key
7983

8084
CKeyMetadata()
8185
{
@@ -85,6 +89,7 @@ class CKeyMetadata
8589
{
8690
nVersion = CKeyMetadata::CURRENT_VERSION;
8791
nCreateTime = nCreateTime_;
92+
hdKeypath.clear();
8893
}
8994

9095
ADD_SERIALIZE_METHODS;
@@ -94,12 +99,18 @@ class CKeyMetadata
9499
READWRITE(this->nVersion);
95100
nVersion = this->nVersion;
96101
READWRITE(nCreateTime);
102+
if (this->nVersion >= VERSION_WITH_HDDATA)
103+
{
104+
READWRITE(hdKeypath);
105+
READWRITE(hdMasterKeyID);
106+
}
97107
}
98108

99109
void SetNull()
100110
{
101111
nVersion = CKeyMetadata::CURRENT_VERSION;
102112
nCreateTime = 0;
113+
hdKeypath.clear();
103114
}
104115
};
105116

0 commit comments

Comments
 (0)