/** * @file helper functions for use in a boltwall server, including setting up the middleware * evaluationg macaroons and lsats, and communicating with the lnd node */ import { Request } from 'express'; import { InvoiceResponse, LoggerInterface } from './typings'; import { Lsat } from 'lsat-js'; export declare const MACAROON_SUGGESTED_SECRET_LENGTH = 32; interface EnvVars { PORT?: string; OPEN_NODE_KEY?: string | undefined; LND_TLS_CERT?: string; LND_MACAROON?: string; SESSION_SECRET: string; LND_SOCKET?: string; CLN_TLS_LOCATION?: string; CLN_TLS_KEY_LOCATION?: string; CLN_TLS_CHAIN_LOCATION?: string; CLN?: boolean; CLN_URI?: string; } /** * @description Utility function for getting required environment variables * It will validate existing env vars and create missing ones that are required * and can be generated randomly (namely the SESSION_SECRET for signing macaroons) * @returns {EnvVars} environment variables relevant to boltwall operation */ export declare function getEnvVars(): EnvVars; /** * @description evaluates environment variables and throws errors * based on what might be missing but required * @property {Request.logger} logger - logger object for returning messages */ export declare function testEnvVars(logger: LoggerInterface): boolean | Error; /** * @description A utility function to create a caveat for use in first party macaroon * based OAuth protocols * @param payreq - BOLT11 payment request to generate challenge from * @returns string encoded caveat of the form `challenge=[random 32 byte string]:[destination pubkey]` */ export declare function createChallengeCaveat(payreq: string): string; /** * Utility function to get a location string to describe _where_ the server is. * useful for setting identifiers in macaroons * @param {Express.request} req - expressjs request object * @param {Express.request.headers} [headers] - optional headers property added by zeit's now * @param {Express.request.hostname} - fallback if not in a now lambda * @returns {String} - location string */ export declare function getLocation({ headers, hostname }: Request): string; /** * @description Given a request and an invoice, generate a new LSAT including building * and signing a new macaroon based on the user defined boltwall config * @param {Request} req * @param {InvoiceResponse} invoice * @returns {Lsat} */ export declare function createLsatFromInvoice(req: Request, invoice: InvoiceResponse): Lsat; /** * @description Utility to create an invoice based on either an authenticated lnd grpc instance * or an opennode connection * @param {Request} req - express request object that either contains an lnd or opennode object * @returns {InvoiceResponse} invoice - returns an invoice with a payreq, id, description, createdAt, and */ export declare function createInvoice(req: Request): Promise; /** * @description Checks the status of an invoice given an id (i.e. a payment hash) * @param {string} invoiceId - the id or paymentHash of the invoice to check the status of * @param {lnd} [lnd] - ln-service authenticated grpc object * @param {req.opennode} [opennode] - authenticated opennode object for communicating with OpenNode API * @param {boolean} [returnSecret=false] - whether or not to return the paymentHash secret in the response * Useful to keep as false for unauthenticated clients who need the secret to prove authorization * @returns {InvoiceResponse} invoice - Object with status, amount, and payment request */ export declare function checkInvoiceStatus(invoiceId: string, lnd?: any, opennode?: any, cln?: any, returnSecret?: boolean): Promise; /** * @description Given a string, determine if it is in hex encoding or not. * @param {string} h - string to evaluate * @returns {boolean} */ export declare function isHex(h: string): boolean; /** * @description A utility function used to determine the origin IP of a given request. * The function accounts for different circumstances such as proxies (x-forwarded-for) or * use in frameworks that don't support Express's req.ip/req.ips properties. * @param {Request} req - request object used to determine the origin * @returns {string} ip address where the request originated from */ export declare function getOriginFromRequest(req: Request): string; export interface TokenChallenge { pubkey: string; challenge: string; signature?: string | undefined; } /** * @description parse a challenge caveat to retrieve its individual pieces: * pubkey, challenge, and signature * @param {String} c - encoded caveat string * @returns {TokenChallenge} */ export declare function decodeChallengeCaveat(c: string): TokenChallenge; export {};