Skip to content

Commit 98315b4

Browse files
committed
Simplifies the interface of signing data functions
1 parent 00ba647 commit 98315b4

File tree

5 files changed

+209
-399
lines changed

5 files changed

+209
-399
lines changed

crates/sdk/src/eth_bridge/bridge_pool.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ pub async fn build_bridge_pool_tx(
8484
query_wasm_code_hash(context, code_path.to_string_lossy()),
8585
aux_signing_data(
8686
context,
87-
&tx_args,
87+
wrap_tx,
8888
// tx signer
8989
Some(sender_),
9090
vec![],
9191
false,
9292
vec![],
93-
None
9493
),
9594
)?;
9695
let fee_payer = signing_data.fee_payer_or_err()?.to_owned();
@@ -130,12 +129,10 @@ pub async fn build_bridge_pool_tx(
130129
query_wasm_code_hash(context, code_path.to_string_lossy()),
131130
aux_inner_signing_data(
132131
context,
133-
&tx_args,
132+
tx_args.signing_keys,
134133
// tx signer
135134
Some(sender_),
136135
vec![],
137-
vec![],
138-
false
139136
)
140137
)?;
141138

crates/sdk/src/signing.rs

Lines changed: 29 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -232,42 +232,16 @@ pub fn find_key_by_pk<U: WalletIo>(
232232
/// is given, an `Error` is returned.
233233
async fn inner_tx_signers(
234234
context: &impl Namada,
235-
signing_keys: &[common::PublicKey],
236-
default_signer: Option<Address>,
237-
signatures: &[Vec<u8>],
238-
// FIXME: can't join this with owner?
239-
// Flag to signal that a missing signer is acceptable. This is useful for
240-
// some transactions in which an an actual signer might not be needed (e.g.
241-
// MASP source or custom txs)
242-
no_sig_ok: bool,
235+
mut signing_keys: Vec<common::PublicKey>,
236+
default_signer: Option<&Address>,
243237
) -> Result<HashSet<common::PublicKey>, Error> {
244-
if !signing_keys.is_empty() {
245-
Ok(signing_keys.iter().cloned().collect())
246-
} else {
247-
match default_signer {
248-
// Use the signer determined by the caller, fetch the signing
249-
// key and apply it
250-
// FIXME: here only call find_pk if the address is implicit
251-
Some(signer) => Ok([find_pk(context, &signer).await?].into()),
252-
None => {
253-
if !signatures.is_empty() {
254-
// If explicit signatures are provided provide no more
255-
// signers
256-
Ok(Default::default())
257-
} else if no_sig_ok {
258-
// If no signature is acceptable provide no signer
259-
Ok(Default::default())
260-
} else {
261-
other_err(
262-
"All transactions must be signed; please either \
263-
specify the key or the address from which to look up \
264-
the signing key."
265-
.to_string(),
266-
)
267-
}
268-
}
269-
}
238+
if let Some(signer) = default_signer {
239+
// Use the signer determined by the caller, fetch the signing key and
240+
// apply it
241+
signing_keys.push(find_pk(context, signer).await?)
270242
}
243+
244+
Ok(signing_keys.into_iter().collect())
271245
}
272246

273247
/// The different parts of a transaction that can be signed. Note that it's
@@ -458,68 +432,18 @@ where
458432
Ok(())
459433
}
460434

461-
/// The auxiliary signing data specifying that the target transaction does not
462-
/// necessarily needs a signer (like MASP sources txs or custom txs)
463-
pub enum NoSigOkData {
464-
/// A wrapper transaction for which a wrapper signature is provided
465-
WrapperSig(Vec<u8>),
466-
/// All the other transactions that don't need a signer
467-
Other,
468-
}
469-
470435
/// Return the necessary data regarding an account to be able to generate
471436
/// signature sections for both the inner and the wrapper transaction
472-
// FIXME: can remove too_many_arguments?
473-
#[allow(clippy::too_many_arguments)]
474437
pub async fn aux_signing_data(
475438
context: &impl Namada,
476-
args: &args::Tx<SdkTypes>,
439+
wrap_tx: &args::Wrapper,
477440
owner: Option<Address>,
478-
// FIXME: we could avoid passing args and providing instead the wrap_tx
479-
// (mandatory) and the set of public keys (we joing them before the call).
480-
// It wouldn't be the same, we attach the extra signing keys to the resul
481-
// of inner_tx_signers which could be based on the owner
482-
extra_public_keys: Vec<common::PublicKey>,
483-
// FIXME: this is only needed if we need to wrap the tx (wrap_tx is some)
484-
// which is always the case when we call this function. Actually not, for
485-
// custom txs the tx might already be wrapped but we still call this to
486-
// extract the wrapper signer
487-
is_shielded_source: bool,
441+
signing_keys: Vec<common::PublicKey>,
442+
disposable_gas_payer: bool,
488443
signatures: Vec<Vec<u8>>,
489-
// FIXME: can't join this with owner?
490-
// FIXME: better, if the wrapper signature is provided only the optional
491-
// signatures should be given, everything else is useless
492-
no_sig_data: Option<NoSigOkData>,
493444
) -> Result<SigningWrapperData, Error> {
494-
let no_sig_ok = match no_sig_data {
495-
Some(NoSigOkData::WrapperSig(wrapper_sig)) =>
496-
// Can't produce any more inner signatures when the wrapper signature is
497-
// provided. Just attach the available serialized signatures
498-
{
499-
return Ok(SigningWrapperData {
500-
signing_data: vec![SigningTxData {
501-
owner: None,
502-
public_keys: Default::default(),
503-
threshold: 0,
504-
account_public_keys_map: Default::default(),
505-
shielded_hash: None,
506-
signatures,
507-
}],
508-
fee_auth: FeeAuthorization::Signature(wrapper_sig),
509-
});
510-
}
511-
Some(NoSigOkData::Other) => true,
512-
None => false,
513-
};
514-
let mut public_keys = inner_tx_signers(
515-
context,
516-
args.signing_keys.as_slice(),
517-
owner.clone(),
518-
&signatures,
519-
no_sig_ok,
520-
)
521-
.await?;
522-
public_keys.extend(extra_public_keys.clone());
445+
let public_keys =
446+
inner_tx_signers(context, signing_keys, owner.as_ref()).await?;
523447

524448
let (account_public_keys_map, threshold) = match &owner {
525449
Some(owner @ Address::Established(_)) => {
@@ -547,27 +471,30 @@ pub async fn aux_signing_data(
547471
0u8,
548472
),
549473
};
550-
let fee_auth = match args.wrap_tx.as_ref().ok_or_else(|| {
551-
Error::Other("Missing expected wrapper arguments".to_string())
552-
})? {
474+
let fee_auth = match wrap_tx {
553475
args::Wrapper {
554476
wrapper_fee_payer: Some(pubkey),
555477
..
556478
} => FeeAuthorization::Signer {
557-
pubkey: pubkey.clone(),
479+
pubkey: pubkey.to_owned(),
558480
disposable_fee_payer: false,
559481
},
560482
_ => {
561-
if is_shielded_source {
562-
FeeAuthorization::Signer {
563-
pubkey: gen_disposable_signing_key(context).await,
564-
disposable_fee_payer: true,
565-
}
566-
} else if let Some(pubkey) = public_keys.first() {
483+
// FIXME: in theory though we want to leave freedom to the user,
484+
// just guide them, look at where we print the other warning message
485+
// and add this one as well, then mention this thing in the PR
486+
if let Some(pubkey) = public_keys.first() {
567487
FeeAuthorization::Signer {
568488
pubkey: pubkey.to_owned(),
569489
disposable_fee_payer: false,
570490
}
491+
// NOTE: the disposable gas_payer is always overridden by
492+
// signing inputs
493+
} else if disposable_gas_payer {
494+
FeeAuthorization::Signer {
495+
pubkey: gen_disposable_signing_key(context).await,
496+
disposable_fee_payer: true,
497+
}
571498
} else {
572499
return Err(Error::Tx(TxSubmitError::InvalidFeePayer));
573500
}
@@ -593,23 +520,12 @@ pub async fn aux_signing_data(
593520
/// signature section for the inner transaction only
594521
pub async fn aux_inner_signing_data(
595522
context: &impl Namada,
596-
// FIXME: technically we only need the signing keys
597-
args: &args::Tx<SdkTypes>,
523+
signing_keys: Vec<common::PublicKey>,
598524
owner: Option<Address>,
599-
extra_public_keys: Vec<common::PublicKey>,
600525
signatures: Vec<Vec<u8>>,
601-
// FIXME: can join this with owner?
602-
no_sig_ok: bool,
603526
) -> Result<SigningTxData, Error> {
604-
let mut public_keys = inner_tx_signers(
605-
context,
606-
args.signing_keys.as_slice(),
607-
owner.clone(),
608-
&signatures,
609-
no_sig_ok,
610-
)
611-
.await?;
612-
public_keys.extend(extra_public_keys.clone());
527+
let public_keys =
528+
inner_tx_signers(context, signing_keys, owner.as_ref()).await?;
613529

614530
let (account_public_keys_map, threshold) = match &owner {
615531
Some(owner @ Address::Established(_)) => {
@@ -2630,20 +2546,6 @@ mod test_signing {
26302546
.expect_err("Test failed");
26312547
}
26322548

2633-
#[tokio::test]
2634-
async fn test_tx_signers_failure() {
2635-
let args = arbitrary_args();
2636-
inner_tx_signers(
2637-
&TestNamadaImpl::new(None).0,
2638-
args.signing_keys.as_slice(),
2639-
None,
2640-
&[],
2641-
false,
2642-
)
2643-
.await
2644-
.expect_err("Test failed");
2645-
}
2646-
26472549
/// Test the unhappy flows in trying to validate
26482550
/// the fee token and amounts, both with and without
26492551
/// the force argument set.

0 commit comments

Comments
 (0)