Nostr.Event.RelayList (Nostr Lib v0.2.1) (event) (nip51) (nip65)

View Source

Relay List Metadata (Kind 10002)

Advertises relays where the user publishes to (write) and where they expect to receive mentions (read). This helps clients discover where to find a user's events and where to send tagged events.

Relay Markers

  • No marker: Relay is used for both read and write
  • read: Relay is used only for receiving mentions
  • write: Relay is used only for publishing

Defined in NIP 65 https://github.com/nostr-protocol/nips/blob/master/65.md

Also referenced in NIP 51 https://github.com/nostr-protocol/nips/blob/master/51.md

Summary

Functions

Creates a new relay list metadata event (kind 10002).

Parses a kind 10002 event into a RelayList struct.

Returns relays marked for reading (includes :read and :both).

Returns relays marked for writing (includes :write and :both).

Types

relay_entry()

@type relay_entry() :: %{url: URI.t(), marker: :read | :write | :both}

t()

@type t() :: %Nostr.Event.RelayList{event: Nostr.Event.t(), relays: [relay_entry()]}

Functions

create(relays, opts \\ [])

@spec create([binary() | tuple() | map()], Keyword.t()) :: t()

Creates a new relay list metadata event (kind 10002).

Arguments

  • relays - List of relay entries (see formats below)
  • opts - Optional event arguments (pubkey, created_at)

Relay Entry Formats

Relays can be specified as:

  • "wss://relay.com" - URL string (both read and write)
  • {"wss://relay.com", :read} - Tuple with marker
  • {"wss://relay.com", :write} - Tuple with marker
  • {"wss://relay.com", :both} - Tuple with marker (same as no marker)
  • %{url: "wss://...", marker: :read} - Map format

Example

iex> RelayList.create([
...>   "wss://relay1.com",
...>   {"wss://relay2.com", :write},
...>   {"wss://relay3.com", :read}
...> ])

parse(event)

@spec parse(Nostr.Event.t()) :: t()

Parses a kind 10002 event into a RelayList struct.

read_relays(relay_list)

@spec read_relays(t()) :: [URI.t()]

Returns relays marked for reading (includes :read and :both).

write_relays(relay_list)

@spec write_relays(t()) :: [URI.t()]

Returns relays marked for writing (includes :write and :both).