import { EventTemplate, NostrEvent, NostrFilter, RelayEventResult, Subscription } from '@napplet/core'; /** * Napplet NAP relay shim entrypoint. * * @module */ /** * Open a live relay subscription through the shell's relay pool. * * Sends a `relay.subscribe` envelope message via postMessage to the parent shell. * The shell queries its local cache and connected relays, streaming * matching events back via `relay.event` messages. * * @param filters One or more NIP-01 subscription filters * @param onEvent Called for each matching event result delivered by the shell * @param onEose Called when the shell signals end of stored events (EOSE) * @param options Optional: `{ relay, group }` for scoped relay subscriptions * @returns A Subscription handle with a `close()` method to tear down the subscription * * @example * ```ts * const sub = subscribe( * { kinds: [1], limit: 20 }, * (event) => console.log('Got event:', event), * () => console.log('EOSE'), * ); * // Later: sub.close(); * ``` */ declare function subscribe(filters: NostrFilter | NostrFilter[], onEvent: (result: RelayEventResult) => void, onEose: () => void, options?: { relay?: string; group?: string; }): Subscription; /** * Publish a Nostr event through the shell. * * The event template is sent to the shell via a `relay.publish` envelope * message. The shell signs the event and broadcasts it to relays. * Napplets never have direct access to signing keys. * * @param template Unsigned event template (kind, content, tags, created_at) * @param options Optional: `{ relay: true }` to publish via the scoped relay instead of the shared pool * @returns The signed NostrEvent after successful publication * * @example * ```ts * const signed = await publish({ * kind: 1, * content: 'Hello Nostr!', * tags: [], * created_at: Math.floor(Date.now() / 1000), * }); * ``` */ declare function publish(template: EventTemplate, _options?: { relay?: boolean; }): Promise; /** * Publish an encrypted Nostr event through the shell. * * The shell encrypts the event content using the specified scheme (NIP-44 or NIP-04), * signs the event, and broadcasts it. Napplets never have direct access to encryption * keys -- this ensures the shell can inspect content before encryption. * * @param template Unsigned event template (kind, content, tags, created_at) * @param recipient Hex-encoded recipient public key * @param encryption Encryption scheme: 'nip44' (default) or 'nip04' * @returns The signed encrypted NostrEvent after successful publication * * @example * ```ts * const signed = await publishEncrypted( * { kind: 4, content: 'secret', tags: [], created_at: now }, * 'recipientPubkey...', * 'nip44', * ); * ``` */ declare function publishEncrypted(template: EventTemplate, recipient: string, encryption?: 'nip44' | 'nip04'): Promise; /** * One-shot query: send a relay.query message, await relay.query.result, resolve. * * Uses the dedicated `relay.query` envelope message for a cleaner protocol * instead of subscribe + collect + close. * * @param filters NIP-01 subscription filters (single or array) * @returns Promise resolving to an array of matching event results * * @example * ```ts * const profiles = await query({ kinds: [0], authors: [pubkey] }); * ``` */ declare function query(filters: NostrFilter | NostrFilter[]): Promise; /** * Install the relay shim on window.napplet.relay. * * Called by @napplet/shim during initialization. * Provides subscribe, publish, and query methods on the relay namespace. * * @returns cleanup function */ declare function installRelayShim(): () => void; export { installRelayShim, publish, publishEncrypted, query, subscribe };