Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bin updates #2

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 21 additions & 7 deletions src/bin/bls_keypair_gen.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
// 2022-2024 (c) Copyright Contributors to the GOSH DAO. All rights reserved.
//
use clap::Parser;
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;

#[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