@walletmesh/aztec-rpc-wallet 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,593 @@
|
|
1
|
+
import type { AccountWallet } from '@aztec/aztec.js';
|
2
|
+
import { AztecWalletError } from '../errors.js';
|
3
|
+
import type { AztecWalletContext, AztecWalletMethodMap } from '../types.js';
|
4
|
+
|
5
|
+
export const AZTEC_WALLET_METHODS: (keyof AztecWalletMethodMap)[] = [
|
6
|
+
'aztec_getBlock',
|
7
|
+
'aztec_getBlockNumber',
|
8
|
+
'aztec_getChainId',
|
9
|
+
'aztec_getVersion',
|
10
|
+
'aztec_getNodeInfo',
|
11
|
+
'aztec_getCurrentBaseFees',
|
12
|
+
'aztec_setScopes',
|
13
|
+
'aztec_getScopes',
|
14
|
+
'aztec_isL1ToL2MessageSynced',
|
15
|
+
'aztec_getL1ToL2MembershipWitness',
|
16
|
+
'aztec_addCapsule',
|
17
|
+
'aztec_getAddress',
|
18
|
+
'aztec_getCompleteAddress',
|
19
|
+
'aztec_registerAccount',
|
20
|
+
'aztec_getRegisteredAccounts',
|
21
|
+
'aztec_addAuthWitness',
|
22
|
+
'aztec_getAuthWitness',
|
23
|
+
'aztec_createAuthWit',
|
24
|
+
'aztec_registerSender',
|
25
|
+
'aztec_getSenders',
|
26
|
+
'aztec_removeSender',
|
27
|
+
'aztec_getContracts',
|
28
|
+
'aztec_getContractInstance',
|
29
|
+
'aztec_getContractClass',
|
30
|
+
'aztec_getContractArtifact',
|
31
|
+
'aztec_isContractClassPubliclyRegistered',
|
32
|
+
'aztec_isContractPubliclyDeployed',
|
33
|
+
'aztec_isContractInitialized',
|
34
|
+
'aztec_registerContract',
|
35
|
+
'aztec_registerContractClass',
|
36
|
+
'aztec_getPublicStorageAt',
|
37
|
+
'aztec_createTxExecutionRequest',
|
38
|
+
'aztec_proveTx',
|
39
|
+
'aztec_sendTx',
|
40
|
+
'aztec_getTxEffect',
|
41
|
+
'aztec_getTxReceipt',
|
42
|
+
'aztec_simulateTx',
|
43
|
+
'aztec_simulateUnconstrained',
|
44
|
+
'aztec_getIncomingNotes',
|
45
|
+
'aztec_addNote',
|
46
|
+
'aztec_addNullifiedNote',
|
47
|
+
'aztec_getUnencryptedLogs',
|
48
|
+
'aztec_getContractClassLogs',
|
49
|
+
'aztec_getEncryptedEvents',
|
50
|
+
'aztec_getUnencryptedEvents',
|
51
|
+
] as const;
|
52
|
+
|
53
|
+
// Handler functions with proper type safety
|
54
|
+
async function handleGetBlock(
|
55
|
+
wallet: AccountWallet,
|
56
|
+
params: AztecWalletMethodMap['aztec_getBlock']['params'],
|
57
|
+
): Promise<AztecWalletMethodMap['aztec_getBlock']['result']> {
|
58
|
+
const block = await wallet.getBlock(params.number);
|
59
|
+
if (!block) throw new AztecWalletError('blockNotFound', 'aztec_getBlock');
|
60
|
+
return block;
|
61
|
+
}
|
62
|
+
|
63
|
+
async function handleGetBlockNumber(
|
64
|
+
wallet: AccountWallet,
|
65
|
+
): Promise<AztecWalletMethodMap['aztec_getBlockNumber']['result']> {
|
66
|
+
return await wallet.getBlockNumber();
|
67
|
+
}
|
68
|
+
|
69
|
+
async function handleGetChainId(
|
70
|
+
wallet: AccountWallet,
|
71
|
+
): Promise<AztecWalletMethodMap['aztec_getChainId']['result']> {
|
72
|
+
return Number(wallet.getChainId());
|
73
|
+
}
|
74
|
+
|
75
|
+
async function handleGetVersion(
|
76
|
+
wallet: AccountWallet,
|
77
|
+
): Promise<AztecWalletMethodMap['aztec_getVersion']['result']> {
|
78
|
+
return Number(wallet.getVersion());
|
79
|
+
}
|
80
|
+
|
81
|
+
async function handleGetNodeInfo(
|
82
|
+
wallet: AccountWallet,
|
83
|
+
): Promise<AztecWalletMethodMap['aztec_getNodeInfo']['result']> {
|
84
|
+
return await wallet.getNodeInfo();
|
85
|
+
}
|
86
|
+
|
87
|
+
async function handleGetCurrentBaseFees(
|
88
|
+
wallet: AccountWallet,
|
89
|
+
): Promise<AztecWalletMethodMap['aztec_getCurrentBaseFees']['result']> {
|
90
|
+
return await wallet.getCurrentBaseFees();
|
91
|
+
}
|
92
|
+
|
93
|
+
async function handleSetScopes(
|
94
|
+
wallet: AccountWallet,
|
95
|
+
params: AztecWalletMethodMap['aztec_setScopes']['params'],
|
96
|
+
): Promise<AztecWalletMethodMap['aztec_setScopes']['result']> {
|
97
|
+
await wallet.setScopes(params.scopes);
|
98
|
+
return true;
|
99
|
+
}
|
100
|
+
|
101
|
+
async function handleGetScopes(
|
102
|
+
wallet: AccountWallet,
|
103
|
+
): Promise<AztecWalletMethodMap['aztec_getScopes']['result']> {
|
104
|
+
const scopes = await wallet.getScopes();
|
105
|
+
return scopes ?? [];
|
106
|
+
}
|
107
|
+
|
108
|
+
async function handleAddCapsule(
|
109
|
+
wallet: AccountWallet,
|
110
|
+
params: AztecWalletMethodMap['aztec_addCapsule']['params'],
|
111
|
+
): Promise<AztecWalletMethodMap['aztec_addCapsule']['result']> {
|
112
|
+
await wallet.addCapsule(params.capsule);
|
113
|
+
return true;
|
114
|
+
}
|
115
|
+
|
116
|
+
async function handleGetAddress(
|
117
|
+
wallet: AccountWallet,
|
118
|
+
): Promise<AztecWalletMethodMap['aztec_getAddress']['result']> {
|
119
|
+
return wallet.getAddress();
|
120
|
+
}
|
121
|
+
|
122
|
+
async function handleGetCompleteAddress(
|
123
|
+
wallet: AccountWallet,
|
124
|
+
): Promise<AztecWalletMethodMap['aztec_getCompleteAddress']['result']> {
|
125
|
+
return wallet.getCompleteAddress();
|
126
|
+
}
|
127
|
+
|
128
|
+
async function handleRegisterAccount(
|
129
|
+
wallet: AccountWallet,
|
130
|
+
params: AztecWalletMethodMap['aztec_registerAccount']['params'],
|
131
|
+
): Promise<AztecWalletMethodMap['aztec_registerAccount']['result']> {
|
132
|
+
return await wallet.registerAccount(params.secretKey, params.partialAddress);
|
133
|
+
}
|
134
|
+
|
135
|
+
async function handleGetRegisteredAccounts(
|
136
|
+
wallet: AccountWallet,
|
137
|
+
): Promise<AztecWalletMethodMap['aztec_getRegisteredAccounts']['result']> {
|
138
|
+
return await wallet.getRegisteredAccounts();
|
139
|
+
}
|
140
|
+
|
141
|
+
async function handleRegisterSender(
|
142
|
+
wallet: AccountWallet,
|
143
|
+
params: AztecWalletMethodMap['aztec_registerSender']['params'],
|
144
|
+
): Promise<AztecWalletMethodMap['aztec_registerSender']['result']> {
|
145
|
+
return await wallet.registerSender(params.sender);
|
146
|
+
}
|
147
|
+
|
148
|
+
async function handleGetSenders(
|
149
|
+
wallet: AccountWallet,
|
150
|
+
): Promise<AztecWalletMethodMap['aztec_getSenders']['result']> {
|
151
|
+
return await wallet.getSenders();
|
152
|
+
}
|
153
|
+
|
154
|
+
async function handleRemoveSender(
|
155
|
+
wallet: AccountWallet,
|
156
|
+
params: AztecWalletMethodMap['aztec_removeSender']['params'],
|
157
|
+
): Promise<AztecWalletMethodMap['aztec_removeSender']['result']> {
|
158
|
+
await wallet.removeSender(params.sender);
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
|
162
|
+
async function handleAddAuthWitness(
|
163
|
+
wallet: AccountWallet,
|
164
|
+
params: AztecWalletMethodMap['aztec_addAuthWitness']['params'],
|
165
|
+
): Promise<AztecWalletMethodMap['aztec_addAuthWitness']['result']> {
|
166
|
+
await wallet.addAuthWitness(params.authWitness);
|
167
|
+
return true;
|
168
|
+
}
|
169
|
+
|
170
|
+
async function handleGetAuthWitness(
|
171
|
+
wallet: AccountWallet,
|
172
|
+
params: AztecWalletMethodMap['aztec_getAuthWitness']['params'],
|
173
|
+
): Promise<AztecWalletMethodMap['aztec_getAuthWitness']['result']> {
|
174
|
+
const witness = await wallet.getAuthWitness(params.messageHash);
|
175
|
+
if (!witness) throw new AztecWalletError('authWitnessNotFound', 'aztec_getAuthWitness');
|
176
|
+
return witness;
|
177
|
+
}
|
178
|
+
|
179
|
+
async function handleCreateAuthWit(
|
180
|
+
wallet: AccountWallet,
|
181
|
+
params: AztecWalletMethodMap['aztec_createAuthWit']['params'],
|
182
|
+
): Promise<AztecWalletMethodMap['aztec_createAuthWit']['result']> {
|
183
|
+
return await wallet.createAuthWit(params.intent);
|
184
|
+
}
|
185
|
+
|
186
|
+
async function handleL1ToL2MessageSynced(
|
187
|
+
wallet: AccountWallet,
|
188
|
+
params: AztecWalletMethodMap['aztec_isL1ToL2MessageSynced']['params'],
|
189
|
+
): Promise<AztecWalletMethodMap['aztec_isL1ToL2MessageSynced']['result']> {
|
190
|
+
return await wallet.isL1ToL2MessageSynced(params.l1ToL2Message);
|
191
|
+
}
|
192
|
+
|
193
|
+
async function handleGetContracts(
|
194
|
+
wallet: AccountWallet,
|
195
|
+
): Promise<AztecWalletMethodMap['aztec_getContracts']['result']> {
|
196
|
+
return await wallet.getContracts();
|
197
|
+
}
|
198
|
+
|
199
|
+
async function handleGetContractInstance(
|
200
|
+
wallet: AccountWallet,
|
201
|
+
params: AztecWalletMethodMap['aztec_getContractInstance']['params'],
|
202
|
+
): Promise<AztecWalletMethodMap['aztec_getContractInstance']['result']> {
|
203
|
+
const instance = await wallet.getContractInstance(params.address);
|
204
|
+
if (!instance) throw new AztecWalletError('contractInstanceNotRegistered', 'aztec_getContractInstance');
|
205
|
+
return instance;
|
206
|
+
}
|
207
|
+
|
208
|
+
async function handleGetContractClass(
|
209
|
+
wallet: AccountWallet,
|
210
|
+
params: AztecWalletMethodMap['aztec_getContractClass']['params'],
|
211
|
+
): Promise<AztecWalletMethodMap['aztec_getContractClass']['result']> {
|
212
|
+
const contractClass = await wallet.getContractClass(params.id);
|
213
|
+
if (!contractClass) throw new AztecWalletError('contractClassNotRegistered', 'aztec_getContractClass');
|
214
|
+
return contractClass;
|
215
|
+
}
|
216
|
+
|
217
|
+
async function handleGetContractArtifact(
|
218
|
+
wallet: AccountWallet,
|
219
|
+
params: AztecWalletMethodMap['aztec_getContractArtifact']['params'],
|
220
|
+
): Promise<AztecWalletMethodMap['aztec_getContractArtifact']['result']> {
|
221
|
+
const artifact = await wallet.getContractArtifact(params.id);
|
222
|
+
if (!artifact) throw new AztecWalletError('contractClassNotRegistered', 'aztec_getContractArtifact');
|
223
|
+
return artifact;
|
224
|
+
}
|
225
|
+
|
226
|
+
async function handleIsContractClassPubliclyRegistered(
|
227
|
+
wallet: AccountWallet,
|
228
|
+
params: AztecWalletMethodMap['aztec_isContractClassPubliclyRegistered']['params'],
|
229
|
+
): Promise<AztecWalletMethodMap['aztec_isContractClassPubliclyRegistered']['result']> {
|
230
|
+
return await wallet.isContractClassPubliclyRegistered(params.id);
|
231
|
+
}
|
232
|
+
|
233
|
+
async function handleIsContractPubliclyDeployed(
|
234
|
+
wallet: AccountWallet,
|
235
|
+
params: AztecWalletMethodMap['aztec_isContractPubliclyDeployed']['params'],
|
236
|
+
): Promise<AztecWalletMethodMap['aztec_isContractPubliclyDeployed']['result']> {
|
237
|
+
return await wallet.isContractPubliclyDeployed(params.address);
|
238
|
+
}
|
239
|
+
|
240
|
+
async function handleIsContractInitialized(
|
241
|
+
wallet: AccountWallet,
|
242
|
+
params: AztecWalletMethodMap['aztec_isContractInitialized']['params'],
|
243
|
+
): Promise<AztecWalletMethodMap['aztec_isContractInitialized']['result']> {
|
244
|
+
return await wallet.isContractInitialized(params.address);
|
245
|
+
}
|
246
|
+
|
247
|
+
async function handleRegisterContract(
|
248
|
+
wallet: AccountWallet,
|
249
|
+
params: AztecWalletMethodMap['aztec_registerContract']['params'],
|
250
|
+
): Promise<AztecWalletMethodMap['aztec_registerContract']['result']> {
|
251
|
+
const { instance, artifact } = params;
|
252
|
+
await wallet.registerContract({ instance, artifact });
|
253
|
+
return true;
|
254
|
+
}
|
255
|
+
|
256
|
+
async function handleRegisterContractClass(
|
257
|
+
wallet: AccountWallet,
|
258
|
+
params: AztecWalletMethodMap['aztec_registerContractClass']['params'],
|
259
|
+
): Promise<AztecWalletMethodMap['aztec_registerContractClass']['result']> {
|
260
|
+
const { artifact } = params;
|
261
|
+
await wallet.registerContractClass(artifact);
|
262
|
+
return true;
|
263
|
+
}
|
264
|
+
|
265
|
+
async function handleGetTxReceipt(
|
266
|
+
wallet: AccountWallet,
|
267
|
+
params: AztecWalletMethodMap['aztec_getTxReceipt']['params'],
|
268
|
+
): Promise<AztecWalletMethodMap['aztec_getTxReceipt']['result']> {
|
269
|
+
const receipt = await wallet.getTxReceipt(params.txHash);
|
270
|
+
if (!receipt) throw new AztecWalletError('transactionNotFound', 'aztec_getTxReceipt');
|
271
|
+
return receipt;
|
272
|
+
}
|
273
|
+
|
274
|
+
async function handleSimulateTx(
|
275
|
+
wallet: AccountWallet,
|
276
|
+
params: AztecWalletMethodMap['aztec_simulateTx']['params'],
|
277
|
+
): Promise<AztecWalletMethodMap['aztec_simulateTx']['result']> {
|
278
|
+
const { txRequest, simulatePublic, msgSender, skipTxValidation, enforceFeePayment, profile } = params;
|
279
|
+
return await wallet.simulateTx(
|
280
|
+
txRequest,
|
281
|
+
simulatePublic,
|
282
|
+
msgSender,
|
283
|
+
skipTxValidation,
|
284
|
+
enforceFeePayment,
|
285
|
+
profile,
|
286
|
+
);
|
287
|
+
}
|
288
|
+
|
289
|
+
async function handleSimulateUnconstrained(
|
290
|
+
wallet: AccountWallet,
|
291
|
+
params: AztecWalletMethodMap['aztec_simulateUnconstrained']['params'],
|
292
|
+
): Promise<AztecWalletMethodMap['aztec_simulateUnconstrained']['result']> {
|
293
|
+
const { functionName, args, to, from } = params;
|
294
|
+
return await wallet.simulateUnconstrained(functionName, args, to, from);
|
295
|
+
}
|
296
|
+
|
297
|
+
async function handleCreateTxExecutionRequest(
|
298
|
+
wallet: AccountWallet,
|
299
|
+
params: AztecWalletMethodMap['aztec_createTxExecutionRequest']['params'],
|
300
|
+
): Promise<AztecWalletMethodMap['aztec_createTxExecutionRequest']['result']> {
|
301
|
+
return await wallet.createTxExecutionRequest(params.exec);
|
302
|
+
}
|
303
|
+
|
304
|
+
async function handleProveTx(
|
305
|
+
wallet: AccountWallet,
|
306
|
+
params: AztecWalletMethodMap['aztec_proveTx']['params'],
|
307
|
+
): Promise<AztecWalletMethodMap['aztec_proveTx']['result']> {
|
308
|
+
return await wallet.proveTx(params.txRequest, params.privateExecutionResult);
|
309
|
+
}
|
310
|
+
|
311
|
+
async function handleSendTx(
|
312
|
+
wallet: AccountWallet,
|
313
|
+
params: AztecWalletMethodMap['aztec_sendTx']['params'],
|
314
|
+
): Promise<AztecWalletMethodMap['aztec_sendTx']['result']> {
|
315
|
+
return await wallet.sendTx(params.tx);
|
316
|
+
}
|
317
|
+
|
318
|
+
async function handleGetTxEffect(
|
319
|
+
wallet: AccountWallet,
|
320
|
+
params: AztecWalletMethodMap['aztec_getTxEffect']['params'],
|
321
|
+
): Promise<AztecWalletMethodMap['aztec_getTxEffect']['result']> {
|
322
|
+
const effect = await wallet.getTxEffect(params.txHash);
|
323
|
+
if (!effect) throw new AztecWalletError('transactionNotFound', 'aztec_getTxEffect');
|
324
|
+
return effect;
|
325
|
+
}
|
326
|
+
|
327
|
+
async function handleGetPublicStorageAt(
|
328
|
+
wallet: AccountWallet,
|
329
|
+
params: AztecWalletMethodMap['aztec_getPublicStorageAt']['params'],
|
330
|
+
): Promise<AztecWalletMethodMap['aztec_getPublicStorageAt']['result']> {
|
331
|
+
return await wallet.getPublicStorageAt(params.contract, params.storageSlot);
|
332
|
+
}
|
333
|
+
|
334
|
+
async function handleGetIncomingNotes(
|
335
|
+
wallet: AccountWallet,
|
336
|
+
params: AztecWalletMethodMap['aztec_getIncomingNotes']['params'],
|
337
|
+
): Promise<AztecWalletMethodMap['aztec_getIncomingNotes']['result']> {
|
338
|
+
return await wallet.getIncomingNotes(params.filter);
|
339
|
+
}
|
340
|
+
|
341
|
+
async function handleAddNote(
|
342
|
+
wallet: AccountWallet,
|
343
|
+
params: AztecWalletMethodMap['aztec_addNote']['params'],
|
344
|
+
): Promise<AztecWalletMethodMap['aztec_addNote']['result']> {
|
345
|
+
await wallet.addNote(params.note);
|
346
|
+
return true;
|
347
|
+
}
|
348
|
+
|
349
|
+
async function handleAddNullifiedNote(
|
350
|
+
wallet: AccountWallet,
|
351
|
+
params: AztecWalletMethodMap['aztec_addNullifiedNote']['params'],
|
352
|
+
): Promise<AztecWalletMethodMap['aztec_addNullifiedNote']['result']> {
|
353
|
+
await wallet.addNullifiedNote(params.note);
|
354
|
+
return true;
|
355
|
+
}
|
356
|
+
|
357
|
+
async function handleGetUnencryptedLogs(
|
358
|
+
wallet: AccountWallet,
|
359
|
+
params: AztecWalletMethodMap['aztec_getUnencryptedLogs']['params'],
|
360
|
+
): Promise<AztecWalletMethodMap['aztec_getUnencryptedLogs']['result']> {
|
361
|
+
return await wallet.getUnencryptedLogs(params.filter);
|
362
|
+
}
|
363
|
+
|
364
|
+
async function handleGetContractClassLogs(
|
365
|
+
wallet: AccountWallet,
|
366
|
+
params: AztecWalletMethodMap['aztec_getContractClassLogs']['params'],
|
367
|
+
): Promise<AztecWalletMethodMap['aztec_getContractClassLogs']['result']> {
|
368
|
+
return await wallet.getContractClassLogs(params.filter);
|
369
|
+
}
|
370
|
+
|
371
|
+
async function handleGetEncryptedEvents(
|
372
|
+
wallet: AccountWallet,
|
373
|
+
params: AztecWalletMethodMap['aztec_getEncryptedEvents']['params'],
|
374
|
+
): Promise<AztecWalletMethodMap['aztec_getEncryptedEvents']['result']> {
|
375
|
+
const { event, from, limit, vpks } = params;
|
376
|
+
return await wallet.getEncryptedEvents(event, from, limit, vpks);
|
377
|
+
}
|
378
|
+
|
379
|
+
async function handleGetUnencryptedEvents(
|
380
|
+
wallet: AccountWallet,
|
381
|
+
params: AztecWalletMethodMap['aztec_getUnencryptedEvents']['params'],
|
382
|
+
): Promise<AztecWalletMethodMap['aztec_getUnencryptedEvents']['result']> {
|
383
|
+
const { event, from, limit } = params;
|
384
|
+
return await wallet.getUnencryptedEvents(event, from, limit);
|
385
|
+
}
|
386
|
+
|
387
|
+
async function handleL1ToL2MembershipWitness(
|
388
|
+
wallet: AccountWallet,
|
389
|
+
params: AztecWalletMethodMap['aztec_getL1ToL2MembershipWitness']['params'],
|
390
|
+
): Promise<AztecWalletMethodMap['aztec_getL1ToL2MembershipWitness']['result']> {
|
391
|
+
const { contractAddress, messageHash, secret } = params;
|
392
|
+
return await wallet.getL1ToL2MembershipWitness(contractAddress, messageHash, secret);
|
393
|
+
}
|
394
|
+
|
395
|
+
export async function aztecWalletHandler<M extends keyof AztecWalletMethodMap>(
|
396
|
+
context: AztecWalletContext,
|
397
|
+
method: M,
|
398
|
+
params: AztecWalletMethodMap[M]['params'],
|
399
|
+
): Promise<AztecWalletMethodMap[M]['result']> {
|
400
|
+
switch (method) {
|
401
|
+
// Chain methods
|
402
|
+
case 'aztec_getBlock':
|
403
|
+
return handleGetBlock(context.wallet, params as AztecWalletMethodMap['aztec_getBlock']['params']);
|
404
|
+
case 'aztec_getBlockNumber':
|
405
|
+
return handleGetBlockNumber(context.wallet);
|
406
|
+
case 'aztec_getChainId':
|
407
|
+
return handleGetChainId(context.wallet);
|
408
|
+
case 'aztec_getVersion':
|
409
|
+
return handleGetVersion(context.wallet);
|
410
|
+
case 'aztec_getNodeInfo':
|
411
|
+
return handleGetNodeInfo(context.wallet);
|
412
|
+
case 'aztec_getCurrentBaseFees':
|
413
|
+
return handleGetCurrentBaseFees(context.wallet);
|
414
|
+
|
415
|
+
// Scopes methods
|
416
|
+
case 'aztec_setScopes':
|
417
|
+
return handleSetScopes(context.wallet, params as AztecWalletMethodMap['aztec_setScopes']['params']);
|
418
|
+
case 'aztec_getScopes':
|
419
|
+
return handleGetScopes(context.wallet);
|
420
|
+
|
421
|
+
// L1->L2 Messages methods
|
422
|
+
case 'aztec_isL1ToL2MessageSynced':
|
423
|
+
return handleL1ToL2MessageSynced(
|
424
|
+
context.wallet,
|
425
|
+
params as AztecWalletMethodMap['aztec_isL1ToL2MessageSynced']['params'],
|
426
|
+
);
|
427
|
+
case 'aztec_getL1ToL2MembershipWitness':
|
428
|
+
return handleL1ToL2MembershipWitness(
|
429
|
+
context.wallet,
|
430
|
+
params as AztecWalletMethodMap['aztec_getL1ToL2MembershipWitness']['params'],
|
431
|
+
);
|
432
|
+
|
433
|
+
// Capsules methods
|
434
|
+
case 'aztec_addCapsule':
|
435
|
+
return handleAddCapsule(context.wallet, params as AztecWalletMethodMap['aztec_addCapsule']['params']);
|
436
|
+
|
437
|
+
// Accounts methods
|
438
|
+
case 'aztec_getAddress':
|
439
|
+
return handleGetAddress(context.wallet);
|
440
|
+
case 'aztec_getCompleteAddress':
|
441
|
+
return handleGetCompleteAddress(context.wallet);
|
442
|
+
case 'aztec_registerAccount':
|
443
|
+
return handleRegisterAccount(
|
444
|
+
context.wallet,
|
445
|
+
params as AztecWalletMethodMap['aztec_registerAccount']['params'],
|
446
|
+
);
|
447
|
+
case 'aztec_getRegisteredAccounts':
|
448
|
+
return handleGetRegisteredAccounts(context.wallet);
|
449
|
+
|
450
|
+
// AuthWitness methods
|
451
|
+
case 'aztec_addAuthWitness':
|
452
|
+
return handleAddAuthWitness(
|
453
|
+
context.wallet,
|
454
|
+
params as AztecWalletMethodMap['aztec_addAuthWitness']['params'],
|
455
|
+
);
|
456
|
+
case 'aztec_getAuthWitness':
|
457
|
+
return handleGetAuthWitness(
|
458
|
+
context.wallet,
|
459
|
+
params as AztecWalletMethodMap['aztec_getAuthWitness']['params'],
|
460
|
+
);
|
461
|
+
case 'aztec_createAuthWit':
|
462
|
+
return handleCreateAuthWit(
|
463
|
+
context.wallet,
|
464
|
+
params as AztecWalletMethodMap['aztec_createAuthWit']['params'],
|
465
|
+
);
|
466
|
+
|
467
|
+
// Senders methods
|
468
|
+
case 'aztec_registerSender':
|
469
|
+
return handleRegisterSender(
|
470
|
+
context.wallet,
|
471
|
+
params as AztecWalletMethodMap['aztec_registerSender']['params'],
|
472
|
+
);
|
473
|
+
case 'aztec_getSenders':
|
474
|
+
return handleGetSenders(context.wallet);
|
475
|
+
case 'aztec_removeSender':
|
476
|
+
return handleRemoveSender(
|
477
|
+
context.wallet,
|
478
|
+
params as AztecWalletMethodMap['aztec_removeSender']['params'],
|
479
|
+
);
|
480
|
+
|
481
|
+
// Contracts methods
|
482
|
+
case 'aztec_getContracts':
|
483
|
+
return handleGetContracts(context.wallet);
|
484
|
+
case 'aztec_getContractInstance':
|
485
|
+
return handleGetContractInstance(
|
486
|
+
context.wallet,
|
487
|
+
params as AztecWalletMethodMap['aztec_getContractInstance']['params'],
|
488
|
+
);
|
489
|
+
case 'aztec_getContractClass':
|
490
|
+
return handleGetContractClass(
|
491
|
+
context.wallet,
|
492
|
+
params as AztecWalletMethodMap['aztec_getContractClass']['params'],
|
493
|
+
);
|
494
|
+
case 'aztec_getContractArtifact':
|
495
|
+
return handleGetContractArtifact(
|
496
|
+
context.wallet,
|
497
|
+
params as AztecWalletMethodMap['aztec_getContractArtifact']['params'],
|
498
|
+
);
|
499
|
+
case 'aztec_isContractClassPubliclyRegistered':
|
500
|
+
return handleIsContractClassPubliclyRegistered(
|
501
|
+
context.wallet,
|
502
|
+
params as AztecWalletMethodMap['aztec_isContractClassPubliclyRegistered']['params'],
|
503
|
+
);
|
504
|
+
case 'aztec_isContractPubliclyDeployed':
|
505
|
+
return handleIsContractPubliclyDeployed(
|
506
|
+
context.wallet,
|
507
|
+
params as AztecWalletMethodMap['aztec_isContractPubliclyDeployed']['params'],
|
508
|
+
);
|
509
|
+
case 'aztec_isContractInitialized':
|
510
|
+
return handleIsContractInitialized(
|
511
|
+
context.wallet,
|
512
|
+
params as AztecWalletMethodMap['aztec_isContractInitialized']['params'],
|
513
|
+
);
|
514
|
+
case 'aztec_registerContract':
|
515
|
+
return handleRegisterContract(
|
516
|
+
context.wallet,
|
517
|
+
params as AztecWalletMethodMap['aztec_registerContract']['params'],
|
518
|
+
);
|
519
|
+
case 'aztec_registerContractClass':
|
520
|
+
return handleRegisterContractClass(
|
521
|
+
context.wallet,
|
522
|
+
params as AztecWalletMethodMap['aztec_registerContractClass']['params'],
|
523
|
+
);
|
524
|
+
case 'aztec_getPublicStorageAt':
|
525
|
+
return handleGetPublicStorageAt(
|
526
|
+
context.wallet,
|
527
|
+
params as AztecWalletMethodMap['aztec_getPublicStorageAt']['params'],
|
528
|
+
);
|
529
|
+
|
530
|
+
// Transactions methods
|
531
|
+
case 'aztec_createTxExecutionRequest':
|
532
|
+
return handleCreateTxExecutionRequest(
|
533
|
+
context.wallet,
|
534
|
+
params as AztecWalletMethodMap['aztec_createTxExecutionRequest']['params'],
|
535
|
+
);
|
536
|
+
case 'aztec_proveTx':
|
537
|
+
return handleProveTx(context.wallet, params as AztecWalletMethodMap['aztec_proveTx']['params']);
|
538
|
+
case 'aztec_sendTx':
|
539
|
+
return handleSendTx(context.wallet, params as AztecWalletMethodMap['aztec_sendTx']['params']);
|
540
|
+
case 'aztec_getTxEffect':
|
541
|
+
return handleGetTxEffect(context.wallet, params as AztecWalletMethodMap['aztec_getTxEffect']['params']);
|
542
|
+
case 'aztec_getTxReceipt':
|
543
|
+
return handleGetTxReceipt(
|
544
|
+
context.wallet,
|
545
|
+
params as AztecWalletMethodMap['aztec_getTxReceipt']['params'],
|
546
|
+
);
|
547
|
+
case 'aztec_simulateTx':
|
548
|
+
return handleSimulateTx(context.wallet, params as AztecWalletMethodMap['aztec_simulateTx']['params']);
|
549
|
+
case 'aztec_simulateUnconstrained':
|
550
|
+
return handleSimulateUnconstrained(
|
551
|
+
context.wallet,
|
552
|
+
params as AztecWalletMethodMap['aztec_simulateUnconstrained']['params'],
|
553
|
+
);
|
554
|
+
|
555
|
+
// Notes methods
|
556
|
+
case 'aztec_getIncomingNotes':
|
557
|
+
return handleGetIncomingNotes(
|
558
|
+
context.wallet,
|
559
|
+
params as AztecWalletMethodMap['aztec_getIncomingNotes']['params'],
|
560
|
+
);
|
561
|
+
case 'aztec_addNote':
|
562
|
+
return handleAddNote(context.wallet, params as AztecWalletMethodMap['aztec_addNote']['params']);
|
563
|
+
case 'aztec_addNullifiedNote':
|
564
|
+
return handleAddNullifiedNote(
|
565
|
+
context.wallet,
|
566
|
+
params as AztecWalletMethodMap['aztec_addNullifiedNote']['params'],
|
567
|
+
);
|
568
|
+
|
569
|
+
// Logs methods
|
570
|
+
case 'aztec_getUnencryptedLogs':
|
571
|
+
return handleGetUnencryptedLogs(
|
572
|
+
context.wallet,
|
573
|
+
params as AztecWalletMethodMap['aztec_getUnencryptedLogs']['params'],
|
574
|
+
);
|
575
|
+
case 'aztec_getContractClassLogs':
|
576
|
+
return handleGetContractClassLogs(
|
577
|
+
context.wallet,
|
578
|
+
params as AztecWalletMethodMap['aztec_getContractClassLogs']['params'],
|
579
|
+
);
|
580
|
+
case 'aztec_getEncryptedEvents':
|
581
|
+
return handleGetEncryptedEvents(
|
582
|
+
context.wallet,
|
583
|
+
params as AztecWalletMethodMap['aztec_getEncryptedEvents']['params'],
|
584
|
+
);
|
585
|
+
case 'aztec_getUnencryptedEvents':
|
586
|
+
return handleGetUnencryptedEvents(
|
587
|
+
context.wallet,
|
588
|
+
params as AztecWalletMethodMap['aztec_getUnencryptedEvents']['params'],
|
589
|
+
);
|
590
|
+
default:
|
591
|
+
throw new AztecWalletError('invalidRequest', `Method not supported: ${String(method)}`);
|
592
|
+
}
|
593
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import {
|
2
|
+
AuthWitness,
|
3
|
+
AztecAddress,
|
4
|
+
Contract,
|
5
|
+
NoFeePaymentMethod,
|
6
|
+
type ContractArtifact,
|
7
|
+
} from '@aztec/aztec.js';
|
8
|
+
|
9
|
+
import { GasSettings } from '@aztec/circuits.js';
|
10
|
+
import type { ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
|
11
|
+
|
12
|
+
import type { AztecWalletContext, TransactionFunctionCall, TransactionParams } from '../types.js';
|
13
|
+
import { AztecWalletError } from '../errors.js';
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Handles the 'aztec_sendTransaction' JSON-RPC method.
|
17
|
+
* Sends transactions to the Aztec network and returns the transaction hash.
|
18
|
+
* @param params - The transaction parameters
|
19
|
+
* @param params.functionCalls - Array of function calls to execute
|
20
|
+
* @param params.authwits - Optional array of authorization witnesses for the transaction
|
21
|
+
* @returns A Promise that resolves to the transaction hash string
|
22
|
+
*/
|
23
|
+
export async function sendTransaction(
|
24
|
+
context: AztecWalletContext,
|
25
|
+
params: TransactionParams,
|
26
|
+
): Promise<string> {
|
27
|
+
try {
|
28
|
+
// Setup the execution request without the calls for now
|
29
|
+
const executionRequestInit: ExecutionRequestInit = {
|
30
|
+
calls: [],
|
31
|
+
authWitnesses: params.authwits?.map(AuthWitness.fromString) ?? [],
|
32
|
+
// TODO: Figure out what we should be doing with this fee parameter
|
33
|
+
fee: {
|
34
|
+
paymentMethod: new NoFeePaymentMethod(),
|
35
|
+
gasSettings: GasSettings.default({ maxFeesPerGas: await context.wallet.getCurrentBaseFees() }),
|
36
|
+
},
|
37
|
+
};
|
38
|
+
|
39
|
+
// Get artifacts and contracts first
|
40
|
+
const contractMap = new Map<string, { contract: Contract; artifact: ContractArtifact }>();
|
41
|
+
for (const c of params.functionCalls) {
|
42
|
+
const contractAddress = AztecAddress.fromString(c.contractAddress);
|
43
|
+
if (!contractMap.has(c.contractAddress)) {
|
44
|
+
const artifact = await context.contractArtifactCache.getContractArtifact(contractAddress);
|
45
|
+
const contract = await Contract.at(contractAddress, artifact, context.wallet);
|
46
|
+
contractMap.set(c.contractAddress, { contract, artifact });
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
// Now build the execution request
|
51
|
+
for (const c of params.functionCalls) {
|
52
|
+
// biome-ignore lint/style/noNonNullAssertion: we know the contract is in the map
|
53
|
+
const { contract } = contractMap.get(c.contractAddress)!;
|
54
|
+
const functionCall = contract.methods[c.functionName](...c.args);
|
55
|
+
executionRequestInit.calls.push(await functionCall.request());
|
56
|
+
}
|
57
|
+
const txExecutionRequest = await context.wallet.createTxExecutionRequest(executionRequestInit);
|
58
|
+
const simulatedTx = await context.wallet.simulateTx(txExecutionRequest, true /* simulatePublic */);
|
59
|
+
const txProvingResult = await context.wallet.proveTx(
|
60
|
+
txExecutionRequest,
|
61
|
+
simulatedTx.privateExecutionResult,
|
62
|
+
);
|
63
|
+
const txHash = await context.wallet.sendTx(txProvingResult.toTx());
|
64
|
+
return txHash.toString();
|
65
|
+
} catch (error) {
|
66
|
+
throw new AztecWalletError('unknownInternalError');
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Handles the 'aztec_simulateTransaction' JSON-RPC method.
|
72
|
+
* Simulates a transaction without submitting it to the network.
|
73
|
+
* @param params - The transaction parameters to simulate
|
74
|
+
* @param params.contractAddress - The target contract address
|
75
|
+
* @param params.functionName - The contract function to call
|
76
|
+
* @param params.args - The function arguments
|
77
|
+
* @returns A Promise that resolves to the simulation result
|
78
|
+
*/
|
79
|
+
export async function simulateTransaction(
|
80
|
+
context: AztecWalletContext,
|
81
|
+
params: TransactionFunctionCall,
|
82
|
+
): Promise<unknown> {
|
83
|
+
try {
|
84
|
+
const { contractAddress, functionName, args } = params;
|
85
|
+
const addr = AztecAddress.fromString(contractAddress);
|
86
|
+
const artifact = await context.contractArtifactCache.getContractArtifact(addr);
|
87
|
+
const contract = await Contract.at(addr, artifact, context.wallet);
|
88
|
+
const result = await contract.methods[functionName](...args).simulate();
|
89
|
+
// TODO: Is this sufficient for serializing the result?
|
90
|
+
switch (typeof result) {
|
91
|
+
case 'string':
|
92
|
+
return result;
|
93
|
+
case 'bigint':
|
94
|
+
return result.toString();
|
95
|
+
case 'object':
|
96
|
+
if (result instanceof Uint8Array) {
|
97
|
+
return Buffer.from(result).toString('hex');
|
98
|
+
}
|
99
|
+
return result;
|
100
|
+
default:
|
101
|
+
return result;
|
102
|
+
}
|
103
|
+
} catch (error) {
|
104
|
+
if (error instanceof AztecWalletError) {
|
105
|
+
throw error;
|
106
|
+
}
|
107
|
+
console.error('Error simulating transaction:', error);
|
108
|
+
throw new AztecWalletError('unknownInternalError', 'aztec_simulateTransaction');
|
109
|
+
}
|
110
|
+
}
|