mirror of
https://github.com/luxfi/multi-party-ecdsa.git
synced 2026-10-30 15:24:24 +00:00
59 lines
1.7 KiB
Rust
59 lines
1.7 KiB
Rust
use anyhow::{anyhow, Context, Result};
|
|
use futures::StreamExt;
|
|
use std::path::PathBuf;
|
|
use structopt::StructOpt;
|
|
|
|
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::state_machine::keygen::Keygen;
|
|
use round_based::async_runtime::AsyncProtocol;
|
|
|
|
mod gg20_sm_client;
|
|
use gg20_sm_client::join_computation;
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
struct Cli {
|
|
#[structopt(short, long, default_value = "http://localhost:8000/")]
|
|
address: surf::Url,
|
|
#[structopt(short, long, default_value = "default-keygen")]
|
|
room: String,
|
|
#[structopt(short, long)]
|
|
output: PathBuf,
|
|
|
|
#[structopt(short, long)]
|
|
index: u16,
|
|
#[structopt(short, long)]
|
|
threshold: u16,
|
|
#[structopt(short, long)]
|
|
number_of_parties: u16,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
let args: Cli = Cli::from_args();
|
|
let mut output_file = tokio::fs::OpenOptions::new()
|
|
.write(true)
|
|
.create_new(true)
|
|
.open(args.output)
|
|
.await
|
|
.context("cannot create output file")?;
|
|
|
|
let (_i, incoming, outgoing) = join_computation(args.address, &args.room)
|
|
.await
|
|
.context("join computation")?;
|
|
|
|
let incoming = incoming.fuse();
|
|
tokio::pin!(incoming);
|
|
tokio::pin!(outgoing);
|
|
|
|
let keygen = Keygen::new(args.index, args.threshold, args.number_of_parties)?;
|
|
let output = AsyncProtocol::new(keygen, incoming, outgoing)
|
|
.run()
|
|
.await
|
|
.map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?;
|
|
let output = serde_json::to_vec_pretty(&output).context("serialize output")?;
|
|
tokio::io::copy(&mut output.as_slice(), &mut output_file)
|
|
.await
|
|
.context("save output to file")?;
|
|
|
|
Ok(())
|
|
}
|