[refactor] manually change remaining instances of master key to seed.

This commit is contained in:
John Newbery 2018-04-04 12:47:55 -04:00
parent 131d4450b9
commit c75c351419
6 changed files with 34 additions and 34 deletions

View file

@ -755,10 +755,10 @@ UniValue dumpwallet(const JSONRPCRequest& request)
CKeyID seed_id = pwallet->GetHDChain().seed_id;
if (!seed_id.IsNull())
{
CKey key;
if (pwallet->GetKey(seed_id, key)) {
CKey seed;
if (pwallet->GetKey(seed_id, seed)) {
CExtKey masterKey;
masterKey.SetSeed(key.begin(), key.size());
masterKey.SetSeed(seed.begin(), seed.size());
file << "# extended private masterkey: " << EncodeExtKey(masterKey) << "\n\n";
}
@ -777,8 +777,8 @@ UniValue dumpwallet(const JSONRPCRequest& request)
file << "hdseed=1";
} else if (mapKeyPool.count(keyid)) {
file << "reserve=1";
} else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "m") {
file << "inactivehdmaster=1";
} else if (pwallet->mapKeyMetadata[keyid].hdKeypath == "s") {
file << "inactivehdseed=1";
} else {
file << "change=1";
}

View file

@ -2925,7 +2925,7 @@ static UniValue getwalletinfo(const JSONRPCRequest& request)
" \"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"
" \"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"
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD master pubkey (only present when HD is enabled)\n"
" \"hdseedid\": \"<hash160>\" (string, optional) the Hash160 of the HD seed (only present when HD is enabled)\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getwalletinfo", "")
@ -3954,7 +3954,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
" \"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"
" \"timestamp\" : timestamp, (number, optional) The creation time of the key if available in seconds since epoch (Jan 1 1970 GMT)\n"
" \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath if the key is HD and available\n"
" \"hdseedid\" : \"<hash160>\" (string, optional) The Hash160 of the HD master pubkey\n"
" \"hdseedid\" : \"<hash160>\" (string, optional) The Hash160 of the HD seed\n"
" \"labels\" (object) Array of labels associated with the address.\n"
" [\n"
" { (json object of label data)\n"

View file

@ -191,17 +191,17 @@ CPubKey CWallet::GenerateNewKey(WalletBatch &batch, bool internal)
void CWallet::DeriveNewChildKey(WalletBatch &batch, CKeyMetadata& metadata, CKey& secret, bool internal)
{
// for now we use a fixed keypath scheme of m/0'/0'/k
CKey key; //master key seed (256bit)
CKey seed; //seed (256bit)
CExtKey masterKey; //hd master key
CExtKey accountKey; //key at m/0'
CExtKey chainChildKey; //key at m/0'/0' (external) or m/0'/1' (internal)
CExtKey childKey; //key at m/0'/0'/<n>'
// try to get the master key
if (!GetKey(hdChain.seed_id, key))
throw std::runtime_error(std::string(__func__) + ": Master key not found");
// try to get the seed
if (!GetKey(hdChain.seed_id, seed))
throw std::runtime_error(std::string(__func__) + ": seed not found");
masterKey.SetSeed(key.begin(), key.size());
masterKey.SetSeed(seed.begin(), seed.size());
// derive m/0'
// use hardened derivation (child keys >= 0x80000000 are hardened after bip32)
@ -689,7 +689,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
Lock();
Unlock(strWalletPassphrase);
// if we are using HD, replace the HD master key (seed) with a new one
// if we are using HD, replace the HD seed with a new one
if (IsHDEnabled()) {
if (!SetHDSeed(GenerateNewSeed())) {
return false;
@ -1462,29 +1462,29 @@ CPubKey CWallet::DeriveNewSeed(const CKey& key)
int64_t nCreationTime = GetTime();
CKeyMetadata metadata(nCreationTime);
// calculate the pubkey
CPubKey pubkey = key.GetPubKey();
assert(key.VerifyPubKey(pubkey));
// calculate the seed
CPubKey seed = key.GetPubKey();
assert(key.VerifyPubKey(seed));
// set the hd keypath to "m" -> Master, refers the masterkeyid to itself
metadata.hdKeypath = "m";
metadata.hd_seed_id = pubkey.GetID();
// set the hd keypath to "s" -> Seed, refers the seed to itself
metadata.hdKeypath = "s";
metadata.hd_seed_id = seed.GetID();
{
LOCK(cs_wallet);
// mem store the metadata
mapKeyMetadata[pubkey.GetID()] = metadata;
mapKeyMetadata[seed.GetID()] = metadata;
// write the key&metadata to the database
if (!AddKeyPubKey(key, pubkey))
if (!AddKeyPubKey(key, seed))
throw std::runtime_error(std::string(__func__) + ": AddKeyPubKey failed");
}
return pubkey;
return seed;
}
bool CWallet::SetHDSeed(const CPubKey& pubkey)
bool CWallet::SetHDSeed(const CPubKey& seed)
{
LOCK(cs_wallet);
// store the keyid (hash160) together with
@ -1492,7 +1492,7 @@ bool CWallet::SetHDSeed(const CPubKey& pubkey)
// as a hdchain object
CHDChain newHdChain;
newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE;
newHdChain.seed_id = pubkey.GetID();
newHdChain.seed_id = seed.GetID();
SetHDChain(newHdChain, false);
return true;
@ -4164,10 +4164,10 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
}
walletInstance->SetMinVersion(FEATURE_LATEST);
// generate a new master key
CPubKey masterPubKey = walletInstance->GenerateNewSeed();
if (!walletInstance->SetHDSeed(masterPubKey))
throw std::runtime_error(std::string(__func__) + ": Storing master key failed");
// generate a new seed
CPubKey seed = walletInstance->GenerateNewSeed();
if (!walletInstance->SetHDSeed(seed))
throw std::runtime_error(std::string(__func__) + ": Storing HD seed failed");
// Top up the keypool
if (!walletInstance->TopUpKeyPool()) {

View file

@ -1139,14 +1139,14 @@ public:
/* Returns true if HD is enabled */
bool IsHDEnabled() const;
/* Generates a new HD master key (will not be activated) */
/* Generates a new HD seed (will not be activated) */
CPubKey GenerateNewSeed();
/* Derives a new HD master key (will not be activated) */
CPubKey DeriveNewSeed(const CKey& key);
/* Set the current HD master key (will reset the chain child index counters)
Sets the master key's version based on the current wallet version (so the
/* Set the current HD seed (will reset the chain child index counters)
Sets the seed's version based on the current wallet version (so the
caller must ensure the current wallet version is correct before calling
this function). */
bool SetHDSeed(const CPubKey& key);

View file

@ -62,7 +62,7 @@ class CHDChain
public:
uint32_t nExternalChainCounter;
uint32_t nInternalChainCounter;
CKeyID seed_id; //!< master key hash160
CKeyID seed_id; //!< seed hash160
static const int VERSION_HD_BASE = 1;
static const int VERSION_HD_CHAIN_SPLIT = 2;
@ -99,7 +99,7 @@ public:
int nVersion;
int64_t nCreateTime; // 0 means unknown
std::string hdKeypath; //optional HD/bip32 keypath
CKeyID hd_seed_id; //id of the HD masterkey used to derive this key
CKeyID hd_seed_id; //id of the HD seed used to derive this key
CKeyMetadata()
{

View file

@ -36,7 +36,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
addr_keypath = comment.split(" addr=")[1]
addr = addr_keypath.split(" ")[0]
keypath = None
if keytype == "inactivehdmaster=1":
if keytype == "inactivehdseed=1":
# ensure the old master is still available
assert(hd_master_addr_old == addr)
elif keytype == "hdseed=1":