-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2adff8
commit 8a0467e
Showing
9 changed files
with
226 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use eyre::{eyre, OptionExt}; | ||
use std::{collections::BTreeMap, error::Error}; | ||
|
||
use frost_core::{keys::KeyPackage, Ciphersuite}; | ||
use frost_ed25519::Ed25519Sha512; | ||
use rand::thread_rng; | ||
use trusted_dealer::MaybeIntoEvenY; | ||
|
||
use crate::{ | ||
args::Command, | ||
config::{Config, Group, Participant}, | ||
}; | ||
|
||
pub(crate) fn trusted_dealer(args: &Command) -> Result<(), Box<dyn Error>> { | ||
let Command::TrustedDealer { ciphersuite, .. } = (*args).clone() else { | ||
panic!("invalid Command"); | ||
}; | ||
|
||
if ciphersuite == "ed25519" { | ||
trusted_dealer_for_ciphersuite::<Ed25519Sha512>(args) | ||
} else { | ||
Err(eyre!("unsupported ciphersuite").into()) | ||
} | ||
} | ||
|
||
pub(crate) fn trusted_dealer_for_ciphersuite<C: Ciphersuite + MaybeIntoEvenY + 'static>( | ||
args: &Command, | ||
) -> Result<(), Box<dyn Error>> { | ||
let Command::TrustedDealer { | ||
config, | ||
ciphersuite: _, | ||
threshold, | ||
num_signers, | ||
} = (*args).clone() | ||
else { | ||
panic!("invalid Command"); | ||
}; | ||
|
||
if config.len() != num_signers as usize { | ||
return Err( | ||
eyre!("The `config` option must specify `num_signers` different config files").into(), | ||
); | ||
} | ||
|
||
let trusted_dealer_config = trusted_dealer::Config { | ||
max_signers: num_signers, | ||
min_signers: threshold, | ||
secret: vec![], | ||
}; | ||
let mut rng = thread_rng(); | ||
|
||
// Generate key shares | ||
let (shares, public_key_package) = | ||
trusted_dealer::trusted_dealer::<C, _>(&trusted_dealer_config, &mut rng)?; | ||
|
||
// First pass over configs; create participants map | ||
let mut participants = BTreeMap::new(); | ||
for (identifier, path) in shares.keys().zip(config.iter()) { | ||
let config = Config::read(Some(path.to_string()))?; | ||
let pubkey = config | ||
.communication_key | ||
.ok_or_eyre("config not initialized")? | ||
.pubkey; | ||
let participant = Participant { | ||
identifier: identifier.serialize(), | ||
pubkey, | ||
server_url: None, | ||
username: None, | ||
}; | ||
participants.insert(hex::encode(identifier.serialize()), participant); | ||
} | ||
|
||
// Second pass over configs; write group information | ||
for (share, path) in shares.values().zip(config.iter()) { | ||
let mut config = Config::read(Some(path.to_string()))?; | ||
let key_package: KeyPackage<C> = share.clone().try_into()?; | ||
let group = Group { | ||
key_package: postcard::to_allocvec(&key_package)?, | ||
public_key_package: postcard::to_allocvec(&public_key_package)?, | ||
participant: participants.clone(), | ||
}; | ||
config.group.insert( | ||
hex::encode(public_key_package.verifying_key().serialize()?), | ||
group, | ||
); | ||
config.write()?; | ||
} | ||
|
||
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
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
Oops, something went wrong.