{"_id":"@devswayam/x402-hono","_rev":"2-69fa2822b3ba9957ccbf44709f5519a5","name":"@devswayam/x402-hono","dist-tags":{"latest":"0.6.0"},"versions":{"0.5.3":{"name":"@devswayam/x402-hono","version":"0.5.3","keywords":[],"author":{"name":"Coinbase Inc."},"license":"Apache-2.0","_id":"@devswayam/x402-hono@0.5.3","maintainers":[{"name":"devswayam","email":"swayamkarle2@gmail.com"}],"homepage":"https://github.com/DevSwayam/x402#readme","bugs":{"url":"https://github.com/DevSwayam/x402/issues"},"dist":{"shasum":"9ebb668b32d0c6f3db320f3f5ba2d904c99997e2","tarball":"https://registry.npmjs.org/@devswayam/x402-hono/-/x402-hono-0.5.3.tgz","fileCount":8,"integrity":"sha512-wUdTSbfbKqGSajE8OWMs04l51aM4V0FWxdP0ncZwUQWK/AxPZA27bNRU6ucFA/ZsTRHUXaqp4TkkYQx3thP1rQ==","signatures":[{"sig":"MEUCIQCWk6jUstX/efx0BI7JfmuZ+PHE1ZKPJllMJpqY+KM8bwIgZ8niilQ6eAbCfvoU0kcifMHiLrDnhKdqIQSgKX65zDA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":48031},"main":"./dist/cjs/index.js","_from":"file:devswayam-x402-hono-0.5.3.tgz","types":"./dist/index.d.ts","module":"./dist/esm/index.js","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"}}},"scripts":{"lint":"eslint . --ext .ts --fix","test":"vitest run","build":"tsup","start":"tsx --env-file=.env index.ts","watch":"tsc --watch","format":"prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"","lint:check":"eslint . --ext .ts","test:watch":"vitest","format:check":"prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\""},"_npmUser":{"name":"devswayam","email":"swayamkarle2@gmail.com"},"_resolved":"/private/var/folders/mm/pn7zw65s2n994mhcr3vrpxq00000gn/T/941b33b79d83c49ed418f7dcf0c4752a/devswayam-x402-hono-0.5.3.tgz","_integrity":"sha512-wUdTSbfbKqGSajE8OWMs04l51aM4V0FWxdP0ncZwUQWK/AxPZA27bNRU6ucFA/ZsTRHUXaqp4TkkYQx3thP1rQ==","repository":{"url":"git+https://github.com/DevSwayam/x402.git","type":"git","directory":"typescript/packages/x402-hono"},"_npmVersion":"11.3.0","description":"x402 Payment Protocol","directories":{},"_nodeVersion":"24.1.0","dependencies":{"zod":"^3.24.2","hono":"^4.7.1","viem":"^2.21.26","unwallet-horizen":"^0.1.1","@coinbase/cdp-sdk":"^1.22.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tsup":"^8.4.0","vite":"^6.2.6","eslint":"^9.24.0","vitest":"^3.0.5","prettier":"3.5.2","@eslint/js":"^9.24.0","typescript":"^5.7.3","@types/node":"^22.13.4","eslint-plugin-jsdoc":"^50.6.9","vite-tsconfig-paths":"^5.1.4","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.6","@typescript-eslint/parser":"^8.29.1","@typescript-eslint/eslint-plugin":"^8.29.1"},"_npmOperationalInternal":{"tmp":"tmp/x402-hono_0.5.3_1756292408892_0.6231257596208066","host":"s3://npm-registry-packages-npm-production"}},"0.6.0":{"name":"@devswayam/x402-hono","version":"0.6.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/DevSwayam/x402.git","directory":"typescript/packages/x402-hono"},"publishConfig":{"access":"public"},"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","prettier":"3.5.2","tsup":"^8.4.0","tsx":"^4.19.2","typescript":"^5.7.3","vite-tsconfig-paths":"^5.1.4","vitest":"^3.0.5","vite":"^6.2.6"},"dependencies":{"@coinbase/cdp-sdk":"^1.22.0","hono":"^4.7.1","viem":"^2.21.26","zod":"^3.24.2","unwallet-horizen":"^0.2.0"},"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"}}},"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":"@devswayam/x402-hono@0.6.0","bugs":{"url":"https://github.com/DevSwayam/x402/issues"},"homepage":"https://github.com/DevSwayam/x402#readme","_integrity":"sha512-uE0L0+UMGODd2tgK54mIlyPt1atbiQ9LVRFtX5SIl9ieQc2HRnnBTWSRhd4tR2oIDDnA7t21fgtNvdk9VxPWXA==","_resolved":"/private/var/folders/mm/pn7zw65s2n994mhcr3vrpxq00000gn/T/9ac3d5a69205471a4ec264aecad2c6eb/devswayam-x402-hono-0.6.0.tgz","_from":"file:devswayam-x402-hono-0.6.0.tgz","_nodeVersion":"24.1.0","_npmVersion":"11.3.0","dist":{"integrity":"sha512-uE0L0+UMGODd2tgK54mIlyPt1atbiQ9LVRFtX5SIl9ieQc2HRnnBTWSRhd4tR2oIDDnA7t21fgtNvdk9VxPWXA==","shasum":"b821940517f675cf50a6a8f45f4cafdd2d8fa92a","tarball":"https://registry.npmjs.org/@devswayam/x402-hono/-/x402-hono-0.6.0.tgz","fileCount":8,"unpackedSize":48031,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHfle+pFoCSZZmoagxqeKk9sXDuVllLcKaCsVRoDuzSLAiEA84dFH5mofUBx0RqRWzI56Lf4/ZeaPRk78n/3cvday9k="}]},"_npmUser":{"name":"devswayam","email":"swayamkarle2@gmail.com"},"directories":{},"maintainers":[{"name":"devswayam","email":"swayamkarle2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/x402-hono_0.6.0_1756316353258_0.014465916538870083"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-27T11:00:08.765Z","modified":"2025-08-27T17:39:13.636Z","0.5.3":"2025-08-27T11:00:09.066Z","0.6.0":"2025-08-27T17:39:13.440Z"},"bugs":{"url":"https://github.com/DevSwayam/x402/issues"},"author":{"name":"Coinbase Inc."},"license":"Apache-2.0","homepage":"https://github.com/DevSwayam/x402#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/DevSwayam/x402.git","directory":"typescript/packages/x402-hono"},"description":"x402 Payment Protocol","maintainers":[{"name":"devswayam","email":"swayamkarle2@gmail.com"}],"readme":"# x402-hono\n\nHono middleware integration for the x402 Payment Protocol. This package allows you to easily add paywall functionality to your Hono applications using the x402 protocol.\n\n## Installation\n\n```bash\nnpm install x402-hono\n```\n\n## Quick Start\n\n```typescript\nimport { Hono } from \"hono\";\nimport { paymentMiddleware, Network } from \"x402-hono\";\n\nconst app = new Hono();\n\n// Configure the payment middleware\napp.use(paymentMiddleware(\n  \"0xYourAddress\",\n  {\n    \"/protected-route\": {\n      price: \"$0.10\",\n      network: \"base-sepolia\",\n      config: {\n        description: \"Access to premium content\",\n      }\n    }\n  }\n));\n\n// Implement your route\napp.get(\"/protected-route\", (c) => {\n  return c.json({ message: \"This content is behind a paywall\" });\n});\n\nserve({\n  fetch: app.fetch,\n  port: 3000\n});\n```\n\n## Configuration\n\nThe `paymentMiddleware` function accepts three parameters:\n\n1. `payTo`: Your receiving address (`0x${string}`)\n2. `routes`: Route configurations for protected endpoints\n3. `facilitator`: (Optional) Configuration for the x402 facilitator service\n4. `paywall`: (Optional) Configuration for the built-in paywall\n\nSee the Middleware Options section below for detailed configuration options.\n\n## Middleware Options\n\nThe middleware supports various configuration options:\n\n### Route Configuration\n\n```typescript\ntype RoutesConfig = Record<string, Price | RouteConfig>;\n\ninterface RouteConfig {\n  price: Price;           // Price in USD or token amount\n  network: Network;       // \"base\" or \"base-sepolia\"\n  config?: PaymentMiddlewareConfig;\n}\n```\n\n### Payment Configuration\n\n```typescript\ninterface PaymentMiddlewareConfig {\n  description?: string;               // Description of the payment\n  mimeType?: string;                  // MIME type of the resource\n  maxTimeoutSeconds?: number;         // Maximum time for payment (default: 60)\n  outputSchema?: Record<string, any>; // JSON schema for the response\n  customPaywallHtml?: string;         // Custom HTML for the paywall\n  resource?: string;                  // Resource URL (defaults to request URL)\n}\n```\n\n### Facilitator Configuration\n\n```typescript\ntype FacilitatorConfig = {\n  url: string;                        // URL of the x402 facilitator service\n  createAuthHeaders?: CreateHeaders;  // Optional function to create authentication headers\n};\n```\n\n\n### Paywall Configuration\n\nFor more on paywall configuration options, refer to the [paywall README](../x402/src/paywall/README.md).\n\n```typescript\ntype PaywallConfig = {\n  cdpClientKey?: string;              // Your CDP Client API Key\n  appName?: string;                   // Name displayed in the paywall wallet selection modal\n  appLogo?: string;                   // Logo for the paywall wallet selection modal\n  sessionTokenEndpoint?: string;      // API endpoint for Coinbase Onramp session authentication\n};\n```\n\n## Optional: Coinbase Onramp Integration\n\n**Note**: Onramp integration is completely optional. Your x402 paywall will work perfectly without it. This feature is for users who want to provide an easy way for their customers to fund their wallets directly from the paywall.\n\nWhen configured, a \"Get more USDC\" button will appear in your paywall, allowing users to purchase USDC directly through Coinbase Onramp.\n\n### Quick Setup\n\n#### 1. Create the Session Token Route\n\nAdd a session token endpoint to your Hono app:\n\n```typescript\nimport { Hono } from \"hono\";\nimport { POST } from \"x402-hono/session-token\";\n\nconst app = new Hono();\n\n// Add the session token endpoint\napp.post(\"/api/x402/session-token\", POST);\n```\n\n#### 2. Configure Your Middleware\n\nAdd `sessionTokenEndpoint` to your middleware configuration. This tells the paywall where to find your session token API:\n\n```typescript\napp.use(paymentMiddleware(\n  payTo,\n  routes,\n  facilitator,\n  {\n    sessionTokenEndpoint: \"path/to/session-token-route\",\n  }\n));\n```\n\n**Important**: The `sessionTokenEndpoint` must match the route you created above. You can use any path you prefer - just make sure both the route and configuration use the same path. Without this configuration, the \"Get more USDC\" button will be hidden.\n\n#### 3. Get CDP API Keys\n\n1. Go to [CDP Portal](https://portal.cdp.coinbase.com/)\n2. Navigate to your project's **[API Keys](https://portal.cdp.coinbase.com/projects/api-keys)**\n3. Click **Create API key**\n4. Download and securely store your API key\n\n#### 4. Enable Onramp Secure Initialization in CDP Portal\n\n1. Go to [CDP Portal](https://portal.cdp.coinbase.com/)\n2. Navigate to **Payments → [Onramp & Offramp](https://portal.cdp.coinbase.com/products/onramp)**\n3. Toggle **\"Enforce secure initialization\"** to **Enabled**\n\n#### 5. Set Environment Variables\n\nAdd your CDP API keys to your environment:\n\n```bash\n# .env\nCDP_API_KEY_ID=your_secret_api_key_id_here\nCDP_API_KEY_SECRET=your_secret_api_key_secret_here\n```\n\n### How Onramp Works\n\nOnce set up, your x402 paywall will automatically show a \"Get more USDC\" button when users need to fund their wallets. \n\n1. **Generates session token**: Your backend securely creates a session token using CDP's API\n2. **Opens secure onramp**: User is redirected to Coinbase Onramp with the session token\n3. **No exposed data**: Wallet addresses and app IDs are never exposed in URLs\n\n### Troubleshooting Onramp\n\n#### Common Issues\n\n1. **\"Missing CDP API credentials\"**\n    - Ensure `CDP_API_KEY_ID` and `CDP_API_KEY_SECRET` are set\n    - Verify you're using **Secret API Keys**, not Client API Keys\n\n2. **\"Failed to generate session token\"**\n    - Check your CDP Secret API key has proper permissions\n    - Verify your project has Onramp enabled\n\n3. **API route not found**\n    - Ensure you've added the session token route: `app.post(\"/your-path\", POST)`\n    - Check that your route path matches your `sessionTokenEndpoint` configuration\n    - Verify the import: `import { POST } from \"x402-hono/session-token\"`\n    - Example: If you configured `sessionTokenEndpoint: \"/api/custom/onramp\"`, add `app.post(\"/api/custom/onramp\", POST)`\n\n\n## Resources\n\n- [x402 Protocol](https://x402.org)\n- [CDP Documentation](https://docs.cdp.coinbase.com)\n- [CDP Discord](https://discord.com/invite/cdp)\n","readmeFilename":"README.md"}