Skip to content

Commit

Permalink
descriptor: Try the other parity in ConstPubkeyProvider::GetPrivKey()
Browse files Browse the repository at this point in the history
GetPrivKey() needs the same handling of all keyids for xonly keys that
ToPrivateString() does. Refactor that into GetPrivKey() and reuse it in
ToPrivateString() to resolve this.
  • Loading branch information
achow101 committed Jan 6, 2025
1 parent 228aba2 commit 092569e
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/script/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,7 @@ class ConstPubkeyProvider final : public PubkeyProvider
bool ToPrivateString(const SigningProvider& arg, std::string& ret) const override
{
CKey key;
if (m_xonly) {
for (const auto& keyid : XOnlyPubKey(m_pubkey).GetKeyIDs()) {
arg.GetKey(keyid, key);
if (key.IsValid()) break;
}
} else {
arg.GetKey(m_pubkey.GetID(), key);
}
if (!key.IsValid()) return false;
if (!GetPrivKey(/*pos=*/0, arg, key)) return false;
ret = EncodeSecret(key);
return true;
}
Expand All @@ -331,7 +323,8 @@ class ConstPubkeyProvider final : public PubkeyProvider
}
bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const override
{
return arg.GetKey(m_pubkey.GetID(), key);
return m_xonly ? arg.GetKeyByXOnly(XOnlyPubKey(m_pubkey), key) :
arg.GetKey(m_pubkey.GetID(), key);
}
std::optional<CPubKey> GetRootPubKey() const override
{
Expand Down

0 comments on commit 092569e

Please sign in to comment.