| 62 | } |
| 63 | |
| 64 | bool MutableTransactionSignatureCreator::CreateSchnorrSig(const SigningProvider& provider, std::vector<unsigned char>& sig, const XOnlyPubKey& pubkey, const uint256* leaf_hash, const uint256* merkle_root, SigVersion sigversion) const |
| 65 | { |
| 66 | assert(sigversion == SigVersion::TAPROOT || sigversion == SigVersion::TAPSCRIPT); |
| 67 | |
| 68 | CKey key; |
| 69 | if (!provider.GetKeyByXOnly(pubkey, key)) return false; |
| 70 | |
| 71 | // BIP341/BIP342 signing needs lots of precomputed transaction data. While some |
| 72 | // (non-SIGHASH_DEFAULT) sighash modes exist that can work with just some subset |
| 73 | // of data present, for now, only support signing when everything is provided. |
| 74 | if (!m_txdata || !m_txdata->m_bip341_taproot_ready || !m_txdata->m_spent_outputs_ready) return false; |
| 75 | |
| 76 | ScriptExecutionData execdata; |
| 77 | execdata.m_annex_init = true; |
| 78 | execdata.m_annex_present = false; // Only support annex-less signing for now. |
| 79 | if (sigversion == SigVersion::TAPSCRIPT) { |
| 80 | execdata.m_codeseparator_pos_init = true; |
| 81 | execdata.m_codeseparator_pos = 0xFFFFFFFF; // Only support non-OP_CODESEPARATOR BIP342 signing for now. |
| 82 | if (!leaf_hash) return false; // BIP342 signing needs leaf hash. |
| 83 | execdata.m_tapleaf_hash_init = true; |
| 84 | execdata.m_tapleaf_hash = *leaf_hash; |
| 85 | } |
| 86 | uint256 hash; |
| 87 | if (!SignatureHashSchnorr(hash, execdata, *txTo, nIn, nHashType, sigversion, *m_txdata, MissingDataBehavior::FAIL)) return false; |
| 88 | sig.resize(64); |
| 89 | // Use uint256{} as aux_rnd for now. |
| 90 | if (!key.SignSchnorr(hash, sig, merkle_root, {})) return false; |
| 91 | if (nHashType) sig.push_back(nHashType); |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | static bool GetCScript(const SigningProvider& provider, const SignatureData& sigdata, const CScriptID& scriptid, CScript& script) |
| 96 | { |