@walletmesh/aztec-rpc-wallet 0.3.0 → 0.4.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 +26 -0
- package/README.md +290 -228
- package/dist/.tsbuildinfo +1 -1
- package/dist/client/aztec-dapp-wallet.d.ts +401 -0
- package/dist/client/aztec-dapp-wallet.d.ts.map +1 -0
- package/dist/client/aztec-dapp-wallet.js +705 -0
- package/dist/client/aztec-router-provider.d.ts +58 -0
- package/dist/client/aztec-router-provider.d.ts.map +1 -0
- package/dist/client/aztec-router-provider.js +62 -0
- package/dist/client/helpers.d.ts +44 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +79 -0
- package/dist/client/register-serializers.d.ts +41 -0
- package/dist/client/register-serializers.d.ts.map +1 -0
- package/dist/client/register-serializers.js +97 -0
- package/dist/contractArtifactCache.d.ts +49 -32
- package/dist/contractArtifactCache.d.ts.map +1 -1
- package/dist/contractArtifactCache.js +47 -34
- package/dist/errors.d.ts +50 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +50 -10
- package/dist/index.d.ts +53 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -17
- package/dist/types.d.ts +345 -268
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -8
- package/dist/wallet/create-node.d.ts +73 -0
- package/dist/wallet/create-node.d.ts.map +1 -0
- package/dist/wallet/create-node.js +99 -0
- package/dist/wallet/handlers/account.d.ts +67 -0
- package/dist/wallet/handlers/account.d.ts.map +1 -0
- package/dist/wallet/handlers/account.js +85 -0
- package/dist/wallet/handlers/contract-interaction.d.ts +77 -0
- package/dist/wallet/handlers/contract-interaction.d.ts.map +1 -0
- package/dist/wallet/handlers/contract-interaction.js +219 -0
- package/dist/wallet/handlers/contract.d.ts +96 -0
- package/dist/wallet/handlers/contract.d.ts.map +1 -0
- package/dist/wallet/handlers/contract.js +146 -0
- package/dist/wallet/handlers/event.d.ts +62 -0
- package/dist/wallet/handlers/event.d.ts.map +1 -0
- package/dist/wallet/handlers/event.js +85 -0
- package/dist/wallet/handlers/index.d.ts +88 -0
- package/dist/wallet/handlers/index.d.ts.map +1 -0
- package/dist/wallet/handlers/index.js +47 -0
- package/dist/wallet/handlers/node.d.ts +117 -0
- package/dist/wallet/handlers/node.d.ts.map +1 -0
- package/dist/wallet/handlers/node.js +196 -0
- package/dist/wallet/handlers/senders.d.ts +70 -0
- package/dist/wallet/handlers/senders.d.ts.map +1 -0
- package/dist/wallet/handlers/senders.js +92 -0
- package/dist/wallet/handlers/transaction.d.ts +123 -0
- package/dist/wallet/handlers/transaction.d.ts.map +1 -0
- package/dist/wallet/handlers/transaction.js +191 -0
- package/dist/wallet/serializers.d.ts +75 -0
- package/dist/wallet/serializers.d.ts.map +1 -0
- package/dist/wallet/serializers.js +501 -0
- package/docs/README.md +290 -229
- package/docs/classes/AztecDappWallet.md +1304 -0
- package/docs/classes/AztecRouterProvider.md +1058 -0
- package/docs/classes/AztecWalletError.md +124 -47
- package/docs/classes/ContractArtifactCache.md +48 -31
- package/docs/functions/connectAztec.md +62 -0
- package/docs/functions/createAztecWallet.md +46 -0
- package/docs/functions/createAztecWalletNode.md +96 -0
- package/docs/functions/registerAztecSerializers.md +61 -0
- package/docs/functions/registerWalletAztecSerializers.md +39 -0
- package/docs/globals.md +16 -14
- package/docs/interfaces/AztecHandlerContext.md +54 -0
- package/docs/interfaces/AztecWalletContext.md +50 -0
- package/docs/interfaces/AztecWalletMethodMap.md +471 -470
- package/docs/type-aliases/AztecChainId.md +16 -3
- package/docs/variables/ALL_AZTEC_METHODS.md +20 -0
- package/docs/variables/AztecWalletErrorMap.md +9 -4
- package/docs/variables/AztecWalletSerializer.md +45 -0
- package/package.json +9 -9
- package/src/client/aztec-dapp-wallet.test.ts +628 -0
- package/src/client/aztec-dapp-wallet.ts +879 -0
- package/src/client/aztec-router-provider.test.ts +235 -0
- package/src/client/aztec-router-provider.ts +64 -0
- package/src/client/helpers.test.ts +187 -0
- package/src/client/helpers.ts +91 -0
- package/src/client/register-serializers.ts +108 -0
- package/src/contractArtifactCache.test.ts +21 -10
- package/src/contractArtifactCache.ts +54 -35
- package/src/errors.ts +58 -10
- package/src/index.test.ts +2 -6
- package/src/index.ts +73 -37
- package/src/types.ts +379 -217
- package/src/wallet/create-node.test.ts +332 -0
- package/src/wallet/create-node.ts +120 -0
- package/src/wallet/handlers/account.test.ts +172 -0
- package/src/wallet/handlers/account.ts +99 -0
- package/src/wallet/handlers/contract-interaction.test.ts +248 -0
- package/src/wallet/handlers/contract-interaction.ts +269 -0
- package/src/wallet/handlers/contract.test.ts +245 -0
- package/src/wallet/handlers/contract.ts +174 -0
- package/src/wallet/handlers/event.test.ts +216 -0
- package/src/wallet/handlers/event.ts +99 -0
- package/src/wallet/handlers/index.ts +84 -0
- package/src/wallet/handlers/node.test.ts +304 -0
- package/src/wallet/handlers/node.ts +230 -0
- package/src/wallet/handlers/senders.test.ts +172 -0
- package/src/wallet/handlers/senders.ts +106 -0
- package/src/wallet/handlers/transaction.test.ts +371 -0
- package/src/wallet/handlers/transaction.ts +239 -0
- package/src/wallet/serializers.test.ts +253 -0
- package/src/wallet/serializers.ts +586 -0
- package/typedoc.json +23 -1
- package/dist/aztecRemoteWallet.d.ts +0 -70
- package/dist/aztecRemoteWallet.d.ts.map +0 -1
- package/dist/aztecRemoteWallet.js +0 -335
- package/dist/chainProvider.d.ts +0 -56
- package/dist/chainProvider.d.ts.map +0 -1
- package/dist/chainProvider.js +0 -98
- package/dist/handlers/aztecAccountWallet.d.ts +0 -4
- package/dist/handlers/aztecAccountWallet.d.ts.map +0 -1
- package/dist/handlers/aztecAccountWallet.js +0 -296
- package/dist/handlers/transactions.d.ts +0 -21
- package/dist/handlers/transactions.d.ts.map +0 -1
- package/dist/handlers/transactions.js +0 -98
- package/dist/handlers.d.ts +0 -27
- package/dist/handlers.d.ts.map +0 -1
- package/dist/handlers.js +0 -55
- package/dist/provider.d.ts +0 -105
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -160
- package/dist/serializers/account.d.ts +0 -164
- package/dist/serializers/account.d.ts.map +0 -1
- package/dist/serializers/account.js +0 -244
- package/dist/serializers/contract.d.ts +0 -62
- package/dist/serializers/contract.d.ts.map +0 -1
- package/dist/serializers/contract.js +0 -130
- package/dist/serializers/index.d.ts +0 -21
- package/dist/serializers/index.d.ts.map +0 -1
- package/dist/serializers/index.js +0 -154
- package/dist/serializers/log.d.ts +0 -66
- package/dist/serializers/log.d.ts.map +0 -1
- package/dist/serializers/log.js +0 -222
- package/dist/serializers/note.d.ts +0 -124
- package/dist/serializers/note.d.ts.map +0 -1
- package/dist/serializers/note.js +0 -208
- package/dist/serializers/transaction.d.ts +0 -99
- package/dist/serializers/transaction.d.ts.map +0 -1
- package/dist/serializers/transaction.js +0 -275
- package/dist/wallet.d.ts +0 -62
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -77
- package/docs/classes/AztecChainProvider.md +0 -553
- package/docs/classes/AztecChainWallet.md +0 -409
- package/docs/classes/AztecProvider.md +0 -1112
- package/docs/interfaces/AztecWalletBaseMethodMap.md +0 -135
- package/docs/interfaces/AztecWalletEventMap.md +0 -17
- package/docs/type-aliases/AztecChainWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletContext.md +0 -29
- package/docs/type-aliases/AztecWalletMethodHandler.md +0 -37
- package/docs/type-aliases/AztecWalletMiddleware.md +0 -13
- package/docs/type-aliases/AztecWalletRouterClient.md +0 -13
- package/docs/type-aliases/TransactionFunctionCall.md +0 -33
- package/docs/type-aliases/TransactionParams.md +0 -27
- package/src/aztecRemoteWallet.test.ts +0 -504
- package/src/aztecRemoteWallet.ts +0 -467
- package/src/chainProvider.test.ts +0 -401
- package/src/chainProvider.ts +0 -116
- package/src/handlers/aztecAccountWallet.test.ts +0 -649
- package/src/handlers/aztecAccountWallet.ts +0 -532
- package/src/handlers/transactions.ts +0 -124
- package/src/handlers.test.ts +0 -270
- package/src/handlers.ts +0 -70
- package/src/provider.test.ts +0 -274
- package/src/provider.ts +0 -189
- package/src/serializers/account.test.ts +0 -125
- package/src/serializers/account.ts +0 -301
- package/src/serializers/contract.test.ts +0 -24
- package/src/serializers/contract.ts +0 -183
- package/src/serializers/index.test.ts +0 -136
- package/src/serializers/index.ts +0 -191
- package/src/serializers/log.test.ts +0 -286
- package/src/serializers/log.ts +0 -292
- package/src/serializers/note.test.ts +0 -125
- package/src/serializers/note.ts +0 -250
- package/src/serializers/transaction.test.ts +0 -320
- package/src/serializers/transaction.ts +0 -409
- package/src/wallet.test.ts +0 -275
- package/src/wallet.ts +0 -94
package/src/serializers/note.ts
DELETED
@@ -1,250 +0,0 @@
|
|
1
|
-
import type { AztecWalletMethodMap } from '../types.js';
|
2
|
-
import type { JSONRPCSerializedData, JSONRPCSerializer } from '@walletmesh/jsonrpc';
|
3
|
-
import { UniqueNote, TxHash, type NotesFilter } from '@aztec/circuit-types';
|
4
|
-
import { ExtendedNote, AztecAddress, Fr } from '@aztec/aztec.js';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Serializer for the aztec_getNotes RPC method.
|
8
|
-
* Handles serialization of note queries and results between JSON-RPC format and native Aztec types.
|
9
|
-
*/
|
10
|
-
export class AztecGetNotesSerializer
|
11
|
-
implements
|
12
|
-
JSONRPCSerializer<
|
13
|
-
AztecWalletMethodMap['aztec_getNotes']['params'],
|
14
|
-
AztecWalletMethodMap['aztec_getNotes']['result']
|
15
|
-
>
|
16
|
-
{
|
17
|
-
params = {
|
18
|
-
/**
|
19
|
-
* Serializes notes filter parameters for RPC transport.
|
20
|
-
* @param method - The RPC method name
|
21
|
-
* @param value - The parameters containing filter criteria for notes
|
22
|
-
* @returns Serialized filter data
|
23
|
-
*/
|
24
|
-
serialize: async (
|
25
|
-
method: string,
|
26
|
-
value: AztecWalletMethodMap['aztec_getNotes']['params'],
|
27
|
-
): Promise<JSONRPCSerializedData> => {
|
28
|
-
const { filter } = value;
|
29
|
-
// Convert instances to their string representations for transport
|
30
|
-
const serializedFilter = {
|
31
|
-
txHash: filter.txHash?.toString(),
|
32
|
-
contractAddress: filter.contractAddress?.toString(),
|
33
|
-
storageSlot: filter.storageSlot?.toString(),
|
34
|
-
owner: filter.owner?.toString(),
|
35
|
-
status: filter.status,
|
36
|
-
siloedNullifier: filter.siloedNullifier?.toString(),
|
37
|
-
scopes: filter.scopes?.map((scope) => scope.toString()),
|
38
|
-
};
|
39
|
-
|
40
|
-
return Promise.resolve({
|
41
|
-
method,
|
42
|
-
serialized: JSON.stringify({ filter: serializedFilter }),
|
43
|
-
});
|
44
|
-
},
|
45
|
-
/**
|
46
|
-
* Deserializes notes filter parameters from RPC transport.
|
47
|
-
* @param _method - The RPC method name
|
48
|
-
* @param data - The serialized filter data
|
49
|
-
* @returns Deserialized filter parameters
|
50
|
-
*/
|
51
|
-
deserialize: async (
|
52
|
-
_method: string,
|
53
|
-
data: JSONRPCSerializedData,
|
54
|
-
): Promise<AztecWalletMethodMap['aztec_getNotes']['params']> => {
|
55
|
-
const { filter } = JSON.parse(data.serialized);
|
56
|
-
|
57
|
-
// Convert string representations back to instances
|
58
|
-
const notesFilter: NotesFilter = {};
|
59
|
-
if (filter.txHash) notesFilter.txHash = TxHash.fromString(filter.txHash);
|
60
|
-
if (filter.contractAddress)
|
61
|
-
notesFilter.contractAddress = AztecAddress.fromString(filter.contractAddress);
|
62
|
-
if (filter.storageSlot) notesFilter.storageSlot = Fr.fromString(filter.storageSlot);
|
63
|
-
if (filter.owner) notesFilter.owner = AztecAddress.fromString(filter.owner);
|
64
|
-
if (filter.status) notesFilter.status = filter.status;
|
65
|
-
if (filter.siloedNullifier) notesFilter.siloedNullifier = Fr.fromString(filter.siloedNullifier);
|
66
|
-
if (filter.scopes)
|
67
|
-
notesFilter.scopes = filter.scopes.map((scope: string) => AztecAddress.fromString(scope));
|
68
|
-
|
69
|
-
return Promise.resolve({
|
70
|
-
filter: notesFilter,
|
71
|
-
});
|
72
|
-
},
|
73
|
-
};
|
74
|
-
|
75
|
-
result = {
|
76
|
-
/**
|
77
|
-
* Serializes the notes query result.
|
78
|
-
* @param method - The RPC method name
|
79
|
-
* @param value - Array of unique notes matching the filter criteria
|
80
|
-
* @returns Serialized note array
|
81
|
-
*/
|
82
|
-
serialize: async (
|
83
|
-
method: string,
|
84
|
-
value: AztecWalletMethodMap['aztec_getNotes']['result'],
|
85
|
-
): Promise<JSONRPCSerializedData> => {
|
86
|
-
return Promise.resolve({
|
87
|
-
method,
|
88
|
-
serialized: JSON.stringify(value.map((n) => n.toString())),
|
89
|
-
});
|
90
|
-
},
|
91
|
-
/**
|
92
|
-
* Deserializes the notes query result.
|
93
|
-
* @param _method - The RPC method name
|
94
|
-
* @param data - The serialized note array data
|
95
|
-
* @returns Array of deserialized unique notes
|
96
|
-
*/
|
97
|
-
deserialize: async (
|
98
|
-
_method: string,
|
99
|
-
data: JSONRPCSerializedData,
|
100
|
-
): Promise<AztecWalletMethodMap['aztec_getNotes']['result']> => {
|
101
|
-
return Promise.resolve(JSON.parse(data.serialized).map((n: string) => UniqueNote.fromString(n)));
|
102
|
-
},
|
103
|
-
};
|
104
|
-
}
|
105
|
-
|
106
|
-
/**
|
107
|
-
* Serializer for the aztec_addNote RPC method.
|
108
|
-
* Handles serialization of note addition requests between JSON-RPC format and native Aztec types.
|
109
|
-
*/
|
110
|
-
export class AztecAddNoteSerializer
|
111
|
-
implements
|
112
|
-
JSONRPCSerializer<
|
113
|
-
AztecWalletMethodMap['aztec_addNote']['params'],
|
114
|
-
AztecWalletMethodMap['aztec_addNote']['result']
|
115
|
-
>
|
116
|
-
{
|
117
|
-
params = {
|
118
|
-
/**
|
119
|
-
* Serializes note addition parameters for RPC transport.
|
120
|
-
* @param method - The RPC method name
|
121
|
-
* @param value - The parameters containing the note to add
|
122
|
-
* @returns Serialized note data
|
123
|
-
*/
|
124
|
-
serialize: async (
|
125
|
-
method: string,
|
126
|
-
value: AztecWalletMethodMap['aztec_addNote']['params'],
|
127
|
-
): Promise<JSONRPCSerializedData> => {
|
128
|
-
const { note } = value;
|
129
|
-
return Promise.resolve({
|
130
|
-
method,
|
131
|
-
serialized: JSON.stringify({ note: note.toBuffer().toString('base64') }),
|
132
|
-
});
|
133
|
-
},
|
134
|
-
/**
|
135
|
-
* Deserializes note addition parameters from RPC transport.
|
136
|
-
* @param _method - The RPC method name
|
137
|
-
* @param data - The serialized note data
|
138
|
-
* @returns Deserialized note parameters
|
139
|
-
*/
|
140
|
-
deserialize: async (
|
141
|
-
_method: string,
|
142
|
-
data: JSONRPCSerializedData,
|
143
|
-
): Promise<AztecWalletMethodMap['aztec_addNote']['params']> => {
|
144
|
-
const { note: noteBase64 } = JSON.parse(data.serialized);
|
145
|
-
const note = ExtendedNote.fromBuffer(Buffer.from(noteBase64, 'base64'));
|
146
|
-
return Promise.resolve({ note });
|
147
|
-
},
|
148
|
-
};
|
149
|
-
|
150
|
-
result = {
|
151
|
-
/**
|
152
|
-
* Serializes the note addition result.
|
153
|
-
* @param method - The RPC method name
|
154
|
-
* @param value - Boolean indicating success of the note addition
|
155
|
-
* @returns Serialized result
|
156
|
-
*/
|
157
|
-
serialize: async (method: string, value: boolean): Promise<JSONRPCSerializedData> => {
|
158
|
-
return Promise.resolve({
|
159
|
-
method,
|
160
|
-
serialized: JSON.stringify(value),
|
161
|
-
});
|
162
|
-
},
|
163
|
-
/**
|
164
|
-
* Deserializes the note addition result.
|
165
|
-
* @param _method - The RPC method name
|
166
|
-
* @param data - The serialized result data
|
167
|
-
* @returns Boolean indicating success
|
168
|
-
*/
|
169
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<boolean> => {
|
170
|
-
return Promise.resolve(JSON.parse(data.serialized));
|
171
|
-
},
|
172
|
-
};
|
173
|
-
}
|
174
|
-
|
175
|
-
/**
|
176
|
-
* Serializer for the aztec_addNullifiedNote RPC method.
|
177
|
-
* Handles serialization of nullified note addition requests between JSON-RPC format and native Aztec types.
|
178
|
-
*/
|
179
|
-
export class AztecAddNullifiedNoteSerializer
|
180
|
-
implements
|
181
|
-
JSONRPCSerializer<
|
182
|
-
AztecWalletMethodMap['aztec_addNullifiedNote']['params'],
|
183
|
-
AztecWalletMethodMap['aztec_addNullifiedNote']['result']
|
184
|
-
>
|
185
|
-
{
|
186
|
-
params = {
|
187
|
-
/**
|
188
|
-
* Serializes nullified note addition parameters for RPC transport.
|
189
|
-
* @param method - The RPC method name
|
190
|
-
* @param value - The parameters containing the nullified note to add
|
191
|
-
* @returns Serialized note data
|
192
|
-
*/
|
193
|
-
serialize: async (
|
194
|
-
method: string,
|
195
|
-
value: AztecWalletMethodMap['aztec_addNullifiedNote']['params'],
|
196
|
-
): Promise<JSONRPCSerializedData> => {
|
197
|
-
const { note } = value;
|
198
|
-
return Promise.resolve({
|
199
|
-
method,
|
200
|
-
serialized: JSON.stringify({ note: note.toBuffer().toString('base64') }),
|
201
|
-
});
|
202
|
-
},
|
203
|
-
/**
|
204
|
-
* Deserializes nullified note addition parameters from RPC transport.
|
205
|
-
* @param _method - The RPC method name
|
206
|
-
* @param data - The serialized note data
|
207
|
-
* @returns Deserialized note parameters
|
208
|
-
*/
|
209
|
-
deserialize: async (
|
210
|
-
_method: string,
|
211
|
-
data: JSONRPCSerializedData,
|
212
|
-
): Promise<AztecWalletMethodMap['aztec_addNullifiedNote']['params']> => {
|
213
|
-
const { note: noteBase64 } = JSON.parse(data.serialized);
|
214
|
-
const note = ExtendedNote.fromBuffer(Buffer.from(noteBase64, 'base64'));
|
215
|
-
return Promise.resolve({ note });
|
216
|
-
},
|
217
|
-
};
|
218
|
-
|
219
|
-
result = {
|
220
|
-
/**
|
221
|
-
* Serializes the nullified note addition result.
|
222
|
-
* @param method - The RPC method name
|
223
|
-
* @param value - Boolean indicating success of the nullified note addition
|
224
|
-
* @returns Serialized result
|
225
|
-
*/
|
226
|
-
serialize: async (method: string, value: boolean): Promise<JSONRPCSerializedData> => {
|
227
|
-
return Promise.resolve({
|
228
|
-
method,
|
229
|
-
serialized: JSON.stringify(value),
|
230
|
-
});
|
231
|
-
},
|
232
|
-
/**
|
233
|
-
* Deserializes the nullified note addition result.
|
234
|
-
* @param _method - The RPC method name
|
235
|
-
* @param data - The serialized result data
|
236
|
-
* @returns Boolean indicating success
|
237
|
-
*/
|
238
|
-
deserialize: async (_method: string, data: JSONRPCSerializedData): Promise<boolean> => {
|
239
|
-
return Promise.resolve(JSON.parse(data.serialized));
|
240
|
-
},
|
241
|
-
};
|
242
|
-
}
|
243
|
-
|
244
|
-
/**
|
245
|
-
* Pre-instantiated serializer instances for Aztec note-related RPC methods.
|
246
|
-
* These instances can be used directly by the RPC handler implementation.
|
247
|
-
*/
|
248
|
-
export const aztecGetNotesSerializer = new AztecGetNotesSerializer();
|
249
|
-
export const aztecAddNoteSerializer = new AztecAddNoteSerializer();
|
250
|
-
export const aztecAddNullifiedNoteSerializer = new AztecAddNullifiedNoteSerializer();
|
@@ -1,320 +0,0 @@
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
2
|
-
import { AztecAddress, TxHash, Tx, NoFeePaymentMethod, TxReceipt } from '@aztec/aztec.js';
|
3
|
-
import {
|
4
|
-
PrivateExecutionResult,
|
5
|
-
TxProvingResult,
|
6
|
-
FunctionCall,
|
7
|
-
TxEffect,
|
8
|
-
TxSimulationResult,
|
9
|
-
TxStatus,
|
10
|
-
PublicSimulationOutput,
|
11
|
-
SimulationError,
|
12
|
-
} from '@aztec/circuit-types';
|
13
|
-
import { Fr, FunctionSelector, PrivateKernelTailCircuitPublicInputs } from '@aztec/circuits.js';
|
14
|
-
import type { ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
|
15
|
-
import { FunctionType } from '@aztec/foundation/abi';
|
16
|
-
import {
|
17
|
-
aztecCreateTxExecutionRequestSerializer,
|
18
|
-
aztecSendTxSerializer,
|
19
|
-
aztecGetTxEffectSerializer,
|
20
|
-
aztecGetTxReceiptSerializer,
|
21
|
-
aztecSimulateTxSerializer,
|
22
|
-
aztecProveTxSerializer,
|
23
|
-
} from './transaction.js';
|
24
|
-
import { TxExecutionRequest } from '@aztec/aztec.js';
|
25
|
-
|
26
|
-
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
27
|
-
|
28
|
-
describe('Transaction Serializers', () => {
|
29
|
-
describe('aztec_createTxExecutionRequest', () => {
|
30
|
-
const METHOD = 'aztec_createTxExecutionRequest';
|
31
|
-
|
32
|
-
it('should serialize and deserialize params', async () => {
|
33
|
-
const randomTx = await TxExecutionRequest.random();
|
34
|
-
const exec = {
|
35
|
-
calls: [], // Empty calls array since we're just testing serialization
|
36
|
-
fee: {
|
37
|
-
gasSettings: randomTx.txContext.gasSettings,
|
38
|
-
paymentMethod: new NoFeePaymentMethod(),
|
39
|
-
},
|
40
|
-
};
|
41
|
-
const params = { exec };
|
42
|
-
|
43
|
-
const serialized = await aztecCreateTxExecutionRequestSerializer.params.serialize(METHOD, params);
|
44
|
-
expect(serialized.method).toBe(METHOD);
|
45
|
-
|
46
|
-
const deserialized = await aztecCreateTxExecutionRequestSerializer.params.deserialize(
|
47
|
-
METHOD,
|
48
|
-
serialized,
|
49
|
-
);
|
50
|
-
expect(deserialized.exec.calls).toEqual([]);
|
51
|
-
expect(deserialized.exec.fee.gasSettings.equals(randomTx.txContext.gasSettings)).toBe(true);
|
52
|
-
expect(deserialized.exec.fee.paymentMethod).toBeDefined();
|
53
|
-
});
|
54
|
-
|
55
|
-
it('should handle complex function calls in params', async () => {
|
56
|
-
const randomTx = await TxExecutionRequest.random();
|
57
|
-
const address = await AztecAddress.random();
|
58
|
-
const selector = FunctionSelector.random();
|
59
|
-
const functionCall = new FunctionCall(
|
60
|
-
'transfer',
|
61
|
-
address,
|
62
|
-
selector,
|
63
|
-
FunctionType.PRIVATE,
|
64
|
-
false,
|
65
|
-
[await Fr.random(), await Fr.random()],
|
66
|
-
[{ kind: 'field' }, { kind: 'boolean' }],
|
67
|
-
);
|
68
|
-
const exec: ExecutionRequestInit = {
|
69
|
-
calls: [functionCall],
|
70
|
-
fee: {
|
71
|
-
gasSettings: randomTx.txContext.gasSettings,
|
72
|
-
paymentMethod: new NoFeePaymentMethod(),
|
73
|
-
},
|
74
|
-
};
|
75
|
-
const params = { exec };
|
76
|
-
|
77
|
-
const serialized = await aztecCreateTxExecutionRequestSerializer.params.serialize(METHOD, params);
|
78
|
-
const deserialized = await aztecCreateTxExecutionRequestSerializer.params.deserialize(
|
79
|
-
METHOD,
|
80
|
-
serialized,
|
81
|
-
);
|
82
|
-
|
83
|
-
// biome-ignore lint/style/noNonNullAssertion: test
|
84
|
-
expect(deserialized.exec.calls[0]!.name).toBe(exec.calls[0]!.name);
|
85
|
-
// biome-ignore lint/style/noNonNullAssertion: test
|
86
|
-
expect(deserialized.exec.calls[0]!.to.toString()).toBe(exec.calls[0]!.to.toString());
|
87
|
-
// biome-ignore lint/style/noNonNullAssertion: test
|
88
|
-
expect(deserialized.exec.calls[0]!.type).toBe(exec.calls[0]!.type);
|
89
|
-
});
|
90
|
-
|
91
|
-
it('should serialize and deserialize result', async () => {
|
92
|
-
const result = await TxExecutionRequest.random();
|
93
|
-
|
94
|
-
const serialized = await aztecCreateTxExecutionRequestSerializer.result.serialize(METHOD, result);
|
95
|
-
expect(serialized.method).toBe(METHOD);
|
96
|
-
|
97
|
-
const deserialized = await aztecCreateTxExecutionRequestSerializer.result.deserialize(
|
98
|
-
METHOD,
|
99
|
-
serialized,
|
100
|
-
);
|
101
|
-
expect(deserialized.toString()).toBe(result.toString());
|
102
|
-
});
|
103
|
-
});
|
104
|
-
|
105
|
-
describe('aztec_getTxEffect', () => {
|
106
|
-
const METHOD = 'aztec_getTxEffect';
|
107
|
-
|
108
|
-
it('should serialize and deserialize params', async () => {
|
109
|
-
const txHash = await TxHash.random();
|
110
|
-
const params = { txHash };
|
111
|
-
|
112
|
-
const serialized = await aztecGetTxEffectSerializer.params.serialize(METHOD, params);
|
113
|
-
expect(serialized.method).toBe(METHOD);
|
114
|
-
|
115
|
-
const deserialized = await aztecGetTxEffectSerializer.params.deserialize(METHOD, serialized);
|
116
|
-
expect(deserialized.txHash.toString()).toBe(txHash.toString());
|
117
|
-
});
|
118
|
-
|
119
|
-
it('should serialize and deserialize result', async () => {
|
120
|
-
const txHash = await TxHash.random();
|
121
|
-
const effect = await TxEffect.random();
|
122
|
-
const blockHash = await Fr.random();
|
123
|
-
const result = {
|
124
|
-
txHash,
|
125
|
-
l2BlockNumber: 123,
|
126
|
-
l2BlockHash: blockHash.toString(),
|
127
|
-
data: effect,
|
128
|
-
};
|
129
|
-
|
130
|
-
const serialized = await aztecGetTxEffectSerializer.result.serialize(METHOD, result);
|
131
|
-
const deserialized = await aztecGetTxEffectSerializer.result.deserialize(METHOD, serialized);
|
132
|
-
|
133
|
-
expect(deserialized.l2BlockNumber).toBe(result.l2BlockNumber);
|
134
|
-
expect(deserialized.data).toBeDefined();
|
135
|
-
});
|
136
|
-
});
|
137
|
-
|
138
|
-
describe('aztec_getTxReceipt', () => {
|
139
|
-
const METHOD = 'aztec_getTxReceipt';
|
140
|
-
|
141
|
-
it('should serialize and deserialize params', async () => {
|
142
|
-
const txHash = await TxHash.random();
|
143
|
-
const params = { txHash };
|
144
|
-
|
145
|
-
const serialized = await aztecGetTxReceiptSerializer.params.serialize(METHOD, params);
|
146
|
-
expect(serialized.method).toBe(METHOD);
|
147
|
-
|
148
|
-
const deserialized = await aztecGetTxReceiptSerializer.params.deserialize(METHOD, serialized);
|
149
|
-
expect(deserialized.txHash.toString()).toBe(txHash.toString());
|
150
|
-
});
|
151
|
-
|
152
|
-
it('should serialize and deserialize result', async () => {
|
153
|
-
const receipt = new TxReceipt(
|
154
|
-
TxHash.random(),
|
155
|
-
TxStatus.DROPPED,
|
156
|
-
'error',
|
157
|
-
undefined,
|
158
|
-
undefined,
|
159
|
-
undefined,
|
160
|
-
);
|
161
|
-
|
162
|
-
const serialized = await aztecGetTxReceiptSerializer.result.serialize(METHOD, receipt);
|
163
|
-
const deserialized = await aztecGetTxReceiptSerializer.result.deserialize(METHOD, serialized);
|
164
|
-
|
165
|
-
expect(deserialized.txHash.toString()).toBe(receipt.txHash.toString());
|
166
|
-
expect(deserialized.error).toBe(receipt.error);
|
167
|
-
});
|
168
|
-
});
|
169
|
-
|
170
|
-
describe('aztec_sendTx', () => {
|
171
|
-
const METHOD = 'aztec_sendTx';
|
172
|
-
|
173
|
-
it('should serialize and deserialize params', async () => {
|
174
|
-
const tx = await Tx.random();
|
175
|
-
const params = { tx };
|
176
|
-
|
177
|
-
const serialized = await aztecSendTxSerializer.params.serialize(METHOD, params);
|
178
|
-
expect(serialized.method).toBe(METHOD);
|
179
|
-
|
180
|
-
const deserialized = await aztecSendTxSerializer.params.deserialize(METHOD, serialized);
|
181
|
-
expect(deserialized.tx.toBuffer().toString('hex')).toBe(tx.toBuffer().toString('hex'));
|
182
|
-
});
|
183
|
-
|
184
|
-
it('should serialize and deserialize result', async () => {
|
185
|
-
const result = await TxHash.random();
|
186
|
-
|
187
|
-
const serialized = await aztecSendTxSerializer.result.serialize(METHOD, result);
|
188
|
-
expect(serialized.method).toBe(METHOD);
|
189
|
-
|
190
|
-
const deserialized = await aztecSendTxSerializer.result.deserialize(METHOD, serialized);
|
191
|
-
expect(deserialized.toString()).toBe(result.toString());
|
192
|
-
});
|
193
|
-
});
|
194
|
-
|
195
|
-
describe('aztec_simulateTx', () => {
|
196
|
-
const METHOD = 'aztec_simulateTx';
|
197
|
-
|
198
|
-
it('should serialize and deserialize params', async () => {
|
199
|
-
const params = {
|
200
|
-
txRequest: await TxExecutionRequest.random(),
|
201
|
-
simulatePublic: true,
|
202
|
-
msgSender: await AztecAddress.random(),
|
203
|
-
skipTxValidation: false,
|
204
|
-
enforceFeePayment: true,
|
205
|
-
profile: false,
|
206
|
-
};
|
207
|
-
|
208
|
-
const serialized = await aztecSimulateTxSerializer.params.serialize(METHOD, params);
|
209
|
-
expect(serialized.method).toBe(METHOD);
|
210
|
-
|
211
|
-
const deserialized = await aztecSimulateTxSerializer.params.deserialize(METHOD, serialized);
|
212
|
-
expect(deserialized.txRequest.toString()).toBe((params.txRequest as TxExecutionRequest).toString());
|
213
|
-
expect(deserialized.simulatePublic).toBe(params.simulatePublic);
|
214
|
-
expect(deserialized.msgSender?.toString()).toBe(params.msgSender.toString());
|
215
|
-
expect(deserialized.skipTxValidation).toBe(params.skipTxValidation);
|
216
|
-
expect(deserialized.enforceFeePayment).toBe(params.enforceFeePayment);
|
217
|
-
expect(deserialized.profile).toBe(params.profile);
|
218
|
-
});
|
219
|
-
|
220
|
-
it('should serialize and deserialize result', async () => {
|
221
|
-
const result = await TxSimulationResult.random();
|
222
|
-
|
223
|
-
const serialized = await aztecSimulateTxSerializer.result.serialize(METHOD, result);
|
224
|
-
const deserialized = await aztecSimulateTxSerializer.result.deserialize(METHOD, serialized);
|
225
|
-
|
226
|
-
expect(deserialized.privateExecutionResult).toBeDefined();
|
227
|
-
expect(deserialized.publicInputs).toBeDefined();
|
228
|
-
expect(deserialized.publicOutput).toBeDefined();
|
229
|
-
|
230
|
-
expect(jsonStringify(deserialized.privateExecutionResult)).toEqual(
|
231
|
-
jsonStringify(result.privateExecutionResult),
|
232
|
-
);
|
233
|
-
expect(jsonStringify(deserialized.publicInputs)).toEqual(jsonStringify(result.publicInputs));
|
234
|
-
if (!result.publicOutput || !deserialized.publicOutput) {
|
235
|
-
// Should never happen
|
236
|
-
throw new Error('Public output is undefined');
|
237
|
-
}
|
238
|
-
expect(jsonStringify(deserialized.publicOutput.constants)).toEqual(
|
239
|
-
jsonStringify(result.publicOutput.constants),
|
240
|
-
);
|
241
|
-
expect(jsonStringify(deserialized.publicOutput.constants)).toEqual(
|
242
|
-
jsonStringify(result.publicOutput.constants),
|
243
|
-
);
|
244
|
-
expect(jsonStringify(deserialized.publicOutput.gasUsed.publicGas)).toEqual(
|
245
|
-
jsonStringify(result.publicOutput.gasUsed.publicGas),
|
246
|
-
);
|
247
|
-
expect(jsonStringify(deserialized.publicOutput.gasUsed.teardownGas)).toEqual(
|
248
|
-
jsonStringify(result.publicOutput.gasUsed.teardownGas),
|
249
|
-
);
|
250
|
-
expect(jsonStringify(deserialized.publicOutput.gasUsed.totalGas)).toEqual(
|
251
|
-
jsonStringify(result.publicOutput.gasUsed.totalGas),
|
252
|
-
);
|
253
|
-
});
|
254
|
-
|
255
|
-
it('should handle simulation errors in result', async () => {
|
256
|
-
const privateExecutionResult = await PrivateExecutionResult.random();
|
257
|
-
const publicInputs = PrivateKernelTailCircuitPublicInputs.empty();
|
258
|
-
const publicOutput = await PublicSimulationOutput.random();
|
259
|
-
// Simulate an error by setting revertReason
|
260
|
-
publicOutput.revertReason = await SimulationError.random();
|
261
|
-
const result = new TxSimulationResult(privateExecutionResult, publicInputs, publicOutput, undefined);
|
262
|
-
|
263
|
-
const serialized = await aztecSimulateTxSerializer.result.serialize(METHOD, result);
|
264
|
-
const deserialized = await aztecSimulateTxSerializer.result.deserialize(METHOD, serialized);
|
265
|
-
|
266
|
-
const output = deserialized.publicOutput;
|
267
|
-
expect(output).toBeDefined();
|
268
|
-
if (output && result.publicOutput) {
|
269
|
-
expect(output.revertReason).toBeDefined();
|
270
|
-
expect(output.gasUsed).toEqual(result.publicOutput.gasUsed);
|
271
|
-
}
|
272
|
-
});
|
273
|
-
});
|
274
|
-
|
275
|
-
describe('aztec_proveTx', () => {
|
276
|
-
const METHOD = 'aztec_proveTx';
|
277
|
-
|
278
|
-
it('should serialize and deserialize params', async () => {
|
279
|
-
const txRequest = await TxExecutionRequest.random();
|
280
|
-
const privateExecutionResult = await PrivateExecutionResult.random();
|
281
|
-
const params = { txRequest, privateExecutionResult };
|
282
|
-
|
283
|
-
const serialized = await aztecProveTxSerializer.params.serialize(METHOD, params);
|
284
|
-
expect(serialized.method).toBe(METHOD);
|
285
|
-
|
286
|
-
const deserialized = await aztecProveTxSerializer.params.deserialize(METHOD, serialized);
|
287
|
-
expect(deserialized.txRequest.toString()).toBe(txRequest.toString());
|
288
|
-
expect(jsonStringify(deserialized.privateExecutionResult)).toEqual(
|
289
|
-
jsonStringify(privateExecutionResult),
|
290
|
-
);
|
291
|
-
});
|
292
|
-
|
293
|
-
it('should serialize and deserialize result', async () => {
|
294
|
-
const result = await TxProvingResult.random();
|
295
|
-
|
296
|
-
const serialized = await aztecProveTxSerializer.result.serialize(METHOD, result);
|
297
|
-
expect(serialized.method).toBe(METHOD);
|
298
|
-
|
299
|
-
const deserialized = await aztecProveTxSerializer.result.deserialize(METHOD, serialized);
|
300
|
-
expect(jsonStringify(deserialized)).toEqual(jsonStringify(result));
|
301
|
-
});
|
302
|
-
|
303
|
-
it('should handle complex private execution results', async () => {
|
304
|
-
const txRequest = await TxExecutionRequest.random();
|
305
|
-
const privateExecutionResult = await PrivateExecutionResult.random();
|
306
|
-
|
307
|
-
// Add nested executions and complex data
|
308
|
-
const nestedExecution = await PrivateExecutionResult.random();
|
309
|
-
privateExecutionResult.entrypoint.nestedExecutions.push(nestedExecution.entrypoint);
|
310
|
-
|
311
|
-
const params = { txRequest, privateExecutionResult };
|
312
|
-
const serialized = await aztecProveTxSerializer.params.serialize(METHOD, params);
|
313
|
-
const deserialized = await aztecProveTxSerializer.params.deserialize(METHOD, serialized);
|
314
|
-
|
315
|
-
expect(jsonStringify(deserialized.privateExecutionResult)).toEqual(
|
316
|
-
jsonStringify(privateExecutionResult),
|
317
|
-
);
|
318
|
-
});
|
319
|
-
});
|
320
|
-
});
|