use crate::{
codec::v1::{Attestation, PendingAttestation, RawAttestation},
error::DecodeError,
};
#[cfg(feature = "eas-verifier")]
mod eas;
#[cfg(feature = "eas-verifier")]
pub use eas::EASVerifier;
#[derive(Debug, thiserror::Error)]
pub enum VerifyError {
#[error("raw attestation lacks a value")]
NoValue,
#[error("attestation is still pending and cannot be verified yet")]
Pending,
#[error("attestation is not the expected type")]
BadAttestationTag,
#[error("error decoding attestation: {0}")]
Decode(DecodeError),
#[cfg(feature = "eas-verifier")]
#[error("error verifying eas attestation: {0}")]
EAS(#[from] eas::EASVerifierError),
}
pub trait AttestationVerifier<P>
where
P: for<'a> Attestation<'a> + Send,
Self: Send + Sync,
{
type Output;
fn verify_raw(
&self,
raw: &RawAttestation,
) -> impl Future<Output = Result<Self::Output, VerifyError>> + Send {
async {
if raw.tag == PendingAttestation::TAG {
return Err(VerifyError::Pending);
}
let Some(value) = raw.value.get() else {
return Err(VerifyError::NoValue);
};
match P::from_raw(raw) {
Ok(attestation) => self.verify(&attestation, value).await,
Err(DecodeError::BadAttestationTag) => Err(VerifyError::BadAttestationTag),
Err(e) => Err(VerifyError::Decode(e)),
}
}
}
fn verify(
&self,
attestation: &P,
value: &[u8],
) -> impl Future<Output = Result<Self::Output, VerifyError>> + Send;
}