diff --git a/apps/src/lib/client/mod.rs b/apps/src/lib/client/mod.rs index 57f3c5a043..8862c5a564 100644 --- a/apps/src/lib/client/mod.rs +++ b/apps/src/lib/client/mod.rs @@ -1,4 +1,3 @@ pub mod rpc; -pub mod signing; pub mod tx; pub mod utils; diff --git a/apps/src/lib/client/signing.rs b/apps/src/lib/client/signing.rs deleted file mode 100644 index 2399c60887..0000000000 --- a/apps/src/lib/client/signing.rs +++ /dev/null @@ -1,79 +0,0 @@ -//! Helpers for making digital signatures using cryptographic keys from the -//! wallet. - -use namada::core::types::account::AccountPublicKeysMap; -use namada::ledger::signing::TxSigningKey; -use namada::ledger::tx; -use namada::ledger::wallet::{Wallet, WalletUtils}; -use namada::proto::Tx; -use namada::types::address::Address; -use namada::types::key::*; - -use crate::cli::args; - -/// Find the public key for the given address and try to load the keypair -/// for it from the wallet. Panics if the key cannot be found or loaded. -pub async fn find_pk( - client: &C, - wallet: &mut Wallet, - addr: &Address, -) -> Result -where - C: namada::ledger::queries::Client + Sync, - C::Error: std::fmt::Display, - U: WalletUtils, -{ - namada::ledger::signing::find_pk(client, wallet, addr, None).await -} - -/// Given CLI arguments and some defaults, determine the rightful transaction -/// signer. Return the given signing key or public key of the given signer if -/// possible. If no explicit signer given, use the `default`. If no `default` -/// is given, panics. -pub async fn tx_signer( - client: &C, - wallet: &mut Wallet, - args: &args::Tx, - default: TxSigningKey, -) -> Result<(Option
, Vec), tx::Error> -where - C: namada::ledger::queries::Client + Sync, - C::Error: std::fmt::Display, - U: WalletUtils, -{ - namada::ledger::signing::tx_signer::(client, wallet, args, default) - .await -} - -/// Sign a transaction with a given signing key or public key of a given signer. -/// If no explicit signer given, use the `default`. If no `default` is given, -/// panics. -/// -/// If this is not a dry run, the tx is put in a wrapper and returned along with -/// hashes needed for monitoring the tx on chain. -/// -/// If it is a dry run, it is not put in a wrapper, but returned as is. -pub async fn sign_tx( - wallet: &mut Wallet, - tx: &mut Tx, - args: &args::Tx, - public_keys_index_map: &AccountPublicKeysMap, - public_keys: &[common::PublicKey], - threshold: u8, - _default: &common::PublicKey, -) -> Result<(), tx::Error> -where - C: namada::ledger::queries::Client + Sync, - C::Error: std::fmt::Display, - U: WalletUtils, -{ - namada::ledger::signing::sign_tx( - wallet, - tx, - args, - public_keys_index_map, - public_keys, - threshold, - ) - .await -} diff --git a/apps/src/lib/client/tx.rs b/apps/src/lib/client/tx.rs index e2daa4b8e1..2ff219e0b7 100644 --- a/apps/src/lib/client/tx.rs +++ b/apps/src/lib/client/tx.rs @@ -12,7 +12,7 @@ use masp_proofs::prover::LocalTxProver; use namada::core::types::account::AccountPublicKeysMap; use namada::ledger::governance::storage as gov_storage; use namada::ledger::rpc::{TxBroadcastData, TxResponse}; -use namada::ledger::signing::TxSigningKey; +use namada::ledger::signing::{find_pk, TxSigningKey}; use namada::ledger::wallet::{Wallet, WalletUtils}; use namada::ledger::{masp, pos, signing, tx}; use namada::proof_of_stake::parameters::PosParams; @@ -33,7 +33,6 @@ use super::rpc; use crate::cli::context::WalletAddress; use crate::cli::{args, safe_exit, Context}; use crate::client::rpc::query_wasm_code_hash; -use crate::client::signing::find_pk; use crate::client::tx::tx::ProcessTxResponse; use crate::config::TendermintMode; use crate::facade::tendermint_rpc::endpoint::broadcast::tx_sync::Response; @@ -171,6 +170,7 @@ where { let (mut tx, addr, public_keys) = tx::build_init_account(client, &mut ctx.wallet, args.clone()).await?; + submit_reveal_aux( client, ctx, @@ -778,7 +778,7 @@ where if args.offline { let signer = ctx.get(&signer); - let key = find_pk(client, &mut ctx.wallet, &signer).await?; + let key = find_pk(client, &mut ctx.wallet, &signer, None).await?; let signing_key = signing::find_key_by_pk(&mut ctx.wallet, &args.tx, &key)?; let offline_proposal = @@ -994,7 +994,8 @@ where safe_exit(1) } - let key = find_pk(client, &mut ctx.wallet, &args.voter_address).await?; + let key = + find_pk(client, &mut ctx.wallet, &args.voter_address, None).await?; let signing_key = signing::find_key_by_pk(&mut ctx.wallet, &args.tx, &key)?; let offline_vote = OfflineVote::new( diff --git a/shared/src/ledger/signing.rs b/shared/src/ledger/signing.rs index 4d3aed9202..b8cdf01c3a 100644 --- a/shared/src/ledger/signing.rs +++ b/shared/src/ledger/signing.rs @@ -154,17 +154,13 @@ pub async fn tx_signer< wallet: &mut Wallet, args: &args::Tx, default: TxSigningKey, -) -> Result<(Option
, Vec), Error> { - let signer = if args.dry_run { - // We cannot override the signer if we're doing a dry run - default - } else if !&args.signing_keys.is_empty() { +) -> Result, Error> { + let signer = if !&args.signing_keys.is_empty() { let public_keys = args.signing_keys.iter().map(|key| key.ref_to()).collect(); - - return Ok((None, public_keys)); + return Ok(public_keys); } else if let Some(verification_key) = &args.verification_key { - return Ok((None, vec![verification_key.clone()])); + return Ok(vec![verification_key.clone()]); } else { // Otherwise use the signer determined by the caller default @@ -173,15 +169,12 @@ pub async fn tx_signer< // Now actually fetch the signing key and apply it match signer { TxSigningKey::WalletAddress(signer) if signer == masp() => { - Ok((None, vec![masp_tx_key().ref_to()])) + Ok(vec![masp_tx_key().ref_to()]) } - TxSigningKey::WalletAddress(signer) => Ok(( - Some(signer.clone()), - vec![ - find_pk::(client, wallet, &signer, args.password.clone()) - .await?, - ], - )), + TxSigningKey::WalletAddress(signer) => Ok(vec![ + find_pk::(client, wallet, &signer, args.password.clone()) + .await?, + ]), TxSigningKey::None => other_err( "All transactions must be signed; please either specify the key \ or the address from which to look up the signing key." diff --git a/shared/src/ledger/tx.rs b/shared/src/ledger/tx.rs index f93af89921..f2aba5974e 100644 --- a/shared/src/ledger/tx.rs +++ b/shared/src/ledger/tx.rs @@ -253,11 +253,11 @@ pub async fn prepare_tx< wallet: &mut Wallet, args: &args::Tx, tx: Tx, - _owner: Option
, + owner: Option
, default_signer: TxSigningKey, #[cfg(not(feature = "mainnet"))] requires_pow: bool, ) -> Result<(Tx, Option
, Vec), Error> { - let (signer_address, signer_public_keys) = + let signer_public_keys = tx_signer::(client, wallet, args, default_signer.clone()).await?; let fee_payer = match &args.fee_payer { @@ -275,7 +275,7 @@ pub async fn prepare_tx< }; if args.dry_run { - Ok((tx, signer_address, signer_public_keys)) + Ok((tx, owner, signer_public_keys)) } else { let epoch = rpc::query_epoch(client).await; Ok(( @@ -290,7 +290,7 @@ pub async fn prepare_tx< requires_pow, ) .await, - signer_address, + owner, signer_public_keys, )) } diff --git a/tests/src/e2e/ledger_tests.rs b/tests/src/e2e/ledger_tests.rs index 63fe36c3ee..fe8e25294a 100644 --- a/tests/src/e2e/ledger_tests.rs +++ b/tests/src/e2e/ledger_tests.rs @@ -565,8 +565,8 @@ fn ledger_txs_and_queries() -> Result<()> { "--node", &validator_one_rpc, ], - // 6. Submit a tx to withdraw from faucet account (requires PoW challenge - // solution) + // 6. Submit a tx to withdraw from faucet account (requires PoW challenge + // solution) vec![ "transfer", "--source",