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
| Action | AUTH needed? |
|---|---|
| Publish any event | No |
Subscribe with tags or authors | No |
Subscribe with #p = your own pubkey | Yes |
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
22242event carrying thechallengetag and arelaytag with this relay's URL (NIP-42). - The event must be less than 10 minutes old, and the
relaytag 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 */
},
});