MCPcopy Create free account
hub / github.com/ElementsProject/elements / WriteCryptedKey

Method WriteCryptedKey

src/wallet/walletdb.cpp:120–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120bool WalletBatch::WriteCryptedKey(const CPubKey& vchPubKey,
121 const std::vector<unsigned char>& vchCryptedSecret,
122 const CKeyMetadata &keyMeta)
123{
124 if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) {
125 return false;
126 }
127
128 // Compute a checksum of the encrypted key
129 uint256 checksum = Hash(vchCryptedSecret);
130
131 const auto key = std::make_pair(DBKeys::CRYPTED_KEY, vchPubKey);
132 if (!WriteIC(key, std::make_pair(vchCryptedSecret, checksum), false)) {
133 // It may already exist, so try writing just the checksum
134 std::vector<unsigned char> val;
135 if (!m_batch->Read(key, val)) {
136 return false;
137 }
138 if (!WriteIC(key, std::make_pair(val, checksum), true)) {
139 return false;
140 }
141 }
142 EraseIC(std::make_pair(DBKeys::KEY, vchPubKey));
143 return true;
144}
145
146bool WalletBatch::WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
147{

Callers 2

CheckDecryptionKeyMethod · 0.80
AddCryptedKeyMethod · 0.80

Calls 2

HashFunction · 0.50
ReadMethod · 0.45

Tested by

no test coverage detected