@walletmesh/aztec-rpc-wallet 0.1.0 → 0.2.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 +18 -0
- package/README.md +4 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/aztecRemoteWallet.d.ts +7 -6
- package/dist/aztecRemoteWallet.d.ts.map +1 -1
- package/dist/aztecRemoteWallet.js +15 -10
- package/dist/chainProvider.d.ts.map +1 -1
- package/dist/chainProvider.js +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
- package/dist/handlers/aztecAccountWallet.js +23 -23
- package/dist/handlers/transactions.d.ts.map +1 -1
- package/dist/handlers/transactions.js +11 -3
- package/dist/serializers/account.d.ts +19 -22
- package/dist/serializers/account.d.ts.map +1 -1
- package/dist/serializers/account.js +44 -45
- package/dist/serializers/contract.d.ts +11 -63
- package/dist/serializers/contract.d.ts.map +1 -1
- package/dist/serializers/contract.js +67 -153
- package/dist/serializers/index.d.ts +1 -4
- package/dist/serializers/index.d.ts.map +1 -1
- package/dist/serializers/index.js +12 -12
- package/dist/serializers/log.d.ts +38 -85
- package/dist/serializers/log.d.ts.map +1 -1
- package/dist/serializers/log.js +106 -115
- package/dist/serializers/note.d.ts +24 -27
- package/dist/serializers/note.d.ts.map +1 -1
- package/dist/serializers/note.js +67 -41
- package/dist/serializers/transaction-utils.d.ts +44 -100
- package/dist/serializers/transaction-utils.d.ts.map +1 -1
- package/dist/serializers/transaction-utils.js +89 -116
- package/dist/serializers/transaction.d.ts +15 -18
- package/dist/serializers/transaction.d.ts.map +1 -1
- package/dist/serializers/transaction.js +51 -62
- package/dist/types.d.ts +9 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +9 -9
- package/src/aztecRemoteWallet.test.ts +34 -33
- package/src/aztecRemoteWallet.ts +25 -15
- package/src/chainProvider.ts +1 -7
- package/src/errors.ts +0 -1
- package/src/handlers/aztecAccountWallet.test.ts +78 -75
- package/src/handlers/aztecAccountWallet.ts +33 -36
- package/src/handlers/transactions.ts +16 -2
- package/src/serializers/account.test.ts +18 -17
- package/src/serializers/account.ts +46 -64
- package/src/serializers/contract.test.ts +14 -16
- package/src/serializers/contract.ts +77 -171
- package/src/serializers/index.test.ts +20 -8
- package/src/serializers/index.ts +16 -32
- package/src/serializers/log.test.ts +201 -28
- package/src/serializers/log.ts +162 -153
- package/src/serializers/note.test.ts +26 -28
- package/src/serializers/note.ts +71 -48
- package/src/serializers/transaction-utils.ts +147 -210
- package/src/serializers/transaction.test.ts +190 -30
- package/src/serializers/transaction.ts +62 -83
- package/src/types.ts +10 -9
- package/tsconfig.json +1 -1
- package/vitest.config.ts +1 -1
- package/dist/serializers/contract-utils.d.ts +0 -40
- package/dist/serializers/contract-utils.d.ts.map +0 -1
- package/dist/serializers/contract-utils.js +0 -102
- package/dist/serializers/core.d.ts +0 -110
- package/dist/serializers/core.d.ts.map +0 -1
- package/dist/serializers/core.js +0 -130
- package/dist/serializers/types.d.ts +0 -49
- package/dist/serializers/types.d.ts.map +0 -1
- package/dist/serializers/types.js +0 -22
- package/src/serializers/contract-utils.ts +0 -104
- package/src/serializers/core.test.ts +0 -56
- package/src/serializers/core.ts +0 -141
- package/src/serializers/types.ts +0 -58
package/src/serializers/note.ts
CHANGED
@@ -1,81 +1,104 @@
|
|
1
1
|
import type { AztecWalletMethodMap } from '../types.js';
|
2
|
-
import type { JSONRPCSerializedData, JSONRPCSerializer } from '
|
3
|
-
import {
|
4
|
-
import
|
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, type NotesFilter } from '@aztec/circuit-types';
|
4
|
+
import { ExtendedNote, AztecAddress, Fr } from '@aztec/aztec.js';
|
7
5
|
|
8
6
|
/**
|
9
|
-
* Serializer for the
|
10
|
-
* Handles serialization of
|
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
|
10
|
+
export class AztecGetNotesSerializer
|
14
11
|
implements
|
15
12
|
JSONRPCSerializer<
|
16
|
-
AztecWalletMethodMap['
|
17
|
-
AztecWalletMethodMap['
|
13
|
+
AztecWalletMethodMap['aztec_getNotes']['params'],
|
14
|
+
AztecWalletMethodMap['aztec_getNotes']['result']
|
18
15
|
>
|
19
16
|
{
|
20
17
|
params = {
|
21
18
|
/**
|
22
|
-
* Serializes
|
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
|
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['
|
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:
|
42
|
+
serialized: JSON.stringify({ filter: serializedFilter }),
|
35
43
|
};
|
36
44
|
},
|
37
45
|
/**
|
38
|
-
* Deserializes
|
39
|
-
* @param
|
46
|
+
* Deserializes notes filter parameters from RPC transport.
|
47
|
+
* @param _method - The RPC method name
|
40
48
|
* @param data - The serialized filter data
|
41
49
|
* @returns Deserialized filter parameters
|
42
50
|
*/
|
43
51
|
deserialize: (
|
44
|
-
|
52
|
+
_method: string,
|
45
53
|
data: JSONRPCSerializedData,
|
46
|
-
): AztecWalletMethodMap['
|
47
|
-
const filter = JSON.parse(
|
48
|
-
|
54
|
+
): 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 {
|
70
|
+
filter: notesFilter,
|
71
|
+
};
|
49
72
|
},
|
50
73
|
};
|
51
74
|
|
52
75
|
result = {
|
53
76
|
/**
|
54
|
-
* Serializes the
|
77
|
+
* Serializes the notes query result.
|
55
78
|
* @param method - The RPC method name
|
56
79
|
* @param value - Array of unique notes matching the filter criteria
|
57
80
|
* @returns Serialized note array
|
58
81
|
*/
|
59
82
|
serialize: (
|
60
83
|
method: string,
|
61
|
-
value: AztecWalletMethodMap['
|
84
|
+
value: AztecWalletMethodMap['aztec_getNotes']['result'],
|
62
85
|
): JSONRPCSerializedData => {
|
63
86
|
return {
|
64
87
|
method,
|
65
|
-
serialized:
|
88
|
+
serialized: JSON.stringify(value.map((n) => n.toString())),
|
66
89
|
};
|
67
90
|
},
|
68
91
|
/**
|
69
|
-
* Deserializes the
|
70
|
-
* @param
|
92
|
+
* Deserializes the notes query result.
|
93
|
+
* @param _method - The RPC method name
|
71
94
|
* @param data - The serialized note array data
|
72
95
|
* @returns Array of deserialized unique notes
|
73
96
|
*/
|
74
97
|
deserialize: (
|
75
|
-
|
98
|
+
_method: string,
|
76
99
|
data: JSONRPCSerializedData,
|
77
|
-
): AztecWalletMethodMap['
|
78
|
-
return JSON.parse(
|
100
|
+
): AztecWalletMethodMap['aztec_getNotes']['result'] => {
|
101
|
+
return JSON.parse(data.serialized).map((n: string) => UniqueNote.fromString(n));
|
79
102
|
},
|
80
103
|
};
|
81
104
|
}
|
@@ -83,7 +106,6 @@ export class AztecGetIncomingNotesSerializer
|
|
83
106
|
/**
|
84
107
|
* Serializer for the aztec_addNote RPC method.
|
85
108
|
* 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
109
|
*/
|
88
110
|
export class AztecAddNoteSerializer
|
89
111
|
implements
|
@@ -106,20 +128,21 @@ export class AztecAddNoteSerializer
|
|
106
128
|
const { note } = value;
|
107
129
|
return {
|
108
130
|
method,
|
109
|
-
serialized:
|
131
|
+
serialized: JSON.stringify({ note: note.toBuffer().toString('base64') }),
|
110
132
|
};
|
111
133
|
},
|
112
134
|
/**
|
113
135
|
* Deserializes note addition parameters from RPC transport.
|
114
|
-
* @param
|
136
|
+
* @param _method - The RPC method name
|
115
137
|
* @param data - The serialized note data
|
116
138
|
* @returns Deserialized note parameters
|
117
139
|
*/
|
118
140
|
deserialize: (
|
119
|
-
|
141
|
+
_method: string,
|
120
142
|
data: JSONRPCSerializedData,
|
121
143
|
): AztecWalletMethodMap['aztec_addNote']['params'] => {
|
122
|
-
const note =
|
144
|
+
const { note: noteBase64 } = JSON.parse(data.serialized);
|
145
|
+
const note = ExtendedNote.fromBuffer(Buffer.from(noteBase64, 'base64'));
|
123
146
|
return { note };
|
124
147
|
},
|
125
148
|
};
|
@@ -134,17 +157,17 @@ export class AztecAddNoteSerializer
|
|
134
157
|
serialize: (method: string, value: boolean): JSONRPCSerializedData => {
|
135
158
|
return {
|
136
159
|
method,
|
137
|
-
serialized:
|
160
|
+
serialized: JSON.stringify(value),
|
138
161
|
};
|
139
162
|
},
|
140
163
|
/**
|
141
164
|
* Deserializes the note addition result.
|
142
|
-
* @param
|
165
|
+
* @param _method - The RPC method name
|
143
166
|
* @param data - The serialized result data
|
144
167
|
* @returns Boolean indicating success
|
145
168
|
*/
|
146
|
-
deserialize: (
|
147
|
-
return JSON.parse(
|
169
|
+
deserialize: (_method: string, data: JSONRPCSerializedData): boolean => {
|
170
|
+
return JSON.parse(data.serialized);
|
148
171
|
},
|
149
172
|
};
|
150
173
|
}
|
@@ -152,7 +175,6 @@ export class AztecAddNoteSerializer
|
|
152
175
|
/**
|
153
176
|
* Serializer for the aztec_addNullifiedNote RPC method.
|
154
177
|
* 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
178
|
*/
|
157
179
|
export class AztecAddNullifiedNoteSerializer
|
158
180
|
implements
|
@@ -175,20 +197,21 @@ export class AztecAddNullifiedNoteSerializer
|
|
175
197
|
const { note } = value;
|
176
198
|
return {
|
177
199
|
method,
|
178
|
-
serialized:
|
200
|
+
serialized: JSON.stringify({ note: note.toBuffer().toString('base64') }),
|
179
201
|
};
|
180
202
|
},
|
181
203
|
/**
|
182
204
|
* Deserializes nullified note addition parameters from RPC transport.
|
183
|
-
* @param
|
205
|
+
* @param _method - The RPC method name
|
184
206
|
* @param data - The serialized note data
|
185
207
|
* @returns Deserialized note parameters
|
186
208
|
*/
|
187
209
|
deserialize: (
|
188
|
-
|
210
|
+
_method: string,
|
189
211
|
data: JSONRPCSerializedData,
|
190
212
|
): AztecWalletMethodMap['aztec_addNullifiedNote']['params'] => {
|
191
|
-
const note =
|
213
|
+
const { note: noteBase64 } = JSON.parse(data.serialized);
|
214
|
+
const note = ExtendedNote.fromBuffer(Buffer.from(noteBase64, 'base64'));
|
192
215
|
return { note };
|
193
216
|
},
|
194
217
|
};
|
@@ -203,17 +226,17 @@ export class AztecAddNullifiedNoteSerializer
|
|
203
226
|
serialize: (method: string, value: boolean): JSONRPCSerializedData => {
|
204
227
|
return {
|
205
228
|
method,
|
206
|
-
serialized:
|
229
|
+
serialized: JSON.stringify(value),
|
207
230
|
};
|
208
231
|
},
|
209
232
|
/**
|
210
233
|
* Deserializes the nullified note addition result.
|
211
|
-
* @param
|
234
|
+
* @param _method - The RPC method name
|
212
235
|
* @param data - The serialized result data
|
213
236
|
* @returns Boolean indicating success
|
214
237
|
*/
|
215
|
-
deserialize: (
|
216
|
-
return JSON.parse(
|
238
|
+
deserialize: (_method: string, data: JSONRPCSerializedData): boolean => {
|
239
|
+
return JSON.parse(data.serialized);
|
217
240
|
},
|
218
241
|
};
|
219
242
|
}
|
@@ -222,6 +245,6 @@ export class AztecAddNullifiedNoteSerializer
|
|
222
245
|
* Pre-instantiated serializer instances for Aztec note-related RPC methods.
|
223
246
|
* These instances can be used directly by the RPC handler implementation.
|
224
247
|
*/
|
225
|
-
export const
|
248
|
+
export const aztecGetNotesSerializer = new AztecGetNotesSerializer();
|
226
249
|
export const aztecAddNoteSerializer = new AztecAddNoteSerializer();
|
227
250
|
export const aztecAddNullifiedNoteSerializer = new AztecAddNullifiedNoteSerializer();
|
@@ -1,237 +1,174 @@
|
|
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
|
-
*
|
17
|
-
*
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
*
|
36
|
-
*
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
147
|
-
*
|
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
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
*
|
157
|
-
*
|
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
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
212
|
-
return JSON.parse(JSON.stringify(this.toJSON()));
|
213
|
-
}
|
112
|
+
return JSON.stringify(serialized);
|
214
113
|
}
|
215
114
|
|
216
115
|
/**
|
217
|
-
*
|
218
|
-
*
|
219
|
-
*
|
220
|
-
*
|
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
|
221
135
|
*/
|
222
|
-
export function
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
136
|
+
export function deserializeExecutionRequestInit(data: string): ExecutionRequestInit {
|
137
|
+
const parsed: SerializedExecutionRequestInit = JSON.parse(data);
|
138
|
+
|
139
|
+
const result: ExecutionRequestInit = {
|
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
|
+
};
|
157
|
+
|
158
|
+
if (parsed.authWitnesses) {
|
159
|
+
result.authWitnesses = parsed.authWitnesses.map((w) => AuthWitness.fromString(w));
|
160
|
+
}
|
161
|
+
if (parsed.hashedArguments) {
|
162
|
+
result.hashedArguments = parsed.hashedArguments.map((ha) =>
|
163
|
+
HashedValues.fromBuffer(Buffer.from(ha, 'base64')),
|
164
|
+
);
|
165
|
+
}
|
166
|
+
if (parsed.nonce) {
|
167
|
+
result.nonce = Fr.fromString(parsed.nonce);
|
168
|
+
}
|
169
|
+
if (parsed.cancellable !== undefined) {
|
170
|
+
result.cancellable = parsed.cancellable;
|
171
|
+
}
|
228
172
|
|
229
|
-
|
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
|
234
|
-
*/
|
235
|
-
export function compareTxProvingResults(a: TxProvingResult, b: TxProvingResult): boolean {
|
236
|
-
return SerializableTxProvingResult.from(a).equals(b);
|
173
|
+
return result;
|
237
174
|
}
|