From 092569e8580b7c2c13b6cc9d29bcb4c5e85bbb44 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Wed, 1 Jan 2025 23:17:44 -0500 Subject: [PATCH] descriptor: Try the other parity in ConstPubkeyProvider::GetPrivKey() 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. --- src/script/descriptor.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 2e1a30744ec11..687fc72d1b82d 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -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; } @@ -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 GetRootPubKey() const override {