Skip to content

Commit

Permalink
fix(address): remove private key function & use unresolved Address
Browse files Browse the repository at this point in the history
This simplifies the lookup of the address.
  • Loading branch information
willemneal committed Jan 6, 2025
1 parent 6404da6 commit 085317f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
7 changes: 1 addition & 6 deletions cmd/soroban-cli/src/commands/contract/arg_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,5 @@ fn resolve_address(addr_or_alias: &str, config: &config::Args) -> Result<String,
}

fn resolve_signer(addr_or_alias: &str, config: &config::Args) -> Option<SigningKey> {
let cmd = crate::commands::keys::address::Cmd {
name: addr_or_alias.to_string(),
hd_path: Some(0),
locator: config.locator.clone(),
};
cmd.private_key().ok()
config.locator.key(addr_or_alias).ok()?.key_pair(None).ok()
}
29 changes: 9 additions & 20 deletions cmd/soroban-cli/src/commands/keys/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum Error {
#[group(skip)]
pub struct Cmd {
/// Name of identity to lookup, default test identity used if not provided
pub name: String,
pub name: UnresolvedMuxedAccount,

/// If identity is a seed phrase use this hd path, default is 0
#[arg(long)]
Expand All @@ -40,25 +40,14 @@ impl Cmd {
Ok(())
}

pub fn private_key(&self) -> Result<ed25519_dalek::SigningKey, Error> {
Ok(self
.locator
.read_identity(&self.name)?
.key_pair(self.hd_path)?)
}

pub fn public_key(&self) -> Result<stellar_strkey::ed25519::PublicKey, Error> {
if let Ok(key) = stellar_strkey::ed25519::PublicKey::from_string(&self.name) {
Ok(key)
} else if let Ok(unresolved) = self.name.parse::<UnresolvedMuxedAccount>() {
let muxed = unresolved.resolve_muxed_account(&self.locator, self.hd_path)?;
Ok(stellar_strkey::ed25519::PublicKey::from_string(
&muxed.to_string(),
)?)
} else {
Ok(stellar_strkey::ed25519::PublicKey::from_payload(
self.private_key()?.verifying_key().as_bytes(),
)?)
}
let muxed = self
.name
.resolve_muxed_account(&self.locator, self.hd_path)?;
let bytes = match muxed {
soroban_sdk::xdr::MuxedAccount::Ed25519(uint256) => uint256.0,
soroban_sdk::xdr::MuxedAccount::MuxedEd25519(muxed_account) => muxed_account.ed25519.0,
};
Ok(stellar_strkey::ed25519::PublicKey(bytes))
}
}
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/config/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl UnresolvedMuxedAccount {
UnresolvedMuxedAccount::Resolved(muxed_account) => {
Err(Error::CannotSign(muxed_account.clone()))
}
UnresolvedMuxedAccount::AliasOrSecret(alias) => Ok(locator.read_identity(alias)?),
UnresolvedMuxedAccount::AliasOrSecret(alias) => Ok(locator.key(alias)?),
}
}
}
Expand Down

0 comments on commit 085317f

Please sign in to comment.