NAME

Net::Nostr::AppData - NIP-78 Arbitrary Custom App Data

SYNOPSIS

use Net::Nostr::AppData;

# Store app-specific data
my $event = Net::Nostr::AppData->to_event(
    pubkey  => $pubkey,
    d_tag   => 'com.example.myapp/settings',
    content => '{"theme":"dark","fontSize":14}',
);

# Parse app data from an event
my $ad = Net::Nostr::AppData->from_event($event);
say $ad->d_tag;    # com.example.myapp/settings
say $ad->content;  # {"theme":"dark","fontSize":14}

# Validate
Net::Nostr::AppData->validate($event);

DESCRIPTION

Implements NIP-78 (Arbitrary Custom App Data). Provides remoteStorage-like capabilities for custom applications that do not care about interoperability.

Kind 30078 is an addressable event. The d tag contains a reference to the app name and context (or any other arbitrary string). The content and other tags can be anything or in any format.

Use cases include:

  • User personal settings on Nostr clients

  • Dynamic parameters propagated from client developers to users

  • Private data for apps that use Nostr relays as a personal database

CONSTRUCTOR

new

my $ad = Net::Nostr::AppData->new(
    d_tag   => 'myapp-settings',
    content => '{"theme":"dark"}',
);

Creates a new Net::Nostr::AppData object. All fields are optional. extra_tags defaults to []. Croaks on unknown arguments. Typically returned by "from_event".

CLASS METHODS

to_event

my $event = Net::Nostr::AppData->to_event(
    pubkey     => $hex_pubkey,
    d_tag      => 'com.example.myapp/settings',
    content    => '{"theme":"dark","fontSize":14}',
    extra_tags => [['version', '2']],
    created_at => time(),
);

Creates a kind 30078 addressable Net::Nostr::Event. d_tag is required and becomes the d tag. content defaults to empty string. extra_tags, if provided, are appended after the d tag. Any remaining arguments are passed through to "new" in Net::Nostr::Event.

from_event

my $ad = Net::Nostr::AppData->from_event($event);

Parses a kind 30078 event into a Net::Nostr::AppData object. Returns undef if the event kind is not 30078.

my $ad = Net::Nostr::AppData->from_event($event);
say $ad->d_tag;
say $ad->content;

validate

Net::Nostr::AppData->validate($event);

Validates a NIP-78 event. Checks that the kind is 30078 and a d tag is present. Croaks if the kind is wrong or the d tag is missing. Returns 1 on success.

eval { Net::Nostr::AppData->validate($event) };
warn "Invalid: $@" if $@;

ACCESSORS

d_tag

The application identifier string from the d tag. Can be any arbitrary string referencing the app name and context.

content

The event content. Can be any format (JSON, plain text, etc.).

extra_tags

Arrayref of additional tags beyond the d tag. Can be anything in any format.

SEE ALSO

NIP-78, Net::Nostr, Net::Nostr::Event