Add BitLogin to your site

No npm install required. Two files, one custom element.

  1. Copy the widget files next to your site

    Grab bitlogin.js and cryptoWorker.js (plus the shared chunk they both import) from a BitLogin release (or build @bitlogin/widget yourself) and drop them in a folder your site serves, e.g. /vendor/bitlogin/. All of them must live in the same directory — the main script loads the worker by a relative URL.

  2. Include the script and the element

    <script type="module" src="/vendor/bitlogin/bitlogin.js"></script>
    <bitlogin-auth
      vault-relays="wss://relay-one.example,wss://relay-two.example,wss://relay-three.example"
      discovery-relays="wss://discovery-one.example,wss://discovery-two.example">
    </bitlogin-auth>

    That's it — the element renders its own sign-in/create/recover UI inside a shadow root, so it won't collide with your site's CSS.

  3. React to sign-in and sign-out

    const bl = document.querySelector('bitlogin-auth');
    
    bl.addEventListener('bitlogin-login', (e) => {
      console.log('signed in as', e.detail.publicKey);
    });
    
    bl.addEventListener('bitlogin-logout', () => {
      console.log('signed out');
    });
  4. Sign events from anywhere on the page

    Once a user is signed in, BitLogin installs a window.nostr provider shaped like the de facto NIP-07 interface used by browser extensions (Alby, nos2x, …). Any existing Nostr web app code that already calls window.nostr works unmodified.

    const pubkey = await window.nostr.getPublicKey();
    
    const signed = await window.nostr.signEvent({
      kind: 1,
      content: 'hello from my app',
      tags: [],
      created_at: Math.floor(Date.now() / 1000),
    });
    
    // NIP-44 encrypted DMs
    const cipher = await window.nostr.nip44.encrypt(peerPubkeyHex, 'hi there');
    const plain  = await window.nostr.nip44.decrypt(peerPubkeyHex, cipher);
    Private keys never leave a dedicated Web Worker. The main thread — your page's JS — only ever sees public keys, signed events, and ciphertext. window.nostr calls are proxied into the worker and back.
  5. Choose your relays

    BitLogin ships with a small built-in bootstrap relay list, but you should point vault-relays and discovery-relays at relays you trust for your users. Use at least three vault relays for redundancy — capsule publication and reads use a quorum, so no single relay is a single point of failure.

  6. That's the whole integration

    No account database, no password-reset email, no server-side session. The account manager demo shows the full loop: create an account, sign a test event, rotate the password, and export a recovery file.