moltspay 0.2.0 → 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.
@@ -103,21 +103,21 @@ declare class SecureWallet {
103
103
  }
104
104
 
105
105
  /**
106
- * createWallet - Agent 创建新钱包
106
+ * createWallet - Create a new wallet for Agent
107
107
  *
108
- * 功能:
109
- * - 生成新的以太坊钱包
110
- * - 安全存储私钥(加密或明文,取决于配置)
111
- * - 返回钱包地址(不返回私钥)
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
112
  */
113
113
  interface CreateWalletOptions {
114
- /** 存储路径,默认 ~/.moltspay/wallet.json */
114
+ /** Storage path, default ~/.moltspay/wallet.json */
115
115
  storagePath?: string;
116
- /** 加密密码(可选,不提供则明文存储) */
116
+ /** Encryption password (optional, plaintext if not provided) */
117
117
  password?: string;
118
- /** 钱包标签/名称 */
118
+ /** Wallet label/name */
119
119
  label?: string;
120
- /** 如果钱包已存在,是否覆盖 */
120
+ /** Overwrite if wallet exists */
121
121
  overwrite?: boolean;
122
122
  }
123
123
  interface WalletData {
@@ -125,11 +125,11 @@ interface WalletData {
125
125
  label?: string;
126
126
  createdAt: string;
127
127
  encrypted: boolean;
128
- /** 加密后的私钥或明文私钥 */
128
+ /** Encrypted or plaintext private key */
129
129
  privateKey: string;
130
- /** 加密用的 IV */
130
+ /** Encryption IV */
131
131
  iv?: string;
132
- /** 加密用的 salt */
132
+ /** Encryption salt */
133
133
  salt?: string;
134
134
  }
135
135
  interface CreateWalletResult {
@@ -137,28 +137,28 @@ interface CreateWalletResult {
137
137
  address?: string;
138
138
  storagePath?: string;
139
139
  error?: string;
140
- /** 是否是新创建的(false 表示加载了已有钱包) */
140
+ /** Whether newly created (false means loaded existing) */
141
141
  isNew?: boolean;
142
142
  }
143
143
  /**
144
- * 创建新钱包
144
+ * Create new wallet
145
145
  *
146
146
  * @example
147
147
  * ```typescript
148
- * // 创建未加密钱包
148
+ * // Create unencrypted wallet
149
149
  * const result = await createWallet();
150
- * console.log('钱包地址:', result.address);
150
+ * console.log('Wallet address:', result.address);
151
151
  *
152
- * // 创建加密钱包
152
+ * // Create encrypted wallet
153
153
  * const result = await createWallet({ password: 'mySecurePassword' });
154
154
  *
155
- * // 指定存储路径
155
+ * // Specify storage path
156
156
  * const result = await createWallet({ storagePath: './my-wallet.json' });
157
157
  * ```
158
158
  */
159
159
  declare function createWallet(options?: CreateWalletOptions): CreateWalletResult;
160
160
  /**
161
- * 加载已有钱包
161
+ * Load existing wallet
162
162
  */
163
163
  declare function loadWallet(options?: {
164
164
  storagePath?: string;
@@ -170,61 +170,61 @@ declare function loadWallet(options?: {
170
170
  error?: string;
171
171
  };
172
172
  /**
173
- * 获取钱包地址(不需要密码)
173
+ * Get wallet address (no password required)
174
174
  */
175
175
  declare function getWalletAddress(storagePath?: string): string | null;
176
176
  /**
177
- * 检查钱包是否存在
177
+ * Check if wallet exists
178
178
  */
179
179
  declare function walletExists(storagePath?: string): boolean;
180
180
 
181
181
  /**
182
- * PermitWallet - 使用 Boss 授权的 Permit 进行支付
182
+ * PermitWallet - Pay using Boss's Permit authorization
183
183
  *
184
- * 场景:
185
- * - Agent 没有自己的 USDC,但 Boss 给了 Permit 授权
186
- * - Agent 使用 Permit 签名 + 自己的钱包执行 transferFrom
187
- * - Agent 只需要少量 ETH gasUSDC Boss 钱包扣除
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
188
  */
189
189
 
190
190
  interface PermitData {
191
- /** Boss 的钱包地址(USDC 持有者) */
191
+ /** Boss's wallet address (USDC holder) */
192
192
  owner: string;
193
- /** Agent 的钱包地址(被授权者) */
193
+ /** Agent's wallet address (authorized spender) */
194
194
  spender: string;
195
- /** 授权金额(USDC6位小数的原始值) */
195
+ /** Authorized amount (USDC, raw 6 decimal value) */
196
196
  value: string;
197
- /** 过期时间戳 */
197
+ /** Expiration timestamp */
198
198
  deadline: number;
199
- /** 签名 v */
199
+ /** Signature v */
200
200
  v: number;
201
- /** 签名 r */
201
+ /** Signature r */
202
202
  r: string;
203
- /** 签名 s */
203
+ /** Signature s */
204
204
  s: string;
205
205
  }
206
206
  interface PermitWalletConfig {
207
207
  chain?: ChainName;
208
- /** Agent 的私钥(用于执行交易) */
208
+ /** Agent's private key (for executing transactions) */
209
209
  privateKey?: string;
210
- /** 从文件加载私钥 */
210
+ /** Load private key from file */
211
211
  walletPath?: string;
212
- /** 解密密码 */
212
+ /** Decryption password */
213
213
  walletPassword?: string;
214
214
  rpcUrl?: string;
215
215
  }
216
216
  interface TransferWithPermitParams {
217
- /** 收款地址 */
217
+ /** Recipient address */
218
218
  to: string;
219
- /** 金额(USDC */
219
+ /** Amount (USDC) */
220
220
  amount: number;
221
- /** Boss 签署的 Permit 数据 */
221
+ /** Boss-signed Permit data */
222
222
  permit: PermitData;
223
223
  }
224
224
  interface TransferWithPermitResult extends TransferResult {
225
- /** Permit 交易 hash */
225
+ /** Permit transaction hash */
226
226
  permitTxHash?: string;
227
- /** Transfer 交易 hash */
227
+ /** Transfer transaction hash */
228
228
  transferTxHash?: string;
229
229
  }
230
230
  declare class PermitWallet {
@@ -236,21 +236,21 @@ declare class PermitWallet {
236
236
  private usdcContract;
237
237
  constructor(config?: PermitWalletConfig);
238
238
  /**
239
- * 检查 Permit 是否有效
239
+ * Check if Permit is valid (current allowance)
240
240
  */
241
241
  checkPermitAllowance(owner: string): Promise<string>;
242
242
  /**
243
- * 使用 Permit 授权进行支付
243
+ * Pay using Permit authorization
244
244
  *
245
- * 流程:
246
- * 1. 调用 permit() 让合约记录 Boss 的授权
247
- * 2. 调用 transferFrom() Boss 钱包转账到收款方
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
248
  *
249
249
  * @example
250
250
  * ```typescript
251
251
  * const wallet = new PermitWallet({ chain: 'base' });
252
252
  *
253
- * // Boss 签署的 permit 数据
253
+ * // Boss-signed permit data
254
254
  * const permit = {
255
255
  * owner: '0xBOSS...',
256
256
  * spender: wallet.address,
@@ -270,16 +270,16 @@ declare class PermitWallet {
270
270
  */
271
271
  transferWithPermit(params: TransferWithPermitParams): Promise<TransferWithPermitResult>;
272
272
  /**
273
- * 获取 ETH 余额(用于支付 gas
273
+ * Get ETH balance (for gas)
274
274
  */
275
275
  getGasBalance(): Promise<string>;
276
276
  /**
277
- * 检查是否有足够的 gas
277
+ * Check if there's enough gas
278
278
  */
279
279
  hasEnoughGas(minEth?: number): Promise<boolean>;
280
280
  }
281
281
  /**
282
- * 格式化 Permit 请求消息(发给 Boss
282
+ * Format Permit request message (to send to Boss)
283
283
  */
284
284
  declare function formatPermitRequest(params: {
285
285
  agentAddress: string;
@@ -103,21 +103,21 @@ declare class SecureWallet {
103
103
  }
104
104
 
105
105
  /**
106
- * createWallet - Agent 创建新钱包
106
+ * createWallet - Create a new wallet for Agent
107
107
  *
108
- * 功能:
109
- * - 生成新的以太坊钱包
110
- * - 安全存储私钥(加密或明文,取决于配置)
111
- * - 返回钱包地址(不返回私钥)
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
112
  */
113
113
  interface CreateWalletOptions {
114
- /** 存储路径,默认 ~/.moltspay/wallet.json */
114
+ /** Storage path, default ~/.moltspay/wallet.json */
115
115
  storagePath?: string;
116
- /** 加密密码(可选,不提供则明文存储) */
116
+ /** Encryption password (optional, plaintext if not provided) */
117
117
  password?: string;
118
- /** 钱包标签/名称 */
118
+ /** Wallet label/name */
119
119
  label?: string;
120
- /** 如果钱包已存在,是否覆盖 */
120
+ /** Overwrite if wallet exists */
121
121
  overwrite?: boolean;
122
122
  }
123
123
  interface WalletData {
@@ -125,11 +125,11 @@ interface WalletData {
125
125
  label?: string;
126
126
  createdAt: string;
127
127
  encrypted: boolean;
128
- /** 加密后的私钥或明文私钥 */
128
+ /** Encrypted or plaintext private key */
129
129
  privateKey: string;
130
- /** 加密用的 IV */
130
+ /** Encryption IV */
131
131
  iv?: string;
132
- /** 加密用的 salt */
132
+ /** Encryption salt */
133
133
  salt?: string;
134
134
  }
135
135
  interface CreateWalletResult {
@@ -137,28 +137,28 @@ interface CreateWalletResult {
137
137
  address?: string;
138
138
  storagePath?: string;
139
139
  error?: string;
140
- /** 是否是新创建的(false 表示加载了已有钱包) */
140
+ /** Whether newly created (false means loaded existing) */
141
141
  isNew?: boolean;
142
142
  }
143
143
  /**
144
- * 创建新钱包
144
+ * Create new wallet
145
145
  *
146
146
  * @example
147
147
  * ```typescript
148
- * // 创建未加密钱包
148
+ * // Create unencrypted wallet
149
149
  * const result = await createWallet();
150
- * console.log('钱包地址:', result.address);
150
+ * console.log('Wallet address:', result.address);
151
151
  *
152
- * // 创建加密钱包
152
+ * // Create encrypted wallet
153
153
  * const result = await createWallet({ password: 'mySecurePassword' });
154
154
  *
155
- * // 指定存储路径
155
+ * // Specify storage path
156
156
  * const result = await createWallet({ storagePath: './my-wallet.json' });
157
157
  * ```
158
158
  */
159
159
  declare function createWallet(options?: CreateWalletOptions): CreateWalletResult;
160
160
  /**
161
- * 加载已有钱包
161
+ * Load existing wallet
162
162
  */
163
163
  declare function loadWallet(options?: {
164
164
  storagePath?: string;
@@ -170,61 +170,61 @@ declare function loadWallet(options?: {
170
170
  error?: string;
171
171
  };
172
172
  /**
173
- * 获取钱包地址(不需要密码)
173
+ * Get wallet address (no password required)
174
174
  */
175
175
  declare function getWalletAddress(storagePath?: string): string | null;
176
176
  /**
177
- * 检查钱包是否存在
177
+ * Check if wallet exists
178
178
  */
179
179
  declare function walletExists(storagePath?: string): boolean;
180
180
 
181
181
  /**
182
- * PermitWallet - 使用 Boss 授权的 Permit 进行支付
182
+ * PermitWallet - Pay using Boss's Permit authorization
183
183
  *
184
- * 场景:
185
- * - Agent 没有自己的 USDC,但 Boss 给了 Permit 授权
186
- * - Agent 使用 Permit 签名 + 自己的钱包执行 transferFrom
187
- * - Agent 只需要少量 ETH gasUSDC Boss 钱包扣除
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
188
  */
189
189
 
190
190
  interface PermitData {
191
- /** Boss 的钱包地址(USDC 持有者) */
191
+ /** Boss's wallet address (USDC holder) */
192
192
  owner: string;
193
- /** Agent 的钱包地址(被授权者) */
193
+ /** Agent's wallet address (authorized spender) */
194
194
  spender: string;
195
- /** 授权金额(USDC6位小数的原始值) */
195
+ /** Authorized amount (USDC, raw 6 decimal value) */
196
196
  value: string;
197
- /** 过期时间戳 */
197
+ /** Expiration timestamp */
198
198
  deadline: number;
199
- /** 签名 v */
199
+ /** Signature v */
200
200
  v: number;
201
- /** 签名 r */
201
+ /** Signature r */
202
202
  r: string;
203
- /** 签名 s */
203
+ /** Signature s */
204
204
  s: string;
205
205
  }
206
206
  interface PermitWalletConfig {
207
207
  chain?: ChainName;
208
- /** Agent 的私钥(用于执行交易) */
208
+ /** Agent's private key (for executing transactions) */
209
209
  privateKey?: string;
210
- /** 从文件加载私钥 */
210
+ /** Load private key from file */
211
211
  walletPath?: string;
212
- /** 解密密码 */
212
+ /** Decryption password */
213
213
  walletPassword?: string;
214
214
  rpcUrl?: string;
215
215
  }
216
216
  interface TransferWithPermitParams {
217
- /** 收款地址 */
217
+ /** Recipient address */
218
218
  to: string;
219
- /** 金额(USDC */
219
+ /** Amount (USDC) */
220
220
  amount: number;
221
- /** Boss 签署的 Permit 数据 */
221
+ /** Boss-signed Permit data */
222
222
  permit: PermitData;
223
223
  }
224
224
  interface TransferWithPermitResult extends TransferResult {
225
- /** Permit 交易 hash */
225
+ /** Permit transaction hash */
226
226
  permitTxHash?: string;
227
- /** Transfer 交易 hash */
227
+ /** Transfer transaction hash */
228
228
  transferTxHash?: string;
229
229
  }
230
230
  declare class PermitWallet {
@@ -236,21 +236,21 @@ declare class PermitWallet {
236
236
  private usdcContract;
237
237
  constructor(config?: PermitWalletConfig);
238
238
  /**
239
- * 检查 Permit 是否有效
239
+ * Check if Permit is valid (current allowance)
240
240
  */
241
241
  checkPermitAllowance(owner: string): Promise<string>;
242
242
  /**
243
- * 使用 Permit 授权进行支付
243
+ * Pay using Permit authorization
244
244
  *
245
- * 流程:
246
- * 1. 调用 permit() 让合约记录 Boss 的授权
247
- * 2. 调用 transferFrom() Boss 钱包转账到收款方
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
248
  *
249
249
  * @example
250
250
  * ```typescript
251
251
  * const wallet = new PermitWallet({ chain: 'base' });
252
252
  *
253
- * // Boss 签署的 permit 数据
253
+ * // Boss-signed permit data
254
254
  * const permit = {
255
255
  * owner: '0xBOSS...',
256
256
  * spender: wallet.address,
@@ -270,16 +270,16 @@ declare class PermitWallet {
270
270
  */
271
271
  transferWithPermit(params: TransferWithPermitParams): Promise<TransferWithPermitResult>;
272
272
  /**
273
- * 获取 ETH 余额(用于支付 gas
273
+ * Get ETH balance (for gas)
274
274
  */
275
275
  getGasBalance(): Promise<string>;
276
276
  /**
277
- * 检查是否有足够的 gas
277
+ * Check if there's enough gas
278
278
  */
279
279
  hasEnoughGas(minEth?: number): Promise<boolean>;
280
280
  }
281
281
  /**
282
- * 格式化 Permit 请求消息(发给 Boss
282
+ * Format Permit request message (to send to Boss)
283
283
  */
284
284
  declare function formatPermitRequest(params: {
285
285
  agentAddress: string;
@@ -773,24 +773,24 @@ var PermitWallet = class {
773
773
  );
774
774
  }
775
775
  /**
776
- * 检查 Permit 是否有效
776
+ * Check if Permit is valid (current allowance)
777
777
  */
778
778
  async checkPermitAllowance(owner) {
779
779
  const allowance = await this.usdcContract.allowance(owner, this.address);
780
780
  return (Number(allowance) / 1e6).toFixed(2);
781
781
  }
782
782
  /**
783
- * 使用 Permit 授权进行支付
783
+ * Pay using Permit authorization
784
784
  *
785
- * 流程:
786
- * 1. 调用 permit() 让合约记录 Boss 的授权
787
- * 2. 调用 transferFrom() Boss 钱包转账到收款方
785
+ * Flow:
786
+ * 1. Call permit() to record Boss's authorization in the contract
787
+ * 2. Call transferFrom() to transfer from Boss's wallet to recipient
788
788
  *
789
789
  * @example
790
790
  * ```typescript
791
791
  * const wallet = new PermitWallet({ chain: 'base' });
792
792
  *
793
- * // Boss 签署的 permit 数据
793
+ * // Boss-signed permit data
794
794
  * const permit = {
795
795
  * owner: '0xBOSS...',
796
796
  * spender: wallet.address,
@@ -913,14 +913,14 @@ var PermitWallet = class {
913
913
  }
914
914
  }
915
915
  /**
916
- * 获取 ETH 余额(用于支付 gas
916
+ * Get ETH balance (for gas)
917
917
  */
918
918
  async getGasBalance() {
919
919
  const balance = await this.provider.getBalance(this.address);
920
920
  return import_ethers3.ethers.formatEther(balance);
921
921
  }
922
922
  /**
923
- * 检查是否有足够的 gas
923
+ * Check if there's enough gas
924
924
  */
925
925
  async hasEnoughGas(minEth = 1e-3) {
926
926
  const balance = await this.getGasBalance();
@@ -932,17 +932,17 @@ function formatPermitRequest(params) {
932
932
  const chainConfig = getChain(chain);
933
933
  const deadline = Math.floor(Date.now() / 1e3) + deadlineHours * 3600;
934
934
  const value = BigInt(Math.floor(amount * 1e6)).toString();
935
- return `\u{1F510} **USDC \u652F\u4ED8\u989D\u5EA6\u6388\u6743\u8BF7\u6C42**
935
+ return `\u{1F510} **USDC Spending Allowance Request**
936
936
 
937
- ${reason ? `**\u7528\u9014:** ${reason}
937
+ ${reason ? `**Purpose:** ${reason}
938
938
  ` : ""}
939
- **\u6388\u6743\u8BE6\u60C5:**
940
- - \u88AB\u6388\u6743\u5730\u5740 (Agent): \`${agentAddress}\`
941
- - \u6388\u6743\u91D1\u989D: ${amount} USDC
942
- - \u6709\u6548\u671F: ${deadlineHours} \u5C0F\u65F6
943
- - \u94FE: ${chainConfig.name}
939
+ **Authorization Details:**
940
+ - Authorized address (Agent): \`${agentAddress}\`
941
+ - Amount: ${amount} USDC
942
+ - Valid for: ${deadlineHours} hours
943
+ - Chain: ${chainConfig.name}
944
944
 
945
- **\u8BF7\u4F7F\u7528\u94B1\u5305\u7B7E\u7F72\u4EE5\u4E0B EIP-2612 Permit:**
945
+ **Please sign the following EIP-2612 Permit with your wallet:**
946
946
 
947
947
  \`\`\`json
948
948
  {
@@ -972,9 +972,9 @@ ${reason ? `**\u7528\u9014:** ${reason}
972
972
  }
973
973
  \`\`\`
974
974
 
975
- \u7B7E\u540D\u540E\uFF0C\u8BF7\u5C06 { v, r, s, deadline } \u53D1\u7ED9 Agent\u3002
975
+ After signing, send { v, r, s, deadline } to the Agent.
976
976
 
977
- \u26A0\uFE0F \u6CE8\u610F\uFF1A\u6B64\u6388\u6743\u4EC5\u5141\u8BB8 Agent \u4ECE\u60A8\u7684\u94B1\u5305\u652F\u4ED8\u6700\u591A ${amount} USDC\uFF0C\u4E0D\u4F1A\u6CC4\u9732\u79C1\u94A5\u3002`;
977
+ \u26A0\uFE0F Note: This authorization only allows the Agent to spend up to ${amount} USDC from your wallet. Your private key is never exposed.`;
978
978
  }
979
979
  // Annotate the CommonJS export names for ESM import in node:
980
980
  0 && (module.exports = {