Parrhesia.API.Auth (parrhesia v0.12.0)

Copy Markdown

Public helpers for event validation and NIP-98 HTTP authentication.

This module is intended for callers that need a programmatic API surface:

For transport-facing validation messages, see Parrhesia.Protocol.validate_event/1.

Summary

Functions

Computes the canonical Nostr event id for an event payload.

Validates a Nostr event and returns validator-friendly error atoms.

Validates a NIP-98 Authorization header using default options.

Validates a NIP-98 Authorization header and returns a shared auth context.

Functions

compute_event_id(event)

@spec compute_event_id(map()) :: String.t()

Computes the canonical Nostr event id for an event payload.

The event does not need to be persisted first. This is useful when building or signing events locally.

validate_event(event)

@spec validate_event(map()) :: :ok | {:error, term()}

Validates a Nostr event and returns validator-friendly error atoms.

This is the low-level validation entrypoint used by the API surface. Unlike Parrhesia.Protocol.validate_event/1, it preserves the raw validator reason so callers can branch on it directly.

validate_nip98(authorization, method, url)

@spec validate_nip98(String.t() | nil, String.t(), String.t()) ::
  {:ok, Parrhesia.API.Auth.Context.t()} | {:error, term()}

Validates a NIP-98 Authorization header using default options.

validate_nip98(authorization, method, url, opts)

@spec validate_nip98(String.t() | nil, String.t(), String.t(), keyword()) ::
  {:ok, Parrhesia.API.Auth.Context.t()} | {:error, term()}

Validates a NIP-98 Authorization header and returns a shared auth context.

The returned Parrhesia.API.Auth.Context includes:

Supported options are forwarded to Parrhesia.Auth.Nip98.validate_authorization_header/4, including :max_age_seconds and :replay_cache.