use thiserror::Error;
#[derive(Debug, Error)]
pub enum VerifyError {
#[error("invalid JWS compact form: expected 3 segments, got {0}")]
InvalidJwsShape(usize),
#[error("base64url decoding failed for {segment} segment: {source}")]
Base64Decode {
segment: &'static str,
source: base64::DecodeError,
},
#[error("invalid or unsupported JWS header (alg must be ES256, typ must be JWT)")]
InvalidJwsHeader,
#[error("JWT payload JSON malformed: {0}")]
PayloadJson(#[from] serde_json::Error),
#[error("audience mismatch: expected `{expected}`, got `{actual}`")]
AudienceMismatch {
expected: String,
actual: String,
},
#[error("nonce mismatch — possible replay or stale request")]
NonceMismatch,
#[error("token expired: exp={exp}, now={now}")]
Expired {
exp: u64,
now: u64,
},
#[error("token issued too far in the future: iat={iat}, now={now}, max skew {max_skew_secs}s")]
NotYetValid {
iat: u64,
now: u64,
max_skew_secs: u64,
},
#[error("DID `{did}` does not encode a valid P-256 public key")]
MalformedDid {
did: String,
},
#[error("verification method `{vm_id}` has an invalid public_key_multibase")]
MalformedVmPubkey {
vm_id: String,
},
#[error("signature has wrong length: expected 64 bytes, got {actual}")]
SignatureWrongLength {
actual: usize,
},
#[error("signature bytes are not a valid P-256 r||s (zero or out-of-range scalar)")]
SignatureInvalidScalars,
#[error("genesis roster self-signature is invalid (does not verify against key encoded in DID)")]
GenesisSignatureInvalid,
#[error(
"chain entry version {entry_version} signed by `{signer_kid}`, which is not in the prior roster"
)]
ChainSignerNotInPriorRoster {
entry_version: u64,
signer_kid: String,
},
#[error("chain entry version {entry_version} has an invalid signature")]
ChainSignatureInvalid {
entry_version: u64,
},
#[error(
"chain version not strictly monotonic: entry version {entry_version} <= prior version {prior_version}"
)]
ChainVersionNotMonotonic {
entry_version: u64,
prior_version: u64,
},
#[error(
"current verification method `{vm_id}` is not in the head roster — device has been revoked"
)]
CurrentVmNotInHeadRoster {
vm_id: String,
},
#[error("JWS outer signature did not verify against the embedded verification method")]
JwtSignatureInvalid,
#[error("rollback detected: current version {current} < last seen {last_seen}")]
RollbackDetected {
current: u64,
last_seen: u64,
},
#[error("roster fork detected: this token's history differs from the one seen at version {version}")]
ForkDetected {
version: u64,
},
#[error("roster chain entry v{entry_version} names {entry_did}, not the issuer")]
ChainEntryDidMismatch {
entry_version: u64,
entry_did: String,
},
}