Nostr.NIP29 (Nostr Lib v0.2.1) (nip29)

View Source

NIP-29: Relay-based Groups helpers.

This module provides relay-agnostic kind classification and tag extraction helpers for group events.

Summary

Functions

Extracts group id using NIP-29 kind-specific tag source (h or d).

Extracts group id from the first d tag on an event.

Extracts group id from the first h tag on an event.

Returns true for kind 9021 join requests.

Returns true for kind 9022 leave requests.

Returns true when kind belongs to NIP-29 management path.

Returns true for NIP-29 relay-generated metadata kinds (39000-39003).

Returns true for NIP-29 moderation kinds (9000-9020).

Collects moderation target values from p, e, a, and code tags.

Collects all previous references from previous tags preserving order.

Returns true when event kind requires a d tag (39000-39003).

Returns true when event kind requires an h group tag by NIP-29 semantics.

Validates NIP-29 group id format: lowercase alnum, -, _.

Validates required d tag and optional group-id charset check.

Validates required h tag and optional group-id charset check.

Validates required NIP-29 structural tags for an event kind.

Types

moderation_target_key()

@type moderation_target_key() :: :p | :e | :a | :code

validation_error()

@type validation_error() :: :missing_h_tag | :missing_d_tag | :invalid_group_id

Functions

group_id(event)

@spec group_id(Nostr.Event.t()) :: binary() | nil

Extracts group id using NIP-29 kind-specific tag source (h or d).

group_id_from_d(event)

@spec group_id_from_d(Nostr.Event.t()) :: binary() | nil

Extracts group id from the first d tag on an event.

group_id_from_h(event)

@spec group_id_from_h(Nostr.Event.t()) :: binary() | nil

Extracts group id from the first h tag on an event.

join_request_kind?(kind)

@spec join_request_kind?(integer()) :: boolean()

Returns true for kind 9021 join requests.

leave_request_kind?(kind)

@spec leave_request_kind?(integer()) :: boolean()

Returns true for kind 9022 leave requests.

management_kind?(kind)

@spec management_kind?(integer()) :: boolean()

Returns true when kind belongs to NIP-29 management path.

metadata_kind?(kind)

@spec metadata_kind?(integer()) :: boolean()

Returns true for NIP-29 relay-generated metadata kinds (39000-39003).

moderation_kind?(kind)

@spec moderation_kind?(integer()) :: boolean()

Returns true for NIP-29 moderation kinds (9000-9020).

moderation_targets(event)

@spec moderation_targets(Nostr.Event.t()) :: %{
  required(moderation_target_key()) => [binary()]
}

Collects moderation target values from p, e, a, and code tags.

previous_refs(event)

@spec previous_refs(Nostr.Event.t()) :: [binary()]

Collects all previous references from previous tags preserving order.

requires_d_tag?(kind)

@spec requires_d_tag?(integer()) :: boolean()

Returns true when event kind requires a d tag (39000-39003).

requires_h_tag?(kind)

@spec requires_h_tag?(integer()) :: boolean()

Returns true when event kind requires an h group tag by NIP-29 semantics.

valid_group_id?(group_id)

@spec valid_group_id?(binary()) :: boolean()

Validates NIP-29 group id format: lowercase alnum, -, _.

validate_d_tag(event, opts \\ [])

@spec validate_d_tag(
  Nostr.Event.t(),
  keyword()
) :: {:ok, binary()} | {:error, validation_error()}

Validates required d tag and optional group-id charset check.

validate_h_tag(event, opts \\ [])

@spec validate_h_tag(
  Nostr.Event.t(),
  keyword()
) :: {:ok, binary()} | {:error, validation_error()}

Validates required h tag and optional group-id charset check.

validate_required_group_tag(event, opts \\ [])

@spec validate_required_group_tag(
  Nostr.Event.t(),
  keyword()
) :: {:ok, nil | binary()} | {:error, validation_error()}

Validates required NIP-29 structural tags for an event kind.