@aztec/wallets 0.0.1-commit.2d9cb6034 → 0.0.1-commit.2f68f620
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.
- package/dest/embedded/account-contract-providers/bundle.d.ts +5 -8
- package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/bundle.js +6 -9
- package/dest/embedded/account-contract-providers/lazy.d.ts +5 -8
- package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
- package/dest/embedded/account-contract-providers/lazy.js +16 -10
- package/dest/embedded/account-contract-providers/types.d.ts +5 -8
- package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.d.ts +53 -8
- package/dest/embedded/embedded_wallet.d.ts.map +1 -1
- package/dest/embedded/embedded_wallet.js +148 -42
- package/dest/embedded/entrypoints/browser.d.ts +2 -2
- package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
- package/dest/embedded/entrypoints/browser.js +37 -10
- package/dest/embedded/entrypoints/node.d.ts +2 -2
- package/dest/embedded/entrypoints/node.d.ts.map +1 -1
- package/dest/embedded/entrypoints/node.js +31 -10
- package/dest/embedded/store_encryption.d.ts +67 -0
- package/dest/embedded/store_encryption.d.ts.map +1 -0
- package/dest/embedded/store_encryption.js +71 -0
- package/dest/embedded/wallet_db.d.ts +5 -4
- package/dest/embedded/wallet_db.d.ts.map +1 -1
- package/dest/embedded/wallet_db.js +9 -9
- package/package.json +12 -10
- package/src/embedded/account-contract-providers/bundle.ts +8 -11
- package/src/embedded/account-contract-providers/lazy.ts +18 -12
- package/src/embedded/account-contract-providers/types.ts +5 -4
- package/src/embedded/embedded_wallet.ts +211 -43
- package/src/embedded/entrypoints/browser.ts +42 -20
- package/src/embedded/entrypoints/node.ts +41 -26
- package/src/embedded/store_encryption.ts +107 -0
- package/src/embedded/wallet_db.ts +12 -9
|
@@ -1,24 +1,43 @@
|
|
|
1
1
|
import { type Account, NO_FROM } from '@aztec/aztec.js/account';
|
|
2
2
|
import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import {
|
|
4
|
+
type InteractionWaitOptions,
|
|
5
|
+
NO_WAIT,
|
|
6
|
+
type SendReturn,
|
|
7
|
+
type WaitOpts,
|
|
8
|
+
getGasLimits,
|
|
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';
|
|
6
20
|
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
7
21
|
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
8
22
|
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
9
23
|
import type { Logger } from '@aztec/foundation/log';
|
|
24
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
10
25
|
import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
|
|
11
26
|
import type { PXE } from '@aztec/pxe/server';
|
|
27
|
+
import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
|
|
12
28
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
-
import {
|
|
29
|
+
import { type ContractInstanceWithAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
|
|
14
30
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
15
31
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
16
32
|
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
17
33
|
import {
|
|
34
|
+
type ContractOverrides,
|
|
18
35
|
ExecutionPayload,
|
|
19
36
|
SimulationOverrides,
|
|
20
37
|
type TxExecutionRequest,
|
|
21
|
-
type
|
|
38
|
+
type TxProfileResult,
|
|
39
|
+
TxStatus,
|
|
40
|
+
type UtilityExecutionResult,
|
|
22
41
|
collectOffchainEffects,
|
|
23
42
|
mergeExecutionPayloads,
|
|
24
43
|
} from '@aztec/stdlib/tx';
|
|
@@ -27,14 +46,49 @@ import { BaseWallet, type SimulateViaEntrypointOptions } from '@aztec/wallet-sdk
|
|
|
27
46
|
import type { AccountContractsProvider } from './account-contract-providers/types.js';
|
|
28
47
|
import { type AccountType, WalletDB } from './wallet_db.js';
|
|
29
48
|
|
|
49
|
+
/** Options for the PXE instance created by the EmbeddedWallet. */
|
|
50
|
+
export type EmbeddedWalletPXEOptions = Partial<PXEConfig> & PXECreationOptions;
|
|
51
|
+
|
|
52
|
+
/** Splits a unified EmbeddedWalletPXEOptions into PXEConfig overrides and PXECreationOptions. */
|
|
53
|
+
export function splitPxeOptions(pxe?: EmbeddedWalletPXEOptions): {
|
|
54
|
+
config: Partial<PXEConfig>;
|
|
55
|
+
creation: PXECreationOptions;
|
|
56
|
+
} {
|
|
57
|
+
if (!pxe) {
|
|
58
|
+
return { config: {}, creation: {} };
|
|
59
|
+
}
|
|
60
|
+
const { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider, ...config } =
|
|
61
|
+
pxe;
|
|
62
|
+
return {
|
|
63
|
+
config,
|
|
64
|
+
creation: { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Options for the EmbeddedWallet's own DB (accounts, senders — distinct from PXE state). */
|
|
69
|
+
export type EmbeddedWalletDBOptions = {
|
|
70
|
+
/** Override the wallet DB backend. If omitted, an IndexedDB (browser) / LMDB (node) store is created. */
|
|
71
|
+
store?: AztecAsyncKVStore;
|
|
72
|
+
};
|
|
73
|
+
|
|
30
74
|
export type EmbeddedWalletOptions = {
|
|
31
75
|
/** Parent logger. Child loggers are derived via createChild() for each subsystem. */
|
|
32
76
|
logger?: Logger;
|
|
33
77
|
/** Use ephemeral (in-memory) stores. Data will not persist across sessions. */
|
|
34
78
|
ephemeral?: boolean;
|
|
35
|
-
/**
|
|
79
|
+
/** PXE configuration and dependency overrides (custom store, prover, simulator). */
|
|
80
|
+
pxe?: EmbeddedWalletPXEOptions;
|
|
81
|
+
/** Wallet DB dependency overrides (custom store). */
|
|
82
|
+
walletDb?: EmbeddedWalletDBOptions;
|
|
83
|
+
/**
|
|
84
|
+
* Override PXE configuration.
|
|
85
|
+
* @deprecated Use `pxe` instead.
|
|
86
|
+
*/
|
|
36
87
|
pxeConfig?: Partial<PXEConfig>;
|
|
37
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Advanced PXE creation options (custom store, prover, simulator).
|
|
90
|
+
* @deprecated Use `pxe` instead.
|
|
91
|
+
*/
|
|
38
92
|
pxeOptions?: PXECreationOptions;
|
|
39
93
|
};
|
|
40
94
|
|
|
@@ -43,6 +97,10 @@ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
|
|
|
43
97
|
export class EmbeddedWallet extends BaseWallet {
|
|
44
98
|
protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
|
|
45
99
|
|
|
100
|
+
// Stub class ids, populated on wallet startup
|
|
101
|
+
// to avoid redundant work per simulation
|
|
102
|
+
protected stubClassIds = new Map<AccountType, Fr>();
|
|
103
|
+
|
|
46
104
|
constructor(
|
|
47
105
|
pxe: PXE,
|
|
48
106
|
aztecNode: AztecNode,
|
|
@@ -94,19 +152,24 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
94
152
|
executionPayload: ExecutionPayload,
|
|
95
153
|
opts: SendOptions<W>,
|
|
96
154
|
): Promise<SendReturn<W>> {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
155
|
+
// PXE has autoSync disabled by the embedded wallet entrypoints, so we sync once here to cover
|
|
156
|
+
// both the inner simulateTx (via simulateViaEntrypoint) and the proveTx that super.sendTx
|
|
157
|
+
await this.pxe.sync();
|
|
158
|
+
const feeOptions = await this.completeFeeOptions({
|
|
159
|
+
from: opts.from,
|
|
160
|
+
feePayer: executionPayload.feePayer,
|
|
161
|
+
gasSettings: opts.fee?.gasSettings,
|
|
162
|
+
forEstimation: true,
|
|
163
|
+
});
|
|
102
164
|
|
|
103
165
|
// Simulate the transaction first to estimate gas and capture required
|
|
104
166
|
// private authwitnesses based on offchain effects.
|
|
105
167
|
const simulationResult = await this.simulateViaEntrypoint(executionPayload, {
|
|
106
168
|
from: opts.from,
|
|
107
169
|
feeOptions,
|
|
108
|
-
|
|
170
|
+
additionalScopes: opts.additionalScopes,
|
|
109
171
|
skipTxValidation: true,
|
|
172
|
+
sendMessagesAs: opts.sendMessagesAs,
|
|
110
173
|
});
|
|
111
174
|
|
|
112
175
|
const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
|
|
@@ -139,12 +202,129 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
139
202
|
gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
|
|
140
203
|
teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
|
|
141
204
|
});
|
|
205
|
+
let wait: InteractionWaitOptions = opts.wait;
|
|
206
|
+
if (wait !== NO_WAIT) {
|
|
207
|
+
const callerWaitOpts: WaitOpts = typeof wait === 'object' ? wait : {};
|
|
208
|
+
wait = {
|
|
209
|
+
...callerWaitOpts,
|
|
210
|
+
// Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
|
|
211
|
+
// rather than waiting until the end of the slot for the checkpoint to be published to L1.
|
|
212
|
+
// This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
|
|
213
|
+
// we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
|
|
214
|
+
// The tradeoff is a weaker guarantee — a proposed block only becomes canonical once it (or
|
|
215
|
+
// a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
|
|
216
|
+
// proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
|
|
217
|
+
waitForStatus: callerWaitOpts.waitForStatus ?? TxStatus.PROPOSED,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
142
220
|
return super.sendTx(executionPayload, {
|
|
143
221
|
...opts,
|
|
222
|
+
wait: wait as W,
|
|
144
223
|
fee: { ...opts.fee, gasSettings },
|
|
145
224
|
});
|
|
146
225
|
}
|
|
147
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Overrides the base simulateTx to drive PXE syncing explicitly. The PXE created by the embedded
|
|
229
|
+
* wallet has autoSync disabled (so we can share one sync across simulate+send in sendTx); for
|
|
230
|
+
* standalone simulations we still need a fresh anchor block, which we provide here.
|
|
231
|
+
*/
|
|
232
|
+
public override async simulateTx(
|
|
233
|
+
executionPayload: ExecutionPayload,
|
|
234
|
+
opts: SimulateOptions,
|
|
235
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
236
|
+
await this.pxe.sync();
|
|
237
|
+
return super.simulateTx(executionPayload, opts);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public override async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
241
|
+
await this.pxe.sync();
|
|
242
|
+
return super.profileTx(executionPayload, opts);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public override async executeUtility(
|
|
246
|
+
call: FunctionCall,
|
|
247
|
+
opts: ExecuteUtilityOptions,
|
|
248
|
+
): Promise<UtilityExecutionResult> {
|
|
249
|
+
await this.pxe.sync();
|
|
250
|
+
return super.executeUtility(call, opts);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
public override async getPrivateEvents<T>(
|
|
254
|
+
eventDef: EventMetadataDefinition,
|
|
255
|
+
eventFilter: PrivateEventFilter,
|
|
256
|
+
): Promise<PrivateEvent<T>[]> {
|
|
257
|
+
await this.pxe.sync();
|
|
258
|
+
return super.getPrivateEvents<T>(eventDef, eventFilter);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public override async registerContract(
|
|
262
|
+
instance: ContractInstanceWithAddress,
|
|
263
|
+
artifact?: ContractArtifact,
|
|
264
|
+
secretKey?: Fr,
|
|
265
|
+
): Promise<ContractInstanceWithAddress> {
|
|
266
|
+
// registerContract may call pxe.updateContract under the hood, which depends on a fresh anchor
|
|
267
|
+
// block to verify the current class id from the node.
|
|
268
|
+
await this.pxe.sync();
|
|
269
|
+
return super.registerContract(instance, artifact, secretKey);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Hashes and registers the stub class for every supported account type with PXE, populating
|
|
274
|
+
* stubClassIds. Called on wallet initialization.
|
|
275
|
+
*/
|
|
276
|
+
async initStubClasses(): Promise<void> {
|
|
277
|
+
const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
|
|
278
|
+
const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
|
|
279
|
+
await this.pxe.registerContractClass(schnorrArtifact);
|
|
280
|
+
|
|
281
|
+
// ecdsa stubs share the same class id
|
|
282
|
+
const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
|
|
283
|
+
const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
|
|
284
|
+
await this.pxe.registerContractClass(ecdsaArtifact);
|
|
285
|
+
|
|
286
|
+
this.stubClassIds.set('schnorr', schnorrClassId);
|
|
287
|
+
this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
|
|
288
|
+
this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
|
|
293
|
+
* Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
|
|
294
|
+
*/
|
|
295
|
+
protected async buildAccountOverrides(addresses: AztecAddress[]): Promise<ContractOverrides> {
|
|
296
|
+
const accounts = await this.getAccounts();
|
|
297
|
+
const contracts: ContractOverrides = {};
|
|
298
|
+
|
|
299
|
+
const filtered = accounts.filter(acc => addresses.some(addr => addr.equals(acc.item)));
|
|
300
|
+
|
|
301
|
+
for (const account of filtered) {
|
|
302
|
+
const address = account.item;
|
|
303
|
+
const { type } = await this.walletDB.retrieveAccount(address);
|
|
304
|
+
const stubClassId = this.stubClassIds.get(type);
|
|
305
|
+
if (!stubClassId) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
312
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
313
|
+
const contractInstance = await this.pxe.getContractInstance(completeAddress.address);
|
|
314
|
+
if (!contractInstance) {
|
|
315
|
+
throw new Error(
|
|
316
|
+
`No contract instance found for address: ${completeAddress.address} during account override building. This is a bug!`,
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
contracts[address.toString()] = {
|
|
321
|
+
instance: { ...contractInstance, currentContractClassId: stubClassId },
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return contracts;
|
|
326
|
+
}
|
|
327
|
+
|
|
148
328
|
/**
|
|
149
329
|
* Simulates calls via a stub account entrypoint, bypassing real account authorization.
|
|
150
330
|
* This allows kernelless simulation with contract overrides, skipping expensive
|
|
@@ -153,8 +333,9 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
153
333
|
protected override async simulateViaEntrypoint(
|
|
154
334
|
executionPayload: ExecutionPayload,
|
|
155
335
|
opts: SimulateViaEntrypointOptions,
|
|
156
|
-
): Promise<
|
|
157
|
-
const { from, feeOptions,
|
|
336
|
+
): Promise<TxSimulationResultWithAppOffset> {
|
|
337
|
+
const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
|
|
338
|
+
const scopes = this.scopesFrom(from, additionalScopes);
|
|
158
339
|
|
|
159
340
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
160
341
|
const finalExecutionPayload = feeExecutionPayload
|
|
@@ -162,16 +343,18 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
162
343
|
: executionPayload;
|
|
163
344
|
const chainInfo = await this.getChainInfo();
|
|
164
345
|
|
|
165
|
-
|
|
346
|
+
const accountOverrides = await this.buildAccountOverrides(scopes);
|
|
347
|
+
const overrides = new SimulationOverrides({ contracts: accountOverrides });
|
|
348
|
+
|
|
166
349
|
let txRequest: TxExecutionRequest;
|
|
167
350
|
if (from === NO_FROM) {
|
|
168
351
|
const entrypoint = new DefaultEntrypoint();
|
|
169
352
|
txRequest = await entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
170
353
|
} else {
|
|
171
|
-
const {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
354
|
+
const { type } = await this.walletDB.retrieveAccount(from);
|
|
355
|
+
const originalAccount = await this.getAccountFromAddress(from);
|
|
356
|
+
const completeAddress = originalAccount.getCompleteAddress();
|
|
357
|
+
const account = await this.accountContracts.createStubAccount(completeAddress, type);
|
|
175
358
|
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
176
359
|
txNonce: Fr.random(),
|
|
177
360
|
cancellable: this.cancellableTransactions,
|
|
@@ -186,32 +369,16 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
186
369
|
);
|
|
187
370
|
}
|
|
188
371
|
|
|
189
|
-
|
|
372
|
+
const result = await this.pxe.simulateTx(txRequest, {
|
|
190
373
|
simulatePublic: true,
|
|
191
374
|
skipFeeEnforcement,
|
|
192
375
|
skipTxValidation,
|
|
193
376
|
overrides,
|
|
194
377
|
scopes,
|
|
378
|
+
senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
|
|
195
379
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
private async getFakeAccountDataFor(address: AztecAddress) {
|
|
199
|
-
const originalAccount = await this.getAccountFromAddress(address);
|
|
200
|
-
const originalAddress = originalAccount.getCompleteAddress();
|
|
201
|
-
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
202
|
-
if (!contractInstance) {
|
|
203
|
-
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
204
|
-
}
|
|
205
|
-
const stubAccount = await this.accountContracts.createStubAccount(originalAddress);
|
|
206
|
-
const stubArtifact = await this.accountContracts.getStubAccountContractArtifact();
|
|
207
|
-
const instance = await getContractInstanceFromInstantiationParams(stubArtifact, {
|
|
208
|
-
salt: Fr.random(),
|
|
209
|
-
});
|
|
210
|
-
return {
|
|
211
|
-
account: stubAccount,
|
|
212
|
-
instance,
|
|
213
|
-
artifact: stubArtifact,
|
|
214
|
-
};
|
|
380
|
+
const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
|
|
381
|
+
return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
|
|
215
382
|
}
|
|
216
383
|
|
|
217
384
|
protected async createAccountInternal(
|
|
@@ -239,7 +406,7 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
239
406
|
}
|
|
240
407
|
}
|
|
241
408
|
|
|
242
|
-
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
409
|
+
const accountManager = await AccountManager.create(this, secret, contract, { salt });
|
|
243
410
|
|
|
244
411
|
const instance = accountManager.getInstance();
|
|
245
412
|
const existingInstance = await this.pxe.getContractInstance(instance.address);
|
|
@@ -287,7 +454,8 @@ export class EmbeddedWallet extends BaseWallet {
|
|
|
287
454
|
this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
|
|
288
455
|
}
|
|
289
456
|
|
|
290
|
-
stop() {
|
|
291
|
-
|
|
457
|
+
async stop(): Promise<void> {
|
|
458
|
+
await this.pxe.stop();
|
|
459
|
+
await this.walletDB.close();
|
|
292
460
|
}
|
|
293
461
|
}
|
|
@@ -3,10 +3,12 @@ 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 { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint/lazy';
|
|
6
8
|
|
|
7
9
|
import { LazyAccountContractsProvider } from '../account-contract-providers/lazy.js';
|
|
8
10
|
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
9
|
-
import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
11
|
+
import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
|
|
10
12
|
import { WalletDB } from '../wallet_db.js';
|
|
11
13
|
|
|
12
14
|
export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
@@ -26,10 +28,16 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
26
28
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
27
29
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
28
30
|
|
|
31
|
+
// Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
|
|
32
|
+
const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
|
|
33
|
+
const mergedConfigOverrides = { ...options.pxeConfig, ...pxeConfigFromPxe };
|
|
34
|
+
const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
|
|
35
|
+
|
|
29
36
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
30
|
-
proverEnabled:
|
|
37
|
+
proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
|
|
31
38
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
32
|
-
|
|
39
|
+
autoSync: false,
|
|
40
|
+
...mergedConfigOverrides,
|
|
33
41
|
});
|
|
34
42
|
|
|
35
43
|
if (options.ephemeral) {
|
|
@@ -37,36 +45,50 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
|
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
const pxeOptions: PXECreationOptions = {
|
|
40
|
-
...
|
|
48
|
+
...mergedCreationOverrides,
|
|
49
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
50
|
+
getPreloadedContracts: async () => [await getStandardMultiCallEntrypoint(), await getStandardAuthRegistry()],
|
|
51
|
+
},
|
|
41
52
|
loggers: {
|
|
42
53
|
store: rootLogger.createChild('pxe:data'),
|
|
43
54
|
pxe: rootLogger.createChild('pxe:service'),
|
|
44
55
|
prover: rootLogger.createChild('pxe:prover'),
|
|
45
|
-
...
|
|
56
|
+
...mergedCreationOverrides.loggers,
|
|
46
57
|
},
|
|
47
58
|
};
|
|
48
59
|
|
|
49
60
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
50
61
|
|
|
51
|
-
const walletDBStore =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const walletDBStore =
|
|
63
|
+
options.walletDb?.store ??
|
|
64
|
+
(options.ephemeral
|
|
65
|
+
? await openTmpStore(true)
|
|
66
|
+
: await createStore(
|
|
67
|
+
'wallet_data',
|
|
68
|
+
{
|
|
69
|
+
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
70
|
+
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
71
|
+
rollupAddress: l1Contracts.rollupAddress,
|
|
72
|
+
},
|
|
73
|
+
1,
|
|
74
|
+
rootLogger.createChild('wallet:data'),
|
|
75
|
+
));
|
|
76
|
+
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
64
77
|
|
|
65
|
-
|
|
78
|
+
const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
|
|
79
|
+
await wallet.initStubClasses();
|
|
80
|
+
return wallet;
|
|
66
81
|
}
|
|
67
82
|
}
|
|
68
83
|
|
|
69
84
|
export { BrowserEmbeddedWallet as EmbeddedWallet };
|
|
70
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
85
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
71
86
|
export { WalletDB } from '../wallet_db.js';
|
|
72
87
|
export type { AccountType } from '../wallet_db.js';
|
|
88
|
+
|
|
89
|
+
// At-rest encryption helpers are intentionally NOT re-exported here. They live
|
|
90
|
+
// on the `@aztec/wallets/embedded/store-encryption` sub-path so consumers
|
|
91
|
+
// (and bundlers) of this entrypoint don't transitively pull in
|
|
92
|
+
// `@aztec/kv-store/sqlite-opfs` and its `new Worker(new URL('./worker.js'))`
|
|
93
|
+
// chain into `@aztec/sqlite3mc-wasm`. Apps that don't use encryption-at-rest
|
|
94
|
+
// (e.g. the playground) should never see sqlite-opfs in their bundle.
|
|
@@ -3,11 +3,13 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
3
3
|
import { createStore, openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
4
4
|
import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
|
|
5
5
|
import { type PXE, type PXECreationOptions, 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 type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
7
9
|
|
|
8
10
|
import { BundleAccountContractsProvider } from '../account-contract-providers/bundle.js';
|
|
9
11
|
import type { AccountContractsProvider } from '../account-contract-providers/types.js';
|
|
10
|
-
import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
12
|
+
import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
|
|
11
13
|
import { WalletDB } from '../wallet_db.js';
|
|
12
14
|
|
|
13
15
|
export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
@@ -27,10 +29,16 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
27
29
|
const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
|
|
28
30
|
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
29
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
|
+
|
|
30
37
|
const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
|
|
31
|
-
proverEnabled:
|
|
38
|
+
proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
|
|
32
39
|
dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
|
|
33
|
-
|
|
40
|
+
autoSync: false,
|
|
41
|
+
...mergedConfigOverrides,
|
|
34
42
|
});
|
|
35
43
|
|
|
36
44
|
if (options.ephemeral) {
|
|
@@ -38,42 +46,49 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
|
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
const pxeOptions: PXECreationOptions = {
|
|
41
|
-
...
|
|
49
|
+
...mergedCreationOverrides,
|
|
50
|
+
preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
|
|
51
|
+
getPreloadedContracts: async () => [await getStandardMultiCallEntrypoint(), await getStandardAuthRegistry()],
|
|
52
|
+
},
|
|
42
53
|
loggers: {
|
|
43
54
|
store: rootLogger.createChild('pxe:data'),
|
|
44
55
|
pxe: rootLogger.createChild('pxe:service'),
|
|
45
56
|
prover: rootLogger.createChild('pxe:prover'),
|
|
46
|
-
...
|
|
57
|
+
...mergedCreationOverrides.loggers,
|
|
47
58
|
},
|
|
48
59
|
};
|
|
49
60
|
|
|
50
61
|
const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
|
|
51
62
|
|
|
52
|
-
const walletDBStore =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
const walletDBStore =
|
|
64
|
+
options.walletDb?.store ??
|
|
65
|
+
(options.ephemeral
|
|
66
|
+
? await openTmpStore(
|
|
67
|
+
`wallet_data_${l1Contracts.rollupAddress}`,
|
|
68
|
+
true,
|
|
69
|
+
undefined,
|
|
70
|
+
undefined,
|
|
71
|
+
rootLogger.createChild('wallet:data').getBindings(),
|
|
72
|
+
)
|
|
73
|
+
: await createStore(
|
|
74
|
+
'wallet_data',
|
|
75
|
+
1,
|
|
76
|
+
{
|
|
77
|
+
dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
|
|
78
|
+
dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
|
|
79
|
+
rollupAddress: l1Contracts.rollupAddress,
|
|
80
|
+
},
|
|
81
|
+
rootLogger.createChild('wallet:data').getBindings(),
|
|
82
|
+
));
|
|
83
|
+
const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
|
|
71
84
|
|
|
72
|
-
|
|
85
|
+
const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger) as T;
|
|
86
|
+
await wallet.initStubClasses();
|
|
87
|
+
return wallet;
|
|
73
88
|
}
|
|
74
89
|
}
|
|
75
90
|
|
|
76
91
|
export { NodeEmbeddedWallet as EmbeddedWallet };
|
|
77
|
-
export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
|
|
92
|
+
export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
|
|
78
93
|
export { WalletDB } from '../wallet_db.js';
|
|
79
94
|
export type { AccountType } from '../wallet_db.js';
|