Skip to content

Commit

Permalink
allow reading message from file
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg committed Jan 30, 2024
1 parent 1112329 commit 31b9cb6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions coordinator/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ pub struct Args {
#[arg(short = 'P', long, default_value = "public-key-package.json")]
pub public_key_package: String,

/// The message to sign. Can be a file with the raw message, or "-". If "-"
/// is specified, then it will be read from standard input as a hex string.
#[arg(short = 'm', long, default_value = "-")]
pub message: String,

/// Where to write the generated raw bytes signature. If "-", the
/// human-readable hex-string is printed to stdout.
#[arg(short = 's', long, default_value = "-")]
Expand Down
8 changes: 7 additions & 1 deletion coordinator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ pub async fn cli(
"=== STEP 2: CHOOSE MESSAGE AND GENERATE COMMITMENT PACKAGE ===\n"
)?;

let signing_package = step_2(reader, logger, participants_config.commitments.clone()).await?;
let signing_package = step_2(
args,
reader,
logger,
participants_config.commitments.clone(),
)
.await?;

#[cfg(feature = "redpallas")]
let randomizer = request_randomizer(reader, logger)?;
Expand Down
19 changes: 14 additions & 5 deletions coordinator/src/step_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,47 @@ use frost::{round1::SigningCommitments, Identifier, SigningPackage};

use std::{
collections::BTreeMap,
fs,
io::{BufRead, Write},
};

use crate::args::Args;

#[derive(Debug, PartialEq, Clone)]
pub struct CommitmentsConfig {
pub message: Vec<u8>,
pub signer_commitments: BTreeMap<Identifier, SigningCommitments>,
}

pub async fn step_2(
args: &Args,
input: &mut impl BufRead,
logger: &mut dyn Write,
commitments: BTreeMap<Identifier, SigningCommitments>,
) -> Result<SigningPackage, Box<dyn std::error::Error>> {
let signing_package = request_message(input, logger, commitments)?;
let signing_package = request_message(args, input, logger, commitments)?;
print_signing_package(logger, &signing_package);
Ok(signing_package)
}

// Input required:
// 1. message
fn request_message(
args: &Args,
input: &mut impl BufRead,
logger: &mut dyn Write,
commitments: BTreeMap<Identifier, SigningCommitments>,
) -> Result<SigningPackage, Box<dyn std::error::Error>> {
writeln!(logger, "The message to be signed (hex encoded)")?;
let message = if args.message == "-" {
writeln!(logger, "The message to be signed (hex encoded)")?;

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

let message = hex::decode(msg.trim())?;
hex::decode(msg.trim())?
} else {
fs::read(&args.message)?
};

let signing_package = SigningPackage::new(commitments, &message);

Expand Down

0 comments on commit 31b9cb6

Please sign in to comment.