solid_pod_rs_nostr/error.rs
1//! Error types for the `solid-pod-rs-nostr` crate.
2//!
3//! The crate surfaces three error domains:
4//!
5//! - [`DidError`] — `did:nostr` parsing and DID-Document rendering.
6//! - [`ResolverError`] — `did:nostr` ↔ WebID bidirectional resolution.
7//! - [`RelayError`] — NIP-01 event validation and relay lifecycle.
8//!
9//! Each error maps cleanly onto a NIP wire-level reject (e.g. `RelayError`
10//! → `["OK", id, false, "<reason>"]`) and onto an HTTP status code when
11//! the consumer serves the `.well-known/did/nostr/:pubkey.json` endpoint.
12
13use thiserror::Error;
14
15/// Errors encountered while parsing `did:nostr` URIs or rendering DID
16/// Documents.
17#[derive(Debug, Error)]
18pub enum DidError {
19 /// The provided hex string does not decode to 32 bytes.
20 #[error("invalid pubkey hex: {0}")]
21 InvalidPubkey(String),
22 /// DID URI did not start with the `did:nostr:` prefix.
23 #[error("not a did:nostr URI: {0}")]
24 NotDidNostr(String),
25}
26
27/// Errors emitted by the `did:nostr` ↔ WebID resolver.
28#[derive(Debug, Error)]
29pub enum ResolverError {
30 /// The URL supplied to the resolver could not be parsed.
31 #[error("invalid url: {0}")]
32 InvalidUrl(String),
33 /// An SSRF policy check refused the outbound request.
34 #[error("ssrf: {0}")]
35 Ssrf(String),
36 /// The transport layer reported a failure.
37 #[error("http: {0}")]
38 Http(String),
39 /// The remote DID document was missing, malformed, or schema-invalid.
40 #[error("malformed DID document: {0}")]
41 Malformed(String),
42}
43
44/// Errors emitted by the embedded Nostr relay.
45#[derive(Debug, Error)]
46pub enum RelayError {
47 /// The event JSON could not be decoded into the NIP-01 envelope.
48 #[error("invalid event: {0}")]
49 InvalidEvent(String),
50 /// Canonical NIP-01 id recomputation does not match the claimed id.
51 #[error("event id mismatch")]
52 IdMismatch,
53 /// BIP-340 signature verification failed.
54 #[error("bad signature: {0}")]
55 BadSignature(String),
56 /// The wire-level message could not be parsed (NIP-01 client→relay).
57 #[error("bad wire message: {0}")]
58 BadMessage(String),
59}