Nostr.Event.Label (Nostr Lib v0.2.1) (event) (nip32)

View Source

Label (Kind 1985)

Attach labels to events, pubkeys, relays, or topics for distributed moderation, content classification, license assignment, and other labeling use cases.

Label Structure

Labels use two tag types:

  • L tags define label namespaces (e.g., "license", "com.example.ontology")
  • l tags define actual labels with a namespace mark

Target Types

Labels can target:

  • Events (e tags)
  • Pubkeys (p tags)
  • Addressable events (a tags)
  • Relays (r tags)
  • Topics (t tags)

Self-Labeling

L and l tags can be added to non-1985 events for self-reporting. In that case, the labels refer to the event itself.

Defined in NIP 32 https://github.com/nostr-protocol/nips/blob/master/32.md

Summary

Functions

Creates a label event (kind 1985).

Parses a kind 1985 event into a Label struct.

Types

t()

@type t() :: %Nostr.Event.Label{
  addresses: [{binary(), binary() | nil}],
  event: Nostr.Event.t(),
  events: [{binary(), binary() | nil}],
  labels: [{binary(), binary()}],
  namespaces: [binary()],
  pubkeys: [{binary(), binary() | nil}],
  relays: [binary()],
  topics: [binary()]
}

Functions

create(labels, targets, opts \\ [])

@spec create([{binary(), binary()} | binary()], map(), Keyword.t()) :: t()

Creates a label event (kind 1985).

Arguments

  • labels - List of labels. Each label can be:
    • {label, namespace} tuple
    • Just a string (uses "ugc" as default namespace)
  • targets - Map with target keys:
    • :events - List of event IDs or {event_id, relay_hint} tuples
    • :pubkeys - List of pubkeys or {pubkey, relay_hint} tuples
    • :addresses - List of addresses or {address, relay_hint} tuples
    • :relays - List of relay URLs
    • :topics - List of topics/hashtags
  • opts - Optional event arguments

Options

  • :content - Explanation for the labeling
  • :pubkey - Event author pubkey
  • :created_at - Event timestamp

Examples

# Label an event with a license
Label.create(
  [{"MIT", "license"}],
  %{events: ["abc123..."]}
)

# Label pubkeys with a topic association
Label.create(
  [{"permies", "#t"}],
  %{pubkeys: [{"pubkey1", "wss://relay.example.com"}, "pubkey2"]}
)

# Moderation label with explanation
Label.create(
  [{"approve", "nip28.moderation"}],
  %{events: ["event_id"]},
  content: "Reviewed and approved for channel"
)

parse(event)

@spec parse(Nostr.Event.t()) :: t()

Parses a kind 1985 event into a Label struct.