diff --git a/Cargo.lock b/Cargo.lock index 412ed42a608..c45b818dc8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2957,7 +2957,7 @@ dependencies = [ "anyhow", "clap 4.4.5", "fuel-core-types", - "libp2p-core 0.38.0", + "libp2p-identity 0.2.4", "serde_json", ] @@ -4373,7 +4373,7 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-identity", + "libp2p-identity 0.1.3", "log", "multiaddr 0.17.1", "multihash 0.17.0", @@ -4473,6 +4473,25 @@ dependencies = [ "zeroize", ] +[[package]] +name = "libp2p-identity" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f37304f29c82ede408db06aaba60cd2f783a111f46414d3fc4beedac19e0c67b" +dependencies = [ + "asn1_der", + "bs58 0.5.0", + "hkdf", + "libsecp256k1", + "log", + "multihash 0.19.1", + "quick-protobuf", + "rand 0.8.5", + "sha2 0.10.8", + "thiserror", + "zeroize", +] + [[package]] name = "libp2p-kad" version = "0.42.0" @@ -4586,7 +4605,7 @@ dependencies = [ "curve25519-dalek 3.2.0", "futures", "libp2p-core 0.39.2", - "libp2p-identity", + "libp2p-identity 0.1.3", "log", "once_cell", "quick-protobuf", @@ -4610,7 +4629,7 @@ dependencies = [ "futures-timer", "if-watch", "libp2p-core 0.39.2", - "libp2p-identity", + "libp2p-identity 0.1.3", "libp2p-tls", "log", "parking_lot 0.12.1", @@ -4697,7 +4716,7 @@ dependencies = [ "futures", "futures-rustls", "libp2p-core 0.39.2", - "libp2p-identity", + "libp2p-identity 0.1.3", "rcgen 0.10.0", "ring", "rustls 0.20.9", @@ -4721,7 +4740,7 @@ dependencies = [ "hex", "if-watch", "libp2p-core 0.39.2", - "libp2p-identity", + "libp2p-identity 0.1.3", "libp2p-noise 0.42.2", "log", "multihash 0.17.0", @@ -5140,6 +5159,16 @@ dependencies = [ "unsigned-varint", ] +[[package]] +name = "multihash" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" +dependencies = [ + "core2", + "unsigned-varint", +] + [[package]] name = "multihash-derive" version = "0.8.1" diff --git a/bin/keygen/Cargo.toml b/bin/keygen/Cargo.toml index 87abf698b89..b74b70fb958 100644 --- a/bin/keygen/Cargo.toml +++ b/bin/keygen/Cargo.toml @@ -13,5 +13,5 @@ description = "Command line utilities for fuel-core key management" anyhow = { workspace = true } clap = { workspace = true, features = ["derive", "env"] } fuel-core-types = { workspace = true, features = ["serde", "random"] } -libp2p-core = { version = "0.38", features = ["secp256k1"] } +libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] } serde_json = { workspace = true, features = ["raw_value"] } diff --git a/bin/keygen/src/keygen.rs b/bin/keygen/src/keygen.rs index caa59937920..5a7458815bd 100644 --- a/bin/keygen/src/keygen.rs +++ b/bin/keygen/src/keygen.rs @@ -1,50 +1,19 @@ -use clap::{ - Parser, - ValueEnum, -}; +use clap::ValueEnum; use fuel_core_types::{ fuel_crypto::{ - rand::{ - prelude::StdRng, - SeedableRng, - }, + rand::{prelude::StdRng, SeedableRng}, SecretKey, }, fuel_tx::Input, }; -use libp2p_core::{ - identity::{ - secp256k1, - Keypair, - }, - PeerId, -}; +use libp2p_identity::{secp256k1, Keypair, PeerId}; use serde_json::json; -use std::{ - ops::Deref, - str::FromStr, -}; - -/// Key management utilities for configuring fuel-core -#[derive(Debug, Parser)] -pub(crate) enum Command { - New(NewKey), - Parse(ParseSecret), -} - -impl Command { - pub(crate) fn exec(&self) -> anyhow::Result<()> { - match self { - Command::New(cmd) => cmd.exec(), - Command::Parse(cmd) => cmd.exec(), - } - } -} +use std::{ops::Deref, str::FromStr}; /// Generate a random new secret & public key in the format expected by fuel-core #[derive(Debug, clap::Args)] #[clap(author, version, about)] -pub(crate) struct NewKey { +pub struct NewKey { #[clap(long = "pretty", short = 'p')] pretty: bool, #[clap( @@ -57,14 +26,14 @@ pub(crate) struct NewKey { } #[derive(Clone, Debug, Default, ValueEnum)] -pub(crate) enum KeyType { +pub enum KeyType { #[default] BlockProduction, Peering, } impl NewKey { - fn exec(&self) -> anyhow::Result<()> { + pub fn exec(&self) -> anyhow::Result<()> { let mut rng = StdRng::from_entropy(); let secret = SecretKey::random(&mut rng); let public_key = secret.public_key(); @@ -81,9 +50,10 @@ impl NewKey { } KeyType::Peering => { let mut bytes = *secret.deref(); - let p2p_secret = secp256k1::SecretKey::from_bytes(&mut bytes) + let p2p_secret = secp256k1::SecretKey::try_from_bytes(&mut bytes) .expect("Should be a valid private key"); - let libp2p_keypair = Keypair::Secp256k1(p2p_secret.into()); + let p2p_keypair = secp256k1::Keypair::from(p2p_secret); + let libp2p_keypair = Keypair::from(p2p_keypair); let peer_id = PeerId::from_public_key(&libp2p_keypair.public()); json!({ "secret": secret_str, @@ -99,7 +69,7 @@ impl NewKey { /// Parse a secret key to view the associated public key #[derive(Debug, clap::Args)] #[clap(author, version, about)] -pub(crate) struct ParseSecret { +pub struct ParseSecret { secret: String, #[clap(long = "pretty", short = 'p')] pretty: bool, @@ -113,7 +83,7 @@ pub(crate) struct ParseSecret { } impl ParseSecret { - fn exec(&self) -> anyhow::Result<()> { + pub fn exec(&self) -> anyhow::Result<()> { let secret = SecretKey::from_str(&self.secret)?; match self.key_type { KeyType::BlockProduction => { @@ -126,9 +96,10 @@ impl ParseSecret { } KeyType::Peering => { let mut bytes = *secret.deref(); - let p2p_secret = secp256k1::SecretKey::from_bytes(&mut bytes) + let p2p_secret = secp256k1::SecretKey::try_from_bytes(&mut bytes) .expect("Should be a valid private key"); - let libp2p_keypair = Keypair::Secp256k1(p2p_secret.into()); + let p2p_keypair = secp256k1::Keypair::from(p2p_secret); + let libp2p_keypair = Keypair::from(p2p_keypair); let peer_id = PeerId::from_public_key(&libp2p_keypair.public()); let output = json!({ "peer_id": peer_id.to_string(), diff --git a/bin/keygen/src/lib.rs b/bin/keygen/src/lib.rs new file mode 100644 index 00000000000..51bb95fabb1 --- /dev/null +++ b/bin/keygen/src/lib.rs @@ -0,0 +1,3 @@ +//! Keygen crate + +pub mod keygen; diff --git a/bin/keygen/src/main.rs b/bin/keygen/src/main.rs index 62fbb198ba6..c05cef36f68 100644 --- a/bin/keygen/src/main.rs +++ b/bin/keygen/src/main.rs @@ -1,10 +1,25 @@ //! A simple keygen cli utility tool for configuring fuel-core use clap::Parser; +use fuel_core_keygen::keygen; -pub mod keygen; +/// Key management utilities for configuring fuel-core +#[derive(Debug, Parser)] +pub(crate) enum Command { + New(keygen::NewKey), + Parse(keygen::ParseSecret), +} + +impl Command { + pub(crate) fn exec(&self) -> anyhow::Result<()> { + match self { + Command::New(cmd) => cmd.exec(), + Command::Parse(cmd) => cmd.exec(), + } + } +} fn main() -> anyhow::Result<()> { - let cmd = keygen::Command::parse(); + let cmd = Command::parse(); cmd.exec() }