@walletmesh/aztec-rpc-wallet 0.2.0 → 0.3.0

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/aztecRemoteWallet.d.ts +4 -8
  4. package/dist/aztecRemoteWallet.d.ts.map +1 -1
  5. package/dist/aztecRemoteWallet.js +5 -29
  6. package/dist/contractArtifactCache.d.ts.map +1 -1
  7. package/dist/contractArtifactCache.js +20 -9
  8. package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
  9. package/dist/handlers/aztecAccountWallet.js +11 -44
  10. package/dist/serializers/account.d.ts +16 -16
  11. package/dist/serializers/account.d.ts.map +1 -1
  12. package/dist/serializers/account.js +43 -43
  13. package/dist/serializers/contract.d.ts +22 -76
  14. package/dist/serializers/contract.d.ts.map +1 -1
  15. package/dist/serializers/contract.js +68 -120
  16. package/dist/serializers/index.d.ts +0 -4
  17. package/dist/serializers/index.d.ts.map +1 -1
  18. package/dist/serializers/index.js +15 -20
  19. package/dist/serializers/log.d.ts +16 -16
  20. package/dist/serializers/log.d.ts.map +1 -1
  21. package/dist/serializers/log.js +43 -43
  22. package/dist/serializers/note.d.ts +12 -12
  23. package/dist/serializers/note.d.ts.map +1 -1
  24. package/dist/serializers/note.js +32 -32
  25. package/dist/serializers/transaction.d.ts +25 -26
  26. package/dist/serializers/transaction.d.ts.map +1 -1
  27. package/dist/serializers/transaction.js +92 -44
  28. package/dist/types.d.ts +7 -30
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/types.js +1 -1
  31. package/docs/README.md +264 -0
  32. package/docs/classes/AztecChainProvider.md +553 -0
  33. package/docs/classes/AztecChainWallet.md +409 -0
  34. package/docs/classes/AztecProvider.md +1112 -0
  35. package/docs/classes/AztecWalletError.md +213 -0
  36. package/docs/classes/ContractArtifactCache.md +81 -0
  37. package/docs/globals.md +34 -0
  38. package/docs/interfaces/AztecWalletBaseMethodMap.md +135 -0
  39. package/docs/interfaces/AztecWalletEventMap.md +17 -0
  40. package/docs/interfaces/AztecWalletMethodMap.md +1012 -0
  41. package/docs/type-aliases/AztecChainId.md +11 -0
  42. package/docs/type-aliases/AztecChainWalletMiddleware.md +13 -0
  43. package/docs/type-aliases/AztecWalletContext.md +29 -0
  44. package/docs/type-aliases/AztecWalletMethodHandler.md +37 -0
  45. package/docs/type-aliases/AztecWalletMiddleware.md +13 -0
  46. package/docs/type-aliases/AztecWalletRouterClient.md +13 -0
  47. package/docs/type-aliases/TransactionFunctionCall.md +33 -0
  48. package/docs/type-aliases/TransactionParams.md +27 -0
  49. package/docs/variables/AztecWalletErrorMap.md +13 -0
  50. package/package.json +9 -9
  51. package/src/aztecRemoteWallet.test.ts +22 -61
  52. package/src/aztecRemoteWallet.ts +8 -35
  53. package/src/chainProvider.test.ts +117 -38
  54. package/src/contractArtifactCache.test.ts +28 -45
  55. package/src/contractArtifactCache.ts +20 -10
  56. package/src/handlers/aztecAccountWallet.test.ts +12 -86
  57. package/src/handlers/aztecAccountWallet.ts +19 -77
  58. package/src/provider.test.ts +0 -2
  59. package/src/serializers/account.test.ts +19 -20
  60. package/src/serializers/account.ts +52 -52
  61. package/src/serializers/contract.test.ts +4 -140
  62. package/src/serializers/contract.ts +93 -166
  63. package/src/serializers/index.test.ts +30 -28
  64. package/src/serializers/index.ts +15 -21
  65. package/src/serializers/log.test.ts +42 -48
  66. package/src/serializers/log.ts +54 -54
  67. package/src/serializers/note.test.ts +43 -16
  68. package/src/serializers/note.ts +39 -39
  69. package/src/serializers/transaction.test.ts +48 -41
  70. package/src/serializers/transaction.ts +146 -58
  71. package/src/types.ts +7 -7
  72. package/src/wallet.test.ts +3 -3
  73. package/dist/serializers/transaction-utils.d.ts +0 -51
  74. package/dist/serializers/transaction-utils.d.ts.map +0 -1
  75. package/dist/serializers/transaction-utils.js +0 -103
  76. package/src/serializers/transaction-utils.ts +0 -174
@@ -1,12 +1,19 @@
1
1
  import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import type { JSONRPCTransport, JSONRPCRequest } from '@walletmesh/jsonrpc';
2
+ import type { JSONRPCRequest } from '@walletmesh/jsonrpc';
3
3
  import { AztecChainProvider } from './chainProvider.js';
4
4
  import { AztecWalletError } from './errors.js';
5
5
  import type { ContractInstanceWithAddress, ContractArtifact, AztecAddress } from '@aztec/aztec.js';
6
6
  import type { AztecWalletMethodMap } from './types.js';
7
7
 
8
8
  const createMockTransport = () => ({
9
- send: vi.fn().mockImplementation(() => Promise.resolve()),
9
+ send: vi
10
+ .fn()
11
+ .mockImplementation(
12
+ async (_request: JSONRPCRequest<AztecWalletMethodMap, keyof AztecWalletMethodMap>) => {
13
+ // Default mock implementation that records the call but returns undefined
14
+ return undefined;
15
+ },
16
+ ),
10
17
  });
11
18
 
12
19
  describe('AztecChainProvider', () => {
@@ -27,10 +34,16 @@ describe('AztecChainProvider', () => {
27
34
  const expectedAddress = '0x1234567890abcdef';
28
35
  const promise = provider.getAccount();
29
36
 
37
+ // Wait for the async operation to complete
38
+ await Promise.resolve();
39
+
30
40
  // Get the request ID from the sent message
31
- const [[sentRequest]] = mockTransport.send.mock.calls as [
32
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_getAccount'>],
33
- ];
41
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
42
+ const firstCall = mockTransport.send.mock.calls[0];
43
+ if (!firstCall) throw new Error('Expected mock to be called');
44
+ const request = firstCall[0];
45
+ if (!request) throw new Error('Expected request to be defined');
46
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_getAccount'>;
34
47
  expect(sentRequest).toEqual({
35
48
  jsonrpc: '2.0',
36
49
  id: expect.any(String),
@@ -51,10 +64,16 @@ describe('AztecChainProvider', () => {
51
64
  it('throws on invalid response', async () => {
52
65
  const promise = provider.getAccount();
53
66
 
67
+ // Wait for the async operation to complete
68
+ await Promise.resolve();
69
+
54
70
  // Get the request ID
55
- const [[sentRequest]] = mockTransport.send.mock.calls as [
56
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_getAccount'>],
57
- ];
71
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
72
+ const firstCall = mockTransport.send.mock.calls[0];
73
+ if (!firstCall) throw new Error('Expected mock to be called');
74
+ const request = firstCall[0];
75
+ if (!request) throw new Error('Expected request to be defined');
76
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_getAccount'>;
58
77
 
59
78
  // Simulate error response
60
79
  await provider.receiveMessage({
@@ -82,10 +101,16 @@ describe('AztecChainProvider', () => {
82
101
  const expectedHash = '0xabcd';
83
102
  const promise = provider.sendTransaction(txParams);
84
103
 
104
+ // Wait for the async operation to complete
105
+ await Promise.resolve();
106
+
85
107
  // Get the request ID
86
- const [[sentRequest]] = mockTransport.send.mock.calls as [
87
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_sendTransaction'>],
88
- ];
108
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
109
+ const firstCall = mockTransport.send.mock.calls[0];
110
+ if (!firstCall) throw new Error('Expected mock to be called');
111
+ const request = firstCall[0];
112
+ if (!request) throw new Error('Expected request to be defined');
113
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_sendTransaction'>;
89
114
  expect(sentRequest).toEqual({
90
115
  jsonrpc: '2.0',
91
116
  id: expect.any(String),
@@ -107,10 +132,16 @@ describe('AztecChainProvider', () => {
107
132
  it('throws on invalid response', async () => {
108
133
  const promise = provider.sendTransaction(txParams);
109
134
 
135
+ // Wait for the async operation to complete
136
+ await Promise.resolve();
137
+
110
138
  // Get the request ID
111
- const [[sentRequest]] = mockTransport.send.mock.calls as [
112
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_sendTransaction'>],
113
- ];
139
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
140
+ const firstCall = mockTransport.send.mock.calls[0];
141
+ if (!firstCall) throw new Error('Expected mock to be called');
142
+ const request = firstCall[0];
143
+ if (!request) throw new Error('Expected request to be defined');
144
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_sendTransaction'>;
114
145
 
115
146
  // Simulate error response
116
147
  await provider.receiveMessage({
@@ -134,10 +165,16 @@ describe('AztecChainProvider', () => {
134
165
  const expectedResult = { success: true, data: 'test' };
135
166
  const promise = provider.simulateTransaction(txParams);
136
167
 
168
+ // Wait for the async operation to complete
169
+ await Promise.resolve();
170
+
137
171
  // Get the request ID
138
- const [[sentRequest]] = mockTransport.send.mock.calls as [
139
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_simulateTransaction'>],
140
- ];
172
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
173
+ const firstCall = mockTransport.send.mock.calls[0];
174
+ if (!firstCall) throw new Error('Expected mock to be called');
175
+ const request = firstCall[0];
176
+ if (!request) throw new Error('Expected request to be defined');
177
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_simulateTransaction'>;
141
178
  expect(sentRequest).toEqual({
142
179
  jsonrpc: '2.0',
143
180
  id: expect.any(String),
@@ -159,10 +196,16 @@ describe('AztecChainProvider', () => {
159
196
  it('throws on invalid response', async () => {
160
197
  const promise = provider.simulateTransaction(txParams);
161
198
 
199
+ // Wait for the async operation to complete
200
+ await Promise.resolve();
201
+
162
202
  // Get the request ID
163
- const [[sentRequest]] = mockTransport.send.mock.calls as [
164
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_simulateTransaction'>],
165
- ];
203
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
204
+ const firstCall = mockTransport.send.mock.calls[0];
205
+ if (!firstCall) throw new Error('Expected mock to be called');
206
+ const request = firstCall[0];
207
+ if (!request) throw new Error('Expected request to be defined');
208
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_simulateTransaction'>;
166
209
 
167
210
  // Simulate error response
168
211
  await provider.receiveMessage({
@@ -184,10 +227,16 @@ describe('AztecChainProvider', () => {
184
227
  it('succeeds on valid response', async () => {
185
228
  const promise = provider.registerContract(contractParams);
186
229
 
230
+ // Wait for the async operation to complete
231
+ await Promise.resolve();
232
+
187
233
  // Get the request ID
188
- const [[sentRequest]] = mockTransport.send.mock.calls as [
189
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContract'>],
190
- ];
234
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
235
+ const firstCall = mockTransport.send.mock.calls[0];
236
+ if (!firstCall) throw new Error('Expected mock to be called');
237
+ const request = firstCall[0];
238
+ if (!request) throw new Error('Expected request to be defined');
239
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContract'>;
191
240
  expect(sentRequest).toEqual({
192
241
  jsonrpc: '2.0',
193
242
  id: expect.any(String),
@@ -208,10 +257,16 @@ describe('AztecChainProvider', () => {
208
257
  it('throws on invalid response', async () => {
209
258
  const promise = provider.registerContract(contractParams);
210
259
 
260
+ // Wait for the async operation to complete
261
+ await Promise.resolve();
262
+
211
263
  // Get the request ID
212
- const [[sentRequest]] = mockTransport.send.mock.calls as [
213
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContract'>],
214
- ];
264
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
265
+ const firstCall = mockTransport.send.mock.calls[0];
266
+ if (!firstCall) throw new Error('Expected mock to be called');
267
+ const request = firstCall[0];
268
+ if (!request) throw new Error('Expected request to be defined');
269
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContract'>;
215
270
 
216
271
  // Simulate error response
217
272
  await provider.receiveMessage({
@@ -232,10 +287,16 @@ describe('AztecChainProvider', () => {
232
287
  it('succeeds on valid response', async () => {
233
288
  const promise = provider.registerContractClass(classParams);
234
289
 
290
+ // Wait for the async operation to complete
291
+ await Promise.resolve();
292
+
235
293
  // Get the request ID
236
- const [[sentRequest]] = mockTransport.send.mock.calls as [
237
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContractClass'>],
238
- ];
294
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
295
+ const firstCall = mockTransport.send.mock.calls[0];
296
+ if (!firstCall) throw new Error('Expected mock to be called');
297
+ const request = firstCall[0];
298
+ if (!request) throw new Error('Expected request to be defined');
299
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContractClass'>;
239
300
  expect(sentRequest).toEqual({
240
301
  jsonrpc: '2.0',
241
302
  id: expect.any(String),
@@ -256,10 +317,16 @@ describe('AztecChainProvider', () => {
256
317
  it('throws on invalid response', async () => {
257
318
  const promise = provider.registerContractClass(classParams);
258
319
 
320
+ // Wait for the async operation to complete
321
+ await Promise.resolve();
322
+
259
323
  // Get the request ID
260
- const [[sentRequest]] = mockTransport.send.mock.calls as [
261
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContractClass'>],
262
- ];
324
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
325
+ const firstCall = mockTransport.send.mock.calls[0];
326
+ if (!firstCall) throw new Error('Expected mock to be called');
327
+ const request = firstCall[0];
328
+ if (!request) throw new Error('Expected request to be defined');
329
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerContractClass'>;
263
330
 
264
331
  // Simulate error response
265
332
  await provider.receiveMessage({
@@ -280,10 +347,16 @@ describe('AztecChainProvider', () => {
280
347
  it('succeeds on valid response', async () => {
281
348
  const promise = provider.registerSender(senderParams);
282
349
 
350
+ // Wait for the async operation to complete
351
+ await Promise.resolve();
352
+
283
353
  // Get the request ID
284
- const [[sentRequest]] = mockTransport.send.mock.calls as [
285
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerSender'>],
286
- ];
354
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
355
+ const firstCall = mockTransport.send.mock.calls[0];
356
+ if (!firstCall) throw new Error('Expected mock to be called');
357
+ const request = firstCall[0];
358
+ if (!request) throw new Error('Expected request to be defined');
359
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerSender'>;
287
360
  expect(sentRequest).toEqual({
288
361
  jsonrpc: '2.0',
289
362
  id: expect.any(String),
@@ -304,10 +377,16 @@ describe('AztecChainProvider', () => {
304
377
  it('throws on invalid response', async () => {
305
378
  const promise = provider.registerSender(senderParams);
306
379
 
380
+ // Wait for the async operation to complete
381
+ await Promise.resolve();
382
+
307
383
  // Get the request ID
308
- const [[sentRequest]] = mockTransport.send.mock.calls as [
309
- [JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerSender'>],
310
- ];
384
+ expect(mockTransport.send).toHaveBeenCalledTimes(1);
385
+ const firstCall = mockTransport.send.mock.calls[0];
386
+ if (!firstCall) throw new Error('Expected mock to be called');
387
+ const request = firstCall[0];
388
+ if (!request) throw new Error('Expected request to be defined');
389
+ const sentRequest = request as JSONRPCRequest<AztecWalletMethodMap, 'aztec_registerSender'>;
311
390
 
312
391
  // Simulate error response
313
392
  await provider.receiveMessage({
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it, vi, beforeEach, type Mock } from 'vitest';
2
- import type { AztecAddress, ContractArtifact, ContractClassWithId, Wallet } from '@aztec/aztec.js';
2
+ import type { AztecAddress, ContractArtifact, Fr, Wallet } from '@aztec/aztec.js';
3
+ import { randomDeployedContract } from '@aztec/circuit-types';
3
4
  import { ContractArtifactCache } from './contractArtifactCache.js';
4
5
  import { AztecWalletError } from './errors.js';
5
6
 
@@ -7,45 +8,23 @@ describe('ContractArtifactCache', () => {
7
8
  let wallet: Wallet;
8
9
  let cache: ContractArtifactCache;
9
10
  let mockContractAddress: AztecAddress;
10
- let mockContractClassId: ContractClassWithId;
11
+ let mockContractClassId: Fr;
11
12
  let mockArtifact: ContractArtifact;
12
13
 
13
- beforeEach(() => {
14
+ beforeEach(async () => {
14
15
  // Mock contract address and class ID
15
16
  // Create a complete mock of AztecAddress
16
- mockContractAddress = {
17
- toString: () => '0x123',
18
- _branding: 'aztec.Address',
19
- xCoord: BigInt(0),
20
- size: 32,
21
- equals: () => false,
22
- toBuffer: () => Buffer.from([]),
23
- toFields: () => [],
24
- toField: () => BigInt(0),
25
- toBigInt: () => BigInt(0),
26
- isZero: () => false,
27
- isValid: () => true,
28
- toAddressPoint: () => ({ x: BigInt(0) }),
29
- toJSON: () => ({ x: '0' }),
30
- [Symbol.for('nodejs.util.inspect.custom')]: () => 'AztecAddress',
31
- } as unknown as AztecAddress;
32
-
33
- // Create a complete mock of ContractClassWithId
34
- mockContractClassId = {
35
- toString: () => '456',
36
- id: BigInt(456),
37
- version: 1,
38
- artifactHash: BigInt(0),
39
- privateFunctions: new Map(),
40
- publicFunctions: new Map(),
41
- packedBytecode: new Uint8Array(),
42
- } as unknown as ContractClassWithId;
43
- mockArtifact = { name: 'TestContract' } as ContractArtifact;
17
+
18
+ const { instance, artifact } = await randomDeployedContract();
19
+
20
+ mockContractAddress = instance.address;
21
+ mockContractClassId = instance.contractClassId;
22
+ mockArtifact = artifact;
44
23
 
45
24
  // Create mock wallet
46
25
  wallet = {
47
- getContractInstance: vi.fn(),
48
- getContractArtifact: vi.fn(),
26
+ getContractMetadata: vi.fn(),
27
+ getContractClassMetadata: vi.fn(),
49
28
  } as unknown as Wallet;
50
29
 
51
30
  // Initialize cache with mock wallet
@@ -64,21 +43,23 @@ describe('ContractArtifactCache', () => {
64
43
 
65
44
  // Verify: Result is from cache, wallet methods not called
66
45
  expect(result).toBe(mockArtifact);
67
- expect(wallet.getContractInstance).not.toHaveBeenCalled();
68
- expect(wallet.getContractArtifact).not.toHaveBeenCalled();
46
+ expect(wallet.getContractMetadata).not.toHaveBeenCalled();
47
+ expect(wallet.getContractClassMetadata).not.toHaveBeenCalled();
69
48
  });
70
49
 
71
50
  it('fetches and caches artifact on cache miss', async () => {
72
51
  // Setup: Configure wallet mocks
73
- (wallet.getContractInstance as Mock).mockResolvedValue({ contractClassId: mockContractClassId });
74
- (wallet.getContractArtifact as Mock).mockResolvedValue(mockArtifact);
52
+ (wallet.getContractMetadata as Mock).mockResolvedValue({
53
+ contractInstance: { contractClassId: mockContractClassId },
54
+ });
55
+ (wallet.getContractClassMetadata as Mock).mockResolvedValue({ artifact: mockArtifact });
75
56
 
76
57
  // Test: Get artifact
77
58
  const result = await cache.getContractArtifact(mockContractAddress);
78
59
 
79
60
  // Verify: Correct methods called and result cached
80
- expect(wallet.getContractInstance).toHaveBeenCalledWith(mockContractAddress);
81
- expect(wallet.getContractArtifact).toHaveBeenCalledWith(mockContractClassId);
61
+ expect(wallet.getContractMetadata).toHaveBeenCalledWith(mockContractAddress);
62
+ expect(wallet.getContractClassMetadata).toHaveBeenCalledWith(mockContractClassId);
82
63
  expect(result).toBe(mockArtifact);
83
64
 
84
65
  // Verify: Result was cached
@@ -89,9 +70,9 @@ describe('ContractArtifactCache', () => {
89
70
  ).toBe(mockArtifact);
90
71
  });
91
72
 
92
- it('throws error if contract instance not found', async () => {
73
+ it('throws error if contract metadata not found', async () => {
93
74
  // Setup: Mock contract instance not found
94
- (wallet.getContractInstance as Mock).mockResolvedValue(null);
75
+ (wallet.getContractMetadata as Mock).mockResolvedValue({ contractInstance: undefined });
95
76
 
96
77
  // Test & Verify: Expect error
97
78
  await expect(cache.getContractArtifact(mockContractAddress)).rejects.toThrow(
@@ -106,10 +87,12 @@ describe('ContractArtifactCache', () => {
106
87
  ).toBeUndefined();
107
88
  });
108
89
 
109
- it('throws error if contract artifact not found', async () => {
110
- // Setup: Mock contract instance found but artifact missing
111
- (wallet.getContractInstance as Mock).mockResolvedValue({ contractClassId: mockContractClassId });
112
- (wallet.getContractArtifact as Mock).mockResolvedValue(null);
90
+ it('throws error if contract class metadata not found', async () => {
91
+ // Setup: Mock contract metadata found but class metadata missing
92
+ (wallet.getContractMetadata as Mock).mockResolvedValue({
93
+ contractInstance: { contractClassId: mockContractClassId },
94
+ });
95
+ (wallet.getContractClassMetadata as Mock).mockResolvedValue({ artifact: undefined });
113
96
 
114
97
  // Test & Verify: Expect error
115
98
  await expect(cache.getContractArtifact(mockContractAddress)).rejects.toThrow(
@@ -60,16 +60,26 @@ export class ContractArtifactCache {
60
60
  return cached;
61
61
  }
62
62
 
63
- const contract = await this.wallet.getContractInstance(contractAddress);
64
- if (!contract) {
65
- throw new AztecWalletError('contractInstanceNotRegistered', addressStr);
66
- }
67
- const artifact = await this.wallet.getContractArtifact(contract.contractClassId);
68
- if (!artifact) {
69
- throw new AztecWalletError('contractClassNotRegistered', contract.contractClassId.toString());
70
- }
63
+ try {
64
+ const contractMetadata = await this.wallet.getContractMetadata(contractAddress);
65
+ const contract = contractMetadata.contractInstance;
66
+ if (!contract) {
67
+ throw new AztecWalletError('contractInstanceNotRegistered', addressStr);
68
+ }
71
69
 
72
- this.cache.set(addressStr, artifact);
73
- return artifact;
70
+ const contractClassMetadata = await this.wallet.getContractClassMetadata(contract.contractClassId);
71
+ const artifact = contractClassMetadata.artifact;
72
+ if (!artifact) {
73
+ throw new AztecWalletError('contractClassNotRegistered', contract.contractClassId.toString());
74
+ }
75
+ this.cache.set(addressStr, artifact);
76
+ return artifact;
77
+ } catch (error) {
78
+ if (error instanceof AztecWalletError) {
79
+ throw error;
80
+ }
81
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
82
+ throw new AztecWalletError('contractInstanceNotRegistered', `${addressStr}: ${errorMessage}`);
83
+ }
74
84
  }
75
85
  }
@@ -6,7 +6,6 @@ import type {
6
6
  ContractInstanceWithAddress,
7
7
  ContractArtifact,
8
8
  PublicKeys,
9
- Note,
10
9
  AuthWitness,
11
10
  Tx,
12
11
  } from '@aztec/aztec.js';
@@ -46,12 +45,8 @@ describe('Aztec Account Wallet Handler', () => {
46
45
  createAuthWit: vi.fn(),
47
46
  isL1ToL2MessageSynced: vi.fn(),
48
47
  getContracts: vi.fn(),
49
- getContractInstance: vi.fn(),
50
- getContractClass: vi.fn(),
51
- getContractArtifact: vi.fn(),
52
- isContractClassPubliclyRegistered: vi.fn(),
53
- isContractPubliclyDeployed: vi.fn(),
54
- isContractInitialized: vi.fn(),
48
+ getContractMetadata: vi.fn(),
49
+ getContractClassMetadata: vi.fn(),
55
50
  registerContract: vi.fn(),
56
51
  registerContractClass: vi.fn(),
57
52
  getPublicStorageAt: vi.fn(),
@@ -255,91 +250,22 @@ describe('Aztec Account Wallet Handler', () => {
255
250
  });
256
251
 
257
252
  describe('Contract Methods', () => {
258
- it('handles aztec_getContractInstance', async () => {
253
+ it('handles aztec_getContractMetadata', async () => {
259
254
  const mockAddress = await AztecAddress.random();
260
- const mockInstance = {
261
- address: mockAddress,
262
- toString: () => mockAddress.toString(),
263
- } as unknown as ContractInstanceWithAddress;
264
- wallet.getContractInstance = vi.fn().mockResolvedValue(mockInstance);
265
-
266
- const result = await aztecWalletHandler(context, 'aztec_getContractInstance', { address: mockAddress });
267
- expect(result).toBe(mockInstance);
268
- });
269
-
270
- it('throws error when contract instance not found', async () => {
271
- wallet.getContractInstance = vi.fn().mockResolvedValue(null);
272
-
273
- const testAddress = await AztecAddress.random();
274
- await expect(
275
- aztecWalletHandler(context, 'aztec_getContractInstance', { address: testAddress }),
276
- ).rejects.toThrow(AztecWalletError);
277
- });
278
-
279
- it('handles aztec_getContractClass', async () => {
280
- const mockId = await Fr.random();
281
- const mockContractClass = { id: mockId };
282
- wallet.getContractClass = vi.fn().mockResolvedValue(mockContractClass);
283
-
284
- const result = await aztecWalletHandler(context, 'aztec_getContractClass', { id: mockId });
285
- expect(result).toBe(mockContractClass);
286
- });
287
-
288
- it('throws error when contract class not found', async () => {
289
- wallet.getContractClass = vi.fn().mockResolvedValue(null);
290
- const mockId = await Fr.random();
291
-
292
- await expect(aztecWalletHandler(context, 'aztec_getContractClass', { id: mockId })).rejects.toThrow(
293
- AztecWalletError,
294
- );
295
- });
296
-
297
- it('handles aztec_getContractArtifact', async () => {
298
- const mockId = await Fr.random();
299
- const mockArtifact = { id: mockId, name: 'TestContract' };
300
- wallet.getContractArtifact = vi.fn().mockResolvedValue(mockArtifact);
255
+ const mockMetadata = { address: mockAddress };
256
+ wallet.getContractMetadata = vi.fn().mockResolvedValue(mockMetadata);
301
257
 
302
- const result = await aztecWalletHandler(context, 'aztec_getContractArtifact', { id: mockId });
303
- expect(result).toBe(mockArtifact);
258
+ const result = await aztecWalletHandler(context, 'aztec_getContractMetadata', { address: mockAddress });
259
+ expect(result).toBe(mockMetadata);
304
260
  });
305
261
 
306
- it('throws error when contract artifact not found', async () => {
307
- wallet.getContractArtifact = vi.fn().mockResolvedValue(null);
262
+ it('handles aztec_getContractClassMetadata', async () => {
308
263
  const mockId = await Fr.random();
264
+ const mockMetadata = { id: mockId };
265
+ wallet.getContractClassMetadata = vi.fn().mockResolvedValue(mockMetadata);
309
266
 
310
- await expect(aztecWalletHandler(context, 'aztec_getContractArtifact', { id: mockId })).rejects.toThrow(
311
- AztecWalletError,
312
- );
313
- });
314
-
315
- it('handles aztec_isContractClassPubliclyRegistered', async () => {
316
- const mockId = await Fr.random();
317
- wallet.isContractClassPubliclyRegistered = vi.fn().mockResolvedValue(true);
318
-
319
- const result = await aztecWalletHandler(context, 'aztec_isContractClassPubliclyRegistered', {
320
- id: mockId,
321
- });
322
- expect(result).toBe(true);
323
- });
324
-
325
- it('handles aztec_isContractPubliclyDeployed', async () => {
326
- const mockAddress = await AztecAddress.random();
327
- wallet.isContractPubliclyDeployed = vi.fn().mockResolvedValue(true);
328
-
329
- const result = await aztecWalletHandler(context, 'aztec_isContractPubliclyDeployed', {
330
- address: mockAddress,
331
- });
332
- expect(result).toBe(true);
333
- });
334
-
335
- it('handles aztec_isContractInitialized', async () => {
336
- const mockAddress = await AztecAddress.random();
337
- wallet.isContractInitialized = vi.fn().mockResolvedValue(true);
338
-
339
- const result = await aztecWalletHandler(context, 'aztec_isContractInitialized', {
340
- address: mockAddress,
341
- });
342
- expect(result).toBe(true);
267
+ const result = await aztecWalletHandler(context, 'aztec_getContractClassMetadata', { id: mockId });
268
+ expect(result).toBe(mockMetadata);
343
269
  });
344
270
 
345
271
  it('handles aztec_registerContract', async () => {