diff --git a/cmd/soroban-cli/src/config/secret.rs b/cmd/soroban-cli/src/config/secret.rs index dddf409ec..e9c3f0d69 100644 --- a/cmd/soroban-cli/src/config/secret.rs +++ b/cmd/soroban-cli/src/config/secret.rs @@ -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)] @@ -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())) @@ -146,10 +144,18 @@ impl Secret { } pub fn public_key(&self, index: Option) -> Result { - 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, print: Print) -> Result {