parent
815a752c88
commit
8272e1c247
@ -1,4 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2021-04-15"
|
||||
channel = "nightly-2021-05-17"
|
||||
components = ["rustfmt", "clippy"]
|
||||
targets = ["armv7-unknown-linux-gnueabihf"]
|
||||
|
@ -1,14 +1,116 @@
|
||||
use crate::bitcoin::Txid;
|
||||
use crate::protocol::CROSS_CURVE_PROOF_SYSTEM;
|
||||
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use ecdsa_fun::fun::Point;
|
||||
use hash_edwards_to_edwards::hash_point_to_point;
|
||||
use monero_adaptor::AdaptorSignature;
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
pub mod alice;
|
||||
pub mod bob;
|
||||
mod state_machine;
|
||||
mod transactions;
|
||||
pub mod transactions;
|
||||
|
||||
pub struct SeenBtcLock {
|
||||
s_0_b: crate::monero::Scalar,
|
||||
pub adaptor_sig: AdaptorSignature,
|
||||
tx_lock_id: Txid,
|
||||
tx_lock: bitcoin::Transaction,
|
||||
pub struct Alice {
|
||||
pub a: crate::bitcoin::SecretKey,
|
||||
pub s_a: crate::monero::Scalar,
|
||||
r_a: Scalar,
|
||||
// private view keys
|
||||
pub v_a: crate::monero::PrivateViewKey,
|
||||
pub v_b: crate::monero::PrivateViewKey,
|
||||
pub S_a: EdwardsPoint,
|
||||
pub S_b: crate::monero::PublicKey,
|
||||
pub R_a: EdwardsPoint,
|
||||
pub S_prime_a: Point,
|
||||
pub R_prime_a: EdwardsPoint,
|
||||
pub pk_a: crate::bitcoin::PublicKey,
|
||||
pub pk_b: crate::bitcoin::PublicKey,
|
||||
pub K_a: crate::monero::PublicViewKey,
|
||||
pub K_b: crate::monero::PublicViewKey,
|
||||
}
|
||||
|
||||
pub struct Bob {
|
||||
b: crate::bitcoin::SecretKey,
|
||||
pub s_b: crate::monero::Scalar,
|
||||
// private view keys
|
||||
pub v_a: crate::monero::PrivateViewKey,
|
||||
pub v_b: crate::monero::PrivateViewKey,
|
||||
pub S_a: EdwardsPoint,
|
||||
pub S_b: crate::monero::PublicKey,
|
||||
pub R_a: EdwardsPoint,
|
||||
pub S_prime_a: Point,
|
||||
pub R_prime_a: EdwardsPoint,
|
||||
pub pk_a: crate::bitcoin::PublicKey,
|
||||
pub pk_b: crate::bitcoin::PublicKey,
|
||||
pub K_a: crate::monero::PublicViewKey,
|
||||
pub K_b: crate::monero::PublicViewKey,
|
||||
}
|
||||
|
||||
pub fn setup() -> (Alice, Bob) {
|
||||
let v_a = crate::monero::PrivateViewKey::new_random(&mut OsRng);
|
||||
let v_b = crate::monero::PrivateViewKey::new_random(&mut OsRng);
|
||||
|
||||
let a = crate::bitcoin::SecretKey::new_random(&mut OsRng);
|
||||
let b = crate::bitcoin::SecretKey::new_random(&mut OsRng);
|
||||
|
||||
let s_a = crate::monero::Scalar::random(&mut OsRng);
|
||||
|
||||
let s_b = crate::monero::Scalar::random(&mut OsRng);
|
||||
let S_b = monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: s_b });
|
||||
|
||||
let (_dleq_proof_s_a, (S_prime_a, S_a)) = CROSS_CURVE_PROOF_SYSTEM.prove(&s_a, &mut OsRng);
|
||||
|
||||
let (r_a, R_a, R_prime_a) = {
|
||||
let r_a = Scalar::random(&mut OsRng);
|
||||
let R_a = r_a * ED25519_BASEPOINT_POINT;
|
||||
|
||||
let pk_hashed_to_point = hash_point_to_point(S_a);
|
||||
|
||||
let R_prime_a = r_a * pk_hashed_to_point;
|
||||
|
||||
(r_a, R_a, R_prime_a)
|
||||
};
|
||||
|
||||
let K_a = v_a.public();
|
||||
let K_b = v_b.public();
|
||||
|
||||
let pk_a = a.public();
|
||||
let pk_b = b.public();
|
||||
|
||||
let alice = Alice {
|
||||
a,
|
||||
v_a,
|
||||
v_b,
|
||||
s_a,
|
||||
S_a,
|
||||
S_b,
|
||||
r_a,
|
||||
R_a,
|
||||
S_prime_a,
|
||||
R_prime_a,
|
||||
pk_a,
|
||||
pk_b,
|
||||
K_a,
|
||||
K_b,
|
||||
};
|
||||
|
||||
let bob = Bob {
|
||||
b,
|
||||
v_a,
|
||||
v_b,
|
||||
s_b,
|
||||
S_a,
|
||||
S_b,
|
||||
R_a,
|
||||
S_prime_a,
|
||||
R_prime_a,
|
||||
pk_a,
|
||||
pk_b,
|
||||
K_a,
|
||||
K_b,
|
||||
};
|
||||
|
||||
(alice, bob)
|
||||
}
|
||||
|
@ -1,35 +1,147 @@
|
||||
use crate::monero::wallet::{TransferRequest, WatchRequest};
|
||||
use crate::monero::TransferProof;
|
||||
use crate::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
||||
use crate::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
||||
use anyhow::Result;
|
||||
use monero::PublicKey;
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
use monero_adaptor::alice::Alice2;
|
||||
use monero_adaptor::AdaptorSignature;
|
||||
|
||||
use crate::bitcoin::Txid;
|
||||
use crate::monero::wallet::WatchRequest;
|
||||
use crate::monero::{Scalar, TransferRequest};
|
||||
use crate::xmr_first_protocol::transactions::xmr_lock::XmrLock;
|
||||
use monero_rpc::wallet::BlockHeight;
|
||||
use uuid::Uuid;
|
||||
|
||||
// watching for xmr_lock
|
||||
pub struct Bob3 {
|
||||
pub b: crate::bitcoin::SecretKey,
|
||||
pub A: crate::bitcoin::PublicKey,
|
||||
pub s_b: crate::monero::Scalar,
|
||||
pub xmr_swap_amount: crate::monero::Amount,
|
||||
pub btc_swap_amount: crate::bitcoin::Amount,
|
||||
pub xmr_lock: XmrLock,
|
||||
v_b: crate::monero::PrivateViewKey,
|
||||
pub tx_lock: BtcLock,
|
||||
// public spend key
|
||||
pub S: crate::monero::PublicKey,
|
||||
pub S_a_bitcoin: crate::bitcoin::PublicKey,
|
||||
pub v: crate::monero::PrivateViewKey,
|
||||
pub alice_redeem_address: bitcoin::Address,
|
||||
}
|
||||
|
||||
impl Bob3 {
|
||||
pub fn watch_for_lock_xmr(&self, wallet: &crate::monero::Wallet) {
|
||||
pub async fn watch_for_lock_xmr(
|
||||
&self,
|
||||
xmr_wallet: &crate::monero::Wallet,
|
||||
btc_wallet: &crate::bitcoin::Wallet,
|
||||
transfer_proof: TransferProof,
|
||||
alice_redeem_address: bitcoin::Address,
|
||||
) -> Result<Bob4> {
|
||||
let req = WatchRequest {
|
||||
public_spend_key: self.xmr_lock.public_spend_key,
|
||||
public_view_key: self.v_b.public(),
|
||||
transfer_proof: self.xmr_lock.transfer_proof.clone(),
|
||||
public_spend_key: self.S,
|
||||
public_view_key: self.v.public(),
|
||||
transfer_proof,
|
||||
conf_target: 1,
|
||||
expected: self.xmr_swap_amount,
|
||||
};
|
||||
wallet.watch_for_transfer(req);
|
||||
let _ = xmr_wallet.watch_for_transfer(req).await?;
|
||||
|
||||
let signed_tx_lock = btc_wallet
|
||||
.sign_and_finalize(self.tx_lock.clone().into())
|
||||
.await?;
|
||||
|
||||
let (_txid, sub) = btc_wallet.broadcast(signed_tx_lock, "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,
|
||||
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
|
||||
pub struct Bob4 {
|
||||
pub b: crate::bitcoin::SecretKey,
|
||||
pub A: crate::bitcoin::PublicKey,
|
||||
pub s_b: crate::monero::Scalar,
|
||||
pub S_a_bitcoin: crate::bitcoin::PublicKey,
|
||||
pub tx_lock: BtcLock,
|
||||
pub alice_redeem_address: crate::bitcoin::Address,
|
||||
pub v: crate::monero::PrivateViewKey,
|
||||
}
|
||||
|
||||
// published btc_lock, watching for xmr_redeem
|
||||
pub struct Bob4;
|
||||
impl Bob4 {
|
||||
pub async fn redeem_xmr_when_btc_redeem_seen(
|
||||
&self,
|
||||
bitcoin_wallet: &crate::bitcoin::Wallet,
|
||||
monero_wallet: &crate::monero::Wallet,
|
||||
swap_id: Uuid,
|
||||
) -> Result<()> {
|
||||
let btc_redeem = BtcRedeem::new(&self.tx_lock, &self.alice_redeem_address);
|
||||
let btc_redeem_encsig = self.b.encsign(self.S_a_bitcoin, btc_redeem.digest());
|
||||
|
||||
let btc_redeem_watcher = bitcoin_wallet.subscribe_to(btc_redeem.clone()).await;
|
||||
|
||||
btc_redeem_watcher.wait_until_confirmed_with(1).await?;
|
||||
|
||||
let btc_redeem_candidate = bitcoin_wallet
|
||||
.get_raw_transaction(btc_redeem.txid())
|
||||
.await?;
|
||||
|
||||
let btc_redeem_sig =
|
||||
btc_redeem.extract_signature_by_key(btc_redeem_candidate, self.b.public())?;
|
||||
let s_a = crate::bitcoin::recover(self.S_a_bitcoin, btc_redeem_sig, btc_redeem_encsig)?;
|
||||
let s_a = crate::monero::private_key_from_secp256k1_scalar(s_a.into());
|
||||
|
||||
let (spend_key, view_key) = {
|
||||
let s_b = monero::PrivateKey { scalar: self.s_b };
|
||||
let s = s_a + s_b;
|
||||
|
||||
(s, self.v)
|
||||
};
|
||||
|
||||
monero_wallet
|
||||
.create_from_and_load(
|
||||
&swap_id.to_string(),
|
||||
spend_key,
|
||||
view_key,
|
||||
monero_rpc::wallet::BlockHeight { height: 0 },
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
pub mod btc_lock;
|
||||
// pub mod btc_redeem;
|
||||
pub mod xmr_lock;
|
||||
pub mod xmr_refund;
|
||||
|
||||
use crate::bitcoin::wallet::Watchable;
|
||||
use crate::bitcoin::{
|
||||
build_shared_output_descriptor, Address, Amount, PartiallySignedTransaction, PublicKey,
|
||||
Transaction, Txid, Wallet, TX_FEE,
|
||||
};
|
||||
use anyhow::{bail, Result};
|
||||
use bdk::bitcoin::{OutPoint, Script, TxIn, TxOut};
|
||||
use bdk::database::BatchDatabase;
|
||||
use bdk::descriptor::Descriptor;
|
||||
use ecdsa_fun::fun::Point;
|
||||
use miniscript::DescriptorTrait;
|
||||
use rand::thread_rng;
|
@ -0,0 +1,6 @@
|
||||
pub mod btc_emergency_refund;
|
||||
pub mod btc_lock;
|
||||
pub mod btc_redeem;
|
||||
pub mod xmr_lock;
|
||||
pub mod xmr_redeem;
|
||||
pub mod xmr_refund;
|
@ -1,7 +1,59 @@
|
||||
use crate::monero::{PrivateViewKey, PublicKey, TransferProof};
|
||||
use crate::monero::wallet::{TransferRequest, WatchRequest};
|
||||
use crate::monero::{Amount, PrivateViewKey, Scalar, TransferProof};
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
use monero::PublicKey;
|
||||
|
||||
pub struct XmrLock {
|
||||
pub public_spend_key: PublicKey,
|
||||
pub public_view_key: PrivateViewKey,
|
||||
pub transfer_proof: TransferProof,
|
||||
S_a: monero::PublicKey,
|
||||
S_b: monero::PublicKey,
|
||||
v_a: PrivateViewKey,
|
||||
v_b: PrivateViewKey,
|
||||
D: EdwardsPoint,
|
||||
amount: Amount,
|
||||
}
|
||||
|
||||
impl XmrLock {
|
||||
pub fn new(
|
||||
S_a: monero::PublicKey,
|
||||
S_b: monero::PublicKey,
|
||||
v_a: PrivateViewKey,
|
||||
v_b: PrivateViewKey,
|
||||
D: EdwardsPoint,
|
||||
amount: Amount,
|
||||
) -> Self {
|
||||
Self {
|
||||
S_a,
|
||||
S_b,
|
||||
v_a,
|
||||
v_b,
|
||||
D,
|
||||
amount,
|
||||
}
|
||||
}
|
||||
pub fn transfer_request(&self) -> TransferRequest {
|
||||
let vk = self.S_a + self.S_b;
|
||||
let v = self.v_a + self.v_b;
|
||||
|
||||
// use from KeyGenerator from monero.rs to do the H(vD) bit for the on time
|
||||
// address
|
||||
let one_time_address = todo!("KeyGenerator.random().one_time_key(self.D)");
|
||||
|
||||
TransferRequest {
|
||||
public_spend_key: one_time_address,
|
||||
public_view_key: v.public(),
|
||||
amount: self.amount,
|
||||
}
|
||||
}
|
||||
pub fn watch_request(&self, transfer_proof: TransferProof) -> WatchRequest {
|
||||
let public_spend_key = self.S_a + self.S_b;
|
||||
let private_view_key = self.v_a + self.v_b;
|
||||
|
||||
WatchRequest {
|
||||
public_spend_key,
|
||||
public_view_key: private_view_key.public(),
|
||||
transfer_proof,
|
||||
conf_target: 1,
|
||||
expected: self.amount,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
use crate::monero::wallet::{TransferRequest, WatchRequest};
|
||||
use crate::monero::{Amount, PrivateKey, PrivateViewKey, Scalar, TransferProof};
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
use monero::PublicKey;
|
||||
|
||||
pub struct XmrRedeem {
|
||||
// recover s_a from btc_redeem
|
||||
s_a: monero::PrivateKey,
|
||||
s_b: monero::PrivateKey,
|
||||
v_a: PrivateViewKey,
|
||||
v_b: PrivateViewKey,
|
||||
// D: EdwardsPoint,
|
||||
amount: Amount,
|
||||
}
|
||||
|
||||
impl XmrRedeem {
|
||||
pub fn new(
|
||||
s_a: monero::PrivateKey,
|
||||
s_b: monero::PrivateKey,
|
||||
v_a: PrivateViewKey,
|
||||
v_b: PrivateViewKey,
|
||||
// D: EdwardsPoint,
|
||||
amount: Amount,
|
||||
) -> Self {
|
||||
Self {
|
||||
s_a,
|
||||
s_b,
|
||||
v_a,
|
||||
v_b,
|
||||
// D,
|
||||
amount,
|
||||
}
|
||||
}
|
||||
pub fn transfer_request(&self) -> TransferRequest {
|
||||
let v = self.v_a + self.v_b;
|
||||
// let h = self.D * v_view;
|
||||
// let private_spend_key = self.s_a + self.s_b + h;
|
||||
let vk = self.s_a + self.s_b;
|
||||
|
||||
TransferRequest {
|
||||
public_spend_key: PublicKey::from_private_key(&vk),
|
||||
public_view_key: v.public(),
|
||||
amount: self.amount,
|
||||
}
|
||||
}
|
||||
pub fn watch_request(&self, transfer_proof: TransferProof) -> WatchRequest {
|
||||
let private_spend_key = self.s_a + self.s_b;
|
||||
let private_view_key = self.v_a + self.v_b;
|
||||
|
||||
WatchRequest {
|
||||
public_spend_key: PublicKey::from_private_key(&private_spend_key),
|
||||
public_view_key: private_view_key.public(),
|
||||
transfer_proof,
|
||||
conf_target: 1,
|
||||
expected: self.amount,
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +1,43 @@
|
||||
use crate::monero::TransferRequest;
|
||||
use crate::monero::wallet::WatchRequest;
|
||||
use crate::monero::{Amount, PrivateViewKey, Scalar};
|
||||
use crate::xmr_first_protocol::alice::Alice4;
|
||||
use anyhow::Result;
|
||||
use monero_adaptor::AdaptorSignature;
|
||||
use monero_adaptor::Signature;
|
||||
|
||||
pub struct XmrRefund {
|
||||
adaptor: AdaptorSignature,
|
||||
signature: Signature,
|
||||
amount: Amount,
|
||||
}
|
||||
|
||||
impl XmrRefund {
|
||||
pub async fn publish_xmr_refund(&self, wallet: &crate::monero::Wallet) -> Result<()> {
|
||||
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();
|
||||
|
||||
let req = TransferRequest {
|
||||
public_spend_key,
|
||||
public_view_key,
|
||||
amount: self.xmr_swap_amount,
|
||||
};
|
||||
struct TransferRequest;
|
||||
|
||||
let _ = wallet.transfer(req).await?;
|
||||
Ok(())
|
||||
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,109 +1,155 @@
|
||||
pub mod harness;
|
||||
|
||||
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
use monero_adaptor::alice::Alice0;
|
||||
use monero_adaptor::bob::Bob0;
|
||||
use rand::rngs::OsRng;
|
||||
use swap::env::GetConfig;
|
||||
use swap::monero;
|
||||
use swap::monero::{PublicKey, Scalar};
|
||||
use swap::protocol::alice::event_loop::FixedRate;
|
||||
use swap::protocol::CROSS_CURVE_PROOF_SYSTEM;
|
||||
use swap::seed::Seed;
|
||||
use swap::xmr_first_protocol::alice::Alice3;
|
||||
use swap::xmr_first_protocol::bob::Bob3;
|
||||
use swap::xmr_first_protocol::{alice, bob};
|
||||
use tempfile::tempdir;
|
||||
use testcontainers::clients::Cli;
|
||||
|
||||
#[tokio::test]
|
||||
async fn happy_path() {
|
||||
let cli = Cli::default();
|
||||
|
||||
let env_config = harness::SlowCancelConfig::get_config();
|
||||
|
||||
let (monero, containers) = harness::init_containers(&cli).await;
|
||||
|
||||
let btc_amount = bitcoin::Amount::from_sat(1_000_000);
|
||||
let xmr_amount = monero::Amount::from_monero(btc_amount.as_btc() / FixedRate::RATE).unwrap();
|
||||
|
||||
let alice_starting_balances = harness::StartingBalances {
|
||||
xmr: xmr_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_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 a = crate::bitcoin::SecretKey::new_random(rng);
|
||||
let b = crate::bitcoin::SecretKey::new_random(rng);
|
||||
|
||||
let s_a = monero::Scalar::random(rng);
|
||||
let s_b = monero::Scalar::random(rng);
|
||||
|
||||
let (dleq_proof_s_b, (S_b_bitcoin, S_b_monero)) = CROSS_CURVE_PROOF_SYSTEM.prove(&s_b, rng);
|
||||
|
||||
let v_a = monero::PrivateViewKey::new_random(rng);
|
||||
let v_b = monero::PrivateViewKey::new_random(rng);
|
||||
|
||||
let alice = Alice3 {
|
||||
xmr_swap_amount: xmr_amount,
|
||||
btc_swap_amount: btc_amount,
|
||||
a,
|
||||
B: b.public(),
|
||||
s_a,
|
||||
S_b_monero,
|
||||
v_a,
|
||||
};
|
||||
|
||||
let bob = Bob3 {
|
||||
xmr_swap_amount,
|
||||
btc_swap_amount,
|
||||
xmr_lock,
|
||||
v_b,
|
||||
};
|
||||
|
||||
alice.publish_xmr_lock(&alice_monero_wallet).await.unwrap();
|
||||
|
||||
bob.watch_for_lock_xmr(&bob_monero_wallet_wallet)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
alice.publish_btc_redeem(&alice_btc_wallet).await.unwrap();
|
||||
|
||||
bob.publish_xmr_redeem(&alice_monero_wallet).await.unwrap();
|
||||
}
|
||||
// pub mod harness;
|
||||
//
|
||||
// use rand::rngs::OsRng;
|
||||
// use swap::env::GetConfig;
|
||||
// use swap::monero;
|
||||
// use swap::protocol::alice::event_loop::FixedRate;
|
||||
// use swap::protocol::CROSS_CURVE_PROOF_SYSTEM;
|
||||
// use swap::seed::Seed;
|
||||
// use swap::xmr_first_protocol::alice::Alice3;
|
||||
// use swap::xmr_first_protocol::bob::Bob3;
|
||||
// use swap::xmr_first_protocol::transactions::btc_lock::BtcLock;
|
||||
// use swap::xmr_first_protocol::transactions::btc_redeem::BtcRedeem;
|
||||
// use tempfile::tempdir;
|
||||
// use testcontainers::clients::Cli;
|
||||
// use uuid::Uuid;
|
||||
//
|
||||
// #[tokio::test]
|
||||
// async fn happy_path() {
|
||||
// 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 a = 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::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 (dleq_proof_s_b, (S_b_bitcoin, S_b_monero)) =
|
||||
// CROSS_CURVE_PROOF_SYSTEM.prove(&s_b, &mut OsRng);
|
||||
//
|
||||
// let (dleq_proof_s_b, (S_a_bitcoin, S_a_monero)) =
|
||||
// CROSS_CURVE_PROOF_SYSTEM.prove(&s_a, &mut OsRng);
|
||||
//
|
||||
// let v_a = monero::PrivateViewKey::new_random(&mut OsRng);
|
||||
// let v_b = monero::PrivateViewKey::new_random(&mut OsRng);
|
||||
//
|
||||
// let btc_redeem_address = bob_bitcoin_wallet.new_address().await.unwrap();
|
||||
//
|
||||
// let tx_lock = BtcLock::new(&bob_bitcoin_wallet, btc_swap_amount,
|
||||
// a.public(), b.public()) .await
|
||||
// .unwrap();
|
||||
//
|
||||
// let tx_redeem = BtcRedeem::new(&tx_lock, &btc_redeem_address);
|
||||
//
|
||||
// let encsig = tx_redeem.encsig(b.clone(),
|
||||
// swap::bitcoin::PublicKey::from(S_a_bitcoin));
|
||||
//
|
||||
// let alice = Alice3 {
|
||||
// xmr_swap_amount,
|
||||
// btc_swap_amount,
|
||||
// a: a.clone(),
|
||||
// B: b.public(),
|
||||
// s_a,
|
||||
// S_b_monero: monero::PublicKey {
|
||||
// point: S_b_monero.compress(),
|
||||
// },
|
||||
// v_a,
|
||||
// redeem_address: alice_bitcoin_wallet.new_address().await.unwrap(),
|
||||
// };
|
||||
//
|
||||
// let bob = Bob3 {
|
||||
// b,
|
||||
// A: a.public(),
|
||||
// s_b,
|
||||
// xmr_swap_amount,
|
||||
// btc_swap_amount,
|
||||
// tx_lock,
|
||||
// S: S_b,
|
||||
// S_a_bitcoin: swap::bitcoin::PublicKey::from(S_b_bitcoin),
|
||||
// alice_redeem_address:
|
||||
// bob_bitcoin_wallet.new_address().await.unwrap(), v: v_b,
|
||||
// };
|
||||
//
|
||||
// let alice = alice.publish_xmr_lock(&alice_monero_wallet).await.unwrap();
|
||||
//
|
||||
// // also publishes lock btc
|
||||
// let bob = bob
|
||||
// .watch_for_lock_xmr(
|
||||
// &bob_monero_wallet,
|
||||
// &bob_bitcoin_wallet,
|
||||
// alice.transfer_proof.clone(),
|
||||
// btc_redeem_address,
|
||||
// )
|
||||
// .await
|
||||
// .unwrap();
|
||||
//
|
||||
// let alice = alice
|
||||
// .watch_for_btc_lock(&alice_bitcoin_wallet)
|
||||
// .await
|
||||
// .unwrap();
|
||||
//
|
||||
// let _ = alice
|
||||
// .publish_btc_redeem(&alice_bitcoin_wallet, encsig)
|
||||
// .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…
Reference in new issue