From c17c6aa08df81aa0086d80b50187c8cd60ecc222 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 10 Jan 2022 18:12:14 -0500 Subject: [PATCH] Add signing support for (sorted)multi_a scripts --- src/script/sign.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 8e084484800..c6164e22d77 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -174,6 +174,29 @@ static bool SignTaprootScript(const SigningProvider& provider, const BaseSignatu result = Vector(std::move(sig)); return true; } + return false; + } + + // multi_a scripts ( OP_CHECKSIG OP_CHECKSIGADD OP_CHECKSIGADD OP_NUMEQUAL) + if (auto match = MatchMultiA(script)) { + std::vector> sigs; + int good_sigs = 0; + for (size_t i = 0; i < match->second.size(); ++i) { + XOnlyPubKey pubkey{*(match->second.rbegin() + i)}; + std::vector sig; + bool good_sig = CreateTaprootScriptSig(creator, sigdata, provider, sig, pubkey, leaf_hash, sigversion); + if (good_sig && good_sigs < match->first) { + ++good_sigs; + sigs.push_back(std::move(sig)); + } else { + sigs.emplace_back(); + } + } + if (good_sigs == match->first) { + result = std::move(sigs); + return true; + } + return false; } return false;