NostrElixir.Nip02 (nostr_elixir v0.3.0)
View SourceNIP-02: Follow List
Functions to create and extract follow list events (kind 3).
Examples
keys = NostrElixir.Keys.generate_keypair()
follows = [
{followed_pubkey, "wss://relay.example.com", "Alice"},
{other_pubkey, nil, nil}
]
event_json = NostrElixir.Nip02.create_follow_list_event(follows, keys.secret_key)
NostrElixir.Nip02.extract_follows(event_json)The term 'contact' is used in some libraries, but the protocol and this module use 'follow' to match NIP-02.
Summary
Functions
Create a signed follow list event from a list of {pubkey, relay_url, alias} tuples.
Extract the follow list from an event JSON string.
Returns a list of {pubkey, relay_url, alias} tuples.
Pretty-print a follow list (list of tuples or structs).
Convert a %Follow{} struct to a {pubkey, relay_url, alias} tuple.
Convert a {pubkey, relay_url, alias} tuple to a %Follow{} struct.
Validate a public key (hex or bech32, 64+ chars).
Validate a relay URL (must start with ws:// or wss://).
Functions
@spec create_follow_list_event( [{String.t(), String.t() | nil, String.t() | nil}], String.t() | map() ) :: String.t()
Create a signed follow list event from a list of {pubkey, relay_url, alias} tuples.
The second argument is the author's secret key (hex or bech32) or a keys map
with a :secret_key field. The event pubkey is derived from that key.
Returns the event as a JSON string.
Extract the follow list from an event JSON string.
Returns a list of {pubkey, relay_url, alias} tuples.
@spec pretty_print( [NostrElixir.Nip02.Follow.t()] | [{String.t(), String.t() | nil, String.t() | nil}] ) :: String.t()
Pretty-print a follow list (list of tuples or structs).
@spec struct_to_tuple(NostrElixir.Nip02.Follow.t()) :: {String.t(), String.t() | nil, String.t() | nil}
Convert a %Follow{} struct to a {pubkey, relay_url, alias} tuple.
@spec tuple_to_struct({String.t(), String.t() | nil, String.t() | nil}) :: NostrElixir.Nip02.Follow.t()
Convert a {pubkey, relay_url, alias} tuple to a %Follow{} struct.
Validate a public key (hex or bech32, 64+ chars).
Validate a relay URL (must start with ws:// or wss://).