Skip to content

Commit 95c3f8c

Browse files
authored
use PublicKey type throughout the workspace (#495)
1 parent 3fbcd5b commit 95c3f8c

22 files changed

+127
-128
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coordinator/src/args.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use eyre::eyre;
1111

1212
use frost_core::{keys::PublicKeyPackage, Ciphersuite, Identifier};
1313
use frost_rerandomized::Randomizer;
14+
use frostd::PublicKey;
1415

1516
use crate::input::read_from_file_or_stdin;
1617

@@ -86,7 +87,7 @@ pub struct ProcessedArgs<C: Ciphersuite> {
8687
pub http: bool,
8788

8889
/// Signers to use in HTTP mode, as a map of public keys to identifiers.
89-
pub signers: HashMap<Vec<u8>, Identifier<C>>,
90+
pub signers: HashMap<PublicKey, Identifier<C>>,
9091

9192
/// The number of participants.
9293
pub num_signers: u16,
@@ -116,7 +117,7 @@ pub struct ProcessedArgs<C: Ciphersuite> {
116117
pub comm_privkey: Option<Vec<u8>>,
117118

118119
/// The coordinator's communication public key for HTTP mode.
119-
pub comm_pubkey: Option<Vec<u8>>,
120+
pub comm_pubkey: Option<PublicKey>,
120121
}
121122

122123
impl<C: Ciphersuite + 'static> ProcessedArgs<C> {

coordinator/src/comms/http.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum SessionState<C: Ciphersuite> {
4343
/// Commitments sent by participants so far, for each message being
4444
/// signed.
4545
commitments: HashMap<Identifier<C>, Vec<SigningCommitments<C>>>,
46-
pubkeys: HashMap<Vec<u8>, Identifier<C>>,
46+
pubkeys: HashMap<PublicKey, Identifier<C>>,
4747
},
4848
/// Commitments have been sent by all participants. Coordinator can create
4949
/// SigningPackage and send to participants. Waiting for participants to
@@ -54,7 +54,7 @@ pub enum SessionState<C: Ciphersuite> {
5454
/// All commitments sent by participants, for each message being signed.
5555
commitments: HashMap<Identifier<C>, Vec<SigningCommitments<C>>>,
5656
/// Pubkey -> Identifier mapping.
57-
pubkeys: HashMap<Vec<u8>, Identifier<C>>,
57+
pubkeys: HashMap<PublicKey, Identifier<C>>,
5858
/// Signature shares sent by participants so far, for each message being
5959
/// signed.
6060
signature_shares: HashMap<Identifier<C>, Vec<SignatureShare<C>>>,
@@ -74,7 +74,7 @@ impl<C: Ciphersuite> SessionState<C> {
7474
pub fn new(
7575
num_messages: usize,
7676
num_signers: usize,
77-
pubkeys: HashMap<Vec<u8>, Identifier<C>>,
77+
pubkeys: HashMap<PublicKey, Identifier<C>>,
7878
) -> Self {
7979
let args = SessionStateArgs {
8080
num_messages,
@@ -113,7 +113,7 @@ impl<C: Ciphersuite> SessionState<C> {
113113
/// Handle commitments sent by a participant.
114114
fn handle_commitments(
115115
&mut self,
116-
pubkey: Vec<u8>,
116+
pubkey: PublicKey,
117117
commitments: Vec<SigningCommitments<C>>,
118118
) -> Result<(), Box<dyn Error>> {
119119
if let SessionState::WaitingForCommitments {
@@ -164,7 +164,7 @@ impl<C: Ciphersuite> SessionState<C> {
164164
) -> Result<
165165
(
166166
Vec<BTreeMap<Identifier<C>, SigningCommitments<C>>>,
167-
HashMap<Vec<u8>, Identifier<C>>,
167+
HashMap<PublicKey, Identifier<C>>,
168168
),
169169
Box<dyn Error>,
170170
> {
@@ -197,7 +197,7 @@ impl<C: Ciphersuite> SessionState<C> {
197197
/// Handle signature share sent by a participant.
198198
fn handle_signature_share(
199199
&mut self,
200-
pubkey: Vec<u8>,
200+
pubkey: PublicKey,
201201
signature_shares: Vec<SignatureShare<C>>,
202202
) -> Result<(), Box<dyn Error>> {
203203
if let SessionState::WaitingForSignatureShares {
@@ -265,11 +265,11 @@ pub struct HTTPComms<C: Ciphersuite> {
265265
access_token: Option<String>,
266266
args: ProcessedArgs<C>,
267267
state: SessionState<C>,
268-
pubkeys: HashMap<Vec<u8>, Identifier<C>>,
268+
pubkeys: HashMap<PublicKey, Identifier<C>>,
269269
// The "send" Noise objects by pubkey of recipients.
270-
send_noise: Option<HashMap<Vec<u8>, Noise>>,
270+
send_noise: Option<HashMap<PublicKey, Noise>>,
271271
// The "receive" Noise objects by pubkey of senders.
272-
recv_noise: Option<HashMap<Vec<u8>, Noise>>,
272+
recv_noise: Option<HashMap<PublicKey, Noise>>,
273273
_phantom: PhantomData<C>,
274274
}
275275

@@ -295,7 +295,7 @@ impl<C: Ciphersuite> HTTPComms<C> {
295295
}
296296

297297
// Encrypts a message for a given recipient.
298-
fn encrypt(&mut self, recipient: &Vec<u8>, msg: Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> {
298+
fn encrypt(&mut self, recipient: &PublicKey, msg: Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> {
299299
let noise_map = self
300300
.send_noise
301301
.as_mut()
@@ -390,7 +390,7 @@ impl<C: Ciphersuite + 'static> Comms<C> for HTTPComms<C> {
390390
.post(format!("{}/create_new_session", self.host_port))
391391
.bearer_auth(self.access_token.as_ref().expect("was just set"))
392392
.json(&frostd::CreateNewSessionArgs {
393-
pubkeys: self.args.signers.keys().cloned().map(PublicKey).collect(),
393+
pubkeys: self.args.signers.keys().cloned().collect(),
394394
message_count: 1,
395395
})
396396
.send()
@@ -423,7 +423,7 @@ impl<C: Ciphersuite + 'static> Comms<C> for HTTPComms<C> {
423423
let send_noise = Noise::new(
424424
builder
425425
.local_private_key(comm_privkey)
426-
.remote_public_key(comm_participant_pubkey)
426+
.remote_public_key(&comm_participant_pubkey.0)
427427
.build_initiator()?,
428428
);
429429
let builder = snow::Builder::new(
@@ -434,7 +434,7 @@ impl<C: Ciphersuite + 'static> Comms<C> for HTTPComms<C> {
434434
let recv_noise = Noise::new(
435435
builder
436436
.local_private_key(comm_privkey)
437-
.remote_public_key(comm_participant_pubkey)
437+
.remote_public_key(&comm_participant_pubkey.0)
438438
.build_responder()?,
439439
);
440440
send_noise_map.insert(comm_participant_pubkey.clone(), send_noise);
@@ -506,7 +506,7 @@ impl<C: Ciphersuite + 'static> Comms<C> for HTTPComms<C> {
506506
)
507507
.json(&frostd::SendArgs {
508508
session_id: self.session_id.unwrap(),
509-
recipients: vec![frostd::PublicKey(recipient.clone())],
509+
recipients: vec![recipient.clone()],
510510
msg,
511511
})
512512
.send()

dkg/src/args.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::rc::Rc;
22

33
use clap::Parser;
44
use frost_core::{Ciphersuite, Identifier};
5+
use frostd::PublicKey;
56

67
#[derive(Parser, Debug, Default)]
78
#[command(author, version, about, long_about = None)]
@@ -30,15 +31,15 @@ pub struct ProcessedArgs<C: Ciphersuite> {
3031
pub comm_privkey: Option<Vec<u8>>,
3132

3233
/// The participant's communication public key for HTTP mode.
33-
pub comm_pubkey: Option<Vec<u8>>,
34+
pub comm_pubkey: Option<PublicKey>,
3435

3536
/// A function that confirms that a public key from the server is trusted by
3637
/// the user; returns the same public key. For HTTP mode.
3738
// It is a `Rc<dyn Fn>` to make it easier to use;
3839
// using `fn()` would preclude using closures and using generics would
3940
// require a lot of code change for something simple.
4041
#[allow(clippy::type_complexity)]
41-
pub comm_participant_pubkey_getter: Option<Rc<dyn Fn(&Vec<u8>) -> Option<Vec<u8>>>>,
42+
pub comm_participant_pubkey_getter: Option<Rc<dyn Fn(&PublicKey) -> Option<PublicKey>>>,
4243

4344
/// The threshold to use for the shares
4445
pub min_signers: u16,
@@ -48,7 +49,7 @@ pub struct ProcessedArgs<C: Ciphersuite> {
4849

4950
/// The list of pubkeys for the other participants. This is only required
5051
/// for the first participant who creates the DKG session.
51-
pub participants: Vec<Vec<u8>>,
52+
pub participants: Vec<PublicKey>,
5253

5354
/// Identifier to use for the participant. Only needed for CLI mode.
5455
pub identifier: Option<Identifier<C>>,

dkg/src/cli.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use eyre::eyre;
22
use frost_core::keys::{KeyPackage, PublicKeyPackage};
33
use frost_core::{self as frost, Ciphersuite, Identifier};
44

5+
use frostd::PublicKey;
56
use rand::thread_rng;
67
use reddsa::frost::redpallas::keys::EvenY;
78
use std::collections::HashMap;
@@ -77,7 +78,7 @@ pub async fn cli_for_processed_args<C: Ciphersuite + 'static + MaybeIntoEvenY>(
7778
(
7879
KeyPackage<C>,
7980
PublicKeyPackage<C>,
80-
HashMap<Vec<u8>, Identifier<C>>,
81+
HashMap<PublicKey, Identifier<C>>,
8182
),
8283
Box<dyn Error>,
8384
> {

dkg/src/comms.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use frost_core::{
66
keys::dkg::{round1, round2},
77
Ciphersuite,
88
};
9+
use frostd::PublicKey;
910

1011
use std::{
1112
collections::{BTreeMap, HashMap},
@@ -46,5 +47,7 @@ pub trait Comms<C: Ciphersuite> {
4647
) -> Result<BTreeMap<Identifier<C>, round2::Package<C>>, Box<dyn Error>>;
4748

4849
/// Return the map of public keys to identifiers for all participants.
49-
fn get_pubkey_identifier_map(&self) -> Result<HashMap<Vec<u8>, Identifier<C>>, Box<dyn Error>>;
50+
fn get_pubkey_identifier_map(
51+
&self,
52+
) -> Result<HashMap<PublicKey, Identifier<C>>, Box<dyn Error>>;
5053
}

dkg/src/comms/cli.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use frost_core::Ciphersuite;
99
use async_trait::async_trait;
1010

1111
use frost::{keys::PublicKeyPackage, Identifier};
12+
use frostd::PublicKey;
1213

1314
use std::collections::HashMap;
1415
use std::{
@@ -138,7 +139,9 @@ where
138139
Ok(received_round2_packages)
139140
}
140141

141-
fn get_pubkey_identifier_map(&self) -> Result<HashMap<Vec<u8>, Identifier<C>>, Box<dyn Error>> {
142+
fn get_pubkey_identifier_map(
143+
&self,
144+
) -> Result<HashMap<PublicKey, Identifier<C>>, Box<dyn Error>> {
142145
Ok(Default::default())
143146
}
144147
}

0 commit comments

Comments
 (0)