signing clients for coconut bandwidth and dkg

This commit is contained in:
Jędrzej Stuczyński
2023-08-02 17:18:22 +01:00
parent 9e40763f7f
commit cc6fdfa110
4 changed files with 106 additions and 4 deletions
@@ -64,6 +64,22 @@ pub trait CoconutBandwidthSigningClient {
)
.await
}
async fn release_funds(
&self,
amount: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
self.execute_coconut_bandwidth_contract(
fee,
CoconutBandwidthExecuteMsg::ReleaseFunds {
funds: amount.into(),
},
"CoconutBandwidth::ReleaseFunds".to_string(),
vec![],
)
.await
}
}
#[async_trait]
@@ -101,12 +117,35 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::nyxd::contract_traits::tests::{mock_coin, IgnoreValue};
// it's enough that this compiles and clippy is happy about it
async fn all_execute_variants_are_covered<C: CoconutBandwidthSigningClient + Send + Sync>(
#[allow(dead_code)]
fn all_execute_variants_are_covered<C: CoconutBandwidthSigningClient + Send + Sync>(
client: C,
msg: CoconutBandwidthExecuteMsg,
) {
unimplemented!()
match msg {
CoconutBandwidthExecuteMsg::DepositFunds { data } => client
.deposit(
mock_coin(),
data.deposit_info().to_string(),
data.identity_key().to_string(),
data.encryption_key().to_string(),
None,
)
.ignore(),
CoconutBandwidthExecuteMsg::SpendCredential { data } => client
.spend_credential(
mock_coin(),
data.blinded_serial_number().to_string(),
data.gateway_cosmos_address().to_string(),
None,
)
.ignore(),
CoconutBandwidthExecuteMsg::ReleaseFunds { funds } => {
client.release_funds(mock_coin(), None).ignore()
}
};
}
}
@@ -7,6 +7,8 @@ use crate::nyxd::error::NyxdError;
use crate::nyxd::{Coin, Fee, SigningCosmWasmClient};
use crate::signing::signer::OfflineSigner;
use async_trait::async_trait;
use cosmrs::AccountId;
use cosmwasm_std::Addr;
use nym_coconut_dkg_common::msg::ExecuteMsg as DkgExecuteMsg;
use nym_coconut_dkg_common::types::EncodedBTEPublicKeyWithProof;
use nym_coconut_dkg_common::verification_key::VerificationKeyShare;
@@ -29,6 +31,13 @@ pub trait DkgSigningClient {
.await
}
async fn surpass_threshold(&self, fee: Option<Fee>) -> Result<ExecuteResult, NyxdError> {
let req = DkgExecuteMsg::SurpassedThreshold {};
self.execute_dkg_contract(fee, req, "surpass DKG threshold".to_string(), vec![])
.await
}
async fn register_dealer(
&self,
bte_key: EncodedBTEPublicKeyWithProof,
@@ -77,6 +86,25 @@ pub trait DkgSigningClient {
)
.await
}
async fn verify_verification_key_share(
&self,
owner: &AccountId,
resharing: bool,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
// the call to unchecked is fine as we're converting from pre-validated `AccountId`
let owner = Addr::unchecked(owner.to_string());
let req = DkgExecuteMsg::VerifyVerificationKeyShare { owner, resharing };
self.execute_dkg_contract(
fee,
req,
"verification key VerifyVerificationKeyShare".to_string(),
vec![],
)
.await
}
}
#[async_trait]
@@ -107,12 +135,40 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::nyxd::contract_traits::tests::IgnoreValue;
// it's enough that this compiles and clippy is happy about it
async fn all_execute_variants_are_covered<C: DkgSigningClient + Send + Sync>(
#[allow(dead_code)]
fn all_execute_variants_are_covered<C: DkgSigningClient + Send + Sync>(
client: C,
msg: DkgExecuteMsg,
) {
unimplemented!()
match msg {
DkgExecuteMsg::RegisterDealer {
bte_key_with_proof,
announce_address,
resharing,
} => client
.register_dealer(bte_key_with_proof, announce_address, resharing, None)
.ignore(),
DkgExecuteMsg::CommitDealing {
dealing_bytes,
resharing,
} => client
.submit_dealing_bytes(dealing_bytes, resharing, None)
.ignore(),
DkgExecuteMsg::CommitVerificationKeyShare { share, resharing } => client
.submit_verification_key_share(share, resharing, None)
.ignore(),
DkgExecuteMsg::VerifyVerificationKeyShare { owner, resharing } => client
.verify_verification_key_share(
&owner.into_string().parse().unwrap(),
resharing,
None,
)
.ignore(),
DkgExecuteMsg::SurpassedThreshold {} => client.surpass_threshold(None).ignore(),
DkgExecuteMsg::AdvanceEpochState {} => client.advance_dkg_epoch_state(None).ignore(),
};
}
}
@@ -158,6 +158,8 @@ macro_rules! collect_paged {
#[cfg(test)]
mod tests {
use crate::nyxd::Coin;
pub(crate) trait IgnoreValue {
fn ignore(self) -> u32
where
@@ -170,4 +172,8 @@ mod tests {
}
impl<T> IgnoreValue for T {}
pub(crate) fn mock_coin() -> Coin {
Coin::new(42, "ufoomp")
}
}
@@ -42,6 +42,7 @@ pub enum ExecuteMsg {
},
VerifyVerificationKeyShare {
// TODO: this should be using a String...
owner: Addr,
resharing: bool,
},