@walletmesh/aztec-rpc-wallet 0.1.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 +7 -0
- package/LICENSE +201 -0
- package/README.md +260 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/aztecRemoteWallet.d.ts +73 -0
- package/dist/aztecRemoteWallet.d.ts.map +1 -0
- package/dist/aztecRemoteWallet.js +354 -0
- package/dist/chainProvider.d.ts +56 -0
- package/dist/chainProvider.d.ts.map +1 -0
- package/dist/chainProvider.js +98 -0
- package/dist/contractArtifactCache.d.ts +50 -0
- package/dist/contractArtifactCache.d.ts.map +1 -0
- package/dist/contractArtifactCache.js +66 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +62 -0
- package/dist/handlers/aztecAccountWallet.d.ts +4 -0
- package/dist/handlers/aztecAccountWallet.d.ts.map +1 -0
- package/dist/handlers/aztecAccountWallet.js +329 -0
- package/dist/handlers/transactions.d.ts +21 -0
- package/dist/handlers/transactions.d.ts.map +1 -0
- package/dist/handlers/transactions.js +90 -0
- package/dist/handlers.d.ts +27 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/handlers.js +55 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/provider.d.ts +105 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +160 -0
- package/dist/serializers/account.d.ts +167 -0
- package/dist/serializers/account.d.ts.map +1 -0
- package/dist/serializers/account.js +245 -0
- package/dist/serializers/contract-utils.d.ts +40 -0
- package/dist/serializers/contract-utils.d.ts.map +1 -0
- package/dist/serializers/contract-utils.js +102 -0
- package/dist/serializers/contract.d.ts +168 -0
- package/dist/serializers/contract.d.ts.map +1 -0
- package/dist/serializers/contract.js +268 -0
- package/dist/serializers/core.d.ts +110 -0
- package/dist/serializers/core.d.ts.map +1 -0
- package/dist/serializers/core.js +130 -0
- package/dist/serializers/index.d.ts +28 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/serializers/index.js +159 -0
- package/dist/serializers/log.d.ts +113 -0
- package/dist/serializers/log.d.ts.map +1 -0
- package/dist/serializers/log.js +231 -0
- package/dist/serializers/note.d.ts +127 -0
- package/dist/serializers/note.d.ts.map +1 -0
- package/dist/serializers/note.js +182 -0
- package/dist/serializers/transaction-utils.d.ts +107 -0
- package/dist/serializers/transaction-utils.d.ts.map +1 -0
- package/dist/serializers/transaction-utils.js +130 -0
- package/dist/serializers/transaction.d.ts +103 -0
- package/dist/serializers/transaction.d.ts.map +1 -0
- package/dist/serializers/transaction.js +238 -0
- package/dist/serializers/types.d.ts +49 -0
- package/dist/serializers/types.d.ts.map +1 -0
- package/dist/serializers/types.js +22 -0
- package/dist/types.d.ts +391 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/wallet.d.ts +62 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +77 -0
- package/package.json +44 -0
- package/src/aztecRemoteWallet.test.ts +542 -0
- package/src/aztecRemoteWallet.ts +484 -0
- package/src/chainProvider.test.ts +322 -0
- package/src/chainProvider.ts +122 -0
- package/src/contractArtifactCache.test.ts +126 -0
- package/src/contractArtifactCache.ts +75 -0
- package/src/errors.ts +71 -0
- package/src/handlers/aztecAccountWallet.test.ts +720 -0
- package/src/handlers/aztecAccountWallet.ts +593 -0
- package/src/handlers/transactions.ts +110 -0
- package/src/handlers.test.ts +270 -0
- package/src/handlers.ts +70 -0
- package/src/index.test.ts +23 -0
- package/src/index.ts +64 -0
- package/src/provider.test.ts +276 -0
- package/src/provider.ts +189 -0
- package/src/serializers/account.test.ts +125 -0
- package/src/serializers/account.ts +319 -0
- package/src/serializers/contract-utils.ts +104 -0
- package/src/serializers/contract.test.ts +162 -0
- package/src/serializers/contract.ts +350 -0
- package/src/serializers/core.test.ts +56 -0
- package/src/serializers/core.ts +141 -0
- package/src/serializers/index.test.ts +122 -0
- package/src/serializers/index.ts +213 -0
- package/src/serializers/log.test.ts +119 -0
- package/src/serializers/log.ts +283 -0
- package/src/serializers/note.test.ts +100 -0
- package/src/serializers/note.ts +227 -0
- package/src/serializers/transaction-utils.ts +237 -0
- package/src/serializers/transaction.test.ts +153 -0
- package/src/serializers/transaction.ts +342 -0
- package/src/serializers/types.ts +58 -0
- package/src/types.ts +295 -0
- package/src/wallet.test.ts +275 -0
- package/src/wallet.ts +94 -0
- package/tsconfig.build.json +6 -0
- package/tsconfig.json +11 -0
- package/typedoc.json +15 -0
- package/vitest.config.ts +10 -0
@@ -0,0 +1,342 @@
|
|
1
|
+
import type { AztecWalletMethodMap } from '../types.js';
|
2
|
+
import type { JSONRPCSerializedData, JSONRPCSerializer } from './types.js';
|
3
|
+
import { encodeBase64, decodeBase64 } from './types.js';
|
4
|
+
import { txHashSerializer } from './core.js';
|
5
|
+
import { TxEffect, TxSimulationResult, inBlockSchemaFor, type TxProvingResult } from '@aztec/circuit-types';
|
6
|
+
import { TxExecutionRequest, TxReceipt, Tx, AztecAddress } from '@aztec/aztec.js';
|
7
|
+
|
8
|
+
import { SerializablePrivateExecutionResult, SerializableTxProvingResult } from './transaction-utils.js';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Serializer for the aztec_createTxExecutionRequest RPC method.
|
12
|
+
* Handles serialization of transaction execution requests between JSON-RPC format and native Aztec types.
|
13
|
+
*/
|
14
|
+
export class AztecCreateTxExecutionRequestSerializer
|
15
|
+
implements
|
16
|
+
JSONRPCSerializer<
|
17
|
+
AztecWalletMethodMap['aztec_createTxExecutionRequest']['params'],
|
18
|
+
AztecWalletMethodMap['aztec_createTxExecutionRequest']['result']
|
19
|
+
>
|
20
|
+
{
|
21
|
+
params = {
|
22
|
+
serialize: (
|
23
|
+
method: string,
|
24
|
+
value: AztecWalletMethodMap['aztec_createTxExecutionRequest']['params'],
|
25
|
+
): JSONRPCSerializedData => {
|
26
|
+
const { exec } = value;
|
27
|
+
return {
|
28
|
+
method,
|
29
|
+
serialized: encodeBase64(JSON.stringify(exec)),
|
30
|
+
};
|
31
|
+
},
|
32
|
+
deserialize: (
|
33
|
+
method: string,
|
34
|
+
data: JSONRPCSerializedData,
|
35
|
+
): AztecWalletMethodMap['aztec_createTxExecutionRequest']['params'] => {
|
36
|
+
const exec = JSON.parse(decodeBase64(data.serialized));
|
37
|
+
return { exec };
|
38
|
+
},
|
39
|
+
};
|
40
|
+
|
41
|
+
result = {
|
42
|
+
serialize: (method: string, value: TxExecutionRequest): JSONRPCSerializedData => {
|
43
|
+
return {
|
44
|
+
method,
|
45
|
+
serialized: encodeBase64(value.toString()),
|
46
|
+
};
|
47
|
+
},
|
48
|
+
deserialize: (method: string, data: JSONRPCSerializedData): TxExecutionRequest => {
|
49
|
+
return TxExecutionRequest.fromString(decodeBase64(data.serialized));
|
50
|
+
},
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Serializer for the aztec_proveTx RPC method.
|
56
|
+
* Handles serialization of transaction proving requests and results between JSON-RPC format and native Aztec types.
|
57
|
+
* Includes handling of private execution results and proving outcomes.
|
58
|
+
*/
|
59
|
+
export class AztecProveTxSerializer
|
60
|
+
implements
|
61
|
+
JSONRPCSerializer<
|
62
|
+
AztecWalletMethodMap['aztec_proveTx']['params'],
|
63
|
+
AztecWalletMethodMap['aztec_proveTx']['result']
|
64
|
+
>
|
65
|
+
{
|
66
|
+
params = {
|
67
|
+
serialize: (
|
68
|
+
method: string,
|
69
|
+
value: AztecWalletMethodMap['aztec_proveTx']['params'],
|
70
|
+
): JSONRPCSerializedData => {
|
71
|
+
const { txRequest, privateExecutionResult } = value;
|
72
|
+
const serializablePrivateExecutionResult =
|
73
|
+
SerializablePrivateExecutionResult.from(privateExecutionResult);
|
74
|
+
return {
|
75
|
+
method,
|
76
|
+
serialized: encodeBase64(JSON.stringify([txRequest.toString(), serializablePrivateExecutionResult])),
|
77
|
+
};
|
78
|
+
},
|
79
|
+
deserialize: (
|
80
|
+
method: string,
|
81
|
+
data: JSONRPCSerializedData,
|
82
|
+
): AztecWalletMethodMap['aztec_proveTx']['params'] => {
|
83
|
+
const [txRequest, privateExecutionResult] = JSON.parse(decodeBase64(data.serialized));
|
84
|
+
return {
|
85
|
+
txRequest: TxExecutionRequest.fromString(txRequest),
|
86
|
+
privateExecutionResult: SerializablePrivateExecutionResult.fromJSON(privateExecutionResult),
|
87
|
+
};
|
88
|
+
},
|
89
|
+
};
|
90
|
+
|
91
|
+
result = {
|
92
|
+
serialize: (method: string, value: TxProvingResult): JSONRPCSerializedData => {
|
93
|
+
const serializableTxProvingResult = SerializableTxProvingResult.from(value);
|
94
|
+
return {
|
95
|
+
method,
|
96
|
+
serialized: encodeBase64(JSON.stringify(serializableTxProvingResult)),
|
97
|
+
};
|
98
|
+
},
|
99
|
+
deserialize: (method: string, data: JSONRPCSerializedData): TxProvingResult => {
|
100
|
+
return SerializableTxProvingResult.fromJSON(JSON.parse(decodeBase64(data.serialized)));
|
101
|
+
},
|
102
|
+
};
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Serializer for the aztec_sendTx RPC method.
|
107
|
+
* Handles serialization of transaction sending requests and transaction hash results between JSON-RPC format and native Aztec types.
|
108
|
+
*/
|
109
|
+
export class AztecSendTxSerializer
|
110
|
+
implements
|
111
|
+
JSONRPCSerializer<
|
112
|
+
AztecWalletMethodMap['aztec_sendTx']['params'],
|
113
|
+
AztecWalletMethodMap['aztec_sendTx']['result']
|
114
|
+
>
|
115
|
+
{
|
116
|
+
params = {
|
117
|
+
serialize: (
|
118
|
+
method: string,
|
119
|
+
value: AztecWalletMethodMap['aztec_sendTx']['params'],
|
120
|
+
): JSONRPCSerializedData => {
|
121
|
+
const { tx } = value;
|
122
|
+
return {
|
123
|
+
method,
|
124
|
+
serialized: encodeBase64(tx.toBuffer().toString('hex')),
|
125
|
+
};
|
126
|
+
},
|
127
|
+
deserialize: (
|
128
|
+
method: string,
|
129
|
+
data: JSONRPCSerializedData,
|
130
|
+
): AztecWalletMethodMap['aztec_sendTx']['params'] => {
|
131
|
+
const tx = Tx.fromBuffer(Buffer.from(decodeBase64(data.serialized), 'hex'));
|
132
|
+
return { tx };
|
133
|
+
},
|
134
|
+
};
|
135
|
+
|
136
|
+
result = {
|
137
|
+
serialize: (
|
138
|
+
method: string,
|
139
|
+
value: AztecWalletMethodMap['aztec_sendTx']['result'],
|
140
|
+
): JSONRPCSerializedData => {
|
141
|
+
return {
|
142
|
+
method,
|
143
|
+
serialized: encodeBase64(txHashSerializer.serialize(value)),
|
144
|
+
};
|
145
|
+
},
|
146
|
+
deserialize: (
|
147
|
+
method: string,
|
148
|
+
data: JSONRPCSerializedData,
|
149
|
+
): AztecWalletMethodMap['aztec_sendTx']['result'] => {
|
150
|
+
return txHashSerializer.deserialize(decodeBase64(data.serialized));
|
151
|
+
},
|
152
|
+
};
|
153
|
+
}
|
154
|
+
|
155
|
+
/**
|
156
|
+
* Serializer for the aztec_getTxEffect RPC method.
|
157
|
+
* Handles serialization of transaction effect queries and results between JSON-RPC format and native Aztec types.
|
158
|
+
* Transaction effects represent the outcome and state changes caused by a transaction.
|
159
|
+
*/
|
160
|
+
export class AztecGetTxEffectSerializer
|
161
|
+
implements
|
162
|
+
JSONRPCSerializer<
|
163
|
+
AztecWalletMethodMap['aztec_getTxEffect']['params'],
|
164
|
+
AztecWalletMethodMap['aztec_getTxEffect']['result']
|
165
|
+
>
|
166
|
+
{
|
167
|
+
params = {
|
168
|
+
serialize: (
|
169
|
+
method: string,
|
170
|
+
value: AztecWalletMethodMap['aztec_getTxEffect']['params'],
|
171
|
+
): JSONRPCSerializedData => {
|
172
|
+
const { txHash } = value;
|
173
|
+
return {
|
174
|
+
method,
|
175
|
+
serialized: encodeBase64(txHashSerializer.serialize(txHash)),
|
176
|
+
};
|
177
|
+
},
|
178
|
+
deserialize: (
|
179
|
+
method: string,
|
180
|
+
data: JSONRPCSerializedData,
|
181
|
+
): AztecWalletMethodMap['aztec_getTxEffect']['params'] => {
|
182
|
+
const txHash = txHashSerializer.deserialize(decodeBase64(data.serialized));
|
183
|
+
return { txHash };
|
184
|
+
},
|
185
|
+
};
|
186
|
+
|
187
|
+
result = {
|
188
|
+
serialize: (
|
189
|
+
method: string,
|
190
|
+
value: AztecWalletMethodMap['aztec_getTxEffect']['result'],
|
191
|
+
): JSONRPCSerializedData => {
|
192
|
+
return {
|
193
|
+
method,
|
194
|
+
serialized: encodeBase64(JSON.stringify(TxEffect.schema.parse(value))),
|
195
|
+
};
|
196
|
+
},
|
197
|
+
deserialize: (
|
198
|
+
method: string,
|
199
|
+
data: JSONRPCSerializedData,
|
200
|
+
): AztecWalletMethodMap['aztec_getTxEffect']['result'] => {
|
201
|
+
return inBlockSchemaFor(TxEffect.schema).parse(JSON.parse(decodeBase64(data.serialized)));
|
202
|
+
},
|
203
|
+
};
|
204
|
+
}
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Serializer for the aztec_getTxReceipt RPC method.
|
208
|
+
* Handles serialization of transaction receipt queries and results between JSON-RPC format and native Aztec types.
|
209
|
+
* Transaction receipts contain detailed information about executed transactions.
|
210
|
+
*/
|
211
|
+
export class AztecGetTxReceiptSerializer
|
212
|
+
implements
|
213
|
+
JSONRPCSerializer<
|
214
|
+
AztecWalletMethodMap['aztec_getTxReceipt']['params'],
|
215
|
+
AztecWalletMethodMap['aztec_getTxReceipt']['result']
|
216
|
+
>
|
217
|
+
{
|
218
|
+
params = {
|
219
|
+
serialize: (
|
220
|
+
method: string,
|
221
|
+
value: AztecWalletMethodMap['aztec_getTxReceipt']['params'],
|
222
|
+
): JSONRPCSerializedData => {
|
223
|
+
const { txHash } = value;
|
224
|
+
return {
|
225
|
+
method,
|
226
|
+
serialized: encodeBase64(txHashSerializer.serialize(txHash)),
|
227
|
+
};
|
228
|
+
},
|
229
|
+
deserialize: (
|
230
|
+
method: string,
|
231
|
+
data: JSONRPCSerializedData,
|
232
|
+
): AztecWalletMethodMap['aztec_getTxReceipt']['params'] => {
|
233
|
+
const txHash = txHashSerializer.deserialize(decodeBase64(data.serialized));
|
234
|
+
return { txHash };
|
235
|
+
},
|
236
|
+
};
|
237
|
+
|
238
|
+
result = {
|
239
|
+
serialize: (method: string, value: TxReceipt): JSONRPCSerializedData => {
|
240
|
+
return {
|
241
|
+
method,
|
242
|
+
serialized: encodeBase64(JSON.stringify(TxReceipt.schema.parse(value))),
|
243
|
+
};
|
244
|
+
},
|
245
|
+
deserialize: (method: string, data: JSONRPCSerializedData): TxReceipt => {
|
246
|
+
return TxReceipt.schema.parse(JSON.parse(decodeBase64(data.serialized)));
|
247
|
+
},
|
248
|
+
};
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Serializer for the aztec_simulateTx RPC method.
|
253
|
+
* Handles serialization of transaction simulation requests and results between JSON-RPC format and native Aztec types.
|
254
|
+
* Supports simulation configuration including public simulation, custom sender, validation options, and profiling.
|
255
|
+
*/
|
256
|
+
export class AztecSimulateTxSerializer
|
257
|
+
implements
|
258
|
+
JSONRPCSerializer<
|
259
|
+
AztecWalletMethodMap['aztec_simulateTx']['params'],
|
260
|
+
AztecWalletMethodMap['aztec_simulateTx']['result']
|
261
|
+
>
|
262
|
+
{
|
263
|
+
params = {
|
264
|
+
serialize: (
|
265
|
+
method: string,
|
266
|
+
value: AztecWalletMethodMap['aztec_simulateTx']['params'],
|
267
|
+
): JSONRPCSerializedData => {
|
268
|
+
const { txRequest, simulatePublic, msgSender, skipTxValidation, enforceFeePayment, profile } = value;
|
269
|
+
return {
|
270
|
+
method,
|
271
|
+
serialized: encodeBase64(
|
272
|
+
JSON.stringify([
|
273
|
+
txRequest.toString(),
|
274
|
+
simulatePublic,
|
275
|
+
msgSender,
|
276
|
+
skipTxValidation,
|
277
|
+
enforceFeePayment,
|
278
|
+
profile,
|
279
|
+
]),
|
280
|
+
),
|
281
|
+
};
|
282
|
+
},
|
283
|
+
deserialize: (
|
284
|
+
method: string,
|
285
|
+
data: JSONRPCSerializedData,
|
286
|
+
): AztecWalletMethodMap['aztec_simulateTx']['params'] => {
|
287
|
+
const [txRequest, simulatePublic, msgSender, skipTxValidation, enforceFeePayment, profile] = JSON.parse(
|
288
|
+
decodeBase64(data.serialized),
|
289
|
+
);
|
290
|
+
return {
|
291
|
+
txRequest: TxExecutionRequest.fromString(txRequest),
|
292
|
+
simulatePublic,
|
293
|
+
msgSender: msgSender ? AztecAddress.fromString(msgSender) : undefined,
|
294
|
+
skipTxValidation,
|
295
|
+
enforceFeePayment,
|
296
|
+
profile,
|
297
|
+
};
|
298
|
+
},
|
299
|
+
};
|
300
|
+
|
301
|
+
result = {
|
302
|
+
serialize: (method: string, value: TxSimulationResult): JSONRPCSerializedData => {
|
303
|
+
const serializablePrivateExecutionResult = SerializablePrivateExecutionResult.from(
|
304
|
+
value.privateExecutionResult,
|
305
|
+
);
|
306
|
+
|
307
|
+
return {
|
308
|
+
method,
|
309
|
+
serialized: encodeBase64(
|
310
|
+
JSON.stringify({
|
311
|
+
privateExecutionResult: serializablePrivateExecutionResult,
|
312
|
+
publicInputs: value.publicInputs,
|
313
|
+
publicOutput: value.publicOutput,
|
314
|
+
profileResult: value.profileResult,
|
315
|
+
}),
|
316
|
+
),
|
317
|
+
};
|
318
|
+
},
|
319
|
+
deserialize: (method: string, data: JSONRPCSerializedData): TxSimulationResult => {
|
320
|
+
const { privateExecutionResult, publicInputs, publicOutput, profileResult } = JSON.parse(
|
321
|
+
decodeBase64(data.serialized),
|
322
|
+
);
|
323
|
+
return new TxSimulationResult(
|
324
|
+
SerializablePrivateExecutionResult.fromJSON(privateExecutionResult),
|
325
|
+
publicInputs,
|
326
|
+
publicOutput,
|
327
|
+
profileResult,
|
328
|
+
);
|
329
|
+
},
|
330
|
+
};
|
331
|
+
}
|
332
|
+
|
333
|
+
/**
|
334
|
+
* Pre-instantiated serializer instances for each Aztec transaction-related RPC method.
|
335
|
+
* These instances can be used directly by the RPC handler implementation.
|
336
|
+
*/
|
337
|
+
export const aztecCreateTxExecutionRequestSerializer = new AztecCreateTxExecutionRequestSerializer();
|
338
|
+
export const aztecProveTxSerializer = new AztecProveTxSerializer();
|
339
|
+
export const aztecSendTxSerializer = new AztecSendTxSerializer();
|
340
|
+
export const aztecGetTxEffectSerializer = new AztecGetTxEffectSerializer();
|
341
|
+
export const aztecGetTxReceiptSerializer = new AztecGetTxReceiptSerializer();
|
342
|
+
export const aztecSimulateTxSerializer = new AztecSimulateTxSerializer();
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import type { JSONRPCSerializedData, JSONRPCSerializer } from '@walletmesh/jsonrpc';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Base interface for type-specific serializers in the Aztec RPC wallet.
|
5
|
+
* Provides a standardized way to convert Aztec-specific types to and from string representations
|
6
|
+
* for network transmission. Each Aztec type (Fr, AztecAddress, etc.) implements this interface
|
7
|
+
* to ensure consistent serialization across the RPC layer.
|
8
|
+
*
|
9
|
+
* @typeParam T - The Aztec type being serialized (e.g., Fr, AztecAddress, TxHash)
|
10
|
+
*/
|
11
|
+
export interface TypeSerializer<T> {
|
12
|
+
/**
|
13
|
+
* Converts a value to its string representation for network transmission.
|
14
|
+
* Implementations should ensure the serialized form can be correctly deserialized
|
15
|
+
* back to the original type.
|
16
|
+
*
|
17
|
+
* @param value - The Aztec type value to serialize
|
18
|
+
* @returns A string representation suitable for network transmission
|
19
|
+
*/
|
20
|
+
serialize(value: T): string;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Reconstructs a value from its string representation.
|
24
|
+
* Implementations should validate the input string and throw appropriate errors
|
25
|
+
* if the data cannot be correctly deserialized.
|
26
|
+
*
|
27
|
+
* @param data - The string data to deserialize, previously created by serialize()
|
28
|
+
* @returns The reconstructed Aztec type value
|
29
|
+
* @throws If the data is invalid or cannot be deserialized
|
30
|
+
*/
|
31
|
+
deserialize(data: string): T;
|
32
|
+
}
|
33
|
+
|
34
|
+
// Re-export core JSON-RPC types from @walletmesh/jsonrpc
|
35
|
+
export type { JSONRPCSerializedData, JSONRPCSerializer };
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Helper function to encode data as base64 for safe network transmission.
|
39
|
+
* Used throughout the serializers to ensure consistent encoding of binary data.
|
40
|
+
*
|
41
|
+
* @param data - The string data to encode
|
42
|
+
* @returns Base64 encoded string
|
43
|
+
*/
|
44
|
+
export function encodeBase64(data: string): string {
|
45
|
+
return btoa(data);
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Helper function to decode base64 data back to its original form.
|
50
|
+
* Used throughout the serializers to decode data received over the network.
|
51
|
+
*
|
52
|
+
* @param data - The base64 encoded string to decode
|
53
|
+
* @returns Original decoded string
|
54
|
+
* @throws If the input is not valid base64
|
55
|
+
*/
|
56
|
+
export function decodeBase64(data: string): string {
|
57
|
+
return atob(data);
|
58
|
+
}
|
package/src/types.ts
ADDED
@@ -0,0 +1,295 @@
|
|
1
|
+
import type {
|
2
|
+
AuthWitness,
|
3
|
+
AztecAddress,
|
4
|
+
ContractArtifact,
|
5
|
+
ContractClassWithId,
|
6
|
+
ContractInstanceWithAddress,
|
7
|
+
ExtendedNote,
|
8
|
+
Fr,
|
9
|
+
PXE,
|
10
|
+
TxExecutionRequest,
|
11
|
+
TxHash,
|
12
|
+
TxReceipt,
|
13
|
+
L2Block,
|
14
|
+
LogFilter,
|
15
|
+
Point,
|
16
|
+
SiblingPath,
|
17
|
+
PartialAddress,
|
18
|
+
CompleteAddress,
|
19
|
+
NodeInfo,
|
20
|
+
AccountWallet,
|
21
|
+
Tx,
|
22
|
+
} from '@aztec/aztec.js';
|
23
|
+
import type { IntentAction, IntentInnerHash } from '@aztec/aztec.js/utils';
|
24
|
+
import type { ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
|
25
|
+
import type { AbiDecoded } from '@aztec/foundation/abi';
|
26
|
+
import type {
|
27
|
+
InBlock,
|
28
|
+
IncomingNotesFilter,
|
29
|
+
EventMetadataDefinition,
|
30
|
+
PrivateExecutionResult,
|
31
|
+
TxEffect,
|
32
|
+
TxProvingResult,
|
33
|
+
UniqueNote,
|
34
|
+
GetUnencryptedLogsResponse,
|
35
|
+
PXEInfo,
|
36
|
+
TxSimulationResult,
|
37
|
+
} from '@aztec/circuit-types';
|
38
|
+
import type { GasFees, L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
|
39
|
+
import type { JSONRPCEventMap, JSONRPCMiddleware } from '@walletmesh/jsonrpc';
|
40
|
+
import type { JSONRPCWalletClient, WalletMethodMap } from '@walletmesh/router';
|
41
|
+
import type { ContractArtifactCache } from './contractArtifactCache.js';
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Represents a single function call to a contract.
|
45
|
+
* @public
|
46
|
+
*/
|
47
|
+
export type TransactionFunctionCall = {
|
48
|
+
/** The address of the contract to interact with */
|
49
|
+
contractAddress: string;
|
50
|
+
/** The name of the function to call */
|
51
|
+
functionName: string;
|
52
|
+
/** The arguments to pass to the function */
|
53
|
+
args: unknown[];
|
54
|
+
};
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Parameters for sending transactions.
|
58
|
+
* @public
|
59
|
+
*/
|
60
|
+
export type TransactionParams = {
|
61
|
+
/** Array of function calls to execute */
|
62
|
+
functionCalls: TransactionFunctionCall[];
|
63
|
+
/** Optional array of authorization witnesses for the transaction */
|
64
|
+
authwits?: string[];
|
65
|
+
};
|
66
|
+
|
67
|
+
export const BASE_WALLET_METHODS: (keyof AztecWalletBaseMethodMap)[] = [
|
68
|
+
'wm_getSupportedMethods',
|
69
|
+
'aztec_connect',
|
70
|
+
'aztec_getAccount',
|
71
|
+
'aztec_sendTransaction',
|
72
|
+
'aztec_simulateTransaction',
|
73
|
+
] as const;
|
74
|
+
|
75
|
+
/**
|
76
|
+
* A mapping of JSON-RPC methods to their parameters and return types for Aztec Wallets.
|
77
|
+
*
|
78
|
+
* This extends the base WalletMethodMap with Aztec-specific methods.
|
79
|
+
* @public
|
80
|
+
*/
|
81
|
+
export interface AztecWalletBaseMethodMap extends WalletMethodMap {
|
82
|
+
/**
|
83
|
+
* Connects to the Aztec network.
|
84
|
+
* @returns A boolean indicating if the connection was successful
|
85
|
+
*/
|
86
|
+
aztec_connect: { result: boolean };
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Gets the account address from the wallet.
|
90
|
+
* @returns The account address as a string
|
91
|
+
*/
|
92
|
+
aztec_getAccount: { result: string };
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Sends transactions to the Aztec network.
|
96
|
+
* @param params - The transactions to execute and optional authorization witnesses
|
97
|
+
* @returns The transaction hash as a string
|
98
|
+
*/
|
99
|
+
aztec_sendTransaction: {
|
100
|
+
params: TransactionParams;
|
101
|
+
result: string;
|
102
|
+
};
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Simulates a transaction without executing it.
|
106
|
+
* @param params - The transaction to simulate
|
107
|
+
* @returns The simulation result
|
108
|
+
*/
|
109
|
+
aztec_simulateTransaction: {
|
110
|
+
params: TransactionFunctionCall;
|
111
|
+
result: unknown;
|
112
|
+
};
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Returns the list of supported methods for the wallet.
|
116
|
+
* @returns An array of supported methods
|
117
|
+
*/
|
118
|
+
wm_getSupportedMethods: {
|
119
|
+
result: string[];
|
120
|
+
};
|
121
|
+
}
|
122
|
+
|
123
|
+
export interface AztecWalletEventMap extends JSONRPCEventMap {
|
124
|
+
// TODO: What events do we need?
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Holds the context passed through RPC middleware.
|
129
|
+
* @public
|
130
|
+
*/
|
131
|
+
export type AztecWalletContext = Record<string, unknown> & {
|
132
|
+
/** The PXE instance for the wallet */
|
133
|
+
pxe: PXE;
|
134
|
+
wallet: AccountWallet;
|
135
|
+
contractArtifactCache: ContractArtifactCache;
|
136
|
+
};
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Type for Aztec Router Wallet middleware.
|
140
|
+
* @public
|
141
|
+
*/
|
142
|
+
export type AztecWalletMiddleware = JSONRPCMiddleware<AztecWalletBaseMethodMap, AztecWalletContext>;
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Type for Aztec Chain Wallet middleware.
|
146
|
+
*/
|
147
|
+
export type AztecChainWalletMiddleware = JSONRPCMiddleware<AztecWalletMethodMap, AztecWalletContext>;
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Type for Aztec wallet router client.
|
151
|
+
* @public
|
152
|
+
*/
|
153
|
+
export type AztecWalletRouterClient = JSONRPCWalletClient<AztecWalletMethodMap>;
|
154
|
+
|
155
|
+
/**
|
156
|
+
* Type for Aztec wallet RPC method map.
|
157
|
+
* This extends the AztecWalletBaseMethodMap with the methods used in by Aztec's `AccountWallet`
|
158
|
+
*/
|
159
|
+
export interface AztecWalletMethodMap extends AztecWalletBaseMethodMap {
|
160
|
+
/* Chain */
|
161
|
+
aztec_getBlock: { params: { number: number }; result: L2Block };
|
162
|
+
aztec_getBlockNumber: { result: number };
|
163
|
+
aztec_getChainId: { result: number };
|
164
|
+
aztec_getVersion: { result: number };
|
165
|
+
aztec_getNodeInfo: { result: NodeInfo };
|
166
|
+
aztec_getProvenBlockNumber: { result: number };
|
167
|
+
aztec_getPXEInfo: { result: PXEInfo };
|
168
|
+
aztec_getCurrentBaseFees: { result: GasFees };
|
169
|
+
|
170
|
+
/* Scopes */
|
171
|
+
aztec_setScopes: { params: { scopes: AztecAddress[] }; result: boolean };
|
172
|
+
aztec_getScopes: { result: AztecAddress[] };
|
173
|
+
|
174
|
+
/* L1->L2 Messages */
|
175
|
+
aztec_isL1ToL2MessageSynced: { params: { l1ToL2Message: Fr }; result: boolean };
|
176
|
+
aztec_getL1ToL2MembershipWitness: {
|
177
|
+
params: { contractAddress: AztecAddress; messageHash: Fr; secret: Fr };
|
178
|
+
result: [bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>];
|
179
|
+
};
|
180
|
+
|
181
|
+
/* Capsules */
|
182
|
+
aztec_addCapsule: { params: { capsule: Fr[] }; result: boolean };
|
183
|
+
|
184
|
+
/* Accounts */
|
185
|
+
aztec_getAddress: { result: AztecAddress };
|
186
|
+
aztec_getCompleteAddress: { result: CompleteAddress };
|
187
|
+
aztec_registerAccount: {
|
188
|
+
params: { secretKey: Fr; partialAddress: PartialAddress };
|
189
|
+
result: CompleteAddress;
|
190
|
+
};
|
191
|
+
aztec_getRegisteredAccounts: { result: CompleteAddress[] };
|
192
|
+
|
193
|
+
/* AuthWitness */
|
194
|
+
aztec_addAuthWitness: { params: { authWitness: AuthWitness }; result: boolean };
|
195
|
+
aztec_getAuthWitness: { params: { messageHash: Fr }; result: Fr[] };
|
196
|
+
aztec_createAuthWit: {
|
197
|
+
params: { intent: Fr | Buffer | IntentAction | IntentInnerHash };
|
198
|
+
result: AuthWitness;
|
199
|
+
};
|
200
|
+
|
201
|
+
/* Senders */
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Registers a contact in the user's PXE
|
205
|
+
* @param params - The sender (contact) address to register
|
206
|
+
* @returns True if registration was successful
|
207
|
+
*/
|
208
|
+
aztec_registerSender: { params: { sender: AztecAddress }; result: AztecAddress };
|
209
|
+
aztec_getSenders: { result: AztecAddress[] };
|
210
|
+
aztec_removeSender: { params: { sender: AztecAddress }; result: boolean };
|
211
|
+
|
212
|
+
/* Contracts */
|
213
|
+
|
214
|
+
aztec_getContracts: { result: AztecAddress[] };
|
215
|
+
aztec_getContractInstance: { params: { address: AztecAddress }; result: ContractInstanceWithAddress };
|
216
|
+
aztec_getContractClass: { params: { id: Fr }; result: ContractClassWithId };
|
217
|
+
aztec_getContractArtifact: { params: { id: Fr }; result: ContractArtifact };
|
218
|
+
aztec_isContractClassPubliclyRegistered: { params: { id: Fr }; result: boolean };
|
219
|
+
aztec_isContractPubliclyDeployed: { params: { address: AztecAddress }; result: boolean };
|
220
|
+
aztec_isContractInitialized: { params: { address: AztecAddress }; result: boolean };
|
221
|
+
|
222
|
+
/**
|
223
|
+
* Registers a contract instance in the user's PXE.
|
224
|
+
* @param params - The contract details to register
|
225
|
+
* @returns True if registration was successful
|
226
|
+
*/
|
227
|
+
aztec_registerContract: {
|
228
|
+
params: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact };
|
229
|
+
result: boolean;
|
230
|
+
};
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Registers a contract class in the user's PXE.
|
234
|
+
* @param params - The contract artifact to register
|
235
|
+
* @returns True if registration was successful
|
236
|
+
*/
|
237
|
+
aztec_registerContractClass: { params: { artifact: ContractArtifact }; result: boolean };
|
238
|
+
// biome-ignore lint/suspicious/noExplicitAny: return type from aztec.js is `any`
|
239
|
+
aztec_getPublicStorageAt: { params: { contract: AztecAddress; storageSlot: Fr }; result: any };
|
240
|
+
|
241
|
+
/* Transactions */
|
242
|
+
aztec_sendTx: { params: { tx: Tx }; result: TxHash };
|
243
|
+
aztec_createTxExecutionRequest: { params: { exec: ExecutionRequestInit }; result: TxExecutionRequest };
|
244
|
+
aztec_proveTx: {
|
245
|
+
params: { txRequest: TxExecutionRequest; privateExecutionResult: PrivateExecutionResult };
|
246
|
+
result: TxProvingResult;
|
247
|
+
};
|
248
|
+
aztec_getTxEffect: { params: { txHash: TxHash }; result: InBlock<TxEffect> };
|
249
|
+
aztec_getTxReceipt: { params: { txHash: TxHash }; result: TxReceipt };
|
250
|
+
|
251
|
+
aztec_simulateTx: {
|
252
|
+
params: {
|
253
|
+
txRequest: TxExecutionRequest;
|
254
|
+
simulatePublic: boolean;
|
255
|
+
msgSender?: AztecAddress;
|
256
|
+
skipTxValidation?: boolean;
|
257
|
+
enforceFeePayment?: boolean;
|
258
|
+
profile?: boolean;
|
259
|
+
};
|
260
|
+
result: TxSimulationResult;
|
261
|
+
};
|
262
|
+
aztec_simulateUnconstrained: {
|
263
|
+
params: { functionName: string; args: unknown[]; to: AztecAddress; from?: AztecAddress };
|
264
|
+
result: AbiDecoded;
|
265
|
+
};
|
266
|
+
|
267
|
+
/* Notes */
|
268
|
+
aztec_getIncomingNotes: { params: { filter: IncomingNotesFilter }; result: UniqueNote[] };
|
269
|
+
aztec_addNote: { params: { note: ExtendedNote }; result: boolean };
|
270
|
+
aztec_addNullifiedNote: { params: { note: ExtendedNote }; result: boolean };
|
271
|
+
|
272
|
+
/* Logs */
|
273
|
+
aztec_getUnencryptedLogs: { params: { filter: LogFilter }; result: GetUnencryptedLogsResponse };
|
274
|
+
aztec_getContractClassLogs: { params: { filter: LogFilter }; result: GetUnencryptedLogsResponse };
|
275
|
+
aztec_getEncryptedEvents: {
|
276
|
+
params: { event: EventMetadataDefinition; from: number; limit: number; vpks?: Point[] };
|
277
|
+
result: unknown[];
|
278
|
+
};
|
279
|
+
aztec_getUnencryptedEvents: {
|
280
|
+
params: { event: EventMetadataDefinition; from: number; limit: number };
|
281
|
+
result: unknown[];
|
282
|
+
};
|
283
|
+
}
|
284
|
+
|
285
|
+
export type AztecWalletMethodHandler<
|
286
|
+
T extends AztecWalletMethodMap,
|
287
|
+
M extends keyof T,
|
288
|
+
C extends AztecWalletContext,
|
289
|
+
> = (
|
290
|
+
context: C,
|
291
|
+
params: T[M]['params'],
|
292
|
+
accountWallet: AccountWallet,
|
293
|
+
) => Promise<T[M]['result']> | T[M]['result'];
|
294
|
+
|
295
|
+
export type AztecChainId = `aztec:${string}`;
|