mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-03 18:13:25 +02:00
desc spkm: Add functions to retrieve specific private keys
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <script/solver.h>
|
#include <script/solver.h>
|
||||||
#include <util/bip32.h>
|
#include <util/bip32.h>
|
||||||
|
#include <util/check.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
@@ -2143,6 +2144,36 @@ std::map<CKeyID, CKey> DescriptorScriptPubKeyMan::GetKeys() const
|
|||||||
return m_map_keys;
|
return m_map_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DescriptorScriptPubKeyMan::HasPrivKey(const CKeyID& keyid) const
|
||||||
|
{
|
||||||
|
AssertLockHeld(cs_desc_man);
|
||||||
|
return m_map_keys.contains(keyid) || m_map_crypted_keys.contains(keyid);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<CKey> DescriptorScriptPubKeyMan::GetKey(const CKeyID& keyid) const
|
||||||
|
{
|
||||||
|
AssertLockHeld(cs_desc_man);
|
||||||
|
if (m_storage.HasEncryptionKeys() && !m_storage.IsLocked()) {
|
||||||
|
const auto& it = m_map_crypted_keys.find(keyid);
|
||||||
|
if (it == m_map_crypted_keys.end()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
const std::vector<unsigned char>& crypted_secret = it->second.second;
|
||||||
|
CKey key;
|
||||||
|
if (!Assume(m_storage.WithEncryptionKey([&](const CKeyingMaterial& encryption_key) {
|
||||||
|
return DecryptKey(encryption_key, crypted_secret, it->second.first, key);
|
||||||
|
}))) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
const auto& it = m_map_keys.find(keyid);
|
||||||
|
if (it == m_map_keys.end()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
|
bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
|
||||||
{
|
{
|
||||||
WalletBatch batch(m_storage.GetDatabase());
|
WalletBatch batch(m_storage.GetDatabase());
|
||||||
|
@@ -633,6 +633,9 @@ public:
|
|||||||
bool SetupDescriptorGeneration(WalletBatch& batch, const CExtKey& master_key, OutputType addr_type, bool internal);
|
bool SetupDescriptorGeneration(WalletBatch& batch, const CExtKey& master_key, OutputType addr_type, bool internal);
|
||||||
|
|
||||||
bool HavePrivateKeys() const override;
|
bool HavePrivateKeys() const override;
|
||||||
|
bool HasPrivKey(const CKeyID& keyid) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
||||||
|
//! Retrieve the particular key if it is available. Returns nullopt if the key is not in the wallet, or if the wallet is locked.
|
||||||
|
std::optional<CKey> GetKey(const CKeyID& keyid) const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
||||||
|
|
||||||
std::optional<int64_t> GetOldestKeyPoolTime() const override;
|
std::optional<int64_t> GetOldestKeyPoolTime() const override;
|
||||||
unsigned int GetKeyPoolSize() const override;
|
unsigned int GetKeyPoolSize() const override;
|
||||||
|
Reference in New Issue
Block a user