[Extension] Trust-Provider: behavioral trust scoring via onBeforeSettle hook
Problem
x402 settles payments between agents, but has no mechanism to evaluate whether the paying agent should be trusted before settlement occurs. A resource server currently has no way to reject settlement from agents with poor behavioral history, known abuse patterns, or insufficient trust data.
As the agent economy scales, settlement without trust evaluation creates risk:
- Agents with adversarial behavior patterns can make payments that complete before abuse is detected
- Resource servers have no way to apply graduated trust policies (strict, quorum, custom)
- There's no standard way to attach trust evidence to the settlement flow
Proposal
A trust-provider extension that uses the existing onBeforeSettle hook to gate settlement on behavioral trust scores from external trust providers.
How it works
import { trustProviderExtension } from '@x402/extensions/trust-provider';
const server = new x402ResourceServer({
extensions: {
'trust-provider': trustProviderExtension({
providers: [{
name: 'dominion-observatory',
url: 'https://dominion-observatory.sgdata.workers.dev',
evaluate: async (query) => {
const res = await fetch(url + '/api/agent-query/' + query.payer.agent_id);
const data = await res.json();
return {
decision: data.server.trust_score >= 60 ? 'PASS' : data.server.trust_score < 40 ? 'FAIL' : 'UNCERTAIN',
score: data.server.trust_score / 100,
};
}
}],
policy: { kind: 'strict' },
failureMode: 'fail-closed',
})
}
});Extension behavior
- onBeforeSettle hook: Queries configured trust providers in parallel with per-provider timeouts
- Aggregation: Applies STRICT (all must PASS), QUORUM (majority), or custom aggregation
- Gate decision:
- PASS: returns void (settlement proceeds)
- FAIL: returns { abort: true, reason: 'trust_evaluation_failed' }
- UNCERTAIN + fail-closed: aborts; fail-open: proceeds
- Advisory headers: Populates X-Trust-Decision, X-Trust-Score via enrichSettlementResponse
Wire types
Two wire types conformant with x402-trust-provider-interface v0.1:
- TrustQuery -- identifies the payer (agent_id/wallet), resource, amount, risk context
- TrustEvaluation -- provider response with decision (PASS/FAIL/UNCERTAIN), score (0-1), evidence URI, TTL
Reference provider
Dominion Observatory provides behavioral trust scores for 4,500+ MCP servers. Live today and can serve as the reference trust provider.
Implementation plan
Following the extension pattern from payment-identifier:
trust-provider/
index.ts -- Public exports
types.ts -- TrustQuery, TrustEvaluation, TrustDecision
schema.ts -- Zod schema for extension declaration
resourceServer.ts -- onBeforeSettle hook + enrichSettlementResponse
client.ts -- Client-side trust metadata attachment
utils.ts -- Aggregation functions (strict, quorum)Uses only the existing ResourceServerExtensionHooks.onBeforeSettle interface. No core changes needed. I have a working implementation ready and can open a PR.
Prior art
- x402-trust-provider-interface spec v0.1
- Testnet demo (Base Sepolia USDC)
- @dominion/trust-provider npm package
AI disclosure: This issue was drafted with AI assistance and reviewed before submission.
Source: x402-foundation/x402