Skip to content

Commit

Permalink
Apply formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Jan 14, 2025
1 parent b59fc3d commit 9601f22
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 19 deletions.
13 changes: 9 additions & 4 deletions cmd/soroban-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use sep5::SeedPhrase;

use crate::{
commands::global,
config::{address::KeyName, locator, secret::{self, Secret}},
print::Print, signer::secure_store,
config::{
address::KeyName,
locator,
secret::{self, Secret},
},
print::Print,
signer::secure_store,
};

#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -51,7 +56,7 @@ impl Cmd {

fn read_secret(&self, print: &Print) -> Result<Secret, Error> {
if let Ok(secret_key) = std::env::var("SOROBAN_SECRET_KEY") {
return Ok(Secret::SecretKey { secret_key })
return Ok(Secret::SecretKey { secret_key });
} else if self.secrets.secure_store {
let prompt = "Type a 12 or 24 word seed phrase:";
let secret_key = read_password(print, prompt)?;
Expand All @@ -71,4 +76,4 @@ fn read_password(print: &Print, prompt: &str) -> Result<String, Error> {
print.arrowln(prompt);
std::io::stdout().flush().map_err(|_| Error::PasswordRead)?;
rpassword::read_password().map_err(|_| Error::PasswordRead)
}
}
9 changes: 2 additions & 7 deletions cmd/soroban-cli/src/commands/keys/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ use super::super::config::{
locator, network,
secret::{self, Secret},
};
use crate::{
commands::global,
config::address::KeyName,
print::Print,
signer::secure_store,
};
use crate::{commands::global, config::address::KeyName, print::Print, signer::secure_store};

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -27,7 +22,7 @@ pub enum Error {
IdentityAlreadyExists(String),

#[error(transparent)]
SecureStore(#[from] secure_store::Error)
SecureStore(#[from] secure_store::Error),
}

#[derive(Debug, clap::Parser, Clone)]
Expand Down
8 changes: 7 additions & 1 deletion cmd/soroban-cli/src/config/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ use std::{
};
use stellar_strkey::{Contract, DecodeError};

use crate::{commands::{global, HEADING_GLOBAL}, print::Print, signer::{self, keyring::StellarEntry}, utils::find_config_dir, Pwd};
use crate::{
commands::{global, HEADING_GLOBAL},
print::Print,
signer::{self, keyring::StellarEntry},
utils::find_config_dir,
Pwd,
};

use super::{
alias,
Expand Down
4 changes: 3 additions & 1 deletion cmd/soroban-cli/src/config/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use sep5::SeedPhrase;
use stellar_strkey::ed25519::{PrivateKey, PublicKey};

use crate::{
print::Print, signer::{self, keyring, LocalKey, SecureStoreEntry, Signer, SignerKind}, utils
print::Print,
signer::{self, keyring, LocalKey, SecureStoreEntry, Signer, SignerKind},
utils,
};

#[derive(thiserror::Error, Debug)]
Expand Down
24 changes: 18 additions & 6 deletions cmd/soroban-cli/src/signer/secure_store.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use sep5::SeedPhrase;

use crate::{
config::{address::KeyName, locator, secret::{self, Secret}}, print::Print, signer::keyring::{self, StellarEntry}
config::{
address::KeyName,
locator,
secret::{self, Secret},
},
print::Print,
signer::keyring::{self, StellarEntry},
};

#[derive(thiserror::Error, Debug)]
pub enum Error{
pub enum Error {
#[error(transparent)]
Config(#[from] locator::Error),

Expand All @@ -19,10 +25,14 @@ pub enum Error{
DoesNotSupportPrivateKey,

#[error(transparent)]
SeedPhrase(#[from] sep5::Error)
SeedPhrase(#[from] sep5::Error),
}

pub fn save_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 @@ -49,11 +59,13 @@ fn write_to_secure_store(
print.infoln(format!("Writing to secure store: {entry_name}"));
let entry = StellarEntry::new(entry_name)?;
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}"));
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)?;
})
}
}

0 comments on commit 9601f22

Please sign in to comment.