{"_id":"@proof.com/x401-workers","_rev":"4-51b08f468a66f244b64b71af1ecb6ab7","name":"@proof.com/x401-workers","dist-tags":{"latest":"0.2.0"},"versions":{"0.0.0-stage":{"name":"@proof.com/x401-workers","version":"0.0.0-stage","_id":"@proof.com/x401-workers@0.0.0-stage","stub":true,"maintainers":[{"name":"jeremie.charrier.ctr","email":"jeremie.charrier.ctr@proof.com"}],"dist":{"shasum":"28b38a7af19732fd95d82beaf11d5f6dc576a5a2","tarball":"https://registry.npmjs.org/@proof.com/x401-workers/-/x401-workers-0.0.0-stage.tgz","fileCount":2,"integrity":"sha512-Yi9qnT1mELVUXmshBFFkZkmc1PAuEXry9oj/SIpAwtFrTkDNqJDn0DJvQXh9ZK1CA8y6S4tyjQGMAmS79yyNKQ==","signatures":[{"sig":"MEUCIBsr+RanTNdw4frUwVoKdIeB1ssUU5Yos5IyQWl65zdlAiEAxmvzZ8qL7So1aknGpfldR/NM9oWjOK3f1ku3M0C97dU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":345},"_npmUser":{"name":"jeremie.charrier.ctr","email":"jeremie.charrier.ctr@proof.com"},"description":"Temporary package placeholder for staged publishing","directories":{}},"0.1.0":{"name":"@proof.com/x401-workers","version":"0.1.0","keywords":["x401","Cloudflare Workers","Verifiable Presentation","OID4VP","Agent","Verifier","Proof","Proof.com"],"author":{"name":"Jeremie Charrier","email":"jeremie.charrier@proof.com"},"license":"Apache-2.0","_id":"@proof.com/x401-workers@0.1.0","maintainers":[{"name":"jeremie.charrier.ctr","email":"jeremie.charrier.ctr@proof.com"},{"name":"benjamin.sleek","email":"benjamin.sleek@proof.com"},{"name":"nalgenewaterbottle","email":"jonathan.lewey@proof.com"}],"homepage":"https://github.com/proof/x401-workers","bugs":{"url":"https://github.com/proof/x401-workers/issues"},"dist":{"shasum":"34f3d94d8c35d4a6921c7603dcd375e69757497c","tarball":"https://registry.npmjs.org/@proof.com/x401-workers/-/x401-workers-0.1.0.tgz","fileCount":43,"integrity":"sha512-MK5r5WhTlORHSpvwHi9MpCbRVqwGZJ/FWLyKNVX27NHfH1auqqpjI8RXMOo2FIjnQlAONfdVlG9WPyxmHJeUuw==","signatures":[{"sig":"MEQCIGMWNqotHy8OES6lw/iwKd6RjyTabhrVcebkl2qcHOOzAiAShYEiv1kxKH32KeLzV1NerrPnYiW1NfsDn4Qjqy5ssA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIDx2CSAF9qj6urKFZworIYQaW9RtJCZXUXNhUM2HY/OFAiEArzaC4/SQGPJQeBAmwh6hAR5r8JldXDx8CFKL01U6kuU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":49104},"type":"module","engines":{"node":">=22.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./hono":{"types":"./dist/hono.d.ts","default":"./dist/hono.js"}},"gitHead":"14e28f5de47392420812af71c5e77d90adee3d3a","scripts":{"lint":"eslint . --fix","test":"node --experimental-test-module-mocks --test tests/*.test.ts","build":"rm -rf dist && tsc -p tsconfig.build.json","format":"prettier --write .","prepare":"npm run build","publint":"publint --pack npm","check-all":"yarn format && yarn lint && yarn typecheck && yarn test && yarn publint","typecheck":"tsc --noEmit","lint:check":"eslint .","format:check":"prettier --check ."},"_npmUser":{"name":"jeremie.charrier.ctr","email":"jeremie.charrier.ctr@proof.com"},"repository":{"url":"git+ssh://git@github.com/proof/x401-workers.git","type":"git"},"_npmVersion":"11.11.0","description":"x401 middleware for Cloudflare Workers.","directories":{},"sideEffects":false,"_nodeVersion":"24.14.1","dependencies":{"@proof.com/x401-node":"^0.3.3","@proof.com/proof-vc-common":"^0.6.2","@proof.com/proof-vc-server":"^0.6.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"yarn@4.17.0","devDependencies":{"hono":"^4.10.0","jose":"^6.2.4","eslint":"^10.5.0","publint":"^0.3.21","prettier":"^3.8.4","typescript":"^6.0.3","@types/node":"^24.13.2","typescript-eslint":"^8.62.0","@cloudflare/workers-types":"^5.20261010.1","prettier-plugin-packagejson":"^3.0.2","eslint-plugin-unused-imports":"^4.4.1"},"peerDependencies":{"hono":">=4"},"peerDependenciesMeta":{"hono":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/x401-workers_0.1.0_1792254645498_0.31064400860000974","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"_id":"@proof.com/x401-workers@0.2.0","bugs":{"url":"https://github.com/proof/x401-workers/issues"},"dist":{"shasum":"4321f1f59ca8ee92008f86d8273d1ec12728a352","tarball":"https://registry.npmjs.org/@proof.com/x401-workers/-/x401-workers-0.2.0.tgz","fileCount":43,"integrity":"sha512-KaWMsRl/84wkTfEjLV2fXOHdBjYPNhbF2/lkIR5uWrxsVEdQ5W5lDCkGhiaQ9Iv7XmAvJLnLhLIcXWy7vcIEHw==","signatures":[{"sig":"MEYCIQD+GzCGvNuTnRmTaS32j4yYlM82WJ0Sx9kGBr3cgsWdBwIhAPi2vnfIPYB+MKmUEdjSjooa3KDXTMOn2lLcwc8GrUsB","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDnJfTl5Bv6YUZXUW/I6/IWsEnhM/GnrEITHn/BEpFGZAiEAlQI8l60R+ge1VPC/uFMzPsIbE/fOsi5ZfJxRvkQC+I4="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@proof.com%2fx401-workers@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":51483},"name":"@proof.com/x401-workers","type":"module","author":{"name":"Jeremie Charrier","email":"jeremie.charrier@proof.com"},"engines":{"node":">=22.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./hono":{"types":"./dist/hono.d.ts","default":"./dist/hono.js"}},"gitHead":"2a8fa71732bc8e7b772a58de997f8fd7ac465aaa","license":"Apache-2.0","scripts":{"lint":"eslint . --fix","test":"node --experimental-test-module-mocks --test tests/*.test.ts","build":"rm -rf dist && tsc -p tsconfig.build.json","format":"prettier --write .","prepare":"npm run build","publint":"publint --pack npm","check-all":"yarn format && yarn lint && yarn typecheck && yarn test && yarn publint","typecheck":"tsc --noEmit","lint:check":"eslint .","format:check":"prettier --check ."},"version":"0.2.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"c687b359-07a4-4536-9b23-9660ea692755"}},"homepage":"https://github.com/proof/x401-workers","keywords":["x401","Cloudflare Workers","Verifiable Presentation","OID4VP","Agent","Verifier","Proof","Proof.com"],"repository":{"url":"git+ssh://git@github.com/proof/x401-workers.git","type":"git"},"_npmVersion":"11.11.0","description":"x401 middleware for Cloudflare Workers.","directories":{},"maintainers":[{"name":"jeremie.charrier.ctr","email":"jeremie.charrier.ctr@proof.com"},{"name":"benjamin.sleek","email":"benjamin.sleek@proof.com"},{"name":"nalgenewaterbottle","email":"jonathan.lewey@proof.com"}],"sideEffects":false,"_nodeVersion":"24.14.1","dependencies":{"@proof.com/x401-node":"^0.3.3","@proof.com/proof-vc-common":"^0.7.0","@proof.com/proof-vc-server":"^0.7.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"yarn@4.17.0","devDependencies":{"hono":"^4.10.0","jose":"^6.2.4","eslint":"^10.5.0","publint":"^0.3.21","prettier":"^3.8.4","typescript":"^6.0.3","@types/node":"^24.13.2","typescript-eslint":"^8.62.0","@cloudflare/workers-types":"^5.20261010.1","prettier-plugin-packagejson":"^3.0.2","eslint-plugin-unused-imports":"^4.4.1"},"peerDependencies":{"hono":">=4"},"peerDependenciesMeta":{"hono":{"optional":true}},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/x401-workers_0.2.0_1793103727037_0.8043161522179105"}}},"time":{"created":"2026-10-17T16:29:49.196Z","modified":"2026-10-27T12:22:07.975Z","0.0.0-stage":"2026-10-17T16:29:49.196Z","0.1.0":"2026-10-17T16:30:45.587Z","0.2.0":"2026-10-27T12:22:07.200Z"},"bugs":{"url":"https://github.com/proof/x401-workers/issues"},"author":{"name":"Jeremie Charrier","email":"jeremie.charrier@proof.com"},"license":"Apache-2.0","homepage":"https://github.com/proof/x401-workers","keywords":["x401","Cloudflare Workers","Verifiable Presentation","OID4VP","Agent","Verifier","Proof","Proof.com"],"repository":{"url":"git+ssh://git@github.com/proof/x401-workers.git","type":"git"},"description":"x401 middleware for Cloudflare Workers.","maintainers":[{"name":"jeremie.charrier.ctr","email":"jeremie.charrier.ctr@proof.com"},{"name":"benjamin.sleek","email":"benjamin.sleek@proof.com"},{"name":"nalgenewaterbottle","email":"jonathan.lewey@proof.com"}],"readme":"# x401-workers\n\nx401-workers lets your Cloudflare Worker require proof of identity on its endpoints.\n\nWhen a request arrives without proof, the Worker answers with an\n[x401](https://x401.proof.com/spec/latest/) proof request. The user presents their credential from\ntheir Proof Cloud Wallet, and your handler receives the verified credential.\n\nTo call those endpoints, use [x401-agent](https://github.com/proof/x401-agent) or\n[x401-cli](https://github.com/proof/x401-cli).\n\n- [Installation](#installation)\n- [Quickstart](#quickstart)\n- [Usage](#usage)\n  - [Add x401 to your Worker](#add-x401-to-your-worker)\n  - [Use Hono](#use-hono)\n  - [Read the user's claims](#read-the-users-claims)\n  - [Request signature for approval](#request-signature-for-approval)\n  - [Use x402](#use-x402)\n- [Options](#options)\n- [Responses](#responses)\n- [Links](#links)\n- [License](#license)\n\n## Installation\n\n```sh\nnpm install @proof.com/x401-workers @proof.com/proof-vc-server\n```\n\nEnable `nodejs_compat` in your Wrangler configuration:\n\n```jsonc\n{\n  \"compatibility_flags\": [\"nodejs_compat\"],\n}\n```\n\n## Quickstart\n\nCreate a Worker from the template, deploy it to `workers.dev` and enroll it as a sandbox Verifier:\n\n```sh\nnpm create cloudflare@latest -- my-verifier --template=proof/x401-workers/template\ncd my-verifier\nnpm run setup\n```\n\nProof emails an activation link to the address you enter during setup. After you activate the\nVerifier, request the endpoint that setup printed with x401-cli:\n\n```sh\nx401-cli login --sandbox\nx401-cli fetch \"https://my-verifier-sandbox.<your-subdomain>.workers.dev/protected\"\n```\n\nThe user presents their credential, and the Worker answers with the verified claims:\n\n```json\n{\n  \"proof_id_default\": [\n    {\n      \"credentialType\": \"ProofCredentialV1\",\n      \"format\": \"dc+sd-jwt\",\n      \"nonce\": \"afc8ffc9-e6cc-4a1d-9cd7-0c0635f264df\",\n      \"givenName\": \"Alexander J\",\n      \"familyName\": \"Sample\",\n      \"isOver18\": true\n    }\n  ]\n}\n```\n\n## Usage\n\n### Add x401 to your Worker\n\nYour Verifier's ID is the URL where your Worker serves its public key. Generate an ES256 signing\nkey and store it as the `SIGNING_JWK` Worker secret:\n\n```sh\nnode -e 'const k = crypto.generateKeyPairSync(\"ec\", { namedCurve: \"P-256\" }); console.log(JSON.stringify(k.privateKey.export({ format: \"jwk\" })))' > signing-key.json\nwrangler secret put SIGNING_JWK < signing-key.json\n```\n\nAdd the nonce table to your D1 migrations:\n\n```sql\nCREATE TABLE x401_nonces (\n  nonce TEXT PRIMARY KEY,\n  expires_at INTEGER NOT NULL\n);\n\nCREATE INDEX x401_nonces_expires_at ON x401_nonces (expires_at);\n```\n\nServe the client metadata document and wrap the endpoint with `withX401`:\n\n```ts\nimport {\n  agentsTrustListUrl,\n  clientMetadataDocument,\n  d1NonceStore,\n  withX401,\n  type X401Options,\n} from \"@proof.com/x401-workers\";\n\ntype Env = { DB: D1Database; SIGNING_JWK: string };\n\nconst options = (env: Env): X401Options => ({\n  clientId: \"https://example.com/.well-known/proof-client.json\",\n  privateKeyFactory: () => JSON.parse(env.SIGNING_JWK),\n  nonceStore: d1NonceStore(env.DB),\n  scope: \"urn:proof:params:scope:verifiable-credentials:basic\",\n  environment: \"sandbox\",\n  expectedOrigins: [agentsTrustListUrl(\"sandbox\")],\n});\n\nexport default {\n  async fetch(request: Request, env: Env) {\n    const { pathname } = new URL(request.url);\n    if (pathname === \"/.well-known/proof-client.json\") {\n      return clientMetadataDocument({ ...options(env), clientName: \"My API\" });\n    }\n    if (pathname === \"/protected\") {\n      return withX401(\n        async (_request, presentation) =>\n          Response.json(presentation.proof_id_default?.[0]?.toJSON()),\n        () => options(env),\n      )(request);\n    }\n    return new Response(\"Not found\", { status: 404 });\n  },\n};\n```\n\nDeploy the Worker, and enroll it on Proof with the email that receives the activation link. Use\n`\"production\"` instead of `\"sandbox\"` when going live.\n\n```sh\nnpx @proof.com/proof-vc-server enroll https://example.com/.well-known/proof-client.json --email admin@example.com --key signing-key.json --environment sandbox\n```\n\n### Use Hono\n\n`x401` sets the verified credentials as `c.var.x401`. `Env` and `options` are the ones above.\n\n```ts\nimport { Hono } from \"hono\";\nimport { clientMetadataDocument } from \"@proof.com/x401-workers\";\nimport { x401, type X401Variables } from \"@proof.com/x401-workers/hono\";\n\nconst app = new Hono<{ Bindings: Env; Variables: X401Variables }>();\n\napp.get(\"/.well-known/proof-client.json\", (c) =>\n  clientMetadataDocument({ ...options(c.env), clientName: \"My API\" }),\n);\napp.use(\n  \"/protected/*\",\n  x401<{ Bindings: Env }>((c) => options(c.env)),\n);\napp.get(\"/protected\", (c) =>\n  c.json(c.var.x401.proof_id_default?.[0]?.toJSON()),\n);\n\nexport default app;\n```\n\n### Read the user's claims\n\nThe handler receives the verified credentials keyed by credential id. The `basic` scope returns\n`proof_id_default`. `Env` and `options` are the ones above.\n\n```ts\nimport { ProofCredentialV1 } from \"@proof.com/proof-vc-server\";\n\nwithX401(\n  async (_request, presentation) => {\n    const credential = presentation.proof_id_default?.[0];\n    if (!(credential instanceof ProofCredentialV1)) {\n      return new Response(\"Unexpected credential\", { status: 400 });\n    }\n    return Response.json({\n      name: `${credential.givenName} ${credential.familyName}`,\n      isOver18: credential.isOver18,\n    });\n  },\n  () => options(env),\n);\n```\n\n### Request signature for approval\n\nYou can request a signature from a user along with their presented credential. Request a signature\nif you require the user to approve a payment mandate, a wire instruction, or anything your business\nneeds human approval on. Pass it as `transactionData`. `Env` and `options` are the ones above.\n\n```ts\nimport { TX_DATA_TYPE, transactionData } from \"@proof.com/proof-vc-server\";\n\nwithX401(\n  async (_request, presentation) => {\n    const order = presentation.proof_id_default?.[0]?.getTransactionData(\n      TX_DATA_TYPE.PAYMENT_ITEMIZED,\n    );\n    return Response.json(order);\n  },\n  () => ({\n    ...options(env),\n    transactionData: transactionData.paymentItemized({\n      currency: \"USD\",\n      items: [{ quantity: 1, unit_cost: 12.5, label: \"Book\" }],\n    }),\n  }),\n);\n```\n\n### Use x402\n\nYou can choose to pay for x401 presentations with x402. Pass an x402-paying `fetch`, which\nreplaces the `fetch` used to call Proof. `X402_PRIVATE_KEY` is a Worker secret holding the payer's `0x…` key, and `Env` and\n`options` are the ones above. [Learn how to pay for verifications with x402](https://dev.proof.com/docs/x401-signatures).\n\n```ts\nimport { x402Client } from \"@x402/core/client\";\nimport { ExactEvmScheme } from \"@x402/evm/exact/client\";\nimport { wrapFetchWithPayment } from \"@x402/fetch\";\nimport { privateKeyToAccount } from \"viem/accounts\";\n\nconst payments = new x402Client().register(\n  \"eip155:*\",\n  new ExactEvmScheme(privateKeyToAccount(env.X402_PRIVATE_KEY)),\n);\n\nwithX401(\n  async () => new Response(\"OK\"),\n  () => ({\n    ...options(env),\n    fetch: wrapFetchWithPayment(fetch, payments),\n  }),\n);\n```\n\n## Options\n\n| Option              | Required | Description                                                                                                     |\n| ------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |\n| `clientId`          | yes      | The URL of your client metadata document                                                                        |\n| `privateKeyFactory` | yes      | Returns the ES256 private JWK whose public key the document publishes                                           |\n| `nonceStore`        | yes      | `d1NonceStore(db)` or `kvNonceStore(kv)`                                                                        |\n| `scope`             | yes      | The credential scope; see [Scopes and claims](https://dev.proof.com/docs/verify-a-credential#scopes-and-claims) |\n| `expectedOrigins`   | yes      | `[agentsTrustListUrl(environment)]`                                                                             |\n| `environment`       | no       | `\"production\"` (default) or `\"sandbox\"`                                                                         |\n| `transactionData`   | no       | Transaction data the user approves with their credential                                                        |\n| `fetch`             | no       | Replaces the `fetch` used to call Proof                                                                         |\n\n## Responses\n\n| Name                                       | Description                                 |\n| ------------------------------------------ | ------------------------------------------- |\n| No `PROOF-RESPONSE`                        | `401` with `PROOF-REQUEST`                  |\n| Malformed, expired or unfetchable response | `400` with `PROOF-RESULT: invalid_response` |\n| Presentation rejected by Proof             | `401` with `PROOF-RESULT: invalid_result`   |\n| Nonce unknown, expired or reused           | `401` with `PROOF-RESULT: invalid_nonce`    |\n\n## Links\n\n- [Read the x401 specification](https://x401.proof.com/spec/latest/)\n- [Call x401 endpoints in code with x401-agent](https://github.com/proof/x401-agent)\n- [Call x401 endpoints from a terminal with x401-cli](https://github.com/proof/x401-cli)\n\n## License\n\n[Apache-2.0](LICENSE)\n","readmeFilename":"README.md"}