@oceanrun/trustgate
v0.1.0
Published
Express middleware for TrustGate — ERC-8004 trust scoring for x402 agents
Maintainers
Readme
trustgate-middleware
Express middleware for TrustGate — ERC-8004 trust scoring for x402 agents. One import, one line.
Install
npm install trustgate-middlewareUsage
import express from 'express'
import { trustGate } from 'trustgate-middleware'
const app = express()
app.use(trustGate())
app.get('/api/data', (req, res) => {
// Only reached if the agent's wallet passed the trust check
res.json({ data: 'protected' })
})The middleware reads the agent's wallet address from the x-agent-address header. If no header is present, the request passes through — only requests with a wallet address are gated.
Custom address extraction
app.use(trustGate({
addressFn: (req) => req.body?.walletAddress,
threshold: 6.0,
minStake: 500,
}))Non-Express usage
import { checkTrust } from 'trustgate-middleware'
const decision = await checkTrust('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
console.log(decision.trusted, decision.score, decision.reasons)Custom block handler
app.use(trustGate({
onBlocked: (req, res, decision) => {
res.status(403).json({
error: 'Agent not trusted',
score: decision.score,
reasons: decision.reasons,
})
}
}))Fail-open mode
If TrustGate is unreachable, allow requests instead of blocking:
app.use(trustGate({ failOpen: true }))Options
| Option | Type | Default | Description |
|---|---|---|---|
| endpoint | string | https://trust-gate-production.up.railway.app | TrustGate API URL |
| threshold | number | 4.0 | Minimum composite score to pass |
| minStake | number | 100 | Minimum ERC-8004 stake in USD |
| addressHeader | string | x-agent-address | Header to read wallet address from |
| addressFn | (req) => string | — | Custom function to extract address |
| onBlocked | (req, res, decision) => void | — | Custom 403 handler |
| failOpen | boolean | false | Allow requests if TrustGate is down |
| timeoutMs | number | 5000 | Request timeout in milliseconds |
Links
- Live API: https://trust-gate-production.up.railway.app
- Source: https://github.com/oceanrun/trust-gate
- Pricing: $0.01 USDC per check on Base mainnet via x402
License
MIT
