| 184 | } |
| 185 | |
| 186 | static bool SignTaproot(const SigningProvider& provider, const BaseSignatureCreator& creator, const WitnessV1Taproot& output, SignatureData& sigdata, std::vector<valtype>& result) |
| 187 | { |
| 188 | TaprootSpendData spenddata; |
| 189 | |
| 190 | // Gather information about this output. |
| 191 | if (provider.GetTaprootSpendData(output, spenddata)) { |
| 192 | sigdata.tr_spenddata.Merge(spenddata); |
| 193 | } |
| 194 | |
| 195 | // Try key path spending. |
| 196 | { |
| 197 | std::vector<unsigned char> sig; |
| 198 | if (sigdata.taproot_key_path_sig.size() == 0) { |
| 199 | if (creator.CreateSchnorrSig(provider, sig, spenddata.internal_key, nullptr, &spenddata.merkle_root, SigVersion::TAPROOT)) { |
| 200 | sigdata.taproot_key_path_sig = sig; |
| 201 | } |
| 202 | } |
| 203 | if (sigdata.taproot_key_path_sig.size()) { |
| 204 | result = Vector(sigdata.taproot_key_path_sig); |
| 205 | return true; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // Try script path spending. |
| 210 | std::vector<std::vector<unsigned char>> smallest_result_stack; |
| 211 | for (const auto& [key, control_blocks] : sigdata.tr_spenddata.scripts) { |
| 212 | const auto& [script, leaf_ver] = key; |
| 213 | std::vector<std::vector<unsigned char>> result_stack; |
| 214 | if (SignTaprootScript(provider, creator, sigdata, leaf_ver, script, result_stack)) { |
| 215 | result_stack.emplace_back(std::begin(script), std::end(script)); // Push the script |
| 216 | result_stack.push_back(*control_blocks.begin()); // Push the smallest control block |
| 217 | if (smallest_result_stack.size() == 0 || |
| 218 | GetSerializeSize(result_stack, PROTOCOL_VERSION) < GetSerializeSize(smallest_result_stack, PROTOCOL_VERSION)) { |
| 219 | smallest_result_stack = std::move(result_stack); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | if (smallest_result_stack.size() != 0) { |
| 224 | result = std::move(smallest_result_stack); |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Sign scriptPubKey using signature made with creator. |
no test coverage detected