@t2000/x402 0.2.1 → 0.2.6
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 +25 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -100,36 +100,43 @@ const res = await client.fetch('https://api.example.com/data', {
|
|
|
100
100
|
});
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
### `parsePaymentRequired(
|
|
103
|
+
### `parsePaymentRequired(headerValue, maxPrice?)`
|
|
104
104
|
|
|
105
|
-
Parses a 402 response into structured payment terms.
|
|
105
|
+
Parses the `PAYMENT-REQUIRED` header from a 402 response into structured payment terms. Validates network (must be `sui`), asset (must be `USDC`), expiry, and price limit.
|
|
106
106
|
|
|
107
107
|
```typescript
|
|
108
108
|
import { parsePaymentRequired } from '@t2000/x402';
|
|
109
109
|
|
|
110
|
-
const
|
|
111
|
-
|
|
110
|
+
const headerValue = response.headers.get('payment-required');
|
|
111
|
+
const terms = parsePaymentRequired(headerValue, 1.0);
|
|
112
|
+
// { amount: '0.01', payTo: '0x...', network: 'sui', nonce: '...', expiresAt: 1709... }
|
|
112
113
|
```
|
|
113
114
|
|
|
114
115
|
## Facilitator API (Server-Side)
|
|
115
116
|
|
|
116
117
|
For API providers who want to accept x402 payments:
|
|
117
118
|
|
|
118
|
-
### `verifyPayment(
|
|
119
|
+
### `verifyPayment(client, request)`
|
|
119
120
|
|
|
120
|
-
Verify that an on-chain payment transaction is valid.
|
|
121
|
+
Verify that an on-chain payment transaction is valid. Checks the transaction for a `PaymentReceipt` event and validates amount, recipient, and nonce.
|
|
121
122
|
|
|
122
123
|
```typescript
|
|
123
124
|
import { verifyPayment } from '@t2000/x402';
|
|
125
|
+
import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
|
|
124
126
|
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
const client = new SuiClient({ url: getFullnodeUrl('mainnet') });
|
|
128
|
+
|
|
129
|
+
const result = await verifyPayment(client, {
|
|
130
|
+
txHash: 'ABC123...',
|
|
131
|
+
amount: '0.01',
|
|
132
|
+
asset: 'USDC',
|
|
133
|
+
payTo: '0x...',
|
|
134
|
+
nonce: 'unique-nonce',
|
|
135
|
+
expiresAt: 1709500000,
|
|
136
|
+
network: 'sui',
|
|
130
137
|
});
|
|
131
138
|
|
|
132
|
-
if (result.
|
|
139
|
+
if (result.verified) {
|
|
133
140
|
// Payment verified — serve the resource
|
|
134
141
|
}
|
|
135
142
|
```
|
|
@@ -148,14 +155,15 @@ Payments are executed on-chain via the [Sui Payment Kit](https://docs.sui.io/sta
|
|
|
148
155
|
|
|
149
156
|
```typescript
|
|
150
157
|
import { buildPaymentTransaction } from '@t2000/x402';
|
|
158
|
+
import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
|
|
159
|
+
|
|
160
|
+
const client = new SuiClient({ url: getFullnodeUrl('mainnet') });
|
|
151
161
|
|
|
152
162
|
// Build a payment transaction (advanced usage)
|
|
153
|
-
const tx = buildPaymentTransaction({
|
|
154
|
-
registryId: '0x...',
|
|
155
|
-
recipient: '0x...',
|
|
156
|
-
amount: 10000n, // raw USDC units
|
|
163
|
+
const tx = await buildPaymentTransaction(client, senderAddress, {
|
|
157
164
|
nonce: 'unique-nonce',
|
|
158
|
-
|
|
165
|
+
amount: '0.01', // USDC as string (converted to raw internally)
|
|
166
|
+
payTo: '0x...',
|
|
159
167
|
});
|
|
160
168
|
```
|
|
161
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t2000/x402",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "x402 payment protocol client for AI agents on Sui — pay for API resources with USDC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"homepage": "https://t2000.ai",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@mysten/sui": "^1",
|
|
39
|
-
"@t2000/sdk": "0.2.
|
|
39
|
+
"@t2000/sdk": "0.2.6"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^22",
|