(
tx: &mut T,
context: &dyn BaseContext,
input_index: usize,
sighash_type: TapSighashType,
taproot_spend_info: TaprootSpendInfo,
)
| 147 | } |
| 148 | |
| 149 | pub fn finalize_musig2_taproot_input<T: PreSignedTransaction + PreSignedMusig2Transaction>( |
| 150 | tx: &mut T, |
| 151 | context: &dyn BaseContext, |
| 152 | input_index: usize, |
| 153 | sighash_type: TapSighashType, |
| 154 | taproot_spend_info: TaprootSpendInfo, |
| 155 | ) { |
| 156 | // TODO: Verify we have partial signatures from all verifiers. |
| 157 | // TODO: Verify each signature against the signers public key. |
| 158 | // See example here: https://github.com/conduition/musig2/blob/c39bfce58098d337a3ec38b54d93def8306d9953/src/signing.rs#L358C1-L366C65 |
| 159 | |
| 160 | let prev_outs = &tx.prev_outs().clone(); |
| 161 | let script = &tx.prev_scripts()[input_index].clone(); |
| 162 | let musig2_nonces: &Vec<PubNonce> = |
| 163 | &tx.musig2_nonces()[&input_index].values().cloned().collect(); |
| 164 | let musig2_signatures: Vec<MaybeScalar> = tx.musig2_signatures()[&input_index] |
| 165 | .values() |
| 166 | .map(|&partial_signature| PartialSignature::from(partial_signature)) |
| 167 | .collect(); |
| 168 | let tx_mut = tx.tx_mut(); |
| 169 | |
| 170 | // Aggregate signature |
| 171 | let signature = generate_taproot_aggregated_signature( |
| 172 | context, |
| 173 | tx_mut, |
| 174 | &generate_aggregated_nonce(musig2_nonces), |
| 175 | input_index, |
| 176 | prev_outs, |
| 177 | script, |
| 178 | sighash_type, |
| 179 | musig2_signatures, // TODO: Is there a more elegant way of doing this? |
| 180 | ) |
| 181 | .unwrap(); // TODO: Add error handling. |
| 182 | |
| 183 | let final_signature = bitcoin::taproot::Signature { |
| 184 | signature: signature.into(), |
| 185 | sighash_type, |
| 186 | }; |
| 187 | |
| 188 | // Push signature to witness |
| 189 | tx_mut.input[input_index] |
| 190 | .witness |
| 191 | .push(final_signature.serialize()); |
| 192 | |
| 193 | // Push script + control block |
| 194 | push_taproot_leaf_script_and_control_block_to_witness( |
| 195 | tx_mut, |
| 196 | input_index, |
| 197 | &taproot_spend_info, |
| 198 | script, |
| 199 | ); |
| 200 | } |
no test coverage detected