NAME

Net::Blossom::AuthToken - BUD-11 Blossom authorization token builder

SYNOPSIS

use Net::Blossom::AuthToken;

my $token = Net::Blossom::AuthToken->new(
    key        => $key,
    action     => 'upload',
    content    => 'Upload Blob',
    expiration => time + 300,
    hashes     => [$sha256],
);

my $header = $token->authorization_header;

DESCRIPTION

Net::Blossom::AuthToken builds BUD-11 Nostr authorization events and encodes them as Blossom Authorization header values.

The key argument must be an object that provides pubkey_hex and sign_event. pubkey_hex must return the Nostr public key as lowercase 64-character hex. sign_event receives the Net::Nostr::Event object, signs it, and must leave the event with a valid signature.

CONSTRUCTOR

new

my $token = Net::Blossom::AuthToken->new(%args);

Required arguments:

  • key

    A signing object that provides pubkey_hex and sign_event.

  • action

    One of get, upload, list, delete, or media.

  • content

    The event content string.

  • expiration

    Unix timestamp. It must be a non-negative integer and must be in the future.

Optional arguments:

  • server

    A lowercase DNS-style domain name for one server scope. This is a domain only, not a URL. Empty labels and leading or trailing label hyphens are rejected.

  • servers

    Array reference of lowercase DNS-style domain names for server scope.

  • hashes

    Array reference of lowercase 64-character SHA-256 hashes. upload, delete, and media authorizations require at least one hash.

  • created_at

    Unix timestamp for the Nostr event. Defaults to the previous Unix second.

Unknown arguments or invalid values croak.

ACCESSORS

key

Returns the signing object passed to new.

action

Returns the BUD-11 action.

content

Returns the event content.

expiration

Returns the expiration timestamp.

server

Returns the original server argument, when one was passed.

servers

Returns the normalized array reference of server domain names.

hashes

Returns the array reference of hash scopes.

created_at

Returns the event creation timestamp.

METHODS

to_event

my $event = $token->to_event;

Builds, signs, and returns a Net::Nostr::Event for kind 24242.

authorization_header

my $header = $token->authorization_header;

Returns the Nostr ... Authorization header value. The payload is canonical JSON encoded as unpadded base64url.

SEE ALSO

Net::Blossom::Client, Net::Nostr::Event