Skip to main content

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

  1. Payment verified → x402 calls on_after_verify hook
  2. TRACE API calledPOST /v1/score with payer's wallet address
  3. Decision made → If routing_decision is HOLD/INVESTIGATE or score < min_score → HTTP 402
  4. Payment proceeds → If ROUTE or ROUTE_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

x402_trace_trust-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

x402_trace_trust-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

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

Hashes for x402_trace_trust-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7a661e09c02563a6da34b25995b8fdfb1a833971b70480ec24c41d38feb8d4ed
MD5 84e24eadebb783ca2f7a8ccf0430a4e4
BLAKE2b-256 bdf46bfcdd081cdd60fb860a5882d502f064c82cc2ec0e82b6145ccc0df8f16d

See more details on using hashes here.

File details

Details for the file x402_trace_trust-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for x402_trace_trust-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ef84e467d3a2e0e8a638ba4fb03ee5356896e23c937df70e6502361e8c9714a
MD5 1f45c9d3a26e8b1da9fefdfebb992f4d
BLAKE2b-256 e8e3757583c304650027ca6428ea86209cc3e3b4020c70b696c81b3086ba87b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page