Files
nostr_login_lite/NOSTR_LOGIN_LITE.md
Your Name 37fb89c0a9 first
2025-09-09 09:32:09 -04:00

20 KiB
Raw Blame History

NOSTR_LOGIN_LITE

Objective

Key differences vs current project

  • UI: replace Stencil/Tailwind component library with a single vanilla-JS modal and minimal CSS.
  • Transport: remove NDK; implement NIP-46 RPC using nostr-tools SimplePool.
  • Crypto: rely on nostr-tools (via CDN global window.NostrTools) for keygen/signing (finalizeEvent), nip04, nip19, and SimplePool; embed a small NIP-44 codec if window.NostrTools.nip44 is not available. The current projects codec is in packages/auth/src/utils/nip44.ts.

Nostr Tools via CDN (global window.NostrTools)

Supported login methods and crypto summary

  • Connect (nip46): secp256k1 Schnorr for event signing/hash; nip44 (ChaCha20/HKDF/HMAC) for RPC payloads, with nip04 fallback. Requires relay connectivity (via NostrTools.SimplePool).
  • Extension: crypto handled by the extension; we bridge calls.
  • Local key: secp256k1 Schnorr signing (NostrTools.finalizeEvent()) and nip04/nip44 encrypt/decrypt locally.
  • Read-only: no client crypto.
  • OTP/DM: no client crypto beyond state persistence; server sends DM and verifies via HTTP.

Minimal file layout

External dependencies strategy

Compatibility requirements

Architecture overview

  • NostrLite: window.nostr facade mirroring current behavior, invokes auth UI when needed.
  • Auth: manages methods (connect/extension/local/readOnly/otp), state, storage, event dispatch.
  • NIP46Client: minimal RPC over NostrTools.SimplePool (subscribe, send request, parse/decrypt, dedupe auth_url).
  • ExtensionBridge: safely handle window.nostr detection, guard against overwrites, switch to extension mode when requested.
  • Store: localStorage helpers for accounts/current/recents and misc values.
  • UI: single vanilla modal that lists options and drives flow, with optional inline iframe starter for providers that publish iframe_url.

Function-level TODO checklist (execution order)

Bootstrap and API surface

window.nostr facade

Auth module

NIP46Client (transport over NostrTools.SimplePool)

Iframe handshake

ExtensionBridge

Local signer (wrapping window.NostrTools)

Store (localStorage helpers)

UI (single modal)

Event bus

Relay configuration helpers

Parity acceptance criteria

Notes and implementation tips

  • Load order: Deps.ensureNostrToolsLoaded() must guard all usages of window.NostrTools.
  • Request de-duplication: mirror setResponseHandler() behavior to avoid auth_url flooding.
  • NIP-44 selection: use nip44 for all methods except "create_account".
  • Iframe origin checks: follow ReadyListener host/subdomain verification.
  • Secret handling in nostrconnect: accept 'ack' or exact secret; see listen.
  • Profile fetch is optional; keep it async and non-blocking, update UI/state when complete.

Out of scope for initial lite version

  • Complex banners/popups and multi-window flows.
  • Full NDK feature parity beyond the minimum for NIP-46 RPC.
  • Advanced error telemetry; keep console logs minimal.

Deliverables

  • Single distributable lite/nostr-login-lite.js usable via:
    • <script src="..."></script> with window.nostr present after [init()](lite/nostr-login-lite.js:1).
    • Optional ESM import with same API.
  • Minimal HTML example showing each auth method path is functional.