0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-13 11:25:02 -05:00

Rename BIP32PubkeyProvider.m_extkey to m_root_extkey

Renaming clarifies that m_extkey is actually the root
extkey that keys are derived from.
This commit is contained in:
Andrew Chow 2020-03-03 17:16:40 -05:00
parent df55d44d0d
commit 66c2cadc91

View file

@ -254,18 +254,19 @@ enum class DeriveType {
/** An object representing a parsed extended public key in a descriptor. */ /** An object representing a parsed extended public key in a descriptor. */
class BIP32PubkeyProvider final : public PubkeyProvider class BIP32PubkeyProvider final : public PubkeyProvider
{ {
CExtPubKey m_extkey; // Root xpub, path, and final derivation step type being used, if any
CExtPubKey m_root_extkey;
KeyPath m_path; KeyPath m_path;
DeriveType m_derive; DeriveType m_derive;
bool GetExtKey(const SigningProvider& arg, CExtKey& ret) const bool GetExtKey(const SigningProvider& arg, CExtKey& ret) const
{ {
CKey key; CKey key;
if (!arg.GetKey(m_extkey.pubkey.GetID(), key)) return false; if (!arg.GetKey(m_root_extkey.pubkey.GetID(), key)) return false;
ret.nDepth = m_extkey.nDepth; ret.nDepth = m_root_extkey.nDepth;
std::copy(m_extkey.vchFingerprint, m_extkey.vchFingerprint + sizeof(ret.vchFingerprint), ret.vchFingerprint); std::copy(m_root_extkey.vchFingerprint, m_root_extkey.vchFingerprint + sizeof(ret.vchFingerprint), ret.vchFingerprint);
ret.nChild = m_extkey.nChild; ret.nChild = m_root_extkey.nChild;
ret.chaincode = m_extkey.chaincode; ret.chaincode = m_root_extkey.chaincode;
ret.key = key; ret.key = key;
return true; return true;
} }
@ -280,7 +281,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
} }
public: public:
BIP32PubkeyProvider(uint32_t exp_index, const CExtPubKey& extkey, KeyPath path, DeriveType derive) : PubkeyProvider(exp_index), m_extkey(extkey), m_path(std::move(path)), m_derive(derive) {} BIP32PubkeyProvider(uint32_t exp_index, const CExtPubKey& extkey, KeyPath path, DeriveType derive) : PubkeyProvider(exp_index), m_root_extkey(extkey), m_path(std::move(path)), m_derive(derive) {}
bool IsRange() const override { return m_derive != DeriveType::NO; } bool IsRange() const override { return m_derive != DeriveType::NO; }
size_t GetSize() const override { return 33; } size_t GetSize() const override { return 33; }
bool GetPubKey(int pos, const SigningProvider& arg, CPubKey* key, KeyOriginInfo& info) const override bool GetPubKey(int pos, const SigningProvider& arg, CPubKey* key, KeyOriginInfo& info) const override
@ -292,7 +293,7 @@ public:
*key = priv_key.GetPubKey(); *key = priv_key.GetPubKey();
} else { } else {
// TODO: optimize by caching // TODO: optimize by caching
CExtPubKey extkey = m_extkey; CExtPubKey extkey = m_root_extkey;
for (auto entry : m_path) { for (auto entry : m_path) {
extkey.Derive(extkey, entry); extkey.Derive(extkey, entry);
} }
@ -301,7 +302,7 @@ public:
*key = extkey.pubkey; *key = extkey.pubkey;
} }
} }
CKeyID keyid = m_extkey.pubkey.GetID(); CKeyID keyid = m_root_extkey.pubkey.GetID();
std::copy(keyid.begin(), keyid.begin() + sizeof(info.fingerprint), info.fingerprint); std::copy(keyid.begin(), keyid.begin() + sizeof(info.fingerprint), info.fingerprint);
info.path = m_path; info.path = m_path;
if (m_derive == DeriveType::UNHARDENED) info.path.push_back((uint32_t)pos); if (m_derive == DeriveType::UNHARDENED) info.path.push_back((uint32_t)pos);
@ -310,7 +311,7 @@ public:
} }
std::string ToString() const override std::string ToString() const override
{ {
std::string ret = EncodeExtPubKey(m_extkey) + FormatHDKeypath(m_path); std::string ret = EncodeExtPubKey(m_root_extkey) + FormatHDKeypath(m_path);
if (IsRange()) { if (IsRange()) {
ret += "/*"; ret += "/*";
if (m_derive == DeriveType::HARDENED) ret += '\''; if (m_derive == DeriveType::HARDENED) ret += '\'';