Nostr.Event.Parser (Nostr Lib v0.2.1)

View Source

Internal module for parsing raw event data into Nostr.Event structs.

This module handles two types of parsing:

Event Kind Routing

Specific event kinds are routed to their dedicated modules:

Event kind ranges (NIP-16):

Unknown kinds fall back to Nostr.Event.Unknown.

Summary

Functions

Parses a JSON string or map into a Nostr.Event struct.

Converts a generic Nostr.Event to a type-specific struct based on event kind.

Functions

parse(event)

@spec parse(String.t() | map()) :: Nostr.Event.t() | {:error, String.t(), term()}

Parses a JSON string or map into a Nostr.Event struct.

Converts Unix timestamps to DateTime and parses tags into Nostr.Tag structs.

parse_specific(event)

@spec parse_specific(Nostr.Event.t()) :: struct()

Converts a generic Nostr.Event to a type-specific struct based on event kind.

Returns a specialized struct (e.g., Nostr.Event.Note, Nostr.Event.Metadata) that may contain parsed content and additional type-specific fields.