diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-27 10:07:30 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-27 14:24:57 +0000 |
| commit | 2c48e37f8341e0d207dd3260c439a0729464b03d (patch) | |
| tree | e3188f6ff8b90e2b883335d95750fe69e16df361 /src/lib/login/fresh.rs | |
| parent | 436b707b2bdecb995bbdb374a029714c9f4c5159 (diff) | |
feat: add --bunker-url to account login for non-interactive use
allows non-interactive bunker:// URL login without requiring --nsec,
by connecting to the remote signer and saving credentials to git config
Diffstat (limited to 'src/lib/login/fresh.rs')
| -rw-r--r-- | src/lib/login/fresh.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs index 0b5922b..8d3a806 100644 --- a/src/lib/login/fresh.rs +++ b/src/lib/login/fresh.rs | |||
| @@ -112,6 +112,62 @@ pub async fn fresh_login_or_signup( | |||
| 112 | Ok((signer, user_ref, source)) | 112 | Ok((signer, user_ref, source)) |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | /// Non-interactive login using a `bunker://` URL provided directly. | ||
| 116 | /// | ||
| 117 | /// Parses the URL, generates a fresh app key, connects to the remote signer, | ||
| 118 | /// and saves the resulting credentials to git config. | ||
| 119 | pub async fn login_with_bunker_url( | ||
| 120 | git_repo: &Option<&Repo>, | ||
| 121 | #[cfg(test)] client: Option<&MockConnect>, | ||
| 122 | #[cfg(not(test))] client: Option<&Client>, | ||
| 123 | bunker_url: &str, | ||
| 124 | save_local: bool, | ||
| 125 | signer_relays: &[String], | ||
| 126 | ) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> { | ||
| 127 | let url = NostrConnectURI::parse(bunker_url) | ||
| 128 | .context("invalid bunker:// URL - must be a valid bunker:// URI")?; | ||
| 129 | |||
| 130 | let (app_key, _) = generate_nostr_connect_app(client, signer_relays)?; | ||
| 131 | |||
| 132 | let printer = Arc::new(Mutex::new(Printer::default())); | ||
| 133 | { | ||
| 134 | let mut p = printer.lock().await; | ||
| 135 | p.println("connecting to remote signer...".to_string()); | ||
| 136 | } | ||
| 137 | |||
| 138 | let (signer, user_public_key, bunker_uri) = | ||
| 139 | listen_for_remote_signer(&app_key, &url, printer).await?; | ||
| 140 | |||
| 141 | let signer_info = SignerInfo::Bunker { | ||
| 142 | bunker_uri: bunker_uri.to_string(), | ||
| 143 | bunker_app_key: app_key.secret_key().to_secret_hex(), | ||
| 144 | npub: Some(user_public_key.to_bech32()?), | ||
| 145 | }; | ||
| 146 | |||
| 147 | let _ = save_to_git_config(git_repo, &signer_info, !save_local).await; | ||
| 148 | |||
| 149 | let user_ref = get_user_details( | ||
| 150 | &user_public_key, | ||
| 151 | client, | ||
| 152 | if let Some(git_repo) = git_repo { | ||
| 153 | Some(git_repo.get_path()?) | ||
| 154 | } else { | ||
| 155 | None | ||
| 156 | }, | ||
| 157 | false, | ||
| 158 | false, | ||
| 159 | ) | ||
| 160 | .await?; | ||
| 161 | |||
| 162 | let source = if save_local { | ||
| 163 | SignerInfoSource::GitLocal | ||
| 164 | } else { | ||
| 165 | SignerInfoSource::GitGlobal | ||
| 166 | }; | ||
| 167 | print_logged_in_as(&user_ref, client.is_none(), &source)?; | ||
| 168 | Ok((signer, user_ref, source)) | ||
| 169 | } | ||
| 170 | |||
| 115 | pub async fn get_fresh_nsec_signer() -> Result< | 171 | pub async fn get_fresh_nsec_signer() -> Result< |
| 116 | Option<( | 172 | Option<( |
| 117 | Arc<dyn NostrSigner>, | 173 | Arc<dyn NostrSigner>, |