import { a as InvoiceStore, I as InvoiceEngine } from '../invoice-engine-BzpQXq7Y.cjs'; import { a as DeroPayConfig } from '../types-Bsy2LUTI.cjs'; export { X as X402ChallengeResponse, a as X402PaymentPolicy, b as X402PolicyResolver, c as X402RouteGuardConfig, d as createX402RouteGuard } from '../x402-Czf0DzVv.cjs'; import '../wallet-rpc-sY1qJ24S.cjs'; import '../rpc/index.cjs'; import '../manager-CNcr_RGt.cjs'; /** * Next.js API route handlers for DeroPay. * * Provides ready-made handlers for invoice creation, status checking, * and webhook reception. * * Usage in Next.js App Router: * ```ts * // app/api/pay/create/route.ts * import { createPaymentHandlers } from "dero-pay/next"; * * const { createInvoiceHandler } = createPaymentHandlers({ * walletRpcUrl: "http://127.0.0.1:10103/json_rpc", * daemonRpcUrl: "http://127.0.0.1:10102/json_rpc", * webhookUrl: "https://mystore.com/webhooks/dero", * webhookSecret: process.env.WEBHOOK_SECRET!, * }); * * export const POST = createInvoiceHandler; * ``` * * ```ts * // app/api/pay/status/route.ts * const { statusHandler } = createPaymentHandlers({ ... }); * export const GET = statusHandler; * ``` * * ```ts * // app/api/pay/webhook/route.ts * const { webhookHandler } = createPaymentHandlers({ ... }); * export const POST = webhookHandler; * ``` */ /** Configuration for the payment handlers */ type PaymentHandlersConfig = DeroPayConfig & { /** Custom store implementation */ store?: InvoiceStore; /** Whether to auto-start the engine (default: true) */ autoStart?: boolean; /** Secret used to sign and verify payment receipts */ receiptSecret?: string; /** Secrets by key ID for receipt key rotation (verification supports all keys) */ receiptSecrets?: Record; /** Active key ID used to issue new receipts when receiptSecrets is set */ receiptKeyId?: string; }; /** * Create Next.js API route handlers for DeroPay. */ declare function createPaymentHandlers(config: PaymentHandlersConfig): { createInvoiceHandler: (request: Request) => Promise; statusHandler: (request: Request) => Promise; listInvoicesHandler: (request: Request) => Promise; statsHandler: (_request: Request) => Promise; webhookHandler: (request: Request) => Promise; healthHandler: (_request: Request) => Promise; escrowActionHandler: (request: Request) => Promise; claimEscrowInvoiceHandler: (request: Request) => Promise; listEscrowsHandler: (request: Request) => Promise; issueReceiptHandler: (request: Request) => Promise; verifyReceiptHandler: (request: Request) => Promise; /** Access the underlying engine instance */ getEngine: () => Promise; }; /** * Next.js middleware helpers for DeroPay API key authentication. * * Protects DeroPay API routes with API key authentication. * Merchant API keys are checked via the X-DeroPay-ApiKey header. * * Usage: * ```ts * // middleware.ts * import { createDeroPayMiddleware } from "dero-pay/next"; * * export const middleware = createDeroPayMiddleware({ * apiKeys: [process.env.DEROPAY_API_KEY!], * protectedPaths: ["/api/pay/create", "/api/pay/invoices", "/api/pay/stats"], * }); * * export const config = { * matcher: ["/api/pay/:path*"], * }; * ``` */ /** Configuration for the DeroPay middleware */ type DeroPayMiddlewareConfig = { /** Valid API keys for authentication */ apiKeys: string[]; /** Paths that require API key authentication */ protectedPaths?: string[]; /** Paths that are public (no auth required, e.g., status endpoint) */ publicPaths?: string[]; /** Header name for the API key (default: X-DeroPay-ApiKey) */ headerName?: string; }; /** * Create a Next.js middleware function for DeroPay API key auth. * * Checks for a valid API key in the request header. * Returns 401 if the key is missing or invalid. */ declare function createDeroPayMiddleware(config: DeroPayMiddlewareConfig): (request: Request) => Promise; /** * Generate a random API key. * * @returns A 32-byte hex string (64 characters) */ declare function generateApiKey(): string; export { type DeroPayMiddlewareConfig, type PaymentHandlersConfig, createDeroPayMiddleware, createPaymentHandlers, generateApiKey };