@aztec/wallets 0.0.1-commit.96dac018d → 0.0.1-commit.993d240

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 +5 -8
  2. package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
  3. package/dest/embedded/account-contract-providers/bundle.js +6 -9
  4. package/dest/embedded/account-contract-providers/lazy.d.ts +5 -8
  5. package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
  6. package/dest/embedded/account-contract-providers/lazy.js +16 -10
  7. package/dest/embedded/account-contract-providers/types.d.ts +5 -8
  8. package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
  9. package/dest/embedded/embedded_wallet.d.ts +64 -10
  10. package/dest/embedded/embedded_wallet.d.ts.map +1 -1
  11. package/dest/embedded/embedded_wallet.js +212 -65
  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 +37 -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 +31 -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 +5 -4
  22. package/dest/embedded/wallet_db.d.ts.map +1 -1
  23. package/dest/embedded/wallet_db.js +9 -9
  24. package/dest/testing.d.ts +1 -1
  25. package/dest/testing.d.ts.map +1 -1
  26. package/dest/testing.js +2 -2
  27. package/package.json +21 -10
  28. package/src/embedded/account-contract-providers/bundle.ts +8 -11
  29. package/src/embedded/account-contract-providers/lazy.ts +18 -12
  30. package/src/embedded/account-contract-providers/types.ts +5 -4
  31. package/src/embedded/embedded_wallet.ts +299 -75
  32. package/src/embedded/entrypoints/browser.ts +42 -20
  33. package/src/embedded/entrypoints/node.ts +41 -26
  34. package/src/embedded/store_encryption.ts +107 -0
  35. package/src/embedded/wallet_db.ts +12 -9
  36. package/src/testing.ts +2 -1
@@ -1,21 +1,47 @@
1
- import { SignerlessAccount } from '@aztec/aztec.js/account';
2
- import { AccountManager } from '@aztec/aztec.js/wallet';
1
+ import { NO_FROM } from '@aztec/aztec.js/account';
2
+ import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
3
+ import { getGasLimits } from '@aztec/aztec.js/contracts';
4
+ import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
5
+ import { DefaultEntrypoint } from '@aztec/entrypoints/default';
3
6
  import { Fq, Fr } from '@aztec/foundation/curves/bn254';
4
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
5
- import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
7
+ import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
8
+ import { GasSettings } from '@aztec/stdlib/gas';
6
9
  import { deriveSigningKey } from '@aztec/stdlib/keys';
7
- import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
10
+ import { SimulationOverrides, TxStatus, collectOffchainEffects, mergeExecutionPayloads } from '@aztec/stdlib/tx';
8
11
  import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
12
+ /** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */ export function splitPxeOptions(pxe) {
13
+ if (!pxe) {
14
+ return {
15
+ config: {},
16
+ creation: {}
17
+ };
18
+ }
19
+ const { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider, ...config } = pxe;
20
+ return {
21
+ config,
22
+ creation: {
23
+ loggers,
24
+ loggerActorLabel,
25
+ proverOrOptions,
26
+ store,
27
+ simulator,
28
+ hooks,
29
+ preloadedContractsProvider
30
+ }
31
+ };
32
+ }
33
+ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
9
34
  export class EmbeddedWallet extends BaseWallet {
10
35
  walletDB;
11
36
  accountContracts;
37
+ estimatedGasPadding;
38
+ // Stub class ids, populated on wallet startup
39
+ // to avoid redundant work per simulation
40
+ stubClassIds;
12
41
  constructor(pxe, aztecNode, walletDB, accountContracts, log){
13
- super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts;
42
+ super(pxe, aztecNode, log), this.walletDB = walletDB, this.accountContracts = accountContracts, this.estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING, this.stubClassIds = new Map();
14
43
  }
15
44
  async getAccountFromAddress(address) {
16
- if (address.equals(AztecAddress.ZERO)) {
17
- return new SignerlessAccount();
18
- }
19
45
  const { secretKey, salt, signingKey, type } = await this.walletDB.retrieveAccount(address);
20
46
  const accountManager = await this.createAccountInternal(type, secretKey, salt, signingKey);
21
47
  const account = await accountManager.getAccount();
@@ -42,72 +68,187 @@ export class EmbeddedWallet extends BaseWallet {
42
68
  return storedSenders;
43
69
  }
44
70
  /**
71
+ * Overrides the base sendTx to add a pre-simulation step before the actual send. The simulation
72
+ * estimates actual gas usage and captures call authorization requests to generate
73
+ * the necessary authwitnesses.
74
+ */ async sendTx(executionPayload, opts) {
75
+ // PXE has autoSync disabled by the embedded wallet entrypoints, so we sync once here to cover
76
+ // both the inner simulateTx (via simulateViaEntrypoint) and the proveTx that super.sendTx
77
+ await this.pxe.sync();
78
+ const feeOptions = await this.completeFeeOptions({
79
+ from: opts.from,
80
+ feePayer: executionPayload.feePayer,
81
+ gasSettings: opts.fee?.gasSettings,
82
+ forEstimation: true
83
+ });
84
+ // Simulate the transaction first to estimate gas and capture required
85
+ // private authwitnesses based on offchain effects.
86
+ const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
87
+ from: opts.from,
88
+ feeOptions,
89
+ additionalScopes: opts.additionalScopes,
90
+ skipTxValidation: true,
91
+ sendMessagesAs: opts.sendMessagesAs
92
+ });
93
+ const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
94
+ const authWitnesses = await Promise.all(offchainEffects.map(async (effect)=>{
95
+ try {
96
+ const authRequest = await CallAuthorizationRequest.fromFields(effect.data);
97
+ return this.createAuthWit(authRequest.onBehalfOf, {
98
+ consumer: effect.contractAddress,
99
+ innerHash: authRequest.innerHash
100
+ });
101
+ } catch {
102
+ return undefined;
103
+ }
104
+ }));
105
+ for (const authwit of authWitnesses){
106
+ if (authwit) {
107
+ executionPayload.authWitnesses.push(authwit);
108
+ }
109
+ }
110
+ const estimated = getGasLimits(simulationResult, this.estimatedGasPadding);
111
+ this.log.verbose(`Estimated gas limits for tx: DA=${estimated.gasLimits.daGas} L2=${estimated.gasLimits.l2Gas} teardownDA=${estimated.teardownGasLimits.daGas} teardownL2=${estimated.teardownGasLimits.l2Gas}`);
112
+ const gasSettings = GasSettings.from({
113
+ ...opts.fee?.gasSettings,
114
+ maxFeesPerGas: feeOptions.gasSettings.maxFeesPerGas,
115
+ maxPriorityFeesPerGas: feeOptions.gasSettings.maxPriorityFeesPerGas,
116
+ gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
117
+ teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits
118
+ });
119
+ const waitOpts = typeof opts.wait === 'object' ? opts.wait : {};
120
+ if (!waitOpts?.waitForStatus) {
121
+ // Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
122
+ // rather than waiting until the end of the slot for the checkpoint to be published to L1.
123
+ // This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
124
+ // we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
125
+ // The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
126
+ // a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
127
+ // proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
128
+ waitOpts.waitForStatus = TxStatus.PROPOSED;
129
+ }
130
+ return super.sendTx(executionPayload, {
131
+ ...opts,
132
+ fee: {
133
+ ...opts.fee,
134
+ gasSettings
135
+ }
136
+ });
137
+ }
138
+ /**
139
+ * Overrides the base simulateTx to drive PXE syncing explicitly. The PXE created by the embedded
140
+ * wallet has autoSync disabled (so we can share one sync across simulate+send in sendTx); for
141
+ * standalone simulations we still need a fresh anchor block, which we provide here.
142
+ */ async simulateTx(executionPayload, opts) {
143
+ await this.pxe.sync();
144
+ return super.simulateTx(executionPayload, opts);
145
+ }
146
+ async profileTx(executionPayload, opts) {
147
+ await this.pxe.sync();
148
+ return super.profileTx(executionPayload, opts);
149
+ }
150
+ async executeUtility(call, opts) {
151
+ await this.pxe.sync();
152
+ return super.executeUtility(call, opts);
153
+ }
154
+ async getPrivateEvents(eventDef, eventFilter) {
155
+ await this.pxe.sync();
156
+ return super.getPrivateEvents(eventDef, eventFilter);
157
+ }
158
+ async registerContract(instance, artifact, secretKey) {
159
+ // registerContract may call pxe.updateContract under the hood, which depends on a fresh anchor
160
+ // block to verify the current class id from the node.
161
+ await this.pxe.sync();
162
+ return super.registerContract(instance, artifact, secretKey);
163
+ }
164
+ /**
165
+ * Hashes and registers the stub class for every supported account type with PXE, populating
166
+ * stubClassIds. Called on wallet initialization.
167
+ */ async initStubClasses() {
168
+ const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
169
+ const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
170
+ await this.pxe.registerContractClass(schnorrArtifact);
171
+ // ecdsa stubs share the same class id
172
+ const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
173
+ const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
174
+ await this.pxe.registerContractClass(ecdsaArtifact);
175
+ this.stubClassIds.set('schnorr', schnorrClassId);
176
+ this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
177
+ this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
178
+ }
179
+ /**
180
+ * Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
181
+ * Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
182
+ */ async buildAccountOverrides(addresses) {
183
+ const accounts = await this.getAccounts();
184
+ const contracts = {};
185
+ const filtered = accounts.filter((acc)=>addresses.some((addr)=>addr.equals(acc.item)));
186
+ for (const account of filtered){
187
+ const address = account.item;
188
+ const { type } = await this.walletDB.retrieveAccount(address);
189
+ const stubClassId = this.stubClassIds.get(type);
190
+ if (!stubClassId) {
191
+ throw new Error(`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`);
192
+ }
193
+ const originalAccount = await this.getAccountFromAddress(address);
194
+ const completeAddress = originalAccount.getCompleteAddress();
195
+ const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
196
+ if (!contractInstance) {
197
+ throw new Error(`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`);
198
+ }
199
+ contracts[address.toString()] = {
200
+ instance: {
201
+ ...contractInstance,
202
+ currentContractClassId: stubClassId
203
+ }
204
+ };
205
+ }
206
+ return contracts;
207
+ }
208
+ /**
45
209
  * Simulates calls via a stub account entrypoint, bypassing real account authorization.
46
210
  * This allows kernelless simulation with contract overrides, skipping expensive
47
211
  * private kernel circuit execution.
48
- */ async simulateViaEntrypoint(executionPayload, from, feeOptions, scopes, _skipTxValidation, _skipFeeEnforcement) {
49
- const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
212
+ */ async simulateViaEntrypoint(executionPayload, opts) {
213
+ const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
214
+ const scopes = this.scopesFrom(from, additionalScopes);
50
215
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
51
- const executionOptions = {
52
- txNonce: Fr.random(),
53
- cancellable: this.cancellableTransactions,
54
- feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
55
- };
56
216
  const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
57
217
  feeExecutionPayload,
58
218
  executionPayload
59
219
  ]) : executionPayload;
60
220
  const chainInfo = await this.getChainInfo();
61
- const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
62
- return this.pxe.simulateTx(txRequest, {
63
- simulatePublic: true,
64
- skipFeeEnforcement: true,
65
- skipTxValidation: true,
66
- overrides: {
67
- contracts: {
68
- [from.toString()]: {
69
- instance,
70
- artifact
71
- }
72
- }
73
- },
74
- scopes
221
+ const accountOverrides = await this.buildAccountOverrides(scopes);
222
+ const overrides = new SimulationOverrides({
223
+ contracts: accountOverrides
75
224
  });
76
- }
77
- async getFakeAccountDataFor(address) {
78
- // While we have the convention of "Zero address means no auth", and also
79
- // we don't have a way to trigger kernelless simulations without overrides,
80
- // we need to explicitly handle the zero address case here by
81
- // returning the actual multicall contract instead of trying to create a stub account for it.
82
- if (!address.equals(AztecAddress.ZERO)) {
83
- const originalAccount = await this.getAccountFromAddress(address);
84
- if (originalAccount instanceof SignerlessAccount) {
85
- throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
86
- }
87
- const originalAddress = originalAccount.getCompleteAddress();
88
- const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
89
- if (!contractInstance) {
90
- throw new Error(`No contract instance found for address: ${originalAddress.address}`);
91
- }
92
- const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
93
- const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
94
- const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
95
- salt: Fr.random()
96
- });
97
- return {
98
- account: stubAccount,
99
- instance,
100
- artifact: stubArtifact
101
- };
225
+ let txRequest;
226
+ if (from === NO_FROM) {
227
+ const entrypoint = new DefaultEntrypoint();
228
+ txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
102
229
  } else {
103
- const { instance, artifact } = await this.accountContracts.getMulticallContract();
104
- const account = new SignerlessAccount();
105
- return {
106
- instance,
107
- account,
108
- artifact
230
+ const { type } = await this.walletDB.retrieveAccount(from);
231
+ const originalAccount = await this.getAccountFromAddress(from);
232
+ const completeAddress = originalAccount.getCompleteAddress();
233
+ const account = await this.accountContracts.createStubAccount(completeAddress, type);
234
+ const executionOptions = {
235
+ txNonce: Fr.random(),
236
+ cancellable: this.cancellableTransactions,
237
+ // If from is an address, feeOptions include the way the account contract should handle the fee payment
238
+ feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
109
239
  };
240
+ txRequest = await account.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
110
241
  }
242
+ const result = await this.pxe.simulateTx(txRequest, {
243
+ simulatePublic: true,
244
+ skipFeeEnforcement,
245
+ skipTxValidation,
246
+ overrides,
247
+ scopes,
248
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs)
249
+ });
250
+ const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
251
+ return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
111
252
  }
112
253
  async createAccountInternal(type, secret, salt, signingKey) {
113
254
  let contract;
@@ -132,7 +273,9 @@ export class EmbeddedWallet extends BaseWallet {
132
273
  throw new Error(`Unknown account type ${type}`);
133
274
  }
134
275
  }
135
- const accountManager = await AccountManager.create(this, secret, contract, salt);
276
+ const accountManager = await AccountManager.create(this, secret, contract, {
277
+ salt
278
+ });
136
279
  const instance = accountManager.getInstance();
137
280
  const existingInstance = await this.pxe.getContractInstance(instance.address);
138
281
  if (!existingInstance) {
@@ -165,7 +308,11 @@ export class EmbeddedWallet extends BaseWallet {
165
308
  setMinFeePadding(value) {
166
309
  this.minFeePadding = value ?? 0.5;
167
310
  }
168
- stop() {
169
- return this.pxe.stop();
311
+ setEstimatedGasPadding(value) {
312
+ this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
313
+ }
314
+ async stop() {
315
+ await this.pxe.stop();
316
+ await this.walletDB.close();
170
317
  }
171
318
  }
@@ -8,7 +8,7 @@ export declare class BrowserEmbeddedWallet extends EmbeddedWallet {
8
8
  static create<T extends BrowserEmbeddedWallet = BrowserEmbeddedWallet>(this: new (pxe: PXE, aztecNode: AztecNode, walletDB: WalletDB, accountContracts: AccountContractsProvider, log?: Logger) => T, nodeOrUrl: string | AztecNode, options?: EmbeddedWalletOptions): Promise<T>;
9
9
  }
10
10
  export { BrowserEmbeddedWallet as EmbeddedWallet };
11
- export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
11
+ export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
12
12
  export { WalletDB } from '../wallet_db.js';
13
13
  export type { AccountType } from '../wallet_db.js';
14
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnJvd3Nlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL2Jyb3dzZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEtBQUssU0FBUyxFQUF5QixNQUFNLHNCQUFzQixDQUFDO0FBQzdFLE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztBQUVsRSxPQUFPLEVBQUUsS0FBSyxHQUFHLEVBQXNDLE1BQU0sd0JBQXdCLENBQUM7QUFJdEYsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSx3Q0FBd0MsQ0FBQztBQUN2RixPQUFPLEVBQUUsY0FBYyxFQUFFLEtBQUsscUJBQXFCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNuRixPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFFM0MscUJBQWEscUJBQXNCLFNBQVEsY0FBYztJQUN2RCxPQUFhLE1BQU0sQ0FBQyxDQUFDLFNBQVMscUJBQXFCLEdB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,GAAG,qBAAqB,EACzE,IAAI,EAAE,KACJ,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,wBAAwB,EAC1C,GAAG,CAAC,EAAE,MAAM,KACT,CAAC,EACN,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,CAAC,CAAC,CAwDZ;CACF;AAED,OAAO,EAAE,qBAAqB,IAAI,cAAc,EAAE,CAAC;AACnD,YAAY,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
@@ -3,40 +3,67 @@ import { createLogger } from '@aztec/foundation/log';
3
3
  import { createStore, openTmpStore } from '@aztec/kv-store/indexeddb';
4
4
  import { createPXE } from '@aztec/pxe/client/lazy';
5
5
  import { getPXEConfig } from '@aztec/pxe/config';
6
+ import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry/lazy';
7
+ import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint/lazy';
6
8
  import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
7
- import { EmbeddedWallet } from '../embedded_wallet.js';
9
+ import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
8
10
  import { WalletDB } from '../wallet_db.js';
9
11
  export class BrowserEmbeddedWallet extends EmbeddedWallet {
10
12
  static async create(nodeOrUrl, options = {}) {
11
13
  const rootLogger = options.logger ?? createLogger('embedded-wallet');
12
14
  const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
13
15
  const l1Contracts = await aztecNode.getL1ContractAddresses();
16
+ // Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
17
+ const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
18
+ const mergedConfigOverrides = {
19
+ ...options.pxeConfig,
20
+ ...pxeConfigFromPxe
21
+ };
22
+ const mergedCreationOverrides = {
23
+ ...options.pxeOptions,
24
+ ...pxeCreationFromPxe
25
+ };
14
26
  const pxeConfig = Object.assign(getPXEConfig(), {
15
- proverEnabled: options.pxeConfig?.proverEnabled ?? false,
27
+ proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
16
28
  dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
17
- ...options.pxeConfig
29
+ autoSync: false,
30
+ ...mergedConfigOverrides
18
31
  });
19
32
  if (options.ephemeral) {
20
33
  delete pxeConfig.dataDirectory;
21
34
  }
22
35
  const pxeOptions = {
23
- ...options.pxeOptions,
36
+ ...mergedCreationOverrides,
37
+ preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
38
+ getPreloadedContracts: async ()=>[
39
+ await getStandardMultiCallEntrypoint(),
40
+ await getStandardAuthRegistry()
41
+ ]
42
+ },
24
43
  loggers: {
25
44
  store: rootLogger.createChild('pxe:data'),
26
45
  pxe: rootLogger.createChild('pxe:service'),
27
46
  prover: rootLogger.createChild('pxe:prover'),
28
- ...options.pxeOptions?.loggers
47
+ ...mergedCreationOverrides.loggers
29
48
  }
30
49
  };
31
50
  const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
32
- const walletDBStore = options.ephemeral ? await openTmpStore(true) : await createStore('wallet_data', {
51
+ const walletDBStore = options.walletDb?.store ?? (options.ephemeral ? await openTmpStore(true) : await createStore('wallet_data', {
33
52
  dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
34
53
  dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
35
- l1Contracts
36
- }, 1, rootLogger.createChild('wallet:data'));
37
- const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
38
- return new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger);
54
+ rollupAddress: l1Contracts.rollupAddress
55
+ }, 1, rootLogger.createChild('wallet:data')));
56
+ const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
57
+ const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger);
58
+ await wallet.initStubClasses();
59
+ return wallet;
39
60
  }
40
61
  }
41
62
  export { BrowserEmbeddedWallet as EmbeddedWallet };
42
63
  export { WalletDB } from '../wallet_db.js';
64
+ // At-rest encryption helpers are intentionally NOT re-exported here. They live
65
+ // on the `@aztec/wallets/embedded/store-encryption` sub-path so consumers
66
+ // (and bundlers) of this entrypoint don't transitively pull in
67
+ // `@aztec/kv-store/sqlite-opfs` and its `new Worker(new URL('./worker.js'))`
68
+ // chain into `@aztec/sqlite3mc-wasm`. Apps that don't use encryption-at-rest
69
+ // (e.g. the playground) should never see sqlite-opfs in their bundle.
@@ -8,7 +8,7 @@ export declare class NodeEmbeddedWallet extends EmbeddedWallet {
8
8
  static create<T extends NodeEmbeddedWallet = NodeEmbeddedWallet>(this: new (pxe: PXE, aztecNode: AztecNode, walletDB: WalletDB, accountContracts: AccountContractsProvider, log?: Logger) => T, nodeOrUrl: string | AztecNode, options?: EmbeddedWalletOptions): Promise<T>;
9
9
  }
10
10
  export { NodeEmbeddedWallet as EmbeddedWallet };
11
- export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
11
+ export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
12
12
  export { WalletDB } from '../wallet_db.js';
13
13
  export type { AccountType } from '../wallet_db.js';
14
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2VtYmVkZGVkL2VudHJ5cG9pbnRzL25vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEt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AiB,CAAC"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/embedded/entrypoints/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,EAAE,KAAK,GAAG,EAAsC,MAAM,mBAAmB,CAAC;AAGjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAmB,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAa,MAAM,CAAC,CAAC,SAAS,kBAAkB,GAAG,kBAAkB,EACnE,IAAI,EAAE,KACJ,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,gBAAgB,EAAE,wBAAwB,EAC1C,GAAG,CAAC,EAAE,MAAM,KACT,CAAC,EACN,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,CAAC,CAAC,CA8DZ;CACF;AAED,OAAO,EAAE,kBAAkB,IAAI,cAAc,EAAE,CAAC;AAChD,YAAY,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
@@ -3,39 +3,60 @@ import { createLogger } from '@aztec/foundation/log';
3
3
  import { createStore, openTmpStore } from '@aztec/kv-store/lmdb-v2';
4
4
  import { getPXEConfig } from '@aztec/pxe/config';
5
5
  import { createPXE } from '@aztec/pxe/server';
6
+ import { getStandardAuthRegistry } from '@aztec/standard-contracts/auth-registry';
7
+ import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint';
6
8
  import { BundleAccountContractsProvider } from '../account-contract-providers/bundle.js';
7
- import { EmbeddedWallet } from '../embedded_wallet.js';
9
+ import { EmbeddedWallet, splitPxeOptions } from '../embedded_wallet.js';
8
10
  import { WalletDB } from '../wallet_db.js';
9
11
  export class NodeEmbeddedWallet extends EmbeddedWallet {
10
12
  static async create(nodeOrUrl, options = {}) {
11
13
  const rootLogger = options.logger ?? createLogger('embedded-wallet');
12
14
  const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
13
15
  const l1Contracts = await aztecNode.getL1ContractAddresses();
16
+ // Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
17
+ const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
18
+ const mergedConfigOverrides = {
19
+ ...options.pxeConfig,
20
+ ...pxeConfigFromPxe
21
+ };
22
+ const mergedCreationOverrides = {
23
+ ...options.pxeOptions,
24
+ ...pxeCreationFromPxe
25
+ };
14
26
  const pxeConfig = Object.assign(getPXEConfig(), {
15
- proverEnabled: options.pxeConfig?.proverEnabled ?? false,
27
+ proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
16
28
  dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
17
- ...options.pxeConfig
29
+ autoSync: false,
30
+ ...mergedConfigOverrides
18
31
  });
19
32
  if (options.ephemeral) {
20
33
  delete pxeConfig.dataDirectory;
21
34
  }
22
35
  const pxeOptions = {
23
- ...options.pxeOptions,
36
+ ...mergedCreationOverrides,
37
+ preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
38
+ getPreloadedContracts: async ()=>[
39
+ await getStandardMultiCallEntrypoint(),
40
+ await getStandardAuthRegistry()
41
+ ]
42
+ },
24
43
  loggers: {
25
44
  store: rootLogger.createChild('pxe:data'),
26
45
  pxe: rootLogger.createChild('pxe:service'),
27
46
  prover: rootLogger.createChild('pxe:prover'),
28
- ...options.pxeOptions?.loggers
47
+ ...mergedCreationOverrides.loggers
29
48
  }
30
49
  };
31
50
  const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
32
- const walletDBStore = options.ephemeral ? await openTmpStore(`wallet_data_${l1Contracts.rollupAddress}`, true, undefined, undefined, rootLogger.createChild('wallet:data').getBindings()) : await createStore('wallet_data', 1, {
51
+ const walletDBStore = options.walletDb?.store ?? (options.ephemeral ? await openTmpStore(`wallet_data_${l1Contracts.rollupAddress}`, true, undefined, undefined, rootLogger.createChild('wallet:data').getBindings()) : await createStore('wallet_data', 1, {
33
52
  dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
34
53
  dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
35
- l1Contracts
36
- }, rootLogger.createChild('wallet:data').getBindings());
37
- const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
38
- return new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger);
54
+ rollupAddress: l1Contracts.rollupAddress
55
+ }, rootLogger.createChild('wallet:data').getBindings()));
56
+ const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
57
+ const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger);
58
+ await wallet.initStubClasses();
59
+ return wallet;
39
60
  }
40
61
  }
41
62
  export { NodeEmbeddedWallet as EmbeddedWallet };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Wallet-layer helpers for opening the embedded wallet's two encrypted stores (PXE + walletDB) as a cohesive unit.
3
+ *
4
+ * Sits on top of `@aztec/kv-store/sqlite-opfs`'s typed `SqliteEncryptionError` and adds:
5
+ *
6
+ * - `storeName: 'pxe' | 'wallet'`, telling callers WHICH store failed.
7
+ * - Cleanup: when the wallet store fails to open, ensures the already-opened PXE store is closed before the error
8
+ * surfaces, so callers don't leak the SAH Pool's OPFS lock.
9
+ */
10
+ import type { Logger } from '@aztec/foundation/log';
11
+ import { AztecSQLiteOPFSStore, SqliteEncryptionError } from '@aztec/kv-store/sqlite-opfs';
12
+ /** Which of the embedded wallet's two stores failed to open. */
13
+ export type EmbeddedStoreName = 'pxe' | 'wallet';
14
+ /**
15
+ * Thrown by {@link openEncryptedEmbeddedStores} when one of the two stores cannot be decrypted with the supplied
16
+ * key. The original {@link SqliteEncryptionError} is preserved as `cause`.
17
+ */
18
+ export declare class EmbeddedWalletEncryptionError extends Error {
19
+ readonly storeName: EmbeddedStoreName;
20
+ constructor(storeName: EmbeddedStoreName, opts: {
21
+ cause: SqliteEncryptionError;
22
+ });
23
+ }
24
+ /** Configuration for {@link openEncryptedEmbeddedStores}. */
25
+ export interface OpenEncryptedEmbeddedStoresOptions {
26
+ pxe: {
27
+ name: string;
28
+ poolDirectory?: string;
29
+ };
30
+ wallet: {
31
+ name: string;
32
+ poolDirectory?: string;
33
+ };
34
+ }
35
+ /**
36
+ * Internal seam for tests to inject a fake store opener. Defaults to `AztecSQLiteOPFSStore.open`. Not part of the
37
+ * public API.
38
+ *
39
+ * @internal
40
+ */
41
+ export type OpenSqliteEncryptedStoreFn = (log: Logger, name: string, poolDirectory: string | undefined, encryptionKey: Uint8Array) => Promise<AztecSQLiteOPFSStore>;
42
+ /**
43
+ * Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
44
+ *
45
+ * The callback is invoked once per store (twice total per call) because `AztecSQLiteOPFSStore.open` *transfers*
46
+ * the key buffer to its worker. A single buffer would detach between the two opens.
47
+ *
48
+ * Failure modes:
49
+ *
50
+ * - PXE store fails to decrypt → throws `EmbeddedWalletEncryptionError({ storeName: 'pxe', cause })`. No cleanup
51
+ * needed (nothing was opened).
52
+ * - Wallet store fails to decrypt → closes the already-opened PXE store then throws
53
+ * `EmbeddedWalletEncryptionError({ storeName: 'wallet', cause })`.
54
+ * - Any non-decrypt error during the wallet open → still closes PXE, then re-throws the original error unwrapped
55
+ * (preserves callers' existing untyped error handling for non-encryption faults).
56
+ *
57
+ * @param config - Per-store name/poolDirectory.
58
+ * @param getEncryptionKey - Returns a fresh 32-byte key per call (the buffer
59
+ * detaches on transfer, so each call must allocate).
60
+ * @param log - Logger for both stores.
61
+ * @param openStore - Internal test seam. Do not pass in production code.
62
+ */
63
+ export declare function openEncryptedEmbeddedStores(config: OpenEncryptedEmbeddedStoresOptions, getEncryptionKey: () => Promise<Uint8Array>, log: Logger, openStore?: OpenSqliteEncryptedStoreFn): Promise<{
64
+ pxeStore: AztecSQLiteOPFSStore;
65
+ walletStore: AztecSQLiteOPFSStore;
66
+ }>;
67
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVfZW5jcnlwdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2VtYmVkZGVkL3N0b3JlX2VuY3J5cHRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7O0dBUUc7QUFDSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUscUJBQXFCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUUxRixnRUFBZ0U7QUFDaEUsTUFBTSxNQUFNLGlCQUFpQixHQUFHLEtBQUssR0FBRyxRQUFRLENBQUM7QUFFakQ7OztHQUdHO0FBQ0gscUJBQWEsNkJBQThCLFNBQVEsS0FBSztJQUN0RCxRQUFRLENBQUMsU0FBUyxFQUFFLGlCQUFpQixDQUFDO0lBRXRDLFlBQVksU0FBUyxFQUFFLGlCQUFpQixFQUFFLElBQUksRUFBRTtRQUFFLEtBQUssRUFBRSxxQkFBcUIsQ0FBQTtLQUFFLEVBSS9FO0NBQ0Y7QUFFRCw2REFBNkQ7QUFDN0QsTUFBTSxXQUFXLGtDQUFrQztJQ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