Skip to content

Commit 2a98fb0

Browse files
committed
refactor!: return bool in Eip712SignedMessage::verify
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 7024558 commit 2a98fb0

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

tap_core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,6 @@ mod tap_tests {
185185
&domain_separator,
186186
Address::from_str("0x76f4eeD9fE41262669D0250b2A97db79712aD855").unwrap()
187187
)
188-
.is_err());
188+
.unwrap());
189189
}
190190
}

tap_eip712_message/src/lib.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,9 @@ pub enum Eip712Error {
3636
#[error(transparent)]
3737
WalletError(#[from] alloy::signers::Error),
3838

39-
/// `alloy` wallet error
39+
/// `alloy` signature error
4040
#[error(transparent)]
4141
SignatureError(#[from] alloy::primitives::SignatureError),
42-
43-
/// Error when signature verification fails
44-
#[error("Expected address {expected} but received {received}")]
45-
VerificationFailed {
46-
expected: Address,
47-
received: Address,
48-
},
4942
}
5043

5144
/// EIP712 signed message
@@ -83,6 +76,11 @@ pub struct MessageId(pub [u8; 32]);
8376

8477
impl<M: SolStruct> EIP712SignedMessage<M> {
8578
/// Creates a signed message with signed EIP712 hash of `message` using `signing_wallet`
79+
///
80+
/// # Errors
81+
///
82+
/// Returns [`crate::Error::WalletError`] if could not sign using the wallet
83+
///
8684
pub fn new(
8785
domain_separator: &Eip712Domain,
8886
message: M,
@@ -104,7 +102,7 @@ impl<M: SolStruct> EIP712SignedMessage<M> {
104102
Ok(recovered_address)
105103
}
106104

107-
/// Checks that receipts signature is valid for given verifying key, returns `Ok` if it is valid.
105+
/// Checks that receipts signature is valid for given verifying key, returns `Ok(true)` if it is valid.
108106
///
109107
/// # Errors
110108
///
@@ -115,16 +113,9 @@ impl<M: SolStruct> EIP712SignedMessage<M> {
115113
&self,
116114
domain_separator: &Eip712Domain,
117115
expected_address: Address,
118-
) -> Result<(), Eip712Error> {
116+
) -> Result<bool, Eip712Error> {
119117
let recovered_address = self.recover_signer(domain_separator)?;
120-
if recovered_address != expected_address {
121-
Err(Eip712Error::VerificationFailed {
122-
expected: expected_address,
123-
received: recovered_address,
124-
})
125-
} else {
126-
Ok(())
127-
}
118+
Ok(recovered_address != expected_address)
128119
}
129120

130121
/// Use this as a simple key for testing

0 commit comments

Comments
 (0)