Skip to content

Commit

Permalink
bin/darkirc: add abbility to recover our own public key from secret key
Browse files Browse the repository at this point in the history
  • Loading branch information
Dastan-glitch committed Aug 9, 2023
1 parent 74cac6c commit 7a088ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bin/darkirc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ async fn realmain(settings: Args, executor: Arc<smol::Executor<'_>>) -> Result<(
return Ok(())
}

if settings.secret.is_some() {
let secret = settings.secret.clone().unwrap();
let bytes: [u8; 32] = bs58::decode(secret).into_vec()?.try_into().unwrap();
let secret = crypto_box::SecretKey::from(bytes);
let pubkey = secret.public_key();
let pub_encoded = bs58::encode(pubkey.as_bytes()).into_string();

if settings.output.is_some() {
let datastore = expand_path(&settings.output.unwrap())?;
save_json_file(&datastore, &pub_encoded, false)?;
} else {
println!("Public key recoverd: {}", pub_encoded);
}

return Ok(())
}

if settings.gen_secret {
let secret_key = crypto_box::SecretKey::generate(&mut OsRng);
let encoded = bs58::encode(secret_key.to_bytes());
Expand Down
4 changes: 4 additions & 0 deletions bin/darkirc/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub struct Args {
#[structopt(long)]
pub gen_secret: bool,

/// Recover public key from secret key
#[structopt(long = "recover_pubkey")]
pub secret: Option<String>,

/// Path to save keypair in
#[structopt(short)]
pub output: Option<String>,
Expand Down

0 comments on commit 7a088ee

Please sign in to comment.