Skip to content

Your own Web3Auth project ​

OAuth login on Nostr ​

Nostr has no accounts or passwords: a user is a keypair, and every post is signed with the private key (nsec). That is why most Nostr apps start by asking people to install a signer extension or paste an nsec, and why most people leave at that step.

nostr-shard-signer lets them sign in the way they do everywhere else, with Google, Apple or X, and still ends with a normal Nostr key:

  1. The user clicks Sign in and picks Google, Apple or X in the Web3Auth sheet.
  2. Web3Auth checks the OAuth login and its MPC network returns the user's secp256k1 private key. The key is split into shares held by independent nodes; no single party, Web3Auth included, holds the whole key.
  3. The key is put back together only inside the signer iframe, which runs on a different origin than your app. It becomes the user's Nostr keypair (npub / nsec).
  4. Your app talks to it through window.nostr, exactly as it would to a browser extension. The page gets the pubkey and signed events, never the nsec.

The next time the user signs in with the same account, they get the same key back. Nothing is stored on your server, and there's no seed phrase to lose.

What users get:

  • A standard Nostr identity. Their npub works across Nostr; profiles, follows and notes made in your app show up in every other client.
  • A backup prompt. After a few posts, the widget asks them to back up their key: a password-encrypted backup (NIP-49 ncryptsec) to copy or download, or the plain nsec. A backup made on one site counts on every site.
  • A way out. The widget's profile menu has an Export key button that shows their nsec, so they can move it to an extension or bunker and keep using the same identity without your app.
  • A profile from day one. If they have no Nostr profile yet, the widget shows the name and picture from their Google, Apple or X account.

Know before you ship:

  • The key belongs to a Web3Auth project: your own (clientId) or the shared one. Web3Auth gives each project its own keys, so the same Google account gets a different npub in an app with another clientId. Never change the clientId of a live app, or move it between the shared project and its own: every OAuth user would get a new, empty identity.
  • Each provider is a separate identity. Signing in with Apple doesn't give the npub the user got with Google.
  • The project owner is trusted with users' keys. Whoever owns the Web3Auth project (clientId) decides which sites may use it, so they can run Web3Auth on a page of their own and get the key of any user who signs in there. The signer keeps the key away from your page's code, not from the owner of the clientId. Users trust an app's owner with the identity they create in that app, as with any Web3Auth embedded wallet. With shared sign-in, that owner is whoever runs the hosted signer.
  • Users who already have a Nostr key shouldn't use OAuth. They sign in with their extension or bunker from the same Sign in sheet and keep their identity.

3. Register your first clientId ​

Option A — Portal UI (recommended)

Open https://<user>.github.io/nostr-shard-signer/portal/, connect your Nostr key (Alby or any NIP-07 extension), fill in your clientId and domain, and click Register. Your key signs once, to prove the npub is yours.

Option B — curl

Two requests, like /update: the first returns a nonce; sign a kind-27235 event whose content is that nonce with the npub's key, and send the same body again with nonce and signedEvent.

bash
curl -X POST https://nostr-shard-registrar.<account>.workers.dev/register \
  -H "Content-Type: application/json" \
  -d '{
    "clientId": "YOUR_WEB3AUTH_CLIENT_ID",
    "npub":     "npub1yourpublickey...",
    "domain":   "https://yourapp.com"
  }'
# → { "ok": true, "nonce": "…", "expiresIn": 300 }; then the same body plus "nonce" and "signedEvent"

A successful response returns the Nostr event ID of the published NIP-33 record:

json
{ "ok": true, "event": "abc123...", "published": 3, "total": 3 }

4. Integrate nostr-bridge.js into your app ​

For a self-hosted signer, pass bunkerOrigin. Without it, the bridge uses the hosted signer. The signer uses the registry it was built with (ROOT_PUBKEY_HEX).

html
<!-- In your parent app's <head> -->
<script src="https://cdn.yourdomain.com/nostr-bridge.js"></script>
<script>
  NostrBridge.init({
    clientId: "YOUR_WEB3AUTH_CLIENT_ID",
    bunkerOrigin: "https://bunker.yourdomain.com", // your self-hosted signer
    layout: "floating", // or "in-place"
    buttonSize: "standard", // or "large_social_grid"
    forceIframe: false, // true = skip native extension check
    poweredBy: true, // false = hide the "Powered by nostr-shard-signer" link on the sign-in sheet
    locale: "es", // the widget's language, if the signer has it (default: the browser's, then English)
    theme: "auto", // light or dark: "auto" (the system's, default), "light" or "dark"; NostrBridge.setTheme() changes it later
    signInUi: "panel", // shared sign-in: Web3Auth's panel in the widget, or "buttons" (the signer's own, in its window)
  });
</script>

window.nostr is installed once NostrBridge.init() resolves (await it). Calls made before the iframe reports its auth state are queued automatically.

js
// After `await NostrBridge.init(...)` — queued if the iframe hasn't reported AUTH_STATE yet
const pubkey = await window.nostr.getPublicKey();
const signed = await window.nostr.signEvent({
  kind: 1,
  content: "Hello Nostr!",
  tags: [],
  created_at: Math.floor(Date.now() / 1000),
});

Updating Allowed Domains ​

Option A — Portal UI (recommended)

Open the developer portal, switch to the Update Domains tab, enter your clientId, add/remove domains, and click Sign & Update. The portal fetches the nonce, prompts your Nostr extension to sign it (kind 27235), and submits the proof — no terminal needed.

Option B — curl

bash
# Phase 1: request a nonce
NONCE=$(curl -s -X POST https://<worker>/update \
  -H "Content-Type: application/json" \
  -d '{"clientId":"YOUR_CLIENT_ID","npub":"npub1..."}' | jq -r .nonce)

# Phase 2: sign the nonce with your Nostr key (using nak or any NIP-01 signer)
SIGNED=$(nak event --kind 27235 --content "$NONCE" --sec <your_nsec>)

# Submit the update with the signed event
curl -X POST https://<worker>/update \
  -H "Content-Type: application/json" \
  -d "{
    \"clientId\":    \"YOUR_CLIENT_ID\",
    \"nonce\":       \"$NONCE\",
    \"domains\":     [\"https://yourapp.com\", \"https://staging.yourapp.com\"],
    \"signedEvent\": $SIGNED
  }"

The nonce is stored in CHALLENGES_KV with a 5-minute TTL and deleted after use.


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