Skip to content

Commit

Permalink
Merge branch 'main' into jh/testnode
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit authored May 22, 2024
2 parents 4363b7d + 35b7901 commit 753875b
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions sequencer/src/bin/pub-key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::bail;
use clap::Parser;
use hotshot::{traits::implementations::derive_libp2p_peer_id, types::BLSPubKey};
use hotshot_types::{
light_client::{StateKeyPair, StateSignKey},
traits::signature_key::SignatureKey,
Expand Down Expand Up @@ -30,13 +31,33 @@ impl FromStr for PrivateKey {
/// Get the public key corresponding to a private key.
#[derive(Clone, Debug, Parser)]
struct Options {
/// The private key to get the public key for.
key: PrivateKey,

// Whether or not to derive the libp2p peer ID from the private key.
#[clap(long, short)]
libp2p: bool,
}

fn main() {
let opt = Options::parse();
match opt.key {
PrivateKey::Bls(key) => println!("{}", PubKey::from_private(&key)),
PrivateKey::Schnorr(key) => println!("{}", StateKeyPair::from_sign_key(key).ver_key()),

match (opt.libp2p, opt.key) {
// Non-libp2p
(false, PrivateKey::Bls(key)) => println!("{}", PubKey::from_private(&key)),
(false, PrivateKey::Schnorr(key)) => {
println!("{}", StateKeyPair::from_sign_key(key).ver_key())
}

// Libp2p
(true, PrivateKey::Bls(key)) => {
println!(
"{}",
derive_libp2p_peer_id::<BLSPubKey>(&key).expect("Failed to derive libp2p peer ID")
);
}
(true, _) => {
eprintln!("Key type unsupported for libp2p peer ID derivation");
}
}
}

0 comments on commit 753875b

Please sign in to comment.