From 9069adbe22861e938fa9cb1e57c7beeb8d2e21af Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Sun, 8 Jun 2025 20:26:38 +0000
Subject: [PATCH] chore: Add the signer to the client if found
Signed-off-by: Awiteb
---
src/cli/commands/mod.rs | 8 ++++++++
src/nostr_utils/mod.rs | 20 ++++++++------------
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/src/cli/commands/mod.rs b/src/cli/commands/mod.rs
index 48f240b..535e3eb 100644
--- a/src/cli/commands/mod.rs
+++ b/src/cli/commands/mod.rs
@@ -117,6 +117,14 @@ impl CliOptions {
unreachable!("There is no other method until now")
}
+ /// Returns the signer
+ pub fn signer(&self) -> Option {
+ if let Some(sk) = &self.secret_key {
+ return Some(Keys::new(sk.clone()));
+ }
+ None
+ }
+
/// Returns an error if there are no relays.
pub fn ensure_relays(&self) -> N34Result<()> {
if self.relays.is_empty() {
diff --git a/src/nostr_utils/mod.rs b/src/nostr_utils/mod.rs
index 6794913..e68af2e 100644
--- a/src/nostr_utils/mod.rs
+++ b/src/nostr_utils/mod.rs
@@ -25,7 +25,7 @@ use futures::future;
use nostr::{
event::{Event, EventId, Kind, Tag, TagStandard, Tags, UnsignedEvent},
filter::Filter,
- key::{Keys, PublicKey},
+ key::PublicKey,
nips::{nip01::Coordinate, nip22, nip34::GitRepositoryAnnouncement},
parser::NostrParser,
types::RelayUrl,
@@ -103,17 +103,13 @@ impl NostrClient {
/// Initializes a new [`NostrClient`] instance and connects to the specified
/// relays.
pub async fn init(options: &CliOptions, relays: &[RelayUrl]) -> Self {
- let client = Self::new(
- Client::builder()
- .signer(Keys::new(
- options
- .secret_key
- .as_ref()
- .expect("This the only method for now")
- .clone(),
- ))
- .build(),
- );
+ let mut client_builder = Client::builder();
+
+ if let Some(signer) = options.signer() {
+ client_builder = client_builder.signer(signer);
+ }
+
+ let client = Self::new(client_builder.build());
client.add_relays(relays).await;
client