moltspay 0.5.4 → 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.
- package/README.md +0 -124
- package/dist/cdp/index.d.mts +111 -0
- package/dist/cdp/index.d.ts +111 -0
- package/dist/cdp/index.js +30655 -0
- package/dist/cdp/index.js.map +1 -0
- package/dist/cdp/index.mjs +30631 -0
- package/dist/cdp/index.mjs.map +1 -0
- package/dist/chains/index.d.mts +1 -1
- package/dist/chains/index.d.ts +1 -1
- package/dist/cli/index.js +940 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +917 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/client/index.d.mts +134 -0
- package/dist/client/index.d.ts +134 -0
- package/dist/client/index.js +331 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +296 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/createWallet-D53qu7ie.d.mts +77 -0
- package/dist/createWallet-D53qu7ie.d.ts +77 -0
- package/dist/index-Dg8n6wdW.d.mts +32 -0
- package/dist/index-Dg8n6wdW.d.ts +32 -0
- package/dist/index.d.mts +6 -1483
- package/dist/index.d.ts +6 -1483
- package/dist/index.js +31039 -4254
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31042 -4203
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.d.mts +120 -0
- package/dist/server/index.d.ts +120 -0
- package/dist/server/index.js +418 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +393 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/wallet/index.d.mts +3 -451
- package/dist/wallet/index.d.ts +3 -451
- package/dist/wallet/index.js +5 -1021
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +16 -1015
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +19 -19
- package/dist/cli.js +0 -1984
- package/dist/cli.js.map +0 -1
- package/dist/cli.mjs +0 -1969
- package/dist/cli.mjs.map +0 -1
- package/dist/guide/index.d.mts +0 -39
- package/dist/guide/index.d.ts +0 -39
- package/dist/guide/index.js +0 -181
- package/dist/guide/index.js.map +0 -1
- package/dist/guide/index.mjs +0 -152
- package/dist/guide/index.mjs.map +0 -1
- package/dist/index-CyFg9s2m.d.mts +0 -161
- package/dist/index-CyFg9s2m.d.ts +0 -161
- package/dist/orders/index.d.mts +0 -97
- package/dist/orders/index.d.ts +0 -97
- package/dist/orders/index.js +0 -162
- package/dist/orders/index.js.map +0 -1
- package/dist/orders/index.mjs +0 -136
- package/dist/orders/index.mjs.map +0 -1
- package/dist/permit/index.d.mts +0 -49
- package/dist/permit/index.d.ts +0 -49
- package/dist/permit/index.js +0 -273
- package/dist/permit/index.js.map +0 -1
- package/dist/permit/index.mjs +0 -246
- package/dist/permit/index.mjs.map +0 -1
- /package/dist/{cli.d.mts → cli/index.d.mts} +0 -0
- /package/dist/{cli.d.ts → cli/index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -14,7 +14,6 @@ Blockchain payment infrastructure for AI Agents on Moltbook.
|
|
|
14
14
|
- 🧾 **Receipt Generation** - Transaction receipts for audit/accounting
|
|
15
15
|
- 🔄 **x402 Protocol** - HTTP-native payments (v0.4.0+)
|
|
16
16
|
- 🏦 **CDP Wallet** - Coinbase Developer Platform integration (v0.4.0+)
|
|
17
|
-
- 🏷️ **Deferred Payment** - Credit-based pay-later for trusted agents (v0.5.4+)
|
|
18
17
|
|
|
19
18
|
## Installation
|
|
20
19
|
|
|
@@ -494,129 +493,6 @@ npx moltspay x402 https://example.com/api -X POST -d "{\"prompt\": \"your text\"
|
|
|
494
493
|
|
|
495
494
|
**Cross-platform tip:** For complex JSON, save to a file and use `-d @filename.json` - works on all systems!
|
|
496
495
|
|
|
497
|
-
## Deferred Payment (Credit-based Pay Later) - v0.5.4+
|
|
498
|
-
|
|
499
|
-
For trusted Agent-to-Agent relationships, deferred payment allows service delivery before payment settlement.
|
|
500
|
-
|
|
501
|
-
### Quick Start
|
|
502
|
-
|
|
503
|
-
```typescript
|
|
504
|
-
import { DeferredPaymentManager, DeferredSellerTemplates } from 'moltspay';
|
|
505
|
-
|
|
506
|
-
// Initialize manager (seller side)
|
|
507
|
-
const manager = new DeferredPaymentManager({
|
|
508
|
-
sellerAddress: '0xSELLER...',
|
|
509
|
-
sellerId: 'zen7',
|
|
510
|
-
chain: 'base',
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
// Create credit account for a buyer
|
|
514
|
-
const account = await manager.createCreditAccount({
|
|
515
|
-
buyerId: 'buyer-agent-123',
|
|
516
|
-
creditLimit: 100, // $100 USDC credit line
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
// Charge a service (deliver now, pay later)
|
|
520
|
-
const result = await manager.charge({
|
|
521
|
-
buyerId: 'buyer-agent-123',
|
|
522
|
-
orderId: 'vo_123',
|
|
523
|
-
service: 'Video Generation 5s 720p',
|
|
524
|
-
amount: 3.99,
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
// Service delivered immediately, buyer pays later...
|
|
528
|
-
|
|
529
|
-
// When buyer sends payment, record settlement
|
|
530
|
-
await manager.recordSettlement({
|
|
531
|
-
paymentId: result.payment.paymentId,
|
|
532
|
-
amount: 3.99,
|
|
533
|
-
txHash: '0xABC...',
|
|
534
|
-
});
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
### Features
|
|
538
|
-
|
|
539
|
-
- **Credit Accounts** - Extend credit lines to trusted buyers
|
|
540
|
-
- **Flexible Terms** - Net-30, Net-60, custom payment terms
|
|
541
|
-
- **Auto Settlement Verification** - On-chain payment verification
|
|
542
|
-
- **Balance Tracking** - Full transaction history per account
|
|
543
|
-
- **Overdue Management** - Mark overdue payments, apply late fees
|
|
544
|
-
- **Installment Plans** - Support for milestone/installment payments
|
|
545
|
-
|
|
546
|
-
### Conversation Flow
|
|
547
|
-
|
|
548
|
-
```
|
|
549
|
-
Buyer: "I'd like video generation, but prefer to pay later."
|
|
550
|
-
|
|
551
|
-
Seller: "I can set up a credit account for you:
|
|
552
|
-
- Credit Limit: $100 USDC
|
|
553
|
-
- Payment Terms: Net-30
|
|
554
|
-
Do you want me to set this up?"
|
|
555
|
-
|
|
556
|
-
Buyer: "Yes, please."
|
|
557
|
-
|
|
558
|
-
Seller: "Done! Account ID: ca_xxx. I'll charge services to your account.
|
|
559
|
-
[status:credit_account_created id=ca_xxx limit=100 USDC]"
|
|
560
|
-
|
|
561
|
-
[Service delivered, charge added]
|
|
562
|
-
|
|
563
|
-
Seller: "Service charged: $3.99. Due in 30 days.
|
|
564
|
-
[status:charge_added payment=dp_xxx amount=3.99 USDC]"
|
|
565
|
-
|
|
566
|
-
[Later, buyer pays]
|
|
567
|
-
|
|
568
|
-
Buyer: "I've sent $3.99 USDC. TX: 0xABC..."
|
|
569
|
-
|
|
570
|
-
Seller: "Payment verified. Balance: $0.00. Thank you!
|
|
571
|
-
[status:settlement_received payment=dp_xxx tx=0xABC amount=3.99 USDC]"
|
|
572
|
-
```
|
|
573
|
-
|
|
574
|
-
### Storage Options
|
|
575
|
-
|
|
576
|
-
```typescript
|
|
577
|
-
// In-memory (testing)
|
|
578
|
-
import { MemoryDeferredStore } from 'moltspay';
|
|
579
|
-
|
|
580
|
-
// File-based (single process production)
|
|
581
|
-
import { JsonDeferredStore } from 'moltspay';
|
|
582
|
-
|
|
583
|
-
const store = new JsonDeferredStore({
|
|
584
|
-
filePath: './data/deferred-payments.json'
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
const manager = new DeferredPaymentManager({
|
|
588
|
-
sellerAddress: '0x...',
|
|
589
|
-
sellerId: 'zen7',
|
|
590
|
-
store, // Use persistent storage
|
|
591
|
-
});
|
|
592
|
-
```
|
|
593
|
-
|
|
594
|
-
### Conversation Templates
|
|
595
|
-
|
|
596
|
-
```typescript
|
|
597
|
-
import { DeferredSellerTemplates, DeferredBuyerTemplates } from 'moltspay';
|
|
598
|
-
|
|
599
|
-
// Seller offers deferred payment
|
|
600
|
-
DeferredSellerTemplates.offerDeferredPayment({
|
|
601
|
-
service: 'Video Generation',
|
|
602
|
-
price: 3.99,
|
|
603
|
-
netDays: 30,
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
// Seller shows account statement
|
|
607
|
-
const summary = await manager.getAccountSummary(accountId);
|
|
608
|
-
DeferredSellerTemplates.accountStatement(summary);
|
|
609
|
-
|
|
610
|
-
// Buyer requests statement
|
|
611
|
-
DeferredBuyerTemplates.requestStatement();
|
|
612
|
-
|
|
613
|
-
// Buyer announces settlement
|
|
614
|
-
DeferredBuyerTemplates.announceSettlement({
|
|
615
|
-
amount: 3.99,
|
|
616
|
-
txHash: '0xABC...',
|
|
617
|
-
});
|
|
618
|
-
```
|
|
619
|
-
|
|
620
496
|
## Environment Variables
|
|
621
497
|
|
|
622
498
|
```bash
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { C as ChainName } from '../index-Dg8n6wdW.mjs';
|
|
2
|
+
import { getChain } from '../chains/index.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* CDP (Coinbase Developer Platform) Wallet Integration
|
|
6
|
+
*
|
|
7
|
+
* Creates and manages wallets via Coinbase's CDP SDK.
|
|
8
|
+
* These wallets are hosted by Coinbase, making them easy to use for AI Agents.
|
|
9
|
+
*
|
|
10
|
+
* @see https://docs.cdp.coinbase.com/
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
interface CDPWalletConfig {
|
|
14
|
+
/** Storage directory (default: ~/.moltspay) */
|
|
15
|
+
storageDir?: string;
|
|
16
|
+
/** Chain name */
|
|
17
|
+
chain?: ChainName;
|
|
18
|
+
/** CDP API credentials (or use env vars) */
|
|
19
|
+
apiKeyId?: string;
|
|
20
|
+
apiKeySecret?: string;
|
|
21
|
+
walletSecret?: string;
|
|
22
|
+
}
|
|
23
|
+
interface CDPWalletData {
|
|
24
|
+
/** Wallet address */
|
|
25
|
+
address: string;
|
|
26
|
+
/** CDP wallet ID */
|
|
27
|
+
walletId: string;
|
|
28
|
+
/** Chain */
|
|
29
|
+
chain: ChainName;
|
|
30
|
+
/** Created timestamp */
|
|
31
|
+
createdAt: string;
|
|
32
|
+
/** CDP account data (for restoration) */
|
|
33
|
+
accountData?: string;
|
|
34
|
+
}
|
|
35
|
+
interface CDPInitResult {
|
|
36
|
+
success: boolean;
|
|
37
|
+
address?: string;
|
|
38
|
+
walletId?: string;
|
|
39
|
+
isNew?: boolean;
|
|
40
|
+
error?: string;
|
|
41
|
+
storagePath?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if CDP SDK is available
|
|
45
|
+
*/
|
|
46
|
+
declare function isCDPAvailable(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Initialize CDP wallet
|
|
49
|
+
*
|
|
50
|
+
* Creates a new CDP wallet or loads existing one.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```bash
|
|
54
|
+
* # Set credentials
|
|
55
|
+
* export CDP_API_KEY_ID=your-key-id
|
|
56
|
+
* export CDP_API_KEY_SECRET=your-key-secret
|
|
57
|
+
*
|
|
58
|
+
* # Initialize
|
|
59
|
+
* npx moltspay init --cdp --chain base
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function initCDPWallet(config?: CDPWalletConfig): Promise<CDPInitResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Load existing CDP wallet
|
|
65
|
+
*/
|
|
66
|
+
declare function loadCDPWallet(config?: CDPWalletConfig): CDPWalletData | null;
|
|
67
|
+
/**
|
|
68
|
+
* Get CDP wallet address (quick check without full init)
|
|
69
|
+
*/
|
|
70
|
+
declare function getCDPWalletAddress(storageDir?: string): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* CDP Wallet class for making payments
|
|
73
|
+
*
|
|
74
|
+
* Uses CDP SDK for wallet operations with x402 support.
|
|
75
|
+
*/
|
|
76
|
+
declare class CDPWallet {
|
|
77
|
+
readonly address: string;
|
|
78
|
+
readonly chain: ChainName;
|
|
79
|
+
readonly chainConfig: ReturnType<typeof getChain>;
|
|
80
|
+
private storageDir;
|
|
81
|
+
constructor(config?: CDPWalletConfig);
|
|
82
|
+
/**
|
|
83
|
+
* Get USDC balance
|
|
84
|
+
*/
|
|
85
|
+
getBalance(): Promise<{
|
|
86
|
+
usdc: string;
|
|
87
|
+
eth: string;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Transfer USDC to a recipient
|
|
91
|
+
*
|
|
92
|
+
* Requires CDP SDK and credentials to sign transactions.
|
|
93
|
+
*/
|
|
94
|
+
transfer(params: {
|
|
95
|
+
to: string;
|
|
96
|
+
amount: number;
|
|
97
|
+
}): Promise<{
|
|
98
|
+
success: boolean;
|
|
99
|
+
txHash?: string;
|
|
100
|
+
error?: string;
|
|
101
|
+
explorerUrl?: string;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Create viem-compatible signer for x402
|
|
105
|
+
*
|
|
106
|
+
* This allows using CDP wallet with x402 protocol.
|
|
107
|
+
*/
|
|
108
|
+
getViemAccount(): Promise<unknown>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { type CDPInitResult, CDPWallet, type CDPWalletConfig, type CDPWalletData, getCDPWalletAddress, initCDPWallet, isCDPAvailable, loadCDPWallet };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { C as ChainName } from '../index-Dg8n6wdW.js';
|
|
2
|
+
import { getChain } from '../chains/index.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* CDP (Coinbase Developer Platform) Wallet Integration
|
|
6
|
+
*
|
|
7
|
+
* Creates and manages wallets via Coinbase's CDP SDK.
|
|
8
|
+
* These wallets are hosted by Coinbase, making them easy to use for AI Agents.
|
|
9
|
+
*
|
|
10
|
+
* @see https://docs.cdp.coinbase.com/
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
interface CDPWalletConfig {
|
|
14
|
+
/** Storage directory (default: ~/.moltspay) */
|
|
15
|
+
storageDir?: string;
|
|
16
|
+
/** Chain name */
|
|
17
|
+
chain?: ChainName;
|
|
18
|
+
/** CDP API credentials (or use env vars) */
|
|
19
|
+
apiKeyId?: string;
|
|
20
|
+
apiKeySecret?: string;
|
|
21
|
+
walletSecret?: string;
|
|
22
|
+
}
|
|
23
|
+
interface CDPWalletData {
|
|
24
|
+
/** Wallet address */
|
|
25
|
+
address: string;
|
|
26
|
+
/** CDP wallet ID */
|
|
27
|
+
walletId: string;
|
|
28
|
+
/** Chain */
|
|
29
|
+
chain: ChainName;
|
|
30
|
+
/** Created timestamp */
|
|
31
|
+
createdAt: string;
|
|
32
|
+
/** CDP account data (for restoration) */
|
|
33
|
+
accountData?: string;
|
|
34
|
+
}
|
|
35
|
+
interface CDPInitResult {
|
|
36
|
+
success: boolean;
|
|
37
|
+
address?: string;
|
|
38
|
+
walletId?: string;
|
|
39
|
+
isNew?: boolean;
|
|
40
|
+
error?: string;
|
|
41
|
+
storagePath?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if CDP SDK is available
|
|
45
|
+
*/
|
|
46
|
+
declare function isCDPAvailable(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Initialize CDP wallet
|
|
49
|
+
*
|
|
50
|
+
* Creates a new CDP wallet or loads existing one.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```bash
|
|
54
|
+
* # Set credentials
|
|
55
|
+
* export CDP_API_KEY_ID=your-key-id
|
|
56
|
+
* export CDP_API_KEY_SECRET=your-key-secret
|
|
57
|
+
*
|
|
58
|
+
* # Initialize
|
|
59
|
+
* npx moltspay init --cdp --chain base
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function initCDPWallet(config?: CDPWalletConfig): Promise<CDPInitResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Load existing CDP wallet
|
|
65
|
+
*/
|
|
66
|
+
declare function loadCDPWallet(config?: CDPWalletConfig): CDPWalletData | null;
|
|
67
|
+
/**
|
|
68
|
+
* Get CDP wallet address (quick check without full init)
|
|
69
|
+
*/
|
|
70
|
+
declare function getCDPWalletAddress(storageDir?: string): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* CDP Wallet class for making payments
|
|
73
|
+
*
|
|
74
|
+
* Uses CDP SDK for wallet operations with x402 support.
|
|
75
|
+
*/
|
|
76
|
+
declare class CDPWallet {
|
|
77
|
+
readonly address: string;
|
|
78
|
+
readonly chain: ChainName;
|
|
79
|
+
readonly chainConfig: ReturnType<typeof getChain>;
|
|
80
|
+
private storageDir;
|
|
81
|
+
constructor(config?: CDPWalletConfig);
|
|
82
|
+
/**
|
|
83
|
+
* Get USDC balance
|
|
84
|
+
*/
|
|
85
|
+
getBalance(): Promise<{
|
|
86
|
+
usdc: string;
|
|
87
|
+
eth: string;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Transfer USDC to a recipient
|
|
91
|
+
*
|
|
92
|
+
* Requires CDP SDK and credentials to sign transactions.
|
|
93
|
+
*/
|
|
94
|
+
transfer(params: {
|
|
95
|
+
to: string;
|
|
96
|
+
amount: number;
|
|
97
|
+
}): Promise<{
|
|
98
|
+
success: boolean;
|
|
99
|
+
txHash?: string;
|
|
100
|
+
error?: string;
|
|
101
|
+
explorerUrl?: string;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Create viem-compatible signer for x402
|
|
105
|
+
*
|
|
106
|
+
* This allows using CDP wallet with x402 protocol.
|
|
107
|
+
*/
|
|
108
|
+
getViemAccount(): Promise<unknown>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { type CDPInitResult, CDPWallet, type CDPWalletConfig, type CDPWalletData, getCDPWalletAddress, initCDPWallet, isCDPAvailable, loadCDPWallet };
|