UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

111 lines (110 loc) 2.88 kB
/** * A strategy for posting messages to Nostr. */ export class NostrStrategy { /** * Creates a new instance. * @param {NostrOptions} options Options for the instance. * @throws {Error} When options are missing or invalid. */ constructor(options: NostrOptions); /** * The ID of the strategy. * @type {string} * @readonly */ readonly id: string; /** * The display name of the strategy. * @type {string} * @readonly */ readonly name: string; /** * Maximum length of a Nostr message in characters. * Most Nostr clients use similar limits to Twitter. * @type {number} * @const */ MAX_MESSAGE_LENGTH: number; /** * Calculates the length of a message according to Nostr's counting rules. * @param {string} message The message to calculate the length of. * @returns {number} The length of the message. */ calculateMessageLength(message: string): number; /** * Posts a message to Nostr relays. * @param {string} message The message to post. * @param {PostOptions} [postOptions] Additional options for the post. * @returns {Promise<NostrEventResponse>} A promise that resolves with the event response. * @throws {Error} When the message fails to post to all relays. */ post(message: string, postOptions?: PostOptions): Promise<NostrEventResponse>; /** * Gets a URL from the response (Nostr doesn't have a standard URL format). * @param {NostrEventResponse} response The response from posting. * @returns {string} A note URL (using the first successful relay). */ getUrlFromResponse(response: NostrEventResponse): string; #private; } export type PostOptions = import("../types.js").PostOptions; export type NostrOptions = { /** * The private key for signing events (hex or bech32). */ privateKey: string; /** * Array of relay URLs to post to. */ relays: string[]; }; export type NostrEvent = { /** * The event ID (32-byte hex). */ id: string; /** * The public key of the event creator (32-byte hex). */ pubkey: string; /** * Unix timestamp in seconds. */ created_at: number; /** * The event kind (1 for short text note). */ kind: number; /** * Array of tags. */ tags: string[][]; /** * The event content. */ content: string; /** * The signature (64-byte hex). */ sig: string; }; export type NostrEventResponse = { /** * The event ID. */ id: string; /** * Whether the event was published successfully. */ success: boolean; /** * Array of relays that accepted the event. */ relays: string[]; /** * Array of relay errors. */ errors: string[]; };