@walletmesh/aztec-rpc-wallet 0.1.0 → 0.1.1
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 +6 -0
- 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 -9
- package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
- package/dist/handlers/aztecAccountWallet.js +22 -22
- package/dist/serializers/account.d.ts +4 -7
- package/dist/serializers/account.d.ts.map +1 -1
- package/dist/serializers/account.js +28 -29
- package/dist/serializers/contract.d.ts +4 -56
- package/dist/serializers/contract.d.ts.map +1 -1
- package/dist/serializers/contract.js +62 -148
- 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 +36 -83
- package/dist/serializers/log.d.ts.map +1 -1
- package/dist/serializers/log.js +96 -107
- package/dist/serializers/note.d.ts +14 -17
- package/dist/serializers/note.d.ts.map +1 -1
- package/dist/serializers/note.js +52 -29
- 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 +82 -118
- package/dist/serializers/transaction.d.ts +3 -6
- package/dist/serializers/transaction.d.ts.map +1 -1
- package/dist/serializers/transaction.js +39 -50
- package/dist/types.d.ts +8 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +5 -5
- package/src/aztecRemoteWallet.test.ts +33 -29
- package/src/aztecRemoteWallet.ts +25 -14
- package/src/handlers/aztecAccountWallet.test.ts +78 -75
- package/src/handlers/aztecAccountWallet.ts +32 -35
- package/src/serializers/account.test.ts +18 -17
- package/src/serializers/account.ts +31 -49
- package/src/serializers/contract.test.ts +14 -16
- package/src/serializers/contract.ts +75 -164
- package/src/serializers/index.test.ts +20 -8
- package/src/serializers/index.ts +16 -20
- package/src/serializers/log.test.ts +201 -28
- package/src/serializers/log.ts +153 -146
- package/src/serializers/note.test.ts +26 -28
- package/src/serializers/note.ts +60 -36
- package/src/serializers/transaction-utils.ts +135 -211
- package/src/serializers/transaction.test.ts +190 -30
- package/src/serializers/transaction.ts +51 -72
- package/src/types.ts +9 -8
- 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,41 +1,49 @@
|
|
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 } 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
|
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['
|
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
|
+
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
|
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['
|
85
|
+
value: AztecWalletMethodMap['aztec_getNotes']['result'],
|
62
86
|
): JSONRPCSerializedData => {
|
63
87
|
return {
|
64
88
|
method,
|
65
|
-
serialized:
|
89
|
+
serialized: JSON.stringify(value.map((n) => n.toString())),
|
66
90
|
};
|
67
91
|
},
|
68
92
|
/**
|
69
|
-
* Deserializes the
|
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['
|
78
|
-
return JSON.parse(
|
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:
|
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 =
|
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:
|
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(
|
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:
|
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 =
|
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:
|
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(
|
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
|
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
|
-
*
|
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
|
-
}
|
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
|
-
*
|
231
|
-
*
|
232
|
-
*
|
233
|
-
*
|
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
|
236
|
-
|
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
|
}
|