Skip to content

Commit

Permalink
Add validation for participant selection in coordinator demo (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
natalieesk committed Jul 19, 2023
1 parent 7825024 commit dacbc86
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 25 additions & 8 deletions coordinator/src/step_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,56 @@ pub fn step_1(reader: &mut impl BufRead, logger: &mut dyn Write) -> Participants
participants
}

fn validate(
id: Identifier,
key_package: PublicKeyPackage,
id_list: &[Identifier],
) -> Result<(), Error> {
if key_package.signer_pubkeys().contains_key(&id) {
return Err(Error::DuplicatedIdentifier);
}; // TODO: Error is actually that the identifier does not exist
if !id_list.contains(&id) {
return Err(Error::DuplicatedIdentifier);
};
Ok(())
}

// TODO: validate min num of participants
// TODO: validate participant must exist

// Input required:
// 1. public key package
// 2. number of signparticipantsers
// 3. identifiers for all signers
// 2. number of participants
// 3. identifiers for all participants
fn choose_participants(
input: &mut impl BufRead,
logger: &mut dyn Write,
) -> Result<ParticipantsConfig, Error> {
writeln!(logger, "Paste the JSON public key package: ").unwrap();
let mut key_package = String::new();
input.read_line(&mut key_package).unwrap();
let pub_key_package = serde_json::from_str(&key_package).unwrap();
let pub_key_package: PublicKeyPackage = serde_json::from_str(&key_package).unwrap();

//TODO: validate for unique identifiers
writeln!(logger, "The number of participants: ").unwrap();

let mut signers = String::new();
input.read_line(&mut signers).unwrap();
let num_of_signers = signers.trim().parse::<u16>().unwrap();
let mut participants = String::new();
input.read_line(&mut participants).unwrap();
let num_of_participants = participants.trim().parse::<u16>().unwrap();

let mut participants = Vec::new();

for i in 1..=num_of_signers {
for i in 1..=num_of_participants {
let package = pub_key_package.clone();
writeln!(logger, "Identifier for participant {:?} (hex encoded):", i).unwrap();

let mut identifier_input = String::new();

input.read_line(&mut identifier_input).unwrap();

let id_value = serde_json::from_str(&identifier_input).unwrap();

validate(id_value, package, &participants)?;

participants.push(id_value)
}
Ok(ParticipantsConfig {
Expand Down
2 changes: 0 additions & 2 deletions coordinator/src/tests/steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ fn check_step_3() {

let signing_package = SigningPackage::new(signing_commitments, b"test");

// expect group sig: "72c948a63797c693e8e978fdb703a1f5a7590472a539da13b71dd6c2b8c1b2a664b7b4af6194439357c5d15f366760fce53c985a186709e74bb0f8e5078ea805"

step_3(
&mut valid_input,
&mut buf,
Expand Down

0 comments on commit dacbc86

Please sign in to comment.