Skip to content

Commit

Permalink
Use resolve_muxed_account to get public key
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Dec 3, 2024
1 parent d9131b4 commit 3ad6b9b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
18 changes: 9 additions & 9 deletions cmd/soroban-cli/src/commands/contract/arg_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::xdr::{
};

use crate::commands::txn_result::TxnResult;
use crate::config::{self};
use crate::config::{self, address, secret};
use soroban_spec_tools::Spec;

#[derive(thiserror::Error, Debug)]
Expand All @@ -39,6 +39,10 @@ pub enum Error {
Xdr(#[from] xdr::Error),
#[error(transparent)]
StrVal(#[from] soroban_spec_tools::Error),
#[error(transparent)]
Address(#[from] address::Error),
#[error(transparent)]
Secret(#[from] secret::Error),
#[error("Missing argument {0}")]
MissingArgument(String),
#[error("")]
Expand Down Expand Up @@ -82,16 +86,12 @@ pub fn build_host_function_parameters(
if let Some(mut val) = matches_.get_raw(&name) {
let mut s = val.next().unwrap().to_string_lossy().to_string();
if matches!(i.type_, ScSpecTypeDef::Address) {
let cmd = crate::commands::keys::address::Cmd {
name: s.clone(),
hd_path: Some(0),
locator: config.locator.clone(),
};
if let Ok(address) = cmd.public_key() {
let addr: address::Address = s.parse()?;
if let Ok(address) = addr.resolve_muxed_account(&config.locator, None) {
s = address.to_string();
}
if let Ok(key) = cmd.private_key() {
signers.push(key);
if let Ok(key) = addr.resolve_secret(&config.locator) {
signers.push(SigningKey::from_bytes(&key.private_key(None)?.0));
}
}
spec.from_string(&s, &i.type_)
Expand Down
34 changes: 17 additions & 17 deletions cmd/soroban-cli/src/commands/keys/address.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::commands::config::secret;

use super::super::config::locator;
use clap::arg;

use crate::{
commands::config::{address, locator, secret},
xdr,
};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Expand All @@ -13,13 +15,16 @@ pub enum Error {

#[error(transparent)]
StrKey(#[from] stellar_strkey::DecodeError),

#[error(transparent)]
Address(#[from] address::Error),
}

#[derive(Debug, clap::Parser, Clone)]
#[group(skip)]
pub struct Cmd {
/// Name of identity to lookup, default test identity used if not provided
pub name: String,
pub name: address::Address,

/// If identity is a seed phrase use this hd path, default is 0
#[arg(long)]
Expand All @@ -35,20 +40,15 @@ 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 {
Ok(stellar_strkey::ed25519::PublicKey::from_payload(
self.private_key()?.verifying_key().as_bytes(),
)?)
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))
}
}
}
}

0 comments on commit 3ad6b9b

Please sign in to comment.