diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-17 15:46:20 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-17 15:46:20 +0000 |
| commit | 4d093c0c5e7b22863926928d2afffd36ad389bef (patch) | |
| tree | d439237587fe94a0aeb2c27a6deaa69ea682538d | |
| parent | 1ea1c19ac93dbf97d82ec7bc1a1f3c0123588fa4 (diff) | |
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.
| -rw-r--r-- | src/bin/ngit/sub_commands/login.rs | 5 | ||||
| -rw-r--r-- | src/lib/login/fresh.rs | 21 | ||||
| -rw-r--r-- | 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 { | |||
| 23 | /// don't fetch user metadata and relay list from relays | 23 | /// don't fetch user metadata and relay list from relays |
| 24 | #[arg(long, action)] | 24 | #[arg(long, action)] |
| 25 | offline: bool, | 25 | offline: bool, |
| 26 | |||
| 27 | /// signer relay for nostrconnect (can be used multiple times) | ||
| 28 | #[arg(long = "signer-relay")] | ||
| 29 | signer_relays: Vec<String>, | ||
| 26 | } | 30 | } |
| 27 | 31 | ||
| 28 | pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | 32 | pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { |
| @@ -62,6 +66,7 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | |||
| 62 | client.as_ref(), | 66 | client.as_ref(), |
| 63 | signer_info, | 67 | signer_info, |
| 64 | log_in_locally_only || command_args.local, | 68 | log_in_locally_only || command_args.local, |
| 69 | &command_args.signer_relays, | ||
| 65 | ) | 70 | ) |
| 66 | .await?; | 71 | .await?; |
| 67 | } | 72 | } |
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( | |||
| 35 | #[cfg(not(test))] client: Option<&Client>, | 35 | #[cfg(not(test))] client: Option<&Client>, |
| 36 | signer_info: Option<SignerInfo>, | 36 | signer_info: Option<SignerInfo>, |
| 37 | save_local: bool, | 37 | save_local: bool, |
| 38 | signer_relays: &[String], | ||
| 38 | ) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> { | 39 | ) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> { |
| 39 | let (signer, public_key, signer_info, source) = loop { | 40 | let (signer, public_key, signer_info, source) = loop { |
| 40 | if let Some(signer_info) = signer_info { | 41 | if let Some(signer_info) = signer_info { |
| @@ -71,7 +72,7 @@ pub async fn fresh_login_or_signup( | |||
| 71 | continue; | 72 | continue; |
| 72 | } | 73 | } |
| 73 | }, | 74 | }, |
| 74 | 1 => match get_fresh_nip46_signer(client).await { | 75 | 1 => match get_fresh_nip46_signer(client, signer_relays).await { |
| 75 | Ok(Some(res)) => break res, | 76 | Ok(Some(res)) => break res, |
| 76 | Ok(None) => continue, | 77 | Ok(None) => continue, |
| 77 | Err(e) => { | 78 | Err(e) => { |
| @@ -247,6 +248,7 @@ fn shorten_string(s: &str) -> String { | |||
| 247 | pub async fn get_fresh_nip46_signer( | 248 | pub async fn get_fresh_nip46_signer( |
| 248 | #[cfg(test)] client: Option<&MockConnect>, | 249 | #[cfg(test)] client: Option<&MockConnect>, |
| 249 | #[cfg(not(test))] client: Option<&Client>, | 250 | #[cfg(not(test))] client: Option<&Client>, |
| 251 | signer_relays: &[String], | ||
| 250 | ) -> Result< | 252 | ) -> Result< |
| 251 | Option<( | 253 | Option<( |
| 252 | Arc<dyn NostrSigner>, | 254 | Arc<dyn NostrSigner>, |
| @@ -255,7 +257,7 @@ pub async fn get_fresh_nip46_signer( | |||
| 255 | SignerInfoSource, | 257 | SignerInfoSource, |
| 256 | )>, | 258 | )>, |
| 257 | > { | 259 | > { |
| 258 | let (app_key, nostr_connect_url) = generate_nostr_connect_app(client)?; | 260 | let (app_key, nostr_connect_url) = generate_nostr_connect_app(client, signer_relays)?; |
| 259 | let printer = Arc::new(Mutex::new(Printer::default())); | 261 | let printer = Arc::new(Mutex::new(Printer::default())); |
| 260 | let signer_choice = Interactor::default().choice( | 262 | let signer_choice = Interactor::default().choice( |
| 261 | PromptChoiceParms::default() | 263 | PromptChoiceParms::default() |
| @@ -366,9 +368,22 @@ pub async fn get_fresh_nip46_signer( | |||
| 366 | pub fn generate_nostr_connect_app( | 368 | pub fn generate_nostr_connect_app( |
| 367 | #[cfg(test)] client: Option<&MockConnect>, | 369 | #[cfg(test)] client: Option<&MockConnect>, |
| 368 | #[cfg(not(test))] client: Option<&Client>, | 370 | #[cfg(not(test))] client: Option<&Client>, |
| 371 | signer_relays: &[String], | ||
| 369 | ) -> Result<(Keys, NostrConnectURI)> { | 372 | ) -> Result<(Keys, NostrConnectURI)> { |
| 370 | let app_key = Keys::generate(); | 373 | let app_key = Keys::generate(); |
| 371 | let relays = if let Some(client) = client { | 374 | let relays = if !signer_relays.is_empty() { |
| 375 | signer_relays | ||
| 376 | .iter() | ||
| 377 | .map(|s| { | ||
| 378 | if s.starts_with("ws://") || s.starts_with("wss://") { | ||
| 379 | s.clone() | ||
| 380 | } else { | ||
| 381 | format!("wss://{s}") | ||
| 382 | } | ||
| 383 | }) | ||
| 384 | .flat_map(|s| RelayUrl::parse(&s)) | ||
| 385 | .collect::<Vec<RelayUrl>>() | ||
| 386 | } else if let Some(client) = client { | ||
| 372 | client | 387 | client |
| 373 | .get_fallback_signer_relays() | 388 | .get_fallback_signer_relays() |
| 374 | .iter() | 389 | .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( | |||
| 40 | if res.is_ok() { | 40 | if res.is_ok() { |
| 41 | res | 41 | res |
| 42 | } else { | 42 | } else { |
| 43 | fresh_login_or_signup(git_repo, client, None, false).await | 43 | fresh_login_or_signup(git_repo, client, None, false, &[]).await |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | 46 | ||