{"_id":"@a402/express","name":"@a402/express","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@a402/express","version":"0.1.0","description":"Express middleware that gates endpoints behind a402 payment","license":"MIT","repository":{"type":"git","url":"git+https://github.com/pixel8labs/a402.git","directory":"sdk/node"},"keywords":["a402","x402","payments","micropayments","express","middleware","usdc"],"type":"module","engines":{"node":">=18"},"main":"./dist/src/index.js","types":"./dist/src/index.d.ts","exports":{".":{"import":"./dist/src/index.js","types":"./dist/src/index.d.ts"}},"scripts":{"build":"tsc","test":"node --test dist/test/*.test.js","prepublishOnly":"npm run build"},"peerDependencies":{"express":">=4.0.0"},"devDependencies":{"@types/express":"^4.17.21","@types/node":"^20.0.0","typescript":"^5.0.0"},"_id":"@a402/express@0.1.0","gitHead":"7315f0830fb30b9dc7ab3e91d1d08bf02f40c5ee","bugs":{"url":"https://github.com/pixel8labs/a402/issues"},"homepage":"https://github.com/pixel8labs/a402#readme","_nodeVersion":"24.4.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-McgH3LKp/Sf6djSDe5DSTYQSDFBuCCoqmN3FVbhSMK2L3lQy+thX7wm6mHEqVTSFwFa7l7rZWjRK36fQP/ueZg==","shasum":"0ec8958ebe07d823a530c7941330518533422e00","tarball":"https://registry.npmjs.org/@a402/express/-/express-0.1.0.tgz","fileCount":10,"unpackedSize":14445,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBWjeq5AKu+++6sIY4aNyKOoMiA0YhF4aoxF4Ud/aKYlAiEAzi0OWfxg4/cP/Vss2QvYg26/kO9q5xUZGV5e0OnwpBM="}]},"_npmUser":{"name":"_persons","email":"ariefdarmawan@pixel8labs.com"},"directories":{},"maintainers":[{"name":"_persons","email":"ariefdarmawan@pixel8labs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/express_0.1.0_1783667362119_0.7188868590407564"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-10T07:09:21.864Z","0.1.0":"2026-07-10T07:09:22.251Z","modified":"2026-07-10T07:09:22.416Z"},"maintainers":[{"name":"_persons","email":"ariefdarmawan@pixel8labs.com"}],"description":"Express middleware that gates endpoints behind a402 payment","homepage":"https://github.com/pixel8labs/a402#readme","keywords":["a402","x402","payments","micropayments","express","middleware","usdc"],"repository":{"type":"git","url":"git+https://github.com/pixel8labs/a402.git","directory":"sdk/node"},"bugs":{"url":"https://github.com/pixel8labs/a402/issues"},"license":"MIT","readme":"# @a402/express\n\nExpress middleware that gates your endpoints behind a402 micropayments. The seller never handles keys or crypto — the facilitator does all of that.\n\n## Install\n\n```bash\nnpm install @a402/express express\n```\n\n## Usage\n\n### Gate multiple routes at once\n\n```ts\nimport express from \"express\";\nimport { a402 } from \"@a402/express\";\n\nconst app = express();\n\napp.use(\n  a402.gate({\n    apiKey: process.env.A402_KEY!,\n    // facilitatorUrl is optional — defaults to a402's hosted facilitator.\n    // Set it only to self-host or point at a staging facilitator.\n    routes: [\n      { method: \"GET\",  path: \"/v1/financials\", price: \"$0.05\" },\n      { method: \"POST\", path: \"/v1/report\",     price: 0.10 },\n      { path: \"/v1/quote\", price: \"$0.01\" }, // method defaults to GET\n    ],\n  })\n);\n\napp.get(\"/v1/financials\", (req, res) => {\n  res.json({ data: \"…\" });\n});\n```\n\n### Single-route helper\n\n```ts\napp.get(\n  \"/v1/financials\",\n  a402.pay(\"$0.05\", {\n    apiKey: process.env.A402_KEY!,\n  }),\n  (req, res) => {\n    res.json({ data: \"…\" });\n  }\n);\n```\n\nPrice accepts a `$`-prefixed string (`\"$0.05\"`) or a plain number (`0.05`), both interpreted as USD.\n\n## How it works\n\n1. **No `X-PAYMENT` header** — the middleware calls `POST /facilitator/challenge` with your API key and the route's price. The facilitator returns a 402 body (`{ x402Version, accepts }`) containing the USDC amount, nonce, payTo address, and validity window the client must sign (EIP-3009).\n\n2. **Client pays** — the client signs the EIP-3009 authorization, packages it as `{ apiKeyId, network, authorization, signature }`, base64-encodes that JSON, and sends it back in the `X-PAYMENT` header.\n\n3. **Settle** — the middleware base64-decodes `X-PAYMENT`, injects your `apiKeyToken` into the body, and calls `POST /facilitator/settle`. On success (HTTP 200) the middleware sets `X-PAYMENT-RESPONSE` to a base64-encoded JSON of the payment object and calls `next()` so your real handler runs. On 402/403 the facilitator's response is forwarded verbatim. Network errors produce a 502.\n\nThe protocol targets EIP-3009 same-chain and cross-chain (CCTP) settlement. A 200 from settle means the source-chain transfer has landed; for cross-chain flows the CCTP mint to the destination chain happens asynchronously.\n\n## Response headers\n\n| Header | When set | Value |\n|---|---|---|\n| `X-PAYMENT-RESPONSE` | Settle succeeded | `base64(JSON(payment))` — contains `status`, `txHash`, `settlementMs`, etc. |\n","readmeFilename":"README.md","_rev":"1-29d7981e1029dfaae081937e5de26a22"}