{"_id":"@ai-universe/receipt-utils","name":"@ai-universe/receipt-utils","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@ai-universe/receipt-utils","version":"1.0.0","description":"Signed receipt issuance and verification helpers built on jose","type":"module","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"build":"tsc","prepare":"node ../../scripts/run-build-if-ready.mjs","test":"jest","clean":"rm -rf dist"},"dependencies":{"jose":"^5.9.4"},"devDependencies":{"@types/jest":"^29.5.12","jest":"^29.7.0","ts-jest":"^29.1.2","typescript":"^5.9.3"},"keywords":["receipts","jose","jws","jwks","ai-universe"],"author":{"name":"AI Universe Team"},"license":"MIT","publishConfig":{"access":"public"},"gitHead":"ad5c09e00bd108e9444ea57cfa2a2c85fd8fccda","_id":"@ai-universe/receipt-utils@1.0.0","_nodeVersion":"20.19.4","_npmVersion":"8.19.4","dist":{"integrity":"sha512-cShxFsUytPFM57XQ9z9z66oN0WzIXj/bG1XbopeeAEcA0OLHMgDLcwprH7bS8kehTmGOsUxMBBsK9VXGUxXJpA==","shasum":"cd806445fe671e22541df09b1605534d59449cef","tarball":"https://registry.npmjs.org/@ai-universe/receipt-utils/-/receipt-utils-1.0.0.tgz","fileCount":25,"unpackedSize":40417,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDwja9uGad5qVtRm5viFMyUg/bUAcZBwRZsKi0fqonwDQIgfs4v2ICoEmYuzd2/pDp4CDC3haO0Ki2I0jlkPIdG+Uw="}]},"_npmUser":{"name":"jleechan","email":"jleechan+npm@gmail.com"},"directories":{},"maintainers":[{"name":"jleechan","email":"jleechan+npm@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/receipt-utils_1.0.0_1764733114531_0.8777191787358032"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-03T03:38:34.427Z","1.0.0":"2025-12-03T03:38:34.749Z","modified":"2025-12-03T03:38:35.053Z"},"maintainers":[{"name":"jleechan","email":"jleechan+npm@gmail.com"}],"description":"Signed receipt issuance and verification helpers built on jose","keywords":["receipts","jose","jws","jwks","ai-universe"],"author":{"name":"AI Universe Team"},"license":"MIT","readme":"# @ai-universe/receipt-utils\n\nTypeScript helpers for issuing and verifying signed receipts using [`jose`](https://github.com/panva/jose). The library prefers asymmetric Ed25519/ES256 keys, publishes JWKS documents for verifiers, and enforces freshness/field validation when receipts are checked.\n\n## Features\n\n- 🔐 Compact JWS receipts with `kid` headers for JWKS-based verification\n- 🗝️ Ed25519 key generation and JWK/JWKS exports for publishing at `.well-known/jwks.json`\n- ✅ Optional freshness, nonce, request ID, and body-hash checks during verification\n- 🧩 Typed receipt payloads that match the suggested server response pattern\n\n## Usage\n\n### Installation\n\nFrom the repository root, install dependencies and build the package:\n\n```bash\ncd shared-libs/packages/receipt-utils\nnpm install\nnpm run build\n```\n\n### Issue a receipt\n\n```typescript\nimport { generateEd25519KeyPair, signReceipt } from '@ai-universe/receipt-utils';\n\nconst { privateKey, jwks } = await generateEd25519KeyPair('receipt-key');\n\nconst receiptJws = await signReceipt(\n  {\n    req_id: 'uuid',\n    uid: 'DLJwXoPZSQUzlb6JQHFOmi0HZWB2',\n    op: 'secondOpinion.ask',\n    models: [{ id: 'gpt-4o', tokens: 17551, cost: 0.093225 }],\n    hash: 'sha256:<hex of response body>',\n    nonce: 'client-supplied'\n  },\n  privateKey,\n  { kid: 'receipt-key', alg: 'EdDSA' }\n);\n```\n\n### Verify a receipt\n\n```typescript\nimport { verifyReceipt } from '@ai-universe/receipt-utils';\n\nconst verification = await verifyReceipt(receiptJws, jwks, {\n  expectedKid: 'receipt-key',\n  expectedAlg: 'EdDSA',\n  expectedReqId: 'uuid',\n  expectedNonce: 'client-supplied',\n  expectedHash: 'sha256:<hex of response body>',\n  // Default freshness window is 5 minutes with 10 seconds of future skew allowance\n});\n\nconsole.log(verification.payload.ts); // ISO timestamp captured at signing time\n```\n\nPublish the `jwks` from `generateEd25519KeyPair` (or `createPublicJwks`) at an endpoint such as `/\\.well-known/jwks.json` so clients can resolve the `kid` used in the JWS header.\n","readmeFilename":"README.md","_rev":"1-cd4c55a86a26de3c38c3d32f1467bf0d"}