@@ -166,7 +166,7 @@ struct PubkeyProvider
166
166
* write_cache is the cache to write keys to (if not nullptr)
167
167
* Caches are not exclusive but this is not tested. Currently we use them exclusively
168
168
*/
169
- virtual bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) = 0;
169
+ virtual bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) const = 0;
170
170
171
171
/* * Whether this represent multiple public keys at different positions. */
172
172
virtual bool IsRange () const = 0;
@@ -199,7 +199,7 @@ class OriginPubkeyProvider final : public PubkeyProvider
199
199
200
200
public:
201
201
OriginPubkeyProvider (uint32_t exp_index, KeyOriginInfo info, std::unique_ptr<PubkeyProvider> provider) : PubkeyProvider(exp_index), m_origin(std::move(info)), m_provider(std::move(provider)) {}
202
- bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) override
202
+ bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) const override
203
203
{
204
204
if (!m_provider->GetPubKey (pos, arg, key, info, read_cache, write_cache)) return false ;
205
205
std::copy (std::begin (m_origin.fingerprint ), std::end (m_origin.fingerprint ), info.fingerprint );
@@ -245,7 +245,7 @@ class ConstPubkeyProvider final : public PubkeyProvider
245
245
246
246
public:
247
247
ConstPubkeyProvider (uint32_t exp_index, const CPubKey& pubkey, bool xonly) : PubkeyProvider(exp_index), m_pubkey(pubkey), m_xonly(xonly) {}
248
- bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) override
248
+ bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) const override
249
249
{
250
250
key = m_pubkey;
251
251
info.path .clear ();
@@ -288,9 +288,6 @@ class BIP32PubkeyProvider final : public PubkeyProvider
288
288
CExtPubKey m_root_extkey;
289
289
KeyPath m_path;
290
290
DeriveType m_derive;
291
- // Cache of the parent of the final derived pubkeys.
292
- // Primarily useful for situations when no read_cache is provided
293
- CExtPubKey m_cached_xpub;
294
291
295
292
bool GetExtKey (const SigningProvider& arg, CExtKey& ret) const
296
293
{
@@ -327,7 +324,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
327
324
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) {}
328
325
bool IsRange () const override { return m_derive != DeriveType::NO; }
329
326
size_t GetSize () const override { return 33 ; }
330
- bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key_out, KeyOriginInfo& final_info_out, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) override
327
+ bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key_out, KeyOriginInfo& final_info_out, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) const override
331
328
{
332
329
// Info of parent of the to be derived pubkey
333
330
KeyOriginInfo parent_info;
@@ -352,9 +349,6 @@ class BIP32PubkeyProvider final : public PubkeyProvider
352
349
final_extkey = parent_extkey;
353
350
if (m_derive == DeriveType::UNHARDENED) der = parent_extkey.Derive (final_extkey, pos);
354
351
}
355
- } else if (m_cached_xpub.pubkey .IsValid () && m_derive != DeriveType::HARDENED) {
356
- parent_extkey = final_extkey = m_cached_xpub;
357
- if (m_derive == DeriveType::UNHARDENED) der = parent_extkey.Derive (final_extkey, pos);
358
352
} else if (IsHardened ()) {
359
353
CExtKey xprv;
360
354
if (!GetDerivedExtKey (arg, xprv)) return false ;
@@ -376,11 +370,6 @@ class BIP32PubkeyProvider final : public PubkeyProvider
376
370
final_info_out = final_info_out_tmp;
377
371
key_out = final_extkey.pubkey ;
378
372
379
- // We rely on the consumer to check that m_derive isn't HARDENED as above
380
- // But we can't have already cached something in case we read something from the cache
381
- // and parent_extkey isn't actually the parent.
382
- if (!m_cached_xpub.pubkey .IsValid ()) m_cached_xpub = parent_extkey;
383
-
384
373
if (write_cache) {
385
374
// Only cache parent if there is any unhardened derivation
386
375
if (m_derive != DeriveType::HARDENED) {
0 commit comments