1use std::fmt;
8
9use nostr::event::builder;
10use nostr::nips::{nip04, nip44, nip46};
11use nostr::PublicKey;
12use nostr_relay_pool::pool;
13use tokio::sync::SetError;
14
15#[derive(Debug)]
17pub enum Error {
18 Builder(builder::Error),
20 NIP04(nip04::Error),
22 NIP44(nip44::Error),
24 NIP46(nip46::Error),
26 Pool(pool::Error),
28 SetUserPublicKey(SetError<PublicKey>),
30 Response(String),
32 SignerPublicKeyNotFound,
34 Timeout,
36 UnexpectedUri,
38 PublicKeyNotMatchAppKeys,
40}
41
42impl std::error::Error for Error {}
43
44impl fmt::Display for Error {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self {
47 Self::Builder(e) => e.fmt(f),
48 Self::NIP04(e) => e.fmt(f),
49 Self::NIP44(e) => e.fmt(f),
50 Self::NIP46(e) => e.fmt(f),
51 Self::Pool(e) => e.fmt(f),
52 Self::SetUserPublicKey(e) => e.fmt(f),
53 Self::Response(e) => e.fmt(f),
54 Self::SignerPublicKeyNotFound => f.write_str("signer public key not found"),
55 Self::Timeout => f.write_str("timeout"),
56 Self::UnexpectedUri => f.write_str("unexpected URI"),
57 Self::PublicKeyNotMatchAppKeys => f.write_str("public key not match app keys"),
58 }
59 }
60}
61
62impl From<builder::Error> for Error {
63 fn from(e: builder::Error) -> Self {
64 Self::Builder(e)
65 }
66}
67
68impl From<nip04::Error> for Error {
69 fn from(e: nip04::Error) -> Self {
70 Self::NIP04(e)
71 }
72}
73
74impl From<nip44::Error> for Error {
75 fn from(e: nip44::Error) -> Self {
76 Self::NIP44(e)
77 }
78}
79
80impl From<nip46::Error> for Error {
81 fn from(e: nip46::Error) -> Self {
82 Self::NIP46(e)
83 }
84}
85
86impl From<pool::Error> for Error {
87 fn from(e: pool::Error) -> Self {
88 Self::Pool(e)
89 }
90}
91
92impl From<SetError<PublicKey>> for Error {
93 fn from(e: SetError<PublicKey>) -> Self {
94 Self::SetUserPublicKey(e)
95 }
96}