@aztec/wallets 0.0.1-commit.fff30aa → 0.0.1-private.5d121bfd

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 +29 -3
  10. package/dest/embedded/embedded_wallet.d.ts.map +1 -1
  11. package/dest/embedded/embedded_wallet.js +75 -25
  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 +22 -5
  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 +16 -5
  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 +17 -15
  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 +114 -18
  29. package/src/embedded/entrypoints/browser.ts +31 -14
  30. package/src/embedded/entrypoints/node.ts +30 -20
  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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmVfZW5jcnlwdGlvbi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2VtYmVkZGVkL3N0b3JlX2VuY3J5cHRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7O0dBUUc7QUFDSCxPQUFPLEtBQUssRUFBRSxNQUFNLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUNwRCxPQUFPLEVBQUUsb0JBQW9CLEVBQUUscUJBQXFCLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUUxRixnRUFBZ0U7QUFDaEUsTUFBTSxNQUFNLGlCQ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AoB,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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X2RiLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZW1iZWRkZWQvd2FsbGV0X2RiLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ3RELE9BQU8sRUFBRSxFQUFFLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDeEQsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDbkQsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQWlCLE1BQU0saUJBQWlCLENBQUM7QUFDeEUsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBRTNELGVBQU8sTUFBTSxZQUFZLDBEQUEyRCxDQUFDO0FBQ3JGLE1BQU0sTUFBTSxXQUFXLEdBQUcsQ0FBQyxPQUFPLFlBQVksQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBTXhELHFCQUFhLFFBQVE7O0lBRWpCLE9BQU8sQ0FBQyxRQUFRO0lBQ2hCLE9BQU8sQ0FBQyxPQUFPO0lBQ2YsT0FBTyxDQUFDLE9BQU87SUFIakIsT0FBTyxlQUlIO0lBRUosTUFBTSxDQUFDLElBQUksQ0FBQyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsT0FBTyxFQUFFLEtBQUssWUFJbkQ7SUFFSyxZQUFZLENBQ2hCLE9BQU8sRUFBRSxZQUFZLEVBQ3JCLEVBQ0UsSUFBS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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.fff30aa",
4
+ "version": "0.0.1-private.5d121bfd",
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.fff30aa",
31
- "@aztec/aztec.js": "0.0.1-commit.fff30aa",
32
- "@aztec/entrypoints": "0.0.1-commit.fff30aa",
33
- "@aztec/foundation": "0.0.1-commit.fff30aa",
34
- "@aztec/kv-store": "0.0.1-commit.fff30aa",
35
- "@aztec/protocol-contracts": "0.0.1-commit.fff30aa",
36
- "@aztec/pxe": "0.0.1-commit.fff30aa",
37
- "@aztec/stdlib": "0.0.1-commit.fff30aa",
38
- "@aztec/wallet-sdk": "0.0.1-commit.fff30aa"
31
+ "@aztec/accounts": "0.0.1-private.5d121bfd",
32
+ "@aztec/aztec.js": "0.0.1-private.5d121bfd",
33
+ "@aztec/entrypoints": "0.0.1-private.5d121bfd",
34
+ "@aztec/foundation": "0.0.1-private.5d121bfd",
35
+ "@aztec/kv-store": "0.0.1-private.5d121bfd",
36
+ "@aztec/protocol-contracts": "0.0.1-private.5d121bfd",
37
+ "@aztec/pxe": "0.0.1-private.5d121bfd",
38
+ "@aztec/standard-contracts": "0.0.1-private.5d121bfd",
39
+ "@aztec/stdlib": "0.0.1-private.5d121bfd",
40
+ "@aztec/wallet-sdk": "0.0.1-private.5d121bfd"
39
41
  },
40
42
  "devDependencies": {
41
43
  "@jest/globals": "^30.0.0",
@@ -44,11 +46,6 @@
44
46
  "ts-node": "^10.9.1",
45
47
  "typescript": "^5.3.3"
46
48
  },
47
- "files": [
48
- "dest",
49
- "src",
50
- "!*.test.*"
51
- ],
52
49
  "typedocOptions": {
53
50
  "entryPoints": [
54
51
  "./src/embedded/entrypoints/browser.ts",
@@ -58,6 +55,11 @@
58
55
  "name": "Wallets",
59
56
  "tsconfig": "./tsconfig.json"
60
57
  },
58
+ "files": [
59
+ "dest",
60
+ "src",
61
+ "!*.test.*"
62
+ ],
61
63
  "engines": {
62
64
  "node": ">=20.10"
63
65
  },
@@ -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,16 +1,26 @@
1
1
  import { type Account, NO_FROM } from '@aztec/aztec.js/account';
2
2
  import { CallAuthorizationRequest } from '@aztec/aztec.js/authorization';
3
3
  import { type InteractionWaitOptions, type SendReturn, type WaitOpts, getGasLimits } from '@aztec/aztec.js/contracts';
4
- import type { Aliased, SendOptions } from '@aztec/aztec.js/wallet';
4
+ import type {
5
+ Aliased,
6
+ ExecuteUtilityOptions,
7
+ PrivateEvent,
8
+ PrivateEventFilter,
9
+ ProfileOptions,
10
+ SendOptions,
11
+ SimulateOptions,
12
+ } from '@aztec/aztec.js/wallet';
5
13
  import { AccountManager, TxSimulationResultWithAppOffset } from '@aztec/aztec.js/wallet';
6
14
  import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
7
15
  import { DefaultEntrypoint } from '@aztec/entrypoints/default';
8
16
  import { Fq, Fr } from '@aztec/foundation/curves/bn254';
9
17
  import type { Logger } from '@aztec/foundation/log';
18
+ import type { AztecAsyncKVStore } from '@aztec/kv-store';
10
19
  import type { PXEConfig, PXECreationOptions } from '@aztec/pxe/client/lazy';
11
20
  import type { PXE } from '@aztec/pxe/server';
21
+ import type { ContractArtifact, EventMetadataDefinition, FunctionCall } from '@aztec/stdlib/abi';
12
22
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
- import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
23
+ import { type ContractInstanceWithAddress, getContractClassFromArtifact } from '@aztec/stdlib/contract';
14
24
  import { GasSettings } from '@aztec/stdlib/gas';
15
25
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
16
26
  import { deriveSigningKey } from '@aztec/stdlib/keys';
@@ -19,7 +29,9 @@ import {
19
29
  ExecutionPayload,
20
30
  SimulationOverrides,
21
31
  type TxExecutionRequest,
32
+ type TxProfileResult,
22
33
  TxStatus,
34
+ type UtilityExecutionResult,
23
35
  collectOffchainEffects,
24
36
  mergeExecutionPayloads,
25
37
  } from '@aztec/stdlib/tx';
@@ -39,10 +51,20 @@ export function splitPxeOptions(pxe?: EmbeddedWalletPXEOptions): {
39
51
  if (!pxe) {
40
52
  return { config: {}, creation: {} };
41
53
  }
42
- const { loggers, loggerActorLabel, proverOrOptions, store, simulator, ...config } = pxe;
43
- return { config, creation: { loggers, loggerActorLabel, proverOrOptions, store, simulator } };
54
+ const { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider, ...config } =
55
+ pxe;
56
+ return {
57
+ config,
58
+ creation: { loggers, loggerActorLabel, proverOrOptions, store, simulator, hooks, preloadedContractsProvider },
59
+ };
44
60
  }
45
61
 
62
+ /** Options for the EmbeddedWallet's own DB (accounts, senders — distinct from PXE state). */
63
+ export type EmbeddedWalletDBOptions = {
64
+ /** Override the wallet DB backend. If omitted, an IndexedDB (browser) / LMDB (node) store is created. */
65
+ store?: AztecAsyncKVStore;
66
+ };
67
+
46
68
  export type EmbeddedWalletOptions = {
47
69
  /** Parent logger. Child loggers are derived via createChild() for each subsystem. */
48
70
  logger?: Logger;
@@ -50,6 +72,8 @@ export type EmbeddedWalletOptions = {
50
72
  ephemeral?: boolean;
51
73
  /** PXE configuration and dependency overrides (custom store, prover, simulator). */
52
74
  pxe?: EmbeddedWalletPXEOptions;
75
+ /** Wallet DB dependency overrides (custom store). */
76
+ walletDb?: EmbeddedWalletDBOptions;
53
77
  /**
54
78
  * Override PXE configuration.
55
79
  * @deprecated Use `pxe` instead.
@@ -67,6 +91,10 @@ const DEFAULT_ESTIMATED_GAS_PADDING = 0.1;
67
91
  export class EmbeddedWallet extends BaseWallet {
68
92
  protected estimatedGasPadding = DEFAULT_ESTIMATED_GAS_PADDING;
69
93
 
94
+ // Stub class ids, populated on wallet startup
95
+ // to avoid redundant work per simulation
96
+ protected stubClassIds = new Map<AccountType, Fr>();
97
+
70
98
  constructor(
71
99
  pxe: PXE,
72
100
  aztecNode: AztecNode,
@@ -118,6 +146,9 @@ export class EmbeddedWallet extends BaseWallet {
118
146
  executionPayload: ExecutionPayload,
119
147
  opts: SendOptions<W>,
120
148
  ): Promise<SendReturn<W>> {
149
+ // PXE has autoSync disabled by the embedded wallet entrypoints, so we sync once here to cover
150
+ // both the inner simulateTx (via simulateViaEntrypoint) and the proveTx that super.sendTx
151
+ await this.pxe.sync();
121
152
  const feeOptions = await this.completeFeeOptions({
122
153
  from: opts.from,
123
154
  feePayer: executionPayload.feePayer,
@@ -132,6 +163,7 @@ export class EmbeddedWallet extends BaseWallet {
132
163
  feeOptions,
133
164
  additionalScopes: opts.additionalScopes,
134
165
  skipTxValidation: true,
166
+ sendMessagesAs: opts.sendMessagesAs,
135
167
  });
136
168
 
137
169
  const offchainEffects = collectOffchainEffects(simulationResult.privateExecutionResult);
@@ -182,6 +214,70 @@ export class EmbeddedWallet extends BaseWallet {
182
214
  });
183
215
  }
184
216
 
217
+ /**
218
+ * Overrides the base simulateTx to drive PXE syncing explicitly. The PXE created by the embedded
219
+ * wallet has autoSync disabled (so we can share one sync across simulate+send in sendTx); for
220
+ * standalone simulations we still need a fresh anchor block, which we provide here.
221
+ */
222
+ public override async simulateTx(
223
+ executionPayload: ExecutionPayload,
224
+ opts: SimulateOptions,
225
+ ): Promise<TxSimulationResultWithAppOffset> {
226
+ await this.pxe.sync();
227
+ return super.simulateTx(executionPayload, opts);
228
+ }
229
+
230
+ public override async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
231
+ await this.pxe.sync();
232
+ return super.profileTx(executionPayload, opts);
233
+ }
234
+
235
+ public override async executeUtility(
236
+ call: FunctionCall,
237
+ opts: ExecuteUtilityOptions,
238
+ ): Promise<UtilityExecutionResult> {
239
+ await this.pxe.sync();
240
+ return super.executeUtility(call, opts);
241
+ }
242
+
243
+ public override async getPrivateEvents<T>(
244
+ eventDef: EventMetadataDefinition,
245
+ eventFilter: PrivateEventFilter,
246
+ ): Promise<PrivateEvent<T>[]> {
247
+ await this.pxe.sync();
248
+ return super.getPrivateEvents<T>(eventDef, eventFilter);
249
+ }
250
+
251
+ public override async registerContract(
252
+ instance: ContractInstanceWithAddress,
253
+ artifact?: ContractArtifact,
254
+ secretKey?: Fr,
255
+ ): Promise<ContractInstanceWithAddress> {
256
+ // registerContract may call pxe.updateContract under the hood, which depends on a fresh anchor
257
+ // block to verify the current class id from the node.
258
+ await this.pxe.sync();
259
+ return super.registerContract(instance, artifact, secretKey);
260
+ }
261
+
262
+ /**
263
+ * Hashes and registers the stub class for every supported account type with PXE, populating
264
+ * stubClassIds. Called on wallet initialization.
265
+ */
266
+ async initStubClasses(): Promise<void> {
267
+ const schnorrArtifact = await this.accountContracts.getStubAccountContractArtifact('schnorr');
268
+ const { id: schnorrClassId } = await getContractClassFromArtifact(schnorrArtifact);
269
+ await this.pxe.registerContractClass(schnorrArtifact);
270
+
271
+ // ecdsa stubs share the same class id
272
+ const ecdsaArtifact = await this.accountContracts.getStubAccountContractArtifact('ecdsasecp256r1');
273
+ const { id: ecdsaClassId } = await getContractClassFromArtifact(ecdsaArtifact);
274
+ await this.pxe.registerContractClass(ecdsaArtifact);
275
+
276
+ this.stubClassIds.set('schnorr', schnorrClassId);
277
+ this.stubClassIds.set('ecdsasecp256k1', ecdsaClassId);
278
+ this.stubClassIds.set('ecdsasecp256r1', ecdsaClassId);
279
+ }
280
+
185
281
  /**
186
282
  * Builds contract overrides for all provided addresses by replacing their account contracts with stub implementations.
187
283
  * Uses a type-specific stub artifact so that the stub's constructor selector matches the real account's constructor.
@@ -195,7 +291,12 @@ export class EmbeddedWallet extends BaseWallet {
195
291
  for (const account of filtered) {
196
292
  const address = account.item;
197
293
  const { type } = await this.walletDB.retrieveAccount(address);
198
- const stubArtifact = await this.accountContracts.getStubAccountContractArtifact(type);
294
+ const stubClassId = this.stubClassIds.get(type);
295
+ if (!stubClassId) {
296
+ throw new Error(
297
+ `Stub class for account type '${type}' was not registered at wallet init. This is a bug — initStubClasses should cover every supported AccountType.`,
298
+ );
299
+ }
199
300
 
200
301
  const originalAccount = await this.getAccountFromAddress(address);
201
302
  const completeAddress = originalAccount.getCompleteAddress();
@@ -206,15 +307,8 @@ export class EmbeddedWallet extends BaseWallet {
206
307
  );
207
308
  }
208
309
 
209
- const stubConstructorArgs = type === 'schnorr' ? [Fr.ZERO, Fr.ZERO] : [Buffer.alloc(32), Buffer.alloc(32)];
210
- const stubInstance = await getContractInstanceFromInstantiationParams(stubArtifact, {
211
- salt: Fr.random(),
212
- constructorArgs: stubConstructorArgs,
213
- });
214
-
215
310
  contracts[address.toString()] = {
216
- instance: stubInstance,
217
- artifact: stubArtifact,
311
+ instance: { ...contractInstance, currentContractClassId: stubClassId },
218
312
  };
219
313
  }
220
314
 
@@ -230,7 +324,7 @@ export class EmbeddedWallet extends BaseWallet {
230
324
  executionPayload: ExecutionPayload,
231
325
  opts: SimulateViaEntrypointOptions,
232
326
  ): Promise<TxSimulationResultWithAppOffset> {
233
- const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement } = opts;
327
+ const { from, feeOptions, additionalScopes, skipTxValidation, skipFeeEnforcement, sendMessagesAs } = opts;
234
328
  const scopes = this.scopesFrom(from, additionalScopes);
235
329
 
236
330
  const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
@@ -240,7 +334,7 @@ export class EmbeddedWallet extends BaseWallet {
240
334
  const chainInfo = await this.getChainInfo();
241
335
 
242
336
  const accountOverrides = await this.buildAccountOverrides(scopes);
243
- const overrides = new SimulationOverrides(accountOverrides);
337
+ const overrides = new SimulationOverrides({ contracts: accountOverrides });
244
338
 
245
339
  let txRequest: TxExecutionRequest;
246
340
  if (from === NO_FROM) {
@@ -271,6 +365,7 @@ export class EmbeddedWallet extends BaseWallet {
271
365
  skipTxValidation,
272
366
  overrides,
273
367
  scopes,
368
+ senderForTags: this.senderForTagsFrom(from, sendMessagesAs),
274
369
  });
275
370
  const appCallOffset = await this.computeAppCallOffset(from, feeOptions);
276
371
  return TxSimulationResultWithAppOffset.fromResultAndOffset(result, appCallOffset);
@@ -301,7 +396,7 @@ export class EmbeddedWallet extends BaseWallet {
301
396
  }
302
397
  }
303
398
 
304
- const accountManager = await AccountManager.create(this, secret, contract, salt);
399
+ const accountManager = await AccountManager.create(this, secret, contract, { salt });
305
400
 
306
401
  const instance = accountManager.getInstance();
307
402
  const existingInstance = await this.pxe.getContractInstance(instance.address);
@@ -349,7 +444,8 @@ export class EmbeddedWallet extends BaseWallet {
349
444
  this.estimatedGasPadding = value ?? DEFAULT_ESTIMATED_GAS_PADDING;
350
445
  }
351
446
 
352
- stop() {
353
- return this.pxe.stop();
447
+ async stop(): Promise<void> {
448
+ await this.pxe.stop();
449
+ await this.walletDB.close();
354
450
  }
355
451
  }