Add input for secret (#362)
This commit is contained in:
parent
480c5c10ff
commit
32bf470df5
|
@ -1,15 +1,12 @@
|
|||
use frost_ed25519::Error;
|
||||
use frost::Error;
|
||||
use frost_ed25519 as frost;
|
||||
use std::io::BufRead;
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Config {
|
||||
pub min_signers: u16,
|
||||
pub max_signers: u16,
|
||||
}
|
||||
|
||||
pub struct _SecretConfig {
|
||||
pub signers: Config,
|
||||
pub secret: Vec<u8>,
|
||||
pub secret: Vec<u8>, // todo
|
||||
}
|
||||
|
||||
pub fn validate_inputs(config: &Config) -> Result<(), Error> {
|
||||
|
@ -48,8 +45,17 @@ pub fn request_inputs(input: &mut impl BufRead) -> Result<Config, Error> {
|
|||
.parse::<u16>()
|
||||
.map_err(|_| Error::InvalidMaxSigners)?;
|
||||
|
||||
Ok(Config {
|
||||
println!("Secret key (if you don't have one then press enter): ");
|
||||
|
||||
let mut secret_input = String::new();
|
||||
input.read_line(&mut secret_input).unwrap();
|
||||
let secret = hex::decode(secret_input.trim()).map_err(|_| Error::MalformedSigningKey)?;
|
||||
|
||||
let config = Config {
|
||||
min_signers,
|
||||
max_signers,
|
||||
})
|
||||
secret,
|
||||
};
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ fn main() -> io::Result<()> {
|
|||
}
|
||||
|
||||
// Print outputs
|
||||
let out = trusted_dealer_keygen(config, &mut rng);
|
||||
let out = trusted_dealer_keygen(&config, &mut rng);
|
||||
if let Err(e) = out {
|
||||
eprintln!("Error: {}", e);
|
||||
std::process::exit(1)
|
||||
|
|
|
@ -5,6 +5,7 @@ fn check_valid_input_for_signers() {
|
|||
let config = Config {
|
||||
min_signers: 2,
|
||||
max_signers: 3,
|
||||
secret: Vec::new(),
|
||||
};
|
||||
|
||||
let expected = validate_inputs(&config);
|
||||
|
@ -17,6 +18,7 @@ fn return_error_if_min_participant_greater_than_max_participant() {
|
|||
let config = Config {
|
||||
min_signers: 4,
|
||||
max_signers: 3,
|
||||
secret: Vec::new(),
|
||||
};
|
||||
|
||||
let expected = validate_inputs(&config);
|
||||
|
@ -29,6 +31,7 @@ fn return_error_if_min_participant_is_less_than_2() {
|
|||
let config = Config {
|
||||
min_signers: 1,
|
||||
max_signers: 3,
|
||||
secret: Vec::new(),
|
||||
};
|
||||
|
||||
let expected = validate_inputs(&config);
|
||||
|
@ -41,6 +44,7 @@ fn return_error_if_max_participant_is_less_than_2() {
|
|||
let config = Config {
|
||||
min_signers: 2,
|
||||
max_signers: 1,
|
||||
secret: Vec::new(),
|
||||
};
|
||||
|
||||
let expected = validate_inputs(&config);
|
||||
|
@ -48,13 +52,22 @@ fn return_error_if_max_participant_is_less_than_2() {
|
|||
assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners));
|
||||
}
|
||||
|
||||
// Testing inclusion of secret input
|
||||
|
||||
#[test]
|
||||
fn return_config_if_valid_input() {
|
||||
let mut valid_input = "3\n6\n".as_bytes();
|
||||
fn check_valid_input_with_secret() {
|
||||
let mut valid_input =
|
||||
"3\n6\n7b1c33d3f5291d85de664833beb1ad469f7fb6025a0ec78b3a790c6e13a98304\n".as_bytes();
|
||||
let config = request_inputs(&mut valid_input).unwrap();
|
||||
|
||||
let secret: Vec<u8> = vec![
|
||||
123, 28, 51, 211, 245, 41, 29, 133, 222, 102, 72, 51, 190, 177, 173, 70, 159, 127, 182, 2,
|
||||
90, 14, 199, 139, 58, 121, 12, 110, 19, 169, 131, 4,
|
||||
];
|
||||
let expected = Config {
|
||||
min_signers: 3,
|
||||
max_signers: 6,
|
||||
secret,
|
||||
};
|
||||
|
||||
assert_eq!(expected, config)
|
||||
|
@ -62,7 +75,7 @@ fn return_config_if_valid_input() {
|
|||
|
||||
#[test]
|
||||
fn return_error_if_invalid_min_signers_input() {
|
||||
let mut invalid_input = "hello\n6\n".as_bytes();
|
||||
let mut invalid_input = "hello\n6\n\n".as_bytes();
|
||||
let expected = request_inputs(&mut invalid_input);
|
||||
|
||||
assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners))
|
||||
|
@ -70,8 +83,16 @@ fn return_error_if_invalid_min_signers_input() {
|
|||
|
||||
#[test]
|
||||
fn return_error_if_invalid_max_signers_input() {
|
||||
let mut invalid_input = "4\nworld\n".as_bytes();
|
||||
let mut invalid_input = "4\nworld\n\n".as_bytes();
|
||||
let expected = request_inputs(&mut invalid_input);
|
||||
|
||||
assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_error_if_secret_is_invalid() {
|
||||
let mut secret_input = "4\n6\nasecret\n".as_bytes();
|
||||
let expected = request_inputs(&mut secret_input);
|
||||
|
||||
assert_eq!(expected, Err(frost_ed25519::Error::MalformedSigningKey))
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::inputs::{Config, _SecretConfig};
|
||||
use crate::inputs::Config;
|
||||
use frost_ed25519 as frost;
|
||||
use rand::thread_rng;
|
||||
|
||||
use crate::trusted_dealer_keygen::_split;
|
||||
use crate::trusted_dealer_keygen::_split_secret;
|
||||
use crate::trusted_dealer_keygen::trusted_dealer_keygen;
|
||||
mod signature_gen;
|
||||
|
||||
|
@ -12,8 +12,9 @@ fn check_keygen_with_dealer() {
|
|||
let config = Config {
|
||||
min_signers: 2,
|
||||
max_signers: 3,
|
||||
secret: Vec::new(),
|
||||
};
|
||||
let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng).unwrap();
|
||||
let (key_packages, pubkeys) = trusted_dealer_keygen(&config, &mut rng).unwrap();
|
||||
let (nonces, commitments) =
|
||||
signature_gen::generate_nonces_and_commitments(config.min_signers, &key_packages, &mut rng);
|
||||
let message = "message to sign".as_bytes();
|
||||
|
@ -31,13 +32,10 @@ fn check_keygen_with_dealer() {
|
|||
#[test]
|
||||
fn check_keygen_with_dealer_with_secret() {
|
||||
let mut rng = thread_rng();
|
||||
let config = Config {
|
||||
let secret_config = Config {
|
||||
min_signers: 2,
|
||||
max_signers: 3,
|
||||
secret: b"byte".to_vec(),
|
||||
};
|
||||
let secret_config = _SecretConfig {
|
||||
signers: config,
|
||||
secret: b"byte".to_vec(), // Todo
|
||||
};
|
||||
_split(secret_config, &mut rng);
|
||||
_split_secret(secret_config, &mut rng);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use rand::thread_rng;
|
|||
|
||||
use crate::inputs::Config;
|
||||
use crate::output::{print_values, Logger};
|
||||
use crate::trusted_dealer_keygen;
|
||||
use crate::trusted_dealer_keygen::trusted_dealer_keygen;
|
||||
|
||||
struct TestLogger(Vec<String>);
|
||||
|
||||
|
@ -21,8 +21,9 @@ fn check_output() {
|
|||
let config = Config {
|
||||
min_signers: 2,
|
||||
max_signers: 3,
|
||||
secret: Vec::new(),
|
||||
};
|
||||
let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng).unwrap();
|
||||
let (key_packages, pubkeys) = trusted_dealer_keygen(&config, &mut rng).unwrap();
|
||||
|
||||
print_values(&key_packages, pubkeys, &mut test_logger);
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ use frost_ed25519 as frost;
|
|||
use rand::rngs::ThreadRng;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::inputs::{Config, _SecretConfig};
|
||||
use crate::inputs::Config;
|
||||
|
||||
pub fn trusted_dealer_keygen(
|
||||
config: Config,
|
||||
config: &Config,
|
||||
rng: &mut ThreadRng,
|
||||
) -> Result<(HashMap<Identifier, KeyPackage>, PublicKeyPackage), Error> {
|
||||
let (shares, pubkeys) =
|
||||
|
@ -23,4 +23,4 @@ pub fn trusted_dealer_keygen(
|
|||
Ok((key_packages, pubkeys))
|
||||
}
|
||||
|
||||
pub fn _split(_config: _SecretConfig, _rng: &mut ThreadRng) {}
|
||||
pub fn _split_secret(_config: Config, _rng: &mut ThreadRng) {}
|
||||
|
|
Loading…
Reference in New Issue