From ba8f011cc106c40624b1955c92e23538c1f18899 Mon Sep 17 00:00:00 2001 From: tyshko-rostyslav <122977916+tyshko-rostyslav@users.noreply.github.com> Date: Mon, 5 Jun 2023 11:54:17 +0200 Subject: [PATCH] MVP CLI Proposal implementation: proof/verify functionality (#168) * next feaf command * delete leaf command * get root command * next feaf call * delete leaf call * get root call * GetProof command * Prove command * Verify command * GenerateProof command * VerifyWithRoots command * GetProof call * Prove call * Verify call * GenerateProof call * VerifyWithRoots call * fmt * redundunt * output moved to stdout, better error msg --- rln-cli/src/commands.rs | 21 ++++++++++++++++++++ rln-cli/src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/rln-cli/src/commands.rs b/rln-cli/src/commands.rs index dbc9f16..abb3267 100644 --- a/rln-cli/src/commands.rs +++ b/rln-cli/src/commands.rs @@ -41,4 +41,25 @@ pub(crate) enum Commands { index: usize, }, GetRoot, + GetProof { + index: usize, + }, + Prove { + #[arg(short, long)] + input: PathBuf, + }, + Verify { + #[arg(short, long)] + file: PathBuf, + }, + GenerateProof { + #[arg(short, long)] + input: PathBuf, + }, + VerifyWithRoots { + #[arg(short, long)] + input: PathBuf, + #[arg(short, long)] + roots: PathBuf, + }, } diff --git a/rln-cli/src/main.rs b/rln-cli/src/main.rs index a704118..650af03 100644 --- a/rln-cli/src/main.rs +++ b/rln-cli/src/main.rs @@ -105,6 +105,49 @@ fn main() -> Result<()> { .get_root(writer)?; Ok(()) } + Some(Commands::GetProof { index }) => { + let writer = std::io::stdout(); + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .get_proof(*index, writer)?; + Ok(()) + } + Some(Commands::Prove { input }) => { + let input_data = File::open(&input)?; + let writer = std::io::stdout(); + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .prove(input_data, writer)?; + Ok(()) + } + Some(Commands::Verify { file }) => { + let input_data = File::open(&file)?; + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .verify(input_data)?; + Ok(()) + } + Some(Commands::GenerateProof { input }) => { + let input_data = File::open(&input)?; + let writer = std::io::stdout(); + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .generate_rln_proof(input_data, writer)?; + Ok(()) + } + Some(Commands::VerifyWithRoots { input, roots }) => { + let input_data = File::open(&input)?; + let roots_data = File::open(&roots)?; + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .verify_with_roots(input_data, roots_data)?; + Ok(()) + } None => Ok(()), } }