@aztec/wallets 4.3.0-nightly.20260513 → 4.3.0-nightly.20260514

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.
@@ -50,3 +50,9 @@ export class BrowserEmbeddedWallet extends EmbeddedWallet {
50
50
  }
51
51
  export { BrowserEmbeddedWallet as EmbeddedWallet };
52
52
  export { WalletDB } from '../wallet_db.js';
53
+ // At-rest encryption helpers are intentionally NOT re-exported here. They live
54
+ // on the `@aztec/wallets/embedded/store-encryption` sub-path so consumers
55
+ // (and bundlers) of this entrypoint don't transitively pull in
56
+ // `@aztec/kv-store/sqlite-opfs` and its `new Worker(new URL('./worker.js'))`
57
+ // chain into `@aztec/sqlite3mc-wasm`. Apps that don't use encryption-at-rest
58
+ // (e.g. the playground) should never see sqlite-opfs in their bundle.
@@ -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
+ //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QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD;AAED;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG,CACvC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,aAAa,EAAE,UAAU,KACtB,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAKnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,kCAAkC,EAC1C,gBAAgB,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,EAC3C,GAAG,EAAE,MAAM,EACX,SAAS,GAAE,0BAA6C,GACvD,OAAO,CAAC;IAAE,QAAQ,EAAE,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
+ }
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": "4.3.0-nightly.20260513",
4
+ "version": "4.3.0-nightly.20260514",
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,15 @@
27
28
  "../package.common.json"
28
29
  ],
29
30
  "dependencies": {
30
- "@aztec/accounts": "4.3.0-nightly.20260513",
31
- "@aztec/aztec.js": "4.3.0-nightly.20260513",
32
- "@aztec/entrypoints": "4.3.0-nightly.20260513",
33
- "@aztec/foundation": "4.3.0-nightly.20260513",
34
- "@aztec/kv-store": "4.3.0-nightly.20260513",
35
- "@aztec/protocol-contracts": "4.3.0-nightly.20260513",
36
- "@aztec/pxe": "4.3.0-nightly.20260513",
37
- "@aztec/stdlib": "4.3.0-nightly.20260513",
38
- "@aztec/wallet-sdk": "4.3.0-nightly.20260513"
31
+ "@aztec/accounts": "4.3.0-nightly.20260514",
32
+ "@aztec/aztec.js": "4.3.0-nightly.20260514",
33
+ "@aztec/entrypoints": "4.3.0-nightly.20260514",
34
+ "@aztec/foundation": "4.3.0-nightly.20260514",
35
+ "@aztec/kv-store": "4.3.0-nightly.20260514",
36
+ "@aztec/protocol-contracts": "4.3.0-nightly.20260514",
37
+ "@aztec/pxe": "4.3.0-nightly.20260514",
38
+ "@aztec/stdlib": "4.3.0-nightly.20260514",
39
+ "@aztec/wallet-sdk": "4.3.0-nightly.20260514"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@jest/globals": "^30.0.0",
@@ -77,3 +77,10 @@ export { BrowserEmbeddedWallet as EmbeddedWallet };
77
77
  export type { EmbeddedWalletOptions, EmbeddedWalletPXEOptions } from '../embedded_wallet.js';
78
78
  export { WalletDB } from '../wallet_db.js';
79
79
  export type { AccountType } from '../wallet_db.js';
80
+
81
+ // At-rest encryption helpers are intentionally NOT re-exported here. They live
82
+ // on the `@aztec/wallets/embedded/store-encryption` sub-path so consumers
83
+ // (and bundlers) of this entrypoint don't transitively pull in
84
+ // `@aztec/kv-store/sqlite-opfs` and its `new Worker(new URL('./worker.js'))`
85
+ // chain into `@aztec/sqlite3mc-wasm`. Apps that don't use encryption-at-rest
86
+ // (e.g. the playground) should never see sqlite-opfs in their bundle.
@@ -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
+ }