commit c8bbc6358bf5738998f6550aad46887d5b1d1806
parent 10ee914cb95f47c9f37b47821bff0a639abf4c0a
Author: triesap <tyson@radroots.org>
Date: Wed, 1 Apr 2026 23:13:55 +0000
nostr: add signerless relay client constructors
Diffstat:
1 file changed, 38 insertions(+), 0 deletions(-)
diff --git a/crates/nostr/src/client.rs b/crates/nostr/src/client.rs
@@ -96,6 +96,20 @@ impl RadrootsNostrClientOptions {
}
impl RadrootsNostrClient {
+ pub fn new_signerless() -> Self {
+ Self {
+ inner: Client::new(),
+ }
+ }
+
+ pub fn new_signerless_with_options(
+ options: RadrootsNostrClientOptions,
+ ) -> Result<Self, RadrootsNostrError> {
+ let opts = options.to_client_options()?;
+ let inner = ClientBuilder::new().opts(opts).build();
+ Ok(Self { inner })
+ }
+
pub fn new(keys: RadrootsNostrKeys) -> Self {
Self {
inner: Client::new(keys),
@@ -219,3 +233,27 @@ pub async fn radroots_nostr_fetch_event_by_id(
.ok_or_else(|| RadrootsNostrError::EventNotFound(event_id.to_hex()))?;
Ok(event.clone())
}
+
+#[cfg(test)]
+mod tests {
+ use super::{RadrootsNostrClient, RadrootsNostrClientOptions};
+
+ #[test]
+ fn signerless_client_has_no_signer() {
+ let client = RadrootsNostrClient::new_signerless();
+
+ assert!(client.signer().is_none());
+ }
+
+ #[test]
+ fn signerless_client_with_options_has_no_signer() {
+ let client = RadrootsNostrClient::new_signerless_with_options(
+ RadrootsNostrClientOptions::new()
+ .automatic_authentication(true)
+ .verify_subscriptions(true),
+ )
+ .expect("signerless client");
+
+ assert!(client.signer().is_none());
+ }
+}