@aztec/wallets 0.0.1-commit.b2a5d0dd1 → 0.0.1-commit.b3d3157a

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 +2 -6
  2. package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
  3. package/dest/embedded/account-contract-providers/bundle.js +0 -4
  4. package/dest/embedded/account-contract-providers/lazy.d.ts +2 -6
  5. package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
  6. package/dest/embedded/account-contract-providers/lazy.js +0 -4
  7. package/dest/embedded/account-contract-providers/types.d.ts +2 -6
  8. package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
  9. package/dest/embedded/embedded_wallet.d.ts +21 -3
  10. package/dest/embedded/embedded_wallet.d.ts.map +1 -1
  11. package/dest/embedded/embedded_wallet.js +91 -36
  12. package/dest/embedded/entrypoints/browser.d.ts +1 -1
  13. package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
  14. package/dest/embedded/entrypoints/browser.js +20 -3
  15. package/dest/embedded/entrypoints/node.d.ts +1 -1
  16. package/dest/embedded/entrypoints/node.d.ts.map +1 -1
  17. package/dest/embedded/entrypoints/node.js +14 -3
  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/package.json +12 -10
  25. package/src/embedded/account-contract-providers/bundle.ts +1 -6
  26. package/src/embedded/account-contract-providers/lazy.ts +1 -6
  27. package/src/embedded/account-contract-providers/types.ts +1 -2
  28. package/src/embedded/embedded_wallet.ts +127 -30
  29. package/src/embedded/entrypoints/browser.ts +18 -3
  30. package/src/embedded/entrypoints/node.ts +11 -3
  31. package/src/embedded/store_encryption.ts +107 -0
  32. package/src/embedded/wallet_db.ts +12 -9
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVfZW5jcnlwdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2VtYmVkZGVkL3N0b3JlX2VuY3J5cHRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7O0dBUUc7QUFDSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUscUJBQXFCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUUxRixnRUFBZ0U7QUFDaEUsTUFBTSxNQUF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AE,oBAAoB,CAAC;IAAC,WAAW,EAAE,oBAAoB,CAAA;CAAE,CAAC,CAWhF"}
@@ -0,0 +1,71 @@
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
+ */ import { AztecSQLiteOPFSStore, SqliteEncryptionError } from '@aztec/kv-store/sqlite-opfs';
10
+ /**
11
+ * Thrown by {@link openEncryptedEmbeddedStores} when one of the two stores cannot be decrypted with the supplied
12
+ * key. The original {@link SqliteEncryptionError} is preserved as `cause`.
13
+ */ export class EmbeddedWalletEncryptionError extends Error {
14
+ storeName;
15
+ constructor(storeName, opts){
16
+ super(`Embedded wallet '${storeName}' store could not be decrypted with the provided key`, {
17
+ cause: opts.cause
18
+ });
19
+ this.name = 'EmbeddedWalletEncryptionError';
20
+ this.storeName = storeName;
21
+ }
22
+ }
23
+ const defaultOpenStore = (log, name, poolDirectory, encryptionKey)=>AztecSQLiteOPFSStore.open(log, name, false, poolDirectory, encryptionKey);
24
+ /**
25
+ * Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
26
+ *
27
+ * The callback is invoked once per store (twice total per call) because `AztecSQLiteOPFSStore.open` *transfers*
28
+ * the key buffer to its worker. A single buffer would detach between the two opens.
29
+ *
30
+ * Failure modes:
31
+ *
32
+ * - PXE store fails to decrypt → throws `EmbeddedWalletEncryptionError({ storeName: 'pxe', cause })`. No cleanup
33
+ * needed (nothing was opened).
34
+ * - Wallet store fails to decrypt → closes the already-opened PXE store then throws
35
+ * `EmbeddedWalletEncryptionError({ storeName: 'wallet', cause })`.
36
+ * - Any non-decrypt error during the wallet open → still closes PXE, then re-throws the original error unwrapped
37
+ * (preserves callers' existing untyped error handling for non-encryption faults).
38
+ *
39
+ * @param config - Per-store name/poolDirectory.
40
+ * @param getEncryptionKey - Returns a fresh 32-byte key per call (the buffer
41
+ * detaches on transfer, so each call must allocate).
42
+ * @param log - Logger for both stores.
43
+ * @param openStore - Internal test seam. Do not pass in production code.
44
+ */ export async function openEncryptedEmbeddedStores(config, getEncryptionKey, log, openStore = defaultOpenStore) {
45
+ const pxeStore = await openOneStore('pxe', config.pxe, getEncryptionKey, log, openStore);
46
+ try {
47
+ const walletStore = await openOneStore('wallet', config.wallet, getEncryptionKey, log, openStore);
48
+ return {
49
+ pxeStore,
50
+ walletStore
51
+ };
52
+ } catch (err) {
53
+ // Cleanup is best-effort — if close() itself throws (e.g. worker already dead), swallow it so the original error
54
+ // surfaces unobstructed.
55
+ await pxeStore.close().catch(()=>{});
56
+ throw err;
57
+ }
58
+ }
59
+ async function openOneStore(storeName, { name, poolDirectory }, getEncryptionKey, log, openStore) {
60
+ const key = await getEncryptionKey();
61
+ try {
62
+ return await openStore(log, name, poolDirectory, key);
63
+ } catch (err) {
64
+ if (err instanceof SqliteEncryptionError && err.code === 'decrypt_failed') {
65
+ throw new EmbeddedWalletEncryptionError(storeName, {
66
+ cause: err
67
+ });
68
+ }
69
+ throw err;
70
+ }
71
+ }
@@ -7,11 +7,11 @@ export declare const AccountTypes: readonly ["schnorr", "ecdsasecp256r1", "ecdsa
7
7
  export type AccountType = (typeof AccountTypes)[number];
8
8
  export declare class WalletDB {
9
9
  #private;
10
+ private store;
11
+ private userLog;
10
12
  private accounts;
11
13
  private aliases;
12
- private userLog;
13
- private constructor();
14
- static init(store: AztecAsyncKVStore, userLog: LogFn): WalletDB;
14
+ constructor(store: AztecAsyncKVStore, userLog: LogFn);
15
15
  storeAccount(address: AztecAddress, { type, secretKey, salt, alias, signingKey }: {
16
16
  type: AccountType;
17
17
  secretKey: Fr;
@@ -30,5 +30,6 @@ export declare class WalletDB {
30
30
  listAccounts(): Promise<Aliased<AztecAddress>[]>;
31
31
  listSenders(): Promise<Aliased<AztecAddress>[]>;
32
32
  deleteAccount(address: AztecAddress): Promise<void>;
33
+ close(): Promise<void>;
33
34
  }
34
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X2RiLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZW1iZWRkZWQvd2FsbGV0X2RiLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ3RELE9BQU8sRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDeEQsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBRTNELGVBQU8sTUFBTSxZQUFZLDBEQUEyRCxDQUFDO0FBQ3JGLE1BQU0sTUFBTSxXQUFXLEdBQUcsQ0FBQyxPQUFPLFlBQVksQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBTXhELHFCQUFhLFFBQVE7O0lBRWpCLE9BQU8sQ0FBQyxRQUFRO0lBQ2hCLE9BQU8sQ0FBQyxPQUFPO0lBQ2YsT0FBTyxDQUFDLE9BQU87SUFIakIsT0FBTyxlQUlIO0lBRUosTUFBTSxDQUFDLElBQUksQ0FBQyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsT0FBTyxFQUFFLEtBQUssWUFJbkQ7SUFFSyxZQUFZLENBQ2hCLE9BQU8sRUFBRSxZQUFZLEVBQ3JCLEVBQ0U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,EACJ,KAAK,EACL,UAAU,EACX,EAAE;QACD,IAAI,EAAE,WAAW,CAAC;QAClB,SAAS,EAAE,EAAE,CAAC;QACd,IAAI,EAAE,EAAE,CAAC;QACT,UAAU,EAAE,EAAE,GAAG,MAAM,CAAC;QACxB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;KAC3B,EACD,GAAG,GAAE,KAAoB,iBAa1B;IAEK,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,KAAoB,iBAGhF;IAEK,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;;;;;;OAcnD;IAEK,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CAWrD;IAEK,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,CASpD;IAoBK,aAAa,CAAC,OAAO,EAAE,YAAY,iBAaxC;IAEK,KAAK,kBAEV;CACF"}
@@ -9,18 +9,15 @@ function accountKey(field, address) {
9
9
  return `${field}:${address.toString()}`;
10
10
  }
11
11
  export class WalletDB {
12
+ store;
13
+ userLog;
12
14
  accounts;
13
15
  aliases;
14
- userLog;
15
- constructor(accounts, aliases, userLog){
16
- this.accounts = accounts;
17
- this.aliases = aliases;
16
+ constructor(store, userLog){
17
+ this.store = store;
18
18
  this.userLog = userLog;
19
- }
20
- static init(store, userLog) {
21
- const accounts = store.openMap('accounts');
22
- const aliases = store.openMap('aliases');
23
- return new WalletDB(accounts, aliases, userLog);
19
+ this.accounts = store.openMap('accounts');
20
+ this.aliases = store.openMap('aliases');
24
21
  }
25
22
  async storeAccount(address, { type, secretKey, salt, alias, signingKey }, log = this.userLog) {
26
23
  if (alias) {
@@ -117,4 +114,7 @@ export class WalletDB {
117
114
  await this.aliases.delete(`accounts:${alias}`);
118
115
  }
119
116
  }
117
+ async close() {
118
+ await this.store.close();
119
+ }
120
120
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aztec/wallets",
3
3
  "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallets",
4
- "version": "0.0.1-commit.b2a5d0dd1",
4
+ "version": "0.0.1-commit.b3d3157a",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  "./embedded": {
@@ -14,6 +14,7 @@
14
14
  "default": "./dest/embedded/entrypoints/node.js"
15
15
  }
16
16
  },
17
+ "./embedded/store-encryption": "./dest/embedded/store_encryption.js",
17
18
  "./testing": "./dest/testing.js"
18
19
  },
19
20
  "scripts": {
@@ -27,15 +28,16 @@
27
28
  "../package.common.json"
28
29
  ],
29
30
  "dependencies": {
30
- "@aztec/accounts": "0.0.1-commit.b2a5d0dd1",
31
- "@aztec/aztec.js": "0.0.1-commit.b2a5d0dd1",
32
- "@aztec/entrypoints": "0.0.1-commit.b2a5d0dd1",
33
- "@aztec/foundation": "0.0.1-commit.b2a5d0dd1",
34
- "@aztec/kv-store": "0.0.1-commit.b2a5d0dd1",
35
- "@aztec/protocol-contracts": "0.0.1-commit.b2a5d0dd1",
36
- "@aztec/pxe": "0.0.1-commit.b2a5d0dd1",
37
- "@aztec/stdlib": "0.0.1-commit.b2a5d0dd1",
38
- "@aztec/wallet-sdk": "0.0.1-commit.b2a5d0dd1"
31
+ "@aztec/accounts": "0.0.1-commit.b3d3157a",
32
+ "@aztec/aztec.js": "0.0.1-commit.b3d3157a",
33
+ "@aztec/entrypoints": "0.0.1-commit.b3d3157a",
34
+ "@aztec/foundation": "0.0.1-commit.b3d3157a",
35
+ "@aztec/kv-store": "0.0.1-commit.b3d3157a",
36
+ "@aztec/protocol-contracts": "0.0.1-commit.b3d3157a",
37
+ "@aztec/pxe": "0.0.1-commit.b3d3157a",
38
+ "@aztec/standard-contracts": "0.0.1-commit.b3d3157a",
39
+ "@aztec/stdlib": "0.0.1-commit.b3d3157a",
40
+ "@aztec/wallet-sdk": "0.0.1-commit.b3d3157a"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@jest/globals": "^30.0.0",
@@ -4,9 +4,8 @@ import { StubEcdsaAccountContractArtifact, createStubEcdsaAccount } from '@aztec
4
4
  import { StubSchnorrAccountContractArtifact, createStubSchnorrAccount } from '@aztec/accounts/stub/schnorr';
5
5
  import type { Account, AccountContract } from '@aztec/aztec.js/account';
6
6
  import type { Fq } from '@aztec/foundation/curves/bn254';
7
- import { getCanonicalMultiCallEntrypoint } from '@aztec/protocol-contracts/multi-call-entrypoint';
8
7
  import type { ContractArtifact } from '@aztec/stdlib/abi';
9
- import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
8
+ import type { CompleteAddress } from '@aztec/stdlib/contract';
10
9
 
11
10
  import type { AccountType } from '../wallet_db.js';
12
11
  import type { AccountContractsProvider } from './types.js';
@@ -35,8 +34,4 @@ export class BundleAccountContractsProvider implements AccountContractsProvider
35
34
  createStubAccount(address: CompleteAddress, type: AccountType): Promise<Account> {
36
35
  return Promise.resolve(type === 'schnorr' ? createStubSchnorrAccount(address) : createStubEcdsaAccount(address));
37
36
  }
38
-
39
- getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }> {
40
- return getCanonicalMultiCallEntrypoint();
41
- }
42
37
  }
@@ -1,8 +1,7 @@
1
1
  import type { Account, AccountContract } from '@aztec/aztec.js/account';
2
2
  import type { Fq } from '@aztec/foundation/curves/bn254';
3
- import { getCanonicalMultiCallEntrypoint } from '@aztec/protocol-contracts/multi-call-entrypoint/lazy';
4
3
  import type { ContractArtifact } from '@aztec/stdlib/abi';
5
- import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
4
+ import type { CompleteAddress } from '@aztec/stdlib/contract';
6
5
 
7
6
  import type { AccountType } from '../wallet_db.js';
8
7
  import type { AccountContractsProvider } from './types.js';
@@ -46,8 +45,4 @@ export class LazyAccountContractsProvider implements AccountContractsProvider {
46
45
  return createStubEcdsaAccount(address);
47
46
  }
48
47
  }
49
-
50
- getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }> {
51
- return getCanonicalMultiCallEntrypoint();
52
- }
53
48
  }
@@ -1,7 +1,7 @@
1
1
  import type { Account, AccountContract } from '@aztec/aztec.js/account';
2
2
  import type { Fq } from '@aztec/foundation/curves/bn254';
3
3
  import type { ContractArtifact } from '@aztec/stdlib/abi';
4
- import type { CompleteAddress, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
4
+ import type { CompleteAddress } from '@aztec/stdlib/contract';
5
5
 
6
6
  import type { AccountType } from '../wallet_db.js';
7
7
 
@@ -16,6 +16,5 @@ export interface AccountContractsProvider {
16
16
  getEcdsaRAccountContract(signingKey: Buffer): Promise<AccountContract>;
17
17
  getEcdsaKAccountContract(signingKey: Buffer): Promise<AccountContract>;
18
18
  getStubAccountContractArtifact(type: AccountType): Promise<ContractArtifact>;
19
- getMulticallContract(): Promise<{ instance: ContractInstanceWithAddress; artifact: ContractArtifact }>;
20
19
  createStubAccount(address: CompleteAddress, type: AccountType): Promise<Account>;
21
20
  }
@@ -1,7 +1,21 @@
1
1
  import { type Account, NO_FROM } from '@aztec/aztec.js/account';
2
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';
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';
5
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';
@@ -10,8 +24,9 @@ import type { Logger } from '@aztec/foundation/log';
10
24
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
11
25
  import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
12
26
  import type { PXE } from '@aztec/pxe/server';
27
+ import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
13
28
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
14
- import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
29
+ import { type ContractInstanceWithAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
15
30
  import { GasSettings } from '@aztec/stdlib/gas';
16
31
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
17
32
  import { deriveSigningKey } from '@aztec/stdlib/keys';
@@ -20,7 +35,9 @@ import {
20
35
  ExecutionPayload,
21
36
  SimulationOverrides,
22
37
  type TxExecutionRequest,
38
+ type TxProfileResult,
23
39
  TxStatus,
40
+ type UtilityExecutionResult,
24
41
  collectOffchainEffects,
25
42
  mergeExecutionPayloads,
26
43
  } from '@aztec/stdlib/tx';
@@ -40,8 +57,12 @@ export function splitPxeOptions(pxe?: EmbeddedWalletPXEOptions): {
40
57
  if (!pxe) {
41
58
  return { config: {}, creation: {} };
42
59
  }
43
- const { loggers, loggerActorLabel, proverOrOptions, store, simulator, ...config } = pxe;
44
- return { config, creation: { loggers, loggerActorLabel, proverOrOptions, store, simulator } };
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
+ };
45
66
  }
46
67
 
47
68
  /** Options for the EmbeddedWallet's own DB (accounts, senders — distinct from PXE state). */
@@ -76,6 +97,10 @@ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
76
97
  export class EmbeddedWallet extends BaseWallet {
77
98
  protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
78
99
 
100
+ // Stub class ids, populated on wallet startup
101
+ // to avoid redundant work per simulation
102
+ protected stubClassIds = new Map<AccountType, Fr>();
103
+
79
104
  constructor(
80
105
  pxe: PXE,
81
106
  aztecNode: AztecNode,
@@ -127,6 +152,9 @@ export class EmbeddedWallet extends BaseWallet {
127
152
  executionPayload: ExecutionPayload,
128
153
  opts: SendOptions<W>,
129
154
  ): Promise<SendReturn<W>> {
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();
130
158
  const feeOptions = await this.completeFeeOptions({
131
159
  from: opts.from,
132
160
  feePayer: executionPayload.feePayer,
@@ -141,6 +169,7 @@ export class EmbeddedWallet extends BaseWallet {
141
169
  feeOptions,
142
170
  additionalScopes: opts.additionalScopes,
143
171
  skipTxValidation: true,
172
+ sendMessagesAs: opts.sendMessagesAs,
144
173
  });
145
174
 
146
175
  const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
@@ -173,24 +202,92 @@ export class EmbeddedWallet extends BaseWallet {
173
202
  gasLimits: opts.fee?.gasSettings?.gasLimits ?? estimated.gasLimits,
174
203
  teardownGasLimits: opts.fee?.gasSettings?.teardownGasLimits ?? estimated.teardownGasLimits,
175
204
  });
176
- const waitOpts: WaitOpts = typeof opts.wait === 'object' ? opts.wait : {};
177
-
178
- if (!waitOpts?.waitForStatus) {
179
- // Default to PROPOSED so the wait returns as soon as the tx lands in a proposed L2 block,
180
- // rather than waiting until the end of the slot for the checkpoint to be published to L1.
181
- // This is what makes MBPS (Multiple Blocks Per Slot) actually improve UX: with CHECKPOINTED
182
- // we'd block until L1 inclusion regardless of how early in the slot the tx was sequenced.
183
- // The tradeoff is a weaker guarantee a proposed block only becomes canonical once it (or
184
- // a later block in the same slot) is checkpointed, so a tx could be re-orged out if the
185
- // proposer fails to publish to L1 (which should be rare, since they'd get slashed for it).
186
- waitOpts!.waitForStatus = TxStatus.PROPOSED;
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
+ };
187
219
  }
188
220
  return super.sendTx(executionPayload, {
189
221
  ...opts,
222
+ wait: wait as W,
190
223
  fee: { ...opts.fee, gasSettings },
191
224
  });
192
225
  }
193
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
+
194
291
  /**
195
292
  * Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
196
293
  * Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
@@ -204,7 +301,12 @@ export class EmbeddedWallet extends BaseWallet {
204
301
  for (const account of filtered) {
205
302
  const address = account.item;
206
303
  const { type } = await this.walletDB.retrieveAccount(address);
207
- const stubArtifact = await this.accountContracts.getStubAccountContractArtifact(type);
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
+ }
208
310
 
209
311
  const originalAccount = await this.getAccountFromAddress(address);
210
312
  const completeAddress = originalAccount.getCompleteAddress();
@@ -215,15 +317,8 @@ export class EmbeddedWallet extends BaseWallet {
215
317
  );
216
318
  }
217
319
 
218
- const stubConstructorArgs = type === 'schnorr' ? [Fr.ZERO, Fr.ZERO] : [Buffer.alloc(32), Buffer.alloc(32)];
219
- const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
220
- salt: Fr.random(),
221
- constructorArgs: stubConstructorArgs,
222
- });
223
-
224
320
  contracts[address.toString()] = {
225
- instance: stubInstance,
226
- artifact: stubArtifact,
321
+ instance: { ...contractInstance, currentContractClassId: stubClassId },
227
322
  };
228
323
  }
229
324
 
@@ -239,7 +334,7 @@ export class EmbeddedWallet extends BaseWallet {
239
334
  executionPayload: ExecutionPayload,
240
335
  opts: SimulateViaEntrypointOptions,
241
336
  ): Promise<TxSimulationResultWithAppOffset> {
242
- const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement } = opts;
337
+ const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
243
338
  const scopes = this.scopesFrom(from, additionalScopes);
244
339
 
245
340
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
@@ -249,7 +344,7 @@ export class EmbeddedWallet extends BaseWallet {
249
344
  const chainInfo = await this.getChainInfo();
250
345
 
251
346
  const accountOverrides = await this.buildAccountOverrides(scopes);
252
- const overrides = new SimulationOverrides(accountOverrides);
347
+ const overrides = new SimulationOverrides({ contracts: accountOverrides });
253
348
 
254
349
  let txRequest: TxExecutionRequest;
255
350
  if (from === NO_FROM) {
@@ -280,6 +375,7 @@ export class EmbeddedWallet extends BaseWallet {
280
375
  skipTxValidation,
281
376
  overrides,
282
377
  scopes,
378
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
283
379
  });
284
380
  const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
285
381
  return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
@@ -310,7 +406,7 @@ export class EmbeddedWallet extends BaseWallet {
310
406
  }
311
407
  }
312
408
 
313
- const accountManager = await AccountManager.create(this, secret, contract, salt);
409
+ const accountManager = await AccountManager.create(this, secret, contract, { salt });
314
410
 
315
411
  const instance = accountManager.getInstance();
316
412
  const existingInstance = await this.pxe.getContractInstance(instance.address);
@@ -358,7 +454,8 @@ export class EmbeddedWallet extends BaseWallet {
358
454
  this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
359
455
  }
360
456
 
361
- stop() {
362
- return this.pxe.stop();
457
+ async stop(): Promise<void> {
458
+ await this.pxe.stop();
459
+ await this.walletDB.close();
363
460
  }
364
461
  }
@@ -3,6 +3,8 @@ 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';
@@ -34,6 +36,7 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
34
36
  const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
35
37
  proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
36
38
  dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
39
+ autoSync: false,
37
40
  ...mergedConfigOverrides,
38
41
  });
39
42
 
@@ -43,6 +46,9 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
43
46
 
44
47
  const pxeOptions: PXECreationOptions = {
45
48
  ...mergedCreationOverrides,
49
+ preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
50
+ getPreloadedContracts: async () => [await getStandardMultiCallEntrypoint(), await getStandardAuthRegistry()],
51
+ },
46
52
  loggers: {
47
53
  store: rootLogger.createChild('pxe:data'),
48
54
  pxe: rootLogger.createChild('pxe:service'),
@@ -62,14 +68,16 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
62
68
  {
63
69
  dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
64
70
  dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
65
- l1Contracts,
71
+ rollupAddress: l1Contracts.rollupAddress,
66
72
  },
67
73
  1,
68
74
  rootLogger.createChild('wallet:data'),
69
75
  ));
70
- const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
76
+ const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
71
77
 
72
- return new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
78
+ const wallet = new this(pxe, aztecNode, walletDB, new LazyAccountContractsProvider(), rootLogger) as T;
79
+ await wallet.initStubClasses();
80
+ return wallet;
73
81
  }
74
82
  }
75
83
 
@@ -77,3 +85,10 @@ export { BrowserEmbeddedWallet as EmbeddedWallet };
77
85
  export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
78
86
  export { WalletDB } from '../wallet_db.js';
79
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.