moltspay 0.3.0 โ†’ 0.4.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
@@ -10,8 +10,10 @@ Blockchain payment infrastructure for AI Agents on Moltbook.
10
10
  - ๐Ÿ”’ **Secure Wallet** - Limits, whitelist, and audit logging
11
11
  - ๐Ÿ“ **EIP-2612 Permit** - Gasless user payments
12
12
  - โ›“๏ธ **Multi-chain** - Base, Polygon, Ethereum (mainnet & testnet)
13
- - ๐Ÿค– **Agent-to-Agent** - Complete A2A payment flow support (v0.2.0+)
13
+ - ๐Ÿค– **Agent-to-Agent** - Complete A2A payment flow support
14
14
  - ๐Ÿงพ **Receipt Generation** - Transaction receipts for audit/accounting
15
+ - ๐Ÿ”„ **x402 Protocol** - HTTP-native payments (v0.4.0+)
16
+ - ๐Ÿฆ **CDP Wallet** - Coinbase Developer Platform integration (v0.4.0+)
15
17
 
16
18
  ## Installation
17
19
 
@@ -245,6 +247,111 @@ const status = parseStatusMarker('[status:payment_sent tx=0xabc amount=3.99 USDC
245
247
  // { type: 'payment_sent', data: { txHash: '0xabc', amount: '3.99' } }
246
248
  ```
247
249
 
250
+ ## x402 Protocol Support (v0.4.0+)
251
+
252
+ x402 is an open standard for HTTP-native payments. When a server returns 402 Payment Required, the client can pay and retry automatically.
253
+
254
+ ### Quick Start with x402
255
+
256
+ ```typescript
257
+ import { createX402Client } from 'moltspay/x402';
258
+
259
+ // Create x402-enabled client (uses local wallet)
260
+ const client = await createX402Client({ chain: 'base' });
261
+
262
+ // Make request - payment handled automatically
263
+ const response = await client.fetch('https://juai8.com/x402pay', {
264
+ method: 'POST',
265
+ headers: { 'Content-Type': 'application/json' },
266
+ body: JSON.stringify({ prompt: 'a cat dancing' })
267
+ });
268
+
269
+ const result = await response.json();
270
+ ```
271
+
272
+ ### One-shot Request
273
+
274
+ ```typescript
275
+ import { x402Fetch } from 'moltspay/x402';
276
+
277
+ // Single paid request (creates client internally)
278
+ const response = await x402Fetch('https://juai8.com/x402pay', {
279
+ method: 'POST',
280
+ body: JSON.stringify({ prompt: 'a cat dancing' })
281
+ }, { chain: 'base' });
282
+ ```
283
+
284
+ ### x402 Flow
285
+
286
+ ```
287
+ Client Agent Service Provider
288
+ โ”‚ โ”‚
289
+ โ”‚ POST /api/video โ”‚
290
+ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚
291
+ โ”‚ โ”‚
292
+ โ”‚ 402 Payment Required โ”‚
293
+ โ”‚ X-PAYMENT-REQUIRED: {price, wallet} โ”‚
294
+ โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚
295
+ โ”‚ โ”‚
296
+ โ”‚ [moltspay auto-signs payment] โ”‚
297
+ โ”‚ โ”‚
298
+ โ”‚ POST /api/video โ”‚
299
+ โ”‚ X-PAYMENT: {signature, auth} โ”‚
300
+ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€> โ”‚
301
+ โ”‚ โ”‚
302
+ โ”‚ 200 OK + result โ”‚
303
+ โ”‚ <โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚
304
+ ```
305
+
306
+ ## CDP Wallet Support (v0.4.0+)
307
+
308
+ Use Coinbase Developer Platform (CDP) for hosted wallet management.
309
+
310
+ ### Initialize CDP Wallet
311
+
312
+ ```bash
313
+ # Set CDP credentials
314
+ export CDP_API_KEY_ID=your-key-id
315
+ export CDP_API_KEY_SECRET=your-key-secret
316
+
317
+ # Initialize CDP wallet
318
+ npx moltspay init --cdp --chain base
319
+ ```
320
+
321
+ ### Use CDP Wallet with x402
322
+
323
+ ```typescript
324
+ import { createX402Client } from 'moltspay/x402';
325
+
326
+ // Create x402 client with CDP wallet
327
+ const client = await createX402Client({
328
+ chain: 'base',
329
+ useCDP: true // Use CDP instead of local wallet
330
+ });
331
+
332
+ // Make paid requests
333
+ const response = await client.fetch('https://juai8.com/x402pay');
334
+ ```
335
+
336
+ ### Direct CDP Wallet Usage
337
+
338
+ ```typescript
339
+ import { CDPWallet } from 'moltspay/cdp';
340
+
341
+ const wallet = new CDPWallet({ chain: 'base' });
342
+
343
+ // Check balance
344
+ const balance = await wallet.getBalance();
345
+ console.log('USDC:', balance.usdc);
346
+
347
+ // Transfer USDC
348
+ const result = await wallet.transfer({
349
+ to: '0xRecipient...',
350
+ amount: 0.99
351
+ });
352
+ console.log('Tx:', result.txHash);
353
+ ```
354
+
248
355
  ## API Reference
249
356
 
250
357
  ### PaymentAgent