Skip to content

feat(pairing): auto-detect NIP-43 relay and route target to /pair sidecar - #470

Merged
tlongwell-block merged 2 commits into
mainfrom
pip/pair-relay-url-detection
May 4, 2026
Merged

feat(pairing): auto-detect NIP-43 relay and route target to /pair sidecar#470
tlongwell-block merged 2 commits into
mainfrom
pip/pair-relay-url-detection

Conversation

@tlongwell-block

Copy link
Copy Markdown
Collaborator

What

When the desktop app starts a NIP-AB pairing session, it now checks the relay's NIP-11 information document for limitation.auth_required: true. If the relay requires auth (NIP-43 access control), the QR code URL is automatically suffixed with /pair so the target device connects to the ephemeral pairing sidecar instead of the auth-locked main relay.

Non-NIP-43 relays continue to work unchanged — the target connects directly to the relay URL without the /pair suffix.

Why

Follows up on #467 (sprout-pair-relay sidecar). The sidecar handles unauthenticated pairing traffic on NIP-43 locked relays, but the desktop client needs to know when to route the target device there.

How

  1. Before generating the QR code, fetch the relay's NIP-11 document (GET / with Accept: application/nostr+json)
  2. Check limitation.auth_required — if true, the relay is NIP-43 locked
  3. Append /pair to the relay URL using url::Url for proper path handling
  4. The source device still connects to the main relay (with auth) for its own WebSocket session

Change

  • 1 file changed: desktop/src-tauri/src/commands/pairing.rs (+55 lines)
  • 1 file touched: desktop/scripts/check-file-sizes.mjs (bump limit 550→600)

Quality

  • ✅ Compiles clean
  • ✅ Clippy clean (no new warnings)
  • ✅ Codex CLI review: 9/10
  • Single low finding: unwrap_or_default() on reqwest client builder (infallible in practice)

When the relay requires NIP-42 authentication (indicating NIP-43 access
control), the QR code URL is automatically suffixed with /pair so the
target device connects to the ephemeral pairing sidecar instead of the
auth-locked main relay.

Non-NIP-43 relays continue to work unchanged — the target connects
directly to the relay URL without the /pair suffix.

Detection: a throwaway WebSocket connection probes for an AUTH challenge
within 3 seconds. If received → NIP-43 locked → append /pair.

Follows up on #467 (sprout-pair-relay sidecar).
Codex review (5/10) identified two issues:
1. AUTH challenge detection is too broad — Sprout sends AUTH on all
   connections regardless of NIP-43 enforcement. Switched to fetching
   the NIP-11 relay info document and checking limitation.auth_required.
2. String-based URL construction breaks URLs with query strings. Switched
   to url::Url for proper path segment appending.
@tlongwell-block
tlongwell-block merged commit 8916825 into main May 4, 2026
13 checks passed
@tlongwell-block
tlongwell-block deleted the pip/pair-relay-url-detection branch May 4, 2026 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant