Skip to main content

xrpl-x402-middleware

Canonical x402 v2 HTTP and MCP resource-server integration for XRPL.

from xrpl_x402_middleware import PaymentMiddlewareASGI, require_payment

app.add_middleware(
    PaymentMiddlewareASGI,
    routes={
        "GET /premium": require_payment(
            pay_to="rMerchant",
            network="xrpl:1",
            xrp_drops=1000,
            resource="https://merchant.example/premium",
            description="Premium data",
            service_name="Example merchant",
            tags=["premium", "xrpl"],
        )
    },
    facilitator_url="http://127.0.0.1:8000",
    bearer_token="replace-with-your-token",
)

The middleware verifies first, buffers the successful handler response, settles, and only then releases protected bytes. Handler errors are not settled. For a settlement_pending result, the upstream x402 resource server retries the identical settlement envelope exactly once. If it is still pending, a later identical request resumes settlement from the cached protected response without rerunning the handler or exposing protected bytes early.

Unsafe methods require the payment-identifier extension. Configure RedisResourceResponseStore so a matching retry can recover the handler result without repeating side effects. The store preserves exact response bytes and retains them for at least maxTimeoutSeconds plus a safety margin (with a 600-second minimum by default), so a still-valid retry cannot repeat the handler after cache expiry.

Before facilitator verification, the middleware rejects payload resource metadata that does not match the authoritative HTTP route or MCP tool. Recovery fingerprints also include the HTTP method, effective URL and query, and a digest of the exact request body; MCP fingerprints include the exact tool name and a digest of its canonical arguments. Raw request bodies and tool arguments are not persisted in the binding record.

Use create_xrpl_mcp_payment_wrapper for paid MCP tools. It composes the official x402 MCP wrapper, registers XRPL exact, preserves extension data, and requires payment identifiers plus RedisResourceResponseStore for non-idempotent tools. Install the helper with pip install "xrpl-x402-middleware[mcp]".

Download files

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

Source Distribution

xrpl_x402_middleware-0.2.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

xrpl_x402_middleware-0.2.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file xrpl_x402_middleware-0.2.0.tar.gz.

File metadata

  • Download URL: xrpl_x402_middleware-0.2.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for xrpl_x402_middleware-0.2.0.tar.gz
Algorithm Hash digest
SHA256 243bb4f628ec61dba171b42bab4e8ef381c40a438a46490d013783c070d79dd2
MD5 2ce30ecb72f8d21b799e2da28be04fc1
BLAKE2b-256 b88c6ae9a286341e32d8c6e2212cc55367288605c10b127b7bdbd1b8b10f8dcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for xrpl_x402_middleware-0.2.0.tar.gz:

Publisher: publish-package.yml on lgcarrier/xrpl-x402-stack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xrpl_x402_middleware-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xrpl_x402_middleware-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7b38baaff5f00446a1d50c9b256bb61e5c338343892c0ec686b222dbc235a45
MD5 d769dd0f0d81550af869744ef79daa05
BLAKE2b-256 aec8ed786ad1e6c1b6fd0b75a20d1285aee510b5ac8b5e6827b42089fa2fcbd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for xrpl_x402_middleware-0.2.0-py3-none-any.whl:

Publisher: publish-package.yml on lgcarrier/xrpl-x402-stack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page