Skip to content

How it works ​

Two login paths, one API:

ModeWho it's forHow it works
Web3Auth OAuthUsers new to Nostr or who prefer social loginGoogle, Apple, or X → MPC key is derived and held inside a sandboxed cross-origin iframe. The nsec never leaves that context.
NIP-07 extension or NIP-46 bunkerUsers who already hold their own Nostr keyAn installed extension (Alby, nos2x…) is used directly. Without one, window.nostr.js connects to a NIP-46 bunker (Amber, nsecBunker…) over an encrypted relay channel. The parent app sees only signed events — never the key.

The bridge detects a stored session on load and switches modes transparently. Both expose an identical window.nostr API, so client code is the same regardless of which path the user chose.

Need zero client-side key reconstruction? Users can keep their key in a NIP-46 bunker they control, such as Amber on their phone or a self-hosted nsecBunker; nostr-shard-signer then just passes calls through.

Architecture ​

┌─────────────────────────────────────────────┐
│  Parent App  (app.example.com)              │
│                                             │
│  <script src="nostr-bridge.js">             │
│  window.nostr  ← Proxy object               │
│                                             │
│  ┌───────────────────────────────────────┐  │
│  │ <iframe src="<pages>/signer.html">    │  │
│  │                                       │  │
│  │  signer.html                          │  │
│  │  ├─ Web3Auth MPC login UI             │  │
│  │  ├─ nsec held in isolated JS context  │  │
│  │  └─ Signs/encrypts via nostr-tools    │  │
│  └───────────────────────────────────────┘  │
│          ↑↓  postMessage (NIP-46 RPC)       │
└─────────────────────────────────────────────┘
                        ↑
             NIP-33 registry check
                        ↑
┌─────────────────────────────────────────────┐
│  registrar-worker.js  (Cloudflare Worker)   │
│  POST /register  POST /update (two-phase)   │
│  REGISTRY_KV: short-lived mutex (60s TTL)   │
│  CHALLENGES_KV: nonces (TTL 5m)             │
│  Source of truth: NIP-33 events on relays   │
└─────────────────────────────────────────────┘
                        ↑
         register/update via UI or curl
                        ↑
┌─────────────────────────────────────────────┐
│  portal/index.html  (GitHub Pages)          │
│  ├─ nostr-bridge.js → window.nostr          │
│  ├─ Connect Nostr key (Alby / NIP-07)       │
│  ├─ Register tab: clientId + domain         │
│  └─ Update tab: sign nonce (kind 27235)     │
└─────────────────────────────────────────────┘

Three-state iframe UI ​

[Login Button] ──login──► [Floating Avatar] ──click──► [Profile Modal]
                                 ▲                            │
                                 └──────────── close ─────────┘

The iframe resizes its container by sending { type: "RESIZE", state: "button" | "avatar" | "modal" } messages to the parent.


Login Modes ​

Mode 1 — Web3Auth OAuth (default) ​

With the page's own clientId, or the hosted signer's shared project without one.

Users click the login button inside the iframe, pick a social provider (Google, Apple, X), and Web3Auth derives a Nostr keypair via MPC. The nsec is reconstructed only inside the cross-origin iframe context and is never serialised to localStorage or sent over the wire.

Unlike storing an nsec on a server, MPC splits the key into threshold shares distributed across independent nodes — no single party, including Web3Auth itself, ever holds the complete key, so a server breach yields only an unusable fragment. The key is still put back together for whoever runs Web3Auth with the project's clientId on an allowlisted page, which the project owner controls (see Security Model).

This is the recommended mode for apps whose users may not have a Nostr identity yet.

Mode 2 — NIP-46 Bunker via window.nostr.js ​

For users who already control their Nostr key, the bridge optionally loads window.nostr.js (WNJ) — a lightweight NIP-46 client that connects to any remote bunker over Nostr relays.

How the handoff works:

  1. NostrBridge.init() loads the WNJ CDN bundle (if forceIframe: false).
  2. Clicking Sign in opens the Web3Auth login with a Nostr signer or bunker option right above it. Picking that opens WNJ's connect UI (bunker URL entry or QR scan for Amber).
  3. Once the user connects, WNJ stores the bunker session in localStorage and exposes window.nostr.
  4. The bridge detects WNJ's session and switches to MODE_WNJ: all window.nostr calls are routed to WNJ. The bridge's widget shows the connected profile; WNJ's own floating pill is hidden so only one widget appears, and Disconnect in the profile also forgets the WNJ bunker.
  5. On subsequent page loads the session is restored silently — no UI shown, no modal opened.

Compatible remote signers:

SignerPlatformNotes
AmberAndroidPhone acts as bunker via NIP-46
nsecBunkerSelf-hostedFull custody, relay of your choice

Any other NIP-46 remote signer works too: paste its bunker:// URL, or scan the nostrconnect:// QR code with the signer app.

NostrBridge.init() option:

js
NostrBridge.init({
  clientId: "YOUR_WEB3AUTH_CLIENT_ID",
  forceIframe: false, // default — loads WNJ; set true to skip WNJ entirely
});

Setting forceIframe: true disables WNJ loading and always uses the Web3Auth iframe, regardless of any stored bunker session.



MIT licensed. The signer runs at signer.shardsigner.com; this site never holds keys.