1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, IdentityError>;
7
8#[derive(Debug, Error)]
10pub enum IdentityError {
11 #[error("invalid DID format: {0}")]
13 InvalidDid(String),
14
15 #[error("identity not found: {0}")]
17 NotFound(String),
18
19 #[error("identity already exists: {0}")]
21 AlreadyExists(String),
22
23 #[error("identity is not active: {0}")]
25 NotActive(String),
26
27 #[error("permission denied: {0}")]
29 PermissionDenied(String),
30
31 #[error("delegation scope violation: {0}")]
33 DelegationViolation(String),
34
35 #[error("credential error: {0}")]
37 CredentialError(String),
38
39 #[error("verification failed: {0}")]
41 VerificationFailed(String),
42
43 #[error("trust chain broken at issuer {issuer}: {reason}")]
47 TrustChainBroken {
48 issuer: String,
50 reason: String,
52 },
53
54 #[error("trust chain cycle detected at issuer {issuer}")]
57 TrustChainCycle {
58 issuer: String,
60 },
61
62 #[error("trust chain exceeded max depth of {max_depth}")]
66 TrustChainTooDeep {
67 max_depth: usize,
69 },
70
71 #[error("trust chain did not reach a recognized trust root")]
75 NoTrustRoot,
76
77 #[error("invalid service endpoint: {0}")]
79 InvalidServiceEndpoint(String),
80
81 #[error("duplicate credential: {0}")]
83 DuplicateCredential(String),
84
85 #[error("username already taken: {0}")]
87 UsernameTaken(String),
88
89 #[error("invalid username: {0}")]
91 UsernameInvalid(String),
92
93 #[error("wallet error: {0}")]
95 WalletError(String),
96
97 #[error("invalid public key: {0}")]
100 InvalidPublicKey(String),
101
102 #[error("crypto error: {0}")]
104 CryptoError(String),
105
106 #[error("serialization error: {0}")]
108 SerializationError(String),
109}
110
111impl From<tenzro_crypto::CryptoError> for IdentityError {
112 fn from(e: tenzro_crypto::CryptoError) -> Self {
113 IdentityError::CryptoError(e.to_string())
114 }
115}
116
117impl From<tenzro_wallet::WalletError> for IdentityError {
118 fn from(e: tenzro_wallet::WalletError) -> Self {
119 IdentityError::WalletError(e.to_string())
120 }
121}
122
123impl From<serde_json::Error> for IdentityError {
124 fn from(e: serde_json::Error) -> Self {
125 IdentityError::SerializationError(e.to_string())
126 }
127}