1use alloy_primitives::Address;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
7pub enum Eip8141Error {
8 #[error("invalid frame mode: {0}")]
10 InvalidMode(u8),
11 #[error("invalid approval scope: {0}")]
13 InvalidScope(u8),
14 #[error("invalid frame status: {0}")]
16 InvalidStatus(u8),
17 #[error("invalid signature scheme: {0}")]
19 InvalidScheme(u8),
20 #[error("invalid address length: {0}")]
22 InvalidAddressLength(usize),
23 #[error("invalid signature message length: {0}")]
25 InvalidMessageLength(usize),
26 #[error("explicit signature message must be nonzero")]
28 ZeroMessage,
29 #[error("arbitrary signature must have an empty signer")]
31 UnexpectedSigner,
32 #[error("invalid signature length: expected {expected}, got {actual}")]
34 InvalidSignatureLength {
35 expected: usize,
37 actual: usize,
39 },
40 #[error("invalid signature parity: {0}")]
42 InvalidParity(u8),
43 #[error("signature scalars must be canonical and low-s")]
45 InvalidSignatureScalar,
46 #[error("p256 public key resolves to {derived}, expected signer {expected}")]
48 P256SignerMismatch {
49 expected: Address,
51 derived: Address,
53 },
54}
55
56impl Eip8141Error {
57 pub const fn is_invalid_mode(self) -> bool {
59 matches!(self, Self::InvalidMode(_))
60 }
61
62 pub const fn is_invalid_scope(self) -> bool {
64 matches!(self, Self::InvalidScope(_))
65 }
66
67 pub const fn is_invalid_status(self) -> bool {
69 matches!(self, Self::InvalidStatus(_))
70 }
71
72 pub const fn is_invalid_scheme(self) -> bool {
74 matches!(self, Self::InvalidScheme(_))
75 }
76
77 pub const fn is_invalid_address_length(self) -> bool {
79 matches!(self, Self::InvalidAddressLength(_))
80 }
81
82 pub const fn is_invalid_message_length(self) -> bool {
84 matches!(self, Self::InvalidMessageLength(_))
85 }
86
87 pub const fn is_zero_message(self) -> bool {
89 matches!(self, Self::ZeroMessage)
90 }
91
92 pub const fn is_unexpected_signer(self) -> bool {
94 matches!(self, Self::UnexpectedSigner)
95 }
96
97 pub const fn is_invalid_signature_length(self) -> bool {
99 matches!(self, Self::InvalidSignatureLength { .. })
100 }
101
102 pub const fn is_invalid_parity(self) -> bool {
104 matches!(self, Self::InvalidParity(_))
105 }
106
107 pub const fn is_invalid_signature_scalar(self) -> bool {
109 matches!(self, Self::InvalidSignatureScalar)
110 }
111
112 pub const fn is_p256_signer_mismatch(self) -> bool {
114 matches!(self, Self::P256SignerMismatch { .. })
115 }
116}