static bool DecryptKey(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCryptedSecret, const CPubKey& vchPubKey, CKey& key) { CKeyingMaterial vchSecret; if(!DecryptSecret(vMasterKey, vchCryptedSecret, vchPubKey.GetHash(), vchSecret)) return false; if (vchSecret.size() != 32) return false; key.Set(vchSecret.begin(), vchSecret.end(), vchPubKey.IsCompressed()); return key.VerifyPubKey(vchPubKey); }
CPubKey CAccount::GenerateNewKey(CWallet& wallet, int keyChain) { CKey secret; secret.MakeNewKey(true); CPubKey pubkey = secret.GetPubKey(); assert(secret.VerifyPubKey(pubkey)); if (!wallet.AddKeyPubKey(secret, pubkey, *this, keyChain)) throw std::runtime_error("CAccount::GenerateNewKey(): AddKeyPubKey failed"); return pubkey; }
CPubKey CAccount::GenerateNewKey(CWallet& wallet, CKeyMetadata& metadata, int keyChain) { if (IsFixedKeyPool()) throw std::runtime_error(strprintf("GenerateNewKey called on a \"%sy\" witness account - this is invalid", GetAccountTypeString(m_Type).c_str())); CKey secret; secret.MakeNewKey(true); CPubKey pubkey = secret.GetPubKey(); assert(secret.VerifyPubKey(pubkey)); if (!wallet.AddKeyPubKey(secret, pubkey, *this, keyChain)) throw std::runtime_error("CAccount::GenerateNewKey(): AddKeyPubKey failed"); return pubkey; }