1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, SdkError>;
4
5#[derive(Debug, Error)]
6pub enum SdkError {
7 #[error("invalid agent id: {0}")]
8 InvalidAgentId(String),
9
10 #[error("agent id must start with did:agent:")]
11 InvalidAgentIdPrefix,
12
13 #[error("invalid public key length: expected 32 bytes, got {0}")]
14 InvalidPublicKeyLength(usize),
15
16 #[error("canonical JSON error: {0}")]
17 CanonicalJson(String),
18
19 #[error("JSON error: {0}")]
20 Json(#[from] serde_json::Error),
21
22 #[error("base64url decode error: {0}")]
23 Base64(#[from] base64::DecodeError),
24
25 #[error("Ed25519 error: {0}")]
26 Ed25519(#[from] ed25519_dalek::SignatureError),
27
28 #[error("random generation error: {0}")]
29 Random(String),
30
31 #[error("invalid signature length: expected 64 bytes, got {0}")]
32 InvalidSignatureLength(usize),
33
34 #[error("invalid event hash: expected {expected}, got {actual}")]
35 InvalidEventHash { expected: String, actual: String },
36
37 #[error("invalid event hash length: expected 32 bytes, got {0}")]
38 InvalidEventHashLength(usize),
39
40 #[error("invalid event protocol: expected {expected}, got {actual}")]
41 InvalidEventProtocol { expected: String, actual: String },
42
43 #[error("invalid event type: expected {expected}, got {actual}")]
44 InvalidEventType { expected: String, actual: String },
45
46 #[error("invalid actor: {0}")]
47 InvalidActor(String),
48
49 #[error("timestamp is outside the allowed live-write window")]
50 TimestampOutOfWindow,
51
52 #[error("invalid nonce: {0}")]
53 InvalidNonce(String),
54
55 #[error("nonce must be greater than accepted max nonce {max_nonce}")]
56 NonceNotGreater { max_nonce: u64 },
57
58 #[error("event requires a room_id")]
59 MissingRoomId,
60
61 #[error("room id mismatch: expected {expected}, got {actual}")]
62 RoomIdMismatch { expected: String, actual: String },
63
64 #[error("permission denied")]
65 PermissionDenied,
66
67 #[error("invalid payload: {0}")]
68 InvalidPayload(String),
69
70 #[error("event type is not defined in the room: {0}")]
71 TypeNotDefined(String),
72
73 #[error("event type is disabled in the room: {0}")]
74 TypeDisabled(String),
75
76 #[error("payload does not satisfy the type schema: {0}")]
77 PayloadSchemaViolation(String),
78
79 #[error("type pack cannot be resolved or fails verification: {0}")]
80 PackUnavailable(String),
81
82 #[error("invalid JWT: {0}")]
83 InvalidJwt(String),
84
85 #[error("invalid JWT claim: {0}")]
86 InvalidJwtClaim(&'static str),
87
88 #[cfg(feature = "http-client")]
89 #[error("HTTP client error: {0}")]
90 Http(#[from] reqwest::Error),
91}