agentscore-gate
v1.0.0
Published
Trust gate middleware for x402 services — check agent reputation before serving
Maintainers
Readme
@agentscore/gate
Trust gate middleware for x402 services. Check an AI agent's reputation score before serving requests.
AgentScore is the credit scoring system for the agent economy. Every x402 transaction is indexed, every wallet is scored, and any service can gate access based on trust.
Quick Start
npm install @agentscore/gateconst express = require('express');
const { trustGate } = require('@agentscore/gate');
const app = express();
// Reject agents with score below 50
app.use(trustGate({ minScore: 50 }));
app.get('/api/data', (req, res) => {
console.log(req.agentScore); // { score: 87, grade: 'A', ... }
res.json({ data: 'trusted response' });
});That's it. Five lines to add trust gating to any x402 service.
How It Works
- Agent makes a request to your service
- Middleware extracts the agent's wallet address
- Checks their AgentScore (cached, sub-millisecond after first lookup)
- Allows, warns, rate-limits, or rejects based on your threshold
Options
trustGate({
minScore: 50, // Minimum score (0-100). Default: 0
action: 'reject', // 'reject' | 'warn' | 'log' | 'rate-limit'
apiKey: 'your-key', // API key for production (recommended)
cacheTtlMs: 300000, // Cache TTL: 5 min default
failOpen: true, // Allow if score lookup fails
allowUnknown: true, // Allow agents with no history
unknownScore: 25, // Score for unknown agents
onBlock: (req, score, reason) => {
console.log(`Blocked: ${score?.address} (${reason})`);
},
})Actions
| Action | Behavior |
|--------|----------|
| reject | Returns 403 with score details and improvement guidance |
| warn | Allows request, adds X-AgentScore-Warning header |
| log | Allows request, logs low-score agents to console |
| rate-limit | Allows request, adds rate-limit reduction headers |
Direct Score Lookup
const { getScore, checkTrust } = require('@agentscore/gate');
// Get full score details
const score = await getScore('0xABC...');
console.log(score.grade); // 'A+'
// Simple trust check
const { allowed } = await checkTrust('0xABC...', 60);Scoring
AgentScore uses a 6-factor model based on on-chain x402 transaction history:
- Reliability (25%) — Success rate
- Volume (15%) — Transaction count
- Consistency (20%) — Regular activity pattern
- Diversity (15%) — Unique counterparties
- Recency (15%) — How recently active
- Tenure (10%) — Time in ecosystem
Grades: A+ (95+), A (85+), A- (75+), B+ (65+), B (55+), B- (45+), C+ (35+), C (25+), D (15+), F (<15)
Response Headers
When an agent passes the gate, these headers are added:
X-AgentScore— Numeric score (0-100)X-AgentScore-Grade— Letter grade
Rejection Response
When an agent is blocked:
{
"error": "Insufficient agent reputation",
"score": 32,
"grade": "C+",
"required": 50,
"message": "This service requires a minimum AgentScore of 50.",
"checkYourScore": "https://agentscore.sh/score/0xABC..."
}Zero Dependencies
This package has no dependencies. It uses native fetch (Node 18+).
