@walletmesh/aztec-rpc-wallet 0.1.1 → 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 (87) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +4 -4
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/aztecRemoteWallet.d.ts +4 -8
  5. package/dist/aztecRemoteWallet.d.ts.map +1 -1
  6. package/dist/aztecRemoteWallet.js +5 -30
  7. package/dist/chainProvider.d.ts.map +1 -1
  8. package/dist/chainProvider.js +1 -1
  9. package/dist/contractArtifactCache.d.ts.map +1 -1
  10. package/dist/contractArtifactCache.js +20 -9
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +1 -1
  13. package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
  14. package/dist/handlers/aztecAccountWallet.js +12 -45
  15. package/dist/handlers/transactions.d.ts.map +1 -1
  16. package/dist/handlers/transactions.js +11 -3
  17. package/dist/serializers/account.d.ts +24 -24
  18. package/dist/serializers/account.d.ts.map +1 -1
  19. package/dist/serializers/account.js +51 -51
  20. package/dist/serializers/contract.d.ts +22 -76
  21. package/dist/serializers/contract.d.ts.map +1 -1
  22. package/dist/serializers/contract.js +68 -120
  23. package/dist/serializers/index.d.ts +0 -4
  24. package/dist/serializers/index.d.ts.map +1 -1
  25. package/dist/serializers/index.js +15 -20
  26. package/dist/serializers/log.d.ts +16 -16
  27. package/dist/serializers/log.d.ts.map +1 -1
  28. package/dist/serializers/log.js +66 -64
  29. package/dist/serializers/note.d.ts +18 -18
  30. package/dist/serializers/note.d.ts.map +1 -1
  31. package/dist/serializers/note.js +54 -51
  32. package/dist/serializers/transaction.d.ts +25 -26
  33. package/dist/serializers/transaction.d.ts.map +1 -1
  34. package/dist/serializers/transaction.js +92 -44
  35. package/dist/types.d.ts +8 -31
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/types.js +1 -1
  38. package/docs/README.md +264 -0
  39. package/docs/classes/AztecChainProvider.md +553 -0
  40. package/docs/classes/AztecChainWallet.md +409 -0
  41. package/docs/classes/AztecProvider.md +1112 -0
  42. package/docs/classes/AztecWalletError.md +213 -0
  43. package/docs/classes/ContractArtifactCache.md +81 -0
  44. package/docs/globals.md +34 -0
  45. package/docs/interfaces/AztecWalletBaseMethodMap.md +135 -0
  46. package/docs/interfaces/AztecWalletEventMap.md +17 -0
  47. package/docs/interfaces/AztecWalletMethodMap.md +1012 -0
  48. package/docs/type-aliases/AztecChainId.md +11 -0
  49. package/docs/type-aliases/AztecChainWalletMiddleware.md +13 -0
  50. package/docs/type-aliases/AztecWalletContext.md +29 -0
  51. package/docs/type-aliases/AztecWalletMethodHandler.md +37 -0
  52. package/docs/type-aliases/AztecWalletMiddleware.md +13 -0
  53. package/docs/type-aliases/AztecWalletRouterClient.md +13 -0
  54. package/docs/type-aliases/TransactionFunctionCall.md +33 -0
  55. package/docs/type-aliases/TransactionParams.md +27 -0
  56. package/docs/variables/AztecWalletErrorMap.md +13 -0
  57. package/package.json +11 -11
  58. package/src/aztecRemoteWallet.test.ts +23 -65
  59. package/src/aztecRemoteWallet.ts +8 -36
  60. package/src/chainProvider.test.ts +117 -38
  61. package/src/chainProvider.ts +1 -7
  62. package/src/contractArtifactCache.test.ts +28 -45
  63. package/src/contractArtifactCache.ts +20 -10
  64. package/src/errors.ts +0 -1
  65. package/src/handlers/aztecAccountWallet.test.ts +12 -86
  66. package/src/handlers/aztecAccountWallet.ts +20 -78
  67. package/src/handlers/transactions.ts +16 -2
  68. package/src/provider.test.ts +0 -2
  69. package/src/serializers/account.test.ts +19 -20
  70. package/src/serializers/account.ts +65 -65
  71. package/src/serializers/contract.test.ts +4 -140
  72. package/src/serializers/contract.ts +98 -176
  73. package/src/serializers/index.test.ts +30 -28
  74. package/src/serializers/index.ts +15 -33
  75. package/src/serializers/log.test.ts +42 -48
  76. package/src/serializers/log.ts +85 -83
  77. package/src/serializers/note.test.ts +43 -16
  78. package/src/serializers/note.ts +62 -63
  79. package/src/serializers/transaction.test.ts +48 -41
  80. package/src/serializers/transaction.ts +154 -66
  81. package/src/types.ts +8 -8
  82. package/src/wallet.test.ts +3 -3
  83. package/tsconfig.json +1 -1
  84. package/dist/serializers/transaction-utils.d.ts +0 -51
  85. package/dist/serializers/transaction-utils.d.ts.map +0 -1
  86. package/dist/serializers/transaction-utils.js +0 -94
  87. package/src/serializers/transaction-utils.ts +0 -161
@@ -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,189 +1,135 @@
1
1
  import type { AztecWalletMethodMap } from '../types.js';
2
2
  import type { JSONRPCSerializedData, JSONRPCSerializer } from '@walletmesh/jsonrpc';
3
- import {
4
- SerializableContractInstance,
5
- ContractClassSchema,
6
- ContractClassWithIdSchema,
7
- ContractInstanceWithAddressSchema,
8
- } from '@aztec/circuits.js';
3
+ import { ContractClassWithIdSchema, ContractInstanceWithAddressSchema } from '@aztec/circuits.js';
9
4
  import { ContractArtifactSchema } from '@aztec/foundation/abi';
10
5
  import { AztecAddress, Fr } from '@aztec/aztec.js';
11
- import type { ContractInstanceWithAddress } from '@aztec/aztec.js';
12
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';
13
10
 
14
- /**
15
- * Serializer for the aztec_getContractInstance RPC method.
16
- * Handles serialization of contract instance queries and results between JSON-RPC format and native Aztec types.
17
- */
18
- export class AztecGetContractInstanceSerializer
19
- implements
20
- JSONRPCSerializer<
21
- AztecWalletMethodMap['aztec_getContractInstance']['params'],
22
- AztecWalletMethodMap['aztec_getContractInstance']['result']
23
- >
24
- {
25
- params = {
26
- /**
27
- * Serializes contract instance query parameters for RPC transport.
28
- * @param method - The RPC method name
29
- * @param value - The parameters containing the contract address to look up
30
- * @returns Serialized address data
31
- */
32
- serialize: (
33
- method: string,
34
- value: AztecWalletMethodMap['aztec_getContractInstance']['params'],
35
- ): JSONRPCSerializedData => ({
36
- method,
37
- serialized: jsonStringify(value.address),
38
- }),
39
- deserialize: (
40
- method: string,
41
- data: JSONRPCSerializedData,
42
- ): AztecWalletMethodMap['aztec_getContractInstance']['params'] => {
43
- return {
44
- address: jsonParseWithSchema(data.serialized, AztecAddress.schema),
45
- };
46
- },
47
- };
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>;
48
18
 
49
- result = {
50
- /**
51
- * Serializes the contract instance query result.
52
- * @param method - The RPC method name
53
- * @param value - The contract instance data including address and state
54
- * @returns Serialized contract instance data
55
- */
56
- serialize: (method: string, value: ContractInstanceWithAddress): JSONRPCSerializedData => ({
57
- method,
58
- serialized: JSON.stringify({
59
- serializableContractInstance: new SerializableContractInstance(value).toBuffer(),
60
- address: jsonStringify(value.address),
61
- }),
62
- }),
63
- deserialize: (method: string, data: JSONRPCSerializedData): ContractInstanceWithAddress => {
64
- const parsed = JSON.parse(data.serialized);
65
- return SerializableContractInstance.fromBuffer(
66
- Buffer.from(parsed.serializableContractInstance),
67
- ).withAddress(jsonParseWithSchema(parsed.address, AztecAddress.schema));
68
- },
69
- };
70
- }
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>;
71
24
 
72
25
  /**
73
- * Serializer for the aztec_getContractClass RPC method.
74
- * 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.
75
28
  */
76
- export class AztecGetContractClassSerializer
29
+ export class AztecGetContractClassMetadataSerializer
77
30
  implements
78
31
  JSONRPCSerializer<
79
- AztecWalletMethodMap['aztec_getContractClass']['params'],
80
- AztecWalletMethodMap['aztec_getContractClass']['result']
32
+ AztecWalletMethodMap['aztec_getContractClassMetadata']['params'],
33
+ AztecWalletMethodMap['aztec_getContractClassMetadata']['result']
81
34
  >
82
35
  {
83
36
  params = {
84
37
  /**
85
- * Serializes contract class query parameters for RPC transport.
38
+ * Serializes contract class metadata query parameters for RPC transport.
86
39
  * @param method - The RPC method name
87
- * @param value - The parameters containing the class ID to look up
88
- * @returns Serialized class ID data
40
+ * @param value - The parameters containing the class ID and artifact inclusion flag
41
+ * @returns Serialized query parameters
89
42
  */
90
- serialize: (
43
+ serialize: async (
91
44
  method: string,
92
- value: AztecWalletMethodMap['aztec_getContractClass']['params'],
93
- ): JSONRPCSerializedData => ({
94
- method,
95
- serialized: JSON.stringify({
96
- 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
+ }),
97
53
  }),
98
- }),
99
- deserialize: (
100
- method: string,
54
+ deserialize: async (
55
+ _method: string,
101
56
  data: JSONRPCSerializedData,
102
- ): AztecWalletMethodMap['aztec_getContractClass']['params'] => {
103
- const { id } = JSON.parse(data.serialized);
104
- 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
+ };
105
63
  },
106
64
  };
107
-
108
65
  result = {
109
66
  /**
110
- * Serializes the contract class query result.
67
+ * Serializes the contract class metadata query result.
111
68
  * @param method - The RPC method name
112
- * @param value - The contract class definition with its ID
113
- * @returns Serialized contract class data
69
+ * @param value - The contract class metadata including class definition and registration status
70
+ * @returns Serialized contract class metadata
114
71
  */
115
- serialize: (
116
- method: string,
117
- value: AztecWalletMethodMap['aztec_getContractClass']['result'],
118
- ): JSONRPCSerializedData => ({
119
- method,
120
- serialized: JSON.stringify(value),
121
- }),
122
- deserialize: (
72
+ serialize: async (
123
73
  method: string,
74
+ value: AztecWalletMethodMap['aztec_getContractClassMetadata']['result'],
75
+ ): Promise<JSONRPCSerializedData> => {
76
+ return {
77
+ method,
78
+ serialized: jsonStringify(value),
79
+ };
80
+ },
81
+ deserialize: async (
82
+ _method: string,
124
83
  data: JSONRPCSerializedData,
125
- ): AztecWalletMethodMap['aztec_getContractClass']['result'] => {
126
- const parsed = JSON.parse(data.serialized);
127
- return ContractClassWithIdSchema.parse(parsed);
84
+ ): Promise<AztecWalletMethodMap['aztec_getContractClassMetadata']['result']> => {
85
+ return await jsonParseWithSchema(data.serialized, ContractClassMetadataSchema);
128
86
  },
129
87
  };
130
88
  }
131
89
 
132
- /**
133
- * Serializer for the aztec_getContractArtifact RPC method.
134
- * Handles serialization of contract artifact queries and results between JSON-RPC format and native Aztec types.
135
- */
136
- export class AztecGetContractArtifactSerializer
90
+ export class AztecGetContractMetadataSerializer
137
91
  implements
138
92
  JSONRPCSerializer<
139
- AztecWalletMethodMap['aztec_getContractArtifact']['params'],
140
- AztecWalletMethodMap['aztec_getContractArtifact']['result']
93
+ AztecWalletMethodMap['aztec_getContractMetadata']['params'],
94
+ AztecWalletMethodMap['aztec_getContractMetadata']['result']
141
95
  >
142
96
  {
143
97
  params = {
144
- /**
145
- * Serializes contract artifact query parameters for RPC transport.
146
- * @param method - The RPC method name
147
- * @param value - The parameters containing the artifact ID to look up
148
- * @returns Serialized artifact ID data
149
- */
150
- serialize: (
151
- method: string,
152
- value: AztecWalletMethodMap['aztec_getContractArtifact']['params'],
153
- ): JSONRPCSerializedData => ({
154
- method,
155
- serialized: JSON.stringify({
156
- id: value.id.toString(),
157
- }),
158
- }),
159
- deserialize: (
98
+ serialize: async (
160
99
  method: string,
100
+ value: AztecWalletMethodMap['aztec_getContractMetadata']['params'],
101
+ ): Promise<JSONRPCSerializedData> => {
102
+ return {
103
+ method,
104
+ serialized: jsonStringify(value.address),
105
+ };
106
+ },
107
+ deserialize: async (
108
+ _method: string,
161
109
  data: JSONRPCSerializedData,
162
- ): AztecWalletMethodMap['aztec_getContractArtifact']['params'] => {
163
- const { id } = JSON.parse(data.serialized);
164
- return { id: Fr.fromString(id) };
110
+ ): Promise<AztecWalletMethodMap['aztec_getContractMetadata']['params']> => {
111
+ return {
112
+ address: await jsonParseWithSchema(data.serialized, AztecAddress.schema),
113
+ };
165
114
  },
166
115
  };
167
116
 
168
117
  result = {
169
- /**
170
- * Serializes the contract artifact query result.
171
- * @param method - The RPC method name
172
- * @param value - The contract artifact data
173
- * @returns Serialized contract artifact
174
- */
175
- serialize: (
176
- method: string,
177
- value: AztecWalletMethodMap['aztec_getContractArtifact']['result'],
178
- ): JSONRPCSerializedData => ({
179
- method,
180
- serialized: JSON.stringify(ContractArtifactSchema.parse(value)),
181
- }),
182
- deserialize: (
118
+ serialize: async (
183
119
  method: string,
120
+ contractMetadata: AztecWalletMethodMap['aztec_getContractMetadata']['result'],
121
+ ): Promise<JSONRPCSerializedData> => {
122
+ return {
123
+ method,
124
+ serialized: jsonStringify(contractMetadata),
125
+ };
126
+ },
127
+ deserialize: async (
128
+ _method: string,
184
129
  data: JSONRPCSerializedData,
185
- ): AztecWalletMethodMap['aztec_getContractArtifact']['result'] =>
186
- ContractArtifactSchema.parse(JSON.parse(data.serialized)),
130
+ ): Promise<AztecWalletMethodMap['aztec_getContractMetadata']['result']> => {
131
+ return await jsonParseWithSchema(data.serialized, ContractMetadataSchema);
132
+ },
187
133
  };
188
134
  }
189
135
 
@@ -205,57 +151,33 @@ export class AztecRegisterContractSerializer
205
151
  * @param value - The parameters containing contract instance and optional artifact
206
152
  * @returns Serialized registration data
207
153
  */
208
- serialize: (
154
+ serialize: async (
209
155
  method: string,
210
156
  value: AztecWalletMethodMap['aztec_registerContract']['params'],
211
- ): JSONRPCSerializedData => ({
157
+ ): Promise<JSONRPCSerializedData> => ({
212
158
  method,
213
159
  serialized: JSON.stringify({
214
- serializableContractInstance: new SerializableContractInstance(value.instance).toBuffer(),
215
- address: value.instance.address.toString(),
216
- artifact: value.artifact ? ContractArtifactSchema.parse(value.artifact) : undefined,
160
+ instance: jsonStringify(value.instance),
161
+ artifact: value.artifact ? jsonStringify(value.artifact) : undefined,
217
162
  }),
218
163
  }),
219
- deserialize: (
220
- method: string,
164
+ deserialize: async (
165
+ _method: string,
221
166
  data: JSONRPCSerializedData,
222
- ): AztecWalletMethodMap['aztec_registerContract']['params'] => {
223
- const { serializableContractInstance, address, artifact } = JSON.parse(data.serialized);
167
+ ): Promise<AztecWalletMethodMap['aztec_registerContract']['params']> => {
168
+ const { instance, artifact } = JSON.parse(data.serialized);
224
169
  return {
225
- instance: SerializableContractInstance.fromBuffer(
226
- Buffer.from(serializableContractInstance),
227
- ).withAddress(AztecAddress.fromString(address)),
228
- artifact: artifact ? ContractArtifactSchema.parse(artifact) : undefined,
170
+ instance: await jsonParseWithSchema(instance, ContractInstanceWithAddressSchema),
171
+ artifact: artifact ? await jsonParseWithSchema(artifact, ContractArtifactSchema) : undefined,
229
172
  };
230
173
  },
231
174
  };
232
-
233
- result = {
234
- /**
235
- * Serializes the contract registration result.
236
- * @param method - The RPC method name
237
- * @param value - Boolean indicating success of registration
238
- * @returns Serialized result
239
- */
240
- serialize: (
241
- method: string,
242
- value: AztecWalletMethodMap['aztec_registerContract']['result'],
243
- ): JSONRPCSerializedData => ({
244
- method,
245
- serialized: JSON.stringify(value),
246
- }),
247
- deserialize: (
248
- method: string,
249
- data: JSONRPCSerializedData,
250
- ): AztecWalletMethodMap['aztec_registerContract']['result'] => JSON.parse(data.serialized),
251
- };
252
175
  }
253
176
 
254
177
  /**
255
178
  * Pre-instantiated serializer instances for Aztec contract-related RPC methods.
256
179
  * These instances can be used directly by the RPC handler implementation.
257
180
  */
258
- export const aztecGetContractInstanceSerializer = new AztecGetContractInstanceSerializer();
259
- export const aztecGetContractClassSerializer = new AztecGetContractClassSerializer();
260
- export const aztecGetContractArtifactSerializer = new AztecGetContractArtifactSerializer();
261
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
  });