1#![warn(
2 clippy::all,
3 clippy::missing_errors_doc,
4 clippy::style,
5 clippy::unseparated_literal_suffix,
6 clippy::pedantic,
7 clippy::nursery
8)]
9#![allow(clippy::future_not_send, clippy::missing_errors_doc)]
10
11mod crypto;
12mod idb_manager;
13mod key_manager;
14mod relay_pool;
15
16pub use idb_manager::{use_idb_database, use_idb_manager};
18pub use key_manager::{
19 use_create_local_key, use_delete_local_key, use_nostr_id_ctx, use_nostr_key, use_nostr_pubkey,
20};
21pub use relay_pool::{
22 use_live_note, use_nostr_notes, use_nostr_relay_pool, use_notes_by_authors, use_notes_by_kind,
23 use_recent_notes, use_relay_events, use_text_notes,
24};
25
26pub use idb_manager::IdbManagerProvider;
28pub use key_manager::{NostrIdProvider, NostrIdStore};
29pub use relay_pool::{NostrRelayPoolProvider, NostrRelayPoolStore};
30
31pub use idb_manager::{IdbStore, NostrIdb};
33pub use key_manager::{IdbKeypairEntry, NostrId, NostrIdAction};
34pub use relay_pool::{
35 NostrRelayPool, ReadyState, RelayEventSubscription, SubscriptionId, SubscriptionInfo, UserRelay,
36};
37
38#[cfg(feature = "test-components")]
40pub use key_manager::{NostrIdLoginTest, NostrIdLoginTestSuspense};
41#[cfg(feature = "test-components")]
42pub use relay_pool::RelayPoolTest;
43
44pub use nostro2_signer::keypair::{EncryptionScheme, GiftwrapScheme, NostrKeypair};
47pub use nostro2_signer::nostro2::*;
48
49pub extern crate nostro2_signer;
52
53#[derive(Clone, Debug, PartialEq, yew::Properties)]
54pub struct AppProps {
55 pub children: yew::html::Children,
56 #[prop_or_default]
57 pub relays: Vec<UserRelay>,
58 #[prop_or_default]
59 pub fallback: yew::html::Html,
60}
61
62#[yew::function_component(NostrAppProvider)]
63pub fn nostr_app_provider(props: &AppProps) -> yew::Html {
64 yew::html! {
65 <yew::suspense::Suspense fallback={props.fallback.clone()}>
66 <IdbManagerProvider>
67 <NostrRelayPoolProvider relays={props.relays.clone()}>
68 <NostrIdProvider>
69 {props.children.clone()}
70 </NostrIdProvider>
71 </NostrRelayPoolProvider>
72 </IdbManagerProvider>
73 </yew::suspense::Suspense>
74 }
75}
76
77#[derive(Debug)]
78pub enum MinionError {
79 Idb(idb::Error),
80 NoNostrKeyFound,
81 NostrError(nostro2_signer::nostro2::errors::NostrErrors),
82 NostrKeypairError(nostro2_signer::errors::NostrKeypairError),
83 CryptoError(wasm_bindgen::JsValue),
84 WasmSerde(serde_wasm_bindgen::Error),
85 NoIdentityFound,
86}
87
88impl std::fmt::Display for MinionError {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 match self {
91 Self::Idb(e) => write!(f, "IDB error: {e}"),
92 Self::NoNostrKeyFound => write!(f, "Could not find Nostr key"),
93 Self::NostrError(e) => write!(f, "Nostr Error: {e}"),
94 Self::NostrKeypairError(e) => write!(f, "Nostr Keypair Error: {e}"),
95 Self::CryptoError(e) => write!(f, "Crypto Error: {e:?}"),
96 Self::WasmSerde(e) => write!(f, "Serialization Error: {e}"),
97 Self::NoIdentityFound => write!(f, "No Identity Found"),
98 }
99 }
100}
101
102impl std::error::Error for MinionError {
103 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
104 match self {
105 Self::Idb(e) => Some(e),
106 Self::NostrError(e) => Some(e),
107 Self::NostrKeypairError(e) => Some(e),
108 Self::WasmSerde(e) => Some(e),
109 _ => None,
110 }
111 }
112}
113
114impl From<idb::Error> for MinionError {
115 fn from(e: idb::Error) -> Self {
116 Self::Idb(e)
117 }
118}
119
120impl From<nostro2_signer::nostro2::errors::NostrErrors> for MinionError {
121 fn from(e: nostro2_signer::nostro2::errors::NostrErrors) -> Self {
122 Self::NostrError(e)
123 }
124}
125
126impl From<nostro2_signer::errors::NostrKeypairError> for MinionError {
127 fn from(e: nostro2_signer::errors::NostrKeypairError) -> Self {
128 Self::NostrKeypairError(e)
129 }
130}
131
132impl From<serde_wasm_bindgen::Error> for MinionError {
133 fn from(e: serde_wasm_bindgen::Error) -> Self {
134 Self::WasmSerde(e)
135 }
136}
137
138impl From<MinionError> for web_sys::wasm_bindgen::JsValue {
139 fn from(e: MinionError) -> Self {
140 Self::from_str(e.to_string().as_str())
141 }
142}