@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.
- package/CHANGELOG.md +12 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/aztecRemoteWallet.d.ts +4 -8
- package/dist/aztecRemoteWallet.d.ts.map +1 -1
- package/dist/aztecRemoteWallet.js +5 -29
- package/dist/contractArtifactCache.d.ts.map +1 -1
- package/dist/contractArtifactCache.js +20 -9
- package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
- package/dist/handlers/aztecAccountWallet.js +11 -44
- package/dist/serializers/account.d.ts +16 -16
- package/dist/serializers/account.d.ts.map +1 -1
- package/dist/serializers/account.js +43 -43
- package/dist/serializers/contract.d.ts +22 -76
- package/dist/serializers/contract.d.ts.map +1 -1
- package/dist/serializers/contract.js +68 -120
- package/dist/serializers/index.d.ts +0 -4
- package/dist/serializers/index.d.ts.map +1 -1
- package/dist/serializers/index.js +15 -20
- package/dist/serializers/log.d.ts +16 -16
- package/dist/serializers/log.d.ts.map +1 -1
- package/dist/serializers/log.js +43 -43
- package/dist/serializers/note.d.ts +12 -12
- package/dist/serializers/note.d.ts.map +1 -1
- package/dist/serializers/note.js +32 -32
- package/dist/serializers/transaction.d.ts +25 -26
- package/dist/serializers/transaction.d.ts.map +1 -1
- package/dist/serializers/transaction.js +92 -44
- package/dist/types.d.ts +7 -30
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/docs/README.md +264 -0
- package/docs/classes/AztecChainProvider.md +553 -0
- package/docs/classes/AztecChainWallet.md +409 -0
- package/docs/classes/AztecProvider.md +1112 -0
- package/docs/classes/AztecWalletError.md +213 -0
- package/docs/classes/ContractArtifactCache.md +81 -0
- package/docs/globals.md +34 -0
- package/docs/interfaces/AztecWalletBaseMethodMap.md +135 -0
- package/docs/interfaces/AztecWalletEventMap.md +17 -0
- package/docs/interfaces/AztecWalletMethodMap.md +1012 -0
- package/docs/type-aliases/AztecChainId.md +11 -0
- package/docs/type-aliases/AztecChainWalletMiddleware.md +13 -0
- package/docs/type-aliases/AztecWalletContext.md +29 -0
- package/docs/type-aliases/AztecWalletMethodHandler.md +37 -0
- package/docs/type-aliases/AztecWalletMiddleware.md +13 -0
- package/docs/type-aliases/AztecWalletRouterClient.md +13 -0
- package/docs/type-aliases/TransactionFunctionCall.md +33 -0
- package/docs/type-aliases/TransactionParams.md +27 -0
- package/docs/variables/AztecWalletErrorMap.md +13 -0
- package/package.json +9 -9
- package/src/aztecRemoteWallet.test.ts +22 -61
- package/src/aztecRemoteWallet.ts +8 -35
- package/src/chainProvider.test.ts +117 -38
- package/src/contractArtifactCache.test.ts +28 -45
- package/src/contractArtifactCache.ts +20 -10
- package/src/handlers/aztecAccountWallet.test.ts +12 -86
- package/src/handlers/aztecAccountWallet.ts +19 -77
- package/src/provider.test.ts +0 -2
- package/src/serializers/account.test.ts +19 -20
- package/src/serializers/account.ts +52 -52
- package/src/serializers/contract.test.ts +4 -140
- package/src/serializers/contract.ts +93 -166
- package/src/serializers/index.test.ts +30 -28
- package/src/serializers/index.ts +15 -21
- package/src/serializers/log.test.ts +42 -48
- package/src/serializers/log.ts +54 -54
- package/src/serializers/note.test.ts +43 -16
- package/src/serializers/note.ts +39 -39
- package/src/serializers/transaction.test.ts +48 -41
- package/src/serializers/transaction.ts +146 -58
- package/src/types.ts +7 -7
- package/src/wallet.test.ts +3 -3
- package/dist/serializers/transaction-utils.d.ts +0 -51
- package/dist/serializers/transaction-utils.d.ts.map +0 -1
- package/dist/serializers/transaction-utils.js +0 -103
- package/src/serializers/transaction-utils.ts +0 -174
package/src/serializers/index.ts
CHANGED
@@ -19,9 +19,8 @@ import {
|
|
19
19
|
aztecGetAuthWitnessSerializer,
|
20
20
|
} from './account.js';
|
21
21
|
import {
|
22
|
-
|
23
|
-
|
24
|
-
aztecGetContractArtifactSerializer,
|
22
|
+
aztecGetContractMetadataSerializer,
|
23
|
+
aztecGetContractClassMetadataSerializer,
|
25
24
|
aztecRegisterContractSerializer,
|
26
25
|
} from './contract.js';
|
27
26
|
import {
|
@@ -60,9 +59,8 @@ const methodSerializers: Record<AztecMethodName, JSONRPCSerializer<unknown, unkn
|
|
60
59
|
aztec_getAuthWitness: aztecGetAuthWitnessSerializer,
|
61
60
|
|
62
61
|
// Contract methods
|
63
|
-
|
64
|
-
|
65
|
-
aztec_getContractArtifact: aztecGetContractArtifactSerializer,
|
62
|
+
aztec_getContractMetadata: aztecGetContractMetadataSerializer,
|
63
|
+
aztec_getContractClassMetadata: aztecGetContractClassMetadataSerializer,
|
66
64
|
aztec_registerContract: aztecRegisterContractSerializer,
|
67
65
|
|
68
66
|
// Transaction methods
|
@@ -93,11 +91,11 @@ const methodSerializers: Record<AztecMethodName, JSONRPCSerializer<unknown, unkn
|
|
93
91
|
* @param value - The value to wrap
|
94
92
|
* @returns Standardized JSON-RPC data structure
|
95
93
|
*/
|
96
|
-
function wrapUnknownValue(method: string, value: unknown): JSONRPCSerializedData {
|
97
|
-
return {
|
94
|
+
async function wrapUnknownValue(method: string, value: unknown): Promise<JSONRPCSerializedData> {
|
95
|
+
return Promise.resolve({
|
98
96
|
method,
|
99
97
|
serialized: JSON.stringify(value),
|
100
|
-
};
|
98
|
+
});
|
101
99
|
}
|
102
100
|
|
103
101
|
/**
|
@@ -108,10 +106,6 @@ function wrapUnknownValue(method: string, value: unknown): JSONRPCSerializedData
|
|
108
106
|
* 1. Routes each method call to its specialized serializer from methodSerializers
|
109
107
|
* 2. Provides fallback handling for unknown methods
|
110
108
|
* 3. Wraps all serialization operations in proper error handling
|
111
|
-
*
|
112
|
-
* The serializer handles both:
|
113
|
-
* - Parameters: Incoming RPC call parameters
|
114
|
-
* - Results: Outgoing RPC call results
|
115
109
|
*/
|
116
110
|
export const AztecWalletSerializer: JSONRPCSerializer<unknown, unknown> = {
|
117
111
|
params: {
|
@@ -122,14 +116,14 @@ export const AztecWalletSerializer: JSONRPCSerializer<unknown, unknown> = {
|
|
122
116
|
* @returns Serialized parameter data
|
123
117
|
* @throws If serialization fails or encounters an error
|
124
118
|
*/
|
125
|
-
serialize: (method: string, value: unknown): JSONRPCSerializedData => {
|
119
|
+
serialize: async (method: string, value: unknown): Promise<JSONRPCSerializedData> => {
|
126
120
|
const serializer = methodSerializers[method as AztecMethodName];
|
127
121
|
if (!serializer?.params) {
|
128
122
|
return wrapUnknownValue(method, value);
|
129
123
|
}
|
130
124
|
|
131
125
|
try {
|
132
|
-
return serializer.params.serialize(method, value);
|
126
|
+
return await serializer.params.serialize(method, value);
|
133
127
|
} catch (error) {
|
134
128
|
throw new Error(`Failed to serialize params for method ${method}: ${error}`);
|
135
129
|
}
|
@@ -141,14 +135,14 @@ export const AztecWalletSerializer: JSONRPCSerializer<unknown, unknown> = {
|
|
141
135
|
* @returns Deserialized parameters
|
142
136
|
* @throws If deserialization fails or encounters an error
|
143
137
|
*/
|
144
|
-
deserialize: (method: string, data: JSONRPCSerializedData): unknown => {
|
138
|
+
deserialize: async (method: string, data: JSONRPCSerializedData): Promise<unknown> => {
|
145
139
|
const serializer = methodSerializers[method as AztecMethodName];
|
146
140
|
if (!serializer?.params) {
|
147
141
|
return data;
|
148
142
|
}
|
149
143
|
|
150
144
|
try {
|
151
|
-
return serializer.params.deserialize(method, data);
|
145
|
+
return await serializer.params.deserialize(method, data);
|
152
146
|
} catch (error) {
|
153
147
|
throw new Error(`Failed to deserialize params for method ${method}: ${error}`);
|
154
148
|
}
|
@@ -162,14 +156,14 @@ export const AztecWalletSerializer: JSONRPCSerializer<unknown, unknown> = {
|
|
162
156
|
* @returns Serialized result data
|
163
157
|
* @throws If serialization fails or encounters an error
|
164
158
|
*/
|
165
|
-
serialize: (method: string, value: unknown): JSONRPCSerializedData => {
|
159
|
+
serialize: async (method: string, value: unknown): Promise<JSONRPCSerializedData> => {
|
166
160
|
const serializer = methodSerializers[method as AztecMethodName];
|
167
161
|
if (!serializer?.result) {
|
168
162
|
return wrapUnknownValue(method, value);
|
169
163
|
}
|
170
164
|
|
171
165
|
try {
|
172
|
-
return serializer.result.serialize(method, value);
|
166
|
+
return await serializer.result.serialize(method, value);
|
173
167
|
} catch (error) {
|
174
168
|
throw new Error(`Failed to serialize result for method ${method}: ${error}`);
|
175
169
|
}
|
@@ -181,14 +175,14 @@ export const AztecWalletSerializer: JSONRPCSerializer<unknown, unknown> = {
|
|
181
175
|
* @returns Deserialized result
|
182
176
|
* @throws If deserialization fails or encounters an error
|
183
177
|
*/
|
184
|
-
deserialize: (method: string, data: JSONRPCSerializedData): unknown => {
|
178
|
+
deserialize: async (method: string, data: JSONRPCSerializedData): Promise<unknown> => {
|
185
179
|
const serializer = methodSerializers[method as AztecMethodName];
|
186
180
|
if (!serializer?.result) {
|
187
181
|
return data;
|
188
182
|
}
|
189
183
|
|
190
184
|
try {
|
191
|
-
return serializer.result.deserialize(method, data);
|
185
|
+
return await serializer.result.deserialize(method, data);
|
192
186
|
} catch (error) {
|
193
187
|
throw new Error(`Failed to deserialize result for method ${method}: ${error}`);
|
194
188
|
}
|
@@ -18,10 +18,6 @@ import {
|
|
18
18
|
} from './log.js';
|
19
19
|
|
20
20
|
describe('Log Serializers', () => {
|
21
|
-
const createRandomLog = async () => {
|
22
|
-
const log = await ExtendedPublicLog.random();
|
23
|
-
return log;
|
24
|
-
};
|
25
21
|
describe('aztec_getPublicLogs', () => {
|
26
22
|
const METHOD = 'aztec_getPublicLogs';
|
27
23
|
|
@@ -36,10 +32,10 @@ describe('Log Serializers', () => {
|
|
36
32
|
|
37
33
|
const params = { filter };
|
38
34
|
|
39
|
-
const serialized = aztecGetPublicLogsSerializer.params.serialize(METHOD, params);
|
35
|
+
const serialized = await aztecGetPublicLogsSerializer.params.serialize(METHOD, params);
|
40
36
|
expect(serialized.method).toBe(METHOD);
|
41
37
|
|
42
|
-
const deserialized = aztecGetPublicLogsSerializer.params.deserialize(METHOD, serialized);
|
38
|
+
const deserialized = await aztecGetPublicLogsSerializer.params.deserialize(METHOD, serialized);
|
43
39
|
expect(deserialized.filter.contractAddress?.toString()).toBe(filter.contractAddress?.toString());
|
44
40
|
expect(deserialized.filter.txHash?.toString()).toBe(filter.txHash?.toString());
|
45
41
|
expect(deserialized.filter.fromBlock).toBe(filter.fromBlock);
|
@@ -54,11 +50,13 @@ describe('Log Serializers', () => {
|
|
54
50
|
maxLogsHit: false,
|
55
51
|
};
|
56
52
|
|
57
|
-
const serialized = aztecGetPublicLogsSerializer.result.serialize(METHOD, result);
|
53
|
+
const serialized = await aztecGetPublicLogsSerializer.result.serialize(METHOD, result);
|
58
54
|
expect(serialized.method).toBe(METHOD);
|
59
55
|
|
60
|
-
const deserialized = aztecGetPublicLogsSerializer.result.deserialize(METHOD, serialized);
|
61
|
-
expect(deserialized.logs
|
56
|
+
const deserialized = await aztecGetPublicLogsSerializer.result.deserialize(METHOD, serialized);
|
57
|
+
expect(deserialized.logs.length).toBeGreaterThan(0);
|
58
|
+
// biome-ignore lint/style/noNonNullAssertion: We know this should be defined
|
59
|
+
expect(deserialized.logs[0]!.toString()).toBe(result.logs[0]!.toString());
|
62
60
|
expect(deserialized.logs.length).toBe(result.logs.length);
|
63
61
|
expect(deserialized.maxLogsHit).toBe(result.maxLogsHit);
|
64
62
|
});
|
@@ -82,10 +80,10 @@ describe('Log Serializers', () => {
|
|
82
80
|
vpks: [await Point.random(), await Point.random()],
|
83
81
|
};
|
84
82
|
|
85
|
-
const serialized = aztecGetPrivateEventsSerializer.params.serialize(METHOD, params);
|
83
|
+
const serialized = await aztecGetPrivateEventsSerializer.params.serialize(METHOD, params);
|
86
84
|
expect(serialized.method).toBe(METHOD);
|
87
85
|
|
88
|
-
const deserialized = aztecGetPrivateEventsSerializer.params.deserialize(METHOD, serialized);
|
86
|
+
const deserialized = await aztecGetPrivateEventsSerializer.params.deserialize(METHOD, serialized);
|
89
87
|
expect(deserialized.event.eventSelector.toString()).toBe(event.eventSelector.toString());
|
90
88
|
expect(deserialized.event.abiType).toEqual(event.abiType);
|
91
89
|
expect(deserialized.event.fieldNames).toEqual(event.fieldNames);
|
@@ -98,7 +96,7 @@ describe('Log Serializers', () => {
|
|
98
96
|
describe('aztec_getPublicEvents', () => {
|
99
97
|
const METHOD = 'aztec_getPublicEvents';
|
100
98
|
|
101
|
-
it('should serialize and deserialize params', () => {
|
99
|
+
it('should serialize and deserialize params', async () => {
|
102
100
|
const event = {
|
103
101
|
eventSelector: EventSelector.fromString('0x12345678'),
|
104
102
|
abiType: {
|
@@ -112,10 +110,10 @@ describe('Log Serializers', () => {
|
|
112
110
|
limit: 10,
|
113
111
|
};
|
114
112
|
|
115
|
-
const serialized = aztecGetPublicEventsSerializer.params.serialize(METHOD, params);
|
113
|
+
const serialized = await aztecGetPublicEventsSerializer.params.serialize(METHOD, params);
|
116
114
|
expect(serialized.method).toBe(METHOD);
|
117
115
|
|
118
|
-
const deserialized = aztecGetPublicEventsSerializer.params.deserialize(METHOD, serialized);
|
116
|
+
const deserialized = await aztecGetPublicEventsSerializer.params.deserialize(METHOD, serialized);
|
119
117
|
expect(deserialized.event.eventSelector.toString()).toBe(event.eventSelector.toString());
|
120
118
|
expect(deserialized.event.abiType).toEqual(event.abiType);
|
121
119
|
expect(deserialized.event.fieldNames).toEqual(event.fieldNames);
|
@@ -141,10 +139,10 @@ describe('Log Serializers', () => {
|
|
141
139
|
};
|
142
140
|
|
143
141
|
const params = { filter };
|
144
|
-
const serialized = aztecGetContractClassLogsSerializer.params.serialize(METHOD, params);
|
142
|
+
const serialized = await aztecGetContractClassLogsSerializer.params.serialize(METHOD, params);
|
145
143
|
expect(serialized.method).toBe(METHOD);
|
146
144
|
|
147
|
-
const deserialized = aztecGetContractClassLogsSerializer.params.deserialize(METHOD, serialized);
|
145
|
+
const deserialized = await aztecGetContractClassLogsSerializer.params.deserialize(METHOD, serialized);
|
148
146
|
expect(deserialized.filter.contractAddress?.toString()).toBe(filter.contractAddress?.toString());
|
149
147
|
expect(deserialized.filter.txHash?.toString()).toBe(filter.txHash?.toString());
|
150
148
|
expect(deserialized.filter.fromBlock).toBe(filter.fromBlock);
|
@@ -152,17 +150,17 @@ describe('Log Serializers', () => {
|
|
152
150
|
expect(deserialized.filter.afterLog?.toString()).toBe(filter.afterLog?.toString());
|
153
151
|
});
|
154
152
|
|
155
|
-
it('should serialize and deserialize params with minimal filter', () => {
|
153
|
+
it('should serialize and deserialize params with minimal filter', async () => {
|
156
154
|
const filter: LogFilter = {
|
157
155
|
fromBlock: 0,
|
158
156
|
toBlock: 100,
|
159
157
|
};
|
160
158
|
|
161
159
|
const params = { filter };
|
162
|
-
const serialized = aztecGetContractClassLogsSerializer.params.serialize(METHOD, params);
|
160
|
+
const serialized = await aztecGetContractClassLogsSerializer.params.serialize(METHOD, params);
|
163
161
|
expect(serialized.method).toBe(METHOD);
|
164
162
|
|
165
|
-
const deserialized = aztecGetContractClassLogsSerializer.params.deserialize(METHOD, serialized);
|
163
|
+
const deserialized = await aztecGetContractClassLogsSerializer.params.deserialize(METHOD, serialized);
|
166
164
|
expect(deserialized.filter.contractAddress).toBeUndefined();
|
167
165
|
expect(deserialized.filter.txHash).toBeUndefined();
|
168
166
|
expect(deserialized.filter.fromBlock).toBe(filter.fromBlock);
|
@@ -177,10 +175,10 @@ describe('Log Serializers', () => {
|
|
177
175
|
maxLogsHit: false,
|
178
176
|
};
|
179
177
|
|
180
|
-
const serialized = aztecGetContractClassLogsSerializer.result.serialize(METHOD, result);
|
178
|
+
const serialized = await aztecGetContractClassLogsSerializer.result.serialize(METHOD, result);
|
181
179
|
expect(serialized.method).toBe(METHOD);
|
182
180
|
|
183
|
-
const deserialized = aztecGetContractClassLogsSerializer.result.deserialize(METHOD, serialized);
|
181
|
+
const deserialized = await aztecGetContractClassLogsSerializer.result.deserialize(METHOD, serialized);
|
184
182
|
expect(deserialized.logs).toEqual([]);
|
185
183
|
expect(deserialized.maxLogsHit).toBe(result.maxLogsHit);
|
186
184
|
});
|
@@ -189,26 +187,26 @@ describe('Log Serializers', () => {
|
|
189
187
|
describe('aztec_getPrivateEvents result handling', () => {
|
190
188
|
const METHOD = 'aztec_getPrivateEvents';
|
191
189
|
|
192
|
-
it('should serialize and deserialize empty result array', () => {
|
190
|
+
it('should serialize and deserialize empty result array', async () => {
|
193
191
|
const result: unknown[] = [];
|
194
|
-
const serialized = aztecGetPrivateEventsSerializer.result.serialize(METHOD, result);
|
192
|
+
const serialized = await aztecGetPrivateEventsSerializer.result.serialize(METHOD, result);
|
195
193
|
expect(serialized.method).toBe(METHOD);
|
196
194
|
|
197
|
-
const deserialized = aztecGetPrivateEventsSerializer.result.deserialize(METHOD, serialized);
|
195
|
+
const deserialized = await aztecGetPrivateEventsSerializer.result.deserialize(METHOD, serialized);
|
198
196
|
expect(deserialized).toEqual([]);
|
199
197
|
});
|
200
198
|
|
201
|
-
it('should serialize and deserialize result with multiple events', () => {
|
199
|
+
it('should serialize and deserialize result with multiple events', async () => {
|
202
200
|
const result = [
|
203
201
|
{ id: 1, data: 'event1' },
|
204
202
|
{ id: 2, data: 'event2' },
|
205
203
|
{ id: 3, data: 'event3' },
|
206
204
|
];
|
207
205
|
|
208
|
-
const serialized = aztecGetPrivateEventsSerializer.result.serialize(METHOD, result);
|
206
|
+
const serialized = await aztecGetPrivateEventsSerializer.result.serialize(METHOD, result);
|
209
207
|
expect(serialized.method).toBe(METHOD);
|
210
208
|
|
211
|
-
const deserialized = aztecGetPrivateEventsSerializer.result.deserialize(METHOD, serialized);
|
209
|
+
const deserialized = await aztecGetPrivateEventsSerializer.result.deserialize(METHOD, serialized);
|
212
210
|
expect(deserialized).toEqual(result);
|
213
211
|
});
|
214
212
|
});
|
@@ -216,41 +214,39 @@ describe('Log Serializers', () => {
|
|
216
214
|
describe('aztec_getPublicEvents result handling', () => {
|
217
215
|
const METHOD = 'aztec_getPublicEvents';
|
218
216
|
|
219
|
-
it('should serialize and deserialize empty result array', () => {
|
217
|
+
it('should serialize and deserialize empty result array', async () => {
|
220
218
|
const result: unknown[] = [];
|
221
|
-
const serialized = aztecGetPublicEventsSerializer.result.serialize(METHOD, result);
|
219
|
+
const serialized = await aztecGetPublicEventsSerializer.result.serialize(METHOD, result);
|
222
220
|
expect(serialized.method).toBe(METHOD);
|
223
221
|
|
224
|
-
const deserialized = aztecGetPublicEventsSerializer.result.deserialize(METHOD, serialized);
|
222
|
+
const deserialized = await aztecGetPublicEventsSerializer.result.deserialize(METHOD, serialized);
|
225
223
|
expect(deserialized).toEqual([]);
|
226
224
|
});
|
227
225
|
|
228
|
-
it('should serialize and deserialize result with multiple events', () => {
|
226
|
+
it('should serialize and deserialize result with multiple events', async () => {
|
229
227
|
const result = [
|
230
228
|
{ id: 1, data: 'event1' },
|
231
229
|
{ id: 2, data: 'event2' },
|
232
230
|
{ id: 3, data: 'event3' },
|
233
231
|
];
|
234
232
|
|
235
|
-
const serialized = aztecGetPublicEventsSerializer.result.serialize(METHOD, result);
|
233
|
+
const serialized = await aztecGetPublicEventsSerializer.result.serialize(METHOD, result);
|
236
234
|
expect(serialized.method).toBe(METHOD);
|
237
235
|
|
238
|
-
const deserialized = aztecGetPublicEventsSerializer.result.deserialize(METHOD, serialized);
|
236
|
+
const deserialized = await aztecGetPublicEventsSerializer.result.deserialize(METHOD, serialized);
|
239
237
|
expect(deserialized).toEqual(result);
|
240
238
|
});
|
241
239
|
});
|
242
240
|
|
243
241
|
describe('Edge Cases', () => {
|
244
|
-
it('should handle invalid JSON in deserialization', () => {
|
242
|
+
it('should handle invalid JSON in deserialization', async () => {
|
245
243
|
const METHOD = 'aztec_getPublicLogs';
|
246
244
|
const invalidData = { method: METHOD, serialized: 'invalid json' };
|
247
245
|
|
248
|
-
expect(()
|
249
|
-
aztecGetPublicLogsSerializer.params.deserialize(METHOD, invalidData);
|
250
|
-
}).toThrow();
|
246
|
+
await expect(aztecGetPublicLogsSerializer.params.deserialize(METHOD, invalidData)).rejects.toThrow();
|
251
247
|
});
|
252
248
|
|
253
|
-
it('should handle malformed event selector', () => {
|
249
|
+
it('should handle malformed event selector', async () => {
|
254
250
|
const METHOD = 'aztec_getPublicEvents';
|
255
251
|
const params = {
|
256
252
|
event: {
|
@@ -269,24 +265,22 @@ describe('Log Serializers', () => {
|
|
269
265
|
limit: 10,
|
270
266
|
};
|
271
267
|
|
272
|
-
expect(()
|
273
|
-
aztecGetPublicEventsSerializer.params.serialize(METHOD, params);
|
274
|
-
}).toThrow();
|
268
|
+
await expect(aztecGetPublicEventsSerializer.params.serialize(METHOD, params)).rejects.toThrow();
|
275
269
|
});
|
276
270
|
|
277
|
-
it('should handle
|
271
|
+
it('should handle optional filter fields', async () => {
|
278
272
|
const METHOD = 'aztec_getPublicLogs';
|
279
273
|
const filter: LogFilter = {
|
280
|
-
fromBlock:
|
281
|
-
toBlock:
|
274
|
+
fromBlock: 0,
|
275
|
+
toBlock: 0,
|
282
276
|
};
|
283
277
|
|
284
278
|
const params = { filter };
|
285
|
-
const serialized = aztecGetPublicLogsSerializer.params.serialize(METHOD, params);
|
286
|
-
const deserialized = aztecGetPublicLogsSerializer.params.deserialize(METHOD, serialized);
|
279
|
+
const serialized = await aztecGetPublicLogsSerializer.params.serialize(METHOD, params);
|
280
|
+
const deserialized = await aztecGetPublicLogsSerializer.params.deserialize(METHOD, serialized);
|
287
281
|
|
288
|
-
expect(deserialized.filter.fromBlock).
|
289
|
-
expect(deserialized.filter.toBlock).
|
282
|
+
expect(deserialized.filter.fromBlock).toBe(0);
|
283
|
+
expect(deserialized.filter.toBlock).toBe(0);
|
290
284
|
});
|
291
285
|
});
|
292
286
|
});
|
package/src/serializers/log.ts
CHANGED
@@ -22,10 +22,10 @@ export class AztecGetPublicLogsSerializer
|
|
22
22
|
>
|
23
23
|
{
|
24
24
|
params = {
|
25
|
-
serialize: (
|
25
|
+
serialize: async (
|
26
26
|
method: string,
|
27
27
|
value: AztecWalletMethodMap['aztec_getPublicLogs']['params'],
|
28
|
-
): JSONRPCSerializedData => {
|
28
|
+
): Promise<JSONRPCSerializedData> => {
|
29
29
|
const { filter } = value;
|
30
30
|
// Convert all fields that need string conversion
|
31
31
|
const serializedFilter = {
|
@@ -36,15 +36,15 @@ export class AztecGetPublicLogsSerializer
|
|
36
36
|
fromBlock: filter.fromBlock,
|
37
37
|
toBlock: filter.toBlock,
|
38
38
|
};
|
39
|
-
return {
|
39
|
+
return Promise.resolve({
|
40
40
|
method,
|
41
41
|
serialized: JSON.stringify({ filter: serializedFilter }),
|
42
|
-
};
|
42
|
+
});
|
43
43
|
},
|
44
|
-
deserialize: (
|
44
|
+
deserialize: async (
|
45
45
|
_method: string,
|
46
46
|
data: JSONRPCSerializedData,
|
47
|
-
): AztecWalletMethodMap['aztec_getPublicLogs']['params'] => {
|
47
|
+
): Promise<AztecWalletMethodMap['aztec_getPublicLogs']['params']> => {
|
48
48
|
const { filter } = JSON.parse(data.serialized);
|
49
49
|
const deserializedFilter: Partial<{
|
50
50
|
txHash: TxHash;
|
@@ -61,25 +61,25 @@ export class AztecGetPublicLogsSerializer
|
|
61
61
|
if (filter.fromBlock !== undefined) deserializedFilter.fromBlock = filter.fromBlock;
|
62
62
|
if (filter.toBlock !== undefined) deserializedFilter.toBlock = filter.toBlock;
|
63
63
|
|
64
|
-
return { filter: deserializedFilter };
|
64
|
+
return Promise.resolve({ filter: deserializedFilter });
|
65
65
|
},
|
66
66
|
};
|
67
67
|
|
68
68
|
result = {
|
69
|
-
serialize: (
|
69
|
+
serialize: async (
|
70
70
|
method: string,
|
71
71
|
value: AztecWalletMethodMap['aztec_getPublicLogs']['result'],
|
72
|
-
): JSONRPCSerializedData => {
|
73
|
-
return {
|
72
|
+
): Promise<JSONRPCSerializedData> => {
|
73
|
+
return Promise.resolve({
|
74
74
|
method,
|
75
75
|
serialized: JSON.stringify(value),
|
76
|
-
};
|
76
|
+
});
|
77
77
|
},
|
78
|
-
deserialize: (
|
78
|
+
deserialize: async (
|
79
79
|
_method: string,
|
80
80
|
data: JSONRPCSerializedData,
|
81
|
-
): AztecWalletMethodMap['aztec_getPublicLogs']['result'] => {
|
82
|
-
return GetPublicLogsResponseSchema.parse(JSON.parse(data.serialized));
|
81
|
+
): Promise<AztecWalletMethodMap['aztec_getPublicLogs']['result']> => {
|
82
|
+
return Promise.resolve(GetPublicLogsResponseSchema.parse(JSON.parse(data.serialized)));
|
83
83
|
},
|
84
84
|
};
|
85
85
|
}
|
@@ -96,10 +96,10 @@ export class AztecGetContractClassLogsSerializer
|
|
96
96
|
>
|
97
97
|
{
|
98
98
|
params = {
|
99
|
-
serialize: (
|
99
|
+
serialize: async (
|
100
100
|
method: string,
|
101
101
|
value: AztecWalletMethodMap['aztec_getContractClassLogs']['params'],
|
102
|
-
): JSONRPCSerializedData => {
|
102
|
+
): Promise<JSONRPCSerializedData> => {
|
103
103
|
const { filter } = value;
|
104
104
|
// Convert fields to strings for schema validation
|
105
105
|
const serializedFilter = {
|
@@ -109,15 +109,15 @@ export class AztecGetContractClassLogsSerializer
|
|
109
109
|
fromBlock: filter.fromBlock,
|
110
110
|
toBlock: filter.toBlock,
|
111
111
|
};
|
112
|
-
return {
|
112
|
+
return Promise.resolve({
|
113
113
|
method,
|
114
114
|
serialized: JSON.stringify({ filter: serializedFilter }),
|
115
|
-
};
|
115
|
+
});
|
116
116
|
},
|
117
|
-
deserialize: (
|
117
|
+
deserialize: async (
|
118
118
|
_method: string,
|
119
119
|
data: JSONRPCSerializedData,
|
120
|
-
): AztecWalletMethodMap['aztec_getContractClassLogs']['params'] => {
|
120
|
+
): Promise<AztecWalletMethodMap['aztec_getContractClassLogs']['params']> => {
|
121
121
|
const { filter } = JSON.parse(data.serialized);
|
122
122
|
const deserializedFilter: LogFilter = {};
|
123
123
|
|
@@ -128,25 +128,25 @@ export class AztecGetContractClassLogsSerializer
|
|
128
128
|
if (filter.fromBlock !== undefined) deserializedFilter.fromBlock = filter.fromBlock;
|
129
129
|
if (filter.toBlock !== undefined) deserializedFilter.toBlock = filter.toBlock;
|
130
130
|
|
131
|
-
return { filter: deserializedFilter };
|
131
|
+
return Promise.resolve({ filter: deserializedFilter });
|
132
132
|
},
|
133
133
|
};
|
134
134
|
|
135
135
|
result = {
|
136
|
-
serialize: (
|
136
|
+
serialize: async (
|
137
137
|
method: string,
|
138
138
|
value: AztecWalletMethodMap['aztec_getContractClassLogs']['result'],
|
139
|
-
): JSONRPCSerializedData => {
|
140
|
-
return {
|
139
|
+
): Promise<JSONRPCSerializedData> => {
|
140
|
+
return Promise.resolve({
|
141
141
|
method,
|
142
142
|
serialized: JSON.stringify(GetContractClassLogsResponseSchema.parse(value)),
|
143
|
-
};
|
143
|
+
});
|
144
144
|
},
|
145
|
-
deserialize: (
|
145
|
+
deserialize: async (
|
146
146
|
_method: string,
|
147
147
|
data: JSONRPCSerializedData,
|
148
|
-
): AztecWalletMethodMap['aztec_getContractClassLogs']['result'] => {
|
149
|
-
return GetContractClassLogsResponseSchema.parse(JSON.parse(data.serialized));
|
148
|
+
): Promise<AztecWalletMethodMap['aztec_getContractClassLogs']['result']> => {
|
149
|
+
return Promise.resolve(GetContractClassLogsResponseSchema.parse(JSON.parse(data.serialized)));
|
150
150
|
},
|
151
151
|
};
|
152
152
|
}
|
@@ -163,12 +163,12 @@ export class AztecGetPrivateEventsSerializer
|
|
163
163
|
>
|
164
164
|
{
|
165
165
|
params = {
|
166
|
-
serialize: (
|
166
|
+
serialize: async (
|
167
167
|
method: string,
|
168
168
|
value: AztecWalletMethodMap['aztec_getPrivateEvents']['params'],
|
169
|
-
): JSONRPCSerializedData => {
|
169
|
+
): Promise<JSONRPCSerializedData> => {
|
170
170
|
const { event, from, limit, vpks } = value;
|
171
|
-
return {
|
171
|
+
return Promise.resolve({
|
172
172
|
method,
|
173
173
|
serialized: JSON.stringify({
|
174
174
|
event: {
|
@@ -182,12 +182,12 @@ export class AztecGetPrivateEventsSerializer
|
|
182
182
|
limit,
|
183
183
|
vpks: vpks?.map((p) => p.toString()),
|
184
184
|
}),
|
185
|
-
};
|
185
|
+
});
|
186
186
|
},
|
187
|
-
deserialize: (
|
187
|
+
deserialize: async (
|
188
188
|
_method: string,
|
189
189
|
data: JSONRPCSerializedData,
|
190
|
-
): AztecWalletMethodMap['aztec_getPrivateEvents']['params'] => {
|
190
|
+
): Promise<AztecWalletMethodMap['aztec_getPrivateEvents']['params']> => {
|
191
191
|
const { event: serializedEvent, from, limit, vpks } = JSON.parse(data.serialized);
|
192
192
|
const event: EventMetadataDefinition = {
|
193
193
|
eventSelector: EventSelector.fromString(serializedEvent.eventSelector),
|
@@ -196,24 +196,24 @@ export class AztecGetPrivateEventsSerializer
|
|
196
196
|
},
|
197
197
|
fieldNames: serializedEvent.fieldNames,
|
198
198
|
};
|
199
|
-
return {
|
199
|
+
return Promise.resolve({
|
200
200
|
event,
|
201
201
|
from,
|
202
202
|
limit,
|
203
203
|
vpks: vpks?.map((p: string) => Point.fromString(p)),
|
204
|
-
};
|
204
|
+
});
|
205
205
|
},
|
206
206
|
};
|
207
207
|
|
208
208
|
result = {
|
209
|
-
serialize: (method: string, value: unknown[]): JSONRPCSerializedData => {
|
210
|
-
return {
|
209
|
+
serialize: async (method: string, value: unknown[]): Promise<JSONRPCSerializedData> => {
|
210
|
+
return Promise.resolve({
|
211
211
|
method,
|
212
212
|
serialized: JSON.stringify(value),
|
213
|
-
};
|
213
|
+
});
|
214
214
|
},
|
215
|
-
deserialize: (_method: string, data: JSONRPCSerializedData): unknown[] => {
|
216
|
-
return JSON.parse(data.serialized);
|
215
|
+
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<unknown[]> => {
|
216
|
+
return Promise.resolve(JSON.parse(data.serialized));
|
217
217
|
},
|
218
218
|
};
|
219
219
|
}
|
@@ -230,12 +230,12 @@ export class AztecGetPublicEventsSerializer
|
|
230
230
|
>
|
231
231
|
{
|
232
232
|
params = {
|
233
|
-
serialize: (
|
233
|
+
serialize: async (
|
234
234
|
method: string,
|
235
235
|
value: AztecWalletMethodMap['aztec_getPublicEvents']['params'],
|
236
|
-
): JSONRPCSerializedData => {
|
236
|
+
): Promise<JSONRPCSerializedData> => {
|
237
237
|
const { event, from, limit } = value;
|
238
|
-
return {
|
238
|
+
return Promise.resolve({
|
239
239
|
method,
|
240
240
|
serialized: JSON.stringify({
|
241
241
|
event: {
|
@@ -248,12 +248,12 @@ export class AztecGetPublicEventsSerializer
|
|
248
248
|
from,
|
249
249
|
limit,
|
250
250
|
}),
|
251
|
-
};
|
251
|
+
});
|
252
252
|
},
|
253
|
-
deserialize: (
|
253
|
+
deserialize: async (
|
254
254
|
_method: string,
|
255
255
|
data: JSONRPCSerializedData,
|
256
|
-
): AztecWalletMethodMap['aztec_getPublicEvents']['params'] => {
|
256
|
+
): Promise<AztecWalletMethodMap['aztec_getPublicEvents']['params']> => {
|
257
257
|
const { event: serializedEvent, from, limit } = JSON.parse(data.serialized);
|
258
258
|
const event: EventMetadataDefinition = {
|
259
259
|
eventSelector: EventSelector.fromString(serializedEvent.eventSelector),
|
@@ -262,23 +262,23 @@ export class AztecGetPublicEventsSerializer
|
|
262
262
|
},
|
263
263
|
fieldNames: serializedEvent.fieldNames,
|
264
264
|
};
|
265
|
-
return {
|
265
|
+
return Promise.resolve({
|
266
266
|
event,
|
267
267
|
from,
|
268
268
|
limit,
|
269
|
-
};
|
269
|
+
});
|
270
270
|
},
|
271
271
|
};
|
272
272
|
|
273
273
|
result = {
|
274
|
-
serialize: (method: string, value: unknown[]): JSONRPCSerializedData => {
|
275
|
-
return {
|
274
|
+
serialize: async (method: string, value: unknown[]): Promise<JSONRPCSerializedData> => {
|
275
|
+
return Promise.resolve({
|
276
276
|
method,
|
277
277
|
serialized: JSON.stringify(value),
|
278
|
-
};
|
278
|
+
});
|
279
279
|
},
|
280
|
-
deserialize: (_method: string, data: JSONRPCSerializedData): unknown[] => {
|
281
|
-
return JSON.parse(data.serialized);
|
280
|
+
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<unknown[]> => {
|
281
|
+
return Promise.resolve(JSON.parse(data.serialized));
|
282
282
|
},
|
283
283
|
};
|
284
284
|
}
|