-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* setup clap CLI * keygen async setup from Clap * keygen async * typechecks pass * yoink, structopt * reorg subdirs * sm-manager * keygen + signing - compilation errors * pending keygen ownership bug * async ownership bugfix * blocking: handling error on 6 of 7 keygen * keygen bug documented
- Loading branch information
Showing
5 changed files
with
93 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,76 @@ | ||
use std::path::PathBuf; | ||
use anyhow::{anyhow, Context, Result}; | ||
use curv::{arithmetic::Converter, BigInt}; | ||
use futures::{SinkExt, StreamExt, TryStreamExt}; | ||
use structopt::StructOpt; | ||
use curv::arithmetic::Converter; | ||
use curv::BigInt; | ||
use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2020::state_machine::sign::{ | ||
OfflineStage, SignManual, | ||
OfflineStage, SignManual, | ||
}; | ||
use round_based::async_runtime::AsyncProtocol; | ||
use round_based::Msg; | ||
use round_based::{async_runtime::AsyncProtocol, Msg}; | ||
use std::path::PathBuf; | ||
use structopt::StructOpt; | ||
|
||
use crate::gg20_sm_client::join_computation; | ||
|
||
#[derive(Debug, StructOpt,Clone)] | ||
#[derive(Debug, StructOpt, Clone)] | ||
pub struct SignCli { | ||
#[structopt(short, long, default_value = "http://localhost:8000/")] | ||
address: surf::Url, | ||
#[structopt(short, long, default_value = "default-signing")] | ||
room: String, | ||
#[structopt(short, long, default_value = "http://localhost:8000/")] | ||
address: surf::Url, | ||
#[structopt(short, long, default_value = "default-signing")] | ||
room: String, | ||
/// Index of the party | ||
#[structopt(short, long, default_value = "0")] | ||
index: u16, | ||
#[structopt(short, long, use_delimiter(true))] | ||
parties: Vec<u16>, | ||
#[structopt(short, long)] | ||
data_to_sign: String, | ||
#[structopt(short, long, default_value = "1")] | ||
index: u16, | ||
#[structopt(short, long, use_delimiter(true))] | ||
parties: Vec<u16>, | ||
#[structopt(short, long, default_value = "vibes be immaculate")] | ||
data_to_sign: String, | ||
} | ||
|
||
pub async fn sign(args: SignCli ) -> Result<()> { | ||
pub async fn sign(args: SignCli) -> Result<()> { | ||
let local_share = PathBuf::from(format!("local-share{}.json", args.index)); | ||
let local_share = tokio::fs::read(local_share) | ||
.await | ||
.context(format!("cannot read local share at index {}",args.index))?; | ||
let local_share = serde_json::from_slice(&local_share).context("parse local share")?; | ||
let number_of_parties = args.parties.len(); | ||
let local_share = tokio::fs::read(local_share) | ||
.await | ||
.context(format!("cannot read local share at index {}", args.index))?; | ||
let local_share = serde_json::from_slice(&local_share).context("parse local share")?; | ||
let number_of_parties = args.parties.len(); | ||
|
||
let (i, incoming, outgoing) = | ||
join_computation(args.address.clone(), &format!("{}-offline", args.room)) | ||
.await | ||
.context("join offline computation")?; | ||
let (i, incoming, outgoing) = | ||
join_computation(args.address.clone(), &format!("{}-offline", args.room)) | ||
.await | ||
.context("join offline computation")?; | ||
|
||
let incoming = incoming.fuse(); | ||
tokio::pin!(incoming); | ||
tokio::pin!(outgoing); | ||
let incoming = incoming.fuse(); | ||
tokio::pin!(incoming); | ||
tokio::pin!(outgoing); | ||
|
||
let signing = OfflineStage::new(i, args.parties, local_share)?; | ||
let completed_offline_stage = AsyncProtocol::new(signing, incoming, outgoing) | ||
.run() | ||
.await | ||
.map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?; | ||
let signing = OfflineStage::new(i, args.parties, local_share)?; | ||
let completed_offline_stage = AsyncProtocol::new(signing, incoming, outgoing) | ||
.run() | ||
.await | ||
// TODO: tk alice can't send messages to herself in round_based dep | ||
.map_err(|e| anyhow!("protocol execution terminated with error: {}", e))?; | ||
|
||
let (_i, incoming, outgoing) = join_computation(args.address, &format!("{}-online", args.room)) | ||
.await | ||
.context("join online computation")?; | ||
let (_i, incoming, outgoing) = join_computation(args.address, &format!("{}-online", args.room)) | ||
.await | ||
.context("join online computation")?; | ||
|
||
tokio::pin!(incoming); | ||
tokio::pin!(outgoing); | ||
tokio::pin!(incoming); | ||
tokio::pin!(outgoing); | ||
|
||
let (signing, partial_signature) = SignManual::new( | ||
BigInt::from_bytes(args.data_to_sign.as_bytes()), | ||
completed_offline_stage, | ||
)?; | ||
let (signing, partial_signature) = | ||
SignManual::new(BigInt::from_bytes(args.data_to_sign.as_bytes()), completed_offline_stage)?; | ||
|
||
outgoing | ||
.send(Msg { | ||
sender: i, | ||
receiver: None, | ||
body: partial_signature, | ||
}) | ||
.await?; | ||
outgoing | ||
.send(Msg { sender: i, receiver: None, body: partial_signature }) | ||
.await?; | ||
|
||
let partial_signatures: Vec<_> = incoming | ||
.take(number_of_parties - 1) | ||
.map_ok(|msg| msg.body) | ||
.try_collect() | ||
.await?; | ||
let signature = signing | ||
.complete(&partial_signatures) | ||
.context("online stage failed")?; | ||
let signature = serde_json::to_string(&signature).context("serialize signature")?; | ||
println!("{}", signature); | ||
let partial_signatures: Vec<_> = incoming | ||
.take(number_of_parties - 1) | ||
.map_ok(|msg| msg.body) | ||
.try_collect() | ||
.await?; | ||
let signature = signing.complete(&partial_signatures).context("online stage failed")?; | ||
let signature = serde_json::to_string(&signature).context("serialize signature")?; | ||
println!("{}", signature); | ||
|
||
Ok(()) | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters