moltspay 0.1.3 → 0.2.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.
@@ -102,4 +102,191 @@ declare class SecureWallet {
102
102
  private updateDailyTotal;
103
103
  }
104
104
 
105
- export { SecureWallet, Wallet, type WalletConfig };
105
+ /**
106
+ * createWallet - Create a new wallet for Agent
107
+ *
108
+ * Features:
109
+ * - Generate new Ethereum wallet
110
+ * - Securely store private key (encrypted or plaintext, depending on config)
111
+ * - Return wallet address (never return private key)
112
+ */
113
+ interface CreateWalletOptions {
114
+ /** Storage path, default ~/.moltspay/wallet.json */
115
+ storagePath?: string;
116
+ /** Encryption password (optional, plaintext if not provided) */
117
+ password?: string;
118
+ /** Wallet label/name */
119
+ label?: string;
120
+ /** Overwrite if wallet exists */
121
+ overwrite?: boolean;
122
+ }
123
+ interface WalletData {
124
+ address: string;
125
+ label?: string;
126
+ createdAt: string;
127
+ encrypted: boolean;
128
+ /** Encrypted or plaintext private key */
129
+ privateKey: string;
130
+ /** Encryption IV */
131
+ iv?: string;
132
+ /** Encryption salt */
133
+ salt?: string;
134
+ }
135
+ interface CreateWalletResult {
136
+ success: boolean;
137
+ address?: string;
138
+ storagePath?: string;
139
+ error?: string;
140
+ /** Whether newly created (false means loaded existing) */
141
+ isNew?: boolean;
142
+ }
143
+ /**
144
+ * Create new wallet
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Create unencrypted wallet
149
+ * const result = await createWallet();
150
+ * console.log('Wallet address:', result.address);
151
+ *
152
+ * // Create encrypted wallet
153
+ * const result = await createWallet({ password: 'mySecurePassword' });
154
+ *
155
+ * // Specify storage path
156
+ * const result = await createWallet({ storagePath: './my-wallet.json' });
157
+ * ```
158
+ */
159
+ declare function createWallet(options?: CreateWalletOptions): CreateWalletResult;
160
+ /**
161
+ * Load existing wallet
162
+ */
163
+ declare function loadWallet(options?: {
164
+ storagePath?: string;
165
+ password?: string;
166
+ }): {
167
+ success: boolean;
168
+ address?: string;
169
+ privateKey?: string;
170
+ error?: string;
171
+ };
172
+ /**
173
+ * Get wallet address (no password required)
174
+ */
175
+ declare function getWalletAddress(storagePath?: string): string | null;
176
+ /**
177
+ * Check if wallet exists
178
+ */
179
+ declare function walletExists(storagePath?: string): boolean;
180
+
181
+ /**
182
+ * PermitWallet - Pay using Boss's Permit authorization
183
+ *
184
+ * Scenario:
185
+ * - Agent doesn't have USDC, but Boss gave a Permit authorization
186
+ * - Agent uses Permit signature + own wallet to execute transferFrom
187
+ * - Agent only needs small amount of ETH for gas, USDC is deducted from Boss's wallet
188
+ */
189
+
190
+ interface PermitData {
191
+ /** Boss's wallet address (USDC holder) */
192
+ owner: string;
193
+ /** Agent's wallet address (authorized spender) */
194
+ spender: string;
195
+ /** Authorized amount (USDC, raw 6 decimal value) */
196
+ value: string;
197
+ /** Expiration timestamp */
198
+ deadline: number;
199
+ /** Signature v */
200
+ v: number;
201
+ /** Signature r */
202
+ r: string;
203
+ /** Signature s */
204
+ s: string;
205
+ }
206
+ interface PermitWalletConfig {
207
+ chain?: ChainName;
208
+ /** Agent's private key (for executing transactions) */
209
+ privateKey?: string;
210
+ /** Load private key from file */
211
+ walletPath?: string;
212
+ /** Decryption password */
213
+ walletPassword?: string;
214
+ rpcUrl?: string;
215
+ }
216
+ interface TransferWithPermitParams {
217
+ /** Recipient address */
218
+ to: string;
219
+ /** Amount (USDC) */
220
+ amount: number;
221
+ /** Boss-signed Permit data */
222
+ permit: PermitData;
223
+ }
224
+ interface TransferWithPermitResult extends TransferResult {
225
+ /** Permit transaction hash */
226
+ permitTxHash?: string;
227
+ /** Transfer transaction hash */
228
+ transferTxHash?: string;
229
+ }
230
+ declare class PermitWallet {
231
+ readonly chain: ChainName;
232
+ readonly chainConfig: ChainConfig;
233
+ readonly address: string;
234
+ private wallet;
235
+ private provider;
236
+ private usdcContract;
237
+ constructor(config?: PermitWalletConfig);
238
+ /**
239
+ * Check if Permit is valid (current allowance)
240
+ */
241
+ checkPermitAllowance(owner: string): Promise<string>;
242
+ /**
243
+ * Pay using Permit authorization
244
+ *
245
+ * Flow:
246
+ * 1. Call permit() to record Boss's authorization in the contract
247
+ * 2. Call transferFrom() to transfer from Boss's wallet to recipient
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const wallet = new PermitWallet({ chain: 'base' });
252
+ *
253
+ * // Boss-signed permit data
254
+ * const permit = {
255
+ * owner: '0xBOSS...',
256
+ * spender: wallet.address,
257
+ * value: '10000000', // 10 USDC
258
+ * deadline: 1234567890,
259
+ * v: 27,
260
+ * r: '0x...',
261
+ * s: '0x...'
262
+ * };
263
+ *
264
+ * const result = await wallet.transferWithPermit({
265
+ * to: '0xSELLER...',
266
+ * amount: 3.99,
267
+ * permit
268
+ * });
269
+ * ```
270
+ */
271
+ transferWithPermit(params: TransferWithPermitParams): Promise<TransferWithPermitResult>;
272
+ /**
273
+ * Get ETH balance (for gas)
274
+ */
275
+ getGasBalance(): Promise<string>;
276
+ /**
277
+ * Check if there's enough gas
278
+ */
279
+ hasEnoughGas(minEth?: number): Promise<boolean>;
280
+ }
281
+ /**
282
+ * Format Permit request message (to send to Boss)
283
+ */
284
+ declare function formatPermitRequest(params: {
285
+ agentAddress: string;
286
+ amount: number;
287
+ deadlineHours?: number;
288
+ chain?: ChainName;
289
+ reason?: string;
290
+ }): string;
291
+
292
+ export { type CreateWalletOptions, type CreateWalletResult, type PermitData, PermitWallet, type PermitWalletConfig, SecureWallet, type TransferWithPermitParams, type TransferWithPermitResult, Wallet, type WalletConfig, type WalletData, createWallet, formatPermitRequest, getWalletAddress, loadWallet, walletExists };
@@ -102,4 +102,191 @@ declare class SecureWallet {
102
102
  private updateDailyTotal;
103
103
  }
104
104
 
105
- export { SecureWallet, Wallet, type WalletConfig };
105
+ /**
106
+ * createWallet - Create a new wallet for Agent
107
+ *
108
+ * Features:
109
+ * - Generate new Ethereum wallet
110
+ * - Securely store private key (encrypted or plaintext, depending on config)
111
+ * - Return wallet address (never return private key)
112
+ */
113
+ interface CreateWalletOptions {
114
+ /** Storage path, default ~/.moltspay/wallet.json */
115
+ storagePath?: string;
116
+ /** Encryption password (optional, plaintext if not provided) */
117
+ password?: string;
118
+ /** Wallet label/name */
119
+ label?: string;
120
+ /** Overwrite if wallet exists */
121
+ overwrite?: boolean;
122
+ }
123
+ interface WalletData {
124
+ address: string;
125
+ label?: string;
126
+ createdAt: string;
127
+ encrypted: boolean;
128
+ /** Encrypted or plaintext private key */
129
+ privateKey: string;
130
+ /** Encryption IV */
131
+ iv?: string;
132
+ /** Encryption salt */
133
+ salt?: string;
134
+ }
135
+ interface CreateWalletResult {
136
+ success: boolean;
137
+ address?: string;
138
+ storagePath?: string;
139
+ error?: string;
140
+ /** Whether newly created (false means loaded existing) */
141
+ isNew?: boolean;
142
+ }
143
+ /**
144
+ * Create new wallet
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Create unencrypted wallet
149
+ * const result = await createWallet();
150
+ * console.log('Wallet address:', result.address);
151
+ *
152
+ * // Create encrypted wallet
153
+ * const result = await createWallet({ password: 'mySecurePassword' });
154
+ *
155
+ * // Specify storage path
156
+ * const result = await createWallet({ storagePath: './my-wallet.json' });
157
+ * ```
158
+ */
159
+ declare function createWallet(options?: CreateWalletOptions): CreateWalletResult;
160
+ /**
161
+ * Load existing wallet
162
+ */
163
+ declare function loadWallet(options?: {
164
+ storagePath?: string;
165
+ password?: string;
166
+ }): {
167
+ success: boolean;
168
+ address?: string;
169
+ privateKey?: string;
170
+ error?: string;
171
+ };
172
+ /**
173
+ * Get wallet address (no password required)
174
+ */
175
+ declare function getWalletAddress(storagePath?: string): string | null;
176
+ /**
177
+ * Check if wallet exists
178
+ */
179
+ declare function walletExists(storagePath?: string): boolean;
180
+
181
+ /**
182
+ * PermitWallet - Pay using Boss's Permit authorization
183
+ *
184
+ * Scenario:
185
+ * - Agent doesn't have USDC, but Boss gave a Permit authorization
186
+ * - Agent uses Permit signature + own wallet to execute transferFrom
187
+ * - Agent only needs small amount of ETH for gas, USDC is deducted from Boss's wallet
188
+ */
189
+
190
+ interface PermitData {
191
+ /** Boss's wallet address (USDC holder) */
192
+ owner: string;
193
+ /** Agent's wallet address (authorized spender) */
194
+ spender: string;
195
+ /** Authorized amount (USDC, raw 6 decimal value) */
196
+ value: string;
197
+ /** Expiration timestamp */
198
+ deadline: number;
199
+ /** Signature v */
200
+ v: number;
201
+ /** Signature r */
202
+ r: string;
203
+ /** Signature s */
204
+ s: string;
205
+ }
206
+ interface PermitWalletConfig {
207
+ chain?: ChainName;
208
+ /** Agent's private key (for executing transactions) */
209
+ privateKey?: string;
210
+ /** Load private key from file */
211
+ walletPath?: string;
212
+ /** Decryption password */
213
+ walletPassword?: string;
214
+ rpcUrl?: string;
215
+ }
216
+ interface TransferWithPermitParams {
217
+ /** Recipient address */
218
+ to: string;
219
+ /** Amount (USDC) */
220
+ amount: number;
221
+ /** Boss-signed Permit data */
222
+ permit: PermitData;
223
+ }
224
+ interface TransferWithPermitResult extends TransferResult {
225
+ /** Permit transaction hash */
226
+ permitTxHash?: string;
227
+ /** Transfer transaction hash */
228
+ transferTxHash?: string;
229
+ }
230
+ declare class PermitWallet {
231
+ readonly chain: ChainName;
232
+ readonly chainConfig: ChainConfig;
233
+ readonly address: string;
234
+ private wallet;
235
+ private provider;
236
+ private usdcContract;
237
+ constructor(config?: PermitWalletConfig);
238
+ /**
239
+ * Check if Permit is valid (current allowance)
240
+ */
241
+ checkPermitAllowance(owner: string): Promise<string>;
242
+ /**
243
+ * Pay using Permit authorization
244
+ *
245
+ * Flow:
246
+ * 1. Call permit() to record Boss's authorization in the contract
247
+ * 2. Call transferFrom() to transfer from Boss's wallet to recipient
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const wallet = new PermitWallet({ chain: 'base' });
252
+ *
253
+ * // Boss-signed permit data
254
+ * const permit = {
255
+ * owner: '0xBOSS...',
256
+ * spender: wallet.address,
257
+ * value: '10000000', // 10 USDC
258
+ * deadline: 1234567890,
259
+ * v: 27,
260
+ * r: '0x...',
261
+ * s: '0x...'
262
+ * };
263
+ *
264
+ * const result = await wallet.transferWithPermit({
265
+ * to: '0xSELLER...',
266
+ * amount: 3.99,
267
+ * permit
268
+ * });
269
+ * ```
270
+ */
271
+ transferWithPermit(params: TransferWithPermitParams): Promise<TransferWithPermitResult>;
272
+ /**
273
+ * Get ETH balance (for gas)
274
+ */
275
+ getGasBalance(): Promise<string>;
276
+ /**
277
+ * Check if there's enough gas
278
+ */
279
+ hasEnoughGas(minEth?: number): Promise<boolean>;
280
+ }
281
+ /**
282
+ * Format Permit request message (to send to Boss)
283
+ */
284
+ declare function formatPermitRequest(params: {
285
+ agentAddress: string;
286
+ amount: number;
287
+ deadlineHours?: number;
288
+ chain?: ChainName;
289
+ reason?: string;
290
+ }): string;
291
+
292
+ export { type CreateWalletOptions, type CreateWalletResult, type PermitData, PermitWallet, type PermitWalletConfig, SecureWallet, type TransferWithPermitParams, type TransferWithPermitResult, Wallet, type WalletConfig, type WalletData, createWallet, formatPermitRequest, getWalletAddress, loadWallet, walletExists };