@xrpay/x402 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,86 @@
1
1
  # @xrpay/x402
2
2
 
3
- XRPL x402 v2 payments and digital commerce for agents. Discover products from opted-in XRPay merchants, pay in XRP or RLUSD, and retrieve the purchased file, order and receipt. No XRPay account or merchant API key is required to browse or buy.
3
+ Charge for your own APIs, data, or services with XRP or RLUSD using x402 v2 on the XRP Ledger. **You do not need an XRPay account, merchant signup, API key, or a purchase from an XRPay merchant to use the core SDK.** Payments go directly to the XRPL recipient you choose.
4
+
5
+ The package also includes optional XRPay digital-commerce tools for discovering and buying products with managed orders, receipts, and private file delivery.
6
+
7
+ ## Which features need an XRPay account?
8
+
9
+ | Feature | XRPay account required? |
10
+ | --- | --- |
11
+ | Charge for your own API with `x402Middleware` | No |
12
+ | Pay a compatible exact XRPL x402 endpoint with `X402Client` | No |
13
+ | Use the public facilitator at `https://api.xrpay.it/api/x402` | No account or API key |
14
+ | Browse or buy from the XRPay digital-product catalog | No buyer account or merchant API key |
15
+ | Sell through XRPay's hosted catalog and use its managed orders, receipts, and file delivery | Yes, for the seller |
16
+
17
+ The core SDK is MIT licensed. Payments require XRPL wallets and network fees; Testnet uses test funds. This package implements the exact XRPL x402 scheme for XRP and RLUSD.
18
+
19
+ ## Quickstart: charge for your own API
20
+
21
+ Requires Node.js 20+. ESM and CommonJS exports are included. Create an empty project and install:
4
22
 
5
23
  ```sh
6
- npm install @xrpay/x402 xrpl
24
+ npm init -y
25
+ npm install @xrpay/x402 express
7
26
  ```
8
27
 
9
- Requires Node.js 20+. ESM and CommonJS exports are included.
28
+ Save this as `paid-api.mjs`:
29
+
30
+ ```js
31
+ // npm install @xrpay/x402 express
32
+ // Uses XRP Testnet. No XRPay account, API key, or product listing is required.
33
+ import express from "express";
34
+ import { x402Middleware } from "@xrpay/x402";
35
+
36
+ const payTo = process.env.XRPL_RECIPIENT_ADDRESS;
37
+ const challengeSecret = process.env.X402_CHALLENGE_SECRET;
38
+ if (!payTo || !challengeSecret) {
39
+ throw new Error("Set XRPL_RECIPIENT_ADDRESS and X402_CHALLENGE_SECRET (at least 32 characters).");
40
+ }
41
+
42
+ const app = express();
43
+ app.get("/api/hello", x402Middleware({
44
+ payTo,
45
+ amount: "0.001", // XRP per request, paid directly to your wallet.
46
+ currency: "XRP",
47
+ testnet: true,
48
+ challengeSecret,
49
+ facilitatorUrl: "https://api.xrpay.it/api/x402", // Public; no API key.
50
+ }), (_req, res) => res.json({ message: "Hello from your paid API!" }));
51
+
52
+ const port = Number(process.env.PORT ?? 3000);
53
+ app.listen(port, "127.0.0.1", () => {
54
+ console.log(`Paid API: http://127.0.0.1:${port}/api/hello (0.001 Testnet XRP)`);
55
+ });
56
+ ```
57
+
58
+ Generate a receiving wallet with the [XRPL Testnet faucet](https://xrpl.org/resources/dev-tools/xrp-faucets), select **Testnet**, and use its classic address below. The API server needs only the receiving address, not that wallet's seed.
59
+
60
+ ```sh
61
+ export XRPL_RECIPIENT_ADDRESS="rYOUR_FUNDED_TESTNET_ADDRESS"
62
+ export X402_CHALLENGE_SECRET="$(openssl rand -hex 32)"
63
+ node paid-api.mjs
64
+ ```
65
+
66
+ The same runnable file is included at `node_modules/@xrpay/x402/examples/paid-api.mjs`. `X402_CHALLENGE_SECRET` is a random secret you generate locally to authenticate payment challenges; it is **not an XRPay API key**. Store it privately and reuse it across server processes and restarts.
67
+
68
+ In another terminal:
69
+
70
+ ```sh
71
+ curl -i http://127.0.0.1:3000/api/hello
72
+ ```
73
+
74
+ An unpaid request returns **HTTP 402** with `PAYMENT-REQUIRED` and the exact payment terms. A compatible agent signs those terms and retries with `PAYMENT-SIGNATURE`. The middleware settles through the public facilitator, then returns **HTTP 200**, the API result, and a `PAYMENT-RESPONSE` receipt. For a runnable payment flow, follow [the agent client example](https://www.xrpay.it/docs/x402#agent).
75
+
76
+ You host the API and control its response. No XRPay product or merchant record is created, and these standalone payments do not create hosted storefront orders or file-delivery entitlements. Those are optional commerce features described below. You can also supply your own `XrplFacilitator` instance through the middleware's `facilitator` option.
77
+
78
+ The example binds to localhost and uses Testnet. For deployment, serve your API over HTTPS and configure the public resource URL when running behind a proxy. Use `testnet: false` and Mainnet wallets deliberately for real XRP payments. RLUSD requires the exact issuer and matching payer/recipient trust lines on the chosen network.
10
79
 
11
80
  ## Buy a digital product
12
81
 
82
+ This optional flow buys from XRPay merchants. Buyers do not need an XRPay account.
83
+
13
84
  ```js
14
85
  import { Client, Wallet } from "xrpl";
15
86
  import { XRPayCommerceClient, createRecoveryCredentials } from "@xrpay/x402/commerce";
@@ -61,6 +132,8 @@ Amounts in SDK spending caps are human XRP/RLUSD amounts. Caps cover authorizati
61
132
 
62
133
  ## MCP server
63
134
 
135
+ These seven tools cover XRPay hosted digital commerce. To charge for your own API independently, use `x402Middleware` from the quickstart above.
136
+
64
137
  ```sh
65
138
  npx -y @xrpay/x402
66
139
  ```
@@ -84,7 +157,9 @@ The MCP server prepares quotes and submits payments signed by your separate XRPL
84
157
 
85
158
  Recovery records are stored privately in `~/.xrpay/agent-commerce`; downloaded files are placed in its `downloads` directory. Back up this state to retain access. Optional environment variables: `XRPAY_COMMERCE_ORIGIN` and `XRPAY_COMMERCE_STATE_DIR`.
86
159
 
87
- ## Merchant setup
160
+ ## Merchant setup for hosted commerce
161
+
162
+ An XRPay merchant account is required for this hosted catalog and fulfillment integration. It is not required for the standalone payment SDK.
88
163
 
89
164
  In XRPay, open **Agent payments → Digital products** (`/dashboard/x402/products`). Create and publish a fixed-price digital product in a live storefront, turn off inventory tracking, upload the private delivery file, and enable agent availability. Each file can be up to 10 MiB; private file storage is capped at 100 MiB per merchant, including retained versions.
90
165
 
@@ -106,20 +181,11 @@ Base: `https://api.xrpay.it`.
106
181
 
107
182
  Create requires `Authorization: Bearer <random-token>` and `Idempotency-Key`. Generate at least 32 random bytes for the token, encoded as hex or base64url. The same bearer token authenticates all purchase operations. Only its SHA-256 is stored by XRPay. Signed retries add `PAYMENT-SIGNATURE`; 402 responses include `PAYMENT-REQUIRED`; paid responses include `PAYMENT-RESPONSE`. A 202 means the recorded payment still needs confirmation, not that it failed. OPTIONS requests support browser CORS.
108
183
 
109
- ## Protect your own API
110
-
111
- ```js
112
- import { x402Middleware } from "@xrpay/x402";
113
- app.get("/report", x402Middleware({
114
- payTo: process.env.MERCHANT_XRP_ADDRESS,
115
- amount: "0.001", currency: "XRP", testnet: true,
116
- challengeSecret: process.env.X402_CHALLENGE_SECRET,
117
- }), (_req, res) => res.json({ report: "paid response" }));
118
- ```
184
+ ## Payment SDK and facilitator
119
185
 
120
- The hosted facilitator is `https://api.xrpay.it/api/x402`, with `/supported`, `/verify` and `/settle`. Public facilitator routes do not need XRPay credentials. Authenticated merchant variants live under `/api/v1/x402` and bind settlement to the merchant wallet and network.
186
+ Use the [standalone API quickstart](#quickstart-charge-for-your-own-api) above for your own service. `X402Client` from `@xrpay/x402/client` can pay compatible exact XRPL x402 resources with explicit network, asset, recipient and spending controls. `@xrpay/x402/protocol` exports wire types and header helpers. Wallet keys stay in the buyer's process.
121
187
 
122
- `X402Client` from `@xrpay/x402/client` can pay any compatible exact XRPL resource with the same explicit network, asset, recipient and spending controls. `@xrpay/x402/protocol` exports wire types and header helpers. Wallet keys stay in the buyer's process. Mainnet settlement uses actual funds and network fees are paid by the buyer.
188
+ The public facilitator is `https://api.xrpay.it/api/x402`, with `/supported`, `/verify` and `/settle`. **These routes need no XRPay account or API key.** The optional authenticated merchant variants under `/api/v1/x402` require XRPay credentials and bind settlement to the merchant wallet and network.
123
189
 
124
190
  ## Development
125
191
 
package/dist/mcp.js CHANGED
@@ -1736,7 +1736,7 @@ function createCommerceToolHandler(options = {}) {
1736
1736
  }
1737
1737
 
1738
1738
  // src/mcp.ts
1739
- var server = new Server({ name: "xrpay-agent-commerce", version: "0.1.0" }, { capabilities: { tools: {} } });
1739
+ var server = new Server({ name: "xrpay-agent-commerce", version: "0.1.1" }, { capabilities: { tools: {} } });
1740
1740
  var execute = createCommerceToolHandler({ origin: process.env.XRPAY_COMMERCE_ORIGIN, stateDirectory: process.env.XRPAY_COMMERCE_STATE_DIR });
1741
1741
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: commerceTools }));
1742
1742
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
@@ -0,0 +1,25 @@
1
+ // npm install @xrpay/x402 express
2
+ // Uses XRP Testnet. No XRPay account, API key, or product listing is required.
3
+ import express from "express";
4
+ import { x402Middleware } from "@xrpay/x402";
5
+
6
+ const payTo = process.env.XRPL_RECIPIENT_ADDRESS;
7
+ const challengeSecret = process.env.X402_CHALLENGE_SECRET;
8
+ if (!payTo || !challengeSecret) {
9
+ throw new Error("Set XRPL_RECIPIENT_ADDRESS and X402_CHALLENGE_SECRET (at least 32 characters).");
10
+ }
11
+
12
+ const app = express();
13
+ app.get("/api/hello", x402Middleware({
14
+ payTo,
15
+ amount: "0.001", // XRP per request, paid directly to your wallet.
16
+ currency: "XRP",
17
+ testnet: true,
18
+ challengeSecret,
19
+ facilitatorUrl: "https://api.xrpay.it/api/x402", // Public; no API key.
20
+ }), (_req, res) => res.json({ message: "Hello from your paid API!" }));
21
+
22
+ const port = Number(process.env.PORT ?? 3000);
23
+ app.listen(port, "127.0.0.1", () => {
24
+ console.log(`Paid API: http://127.0.0.1:${port}/api/hello (0.001 Testnet XRP)`);
25
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xrpay/x402",
3
- "version": "0.1.0",
4
- "description": "XRPL x402 payments and agent commerce: discover, buy, and receive digital products from XRPay merchants",
3
+ "version": "0.1.1",
4
+ "description": "Charge for your own APIs with XRP or RLUSD\u2014no XRPay account required. Includes optional agent commerce and MCP tools.",
5
5
  "type": "module",
6
6
  "main": "./dist/server.cjs",
7
7
  "types": "./dist/server.d.ts",
@@ -66,7 +66,7 @@
66
66
  "@modelcontextprotocol/sdk": "^1.29.0"
67
67
  },
68
68
  "license": "MIT",
69
- "homepage": "https://www.xrpay.it/docs/x402-commerce",
69
+ "homepage": "https://www.xrpay.it/docs/x402",
70
70
  "repository": {
71
71
  "type": "git",
72
72
  "url": "git+https://github.com/gsabbih6/ripple-pay.git",