@mcp-dockmaster/mcp-cryptowallet-evm 1.0.1 → 1.0.3
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/build/handlers/utils.d.ts +1 -1
- package/build/handlers/utils.js +9 -0
- package/build/handlers/utils.js.map +1 -1
- package/build/handlers/wallet.d.ts +3 -2
- package/build/handlers/wallet.js +158 -93
- package/build/handlers/wallet.js.map +1 -1
- package/build/handlers/wallet.types.d.ts +14 -0
- package/build/handlers/wallet.types.js +2 -0
- package/build/handlers/wallet.types.js.map +1 -0
- package/build/index.js +0 -0
- package/build/tools.d.ts +67 -3
- package/build/tools.js +42 -41
- package/build/tools.js.map +1 -1
- package/package.json +1 -1
- package/.eslintrc/index.js +0 -12
- package/required-methods.md +0 -53
- package/tests/handlers/network.test.ts +0 -73
- package/tests/handlers/provider.test.ts +0 -197
- package/tests/handlers/wallet.test.ts +0 -289
@@ -1,289 +0,0 @@
|
|
1
|
-
import { ethers } from 'ethers';
|
2
|
-
import {
|
3
|
-
createWalletHandler,
|
4
|
-
fromPrivateKeyHandler,
|
5
|
-
fromMnemonicHandler,
|
6
|
-
fromEncryptedJsonHandler,
|
7
|
-
encryptWalletHandler,
|
8
|
-
getAddressHandler,
|
9
|
-
getPublicKeyHandler,
|
10
|
-
getPrivateKeyHandler,
|
11
|
-
getMnemonicHandler,
|
12
|
-
getBalanceHandler,
|
13
|
-
getChainIdHandler,
|
14
|
-
getGasPriceHandler,
|
15
|
-
getTransactionCountHandler,
|
16
|
-
callHandler,
|
17
|
-
signMessageHandler,
|
18
|
-
verifyMessageHandler
|
19
|
-
} from '../../src/handlers/wallet.js';
|
20
|
-
|
21
|
-
// Mock ethers.js functions
|
22
|
-
jest.mock('ethers', () => {
|
23
|
-
const originalModule = jest.requireActual('ethers');
|
24
|
-
|
25
|
-
// Create a mock wallet
|
26
|
-
const mockWallet = {
|
27
|
-
address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
|
28
|
-
privateKey: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
29
|
-
publicKey: '0x04a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6',
|
30
|
-
mnemonic: {
|
31
|
-
phrase: 'test test test test test test test test test test test junk',
|
32
|
-
path: "m/44'/60'/0'/0/0",
|
33
|
-
locale: 'en'
|
34
|
-
},
|
35
|
-
connect: jest.fn().mockImplementation((provider) => {
|
36
|
-
mockWallet.provider = provider;
|
37
|
-
return mockWallet;
|
38
|
-
}),
|
39
|
-
getBalance: jest.fn().mockResolvedValue(originalModule.utils.parseEther('1.0')),
|
40
|
-
getChainId: jest.fn().mockResolvedValue(1),
|
41
|
-
getGasPrice: jest.fn().mockResolvedValue(originalModule.utils.parseUnits('50', 'gwei')),
|
42
|
-
getTransactionCount: jest.fn().mockResolvedValue(5),
|
43
|
-
call: jest.fn().mockResolvedValue('0x0000000000000000000000000000000000000000000000000000000000000001'),
|
44
|
-
signMessage: jest.fn().mockResolvedValue('0xsignature'),
|
45
|
-
encrypt: jest.fn().mockResolvedValue(JSON.stringify({ version: 3, id: 'test', address: '742d35cc6634c0532925a3b844bc454e4438f44e' })),
|
46
|
-
provider: null
|
47
|
-
};
|
48
|
-
|
49
|
-
// Create a mock provider
|
50
|
-
const mockProvider = {
|
51
|
-
getBalance: jest.fn().mockResolvedValue(originalModule.utils.parseEther('1.0')),
|
52
|
-
getBlock: jest.fn().mockResolvedValue({
|
53
|
-
hash: '0xblock',
|
54
|
-
number: 1000000,
|
55
|
-
timestamp: Date.now() / 1000
|
56
|
-
}),
|
57
|
-
getTransaction: jest.fn().mockResolvedValue({
|
58
|
-
hash: '0xtx',
|
59
|
-
from: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
|
60
|
-
to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
|
61
|
-
}),
|
62
|
-
getTransactionReceipt: jest.fn().mockResolvedValue({
|
63
|
-
status: 1,
|
64
|
-
blockNumber: 1000000
|
65
|
-
}),
|
66
|
-
getCode: jest.fn().mockResolvedValue('0x'),
|
67
|
-
getStorageAt: jest.fn().mockResolvedValue('0x0000000000000000000000000000000000000000000000000000000000000000'),
|
68
|
-
estimateGas: jest.fn().mockResolvedValue(ethers.BigNumber.from(21000)),
|
69
|
-
getLogs: jest.fn().mockResolvedValue([]),
|
70
|
-
getResolver: jest.fn().mockResolvedValue(null),
|
71
|
-
lookupAddress: jest.fn().mockResolvedValue(null),
|
72
|
-
resolveName: jest.fn().mockResolvedValue(null),
|
73
|
-
getNetwork: jest.fn().mockResolvedValue({ name: 'homestead', chainId: 1 }),
|
74
|
-
getBlockNumber: jest.fn().mockResolvedValue(1000000),
|
75
|
-
getFeeData: jest.fn().mockResolvedValue({
|
76
|
-
gasPrice: ethers.utils.parseUnits('50', 'gwei'),
|
77
|
-
maxFeePerGas: ethers.utils.parseUnits('100', 'gwei'),
|
78
|
-
maxPriorityFeePerGas: ethers.utils.parseUnits('2', 'gwei')
|
79
|
-
})
|
80
|
-
};
|
81
|
-
|
82
|
-
return {
|
83
|
-
...originalModule,
|
84
|
-
Wallet: {
|
85
|
-
createRandom: jest.fn().mockReturnValue(mockWallet),
|
86
|
-
fromMnemonic: jest.fn().mockReturnValue(mockWallet),
|
87
|
-
fromEncryptedJson: jest.fn().mockResolvedValue(mockWallet)
|
88
|
-
},
|
89
|
-
providers: {
|
90
|
-
JsonRpcProvider: jest.fn().mockReturnValue(mockProvider)
|
91
|
-
},
|
92
|
-
getDefaultProvider: jest.fn().mockReturnValue(mockProvider),
|
93
|
-
utils: originalModule.utils
|
94
|
-
};
|
95
|
-
});
|
96
|
-
|
97
|
-
describe('Wallet Creation and Management Handlers', () => {
|
98
|
-
test('createWalletHandler should create a random wallet', async () => {
|
99
|
-
const result = await createWalletHandler({});
|
100
|
-
|
101
|
-
expect(result.isError).toBe(false);
|
102
|
-
expect(result.toolResult).toHaveProperty('address');
|
103
|
-
expect(result.toolResult).toHaveProperty('privateKey');
|
104
|
-
expect(result.toolResult).toHaveProperty('publicKey');
|
105
|
-
expect(result.toolResult).toHaveProperty('mnemonic');
|
106
|
-
});
|
107
|
-
|
108
|
-
test('createWalletHandler should encrypt wallet if password is provided', async () => {
|
109
|
-
const result = await createWalletHandler({ password: 'test123' });
|
110
|
-
|
111
|
-
expect(result.isError).toBe(false);
|
112
|
-
expect(result.toolResult).toHaveProperty('encryptedWallet');
|
113
|
-
});
|
114
|
-
|
115
|
-
test('fromPrivateKeyHandler should create a wallet from a private key', async () => {
|
116
|
-
const result = await fromPrivateKeyHandler({
|
117
|
-
privateKey: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
118
|
-
});
|
119
|
-
|
120
|
-
expect(result.isError).toBe(false);
|
121
|
-
expect(result.toolResult).toHaveProperty('address');
|
122
|
-
expect(result.toolResult).toHaveProperty('privateKey');
|
123
|
-
expect(result.toolResult).toHaveProperty('publicKey');
|
124
|
-
});
|
125
|
-
|
126
|
-
test('fromMnemonicHandler should create a wallet from a mnemonic', async () => {
|
127
|
-
const result = await fromMnemonicHandler({
|
128
|
-
mnemonic: 'test test test test test test test test test test test junk'
|
129
|
-
});
|
130
|
-
|
131
|
-
expect(result.isError).toBe(false);
|
132
|
-
expect(result.toolResult).toHaveProperty('address');
|
133
|
-
expect(result.toolResult).toHaveProperty('privateKey');
|
134
|
-
expect(result.toolResult).toHaveProperty('publicKey');
|
135
|
-
expect(result.toolResult).toHaveProperty('mnemonic');
|
136
|
-
});
|
137
|
-
|
138
|
-
test('fromEncryptedJsonHandler should create a wallet from encrypted JSON', async () => {
|
139
|
-
const result = await fromEncryptedJsonHandler({
|
140
|
-
json: JSON.stringify({ version: 3, id: 'test', address: '742d35cc6634c0532925a3b844bc454e4438f44e' }),
|
141
|
-
password: 'test123'
|
142
|
-
});
|
143
|
-
|
144
|
-
expect(result.isError).toBe(false);
|
145
|
-
expect(result.toolResult).toHaveProperty('address');
|
146
|
-
expect(result.toolResult).toHaveProperty('privateKey');
|
147
|
-
expect(result.toolResult).toHaveProperty('publicKey');
|
148
|
-
});
|
149
|
-
|
150
|
-
test('encryptWalletHandler should encrypt a wallet', async () => {
|
151
|
-
const result = await encryptWalletHandler({
|
152
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
153
|
-
password: 'test123'
|
154
|
-
});
|
155
|
-
|
156
|
-
expect(result.isError).toBe(false);
|
157
|
-
expect(result.toolResult).toHaveProperty('encryptedWallet');
|
158
|
-
});
|
159
|
-
});
|
160
|
-
|
161
|
-
describe('Wallet Properties Handlers', () => {
|
162
|
-
test('getAddressHandler should return the wallet address', async () => {
|
163
|
-
const result = await getAddressHandler({
|
164
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
165
|
-
});
|
166
|
-
|
167
|
-
expect(result.isError).toBe(false);
|
168
|
-
expect(result.toolResult).toHaveProperty('address');
|
169
|
-
expect(result.toolResult.address).toBe('0x742d35Cc6634C0532925a3b844Bc454e4438f44e');
|
170
|
-
});
|
171
|
-
|
172
|
-
test('getPublicKeyHandler should return the wallet public key', async () => {
|
173
|
-
const result = await getPublicKeyHandler({
|
174
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
175
|
-
});
|
176
|
-
|
177
|
-
expect(result.isError).toBe(false);
|
178
|
-
expect(result.toolResult).toHaveProperty('publicKey');
|
179
|
-
});
|
180
|
-
|
181
|
-
test('getPrivateKeyHandler should return the wallet private key', async () => {
|
182
|
-
const result = await getPrivateKeyHandler({
|
183
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
184
|
-
});
|
185
|
-
|
186
|
-
expect(result.isError).toBe(false);
|
187
|
-
expect(result.toolResult).toHaveProperty('privateKey');
|
188
|
-
expect(result.toolResult.privateKey).toBe('0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
|
189
|
-
});
|
190
|
-
|
191
|
-
test('getMnemonicHandler should return the wallet mnemonic', async () => {
|
192
|
-
const result = await getMnemonicHandler({
|
193
|
-
wallet: 'test test test test test test test test test test test junk'
|
194
|
-
});
|
195
|
-
|
196
|
-
expect(result.isError).toBe(false);
|
197
|
-
expect(result.toolResult).toHaveProperty('mnemonic');
|
198
|
-
expect(result.toolResult.mnemonic).toBe('test test test test test test test test test test test junk');
|
199
|
-
});
|
200
|
-
});
|
201
|
-
|
202
|
-
describe('Blockchain Methods Handlers', () => {
|
203
|
-
test('getBalanceHandler should return the wallet balance', async () => {
|
204
|
-
const result = await getBalanceHandler({
|
205
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
206
|
-
provider: 'https://mainnet.infura.io/v3/your-api-key'
|
207
|
-
});
|
208
|
-
|
209
|
-
expect(result.isError).toBe(false);
|
210
|
-
expect(result.toolResult).toHaveProperty('balance');
|
211
|
-
expect(result.toolResult).toHaveProperty('balanceInEth');
|
212
|
-
expect(result.toolResult.balanceInEth).toBe('1.0');
|
213
|
-
});
|
214
|
-
|
215
|
-
test('getChainIdHandler should return the chain ID', async () => {
|
216
|
-
const result = await getChainIdHandler({
|
217
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
218
|
-
provider: 'https://mainnet.infura.io/v3/your-api-key'
|
219
|
-
});
|
220
|
-
|
221
|
-
expect(result.isError).toBe(false);
|
222
|
-
expect(result.toolResult).toHaveProperty('chainId');
|
223
|
-
expect(result.toolResult.chainId).toBe(1);
|
224
|
-
});
|
225
|
-
|
226
|
-
test('getGasPriceHandler should return the gas price', async () => {
|
227
|
-
const result = await getGasPriceHandler({
|
228
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
229
|
-
provider: 'https://mainnet.infura.io/v3/your-api-key'
|
230
|
-
});
|
231
|
-
|
232
|
-
expect(result.isError).toBe(false);
|
233
|
-
expect(result.toolResult).toHaveProperty('gasPrice');
|
234
|
-
expect(result.toolResult).toHaveProperty('gasPriceInGwei');
|
235
|
-
expect(result.toolResult.gasPriceInGwei).toBe('50.0');
|
236
|
-
});
|
237
|
-
|
238
|
-
test('getTransactionCountHandler should return the transaction count', async () => {
|
239
|
-
const result = await getTransactionCountHandler({
|
240
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
241
|
-
provider: 'https://mainnet.infura.io/v3/your-api-key'
|
242
|
-
});
|
243
|
-
|
244
|
-
expect(result.isError).toBe(false);
|
245
|
-
expect(result.toolResult).toHaveProperty('transactionCount');
|
246
|
-
expect(result.toolResult.transactionCount).toBe(5);
|
247
|
-
});
|
248
|
-
|
249
|
-
test('callHandler should call a contract method', async () => {
|
250
|
-
const result = await callHandler({
|
251
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
252
|
-
provider: 'https://mainnet.infura.io/v3/your-api-key',
|
253
|
-
transaction: {
|
254
|
-
to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
|
255
|
-
data: '0x70a08231000000000000000000000000742d35cc6634c0532925a3b844bc454e4438f44e'
|
256
|
-
}
|
257
|
-
});
|
258
|
-
|
259
|
-
expect(result.isError).toBe(false);
|
260
|
-
expect(result.toolResult).toHaveProperty('result');
|
261
|
-
});
|
262
|
-
});
|
263
|
-
|
264
|
-
describe('Signing Methods Handlers', () => {
|
265
|
-
test('signMessageHandler should sign a message', async () => {
|
266
|
-
const result = await signMessageHandler({
|
267
|
-
wallet: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
268
|
-
message: 'Hello, world!'
|
269
|
-
});
|
270
|
-
|
271
|
-
expect(result.isError).toBe(false);
|
272
|
-
expect(result.toolResult).toHaveProperty('signature');
|
273
|
-
expect(result.toolResult).toHaveProperty('message');
|
274
|
-
expect(result.toolResult.signature).toBe('0xsignature');
|
275
|
-
expect(result.toolResult.message).toBe('Hello, world!');
|
276
|
-
});
|
277
|
-
|
278
|
-
test('verifyMessageHandler should verify a signed message', async () => {
|
279
|
-
const result = await verifyMessageHandler({
|
280
|
-
message: 'Hello, world!',
|
281
|
-
signature: '0xsignature',
|
282
|
-
address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
|
283
|
-
});
|
284
|
-
|
285
|
-
expect(result.isError).toBe(false);
|
286
|
-
expect(result.toolResult).toHaveProperty('isValid');
|
287
|
-
expect(result.toolResult).toHaveProperty('recoveredAddress');
|
288
|
-
});
|
289
|
-
});
|