cronos-agent-wallet 1.2.5 → 1.2.7

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.
@@ -5,6 +5,7 @@ exports.AgentClient = void 0;
5
5
  const AgentWallet_1 = require("./internal/AgentWallet");
6
6
  const CronosUsdcExecutor_1 = require("./internal/CronosUsdcExecutor");
7
7
  const x402ToolClient_1 = require("./internal/x402ToolClient");
8
+ const config_1 = require("./config");
8
9
  /**
9
10
  * AgentClient
10
11
  * -----------
@@ -16,19 +17,21 @@ class AgentClient {
16
17
  wallet;
17
18
  context;
18
19
  constructor(config) {
19
- if (!config.privateKey) {
20
+ // 0. Merge with defaults
21
+ const fullConfig = { ...config_1.AGENT_CONFIG_DEFAULTS, ...config };
22
+ if (!fullConfig.privateKey) {
20
23
  throw new Error("AgentClient: privateKey is required");
21
24
  }
22
- if (!config.rpcUrl) {
25
+ if (!fullConfig.rpcUrl) {
23
26
  throw new Error("AgentClient: rpcUrl is required");
24
27
  }
25
- if (!config.chainId) {
28
+ if (!fullConfig.chainId) {
26
29
  throw new Error("AgentClient: chainId is required");
27
30
  }
28
31
  // 1. Create executor (chain-specific)
29
- const executor = new CronosUsdcExecutor_1.CronosUsdcExecutor(config.rpcUrl, config.privateKey, config.usdcAddress, config.chainId);
32
+ const executor = new CronosUsdcExecutor_1.CronosUsdcExecutor(fullConfig.rpcUrl, fullConfig.privateKey, fullConfig.usdcAddress, fullConfig.chainId);
30
33
  // 2. Create wallet (policy + persistence)
31
- this.wallet = new AgentWallet_1.AgentWallet(executor.getAddress(), executor, executor.getProvider(), executor.getSigner(), config);
34
+ this.wallet = new AgentWallet_1.AgentWallet(executor.getAddress(), executor, executor.getProvider(), executor.getSigner(), fullConfig);
32
35
  // 3. Context passed per request
33
36
  this.context = {
34
37
  chainId: config.chainId,
@@ -192,12 +192,15 @@ class AgentWallet {
192
192
  const localHash = hashPolicy(this.config);
193
193
  // Note: We check if on-chain hash is set (non-zero) before enforcing
194
194
  if (onChain.policyHash !== ethers_1.ethers.ZeroHash && onChain.policyHash !== localHash) {
195
- const msg = `Policy Hash Mismatch! Local: ${localHash}, Chain: ${onChain.policyHash}`;
195
+ const msg = `[SECURITY] Policy Mismatch! Your local config (dailyLimit/maxPerTx) differs from the on-chain policy. \n` +
196
+ ` -> Local Hash: ${localHash}\n` +
197
+ ` -> Chain Hash: ${onChain.policyHash}\n` +
198
+ ` -> Tip: Ensure your 'AgentClient' config matches what you deployed via 'set_policy'.`;
196
199
  if (this.config?.strictPolicy) {
197
200
  throw new Error(msg);
198
201
  }
199
202
  else {
200
- console.warn(`[AgentWallet] WARN: ${msg}. Running in PERMISSIVE mode.`);
203
+ console.warn(`[AgentWallet] WARN: ${msg}\n -> Running in PERMISSIVE mode.`);
201
204
  }
202
205
  }
203
206
  else {
@@ -205,7 +208,12 @@ class AgentWallet {
205
208
  }
206
209
  }
207
210
  catch (error) {
208
- console.error("[AgentWallet] Anchor check failed:", error.message);
211
+ // Only log here if we are NOT throwing (i.e. unexpected errors), or if permissive.
212
+ // If strict, the caller (constructor) will catch and log/exit, so we avoid double logs.
213
+ if (!this.config?.strictPolicy) {
214
+ console.error("[AgentWallet] Anchor check failed:", error.message);
215
+ }
216
+ // Propagate if strict
209
217
  if (this.config?.strictPolicy)
210
218
  throw error;
211
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cronos-agent-wallet",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [