Skip to content

Commit

Permalink
Merge branch 'murisi/separare-signing-v2' (#1673)
Browse files Browse the repository at this point in the history
* origin/murisi/separare-signing-v2:
  added chagelog
  Added changelog entry.
  clippy, fmt
  Simplified the reveal PK transaction construction flow. Factored chain_id reading from submit functions.
  Allow Tx builders to take verification keys.
  Increased usage of PublicKeys relative to SecretKeys in tx construction.
  Only reveal a public key when the signer is an implicit address.
  Now only use TxBroadcastData::Wrapper for non dry runs.
  Now update proof of work solution in transaction header.
  Separating out the reveal PK transaction construction.
  Separate transaction building from signing from submission.
  Removed unnecessary header updates for dry runs.
  • Loading branch information
Fraccaman committed Jul 6, 2023
2 parents 848d0b0 + 673ef1b commit 5f493a5
Show file tree
Hide file tree
Showing 17 changed files with 822 additions and 659 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/improvements/1498-separate-signing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Separate the transaction building, signing, and submission
actions in the SDKs API to enable hardware wallet usage
([\#1498](https://github.com/anoma/namada/pull/1498))
2 changes: 1 addition & 1 deletion apps/src/bin/namada-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub async fn main() -> Result<()> {
.unwrap();
let args = args.to_sdk(&mut ctx);
tx::submit_init_validator::<HttpClient>(&client, ctx, args)
.await;
.await?;
}
Sub::TxInitProposal(TxInitProposal(args)) => {
wait_until_node_is_synched(&args.tx.ledger_address).await;
Expand Down
26 changes: 24 additions & 2 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,8 @@ pub mod args {
pub const VALIDATOR_CODE_PATH: ArgOpt<PathBuf> =
arg_opt("validator-code-path");
pub const VALUE: ArgOpt<String> = arg_opt("value");
pub const VERIFICATION_KEY: ArgOpt<WalletPublicKey> =
arg_opt("verification-key");
pub const VIEWING_KEY: Arg<WalletViewingKey> = arg("key");
pub const WALLET_ALIAS_FORCE: ArgFlag = flag("wallet-alias-force");
pub const WASM_CHECKSUMS_PATH: Arg<PathBuf> = arg("wasm-checksums-path");
Expand Down Expand Up @@ -3371,11 +3373,16 @@ pub mod args {
fee_token: ctx.get(&self.fee_token),
gas_limit: self.gas_limit,
signing_key: self.signing_key.map(|x| ctx.get_cached(&x)),
verification_key: self
.verification_key
.map(|x| ctx.get_cached(&x)),
signer: self.signer.map(|x| ctx.get(&x)),
tx_reveal_code_path: self.tx_reveal_code_path,
password: self.password,
expiration: self.expiration,
chain_id: self.chain_id,
chain_id: self
.chain_id
.or_else(|| Some(ctx.config.ledger.chain_id.clone())),
}
}
}
Expand Down Expand Up @@ -3434,7 +3441,8 @@ pub mod args {
public key, public key hash or alias from your \
wallet.",
)
.conflicts_with(SIGNER.name),
.conflicts_with(SIGNER.name)
.conflicts_with(VERIFICATION_KEY.name),
)
.arg(
SIGNER
Expand All @@ -3443,6 +3451,18 @@ pub mod args {
"Sign the transaction with the keypair of the public \
key of the given address.",
)
.conflicts_with(SIGNING_KEY_OPT.name)
.conflicts_with(VERIFICATION_KEY.name),
)
.arg(
VERIFICATION_KEY
.def()
.help(
"Sign the transaction with the key for the given \
public key, public key hash or alias from your \
wallet.",
)
.conflicts_with(SIGNER.name)
.conflicts_with(SIGNING_KEY_OPT.name),
)
.arg(CHAIN_ID_OPT.def().help("The chain ID."))
Expand All @@ -3462,6 +3482,7 @@ pub mod args {
let gas_limit = GAS_LIMIT.parse(matches).amount.into();
let expiration = EXPIRATION_OPT.parse(matches);
let signing_key = SIGNING_KEY_OPT.parse(matches);
let verification_key = VERIFICATION_KEY.parse(matches);
let signer = SIGNER.parse(matches);
let tx_reveal_code_path = PathBuf::from(TX_REVEAL_PK);
let chain_id = CHAIN_ID_OPT.parse(matches);
Expand All @@ -3479,6 +3500,7 @@ pub mod args {
gas_limit,
expiration,
signing_key,
verification_key,
signer,
tx_reveal_code_path,
password,
Expand Down
28 changes: 8 additions & 20 deletions apps/src/lib/client/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ 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_keypair<
pub async fn find_pk<
C: namada::ledger::queries::Client + Sync,
U: WalletUtils,
>(
client: &C,
wallet: &mut Wallet<U>,
addr: &Address,
) -> Result<common::SecretKey, tx::Error> {
namada::ledger::signing::find_keypair::<C, U>(client, wallet, addr, None)
.await
) -> Result<common::PublicKey, tx::Error> {
namada::ledger::signing::find_pk(client, wallet, addr, None).await
}

/// Given CLI arguments and some defaults, determine the rightful transaction
Expand All @@ -38,7 +37,7 @@ pub async fn tx_signer<
wallet: &mut Wallet<U>,
args: &args::Tx,
default: TxSigningKey,
) -> Result<common::SecretKey, tx::Error> {
) -> Result<(Option<Address>, common::PublicKey), tx::Error> {
namada::ledger::signing::tx_signer::<C, U>(client, wallet, args, default)
.await
}
Expand All @@ -55,23 +54,12 @@ pub async fn sign_tx<
C: namada::ledger::queries::Client + Sync,
U: WalletUtils,
>(
client: &C,
wallet: &mut Wallet<U>,
tx: Tx,
tx: &mut Tx,
args: &args::Tx,
default: TxSigningKey,
#[cfg(not(feature = "mainnet"))] requires_pow: bool,
) -> Result<TxBroadcastData, tx::Error> {
namada::ledger::signing::sign_tx::<C, U>(
client,
wallet,
tx,
args,
default,
#[cfg(not(feature = "mainnet"))]
requires_pow,
)
.await
default: &common::PublicKey,
) -> Result<(), tx::Error> {
namada::ledger::signing::sign_tx(wallet, tx, args, default).await
}

/// Create a wrapper tx from a normal tx. Get the hash of the
Expand Down
Loading

0 comments on commit 5f493a5

Please sign in to comment.