@walletmesh/aztec-rpc-wallet 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/aztecRemoteWallet.d.ts +7 -6
  4. package/dist/aztecRemoteWallet.d.ts.map +1 -1
  5. package/dist/aztecRemoteWallet.js +15 -9
  6. package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
  7. package/dist/handlers/aztecAccountWallet.js +22 -22
  8. package/dist/serializers/account.d.ts +4 -7
  9. package/dist/serializers/account.d.ts.map +1 -1
  10. package/dist/serializers/account.js +28 -29
  11. package/dist/serializers/contract.d.ts +4 -56
  12. package/dist/serializers/contract.d.ts.map +1 -1
  13. package/dist/serializers/contract.js +62 -148
  14. package/dist/serializers/index.d.ts +1 -4
  15. package/dist/serializers/index.d.ts.map +1 -1
  16. package/dist/serializers/index.js +12 -12
  17. package/dist/serializers/log.d.ts +36 -83
  18. package/dist/serializers/log.d.ts.map +1 -1
  19. package/dist/serializers/log.js +96 -107
  20. package/dist/serializers/note.d.ts +14 -17
  21. package/dist/serializers/note.d.ts.map +1 -1
  22. package/dist/serializers/note.js +52 -29
  23. package/dist/serializers/transaction-utils.d.ts +44 -100
  24. package/dist/serializers/transaction-utils.d.ts.map +1 -1
  25. package/dist/serializers/transaction-utils.js +82 -118
  26. package/dist/serializers/transaction.d.ts +3 -6
  27. package/dist/serializers/transaction.d.ts.map +1 -1
  28. package/dist/serializers/transaction.js +39 -50
  29. package/dist/types.d.ts +8 -8
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/types.js +1 -1
  32. package/package.json +5 -5
  33. package/src/aztecRemoteWallet.test.ts +33 -29
  34. package/src/aztecRemoteWallet.ts +25 -14
  35. package/src/handlers/aztecAccountWallet.test.ts +78 -75
  36. package/src/handlers/aztecAccountWallet.ts +32 -35
  37. package/src/serializers/account.test.ts +18 -17
  38. package/src/serializers/account.ts +31 -49
  39. package/src/serializers/contract.test.ts +14 -16
  40. package/src/serializers/contract.ts +75 -164
  41. package/src/serializers/index.test.ts +20 -8
  42. package/src/serializers/index.ts +16 -20
  43. package/src/serializers/log.test.ts +201 -28
  44. package/src/serializers/log.ts +153 -146
  45. package/src/serializers/note.test.ts +26 -28
  46. package/src/serializers/note.ts +60 -36
  47. package/src/serializers/transaction-utils.ts +135 -211
  48. package/src/serializers/transaction.test.ts +190 -30
  49. package/src/serializers/transaction.ts +51 -72
  50. package/src/types.ts +9 -8
  51. package/vitest.config.ts +1 -1
  52. package/dist/serializers/contract-utils.d.ts +0 -40
  53. package/dist/serializers/contract-utils.d.ts.map +0 -1
  54. package/dist/serializers/contract-utils.js +0 -102
  55. package/dist/serializers/core.d.ts +0 -110
  56. package/dist/serializers/core.d.ts.map +0 -1
  57. package/dist/serializers/core.js +0 -130
  58. package/dist/serializers/types.d.ts +0 -49
  59. package/dist/serializers/types.d.ts.map +0 -1
  60. package/dist/serializers/types.js +0 -22
  61. package/src/serializers/contract-utils.ts +0 -104
  62. package/src/serializers/core.test.ts +0 -56
  63. package/src/serializers/core.ts +0 -141
  64. package/src/serializers/types.ts +0 -58
@@ -1,41 +1,49 @@
1
1
  import type { AztecWalletMethodMap } from '../types.js';
2
- import type { JSONRPCSerializedData, JSONRPCSerializer } from './types.js';
3
- import { encodeBase64, decodeBase64 } from './types.js';
4
- import type { IncomingNotesFilter } from '@aztec/circuit-types';
5
- import { UniqueNote } from '@aztec/circuit-types';
6
- import { ExtendedNote } from '@aztec/aztec.js';
2
+ import type { JSONRPCSerializedData, JSONRPCSerializer } from '@walletmesh/jsonrpc';
3
+ import { UniqueNote, TxHash } from '@aztec/circuit-types';
4
+ import { ExtendedNote, AztecAddress, Fr } from '@aztec/aztec.js';
7
5
 
8
6
  /**
9
- * Serializer for the aztec_getIncomingNotes RPC method.
10
- * Handles serialization of incoming note queries and results between JSON-RPC format and native Aztec types.
11
- * Used to retrieve notes that have been sent to an account but not yet processed.
7
+ * Serializer for the aztec_getNotes RPC method.
8
+ * Handles serialization of note queries and results between JSON-RPC format and native Aztec types.
12
9
  */
13
- export class AztecGetIncomingNotesSerializer
10
+ export class AztecGetNotesSerializer
14
11
  implements
15
12
  JSONRPCSerializer<
16
- AztecWalletMethodMap['aztec_getIncomingNotes']['params'],
17
- AztecWalletMethodMap['aztec_getIncomingNotes']['result']
13
+ AztecWalletMethodMap['aztec_getNotes']['params'],
14
+ AztecWalletMethodMap['aztec_getNotes']['result']
18
15
  >
19
16
  {
20
17
  params = {
21
18
  /**
22
- * Serializes incoming notes filter parameters for RPC transport.
19
+ * Serializes notes filter parameters for RPC transport.
23
20
  * @param method - The RPC method name
24
- * @param value - The parameters containing filter criteria for incoming notes
21
+ * @param value - The parameters containing filter criteria for notes
25
22
  * @returns Serialized filter data
26
23
  */
27
24
  serialize: (
28
25
  method: string,
29
- value: AztecWalletMethodMap['aztec_getIncomingNotes']['params'],
26
+ value: AztecWalletMethodMap['aztec_getNotes']['params'],
30
27
  ): JSONRPCSerializedData => {
31
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
+
32
40
  return {
33
41
  method,
34
- serialized: encodeBase64(JSON.stringify(filter)),
42
+ serialized: JSON.stringify({ filter: serializedFilter }),
35
43
  };
36
44
  },
37
45
  /**
38
- * Deserializes incoming notes filter parameters from RPC transport.
46
+ * Deserializes notes filter parameters from RPC transport.
39
47
  * @param method - The RPC method name
40
48
  * @param data - The serialized filter data
41
49
  * @returns Deserialized filter parameters
@@ -43,30 +51,46 @@ export class AztecGetIncomingNotesSerializer
43
51
  deserialize: (
44
52
  method: string,
45
53
  data: JSONRPCSerializedData,
46
- ): AztecWalletMethodMap['aztec_getIncomingNotes']['params'] => {
47
- const filter = JSON.parse(decodeBase64(data.serialized)) as IncomingNotesFilter;
48
- return { filter };
54
+ ): AztecWalletMethodMap['aztec_getNotes']['params'] => {
55
+ const { filter } = JSON.parse(data.serialized);
56
+
57
+ // Convert string representations back to instances
58
+ return {
59
+ filter: {
60
+ txHash: filter.txHash ? TxHash.fromString(filter.txHash) : undefined,
61
+ contractAddress: filter.contractAddress
62
+ ? AztecAddress.fromString(filter.contractAddress)
63
+ : undefined,
64
+ storageSlot: filter.storageSlot ? Fr.fromString(filter.storageSlot) : undefined,
65
+ owner: filter.owner ? AztecAddress.fromString(filter.owner) : undefined,
66
+ status: filter.status,
67
+ siloedNullifier: filter.siloedNullifier ? Fr.fromString(filter.siloedNullifier) : undefined,
68
+ scopes: filter.scopes
69
+ ? filter.scopes.map((scope: string) => AztecAddress.fromString(scope))
70
+ : undefined,
71
+ },
72
+ };
49
73
  },
50
74
  };
51
75
 
52
76
  result = {
53
77
  /**
54
- * Serializes the incoming notes query result.
78
+ * Serializes the notes query result.
55
79
  * @param method - The RPC method name
56
80
  * @param value - Array of unique notes matching the filter criteria
57
81
  * @returns Serialized note array
58
82
  */
59
83
  serialize: (
60
84
  method: string,
61
- value: AztecWalletMethodMap['aztec_getIncomingNotes']['result'],
85
+ value: AztecWalletMethodMap['aztec_getNotes']['result'],
62
86
  ): JSONRPCSerializedData => {
63
87
  return {
64
88
  method,
65
- serialized: encodeBase64(JSON.stringify(value.map((n) => n.toString()))),
89
+ serialized: JSON.stringify(value.map((n) => n.toString())),
66
90
  };
67
91
  },
68
92
  /**
69
- * Deserializes the incoming notes query result.
93
+ * Deserializes the notes query result.
70
94
  * @param method - The RPC method name
71
95
  * @param data - The serialized note array data
72
96
  * @returns Array of deserialized unique notes
@@ -74,8 +98,8 @@ export class AztecGetIncomingNotesSerializer
74
98
  deserialize: (
75
99
  method: string,
76
100
  data: JSONRPCSerializedData,
77
- ): AztecWalletMethodMap['aztec_getIncomingNotes']['result'] => {
78
- return JSON.parse(decodeBase64(data.serialized)).map((n: string) => UniqueNote.fromString(n));
101
+ ): AztecWalletMethodMap['aztec_getNotes']['result'] => {
102
+ return JSON.parse(data.serialized).map((n: string) => UniqueNote.fromString(n));
79
103
  },
80
104
  };
81
105
  }
@@ -83,7 +107,6 @@ export class AztecGetIncomingNotesSerializer
83
107
  /**
84
108
  * Serializer for the aztec_addNote RPC method.
85
109
  * Handles serialization of note addition requests between JSON-RPC format and native Aztec types.
86
- * Used to add new notes to an account's note tree.
87
110
  */
88
111
  export class AztecAddNoteSerializer
89
112
  implements
@@ -106,7 +129,7 @@ export class AztecAddNoteSerializer
106
129
  const { note } = value;
107
130
  return {
108
131
  method,
109
- serialized: encodeBase64(note.toBuffer().toString('hex')),
132
+ serialized: JSON.stringify({ note: note.toBuffer().toString('base64') }),
110
133
  };
111
134
  },
112
135
  /**
@@ -119,7 +142,8 @@ export class AztecAddNoteSerializer
119
142
  method: string,
120
143
  data: JSONRPCSerializedData,
121
144
  ): AztecWalletMethodMap['aztec_addNote']['params'] => {
122
- const note = ExtendedNote.fromBuffer(Buffer.from(decodeBase64(data.serialized), 'hex'));
145
+ const { note: noteBase64 } = JSON.parse(data.serialized);
146
+ const note = ExtendedNote.fromBuffer(Buffer.from(noteBase64, 'base64'));
123
147
  return { note };
124
148
  },
125
149
  };
@@ -134,7 +158,7 @@ export class AztecAddNoteSerializer
134
158
  serialize: (method: string, value: boolean): JSONRPCSerializedData => {
135
159
  return {
136
160
  method,
137
- serialized: encodeBase64(JSON.stringify(value)),
161
+ serialized: JSON.stringify(value),
138
162
  };
139
163
  },
140
164
  /**
@@ -144,7 +168,7 @@ export class AztecAddNoteSerializer
144
168
  * @returns Boolean indicating success
145
169
  */
146
170
  deserialize: (method: string, data: JSONRPCSerializedData): boolean => {
147
- return JSON.parse(decodeBase64(data.serialized));
171
+ return JSON.parse(data.serialized);
148
172
  },
149
173
  };
150
174
  }
@@ -152,7 +176,6 @@ export class AztecAddNoteSerializer
152
176
  /**
153
177
  * Serializer for the aztec_addNullifiedNote RPC method.
154
178
  * Handles serialization of nullified note addition requests between JSON-RPC format and native Aztec types.
155
- * Used to mark notes as spent/nullified in the note tree.
156
179
  */
157
180
  export class AztecAddNullifiedNoteSerializer
158
181
  implements
@@ -175,7 +198,7 @@ export class AztecAddNullifiedNoteSerializer
175
198
  const { note } = value;
176
199
  return {
177
200
  method,
178
- serialized: encodeBase64(note.toBuffer().toString('hex')),
201
+ serialized: JSON.stringify({ note: note.toBuffer().toString('base64') }),
179
202
  };
180
203
  },
181
204
  /**
@@ -188,7 +211,8 @@ export class AztecAddNullifiedNoteSerializer
188
211
  method: string,
189
212
  data: JSONRPCSerializedData,
190
213
  ): AztecWalletMethodMap['aztec_addNullifiedNote']['params'] => {
191
- const note = ExtendedNote.fromBuffer(Buffer.from(decodeBase64(data.serialized), 'hex'));
214
+ const { note: noteBase64 } = JSON.parse(data.serialized);
215
+ const note = ExtendedNote.fromBuffer(Buffer.from(noteBase64, 'base64'));
192
216
  return { note };
193
217
  },
194
218
  };
@@ -203,7 +227,7 @@ export class AztecAddNullifiedNoteSerializer
203
227
  serialize: (method: string, value: boolean): JSONRPCSerializedData => {
204
228
  return {
205
229
  method,
206
- serialized: encodeBase64(JSON.stringify(value)),
230
+ serialized: JSON.stringify(value),
207
231
  };
208
232
  },
209
233
  /**
@@ -213,7 +237,7 @@ export class AztecAddNullifiedNoteSerializer
213
237
  * @returns Boolean indicating success
214
238
  */
215
239
  deserialize: (method: string, data: JSONRPCSerializedData): boolean => {
216
- return JSON.parse(decodeBase64(data.serialized));
240
+ return JSON.parse(data.serialized);
217
241
  },
218
242
  };
219
243
  }
@@ -222,6 +246,6 @@ export class AztecAddNullifiedNoteSerializer
222
246
  * Pre-instantiated serializer instances for Aztec note-related RPC methods.
223
247
  * These instances can be used directly by the RPC handler implementation.
224
248
  */
225
- export const aztecGetIncomingNotesSerializer = new AztecGetIncomingNotesSerializer();
249
+ export const aztecGetNotesSerializer = new AztecGetNotesSerializer();
226
250
  export const aztecAddNoteSerializer = new AztecAddNoteSerializer();
227
251
  export const aztecAddNullifiedNoteSerializer = new AztecAddNullifiedNoteSerializer();
@@ -1,237 +1,161 @@
1
- import { PrivateExecutionResult, TxProvingResult } from '@aztec/circuit-types';
2
- import type {
3
- CountedContractClassLog,
4
- CountedPublicExecutionRequest,
5
- NoteAndSlot,
6
- PublicExecutionRequest,
7
- } from '@aztec/circuit-types';
8
- import type {
9
- ClientIvcProof,
10
- PrivateCircuitPublicInputs,
11
- PrivateKernelTailCircuitPublicInputs,
12
- } from '@aztec/circuits.js';
13
- import { Fr } from '@aztec/aztec.js';
14
-
15
1
  /**
16
- * Interface representing the serialized form of a private execution result.
17
- * Contains all data needed to reconstruct a PrivateExecutionResult instance.
2
+ * @module transaction-utils
3
+ * Utilities for serializing and deserializing Aztec transaction execution requests.
4
+ * These utilities handle the conversion between native Aztec types and JSON-RPC compatible formats.
18
5
  */
19
- interface SerializedPrivateExecutionResultData {
20
- acir: string;
21
- vk: string;
22
- partialWitness: [number, string][];
23
- publicInputs: PrivateCircuitPublicInputs;
24
- noteHashLeafIndexMap: [string, string][];
25
- newNotes: NoteAndSlot[];
26
- noteHashNullifierCounterMap: [number, number][];
27
- returnValues: string[];
28
- nestedExecutions: SerializedPrivateExecutionResultData[];
29
- enqueuedPublicFunctionCalls: CountedPublicExecutionRequest[];
30
- publicTeardownFunctionCall: PublicExecutionRequest;
31
- contractClassLogs: CountedContractClassLog[];
32
- }
6
+
7
+ import { HashedValues, FunctionCall, AuthWitness } from '@aztec/circuit-types';
8
+ import { AztecAddress, Fr, FunctionSelector, GasSettings } from '@aztec/circuits.js';
9
+ import type { FunctionType, AbiType } from '@aztec/foundation/abi';
10
+ import type { ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
11
+ import { NoFeePaymentMethod } from '@aztec/aztec.js';
33
12
 
34
13
  /**
35
- * Extends PrivateExecutionResult to add serialization capabilities.
36
- * Provides methods to convert private execution results to/from JSON format for RPC transport.
14
+ * Interface representing the serialized form of a function call.
15
+ * This structure maps the native FunctionCall type to a JSON-serializable format
16
+ * where complex Aztec types are converted to strings.
17
+ *
18
+ * @property name - The name of the function being called
19
+ * @property to - The target contract address as a string
20
+ * @property selector - The function selector as a string
21
+ * @property type - The function type (public/private)
22
+ * @property isStatic - Whether the function is static (read-only)
23
+ * @property args - Array of function arguments as strings
24
+ * @property returnTypes - Array of return type definitions
37
25
  */
38
- export class SerializablePrivateExecutionResult extends PrivateExecutionResult {
39
- /**
40
- * Creates a SerializablePrivateExecutionResult from a PrivateExecutionResult instance.
41
- * @param result - The PrivateExecutionResult to convert
42
- * @returns A new SerializablePrivateExecutionResult instance
43
- */
44
- static from(result: PrivateExecutionResult): SerializablePrivateExecutionResult {
45
- return new SerializablePrivateExecutionResult(
46
- result.acir,
47
- result.vk,
48
- result.partialWitness,
49
- result.publicInputs,
50
- result.noteHashLeafIndexMap,
51
- result.newNotes,
52
- result.noteHashNullifierCounterMap,
53
- result.returnValues,
54
- result.nestedExecutions,
55
- result.enqueuedPublicFunctionCalls,
56
- result.publicTeardownFunctionCall,
57
- result.contractClassLogs,
58
- );
59
- }
60
-
61
- /**
62
- * Converts the execution result to a JSON-serializable format.
63
- * Handles conversion of complex types like Buffers, Maps, and nested execution results.
64
- * @returns The serialized execution result data
65
- */
66
- toJSON(): SerializedPrivateExecutionResultData {
67
- return {
68
- acir: this.acir.toString('base64'),
69
- vk: this.vk.toString('base64'),
70
- partialWitness: Array.from(this.partialWitness.entries()),
71
- publicInputs: this.publicInputs,
72
- noteHashLeafIndexMap: Array.from(this.noteHashLeafIndexMap.entries()).map(([k, v]) => [
73
- k.toString(),
74
- v.toString(),
75
- ]),
76
- newNotes: this.newNotes,
77
- noteHashNullifierCounterMap: Array.from(this.noteHashNullifierCounterMap.entries()),
78
- returnValues: this.returnValues.map((fr: Fr) => fr.toString()),
79
- nestedExecutions: this.nestedExecutions.map((exec: PrivateExecutionResult) =>
80
- exec instanceof SerializablePrivateExecutionResult
81
- ? exec.toJSON()
82
- : new SerializablePrivateExecutionResult(
83
- exec.acir,
84
- exec.vk,
85
- exec.partialWitness,
86
- exec.publicInputs,
87
- exec.noteHashLeafIndexMap,
88
- exec.newNotes,
89
- exec.noteHashNullifierCounterMap,
90
- exec.returnValues,
91
- exec.nestedExecutions,
92
- exec.enqueuedPublicFunctionCalls,
93
- exec.publicTeardownFunctionCall,
94
- exec.contractClassLogs,
95
- ).toJSON(),
96
- ),
97
- enqueuedPublicFunctionCalls: this.enqueuedPublicFunctionCalls,
98
- publicTeardownFunctionCall: this.publicTeardownFunctionCall,
99
- contractClassLogs: this.contractClassLogs,
100
- };
101
- }
102
-
103
- /**
104
- * Creates a SerializablePrivateExecutionResult from JSON data.
105
- * @param json - JSON string or pre-parsed data object
106
- * @returns A new SerializablePrivateExecutionResult instance
107
- */
108
- static fromJSON(json: string | SerializedPrivateExecutionResultData): SerializablePrivateExecutionResult {
109
- const data: SerializedPrivateExecutionResultData = typeof json === 'string' ? JSON.parse(json) : json;
110
-
111
- return new SerializablePrivateExecutionResult(
112
- Buffer.from(data.acir, 'base64'),
113
- Buffer.from(data.vk, 'base64'),
114
- new Map(data.partialWitness),
115
- data.publicInputs,
116
- new Map(data.noteHashLeafIndexMap.map(([k, v]) => [BigInt(k), BigInt(v)])),
117
- data.newNotes,
118
- new Map(data.noteHashNullifierCounterMap),
119
- data.returnValues.map((str: string) => Fr.fromString(str)),
120
- data.nestedExecutions.map((exec: SerializedPrivateExecutionResultData) =>
121
- SerializablePrivateExecutionResult.fromJSON(exec),
122
- ),
123
- data.enqueuedPublicFunctionCalls,
124
- data.publicTeardownFunctionCall,
125
- data.contractClassLogs,
126
- );
127
- }
128
-
129
- /**
130
- * Compares this execution result with another for equality.
131
- * @param other - The execution result to compare against
132
- * @returns True if the execution results are equivalent
133
- */
134
- equals(other: PrivateExecutionResult): boolean {
135
- const thisJson = JSON.stringify(SerializablePrivateExecutionResult.from(this).toJSON());
136
- const otherJson = JSON.stringify(SerializablePrivateExecutionResult.from(other).toJSON());
137
- return thisJson === otherJson;
138
- }
139
-
140
- toComparable(): SerializedPrivateExecutionResultData {
141
- return JSON.parse(JSON.stringify(this.toJSON()));
142
- }
26
+ interface SerializedFunctionCall {
27
+ name: string;
28
+ to: string;
29
+ selector: string;
30
+ type: FunctionType;
31
+ isStatic: boolean;
32
+ args: string[];
33
+ returnTypes: AbiType[];
143
34
  }
144
35
 
145
36
  /**
146
- * Interface representing the serialized form of a transaction proving result.
147
- * Contains the private execution result, public inputs, and client IVC proof.
37
+ * Interface representing the serialized form of an execution request initialization.
38
+ * This structure maps the ExecutionRequestInit type to a JSON-serializable format
39
+ * where complex Aztec types are converted to strings.
40
+ *
41
+ * @property calls - Array of serialized function calls
42
+ * @property authWitnesses - Optional array of authentication witness strings
43
+ * @property hashedArguments - Optional array of hashed argument values as base64 strings
44
+ * @property fee - Fee settings including gas configuration
45
+ * @property nonce - Optional transaction nonce as a string
46
+ * @property cancellable - Optional flag indicating if the transaction can be cancelled
148
47
  */
149
- interface SerializedTxProvingResultData {
150
- privateExecutionResult: ReturnType<SerializablePrivateExecutionResult['toJSON']>;
151
- publicInputs: PrivateKernelTailCircuitPublicInputs;
152
- clientIvcProof: ClientIvcProof;
48
+ interface SerializedExecutionRequestInit {
49
+ calls: SerializedFunctionCall[];
50
+ authWitnesses?: string[];
51
+ hashedArguments?: string[];
52
+ fee: {
53
+ gasSettings: string;
54
+ };
55
+ nonce?: string;
56
+ cancellable?: boolean;
153
57
  }
154
58
 
155
59
  /**
156
- * Extends TxProvingResult to add serialization capabilities.
157
- * Provides methods to convert transaction proving results to/from JSON format for RPC transport.
60
+ * Serializes an ExecutionRequestInit object to a string for JSON-RPC transport.
61
+ * This function converts a native Aztec transaction execution request into a format
62
+ * that can be safely transmitted over JSON-RPC, handling the conversion of complex
63
+ * types like addresses, field elements, and function selectors to strings.
64
+ *
65
+ * Note: The fee payment method is not serialized as it contains async methods.
66
+ * The deserializer will use a default NoFeePaymentMethod which should be replaced
67
+ * by the caller with an appropriate implementation.
68
+ *
69
+ * @param init - The ExecutionRequestInit object to serialize, containing:
70
+ * - calls: Array of function calls to execute
71
+ * - fee: Gas settings and payment method
72
+ * - authWitnesses: Optional authentication proofs
73
+ * - hashedArguments: Optional pre-hashed arguments
74
+ * - nonce: Optional transaction nonce
75
+ * - cancellable: Optional cancellation flag
76
+ * @returns A JSON string representation of the serialized data, with all complex
77
+ * Aztec types converted to string representations
78
+ * @throws If any of the complex types cannot be serialized
158
79
  */
159
- export class SerializableTxProvingResult extends TxProvingResult {
160
- /**
161
- * Creates a SerializableTxProvingResult from a TxProvingResult instance.
162
- * @param result - The TxProvingResult to convert
163
- * @returns A new SerializableTxProvingResult instance
164
- */
165
- static from(result: TxProvingResult): SerializableTxProvingResult {
166
- return new SerializableTxProvingResult(
167
- result.privateExecutionResult,
168
- result.publicInputs,
169
- result.clientIvcProof,
170
- );
80
+ export function serializeExecutionRequestInit(init: ExecutionRequestInit): string {
81
+ const serialized: SerializedExecutionRequestInit = {
82
+ calls: init.calls.map((call) => ({
83
+ name: call.name,
84
+ to: call.to.toString(),
85
+ selector: call.selector.toString(),
86
+ type: call.type,
87
+ isStatic: call.isStatic,
88
+ args: call.args.map((arg) => arg.toString()),
89
+ returnTypes: call.returnTypes,
90
+ })),
91
+ fee: {
92
+ gasSettings: init.fee.gasSettings.toBuffer().toString('base64'),
93
+ },
94
+ };
95
+
96
+ if (init.authWitnesses) {
97
+ serialized.authWitnesses = init.authWitnesses.map((w) => w.toString());
171
98
  }
172
99
 
173
- /**
174
- * Converts the proving result to a JSON-serializable format.
175
- * @returns The serialized proving result data
176
- */
177
- toJSON(): SerializedTxProvingResultData {
178
- return {
179
- privateExecutionResult: SerializablePrivateExecutionResult.from(this.privateExecutionResult).toJSON(),
180
- publicInputs: this.publicInputs,
181
- clientIvcProof: this.clientIvcProof,
182
- };
100
+ if (init.hashedArguments) {
101
+ serialized.hashedArguments = init.hashedArguments.map((ha) => ha.toBuffer().toString('base64'));
183
102
  }
184
103
 
185
- /**
186
- * Creates a SerializableTxProvingResult from JSON data.
187
- * @param json - JSON string or pre-parsed data object
188
- * @returns A new SerializableTxProvingResult instance
189
- */
190
- static fromJSON(json: string | SerializedTxProvingResultData): SerializableTxProvingResult {
191
- const data: SerializedTxProvingResultData = typeof json === 'string' ? JSON.parse(json) : json;
192
-
193
- return new SerializableTxProvingResult(
194
- SerializablePrivateExecutionResult.fromJSON(data.privateExecutionResult),
195
- data.publicInputs,
196
- data.clientIvcProof,
197
- );
104
+ if (init.nonce) {
105
+ serialized.nonce = init.nonce.toString();
198
106
  }
199
107
 
200
- /**
201
- * Compares this proving result with another for equality.
202
- * @param other - The proving result to compare against
203
- * @returns True if the proving results are equivalent
204
- */
205
- equals(other: TxProvingResult): boolean {
206
- const thisJson = JSON.stringify(SerializableTxProvingResult.from(this).toJSON());
207
- const otherJson = JSON.stringify(SerializableTxProvingResult.from(other).toJSON());
208
- return thisJson === otherJson;
108
+ if (init.cancellable !== undefined) {
109
+ serialized.cancellable = init.cancellable;
209
110
  }
210
111
 
211
- toComparable(): SerializedTxProvingResultData {
212
- return JSON.parse(JSON.stringify(this.toJSON()));
213
- }
214
- }
215
-
216
- /**
217
- * Utility function to compare two PrivateExecutionResult instances for equality.
218
- * @param a - First execution result
219
- * @param b - Second execution result
220
- * @returns True if the execution results are equivalent
221
- */
222
- export function comparePrivateExecutionResults(
223
- a: PrivateExecutionResult,
224
- b: PrivateExecutionResult,
225
- ): boolean {
226
- return SerializablePrivateExecutionResult.from(a).equals(b);
112
+ return JSON.stringify(serialized);
227
113
  }
228
114
 
229
115
  /**
230
- * Utility function to compare two TxProvingResult instances for equality.
231
- * @param a - First proving result
232
- * @param b - Second proving result
233
- * @returns True if the proving results are equivalent
116
+ * Deserializes a string into an ExecutionRequestInit object for use in the Aztec protocol.
117
+ * This function reconstructs a native Aztec transaction execution request from its
118
+ * JSON-RPC serialized form, converting string representations back into their
119
+ * appropriate Aztec types.
120
+ *
121
+ * Note: A default NoFeePaymentMethod is used for the fee payment method.
122
+ * The caller should override this with the appropriate implementation based on
123
+ * their fee payment requirements.
124
+ *
125
+ * @param data - The serialized string data containing:
126
+ * - calls: Array of serialized function calls
127
+ * - fee: Serialized gas settings
128
+ * - authWitnesses: Optional serialized authentication proofs
129
+ * - hashedArguments: Optional serialized hashed arguments
130
+ * - nonce: Optional serialized nonce
131
+ * - cancellable: Optional cancellation flag
132
+ * @returns The deserialized ExecutionRequestInit object with all string representations
133
+ * converted back to their native Aztec types
134
+ * @throws If any of the serialized data cannot be properly deserialized into valid Aztec types
234
135
  */
235
- export function compareTxProvingResults(a: TxProvingResult, b: TxProvingResult): boolean {
236
- return SerializableTxProvingResult.from(a).equals(b);
136
+ export function deserializeExecutionRequestInit(data: string): ExecutionRequestInit {
137
+ const parsed: SerializedExecutionRequestInit = JSON.parse(data);
138
+
139
+ return {
140
+ calls: parsed.calls.map(
141
+ (call) =>
142
+ new FunctionCall(
143
+ call.name,
144
+ AztecAddress.fromString(call.to),
145
+ FunctionSelector.fromString(call.selector),
146
+ call.type,
147
+ call.isStatic,
148
+ call.args.map((arg) => Fr.fromString(arg)),
149
+ call.returnTypes,
150
+ ),
151
+ ),
152
+ fee: {
153
+ gasSettings: GasSettings.fromBuffer(Buffer.from(parsed.fee.gasSettings, 'base64')),
154
+ paymentMethod: new NoFeePaymentMethod(), // Default, caller should override
155
+ },
156
+ authWitnesses: parsed.authWitnesses?.map((w) => AuthWitness.fromString(w)),
157
+ hashedArguments: parsed.hashedArguments?.map((ha) => HashedValues.fromBuffer(Buffer.from(ha, 'base64'))),
158
+ nonce: parsed.nonce ? Fr.fromString(parsed.nonce) : undefined,
159
+ cancellable: parsed.cancellable,
160
+ };
237
161
  }