-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdbe919
commit 18629cc
Showing
3 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
pub mod resolve; | ||
pub mod publish; | ||
pub mod generate; | ||
pub mod generate; | ||
mod publickey; | ||
|
||
pub use publickey::cli_publickey; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::{fs::read_to_string, path::{Path, PathBuf}}; | ||
use clap::ArgMatches; | ||
use pkarr::Keypair; | ||
|
||
|
||
|
||
const SECRET_KEY_LENGTH: usize = 32; | ||
|
||
fn read_seed_file(matches: &ArgMatches) -> Keypair { | ||
let unexpanded_path: &String = matches.get_one("seed").unwrap(); | ||
let expanded_path: String = shellexpand::full(unexpanded_path) | ||
.expect("Valid shell path.") | ||
.into(); | ||
let path = Path::new(&expanded_path); | ||
let path = PathBuf::from(path); | ||
|
||
let seed = read_to_string(path); | ||
if let Err(e) = seed { | ||
eprintln!("Failed to read seed at {expanded_path}. {e}"); | ||
std::process::exit(1); | ||
}; | ||
let seed = seed.unwrap(); | ||
parse_seed(&seed) | ||
} | ||
|
||
fn parse_seed(seed: &str) -> Keypair { | ||
let seed = seed.trim(); | ||
let decode_result = zbase32::decode_full_bytes_str(&seed); | ||
if let Err(e) = decode_result { | ||
eprintln!("Failed to parse the seed file. {e} {seed}"); | ||
std::process::exit(1); | ||
}; | ||
|
||
let plain_secret = decode_result.unwrap(); | ||
|
||
let slice: &[u8; SECRET_KEY_LENGTH] = &plain_secret[0..SECRET_KEY_LENGTH].try_into().unwrap(); | ||
let keypair = Keypair::from_secret_key(slice); | ||
keypair | ||
} | ||
|
||
pub async fn cli_publickey(matches: &ArgMatches) { | ||
|
||
let keypair = read_seed_file(matches); | ||
let pubkey = keypair.to_z32(); | ||
|
||
println!("{pubkey}"); | ||
|
||
} | ||
|