@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,140 +1,17 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { Fr, AztecAddress } from '@aztec/aztec.js';
3
- import { Buffer } from 'node:buffer';
4
- import {
5
- aztecGetContractInstanceSerializer,
6
- aztecGetContractClassSerializer,
7
- aztecGetContractArtifactSerializer,
8
- aztecRegisterContractSerializer,
9
- } from './contract.js';
10
- import {
11
- getContractClassFromArtifact,
12
- ContractClassWithIdSchema,
13
- ContractInstanceWithAddressSchema,
14
- SerializableContractInstance,
15
- } from '@aztec/circuits.js';
16
- import {
17
- ContractArtifact,
18
- ContractArtifactSchema,
19
- type FieldLayout,
20
- type ContractNote,
21
- } from '@aztec/foundation/abi';
22
- import { randomContractArtifact, randomDeployedContract } from '@aztec/circuit-types';
2
+ import { aztecRegisterContractSerializer } from './contract.js';
3
+ import { randomDeployedContract } from '@aztec/circuit-types';
23
4
  describe('Contract Serializers', () => {
24
- describe('aztec_getContractInstance', () => {
25
- it('should serialize and deserialize params', async () => {
26
- const address = await AztecAddress.random();
27
- const params = { address };
28
-
29
- const serialized = aztecGetContractInstanceSerializer.params.serialize(
30
- 'aztec_getContractInstance',
31
- params,
32
- );
33
- expect(serialized.method).toBe('aztec_getContractInstance');
34
-
35
- const deserialized = aztecGetContractInstanceSerializer.params.deserialize(
36
- 'aztec_getContractInstance',
37
- serialized,
38
- );
39
- expect(deserialized.address.toString()).toBe(address.toString());
40
- });
41
-
42
- it('should serialize and deserialize result', async () => {
43
- // Create a contract instance with all required fields
44
- const result = (await SerializableContractInstance.random()).withAddress(await AztecAddress.random());
45
-
46
- const serialized = aztecGetContractInstanceSerializer.result.serialize(
47
- 'aztec_getContractInstance',
48
- result,
49
- );
50
- expect(serialized.method).toBe('aztec_getContractInstance');
51
-
52
- const deserialized = aztecGetContractInstanceSerializer.result.deserialize(
53
- 'aztec_getContractInstance',
54
- serialized,
55
- );
56
- expect(deserialized.address.toString()).toBe(result.address.toString());
57
- expect(deserialized.contractClassId.toString()).toBe(result.contractClassId.toString());
58
- expect(deserialized.deployer.toString()).toBe(result.deployer.toString());
59
- expect(deserialized.salt.toString()).toBe(result.salt.toString());
60
- expect(deserialized.version).toBe(result.version);
61
- });
62
- });
63
-
64
- describe('aztec_getContractClass', () => {
65
- it('should serialize and deserialize params', async () => {
66
- const id = await Fr.random();
67
- const params = { id };
68
-
69
- const serialized = aztecGetContractClassSerializer.params.serialize('aztec_getContractClass', params);
70
- expect(serialized.method).toBe('aztec_getContractClass');
71
-
72
- const deserialized = aztecGetContractClassSerializer.params.deserialize(
73
- 'aztec_getContractClass',
74
- serialized,
75
- );
76
- expect(deserialized.id.toString()).toBe(id.toString());
77
- });
78
-
79
- it('should serialize and deserialize result', async () => {
80
- const artifact = await randomContractArtifact();
81
- const result = getContractClassFromArtifact(artifact);
82
- const serialized = aztecGetContractClassSerializer.result.serialize('aztec_getContractClass', result);
83
- expect(serialized.method).toBe('aztec_getContractClass');
84
-
85
- const deserialized = aztecGetContractClassSerializer.result.deserialize(
86
- 'aztec_getContractClass',
87
- serialized,
88
- );
89
- expect(deserialized.artifactHash.toString()).toEqual(result.artifactHash.toString());
90
- expect(deserialized.id.toString()).toEqual(result.id.toString());
91
- expect(deserialized.privateFunctions).toEqual(result.privateFunctions);
92
- expect(deserialized.publicFunctions).toEqual(result.publicFunctions);
93
- expect(deserialized.packedBytecode).toEqual(result.packedBytecode);
94
- });
95
- });
96
-
97
- describe('aztec_getContractArtifact', () => {
98
- it('should serialize and deserialize params', async () => {
99
- const id = await Fr.random();
100
- const serialized = aztecGetContractArtifactSerializer.params.serialize('aztec_getContractArtifact', {
101
- id,
102
- });
103
- expect(serialized.method).toBe('aztec_getContractArtifact');
104
-
105
- const deserialized = aztecGetContractArtifactSerializer.params.deserialize(
106
- 'aztec_getContractArtifact',
107
- serialized,
108
- );
109
- expect(deserialized.id.toString()).toBe(id.toString());
110
- });
111
-
112
- it('should serialize and deserialize result', async () => {
113
- const result = await randomContractArtifact();
114
- const serialized = aztecGetContractArtifactSerializer.result.serialize(
115
- 'aztec_getContractArtifact',
116
- result,
117
- );
118
- expect(serialized.method).toBe('aztec_getContractArtifact');
119
-
120
- const deserialized = aztecGetContractArtifactSerializer.result.deserialize(
121
- 'aztec_getContractArtifact',
122
- serialized,
123
- );
124
- expect(ContractArtifactSchema.parse(deserialized)).toEqual(result);
125
- });
126
- });
127
-
128
5
  describe('aztec_registerContract', () => {
129
6
  it('should serialize and deserialize params', async () => {
130
7
  const { instance, artifact } = await randomDeployedContract();
131
- const serialized = aztecRegisterContractSerializer.params.serialize('aztec_registerContract', {
8
+ const serialized = await aztecRegisterContractSerializer.params.serialize('aztec_registerContract', {
132
9
  instance,
133
10
  artifact,
134
11
  });
135
12
  expect(serialized.method).toBe('aztec_registerContract');
136
13
 
137
- const deserialized = aztecRegisterContractSerializer.params.deserialize(
14
+ const deserialized = await aztecRegisterContractSerializer.params.deserialize(
138
15
  'aztec_registerContract',
139
16
  serialized,
140
17
  );
@@ -143,18 +20,5 @@ describe('Contract Serializers', () => {
143
20
  expect(deserialized.instance.deployer.toString()).toBe(instance.deployer.toString());
144
21
  expect(deserialized.artifact).toEqual(artifact);
145
22
  });
146
-
147
- it('should serialize and deserialize result', () => {
148
- const result = true;
149
-
150
- const serialized = aztecRegisterContractSerializer.result.serialize('aztec_registerContract', result);
151
- expect(serialized.method).toBe('aztec_registerContract');
152
-
153
- const deserialized = aztecRegisterContractSerializer.result.deserialize(
154
- 'aztec_registerContract',
155
- serialized,
156
- );
157
- expect(deserialized).toBe(result);
158
- });
159
23
  });
160
24
  });
@@ -1,184 +1,135 @@
1
1
  import type { AztecWalletMethodMap } from '../types.js';
2
2
  import type { JSONRPCSerializedData, JSONRPCSerializer } from '@walletmesh/jsonrpc';
3
- import { SerializableContractInstance, ContractClassWithIdSchema } from '@aztec/circuits.js';
3
+ import { ContractClassWithIdSchema, ContractInstanceWithAddressSchema } from '@aztec/circuits.js';
4
4
  import { ContractArtifactSchema } from '@aztec/foundation/abi';
5
5
  import { AztecAddress, Fr } from '@aztec/aztec.js';
6
- import type { ContractInstanceWithAddress } from '@aztec/aztec.js';
7
6
  import { jsonStringify, jsonParseWithSchema } from '@aztec/foundation/json-rpc';
7
+ import type { ZodFor } from '@aztec/foundation/schemas';
8
+ import type { ContractMetadata, ContractClassMetadata } from '@aztec/circuit-types';
9
+ import { z } from 'zod';
8
10
 
9
- /**
10
- * Serializer for the aztec_getContractInstance RPC method.
11
- * Handles serialization of contract instance queries and results between JSON-RPC format and native Aztec types.
12
- */
13
- export class AztecGetContractInstanceSerializer
14
- implements
15
- JSONRPCSerializer<
16
- AztecWalletMethodMap['aztec_getContractInstance']['params'],
17
- AztecWalletMethodMap['aztec_getContractInstance']['result']
18
- >
19
- {
20
- params = {
21
- /**
22
- * Serializes contract instance query parameters for RPC transport.
23
- * @param method - The RPC method name
24
- * @param value - The parameters containing the contract address to look up
25
- * @returns Serialized address data
26
- */
27
- serialize: (
28
- method: string,
29
- value: AztecWalletMethodMap['aztec_getContractInstance']['params'],
30
- ): JSONRPCSerializedData => ({
31
- method,
32
- serialized: jsonStringify(value.address),
33
- }),
34
- deserialize: (
35
- _method: string,
36
- data: JSONRPCSerializedData,
37
- ): AztecWalletMethodMap['aztec_getContractInstance']['params'] => {
38
- return {
39
- address: jsonParseWithSchema(data.serialized, AztecAddress.schema),
40
- };
41
- },
42
- };
11
+ // Zod schemas for contract metadata serialization.
12
+ // These are copied from @aztec/circuit-types because they are not exported.
13
+ const ContractMetadataSchema = z.object({
14
+ contractInstance: z.union([ContractInstanceWithAddressSchema, z.undefined()]),
15
+ isContractInitialized: z.boolean(),
16
+ isContractPubliclyDeployed: z.boolean(),
17
+ }) satisfies ZodFor<ContractMetadata>;
43
18
 
44
- result = {
45
- /**
46
- * Serializes the contract instance query result.
47
- * @param method - The RPC method name
48
- * @param value - The contract instance data including address and state
49
- * @returns Serialized contract instance data
50
- */
51
- serialize: (method: string, value: ContractInstanceWithAddress): JSONRPCSerializedData => ({
52
- method,
53
- serialized: JSON.stringify({
54
- serializableContractInstance: new SerializableContractInstance(value).toBuffer(),
55
- address: jsonStringify(value.address),
56
- }),
57
- }),
58
- deserialize: (_method: string, data: JSONRPCSerializedData): ContractInstanceWithAddress => {
59
- const parsed = JSON.parse(data.serialized);
60
- return SerializableContractInstance.fromBuffer(
61
- Buffer.from(parsed.serializableContractInstance),
62
- ).withAddress(jsonParseWithSchema(parsed.address, AztecAddress.schema));
63
- },
64
- };
65
- }
19
+ const ContractClassMetadataSchema = z.object({
20
+ contractClass: z.union([ContractClassWithIdSchema, z.undefined()]),
21
+ isContractClassPubliclyRegistered: z.boolean(),
22
+ artifact: z.union([ContractArtifactSchema, z.undefined()]),
23
+ }) satisfies ZodFor<ContractClassMetadata>;
66
24
 
67
25
  /**
68
- * Serializer for the aztec_getContractClass RPC method.
69
- * Handles serialization of contract class queries and results between JSON-RPC format and native Aztec types.
26
+ * Serializer for the aztec_getContractClassMetadata RPC method.
27
+ * Handles serialization of contract class metadata queries and results between JSON-RPC format and native Aztec types.
70
28
  */
71
- export class AztecGetContractClassSerializer
29
+ export class AztecGetContractClassMetadataSerializer
72
30
  implements
73
31
  JSONRPCSerializer<
74
- AztecWalletMethodMap['aztec_getContractClass']['params'],
75
- AztecWalletMethodMap['aztec_getContractClass']['result']
32
+ AztecWalletMethodMap['aztec_getContractClassMetadata']['params'],
33
+ AztecWalletMethodMap['aztec_getContractClassMetadata']['result']
76
34
  >
77
35
  {
78
36
  params = {
79
37
  /**
80
- * Serializes contract class query parameters for RPC transport.
38
+ * Serializes contract class metadata query parameters for RPC transport.
81
39
  * @param method - The RPC method name
82
- * @param value - The parameters containing the class ID to look up
83
- * @returns Serialized class ID data
40
+ * @param value - The parameters containing the class ID and artifact inclusion flag
41
+ * @returns Serialized query parameters
84
42
  */
85
- serialize: (
43
+ serialize: async (
86
44
  method: string,
87
- value: AztecWalletMethodMap['aztec_getContractClass']['params'],
88
- ): JSONRPCSerializedData => ({
89
- method,
90
- serialized: JSON.stringify({
91
- id: value.id.toString(),
45
+ value: AztecWalletMethodMap['aztec_getContractClassMetadata']['params'],
46
+ ): Promise<JSONRPCSerializedData> =>
47
+ Promise.resolve({
48
+ method,
49
+ serialized: JSON.stringify({
50
+ id: value.id.toString(),
51
+ includeArtifact: value.includeArtifact,
52
+ }),
92
53
  }),
93
- }),
94
- deserialize: (
54
+ deserialize: async (
95
55
  _method: string,
96
56
  data: JSONRPCSerializedData,
97
- ): AztecWalletMethodMap['aztec_getContractClass']['params'] => {
98
- const { id } = JSON.parse(data.serialized);
99
- return { id: Fr.fromString(id) };
57
+ ): Promise<AztecWalletMethodMap['aztec_getContractClassMetadata']['params']> => {
58
+ const { id, includeArtifact } = JSON.parse(data.serialized);
59
+ return {
60
+ id: Fr.fromString(id),
61
+ includeArtifact,
62
+ };
100
63
  },
101
64
  };
102
-
103
65
  result = {
104
66
  /**
105
- * Serializes the contract class query result.
67
+ * Serializes the contract class metadata query result.
106
68
  * @param method - The RPC method name
107
- * @param value - The contract class definition with its ID
108
- * @returns Serialized contract class data
69
+ * @param value - The contract class metadata including class definition and registration status
70
+ * @returns Serialized contract class metadata
109
71
  */
110
- serialize: (
72
+ serialize: async (
111
73
  method: string,
112
- value: AztecWalletMethodMap['aztec_getContractClass']['result'],
113
- ): JSONRPCSerializedData => ({
114
- method,
115
- serialized: JSON.stringify(value),
116
- }),
117
- deserialize: (
74
+ value: AztecWalletMethodMap['aztec_getContractClassMetadata']['result'],
75
+ ): Promise<JSONRPCSerializedData> => {
76
+ return {
77
+ method,
78
+ serialized: jsonStringify(value),
79
+ };
80
+ },
81
+ deserialize: async (
118
82
  _method: string,
119
83
  data: JSONRPCSerializedData,
120
- ): AztecWalletMethodMap['aztec_getContractClass']['result'] => {
121
- const parsed = JSON.parse(data.serialized);
122
- return ContractClassWithIdSchema.parse(parsed);
84
+ ): Promise<AztecWalletMethodMap['aztec_getContractClassMetadata']['result']> => {
85
+ return await jsonParseWithSchema(data.serialized, ContractClassMetadataSchema);
123
86
  },
124
87
  };
125
88
  }
126
89
 
127
- /**
128
- * Serializer for the aztec_getContractArtifact RPC method.
129
- * Handles serialization of contract artifact queries and results between JSON-RPC format and native Aztec types.
130
- */
131
- export class AztecGetContractArtifactSerializer
90
+ export class AztecGetContractMetadataSerializer
132
91
  implements
133
92
  JSONRPCSerializer<
134
- AztecWalletMethodMap['aztec_getContractArtifact']['params'],
135
- AztecWalletMethodMap['aztec_getContractArtifact']['result']
93
+ AztecWalletMethodMap['aztec_getContractMetadata']['params'],
94
+ AztecWalletMethodMap['aztec_getContractMetadata']['result']
136
95
  >
137
96
  {
138
97
  params = {
139
- /**
140
- * Serializes contract artifact query parameters for RPC transport.
141
- * @param method - The RPC method name
142
- * @param value - The parameters containing the artifact ID to look up
143
- * @returns Serialized artifact ID data
144
- */
145
- serialize: (
98
+ serialize: async (
146
99
  method: string,
147
- value: AztecWalletMethodMap['aztec_getContractArtifact']['params'],
148
- ): JSONRPCSerializedData => ({
149
- method,
150
- serialized: JSON.stringify({
151
- id: value.id.toString(),
152
- }),
153
- }),
154
- deserialize: (
100
+ value: AztecWalletMethodMap['aztec_getContractMetadata']['params'],
101
+ ): Promise<JSONRPCSerializedData> => {
102
+ return {
103
+ method,
104
+ serialized: jsonStringify(value.address),
105
+ };
106
+ },
107
+ deserialize: async (
155
108
  _method: string,
156
109
  data: JSONRPCSerializedData,
157
- ): AztecWalletMethodMap['aztec_getContractArtifact']['params'] => {
158
- const { id } = JSON.parse(data.serialized);
159
- return { id: Fr.fromString(id) };
110
+ ): Promise<AztecWalletMethodMap['aztec_getContractMetadata']['params']> => {
111
+ return {
112
+ address: await jsonParseWithSchema(data.serialized, AztecAddress.schema),
113
+ };
160
114
  },
161
115
  };
162
116
 
163
117
  result = {
164
- /**
165
- * Serializes the contract artifact query result.
166
- * @param method - The RPC method name
167
- * @param value - The contract artifact data
168
- * @returns Serialized contract artifact
169
- */
170
- serialize: (
118
+ serialize: async (
171
119
  method: string,
172
- value: AztecWalletMethodMap['aztec_getContractArtifact']['result'],
173
- ): JSONRPCSerializedData => ({
174
- method,
175
- serialized: JSON.stringify(ContractArtifactSchema.parse(value)),
176
- }),
177
- deserialize: (
120
+ contractMetadata: AztecWalletMethodMap['aztec_getContractMetadata']['result'],
121
+ ): Promise<JSONRPCSerializedData> => {
122
+ return {
123
+ method,
124
+ serialized: jsonStringify(contractMetadata),
125
+ };
126
+ },
127
+ deserialize: async (
178
128
  _method: string,
179
129
  data: JSONRPCSerializedData,
180
- ): AztecWalletMethodMap['aztec_getContractArtifact']['result'] =>
181
- ContractArtifactSchema.parse(JSON.parse(data.serialized)),
130
+ ): Promise<AztecWalletMethodMap['aztec_getContractMetadata']['result']> => {
131
+ return await jsonParseWithSchema(data.serialized, ContractMetadataSchema);
132
+ },
182
133
  };
183
134
  }
184
135
 
@@ -200,57 +151,33 @@ export class AztecRegisterContractSerializer
200
151
  * @param value - The parameters containing contract instance and optional artifact
201
152
  * @returns Serialized registration data
202
153
  */
203
- serialize: (
154
+ serialize: async (
204
155
  method: string,
205
156
  value: AztecWalletMethodMap['aztec_registerContract']['params'],
206
- ): JSONRPCSerializedData => ({
157
+ ): Promise<JSONRPCSerializedData> => ({
207
158
  method,
208
159
  serialized: JSON.stringify({
209
- serializableContractInstance: new SerializableContractInstance(value.instance).toBuffer(),
210
- address: value.instance.address.toString(),
211
- artifact: value.artifact ? ContractArtifactSchema.parse(value.artifact) : undefined,
160
+ instance: jsonStringify(value.instance),
161
+ artifact: value.artifact ? jsonStringify(value.artifact) : undefined,
212
162
  }),
213
163
  }),
214
- deserialize: (
164
+ deserialize: async (
215
165
  _method: string,
216
166
  data: JSONRPCSerializedData,
217
- ): AztecWalletMethodMap['aztec_registerContract']['params'] => {
218
- const { serializableContractInstance, address, artifact } = JSON.parse(data.serialized);
167
+ ): Promise<AztecWalletMethodMap['aztec_registerContract']['params']> => {
168
+ const { instance, artifact } = JSON.parse(data.serialized);
219
169
  return {
220
- instance: SerializableContractInstance.fromBuffer(
221
- Buffer.from(serializableContractInstance),
222
- ).withAddress(AztecAddress.fromString(address)),
223
- artifact: artifact ? ContractArtifactSchema.parse(artifact) : undefined,
170
+ instance: await jsonParseWithSchema(instance, ContractInstanceWithAddressSchema),
171
+ artifact: artifact ? await jsonParseWithSchema(artifact, ContractArtifactSchema) : undefined,
224
172
  };
225
173
  },
226
174
  };
227
-
228
- result = {
229
- /**
230
- * Serializes the contract registration result.
231
- * @param method - The RPC method name
232
- * @param value - Boolean indicating success of registration
233
- * @returns Serialized result
234
- */
235
- serialize: (
236
- method: string,
237
- value: AztecWalletMethodMap['aztec_registerContract']['result'],
238
- ): JSONRPCSerializedData => ({
239
- method,
240
- serialized: JSON.stringify(value),
241
- }),
242
- deserialize: (
243
- _method: string,
244
- data: JSONRPCSerializedData,
245
- ): AztecWalletMethodMap['aztec_registerContract']['result'] => JSON.parse(data.serialized),
246
- };
247
175
  }
248
176
 
249
177
  /**
250
178
  * Pre-instantiated serializer instances for Aztec contract-related RPC methods.
251
179
  * These instances can be used directly by the RPC handler implementation.
252
180
  */
253
- export const aztecGetContractInstanceSerializer = new AztecGetContractInstanceSerializer();
254
- export const aztecGetContractClassSerializer = new AztecGetContractClassSerializer();
255
- export const aztecGetContractArtifactSerializer = new AztecGetContractArtifactSerializer();
256
181
  export const aztecRegisterContractSerializer = new AztecRegisterContractSerializer();
182
+ export const aztecGetContractClassMetadataSerializer = new AztecGetContractClassMetadataSerializer();
183
+ export const aztecGetContractMetadataSerializer = new AztecGetContractMetadataSerializer();
@@ -1,7 +1,7 @@
1
- import { describe, expect, it, beforeEach, vi } from 'vitest';
1
+ import { describe, expect, it, beforeEach } from 'vitest';
2
2
  import { AztecWalletSerializer } from './index.js';
3
3
  import { AztecAddress, Tx } from '@aztec/aztec.js';
4
- import type { JSONRPCSerializer } from './types.js';
4
+ import type { JSONRPCSerializer } from '@walletmesh/jsonrpc';
5
5
  import type { AztecWalletMethodMap } from '../types.js';
6
6
 
7
7
  describe('AztecWalletSerializer', () => {
@@ -17,36 +17,36 @@ describe('AztecWalletSerializer', () => {
17
17
  describe('params', () => {
18
18
  it('should serialize params for known methods', async () => {
19
19
  const params = { scopes: [await AztecAddress.random()] };
20
- const result = AztecWalletSerializer.params.serialize(knownMethod, params);
20
+ const result = await AztecWalletSerializer.params.serialize(knownMethod, params);
21
21
  expect(result).toBeDefined();
22
22
  expect(result.method).toBe(knownMethod);
23
23
  expect(typeof result.serialized).toBe('string');
24
24
  });
25
25
 
26
- it('should wrap unknown method params in JSONRPCSerializedData format', () => {
26
+ it('should wrap unknown method params in JSONRPCSerializedData format', async () => {
27
27
  const params = { someParam: 'value' };
28
- const result = AztecWalletSerializer.params.serialize(unknownMethod, params);
28
+ const result = await AztecWalletSerializer.params.serialize(unknownMethod, params);
29
29
  expect(result).toBeDefined();
30
30
  expect(result.method).toBe(unknownMethod);
31
31
  expect(typeof result.serialized).toBe('string');
32
32
  });
33
33
 
34
- it('should pass through serialized data for unknown methods', () => {
34
+ it('should pass through serialized data for unknown methods', async () => {
35
35
  const serializedData = { serialized: 'base64data', method: unknownMethod };
36
- const result = AztecWalletSerializer.params.deserialize(unknownMethod, serializedData);
36
+ const result = await AztecWalletSerializer.params.deserialize(unknownMethod, serializedData);
37
37
  expect(result).toEqual(serializedData);
38
38
  });
39
39
 
40
- it('should throw error when params serializer fails', () => {
40
+ it('should throw error when params serializer fails', async () => {
41
41
  const params = { scopes: undefined }; // Invalid - scopes must be an array
42
- expect(() => AztecWalletSerializer.params.serialize(knownMethod, params)).toThrow(
42
+ await expect(AztecWalletSerializer.params.serialize(knownMethod, params)).rejects.toThrow(
43
43
  /Failed to serialize params/,
44
44
  );
45
45
  });
46
46
 
47
- it('should throw error when params deserializer fails', () => {
47
+ it('should throw error when params deserializer fails', async () => {
48
48
  const serializedData = { serialized: 'invalid-data', method: knownMethod };
49
- expect(() => AztecWalletSerializer.params.deserialize(knownMethod, serializedData)).toThrow(
49
+ await expect(AztecWalletSerializer.params.deserialize(knownMethod, serializedData)).rejects.toThrow(
50
50
  /Failed to deserialize params/,
51
51
  );
52
52
  });
@@ -58,40 +58,42 @@ describe('AztecWalletSerializer', () => {
58
58
  expect(resultSerializer).toBeDefined();
59
59
  });
60
60
 
61
- it('should serialize result for known methods', () => {
61
+ it('should serialize result for known methods', async () => {
62
62
  const value = true;
63
- const result = resultSerializer.serialize(knownMethod, value);
63
+ const result = await resultSerializer.serialize(knownMethod, value);
64
64
  expect(result).toBeDefined();
65
65
  expect(result.method).toBe(knownMethod);
66
66
  expect(typeof result.serialized).toBe('string');
67
67
  });
68
68
 
69
- it('should wrap unknown method result in JSONRPCSerializedData format', () => {
69
+ it('should wrap unknown method result in JSONRPCSerializedData format', async () => {
70
70
  const testResult = { someResult: 'value' };
71
- const result = resultSerializer.serialize(unknownMethod, testResult);
71
+ const result = await resultSerializer.serialize(unknownMethod, testResult);
72
72
  expect(result).toBeDefined();
73
73
  expect(result.method).toBe(unknownMethod);
74
74
  expect(typeof result.serialized).toBe('string');
75
75
  });
76
76
 
77
- it('should pass through serialized data for unknown methods', () => {
77
+ it('should pass through serialized data for unknown methods', async () => {
78
78
  const serializedData = { serialized: 'base64data', method: unknownMethod };
79
- const result = resultSerializer.deserialize(unknownMethod, serializedData);
79
+ const result = await resultSerializer.deserialize(unknownMethod, serializedData);
80
80
  expect(result).toEqual(serializedData);
81
81
  });
82
82
 
83
- it('should throw error when result serializer fails', () => {
83
+ it('should throw error when result serializer fails', async () => {
84
84
  interface CircularRef {
85
85
  ref: CircularRef | null;
86
86
  }
87
87
  const circular: CircularRef = { ref: null };
88
88
  circular.ref = circular; // Create circular reference which can't be JSON stringified
89
- expect(() => resultSerializer.serialize(knownMethod, circular)).toThrow(/Failed to serialize result/);
89
+ await expect(resultSerializer.serialize(knownMethod, circular)).rejects.toThrow(
90
+ /Failed to serialize result/,
91
+ );
90
92
  });
91
93
 
92
- it('should throw error when result deserializer fails', () => {
94
+ it('should throw error when result deserializer fails', async () => {
93
95
  const serializedData = { serialized: 'invalid-data', method: knownMethod };
94
- expect(() => resultSerializer.deserialize(knownMethod, serializedData)).toThrow(
96
+ await expect(resultSerializer.deserialize(knownMethod, serializedData)).rejects.toThrow(
95
97
  /Failed to deserialize result/,
96
98
  );
97
99
  });
@@ -99,18 +101,18 @@ describe('AztecWalletSerializer', () => {
99
101
 
100
102
  describe('integration', () => {
101
103
  it('should handle contract methods', async () => {
102
- const method = 'aztec_getContractInstance';
104
+ const method = 'aztec_getContractMetadata';
103
105
  const params = { address: await AztecAddress.random() };
104
106
 
105
- const serializedParams = AztecWalletSerializer.params.serialize(method, params);
107
+ const serializedParams = await AztecWalletSerializer.params.serialize(method, params);
106
108
  expect(serializedParams).toBeDefined();
107
109
  expect(serializedParams.method).toBe(method);
108
110
  expect(typeof serializedParams.serialized).toBe('string');
109
111
 
110
- const deserializedParams = AztecWalletSerializer.params.deserialize(
112
+ const deserializedParams = (await AztecWalletSerializer.params.deserialize(
111
113
  method,
112
114
  serializedParams,
113
- ) as AztecWalletMethodMap['aztec_getContractInstance']['params'];
115
+ )) as AztecWalletMethodMap['aztec_getContractMetadata']['params'];
114
116
  expect(deserializedParams.address.toString()).toBe(params.address.toString());
115
117
  });
116
118
 
@@ -119,15 +121,15 @@ describe('AztecWalletSerializer', () => {
119
121
  const tx = await Tx.random();
120
122
  const params = { tx };
121
123
 
122
- const serializedParams = AztecWalletSerializer.params.serialize(method, params);
124
+ const serializedParams = await AztecWalletSerializer.params.serialize(method, params);
123
125
  expect(serializedParams).toBeDefined();
124
126
  expect(serializedParams.method).toBe(method);
125
127
  expect(typeof serializedParams.serialized).toBe('string');
126
128
 
127
- const deserializedParams = AztecWalletSerializer.params.deserialize(
129
+ const deserializedParams = (await AztecWalletSerializer.params.deserialize(
128
130
  method,
129
131
  serializedParams,
130
- ) as AztecWalletMethodMap['aztec_sendTx']['params'];
132
+ )) as AztecWalletMethodMap['aztec_sendTx']['params'];
131
133
  expect(deserializedParams.tx.toBuffer().toString('hex')).toBe(tx.toBuffer().toString('hex'));
132
134
  });
133
135
  });