UNPKG

@getalby/lightning-tools

Version:

Collection of helpful building blocks and tools to develop Bitcoin Lightning web apps

52 lines (46 loc) 1.61 kB
interface Wallet { payInvoice(args: { invoice: string; }): Promise<{ preimage: string; }>; } declare const fetchWithL402: (url: string, fetchArgs: RequestInit, options: { wallet: Wallet; }) => Promise<Response>; interface WwwAuthenticatePayload { token: string; invoice: string; [key: string]: string; } /** * Client: parse "www-authenticate" header from server response * @param input * @returns details from the header value (token or macaroon, invoice) */ declare const parseL402: (input: string) => WwwAuthenticatePayload; type MacaroonPayload<T> = T & { paymentHash: string; }; declare function issueL402Macaroon<T extends Record<string, unknown>>(secret: string, paymentHash: string, params?: T): Promise<string>; declare function verifyL402Macaroon<T = unknown>(secret: string, token: string): Promise<MacaroonPayload<T>>; /** * Server: create a WWW-Authenticate header for a given macaroon and invoice * @param args the macaroon/token and invoice generated for the client's request * @returns the header value */ declare const makeL402AuthenticateHeader: (args: { token?: string; invoice: string; }) => string; /** * Server: parse "authorization" header sent from client * @param input value from authorization header * @returns the macaroon and preimage */ declare function parseL402Authorization(input: string): { token: string; preimage: string; } | null; export { fetchWithL402, issueL402Macaroon, makeL402AuthenticateHeader, parseL402, parseL402Authorization, verifyL402Macaroon }; export type { MacaroonPayload };