Skip to content

Commit

Permalink
Cleanup & refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Jan 14, 2025
1 parent 16cfacd commit 5b763f2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Cmd {
if self.secrets.secure_store {
let seed_phrase: SeedPhrase = secret_key.parse()?;
let print = &Print::new(false);
Ok(SecureStore::secret(print, &self.name, seed_phrase)?)
Ok(SecureStore::save_secret(print, &self.name, seed_phrase)?)
} else {
Ok(secret_key.parse()?)
}
Expand Down
14 changes: 6 additions & 8 deletions cmd/soroban-cli/src/commands/keys/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,13 @@ impl Cmd {
fn secret(&self, print: &Print) -> Result<Secret, Error> {
let seed_phrase = self.seed_phrase()?;
if self.secure_store {
let secret = SecureStore::secret(print, &self.name, seed_phrase)?;
return Ok(secret)
}
let secret: Secret = seed_phrase.into();
Ok(if self.as_secret {
secret.private_key(self.hd_path)?.into()
Ok(SecureStore::save_secret(print, &self.name, seed_phrase)?)
} else if self.as_secret {
let secret: Secret = seed_phrase.into();
Ok(secret.private_key(self.hd_path)?.into())
} else {
secret
})
Ok(seed_phrase.into())
}
}

fn seed_phrase(&self) -> Result<SeedPhrase, Error> {
Expand Down
2 changes: 0 additions & 2 deletions cmd/soroban-cli/src/config/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use crate::{

#[derive(thiserror::Error, Debug)]
pub enum Error {
// #[error("seed_phrase must be 12 words long, found {len}")]
// InvalidSeedPhrase { len: usize },
#[error(transparent)]
Secret(#[from] stellar_strkey::DecodeError),
#[error(transparent)]
Expand Down
7 changes: 3 additions & 4 deletions cmd/soroban-cli/src/signer/secure_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum Error{
}

impl SecureStore {
pub fn secret(print: &Print, entry_name: &KeyName, seed_phrase: SeedPhrase) -> Result<Secret, Error> {
pub fn save_secret(print: &Print, entry_name: &KeyName, seed_phrase: SeedPhrase) -> Result<Secret, Error> {
// secure_store:org.stellar.cli:<key name>
let entry_name_with_prefix = format!(
"{}{}-{}",
Expand All @@ -51,14 +51,13 @@ impl SecureStore {
) -> Result<(), Error> {
print.infoln(format!("Writing to secure store: {entry_name}"));
let entry = StellarEntry::new(entry_name)?;
if let Ok(key) = entry.get_public_key(None) {
Ok(if let Ok(key) = entry.get_public_key(None) {
print.warnln(format!("A key for {entry_name} already exists in your operating system's secure store: {key}"));
} else {
print.infoln(format!(
"Saving a new key to your operating system's secure store: {entry_name}"
));
entry.set_seed_phrase(seed_phrase)?;
}
Ok(())
})
}
}

0 comments on commit 5b763f2

Please sign in to comment.