NostrElixir.Nip10 (nostr_elixir v0.1.0)
View SourceNIP-10: Text Notes and Threads (Replies, Mentions)
This module provides helpers for creating text note events (kind 1) and threaded replies according to NIP-10.
Implementation note:
Tag construction is implemented in pure Elixir for full NIP-10 spec compliance. This is because the Rust
nostr
crate's tag logic is either not spec-compliant or is in flux (as observed in recent versions, where"p"
tags are missing from replies). By building tags in Elixir, we ensure correct and predictable behavior, and make it easy to adapt to future spec changes.
See: https://github.com/nostr-protocol/nips/blob/master/10.md
Examples
iex> keys = NostrElixir.Keys.generate_keypair()
iex> event_json = NostrElixir.Nip10.create_text_note(keys, "Hello, Nostr!")
iex> NostrElixir.Event.verify(event_json)
true
iex> reply_json = NostrElixir.Nip10.create_reply(keys, "Replying!", event_json)
iex> NostrElixir.Event.verify(reply_json)
true
Summary
Functions
Build NIP-10 tags for a reply event, given the reply-to and (optional) root event.
Create and sign a text note reply event (kind 1) with proper NIP-10 tags.
Create and sign a text note event (kind 1).
Pretty-print a text note event JSON (shows content and tags).
Functions
Build NIP-10 tags for a reply event, given the reply-to and (optional) root event.
Create and sign a text note reply event (kind 1) with proper NIP-10 tags.
keys
: keypair map or JSONcontent
: reply textreply_to_event_json
: JSON of the event being replied toroot_event_json
: (optional) JSON of the thread root eventrelay_url
: (optional) relay URL for tags
Examples
iex> keys = NostrElixir.Keys.generate_keypair()
iex> root_json = NostrElixir.Nip10.create_text_note(keys, "Root post")
iex> reply_json = NostrElixir.Nip10.create_reply(keys, "Reply!", root_json)
iex> is_binary(reply_json)
true
Create and sign a text note event (kind 1).
Examples
iex> keys = NostrElixir.Keys.generate_keypair()
iex> event_json = NostrElixir.Nip10.create_text_note(keys, "Hello!")
iex> is_binary(event_json)
true
Pretty-print a text note event JSON (shows content and tags).