moltspay 0.5.3 → 0.7.0

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.
Files changed (67) hide show
  1. package/dist/cdp/index.d.mts +111 -0
  2. package/dist/cdp/index.d.ts +111 -0
  3. package/dist/cdp/index.js +30655 -0
  4. package/dist/cdp/index.js.map +1 -0
  5. package/dist/cdp/index.mjs +30631 -0
  6. package/dist/cdp/index.mjs.map +1 -0
  7. package/dist/chains/index.d.mts +1 -1
  8. package/dist/chains/index.d.ts +1 -1
  9. package/dist/cli/index.js +940 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/index.mjs +917 -0
  12. package/dist/cli/index.mjs.map +1 -0
  13. package/dist/client/index.d.mts +134 -0
  14. package/dist/client/index.d.ts +134 -0
  15. package/dist/client/index.js +331 -0
  16. package/dist/client/index.js.map +1 -0
  17. package/dist/client/index.mjs +296 -0
  18. package/dist/client/index.mjs.map +1 -0
  19. package/dist/createWallet-D53qu7ie.d.mts +77 -0
  20. package/dist/createWallet-D53qu7ie.d.ts +77 -0
  21. package/dist/index-Dg8n6wdW.d.mts +32 -0
  22. package/dist/index-Dg8n6wdW.d.ts +32 -0
  23. package/dist/index.d.mts +6 -937
  24. package/dist/index.d.ts +6 -937
  25. package/dist/index.js +31023 -3250
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +30998 -3178
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/server/index.d.mts +120 -0
  30. package/dist/server/index.d.ts +120 -0
  31. package/dist/server/index.js +418 -0
  32. package/dist/server/index.js.map +1 -0
  33. package/dist/server/index.mjs +393 -0
  34. package/dist/server/index.mjs.map +1 -0
  35. package/dist/wallet/index.d.mts +3 -451
  36. package/dist/wallet/index.d.ts +3 -451
  37. package/dist/wallet/index.js +5 -1021
  38. package/dist/wallet/index.js.map +1 -1
  39. package/dist/wallet/index.mjs +16 -1015
  40. package/dist/wallet/index.mjs.map +1 -1
  41. package/package.json +19 -19
  42. package/dist/cli.js +0 -1984
  43. package/dist/cli.js.map +0 -1
  44. package/dist/cli.mjs +0 -1969
  45. package/dist/cli.mjs.map +0 -1
  46. package/dist/guide/index.d.mts +0 -39
  47. package/dist/guide/index.d.ts +0 -39
  48. package/dist/guide/index.js +0 -181
  49. package/dist/guide/index.js.map +0 -1
  50. package/dist/guide/index.mjs +0 -152
  51. package/dist/guide/index.mjs.map +0 -1
  52. package/dist/index-CyFg9s2m.d.mts +0 -161
  53. package/dist/index-CyFg9s2m.d.ts +0 -161
  54. package/dist/orders/index.d.mts +0 -97
  55. package/dist/orders/index.d.ts +0 -97
  56. package/dist/orders/index.js +0 -162
  57. package/dist/orders/index.js.map +0 -1
  58. package/dist/orders/index.mjs +0 -136
  59. package/dist/orders/index.mjs.map +0 -1
  60. package/dist/permit/index.d.mts +0 -49
  61. package/dist/permit/index.d.ts +0 -49
  62. package/dist/permit/index.js +0 -273
  63. package/dist/permit/index.js.map +0 -1
  64. package/dist/permit/index.mjs +0 -246
  65. package/dist/permit/index.mjs.map +0 -1
  66. /package/dist/{cli.d.mts → cli/index.d.mts} +0 -0
  67. /package/dist/{cli.d.ts → cli/index.d.ts} +0 -0
package/dist/index.d.mts CHANGED
@@ -1,938 +1,7 @@
1
- import { C as ChainName, a as ChainConfig, P as PaymentAgentConfig, b as CreateInvoiceParams, I as Invoice, V as VerifyOptions, c as VerifyResult, W as WalletBalance, A as AuditAction, d as AuditEntry } from './index-CyFg9s2m.mjs';
2
- export { E as EIP712TypedData, e as PendingTransfer, f as PermitExecuteResult, g as PermitRequest, h as PermitSignature, S as SecureWalletConfig, i as SecurityLimits, T as TransferParams, j as TransferResult } from './index-CyFg9s2m.mjs';
3
- export { AllowanceStatus, AllowanceWallet, AllowanceWalletConfig, CreateWalletOptions, CreateWalletResult, OwnerPermit, PermitData, PermitSigner, PermitWallet, PermitWalletConfig, SecureWallet, SignPermitConfig, SignPermitParams, SignPermitResult, SpendParams, SpendResult, TransferWithPermitParams, TransferWithPermitResult, Wallet, WalletData, createWallet, formatPermitRequest, generatePermitInstructions, getWalletAddress, loadWallet, signPermit, walletExists } from './wallet/index.mjs';
4
- export { PermitPayment } from './permit/index.mjs';
5
- export { CreateOrderParams, MemoryOrderStore, Order, OrderManager, OrderStatus, OrderStore } from './orders/index.mjs';
1
+ export { Charge, ChargeStatus, MoltsPayServer, MoltsPayServerOptions, PaymentRequest, ProviderConfig, RegisteredSkill, ServiceConfig, ServicesManifest, SkillFunction } from './server/index.mjs';
2
+ export { ClientConfig, MoltsPayClient, MoltsPayClientOptions, PaymentRequired, ProviderInfo, ServiceInfo, ServicesResponse, VerifyResponse, WalletData } from './client/index.mjs';
3
+ export { CHAINS, ERC20_ABI, getChain, getChainById, listChains } from './chains/index.mjs';
4
+ export { c as createWallet, g as getWalletAddress, l as loadWallet, w as walletExists } from './createWallet-D53qu7ie.mjs';
6
5
  export { VerifyPaymentParams, VerifyPaymentResult, getTransactionStatus, verifyPayment, waitForTransaction } from './verify/index.mjs';
7
- export { PaymentGuideParams, extractTransactionHash, generatePaymentGuide, generatePaymentReminder, generateWalletGuide, hasTransactionHash } from './guide/index.mjs';
8
- import { getChain } from './chains/index.mjs';
9
- export { CHAINS, ERC20_ABI, getChainById, listChains } from './chains/index.mjs';
10
- import { ethers } from 'ethers';
11
-
12
- /**
13
- * PaymentAgent - Core Payment Agent
14
- *
15
- * Features:
16
- * - Generate Invoice (payment request)
17
- * - Verify on-chain payment
18
- * - Generate wallet deep link
19
- */
20
-
21
- declare class PaymentAgent {
22
- readonly chain: ChainName;
23
- readonly chainConfig: ChainConfig;
24
- readonly walletAddress: string;
25
- private provider;
26
- private usdcContract;
27
- static readonly PROTOCOL_VERSION = "1.0";
28
- constructor(config?: PaymentAgentConfig);
29
- /**
30
- * Generate payment request(Invoice)
31
- */
32
- createInvoice(params: CreateInvoiceParams): Invoice;
33
- /**
34
- * Generate wallet deep link(supports MetaMask etc)
35
- */
36
- generateDeepLink(amount: number, memo: string): string;
37
- /**
38
- * Verify on-chain payment
39
- */
40
- verifyPayment(txHash: string, options?: VerifyOptions): Promise<VerifyResult>;
41
- /**
42
- * Scan recent transfers (match by amount)
43
- */
44
- scanRecentTransfers(expectedAmount: number, timeoutMinutes?: number): Promise<VerifyResult>;
45
- /**
46
- * Get wallet balance
47
- */
48
- getBalance(address?: string): Promise<WalletBalance>;
49
- /**
50
- * Format Invoice as human-readable message
51
- */
52
- formatInvoiceMessage(invoice: Invoice, includeJson?: boolean): string;
53
- }
54
-
55
- /**
56
- * AgentWallet - Zero-config wallet for AI Agents
57
- *
58
- * Design principles:
59
- * - Auto-initialize on first use (no manual setup)
60
- * - Generate address locally (no gas needed)
61
- * - Owner authorizes via Permit (can be CLI or UI)
62
- * - Agent only needs gas when actually spending
63
- */
64
-
65
- interface OwnerPermit {
66
- owner: string;
67
- value: string;
68
- deadline: number;
69
- nonce: number;
70
- v: number;
71
- r: string;
72
- s: string;
73
- }
74
- interface AgentWalletConfig {
75
- /** Storage directory for wallet data (default: ~/.moltspay) */
76
- storageDir?: string;
77
- /** Chain to use */
78
- chain?: ChainName;
79
- /** Custom RPC URL */
80
- rpcUrl?: string;
81
- }
82
- interface SpendResult {
83
- success: boolean;
84
- txHash?: string;
85
- error?: string;
86
- from: string;
87
- to: string;
88
- amount: number;
89
- remainingAllowance?: string;
90
- explorerUrl?: string;
91
- }
92
- declare class AgentWallet {
93
- readonly chain: ChainName;
94
- readonly chainConfig: ChainConfig;
95
- readonly storageDir: string;
96
- private _address;
97
- private _privateKey;
98
- private _wallet;
99
- private _provider;
100
- private _permits;
101
- constructor(config?: AgentWalletConfig);
102
- private getDefaultStorageDir;
103
- private getWalletPath;
104
- private getPermitsPath;
105
- /**
106
- * Auto-initialize: create wallet if not exists
107
- * This is called automatically in constructor
108
- */
109
- private ensureInitialized;
110
- /** Agent's address (auto-generated on first use) */
111
- get address(): string;
112
- private get wallet();
113
- private get provider();
114
- /**
115
- * Store a Permit from Owner
116
- */
117
- storePermit(permit: OwnerPermit): void;
118
- /**
119
- * Get stored permit for an owner
120
- */
121
- getPermit(owner: string): OwnerPermit | undefined;
122
- /**
123
- * Check allowance from an owner
124
- */
125
- checkAllowance(owner: string): Promise<{
126
- allowance: string;
127
- ownerBalance: string;
128
- canSpend: boolean;
129
- }>;
130
- /**
131
- * Spend USDC from Owner's wallet
132
- *
133
- * @param to - Recipient (service provider)
134
- * @param amount - Amount in USDC
135
- * @param permit - Optional, uses stored permit if not provided
136
- */
137
- spend(to: string, amount: number, permit?: OwnerPermit): Promise<SpendResult>;
138
- /**
139
- * Get USDC balance
140
- */
141
- getBalance(): Promise<{
142
- usdc: string;
143
- eth: string;
144
- }>;
145
- /**
146
- * Transfer USDC to a recipient (direct payment)
147
- *
148
- * This is the simplest payment method - Agent pays directly from its wallet.
149
- * Requires Agent wallet to have USDC (funded by Owner).
150
- *
151
- * @example
152
- * ```typescript
153
- * const wallet = new AgentWallet({ chain: 'base' });
154
- *
155
- * // Check balance
156
- * const balance = await wallet.getBalance();
157
- * console.log('USDC:', balance.usdc);
158
- *
159
- * // Pay for service
160
- * const result = await wallet.transfer({
161
- * to: '0xServiceProvider...',
162
- * amount: 0.99
163
- * });
164
- * console.log('Tx:', result.txHash);
165
- * ```
166
- */
167
- transfer(params: {
168
- to: string;
169
- amount: number;
170
- }): Promise<{
171
- success: boolean;
172
- txHash?: string;
173
- error?: string;
174
- from?: string;
175
- to?: string;
176
- amount?: number;
177
- explorerUrl?: string;
178
- }>;
179
- /**
180
- * Pay for a service (transfer USDC to service provider)
181
- *
182
- * This is the main method for Agent-to-Agent payments.
183
- * Returns payment data ready to submit to service API.
184
- *
185
- * @example
186
- * ```typescript
187
- * const wallet = new AgentWallet({ chain: 'base' });
188
- *
189
- * // Pay for Zen7 video service
190
- * const payment = await wallet.payService({
191
- * provider: '0xb8d6f2441e8f8dfB6288A74Cf73804cDd0484E0C',
192
- * amount: 0.99,
193
- * service: 'video_generation'
194
- * });
195
- *
196
- * if (payment.success) {
197
- * // Submit to service API
198
- * await fetch('/v1/video/generate', {
199
- * body: JSON.stringify({
200
- * prompt: "...",
201
- * payment: payment.paymentData // Ready to use!
202
- * })
203
- * });
204
- * }
205
- * ```
206
- */
207
- payService(params: {
208
- provider: string;
209
- amount: number;
210
- service?: string;
211
- }): Promise<{
212
- success: boolean;
213
- txHash?: string;
214
- error?: string;
215
- paymentData?: {
216
- method: 'transfer';
217
- chain: string;
218
- tx_hash: string;
219
- };
220
- explorerUrl?: string;
221
- }>;
222
- /**
223
- * Get gas balance (ETH needed for transactions)
224
- */
225
- getGasBalance(): Promise<string>;
226
- /**
227
- * Check if agent has enough gas
228
- */
229
- hasGas(minEth?: number): Promise<boolean>;
230
- /**
231
- * Generate authorization request for Owner
232
- * Owner can sign this with CLI (ethers) or MetaMask
233
- */
234
- generateAuthRequest(params: {
235
- ownerAddress: string;
236
- amount: number;
237
- expiresInHours?: number;
238
- }): Promise<{
239
- message: string;
240
- typedData: object;
241
- cliCommand: string;
242
- }>;
243
- }
244
- /**
245
- * Quick helper to get agent address (auto-initializes if needed)
246
- */
247
- declare function getAgentAddress(config?: AgentWalletConfig): string;
248
-
249
- /**
250
- * AuditLog - Immutable Audit Log
251
- *
252
- * Features:
253
- * - Hash-chained, any modification breaks the chain
254
- * - Stored by date in separate files
255
- * - JSONL format for easy append and parse
256
- */
257
-
258
- interface LogParams {
259
- action: AuditAction;
260
- request_id: string;
261
- from?: string;
262
- to?: string;
263
- amount?: number;
264
- tx_hash?: string;
265
- reason?: string;
266
- requester?: string;
267
- metadata?: Record<string, unknown>;
268
- }
269
- declare class AuditLog {
270
- private basePath;
271
- private lastHash;
272
- constructor(basePath?: string);
273
- /**
274
- * Record audit log
275
- */
276
- log(params: LogParams): Promise<AuditEntry>;
277
- /**
278
- * Read logs for specified date
279
- */
280
- read(date?: Date): AuditEntry[];
281
- /**
282
- * Verify log integrity
283
- */
284
- verify(date?: Date): {
285
- valid: boolean;
286
- errors: string[];
287
- };
288
- /**
289
- * Search logs
290
- */
291
- search(filter: Partial<{
292
- action: AuditAction;
293
- request_id: string;
294
- from: string;
295
- to: string;
296
- startDate: Date;
297
- endDate: Date;
298
- }>): AuditEntry[];
299
- /**
300
- * Get log file path
301
- */
302
- private getFilePath;
303
- /**
304
- * Calculate entry hash
305
- */
306
- private calculateHash;
307
- /**
308
- * Load last log entry hash
309
- */
310
- private loadLastHash;
311
- /**
312
- * Ensure directory exists
313
- */
314
- private ensureDir;
315
- }
316
-
317
- /**
318
- * Receipt - Transaction receipt generation
319
- *
320
- * Generate standardized transaction receipts for reconciliation/reimbursement/audit
321
- */
322
-
323
- interface ReceiptParams {
324
- /** Invoice ID (auto-generated or specified) */
325
- invoiceId?: string;
326
- /** Order ID */
327
- orderId: string;
328
- /** Service name */
329
- service: string;
330
- /** Service description */
331
- description?: string;
332
- /** Amount */
333
- amount: number;
334
- /** Token */
335
- token?: 'USDC' | 'USDT' | 'ETH';
336
- /** Chain */
337
- chain: ChainName;
338
- /** Transaction hash */
339
- txHash: string;
340
- /** Payer address */
341
- payerAddress: string;
342
- /** Recipient address */
343
- recipientAddress: string;
344
- /** Delivery info */
345
- delivery?: {
346
- /** Delivery URL */
347
- url?: string;
348
- /** File hash */
349
- fileHash?: string;
350
- /** Delivery timestamp */
351
- deliveredAt?: string;
352
- };
353
- /** Additional metadata */
354
- metadata?: Record<string, unknown>;
355
- }
356
- interface Receipt {
357
- type: 'receipt';
358
- version: '1.0';
359
- /** Invoice ID */
360
- invoiceId: string;
361
- /** Order ID */
362
- orderId: string;
363
- /** Service */
364
- service: string;
365
- description?: string;
366
- /** Amount */
367
- amount: string;
368
- token: string;
369
- /** Chain info */
370
- chain: string;
371
- chainId: number;
372
- /** Transaction info */
373
- txHash: string;
374
- txUrl: string;
375
- /** Parties */
376
- payer: string;
377
- recipient: string;
378
- /** Timestamps */
379
- paidAt: string;
380
- issuedAt: string;
381
- /** Delivery info */
382
- delivery?: {
383
- url?: string;
384
- fileHash?: string;
385
- deliveredAt?: string;
386
- };
387
- /** Additional metadata */
388
- metadata?: Record<string, unknown>;
389
- }
390
- /**
391
- * Generate transaction receipt
392
- */
393
- declare function generateReceipt(params: ReceiptParams): Receipt;
394
- /**
395
- * Generate receipt from Invoice + VerifyResult
396
- */
397
- declare function generateReceiptFromInvoice(invoice: Invoice, verifyResult: VerifyResult, delivery?: ReceiptParams['delivery']): Receipt;
398
- /**
399
- * Format receipt as human-readable message (Markdown)
400
- */
401
- declare function formatReceiptMessage(receipt: Receipt): string;
402
- /**
403
- * Format receipt as plain text (for Feishu/WhatsApp)
404
- */
405
- declare function formatReceiptText(receipt: Receipt): string;
406
- /**
407
- * Format receipt as JSON (for Agent parsing)
408
- */
409
- declare function formatReceiptJson(receipt: Receipt): string;
410
-
411
- /**
412
- * Agent Conversation Templates
413
- *
414
- * Standardized Agent-to-Agent payment conversation templates
415
- * Can be embedded in prompts or used for dialogue generation
416
- */
417
-
418
- declare const SellerTemplates: {
419
- /**
420
- * 1. Capability Check - Ask if buyer has payment capability
421
- */
422
- askPaymentCapability(): string;
423
- /**
424
- * 2. Settlement Method - Explain how we settle
425
- */
426
- explainSettlement(chain?: ChainName): string;
427
- /**
428
- * 3.1 Installation Guide - First step: install SDK
429
- */
430
- guideInstall(): string;
431
- /**
432
- * 3.2 Confirm Wallet Address
433
- */
434
- confirmWalletAddress(address: string): string;
435
- /**
436
- * 3.3 Funding Options - Request funding from Owner
437
- */
438
- guideFunding(agentAddress: string, suggestedAmount?: number): string;
439
- /**
440
- * 3.5 Confirm Capability Ready
441
- */
442
- confirmCapabilityReady(): string;
443
- /**
444
- * 4. Ask Service Requirements
445
- */
446
- askServiceRequirements(serviceName?: string): string;
447
- /**
448
- * 5. Quote
449
- */
450
- quote(params: {
451
- service: string;
452
- price: number;
453
- recipientAddress: string;
454
- chain?: ChainName;
455
- }): string;
456
- /**
457
- * 7. Verifying
458
- */
459
- verifying(): string;
460
- /**
461
- * 7. Verification Passed
462
- */
463
- verificationPassed(amount: string): string;
464
- /**
465
- * 7. Verification Failed
466
- */
467
- verificationFailed(error: string): string;
468
- /**
469
- * 8. Delivery
470
- */
471
- deliver(params: {
472
- downloadUrl: string;
473
- fileHash?: string;
474
- }): string;
475
- /**
476
- * 9. Receipt
477
- */
478
- receipt(receipt: Receipt): string;
479
- /**
480
- * 10. End
481
- */
482
- end(): string;
483
- /**
484
- * Offer Permit payment option
485
- */
486
- offerPermitPayment(params: {
487
- service: string;
488
- price: number;
489
- sellerAddress: string;
490
- chain?: ChainName;
491
- invoiceId: string;
492
- }): string;
493
- /**
494
- * Confirm Permit received, executing payment
495
- */
496
- executingPermit(invoiceId: string): string;
497
- /**
498
- * Permit payment successful
499
- */
500
- permitPaymentReceived(params: {
501
- amount: number;
502
- txHash: string;
503
- invoiceId: string;
504
- }): string;
505
- /**
506
- * Permit payment failed
507
- */
508
- permitPaymentFailed(error: string, invoiceId: string): string;
509
- };
510
- declare const BuyerTemplates: {
511
- /**
512
- * 0. Request Service
513
- */
514
- requestService(service: string): string;
515
- /**
516
- * 1. No Capability
517
- */
518
- noCapability(): string;
519
- /**
520
- * 1. Has Capability
521
- */
522
- hasCapability(balance?: string): string;
523
- /**
524
- * 2. Agree to Guide
525
- */
526
- agreeToGuide(): string;
527
- /**
528
- * 3.1 Report Wallet Created
529
- */
530
- walletCreated(address: string): string;
531
- /**
532
- * 3.3 Report Funding Received
533
- */
534
- fundingReceived(amount: number): string;
535
- /**
536
- * 3.4 Request Funding from Owner
537
- */
538
- requestFunding(agentAddress: string, amount: number, reason?: string): string;
539
- /**
540
- * 4. Submit Requirements
541
- */
542
- submitRequirements(requirements: string): string;
543
- /**
544
- * 5. Confirm Purchase
545
- */
546
- confirmPurchase(): string;
547
- /**
548
- * 6. Report Payment Sent
549
- */
550
- paymentSent(txHash: string, amount: number): string;
551
- /**
552
- * 8. Confirm Delivery Received
553
- */
554
- deliveryReceived(): string;
555
- /**
556
- * 9. Confirm Receipt
557
- */
558
- receiptReceived(): string;
559
- /**
560
- * Request Permit from Boss
561
- */
562
- requestPermitFromBoss(params: {
563
- amount: number;
564
- agentAddress: string;
565
- deadlineHours?: number;
566
- reason?: string;
567
- }): string;
568
- /**
569
- * Confirm willing to pay via Permit
570
- */
571
- confirmPermitPayment(): string;
572
- /**
573
- * Send signed Permit to Seller
574
- */
575
- sendPermit(params: {
576
- permit: {
577
- owner: string;
578
- spender: string;
579
- value: string;
580
- deadline: number;
581
- nonce: number;
582
- v: number;
583
- r: string;
584
- s: string;
585
- };
586
- invoiceId: string;
587
- amount: number;
588
- }): string;
589
- /**
590
- * Simplified Permit message (compact JSON for agent parsing)
591
- */
592
- sendPermitCompact(params: {
593
- permit: {
594
- owner: string;
595
- spender: string;
596
- value: string;
597
- deadline: number;
598
- v: number;
599
- r: string;
600
- s: string;
601
- };
602
- invoiceId: string;
603
- }): string;
604
- };
605
- declare const StatusMarkers: {
606
- walletReady: string;
607
- permitReady: (amount: number) => string;
608
- permitSent: (invoiceId: string, amount: number) => string;
609
- awaitingPermit: (invoiceId: string) => string;
610
- paymentSent: (txHash: string, amount: number) => string;
611
- paymentConfirmed: (txHash: string) => string;
612
- delivered: (url: string, hash?: string) => string;
613
- receiptIssued: (invoiceId: string, txHash: string) => string;
614
- };
615
- declare function parseStatusMarker(message: string): {
616
- type: string;
617
- data: Record<string, string>;
618
- } | null;
619
-
620
- /**
621
- * x402 Client - Easy HTTP client with automatic payment handling
622
- *
623
- * Wraps @x402/fetch to provide simple API for AI Agents.
624
- *
625
- * @example
626
- * ```typescript
627
- * import { createX402Client } from 'moltspay/x402';
628
- *
629
- * // Using local wallet (AgentWallet)
630
- * const client = await createX402Client({ chain: 'base' });
631
- *
632
- * // Using CDP wallet
633
- * const client = await createX402Client({ chain: 'base', useCDP: true });
634
- *
635
- * // Make request - payment handled automatically
636
- * const response = await client.fetch('https://juai8.com/zen7/v1/video/generate');
637
- * ```
638
- */
639
-
640
- interface X402ClientConfig {
641
- /** Chain to use */
642
- chain?: ChainName;
643
- /** Use CDP wallet instead of local wallet */
644
- useCDP?: boolean;
645
- /** Custom private key (overrides stored wallet) */
646
- privateKey?: string;
647
- /** Storage directory for wallet */
648
- storageDir?: string;
649
- }
650
- interface X402Client {
651
- /** Fetch with automatic x402 payment handling */
652
- fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
653
- /** Wallet address */
654
- address: string;
655
- /** Chain being used */
656
- chain: ChainName;
657
- }
658
- /**
659
- * Check if @x402/fetch is available
660
- */
661
- declare function isX402Available(): boolean;
662
- /**
663
- * Create x402 client
664
- *
665
- * Automatically handles 402 Payment Required responses.
666
- *
667
- * @example
668
- * ```typescript
669
- * import { createX402Client } from 'moltspay/x402';
670
- *
671
- * const client = await createX402Client({ chain: 'base' });
672
- *
673
- * // Request paid API - payment handled automatically
674
- * const response = await client.fetch('https://juai8.com/zen7/v1/video/generate', {
675
- * method: 'POST',
676
- * headers: { 'Content-Type': 'application/json' },
677
- * body: JSON.stringify({ prompt: 'a cat dancing' })
678
- * });
679
- *
680
- * const result = await response.json();
681
- * ```
682
- */
683
- declare function createX402Client(config?: X402ClientConfig): Promise<X402Client>;
684
- /**
685
- * Simple one-shot x402 request
686
- *
687
- * For when you just need to make one paid request.
688
- *
689
- * @example
690
- * ```typescript
691
- * import { x402Fetch } from 'moltspay/x402';
692
- *
693
- * const response = await x402Fetch('https://juai8.com/zen7/v1/video/generate', {
694
- * method: 'POST',
695
- * body: JSON.stringify({ prompt: 'a cat dancing' })
696
- * }, { chain: 'base' });
697
- * ```
698
- */
699
- declare function x402Fetch(input: string | URL | Request, init?: RequestInit, config?: X402ClientConfig): Promise<Response>;
700
-
701
- /**
702
- * x402 Protocol Support for MoltsPay
703
- *
704
- * x402 is an open standard for HTTP-native payments.
705
- * When a server returns 402 Payment Required, the client can pay and retry.
706
- *
707
- * @see https://x402.org
708
- * @see https://github.com/coinbase/x402
709
- */
710
-
711
- declare const X402_VERSION = 2;
712
- declare const PAYMENT_REQUIRED_HEADER = "x-payment-required";
713
- declare const PAYMENT_HEADER = "x-payment";
714
- declare const PAYMENT_RESPONSE_HEADER = "x-payment-response";
715
- /**
716
- * x402 Payment Requirements (from server 402 response)
717
- */
718
- interface X402PaymentRequirements {
719
- /** Scheme (e.g., "exact") */
720
- scheme: string;
721
- /** Network (e.g., "eip155:8453" for Base) */
722
- network: string;
723
- /** Maximum amount in base units (e.g., "990000" for 0.99 USDC) */
724
- maxAmountRequired: string;
725
- /** Payee address */
726
- resource: string;
727
- /** Payment description */
728
- description?: string;
729
- /** MIME type of the resource */
730
- mimeType?: string;
731
- /** Output schema for the resource */
732
- outputSchema?: unknown;
733
- /** Expiration timestamp */
734
- expiration?: number;
735
- /** Extra data */
736
- extra?: string;
737
- }
738
- /**
739
- * x402 Payment Payload (client sends to server)
740
- */
741
- interface X402PaymentPayload {
742
- /** x402 protocol version */
743
- x402Version: number;
744
- /** Scheme used */
745
- scheme: string;
746
- /** Network used */
747
- network: string;
748
- /** Scheme-specific payload */
749
- payload: unknown;
750
- }
751
- /**
752
- * Parse x402 Payment Required header from 402 response
753
- */
754
- declare function parsePaymentRequired(header: string): X402PaymentRequirements[];
755
- /**
756
- * Encode payment payload for x-payment header
757
- */
758
- declare function encodePaymentPayload(payload: X402PaymentPayload): string;
759
- /**
760
- * Convert chain name to x402 network identifier
761
- */
762
- declare function chainToNetwork(chain: ChainName): string;
763
- /**
764
- * Convert x402 network identifier to chain name
765
- */
766
- declare function networkToChain(network: string): ChainName | null;
767
- /**
768
- * EIP-3009 Authorization for USDC transferWithAuthorization
769
- */
770
- interface EIP3009Authorization {
771
- from: string;
772
- to: string;
773
- value: string;
774
- validAfter: string;
775
- validBefore: string;
776
- nonce: string;
777
- }
778
- /**
779
- * Sign EIP-3009 transferWithAuthorization
780
- * Used for x402 "exact" scheme with USDC
781
- */
782
- declare function signEIP3009(wallet: ethers.Wallet, params: {
783
- to: string;
784
- amount: number;
785
- validAfter?: number;
786
- validBefore?: number;
787
- chain: ChainName;
788
- }): Promise<{
789
- authorization: EIP3009Authorization;
790
- signature: string;
791
- }>;
792
- /**
793
- * Create x402 payment payload for "exact" scheme on EVM
794
- */
795
- declare function createExactEvmPayload(wallet: ethers.Wallet, requirements: X402PaymentRequirements, chain: ChainName): Promise<X402PaymentPayload>;
796
- /**
797
- * Wrap fetch to handle x402 402 responses automatically
798
- *
799
- * @example
800
- * ```typescript
801
- * import { AgentWallet } from 'moltspay';
802
- * import { wrapFetchWith402 } from 'moltspay/x402';
803
- *
804
- * const wallet = new AgentWallet({ chain: 'base' });
805
- * const fetch402 = wrapFetchWith402(fetch, wallet);
806
- *
807
- * // Automatically handles 402 and pays
808
- * const response = await fetch402('https://api.example.com/paid-resource');
809
- * ```
810
- */
811
- declare function wrapFetchWith402(fetchFn: typeof fetch, wallet: {
812
- address: string;
813
- chain: ChainName;
814
- }, privateKey: string): (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
815
- /**
816
- * Server-side: Generate x402 Payment Required response
817
- */
818
- declare function createPaymentRequiredResponse(requirements: X402PaymentRequirements[]): {
819
- status: 402;
820
- headers: Record<string, string>;
821
- };
822
- /**
823
- * Server-side: Verify x402 payment header
824
- */
825
- declare function verifyPaymentHeader(header: string, expectedRecipient: string, expectedAmount: number): {
826
- valid: boolean;
827
- error?: string;
828
- payload?: X402PaymentPayload;
829
- };
830
-
831
- /**
832
- * CDP (Coinbase Developer Platform) Wallet Integration
833
- *
834
- * Creates and manages wallets via Coinbase's CDP SDK.
835
- * These wallets are hosted by Coinbase, making them easy to use for AI Agents.
836
- *
837
- * @see https://docs.cdp.coinbase.com/
838
- */
839
-
840
- interface CDPWalletConfig {
841
- /** Storage directory (default: ~/.moltspay) */
842
- storageDir?: string;
843
- /** Chain name */
844
- chain?: ChainName;
845
- /** CDP API credentials (or use env vars) */
846
- apiKeyId?: string;
847
- apiKeySecret?: string;
848
- walletSecret?: string;
849
- }
850
- interface CDPWalletData {
851
- /** Wallet address */
852
- address: string;
853
- /** CDP wallet ID */
854
- walletId: string;
855
- /** Chain */
856
- chain: ChainName;
857
- /** Created timestamp */
858
- createdAt: string;
859
- /** CDP account data (for restoration) */
860
- accountData?: string;
861
- }
862
- interface CDPInitResult {
863
- success: boolean;
864
- address?: string;
865
- walletId?: string;
866
- isNew?: boolean;
867
- error?: string;
868
- storagePath?: string;
869
- }
870
- /**
871
- * Check if CDP SDK is available
872
- */
873
- declare function isCDPAvailable(): boolean;
874
- /**
875
- * Initialize CDP wallet
876
- *
877
- * Creates a new CDP wallet or loads existing one.
878
- *
879
- * @example
880
- * ```bash
881
- * # Set credentials
882
- * export CDP_API_KEY_ID=your-key-id
883
- * export CDP_API_KEY_SECRET=your-key-secret
884
- *
885
- * # Initialize
886
- * npx moltspay init --cdp --chain base
887
- * ```
888
- */
889
- declare function initCDPWallet(config?: CDPWalletConfig): Promise<CDPInitResult>;
890
- /**
891
- * Load existing CDP wallet
892
- */
893
- declare function loadCDPWallet(config?: CDPWalletConfig): CDPWalletData | null;
894
- /**
895
- * Get CDP wallet address (quick check without full init)
896
- */
897
- declare function getCDPWalletAddress(storageDir?: string): string | null;
898
- /**
899
- * CDP Wallet class for making payments
900
- *
901
- * Uses CDP SDK for wallet operations with x402 support.
902
- */
903
- declare class CDPWallet {
904
- readonly address: string;
905
- readonly chain: ChainName;
906
- readonly chainConfig: ReturnType<typeof getChain>;
907
- private storageDir;
908
- constructor(config?: CDPWalletConfig);
909
- /**
910
- * Get USDC balance
911
- */
912
- getBalance(): Promise<{
913
- usdc: string;
914
- eth: string;
915
- }>;
916
- /**
917
- * Transfer USDC to a recipient
918
- *
919
- * Requires CDP SDK and credentials to sign transactions.
920
- */
921
- transfer(params: {
922
- to: string;
923
- amount: number;
924
- }): Promise<{
925
- success: boolean;
926
- txHash?: string;
927
- error?: string;
928
- explorerUrl?: string;
929
- }>;
930
- /**
931
- * Create viem-compatible signer for x402
932
- *
933
- * This allows using CDP wallet with x402 protocol.
934
- */
935
- getViemAccount(): Promise<unknown>;
936
- }
937
-
938
- export { AgentWallet, AuditAction, AuditEntry, AuditLog, BuyerTemplates, type CDPInitResult, CDPWallet, type CDPWalletConfig, type CDPWalletData, ChainConfig, ChainName, CreateInvoiceParams, type EIP3009Authorization, Invoice, PAYMENT_HEADER, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PaymentAgent, PaymentAgentConfig, type Receipt, type ReceiptParams, SellerTemplates, StatusMarkers, VerifyOptions, VerifyResult, WalletBalance, type X402Client, type X402ClientConfig, type X402PaymentPayload, type X402PaymentRequirements, X402_VERSION, chainToNetwork, createExactEvmPayload, createPaymentRequiredResponse, createX402Client, encodePaymentPayload, formatReceiptJson, formatReceiptMessage, formatReceiptText, generateReceipt, generateReceiptFromInvoice, getAgentAddress, getCDPWalletAddress, getChain, initCDPWallet, isCDPAvailable, isX402Available, loadCDPWallet, networkToChain, parsePaymentRequired, parseStatusMarker, signEIP3009, verifyPaymentHeader, wrapFetchWith402, x402Fetch };
6
+ export { CDPWallet, getCDPWalletAddress, initCDPWallet, isCDPAvailable, loadCDPWallet } from './cdp/index.mjs';
7
+ import './index-Dg8n6wdW.mjs';