diff --git a/src/cli/commands/issue/new.rs b/src/cli/commands/issue/new.rs index bcaf097..fcffd37 100644 --- a/src/cli/commands/issue/new.rs +++ b/src/cli/commands/issue/new.rs @@ -102,7 +102,7 @@ impl CommandRunner for NewArgs { )?)?; let relays = options.relays.clone().flat_relays(&options.config.sets)?; let client = NostrClient::init(&options, &relays).await; - let user_pubk = options.pubkey().await?; + let user_pubk = client.pubkey().await?; let coordinates = naddrs.clone().into_coordinates(); client.add_relays(&naddrs.extract_relays()).await; let repos = client.fetch_repos(coordinates.as_slice()).await?; diff --git a/src/cli/commands/mod.rs b/src/cli/commands/mod.rs index ea94134..3fe8b26 100644 --- a/src/cli/commands/mod.rs +++ b/src/cli/commands/mod.rs @@ -32,7 +32,7 @@ use std::sync::Arc; use std::time::Duration; use clap::{Args, Parser}; -use nostr::key::{Keys, PublicKey, SecretKey}; +use nostr::key::{Keys, SecretKey}; use nostr::nips::nip46::NostrConnectURI; use nostr::signer::{IntoNostrSigner, NostrSigner}; use nostr_connect::client::NostrConnect; @@ -124,19 +124,6 @@ pub enum Commands { impl CliOptions { - /// Gets the public key of the user. - pub async fn pubkey(&self) -> N34Result { - let Some(signer) = self.signer().await? else { - unreachable!( - "This method should only be called when a signer is required. If this panic \ - occurs, it indicates a bug where the command failed to properly require a signer \ - (which is the default behavior)" - ) - }; - - signer.get_public_key().await.map_err(N34Error::SignerError) - } - /// Returns the signer pub async fn signer(&self) -> N34Result>> { if self.nip07 { diff --git a/src/cli/commands/patch/send.rs b/src/cli/commands/patch/send.rs index 25bfa4a..173680f 100644 --- a/src/cli/commands/patch/send.rs +++ b/src/cli/commands/patch/send.rs @@ -73,8 +73,8 @@ impl CommandRunner for SendArgs { let repo_coordinates = naddrs.clone().into_coordinates(); let relays = options.relays.clone().flat_relays(&options.config.sets)?; - let user_pubk = options.pubkey().await?; let client = NostrClient::init(&options, &relays).await; + let user_pubk = client.pubkey().await?; client.add_relays(&naddrs.extract_relays()).await; if let Some(original_patch) = &self.original_patch { diff --git a/src/cli/commands/reply.rs b/src/cli/commands/reply.rs index 9c25fab..b837ff9 100644 --- a/src/cli/commands/reply.rs +++ b/src/cli/commands/reply.rs @@ -81,8 +81,7 @@ impl CommandRunner for ReplyArgs { let nostr_address_path = utils::nostr_address_path()?; let relays = options.relays.clone().flat_relays(&options.config.sets)?; let client = NostrClient::init(&options, &relays).await; - let user_pubk = options.pubkey().await?; - + let user_pubk = client.pubkey().await?; let repo_naddrs = if let Some(naddrs) = self.naddrs.flat_naddrs(&options.config.sets)? { client.add_relays(&naddrs.extract_relays()).await; Some(naddrs) diff --git a/src/cli/commands/repo/announce.rs b/src/cli/commands/repo/announce.rs index faaea7a..500e122 100644 --- a/src/cli/commands/repo/announce.rs +++ b/src/cli/commands/repo/announce.rs @@ -83,7 +83,7 @@ impl CommandRunner for AnnounceArgs { async fn run(mut self, options: CliOptions) -> N34Result<()> { let relays = options.relays.clone().flat_relays(&options.config.sets)?; let client = NostrClient::init(&options, &relays).await; - let user_pubk = options.pubkey().await?; + let user_pubk = client.pubkey().await?; let relays_list = client.user_relays_list(user_pubk).await?; client .add_relays(&utils::add_read_relays(relays_list.as_ref())) diff --git a/src/cli/common_commands.rs b/src/cli/common_commands.rs index ccd43cb..ef8cc32 100644 --- a/src/cli/common_commands.rs +++ b/src/cli/common_commands.rs @@ -50,13 +50,13 @@ pub async fn issue_status_command( new_status: IssueStatus, check_fn: impl FnOnce(&IssueStatus) -> N34Result<()>, ) -> N34Result<()> { - let user_pkey = options.pubkey().await?; let naddrs = utils::naddrs_or_file( naddrs.flat_naddrs(&options.config.sets)?, &utils::nostr_address_path()?, )?; let relays = options.relays.clone().flat_relays(&options.config.sets)?; let client = NostrClient::init(&options, &relays).await; + let user_pubk = client.pubkey().await?; client .add_relays(&[naddrs.extract_relays(), issue_id.relays].concat()) .await; @@ -98,10 +98,10 @@ pub async fn issue_status_command( .map(|c| Tag::coordinate(c, relay_hint.clone())), ) .dedup_tags() - .build(user_pkey); + .build(user_pubk); let event_id = status_event.id.expect("There is an id"); - let user_relays_list = client.user_relays_list(user_pkey).await?; + let user_relays_list = client.user_relays_list(user_pubk).await?; let write_relays = [ relays, naddrs.extract_relays(), @@ -134,13 +134,13 @@ pub async fn patch_status_command( merge_or_applied_patches: Vec, check_fn: impl FnOnce(&PatchStatus) -> N34Result<()>, ) -> N34Result<()> { - let user_pkey = options.pubkey().await?; let naddrs = utils::naddrs_or_file( naddrs.flat_naddrs(&options.config.sets)?, &utils::nostr_address_path()?, )?; let relays = options.relays.clone().flat_relays(&options.config.sets)?; let client = NostrClient::init(&options, &relays).await; + let user_pubk = client.pubkey().await?; client .add_relays(&[naddrs.extract_relays(), patch_id.relays].concat()) .await; @@ -227,10 +227,10 @@ pub async fn patch_status_command( } } - let status_event = status_builder.dedup_tags().build(user_pkey); + let status_event = status_builder.dedup_tags().build(user_pubk); let event_id = status_event.id.expect("There is an id"); - let user_relays_list = client.user_relays_list(user_pkey).await?; + let user_relays_list = client.user_relays_list(user_pubk).await?; let write_relays = [ relays, naddrs.extract_relays(), diff --git a/src/nostr_utils/mod.rs b/src/nostr_utils/mod.rs index f870fcc..712089c 100644 --- a/src/nostr_utils/mod.rs +++ b/src/nostr_utils/mod.rs @@ -124,6 +124,16 @@ impl NostrClient { client } + //// Returns the users public key + pub async fn pubkey(&self) -> N34Result { + self.client + .signer() + .await? + .get_public_key() + .await + .map_err(N34Error::SignerError) + } + /// Add relays and connect to them pub async fn add_relays(&self, relays: &[RelayUrl]) { if relays.is_empty() {