Authentication (NIP-42)

AUTH is optional on app lanes. You need it only to subscribe with #p to your own public key.

When you need it

ActionAUTH needed?
Publish any eventNo
Subscribe with tags or authorsNo
Subscribe with #p = your own pubkeyYes

How it works

  • On connect the relay sends ["AUTH", <challenge>]. Clients that do not use AUTH can ignore it.
  • To authenticate, reply with a signed kind 22242 event carrying the challenge tag and a relay tag with this relay's URL (NIP-42).
  • The event must be less than 10 minutes old, and the relay tag must point at the host you connected to.
  • Once accepted, events you publish on that connection are rate-limited under your authenticated key.
// Continues the Quick start; also import getPublicKey from "nostr-tools/pure".
// The relay sends ["AUTH", <challenge>] as soon as you connect.
// Answer it only if you need #p subscriptions (your own inbox).
await relay.auth(async (template) => finalizeEvent(template, sk));

relay.subscribe([{ kinds: [20078], "#p": [getPublicKey(sk)] }], {
  onevent(invite) {
    /* someone signalled you */
  },
});