NostrElixir.Nip65 (nostr_elixir v0.3.0)
View SourceNIP-65: Relay List Metadata
This module provides functions to create and extract relay list metadata events as specified in NIP-65.
Examples
keys = NostrElixir.Keys.generate_keypair()
relays = [
{"wss://relay1.example.com", "read"},
{"wss://relay2.example.com", "write"},
{"wss://relay3.example.com", nil}
]
event_json = NostrElixir.Nip65.create_relay_list_event(relays, keys.secret_key)
NostrElixir.Nip65.extract_relay_list(event_json)The relay list is a list of {relay_url, metadata} tuples, where metadata is either "read", "write", or nil.
Events are signed with the author's secret key (hex, bech32, or a keys map).
Summary
Functions
Create a signed relay list event from a list of {relay_url, metadata} tuples.
Extract the relay list from an event JSON string.
Pretty-print a relay list (list of tuples or structs).
Convert a %Relay{} struct to a {url, metadata} tuple.
Convert a {url, metadata} tuple to a %Relay{} struct.
Validate relay metadata (must be "read", "write", or nil). Returns true if valid, false otherwise.
Validate a relay URL (must start with ws:// or wss://). Returns true if valid, false otherwise.
Functions
Create a signed relay list event from a list of {relay_url, metadata} tuples.
relays: List of{relay_url, metadata}tuples.metadatacan be "read", "write", ornil.secret_key: Author's secret key (hex or bech32), or a keys map with:secret_key.
Returns the event as a JSON string.
Extract the relay list from an event JSON string.
Returns a list of {relay_url, metadata} tuples.
@spec pretty_print([NostrElixir.Nip65.Relay.t()] | [{String.t(), String.t() | nil}]) :: String.t()
Pretty-print a relay list (list of tuples or structs).
@spec struct_to_tuple(NostrElixir.Nip65.Relay.t()) :: {String.t(), String.t() | nil}
Convert a %Relay{} struct to a {url, metadata} tuple.
@spec tuple_to_struct({String.t(), String.t() | nil}) :: NostrElixir.Nip65.Relay.t()
Convert a {url, metadata} tuple to a %Relay{} struct.
Validate relay metadata (must be "read", "write", or nil). Returns true if valid, false otherwise.
Validate a relay URL (must start with ws:// or wss://). Returns true if valid, false otherwise.