{"_id":"@aeon-ai-pay/hono","name":"@aeon-ai-pay/hono","dist-tags":{"latest":"2.1.0"},"versions":{"2.1.0":{"name":"@aeon-ai-pay/hono","version":"2.1.0","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/index.d.ts","keywords":[],"license":"Apache-2.0","author":{"name":"Coinbase Inc."},"repository":{"type":"git","url":"git+https://github.com/coinbase/x402.git"},"description":"x402 Payment Protocol","devDependencies":{"@eslint/js":"^9.24.0","@types/node":"^22.13.4","@typescript-eslint/eslint-plugin":"^8.29.1","@typescript-eslint/parser":"^8.29.1","eslint":"^9.24.0","eslint-plugin-import":"^2.31.0","eslint-plugin-jsdoc":"^50.6.9","eslint-plugin-prettier":"^5.2.6","hono":"^4.7.1","prettier":"3.5.2","tsup":"^8.4.0","tsx":"^4.19.2","typescript":"^5.7.3","vite":"^6.2.6","vite-tsconfig-paths":"^5.1.4","vitest":"^3.0.5"},"dependencies":{"zod":"^3.24.2","@aeon-ai-pay/core":"^2.1.0","@aeon-ai-pay/extensions":"^2.1.0"},"peerDependencies":{"hono":"^4.0.0","@aeon-ai-pay/paywall":"2.1.0"},"peerDependenciesMeta":{"@aeon-ai-pay/paywall":{"optional":true}},"exports":{".":{"import":{"types":"./dist/esm/index.d.mts","default":"./dist/esm/index.mjs"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.js"}}},"publishConfig":{"access":"public"},"scripts":{"start":"tsx --env-file=.env index.ts","test":"vitest run","test:watch":"vitest","build":"tsup","watch":"tsc --watch","format":"prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"","format:check":"prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"","lint":"eslint . --ext .ts --fix","lint:check":"eslint . --ext .ts"},"_id":"@aeon-ai-pay/hono@2.1.0","bugs":{"url":"https://github.com/coinbase/x402/issues"},"homepage":"https://github.com/coinbase/x402#readme","_integrity":"sha512-0yN1fnti3G2OoJ1NSladIjAmbzTIR1BWHhMtjSc4CTBFuZF7DPYv7kj/rK3JVKX6hGUEK/1gY/SEtBU+ZwvU0g==","_resolved":"/private/var/folders/rr/hyts0bs54zn73fgjjlld0tvm0000gn/T/c0bffda6130b6cf9f06f1986e01f5c1e/aeon-ai-pay-hono-2.1.0.tgz","_from":"file:aeon-ai-pay-hono-2.1.0.tgz","_nodeVersion":"25.8.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-0yN1fnti3G2OoJ1NSladIjAmbzTIR1BWHhMtjSc4CTBFuZF7DPYv7kj/rK3JVKX6hGUEK/1gY/SEtBU+ZwvU0g==","shasum":"b4c59a53e8257d3df6f98b80aa21cb1322fae233","tarball":"https://registry.npmjs.org/@aeon-ai-pay/hono/-/hono-2.1.0.tgz","fileCount":8,"unpackedSize":63587,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIA8Lj1DJsSdw/dD60oEdwHs+yZoHPgTjS4/Z+WQ9kIYzAiAYDeRNJedyRXO+aBwrLa5h1MLc6H4sIQOcaFjVBJBe+Q=="}]},"_npmUser":{"name":"aeon_project","email":"code@alchemypay.org"},"directories":{},"maintainers":[{"name":"aeon_project","email":"code@alchemypay.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hono_2.1.0_1775096345232_0.18593365233823733"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-02T02:19:05.159Z","2.1.0":"2026-04-02T02:19:05.380Z","modified":"2026-04-02T02:19:05.574Z"},"maintainers":[{"name":"aeon_project","email":"code@alchemypay.org"}],"description":"x402 Payment Protocol","homepage":"https://github.com/coinbase/x402#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/coinbase/x402.git"},"author":{"name":"Coinbase Inc."},"bugs":{"url":"https://github.com/coinbase/x402/issues"},"license":"Apache-2.0","readme":"# @x402/hono\n\nHono middleware integration for the x402 Payment Protocol. This package provides a simple middleware function for adding x402 payment requirements to your Hono applications.\n\n## Installation\n\n```bash\npnpm install @x402/hono\n```\n\n## Quick Start\n\n```typescript\nimport { Hono } from \"hono\";\nimport { serve } from \"@hono/node-server\";\nimport { paymentMiddleware, x402ResourceServer } from \"@x402/hono\";\nimport { ExactEvmScheme } from \"@x402/evm/exact/server\";\nimport { HTTPFacilitatorClient } from \"@x402/core/server\";\n\nconst app = new Hono();\n\nconst facilitatorClient = new HTTPFacilitatorClient({ url: \"https://facilitator.x402.org\" });\nconst resourceServer = new x402ResourceServer(facilitatorClient)\n  .register(\"eip155:84532\", new ExactEvmScheme());\n\n// Apply the payment middleware with your configuration\napp.use(\n  paymentMiddleware(\n    {\n      \"GET /protected-route\": {\n        accepts: {\n          scheme: \"exact\",\n          price: \"$0.10\",\n          network: \"eip155:84532\",\n          payTo: \"0xYourAddress\",\n        },\n        description: \"Access to premium content\",\n      },\n    },\n    resourceServer,\n  ),\n);\n\n// Implement your protected route\napp.get(\"/protected-route\", (c) => {\n  return c.json({ message: \"This content is behind a paywall\" });\n});\n\nserve({ fetch: app.fetch, port: 3000 });\n```\n\n## Configuration\n\nThe `paymentMiddleware` function accepts the following parameters:\n\n```typescript\npaymentMiddleware(\n  routes: RoutesConfig,\n  server: x402ResourceServer,\n  paywallConfig?: PaywallConfig,\n  paywall?: PaywallProvider,\n  syncFacilitatorOnStart?: boolean\n)\n```\n\n### Parameters\n\n1. **`routes`** (required): Route configurations for protected endpoints\n2. **`server`** (required): Pre-configured x402ResourceServer instance\n3. **`paywallConfig`** (optional): Configuration for the built-in paywall UI\n4. **`paywall`** (optional): Custom paywall provider\n5. **`syncFacilitatorOnStart`** (optional): Whether to sync with facilitator on startup (defaults to true)\n\n## API Reference\n\n### HonoAdapter\n\nThe `HonoAdapter` class implements the `HTTPAdapter` interface from `@x402/core`, providing Hono-specific request handling:\n\n```typescript\nclass HonoAdapter implements HTTPAdapter {\n  getHeader(name: string): string | undefined;\n  getMethod(): string;\n  getPath(): string;\n  getUrl(): string;\n  getAcceptHeader(): string;\n  getUserAgent(): string;\n}\n```\n\n### Middleware Function\n\n```typescript\nfunction paymentMiddleware(\n  routes: RoutesConfig,\n  server: x402ResourceServer,\n  paywallConfig?: PaywallConfig,\n  paywall?: PaywallProvider,\n  syncFacilitatorOnStart?: boolean,\n): MiddlewareHandler;\n```\n\nCreates Hono middleware that:\n\n1. Uses the provided x402ResourceServer for payment processing\n2. Checks if the incoming request matches a protected route\n3. Validates payment headers if required\n4. Returns payment instructions (402 status) if payment is missing or invalid\n5. Processes the request if payment is valid\n6. Handles settlement after successful response\n\n### Route Configuration\n\nRoutes are passed as the first parameter to `paymentMiddleware`:\n\n```typescript\nconst routes: RoutesConfig = {\n  \"GET /api/protected\": {\n    accepts: {\n      scheme: \"exact\",\n      price: \"$0.10\",\n      network: \"eip155:84532\",\n      payTo: \"0xYourAddress\",\n      maxTimeoutSeconds: 60,\n    },\n    description: \"Premium API access\",\n  },\n};\n\napp.use(paymentMiddleware(routes, resourceServer));\n```\n\n### Paywall Configuration\n\nThe middleware automatically displays a paywall UI when browsers request protected endpoints.\n\n**Option 1: Full Paywall UI (Recommended)**\n\nInstall the optional `@x402/paywall` package for a complete wallet connection and payment UI:\n\n```bash\npnpm add @x402/paywall\n```\n\nThen configure it:\n\n```typescript\nconst paywallConfig: PaywallConfig = {\n  appName: \"Your App Name\",\n  appLogo: \"/path/to/logo.svg\",\n  testnet: true,\n};\n\napp.use(paymentMiddleware(routes, resourceServer, paywallConfig));\n```\n\n**Option 2: Basic Paywall (No Installation)**\n\nWithout `@x402/paywall` installed, the middleware returns a basic HTML page with payment instructions.\n\n**Option 3: Custom Paywall Provider**\n\nProvide your own paywall provider:\n\n```typescript\napp.use(paymentMiddleware(routes, resourceServer, paywallConfig, customPaywallProvider));\n```\n\n## Advanced Usage\n\n### Multiple Protected Routes\n\n```typescript\napp.use(\n  paymentMiddleware(\n    {\n      \"GET /api/premium/*\": {\n        accepts: {\n          scheme: \"exact\",\n          price: \"$1.00\",\n          network: \"eip155:8453\",\n          payTo: \"0xYourAddress\",\n        },\n        description: \"Premium API access\",\n      },\n      \"GET /api/data\": {\n        accepts: {\n          scheme: \"exact\",\n          price: \"$0.50\",\n          network: \"eip155:84532\",\n          payTo: \"0xYourAddress\",\n          maxTimeoutSeconds: 120,\n        },\n        description: \"Data endpoint access\",\n      },\n    },\n    resourceServer,\n  ),\n);\n```\n\n### Multiple Payment Networks\n\n```typescript\napp.use(\n  paymentMiddleware(\n    {\n      \"GET /weather\": {\n        accepts: [\n          {\n            scheme: \"exact\",\n            price: \"$0.001\",\n            network: \"eip155:84532\",\n            payTo: evmAddress,\n          },\n          {\n            scheme: \"exact\",\n            price: \"$0.001\",\n            network: \"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1\",\n            payTo: svmAddress,\n          },\n        ],\n        description: \"Weather data\",\n        mimeType: \"application/json\",\n      },\n    },\n    new x402ResourceServer(facilitatorClient)\n      .register(\"eip155:84532\", new ExactEvmScheme())\n      .register(\"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1\", new ExactSvmScheme()),\n  ),\n);\n```\n\n### Custom Facilitator Client\n\nIf you need to use a custom facilitator server, configure it when creating the x402ResourceServer:\n\n```typescript\nimport { HTTPFacilitatorClient } from \"@x402/core/server\";\nimport { x402ResourceServer } from \"@x402/hono\";\nimport { ExactEvmScheme } from \"@x402/evm/exact/server\";\n\nconst customFacilitator = new HTTPFacilitatorClient({\n  url: \"https://your-facilitator.com\",\n  createAuthHeaders: async () => ({\n    verify: { Authorization: \"Bearer your-token\" },\n    settle: { Authorization: \"Bearer your-token\" },\n  }),\n});\n\nconst resourceServer = new x402ResourceServer(customFacilitator)\n  .register(\"eip155:84532\", new ExactEvmScheme());\n\napp.use(paymentMiddleware(routes, resourceServer, paywallConfig));\n```\n","readmeFilename":"README.md","_rev":"1-da4213f9d8f1dddbd9e83b7f2ca22713"}