Skip to content

Commit

Permalink
keys address: use keychain entry in secret to get the pub key
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Nov 20, 2024
1 parent dce2d97 commit a34e808
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cmd/soroban-cli/src/config/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum Error {
Signer(#[from] signer::Error),
#[error("Ledger does not reveal secret key")]
LedgerDoesNotRevealSecretKey,
#[error(transparent)]
Keyring(#[from] keyring::Error),
}

#[derive(Debug, clap::Args, Clone)]
Expand Down Expand Up @@ -109,12 +111,8 @@ impl FromStr for Secret {
} else if s == "ledger" {
Ok(Secret::Ledger)
} else if s.starts_with(keyring::KEYCHAIN_ENTRY_PREFIX) {
let entry_name = s
.strip_prefix(keyring::KEYCHAIN_ENTRY_PREFIX)
.ok_or(Error::InvalidAddress(s.to_string()))?;

Ok(Secret::Keychain {
entry_name: entry_name.to_owned(),
entry_name: s.to_owned(),
})
} else {
Err(Error::InvalidAddress(s.to_string()))
Expand Down Expand Up @@ -146,10 +144,18 @@ impl Secret {
}

pub fn public_key(&self, index: Option<usize>) -> Result<PublicKey, Error> {
let key = self.key_pair(index)?;
Ok(stellar_strkey::ed25519::PublicKey::from_payload(
key.verifying_key().as_bytes(),
)?)
match self {
Secret::Keychain { entry_name } => {
let entry = keyring::StellarEntry::new(entry_name)?;
Ok(entry.get_public_key()?)
}
_ => {
let key = self.key_pair(index)?;
Ok(stellar_strkey::ed25519::PublicKey::from_payload(
key.verifying_key().as_bytes(),
)?)
}
}
}

pub fn signer(&self, index: Option<usize>, print: Print) -> Result<Signer, Error> {
Expand Down

0 comments on commit a34e808

Please sign in to comment.