diff --git a/cmd/soroban-cli/src/commands/keys/address.rs b/cmd/soroban-cli/src/commands/keys/address.rs index 145d8c30a..aa5a2940d 100644 --- a/cmd/soroban-cli/src/commands/keys/address.rs +++ b/cmd/soroban-cli/src/commands/keys/address.rs @@ -1,9 +1,6 @@ use clap::arg; -use crate::{ - commands::config::{address, locator, secret}, - xdr, -}; +use crate::commands::config::{address, locator, secret}; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -24,7 +21,7 @@ pub enum Error { #[group(skip)] pub struct Cmd { /// Name of identity to lookup, default test identity used if not provided - pub name: address::Address, + pub name: String, /// If identity is a seed phrase use this hd path, default is 0 #[arg(long)] @@ -40,15 +37,20 @@ impl Cmd { Ok(()) } + pub fn private_key(&self) -> Result { + Ok(self + .locator + .read_identity(&self.name)? + .key_pair(self.hd_path)?) + } + pub fn public_key(&self) -> Result { - match self - .name - .resolve_muxed_account(&self.locator, self.hd_path)? - { - xdr::MuxedAccount::Ed25519(pk) => Ok(stellar_strkey::ed25519::PublicKey(pk.0)), - xdr::MuxedAccount::MuxedEd25519(xdr::MuxedAccountMed25519 { ed25519, .. }) => { - Ok(stellar_strkey::ed25519::PublicKey(ed25519.0)) - } + if let Ok(key) = stellar_strkey::ed25519::PublicKey::from_string(&self.name) { + Ok(key) + } else { + Ok(stellar_strkey::ed25519::PublicKey::from_payload( + self.private_key()?.verifying_key().as_bytes(), + )?) } } }