1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum Error {
6 #[error("Assertion failed: {0}")]
8 AssertionFailed(String),
9
10 #[error("Bad NIP-46 Bunker URL")]
12 BadBunkerUrl,
13
14 #[error("Bad Encrypted Message")]
16 BadEncryptedMessage,
17
18 #[error("Bad Encrypted Message due to invalid base64")]
20 BadEncryptedMessageBase64(base64::DecodeError),
21
22 #[error("Base64 Decoding Error: {0}")]
24 Base64(#[from] base64::DecodeError),
25
26 #[error("Bech32 Error: {0}")]
28 Bech32Decode(#[from] bech32::DecodeError),
29
30 #[error("Bech32 Error: {0}")]
32 Bech32Encode(#[from] bech32::EncodeError),
33
34 #[error("Bech32 Error: {0}")]
36 Bech32Hrp(#[from] bech32::primitives::hrp::Error),
37
38 #[error("Crypto Error: {0}")]
40 Crypto(#[from] nip44::Error),
41
42 #[cfg(feature = "client")]
44 #[error("Disconnected")]
45 Disconnected,
46
47 #[error("Private Key Encryption/Decryption Error")]
49 PrivateKeyEncryption,
50
51 #[error("From UTF-8 Error")]
53 FromUtf8(#[from] std::string::FromUtf8Error),
54
55 #[error("Wrong Bech32 Kind: Expected {0} found {0}")]
57 WrongBech32(String, String),
58
59 #[error("Key or Signature Error: {0}")]
61 KeyOrSignature(#[from] secp256k1::Error),
62
63 #[error("Event is in the future")]
65 EventInFuture,
66
67 #[error("Formatting Error: {0}")]
69 Fmt(#[from] std::fmt::Error),
70
71 #[error("Hash Mismatch")]
73 HashMismatch,
74
75 #[error("Hex Decode Error: {0}")]
77 HexDecode(#[from] hex::FromHexError),
78
79 #[cfg(feature = "client")]
81 #[error("HTTP: {0}")]
82 Http(#[from] http::Error),
83
84 #[error("Invalid Encrypted Private Key")]
86 InvalidEncryptedPrivateKey,
87
88 #[error("Invalid Encrypted Event")]
90 InvalidEncryptedEvent,
91
92 #[error("Invalid HLL data")]
94 InvalidHll,
95
96 #[error("Invalid event Id")]
98 InvalidId,
99
100 #[error("Invalid event Id Prefix")]
102 InvalidIdPrefix,
103
104 #[error("Invalid digest length")]
106 InvalidLength(#[from] hmac::digest::InvalidLength),
107
108 #[error("Invalid naddr")]
110 InvalidNAddr,
111
112 #[error("Invalid nevent")]
114 InvalidNEvent,
115
116 #[error("Invalid Operation")]
118 InvalidOperation,
119
120 #[error("Invalid Private Key")]
122 InvalidPrivateKey,
123
124 #[error("Invalid Profile")]
126 InvalidProfile,
127
128 #[error("Invalid Public Key")]
130 InvalidPublicKey,
131
132 #[error("Invalid Public Key Prefix")]
134 InvalidPublicKeyPrefix,
135
136 #[error("Invalid Recipient")]
138 InvalidRecipient,
139
140 #[error("Invalid state: \"{0}\"")]
142 InvalidState(String),
143
144 #[error("Invalid URL: \"{0}\"")]
146 InvalidUrl(#[from] url::ParseError),
147
148 #[cfg(feature = "client")]
150 #[error("Invalid URI: {0}")]
151 InvalidUri(#[from] http::uri::InvalidUri),
152
153 #[error("Invalid URL TLV encoding")]
155 InvalidUrlTlv,
156
157 #[error("Invalid URL Host: \"{0}\"")]
159 InvalidUrlHost(String),
160
161 #[error("Invalid URL Scheme: \"{0}\"")]
163 InvalidUrlScheme(String),
164
165 #[error("Missing URL Authority")]
167 InvalidUrlMissingAuthority,
168
169 #[cfg(feature = "nip46")]
171 #[error("NIP-46 error: {0}")]
172 Nip46Error(String),
173
174 #[cfg(feature = "nip46")]
176 #[error("NIP-46 failed to post: {0}")]
177 Nip46FailedToPost(String),
178
179 #[cfg(feature = "nip46")]
181 #[error("NIP-46 no response")]
182 Nip46NoResponse,
183
184 #[error("Event kind is not replaceable")]
186 NonReplaceableAddr,
187
188 #[error("No private key")]
190 NoPrivateKey,
191
192 #[error("No public key")]
194 NoPublicKey,
195
196 #[error("Out of Range")]
198 OutOfRange(usize),
199
200 #[error("Parse integer error")]
202 ParseInt(#[from] std::num::ParseIntError),
203
204 #[error("Relay (broken) says auth-required before challenging with AUTH")]
206 RelayDidNotAuth,
207
208 #[error("Relay (broken) forgot that we already successfully AUTHed")]
210 RelayForgotAuth,
211
212 #[error("Relay rejected our post")]
214 RelayRejectedPost,
215
216 #[error("Relay rejected our AUTH")]
218 RelayRejectedAuth,
219
220 #[error("Relay requires AUTH")]
222 RelayRequiresAuth,
223
224 #[cfg(feature = "client")]
226 #[error("HTTP error: {0}")]
227 Reqwest(#[from] reqwest::Error),
228
229 #[error("Scrypt invalid output length")]
231 Scrypt,
232
233 #[error("JSON (de)serialization error: {0}")]
235 SerdeJson(#[from] serde_json::Error),
236
237 #[error("Signer is locked")]
239 SignerIsLocked,
240
241 #[error("Try From Slice error: {0}")]
243 Slice(#[from] std::array::TryFromSliceError),
244
245 #[cfg(feature = "speedy")]
247 #[error("Speedy (de)serialization error: {0}")]
248 Speedy(#[from] speedy::Error),
249
250 #[error("Tag mismatch")]
252 TagMismatch,
253
254 #[cfg(feature = "client")]
256 #[error("Timeout")]
257 TimedOut,
258
259 #[cfg(feature = "client")]
261 #[error("Timeout: {0}")]
262 Timeout(#[from] tokio::time::error::Elapsed),
263
264 #[error("Unknown event kind = {0}")]
266 UnknownEventKind(u32),
267
268 #[error("Unknown key security = {0}")]
270 UnknownKeySecurity(u8),
271
272 #[error("Unknown cipher version = {0}")]
274 UnknownCipherVersion(u8),
275
276 #[error("Decryption error: {0}")]
278 Unpad(#[from] aes::cipher::block_padding::UnpadError),
279
280 #[error("Unsupported algorithm")]
282 UnsupportedAlgorithm,
283
284 #[error("Not a valid nostr relay url: {0}")]
286 Url(String),
287
288 #[error("UTF-8 Error: {0}")]
290 Utf8Error(#[from] std::str::Utf8Error),
291
292 #[cfg(feature = "client")]
294 #[error("Websocket error: {0}")]
295 Websocket(#[from] tungstenite::Error),
296
297 #[cfg(feature = "client")]
299 #[error("Websocket connection failed: {0}")]
300 WebsocketConnectionFailed(http::StatusCode),
301
302 #[error("Wrong event kind")]
304 WrongEventKind,
305
306 #[error("Wrong length hex string")]
308 WrongLengthHexString,
309
310 #[error("Wrong length bytes for event kind")]
312 WrongLengthKindBytes,
313
314 #[error("Wrong decryption password")]
316 WrongDecryptionPassword,
317
318 #[error("Invalid Zap Receipt: {0}")]
320 ZapReceipt(String),
321}