1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use super::super::{locator, secret};
use clap::arg;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),
#[error(transparent)]
Secret(#[from] secret::Error),
#[error(transparent)]
StrKey(#[from] stellar_strkey::DecodeError),
}
#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {
pub name: Option<String>,
#[arg(long)]
pub hd_path: Option<usize>,
#[command(flatten)]
pub locator: locator::Args,
}
impl Cmd {
pub fn run(&self) -> Result<(), Error> {
println!("{}", self.private_key()?.to_string());
Ok(())
}
pub fn private_key(&self) -> Result<stellar_strkey::ed25519::PrivateKey, Error> {
Ok(if let Some(name) = &self.name {
self.locator.read_identity(name)?
} else {
secret::Secret::test_seed_phrase()?
}
.private_key(self.hd_path)?)
}
}