@aztec/wallets 5.0.0-private.20260319 → 5.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dest/embedded/account-contract-providers/bundle.d.ts +6 -8
  2. package/dest/embedded/account-contract-providers/bundle.d.ts.map +1 -1
  3. package/dest/embedded/account-contract-providers/bundle.js +10 -10
  4. package/dest/embedded/account-contract-providers/lazy.d.ts +6 -8
  5. package/dest/embedded/account-contract-providers/lazy.d.ts.map +1 -1
  6. package/dest/embedded/account-contract-providers/lazy.js +20 -10
  7. package/dest/embedded/account-contract-providers/types.d.ts +6 -8
  8. package/dest/embedded/account-contract-providers/types.d.ts.map +1 -1
  9. package/dest/embedded/embedded_wallet.d.ts +54 -8
  10. package/dest/embedded/embedded_wallet.d.ts.map +1 -1
  11. package/dest/embedded/embedded_wallet.js +201 -65
  12. package/dest/embedded/entrypoints/browser.d.ts +2 -2
  13. package/dest/embedded/entrypoints/browser.d.ts.map +1 -1
  14. package/dest/embedded/entrypoints/browser.js +39 -10
  15. package/dest/embedded/entrypoints/node.d.ts +2 -2
  16. package/dest/embedded/entrypoints/node.d.ts.map +1 -1
  17. package/dest/embedded/entrypoints/node.js +33 -10
  18. package/dest/embedded/store_encryption.d.ts +67 -0
  19. package/dest/embedded/store_encryption.d.ts.map +1 -0
  20. package/dest/embedded/store_encryption.js +71 -0
  21. package/dest/embedded/wallet_db.d.ts +7 -6
  22. package/dest/embedded/wallet_db.d.ts.map +1 -1
  23. package/dest/embedded/wallet_db.js +10 -9
  24. package/dest/testing.d.ts +8 -4
  25. package/dest/testing.d.ts.map +1 -1
  26. package/dest/testing.js +8 -14
  27. package/package.json +12 -10
  28. package/src/embedded/account-contract-providers/bundle.ts +13 -12
  29. package/src/embedded/account-contract-providers/lazy.ts +23 -12
  30. package/src/embedded/account-contract-providers/types.ts +6 -4
  31. package/src/embedded/embedded_wallet.ts +266 -72
  32. package/src/embedded/entrypoints/browser.ts +47 -20
  33. package/src/embedded/entrypoints/node.ts +46 -26
  34. package/src/embedded/store_encryption.ts +107 -0
  35. package/src/embedded/wallet_db.ts +13 -10
  36. package/src/testing.ts +11 -16
@@ -3,11 +3,14 @@ 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 { getStandardHandshakeRegistry } from '@aztec/standard-contracts/handshake-registry';
8
+ import { getStandardMultiCallEntrypoint } from '@aztec/standard-contracts/multi-call-entrypoint';
6
9
  import type { AztecNode } from '@aztec/stdlib/interfaces/client';
7
10
 
8
11
  import { BundleAccountContractsProvider } from '../account-contract-providers/bundle.js';
9
12
  import type { AccountContractsProvider } from '../account-contract-providers/types.js';
10
- import { EmbeddedWallet, type EmbeddedWalletOptions } from '../embedded_wallet.js';
13
+ import { EmbeddedWallet, type EmbeddedWalletOptions, splitPxeOptions } from '../embedded_wallet.js';
11
14
  import { WalletDB } from '../wallet_db.js';
12
15
 
13
16
  export class NodeEmbeddedWallet extends EmbeddedWallet {
@@ -27,10 +30,16 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
27
30
  const aztecNode = typeof nodeOrUrl === 'string' ? createAztecNodeClient(nodeOrUrl) : nodeOrUrl;
28
31
  const l1Contracts = await aztecNode.getL1ContractAddresses();
29
32
 
33
+ // Support both the new unified `pxe` option and the deprecated `pxeConfig`/`pxeOptions`.
34
+ const { config: pxeConfigFromPxe, creation: pxeCreationFromPxe } = splitPxeOptions(options.pxe);
35
+ const mergedConfigOverrides = { ...options.pxeConfig, ...pxeConfigFromPxe };
36
+ const mergedCreationOverrides: PXECreationOptions = { ...options.pxeOptions, ...pxeCreationFromPxe };
37
+
30
38
  const pxeConfig: PXEConfig = Object.assign(getPXEConfig(), {
31
- proverEnabled: options.pxeConfig?.proverEnabled ?? false,
39
+ proverEnabled: mergedConfigOverrides.proverEnabled ?? false,
32
40
  dataDirectory: `pxe_data_${l1Contracts.rollupAddress}`,
33
- ...options.pxeConfig,
41
+ autoSync: false,
42
+ ...mergedConfigOverrides,
34
43
  });
35
44
 
36
45
  if (options.ephemeral) {
@@ -38,42 +47,53 @@ export class NodeEmbeddedWallet extends EmbeddedWallet {
38
47
  }
39
48
 
40
49
  const pxeOptions: PXECreationOptions = {
41
- ...options.pxeOptions,
50
+ ...mergedCreationOverrides,
51
+ preloadedContractsProvider: mergedCreationOverrides.preloadedContractsProvider ?? {
52
+ getPreloadedContracts: async () => [
53
+ await getStandardMultiCallEntrypoint(),
54
+ await getStandardAuthRegistry(),
55
+ await getStandardHandshakeRegistry(),
56
+ ],
57
+ },
42
58
  loggers: {
43
59
  store: rootLogger.createChild('pxe:data'),
44
60
  pxe: rootLogger.createChild('pxe:service'),
45
61
  prover: rootLogger.createChild('pxe:prover'),
46
- ...options.pxeOptions?.loggers,
62
+ ...mergedCreationOverrides.loggers,
47
63
  },
48
64
  };
49
65
 
50
66
  const pxe = await createPXE(aztecNode, pxeConfig, pxeOptions);
51
67
 
52
- const walletDBStore = options.ephemeral
53
- ? await openTmpStore(
54
- `wallet_data_${l1Contracts.rollupAddress}`,
55
- true,
56
- undefined,
57
- undefined,
58
- rootLogger.createChild('wallet:data').getBindings(),
59
- )
60
- : await createStore(
61
- 'wallet_data',
62
- 1,
63
- {
64
- dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
65
- dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
66
- l1Contracts,
67
- },
68
- rootLogger.createChild('wallet:data').getBindings(),
69
- );
70
- const walletDB = WalletDB.init(walletDBStore, rootLogger.createChild('wallet:db').info);
68
+ const walletDBStore =
69
+ options.walletDb?.store ??
70
+ (options.ephemeral
71
+ ? await openTmpStore(
72
+ `wallet_data_${l1Contracts.rollupAddress}`,
73
+ true,
74
+ undefined,
75
+ undefined,
76
+ rootLogger.createChild('wallet:data').getBindings(),
77
+ )
78
+ : await createStore(
79
+ 'wallet_data',
80
+ 1,
81
+ {
82
+ dataDirectory: `wallet_data_${l1Contracts.rollupAddress}`,
83
+ dataStoreMapSizeKb: pxeConfig.dataStoreMapSizeKb,
84
+ rollupAddress: l1Contracts.rollupAddress,
85
+ },
86
+ rootLogger.createChild('wallet:data').getBindings(),
87
+ ));
88
+ const walletDB = new WalletDB(walletDBStore, rootLogger.createChild('wallet:db').info);
71
89
 
72
- return new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger) as T;
90
+ const wallet = new this(pxe, aztecNode, walletDB, new BundleAccountContractsProvider(), rootLogger) as T;
91
+ await wallet.initStubClasses();
92
+ return wallet;
73
93
  }
74
94
  }
75
95
 
76
96
  export { NodeEmbeddedWallet as EmbeddedWallet };
77
- export type { EmbeddedWalletOptions } from '../embedded_wallet.js';
97
+ export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
78
98
  export { WalletDB } from '../wallet_db.js';
79
99
  export type { AccountType } from '../wallet_db.js';
@@ -0,0 +1,107 @@
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
+
13
+ /** Which of the embedded wallet's two stores failed to open. */
14
+ export type EmbeddedStoreName = 'pxe' | 'wallet';
15
+
16
+ /**
17
+ * Thrown by {@link openEncryptedEmbeddedStores} when one of the two stores cannot be decrypted with the supplied
18
+ * key. The original {@link SqliteEncryptionError} is preserved as `cause`.
19
+ */
20
+ export class EmbeddedWalletEncryptionError extends Error {
21
+ readonly storeName: EmbeddedStoreName;
22
+
23
+ constructor(storeName: EmbeddedStoreName, opts: { cause: SqliteEncryptionError }) {
24
+ super(`Embedded wallet '${storeName}' store could not be decrypted with the provided key`, { cause: opts.cause });
25
+ this.name = 'EmbeddedWalletEncryptionError';
26
+ this.storeName = storeName;
27
+ }
28
+ }
29
+
30
+ /** Configuration for {@link openEncryptedEmbeddedStores}. */
31
+ export interface OpenEncryptedEmbeddedStoresOptions {
32
+ pxe: { name: string; poolDirectory?: string };
33
+ wallet: { name: string; poolDirectory?: string };
34
+ }
35
+
36
+ /**
37
+ * Internal seam for tests to inject a fake store opener. Defaults to `AztecSQLiteOPFSStore.open`. Not part of the
38
+ * public API.
39
+ *
40
+ * @internal
41
+ */
42
+ export type OpenSqliteEncryptedStoreFn = (
43
+ log: Logger,
44
+ name: string,
45
+ poolDirectory: string | undefined,
46
+ encryptionKey: Uint8Array,
47
+ ) => Promise<AztecSQLiteOPFSStore>;
48
+
49
+ const defaultOpenStore: OpenSqliteEncryptedStoreFn = (log, name, poolDirectory, encryptionKey) =>
50
+ AztecSQLiteOPFSStore.open(log, name, false, poolDirectory, encryptionKey);
51
+
52
+ /**
53
+ * Opens the PXE and wallet stores in sequence, both encrypted with keys obtained from `getEncryptionKey`.
54
+ *
55
+ * The callback is invoked once per store (twice total per call) because `AztecSQLiteOPFSStore.open` *transfers*
56
+ * the key buffer to its worker. A single buffer would detach between the two opens.
57
+ *
58
+ * Failure modes:
59
+ *
60
+ * - PXE store fails to decrypt → throws `EmbeddedWalletEncryptionError({ storeName: 'pxe', cause })`. No cleanup
61
+ * needed (nothing was opened).
62
+ * - Wallet store fails to decrypt → closes the already-opened PXE store then throws
63
+ * `EmbeddedWalletEncryptionError({ storeName: 'wallet', cause })`.
64
+ * - Any non-decrypt error during the wallet open → still closes PXE, then re-throws the original error unwrapped
65
+ * (preserves callers' existing untyped error handling for non-encryption faults).
66
+ *
67
+ * @param config - Per-store name/poolDirectory.
68
+ * @param getEncryptionKey - Returns a fresh 32-byte key per call (the buffer
69
+ * detaches on transfer, so each call must allocate).
70
+ * @param log - Logger for both stores.
71
+ * @param openStore - Internal test seam. Do not pass in production code.
72
+ */
73
+ export async function openEncryptedEmbeddedStores(
74
+ config: OpenEncryptedEmbeddedStoresOptions,
75
+ getEncryptionKey: () => Promise<Uint8Array>,
76
+ log: Logger,
77
+ openStore: OpenSqliteEncryptedStoreFn = defaultOpenStore,
78
+ ): Promise<{ pxeStore: AztecSQLiteOPFSStore; walletStore: AztecSQLiteOPFSStore }> {
79
+ const pxeStore = await openOneStore('pxe', config.pxe, getEncryptionKey, log, openStore);
80
+ try {
81
+ const walletStore = await openOneStore('wallet', config.wallet, getEncryptionKey, log, openStore);
82
+ return { pxeStore, walletStore };
83
+ } catch (err) {
84
+ // Cleanup is best-effort — if close() itself throws (e.g. worker already dead), swallow it so the original error
85
+ // surfaces unobstructed.
86
+ await pxeStore.close().catch(() => {});
87
+ throw err;
88
+ }
89
+ }
90
+
91
+ async function openOneStore(
92
+ storeName: EmbeddedStoreName,
93
+ { name, poolDirectory }: { name: string; poolDirectory?: string },
94
+ getEncryptionKey: () => Promise<Uint8Array>,
95
+ log: Logger,
96
+ openStore: OpenSqliteEncryptedStoreFn,
97
+ ): Promise<AztecSQLiteOPFSStore> {
98
+ const key = await getEncryptionKey();
99
+ try {
100
+ return await openStore(log, name, poolDirectory, key);
101
+ } catch (err) {
102
+ if (err instanceof SqliteEncryptionError && err.code === 'decrypt_failed') {
103
+ throw new EmbeddedWalletEncryptionError(storeName, { cause: err });
104
+ }
105
+ throw err;
106
+ }
107
+ }
@@ -4,7 +4,7 @@ import type { LogFn } from '@aztec/foundation/log';
4
4
  import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
5
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
6
 
7
- export const AccountTypes = ['schnorr', 'ecdsasecp256r1', 'ecdsasecp256k1'] as const;
7
+ export const AccountTypes = ['schnorr', 'schnorr_initializerless', 'ecdsasecp256r1', 'ecdsasecp256k1'] as const;
8
8
  export type AccountType = (typeof AccountTypes)[number];
9
9
 
10
10
  function accountKey(field: string, address: AztecAddress | string): string {
@@ -12,16 +12,15 @@ function accountKey(field: string, address: AztecAddress | string): string {
12
12
  }
13
13
 
14
14
  export class WalletDB {
15
- private constructor(
16
- private accounts: AztecAsyncMap<string, Buffer>,
17
- private aliases: AztecAsyncMap<string, Buffer>,
18
- private userLog: LogFn,
19
- ) {}
15
+ private accounts: AztecAsyncMap<string, Buffer>;
16
+ private aliases: AztecAsyncMap<string, Buffer>;
20
17
 
21
- static init(store: AztecAsyncKVStore, userLog: LogFn) {
22
- const accounts = store.openMap<string, Buffer>('accounts');
23
- const aliases = store.openMap<string, Buffer>('aliases');
24
- return new WalletDB(accounts, aliases, userLog);
18
+ constructor(
19
+ private store: AztecAsyncKVStore,
20
+ private userLog: LogFn,
21
+ ) {
22
+ this.accounts = store.openMap<string, Buffer>('accounts');
23
+ this.aliases = store.openMap<string, Buffer>('aliases');
25
24
  }
26
25
 
27
26
  async storeAccount(
@@ -131,4 +130,8 @@ export class WalletDB {
131
130
  await this.aliases.delete(`accounts:${alias}`);
132
131
  }
133
132
  }
133
+
134
+ async close() {
135
+ await this.store.close();
136
+ }
134
137
  }
package/src/testing.ts CHANGED
@@ -1,31 +1,25 @@
1
1
  import type { InitialAccountData } from '@aztec/accounts/testing';
2
2
  import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
3
- import type { WaitOpts } from '@aztec/aztec.js/contracts';
4
3
  import type { AccountManager } from '@aztec/aztec.js/wallet';
5
4
  import type { Fq, Fr } from '@aztec/foundation/curves/bn254';
6
5
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
7
6
 
8
7
  interface WalletWithSchnorrAccounts {
9
- createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq, alias?: string): Promise<AccountManager>;
8
+ createSchnorrInitializerlessAccount(secret: Fr, salt: Fr, signingKey?: Fq, alias?: string): Promise<AccountManager>;
10
9
  }
11
10
 
12
- export async function deployFundedSchnorrAccounts(
11
+ /**
12
+ * Creates the given (genesis-funded) test accounts as initializerless schnorr accounts. Initializerless
13
+ * accounts need no deployment tx — creating one registers the instance and materializes its immutable keys
14
+ * locally — so the accounts are usable as soon as they are created, funded via genesis at their addresses.
15
+ */
16
+ export async function createFundedInitializerlessAccounts(
13
17
  wallet: WalletWithSchnorrAccounts,
14
18
  accountsData: InitialAccountData[],
15
- waitOptions?: WaitOpts,
16
19
  ) {
17
20
  const accountManagers = [];
18
- // Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
19
- for (let i = 0; i < accountsData.length; i++) {
20
- const { secret, salt, signingKey } = accountsData[i];
21
- const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
22
- const deployMethod = await accountManager.getDeployMethod();
23
- await deployMethod.send({
24
- from: AztecAddress.ZERO,
25
- skipClassPublication: i !== 0,
26
- wait: waitOptions,
27
- });
28
- accountManagers.push(accountManager);
21
+ for (const { secret, salt, signingKey } of accountsData) {
22
+ accountManagers.push(await wallet.createSchnorrInitializerlessAccount(secret, salt, signingKey));
29
23
  }
30
24
  return accountManagers;
31
25
  }
@@ -36,7 +30,8 @@ export async function registerInitialLocalNetworkAccountsInWallet(
36
30
  const testAccounts = await getInitialTestAccountsData();
37
31
  return Promise.all(
38
32
  testAccounts.map(async account => {
39
- return (await wallet.createSchnorrAccount(account.secret, account.salt, account.signingKey)).address;
33
+ return (await wallet.createSchnorrInitializerlessAccount(account.secret, account.salt, account.signingKey))
34
+ .address;
40
35
  }),
41
36
  );
42
37
  }