Skip to content

Commit

Permalink
refactor: allow any display error on verify signer
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <[email protected]>
  • Loading branch information
gusinacio committed Mar 8, 2024
1 parent 3d14126 commit e1b7824
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions tap_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub enum Error {

#[error("Receipt error: {0}")]
ReceiptError(#[from] ReceiptError),

#[error("Failed to check the signer: {0}")]
FailedToVerifySigner(String),
}

pub type Result<T> = StdResult<T, Error>;
5 changes: 3 additions & 2 deletions tap_core/src/tap_manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ where
///
/// Returns [`Error::AdapterError`] if there are any errors while storing RAV
///
pub async fn verify_and_store_rav<F, Fut>(
pub async fn verify_and_store_rav<F, Fut, Err>(
&self,
expected_rav: ReceiptAggregateVoucher,
signed_rav: SignedRAV,
verify_signer: F,
) -> std::result::Result<(), Error>
where
F: FnOnce(Address) -> Fut,
Fut: Future<Output = Result<bool, Error>>,
Fut: Future<Output = Result<bool, Err>>,
Err: std::fmt::Display,
{
self.receipt_auditor
.check_rav_signature(&signed_rav, verify_signer)
Expand Down
10 changes: 5 additions & 5 deletions tap_core/src/tap_manager/test/manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async fn manager_create_rav_request_all_valid_receipts(
.verify_and_store_rav(
rav_request.expected_rav,
signed_rav,
|address: Address| async move { Ok(keys.1 == address) }
|address: Address| async move { Ok::<bool, String>(keys.1 == address) }
)
.await
.is_ok());
Expand Down Expand Up @@ -263,7 +263,7 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts(
.verify_and_store_rav(
rav_request.expected_rav,
signed_rav,
|address: Address| async move { Ok(keys.1 == address) }
|address: Address| async move { Ok::<bool, String>(keys.1 == address) }
)
.await
.is_ok());
Expand Down Expand Up @@ -313,7 +313,7 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts(
.verify_and_store_rav(
rav_request.expected_rav,
signed_rav,
|address: Address| async move { Ok(keys.1 == address) }
|address: Address| async move { Ok::<bool, String>(keys.1 == address) }
)
.await
.is_ok());
Expand Down Expand Up @@ -394,7 +394,7 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts_consecutive_tim
.verify_and_store_rav(
rav_request_1.expected_rav,
signed_rav_1,
|address: Address| async move { Ok(keys.1 == address) }
|address: Address| async move { Ok::<bool, String>(keys.1 == address) }
)
.await
.is_ok());
Expand Down Expand Up @@ -459,7 +459,7 @@ async fn manager_create_multiple_rav_requests_all_valid_receipts_consecutive_tim
.verify_and_store_rav(
rav_request_2.expected_rav,
signed_rav_2,
|address: Address| async move { Ok(keys.1 == address) }
|address: Address| async move { Ok::<bool, String>(keys.1 == address) }
)
.await
.is_ok());
Expand Down
11 changes: 8 additions & 3 deletions tap_core/src/tap_receipt/receipt_auditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ impl<E> ReceiptAuditor<E> {
}
}

pub async fn check_rav_signature<F, Fut>(
pub async fn check_rav_signature<F, Fut, Err>(
&self,
signed_rav: &SignedRAV,
verify_signer: F,
) -> Result<(), Error>
where
F: FnOnce(Address) -> Fut,
Fut: Future<Output = Result<bool, Error>>,
Fut: Future<Output = Result<bool, Err>>,
Err: std::fmt::Display,
{
let recovered_address = signed_rav.recover_signer(&self.domain_separator)?;
if verify_signer(recovered_address).await? {
if verify_signer(recovered_address)
.await
.map_err(|e| Error::FailedToVerifySigner(e.to_string()))?
{
Ok(())
} else {
Err(Error::InvalidRecoveredSigner {
Expand All @@ -61,6 +65,7 @@ where
.map_err(|err| ReceiptError::InvalidSignature {
source_error_message: err.to_string(),
})?;

if self
.executor
.subtract_escrow(receipt_signer_address, signed_receipt.message.value)
Expand Down
2 changes: 1 addition & 1 deletion tap_integration_tests/tests/indexer_mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ where
.verify_and_store_rav(
rav_request.expected_rav,
remote_rav_result.data,
|address| async move { Ok(address == expected_sender_id) },
|address| async move { Ok::<bool, String>(address == expected_sender_id) },
)
.await?;

Expand Down

0 comments on commit e1b7824

Please sign in to comment.