TRACE trust scoring extension for x402 payment middleware
Project description
x402-trace-trust
TRACE trust scoring extension for x402 payment middleware.
Overview
This package provides a drop-in x402 extension that integrates with the TRACE API to evaluate agent trust scores before processing payments. Untrusted agents (score below threshold, active flags) are rejected with HTTP 402 before any payment is settled.
Installation
pip install x402-trace-trust
Quick Start
from x402.extensions.trace_trust import TraceTrustExtension
from x402.server import x402_server
# Create the TRACE trust extension
trace_ext = TraceTrustExtension(
api_key="sk_trace_...", # Your TRACE API key
min_score=0.35, # Minimum trust score (0.0-1.0)
fail_closed=True, # Reject on API failure
)
# Add to your x402 server
app = x402_server(
extensions=[trace_ext],
# ... other x402 config
)
How It Works
- Payment verified → x402 calls
on_after_verifyhook - TRACE API called →
POST /v1/scorewith payer's wallet address - Decision made → If
routing_decisionisHOLD/INVESTIGATEor score <min_score→ HTTP 402 - Payment proceeds → If
ROUTEorROUTE_WITH_CAUTION
Routing Decisions
| Decision | Score Range | Action |
|---|---|---|
ROUTE |
≥ 0.65 | Process payment |
ROUTE_WITH_CAUTION |
0.35 – 0.65 | Process with monitoring |
HOLD |
< 0.35 | Reject (402) |
INVESTIGATE |
Any + flags | Reject (402) |
Configuration
| Parameter | Default | Description |
|---|---|---|
api_key |
Required | Your TRACE API key |
min_score |
0.35 |
Minimum score to allow routing |
fail_closed |
True |
Reject on API failure |
api_url |
https://traceapi-xxf56.ondigitalocean.app/v1/score |
TRACE API endpoint |
Fail-Closed vs Fail-Open
- fail_closed=True (default): If TRACE API is unreachable, payment is rejected. Safer for high-value transactions.
- fail_closed=False: If TRACE API is unreachable, payment is allowed. Use for non-critical flows.
Architecture
┌─────────────┐ x402 flow ┌──────────────┐
│ Client │ ─────────────────► │ x402 Server │
└─────────────┘ │ │
│ on_after_ │
│ verify │
└──────┬───────┘
│
▼
┌─────────────────────┐
│ TRACE Trust Ext. │
│ (this package) │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ TRACE API │
│ POST /v1/score │
└─────────────────────┘
Development
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest tests/
# Lint
ruff check .
# Format
ruff format .
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file x402_trace_trust-0.1.0.tar.gz.
File metadata
- Download URL: x402_trace_trust-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a661e09c02563a6da34b25995b8fdfb1a833971b70480ec24c41d38feb8d4ed
|
|
| MD5 |
84e24eadebb783ca2f7a8ccf0430a4e4
|
|
| BLAKE2b-256 |
bdf46bfcdd081cdd60fb860a5882d502f064c82cc2ec0e82b6145ccc0df8f16d
|
File details
Details for the file x402_trace_trust-0.1.0-py3-none-any.whl.
File metadata
- Download URL: x402_trace_trust-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ef84e467d3a2e0e8a638ba4fb03ee5356896e23c937df70e6502361e8c9714a
|
|
| MD5 |
1f45c9d3a26e8b1da9fefdfebb992f4d
|
|
| BLAKE2b-256 |
e8e3757583c304650027ca6428ea86209cc3e3b4020c70b696c81b3086ba87b1
|