1use thiserror::Error;
2
3#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
5#[cfg_attr(feature = "native-bindings", derive(uniffi::Error))]
6pub enum SoftchatError {
7 #[error("invalid secret key")]
9 InvalidSecretKey,
10
11 #[error("invalid public key")]
13 InvalidPublicKey,
14
15 #[error("invalid Nostr event ID")]
17 InvalidEventId,
18
19 #[error("invalid Nostr event signature")]
21 InvalidEventSignature,
22
23 #[error("invalid Nostr event kind")]
25 InvalidEventKind,
26
27 #[error("invalid Nostr event timestamp")]
29 InvalidEventTimestamp,
30
31 #[error("invalid Nostr event tag")]
33 InvalidEventTag,
34
35 #[error("invalid Nostr event JSON")]
37 InvalidEventJson,
38
39 #[error("Nostr event is too large")]
41 EventTooLarge,
42
43 #[error("Nostr event signing failed")]
45 EventSigningFailed,
46
47 #[error("NIP-59 envelope creation failed")]
49 Nip59EnvelopeCreationFailed,
50
51 #[error("invalid NIP-59 envelope")]
53 InvalidNip59Envelope,
54
55 #[error("NIP-17 text message creation failed")]
57 Nip17MessageCreationFailed,
58
59 #[error("invalid NIP-17 text message")]
61 InvalidNip17Message,
62
63 #[error("invalid NIP-19 identifier")]
65 InvalidNip19Identifier,
66
67 #[error("external signer capability is unavailable")]
69 ExternalSignerCapabilityUnavailable,
70
71 #[error("external signer operation was cancelled")]
73 ExternalSignerCancelled,
74
75 #[error("external signer rejected the request")]
77 ExternalSignerRejected,
78
79 #[error("external signer returned an invalid signature")]
81 InvalidExternalSignature,
82
83 #[error("invalid relay frame")]
85 InvalidRelayFrame,
86
87 #[error("invalid relay filter")]
89 InvalidRelayFilter,
90
91 #[error("invalid relay authentication")]
93 InvalidRelayAuthentication,
94
95 #[error("invalid relay batch")]
97 InvalidRelayBatch,
98
99 #[error("invalid attachment metadata")]
101 InvalidAttachmentMetadata,
102
103 #[error("attachment is too large")]
105 AttachmentTooLarge,
106
107 #[error("attachment encryption failed")]
109 AttachmentEncryptionFailed,
110
111 #[error("attachment decryption failed")]
113 AttachmentDecryptionFailed,
114
115 #[error("invalid HTTP authorization request")]
117 InvalidHttpAuthorization,
118
119 #[error("invalid Softchat event")]
121 InvalidSoftchatEvent,
122
123 #[error("Softchat event creation failed")]
125 SoftchatEventCreationFailed,
126
127 #[error("invalid Softchat event projection")]
129 InvalidSoftchatProjection,
130
131 #[error("invalid private user metadata")]
133 InvalidUserMetadata,
134
135 #[error("invalid private contact list")]
137 InvalidContactList,
138
139 #[error("invalid application data")]
141 InvalidApplicationData,
142
143 #[error("invalid relay session transition")]
145 InvalidRelaySession,
146
147 #[error("relay session queue is full")]
149 RelaySessionQueueFull,
150
151 #[error("invalid delivery state")]
153 InvalidDeliveryState,
154
155 #[error("invalid persistence adapter result")]
157 InvalidPersistenceResult,
158
159 #[error("invalid Noise handshake")]
161 InvalidNoiseHandshake,
162
163 #[error("Noise handshake is already consumed")]
165 NoiseHandshakeConsumed,
166
167 #[error("Noise session is closed")]
169 NoiseSessionClosed,
170
171 #[error("Noise transport operation failed")]
173 NoiseTransportFailed,
174
175 #[error("invalid Negentropy reconciliation")]
177 InvalidNegentropy,
178
179 #[error("plaintext must not be empty")]
181 EmptyPlaintext,
182
183 #[error("plaintext is too large")]
185 PlaintextTooLarge,
186
187 #[error("unsupported encryption algorithm")]
189 UnsupportedAlgorithm,
190
191 #[error("ciphertext is too large")]
193 CiphertextTooLarge,
194
195 #[error("message encryption failed")]
197 EncryptionFailed,
198
199 #[error("message decryption failed")]
201 DecryptionFailed,
202
203 #[error("identity is erased")]
205 IdentityErased,
206
207 #[error("Softchat operation failed")]
209 InternalFailure,
210}
211
212impl SoftchatError {
213 #[must_use]
215 pub const fn code(&self) -> &'static str {
216 match self {
217 Self::InvalidSecretKey => "invalid_secret_key",
218 Self::InvalidPublicKey => "invalid_public_key",
219 Self::InvalidEventId => "invalid_event_id",
220 Self::InvalidEventSignature => "invalid_event_signature",
221 Self::InvalidEventKind => "invalid_event_kind",
222 Self::InvalidEventTimestamp => "invalid_event_timestamp",
223 Self::InvalidEventTag => "invalid_event_tag",
224 Self::InvalidEventJson => "invalid_event_json",
225 Self::EventTooLarge => "event_too_large",
226 Self::EventSigningFailed => "event_signing_failed",
227 Self::Nip59EnvelopeCreationFailed => "nip59_envelope_creation_failed",
228 Self::InvalidNip59Envelope => "invalid_nip59_envelope",
229 Self::Nip17MessageCreationFailed => "nip17_message_creation_failed",
230 Self::InvalidNip17Message => "invalid_nip17_message",
231 Self::InvalidNip19Identifier => "invalid_nip19_identifier",
232 Self::ExternalSignerCapabilityUnavailable => "external_signer_capability_unavailable",
233 Self::ExternalSignerCancelled => "external_signer_cancelled",
234 Self::ExternalSignerRejected => "external_signer_rejected",
235 Self::InvalidExternalSignature => "invalid_external_signature",
236 Self::InvalidRelayFrame => "invalid_relay_frame",
237 Self::InvalidRelayFilter => "invalid_relay_filter",
238 Self::InvalidRelayAuthentication => "invalid_relay_authentication",
239 Self::InvalidRelayBatch => "invalid_relay_batch",
240 Self::InvalidAttachmentMetadata => "invalid_attachment_metadata",
241 Self::AttachmentTooLarge => "attachment_too_large",
242 Self::AttachmentEncryptionFailed => "attachment_encryption_failed",
243 Self::AttachmentDecryptionFailed => "attachment_decryption_failed",
244 Self::InvalidHttpAuthorization => "invalid_http_authorization",
245 Self::InvalidSoftchatEvent => "invalid_softchat_event",
246 Self::SoftchatEventCreationFailed => "softchat_event_creation_failed",
247 Self::InvalidSoftchatProjection => "invalid_softchat_projection",
248 Self::InvalidUserMetadata => "invalid_user_metadata",
249 Self::InvalidContactList => "invalid_contact_list",
250 Self::InvalidApplicationData => "invalid_application_data",
251 Self::InvalidRelaySession => "invalid_relay_session",
252 Self::RelaySessionQueueFull => "relay_session_queue_full",
253 Self::InvalidDeliveryState => "invalid_delivery_state",
254 Self::InvalidPersistenceResult => "invalid_persistence_result",
255 Self::InvalidNoiseHandshake => "invalid_noise_handshake",
256 Self::NoiseHandshakeConsumed => "noise_handshake_consumed",
257 Self::NoiseSessionClosed => "noise_session_closed",
258 Self::NoiseTransportFailed => "noise_transport_failed",
259 Self::InvalidNegentropy => "invalid_negentropy",
260 Self::EmptyPlaintext => "empty_plaintext",
261 Self::PlaintextTooLarge => "plaintext_too_large",
262 Self::UnsupportedAlgorithm => "unsupported_algorithm",
263 Self::CiphertextTooLarge => "ciphertext_too_large",
264 Self::EncryptionFailed => "encryption_failed",
265 Self::DecryptionFailed => "decryption_failed",
266 Self::IdentityErased => "identity_erased",
267 Self::InternalFailure => "internal_failure",
268 }
269 }
270}