@cloudpayx/x402-pay 0.2.3 → 0.2.4
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 +17 -10
- package/examples/quickstart-validation.mjs +65 -0
- package/package.json +3 -2
- package/types/public-node.d.ts +1 -1
- package/README.before-0.2.3.bak +0 -94
package/README.md
CHANGED
|
@@ -16,6 +16,23 @@ Self-funded agents can integrate without a cloudpayX account, dashboard, or mand
|
|
|
16
16
|
**Protocol:** x402 V2, `exact`
|
|
17
17
|
**Assets:** XRP, RLUSD, Circle USDC
|
|
18
18
|
|
|
19
|
+
## Quick start: validate a payment configuration
|
|
20
|
+
|
|
21
|
+
Start with a no-wallet example before connecting a live XRPL signer.
|
|
22
|
+
|
|
23
|
+
From the SDK project:
|
|
24
|
+
|
|
25
|
+
npm install
|
|
26
|
+
node examples/quickstart-validation.mjs
|
|
27
|
+
|
|
28
|
+
The example imports the published SDK interface, configures an XRP purchase, and calls `validateSecureNodePurchase()`.
|
|
29
|
+
|
|
30
|
+
It uses placeholder addresses and a signer that refuses to sign. **No funds move.**
|
|
31
|
+
|
|
32
|
+
Validation confirms the guarded configuration structure. It does not authorize a payment, validate an address checksum, or verify settlement.
|
|
33
|
+
|
|
34
|
+
For live integration, replace the placeholders with a compatible XRPL signer, real payment details, and your own authorization policy. Use `executeSecureNodePurchase()` for execution and `reconcileSecureNodePurchase()` for settlement verification.
|
|
35
|
+
|
|
19
36
|
## Capabilities
|
|
20
37
|
|
|
21
38
|
- **Autonomous agent payments:** Agents can purchase compatible x402 resources using their own XRPL signing infrastructure.
|
|
@@ -69,16 +86,6 @@ Applications must secure their XRPL signing credentials independently. An agent
|
|
|
69
86
|
|
|
70
87
|
Issued-token payments require applicable trustlines, sufficient balances, and XRP for network fees and reserves. Third-party resource delivery depends on the seller and network conditions.
|
|
71
88
|
|
|
72
|
-
## Testing
|
|
73
|
-
|
|
74
|
-
The v0.2.2 implementation completed:
|
|
75
|
-
|
|
76
|
-
- **234 automated tests passed**
|
|
77
|
-
- **0 test failures**
|
|
78
|
-
- **Successful TypeScript build**
|
|
79
|
-
|
|
80
|
-
Test coverage includes supported assets, authorization, guarded signing, persistent budgets, transaction journaling, HTTP resource protections, and settlement reconciliation.
|
|
81
|
-
|
|
82
89
|
## Resources
|
|
83
90
|
|
|
84
91
|
- Website: https://cloudpayx.com
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { validateSecureNodePurchase } from '@cloudpayx/x402-pay';
|
|
2
|
+
|
|
3
|
+
// Example-only addresses. No real wallet or signing credentials.
|
|
4
|
+
const payer = 'r' + 'A'.repeat(25);
|
|
5
|
+
const seller = 'r' + 'B'.repeat(25);
|
|
6
|
+
const resource = 'https://example.com/paid-resource';
|
|
7
|
+
|
|
8
|
+
const purchase = {
|
|
9
|
+
intent: {
|
|
10
|
+
intentId: 'cpx-quickstart-0001',
|
|
11
|
+
payer,
|
|
12
|
+
seller,
|
|
13
|
+
resource,
|
|
14
|
+
asset: 'XRP',
|
|
15
|
+
amount: '1000' // XRP amounts are in drops
|
|
16
|
+
},
|
|
17
|
+
journalDir: './cpx-quickstart-journal',
|
|
18
|
+
budgetCaps: {
|
|
19
|
+
xrpDrops: '1000000',
|
|
20
|
+
rlusd: '2',
|
|
21
|
+
usdc: '2'
|
|
22
|
+
},
|
|
23
|
+
signer: {
|
|
24
|
+
classicAddress: payer,
|
|
25
|
+
sign: async () => {
|
|
26
|
+
throw new Error('DEMO_SIGNING_DISABLED');
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
policy: {
|
|
30
|
+
assets: [{
|
|
31
|
+
kind: 'xrp',
|
|
32
|
+
asset: 'XRP',
|
|
33
|
+
maxAmountDrops: '1000'
|
|
34
|
+
}],
|
|
35
|
+
recipients: {
|
|
36
|
+
mode: 'allowlist',
|
|
37
|
+
addresses: [seller]
|
|
38
|
+
},
|
|
39
|
+
approval: {
|
|
40
|
+
mode: 'callback',
|
|
41
|
+
authorize: async () => false
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
oneShot: {
|
|
45
|
+
recipient: seller,
|
|
46
|
+
asset: 'XRP',
|
|
47
|
+
exactAmount: '1000',
|
|
48
|
+
maxFeeDrops: '100'
|
|
49
|
+
},
|
|
50
|
+
maxFeeDrops: '100',
|
|
51
|
+
request: {
|
|
52
|
+
url: resource,
|
|
53
|
+
init: {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
body: '{}'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const valid = validateSecureNodePurchase(purchase);
|
|
61
|
+
|
|
62
|
+
console.log('cpX x402 Pay');
|
|
63
|
+
console.log('Configuration valid:', valid);
|
|
64
|
+
console.log('No wallet connected. No transaction signed or submitted.');
|
|
65
|
+
console.log('This checks configuration shape, not payment authorization or settlement.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudpayx/x402-pay",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "XRPL-native x402 payment SDK for autonomous AI agents. Secure, wallet-agnostic XRP, RLUSD and Circle USDC payments with spending policies and verified settlement.",
|
|
6
6
|
"dependencies": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"scripts/trusted-xrpl-primitives.mjs",
|
|
39
39
|
"scripts/trusted-xrpl-recovery.mjs",
|
|
40
40
|
"types/",
|
|
41
|
-
"README.md"
|
|
41
|
+
"README.md",
|
|
42
|
+
"examples/quickstart-validation.mjs"
|
|
42
43
|
]
|
|
43
44
|
}
|
package/types/public-node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** cpX x402 Pay
|
|
1
|
+
/** cpX x402 Pay supported Node.js API; no wallet keys are handled here. */
|
|
2
2
|
import type { ClientXrplSigner } from '@x402/xrpl';
|
|
3
3
|
import type { AgentPaymentConfig } from '../dist/src/policy.js';
|
|
4
4
|
import type { GuardOptions } from '../dist/src/one_shot_guard.js';
|
package/README.before-0.2.3.bak
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# cpX x402 Pay | XRPL Agent Payment SDK
|
|
2
|
-
|
|
3
|
-
**Purpose:** Let an unaffiliated, self-funded agent participate in the XRPL x402 economy without a cloudpayX registration, dashboard, Supabase session, or required wallet brand. This is an XRPL-native SDK for autonomous agents purchasing x402-protected resources.
|
|
4
|
-
|
|
5
|
-
The SDK supports wallet-agnostic signing, three-asset payment policies, spending controls, guarded signing, and validated-ledger reconciliation. Agents must use compatible XRPL signers and maintain sufficient funds.
|
|
6
|
-
|
|
7
|
-
## Source
|
|
8
|
-
|
|
9
|
-
- `src/policy.ts` — strict, dependency-free XRPL x402 V2 policy checks.
|
|
10
|
-
- `src/assets.ts` — verified XRPL mainnet XRP / Ripple RLUSD / Circle USDC identity constants and three-asset policy builder.
|
|
11
|
-
- `src/index.ts` — adapter to the existing proven `@x402/core`, `@x402/fetch`, `@x402/xrpl` client.
|
|
12
|
-
- `examples/feral-agent.example.ts` — signer-injection example; no secrets or hardcoded wallet provider.
|
|
13
|
-
- `examples/simulation-only.mjs` — no-wallet, no-network, no-payment demonstration.
|
|
14
|
-
- `tests/policy.test.mjs` and `tests/three-assets.test.mjs` — locally executable approval/denial tests for all three assets.
|
|
15
|
-
|
|
16
|
-
## On your Mac (do not deploy yet)
|
|
17
|
-
|
|
18
|
-
**Keep this a separate test folder, do not copy over `src/cloudpayx_x402_pay.ts` or `src/cloudpayx_x402_pay_configured.ts`.**
|
|
19
|
-
|
|
20
|
-
1. Unzip, open Terminal in the unzipped directory.
|
|
21
|
-
2. Run `npm install` (the official `@x402/*` packages are required for the SDK adapter).
|
|
22
|
-
3. Run `npm run test:policy` and `npm run demo:dry-run`.
|
|
23
|
-
4. Run `npm run build` to check SDK integration types against the actual installed packages.
|
|
24
|
-
|
|
25
|
-
`npm run test:policy` needs only the TypeScript compiler, Node.js, and the dependency-free policy module. The build needs official x402 packages; network/package installation was unavailable during packaging.
|
|
26
|
-
|
|
27
|
-
## Three verified XRPL mainnet assets
|
|
28
|
-
|
|
29
|
-
The optional helper `createThreeAssetPolicy` pins the network to `xrpl:0` and enables ONLY these official asset identities:
|
|
30
|
-
|
|
31
|
-
| Asset | x402 `asset` | x402 `extra.issuer` | Max amount unit |
|
|
32
|
-
| --- | --- | --- | --- |
|
|
33
|
-
| XRP | `XRP` | None | Integer drops (1 XRP = 1,000,000 drops) |
|
|
34
|
-
| Ripple RLUSD | `524C555344000000000000000000000000000000` | `rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De` | Decimal RLUSD tokens |
|
|
35
|
-
| Circle USDC on XRPL | `5553444300000000000000000000000000000000` | `rGm7WCVp9gb4jZHWTEtGUr4dd74z2XuWhE` | Decimal USDC tokens |
|
|
36
|
-
|
|
37
|
-
Only these XRPL issuances are accepted by this helper, *not* similarly named bridged tokens, Base USDC, or arbitrary USD IOUs. Signing always uses a caller-supplied `ClientXrplSigner`. **There is no automatic token conversion, exchange quoting, currency netting, or account registration.**
|
|
38
|
-
|
|
39
|
-
## Sample: permissionless, self-funded agent using all three
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
import { createCpXX402AgentPay, createThreeAssetPolicy } from './src/index.js';
|
|
43
|
-
|
|
44
|
-
const { paidFetch } = createCpXX402AgentPay({
|
|
45
|
-
signer: MY_SECURE_XRPL_SIGNER, // compatible @x402/xrpl ClientXrplSigner
|
|
46
|
-
policy: createThreeAssetPolicy({
|
|
47
|
-
limits: {
|
|
48
|
-
xrpDrops: '50000', // 0.05 XRP
|
|
49
|
-
rlusd: '0.05', // 0.05 RLUSD
|
|
50
|
-
usdc: '0.05' // 0.05 Circle USDC (XRPL)
|
|
51
|
-
},
|
|
52
|
-
recipients: { mode: 'any' }, // opt-in open seller participation
|
|
53
|
-
approval: { mode: 'autonomous' } // explicit local operator/agent opt-in
|
|
54
|
-
})
|
|
55
|
-
});
|
|
56
|
-
const response = await paidFetch('https://a-trusted-x402-resource.example/report');
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
`MY_SECURE_XRPL_SIGNER` and seller URL are placeholders. Don't paste wallet secrets into this file. **An unknown agent can use the SDK with its own signer, but does not gain authority over anyone else's funds.**
|
|
60
|
-
|
|
61
|
-
`npm run demo:dry-run` simulates XRP, RLUSD, and USDC policy decisions without a wallet or network.
|
|
62
|
-
|
|
63
|
-
## Units are not interchangeable
|
|
64
|
-
|
|
65
|
-
| XRPL asset | x402 `amount` units | `maxAmount...` example |
|
|
66
|
-
| --- | --- | --- |
|
|
67
|
-
| Native XRP | Drops (1,000,000 drops = 1 XRP) | `{kind:'xrp',asset:'XRP',maxAmountDrops:'50000'}` = 0.05 XRP |
|
|
68
|
-
| RLUSD, USDC or other XRPL-issued token | Decimal issued-token value | `{kind:'issued', asset:'...', issuer:'...', maxAmount:'0.05'}` = 0.05 token |
|
|
69
|
-
|
|
70
|
-
This module rejects scientific notation and prices above its exact cap. Limits are independent; they are **not** an equivalent USD portfolio budget. **Network fees are extra; the per-payment cap bounds the x402 transfer amount, not the combined cost including XRPL fees, trustline reserves, or issuer transfer fees.** XRPL recipient validation here only checks basic address *shape*. The underlying SDK/signer/facilitator must validate destination checksum, invoice/transaction binding, signature authorization, settlement, and errors.
|
|
71
|
-
|
|
72
|
-
## Security boundaries
|
|
73
|
-
|
|
74
|
-
- No Xaman dependency and no human cloudpayX account required for self-funded agents.
|
|
75
|
-
- Strict XRPL mainnet `xrpl:0`, x402 V2, `exact` scheme, `areFeesSponsored=false`.
|
|
76
|
-
- Explicit assets and exact amount caps; opt-in seller-neutral recipient policy or allowlist.
|
|
77
|
-
- Explicit `autonomous` opt-in or application-provided authorization callback, with fail-closed exceptions.
|
|
78
|
-
- A self-funded agent retains *unrestricted authority over its own signer*. A local SDK is **not a trust boundary** against an agent holding the key: it can bypass these checks. Hardware signers, dedicated wallets, and controlled signer services are needed for stronger enforcement.
|
|
79
|
-
- **Security protections:** Spending budgets, duplicate-payment protection, resource-host validation, anti-SSRF controls, replay protection, fee budgeting, guarded signing, and validated-ledger reconciliation are covered by the SDK's security tests. These controls apply when payments use the guarded SDK interface.
|
|
80
|
-
- The live x402 facilitator/service should validate transaction signatures and bind invoice, amount, asset, destination and network, as described in the XRPL exact scheme spec.
|
|
81
|
-
|
|
82
|
-
## Operational conditions for USDC and RLUSD
|
|
83
|
-
|
|
84
|
-
The agent wallet must have the required XRPL token trustline/balance/authorization (where applicable) and enough XRP for transaction fees and reserves. A valid policy decision **does not** guarantee a successful token payment or a resource response. The resource server must advertise a compatible x402 `accepts` entry; the SDK does not auto-swap XRP into stablecoins.
|
|
85
|
-
|
|
86
|
-
XRPL-issued assets require sufficient balances, applicable trustlines, and XRP for fees and reserves. Payment success and resource delivery depend on the network and seller. An agent with unrestricted access to its own signing keys can bypass local SDK policies.
|
|
87
|
-
|
|
88
|
-
**Official issuers:** [Ripple RLUSD](https://docs.ripple.com/products/stablecoin/developer-resources/rlusd-on-the-xrpl) and [Circle XRPL USDC](https://www.circle.com/blog/now-available-usdc-on-the-xrpl).
|
|
89
|
-
|
|
90
|
-
## Integration guidance
|
|
91
|
-
|
|
92
|
-
Use a dedicated, limited-balance XRPL wallet when integrating a new signer or seller. Validate the complete payment and resource-delivery flow before granting unattended spending authority. For stronger enforcement, keep signing authority outside the agent's direct control.
|
|
93
|
-
|
|
94
|
-
Specifications: https://github.com/x402-foundation/x402/blob/main/specs/schemes/exact/scheme_exact_xrpl.md
|