Parrhesia.Protocol
(parrhesia v0.12.0)
Copy Markdown
Nostr protocol message decode/encode helpers.
This module is transport-oriented: it turns websocket payloads into structured tuples and back again.
For programmatic API calls inside the application, prefer the Parrhesia.API.* modules.
In particular:
validate_event/1returns user-facing error stringsParrhesia.API.Auth.validate_event/1returns machine-friendly validator atoms
Summary
Functions
Decodes a client websocket payload into a structured protocol tuple.
Converts a decode error into the relay notice string that should be sent to a client.
Encodes a relay message tuple into the JSON frame sent to clients.
Validates an event and returns relay-facing error strings.
Types
@type decode_error() ::
:invalid_json
| :invalid_message
| :invalid_event
| :invalid_subscription_id
| :invalid_filters
| :invalid_auth
| :invalid_count
| :invalid_negentropy
@type event() :: map()
@type filter() :: map()
@type relay_message() :: {:notice, String.t()} | {:ok, String.t(), boolean(), String.t()} | {:closed, String.t(), String.t()} | {:eose, String.t()} | {:event, String.t(), event()} | {:auth, String.t()} | {:count, String.t(), map()} | {:neg_msg, String.t(), String.t()} | {:neg_err, String.t(), String.t()}
Functions
@spec decode_client(binary()) :: {:ok, client_message()} | {:error, decode_error()}
Decodes a client websocket payload into a structured protocol tuple.
@spec decode_error_notice(decode_error()) :: String.t()
Converts a decode error into the relay notice string that should be sent to a client.
@spec encode_relay(relay_message()) :: binary()
Encodes a relay message tuple into the JSON frame sent to clients.
Validates an event and returns relay-facing error strings.