|
|
|
@ -3,10 +3,10 @@ use crate::bitcoin::{
|
|
|
|
|
verify_sig, Address, EmptyWitnessStack, NoInputs, NotThreeWitnesses, PublicKey, TooManyInputs,
|
|
|
|
|
Transaction, TxCancel,
|
|
|
|
|
};
|
|
|
|
|
use crate::{bitcoin, monero};
|
|
|
|
|
use ::bitcoin::util::bip143::SigHashCache;
|
|
|
|
|
use ::bitcoin::{SigHash, SigHashType, Txid};
|
|
|
|
|
use ::bitcoin::{Script, SigHash, SigHashType, Txid};
|
|
|
|
|
use anyhow::{bail, Context, Result};
|
|
|
|
|
use bitcoin::Script;
|
|
|
|
|
use ecdsa_fun::Signature;
|
|
|
|
|
use miniscript::{Descriptor, DescriptorTrait};
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
@ -77,7 +77,31 @@ impl TxRefund {
|
|
|
|
|
Ok(tx_refund)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn extract_signature_by_key(
|
|
|
|
|
pub fn extract_monero_private_key(
|
|
|
|
|
&self,
|
|
|
|
|
published_refund_tx: bitcoin::Transaction,
|
|
|
|
|
s_a: monero::Scalar,
|
|
|
|
|
a: bitcoin::SecretKey,
|
|
|
|
|
S_b_bitcoin: bitcoin::PublicKey,
|
|
|
|
|
) -> Result<monero::PrivateKey> {
|
|
|
|
|
let s_a = monero::PrivateKey { scalar: s_a };
|
|
|
|
|
|
|
|
|
|
let tx_refund_sig = self
|
|
|
|
|
.extract_signature_by_key(published_refund_tx, a.public())
|
|
|
|
|
.context("Failed to extract signature from Bitcoin refund tx")?;
|
|
|
|
|
let tx_refund_encsig = a.encsign(S_b_bitcoin, self.digest());
|
|
|
|
|
|
|
|
|
|
let s_b = bitcoin::recover(S_b_bitcoin, tx_refund_sig, tx_refund_encsig)
|
|
|
|
|
.context("Failed to recover Monero secret key from Bitcoin signature")?;
|
|
|
|
|
|
|
|
|
|
let s_b = monero::private_key_from_secp256k1_scalar(s_b.into());
|
|
|
|
|
|
|
|
|
|
let spend_key = s_a + s_b;
|
|
|
|
|
|
|
|
|
|
Ok(spend_key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn extract_signature_by_key(
|
|
|
|
|
&self,
|
|
|
|
|
candidate_transaction: Transaction,
|
|
|
|
|
B: PublicKey,
|
|
|
|
|