import * as nostr_tools from 'nostr-tools'; import { SimplePool } from 'nostr-tools'; import { NostrSigner } from '@nostr-wot/signers'; /** * NIP-57 zap request (kind 9734). * * Flow: * 1. Caller looks up the recipient's lud16 (lightning address) and * fetches their LNURL-pay endpoint. * 2. The endpoint advertises `allowsNostr: true` and a `nostrPubkey`. * 3. Caller builds a zap request event signed by the zapper, encodes * it as a `nostr` query parameter on the LNURL callback, gets back * a bolt11 invoice. * 4. Caller pays the invoice (via NWC, WebLN, or a wallet). * 5. The recipient receives a kind 9735 zap receipt published by the * LNURL provider, containing the original zap request as a tag. */ interface ZapRequestArgs { /** Recipient's hex pubkey. */ recipientPubkey: string; /** Amount in millisatoshis. */ amountMsats: number; /** Optional comment (zap note). */ comment?: string; /** Relays where the recipient should look for the zap receipt. */ relays: string[]; /** Optional event id being zapped (zap a specific note). */ eventId?: string; /** Optional addr/kind tags for replaceable events. */ addrTag?: string; } /** * Build + sign a NIP-57 zap request event. Returns the signed event, * which the caller appends to the LNURL callback as `nostr=...`. * * Validates two NIP-57 requirements that the spec calls out explicitly: * - `relays` must be non-empty (the LNURL provider needs at least one * relay to publish the kind 9735 receipt to). * - `amountMsats` must be a positive integer. */ declare function buildZapRequest(signer: NostrSigner, args: ZapRequestArgs): Promise<{ event: nostr_tools.Event; encoded: string; }>; /** * Resolve a lightning address (`name@domain.com`) to its LNURL-pay * metadata. Returns null if the address is unreachable or doesn't * support Nostr zaps. */ declare function fetchLnurlPayMetadata(lud16: string, fetchImpl?: typeof fetch): Promise<{ callback: string; minSendable: number; maxSendable: number; metadata: string; allowsNostr: boolean; nostrPubkey?: string; } | null>; /** * Full zap pipeline: lud16 → LNURL → invoice. Caller pays the returned * `pr` (bolt11 invoice) via their wallet. */ declare function requestZapInvoice(signer: NostrSigner, options: ZapRequestArgs & { lud16: string; fetchImpl?: typeof fetch; }): Promise<{ invoice: string; zapRequest: nostr_tools.Event; }>; /** * Nostr Wallet Connect (NIP-47). * * The wallet daemon advertises a connection URI that includes: * - `nostrwalletconnect://?relay=...&secret=...` * * The client encrypts kind 23194 requests via NIP-04 to the wallet * pubkey, publishes them to the wallet's relay, and waits for the * matching kind 23195 response. * * This client supports the standard NWC methods: `pay_invoice`, * `make_invoice`, `lookup_invoice`, `list_transactions`, `get_balance`, * `get_info`. Custom methods can be invoked via `call(method, params)`. */ declare const NWC_REQUEST_KIND = 23194; declare const NWC_RESPONSE_KIND = 23195; interface NWCConnection { walletPubkey: string; relay: string; clientSecretKey: Uint8Array; } declare function parseNwcUri(uri: string): NWCConnection; type NwcResult = { result: T; result_type: string; } | { error: { code: string; message: string; }; }; declare class NwcClient { #private; constructor(connection: NWCConnection, pool?: SimplePool); static fromUri(uri: string, pool?: SimplePool): NwcClient; payInvoice(invoice: string): Promise<{ preimage: string; fees_paid?: number; }>; makeInvoice(amountSats: number, description?: string): Promise<{ invoice: string; payment_hash: string; }>; getBalance(): Promise<{ balance: number; }>; getInfo(): Promise<{ alias: string; color: string; pubkey: string; network: string; block_height: number; methods: string[]; }>; lookupInvoice(payment_hash: string): Promise<{ invoice?: string; settled?: boolean; settled_at?: number; amount?: number; }>; /** * Generic call. Returns the wallet's `result` payload or throws an * Error with `code` and `message` from the wallet on failure. */ call(method: string, params: Record): Promise; } interface RawNostrEvent { kind: number; pubkey: string; tags: string[][]; content: string; id: string; sig: string; created_at: number; } interface ValidatedZapReceipt { senderPubkey: string; amountMsat: number; bolt11: string; messageId?: string; comment?: string; /** The id of the receipt event (for de-dup). */ receiptId: string; /** The signer of the receipt — the recipient's LNURL provider. */ providerPubkey: string; } declare function validateZapReceipt(event: RawNostrEvent, expectedRecipient: string, trustedProviderPubkeys?: Set): ValidatedZapReceipt | null; interface WebLNProvider { enable(): Promise; sendPayment(invoice: string): Promise<{ preimage: string; }>; } declare global { interface Window { webln?: WebLNProvider; } } declare function isWebLNAvailable(): boolean; interface WebLNZapOptions { signer: NostrSigner; recipientPubkey: string; /** Recipient Lightning Address (lud16, e.g. `alice@example.com`). */ recipientLud16: string; /** Optional event id being zapped — omit to send a user-zap (no `e` tag). */ eventId?: string; /** Amount in sats. Converted to msats internally. */ amountSats: number; /** Relays to include in the zap-request `relays` tag. Defaults applied if empty. */ relays: string[]; /** Optional comment included both in the zap-request content and as LNURL `comment`. */ comment?: string; /** Optional `fetch` override — useful for tests. */ fetchImpl?: typeof fetch; } /** * Send a zap to `recipientLud16` for `amountSats` via WebLN. * * Throws if WebLN is unavailable, the lud16 doesn't accept Nostr zaps, or * the amount is outside the LNURL provider's `min/maxSendable` window. */ declare function zapViaWebLN(opts: WebLNZapOptions): Promise<{ preimage: string; }>; interface LnbitsToNwcResult { nwcUri: string; } /** * Convert an LNbits instance URL + admin key into an NWC URI by calling the * LNbits NWC service plugin's pairing endpoint. * * Throws with friendly messages on the common failure modes: * - 404: NWC plugin not enabled on this LNbits instance * - 401/403: invalid admin key * - other non-2xx: surfaced as `LNbits returned ` */ declare function lnbitsToNwc(instanceUrl: string, adminKey: string, fetchImpl?: typeof fetch): Promise; export { type LnbitsToNwcResult, type NWCConnection, NWC_REQUEST_KIND, NWC_RESPONSE_KIND, NwcClient, type NwcResult, type RawNostrEvent, type ValidatedZapReceipt, type WebLNZapOptions, type ZapRequestArgs, buildZapRequest, fetchLnurlPayMetadata, isWebLNAvailable, lnbitsToNwc, parseNwcUri, requestZapInvoice, validateZapReceipt, zapViaWebLN };