Skip to content

Commit

Permalink
Improve usability for coordinator demo (#48)
Browse files Browse the repository at this point in the history
Fix test values
Improve identifier input so it doesn't need to be in quotes
Remove unecessary text
  • Loading branch information
natalieesk committed Jul 20, 2023
1 parent 5f65160 commit 9f2c617
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
17 changes: 11 additions & 6 deletions coordinator/src/step_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use frost_ed25519 as frost;

use frost::{keys::PublicKeyPackage, Error, Identifier};

use eyre::eyre;
use std::io::{BufRead, Write};

pub struct ParticipantsConfig {
Expand Down Expand Up @@ -34,7 +35,15 @@ fn validate(
}

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

pub fn read_identifier(input: &mut impl BufRead) -> Result<Identifier, Box<dyn std::error::Error>> {
let mut identifier_input = String::new();
input.read_line(&mut identifier_input)?;
let bytes = hex::decode(identifier_input.trim())?;
let serialization = bytes.try_into().map_err(|_| eyre!("Invalid Identifier"))?;
let identifier = Identifier::deserialize(&serialization)?;
Ok(identifier)
}

// Input required:
// 1. public key package
Expand All @@ -61,11 +70,7 @@ fn choose_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();
let id_value = read_identifier(input).unwrap();

validate(id_value, package, &participants)?;

Expand Down
4 changes: 1 addition & 3 deletions coordinator/src/step_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ fn request_inputs_commitments(
logger: &mut dyn Write,
participants: Vec<Identifier>,
) -> Result<SigningPackage, Box<dyn std::error::Error>> {
writeln!(logger, "The message to be signed")?;
writeln!(logger, "The message to be signed (hex encoded)")?;

let mut msg = String::new();
input.read_line(&mut msg)?;

let message = hex::decode(msg.trim())?;

writeln!(logger, "The number of signers: ")?;

let mut commitments_list: BTreeMap<Identifier, SigningCommitments> = BTreeMap::new();

for p in participants {
Expand Down
7 changes: 0 additions & 7 deletions coordinator/src/step_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ fn request_inputs_signature_shares(
participants: ParticipantsConfig,
signing_package: SigningPackage,
) -> Result<Signature, Box<dyn std::error::Error>> {
writeln!(
logger,
"The number of signers: {}",
participants.participants.len()
)?;
println!("{}", participants.participants.len());

let mut signatures_list: HashMap<Identifier, SignatureShare> = HashMap::new();

for p in participants.participants {
Expand Down
2 changes: 1 addition & 1 deletion coordinator/src/tests/steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn check_step_3() {
signing_package,
);

let expected = "The number of signers: 2\nPlease enter JSON encoded signatures for participant Identifier(\"0100000000000000000000000000000000000000000000000000000000000000\"):\nPlease enter JSON encoded signatures for participant Identifier(\"0300000000000000000000000000000000000000000000000000000000000000\"):\nGroup signature: \"72c948a63797c693e8e978fdb703a1f5a7590472a539da13b71dd6c2b8c1b2a664b7b4af6194439357c5d15f366760fce53c985a186709e74bb0f8e5078ea805\"\n";
let expected = "Please enter JSON encoded signatures for participant Identifier(\"0100000000000000000000000000000000000000000000000000000000000000\"):\nPlease enter JSON encoded signatures for participant Identifier(\"0300000000000000000000000000000000000000000000000000000000000000\"):\nGroup signature: \"72c948a63797c693e8e978fdb703a1f5a7590472a539da13b71dd6c2b8c1b2a664b7b4af6194439357c5d15f366760fce53c985a186709e74bb0f8e5078ea805\"\n";

let (_, res) = &buf.into_parts();
let actual = hex::encode(res.as_ref().unwrap());
Expand Down
6 changes: 3 additions & 3 deletions coordinator/src/tests/values.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ num of participants:
Identifier for participant 1:

```
"0100000000000000000000000000000000000000000000000000000000000000"
0100000000000000000000000000000000000000000000000000000000000000
```

Identifier for participant 3:

```
"0300000000000000000000000000000000000000000000000000000000000000"
0300000000000000000000000000000000000000000000000000000000000000
```

Message to be signed:

```
9c9879ea25578cd0ea40aadea10bcba5517c2395632725c435ae
74657374
```

Commitment for Identifier 1:
Expand Down

0 comments on commit 9f2c617

Please sign in to comment.