NostrElixir.Nip23 (nostr_elixir v0.1.0)
View SourceNIP-23: Long-form Content
This module provides helpers for creating long-form content events (kind 30023) according to NIP-23.
Implementation note:
Tag construction is implemented in pure Elixir for full NIP-23 spec compliance. This ensures correct and predictable behavior for all required and optional tags, and makes it easy to adapt to future spec changes.
See: https://github.com/nostr-protocol/nips/blob/master/23.md
Examples
iex> keys = NostrElixir.Keys.generate_keypair()
iex> opts = %{
...> title: "My Article",
...> summary: "A brief summary",
...> image: "https://example.com/image.jpg",
...> published_at: 1234567890
...> }
iex> content = "# My Article\n\nThis is the full article content in Markdown..."
iex> event_json = NostrElixir.Nip23.create_long_form(keys, content, opts)
iex> NostrElixir.Event.verify(event_json)
true
Summary
Functions
Build NIP-23 tags from options map.
Create and sign a long-form content event (kind 30023).
Extract metadata from a long-form content event JSON. Returns a %LongForm{} struct with the extracted data.
Pretty-print a long-form content event (shows title, summary, and content preview).
Functions
Build NIP-23 tags from options map.
Create and sign a long-form content event (kind 30023).
Options
:title
- (required) The article title:summary
- (optional) A brief summary of the article:image
- (optional) URL to a cover image:published_at
- (optional) Unix timestamp when the article was published:hashtags
- (optional) List of hashtags (without the # symbol):canonical
- (optional) Canonical URL for the article:lang
- (optional) Language code (e.g., "en", "es")
Examples
iex> keys = NostrElixir.Keys.generate_keypair()
iex> opts = %{title: "My Article"}
iex> content = "# My Article\n\nContent here..."
iex> event_json = NostrElixir.Nip23.create_long_form(keys, content, opts)
iex> is_binary(event_json)
true
Extract metadata from a long-form content event JSON. Returns a %LongForm{} struct with the extracted data.
Examples
iex> event_json = "{"kind": 30023, "content": "# Title\nContent", "tags": [["title", "Title"]]}"
iex> metadata = NostrElixir.Nip23.extract_metadata(event_json)
iex> metadata.title
"Title"
Pretty-print a long-form content event (shows title, summary, and content preview).