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("agent id must use base58btc multibase encoding")]
14 UnsupportedAgentIdEncoding,
15
16 #[error("invalid public key length: expected 32 bytes, got {0}")]
17 InvalidPublicKeyLength(usize),
18
19 #[error("multibase decode error: {0}")]
20 Multibase(String),
21
22 #[error("canonical JSON error: {0}")]
23 CanonicalJson(String),
24
25 #[error("JSON error: {0}")]
26 Json(#[from] serde_json::Error),
27
28 #[error("base64url decode error: {0}")]
29 Base64(#[from] base64::DecodeError),
30
31 #[error("Ed25519 error: {0}")]
32 Ed25519(#[from] ed25519_dalek::SignatureError),
33
34 #[error("random generation error: {0}")]
35 Random(String),
36
37 #[error("invalid signature length: expected 64 bytes, got {0}")]
38 InvalidSignatureLength(usize),
39
40 #[error("invalid event id: expected {expected}, got {actual}")]
41 InvalidEventId { expected: String, actual: String },
42
43 #[error("invalid event protocol: expected {expected}, got {actual}")]
44 InvalidEventProtocol { expected: String, actual: String },
45
46 #[error("invalid event type: expected {expected}, got {actual}")]
47 InvalidEventType { expected: String, actual: String },
48
49 #[error("invalid actor: {0}")]
50 InvalidActor(String),
51
52 #[error("timestamp is outside the allowed live-write window")]
53 TimestampOutOfWindow,
54
55 #[error("nonce was already used in this replay scope")]
56 NonceReused,
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 JWT: {0}")]
68 InvalidJwt(String),
69
70 #[error("invalid JWT claim: {0}")]
71 InvalidJwtClaim(&'static str),
72
73 #[cfg(feature = "http-client")]
74 #[error("HTTP client error: {0}")]
75 Http(#[from] reqwest::Error),
76}