Skip to content

Nostr Protocol

Introduction

Nostr (Notes and Other Stuff Transmitted by Relays) is a simple, open protocol that enables a truly censorship-resistant and globally distributed social media platform. The protocol is based on cryptographic keypairs, simple event objects, and a network of relay servers that store and forward these events.

Protocol Components

The Nostr ecosystem consists of these main components:

  1. Clients: Applications that allow users to create and consume content
  2. Relays: Servers that store and distribute events
  3. Events: The basic data structure used to carry all information
  4. Filters: Query parameters used to request specific events from relays

Core Concepts

Cryptographic Identity

In Nostr, users are identified by a keypair:

  • Public key: Acts as the user's identity and is shared openly
  • Private key: Used to sign events and must be kept secure

There is no central authority or registration process - anyone can generate a keypair and start participating.

Protocol Flow

  1. Event Creation: Users create signed events using their private key
  2. Event Publication: Clients send events to one or more relays
  3. Event Storage: Relays validate and store valid events
  4. Event Discovery: Other users query relays using filters to find events
  5. Event Consumption: Clients process and display events to users

WebSocket Communication

Clients and relays communicate over WebSocket connections using a simple message format:

Client to Relay:

  • ["EVENT", <event-json>] - Publish an event
  • ["REQ", <subscription-id>, <filter1>, <filter2>, ...] - Request/subscribe to events
  • ["CLOSE", <subscription-id>] - Close a subscription

Relay to Client:

  • ["EVENT", <subscription-id>, <event-json>] - Return an event matching a subscription
  • ["OK", <event-id>, <true|false>, <message>] - Acknowledge an event submission
  • ["EOSE", <subscription-id>] - Signal the end of stored events
  • ["CLOSED", <subscription-id>, <message>] - Notify that a subscription was closed
  • ["NOTICE", <message>] - Send a human-readable message

Key Protocol Elements

Events

Events are the fundamental data structure in Nostr. All information is transmitted as events, including:

  • User profiles
  • Text notes
  • Mentions
  • Reactions
  • Follows
  • Reposts
  • Direct messages
  • Group chats
  • And much more...

Each event has a standard structure including:

  • id: Unique identifier (SHA-256 hash)
  • pubkey: Creator's public key
  • created_at: Timestamp
  • kind: Type of event
  • tags: References to other events, users, etc.
  • content: Main payload
  • sig: Cryptographic signature

Learn more about Nostr events →

Filters

Filters allow clients to request specific events from relays based on criteria such as:

  • Event IDs
  • Authors (pubkeys)
  • Event kinds
  • Tag values
  • Time ranges
  • Limits

Filters are combined into subscriptions, enabling real-time updates as new matching events are received by relays.

Learn more about Nostr filters →

NIPs (Nostr Implementation Possibilities)

The Nostr protocol is continuously evolving through NIPs - documents that specify new features, conventions, and improvements. The fundamental protocol is defined in NIP-01, with many additional NIPs extending the core functionality.

Some key NIPs:

  • NIP-01: Basic protocol flow
  • NIP-02: Contact lists and petnames
  • NIP-05: Mapping Nostr keys to DNS-based internet identifiers
  • NIP-10: Conventions for event relationship tags
  • NIP-19: bech32-encoded entities
  • NIP-65: Relay lists

Design Principles

Nostr is built on principles of:

  • Simplicity: The core protocol is intentionally minimalistic
  • Decentralization: No central servers or authorities
  • User Control: Users own their identity and choose which relays to use
  • Censorship Resistance: No single point of failure or control
  • Extensibility: The protocol can be extended through NIPs

References