@aztec/wallets 5.0.0-private.20260318 → 5.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dest/embedded/account-contract-providers/bundle.d.ts +6 -8
  2. package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
  3. package/dest/embedded/account-contract-providers/bundle.js +10 -10
  4. package/dest/embedded/account-contract-providers/lazy.d.ts +6 -8
  5. package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
  6. package/dest/embedded/account-contract-providers/lazy.js +20 -10
  7. package/dest/embedded/account-contract-providers/types.d.ts +6 -8
  8. package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
  9. package/dest/embedded/embedded_wallet.d.ts +65 -10
  10. package/dest/embedded/embedded_wallet.d.ts.map +1 -1
  11. package/dest/embedded/embedded_wallet.js +252 -59
  12. package/dest/embedded/entrypoints/browser.d.ts +2 -2
  13. package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
  14. package/dest/embedded/entrypoints/browser.js +39 -10
  15. package/dest/embedded/entrypoints/node.d.ts +2 -2
  16. package/dest/embedded/entrypoints/node.d.ts.map +1 -1
  17. package/dest/embedded/entrypoints/node.js +33 -10
  18. package/dest/embedded/store_encryption.d.ts +67 -0
  19. package/dest/embedded/store_encryption.d.ts.map +1 -0
  20. package/dest/embedded/store_encryption.js +71 -0
  21. package/dest/embedded/wallet_db.d.ts +7 -6
  22. package/dest/embedded/wallet_db.d.ts.map +1 -1
  23. package/dest/embedded/wallet_db.js +10 -9
  24. package/dest/testing.d.ts +8 -4
  25. package/dest/testing.d.ts.map +1 -1
  26. package/dest/testing.js +8 -14
  27. package/package.json +12 -10
  28. package/src/embedded/account-contract-providers/bundle.ts +13 -12
  29. package/src/embedded/account-contract-providers/lazy.ts +23 -12
  30. package/src/embedded/account-contract-providers/types.ts +6 -4
  31. package/src/embedded/embedded_wallet.ts +331 -67
  32. package/src/embedded/entrypoints/browser.ts +47 -20
  33. package/src/embedded/entrypoints/node.ts +46 -26
  34. package/src/embedded/store_encryption.ts +107 -0
  35. package/src/embedded/wallet_db.ts +13 -10
  36. package/src/testing.ts +11 -16
@@ -1,38 +1,108 @@
1
- import { type Account, SignerlessAccount } from '@aztec/aztec.js/account';
2
- import type { Aliased } from '@aztec/aztec.js/wallet';
3
- import { AccountManager } from '@aztec/aztec.js/wallet';
1
+ import { type Account, NO_FROM } from '@aztec/aztec.js/account';
2
+ import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
3
+ import {
4
+ ContractFunctionInteraction,
5
+ type InteractionWaitOptions,
6
+ NO_WAIT,
7
+ type SendReturn,
8
+ type WaitOpts,
9
+ } from '@aztec/aztec.js/contracts';
10
+ import type {
11
+ Aliased,
12
+ ExecuteUtilityOptions,
13
+ PrivateEvent,
14
+ PrivateEventFilter,
15
+ ProfileOptions,
16
+ SendOptions,
17
+ SimulateOptions,
18
+ } from '@aztec/aztec.js/wallet';
19
+ import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
4
20
  import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
21
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
22
+ import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
23
+ import { Schnorr } from '@aztec/foundation/crypto/schnorr';
5
24
  import { Fq, Fr } from '@aztec/foundation/curves/bn254';
6
25
  import type { Logger } from '@aztec/foundation/log';
7
- import type { AccessScopes, PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
26
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
27
+ import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
8
28
  import type { PXE } from '@aztec/pxe/server';
29
+ import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
9
30
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
10
- import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
31
+ import { type ContractInstanceWithAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
32
+ import { GasSettings } from '@aztec/stdlib/gas';
11
33
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
12
34
  import { deriveSigningKey } from '@aztec/stdlib/keys';
13
35
  import {
36
+ type ContractOverrides,
14
37
  ExecutionPayload,
15
38
  SimulationOverrides,
16
- type TxSimulationResult,
39
+ type TxExecutionRequest,
40
+ type TxProfileResult,
41
+ TxStatus,
42
+ type UtilityExecutionResult,
43
+ collectOffchainEffects,
17
44
  mergeExecutionPayloads,
18
45
  } from '@aztec/stdlib/tx';
19
- import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
46
+ import { BaseWallet, type SimulateViaEntrypointOptions, getGasLimits } from '@aztec/wallet-sdk/base-wallet';
20
47
 
21
48
  import type { AccountContractsProvider } from './account-contract-providers/types.js';
22
49
  import { type AccountType, WalletDB } from './wallet_db.js';
23
50
 
51
+ /** Options for the PXE instance created by the EmbeddedWallet. */
52
+ export type EmbeddedWalletPXEOptions = Partial<PXEConfig> & PXECreationOptions;
53
+
54
+ /** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */
55
+ export function splitPxeOptions(pxe?: EmbeddedWalletPXEOptions): {
56
+ config: Partial<PXEConfig>;
57
+ creation: PXECreationOptions;
58
+ } {
59
+ if (!pxe) {
60
+ return { config: {}, creation: {} };
61
+ }
62
+ const { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider, ...config } =
63
+ pxe;
64
+ return {
65
+ config,
66
+ creation: { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider },
67
+ };
68
+ }
69
+
70
+ /** Options for the EmbeddedWallet's own DB (accounts, senders — distinct from PXE state). */
71
+ export type EmbeddedWalletDBOptions = {
72
+ /** Override the wallet DB backend. If omitted, an IndexedDB (browser) / LMDB (node) store is created. */
73
+ store?: AztecAsyncKVStore;
74
+ };
75
+
24
76
  export type EmbeddedWalletOptions = {
25
77
  /** Parent logger. Child loggers are derived via createChild() for each subsystem. */
26
78
  logger?: Logger;
27
79
  /** Use ephemeral (in-memory) stores. Data will not persist across sessions. */
28
80
  ephemeral?: boolean;
29
- /** Override PXE configuration. */
81
+ /** PXE configuration and dependency overrides (custom store, prover, simulator). */
82
+ pxe?: EmbeddedWalletPXEOptions;
83
+ /** Wallet DB dependency overrides (custom store). */
84
+ walletDb?: EmbeddedWalletDBOptions;
85
+ /**
86
+ * Override PXE configuration.
87
+ * @deprecated Use `pxe` instead.
88
+ */
30
89
  pxeConfig?: Partial<PXEConfig>;
31
- /** Advanced PXE creation options (custom store, prover, simulator). */
90
+ /**
91
+ * Advanced PXE creation options (custom store, prover, simulator).
92
+ * @deprecated Use `pxe` instead.
93
+ */
32
94
  pxeOptions?: PXECreationOptions;
33
95
  };
34
96
 
97
+ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
98
+
35
99
  export class EmbeddedWallet extends BaseWallet {
100
+ protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
101
+
102
+ // Stub class ids, populated on wallet startup
103
+ // to avoid redundant work per simulation
104
+ protected stubClassIds = new Map<AccountType, Fr>();
105
+
36
106
  constructor(
37
107
  pxe: PXE,
38
108
  aztecNode: AztecNode,
@@ -44,10 +114,6 @@ export class EmbeddedWallet extends BaseWallet {
44
114
  }
45
115
 
46
116
  protected async getAccountFromAddress(address: AztecAddress): Promise<Account> {
47
- if (address.equals(AztecAddress.ZERO)) {
48
- return new SignerlessAccount();
49
- }
50
-
51
117
  const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
52
118
  const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
53
119
  const account = await accountManager.getAccount();
@@ -79,6 +145,190 @@ export class EmbeddedWallet extends BaseWallet {
79
145
  return storedSenders;
80
146
  }
81
147
 
148
+ /**
149
+ * Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
150
+ * estimates actual gas usage and captures call authorization requests to generate
151
+ * the necessary authwitnesses.
152
+ */
153
+ public override async sendTx<W extends InteractionWaitOptions = undefined>(
154
+ executionPayload: ExecutionPayload,
155
+ opts: SendOptions<W>,
156
+ ): Promise<SendReturn<W>> {
157
+ // PXE has autoSync disabled by the embedded wallet entrypoints, so we sync once here to cover
158
+ // both the inner simulateTx (via simulateViaEntrypoint) and the proveTx that super.sendTx
159
+ await this.pxe.sync();
160
+ const feeOptions = await this.completeFeeOptions({
161
+ from: opts.from,
162
+ feePayer: executionPayload.feePayer,
163
+ gasSettings: opts.fee?.gasSettings,
164
+ forEstimation: true,
165
+ });
166
+
167
+ // Simulate the transaction first to estimate gas and capture required
168
+ // private authwitnesses based on offchain effects.
169
+ const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
170
+ from: opts.from,
171
+ feeOptions,
172
+ additionalScopes: opts.additionalScopes,
173
+ skipTxValidation: true,
174
+ sendMessagesAs: opts.sendMessagesAs,
175
+ });
176
+
177
+ const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
178
+ const authWitnesses = await Promise.all(
179
+ offchainEffects.map(async effect => {
180
+ try {
181
+ const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
182
+ return this.createAuthWit(authRequest.onBehalfOf, {
183
+ consumer: effect.contractAddress,
184
+ innerHash: authRequest.innerHash,
185
+ });
186
+ } catch {
187
+ return undefined;
188
+ }
189
+ }),
190
+ );
191
+ for (const authwit of authWitnesses) {
192
+ if (authwit) {
193
+ executionPayload.authWitnesses.push(authwit);
194
+ }
195
+ }
196
+ const maxTxGasLimits = await this.getMaxTxGasLimits();
197
+ const estimated = getGasLimits(simulationResult.gasUsed, maxTxGasLimits, this.estimatedGasPadding);
198
+ this.log.verbose(
199
+ `Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
200
+ );
201
+ const gasSettings = GasSettings.from({
202
+ ...opts.fee?.gasSettings,
203
+ maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
204
+ maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
205
+ gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
206
+ teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
207
+ });
208
+ let wait: InteractionWaitOptions = opts.wait;
209
+ if (wait !== NO_WAIT) {
210
+ const callerWaitOpts: WaitOpts = typeof wait === 'object' ? wait : {};
211
+ wait = {
212
+ ...callerWaitOpts,
213
+ // Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
214
+ // rather than waiting until the end of the slot for the checkpoint to be published to L1.
215
+ // This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
216
+ // we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
217
+ // The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
218
+ // a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
219
+ // proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
220
+ waitForStatus: callerWaitOpts.waitForStatus ?? TxStatus.PROPOSED,
221
+ };
222
+ }
223
+ return super.sendTx(executionPayload, {
224
+ ...opts,
225
+ wait: wait as W,
226
+ fee: { ...opts.fee, gasSettings },
227
+ });
228
+ }
229
+
230
+ /**
231
+ * Overrides the base simulateTx to drive PXE syncing explicitly. The PXE created by the embedded
232
+ * wallet has autoSync disabled (so we can share one sync across simulate+send in sendTx); for
233
+ * standalone simulations we still need a fresh anchor block, which we provide here.
234
+ */
235
+ public override async simulateTx(
236
+ executionPayload: ExecutionPayload,
237
+ opts: SimulateOptions,
238
+ ): Promise<TxSimulationResultWithAppOffset> {
239
+ await this.pxe.sync();
240
+ return super.simulateTx(executionPayload, opts);
241
+ }
242
+
243
+ public override async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
244
+ await this.pxe.sync();
245
+ return super.profileTx(executionPayload, opts);
246
+ }
247
+
248
+ public override async executeUtility(
249
+ call: FunctionCall,
250
+ opts: ExecuteUtilityOptions,
251
+ ): Promise<UtilityExecutionResult> {
252
+ await this.pxe.sync();
253
+ return super.executeUtility(call, opts);
254
+ }
255
+
256
+ public override async getPrivateEvents<T>(
257
+ eventDef: EventMetadataDefinition,
258
+ eventFilter: PrivateEventFilter,
259
+ ): Promise<PrivateEvent<T>[]> {
260
+ await this.pxe.sync();
261
+ return super.getPrivateEvents<T>(eventDef, eventFilter);
262
+ }
263
+
264
+ public override async registerContract(
265
+ instance: ContractInstanceWithAddress,
266
+ artifact?: ContractArtifact,
267
+ secretKey?: Fr,
268
+ ): Promise<ContractInstanceWithAddress> {
269
+ // registerContract may call pxe.updateContract under the hood, which depends on a fresh anchor
270
+ // block to verify the current class id from the node.
271
+ await this.pxe.sync();
272
+ return super.registerContract(instance, artifact, secretKey);
273
+ }
274
+
275
+ /**
276
+ * Hashes and registers the stub class for every supported account type with PXE, populating
277
+ * stubClassIds. Called on wallet initialization.
278
+ */
279
+ async initStubClasses(): Promise<void> {
280
+ const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
281
+ const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
282
+ await this.pxe.registerContractClass(schnorrArtifact);
283
+
284
+ // ecdsa stubs share the same class id
285
+ const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
286
+ const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
287
+ await this.pxe.registerContractClass(ecdsaArtifact);
288
+
289
+ this.stubClassIds.set('schnorr', schnorrClassId);
290
+ this.stubClassIds.set('schnorr_initializerless', schnorrClassId);
291
+ this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
292
+ this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
293
+ }
294
+
295
+ /**
296
+ * Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
297
+ * Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
298
+ */
299
+ protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
300
+ const accounts = await this.getAccounts();
301
+ const contracts: ContractOverrides = {};
302
+
303
+ const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
304
+
305
+ for (const account of filtered) {
306
+ const address = account.item;
307
+ const { type } = await this.walletDB.retrieveAccount(address);
308
+ const stubClassId = this.stubClassIds.get(type);
309
+ if (!stubClassId) {
310
+ throw new Error(
311
+ `Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
312
+ );
313
+ }
314
+
315
+ const originalAccount = await this.getAccountFromAddress(address);
316
+ const completeAddress = originalAccount.getCompleteAddress();
317
+ const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
318
+ if (!contractInstance) {
319
+ throw new Error(
320
+ `No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
321
+ );
322
+ }
323
+
324
+ contracts[address.toString()] = {
325
+ instance: { ...contractInstance, currentContractClassId: stubClassId },
326
+ };
327
+ }
328
+
329
+ return contracts;
330
+ }
331
+
82
332
  /**
83
333
  * Simulates calls via a stub account entrypoint, bypassing real account authorization.
84
334
  * This allows kernelless simulation with contract overrides, skipping expensive
@@ -86,69 +336,53 @@ export class EmbeddedWallet extends BaseWallet {
86
336
  */
87
337
  protected override async simulateViaEntrypoint(
88
338
  executionPayload: ExecutionPayload,
89
- from: AztecAddress,
90
- feeOptions: FeeOptions,
91
- scopes: AccessScopes,
92
- skipTxValidation?: boolean,
93
- skipFeeEnforcement?: boolean,
94
- ): Promise<TxSimulationResult> {
95
- let overrides: SimulationOverrides | undefined;
96
- let fromAccount: Account;
97
- if (!from.equals(AztecAddress.ZERO)) {
98
- const { account, instance, artifact } = await this.getFakeAccountDataFor(from);
99
- fromAccount = account;
100
- overrides = {
101
- contracts: { [from.toString()]: { instance, artifact } },
102
- };
103
- } else {
104
- fromAccount = await this.getAccountFromAddress(from);
105
- }
339
+ opts: SimulateViaEntrypointOptions,
340
+ ): Promise<TxSimulationResultWithAppOffset> {
341
+ const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
342
+ const scopes = this.scopesFrom(from, additionalScopes);
106
343
 
107
344
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
108
- const executionOptions: DefaultAccountEntrypointOptions = {
109
- txNonce: Fr.random(),
110
- cancellable: this.cancellableTransactions,
111
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
112
- };
113
345
  const finalExecutionPayload = feeExecutionPayload
114
346
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
115
347
  : executionPayload;
116
348
  const chainInfo = await this.getChainInfo();
117
- const txRequest = await fromAccount.createTxExecutionRequest(
118
- finalExecutionPayload,
119
- feeOptions.gasSettings,
120
- chainInfo,
121
- executionOptions,
122
- );
123
- return this.pxe.simulateTx(txRequest, {
349
+
350
+ const accountOverrides = await this.buildAccountOverrides(scopes);
351
+ const overrides = new SimulationOverrides({ contracts: accountOverrides });
352
+
353
+ let txRequest: TxExecutionRequest;
354
+ if (from === NO_FROM) {
355
+ const entrypoint = new DefaultEntrypoint();
356
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
357
+ } else {
358
+ const { type } = await this.walletDB.retrieveAccount(from);
359
+ const originalAccount = await this.getAccountFromAddress(from);
360
+ const completeAddress = originalAccount.getCompleteAddress();
361
+ const account = await this.accountContracts.createStubAccount(completeAddress, type);
362
+ const executionOptions: DefaultAccountEntrypointOptions = {
363
+ txNonce: Fr.random(),
364
+ cancellable: this.cancellableTransactions,
365
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
366
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
367
+ };
368
+ txRequest = await account.createTxExecutionRequest(
369
+ finalExecutionPayload,
370
+ feeOptions.gasSettings,
371
+ chainInfo,
372
+ executionOptions,
373
+ );
374
+ }
375
+
376
+ const result = await this.pxe.simulateTx(txRequest, {
124
377
  simulatePublic: true,
125
378
  skipFeeEnforcement,
126
379
  skipTxValidation,
127
380
  overrides,
128
381
  scopes,
382
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
129
383
  });
130
- }
131
-
132
- private async getFakeAccountDataFor(address: AztecAddress) {
133
- const originalAccount = await this.getAccountFromAddress(address);
134
- if (originalAccount instanceof SignerlessAccount) {
135
- throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
136
- }
137
- const originalAddress = (originalAccount as Account).getCompleteAddress();
138
- const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
139
- if (!contractInstance) {
140
- throw new Error(`No contract instance found for address: ${originalAddress.address}`);
141
- }
142
- const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
143
- const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
144
- const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
145
- salt: Fr.random(),
146
- });
147
- return {
148
- account: stubAccount,
149
- instance,
150
- artifact: stubArtifact,
151
- };
384
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
385
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
152
386
  }
153
387
 
154
388
  protected async createAccountInternal(
@@ -158,11 +392,19 @@ export class EmbeddedWallet extends BaseWallet {
158
392
  signingKey: Buffer,
159
393
  ): Promise<AccountManager> {
160
394
  let contract;
395
+ let immutablesHash;
396
+ let publicKey;
161
397
  switch (type) {
162
398
  case 'schnorr': {
163
399
  contract = await this.accountContracts.getSchnorrAccountContract(Fq.fromBuffer(signingKey));
164
400
  break;
165
401
  }
402
+ case 'schnorr_initializerless': {
403
+ contract = await this.accountContracts.getSchnorrInitializerlessAccountContract(Fq.fromBuffer(signingKey));
404
+ publicKey = await new Schnorr().computePublicKey(Fq.fromBuffer(signingKey));
405
+ immutablesHash = await poseidon2Hash([publicKey.x, publicKey.y]);
406
+ break;
407
+ }
166
408
  case 'ecdsasecp256k1': {
167
409
  contract = await this.accountContracts.getEcdsaKAccountContract(signingKey);
168
410
  break;
@@ -176,17 +418,29 @@ export class EmbeddedWallet extends BaseWallet {
176
418
  }
177
419
  }
178
420
 
179
- const accountManager = await AccountManager.create(this, secret, contract, salt);
421
+ const accountManager = await AccountManager.create(this, secret, contract, { salt, immutablesHash });
180
422
 
181
423
  const instance = accountManager.getInstance();
182
424
  const existingInstance = await this.pxe.getContractInstance(instance.address);
183
425
  if (!existingInstance) {
184
426
  const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
427
+ const artifact = existingArtifact ?? (await accountManager.getAccountContract().getContractArtifact());
185
428
  await this.registerContract(
186
429
  instance,
187
430
  !existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined,
188
431
  accountManager.getSecretKey(),
189
432
  );
433
+ if (type === 'schnorr_initializerless') {
434
+ const constructor = artifact.functions.find(f => f.name === 'constructor');
435
+ if (!constructor) {
436
+ throw new Error('Could not create SchnorrInitializerlessAccountContract: constructor ABI not found');
437
+ }
438
+ const storeCall = new ContractFunctionInteraction(this, instance.address, constructor, [
439
+ publicKey!.x,
440
+ publicKey!.y,
441
+ ]);
442
+ await storeCall.simulate({ from: instance.address });
443
+ }
190
444
  }
191
445
  return accountManager;
192
446
  }
@@ -208,6 +462,11 @@ export class EmbeddedWallet extends BaseWallet {
208
462
  return this.createAndStoreAccount(alias ?? '', 'schnorr', secret, salt, sk.toBuffer());
209
463
  }
210
464
 
465
+ createSchnorrInitializerlessAccount(secret: Fr, salt: Fr, signingKey?: Fq, alias?: string): Promise<AccountManager> {
466
+ const sk = signingKey ?? deriveSigningKey(secret);
467
+ return this.createAndStoreAccount(alias ?? '', 'schnorr_initializerless', secret, salt, sk.toBuffer());
468
+ }
469
+
211
470
  createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer, alias?: string): Promise<AccountManager> {
212
471
  return this.createAndStoreAccount(alias ?? '', 'ecdsasecp256r1', secret, salt, signingKey);
213
472
  }
@@ -220,7 +479,12 @@ export class EmbeddedWallet extends BaseWallet {
220
479
  this.minFeePadding = value ?? 0.5;
221
480
  }
222
481
 
223
- stop() {
224
- return this.pxe.stop();
482
+ setEstimatedGasPadding(value?: number) {
483
+ this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
484
+ }
485
+
486
+ async stop(): Promise<void> {
487
+ await this.pxe.stop();
488
+ await this.walletDB.close();
225
489
  }
226
490
  }
@@ -3,10 +3,13 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { createStore, openTmpStore } from '@aztec/kv-store/indexeddb';
4
4
  import { type PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/client/lazy';
5
5
  import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
6
+ import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry/lazy';
7
+ import { getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry/lazy';
8
+ import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint/lazy';
6
9
 
7
10
  import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
8
11
  import type { AccountContractsProvider } from '../account-contract-providers/types.js';
9
- import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
12
+ import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
10
13
  import { WalletDB } from '../wallet_db.js';
11
14
 
12
15
  export class BrowserEmbeddedWallet extends EmbeddedWallet {
@@ -26,10 +29,16 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
26
29
  const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
27
30
  const l1Contracts = await aztecNode.getL1ContractAddresses();
28
31
 
32
+ // Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
33
+ const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
34
+ const mergedConfigOverrides = { ...options.pxeConfig, ...pxeConfigFromPxe };
35
+ const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
36
+
29
37
  const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
30
- proverEnabled: options.pxeConfig?.proverEnabled ?? false,
38
+ proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
31
39
  dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
32
- ...options.pxeConfig,
40
+ autoSync: false,
41
+ ...mergedConfigOverrides,
33
42
  });
34
43
 
35
44
  if (options.ephemeral) {
@@ -37,36 +46,54 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
37
46
  }
38
47
 
39
48
  const pxeOptions: PXECreationOptions = {
40
- ...options.pxeOptions,
49
+ ...mergedCreationOverrides,
50
+ preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
51
+ getPreloadedContracts: async () => [
52
+ await getStandardMultiCallEntrypoint(),
53
+ await getStandardAuthRegistry(),
54
+ await getStandardHandshakeRegistry(),
55
+ ],
56
+ },
41
57
  loggers: {
42
58
  store: rootLogger.createChild('pxe:data'),
43
59
  pxe: rootLogger.createChild('pxe:service'),
44
60
  prover: rootLogger.createChild('pxe:prover'),
45
- ...options.pxeOptions?.loggers,
61
+ ...mergedCreationOverrides.loggers,
46
62
  },
47
63
  };
48
64
 
49
65
  const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
50
66
 
51
- const walletDBStore = options.ephemeral
52
- ? await openTmpStore(true)
53
- : await createStore(
54
- 'wallet_data',
55
- {
56
- dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
57
- dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
58
- l1Contracts,
59
- },
60
- 1,
61
- rootLogger.createChild('wallet:data'),
62
- );
63
- const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
67
+ const walletDBStore =
68
+ options.walletDb?.store ??
69
+ (options.ephemeral
70
+ ? await openTmpStore(true)
71
+ : await createStore(
72
+ 'wallet_data',
73
+ {
74
+ dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
75
+ dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
76
+ rollupAddress: l1Contracts.rollupAddress,
77
+ },
78
+ 1,
79
+ rootLogger.createChild('wallet:data'),
80
+ ));
81
+ const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
64
82
 
65
- return new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
83
+ const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
84
+ await wallet.initStubClasses();
85
+ return wallet;
66
86
  }
67
87
  }
68
88
 
69
89
  export { BrowserEmbeddedWallet as EmbeddedWallet };
70
- export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
90
+ export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
71
91
  export { WalletDB } from '../wallet_db.js';
72
92
  export type { AccountType } from '../wallet_db.js';
93
+
94
+ // At-rest encryption helpers are intentionally NOT re-exported here. They live
95
+ // on the `@aztec/wallets/embedded/store-encryption` sub-path so consumers
96
+ // (and bundlers) of this entrypoint don't transitively pull in
97
+ // `@aztec/kv-store/sqlite-opfs` and its `new Worker(new URL('./worker.js'))`
98
+ // chain into `@aztec/sqlite3mc-wasm`. Apps that don't use encryption-at-rest
99
+ // (e.g. the playground) should never see sqlite-opfs in their bundle.