NostrElixir.Nip02 (nostr_elixir v0.1.0)
View SourceNIP-02: Follow List
Functions to create and extract follow list events (kind 3).
Examples
iex> follows = [
...> {"npub1...", "wss://relay.example.com", "Alice"},
...> {"npub2...", nil, nil}
...> ]
iex> pubkey = "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
iex> event_json = NostrElixir.Nip02.create_follow_list_event(follows, pubkey)
iex> is_binary(event_json)
true
iex> NostrElixir.Nip02.extract_follows(event_json)
[
{"npub1...", "wss://relay.example.com", "Alice"},
{"npub2...", nil, nil}
]
The term 'contact' is used in some libraries, but the protocol and this module use 'follow' to match NIP-02.
Summary
Functions
Create a follow list event from a list of {pubkey, relay_url, alias}
tuples and a public 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.
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() ) :: String.t()
Create a follow list event from a list of {pubkey, relay_url, alias}
tuples and a public 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://).