@mentaproject/client 0.1.35 → 0.1.37

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/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@mentaproject/client",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "High level EVM library used into the Menta App to facilitate Blockchain interactions. ",
5
- "main": "dist/index.js",
5
+ "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "sideEffects": false,
@@ -11,42 +11,42 @@
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.mjs",
14
- "require": "./dist/index.js"
14
+ "require": "./dist/index.cjs"
15
15
  },
16
16
  "./types": {
17
17
  "types": "./dist/types/index.d.ts",
18
18
  "import": "./dist/types/index.mjs",
19
- "require": "./dist/types/index.js"
19
+ "require": "./dist/types/index.cjs"
20
20
  },
21
21
  "./package.json": "./package.json"
22
22
  },
23
23
  "scripts": {
24
24
  "test:file": "tsx test.ts",
25
25
  "test": "jest -i",
26
- "build": "tsc --project tsconfig.json",
27
- "patch": "npm version patch && npm run build && npm publish --access public",
28
- "minor": "npm version minor && npm run build && npm publish --access public",
29
- "major": "npm version major && npm run build && npm publish --access public"
26
+ "build": "tsup && tsc --emitDeclarationOnly",
27
+ "build:fast": "tsup",
28
+ "preversion": "npm whoami && npm run build",
29
+ "postversion": "npm publish --access public && git push --follow-tags || (git tag -d $(git describe --tags --abbrev=0) && git reset --hard HEAD~1 && exit 1)",
30
+ "patch": "npm version patch",
31
+ "minor": "npm version minor",
32
+ "major": "npm version major"
30
33
  },
31
34
  "author": "@mentaproject",
32
35
  "license": "ISC",
33
36
  "dependencies": {
34
37
  "@mentaproject/contracts": "^0.0.11",
35
- "@mentaproject/core": "^0.6.4",
38
+ "@mentaproject/core": "^0.7.3",
36
39
  "@modelcontextprotocol/sdk": "^1.13.0",
37
40
  "@shazow/whatsabi": "^0.21.1"
38
41
  },
39
42
  "devDependencies": {
40
- "@rollup/plugin-commonjs": "^28.0.3",
41
- "@rollup/plugin-node-resolve": "^16.0.1",
42
- "@rollup/plugin-typescript": "^12.1.2",
43
43
  "@types/jest": "^30.0.0",
44
44
  "@types/node": "^22.15.29",
45
45
  "jest": "^30.0.2",
46
46
  "jest-mock-extended": "^4.0.0",
47
- "rollup": "^4.40.1",
48
47
  "ts-jest": "^29.4.0",
49
48
  "tslib": "^2.8.1",
49
+ "tsup": "^8.5.1",
50
50
  "tsx": "^4.19.4",
51
51
  "typescript": "^5.8.3"
52
52
  },
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import type { MentaAccountClient } from "@mentaproject/core/types";
5
5
  import { createMentaAccount } from "@mentaproject/core/clients";
6
+ import { createClient } from "@mentaproject/core";
6
7
 
7
8
  import { BlockManager } from "../managers/BlockManager";
8
9
  import { TransactionManager } from "../managers/TransactionManager";
@@ -15,7 +16,6 @@ import {
15
16
  MentaClientConfig,
16
17
  } from "../types/MentaClient";
17
18
  import { withCache } from "../utils/withCache";
18
- import { createClient } from "@mentaproject/core";
19
19
  import { Account } from "./Account";
20
20
 
21
21
  /**
@@ -150,10 +150,11 @@ export class MentaClient {
150
150
  coreClient = withCache(coreClient, this.params.cache);
151
151
  }
152
152
 
153
- this._rpc = await createMentaAccount(coreClient, {
154
- signer: this.params.signer,
153
+ this._rpc = await createMentaAccount(coreClient as any, {
155
154
  bundlerTransport: this.params.bundlerTransport,
156
155
  publicTransport: this.params.transport,
156
+ signer: this.params.signer,
157
+ validatorAddress: this.params.validatorAddress,
157
158
  });
158
159
 
159
160
  this._account = this.accounts.get(this.rpc.account.address);
@@ -1,14 +1,11 @@
1
1
  /**
2
2
  * @module MentaClientTypes
3
3
  */
4
- import {
5
- CoreClientConfig,
6
- PasskeySigner,
7
- Transport,
8
- } from "@mentaproject/core/types";
4
+ import { Address, CoreClientConfig, Transport } from "@mentaproject/core/types";
9
5
  import { ICache } from "./Cache";
10
6
  import { watchBlockNumber, watchBlocks } from "@mentaproject/core/actions";
11
7
  import { IPersistenceAdapter } from "./PersistenceAdapter";
8
+ import { WebAuthnAccount } from "@mentaproject/core/account-abstraction";
12
9
 
13
10
  /**
14
11
  * Configuration for the client's cache.
@@ -46,7 +43,11 @@ export interface MentaClientConfig extends CoreClientConfig {
46
43
  /**
47
44
  * Passkey compatible signer used for signing user operations
48
45
  */
49
- signer: PasskeySigner;
46
+ signer: WebAuthnAccount;
47
+ /**
48
+ * Validator address used for userOperations
49
+ */
50
+ validatorAddress: Address;
50
51
  }
51
52
 
52
53
  /**
@@ -6,6 +6,19 @@ import type { CoreClient } from "@mentaproject/core/types";
6
6
  import { ICache } from "../types/Cache";
7
7
  import { Methods } from "../types/JsonRPC";
8
8
 
9
+ // EntryPoint.getNonce selector - must never be cached to avoid nonce reuse
10
+ const GET_NONCE_SELECTOR = "0x35567e1a";
11
+
12
+ /**
13
+ * Checks if an eth_call is a getNonce call to the EntryPoint.
14
+ * These calls must not be cached to ensure fresh nonce values for each UserOperation.
15
+ */
16
+ function isNonceCall(method: Methods, params: any): boolean {
17
+ if (method !== "eth_call") return false;
18
+ const callData = params?.[0]?.data;
19
+ return typeof callData === "string" && callData.startsWith(GET_NONCE_SELECTOR);
20
+ }
21
+
9
22
  /**
10
23
  * A higher-order function that enhances a class method with caching capabilities.
11
24
  * It intercepts RPC requests made through the client and caches their responses
@@ -29,16 +42,21 @@ export function withCache<T extends CoreClient>(client: T, cache: ICache): T {
29
42
  client.request = (async (args: { method: Methods, params: any }) => {
30
43
  const { method, params } = args;
31
44
 
45
+ // Never cache nonce calls - they must always return fresh values
46
+ const shouldSkipCache = method === "eth_blockNumber" || isNonceCall(method, params);
47
+
32
48
  const cacheKey = `${client.chain!.id}:${method}:${JSON.stringify(params || [], (_, v) => typeof v === 'bigint' ? v.toString() : v)}`;
33
49
 
34
50
  let result;
35
- if (method !== "eth_blockNumber") result = cache.get(cacheKey);
51
+ if (!shouldSkipCache) {
52
+ result = cache.get(cacheKey);
53
+ }
36
54
 
37
55
  if (!result) {
38
56
  result = await originalRequest(args as any);
39
57
  };
40
58
 
41
- if (result !== null && result !== undefined && method !== "eth_blockNumber") {
59
+ if (result !== null && result !== undefined && !shouldSkipCache) {
42
60
  const ttl = cache.config.ttlPolicies[method] || cache.config.defaultTtl;
43
61
  await cache.set(cacheKey, result, ttl);
44
62
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ index: "src/index.ts",
6
+ "types/index": "src/types/index.ts",
7
+ },
8
+ format: ["cjs", "esm"],
9
+ dts: false,
10
+ sourcemap: true,
11
+ clean: false,
12
+ external: [
13
+ "@mentaproject/contracts",
14
+ "@mentaproject/core",
15
+ "@modelcontextprotocol/sdk",
16
+ "@shazow/whatsabi",
17
+ ],
18
+ });