moltspay 0.5.4 → 0.7.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.
Files changed (68) hide show
  1. package/README.md +0 -124
  2. package/dist/cdp/index.d.mts +111 -0
  3. package/dist/cdp/index.d.ts +111 -0
  4. package/dist/cdp/index.js +30655 -0
  5. package/dist/cdp/index.js.map +1 -0
  6. package/dist/cdp/index.mjs +30631 -0
  7. package/dist/cdp/index.mjs.map +1 -0
  8. package/dist/chains/index.d.mts +1 -1
  9. package/dist/chains/index.d.ts +1 -1
  10. package/dist/cli/index.js +990 -0
  11. package/dist/cli/index.js.map +1 -0
  12. package/dist/cli/index.mjs +967 -0
  13. package/dist/cli/index.mjs.map +1 -0
  14. package/dist/client/index.d.mts +134 -0
  15. package/dist/client/index.d.ts +134 -0
  16. package/dist/client/index.js +331 -0
  17. package/dist/client/index.js.map +1 -0
  18. package/dist/client/index.mjs +296 -0
  19. package/dist/client/index.mjs.map +1 -0
  20. package/dist/createWallet-D53qu7ie.d.mts +77 -0
  21. package/dist/createWallet-D53qu7ie.d.ts +77 -0
  22. package/dist/index-Dg8n6wdW.d.mts +32 -0
  23. package/dist/index-Dg8n6wdW.d.ts +32 -0
  24. package/dist/index.d.mts +6 -1483
  25. package/dist/index.d.ts +6 -1483
  26. package/dist/index.js +31039 -4254
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +31042 -4203
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/server/index.d.mts +120 -0
  31. package/dist/server/index.d.ts +120 -0
  32. package/dist/server/index.js +418 -0
  33. package/dist/server/index.js.map +1 -0
  34. package/dist/server/index.mjs +393 -0
  35. package/dist/server/index.mjs.map +1 -0
  36. package/dist/wallet/index.d.mts +3 -451
  37. package/dist/wallet/index.d.ts +3 -451
  38. package/dist/wallet/index.js +5 -1021
  39. package/dist/wallet/index.js.map +1 -1
  40. package/dist/wallet/index.mjs +16 -1015
  41. package/dist/wallet/index.mjs.map +1 -1
  42. package/package.json +19 -19
  43. package/dist/cli.js +0 -1984
  44. package/dist/cli.js.map +0 -1
  45. package/dist/cli.mjs +0 -1969
  46. package/dist/cli.mjs.map +0 -1
  47. package/dist/guide/index.d.mts +0 -39
  48. package/dist/guide/index.d.ts +0 -39
  49. package/dist/guide/index.js +0 -181
  50. package/dist/guide/index.js.map +0 -1
  51. package/dist/guide/index.mjs +0 -152
  52. package/dist/guide/index.mjs.map +0 -1
  53. package/dist/index-CyFg9s2m.d.mts +0 -161
  54. package/dist/index-CyFg9s2m.d.ts +0 -161
  55. package/dist/orders/index.d.mts +0 -97
  56. package/dist/orders/index.d.ts +0 -97
  57. package/dist/orders/index.js +0 -162
  58. package/dist/orders/index.js.map +0 -1
  59. package/dist/orders/index.mjs +0 -136
  60. package/dist/orders/index.mjs.map +0 -1
  61. package/dist/permit/index.d.mts +0 -49
  62. package/dist/permit/index.d.ts +0 -49
  63. package/dist/permit/index.js +0 -273
  64. package/dist/permit/index.js.map +0 -1
  65. package/dist/permit/index.mjs +0 -246
  66. package/dist/permit/index.mjs.map +0 -1
  67. /package/dist/{cli.d.mts → cli/index.d.mts} +0 -0
  68. /package/dist/{cli.d.ts → cli/index.d.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,1484 +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.js';
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.js';
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.js';
4
- export { PermitPayment } from './permit/index.js';
5
- export { CreateOrderParams, MemoryOrderStore, Order, OrderManager, OrderStatus, OrderStore } from './orders/index.js';
1
+ export { Charge, ChargeStatus, MoltsPayServer, MoltsPayServerOptions, PaymentRequest, ProviderConfig, RegisteredSkill, ServiceConfig, ServicesManifest, SkillFunction } from './server/index.js';
2
+ export { ClientConfig, MoltsPayClient, MoltsPayClientOptions, PaymentRequired, ProviderInfo, ServiceInfo, ServicesResponse, VerifyResponse, WalletData } from './client/index.js';
3
+ export { CHAINS, ERC20_ABI, getChain, getChainById, listChains } from './chains/index.js';
4
+ export { c as createWallet, g as getWalletAddress, l as loadWallet, w as walletExists } from './createWallet-D53qu7ie.js';
6
5
  export { VerifyPaymentParams, VerifyPaymentResult, getTransactionStatus, verifyPayment, waitForTransaction } from './verify/index.js';
7
- export { PaymentGuideParams, extractTransactionHash, generatePaymentGuide, generatePaymentReminder, generateWalletGuide, hasTransactionHash } from './guide/index.js';
8
- import { getChain } from './chains/index.js';
9
- export { CHAINS, ERC20_ABI, getChainById, listChains } from './chains/index.js';
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
- /**
939
- * Deferred Payment Types
940
- *
941
- * Supports credit-based, milestone, and subscription payment models
942
- * for trusted Agent-to-Agent transactions.
943
- */
944
-
945
- interface CreditAccount {
946
- /** Unique account identifier */
947
- accountId: string;
948
- /** Buyer/debtor address or identifier */
949
- buyerId: string;
950
- /** Seller/creditor address */
951
- sellerId: string;
952
- /** Credit limit in USDC */
953
- creditLimit: number;
954
- /** Current balance owed (positive = buyer owes seller) */
955
- balance: number;
956
- /** Account status */
957
- status: CreditAccountStatus;
958
- /** Settlement chain */
959
- chain: ChainName;
960
- /** Payment terms */
961
- terms: PaymentTerms;
962
- /** Account creation time */
963
- createdAt: string;
964
- /** Last activity time */
965
- updatedAt: string;
966
- /** Transaction history */
967
- transactions: CreditTransaction[];
968
- /** Optional metadata */
969
- metadata?: Record<string, unknown>;
970
- }
971
- type CreditAccountStatus = 'active' | 'suspended' | 'closed' | 'pending';
972
- interface PaymentTerms {
973
- /** Net days for payment (e.g., 30 = Net-30) */
974
- netDays: number;
975
- /** Grace period after due date before suspension */
976
- graceDays: number;
977
- /** Settlement frequency: on-demand, daily, weekly, monthly */
978
- settlementFrequency: SettlementFrequency;
979
- /** Minimum balance to trigger auto-settlement */
980
- autoSettleThreshold?: number;
981
- /** Late fee percentage (optional) */
982
- lateFeePercent?: number;
983
- }
984
- type SettlementFrequency = 'on-demand' | 'daily' | 'weekly' | 'monthly';
985
- interface CreditTransaction {
986
- /** Transaction ID */
987
- txId: string;
988
- /** Transaction type */
989
- type: CreditTransactionType;
990
- /** Amount (positive for charges, negative for payments/credits) */
991
- amount: number;
992
- /** Running balance after this transaction */
993
- balanceAfter: number;
994
- /** Reference (order ID, service name, etc.) */
995
- reference: string;
996
- /** Optional on-chain tx hash for settlements */
997
- onChainTxHash?: string;
998
- /** Transaction time */
999
- timestamp: string;
1000
- /** Notes */
1001
- notes?: string;
1002
- }
1003
- type CreditTransactionType = 'charge' | 'payment' | 'credit' | 'adjustment' | 'late_fee' | 'refund';
1004
- interface DeferredPayment {
1005
- /** Payment ID */
1006
- paymentId: string;
1007
- /** Associated credit account (if using credit) */
1008
- accountId?: string;
1009
- /** Order/service ID */
1010
- orderId: string;
1011
- /** Service description */
1012
- service: string;
1013
- /** Total amount */
1014
- amount: number;
1015
- /** Amount paid so far */
1016
- paidAmount: number;
1017
- /** Payment status */
1018
- status: DeferredPaymentStatus;
1019
- /** Due date (ISO string) */
1020
- dueDate: string;
1021
- /** Settlement chain */
1022
- chain: ChainName;
1023
- /** Buyer identifier */
1024
- buyerId: string;
1025
- /** Seller address */
1026
- sellerAddress: string;
1027
- /** Payment plan (for installments) */
1028
- plan?: PaymentPlan;
1029
- /** Creation time */
1030
- createdAt: string;
1031
- /** Last update time */
1032
- updatedAt: string;
1033
- /** Settlement transactions */
1034
- settlements: Settlement[];
1035
- /** Optional metadata */
1036
- metadata?: Record<string, unknown>;
1037
- }
1038
- type DeferredPaymentStatus = 'pending' | 'partial' | 'paid' | 'overdue' | 'settled' | 'cancelled' | 'disputed';
1039
- interface PaymentPlan {
1040
- /** Plan type */
1041
- type: 'fixed' | 'milestone' | 'subscription';
1042
- /** Total installments */
1043
- totalInstallments: number;
1044
- /** Completed installments */
1045
- completedInstallments: number;
1046
- /** Installment schedule */
1047
- schedule: Installment[];
1048
- }
1049
- interface Installment {
1050
- /** Installment number (1-based) */
1051
- number: number;
1052
- /** Amount for this installment */
1053
- amount: number;
1054
- /** Due date */
1055
- dueDate: string;
1056
- /** Status */
1057
- status: 'pending' | 'paid' | 'overdue';
1058
- /** Settlement tx hash (if paid) */
1059
- txHash?: string;
1060
- /** Milestone description (for milestone-based) */
1061
- milestone?: string;
1062
- }
1063
- interface Settlement {
1064
- /** Settlement ID */
1065
- settlementId: string;
1066
- /** Amount settled */
1067
- amount: number;
1068
- /** On-chain transaction hash */
1069
- txHash: string;
1070
- /** Chain */
1071
- chain: ChainName;
1072
- /** Settlement time */
1073
- timestamp: string;
1074
- /** Verification status */
1075
- verified: boolean;
1076
- }
1077
- interface CreateCreditAccountParams {
1078
- buyerId: string;
1079
- sellerId: string;
1080
- creditLimit: number;
1081
- chain?: ChainName;
1082
- terms?: Partial<PaymentTerms>;
1083
- metadata?: Record<string, unknown>;
1084
- }
1085
- interface CreateDeferredPaymentParams {
1086
- accountId?: string;
1087
- orderId: string;
1088
- service: string;
1089
- amount: number;
1090
- buyerId: string;
1091
- sellerAddress: string;
1092
- chain?: ChainName;
1093
- dueInDays?: number;
1094
- plan?: Omit<PaymentPlan, 'completedInstallments'>;
1095
- metadata?: Record<string, unknown>;
1096
- }
1097
- interface RecordSettlementParams {
1098
- paymentId: string;
1099
- amount: number;
1100
- txHash: string;
1101
- chain?: ChainName;
1102
- }
1103
- interface DeferredPaymentStore {
1104
- createAccount(params: CreateCreditAccountParams): Promise<CreditAccount>;
1105
- getAccount(accountId: string): Promise<CreditAccount | null>;
1106
- getAccountByBuyer(buyerId: string, sellerId: string): Promise<CreditAccount | null>;
1107
- updateAccount(accountId: string, updates: Partial<CreditAccount>): Promise<CreditAccount>;
1108
- listAccounts(sellerId: string): Promise<CreditAccount[]>;
1109
- createPayment(params: CreateDeferredPaymentParams): Promise<DeferredPayment>;
1110
- getPayment(paymentId: string): Promise<DeferredPayment | null>;
1111
- updatePayment(paymentId: string, updates: Partial<DeferredPayment>): Promise<DeferredPayment>;
1112
- listPayments(filter: PaymentFilter): Promise<DeferredPayment[]>;
1113
- addTransaction(accountId: string, tx: Omit<CreditTransaction, 'txId' | 'timestamp'>): Promise<CreditTransaction>;
1114
- }
1115
- interface PaymentFilter {
1116
- accountId?: string;
1117
- buyerId?: string;
1118
- sellerId?: string;
1119
- status?: DeferredPaymentStatus | DeferredPaymentStatus[];
1120
- overdueOnly?: boolean;
1121
- }
1122
-
1123
- /**
1124
- * Deferred Payment Manager
1125
- *
1126
- * Manages credit accounts and deferred payments for Agent-to-Agent transactions.
1127
- * Supports credit-based, milestone, and installment payment models.
1128
- */
1129
-
1130
- interface DeferredPaymentManagerConfig {
1131
- /** Seller's wallet address for receiving payments */
1132
- sellerAddress: string;
1133
- /** Seller's identifier */
1134
- sellerId: string;
1135
- /** Default chain for payments */
1136
- chain?: ChainName;
1137
- /** Custom store implementation (defaults to MemoryDeferredStore) */
1138
- store?: DeferredPaymentStore;
1139
- /** Auto-verify settlements on-chain */
1140
- autoVerify?: boolean;
1141
- }
1142
- interface ChargeResult {
1143
- success: boolean;
1144
- payment?: DeferredPayment;
1145
- transaction?: CreditTransaction;
1146
- error?: string;
1147
- /** True if credit limit would be exceeded */
1148
- creditExceeded?: boolean;
1149
- }
1150
- interface SettlementResult {
1151
- success: boolean;
1152
- settlement?: Settlement;
1153
- payment?: DeferredPayment;
1154
- transaction?: CreditTransaction;
1155
- error?: string;
1156
- }
1157
- interface AccountSummary {
1158
- account: CreditAccount;
1159
- pendingPayments: DeferredPayment[];
1160
- overduePayments: DeferredPayment[];
1161
- availableCredit: number;
1162
- totalOwed: number;
1163
- }
1164
- declare class DeferredPaymentManager {
1165
- private config;
1166
- constructor(config: DeferredPaymentManagerConfig);
1167
- /**
1168
- * Create a new credit account for a buyer
1169
- */
1170
- createCreditAccount(params: {
1171
- buyerId: string;
1172
- creditLimit: number;
1173
- netDays?: number;
1174
- metadata?: Record<string, unknown>;
1175
- }): Promise<CreditAccount>;
1176
- /**
1177
- * Get or create a credit account for a buyer
1178
- */
1179
- getOrCreateAccount(params: {
1180
- buyerId: string;
1181
- creditLimit?: number;
1182
- }): Promise<CreditAccount>;
1183
- /**
1184
- * Get credit account by ID
1185
- */
1186
- getAccount(accountId: string): Promise<CreditAccount | null>;
1187
- /**
1188
- * Get credit account by buyer ID
1189
- */
1190
- getAccountByBuyer(buyerId: string): Promise<CreditAccount | null>;
1191
- /**
1192
- * Update credit limit
1193
- */
1194
- updateCreditLimit(accountId: string, newLimit: number): Promise<CreditAccount>;
1195
- /**
1196
- * Suspend an account
1197
- */
1198
- suspendAccount(accountId: string, reason?: string): Promise<CreditAccount>;
1199
- /**
1200
- * Reactivate a suspended account
1201
- */
1202
- reactivateAccount(accountId: string): Promise<CreditAccount>;
1203
- /**
1204
- * Get account summary with pending/overdue payments
1205
- */
1206
- getAccountSummary(accountId: string): Promise<AccountSummary | null>;
1207
- /**
1208
- * List all credit accounts for this seller
1209
- */
1210
- listAccounts(): Promise<CreditAccount[]>;
1211
- /**
1212
- * Charge a service to a credit account (deferred payment)
1213
- */
1214
- charge(params: {
1215
- buyerId: string;
1216
- orderId: string;
1217
- service: string;
1218
- amount: number;
1219
- dueInDays?: number;
1220
- metadata?: Record<string, unknown>;
1221
- }): Promise<ChargeResult>;
1222
- /**
1223
- * Create a deferred payment without a credit account (standalone)
1224
- */
1225
- createDeferredPayment(params: CreateDeferredPaymentParams): Promise<DeferredPayment>;
1226
- /**
1227
- * Get deferred payment by ID
1228
- */
1229
- getPayment(paymentId: string): Promise<DeferredPayment | null>;
1230
- /**
1231
- * List deferred payments with filters
1232
- */
1233
- listPayments(filter?: PaymentFilter): Promise<DeferredPayment[]>;
1234
- /**
1235
- * Get overdue payments
1236
- */
1237
- getOverduePayments(): Promise<DeferredPayment[]>;
1238
- /**
1239
- * Record a settlement (payment received)
1240
- */
1241
- recordSettlement(params: RecordSettlementParams): Promise<SettlementResult>;
1242
- /**
1243
- * Settle all pending charges for an account
1244
- */
1245
- settleAccount(accountId: string, txHash: string): Promise<SettlementResult>;
1246
- /**
1247
- * Issue a credit (reduce balance owed)
1248
- */
1249
- issueCredit(params: {
1250
- accountId: string;
1251
- amount: number;
1252
- reason: string;
1253
- }): Promise<CreditTransaction>;
1254
- /**
1255
- * Issue a refund
1256
- */
1257
- issueRefund(params: {
1258
- paymentId: string;
1259
- amount: number;
1260
- reason: string;
1261
- }): Promise<SettlementResult>;
1262
- /**
1263
- * Mark overdue payments
1264
- */
1265
- markOverduePayments(): Promise<DeferredPayment[]>;
1266
- /**
1267
- * Apply late fees to overdue accounts
1268
- */
1269
- applyLateFees(): Promise<CreditTransaction[]>;
1270
- }
1271
-
1272
- /**
1273
- * In-Memory Store for Deferred Payments
1274
- *
1275
- * Suitable for testing and single-process deployments.
1276
- * For production, implement DeferredPaymentStore with persistent storage.
1277
- */
1278
-
1279
- declare class MemoryDeferredStore implements DeferredPaymentStore {
1280
- private accounts;
1281
- private payments;
1282
- private buyerSellerIndex;
1283
- private makeKey;
1284
- createAccount(params: CreateCreditAccountParams): Promise<CreditAccount>;
1285
- getAccount(accountId: string): Promise<CreditAccount | null>;
1286
- getAccountByBuyer(buyerId: string, sellerId: string): Promise<CreditAccount | null>;
1287
- updateAccount(accountId: string, updates: Partial<CreditAccount>): Promise<CreditAccount>;
1288
- listAccounts(sellerId: string): Promise<CreditAccount[]>;
1289
- createPayment(params: CreateDeferredPaymentParams): Promise<DeferredPayment>;
1290
- getPayment(paymentId: string): Promise<DeferredPayment | null>;
1291
- updatePayment(paymentId: string, updates: Partial<DeferredPayment>): Promise<DeferredPayment>;
1292
- listPayments(filter: PaymentFilter): Promise<DeferredPayment[]>;
1293
- addTransaction(accountId: string, tx: Omit<CreditTransaction, 'txId' | 'timestamp'>): Promise<CreditTransaction>;
1294
- /**
1295
- * Get all data (for debugging/export)
1296
- */
1297
- export(): {
1298
- accounts: CreditAccount[];
1299
- payments: DeferredPayment[];
1300
- };
1301
- /**
1302
- * Import data (for restore)
1303
- */
1304
- import(data: {
1305
- accounts: CreditAccount[];
1306
- payments: DeferredPayment[];
1307
- }): void;
1308
- /**
1309
- * Clear all data
1310
- */
1311
- clear(): void;
1312
- }
1313
-
1314
- /**
1315
- * JSON File-based Store for Deferred Payments
1316
- *
1317
- * Persists deferred payment data to a JSON file.
1318
- * Suitable for single-process production deployments.
1319
- *
1320
- * For multi-process or distributed systems, implement DeferredPaymentStore
1321
- * with a proper database (PostgreSQL, Redis, etc.).
1322
- */
1323
-
1324
- interface JsonDeferredStoreConfig {
1325
- /** Path to the JSON file */
1326
- filePath: string;
1327
- /** Auto-save after each write operation (default: true) */
1328
- autoSave?: boolean;
1329
- /** Pretty print JSON (default: true) */
1330
- prettyPrint?: boolean;
1331
- }
1332
- declare class JsonDeferredStore implements DeferredPaymentStore {
1333
- private memory;
1334
- private config;
1335
- private dirty;
1336
- constructor(config: JsonDeferredStoreConfig);
1337
- /**
1338
- * Load data from file
1339
- */
1340
- load(): void;
1341
- /**
1342
- * Save data to file
1343
- */
1344
- save(): void;
1345
- /**
1346
- * Mark as dirty and optionally auto-save
1347
- */
1348
- private markDirty;
1349
- /**
1350
- * Check if there are unsaved changes
1351
- */
1352
- isDirty(): boolean;
1353
- createAccount(params: CreateCreditAccountParams): Promise<CreditAccount>;
1354
- getAccount(accountId: string): Promise<CreditAccount | null>;
1355
- getAccountByBuyer(buyerId: string, sellerId: string): Promise<CreditAccount | null>;
1356
- updateAccount(accountId: string, updates: Partial<CreditAccount>): Promise<CreditAccount>;
1357
- listAccounts(sellerId: string): Promise<CreditAccount[]>;
1358
- createPayment(params: CreateDeferredPaymentParams): Promise<DeferredPayment>;
1359
- getPayment(paymentId: string): Promise<DeferredPayment | null>;
1360
- updatePayment(paymentId: string, updates: Partial<DeferredPayment>): Promise<DeferredPayment>;
1361
- listPayments(filter: PaymentFilter): Promise<DeferredPayment[]>;
1362
- addTransaction(accountId: string, tx: Omit<CreditTransaction, 'txId' | 'timestamp'>): Promise<CreditTransaction>;
1363
- /**
1364
- * Export all data
1365
- */
1366
- export(): {
1367
- accounts: CreditAccount[];
1368
- payments: DeferredPayment[];
1369
- };
1370
- /**
1371
- * Clear all data (including file)
1372
- */
1373
- clear(): void;
1374
- }
1375
-
1376
- /**
1377
- * Deferred Payment Conversation Templates
1378
- *
1379
- * Natural language templates for Agent-to-Agent deferred payment flows.
1380
- */
1381
-
1382
- declare const DeferredStatusMarkers: {
1383
- creditAccountCreated: (accountId: string, limit: number) => string;
1384
- chargeAdded: (paymentId: string, amount: number) => string;
1385
- settlementReceived: (paymentId: string, txHash: string, amount: number) => string;
1386
- accountSettled: (accountId: string, txHash: string, amount: number) => string;
1387
- creditIssued: (accountId: string, amount: number) => string;
1388
- accountSuspended: (accountId: string, reason: string) => string;
1389
- paymentOverdue: (paymentId: string, amount: number) => string;
1390
- };
1391
- declare const DeferredSellerTemplates: {
1392
- /**
1393
- * Offer deferred payment option
1394
- */
1395
- offerDeferredPayment: (params: {
1396
- service: string;
1397
- price: number;
1398
- netDays?: number;
1399
- }) => string;
1400
- /**
1401
- * Explain credit account setup
1402
- */
1403
- explainCreditAccount: () => string;
1404
- /**
1405
- * Confirm credit account creation
1406
- */
1407
- creditAccountCreated: (account: CreditAccount) => string;
1408
- /**
1409
- * Charge confirmation
1410
- */
1411
- chargeConfirmation: (payment: DeferredPayment, availableCredit: number) => string;
1412
- /**
1413
- * Credit limit exceeded
1414
- */
1415
- creditLimitExceeded: (params: {
1416
- requested: number;
1417
- available: number;
1418
- balance: number;
1419
- limit: number;
1420
- }) => string;
1421
- /**
1422
- * Account summary/statement
1423
- */
1424
- accountStatement: (summary: AccountSummary) => string;
1425
- /**
1426
- * Settlement confirmation
1427
- */
1428
- settlementConfirmation: (params: {
1429
- amount: number;
1430
- txHash: string;
1431
- newBalance: number;
1432
- paymentId?: string;
1433
- }) => string;
1434
- /**
1435
- * Overdue notice
1436
- */
1437
- overdueNotice: (payments: DeferredPayment[]) => string;
1438
- /**
1439
- * Credit issued confirmation
1440
- */
1441
- creditIssued: (params: {
1442
- amount: number;
1443
- reason: string;
1444
- newBalance: number;
1445
- accountId: string;
1446
- }) => string;
1447
- };
1448
- declare const DeferredBuyerTemplates: {
1449
- /**
1450
- * Request deferred payment
1451
- */
1452
- requestDeferredPayment: (service: string) => string;
1453
- /**
1454
- * Accept credit account offer
1455
- */
1456
- acceptCreditAccount: () => string;
1457
- /**
1458
- * Request credit limit increase
1459
- */
1460
- requestCreditIncrease: (currentLimit: number, requestedLimit: number) => string;
1461
- /**
1462
- * Request account statement
1463
- */
1464
- requestStatement: () => string;
1465
- /**
1466
- * Announce settlement payment
1467
- */
1468
- announceSettlement: (params: {
1469
- amount: number;
1470
- txHash: string;
1471
- accountId?: string;
1472
- }) => string;
1473
- /**
1474
- * Dispute a charge
1475
- */
1476
- disputeCharge: (paymentId: string, reason: string) => string;
1477
- };
1478
- interface ParsedDeferredStatus {
1479
- type: string;
1480
- data: Record<string, string>;
1481
- }
1482
- declare function parseDeferredStatusMarker(text: string): ParsedDeferredStatus | null;
1483
-
1484
- export { type AccountSummary, AgentWallet, AuditAction, AuditEntry, AuditLog, BuyerTemplates, type CDPInitResult, CDPWallet, type CDPWalletConfig, type CDPWalletData, ChainConfig, ChainName, type ChargeResult, type CreateCreditAccountParams, type CreateDeferredPaymentParams, CreateInvoiceParams, type CreditAccount, type CreditAccountStatus, type CreditTransaction, type CreditTransactionType, DeferredBuyerTemplates, type DeferredPayment, DeferredPaymentManager, type DeferredPaymentManagerConfig, type DeferredPaymentStatus, type DeferredPaymentStore, DeferredSellerTemplates, DeferredStatusMarkers, type EIP3009Authorization, type Installment, Invoice, JsonDeferredStore, type JsonDeferredStoreConfig, MemoryDeferredStore, PAYMENT_HEADER, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, type ParsedDeferredStatus, PaymentAgent, PaymentAgentConfig, type PaymentFilter, type PaymentPlan, type PaymentTerms, type Receipt, type ReceiptParams, type RecordSettlementParams, SellerTemplates, type Settlement, type SettlementFrequency, type SettlementResult, 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, parseDeferredStatusMarker, parsePaymentRequired, parseStatusMarker, signEIP3009, verifyPaymentHeader, wrapFetchWith402, x402Fetch };
6
+ export { CDPWallet, getCDPWalletAddress, initCDPWallet, isCDPAvailable, loadCDPWallet } from './cdp/index.js';
7
+ import './index-Dg8n6wdW.js';