Move generation of keys inside State0::new

The event loop will now use this function so I want to simplify its
usage to avoid having to instantiate too many items to use it.
This commit is contained in:
Franck Royer 2021-02-04 17:01:08 +11:00
parent 788445964a
commit fd084b764d
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 14 additions and 24 deletions

View File

@ -175,30 +175,20 @@ impl Builder {
btc_to_swap: bitcoin::Amount,
xmr_to_swap: monero::Amount,
) -> Result<AliceState> {
let rng = &mut OsRng;
let amounts = SwapAmounts {
btc: btc_to_swap,
xmr: xmr_to_swap,
};
let a = bitcoin::SecretKey::new_random(rng);
let s_a = cross_curve_dleq::Scalar::random(rng);
let v_a = monero::PrivateViewKey::new_random(rng);
let redeem_address = self.bitcoin_wallet.new_address().await?;
let punish_address = redeem_address.clone();
let state0 = State0::new(
a,
s_a,
v_a,
amounts.btc,
amounts.xmr,
self.execution_params.bitcoin_cancel_timelock,
self.execution_params.bitcoin_punish_timelock,
redeem_address,
punish_address,
rng,
);
self.bitcoin_wallet.as_ref(),
&mut OsRng,
)
.await?;
Ok(AliceState::Started { amounts, state0 })
}

View File

@ -101,25 +101,25 @@ pub struct State0 {
}
impl State0 {
#[allow(clippy::too_many_arguments)]
pub fn new<R>(
a: bitcoin::SecretKey,
s_a: cross_curve_dleq::Scalar,
v_a: monero::PrivateViewKey,
pub async fn new<R>(
btc: bitcoin::Amount,
xmr: monero::Amount,
cancel_timelock: Timelock,
punish_timelock: Timelock,
redeem_address: bitcoin::Address,
punish_address: bitcoin::Address,
bitcoin_wallet: &bitcoin::Wallet,
rng: &mut R,
) -> Self
) -> Result<Self>
where
R: RngCore + CryptoRng,
{
let a = bitcoin::SecretKey::new_random(rng);
let s_a = cross_curve_dleq::Scalar::random(rng);
let v_a = monero::PrivateViewKey::new_random(rng);
let redeem_address = bitcoin_wallet.new_address().await?;
let punish_address = redeem_address.clone();
let dleq_proof_s_a = cross_curve_dleq::Proof::new(rng, &s_a);
Self {
Ok(Self {
a,
s_a,
v_a,
@ -130,7 +130,7 @@ impl State0 {
xmr,
cancel_timelock,
punish_timelock,
}
})
}
pub fn receive(self, msg: Message0) -> Result<State1> {