Skip to content

Options and API ​

3. API ​

NostrBridge.init(config): Promise<void> ​

OptionTypeDefaultNotes
clientIdstringnoneYour Web3Auth client ID: Google/Apple/X with your project's keys. Without it, Google/Apple/X goes through shared sign-in (see section 1)
nostrOnlybooleanfalsetrue: no Google/Apple/X, only extension / bunker sign-in; clientId is ignored
globalLogin"offer" | "off" | "require""offer"With your own clientId: whether users may use their global account (same identities on every site; the signer's operator can open it, you can't) next to an account only for your site. "off": only-for-this-site accounts; "require": the global account only
bunkerOriginstring (absolute URL)https://signer.shardsigner.comOnly for a self-hosted signer
forceIframebooleanfalsetrue: ignore an installed extension and don't offer bunkers; always use Web3Auth. Ignored with nostrOnly
layout"floating" | "in-place""floating"Floating widget sits bottom-right
buttonSize"standard" | "large_social_grid""standard"
mountSelectorstring (CSS selector)noneWhere the widget renders with layout: "in-place"; falls back to <body>
poweredBybooleantruefalse: hide the "Powered by nostr-shard-signer" link at the bottom of the sign-in sheet
localestringthe browser's languageLanguage code for the widget ("es", "pt-BR"). Used only if the signer has that language, else the browser's, else English. Pages can't supply or change the signer's text.
theme"auto" | "light" | "dark""auto"The widget light or dark. "auto" follows the system setting. Change it later with NostrBridge.setTheme() (a page with its own dark-mode toggle). The signer's windows follow the system. Pages can't pass colours.
signInUi"panel" | "buttons""panel"Shared sign-in: Web3Auth's own panel in the widget (every provider the project offers, wallets hidden, Web3Auth's languages) or the signer's own Google, Apple, Facebook and X buttons in the sign-in window (the signer's languages and design)

Rejects if bunkerOrigin is not a valid URL (a corrected call may then retry). Later calls return the first call's promise and ignore their config. On load it:

  1. Asks an installed NIP-07 extension for the pubkey (waits up to 5 s). If it answers, signing goes through it. If it doesn't (locked, or waiting for the user to approve), the sign-in chooser offers "Browser extension", and a late approval still signs the user in.
  2. Without an extension, loads window.nostr.js so users can connect a NIP-46 bunker (Amber, nsecBunker or any other). It can't load next to an extension, so extension users are not offered bunkers.
  3. Replaces window.nostr with its own object, and injects the signer iframe (the Sign in button / avatar widget).
  4. Restores a session from a previous visit if there is one.

NostrBridge.ready: Promise<void> ​

Resolves once init() has completed, whoever called it (e.g. the data-client-id auto-init).

NostrBridge.onAuthChange(callback): () => void ​

callback({ loggedIn, pubkey }) runs on every sign-in / sign-out, and when the user switches to another identity on this site (shared sign-in: same loggedIn, new pubkey), only when the state changes. Re-read anything tied to the pubkey then. If the state is already known when you subscribe, it also runs right away, so a restored session is never missed. Returns an unsubscribe function. Can be called before init().

The same data is dispatched as a CustomEvent on window: window.addEventListener("nostr-bridge:auth", (e) => e.detail /* { loggedIn, pubkey } */).

NostrBridge.login(): Promise<void> ​

Opens the sign-in modal, the same as the widget's "Sign in" button (it also offers the user's extension or NIP-46 bunker). Resolves once the modal was requested, or immediately if already logged in; the result arrives through onAuthChange. Rejects if init() was never called. Call it from a click handler.

NostrBridge.logout(): Promise<void> ​

Signs the user out (Web3Auth session, or the extension/bunker connection as far as the bridge is concerned). Resolves once the logged-out state has been reported.

NostrBridge.setTheme(theme): void ​

"auto", "light" or "dark": the widget's theme from now on, e.g. when the page's own dark-mode toggle changes. Throws on any other value. Before init(), it becomes the default for it.

NostrBridge.getAuthState(): { loggedIn: boolean, pubkey: string | null } ​

Synchronous current state.

NostrBridge.getSavedSession(): { pubkey, mode: "iframe" | "wnj" } | null ​

Session cached in localStorage from a previous visit. Works before init(), e.g. to render the signed-in UI without a flash.

window.nostr (standard NIP-07) ​

MethodReturnsNotes
getPublicKey()Promise<string>64-char hex pubkey
signEvent({ kind, created_at, tags, content })Promise<{ id, pubkey, sig, … }>pubkey is filled in by the signer
nip04.encrypt(pubkeyHex, plaintext) / nip04.decrypt(pubkeyHex, ciphertext)Promise<string>Legacy DMs
nip44.encrypt(pubkeyHex, plaintext) / nip44.decrypt(pubkeyHex, ciphertext)Promise<string>
evolustr.capabilities() / evolustr.getWrapKey() / evolustr.enrollPasskey()see notesEvolustr Signer API: a key per app (by page origin) for its encrypted data

Behaviour:

  • Calls made while the signer is still loading are queued. After that, calls made while logged out reject with "nostr-bridge: user is not logged in…".
  • Don't rely on window.nostr calls to open a login prompt. The user signs in through the widget, or your button calling NostrBridge.login().
  • With Web3Auth login, ordinary public content is signed without asking by default: kinds 1, 7, 1111, 30818 (wiki), 10003/30003 (bookmarks), 31922/31923 (calendar), 30078 (app data, except Evolustr data keys), and 27235 (NIP-98) for nostr.build uploads. Users can turn these off per site. Replaceable data (lists, bookmarks, app data) is replaced without asking only when this site signed what's on the relays, or the change only adds list entries or removes ones this site added; otherwise the user is asked. Events dated more than 5 minutes ahead are refused, and so are deletions (kind 5) aimed at the user's Evolustr vaults or at another key's address. Kinds 0, 3, 10002, 5, 22242, 24242 and 62, other kinds, nip04.encrypt and both decrypts show a confirmation in the widget. Extensions and bunkers apply their own rules, Evolustr vault events included: the signer can't ask for those when an extension signs (#205).
  • Confirmations are queued, so parallel signEvent calls are fine; the user answers them one at a time. Still, sign the steps of one action in sequence if their order matters.
  • With Web3Auth login, calls reject after 30 s without an answer from the signer. A call waiting on a confirmation has no timeout: it settles when the user approves or rejects, or logs out.
  • window.nostr.evolustr works with Web3Auth and with an extension or bunker. getWrapKey() resolves to a 32-byte key (base64url) for the page's origin; the user approves the app in the widget, and may have to create or use a passkey there first. These calls have no timeout; don't add a short one. Only https: pages (and http://localhost) get a key. Use @evolustr/client rather than calling them directly.

4. Events ​

For auth changes, prefer NostrBridge.onAuthChange or the nostr-bridge:auth event (section 3). The bridge also dispatches MessageEvents on window, kept for existing integrations and for SIGNER_ERROR. They have event.origin === "". Ignore anything else, because real postMessage traffic always has a non-empty origin.

event.dataWhen
{ type: "AUTH_STATE", loggedIn: true, pubkey }Sign-in, or session restored on load
{ type: "AUTH_STATE", loggedIn: false, pubkey: null }Sign-out, or restored session expired
{ type: "SIGNER_ERROR", code, message, hint }The signer iframe failed; see section 5

AUTH_STATE can fire more than once with the same value; make handlers idempotent. (onAuthChange and nostr-bridge:auth skip repeats.)

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