@mentaproject/client 0.1.25 → 0.1.29
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/dist/structures/MentaClient.d.ts +2 -0
- package/dist/structures/MentaClient.js +2 -0
- package/dist/utils/withCache.d.ts +2 -2
- package/dist/utils/withCache.js +0 -1
- package/package.json +2 -2
- package/src/structures/MentaClient.ts +8 -2
- package/src/utils/withCache.ts +3 -3
- package/tests/structures/MentaClient.test.ts +22 -1
|
@@ -8,6 +8,7 @@ import { ContractManager } from "../managers/ContractManager";
|
|
|
8
8
|
import { AccountManager } from "../managers/AccountManager";
|
|
9
9
|
import { PersistenceManager } from "../managers/PersistenceManager";
|
|
10
10
|
import { ClientEvents, GetListenerCallback, MentaClientConfig } from "../types/MentaClient";
|
|
11
|
+
import { Account } from "./Account";
|
|
11
12
|
/**
|
|
12
13
|
* The main client for interacting with the Menta API.
|
|
13
14
|
* It provides managers for blocks, transactions, contracts, and accounts.
|
|
@@ -44,6 +45,7 @@ export declare class MentaClient {
|
|
|
44
45
|
* @description Provides methods to manage and interact with blockchain accounts.
|
|
45
46
|
*/
|
|
46
47
|
accounts: AccountManager;
|
|
48
|
+
account: Account;
|
|
47
49
|
/**
|
|
48
50
|
* Subscribes to a specific client event.
|
|
49
51
|
* @template TEvent The type of the event to listen for.
|
|
@@ -88,6 +88,7 @@ export class MentaClient {
|
|
|
88
88
|
else {
|
|
89
89
|
this.accounts = new AccountManager(this);
|
|
90
90
|
}
|
|
91
|
+
this.account = this.accounts.get(this.rpc.account.address);
|
|
91
92
|
}
|
|
92
93
|
async init() {
|
|
93
94
|
let coreClient = createClient(this.params);
|
|
@@ -97,6 +98,7 @@ export class MentaClient {
|
|
|
97
98
|
this._rpc = await createMentaAccount(coreClient, {
|
|
98
99
|
signer: this.params.signer,
|
|
99
100
|
bundlerTransport: this.params.bundlerTransport,
|
|
101
|
+
publicTransport: this.params.transport,
|
|
100
102
|
});
|
|
101
103
|
}
|
|
102
104
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreClient } from "
|
|
1
|
+
import type { CoreClient } from "@mentaproject/core/types";
|
|
2
2
|
import { ICache } from "../types/Cache";
|
|
3
3
|
/**
|
|
4
4
|
* A higher-order function that enhances a class method with caching capabilities.
|
|
@@ -9,4 +9,4 @@ import { ICache } from "../types/Cache";
|
|
|
9
9
|
* @param cache The cache implementation (ICache) to use for storing and retrieving responses.
|
|
10
10
|
* @returns The enhanced CoreClient instance with caching enabled.
|
|
11
11
|
*/
|
|
12
|
-
export declare function withCache(client:
|
|
12
|
+
export declare function withCache<T extends CoreClient>(client: T, cache: ICache): T;
|
package/dist/utils/withCache.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentaproject/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "High level EVM library used into the Menta App to facilitate Blockchain interactions. ",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@mentaproject/contracts": "^0.0.11",
|
|
35
|
-
"@mentaproject/core": "^0.
|
|
35
|
+
"@mentaproject/core": "^0.6.1",
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.13.0",
|
|
37
37
|
"@shazow/whatsabi": "^0.21.1"
|
|
38
38
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module MentaClient
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { MentaAccountClient } from "@mentaproject/core/types";
|
|
5
5
|
import { createMentaAccount } from "@mentaproject/core/clients";
|
|
6
6
|
|
|
7
7
|
import { BlockManager } from "../managers/BlockManager";
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "../types/MentaClient";
|
|
17
17
|
import { withCache } from "../utils/withCache";
|
|
18
18
|
import { createClient } from "@mentaproject/core";
|
|
19
|
+
import { Account } from "./Account";
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* The main client for interacting with the Menta API.
|
|
@@ -59,6 +60,8 @@ export class MentaClient {
|
|
|
59
60
|
*/
|
|
60
61
|
public accounts!: AccountManager;
|
|
61
62
|
|
|
63
|
+
public account: Account;
|
|
64
|
+
|
|
62
65
|
/**
|
|
63
66
|
* Subscribes to a specific client event.
|
|
64
67
|
* @template TEvent The type of the event to listen for.
|
|
@@ -128,10 +131,12 @@ export class MentaClient {
|
|
|
128
131
|
} else {
|
|
129
132
|
this.accounts = new AccountManager(this);
|
|
130
133
|
}
|
|
134
|
+
|
|
135
|
+
this.account = this.accounts.get(this.rpc.account.address);
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
async init() {
|
|
134
|
-
let coreClient = createClient(this.params)
|
|
139
|
+
let coreClient = createClient(this.params);
|
|
135
140
|
|
|
136
141
|
if (this.params.cache) {
|
|
137
142
|
coreClient = withCache(coreClient, this.params.cache);
|
|
@@ -140,6 +145,7 @@ export class MentaClient {
|
|
|
140
145
|
this._rpc = await createMentaAccount(coreClient, {
|
|
141
146
|
signer: this.params.signer,
|
|
142
147
|
bundlerTransport: this.params.bundlerTransport,
|
|
148
|
+
publicTransport: this.params.transport,
|
|
143
149
|
});
|
|
144
150
|
}
|
|
145
151
|
|
package/src/utils/withCache.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module withCache
|
|
3
3
|
*/
|
|
4
4
|
import { watchBlockNumber } from "@mentaproject/core/actions";
|
|
5
|
-
import { CoreClient } from "
|
|
5
|
+
import type { CoreClient } from "@mentaproject/core/types";
|
|
6
6
|
import { ICache } from "../types/Cache";
|
|
7
7
|
import { Methods } from "../types/JsonRPC";
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ import { Methods } from "../types/JsonRPC";
|
|
|
15
15
|
* @param cache The cache implementation (ICache) to use for storing and retrieving responses.
|
|
16
16
|
* @returns The enhanced CoreClient instance with caching enabled.
|
|
17
17
|
*/
|
|
18
|
-
export function withCache(client:
|
|
18
|
+
export function withCache<T extends CoreClient>(client: T, cache: ICache): T {
|
|
19
19
|
watchBlockNumber(client, {
|
|
20
20
|
onBlockNumber: (blockNumber) => {
|
|
21
21
|
cache.setBlockNumber(blockNumber);
|
|
@@ -47,4 +47,4 @@ export function withCache(client: CoreClient, cache: ICache) {
|
|
|
47
47
|
}) as any;
|
|
48
48
|
|
|
49
49
|
return client;
|
|
50
|
-
}
|
|
50
|
+
}
|
|
@@ -8,6 +8,23 @@ import { PersistenceManager } from '../../src/managers/PersistenceManager';
|
|
|
8
8
|
import { MentaClientConfig } from '../../src/types/MentaClient';
|
|
9
9
|
import { http } from '@mentaproject/core';
|
|
10
10
|
import { mainnet } from 'viem/chains';
|
|
11
|
+
import type { PasskeySigner } from '@mentaproject/core/types';
|
|
12
|
+
|
|
13
|
+
// Mock passkey signer for testing
|
|
14
|
+
const mockSigner = {
|
|
15
|
+
address: '0x0000000000000000000000000000000000000000',
|
|
16
|
+
type: 'local',
|
|
17
|
+
source: 'custom',
|
|
18
|
+
publicKey: '0x00',
|
|
19
|
+
pubX: 0n,
|
|
20
|
+
pubY: 0n,
|
|
21
|
+
authenticatorId: 'mock-authenticator',
|
|
22
|
+
authenticatorIdHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
23
|
+
rpID: 'localhost',
|
|
24
|
+
signMessage: async () => '0x00',
|
|
25
|
+
signTransaction: async () => '0x00',
|
|
26
|
+
signTypedData: async () => '0x00',
|
|
27
|
+
} as unknown as PasskeySigner;
|
|
11
28
|
|
|
12
29
|
describe('MentaClient', () => {
|
|
13
30
|
let client: MentaClient;
|
|
@@ -15,6 +32,8 @@ describe('MentaClient', () => {
|
|
|
15
32
|
transport: http('http://localhost:8545'),
|
|
16
33
|
chain: mainnet,
|
|
17
34
|
persistenceAdapter: mockPersistenceAdapter,
|
|
35
|
+
bundlerTransport: http('http://localhost:4337'),
|
|
36
|
+
signer: mockSigner,
|
|
18
37
|
};
|
|
19
38
|
|
|
20
39
|
beforeEach(() => {
|
|
@@ -33,8 +52,10 @@ describe('MentaClient', () => {
|
|
|
33
52
|
const clientWithoutPersistence = new MentaClient({
|
|
34
53
|
transport: http('http://localhost:8545'),
|
|
35
54
|
chain: mainnet,
|
|
55
|
+
bundlerTransport: http('http://localhost:4337'),
|
|
56
|
+
signer: mockSigner,
|
|
36
57
|
});
|
|
37
58
|
expect(clientWithoutPersistence.persistenceManager).toBeUndefined();
|
|
38
59
|
expect(clientWithoutPersistence.accounts).toBeInstanceOf(AccountManager);
|
|
39
60
|
});
|
|
40
|
-
});
|
|
61
|
+
});
|