-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcoordinator.rs
115 lines (98 loc) · 3.36 KB
/
coordinator.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use std::collections::HashMap;
use std::error::Error;
use coordinator::cli::cli_for_processed_args;
use eyre::eyre;
use eyre::Context;
use eyre::OptionExt;
use frost_core::keys::PublicKeyPackage;
use frost_core::Ciphersuite;
use frost_ed25519::Ed25519Sha512;
use frost_rerandomized::RandomizedCiphersuite;
use reddsa::frost::redpallas::PallasBlake2b512;
use reqwest::Url;
use crate::{args::Command, config::Config};
pub(crate) async fn run(args: &Command) -> Result<(), Box<dyn Error>> {
let Command::Coordinator { config, group, .. } = (*args).clone() else {
panic!("invalid Command");
};
let config = Config::read(config)?;
let group = config.group.get(&group).ok_or_eyre("Group not found")?;
if group.ciphersuite == Ed25519Sha512::ID {
run_for_ciphersuite::<Ed25519Sha512>(args).await
} else if group.ciphersuite == PallasBlake2b512::ID {
run_for_ciphersuite::<PallasBlake2b512>(args).await
} else {
Err(eyre!("unsupported ciphersuite").into())
}
}
pub(crate) async fn run_for_ciphersuite<C: RandomizedCiphersuite + 'static>(
args: &Command,
) -> Result<(), Box<dyn Error>> {
let Command::Coordinator {
config,
server_url,
group,
signers,
message,
randomizer,
signature,
} = (*args).clone()
else {
panic!("invalid Command");
};
let config = Config::read(config)?;
let group = config.group.get(&group).ok_or_eyre("Group not found")?;
let public_key_package: PublicKeyPackage<C> = postcard::from_bytes(&group.public_key_package)?;
let mut input = Box::new(std::io::stdin().lock());
let mut output = std::io::stdout();
let server_url = if let Some(server_url) = server_url {
server_url
} else {
group.server_url.clone().ok_or_eyre("server-url required")?
};
let server_url_parsed =
Url::parse(&format!("https://{}", server_url)).wrap_err("error parsing server-url")?;
let signers = signers
.iter()
.map(|s| {
let pubkey = hex::decode(s)?.to_vec();
let contact = group.participant_by_pubkey(&pubkey)?;
Ok((pubkey, contact.identifier()?))
})
.collect::<Result<HashMap<_, _>, Box<dyn Error>>>()?;
let num_signers = signers.len() as u16;
let pargs = coordinator::args::ProcessedArgs {
cli: false,
http: true,
signers,
num_signers,
public_key_package,
messages: coordinator::args::read_messages(&message, &mut output, &mut input)?,
randomizers: coordinator::args::read_randomizers(&randomizer, &mut output, &mut input)?,
signature,
ip: server_url_parsed
.host_str()
.ok_or_eyre("host missing in URL")?
.to_owned(),
port: server_url_parsed
.port_or_known_default()
.expect("always works for https"),
comm_privkey: Some(
config
.communication_key
.clone()
.ok_or_eyre("user not initialized")?
.privkey
.clone(),
),
comm_pubkey: Some(
config
.communication_key
.ok_or_eyre("user not initialized")?
.pubkey
.clone(),
),
};
cli_for_processed_args(pargs, &mut input, &mut output).await?;
Ok(())
}