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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
243bb4f628ec61dba171b42bab4e8ef381c40a438a46490d013783c070d79dd2
|
|
| MD5 |
2ce30ecb72f8d21b799e2da28be04fc1
|
|
| BLAKE2b-256 |
b88c6ae9a286341e32d8c6e2212cc55367288605c10b127b7bdbd1b8b10f8dcc
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xrpl_x402_middleware-0.2.0.tar.gz -
Subject digest:
243bb4f628ec61dba171b42bab4e8ef381c40a438a46490d013783c070d79dd2 - Sigstore transparency entry: 2704818767
- Sigstore integration time:
-
Permalink:
lgcarrier/xrpl-x402-stack@00a6ffce2c9e1cffefa5e2ba057401782e0b3b00 -
Branch / Tag:
refs/tags/middleware-v0.2.0 - Owner: https://github.com/lgcarrier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@00a6ffce2c9e1cffefa5e2ba057401782e0b3b00 -
Trigger Event:
push
-
Statement type:
File details
Details for the file xrpl_x402_middleware-0.2.0-py3-none-any.whl.
File metadata
- Download URL: xrpl_x402_middleware-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7b38baaff5f00446a1d50c9b256bb61e5c338343892c0ec686b222dbc235a45
|
|
| MD5 |
d769dd0f0d81550af869744ef79daa05
|
|
| BLAKE2b-256 |
aec8ed786ad1e6c1b6fd0b75a20d1285aee510b5ac8b5e6827b42089fa2fcbd1
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xrpl_x402_middleware-0.2.0-py3-none-any.whl -
Subject digest:
f7b38baaff5f00446a1d50c9b256bb61e5c338343892c0ec686b222dbc235a45 - Sigstore transparency entry: 2704818812
- Sigstore integration time:
-
Permalink:
lgcarrier/xrpl-x402-stack@00a6ffce2c9e1cffefa5e2ba057401782e0b3b00 -
Branch / Tag:
refs/tags/middleware-v0.2.0 - Owner: https://github.com/lgcarrier
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@00a6ffce2c9e1cffefa5e2ba057401782e0b3b00 -
Trigger Event:
push
-
Statement type: