{"_id":"@assaylabs/escrow-gate","name":"@assaylabs/escrow-gate","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@assaylabs/escrow-gate","version":"0.1.0","description":"Express middleware for gating requests with Assay trust assessments.","type":"module","main":"dist/index.js","types":"dist/index.d.ts","license":"MIT","repository":{"type":"git","url":"git+https://github.com/Grandionn/assay-protocol.git"},"keywords":["assay","trust","ai-agents","erc-8004","escrow","middleware","express","base"],"gitHead":"59fe3129cf14c774fecf89a232d66bf9af6a2c3a","_id":"@assaylabs/escrow-gate@0.1.0","bugs":{"url":"https://github.com/Grandionn/assay-protocol/issues"},"homepage":"https://github.com/Grandionn/assay-protocol#readme","_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-LvLgaqWEJFgjftHRqnGENImHRkCF+rtnHzZxK9Ky5mKs9FWU+llcCqsMi18Sw7iBz2xiFRHYvuIxw/+zuinmmA==","shasum":"da6f32dcf3d860fa8f8505e11e65195ce31911f9","tarball":"https://registry.npmjs.org/@assaylabs/escrow-gate/-/escrow-gate-0.1.0.tgz","fileCount":4,"unpackedSize":9673,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFfBZrby0m0/gH7gIVNIFzjeFE+p55/RxUNZhFKWizARAiAIFL0vYZIUik6/PIwoiwrcEWIHrGjsTqqmPmGRwhRTpg=="}]},"_npmUser":{"name":"grandion","email":"granthverma2005@gmail.com"},"directories":{},"maintainers":[{"name":"grandion","email":"granthverma2005@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/escrow-gate_0.1.0_1779454191805_0.672918573395165"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-22T12:49:51.668Z","0.1.0":"2026-05-22T12:49:51.980Z","modified":"2026-05-22T12:49:52.259Z"},"maintainers":[{"name":"grandion","email":"granthverma2005@gmail.com"}],"description":"Express middleware for gating requests with Assay trust assessments.","homepage":"https://github.com/Grandionn/assay-protocol#readme","keywords":["assay","trust","ai-agents","erc-8004","escrow","middleware","express","base"],"repository":{"type":"git","url":"git+https://github.com/Grandionn/assay-protocol.git"},"bugs":{"url":"https://github.com/Grandionn/assay-protocol/issues"},"license":"MIT","readme":"# @assaylabs/escrow-gate\n\nExpress middleware for gating requests with Assay trust assessments.\n\nBefore an app pays, delegates to, or routes work toward an AI agent, it can require a minimum metadata-quality trust threshold from Assay Discovery.\n\n## Install\n\n```bash\nnpm install @assaylabs/escrow-gate\n```\n\n## Quick Start\n\n```ts\nimport express from 'express';\nimport { trustGate } from '@assaylabs/escrow-gate';\n\nconst app = express();\napp.use(express.json());\n\napp.post(\n  '/jobs',\n  trustGate({ minScore: 60 }),\n  (req, res) => {\n    res.json({ ok: true, trust: req.assayTrust });\n  },\n);\n```\n\nBy default, the middleware looks for an agent address in these locations:\n\n- `req.body.agentAddress`\n- `req.body.address`\n- `req.body.agent`\n- `req.params.agentAddress`\n- `req.params.address`\n- `req.query.agentAddress`\n- `req.query.address`\n- `req.headers['x-agent-address']`\n\nIf the agent's `trustAssessment` is below the required threshold, the middleware returns `403`.\n\n## How It Works\n\n`trustGate()` calls the Assay Discovery API and fetches the target agent record from:\n\n```txt\nGET https://assay-discovery-api.onrender.com/agents/:address\n```\n\nIt then reads the `trustAssessment` field and compares it to `minScore`.\n\nThis is different from the on-chain Assay Score. `trustAssessment` is a metadata-quality and profile-completeness signal used for discovery and gating, especially for ERC-8004 indexed agents that may not yet have settled Assay escrows.\n\n## Usage\n\n### Gate requests by default threshold\n\n```ts\napp.use(trustGate());\n```\n\nDefault threshold: `60`\n\n### Require a higher threshold\n\n```ts\napp.post('/settle', trustGate({ minScore: 75 }), handler);\n```\n\n### Use a custom Discovery API URL\n\n```ts\napp.use(\n  trustGate({\n    minScore: 70,\n    apiUrl: 'https://my-assay-proxy.example.com',\n  }),\n);\n```\n\n### Extract the address from a custom request shape\n\n```ts\napp.post(\n  '/delegate',\n  trustGate({\n    resolveAddress: (req) => req.body?.agent?.wallet,\n  }),\n  handler,\n);\n```\n\n### Attach the result under a custom property\n\n```ts\napp.use(\n  trustGate({\n    attachProperty: 'trustGateResult',\n  }),\n);\n```\n\n## Middleware Result\n\nOn success, the middleware attaches this object to the request. By default it is available at `req.assayTrust`.\n\n```ts\n{\n  address: string;\n  trustAssessment: number;\n  minScore: number;\n  allowed: boolean;\n  agent: {\n    address?: string;\n    name?: string;\n    trustAssessment?: number;\n    assayScore?: number;\n    stake?: number | string;\n    capability?: string;\n    erc8004AgentId?: number | null;\n  };\n}\n```\n\n## Error Responses\n\n### Missing agent address\n\n```json\n{\n  \"error\": \"Agent address is required for trustGate middleware.\"\n}\n```\n\n### Agent below threshold\n\n```json\n{\n  \"error\": \"Agent trust assessment is below the required threshold.\",\n  \"address\": \"erc8004-35\",\n  \"trustAssessment\": 42,\n  \"minScore\": 60\n}\n```\n\n### Discovery API unavailable\n\n```json\n{\n  \"error\": \"Failed to validate agent trust assessment.\",\n  \"details\": \"...\"\n}\n```\n\n## Options\n\n```ts\ntype TrustGateOptions = {\n  minScore?: number;\n  apiUrl?: string;\n  addressFields?: string[];\n  resolveAddress?: (req) => string | null | undefined | Promise<string | null | undefined>;\n  attachProperty?: string;\n  allowMissingAddress?: boolean;\n  timeoutMs?: number;\n};\n```\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-ceebe9843117ad69b8c69b29b9c356a0"}