moltspay 0.1.2 → 0.2.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 +126 -0
- package/dist/cli.js +17 -3
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +17 -3
- package/dist/cli.mjs.map +1 -1
- package/dist/guide/index.d.mts +39 -0
- package/dist/guide/index.d.ts +39 -0
- package/dist/guide/index.js +181 -0
- package/dist/guide/index.js.map +1 -0
- package/dist/guide/index.mjs +152 -0
- package/dist/guide/index.mjs.map +1 -0
- package/dist/index.d.mts +250 -2
- package/dist/index.d.ts +250 -2
- package/dist/index.js +979 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +958 -12
- package/dist/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +188 -1
- package/dist/wallet/index.d.ts +188 -1
- package/dist/wallet/index.js +378 -2
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +371 -1
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/wallet/index.d.mts
CHANGED
|
@@ -102,4 +102,191 @@ declare class SecureWallet {
|
|
|
102
102
|
private updateDailyTotal;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
/**
|
|
106
|
+
* createWallet - 为 Agent 创建新钱包
|
|
107
|
+
*
|
|
108
|
+
* 功能:
|
|
109
|
+
* - 生成新的以太坊钱包
|
|
110
|
+
* - 安全存储私钥(加密或明文,取决于配置)
|
|
111
|
+
* - 返回钱包地址(不返回私钥)
|
|
112
|
+
*/
|
|
113
|
+
interface CreateWalletOptions {
|
|
114
|
+
/** 存储路径,默认 ~/.moltspay/wallet.json */
|
|
115
|
+
storagePath?: string;
|
|
116
|
+
/** 加密密码(可选,不提供则明文存储) */
|
|
117
|
+
password?: string;
|
|
118
|
+
/** 钱包标签/名称 */
|
|
119
|
+
label?: string;
|
|
120
|
+
/** 如果钱包已存在,是否覆盖 */
|
|
121
|
+
overwrite?: boolean;
|
|
122
|
+
}
|
|
123
|
+
interface WalletData {
|
|
124
|
+
address: string;
|
|
125
|
+
label?: string;
|
|
126
|
+
createdAt: string;
|
|
127
|
+
encrypted: boolean;
|
|
128
|
+
/** 加密后的私钥或明文私钥 */
|
|
129
|
+
privateKey: string;
|
|
130
|
+
/** 加密用的 IV */
|
|
131
|
+
iv?: string;
|
|
132
|
+
/** 加密用的 salt */
|
|
133
|
+
salt?: string;
|
|
134
|
+
}
|
|
135
|
+
interface CreateWalletResult {
|
|
136
|
+
success: boolean;
|
|
137
|
+
address?: string;
|
|
138
|
+
storagePath?: string;
|
|
139
|
+
error?: string;
|
|
140
|
+
/** 是否是新创建的(false 表示加载了已有钱包) */
|
|
141
|
+
isNew?: boolean;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 创建新钱包
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* // 创建未加密钱包
|
|
149
|
+
* const result = await createWallet();
|
|
150
|
+
* console.log('钱包地址:', result.address);
|
|
151
|
+
*
|
|
152
|
+
* // 创建加密钱包
|
|
153
|
+
* const result = await createWallet({ password: 'mySecurePassword' });
|
|
154
|
+
*
|
|
155
|
+
* // 指定存储路径
|
|
156
|
+
* const result = await createWallet({ storagePath: './my-wallet.json' });
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare function createWallet(options?: CreateWalletOptions): CreateWalletResult;
|
|
160
|
+
/**
|
|
161
|
+
* 加载已有钱包
|
|
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
|
+
* 获取钱包地址(不需要密码)
|
|
174
|
+
*/
|
|
175
|
+
declare function getWalletAddress(storagePath?: string): string | null;
|
|
176
|
+
/**
|
|
177
|
+
* 检查钱包是否存在
|
|
178
|
+
*/
|
|
179
|
+
declare function walletExists(storagePath?: string): boolean;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* PermitWallet - 使用 Boss 授权的 Permit 进行支付
|
|
183
|
+
*
|
|
184
|
+
* 场景:
|
|
185
|
+
* - Agent 没有自己的 USDC,但 Boss 给了 Permit 授权
|
|
186
|
+
* - Agent 使用 Permit 签名 + 自己的钱包执行 transferFrom
|
|
187
|
+
* - Agent 只需要少量 ETH 付 gas,USDC 从 Boss 钱包扣除
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
interface PermitData {
|
|
191
|
+
/** Boss 的钱包地址(USDC 持有者) */
|
|
192
|
+
owner: string;
|
|
193
|
+
/** Agent 的钱包地址(被授权者) */
|
|
194
|
+
spender: string;
|
|
195
|
+
/** 授权金额(USDC,6位小数的原始值) */
|
|
196
|
+
value: string;
|
|
197
|
+
/** 过期时间戳 */
|
|
198
|
+
deadline: number;
|
|
199
|
+
/** 签名 v */
|
|
200
|
+
v: number;
|
|
201
|
+
/** 签名 r */
|
|
202
|
+
r: string;
|
|
203
|
+
/** 签名 s */
|
|
204
|
+
s: string;
|
|
205
|
+
}
|
|
206
|
+
interface PermitWalletConfig {
|
|
207
|
+
chain?: ChainName;
|
|
208
|
+
/** Agent 的私钥(用于执行交易) */
|
|
209
|
+
privateKey?: string;
|
|
210
|
+
/** 从文件加载私钥 */
|
|
211
|
+
walletPath?: string;
|
|
212
|
+
/** 解密密码 */
|
|
213
|
+
walletPassword?: string;
|
|
214
|
+
rpcUrl?: string;
|
|
215
|
+
}
|
|
216
|
+
interface TransferWithPermitParams {
|
|
217
|
+
/** 收款地址 */
|
|
218
|
+
to: string;
|
|
219
|
+
/** 金额(USDC) */
|
|
220
|
+
amount: number;
|
|
221
|
+
/** Boss 签署的 Permit 数据 */
|
|
222
|
+
permit: PermitData;
|
|
223
|
+
}
|
|
224
|
+
interface TransferWithPermitResult extends TransferResult {
|
|
225
|
+
/** Permit 交易 hash */
|
|
226
|
+
permitTxHash?: string;
|
|
227
|
+
/** Transfer 交易 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
|
+
* 检查 Permit 是否有效
|
|
240
|
+
*/
|
|
241
|
+
checkPermitAllowance(owner: string): Promise<string>;
|
|
242
|
+
/**
|
|
243
|
+
* 使用 Permit 授权进行支付
|
|
244
|
+
*
|
|
245
|
+
* 流程:
|
|
246
|
+
* 1. 调用 permit() 让合约记录 Boss 的授权
|
|
247
|
+
* 2. 调用 transferFrom() 从 Boss 钱包转账到收款方
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const wallet = new PermitWallet({ chain: 'base' });
|
|
252
|
+
*
|
|
253
|
+
* // Boss 签署的 permit 数据
|
|
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
|
+
* 获取 ETH 余额(用于支付 gas)
|
|
274
|
+
*/
|
|
275
|
+
getGasBalance(): Promise<string>;
|
|
276
|
+
/**
|
|
277
|
+
* 检查是否有足够的 gas
|
|
278
|
+
*/
|
|
279
|
+
hasEnoughGas(minEth?: number): Promise<boolean>;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* 格式化 Permit 请求消息(发给 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 };
|
package/dist/wallet/index.d.ts
CHANGED
|
@@ -102,4 +102,191 @@ declare class SecureWallet {
|
|
|
102
102
|
private updateDailyTotal;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
/**
|
|
106
|
+
* createWallet - 为 Agent 创建新钱包
|
|
107
|
+
*
|
|
108
|
+
* 功能:
|
|
109
|
+
* - 生成新的以太坊钱包
|
|
110
|
+
* - 安全存储私钥(加密或明文,取决于配置)
|
|
111
|
+
* - 返回钱包地址(不返回私钥)
|
|
112
|
+
*/
|
|
113
|
+
interface CreateWalletOptions {
|
|
114
|
+
/** 存储路径,默认 ~/.moltspay/wallet.json */
|
|
115
|
+
storagePath?: string;
|
|
116
|
+
/** 加密密码(可选,不提供则明文存储) */
|
|
117
|
+
password?: string;
|
|
118
|
+
/** 钱包标签/名称 */
|
|
119
|
+
label?: string;
|
|
120
|
+
/** 如果钱包已存在,是否覆盖 */
|
|
121
|
+
overwrite?: boolean;
|
|
122
|
+
}
|
|
123
|
+
interface WalletData {
|
|
124
|
+
address: string;
|
|
125
|
+
label?: string;
|
|
126
|
+
createdAt: string;
|
|
127
|
+
encrypted: boolean;
|
|
128
|
+
/** 加密后的私钥或明文私钥 */
|
|
129
|
+
privateKey: string;
|
|
130
|
+
/** 加密用的 IV */
|
|
131
|
+
iv?: string;
|
|
132
|
+
/** 加密用的 salt */
|
|
133
|
+
salt?: string;
|
|
134
|
+
}
|
|
135
|
+
interface CreateWalletResult {
|
|
136
|
+
success: boolean;
|
|
137
|
+
address?: string;
|
|
138
|
+
storagePath?: string;
|
|
139
|
+
error?: string;
|
|
140
|
+
/** 是否是新创建的(false 表示加载了已有钱包) */
|
|
141
|
+
isNew?: boolean;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 创建新钱包
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* // 创建未加密钱包
|
|
149
|
+
* const result = await createWallet();
|
|
150
|
+
* console.log('钱包地址:', result.address);
|
|
151
|
+
*
|
|
152
|
+
* // 创建加密钱包
|
|
153
|
+
* const result = await createWallet({ password: 'mySecurePassword' });
|
|
154
|
+
*
|
|
155
|
+
* // 指定存储路径
|
|
156
|
+
* const result = await createWallet({ storagePath: './my-wallet.json' });
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
declare function createWallet(options?: CreateWalletOptions): CreateWalletResult;
|
|
160
|
+
/**
|
|
161
|
+
* 加载已有钱包
|
|
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
|
+
* 获取钱包地址(不需要密码)
|
|
174
|
+
*/
|
|
175
|
+
declare function getWalletAddress(storagePath?: string): string | null;
|
|
176
|
+
/**
|
|
177
|
+
* 检查钱包是否存在
|
|
178
|
+
*/
|
|
179
|
+
declare function walletExists(storagePath?: string): boolean;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* PermitWallet - 使用 Boss 授权的 Permit 进行支付
|
|
183
|
+
*
|
|
184
|
+
* 场景:
|
|
185
|
+
* - Agent 没有自己的 USDC,但 Boss 给了 Permit 授权
|
|
186
|
+
* - Agent 使用 Permit 签名 + 自己的钱包执行 transferFrom
|
|
187
|
+
* - Agent 只需要少量 ETH 付 gas,USDC 从 Boss 钱包扣除
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
interface PermitData {
|
|
191
|
+
/** Boss 的钱包地址(USDC 持有者) */
|
|
192
|
+
owner: string;
|
|
193
|
+
/** Agent 的钱包地址(被授权者) */
|
|
194
|
+
spender: string;
|
|
195
|
+
/** 授权金额(USDC,6位小数的原始值) */
|
|
196
|
+
value: string;
|
|
197
|
+
/** 过期时间戳 */
|
|
198
|
+
deadline: number;
|
|
199
|
+
/** 签名 v */
|
|
200
|
+
v: number;
|
|
201
|
+
/** 签名 r */
|
|
202
|
+
r: string;
|
|
203
|
+
/** 签名 s */
|
|
204
|
+
s: string;
|
|
205
|
+
}
|
|
206
|
+
interface PermitWalletConfig {
|
|
207
|
+
chain?: ChainName;
|
|
208
|
+
/** Agent 的私钥(用于执行交易) */
|
|
209
|
+
privateKey?: string;
|
|
210
|
+
/** 从文件加载私钥 */
|
|
211
|
+
walletPath?: string;
|
|
212
|
+
/** 解密密码 */
|
|
213
|
+
walletPassword?: string;
|
|
214
|
+
rpcUrl?: string;
|
|
215
|
+
}
|
|
216
|
+
interface TransferWithPermitParams {
|
|
217
|
+
/** 收款地址 */
|
|
218
|
+
to: string;
|
|
219
|
+
/** 金额(USDC) */
|
|
220
|
+
amount: number;
|
|
221
|
+
/** Boss 签署的 Permit 数据 */
|
|
222
|
+
permit: PermitData;
|
|
223
|
+
}
|
|
224
|
+
interface TransferWithPermitResult extends TransferResult {
|
|
225
|
+
/** Permit 交易 hash */
|
|
226
|
+
permitTxHash?: string;
|
|
227
|
+
/** Transfer 交易 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
|
+
* 检查 Permit 是否有效
|
|
240
|
+
*/
|
|
241
|
+
checkPermitAllowance(owner: string): Promise<string>;
|
|
242
|
+
/**
|
|
243
|
+
* 使用 Permit 授权进行支付
|
|
244
|
+
*
|
|
245
|
+
* 流程:
|
|
246
|
+
* 1. 调用 permit() 让合约记录 Boss 的授权
|
|
247
|
+
* 2. 调用 transferFrom() 从 Boss 钱包转账到收款方
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const wallet = new PermitWallet({ chain: 'base' });
|
|
252
|
+
*
|
|
253
|
+
* // Boss 签署的 permit 数据
|
|
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
|
+
* 获取 ETH 余额(用于支付 gas)
|
|
274
|
+
*/
|
|
275
|
+
getGasBalance(): Promise<string>;
|
|
276
|
+
/**
|
|
277
|
+
* 检查是否有足够的 gas
|
|
278
|
+
*/
|
|
279
|
+
hasEnoughGas(minEth?: number): Promise<boolean>;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* 格式化 Permit 请求消息(发给 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 };
|