@aztec/wallets 0.0.1-commit.21ecf947b → 0.0.1-commit.2448fdb

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 (32) hide show
  1. package/dest/embedded/account-contract-providers/bundle.d.ts +9 -4
  2. package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
  3. package/dest/embedded/account-contract-providers/bundle.js +10 -5
  4. package/dest/embedded/account-contract-providers/lazy.d.ts +9 -4
  5. package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
  6. package/dest/embedded/account-contract-providers/lazy.js +20 -6
  7. package/dest/embedded/account-contract-providers/types.d.ts +9 -4
  8. package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
  9. package/dest/embedded/embedded_wallet.d.ts +40 -8
  10. package/dest/embedded/embedded_wallet.d.ts.map +1 -1
  11. package/dest/embedded/embedded_wallet.js +164 -50
  12. package/dest/embedded/entrypoints/browser.d.ts +8 -3
  13. package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
  14. package/dest/embedded/entrypoints/browser.js +32 -15
  15. package/dest/embedded/entrypoints/node.d.ts +7 -11
  16. package/dest/embedded/entrypoints/node.d.ts.map +1 -1
  17. package/dest/embedded/entrypoints/node.js +22 -14
  18. package/dest/testing.d.ts +1 -1
  19. package/dest/testing.d.ts.map +1 -1
  20. package/dest/testing.js +2 -2
  21. package/package.json +19 -9
  22. package/src/embedded/account-contract-providers/bundle.ts +13 -6
  23. package/src/embedded/account-contract-providers/lazy.ts +23 -7
  24. package/src/embedded/account-contract-providers/types.ts +6 -3
  25. package/src/embedded/embedded_wallet.ts +211 -60
  26. package/src/embedded/entrypoints/browser.ts +46 -19
  27. package/src/embedded/entrypoints/node.ts +34 -30
  28. package/src/testing.ts +2 -1
  29. package/dest/embedded/embedded_wallet_browser.d.ts +0 -5
  30. package/dest/embedded/embedded_wallet_browser.d.ts.map +0 -1
  31. package/dest/embedded/embedded_wallet_browser.js +0 -31
  32. package/src/embedded/embedded_wallet_browser.ts +0 -40
@@ -1,29 +1,72 @@
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 { type InteractionWaitOptions, type SendReturn, type WaitOpts, getGasLimits } from '@aztec/aztec.js/contracts';
4
+ import type { Aliased, SendOptions } from '@aztec/aztec.js/wallet';
5
+ import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
4
6
  import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
7
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
5
8
  import { Fq, Fr } from '@aztec/foundation/curves/bn254';
6
9
  import type { Logger } from '@aztec/foundation/log';
7
- import type { AccessScopes } from '@aztec/pxe/client/lazy';
10
+ import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
8
11
  import type { PXE } from '@aztec/pxe/server';
9
12
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
10
13
  import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
14
+ import { GasSettings } from '@aztec/stdlib/gas';
11
15
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
12
16
  import { deriveSigningKey } from '@aztec/stdlib/keys';
13
- import { ExecutionPayload, type TxSimulationResult, mergeExecutionPayloads } from '@aztec/stdlib/tx';
14
- import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
17
+ import {
18
+ type ContractOverrides,
19
+ ExecutionPayload,
20
+ SimulationOverrides,
21
+ type TxExecutionRequest,
22
+ TxStatus,
23
+ collectOffchainEffects,
24
+ mergeExecutionPayloads,
25
+ } from '@aztec/stdlib/tx';
26
+ import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk/base-wallet';
15
27
 
16
28
  import type { AccountContractsProvider } from './account-contract-providers/types.js';
17
29
  import { type AccountType, WalletDB } from './wallet_db.js';
18
30
 
31
+ /** Options for the PXE instance created by the EmbeddedWallet. */
32
+ export type EmbeddedWalletPXEOptions = Partial<PXEConfig> & PXECreationOptions;
33
+
34
+ /** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */
35
+ export function splitPxeOptions(pxe?: EmbeddedWalletPXEOptions): {
36
+ config: Partial<PXEConfig>;
37
+ creation: PXECreationOptions;
38
+ } {
39
+ if (!pxe) {
40
+ return { config: {}, creation: {} };
41
+ }
42
+ const { loggers, loggerActorLabel, proverOrOptions, store, simulator, ...config } = pxe;
43
+ return { config, creation: { loggers, loggerActorLabel, proverOrOptions, store, simulator } };
44
+ }
45
+
19
46
  export type EmbeddedWalletOptions = {
20
47
  /** Parent logger. Child loggers are derived via createChild() for each subsystem. */
21
48
  logger?: Logger;
22
49
  /** Use ephemeral (in-memory) stores. Data will not persist across sessions. */
23
50
  ephemeral?: boolean;
51
+ /** PXE configuration and dependency overrides (custom store, prover, simulator). */
52
+ pxe?: EmbeddedWalletPXEOptions;
53
+ /**
54
+ * Override PXE configuration.
55
+ * @deprecated Use `pxe` instead.
56
+ */
57
+ pxeConfig?: Partial<PXEConfig>;
58
+ /**
59
+ * Advanced PXE creation options (custom store, prover, simulator).
60
+ * @deprecated Use `pxe` instead.
61
+ */
62
+ pxeOptions?: PXECreationOptions;
24
63
  };
25
64
 
65
+ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
66
+
26
67
  export class EmbeddedWallet extends BaseWallet {
68
+ protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
69
+
27
70
  constructor(
28
71
  pxe: PXE,
29
72
  aztecNode: AztecNode,
@@ -35,10 +78,6 @@ export class EmbeddedWallet extends BaseWallet {
35
78
  }
36
79
 
37
80
  protected async getAccountFromAddress(address: AztecAddress): Promise<Account> {
38
- if (address.equals(AztecAddress.ZERO)) {
39
- return new SignerlessAccount();
40
- }
41
-
42
81
  const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
43
82
  const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
44
83
  const account = await accountManager.getAccount();
@@ -70,6 +109,118 @@ export class EmbeddedWallet extends BaseWallet {
70
109
  return storedSenders;
71
110
  }
72
111
 
112
+ /**
113
+ * Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
114
+ * estimates actual gas usage and captures call authorization requests to generate
115
+ * the necessary authwitnesses.
116
+ */
117
+ public override async sendTx<W extends InteractionWaitOptions = undefined>(
118
+ executionPayload: ExecutionPayload,
119
+ opts: SendOptions<W>,
120
+ ): Promise<SendReturn<W>> {
121
+ const feeOptions = await this.completeFeeOptions({
122
+ from: opts.from,
123
+ feePayer: executionPayload.feePayer,
124
+ gasSettings: opts.fee?.gasSettings,
125
+ forEstimation: true,
126
+ });
127
+
128
+ // Simulate the transaction first to estimate gas and capture required
129
+ // private authwitnesses based on offchain effects.
130
+ const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
131
+ from: opts.from,
132
+ feeOptions,
133
+ additionalScopes: opts.additionalScopes,
134
+ skipTxValidation: true,
135
+ });
136
+
137
+ const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
138
+ const authWitnesses = await Promise.all(
139
+ offchainEffects.map(async effect => {
140
+ try {
141
+ const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
142
+ return this.createAuthWit(authRequest.onBehalfOf, {
143
+ consumer: effect.contractAddress,
144
+ innerHash: authRequest.innerHash,
145
+ });
146
+ } catch {
147
+ return undefined;
148
+ }
149
+ }),
150
+ );
151
+ for (const authwit of authWitnesses) {
152
+ if (authwit) {
153
+ executionPayload.authWitnesses.push(authwit);
154
+ }
155
+ }
156
+ const estimated = getGasLimits(simulationResult, this.estimatedGasPadding);
157
+ this.log.verbose(
158
+ `Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`,
159
+ );
160
+ const gasSettings = GasSettings.from({
161
+ ...opts.fee?.gasSettings,
162
+ maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
163
+ maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
164
+ gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
165
+ teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
166
+ });
167
+ const waitOpts: WaitOpts = typeof opts.wait === 'object' ? opts.wait : {};
168
+
169
+ if (!waitOpts?.waitForStatus) {
170
+ // Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
171
+ // rather than waiting until the end of the slot for the checkpoint to be published to L1.
172
+ // This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
173
+ // we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
174
+ // The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
175
+ // a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
176
+ // proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
177
+ waitOpts!.waitForStatus = TxStatus.PROPOSED;
178
+ }
179
+ return super.sendTx(executionPayload, {
180
+ ...opts,
181
+ fee: { ...opts.fee, gasSettings },
182
+ });
183
+ }
184
+
185
+ /**
186
+ * Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
187
+ * Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
188
+ */
189
+ protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
190
+ const accounts = await this.getAccounts();
191
+ const contracts: ContractOverrides = {};
192
+
193
+ const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
194
+
195
+ for (const account of filtered) {
196
+ const address = account.item;
197
+ const { type } = await this.walletDB.retrieveAccount(address);
198
+ const stubArtifact = await this.accountContracts.getStubAccountContractArtifact(type);
199
+
200
+ const originalAccount = await this.getAccountFromAddress(address);
201
+ const completeAddress = originalAccount.getCompleteAddress();
202
+ const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
203
+ if (!contractInstance) {
204
+ throw new Error(
205
+ `No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
206
+ );
207
+ }
208
+
209
+ const stubConstructorArgs = type === 'schnorr' ? [Fr.ZERO, Fr.ZERO] : [Buffer.alloc(32), Buffer.alloc(32)];
210
+ const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
211
+ salt: Fr.random(),
212
+ constructorArgs: stubConstructorArgs,
213
+ });
214
+
215
+ contracts[address.toString()] = {
216
+ instance: stubInstance,
217
+ artifact: stubArtifact,
218
+ };
219
+ }
220
+
221
+ return contracts;
222
+ }
223
+
73
224
  /**
74
225
  * Simulates calls via a stub account entrypoint, bypassing real account authorization.
75
226
  * This allows kernelless simulation with contract overrides, skipping expensive
@@ -77,61 +228,52 @@ export class EmbeddedWallet extends BaseWallet {
77
228
  */
78
229
  protected override async simulateViaEntrypoint(
79
230
  executionPayload: ExecutionPayload,
80
- from: AztecAddress,
81
- feeOptions: FeeOptions,
82
- scopes: AccessScopes,
83
- _skipTxValidation?: boolean,
84
- _skipFeeEnforcement?: boolean,
85
- ): Promise<TxSimulationResult> {
86
- const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
231
+ opts: SimulateViaEntrypointOptions,
232
+ ): Promise<TxSimulationResultWithAppOffset> {
233
+ const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement } = opts;
234
+ const scopes = this.scopesFrom(from, additionalScopes);
87
235
 
88
236
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
89
- const executionOptions: DefaultAccountEntrypointOptions = {
90
- txNonce: Fr.random(),
91
- cancellable: this.cancellableTransactions,
92
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
93
- };
94
237
  const finalExecutionPayload = feeExecutionPayload
95
238
  ? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
96
239
  : executionPayload;
97
240
  const chainInfo = await this.getChainInfo();
98
- const txRequest = await fromAccount.createTxExecutionRequest(
99
- finalExecutionPayload,
100
- feeOptions.gasSettings,
101
- chainInfo,
102
- executionOptions,
103
- );
104
- return this.pxe.simulateTx(txRequest, {
105
- simulatePublic: true,
106
- skipFeeEnforcement: true,
107
- skipTxValidation: true,
108
- overrides: {
109
- contracts: { [from.toString()]: { instance, artifact } },
110
- },
111
- scopes,
112
- });
113
- }
114
241
 
115
- private async getFakeAccountDataFor(address: AztecAddress) {
116
- const originalAccount = await this.getAccountFromAddress(address);
117
- if (originalAccount instanceof SignerlessAccount) {
118
- throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
119
- }
120
- const originalAddress = (originalAccount as Account).getCompleteAddress();
121
- const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
122
- if (!contractInstance) {
123
- throw new Error(`No contract instance found for address: ${originalAddress.address}`);
242
+ const accountOverrides = await this.buildAccountOverrides(scopes);
243
+ const overrides = new SimulationOverrides(accountOverrides);
244
+
245
+ let txRequest: TxExecutionRequest;
246
+ if (from === NO_FROM) {
247
+ const entrypoint = new DefaultEntrypoint();
248
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
249
+ } else {
250
+ const { type } = await this.walletDB.retrieveAccount(from);
251
+ const originalAccount = await this.getAccountFromAddress(from);
252
+ const completeAddress = originalAccount.getCompleteAddress();
253
+ const account = await this.accountContracts.createStubAccount(completeAddress, type);
254
+ const executionOptions: DefaultAccountEntrypointOptions = {
255
+ txNonce: Fr.random(),
256
+ cancellable: this.cancellableTransactions,
257
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
258
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
259
+ };
260
+ txRequest = await account.createTxExecutionRequest(
261
+ finalExecutionPayload,
262
+ feeOptions.gasSettings,
263
+ chainInfo,
264
+ executionOptions,
265
+ );
124
266
  }
125
- const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
126
- const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
127
- const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
128
- salt: Fr.random(),
267
+
268
+ const result = await this.pxe.simulateTx(txRequest, {
269
+ simulatePublic: true,
270
+ skipFeeEnforcement,
271
+ skipTxValidation,
272
+ overrides,
273
+ scopes,
129
274
  });
130
- return {
131
- account: stubAccount,
132
- instance,
133
- artifact: stubArtifact,
134
- };
275
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
276
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
135
277
  }
136
278
 
137
279
  protected async createAccountInternal(
@@ -162,10 +304,15 @@ export class EmbeddedWallet extends BaseWallet {
162
304
  const accountManager = await AccountManager.create(this, secret, contract, salt);
163
305
 
164
306
  const instance = accountManager.getInstance();
165
- const artifact = await accountManager.getAccountContract().getContractArtifact();
166
-
167
- await this.registerContract(instance, artifact, accountManager.getSecretKey());
168
-
307
+ const existingInstance = await this.pxe.getContractInstance(instance.address);
308
+ if (!existingInstance) {
309
+ const existingArtifact = await this.pxe.getContractArtifact(instance.currentContractClassId);
310
+ await this.registerContract(
311
+ instance,
312
+ !existingArtifact ? await accountManager.getAccountContract().getContractArtifact() : undefined,
313
+ accountManager.getSecretKey(),
314
+ );
315
+ }
169
316
  return accountManager;
170
317
  }
171
318
 
@@ -198,6 +345,10 @@ export class EmbeddedWallet extends BaseWallet {
198
345
  this.minFeePadding = value ?? 0.5;
199
346
  }
200
347
 
348
+ setEstimatedGasPadding(value?: number) {
349
+ this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
350
+ }
351
+
201
352
  stop() {
202
353
  return this.pxe.stop();
203
354
  }
@@ -1,50 +1,77 @@
1
- import { createAztecNodeClient } from '@aztec/aztec.js/node';
2
- import { createLogger } from '@aztec/foundation/log';
1
+ import { type AztecNode, createAztecNodeClient } from '@aztec/aztec.js/node';
2
+ import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { createStore, openTmpStore } from '@aztec/kv-store/indexeddb';
4
- import { createPXE } from '@aztec/pxe/client/lazy';
5
- import { getPXEConfig } from '@aztec/pxe/config';
4
+ import { type PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/client/lazy';
5
+ import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
6
6
 
7
7
  import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
8
- import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
8
+ import type { AccountContractsProvider } from '../account-contract-providers/types.js';
9
+ import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
9
10
  import { WalletDB } from '../wallet_db.js';
10
11
 
11
12
  export class BrowserEmbeddedWallet extends EmbeddedWallet {
12
- static async create(nodeUrl: string, options: EmbeddedWalletOptions = {}): Promise<BrowserEmbeddedWallet> {
13
+ static async create<T extends BrowserEmbeddedWallet = BrowserEmbeddedWallet>(
14
+ this: new (
15
+ pxe: PXE,
16
+ aztecNode: AztecNode,
17
+ walletDB: WalletDB,
18
+ accountContracts: AccountContractsProvider,
19
+ log?: Logger,
20
+ ) => T,
21
+ nodeOrUrl: string | AztecNode,
22
+ options: EmbeddedWalletOptions = {},
23
+ ): Promise<T> {
13
24
  const rootLogger = options.logger ?? createLogger('embedded-wallet');
14
25
 
15
- const aztecNode = createAztecNodeClient(nodeUrl);
16
-
26
+ const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
17
27
  const l1Contracts = await aztecNode.getL1ContractAddresses();
18
- const rollupAddress = l1Contracts.rollupAddress;
19
28
 
20
- const config = getPXEConfig();
21
- if (!options.ephemeral) {
22
- config.dataDirectory = `pxe-${rollupAddress}`;
29
+ // Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
30
+ const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
31
+ const mergedConfigOverrides = { ...options.pxeConfig, ...pxeConfigFromPxe };
32
+ const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
33
+
34
+ const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
35
+ proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
36
+ dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
37
+ ...mergedConfigOverrides,
38
+ });
39
+
40
+ if (options.ephemeral) {
41
+ delete pxeConfig.dataDirectory;
23
42
  }
24
43
 
25
- const pxe = await createPXE(aztecNode, config, {
44
+ const pxeOptions: PXECreationOptions = {
45
+ ...mergedCreationOverrides,
26
46
  loggers: {
27
47
  store: rootLogger.createChild('pxe:data'),
28
48
  pxe: rootLogger.createChild('pxe:service'),
29
49
  prover: rootLogger.createChild('pxe:prover'),
50
+ ...mergedCreationOverrides.loggers,
30
51
  },
31
- });
52
+ };
53
+
54
+ const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
32
55
 
33
56
  const walletDBStore = options.ephemeral
34
57
  ? await openTmpStore(true)
35
58
  : await createStore(
36
- `wallet-${rollupAddress}`,
37
- { dataDirectory: 'wallet', dataStoreMapSizeKb: 2e10 },
38
- undefined,
59
+ 'wallet_data',
60
+ {
61
+ dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
62
+ dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
63
+ l1Contracts,
64
+ },
65
+ 1,
39
66
  rootLogger.createChild('wallet:data'),
40
67
  );
41
68
  const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
42
69
 
43
- return new BrowserEmbeddedWallet(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger);
70
+ return new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
44
71
  }
45
72
  }
46
73
 
47
74
  export { BrowserEmbeddedWallet as EmbeddedWallet };
48
- export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
75
+ export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
49
76
  export { WalletDB } from '../wallet_db.js';
50
77
  export type { AccountType } from '../wallet_db.js';
@@ -1,34 +1,41 @@
1
1
  import { createAztecNodeClient } from '@aztec/aztec.js/node';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { createStore as createWalletStore, openTmpStore } from '@aztec/kv-store/lmdb-v2';
4
- import type { PXEConfig } from '@aztec/pxe/config';
5
- import { getPXEConfig } from '@aztec/pxe/config';
6
- import { type PXECreationOptions, createPXE } from '@aztec/pxe/server';
2
+ import { type Logger, createLogger } from '@aztec/foundation/log';
3
+ import { createStore, openTmpStore } from '@aztec/kv-store/lmdb-v2';
4
+ import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
5
+ import { type PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/server';
7
6
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
8
7
 
9
8
  import { BundleAccountContractsProvider } from '../account-contract-providers/bundle.js';
10
- import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
9
+ import type { AccountContractsProvider } from '../account-contract-providers/types.js';
10
+ import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
11
11
  import { WalletDB } from '../wallet_db.js';
12
12
 
13
- export type NodeEmbeddedWalletOptions = EmbeddedWalletOptions & {
14
- /** Override PXE configuration. */
15
- pxeConfig?: Partial<PXEConfig>;
16
- /** Advanced PXE creation options (custom store, prover, simulator). */
17
- pxeOptions?: PXECreationOptions;
18
- };
19
-
20
13
  export class NodeEmbeddedWallet extends EmbeddedWallet {
21
- static async create(
14
+ static async create<T extends NodeEmbeddedWallet = NodeEmbeddedWallet>(
15
+ this: new (
16
+ pxe: PXE,
17
+ aztecNode: AztecNode,
18
+ walletDB: WalletDB,
19
+ accountContracts: AccountContractsProvider,
20
+ log?: Logger,
21
+ ) => T,
22
22
  nodeOrUrl: string | AztecNode,
23
- options: NodeEmbeddedWalletOptions = {},
24
- ): Promise<NodeEmbeddedWallet> {
23
+ options: EmbeddedWalletOptions = {},
24
+ ): Promise<T> {
25
25
  const rootLogger = options.logger ?? createLogger('embedded-wallet');
26
26
 
27
27
  const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
28
+ const l1Contracts = await aztecNode.getL1ContractAddresses();
29
+
30
+ // Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
31
+ const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
32
+ const mergedConfigOverrides = { ...options.pxeConfig, ...pxeConfigFromPxe };
33
+ const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
28
34
 
29
- const pxeConfig = Object.assign(getPXEConfig(), {
30
- proverEnabled: options.pxeConfig?.proverEnabled ?? false,
31
- ...options.pxeConfig,
35
+ const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
36
+ proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
37
+ dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
38
+ ...mergedConfigOverrides,
32
39
  });
33
40
 
34
41
  if (options.ephemeral) {
@@ -36,45 +43,42 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
36
43
  }
37
44
 
38
45
  const pxeOptions: PXECreationOptions = {
39
- ...options.pxeOptions,
46
+ ...mergedCreationOverrides,
40
47
  loggers: {
41
48
  store: rootLogger.createChild('pxe:data'),
42
49
  pxe: rootLogger.createChild('pxe:service'),
43
50
  prover: rootLogger.createChild('pxe:prover'),
44
- ...options.pxeOptions?.loggers,
51
+ ...mergedCreationOverrides.loggers,
45
52
  },
46
53
  };
47
54
 
48
55
  const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
49
56
 
50
- const l1Contracts = await aztecNode.getL1ContractAddresses();
51
- const rollupAddress = l1Contracts.rollupAddress;
52
-
53
57
  const walletDBStore = options.ephemeral
54
58
  ? await openTmpStore(
55
- 'wallet_data',
59
+ `wallet_data_${l1Contracts.rollupAddress}`,
56
60
  true,
57
61
  undefined,
58
62
  undefined,
59
63
  rootLogger.createChild('wallet:data').getBindings(),
60
64
  )
61
- : await createWalletStore(
65
+ : await createStore(
62
66
  'wallet_data',
63
67
  1,
64
68
  {
65
- dataDirectory: pxeConfig.dataDirectory,
69
+ dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
66
70
  dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
67
- l1Contracts: { rollupAddress },
71
+ l1Contracts,
68
72
  },
69
73
  rootLogger.createChild('wallet:data').getBindings(),
70
74
  );
71
75
  const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
72
76
 
73
- return new NodeEmbeddedWallet(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger);
77
+ return new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger) as T;
74
78
  }
75
79
  }
76
80
 
77
81
  export { NodeEmbeddedWallet as EmbeddedWallet };
78
- export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
82
+ export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
79
83
  export { WalletDB } from '../wallet_db.js';
80
84
  export type { AccountType } from '../wallet_db.js';
package/src/testing.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { InitialAccountData } from '@aztec/accounts/testing';
2
2
  import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
3
+ import { NO_FROM } from '@aztec/aztec.js/account';
3
4
  import type { WaitOpts } from '@aztec/aztec.js/contracts';
4
5
  import type { AccountManager } from '@aztec/aztec.js/wallet';
5
6
  import type { Fq, Fr } from '@aztec/foundation/curves/bn254';
@@ -21,7 +22,7 @@ export async function deployFundedSchnorrAccounts(
21
22
  const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
22
23
  const deployMethod = await accountManager.getDeployMethod();
23
24
  await deployMethod.send({
24
- from: AztecAddress.ZERO,
25
+ from: NO_FROM,
25
26
  skipClassPublication: i !== 0,
26
27
  wait: waitOptions,
27
28
  });
@@ -1,5 +0,0 @@
1
- import { EmbeddedWallet } from './embedded_wallet.js';
2
- export declare class BrowserEmbeddedWallet extends EmbeddedWallet {
3
- static create(nodeUrl: string): Promise<BrowserEmbeddedWallet>;
4
- }
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW1iZWRkZWRfd2FsbGV0X2Jyb3dzZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9lbWJlZGRlZC9lbWJlZGRlZF93YWxsZXRfYnJvd3Nlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFPQSxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFHdEQscUJBQWEscUJBQXNCLFNBQVEsY0FBYztJQUN2RCxPQUFhLE1BQU0sQ0FBQyxPQUFPLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxxQkFBcUIsQ0FBQyxDQTJCbkU7Q0FDRiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"embedded_wallet_browser.d.ts","sourceRoot":"","sources":["../../src/embedded/embedded_wallet_browser.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,qBAAa,qBAAsB,SAAQ,cAAc;IACvD,OAAa,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA2BnE;CACF"}
@@ -1,31 +0,0 @@
1
- import { createAztecNodeClient } from '@aztec/aztec.js/node';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { createStore } from '@aztec/kv-store/indexeddb';
4
- import { createPXE } from '@aztec/pxe/client/lazy';
5
- import { getPXEConfig } from '@aztec/pxe/config';
6
- import { LazyAccountContractsProvider } from './account-contract-providers/lazy.js';
7
- import { EmbeddedWallet } from './embedded_wallet.js';
8
- import { WalletDB } from './wallet_db.js';
9
- export class BrowserEmbeddedWallet extends EmbeddedWallet {
10
- static async create(nodeUrl) {
11
- const aztecNode = createAztecNodeClient(nodeUrl);
12
- const l1Contracts = await aztecNode.getL1ContractAddresses();
13
- const rollupAddress = l1Contracts.rollupAddress;
14
- const config = getPXEConfig();
15
- config.dataDirectory = `pxe-${rollupAddress}`;
16
- const pxe = await createPXE(aztecNode, config, {
17
- loggers: {
18
- store: createLogger('pxe:data:idb'),
19
- pxe: createLogger('pxe:service'),
20
- prover: createLogger('bb:wasm:lazy')
21
- }
22
- });
23
- const logger = createLogger('embedded-wallet:browser');
24
- const walletDBStore = await createStore(`wallet-${rollupAddress}`, {
25
- dataDirectory: 'wallet',
26
- dataStoreMapSizeKb: 2e10
27
- }, undefined, createLogger('wallet:data:idb'));
28
- const walletDB = WalletDB.init(walletDBStore, logger.info);
29
- return new BrowserEmbeddedWallet(pxe, aztecNode, walletDB, new LazyAccountContractsProvider());
30
- }
31
- }
@@ -1,40 +0,0 @@
1
- import { createAztecNodeClient } from '@aztec/aztec.js/node';
2
- import { createLogger } from '@aztec/foundation/log';
3
- import { createStore } from '@aztec/kv-store/indexeddb';
4
- import { createPXE } from '@aztec/pxe/client/lazy';
5
- import { getPXEConfig } from '@aztec/pxe/config';
6
-
7
- import { LazyAccountContractsProvider } from './account-contract-providers/lazy.js';
8
- import { EmbeddedWallet } from './embedded_wallet.js';
9
- import { WalletDB } from './wallet_db.js';
10
-
11
- export class BrowserEmbeddedWallet extends EmbeddedWallet {
12
- static async create(nodeUrl: string): Promise<BrowserEmbeddedWallet> {
13
- const aztecNode = createAztecNodeClient(nodeUrl);
14
-
15
- const l1Contracts = await aztecNode.getL1ContractAddresses();
16
- const rollupAddress = l1Contracts.rollupAddress;
17
-
18
- const config = getPXEConfig();
19
- config.dataDirectory = `pxe-${rollupAddress}`;
20
-
21
- const pxe = await createPXE(aztecNode, config, {
22
- loggers: {
23
- store: createLogger('pxe:data:idb'),
24
- pxe: createLogger('pxe:service'),
25
- prover: createLogger('bb:wasm:lazy'),
26
- },
27
- });
28
-
29
- const logger = createLogger('embedded-wallet:browser');
30
- const walletDBStore = await createStore(
31
- `wallet-${rollupAddress}`,
32
- { dataDirectory: 'wallet', dataStoreMapSizeKb: 2e10 },
33
- undefined,
34
- createLogger('wallet:data:idb'),
35
- );
36
- const walletDB = WalletDB.init(walletDBStore, logger.info);
37
-
38
- return new BrowserEmbeddedWallet(pxe, aztecNode, walletDB, new LazyAccountContractsProvider());
39
- }
40
- }