diff --git a/Cargo.lock b/Cargo.lock index 3310616..8b312a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -409,6 +409,7 @@ dependencies = [ "mime", "mime_guess", "nom 7.1.3", + "nostr", "nostr-sdk", "once_cell", "par-stream", diff --git a/Cargo.toml b/Cargo.toml index 2d10e28..f5d7e44 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ log = "0.4.17" mime = "0.3" mime_guess = "2.0" nom = "7.1.3" +nostr = "0.25.0" nostr-sdk = "0.25.0" once_cell = "1.17.1" par-stream = { version = "0.10.2", features = ["runtime-tokio"] } diff --git a/src/bin/carbonadod.rs b/src/bin/carbonadod.rs index 9b9c26d..3766afc 100644 --- a/src/bin/carbonadod.rs +++ b/src/bin/carbonadod.rs @@ -11,11 +11,18 @@ use log::error; enum Commands { /// Start storage provider node with configured frontends Start, + /// Derive the parity npub from nsec + ParityNpub { + /// Nostr secret key + #[arg(long)] + nsec: String, + }, } pub async fn try_main() -> Result<()> { match Commands::parse() { Commands::Start => carbonado_node::start().await?, + Commands::ParityNpub { nsec } => carbonado_node::parity_npub(&nsec)?, } Ok(()) diff --git a/src/lib.rs b/src/lib.rs index a04f426..ca7de48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,3 +40,22 @@ pub async fn start() -> Result<()> { Ok(()) } + +pub fn parity_npub(nsec: &str) -> Result<()> { + use nostr::{secp256k1::SecretKey, FromBech32, Keys, ToBech32}; + + let secret_key = SecretKey::from_bech32(nsec)?; + let keys = Keys::new(secret_key); + let (pk, parity) = keys.normalized_public_key()?.x_only_public_key(); + + println!( + "Parity npub is: {}{}", + match parity { + secp256k1::Parity::Even => '+', + secp256k1::Parity::Odd => '-', + }, + pk.to_bech32()? + ); + + Ok(()) +}