@aztec/wallet-sdk 0.0.1-commit.001888fc

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.
Files changed (66) hide show
  1. package/README.md +321 -0
  2. package/dest/base-wallet/base_wallet.d.ts +142 -0
  3. package/dest/base-wallet/base_wallet.d.ts.map +1 -0
  4. package/dest/base-wallet/base_wallet.js +357 -0
  5. package/dest/base-wallet/index.d.ts +3 -0
  6. package/dest/base-wallet/index.d.ts.map +1 -0
  7. package/dest/base-wallet/index.js +2 -0
  8. package/dest/base-wallet/utils.d.ts +49 -0
  9. package/dest/base-wallet/utils.d.ts.map +1 -0
  10. package/dest/base-wallet/utils.js +131 -0
  11. package/dest/crypto.d.ts +192 -0
  12. package/dest/crypto.d.ts.map +1 -0
  13. package/dest/crypto.js +394 -0
  14. package/dest/emoji_alphabet.d.ts +35 -0
  15. package/dest/emoji_alphabet.d.ts.map +1 -0
  16. package/dest/emoji_alphabet.js +299 -0
  17. package/dest/extension/handlers/background_connection_handler.d.ts +158 -0
  18. package/dest/extension/handlers/background_connection_handler.d.ts.map +1 -0
  19. package/dest/extension/handlers/background_connection_handler.js +258 -0
  20. package/dest/extension/handlers/content_script_connection_handler.d.ts +56 -0
  21. package/dest/extension/handlers/content_script_connection_handler.d.ts.map +1 -0
  22. package/dest/extension/handlers/content_script_connection_handler.js +174 -0
  23. package/dest/extension/handlers/index.d.ts +12 -0
  24. package/dest/extension/handlers/index.d.ts.map +1 -0
  25. package/dest/extension/handlers/index.js +10 -0
  26. package/dest/extension/handlers/internal_message_types.d.ts +63 -0
  27. package/dest/extension/handlers/internal_message_types.d.ts.map +1 -0
  28. package/dest/extension/handlers/internal_message_types.js +22 -0
  29. package/dest/extension/provider/extension_provider.d.ts +107 -0
  30. package/dest/extension/provider/extension_provider.d.ts.map +1 -0
  31. package/dest/extension/provider/extension_provider.js +160 -0
  32. package/dest/extension/provider/extension_wallet.d.ts +132 -0
  33. package/dest/extension/provider/extension_wallet.d.ts.map +1 -0
  34. package/dest/extension/provider/extension_wallet.js +278 -0
  35. package/dest/extension/provider/index.d.ts +3 -0
  36. package/dest/extension/provider/index.d.ts.map +1 -0
  37. package/dest/extension/provider/index.js +2 -0
  38. package/dest/manager/index.d.ts +3 -0
  39. package/dest/manager/index.d.ts.map +1 -0
  40. package/dest/manager/index.js +1 -0
  41. package/dest/manager/types.d.ts +167 -0
  42. package/dest/manager/types.d.ts.map +1 -0
  43. package/dest/manager/types.js +19 -0
  44. package/dest/manager/wallet_manager.d.ts +70 -0
  45. package/dest/manager/wallet_manager.d.ts.map +1 -0
  46. package/dest/manager/wallet_manager.js +226 -0
  47. package/dest/types.d.ts +123 -0
  48. package/dest/types.d.ts.map +1 -0
  49. package/dest/types.js +11 -0
  50. package/package.json +105 -0
  51. package/src/base-wallet/base_wallet.ts +498 -0
  52. package/src/base-wallet/index.ts +2 -0
  53. package/src/base-wallet/utils.ts +238 -0
  54. package/src/crypto.ts +499 -0
  55. package/src/emoji_alphabet.ts +317 -0
  56. package/src/extension/handlers/background_connection_handler.ts +423 -0
  57. package/src/extension/handlers/content_script_connection_handler.ts +246 -0
  58. package/src/extension/handlers/index.ts +25 -0
  59. package/src/extension/handlers/internal_message_types.ts +69 -0
  60. package/src/extension/provider/extension_provider.ts +233 -0
  61. package/src/extension/provider/extension_wallet.ts +329 -0
  62. package/src/extension/provider/index.ts +7 -0
  63. package/src/manager/index.ts +12 -0
  64. package/src/manager/types.ts +177 -0
  65. package/src/manager/wallet_manager.ts +257 -0
  66. package/src/types.ts +132 -0
@@ -0,0 +1,498 @@
1
+ import type { Account } from '@aztec/aztec.js/account';
2
+ import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
3
+ import {
4
+ type InteractionWaitOptions,
5
+ NO_WAIT,
6
+ type SendReturn,
7
+ extractOffchainOutput,
8
+ } from '@aztec/aztec.js/contracts';
9
+ import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
10
+ import { waitForTx } from '@aztec/aztec.js/node';
11
+ import type {
12
+ Aliased,
13
+ AppCapabilities,
14
+ BatchResults,
15
+ BatchedMethod,
16
+ ExecuteUtilityOptions,
17
+ PrivateEvent,
18
+ PrivateEventFilter,
19
+ ProfileOptions,
20
+ SendOptions,
21
+ SimulateOptions,
22
+ Wallet,
23
+ WalletCapabilities,
24
+ } from '@aztec/aztec.js/wallet';
25
+ import {
26
+ GAS_ESTIMATION_DA_GAS_LIMIT,
27
+ GAS_ESTIMATION_L2_GAS_LIMIT,
28
+ GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT,
29
+ GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
30
+ } from '@aztec/constants';
31
+ import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
32
+ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
33
+ import { Fr } from '@aztec/foundation/curves/bn254';
34
+ import { createLogger } from '@aztec/foundation/log';
35
+ import type { FieldsOf } from '@aztec/foundation/types';
36
+ import { type AccessScopes, displayDebugLogs } from '@aztec/pxe/client/lazy';
37
+ import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
38
+ import {
39
+ type ContractArtifact,
40
+ type EventMetadataDefinition,
41
+ type FunctionCall,
42
+ decodeFromAbi,
43
+ } from '@aztec/stdlib/abi';
44
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
45
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
46
+ import {
47
+ type ContractInstanceWithAddress,
48
+ computePartialAddress,
49
+ getContractClassFromArtifact,
50
+ } from '@aztec/stdlib/contract';
51
+ import { SimulationError } from '@aztec/stdlib/errors';
52
+ import { Gas, GasSettings } from '@aztec/stdlib/gas';
53
+ import { siloNullifier } from '@aztec/stdlib/hash';
54
+ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
55
+ import {
56
+ BlockHeader,
57
+ type TxExecutionRequest,
58
+ type TxProfileResult,
59
+ TxSimulationResult,
60
+ type UtilityExecutionResult,
61
+ } from '@aztec/stdlib/tx';
62
+ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
63
+
64
+ import { inspect } from 'util';
65
+
66
+ import { buildMergedSimulationResult, extractOptimizablePublicStaticCalls, simulateViaNode } from './utils.js';
67
+
68
+ /**
69
+ * Options to configure fee payment for a transaction
70
+ */
71
+ export type FeeOptions = {
72
+ /**
73
+ * A wallet-provided fallback fee payment method that is used only if the transaction that is being constructed
74
+ * doesn't already include one
75
+ */
76
+ walletFeePaymentMethod?: FeePaymentMethod;
77
+ /** Configuration options for the account to properly handle the selected fee payment method */
78
+ accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
79
+ /** The gas settings to use for the transaction */
80
+ gasSettings: GasSettings;
81
+ };
82
+
83
+ /**
84
+ * A base class for Wallet implementations
85
+ */
86
+ export abstract class BaseWallet implements Wallet {
87
+ protected minFeePadding = 0.5;
88
+ protected cancellableTransactions = false;
89
+
90
+ // Protected because we want to force wallets to instantiate their own PXE.
91
+ protected constructor(
92
+ protected readonly pxe: PXE,
93
+ protected readonly aztecNode: AztecNode,
94
+ protected log = createLogger('wallet-sdk:base_wallet'),
95
+ ) {}
96
+
97
+ protected scopesFrom(from: AztecAddress, additionalScopes: AztecAddress[] = []): AztecAddress[] {
98
+ const allScopes = from.isZero() ? additionalScopes : [from, ...additionalScopes];
99
+ const scopeSet = new Set(allScopes.map(address => address.toString()));
100
+ return [...scopeSet].map(AztecAddress.fromString);
101
+ }
102
+
103
+ protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
104
+
105
+ abstract getAccounts(): Promise<Aliased<AztecAddress>[]>;
106
+
107
+ /**
108
+ * Returns the list of aliased contacts associated with the wallet.
109
+ * This base implementation directly returns PXE's senders, but note that in general contacts are a superset of senders.
110
+ * - Senders: Addresses we check during synching in case they sent us notes,
111
+ * - Contacts: more general concept akin to a phone's contact list.
112
+ * @returns The aliased collection of AztecAddresses that form this wallet's address book
113
+ */
114
+ async getAddressBook(): Promise<Aliased<AztecAddress>[]> {
115
+ const senders: AztecAddress[] = await this.pxe.getSenders();
116
+ return senders.map(sender => ({ item: sender, alias: '' }));
117
+ }
118
+
119
+ async getChainInfo(): Promise<ChainInfo> {
120
+ const { l1ChainId, rollupVersion } = await this.aztecNode.getNodeInfo();
121
+ return { chainId: new Fr(l1ChainId), version: new Fr(rollupVersion) };
122
+ }
123
+
124
+ protected async createTxExecutionRequestFromPayloadAndFee(
125
+ executionPayload: ExecutionPayload,
126
+ from: AztecAddress,
127
+ feeOptions: FeeOptions,
128
+ ): Promise<TxExecutionRequest> {
129
+ const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
130
+ const executionOptions: DefaultAccountEntrypointOptions = {
131
+ txNonce: Fr.random(),
132
+ cancellable: this.cancellableTransactions,
133
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
134
+ };
135
+ const finalExecutionPayload = feeExecutionPayload
136
+ ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
137
+ : executionPayload;
138
+ const fromAccount = await this.getAccountFromAddress(from);
139
+ const chainInfo = await this.getChainInfo();
140
+ return fromAccount.createTxExecutionRequest(
141
+ finalExecutionPayload,
142
+ feeOptions.gasSettings,
143
+ chainInfo,
144
+ executionOptions,
145
+ );
146
+ }
147
+
148
+ public async createAuthWit(
149
+ from: AztecAddress,
150
+ messageHashOrIntent: IntentInnerHash | CallIntent,
151
+ ): Promise<AuthWitness> {
152
+ const account = await this.getAccountFromAddress(from);
153
+ const chainInfo = await this.getChainInfo();
154
+ return account.createAuthWit(messageHashOrIntent, chainInfo);
155
+ }
156
+
157
+ /**
158
+ * Request capabilities from the wallet.
159
+ *
160
+ * This method is wallet-implementation-dependent and must be provided by classes extending BaseWallet.
161
+ * Embedded wallets typically don't support capability-based authorization (no user authorization flow),
162
+ * while external wallets (browser extensions, hardware wallets) implement this to reduce authorization
163
+ * friction by allowing apps to request permissions upfront.
164
+ *
165
+ * TODO: Consider making it abstract so implementing it is a conscious decision. Leaving it as-is
166
+ * while the feature stabilizes.
167
+ *
168
+ * @param _manifest - Application capability manifest declaring what operations the app needs
169
+ */
170
+ public requestCapabilities(_manifest: AppCapabilities): Promise<WalletCapabilities> {
171
+ throw new Error('Not implemented');
172
+ }
173
+
174
+ public async batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
175
+ const results: any[] = [];
176
+ for (const method of methods) {
177
+ const { name, args } = method;
178
+ // Type safety is guaranteed by the BatchedMethod type, which ensures that:
179
+ // 1. `name` is a valid batchable method name
180
+ // 2. `args` matches the parameter types of that specific method
181
+ // 3. The return type is correctly mapped in BatchResults<T>
182
+ // We use dynamic dispatch here for simplicity, but the types are enforced at the call site.
183
+
184
+ const fn = this[name] as (...args: any[]) => Promise<any>;
185
+ const result = await fn.apply(this, args);
186
+ // Wrap result with method name for discriminated union deserialization
187
+ results.push({ name, result });
188
+ }
189
+ return results as BatchResults<T>;
190
+ }
191
+
192
+ /**
193
+ * Completes partial user-provided fee options with wallet defaults.
194
+ * @param from - The address where the transaction is being sent from
195
+ * @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
196
+ * @param gasSettings - User-provided partial gas settings
197
+ * @returns - Complete fee options that can be used to create a transaction execution request
198
+ */
199
+ protected async completeFeeOptions(
200
+ from: AztecAddress,
201
+ feePayer?: AztecAddress,
202
+ gasSettings?: Partial<FieldsOf<GasSettings>>,
203
+ ): Promise<FeeOptions> {
204
+ const maxFeesPerGas =
205
+ gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
206
+ let accountFeePaymentMethodOptions;
207
+ // The transaction does not include a fee payment method, so we set the flag
208
+ // for the account to use its fee juice balance
209
+ if (!feePayer) {
210
+ accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
211
+ } else {
212
+ // The transaction includes fee payment method, so we check if we are the fee payer for it
213
+ // (this can only happen if the embedded payment method is FeeJuiceWithClaim)
214
+ accountFeePaymentMethodOptions = from.equals(feePayer)
215
+ ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
216
+ : AccountFeePaymentMethodOptions.EXTERNAL;
217
+ }
218
+ const fullGasSettings: GasSettings = GasSettings.default({ ...gasSettings, maxFeesPerGas });
219
+ this.log.debug(`Using L2 gas settings`, fullGasSettings);
220
+ return {
221
+ gasSettings: fullGasSettings,
222
+ walletFeePaymentMethod: undefined,
223
+ accountFeePaymentMethodOptions,
224
+ };
225
+ }
226
+
227
+ /**
228
+ * Completes partial user-provided fee options with unreasonably high gas limits
229
+ * for gas estimation. Uses the same logic as completeFeeOptions but sets high limits
230
+ * to avoid running out of gas during estimation.
231
+ * @param from - The address where the transaction is being sent from
232
+ * @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
233
+ * @param gasSettings - User-provided partial gas settings
234
+ */
235
+ protected async completeFeeOptionsForEstimation(
236
+ from: AztecAddress,
237
+ feePayer?: AztecAddress,
238
+ gasSettings?: Partial<FieldsOf<GasSettings>>,
239
+ ) {
240
+ const defaultFeeOptions = await this.completeFeeOptions(from, feePayer, gasSettings);
241
+ const {
242
+ gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
243
+ } = defaultFeeOptions;
244
+ // Use unrealistically high gas limits for estimation to avoid running out of gas.
245
+ // They will be tuned down after the simulation.
246
+ const gasSettingsForEstimation = new GasSettings(
247
+ new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
248
+ new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
249
+ maxFeesPerGas,
250
+ maxPriorityFeesPerGas,
251
+ );
252
+ return {
253
+ ...defaultFeeOptions,
254
+ gasSettings: gasSettingsForEstimation,
255
+ };
256
+ }
257
+
258
+ registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
259
+ return this.pxe.registerSender(address);
260
+ }
261
+
262
+ async registerContract(
263
+ instance: ContractInstanceWithAddress,
264
+ artifact?: ContractArtifact,
265
+ secretKey?: Fr,
266
+ ): Promise<ContractInstanceWithAddress> {
267
+ const existingInstance = await this.pxe.getContractInstance(instance.address);
268
+
269
+ if (existingInstance) {
270
+ // Instance already registered in the wallet
271
+ if (artifact) {
272
+ const thisContractClass = await getContractClassFromArtifact(artifact);
273
+ if (!thisContractClass.id.equals(existingInstance.currentContractClassId)) {
274
+ // wallet holds an outdated version of this contract
275
+ await this.pxe.updateContract(instance.address, artifact);
276
+ instance.currentContractClassId = thisContractClass.id;
277
+ }
278
+ }
279
+ // If no artifact provided, we just use the existing registration
280
+ } else {
281
+ // Instance not registered yet
282
+ if (!artifact) {
283
+ // Try to get the artifact from the wallet's contract class storage
284
+ artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
285
+ if (!artifact) {
286
+ throw new Error(
287
+ `Cannot register contract at ${instance.address.toString()}: artifact is required but not provided, and wallet does not have the artifact for contract class ${instance.currentContractClassId.toString()}`,
288
+ );
289
+ }
290
+ }
291
+ await this.pxe.registerContract({ artifact, instance });
292
+ }
293
+
294
+ if (secretKey) {
295
+ await this.pxe.registerAccount(secretKey, await computePartialAddress(instance));
296
+ }
297
+ return instance;
298
+ }
299
+
300
+ /**
301
+ * Simulates calls through the standard PXE path (account entrypoint).
302
+ * @param executionPayload - The execution payload to simulate.
303
+ * @param from - The sender address.
304
+ * @param feeOptions - Fee options for the transaction.
305
+ * @param skipTxValidation - Whether to skip tx validation.
306
+ * @param skipFeeEnforcement - Whether to skip fee enforcement.
307
+ * @param scopes - The scopes to use for the simulation.
308
+ */
309
+ protected async simulateViaEntrypoint(
310
+ executionPayload: ExecutionPayload,
311
+ from: AztecAddress,
312
+ feeOptions: FeeOptions,
313
+ scopes: AccessScopes,
314
+ skipTxValidation?: boolean,
315
+ skipFeeEnforcement?: boolean,
316
+ ) {
317
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
318
+ return this.pxe.simulateTx(txRequest, { simulatePublic: true, skipTxValidation, skipFeeEnforcement, scopes });
319
+ }
320
+
321
+ /**
322
+ * Simulates a transaction, optimizing leading public static calls by running them directly
323
+ * on the node while sending the remaining calls through the standard PXE path.
324
+ * Return values from both paths are merged back in original call order.
325
+ * @param executionPayload - The execution payload to simulate.
326
+ * @param opts - Simulation options (from address, fee settings, etc.).
327
+ * @returns The merged simulation result.
328
+ */
329
+ async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
330
+ const feeOptions = opts.fee?.estimateGas
331
+ ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings)
332
+ : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
333
+ const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
334
+ const remainingPayload = { ...executionPayload, calls: remainingCalls };
335
+
336
+ const chainInfo = await this.getChainInfo();
337
+ let blockHeader: BlockHeader;
338
+ // PXE might not be synced yet, so we pull the latest header from the node
339
+ // To keep things consistent, we'll always try with PXE first
340
+ try {
341
+ blockHeader = await this.pxe.getSyncedBlockHeader();
342
+ } catch {
343
+ blockHeader = (await this.aztecNode.getBlockHeader())!;
344
+ }
345
+
346
+ const [optimizedResults, normalResult] = await Promise.all([
347
+ optimizableCalls.length > 0
348
+ ? simulateViaNode(
349
+ this.aztecNode,
350
+ optimizableCalls,
351
+ opts.from,
352
+ chainInfo,
353
+ feeOptions.gasSettings,
354
+ blockHeader,
355
+ opts.skipFeeEnforcement ?? true,
356
+ this.getContractName.bind(this),
357
+ )
358
+ : Promise.resolve([]),
359
+ remainingCalls.length > 0
360
+ ? this.simulateViaEntrypoint(
361
+ remainingPayload,
362
+ opts.from,
363
+ feeOptions,
364
+ this.scopesFrom(opts.from, opts.additionalScopes),
365
+ opts.skipTxValidation,
366
+ opts.skipFeeEnforcement ?? true,
367
+ )
368
+ : Promise.resolve(null),
369
+ ]);
370
+
371
+ return buildMergedSimulationResult(optimizedResults, normalResult);
372
+ }
373
+
374
+ async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
375
+ const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
376
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
377
+ return this.pxe.profileTx(txRequest, {
378
+ profileMode: opts.profileMode,
379
+ skipProofGeneration: opts.skipProofGeneration ?? true,
380
+ scopes: this.scopesFrom(opts.from, opts.additionalScopes),
381
+ });
382
+ }
383
+
384
+ public async sendTx<W extends InteractionWaitOptions = undefined>(
385
+ executionPayload: ExecutionPayload,
386
+ opts: SendOptions<W>,
387
+ ): Promise<SendReturn<W>> {
388
+ const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
389
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
390
+ const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
391
+ const offchainOutput = extractOffchainOutput(
392
+ provenTx.getOffchainEffects(),
393
+ provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
394
+ );
395
+ const tx = await provenTx.toTx();
396
+ const txHash = tx.getTxHash();
397
+ if (await this.aztecNode.getTxEffect(txHash)) {
398
+ throw new Error(`A settled tx with equal hash ${txHash.toString()} exists.`);
399
+ }
400
+ this.log.debug(`Sending transaction ${txHash}`);
401
+ await this.aztecNode.sendTx(tx).catch(err => {
402
+ throw this.contextualizeError(err, inspect(tx));
403
+ });
404
+ this.log.info(`Sent transaction ${txHash}`);
405
+
406
+ // If wait is NO_WAIT, return txHash immediately
407
+ if (opts.wait === NO_WAIT) {
408
+ return { txHash, ...offchainOutput } as SendReturn<W>;
409
+ }
410
+
411
+ // Otherwise, wait for the full receipt (default behavior on wait: undefined)
412
+ const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
413
+ const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
414
+
415
+ // Display debug logs from public execution if present (served in test mode only)
416
+ if (receipt.debugLogs?.length) {
417
+ await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
418
+ }
419
+
420
+ return { receipt, ...offchainOutput } as SendReturn<W>;
421
+ }
422
+
423
+ /**
424
+ * Resolves a contract address to a human-readable name via PXE, if available.
425
+ * @param address - The contract address to resolve.
426
+ */
427
+ protected async getContractName(address: AztecAddress): Promise<string | undefined> {
428
+ const instance = await this.pxe.getContractInstance(address);
429
+ if (!instance) {
430
+ return undefined;
431
+ }
432
+ const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
433
+ return artifact?.name;
434
+ }
435
+
436
+ protected contextualizeError(err: Error, ...context: string[]): Error {
437
+ let contextStr = '';
438
+ if (context.length > 0) {
439
+ contextStr = `\nContext:\n${context.join('\n')}`;
440
+ }
441
+ if (err instanceof SimulationError) {
442
+ err.setAztecContext(contextStr);
443
+ } else {
444
+ this.log.error(err.name, err);
445
+ this.log.debug(contextStr);
446
+ }
447
+ return err;
448
+ }
449
+
450
+ executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
451
+ return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: [opts.scope] });
452
+ }
453
+
454
+ async getPrivateEvents<T>(
455
+ eventDef: EventMetadataDefinition,
456
+ eventFilter: PrivateEventFilter,
457
+ ): Promise<PrivateEvent<T>[]> {
458
+ const pxeEvents = await this.pxe.getPrivateEvents(eventDef.eventSelector, eventFilter);
459
+
460
+ const decodedEvents = pxeEvents.map((pxeEvent: PackedPrivateEvent): PrivateEvent<T> => {
461
+ return {
462
+ event: decodeFromAbi([eventDef.abiType], pxeEvent.packedEvent) as T,
463
+ metadata: {
464
+ l2BlockNumber: pxeEvent.l2BlockNumber,
465
+ l2BlockHash: pxeEvent.l2BlockHash,
466
+ txHash: pxeEvent.txHash,
467
+ },
468
+ };
469
+ });
470
+
471
+ return decodedEvents;
472
+ }
473
+
474
+ async getContractMetadata(address: AztecAddress) {
475
+ const instance = await this.pxe.getContractInstance(address);
476
+ const initNullifier = await siloNullifier(address, address.toField());
477
+ const publiclyRegisteredContract = await this.aztecNode.getContract(address);
478
+ const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
479
+ const isContractUpdated =
480
+ publiclyRegisteredContract &&
481
+ !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
482
+ return {
483
+ instance: instance ?? undefined,
484
+ isContractInitialized: !!initNullifierMembershipWitness,
485
+ isContractPublished: !!publiclyRegisteredContract,
486
+ isContractUpdated: !!isContractUpdated,
487
+ updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
488
+ };
489
+ }
490
+
491
+ async getContractClassMetadata(id: Fr) {
492
+ const publiclyRegisteredContractClass = await this.aztecNode.getContractClass(id);
493
+ return {
494
+ isArtifactRegistered: !!(await this.pxe.getContractArtifact(id)),
495
+ isContractClassPubliclyRegistered: !!publiclyRegisteredContractClass,
496
+ };
497
+ }
498
+ }
@@ -0,0 +1,2 @@
1
+ export { BaseWallet, type FeeOptions } from './base_wallet.js';
2
+ export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';