Add error handling for split_secret (#362)
This commit is contained in:
parent
bc987bbba8
commit
2bba8bfa15
12
src/main.rs
12
src/main.rs
|
@ -32,18 +32,18 @@ fn main() -> io::Result<()> {
|
|||
}
|
||||
|
||||
let keygen = if config.secret.is_empty() {
|
||||
trusted_dealer_keygen(&config, &mut rng).unwrap()
|
||||
trusted_dealer_keygen(&config, &mut rng)
|
||||
} else {
|
||||
split_secret(&config, &mut rng)
|
||||
};
|
||||
|
||||
// Print outputs
|
||||
// if let Err(e) = keygen {
|
||||
// eprintln!("Error: {}", e);
|
||||
// std::process::exit(1)
|
||||
// }
|
||||
if let Err(e) = keygen {
|
||||
eprintln!("Error: {}", e);
|
||||
std::process::exit(1)
|
||||
}
|
||||
|
||||
let (key_packages, pubkeys) = keygen;
|
||||
let (key_packages, pubkeys) = keygen.unwrap();
|
||||
|
||||
let mut console_logger = ConsoleLogger::default();
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ fn check_keygen_with_dealer_with_secret() {
|
|||
max_signers: 3,
|
||||
secret,
|
||||
};
|
||||
let (key_packages, pubkeys) = split_secret(&secret_config, &mut rng);
|
||||
let (key_packages, pubkeys) = split_secret(&secret_config, &mut rng).unwrap();
|
||||
let (nonces, commitments) = signature_gen::generate_nonces_and_commitments(
|
||||
secret_config.min_signers,
|
||||
&key_packages,
|
||||
|
|
|
@ -101,7 +101,7 @@ fn check_output_with_secret() {
|
|||
max_signers: 3,
|
||||
secret,
|
||||
};
|
||||
let (key_packages, pubkeys) = split_secret(&config, &mut rng);
|
||||
let (key_packages, pubkeys) = split_secret(&config, &mut rng).unwrap();
|
||||
|
||||
print_values(&key_packages, pubkeys, &mut test_logger);
|
||||
|
||||
|
|
|
@ -26,17 +26,17 @@ pub fn trusted_dealer_keygen(
|
|||
pub fn split_secret(
|
||||
config: &Config,
|
||||
rng: &mut ThreadRng,
|
||||
) -> (HashMap<Identifier, KeyPackage>, PublicKeyPackage) {
|
||||
) -> Result<(HashMap<Identifier, KeyPackage>, PublicKeyPackage), Error> {
|
||||
let sec = config.secret.clone();
|
||||
let again = sec.try_into().unwrap();
|
||||
let secret_key = SigningKey::from_bytes(again).unwrap();
|
||||
let secret_key = SigningKey::from_bytes(again)?;
|
||||
let (shares, pubkeys) =
|
||||
frost::keys::split(&secret_key, config.max_signers, config.min_signers, rng).unwrap();
|
||||
frost::keys::split(&secret_key, config.max_signers, config.min_signers, rng)?;
|
||||
let mut key_packages: HashMap<_, _> = HashMap::new();
|
||||
|
||||
for (k, v) in shares {
|
||||
let key_package = frost::keys::KeyPackage::try_from(v).unwrap();
|
||||
let key_package = frost::keys::KeyPackage::try_from(v)?;
|
||||
key_packages.insert(k, key_package);
|
||||
}
|
||||
(key_packages, pubkeys)
|
||||
Ok((key_packages, pubkeys))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue