mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-03-01 11:11:14 -05:00
WIP: cleanup happy path, monero signing broken
This commit is contained in:
parent
8272e1c247
commit
7aabc8703d
@ -1,11 +1,9 @@
|
|||||||
use crate::bitcoin::Txid;
|
|
||||||
use crate::protocol::CROSS_CURVE_PROOF_SYSTEM;
|
use crate::protocol::CROSS_CURVE_PROOF_SYSTEM;
|
||||||
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
||||||
use curve25519_dalek::edwards::EdwardsPoint;
|
use curve25519_dalek::edwards::EdwardsPoint;
|
||||||
use curve25519_dalek::scalar::Scalar;
|
use curve25519_dalek::scalar::Scalar;
|
||||||
use ecdsa_fun::fun::Point;
|
use ecdsa_fun::fun::Point;
|
||||||
use hash_edwards_to_edwards::hash_point_to_point;
|
use hash_edwards_to_edwards::hash_point_to_point;
|
||||||
use monero_adaptor::AdaptorSignature;
|
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
|
|
||||||
pub mod alice;
|
pub mod alice;
|
||||||
|
@ -6,7 +6,6 @@ use crate::monero::{Scalar, TransferProof, TransferRequest};
|
|||||||
use crate::monero_ext::ScalarExt;
|
use crate::monero_ext::ScalarExt;
|
||||||
use crate::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
use crate::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
||||||
use crate::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
use crate::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
||||||
use crate::xmr_first_protocol::transactions::xmr_refund::XmrRefund;
|
|
||||||
|
|
||||||
// start
|
// start
|
||||||
pub struct Alice3 {
|
pub struct Alice3 {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use crate::monero::wallet::{TransferRequest, WatchRequest};
|
use crate::monero::wallet::WatchRequest;
|
||||||
use crate::monero::TransferProof;
|
use crate::monero::TransferProof;
|
||||||
use crate::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
use crate::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
||||||
use crate::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
use crate::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use monero_rpc::wallet::BlockHeight;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
// watching for xmr_lock
|
// watching for xmr_lock
|
||||||
@ -56,40 +55,6 @@ impl Bob3 {
|
|||||||
v: self.v,
|
v: self.v,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn emergency_refund_if_refund_xmr_seen(
|
|
||||||
&self,
|
|
||||||
xmr_wallet: &crate::monero::Wallet,
|
|
||||||
btc_wallet: &crate::bitcoin::Wallet,
|
|
||||||
transfer_proof: TransferProof,
|
|
||||||
) -> Result<Bob4> {
|
|
||||||
let req = WatchRequest {
|
|
||||||
public_spend_key: todo!(),
|
|
||||||
public_view_key: todo!(),
|
|
||||||
transfer_proof,
|
|
||||||
conf_target: 1,
|
|
||||||
expected: self.xmr_swap_amount,
|
|
||||||
};
|
|
||||||
let _ = xmr_wallet.watch_for_transfer(req).await?;
|
|
||||||
|
|
||||||
let emergency_refund = btc_wallet
|
|
||||||
.sign_and_finalize(self.tx_lock.clone().into())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let (_txid, sub) = btc_wallet.broadcast(emergency_refund, "lock").await?;
|
|
||||||
|
|
||||||
let _ = sub.wait_until_confirmed_with(1).await?;
|
|
||||||
|
|
||||||
Ok(Bob4 {
|
|
||||||
b: self.b.clone(),
|
|
||||||
A: self.A,
|
|
||||||
s_b: self.s_b,
|
|
||||||
S_a_bitcoin: self.S_a_bitcoin,
|
|
||||||
tx_lock: self.tx_lock.clone(),
|
|
||||||
alice_redeem_address: self.alice_redeem_address.clone(),
|
|
||||||
v: self.v,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// published btc_lock, watching for btc_redeem
|
// published btc_lock, watching for btc_redeem
|
||||||
|
@ -1,109 +0,0 @@
|
|||||||
use crate::bitcoin::wallet::Watchable;
|
|
||||||
use crate::bitcoin::{
|
|
||||||
verify_encsig, verify_sig, Address, EmptyWitnessStack, EncryptedSignature, NoInputs,
|
|
||||||
NotThreeWitnesses, PublicKey, SecretKey, TooManyInputs, Transaction,
|
|
||||||
};
|
|
||||||
use crate::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
|
||||||
use crate::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
|
||||||
use ::bitcoin::util::bip143::SigHashCache;
|
|
||||||
use ::bitcoin::{SigHash, SigHashType, Txid};
|
|
||||||
use anyhow::{bail, Context, Result};
|
|
||||||
use bitcoin::Script;
|
|
||||||
use ecdsa_fun::adaptor::{Adaptor, HashTranscript};
|
|
||||||
use ecdsa_fun::fun::Scalar;
|
|
||||||
use ecdsa_fun::nonce::Deterministic;
|
|
||||||
use ecdsa_fun::Signature;
|
|
||||||
use miniscript::{Descriptor, DescriptorTrait};
|
|
||||||
use sha2::Sha256;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct BtcEmergencyRefund {
|
|
||||||
inner: Transaction,
|
|
||||||
digest: SigHash,
|
|
||||||
lock_output_descriptor: Descriptor<::bitcoin::PublicKey>,
|
|
||||||
watch_script: Script,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BtcEmergencyRefund {
|
|
||||||
pub fn new(tx_redeem: &BtcRedeem, redeem_address: &Address) -> Self {
|
|
||||||
let tx_refund = tx_redeem.build_take_transaction(redeem_address, None);
|
|
||||||
|
|
||||||
let digest = SigHashCache::new(&tx_refund).signature_hash(
|
|
||||||
0, // Only one input: lock_input (lock transaction)
|
|
||||||
&tx_refund.output_descriptor.script_code(),
|
|
||||||
tx_refund.lock_amount().as_sat(),
|
|
||||||
SigHashType::All,
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
inner: tx_refund,
|
|
||||||
digest,
|
|
||||||
lock_output_descriptor: tx_refund.output_descriptor.clone(),
|
|
||||||
watch_script: redeem_address.script_pubkey(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn txid(&self) -> Txid {
|
|
||||||
self.inner.txid()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn digest(&self) -> SigHash {
|
|
||||||
self.digest
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn complete(
|
|
||||||
mut self,
|
|
||||||
a: SecretKey,
|
|
||||||
s_a: Scalar,
|
|
||||||
B: PublicKey,
|
|
||||||
encrypted_signature: EncryptedSignature,
|
|
||||||
) -> Result<Transaction> {
|
|
||||||
verify_encsig(
|
|
||||||
B,
|
|
||||||
PublicKey::from(s_a.clone()),
|
|
||||||
&self.digest(),
|
|
||||||
&encrypted_signature,
|
|
||||||
)
|
|
||||||
.context("Invalid encrypted signature received")?;
|
|
||||||
|
|
||||||
let sig_a = a.sign(self.digest());
|
|
||||||
let adaptor = Adaptor::<HashTranscript<Sha256>, Deterministic<Sha256>>::default();
|
|
||||||
let sig_b = adaptor.decrypt_signature(&s_a, encrypted_signature);
|
|
||||||
|
|
||||||
let satisfier = {
|
|
||||||
let mut satisfier = HashMap::with_capacity(2);
|
|
||||||
|
|
||||||
let A = ::bitcoin::PublicKey {
|
|
||||||
compressed: true,
|
|
||||||
key: a.public.into(),
|
|
||||||
};
|
|
||||||
let B = ::bitcoin::PublicKey {
|
|
||||||
compressed: true,
|
|
||||||
key: B.0.into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// The order in which these are inserted doesn't matter
|
|
||||||
satisfier.insert(A, (sig_a.into(), ::bitcoin::SigHashType::All));
|
|
||||||
satisfier.insert(B, (sig_b.into(), ::bitcoin::SigHashType::All));
|
|
||||||
|
|
||||||
satisfier
|
|
||||||
};
|
|
||||||
|
|
||||||
self.lock_output_descriptor
|
|
||||||
.satisfy(&mut self.inner.input[0], satisfier)
|
|
||||||
.context("Failed to sign Bitcoin redeem transaction")?;
|
|
||||||
|
|
||||||
Ok(self.inner)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Watchable for BtcEmergencyRefund {
|
|
||||||
fn id(&self) -> Txid {
|
|
||||||
self.txid()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn script(&self) -> Script {
|
|
||||||
self.watch_script.clone()
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,7 @@ use crate::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
|||||||
use ::bitcoin::util::bip143::SigHashCache;
|
use ::bitcoin::util::bip143::SigHashCache;
|
||||||
use ::bitcoin::{SigHash, SigHashType, Txid};
|
use ::bitcoin::{SigHash, SigHashType, Txid};
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use bdk::bitcoin::Script;
|
use bdk::bitcoin::{OutPoint, Script};
|
||||||
use bitcoin::{PrivateKey, TxIn, TxOut};
|
use bitcoin::{PrivateKey, TxIn, TxOut};
|
||||||
use ecdsa_fun::adaptor::{Adaptor, HashTranscript};
|
use ecdsa_fun::adaptor::{Adaptor, HashTranscript};
|
||||||
use ecdsa_fun::fun::Scalar;
|
use ecdsa_fun::fun::Scalar;
|
||||||
@ -50,6 +50,25 @@ impl BtcRedeem {
|
|||||||
self.inner.txid()
|
self.inner.txid()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_outpoint(&self) -> OutPoint {
|
||||||
|
// This is fine because a transaction that has that many outputs is not
|
||||||
|
// realistic
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
|
OutPoint::new(self.txid(), self.lock_output_vout() as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retreive the index of the locked output in the transaction outputs
|
||||||
|
/// vector
|
||||||
|
fn lock_output_vout(&self) -> usize {
|
||||||
|
self.inner
|
||||||
|
.clone()
|
||||||
|
.extract_tx()
|
||||||
|
.output
|
||||||
|
.iter()
|
||||||
|
.position(|output| output.script_pubkey == self.output_descriptor.script_pubkey())
|
||||||
|
.expect("transaction contains lock output")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn digest(&self) -> SigHash {
|
pub fn digest(&self) -> SigHash {
|
||||||
self.digest
|
self.digest
|
||||||
}
|
}
|
||||||
@ -144,16 +163,16 @@ impl BtcRedeem {
|
|||||||
Ok(sig)
|
Ok(sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_transaction(
|
// pub fn build_transaction(
|
||||||
&self,
|
// &self,
|
||||||
a: SecretKey,
|
// a: SecretKey,
|
||||||
s_a: Scalar,
|
// s_a: Scalar,
|
||||||
B: PublicKey,
|
// B: PublicKey,
|
||||||
encsig: EncryptedSignature,
|
// encsig: EncryptedSignature,
|
||||||
) -> Transaction {
|
// ) -> Transaction {
|
||||||
let signed_tx_redeem = self.complete(a, s_a, B, encsig)?;
|
// let signed_tx_redeem = self.complete(a, s_a, B, encsig)?;
|
||||||
signed_tx_redeem
|
// signed_tx_redeem
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn build_take_transaction(
|
pub fn build_take_transaction(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
pub mod btc_emergency_refund;
|
|
||||||
pub mod btc_lock;
|
pub mod btc_lock;
|
||||||
pub mod btc_redeem;
|
pub mod btc_redeem;
|
||||||
pub mod xmr_lock;
|
pub mod xmr_lock;
|
||||||
pub mod xmr_redeem;
|
pub mod xmr_redeem;
|
||||||
pub mod xmr_refund;
|
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
use crate::monero::wallet::WatchRequest;
|
|
||||||
use crate::monero::{Amount, PrivateViewKey, Scalar};
|
|
||||||
use crate::xmr_first_protocol::alice::Alice4;
|
|
||||||
use anyhow::Result;
|
|
||||||
use monero_adaptor::Signature;
|
|
||||||
|
|
||||||
pub struct XmrRefund {
|
|
||||||
signature: Signature,
|
|
||||||
amount: Amount,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct TransferRequest;
|
|
||||||
|
|
||||||
impl XmrRefund {
|
|
||||||
pub fn new(signature: Signature, amount: Amount) -> Self {
|
|
||||||
XmrRefund {
|
|
||||||
signature,
|
|
||||||
amount: xmr_swap_amount,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn transfer_request(&self) -> TransferRequest {
|
|
||||||
todo!();
|
|
||||||
TransferRequest
|
|
||||||
}
|
|
||||||
// pub fn watch_request(&self) -> WatchRequest {
|
|
||||||
// let S_a = monero::PublicKey::from_private_key(&monero::PrivateKey {
|
|
||||||
// scalar: self.s_a });
|
|
||||||
//
|
|
||||||
// let public_spend_key = S_a + self.S_b_monero;
|
|
||||||
// let public_view_key = self.v_a.public();
|
|
||||||
//
|
|
||||||
// WatchRequest {
|
|
||||||
// public_spend_key,
|
|
||||||
// public_view_key,
|
|
||||||
// transfer_proof: todo!("xfer without broadcasting to get xfer proof"),
|
|
||||||
// conf_target: 1,
|
|
||||||
// expected: self.amount,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
pub fn extract_r_a(&self) -> Scalar {
|
|
||||||
self.signature.extract()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,130 +0,0 @@
|
|||||||
pub mod harness;
|
|
||||||
|
|
||||||
use rand::rngs::OsRng;
|
|
||||||
use swap::bitcoin::BtcLock;
|
|
||||||
use swap::env::GetConfig;
|
|
||||||
use swap::monero;
|
|
||||||
use swap::monero::TransferRequest;
|
|
||||||
use swap::protocol::alice::event_loop::FixedRate;
|
|
||||||
use swap::protocol::CROSS_CURVE_PROOF_SYSTEM;
|
|
||||||
use swap::seed::Seed;
|
|
||||||
use swap::xmr_first_protocol::alice::{publish_xmr_refund, Alice3};
|
|
||||||
use swap::xmr_first_protocol::bob::Bob3;
|
|
||||||
use swap::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
|
||||||
use swap::xmr_first_protocol::transactions::xmr_lock::XmrLock;
|
|
||||||
use swap::xmr_first_protocol::transactions::xmr_refund::XmrRefund;
|
|
||||||
use tempfile::tempdir;
|
|
||||||
use testcontainers::clients::Cli;
|
|
||||||
use swap::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
|
||||||
use monero::{PublicKey, PrivateKey};
|
|
||||||
use swap::xmr_first_protocol::setup;
|
|
||||||
use swap::xmr_first_protocol::transactions::xmr_redeem::XmrRedeem;
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn refund() {
|
|
||||||
let cli = Cli::default();
|
|
||||||
|
|
||||||
let env_config = harness::SlowCancelConfig::get_config();
|
|
||||||
|
|
||||||
let (monero, containers) = harness::init_containers(&cli).await;
|
|
||||||
|
|
||||||
let btc_swap_amount = bitcoin::Amount::from_sat(1_000_000);
|
|
||||||
let xmr_swap_amount =
|
|
||||||
monero::Amount::from_monero(btc_swap_amount.as_btc() / FixedRate::RATE).unwrap();
|
|
||||||
|
|
||||||
let alice_starting_balances = harness::StartingBalances {
|
|
||||||
xmr: xmr_swap_amount * 10,
|
|
||||||
btc: bitcoin::Amount::ZERO,
|
|
||||||
};
|
|
||||||
|
|
||||||
let electrs_rpc_port = containers
|
|
||||||
.electrs
|
|
||||||
.get_host_port(harness::electrs::RPC_PORT)
|
|
||||||
.expect("Could not map electrs rpc port");
|
|
||||||
|
|
||||||
let alice_seed = Seed::random().unwrap();
|
|
||||||
let (alice_bitcoin_wallet, alice_monero_wallet) = harness::init_test_wallets(
|
|
||||||
"Alice",
|
|
||||||
containers.bitcoind_url.clone(),
|
|
||||||
&monero,
|
|
||||||
alice_starting_balances.clone(),
|
|
||||||
tempdir().unwrap().path(),
|
|
||||||
electrs_rpc_port,
|
|
||||||
&alice_seed,
|
|
||||||
env_config.clone(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let bob_seed = Seed::random().unwrap();
|
|
||||||
let bob_starting_balances = harness::StartingBalances {
|
|
||||||
xmr: monero::Amount::ZERO,
|
|
||||||
btc: btc_swap_amount * 10,
|
|
||||||
};
|
|
||||||
|
|
||||||
let (bob_bitcoin_wallet, bob_monero_wallet) = harness::init_test_wallets(
|
|
||||||
"Bob",
|
|
||||||
containers.bitcoind_url,
|
|
||||||
&monero,
|
|
||||||
bob_starting_balances.clone(),
|
|
||||||
tempdir().unwrap().path(),
|
|
||||||
electrs_rpc_port,
|
|
||||||
&bob_seed,
|
|
||||||
env_config,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let (alice, bob) = setup();
|
|
||||||
|
|
||||||
let btc_redeem_address = alice_bitcoin_wallet.new_address().await.unwrap();
|
|
||||||
|
|
||||||
// transactions
|
|
||||||
let btc_lock =
|
|
||||||
BtcLock::new(&bob_bitcoin_wallet, btc_swap_amount, a.public(), b.public()).await?;
|
|
||||||
let btc_redeem = BtcRedeem::new(&btc_lock, &btc_redeem_address);
|
|
||||||
let xmr_lock = XmrLock::new(alice.S_a.into(), alice.S_b, alice.v_a, alice.v_b, xmr_swap_amount);
|
|
||||||
//let xmr_redeem = XmrRedeem::new(s_a, PrivateKey::from_scalar(bob.s_b), alice.v_a, alice.v_b, xmr_swap_amount);
|
|
||||||
let xmr_refund = XmrRefund::new(sig, xmr_swap_amount);
|
|
||||||
|
|
||||||
// Alice publishes xmr_lock
|
|
||||||
let xmr_lock_transfer_proof = alice_monero_wallet
|
|
||||||
.transfer(xmr_lock.transfer_request())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Bob waits until xmr_lock is seen
|
|
||||||
let _ = bob_monero_wallet
|
|
||||||
.watch_for_transfer(xmr_lock.watch_request(xmr_lock_transfer_proof))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Bob publishes btc_lock
|
|
||||||
let signed_tx_lock = bob_bitcoin_wallet
|
|
||||||
.sign_and_finalize(btc_lock.clone().into())
|
|
||||||
.await?;
|
|
||||||
let (_txid, sub) = bob_bitcoin_wallet.broadcast(signed_tx_lock, "lock").await.unwrap();
|
|
||||||
let _ = sub.wait_until_confirmed_with(1).await?;
|
|
||||||
|
|
||||||
// alice publishes xmr_refund
|
|
||||||
// let xmr_refund_transfer_proof = alice_monero_wallet
|
|
||||||
// .transfer(xmr_refund.transfer_request())
|
|
||||||
// .await
|
|
||||||
// .unwrap();
|
|
||||||
|
|
||||||
// alice publishes btc_redeem
|
|
||||||
btc_redeem.encsig((), ());
|
|
||||||
let (_, btc_redeem_sub) = alice_bitcoin_wallet.broadcast(btc_redeem.build_transaction(alice.a, alice.s_a, alice.pk_b, btc_lock.), "redeem")
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// bob sees xmr_refund and btc_redeem
|
|
||||||
let _ = bob_monero_wallet
|
|
||||||
.watch_for_transfer(xmr_lock.watch_request(xmr_refund_transfer_proof))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let _ = btc_redeem_sub.wait_until_seen()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// extract r_a from xmr_refund
|
|
||||||
let _ = bob_bitcoin_wallet.broadcast("redeem")
|
|
||||||
}
|
|
@ -1,155 +1,151 @@
|
|||||||
// pub mod harness;
|
pub mod harness;
|
||||||
//
|
|
||||||
// use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
// use swap::env::GetConfig;
|
use swap::env::GetConfig;
|
||||||
// use swap::monero;
|
use swap::monero;
|
||||||
// use swap::protocol::alice::event_loop::FixedRate;
|
use swap::protocol::alice::event_loop::FixedRate;
|
||||||
// use swap::protocol::CROSS_CURVE_PROOF_SYSTEM;
|
use swap::protocol::CROSS_CURVE_PROOF_SYSTEM;
|
||||||
// use swap::seed::Seed;
|
use swap::seed::Seed;
|
||||||
// use swap::xmr_first_protocol::alice::Alice3;
|
use swap::xmr_first_protocol::alice::Alice3;
|
||||||
// use swap::xmr_first_protocol::bob::Bob3;
|
use swap::xmr_first_protocol::bob::Bob3;
|
||||||
// use swap::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
use swap::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
||||||
// use swap::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
use swap::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
||||||
// use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
// use testcontainers::clients::Cli;
|
use testcontainers::clients::Cli;
|
||||||
// use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
//
|
|
||||||
// #[tokio::test]
|
#[tokio::test]
|
||||||
// async fn happy_path() {
|
async fn happy_path() {
|
||||||
// let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
//
|
|
||||||
// let env_config = harness::SlowCancelConfig::get_config();
|
let env_config = harness::SlowCancelConfig::get_config();
|
||||||
//
|
|
||||||
// let (monero, containers) = harness::init_containers(&cli).await;
|
let (monero, containers) = harness::init_containers(&cli).await;
|
||||||
//
|
|
||||||
// let btc_swap_amount = bitcoin::Amount::from_sat(1_000_000);
|
let btc_swap_amount = bitcoin::Amount::from_sat(1_000_000);
|
||||||
// let xmr_swap_amount =
|
let xmr_swap_amount =
|
||||||
// monero::Amount::from_monero(btc_swap_amount.as_btc() /
|
monero::Amount::from_monero(btc_swap_amount.as_btc() / FixedRate::RATE).unwrap();
|
||||||
// FixedRate::RATE).unwrap();
|
|
||||||
//
|
let alice_starting_balances = harness::StartingBalances {
|
||||||
// let alice_starting_balances = harness::StartingBalances {
|
xmr: xmr_swap_amount * 10,
|
||||||
// xmr: xmr_swap_amount * 10,
|
btc: bitcoin::Amount::ZERO,
|
||||||
// btc: bitcoin::Amount::ZERO,
|
};
|
||||||
// };
|
|
||||||
//
|
let electrs_rpc_port = containers
|
||||||
// let electrs_rpc_port = containers
|
.electrs
|
||||||
// .electrs
|
.get_host_port(harness::electrs::RPC_PORT)
|
||||||
// .get_host_port(harness::electrs::RPC_PORT)
|
.expect("Could not map electrs rpc port");
|
||||||
// .expect("Could not map electrs rpc port");
|
|
||||||
//
|
let alice_seed = Seed::random().unwrap();
|
||||||
// let alice_seed = Seed::random().unwrap();
|
let (alice_bitcoin_wallet, alice_monero_wallet) = harness::init_test_wallets(
|
||||||
// let (alice_bitcoin_wallet, alice_monero_wallet) =
|
"Alice",
|
||||||
// harness::init_test_wallets( "Alice",
|
containers.bitcoind_url.clone(),
|
||||||
// containers.bitcoind_url.clone(),
|
&monero,
|
||||||
// &monero,
|
alice_starting_balances.clone(),
|
||||||
// alice_starting_balances.clone(),
|
tempdir().unwrap().path(),
|
||||||
// tempdir().unwrap().path(),
|
electrs_rpc_port,
|
||||||
// electrs_rpc_port,
|
&alice_seed,
|
||||||
// &alice_seed,
|
env_config.clone(),
|
||||||
// env_config.clone(),
|
)
|
||||||
// )
|
.await;
|
||||||
// .await;
|
|
||||||
//
|
let bob_seed = Seed::random().unwrap();
|
||||||
// let bob_seed = Seed::random().unwrap();
|
let bob_starting_balances = harness::StartingBalances {
|
||||||
// let bob_starting_balances = harness::StartingBalances {
|
xmr: monero::Amount::ZERO,
|
||||||
// xmr: monero::Amount::ZERO,
|
btc: btc_swap_amount * 10,
|
||||||
// btc: btc_swap_amount * 10,
|
};
|
||||||
// };
|
|
||||||
//
|
let (bob_bitcoin_wallet, bob_monero_wallet) = harness::init_test_wallets(
|
||||||
// let (bob_bitcoin_wallet, bob_monero_wallet) = harness::init_test_wallets(
|
"Bob",
|
||||||
// "Bob",
|
containers.bitcoind_url,
|
||||||
// containers.bitcoind_url,
|
&monero,
|
||||||
// &monero,
|
bob_starting_balances.clone(),
|
||||||
// bob_starting_balances.clone(),
|
tempdir().unwrap().path(),
|
||||||
// tempdir().unwrap().path(),
|
electrs_rpc_port,
|
||||||
// electrs_rpc_port,
|
&bob_seed,
|
||||||
// &bob_seed,
|
env_config,
|
||||||
// env_config,
|
)
|
||||||
// )
|
.await;
|
||||||
// .await;
|
|
||||||
//
|
let a = swap::bitcoin::SecretKey::new_random(&mut OsRng);
|
||||||
// let a = swap::bitcoin::SecretKey::new_random(&mut OsRng);
|
let b = swap::bitcoin::SecretKey::new_random(&mut OsRng);
|
||||||
// let b = swap::bitcoin::SecretKey::new_random(&mut OsRng);
|
|
||||||
//
|
let s_a = monero::Scalar::random(&mut OsRng);
|
||||||
// let s_a = monero::Scalar::random(&mut OsRng);
|
let S_a = monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: s_a });
|
||||||
// let S_a = monero::PublicKey::from_private_key(&monero::PrivateKey {
|
|
||||||
// scalar: s_a });
|
let s_b = monero::Scalar::random(&mut OsRng);
|
||||||
//
|
let S_b = monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: s_b });
|
||||||
// let s_b = monero::Scalar::random(&mut OsRng);
|
|
||||||
// let S_b = monero::PublicKey::from_private_key(&monero::PrivateKey {
|
let (dleq_proof_s_b, (S_b_bitcoin, S_b_monero)) =
|
||||||
// scalar: s_b });
|
CROSS_CURVE_PROOF_SYSTEM.prove(&s_b, &mut OsRng);
|
||||||
//
|
|
||||||
// let (dleq_proof_s_b, (S_b_bitcoin, S_b_monero)) =
|
let (dleq_proof_s_b, (S_a_bitcoin, S_a_monero)) =
|
||||||
// CROSS_CURVE_PROOF_SYSTEM.prove(&s_b, &mut OsRng);
|
CROSS_CURVE_PROOF_SYSTEM.prove(&s_a, &mut OsRng);
|
||||||
//
|
|
||||||
// let (dleq_proof_s_b, (S_a_bitcoin, S_a_monero)) =
|
let v_a = monero::PrivateViewKey::new_random(&mut OsRng);
|
||||||
// CROSS_CURVE_PROOF_SYSTEM.prove(&s_a, &mut OsRng);
|
let v_b = monero::PrivateViewKey::new_random(&mut OsRng);
|
||||||
//
|
|
||||||
// let v_a = monero::PrivateViewKey::new_random(&mut OsRng);
|
let btc_redeem_address = bob_bitcoin_wallet.new_address().await.unwrap();
|
||||||
// let v_b = monero::PrivateViewKey::new_random(&mut OsRng);
|
|
||||||
//
|
let tx_lock = BtcLock::new(&bob_bitcoin_wallet, btc_swap_amount, a.public(), b.public())
|
||||||
// let btc_redeem_address = bob_bitcoin_wallet.new_address().await.unwrap();
|
.await
|
||||||
//
|
.unwrap();
|
||||||
// let tx_lock = BtcLock::new(&bob_bitcoin_wallet, btc_swap_amount,
|
|
||||||
// a.public(), b.public()) .await
|
let tx_redeem = BtcRedeem::new(&tx_lock, &btc_redeem_address);
|
||||||
// .unwrap();
|
|
||||||
//
|
let encsig = tx_redeem.encsig(b.clone(), swap::bitcoin::PublicKey::from(S_a_bitcoin));
|
||||||
// let tx_redeem = BtcRedeem::new(&tx_lock, &btc_redeem_address);
|
|
||||||
//
|
let alice = Alice3 {
|
||||||
// let encsig = tx_redeem.encsig(b.clone(),
|
xmr_swap_amount,
|
||||||
// swap::bitcoin::PublicKey::from(S_a_bitcoin));
|
btc_swap_amount,
|
||||||
//
|
a: a.clone(),
|
||||||
// let alice = Alice3 {
|
B: b.public(),
|
||||||
// xmr_swap_amount,
|
s_a,
|
||||||
// btc_swap_amount,
|
S_b_monero: monero::PublicKey {
|
||||||
// a: a.clone(),
|
point: S_b_monero.compress(),
|
||||||
// B: b.public(),
|
},
|
||||||
// s_a,
|
v_a,
|
||||||
// S_b_monero: monero::PublicKey {
|
redeem_address: alice_bitcoin_wallet.new_address().await.unwrap(),
|
||||||
// point: S_b_monero.compress(),
|
};
|
||||||
// },
|
|
||||||
// v_a,
|
let bob = Bob3 {
|
||||||
// redeem_address: alice_bitcoin_wallet.new_address().await.unwrap(),
|
b,
|
||||||
// };
|
A: a.public(),
|
||||||
//
|
s_b,
|
||||||
// let bob = Bob3 {
|
xmr_swap_amount,
|
||||||
// b,
|
btc_swap_amount,
|
||||||
// A: a.public(),
|
tx_lock,
|
||||||
// s_b,
|
S: S_b,
|
||||||
// xmr_swap_amount,
|
S_a_bitcoin: swap::bitcoin::PublicKey::from(S_b_bitcoin),
|
||||||
// btc_swap_amount,
|
alice_redeem_address: bob_bitcoin_wallet.new_address().await.unwrap(),
|
||||||
// tx_lock,
|
v: v_b,
|
||||||
// S: S_b,
|
};
|
||||||
// S_a_bitcoin: swap::bitcoin::PublicKey::from(S_b_bitcoin),
|
|
||||||
// alice_redeem_address:
|
let alice = alice.publish_xmr_lock(&alice_monero_wallet).await.unwrap();
|
||||||
// bob_bitcoin_wallet.new_address().await.unwrap(), v: v_b,
|
|
||||||
// };
|
// also publishes lock btc
|
||||||
//
|
let bob = bob
|
||||||
// let alice = alice.publish_xmr_lock(&alice_monero_wallet).await.unwrap();
|
.watch_for_lock_xmr(
|
||||||
//
|
&bob_monero_wallet,
|
||||||
// // also publishes lock btc
|
&bob_bitcoin_wallet,
|
||||||
// let bob = bob
|
alice.transfer_proof.clone(),
|
||||||
// .watch_for_lock_xmr(
|
btc_redeem_address,
|
||||||
// &bob_monero_wallet,
|
)
|
||||||
// &bob_bitcoin_wallet,
|
.await
|
||||||
// alice.transfer_proof.clone(),
|
.unwrap();
|
||||||
// btc_redeem_address,
|
|
||||||
// )
|
let alice = alice
|
||||||
// .await
|
.watch_for_btc_lock(&alice_bitcoin_wallet)
|
||||||
// .unwrap();
|
.await
|
||||||
//
|
.unwrap();
|
||||||
// let alice = alice
|
|
||||||
// .watch_for_btc_lock(&alice_bitcoin_wallet)
|
let _ = alice
|
||||||
// .await
|
.publish_btc_redeem(&alice_bitcoin_wallet, encsig)
|
||||||
// .unwrap();
|
.await
|
||||||
//
|
.unwrap();
|
||||||
// let _ = alice
|
|
||||||
// .publish_btc_redeem(&alice_bitcoin_wallet, encsig)
|
let swap_id = Uuid::new_v4();
|
||||||
// .await
|
bob.redeem_xmr_when_btc_redeem_seen(&bob_bitcoin_wallet, &bob_monero_wallet, swap_id)
|
||||||
// .unwrap();
|
.await
|
||||||
//
|
.unwrap();
|
||||||
// let swap_id = Uuid::new_v4();
|
}
|
||||||
// bob.redeem_xmr_when_btc_redeem_seen(&bob_bitcoin_wallet,
|
|
||||||
// &bob_monero_wallet, swap_id) .await
|
|
||||||
// .unwrap();
|
|
||||||
// }
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user