@aztec/wallet-sdk 0.0.1-commit.4ad48494d → 0.0.1-commit.4d3c002

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 (58) hide show
  1. package/dest/base-wallet/base_wallet.d.ts +31 -19
  2. package/dest/base-wallet/base_wallet.d.ts.map +1 -1
  3. package/dest/base-wallet/base_wallet.js +108 -48
  4. package/dest/base-wallet/index.d.ts +2 -2
  5. package/dest/base-wallet/index.d.ts.map +1 -1
  6. package/dest/base-wallet/utils.d.ts +3 -2
  7. package/dest/base-wallet/utils.d.ts.map +1 -1
  8. package/dest/base-wallet/utils.js +6 -3
  9. package/dest/crypto.d.ts +39 -1
  10. package/dest/crypto.d.ts.map +1 -1
  11. package/dest/crypto.js +88 -0
  12. package/dest/extension/provider/extension_wallet.d.ts +4 -6
  13. package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
  14. package/dest/extension/provider/extension_wallet.js +9 -2
  15. package/dest/extension/provider/index.d.ts +2 -2
  16. package/dest/extension/provider/index.d.ts.map +1 -1
  17. package/dest/iframe/handlers/iframe_connection_handler.d.ts +118 -0
  18. package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
  19. package/dest/iframe/handlers/iframe_connection_handler.js +228 -0
  20. package/dest/iframe/handlers/index.d.ts +2 -0
  21. package/dest/iframe/handlers/index.d.ts.map +1 -0
  22. package/dest/iframe/handlers/index.js +1 -0
  23. package/dest/iframe/provider/iframe_discovery.d.ts +25 -0
  24. package/dest/iframe/provider/iframe_discovery.d.ts.map +1 -0
  25. package/dest/iframe/provider/iframe_discovery.js +167 -0
  26. package/dest/iframe/provider/iframe_provider.d.ts +65 -0
  27. package/dest/iframe/provider/iframe_provider.d.ts.map +1 -0
  28. package/dest/iframe/provider/iframe_provider.js +257 -0
  29. package/dest/iframe/provider/iframe_wallet.d.ts +68 -0
  30. package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
  31. package/dest/iframe/provider/iframe_wallet.js +200 -0
  32. package/dest/iframe/provider/index.d.ts +4 -0
  33. package/dest/iframe/provider/index.d.ts.map +1 -0
  34. package/dest/iframe/provider/index.js +3 -0
  35. package/dest/manager/types.d.ts +6 -5
  36. package/dest/manager/types.d.ts.map +1 -1
  37. package/dest/manager/wallet_manager.d.ts +1 -1
  38. package/dest/manager/wallet_manager.d.ts.map +1 -1
  39. package/dest/manager/wallet_manager.js +48 -18
  40. package/dest/types.d.ts +14 -2
  41. package/dest/types.d.ts.map +1 -1
  42. package/dest/types.js +4 -0
  43. package/package.json +12 -8
  44. package/src/base-wallet/base_wallet.ts +159 -81
  45. package/src/base-wallet/index.ts +1 -1
  46. package/src/base-wallet/utils.ts +8 -0
  47. package/src/crypto.ts +104 -0
  48. package/src/extension/provider/extension_wallet.ts +13 -10
  49. package/src/extension/provider/index.ts +1 -1
  50. package/src/iframe/handlers/iframe_connection_handler.ts +328 -0
  51. package/src/iframe/handlers/index.ts +7 -0
  52. package/src/iframe/provider/iframe_discovery.ts +185 -0
  53. package/src/iframe/provider/iframe_provider.ts +331 -0
  54. package/src/iframe/provider/iframe_wallet.ts +229 -0
  55. package/src/iframe/provider/index.ts +3 -0
  56. package/src/manager/types.ts +5 -4
  57. package/src/manager/wallet_manager.ts +55 -23
  58. package/src/types.ts +13 -0
@@ -1,21 +1,28 @@
1
- import type { Account } from '@aztec/aztec.js/account';
1
+ import type { Account, NoFrom } from '@aztec/aztec.js/account';
2
+ import { NO_FROM } from '@aztec/aztec.js/account';
2
3
  import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
3
- import { type InteractionWaitOptions, NO_WAIT, type SendReturn } from '@aztec/aztec.js/contracts';
4
+ import {
5
+ type InteractionWaitOptions,
6
+ NO_WAIT,
7
+ type SendReturn,
8
+ extractOffchainOutput,
9
+ } from '@aztec/aztec.js/contracts';
4
10
  import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
5
11
  import { waitForTx } from '@aztec/aztec.js/node';
6
- import type {
7
- Aliased,
8
- AppCapabilities,
9
- BatchResults,
10
- BatchedMethod,
11
- PrivateEvent,
12
- PrivateEventFilter,
13
- ProfileOptions,
14
- SendOptions,
15
- SimulateOptions,
16
- SimulateUtilityOptions,
17
- Wallet,
18
- WalletCapabilities,
12
+ import {
13
+ type Aliased,
14
+ type AppCapabilities,
15
+ type BatchResults,
16
+ type BatchedMethod,
17
+ ContractInitializationStatus,
18
+ type ExecuteUtilityOptions,
19
+ type PrivateEvent,
20
+ type PrivateEventFilter,
21
+ type ProfileOptions,
22
+ type SendOptions,
23
+ type SimulateOptions,
24
+ type Wallet,
25
+ type WalletCapabilities,
19
26
  } from '@aztec/aztec.js/wallet';
20
27
  import {
21
28
  GAS_ESTIMATION_DA_GAS_LIMIT,
@@ -24,10 +31,12 @@ import {
24
31
  GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
25
32
  } from '@aztec/constants';
26
33
  import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
34
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
27
35
  import type { ChainInfo } from '@aztec/entrypoints/interfaces';
28
36
  import { Fr } from '@aztec/foundation/curves/bn254';
29
37
  import { createLogger } from '@aztec/foundation/log';
30
38
  import type { FieldsOf } from '@aztec/foundation/types';
39
+ import { displayDebugLogs } from '@aztec/pxe/client/lazy';
31
40
  import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
32
41
  import {
33
42
  type ContractArtifact,
@@ -36,7 +45,7 @@ import {
36
45
  decodeFromAbi,
37
46
  } from '@aztec/stdlib/abi';
38
47
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
39
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
48
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
40
49
  import {
41
50
  type ContractInstanceWithAddress,
42
51
  computePartialAddress,
@@ -44,14 +53,17 @@ import {
44
53
  } from '@aztec/stdlib/contract';
45
54
  import { SimulationError } from '@aztec/stdlib/errors';
46
55
  import { Gas, GasSettings } from '@aztec/stdlib/gas';
47
- import { siloNullifier } from '@aztec/stdlib/hash';
56
+ import {
57
+ computeSiloedPrivateInitializationNullifier,
58
+ computeSiloedPublicInitializationNullifier,
59
+ } from '@aztec/stdlib/hash';
48
60
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
49
61
  import {
50
62
  BlockHeader,
51
63
  type TxExecutionRequest,
52
64
  type TxProfileResult,
53
65
  TxSimulationResult,
54
- type UtilitySimulationResult,
66
+ type UtilityExecutionResult,
55
67
  } from '@aztec/stdlib/tx';
56
68
  import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
57
69
 
@@ -69,11 +81,21 @@ export type FeeOptions = {
69
81
  */
70
82
  walletFeePaymentMethod?: FeePaymentMethod;
71
83
  /** Configuration options for the account to properly handle the selected fee payment method */
72
- accountFeePaymentMethodOptions: AccountFeePaymentMethodOptions;
84
+ accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
73
85
  /** The gas settings to use for the transaction */
74
86
  gasSettings: GasSettings;
75
87
  };
76
88
 
89
+ /** Options for `simulateViaEntrypoint`. */
90
+ export type SimulateViaEntrypointOptions = Pick<
91
+ SimulateOptions,
92
+ 'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'
93
+ > & {
94
+ /** Fee options for the entrypoint */
95
+ feeOptions: FeeOptions;
96
+ /** Scopes to use for the simulation */
97
+ scopes: AztecAddress[];
98
+ };
77
99
  /**
78
100
  * A base class for Wallet implementations
79
101
  */
@@ -88,10 +110,10 @@ export abstract class BaseWallet implements Wallet {
88
110
  protected log = createLogger('wallet-sdk:base_wallet'),
89
111
  ) {}
90
112
 
91
- // When `from` is the zero address (e.g. when deploying a new account contract), we return an
92
- // empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
93
- protected scopesFor(from: AztecAddress): AztecAddress[] {
94
- return from.isZero() ? [] : [from];
113
+ protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
114
+ const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
115
+ const scopeSet = new Set(allScopes.map(address => address.toString()));
116
+ return [...scopeSet].map(AztecAddress.fromString);
95
117
  }
96
118
 
97
119
  protected abstract getAccountFromAddress(address: AztecAddress): Promise<Account>;
@@ -117,26 +139,33 @@ export abstract class BaseWallet implements Wallet {
117
139
 
118
140
  protected async createTxExecutionRequestFromPayloadAndFee(
119
141
  executionPayload: ExecutionPayload,
120
- from: AztecAddress,
142
+ from: AztecAddress | NoFrom,
121
143
  feeOptions: FeeOptions,
122
144
  ): Promise<TxExecutionRequest> {
123
145
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
124
- const executionOptions: DefaultAccountEntrypointOptions = {
125
- txNonce: Fr.random(),
126
- cancellable: this.cancellableTransactions,
127
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
128
- };
129
146
  const finalExecutionPayload = feeExecutionPayload
130
147
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
131
148
  : executionPayload;
132
- const fromAccount = await this.getAccountFromAddress(from);
133
149
  const chainInfo = await this.getChainInfo();
134
- return fromAccount.createTxExecutionRequest(
135
- finalExecutionPayload,
136
- feeOptions.gasSettings,
137
- chainInfo,
138
- executionOptions,
139
- );
150
+
151
+ if (from === NO_FROM) {
152
+ const entrypoint = new DefaultEntrypoint();
153
+ return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
154
+ } else {
155
+ const fromAccount = await this.getAccountFromAddress(from);
156
+ const executionOptions: DefaultAccountEntrypointOptions = {
157
+ txNonce: Fr.random(),
158
+ cancellable: this.cancellableTransactions,
159
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
160
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
161
+ };
162
+ return fromAccount.createTxExecutionRequest(
163
+ finalExecutionPayload,
164
+ feeOptions.gasSettings,
165
+ chainInfo,
166
+ executionOptions,
167
+ );
168
+ }
140
169
  }
141
170
 
142
171
  public async createAuthWit(
@@ -191,23 +220,27 @@ export abstract class BaseWallet implements Wallet {
191
220
  * @returns - Complete fee options that can be used to create a transaction execution request
192
221
  */
193
222
  protected async completeFeeOptions(
194
- from: AztecAddress,
223
+ from: AztecAddress | NoFrom,
195
224
  feePayer?: AztecAddress,
196
225
  gasSettings?: Partial<FieldsOf<GasSettings>>,
197
226
  ): Promise<FeeOptions> {
198
227
  const maxFeesPerGas =
199
228
  gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
200
229
  let accountFeePaymentMethodOptions;
201
- // The transaction does not include a fee payment method, so we set the flag
202
- // for the account to use its fee juice balance
203
- if (!feePayer) {
204
- accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
205
- } else {
206
- // The transaction includes fee payment method, so we check if we are the fee payer for it
207
- // (this can only happen if the embedded payment method is FeeJuiceWithClaim)
208
- accountFeePaymentMethodOptions = from.equals(feePayer)
209
- ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
210
- : AccountFeePaymentMethodOptions.EXTERNAL;
230
+ // If from is an address, we need to determine the appropriate fee payment method options for the
231
+ // account contract entrypoint to use
232
+ if (from !== NO_FROM) {
233
+ if (!feePayer) {
234
+ // The transaction does not include a fee payment method, so we set the flag
235
+ // for the account to use its fee juice balance
236
+ accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
237
+ } else {
238
+ // The transaction includes fee payment method, so we check if we are the fee payer for it
239
+ // (this can only happen if the embedded payment method is FeeJuiceWithClaim)
240
+ accountFeePaymentMethodOptions = from.equals(feePayer)
241
+ ? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
242
+ : AccountFeePaymentMethodOptions.EXTERNAL;
243
+ }
211
244
  }
212
245
  const fullGasSettings: GasSettings = GasSettings.default({ ...gasSettings, maxFeesPerGas });
213
246
  this.log.debug(`Using L2 gas settings`, fullGasSettings);
@@ -227,7 +260,7 @@ export abstract class BaseWallet implements Wallet {
227
260
  * @param gasSettings - User-provided partial gas settings
228
261
  */
229
262
  protected async completeFeeOptionsForEstimation(
230
- from: AztecAddress,
263
+ from: AztecAddress | NoFrom,
231
264
  feePayer?: AztecAddress,
232
265
  gasSettings?: Partial<FieldsOf<GasSettings>>,
233
266
  ) {
@@ -294,22 +327,20 @@ export abstract class BaseWallet implements Wallet {
294
327
  /**
295
328
  * Simulates calls through the standard PXE path (account entrypoint).
296
329
  * @param executionPayload - The execution payload to simulate.
297
- * @param from - The sender address.
298
- * @param feeOptions - Fee options for the transaction.
299
- * @param skipTxValidation - Whether to skip tx validation.
300
- * @param skipFeeEnforcement - Whether to skip fee enforcement.
301
- * @param scopes - The scopes to use for the simulation.
330
+ * @param opts - Simulation options.
302
331
  */
303
- protected async simulateViaEntrypoint(
304
- executionPayload: ExecutionPayload,
305
- from: AztecAddress,
306
- feeOptions: FeeOptions,
307
- skipTxValidation?: boolean,
308
- skipFeeEnforcement?: boolean,
309
- scopes?: AztecAddress[],
310
- ) {
311
- const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, from, feeOptions);
312
- return this.pxe.simulateTx(txRequest, { simulatePublic: true, skipTxValidation, skipFeeEnforcement, scopes });
332
+ protected async simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions) {
333
+ const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(
334
+ executionPayload,
335
+ opts.from,
336
+ opts.feeOptions,
337
+ );
338
+ return this.pxe.simulateTx(txRequest, {
339
+ simulatePublic: true,
340
+ skipTxValidation: opts.skipTxValidation,
341
+ skipFeeEnforcement: opts.skipFeeEnforcement,
342
+ scopes: opts.scopes,
343
+ });
313
344
  }
314
345
 
315
346
  /**
@@ -337,27 +368,28 @@ export abstract class BaseWallet implements Wallet {
337
368
  blockHeader = (await this.aztecNode.getBlockHeader())!;
338
369
  }
339
370
 
371
+ const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
340
372
  const [optimizedResults, normalResult] = await Promise.all([
341
373
  optimizableCalls.length > 0
342
374
  ? simulateViaNode(
343
375
  this.aztecNode,
344
376
  optimizableCalls,
345
- opts.from,
377
+ simulationOrigin,
346
378
  chainInfo,
347
379
  feeOptions.gasSettings,
348
380
  blockHeader,
349
381
  opts.skipFeeEnforcement ?? true,
382
+ this.getContractName.bind(this),
350
383
  )
351
384
  : Promise.resolve([]),
352
385
  remainingCalls.length > 0
353
- ? this.simulateViaEntrypoint(
354
- remainingPayload,
355
- opts.from,
386
+ ? this.simulateViaEntrypoint(remainingPayload, {
387
+ from: opts.from,
356
388
  feeOptions,
357
- opts.skipTxValidation,
358
- opts.skipFeeEnforcement ?? true,
359
- this.scopesFor(opts.from),
360
- )
389
+ scopes: this.scopesFrom(opts.from, opts.additionalScopes),
390
+ skipTxValidation: opts.skipTxValidation,
391
+ skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
392
+ })
361
393
  : Promise.resolve(null),
362
394
  ]);
363
395
 
@@ -370,7 +402,7 @@ export abstract class BaseWallet implements Wallet {
370
402
  return this.pxe.profileTx(txRequest, {
371
403
  profileMode: opts.profileMode,
372
404
  skipProofGeneration: opts.skipProofGeneration ?? true,
373
- scopes: this.scopesFor(opts.from),
405
+ scopes: this.scopesFrom(opts.from, opts.additionalScopes),
374
406
  });
375
407
  }
376
408
 
@@ -380,7 +412,11 @@ export abstract class BaseWallet implements Wallet {
380
412
  ): Promise<SendReturn<W>> {
381
413
  const feeOptions = await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
382
414
  const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
383
- const provenTx = await this.pxe.proveTx(txRequest, this.scopesFor(opts.from));
415
+ const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
416
+ const offchainOutput = extractOffchainOutput(
417
+ provenTx.getOffchainEffects(),
418
+ provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
419
+ );
384
420
  const tx = await provenTx.toTx();
385
421
  const txHash = tx.getTxHash();
386
422
  if (await this.aztecNode.getTxEffect(txHash)) {
@@ -394,12 +430,32 @@ export abstract class BaseWallet implements Wallet {
394
430
 
395
431
  // If wait is NO_WAIT, return txHash immediately
396
432
  if (opts.wait === NO_WAIT) {
397
- return txHash as SendReturn<W>;
433
+ return { txHash, ...offchainOutput } as SendReturn<W>;
398
434
  }
399
435
 
400
436
  // Otherwise, wait for the full receipt (default behavior on wait: undefined)
401
437
  const waitOpts = typeof opts.wait === 'object' ? opts.wait : undefined;
402
- return (await waitForTx(this.aztecNode, txHash, waitOpts)) as SendReturn<W>;
438
+ const receipt = await waitForTx(this.aztecNode, txHash, waitOpts);
439
+
440
+ // Display debug logs from public execution if present (served in test mode only)
441
+ if (receipt.debugLogs?.length) {
442
+ await displayDebugLogs(receipt.debugLogs, this.getContractName.bind(this));
443
+ }
444
+
445
+ return { receipt, ...offchainOutput } as SendReturn<W>;
446
+ }
447
+
448
+ /**
449
+ * Resolves a contract address to a human-readable name via PXE, if available.
450
+ * @param address - The contract address to resolve.
451
+ */
452
+ protected async getContractName(address: AztecAddress): Promise<string | undefined> {
453
+ const instance = await this.pxe.getContractInstance(address);
454
+ if (!instance) {
455
+ return undefined;
456
+ }
457
+ const artifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
458
+ return artifact?.name;
403
459
  }
404
460
 
405
461
  protected contextualizeError(err: Error, ...context: string[]): Error {
@@ -416,8 +472,8 @@ export abstract class BaseWallet implements Wallet {
416
472
  return err;
417
473
  }
418
474
 
419
- simulateUtility(call: FunctionCall, opts: SimulateUtilityOptions): Promise<UtilitySimulationResult> {
420
- return this.pxe.simulateUtility(call, { authwits: opts.authWitnesses, scopes: [opts.scope] });
475
+ executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
476
+ return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
421
477
  }
422
478
 
423
479
  async getPrivateEvents<T>(
@@ -440,17 +496,39 @@ export abstract class BaseWallet implements Wallet {
440
496
  return decodedEvents;
441
497
  }
442
498
 
499
+ /**
500
+ * Returns metadata about a contract, including whether it has been initialized, published, and updated.
501
+ * @param address - The contract address to query.
502
+ */
443
503
  async getContractMetadata(address: AztecAddress) {
444
504
  const instance = await this.pxe.getContractInstance(address);
445
- const initNullifier = await siloNullifier(address, address.toField());
446
- const publiclyRegisteredContract = await this.aztecNode.getContract(address);
447
- const initNullifierMembershipWitness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
505
+ const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
506
+
507
+ let initializationStatus: ContractInitializationStatus;
508
+ if (instance) {
509
+ // We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
510
+ // emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
511
+ const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
512
+ const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
513
+ initializationStatus = witness
514
+ ? ContractInitializationStatus.INITIALIZED
515
+ : ContractInitializationStatus.UNINITIALIZED;
516
+ } else {
517
+ // Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
518
+ // public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
519
+ // public functions that require initialization checks), so its absence doesn't mean the contract is
520
+ // uninitialized.
521
+ const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
522
+ const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
523
+ initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
524
+ }
525
+ const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
448
526
  const isContractUpdated =
449
527
  publiclyRegisteredContract &&
450
528
  !publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
451
529
  return {
452
530
  instance: instance ?? undefined,
453
- isContractInitialized: !!initNullifierMembershipWitness,
531
+ initializationStatus,
454
532
  isContractPublished: !!publiclyRegisteredContract,
455
533
  isContractUpdated: !!isContractUpdated,
456
534
  updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
@@ -1,2 +1,2 @@
1
- export { BaseWallet, type FeeOptions } from './base_wallet.js';
1
+ export { BaseWallet, type FeeOptions, type SimulateViaEntrypointOptions } from './base_wallet.js';
2
2
  export { simulateViaNode, buildMergedSimulationResult, extractOptimizablePublicStaticCalls } from './utils.js';
@@ -4,6 +4,8 @@ import type { ChainInfo } from '@aztec/entrypoints/interfaces';
4
4
  import { makeTuple } from '@aztec/foundation/array';
5
5
  import { Fr } from '@aztec/foundation/curves/bn254';
6
6
  import type { Tuple } from '@aztec/foundation/serialize';
7
+ import type { ContractNameResolver } from '@aztec/pxe/client/lazy';
8
+ import { displayDebugLogs } from '@aztec/pxe/client/lazy';
7
9
  import { generateSimulatedProvingResult } from '@aztec/pxe/simulator';
8
10
  import { type FunctionCall, FunctionSelector } from '@aztec/stdlib/abi';
9
11
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -72,6 +74,7 @@ async function simulateBatchViaNode(
72
74
  gasSettings: GasSettings,
73
75
  blockHeader: BlockHeader,
74
76
  skipFeeEnforcement: boolean,
77
+ getContractName: ContractNameResolver,
75
78
  ): Promise<TxSimulationResult> {
76
79
  const txContext = new TxContext(chainInfo.chainId, chainInfo.version, gasSettings);
77
80
 
@@ -145,6 +148,9 @@ async function simulateBatchViaNode(
145
148
  throw publicOutput.revertReason;
146
149
  }
147
150
 
151
+ // Display debug logs from the public simulation.
152
+ await displayDebugLogs(publicOutput.debugLogs, getContractName);
153
+
148
154
  return new TxSimulationResult(privateResult, provingResult.publicInputs, publicOutput, undefined);
149
155
  }
150
156
 
@@ -169,6 +175,7 @@ export async function simulateViaNode(
169
175
  gasSettings: GasSettings,
170
176
  blockHeader: BlockHeader,
171
177
  skipFeeEnforcement: boolean = true,
178
+ getContractName: ContractNameResolver,
172
179
  ): Promise<TxSimulationResult[]> {
173
180
  const batches: FunctionCall[][] = [];
174
181
 
@@ -187,6 +194,7 @@ export async function simulateViaNode(
187
194
  gasSettings,
188
195
  blockHeader,
189
196
  skipFeeEnforcement,
197
+ getContractName,
190
198
  );
191
199
  results.push(result);
192
200
  }
package/src/crypto.ts CHANGED
@@ -497,3 +497,107 @@ export function hashToEmoji(hash: string, count: number = DEFAULT_EMOJI_GRID_SIZ
497
497
  }
498
498
  return emojis.join('');
499
499
  }
500
+
501
+ // ─── Passphrase-based encryption (PBKDF2 + AES-256-GCM) ───────────────────
502
+
503
+ /** Default PBKDF2 iteration count. High to compensate for short PINs (~1-2s on modern hardware). */
504
+ const DEFAULT_PBKDF2_ITERATIONS = 2_000_000;
505
+ const PBKDF2_SALT_BYTES = 16;
506
+ const PBKDF2_IV_BYTES = 12;
507
+
508
+ /**
509
+ * Derives an AES-256-GCM key from a passphrase using PBKDF2-SHA256.
510
+ *
511
+ * @param passphrase - The user-provided passphrase or PIN
512
+ * @param salt - Random salt bytes
513
+ * @param iterations - PBKDF2 iteration count (default: 2,000,000)
514
+ * @returns An AES-256-GCM CryptoKey
515
+ */
516
+ export async function deriveKeyFromPassphrase(
517
+ passphrase: string,
518
+ salt: Uint8Array,
519
+ iterations: number = DEFAULT_PBKDF2_ITERATIONS,
520
+ ): Promise<CryptoKey> {
521
+ const keyMaterial = await crypto.subtle.importKey('raw', new TextEncoder().encode(passphrase), 'PBKDF2', false, [
522
+ 'deriveKey',
523
+ ]);
524
+ return crypto.subtle.deriveKey(
525
+ { name: 'PBKDF2', salt: salt as BufferSource, iterations, hash: 'SHA-256' },
526
+ keyMaterial,
527
+ { name: 'AES-GCM', length: 256 },
528
+ false,
529
+ ['encrypt', 'decrypt'],
530
+ );
531
+ }
532
+
533
+ /**
534
+ * Encrypts arbitrary bytes with a passphrase using PBKDF2 + AES-256-GCM.
535
+ *
536
+ * Output layout: `[salt (16)] [iv (12)] [ciphertext (...)]`
537
+ *
538
+ * @param plaintext - Data to encrypt
539
+ * @param passphrase - User passphrase or PIN
540
+ * @param iterations - PBKDF2 iteration count (default: 2,000,000)
541
+ * @returns A Uint8Array containing salt + iv + ciphertext
542
+ */
543
+ export async function encryptWithPassphrase(
544
+ plaintext: Uint8Array,
545
+ passphrase: string,
546
+ iterations: number = DEFAULT_PBKDF2_ITERATIONS,
547
+ ): Promise<Uint8Array> {
548
+ const salt = crypto.getRandomValues(new Uint8Array(PBKDF2_SALT_BYTES));
549
+ const iv = crypto.getRandomValues(new Uint8Array(PBKDF2_IV_BYTES));
550
+ const key = await deriveKeyFromPassphrase(passphrase, salt, iterations);
551
+ const ciphertext = new Uint8Array(
552
+ await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, plaintext as BufferSource),
553
+ );
554
+ const result = new Uint8Array(PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES + ciphertext.length);
555
+ result.set(salt, 0);
556
+ result.set(iv, PBKDF2_SALT_BYTES);
557
+ result.set(ciphertext, PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
558
+ return result;
559
+ }
560
+
561
+ /**
562
+ * Decrypts data produced by {@link encryptWithPassphrase}.
563
+ *
564
+ * @param data - The encrypted blob (salt + iv + ciphertext)
565
+ * @param passphrase - The passphrase used during encryption
566
+ * @param iterations - PBKDF2 iteration count (must match encryption)
567
+ * @returns The decrypted plaintext bytes
568
+ * @throws On wrong passphrase (AES-GCM auth tag mismatch)
569
+ */
570
+ export async function decryptWithPassphrase(
571
+ data: Uint8Array,
572
+ passphrase: string,
573
+ iterations: number = DEFAULT_PBKDF2_ITERATIONS,
574
+ ): Promise<Uint8Array> {
575
+ const salt = data.slice(0, PBKDF2_SALT_BYTES);
576
+ const iv = data.slice(PBKDF2_SALT_BYTES, PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
577
+ const ciphertext = data.slice(PBKDF2_SALT_BYTES + PBKDF2_IV_BYTES);
578
+ const key = await deriveKeyFromPassphrase(passphrase, salt, iterations);
579
+ return new Uint8Array(await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext as BufferSource));
580
+ }
581
+
582
+ /**
583
+ * Converts a Uint8Array to a base64 string.
584
+ */
585
+ export function uint8ToBase64(bytes: Uint8Array): string {
586
+ let binary = '';
587
+ for (const b of bytes) {
588
+ binary += String.fromCharCode(b);
589
+ }
590
+ return btoa(binary);
591
+ }
592
+
593
+ /**
594
+ * Converts a base64 string to a Uint8Array.
595
+ */
596
+ export function base64ToUint8(b64: string): Uint8Array {
597
+ const binary = atob(b64);
598
+ const bytes = new Uint8Array(binary.length);
599
+ for (let i = 0; i < binary.length; i++) {
600
+ bytes[i] = binary.charCodeAt(i);
601
+ }
602
+ return bytes;
603
+ }
@@ -6,7 +6,7 @@ import { schemaHasMethod } from '@aztec/foundation/schemas';
6
6
  import type { FunctionsOf } from '@aztec/foundation/types';
7
7
 
8
8
  import { type EncryptedPayload, decrypt, encrypt } from '../../crypto.js';
9
- import { type WalletMessage, WalletMessageType, type WalletResponse } from '../../types.js';
9
+ import { type DisconnectCallback, type WalletMessage, WalletMessageType, type WalletResponse } from '../../types.js';
10
10
 
11
11
  /**
12
12
  * Internal type representing a wallet method call before encryption.
@@ -19,11 +19,6 @@ type WalletMethodCall = {
19
19
  args: unknown[];
20
20
  };
21
21
 
22
- /**
23
- * Callback type for wallet disconnect events.
24
- */
25
- export type DisconnectCallback = () => void;
26
-
27
22
  /**
28
23
  * A wallet implementation that communicates with browser extension wallets
29
24
  * using an encrypted MessageChannel.
@@ -109,7 +104,7 @@ export class ExtensionWallet {
109
104
  sharedKey: CryptoKey,
110
105
  chainInfo: ChainInfo,
111
106
  appId: string,
112
- ): Wallet {
107
+ ): ExtensionWallet {
113
108
  const wallet = new ExtensionWallet(chainInfo, appId, extensionId, port, sharedKey);
114
109
 
115
110
  // Set up message handler for encrypted responses and unencrypted control messages
@@ -127,8 +122,10 @@ export class ExtensionWallet {
127
122
  wallet.port.start();
128
123
 
129
124
  return new Proxy(wallet, {
130
- get: (target, prop) => {
131
- if (schemaHasMethod(WalletSchema, prop.toString())) {
125
+ get: (target, prop, receiver) => {
126
+ if (prop === 'asWallet') {
127
+ return () => receiver as unknown as Wallet;
128
+ } else if (schemaHasMethod(WalletSchema, prop.toString())) {
132
129
  return async (...args: unknown[]) => {
133
130
  const result = await target.postMessage({
134
131
  type: prop.toString() as keyof FunctionsOf<Wallet>,
@@ -140,7 +137,13 @@ export class ExtensionWallet {
140
137
  return target[prop as keyof ExtensionWallet];
141
138
  }
142
139
  },
143
- }) as unknown as Wallet;
140
+ });
141
+ }
142
+
143
+ asWallet(): Wallet {
144
+ // Overridden by the proxy in create() to return the proxy itself.
145
+ // This body is never reached when accessed through create().
146
+ return this as unknown as Wallet;
144
147
  }
145
148
 
146
149
  /**
@@ -1,4 +1,4 @@
1
- export { ExtensionWallet, type DisconnectCallback } from './extension_wallet.js';
1
+ export { ExtensionWallet } from './extension_wallet.js';
2
2
  export {
3
3
  ExtensionProvider,
4
4
  type DiscoveredWallet,