Skip to content

Commit

Permalink
Updated bin to work without args and parse arguments with clap
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkovAlexander committed Mar 19, 2024
1 parent 58a2b7d commit 5ffe481
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "gosh_bls_lib"
version = "0.3.0"
version = "0.3.1"

[profile.profiling]
debug = 1
Expand All @@ -27,6 +27,7 @@ strip = true # Automatically strip symbols from the binary.
[dependencies]
anyhow = "1.0.80"
blst = { features = ["portable"], version = "0.3.5" }
clap = { version = "4.5.3", features = ["derive"] }
criterion = "0.3"
failure = "0.1"
hex = "0.4.3"
Expand Down
29 changes: 22 additions & 7 deletions src/bin/bls_keypair_gen.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
// 2022-2024 (c) Copyright Contributors to the GOSH DAO. All rights reserved.
//
use gosh_bls_lib::bls::gen_bls_key_pair;
use gosh_bls_lib::bls::gen_bls_key_pair_based_on_key_material;
use gosh_bls_lib::bls::BLS_SECRET_KEY_LEN;
use clap::Parser;

#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Args {
/// Hex string with 32 bytes of key material for bls
#[arg(short, long)]
key_material: Option<String>
}


fn main() {
let args: Vec<String> = std::env::args().collect();
assert!(args.len() > 1, "Secret key should be passed as an argument");
let args: Args = Args::parse();

let (public, secret) = if let Some(key_material) = args.key_material {
let mut secret_key = [0_u8; BLS_SECRET_KEY_LEN];
hex::decode_to_slice(key_material.trim_start_matches("0x"), &mut secret_key)
.expect("Failed to decode secret key from hex");

let mut secret_key = [0_u8; BLS_SECRET_KEY_LEN];
hex::decode_to_slice(args[1].trim_start_matches("0x"), &mut secret_key)
.expect("Failed to decode secret key from hex");
gen_bls_key_pair_based_on_key_material(&secret_key)
.expect("Failed to generate BLS key pair")
} else {
gen_bls_key_pair().expect("Failed to generate BLS key pair")
};

let (public, secret) = gen_bls_key_pair_based_on_key_material(&secret_key)
.expect("Failed to generate BLS key pair");
println!(
r#"{{
"public": "{}",
Expand Down

0 comments on commit 5ffe481

Please sign in to comment.