Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use PublicKey type throughout the workspace #495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions coordinator/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use eyre::eyre;

use frost_core::{keys::PublicKeyPackage, Ciphersuite, Identifier};
use frost_rerandomized::Randomizer;
use frostd::PublicKey;

use crate::input::read_from_file_or_stdin;

Expand Down Expand Up @@ -86,7 +87,7 @@ pub struct ProcessedArgs<C: Ciphersuite> {
pub http: bool,

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

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

/// The coordinator's communication public key for HTTP mode.
pub comm_pubkey: Option<Vec<u8>>,
pub comm_pubkey: Option<PublicKey>,
}

impl<C: Ciphersuite + 'static> ProcessedArgs<C> {
Expand Down
28 changes: 14 additions & 14 deletions coordinator/src/comms/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum SessionState<C: Ciphersuite> {
/// Commitments sent by participants so far, for each message being
/// signed.
commitments: HashMap<Identifier<C>, Vec<SigningCommitments<C>>>,
pubkeys: HashMap<Vec<u8>, Identifier<C>>,
pubkeys: HashMap<PublicKey, Identifier<C>>,
},
/// Commitments have been sent by all participants. Coordinator can create
/// SigningPackage and send to participants. Waiting for participants to
Expand All @@ -54,7 +54,7 @@ pub enum SessionState<C: Ciphersuite> {
/// All commitments sent by participants, for each message being signed.
commitments: HashMap<Identifier<C>, Vec<SigningCommitments<C>>>,
/// Pubkey -> Identifier mapping.
pubkeys: HashMap<Vec<u8>, Identifier<C>>,
pubkeys: HashMap<PublicKey, Identifier<C>>,
/// Signature shares sent by participants so far, for each message being
/// signed.
signature_shares: HashMap<Identifier<C>, Vec<SignatureShare<C>>>,
Expand All @@ -74,7 +74,7 @@ impl<C: Ciphersuite> SessionState<C> {
pub fn new(
num_messages: usize,
num_signers: usize,
pubkeys: HashMap<Vec<u8>, Identifier<C>>,
pubkeys: HashMap<PublicKey, Identifier<C>>,
) -> Self {
let args = SessionStateArgs {
num_messages,
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<C: Ciphersuite> SessionState<C> {
/// Handle commitments sent by a participant.
fn handle_commitments(
&mut self,
pubkey: Vec<u8>,
pubkey: PublicKey,
commitments: Vec<SigningCommitments<C>>,
) -> Result<(), Box<dyn Error>> {
if let SessionState::WaitingForCommitments {
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<C: Ciphersuite> SessionState<C> {
) -> Result<
(
Vec<BTreeMap<Identifier<C>, SigningCommitments<C>>>,
HashMap<Vec<u8>, Identifier<C>>,
HashMap<PublicKey, Identifier<C>>,
),
Box<dyn Error>,
> {
Expand Down Expand Up @@ -197,7 +197,7 @@ impl<C: Ciphersuite> SessionState<C> {
/// Handle signature share sent by a participant.
fn handle_signature_share(
&mut self,
pubkey: Vec<u8>,
pubkey: PublicKey,
signature_shares: Vec<SignatureShare<C>>,
) -> Result<(), Box<dyn Error>> {
if let SessionState::WaitingForSignatureShares {
Expand Down Expand Up @@ -265,11 +265,11 @@ pub struct HTTPComms<C: Ciphersuite> {
access_token: Option<String>,
args: ProcessedArgs<C>,
state: SessionState<C>,
pubkeys: HashMap<Vec<u8>, Identifier<C>>,
pubkeys: HashMap<PublicKey, Identifier<C>>,
// The "send" Noise objects by pubkey of recipients.
send_noise: Option<HashMap<Vec<u8>, Noise>>,
send_noise: Option<HashMap<PublicKey, Noise>>,
// The "receive" Noise objects by pubkey of senders.
recv_noise: Option<HashMap<Vec<u8>, Noise>>,
recv_noise: Option<HashMap<PublicKey, Noise>>,
_phantom: PhantomData<C>,
}

Expand All @@ -295,7 +295,7 @@ impl<C: Ciphersuite> HTTPComms<C> {
}

// Encrypts a message for a given recipient.
fn encrypt(&mut self, recipient: &Vec<u8>, msg: Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> {
fn encrypt(&mut self, recipient: &PublicKey, msg: Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> {
let noise_map = self
.send_noise
.as_mut()
Expand Down Expand Up @@ -390,7 +390,7 @@ impl<C: Ciphersuite + 'static> Comms<C> for HTTPComms<C> {
.post(format!("{}/create_new_session", self.host_port))
.bearer_auth(self.access_token.as_ref().expect("was just set"))
.json(&frostd::CreateNewSessionArgs {
pubkeys: self.args.signers.keys().cloned().map(PublicKey).collect(),
pubkeys: self.args.signers.keys().cloned().collect(),
message_count: 1,
})
.send()
Expand Down Expand Up @@ -423,7 +423,7 @@ impl<C: Ciphersuite + 'static> Comms<C> for HTTPComms<C> {
let send_noise = Noise::new(
builder
.local_private_key(comm_privkey)
.remote_public_key(comm_participant_pubkey)
.remote_public_key(&comm_participant_pubkey.0)
.build_initiator()?,
);
let builder = snow::Builder::new(
Expand All @@ -434,7 +434,7 @@ impl<C: Ciphersuite + 'static> Comms<C> for HTTPComms<C> {
let recv_noise = Noise::new(
builder
.local_private_key(comm_privkey)
.remote_public_key(comm_participant_pubkey)
.remote_public_key(&comm_participant_pubkey.0)
.build_responder()?,
);
send_noise_map.insert(comm_participant_pubkey.clone(), send_noise);
Expand Down Expand Up @@ -506,7 +506,7 @@ impl<C: Ciphersuite + 'static> Comms<C> for HTTPComms<C> {
)
.json(&frostd::SendArgs {
session_id: self.session_id.unwrap(),
recipients: vec![frostd::PublicKey(recipient.clone())],
recipients: vec![recipient.clone()],
msg,
})
.send()
Expand Down
7 changes: 4 additions & 3 deletions dkg/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::rc::Rc;

use clap::Parser;
use frost_core::{Ciphersuite, Identifier};
use frostd::PublicKey;

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

/// The participant's communication public key for HTTP mode.
pub comm_pubkey: Option<Vec<u8>>,
pub comm_pubkey: Option<PublicKey>,

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

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

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

/// Identifier to use for the participant. Only needed for CLI mode.
pub identifier: Option<Identifier<C>>,
Expand Down
3 changes: 2 additions & 1 deletion dkg/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use eyre::eyre;
use frost_core::keys::{KeyPackage, PublicKeyPackage};
use frost_core::{self as frost, Ciphersuite, Identifier};

use frostd::PublicKey;
use rand::thread_rng;
use reddsa::frost::redpallas::keys::EvenY;
use std::collections::HashMap;
Expand Down Expand Up @@ -77,7 +78,7 @@ pub async fn cli_for_processed_args<C: Ciphersuite + 'static + MaybeIntoEvenY>(
(
KeyPackage<C>,
PublicKeyPackage<C>,
HashMap<Vec<u8>, Identifier<C>>,
HashMap<PublicKey, Identifier<C>>,
),
Box<dyn Error>,
> {
Expand Down
5 changes: 4 additions & 1 deletion dkg/src/comms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use frost_core::{
keys::dkg::{round1, round2},
Ciphersuite,
};
use frostd::PublicKey;

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

/// Return the map of public keys to identifiers for all participants.
fn get_pubkey_identifier_map(&self) -> Result<HashMap<Vec<u8>, Identifier<C>>, Box<dyn Error>>;
fn get_pubkey_identifier_map(
&self,
) -> Result<HashMap<PublicKey, Identifier<C>>, Box<dyn Error>>;
}
5 changes: 4 additions & 1 deletion dkg/src/comms/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use frost_core::Ciphersuite;
use async_trait::async_trait;

use frost::{keys::PublicKeyPackage, Identifier};
use frostd::PublicKey;

use std::collections::HashMap;
use std::{
Expand Down Expand Up @@ -138,7 +139,9 @@ where
Ok(received_round2_packages)
}

fn get_pubkey_identifier_map(&self) -> Result<HashMap<Vec<u8>, Identifier<C>>, Box<dyn Error>> {
fn get_pubkey_identifier_map(
&self,
) -> Result<HashMap<PublicKey, Identifier<C>>, Box<dyn Error>> {
Ok(Default::default())
}
}
Expand Down
Loading
Loading