Skip to content

Commit c75c351

Browse files
committed
[refactor] manually change remaining instances of master key to seed.
1 parent 131d445 commit c75c351

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

src/wallet/rpcdump.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,10 @@ UniValue dumpwallet(const JSONRPCRequest& request)
755755
CKeyID seed_id = pwallet->GetHDChain().seed_id;
756756
if (!seed_id.IsNull())
757757
{
758-
CKey key;
759-
if (pwallet->GetKey(seed_id, key)) {
758+
CKey seed;
759+
if (pwallet->GetKey(seed_id, seed)) {
760760
CExtKey masterKey;
761-
masterKey.SetSeed(key.begin(), key.size());
761+
masterKey.SetSeed(seed.begin(), seed.size());
762762

763763
file << "# extended private masterkey: " << EncodeExtKey(masterKey) << "\n\n";
764764
}
@@ -777,8 +777,8 @@ UniValue dumpwallet(const JSONRPCRequest& request)
777777
file << "hdseed=1";
778778
} else if (mapKeyPool.count(keyid)) {
779779
file << "reserve=1";
780-
} else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "m") {
781-
file << "inactivehdmaster=1";
780+
} else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "s") {
781+
file << "inactivehdseed=1";
782782
} else {
783783
file << "change=1";
784784
}

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
29252925
" \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys are pre-generated for internal use (used for change outputs, only appears if the wallet is using this feature, otherwise external keys are used)\n"
29262926
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
29272927
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
2928-
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD master pubkey (only present when HD is enabled)\n"
2928+
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
29292929
"}\n"
29302930
"\nExamples:\n"
29312931
+ HelpExampleCli("getwalletinfo", "")
@@ -3954,7 +3954,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
39543954
" \"account\" : \"account\" (string) DEPRECATED. This field will be removed in V0.18. To see this deprecated field, start bitcoind with -deprecatedrpc=accounts. The account associated with the address, \"\" is the default account\n"
39553955
" \"timestamp\" : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
39563956
" \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath if the key is HD and available\n"
3957-
" \"hdseedid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n"
3957+
" \"hdseedid\" : \"<hash160>\" (string, optional) The Hash160 of the HD seed\n"
39583958
" \"labels\" (object) Array of labels associated with the address.\n"
39593959
" [\n"
39603960
" { (json object of label data)\n"

src/wallet/wallet.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ CPubKey CWallet::GenerateNewKey(WalletBatch &batch, bool internal)
191191
void CWallet::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, bool internal)
192192
{
193193
// for now we use a fixed keypath scheme of m/0'/0'/k
194-
CKey key; //master key seed (256bit)
194+
CKey seed; //seed (256bit)
195195
CExtKey masterKey; //hd master key
196196
CExtKey accountKey; //key at m/0'
197197
CExtKey chainChildKey; //key at m/0'/0' (external) or m/0'/1' (internal)
198198
CExtKey childKey; //key at m/0'/0'/<n>'
199199

200-
// try to get the master key
201-
if (!GetKey(hdChain.seed_id, key))
202-
throw std::runtime_error(std::string(__func__) + ": Master key not found");
200+
// try to get the seed
201+
if (!GetKey(hdChain.seed_id, seed))
202+
throw std::runtime_error(std::string(__func__) + ": seed not found");
203203

204-
masterKey.SetSeed(key.begin(), key.size());
204+
masterKey.SetSeed(seed.begin(), seed.size());
205205

206206
// derive m/0'
207207
// use hardened derivation (child keys >= 0x80000000 are hardened after bip32)
@@ -689,7 +689,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
689689
Lock();
690690
Unlock(strWalletPassphrase);
691691

692-
// if we are using HD, replace the HD master key (seed) with a new one
692+
// if we are using HD, replace the HD seed with a new one
693693
if (IsHDEnabled()) {
694694
if (!SetHDSeed(GenerateNewSeed())) {
695695
return false;
@@ -1462,37 +1462,37 @@ CPubKey CWallet::DeriveNewSeed(const CKey& key)
14621462
int64_t nCreationTime = GetTime();
14631463
CKeyMetadata metadata(nCreationTime);
14641464

1465-
// calculate the pubkey
1466-
CPubKey pubkey = key.GetPubKey();
1467-
assert(key.VerifyPubKey(pubkey));
1465+
// calculate the seed
1466+
CPubKey seed = key.GetPubKey();
1467+
assert(key.VerifyPubKey(seed));
14681468

1469-
// set the hd keypath to "m" -> Master, refers the masterkeyid to itself
1470-
metadata.hdKeypath = "m";
1471-
metadata.hd_seed_id = pubkey.GetID();
1469+
// set the hd keypath to "s" -> Seed, refers the seed to itself
1470+
metadata.hdKeypath = "s";
1471+
metadata.hd_seed_id = seed.GetID();
14721472

14731473
{
14741474
LOCK(cs_wallet);
14751475

14761476
// mem store the metadata
1477-
mapKeyMetadata[pubkey.GetID()] = metadata;
1477+
mapKeyMetadata[seed.GetID()] = metadata;
14781478

14791479
// write the key&metadata to the database
1480-
if (!AddKeyPubKey(key, pubkey))
1480+
if (!AddKeyPubKey(key, seed))
14811481
throw std::runtime_error(std::string(__func__) + ": AddKeyPubKey failed");
14821482
}
14831483

1484-
return pubkey;
1484+
return seed;
14851485
}
14861486

1487-
bool CWallet::SetHDSeed(const CPubKey& pubkey)
1487+
bool CWallet::SetHDSeed(const CPubKey& seed)
14881488
{
14891489
LOCK(cs_wallet);
14901490
// store the keyid (hash160) together with
14911491
// the child index counter in the database
14921492
// as a hdchain object
14931493
CHDChain newHdChain;
14941494
newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
1495-
newHdChain.seed_id = pubkey.GetID();
1495+
newHdChain.seed_id = seed.GetID();
14961496
SetHDChain(newHdChain, false);
14971497

14981498
return true;
@@ -4164,10 +4164,10 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
41644164
}
41654165
walletInstance->SetMinVersion(FEATURE_LATEST);
41664166

4167-
// generate a new master key
4168-
CPubKey masterPubKey = walletInstance->GenerateNewSeed();
4169-
if (!walletInstance->SetHDSeed(masterPubKey))
4170-
throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
4167+
// generate a new seed
4168+
CPubKey seed = walletInstance->GenerateNewSeed();
4169+
if (!walletInstance->SetHDSeed(seed))
4170+
throw std::runtime_error(std::string(__func__) + ": Storing HD seed failed");
41714171

41724172
// Top up the keypool
41734173
if (!walletInstance->TopUpKeyPool()) {

src/wallet/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,14 +1139,14 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
11391139
/* Returns true if HD is enabled */
11401140
bool IsHDEnabled() const;
11411141

1142-
/* Generates a new HD master key (will not be activated) */
1142+
/* Generates a new HD seed (will not be activated) */
11431143
CPubKey GenerateNewSeed();
11441144

11451145
/* Derives a new HD master key (will not be activated) */
11461146
CPubKey DeriveNewSeed(const CKey& key);
11471147

1148-
/* Set the current HD master key (will reset the chain child index counters)
1149-
Sets the master key's version based on the current wallet version (so the
1148+
/* Set the current HD seed (will reset the chain child index counters)
1149+
Sets the seed's version based on the current wallet version (so the
11501150
caller must ensure the current wallet version is correct before calling
11511151
this function). */
11521152
bool SetHDSeed(const CPubKey& key);

src/wallet/walletdb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class CHDChain
6262
public:
6363
uint32_t nExternalChainCounter;
6464
uint32_t nInternalChainCounter;
65-
CKeyID seed_id; //!< master key hash160
65+
CKeyID seed_id; //!< seed hash160
6666

6767
static const int VERSION_HD_BASE = 1;
6868
static const int VERSION_HD_CHAIN_SPLIT = 2;
@@ -99,7 +99,7 @@ class CKeyMetadata
9999
int nVersion;
100100
int64_t nCreateTime; // 0 means unknown
101101
std::string hdKeypath; //optional HD/bip32 keypath
102-
CKeyID hd_seed_id; //id of the HD masterkey used to derive this key
102+
CKeyID hd_seed_id; //id of the HD seed used to derive this key
103103

104104
CKeyMetadata()
105105
{

test/functional/wallet_dump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
3636
addr_keypath = comment.split(" addr=")[1]
3737
addr = addr_keypath.split(" ")[0]
3838
keypath = None
39-
if keytype == "inactivehdmaster=1":
39+
if keytype == "inactivehdseed=1":
4040
# ensure the old master is still available
4141
assert(hd_master_addr_old == addr)
4242
elif keytype == "hdseed=1":

0 commit comments

Comments
 (0)