NostrElixir.Nip09 (nostr_elixir v0.1.0)

View Source

NIP-09: Event Deletion

This module provides helpers for creating event deletion events (kind 5) according to NIP-09.

Implementation note:

Tag construction is implemented in pure Elixir for full NIP-09 spec compliance. This ensures correct and predictable behavior for event deletion tags.

See: https://github.com/nostr-protocol/nips/blob/master/09.md

Examples

iex> keys = NostrElixir.Keys.generate_keypair()
iex> event_ids = ["event_id_1", "event_id_2"]
iex> reason = "Content was inappropriate"
iex> event_json = NostrElixir.Nip09.create_deletion_event(keys, event_ids, reason)
iex> NostrElixir.Event.verify(event_json)
true

Summary

Functions

Build NIP-09 deletion tags from a list of event IDs.

Create and sign an event deletion event (kind 5).

Extract deletion information from an event deletion event JSON. Returns a %Deletion{} struct with the extracted data.

Pretty-print an event deletion event (shows event IDs and reason).

Functions

build_deletion_tags(event_ids)

Build NIP-09 deletion tags from a list of event IDs.

create_deletion_event(keys, event_ids, reason \\ nil)

Create and sign an event deletion event (kind 5).

Parameters

  • keys - keypair map or JSON
  • event_ids - list of event IDs to delete
  • reason - (optional) reason for deletion

Examples

iex> keys = NostrElixir.Keys.generate_keypair()
iex> event_ids = ["abc123", "def456"]
iex> event_json = NostrElixir.Nip09.create_deletion_event(keys, event_ids)
iex> is_binary(event_json)
true

extract_deletion(event_json)

Extract deletion information from an event deletion event JSON. Returns a %Deletion{} struct with the extracted data.

Examples

iex> event_json = "{"kind": 5, "content": "Inappropriate content", "tags": [["e", "event_id_1"], ["e", "event_id_2"]]}"
iex> deletion = NostrElixir.Nip09.extract_deletion(event_json)
iex> deletion.event_ids
["event_id_1", "event_id_2"]
iex> deletion.reason
"Inappropriate content"

pretty_print(event_json)

Pretty-print an event deletion event (shows event IDs and reason).