Skip to content

Commit 13a8f2d

Browse files
committed
feat(middleware): add V2 domain separator to sender middleware
Update sender middleware to use version-appropriate domain separators for signer recovery. V1 receipts use legacy domain, V2 receipts use Horizon domain for correct escrow account lookups.
1 parent bb4e680 commit 13a8f2d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crates/service/src/middleware/sender.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use crate::{error::IndexerServiceError, tap::TapReceipt};
1717
pub struct SenderState {
1818
/// Used to recover the signer address
1919
pub domain_separator: Eip712Domain,
20+
/// Used to recoer the signer addres for V2 receipts(Horizon)
21+
pub domain_separator_v2: Eip712Domain,
2022
/// Used to get the sender address given the signer address if v1 receipt
2123
pub escrow_accounts_v1: Option<watch::Receiver<EscrowAccounts>>,
2224
/// Used to get the sender address given the signer address if v2 receipt
@@ -46,9 +48,9 @@ pub async fn sender_middleware(
4648
next: Next,
4749
) -> Result<Response, IndexerServiceError> {
4850
if let Some(receipt) = request.extensions().get::<TapReceipt>() {
49-
let signer = receipt.recover_signer(&state.domain_separator)?;
5051
let sender = match receipt {
5152
TapReceipt::V1(_) => {
53+
let signer = receipt.recover_signer(&state.domain_separator)?;
5254
if let Some(ref escrow_accounts_v1) = state.escrow_accounts_v1 {
5355
escrow_accounts_v1.borrow().get_sender_for_signer(&signer)?
5456
} else {
@@ -58,6 +60,7 @@ pub async fn sender_middleware(
5860
}
5961
}
6062
TapReceipt::V2(_) => {
63+
let signer = receipt.recover_signer(&state.domain_separator_v2)?;
6164
if let Some(ref escrow_accounts_v2) = state.escrow_accounts_v2 {
6265
escrow_accounts_v2.borrow().get_sender_for_signer(&signer)?
6366
} else {
@@ -110,6 +113,7 @@ mod tests {
110113

111114
let state = SenderState {
112115
domain_separator: test_assets::TAP_EIP712_DOMAIN.clone(),
116+
domain_separator_v2: test_assets::TAP_EIP712_DOMAIN_V2.clone(),
113117
escrow_accounts_v1: Some(escrow_accounts_v1),
114118
escrow_accounts_v2: Some(escrow_accounts_v2),
115119
};

0 commit comments

Comments
 (0)