NAME
Net::Nostr::PaymentTargets - NIP-A3 payment target lists
SYNOPSIS
use Net::Nostr::PaymentTargets;
my $list = Net::Nostr::PaymentTargets->new(targets => [
['bitcoin', 'bc1qxq66e0t8d7ugdecwnmv58e90tpry23nc84pg9k'],
['nano', 'nano_1dctqbmqxfppo9pswbm6kg9d4s4mbraqn8i4m7ob9gnzz91aurmuho48jx3c'],
['unknowntype', 'l7tbta5b9xze6ckkfc99uohzxd009b0r'],
]);
my $event = $list->to_event(
pubkey => 'afc93622eb4d79c0fb75e56e0c14553f7214b0a466abeba14cb38968c6755e6a',
created_at => 1000,
);
my $parsed = Net::Nostr::PaymentTargets->from_event($event);
my $links = $parsed->uris;
DESCRIPTION
Builds and parses kind 10133 replaceable payment target lists. Order and duplicates are preserved, including unknown payment types. An empty list can replace a previously published list to remove its targets.
The library validates NIP-A3 structure and payment type syntax, but does not check network-specific address checksums, account existence, or ownership. Such checks depend on the target network and remain application policy. No payment is initiated and no URI is opened by this module.
METHODS
new
Strict constructor accepting named arguments as either a flat list or a single hash reference. Requires targets, an arrayref of pairs [$type, $address]. Types use lowercase RFC-8905 authority syntax: an ASCII letter followed by letters, digits, hyphens, or periods. Addresses must be non-empty scalar strings without control characters. Optional scalar content defaults to an empty string. Invalid structures and unknown arguments croak. Returned objects contain structurally valid targets; no deferred validation is required.
targets
Returns a defensive copy of the ordered target pairs. Read-only.
to_event
Builds a structurally validated Net::Nostr::Event of kind 10133. Requires pubkey; accepts other ordinary event fields such as created_at and sig. The object's kind, content, and tags cannot be overridden. The result is unsigned unless a signature was supplied; sign with the author's key before publication. Event field formats are checked by its constructor.
from_event
Parses a Net::Nostr::Event. Rechecks event field formats, requires kind 10133, and validates every payto tag exactly as the constructor validates target pairs. Other event tags and content are retained, so parsing then serializing does not discard metadata or reorder tags. It does not verify the event ID or signature; authenticate events before trusting their payment targets. The returned target object requires no later structural validation.
uris
Returns an ordered arrayref of link strings. Uses bitcoin: and ethereum: for those types and payto://type/address for every other type, including unknown ones. The address is encoded as a single UTF-8 URI component so embedded query or fragment characters remain part of the address. Type-specific URI options and payment amounts are outside this helper.