bool CAccountHD::GetKey(const CKeyID& keyID, CKey& key) const { assert(!m_readOnly); assert(IsHD()); // Witness keys are a special case. // They are stored instead of generated on demand (so that they work in encrypted wallets) if (IsPoW2Witness()) { if (internalKeyStore.GetKey(keyID, key)) { // But skip it if it is an empty key... (Which can happen by design) // Technical: Witness keystore is filled with "public/empty" pairs as the public keys are created and then populated on demand with "public/witness" keys only when they are needed/generated (first use) if (key.IsValid()) return true; } } if (IsLocked()) return false; int64_t nKeyIndex = -1; CExtKey privKey; if (externalKeyStore.GetKey(keyID, nKeyIndex)) { primaryChainKeyPriv.Derive(privKey, nKeyIndex); if(privKey.Neuter().pubkey.GetID() != keyID) assert(0); key = privKey.key; return true; } if (internalKeyStore.GetKey(keyID, nKeyIndex)) { changeChainKeyPriv.Derive(privKey, nKeyIndex); if(privKey.Neuter().pubkey.GetID() != keyID) assert(0); key = privKey.key; return true; } return false; }
bool CAccountHD::GetKey(const CKeyID& keyID, CKey& key) const { if (IsLocked()) return false; int64_t nKeyIndex = -1; CExtKey privKey; if (externalKeyStore.GetKey(keyID, nKeyIndex)) { primaryChainKeyPriv.Derive(privKey, nKeyIndex); if (privKey.Neuter().pubkey.GetID() != keyID) assert(0); key = privKey.key; return true; } if (internalKeyStore.GetKey(keyID, nKeyIndex)) { changeChainKeyPriv.Derive(privKey, nKeyIndex); if (privKey.Neuter().pubkey.GetID() != keyID) assert(0); key = privKey.key; return true; } return false; }