From 4d093c0c5e7b22863926928d2afffd36ad389bef Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 17 Feb 2026 15:46:20 +0000 Subject: add --signer-relay option to ngit account login Allow users to specify custom signer relays for nostrconnect login. Relay URLs are auto-prefixed with wss:// if no scheme is provided. --- src/bin/ngit/sub_commands/login.rs | 5 +++++ src/lib/login/fresh.rs | 21 ++++++++++++++++++--- src/lib/login/mod.rs | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs index 9081e66..3acfb66 100644 --- a/src/bin/ngit/sub_commands/login.rs +++ b/src/bin/ngit/sub_commands/login.rs @@ -23,6 +23,10 @@ pub struct SubCommandArgs { /// don't fetch user metadata and relay list from relays #[arg(long, action)] offline: bool, + + /// signer relay for nostrconnect (can be used multiple times) + #[arg(long = "signer-relay")] + signer_relays: Vec, } pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { @@ -62,6 +66,7 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { client.as_ref(), signer_info, log_in_locally_only || command_args.local, + &command_args.signer_relays, ) .await?; } diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs index 8e49085..2f6becf 100644 --- a/src/lib/login/fresh.rs +++ b/src/lib/login/fresh.rs @@ -35,6 +35,7 @@ pub async fn fresh_login_or_signup( #[cfg(not(test))] client: Option<&Client>, signer_info: Option, save_local: bool, + signer_relays: &[String], ) -> Result<(Arc, UserRef, SignerInfoSource)> { let (signer, public_key, signer_info, source) = loop { if let Some(signer_info) = signer_info { @@ -71,7 +72,7 @@ pub async fn fresh_login_or_signup( continue; } }, - 1 => match get_fresh_nip46_signer(client).await { + 1 => match get_fresh_nip46_signer(client, signer_relays).await { Ok(Some(res)) => break res, Ok(None) => continue, Err(e) => { @@ -247,6 +248,7 @@ fn shorten_string(s: &str) -> String { pub async fn get_fresh_nip46_signer( #[cfg(test)] client: Option<&MockConnect>, #[cfg(not(test))] client: Option<&Client>, + signer_relays: &[String], ) -> Result< Option<( Arc, @@ -255,7 +257,7 @@ pub async fn get_fresh_nip46_signer( SignerInfoSource, )>, > { - let (app_key, nostr_connect_url) = generate_nostr_connect_app(client)?; + let (app_key, nostr_connect_url) = generate_nostr_connect_app(client, signer_relays)?; let printer = Arc::new(Mutex::new(Printer::default())); let signer_choice = Interactor::default().choice( PromptChoiceParms::default() @@ -366,9 +368,22 @@ pub async fn get_fresh_nip46_signer( pub fn generate_nostr_connect_app( #[cfg(test)] client: Option<&MockConnect>, #[cfg(not(test))] client: Option<&Client>, + signer_relays: &[String], ) -> Result<(Keys, NostrConnectURI)> { let app_key = Keys::generate(); - let relays = if let Some(client) = client { + let relays = if !signer_relays.is_empty() { + signer_relays + .iter() + .map(|s| { + if s.starts_with("ws://") || s.starts_with("wss://") { + s.clone() + } else { + format!("wss://{s}") + } + }) + .flat_map(|s| RelayUrl::parse(&s)) + .collect::>() + } else if let Some(client) = client { client .get_fallback_signer_relays() .iter() diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs index 3fcd755..b484fea 100644 --- a/src/lib/login/mod.rs +++ b/src/lib/login/mod.rs @@ -40,7 +40,7 @@ pub async fn login_or_signup( if res.is_ok() { res } else { - fresh_login_or_signup(git_repo, client, None, false).await + fresh_login_or_signup(git_repo, client, None, false, &[]).await } } -- cgit v1.2.3