Skip to content

Commit

Permalink
Merge pull request #3699 from anoma/grarco/disposable-signer-update
Browse files Browse the repository at this point in the history
Update disposable signer
  • Loading branch information
mergify[bot] authored Aug 26, 2024
2 parents 2256e38 + 86f053e commit 24eebc7
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Made the `disposable-gas-payer` cli arg specific to some transactions.
([\#3699](https://github.com/anoma/namada/pull/3699))
85 changes: 67 additions & 18 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4373,6 +4373,7 @@ pub mod args {
std::fs::read(path).expect("Expected a file at given path")
}),
owner: ctx.borrow_chain_or_exit().get(&self.owner),
disposable_signing_key: self.disposable_signing_key,
})
}
}
Expand All @@ -4384,12 +4385,14 @@ pub mod args {
let data_path = DATA_PATH_OPT.parse(matches);
let serialized_tx = TX_PATH_OPT.parse(matches);
let owner = OWNER.parse(matches);
let disposable_signing_key = DISPOSABLE_SIGNING_KEY.parse(matches);
Self {
tx,
code_path,
data_path,
serialized_tx,
owner,
disposable_signing_key,
}
}

Expand Down Expand Up @@ -4425,6 +4428,15 @@ pub mod args {
"The address corresponding to the signatures or signing \
keys."
)))
.arg(
DISPOSABLE_SIGNING_KEY
.def()
.help(wrap!(
"Generates an ephemeral, disposable keypair to \
sign the wrapper transaction."
))
.conflicts_with(FEE_PAYER_OPT.name),
)
}
}

Expand Down Expand Up @@ -4526,6 +4538,7 @@ pub mod args {
tx,
data,
gas_spending_keys,
disposable_signing_key: self.disposable_signing_key,
tx_code_path: self.tx_code_path.to_path_buf(),
})
}
Expand All @@ -4549,11 +4562,13 @@ pub mod args {
if let Some(key) = GAS_SPENDING_KEY.parse(matches) {
gas_spending_keys.push(key);
}
let disposable_gas_payer = DISPOSABLE_SIGNING_KEY.parse(matches);

Self {
tx,
data,
gas_spending_keys,
disposable_signing_key: disposable_gas_payer,
tx_code_path,
}
}
Expand All @@ -4580,6 +4595,15 @@ pub mod args {
"The optional spending key that will be used in addition \
to the source for gas payment."
)))
.arg(
DISPOSABLE_SIGNING_KEY
.def()
.help(wrap!(
"Generates an ephemeral, disposable keypair to \
sign the wrapper transaction."
))
.conflicts_with(FEE_PAYER_OPT.name),
)
}
}

Expand Down Expand Up @@ -4683,6 +4707,7 @@ pub mod args {
tx,
data,
gas_spending_keys,
disposable_signing_key: self.disposable_signing_key,
source: chain_ctx.get_cached(&self.source),
tx_code_path: self.tx_code_path.to_path_buf(),
})
Expand All @@ -4706,12 +4731,14 @@ pub mod args {
if let Some(key) = GAS_SPENDING_KEY.parse(matches) {
gas_spending_keys.push(key);
}
let disposable_signing_key = DISPOSABLE_SIGNING_KEY.parse(matches);

Self {
tx,
source,
data,
gas_spending_keys,
disposable_signing_key,
tx_code_path,
}
}
Expand All @@ -4738,6 +4765,15 @@ pub mod args {
"The optional spending key that will be used in addition \
to the source for gas payment."
)))
.arg(
DISPOSABLE_SIGNING_KEY
.def()
.help(wrap!(
"Generates an ephemeral, disposable keypair to \
sign the wrapper transaction."
))
.conflicts_with(FEE_PAYER_OPT.name),
)
}
}

Expand Down Expand Up @@ -4770,6 +4806,7 @@ pub mod args {
ibc_shielding_data: self.ibc_shielding_data,
ibc_memo: self.ibc_memo,
gas_spending_keys,
disposable_signing_key: self.disposable_signing_key,
tx_code_path: self.tx_code_path.to_path_buf(),
})
}
Expand Down Expand Up @@ -4799,6 +4836,7 @@ pub mod args {
if let Some(key) = GAS_SPENDING_KEY.parse(matches) {
gas_spending_keys.push(key);
}
let disposable_signing_key = DISPOSABLE_SIGNING_KEY.parse(matches);
let tx_code_path = PathBuf::from(TX_IBC_WASM);
Self {
tx,
Expand All @@ -4814,6 +4852,7 @@ pub mod args {
ibc_shielding_data,
ibc_memo,
gas_spending_keys,
disposable_signing_key,
tx_code_path,
}
}
Expand Down Expand Up @@ -4862,6 +4901,15 @@ pub mod args {
to the source for gas payment (if this is a shielded \
action)."
)))
.arg(
DISPOSABLE_SIGNING_KEY
.def()
.help(wrap!(
"Generates an ephemeral, disposable keypair to \
sign the wrapper transaction."
))
.conflicts_with(FEE_PAYER_OPT.name),
)
}
}

Expand Down Expand Up @@ -6542,6 +6590,7 @@ pub mod args {
tx,
tx_data,
owner: ctx.borrow_chain_or_exit().get(&self.owner),
disposable_signing_key: self.disposable_signing_key,
})
}
}
Expand All @@ -6551,10 +6600,12 @@ pub mod args {
let tx = Tx::parse(matches);
let tx_path = TX_PATH.parse(matches);
let owner = OWNER.parse(matches);
let disposable_signing_key = DISPOSABLE_SIGNING_KEY.parse(matches);
Self {
tx,
tx_data: tx_path,
owner,
disposable_signing_key,
}
}

Expand All @@ -6566,6 +6617,15 @@ pub mod args {
.arg(
OWNER.def().help(wrap!("The address of the account owner")),
)
.arg(
DISPOSABLE_SIGNING_KEY
.def()
.help(wrap!(
"Generates an ephemeral, disposable keypair to \
sign the wrapper transaction."
))
.conflicts_with(FEE_PAYER_OPT.name),
)
}
}

Expand Down Expand Up @@ -7032,7 +7092,6 @@ pub mod args {
})
})
.collect::<Result<Vec<_>, _>>()?,
disposable_signing_key: self.disposable_signing_key,
tx_reveal_code_path: self.tx_reveal_code_path,
password: self.password,
expiration: self.expiration,
Expand Down Expand Up @@ -7123,11 +7182,6 @@ pub mod args {
))
.conflicts_with_all([EXPIRATION_OPT.name]),
)
.arg(DISPOSABLE_SIGNING_KEY.def().help(wrap!(
"Generates an ephemeral, disposable keypair to sign the \
wrapper transaction. This keypair will be immediately \
discarded after use."
)))
.arg(
SIGNING_KEYS
.def()
Expand All @@ -7153,16 +7207,13 @@ pub mod args {
"The output folder path where the artifact will be stored."
)))
.arg(CHAIN_ID_OPT.def().help(wrap!("The chain ID.")))
.arg(
FEE_PAYER_OPT
.def()
.help(wrap!(
"The implicit address of the gas payer. It defaults \
to the address associated to the first key passed to \
--signing-keys."
))
.conflicts_with(DISPOSABLE_SIGNING_KEY.name),
)
.arg(FEE_PAYER_OPT.def().help(wrap!(
"The implicit address of the gas payer. It defaults to the \
address associated to the first key passed to \
--signing-keys. If the specific transaction supports \
--disposable-signing-key, then this one will overwrite this \
argument."
)))
.arg(
USE_DEVICE
.def()
Expand Down Expand Up @@ -7203,7 +7254,6 @@ pub mod args {
let gas_limit = GAS_LIMIT.parse(matches);
let wallet_alias_force = WALLET_ALIAS_FORCE.parse(matches);
let expiration = EXPIRATION_OPT.parse(matches);
let disposable_signing_key = DISPOSABLE_SIGNING_KEY.parse(matches);
let signing_keys = SIGNING_KEYS.parse(matches);
let signatures = SIGNATURES.parse(matches);
let tx_reveal_code_path = PathBuf::from(TX_REVEAL_PK);
Expand Down Expand Up @@ -7236,7 +7286,6 @@ pub mod args {
fee_token,
gas_limit,
expiration,
disposable_signing_key,
signing_keys,
signatures,
tx_reveal_code_path,
Expand Down
27 changes: 20 additions & 7 deletions crates/apps_lib/src/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ pub async fn aux_signing_data(
args: &args::Tx,
owner: Option<Address>,
default_signer: Option<Address>,
disposable_signing_key: bool,
) -> Result<signing::SigningTxData, error::Error> {
let signing_data =
signing::aux_signing_data(context, args, owner, default_signer, vec![])
.await?;
let signing_data = signing::aux_signing_data(
context,
args,
owner,
default_signer,
vec![],
disposable_signing_key,
)
.await?;

if args.disposable_signing_key {
if disposable_signing_key {
if !(args.dry_run || args.dry_run_wrapper) {
// Store the generated signing key to wallet in case of need
context.wallet().await.save().map_err(|_| {
Expand Down Expand Up @@ -1013,6 +1020,7 @@ pub async fn sign_tx<N: Namada>(
tx: tx_args,
tx_data,
owner,
disposable_signing_key,
}: args::SignTx,
) -> Result<(), error::Error>
where
Expand All @@ -1025,9 +1033,14 @@ where
safe_exit(1)
};
let default_signer = Some(owner.clone());
let signing_data =
aux_signing_data(namada, &tx_args, Some(owner.clone()), default_signer)
.await?;
let signing_data = aux_signing_data(
namada,
&tx_args,
Some(owner.clone()),
default_signer,
disposable_signing_key,
)
.await?;

let mut wallet = namada.wallet_mut().await;

Expand Down
1 change: 0 additions & 1 deletion crates/apps_lib/src/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn get_tx_args(use_device: bool) -> TxArgs {
fee_token: genesis_fee_token_address(),
gas_limit: 0.into(),
expiration: Default::default(),
disposable_signing_key: false,
chain_id: None,
signing_keys: vec![],
signatures: vec![],
Expand Down
Loading

0 comments on commit 24eebc7

Please sign in to comment.