Skip to content

Commit

Permalink
Add parity-npub commmand.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoquick committed Dec 6, 2023
1 parent 3779e06 commit d3b6477
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
7 changes: 7 additions & 0 deletions src/bin/carbonadod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit d3b6477

Please sign in to comment.