mpc_client/protocols/
mod.rsuse crate::{Client, ClientOptions, EventLoop, Result, Transport};
use async_trait::async_trait;
use mpc_protocol::{hex, Event, Keypair, Parameters};
use serde::{Deserialize, Serialize};
mod bridge;
mod session;
#[cfg(feature = "cggmp")]
pub mod cggmp;
#[cfg(feature = "frost-ed25519")]
pub mod frost;
pub(crate) use bridge::Bridge;
pub use bridge::{
wait_for_close, wait_for_driver, wait_for_session_finish,
};
pub use session::{
wait_for_session, SessionEventHandler, SessionHandler,
SessionInitiator, SessionParticipant,
};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ServerOptions {
pub server_url: String,
#[serde(with = "hex::serde")]
pub server_public_key: Vec<u8>,
pub pattern: Option<String>,
}
#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionOptions {
pub keypair: Keypair,
pub server: ServerOptions,
pub parameters: Parameters,
}
#[async_trait]
pub trait Driver {
type Output;
async fn handle_event(
&mut self,
event: Event,
) -> Result<Option<Self::Output>>;
async fn execute(&mut self) -> Result<()>;
fn into_transport(self) -> Transport;
}
pub(crate) async fn new_client(
options: SessionOptions,
) -> Result<(Client, EventLoop)> {
let server_url = options.server.server_url;
let options = ClientOptions {
keypair: options.keypair,
server_public_key: options.server.server_public_key,
pattern: options.server.pattern,
};
let url = options.url(&server_url);
Ok(Client::new(&url, options).await?)
}
pub(crate) fn public_key_to_str(public_key: &[u8]) -> String {
hex::encode(&public_key[0..6])
}