diff --git a/src/key.h b/src/key.h --- a/src/key.h +++ b/src/key.h @@ -170,7 +170,7 @@ void Decode(const uint8_t code[BIP32_EXTKEY_SIZE]); bool Derive(CExtKey &out, unsigned int nChild) const; CExtPubKey Neuter() const; - void SetMaster(const uint8_t *seed, unsigned int nSeedLen); + void SetSeed(const uint8_t *seed, unsigned int nSeedLen); template void Serialize(Stream &s) const { unsigned int len = BIP32_EXTKEY_SIZE; ::WriteCompactSize(s, len); diff --git a/src/key.cpp b/src/key.cpp --- a/src/key.cpp +++ b/src/key.cpp @@ -339,7 +339,7 @@ return key.Derive(out.key, out.chaincode, _nChild, chaincode); } -void CExtKey::SetMaster(const uint8_t *seed, unsigned int nSeedLen) { +void CExtKey::SetSeed(const uint8_t *seed, unsigned int nSeedLen) { static const uint8_t hashkey[] = {'B', 'i', 't', 'c', 'o', 'i', 'n', ' ', 's', 'e', 'e', 'd'}; std::vector> vout(64); diff --git a/src/test/bip32_tests.cpp b/src/test/bip32_tests.cpp --- a/src/test/bip32_tests.cpp +++ b/src/test/bip32_tests.cpp @@ -98,7 +98,7 @@ std::vector seed = ParseHex(test.strHexMaster); CExtKey key; CExtPubKey pubkey; - key.SetMaster(seed.data(), seed.size()); + key.SetSeed(seed.data(), seed.size()); pubkey = key.Neuter(); for (const TestDerivation &derive : test.vDerive) { uint8_t data[74]; diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -892,12 +892,12 @@ file << "\n"; // add the base58check encoded extended master if the wallet uses HD - CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; - if (!masterKeyID.IsNull()) { + CKeyID seed_id = pwallet->GetHDChain().seed_id; + if (!seed_id.IsNull()) { CKey key; - if (pwallet->GetKey(masterKeyID, key)) { + if (pwallet->GetKey(seed_id, key)) { CExtKey masterKey; - masterKey.SetMaster(key.begin(), key.size()); + masterKey.SetSeed(key.begin(), key.size()); file << "# extended private masterkey: " << EncodeExtKey(masterKey) << "\n\n"; @@ -916,7 +916,7 @@ if (GetWalletAddressesForKey(config, pwallet, keyid, strAddr, strLabel)) { file << strprintf("label=%s", strLabel); - } else if (keyid == masterKeyID) { + } else if (keyid == seed_id) { file << "hdmaster=1"; } else if (mapKeyPool.count(keyid)) { file << "reserve=1"; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3317,8 +3317,8 @@ obj.pushKV("txcount", (int)pwallet->mapWallet.size()); obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); obj.pushKV("keypoolsize", (int64_t)kpExternalSize); - CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; - if (!masterKeyID.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { + CKeyID seed_id = pwallet->GetHDChain().seed_id; + if (!seed_id.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { obj.pushKV("keypoolsize_hd_internal", int64_t(pwallet->GetKeyPoolSize() - kpExternalSize)); } @@ -3326,8 +3326,8 @@ obj.pushKV("unlocked_until", pwallet->nRelockTime); } obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); - if (!masterKeyID.IsNull()) { - obj.pushKV("hdmasterkeyid", masterKeyID.GetHex()); + if (!seed_id.IsNull()) { + obj.pushKV("hdmasterkeyid", seed_id.GetHex()); } return obj; } @@ -4488,7 +4488,7 @@ ret.pushKV("timestamp", meta->nCreateTime); if (!meta->hdKeypath.empty()) { ret.pushKV("hdkeypath", meta->hdKeypath); - ret.pushKV("hdmasterkeyid", meta->hdMasterKeyID.GetHex()); + ret.pushKV("hdmasterkeyid", meta->hd_seed_id.GetHex()); } } return ret; @@ -4562,7 +4562,7 @@ CPubKey master_pub_key; if (request.params[1].isNull()) { - master_pub_key = pwallet->GenerateNewHDMasterKey(); + master_pub_key = pwallet->GenerateNewSeed(); } else { CKey key = DecodeSecret(request.params[1].get_str()); if (!key.IsValid()) { @@ -4576,10 +4576,10 @@ "as a loose private key)"); } - master_pub_key = pwallet->DeriveNewMasterHDKey(key); + master_pub_key = pwallet->DeriveNewSeed(key); } - pwallet->SetHDMasterKey(master_pub_key); + pwallet->SetHDSeed(master_pub_key); if (flush_key_pool) { pwallet->NewKeyPool(); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1297,12 +1297,12 @@ bool IsHDEnabled() const; /* Generates a new HD master key (will not be activated) */ - CPubKey GenerateNewHDMasterKey(); + CPubKey GenerateNewSeed(); /** * Derives a new HD master key (will not be activated) */ - CPubKey DeriveNewMasterHDKey(const CKey &key); + CPubKey DeriveNewSeed(const CKey &key); /** * Set the current HD master key (will reset the chain child index counters) @@ -1310,7 +1310,7 @@ * caller must ensure the current wallet version is correct before calling * this function). */ - void SetHDMasterKey(const CPubKey &key); + void SetHDSeed(const CPubKey &key); /** * Blocks until the wallet state is up-to-date to /at least/ the current diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -214,12 +214,12 @@ CExtKey childKey; // try to get the master key - if (!GetKey(hdChain.masterKeyID, key)) { + if (!GetKey(hdChain.seed_id, key)) { throw std::runtime_error(std::string(__func__) + ": Master key not found"); } - masterKey.SetMaster(key.begin(), key.size()); + masterKey.SetSeed(key.begin(), key.size()); // derive m/0' // use hardened derivation (child keys >= 0x80000000 are hardened after @@ -254,7 +254,7 @@ } } while (HaveKey(childKey.key.GetPubKey().GetID())); secret = childKey.key; - metadata.hdMasterKeyID = hdChain.masterKeyID; + metadata.hd_seed_id = hdChain.seed_id; // update the chain model in the database if (!batch.WriteHDChain(hdChain)) { throw std::runtime_error(std::string(__func__) + @@ -789,7 +789,7 @@ // If we are using HD, replace the HD master key (seed) with a new one. if (IsHDEnabled()) { - SetHDMasterKey(GenerateNewHDMasterKey()); + SetHDSeed(GenerateNewSeed()); } NewKeyPool(); @@ -1548,13 +1548,13 @@ return nChange; } -CPubKey CWallet::GenerateNewHDMasterKey() { +CPubKey CWallet::GenerateNewSeed() { CKey key; key.MakeNewKey(true); - return DeriveNewMasterHDKey(key); + return DeriveNewSeed(key); } -CPubKey CWallet::DeriveNewMasterHDKey(const CKey &key) { +CPubKey CWallet::DeriveNewSeed(const CKey &key) { int64_t nCreationTime = GetTime(); CKeyMetadata metadata(nCreationTime); @@ -1564,7 +1564,7 @@ // Set the hd keypath to "m" -> Master, refers the masterkeyid to itself. metadata.hdKeypath = "m"; - metadata.hdMasterKeyID = pubkey.GetID(); + metadata.hd_seed_id = pubkey.GetID(); LOCK(cs_wallet); @@ -1580,7 +1580,7 @@ return pubkey; } -void CWallet::SetHDMasterKey(const CPubKey &pubkey) { +void CWallet::SetHDSeed(const CPubKey &seed) { LOCK(cs_wallet); // Store the keyid (hash160) together with the child index counter in the @@ -1589,7 +1589,7 @@ newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) ? CHDChain::VERSION_HD_CHAIN_SPLIT : CHDChain::VERSION_HD_BASE; - newHdChain.masterKeyID = pubkey.GetID(); + newHdChain.seed_id = seed.GetID(); SetHDChain(newHdChain, false); } @@ -1604,7 +1604,7 @@ } bool CWallet::IsHDEnabled() const { - return !hdChain.masterKeyID.IsNull(); + return !hdChain.seed_id.IsNull(); } int64_t CWalletTx::GetTxTime() const { @@ -4457,8 +4457,8 @@ walletInstance->SetMinVersion(FEATURE_HD); // generate a new master key - CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); - walletInstance->SetHDMasterKey(masterPubKey); + CPubKey masterPubKey = walletInstance->GenerateNewSeed(); + walletInstance->SetHDSeed(masterPubKey); hd_upgrade = true; } // Upgrade to HD chain split if necessary @@ -4492,8 +4492,8 @@ walletInstance->SetMinVersion(FEATURE_LATEST); // Generate a new master key. - CPubKey masterPubKey = walletInstance->GenerateNewHDMasterKey(); - walletInstance->SetHDMasterKey(masterPubKey); + CPubKey masterPubKey = walletInstance->GenerateNewSeed(); + walletInstance->SetHDSeed(masterPubKey); // Top up the keypool if (!walletInstance->TopUpKeyPool()) { diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -64,7 +64,7 @@ uint32_t nExternalChainCounter; uint32_t nInternalChainCounter; //!< master key hash160 - CKeyID masterKeyID; + CKeyID seed_id; static const int VERSION_HD_BASE = 1; static const int VERSION_HD_CHAIN_SPLIT = 2; @@ -77,7 +77,7 @@ inline void SerializationOp(Stream &s, Operation ser_action) { READWRITE(this->nVersion); READWRITE(nExternalChainCounter); - READWRITE(masterKeyID); + READWRITE(seed_id); if (this->nVersion >= VERSION_HD_CHAIN_SPLIT) { READWRITE(nInternalChainCounter); } @@ -87,7 +87,7 @@ nVersion = CHDChain::CURRENT_VERSION; nExternalChainCounter = 0; nInternalChainCounter = 0; - masterKeyID.SetNull(); + seed_id.SetNull(); } }; @@ -102,7 +102,7 @@ // optional HD/bip32 keypath. std::string hdKeypath; // Id of the HD masterkey used to derive this key. - CKeyID hdMasterKeyID; + CKeyID hd_seed_id; CKeyMetadata() { SetNull(); } explicit CKeyMetadata(int64_t nCreateTime_) { @@ -118,7 +118,7 @@ READWRITE(nCreateTime); if (this->nVersion >= VERSION_WITH_HDDATA) { READWRITE(hdKeypath); - READWRITE(hdMasterKeyID); + READWRITE(hd_seed_id); } } @@ -126,7 +126,7 @@ nVersion = CKeyMetadata::CURRENT_VERSION; nCreateTime = 0; hdKeypath.clear(); - hdMasterKeyID.SetNull(); + hd_seed_id.SetNull(); } };