@aztec/kv-store 0.0.1-commit.86469d5 → 0.0.1-commit.8655d4a

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 (112) hide show
  1. package/dest/bench/shared_map_bench.d.ts +19 -0
  2. package/dest/bench/shared_map_bench.d.ts.map +1 -0
  3. package/dest/bench/shared_map_bench.js +91 -0
  4. package/dest/indexeddb/index.d.ts +2 -2
  5. package/dest/indexeddb/index.d.ts.map +1 -1
  6. package/dest/indexeddb/index.js +1 -1
  7. package/dest/indexeddb/map.d.ts +7 -1
  8. package/dest/indexeddb/map.d.ts.map +1 -1
  9. package/dest/indexeddb/map.js +12 -2
  10. package/dest/indexeddb/multi_map.js +1 -1
  11. package/dest/indexeddb/store.d.ts +1 -1
  12. package/dest/indexeddb/store.d.ts.map +1 -1
  13. package/dest/indexeddb/store.js +6 -4
  14. package/dest/interfaces/array_test_suite.d.ts +1 -1
  15. package/dest/interfaces/array_test_suite.d.ts.map +1 -1
  16. package/dest/interfaces/array_test_suite.js +33 -34
  17. package/dest/interfaces/index.d.ts +2 -2
  18. package/dest/interfaces/index.d.ts.map +1 -1
  19. package/dest/interfaces/map_test_suite.d.ts +1 -1
  20. package/dest/interfaces/map_test_suite.d.ts.map +1 -1
  21. package/dest/interfaces/map_test_suite.js +32 -33
  22. package/dest/interfaces/multi_map_test_suite.d.ts +1 -1
  23. package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
  24. package/dest/interfaces/multi_map_test_suite.js +68 -69
  25. package/dest/interfaces/set_test_suite.d.ts +1 -1
  26. package/dest/interfaces/set_test_suite.d.ts.map +1 -1
  27. package/dest/interfaces/set_test_suite.js +13 -14
  28. package/dest/interfaces/singleton_test_suite.d.ts +1 -1
  29. package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
  30. package/dest/interfaces/singleton_test_suite.js +6 -7
  31. package/dest/lmdb/index.d.ts +2 -2
  32. package/dest/lmdb/index.d.ts.map +1 -1
  33. package/dest/lmdb/index.js +2 -2
  34. package/dest/lmdb/store.d.ts +3 -3
  35. package/dest/lmdb/store.d.ts.map +1 -1
  36. package/dest/lmdb/store.js +12 -8
  37. package/dest/lmdb-v2/factory.d.ts +29 -4
  38. package/dest/lmdb-v2/factory.d.ts.map +1 -1
  39. package/dest/lmdb-v2/factory.js +61 -10
  40. package/dest/lmdb-v2/read_transaction.js +21 -19
  41. package/dest/lmdb-v2/store.d.ts +2 -2
  42. package/dest/lmdb-v2/store.d.ts.map +1 -1
  43. package/dest/lmdb-v2/store.js +4 -4
  44. package/dest/sqlite-opfs/array.d.ts +21 -0
  45. package/dest/sqlite-opfs/array.d.ts.map +1 -0
  46. package/dest/sqlite-opfs/array.js +128 -0
  47. package/dest/sqlite-opfs/errors.d.ts +27 -0
  48. package/dest/sqlite-opfs/errors.d.ts.map +1 -0
  49. package/dest/sqlite-opfs/errors.js +34 -0
  50. package/dest/sqlite-opfs/index.d.ts +16 -0
  51. package/dest/sqlite-opfs/index.d.ts.map +1 -0
  52. package/dest/sqlite-opfs/index.js +22 -0
  53. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts +32 -0
  54. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts.map +1 -0
  55. package/dest/sqlite-opfs/internal/ordered-binary-browser.js +448 -0
  56. package/dest/sqlite-opfs/map.d.ts +35 -0
  57. package/dest/sqlite-opfs/map.d.ts.map +1 -0
  58. package/dest/sqlite-opfs/map.js +163 -0
  59. package/dest/sqlite-opfs/messages.d.ts +66 -0
  60. package/dest/sqlite-opfs/messages.d.ts.map +1 -0
  61. package/dest/sqlite-opfs/messages.js +5 -0
  62. package/dest/sqlite-opfs/multi_map.d.ts +16 -0
  63. package/dest/sqlite-opfs/multi_map.d.ts.map +1 -0
  64. package/dest/sqlite-opfs/multi_map.js +67 -0
  65. package/dest/sqlite-opfs/set.d.ts +13 -0
  66. package/dest/sqlite-opfs/set.d.ts.map +1 -0
  67. package/dest/sqlite-opfs/set.js +19 -0
  68. package/dest/sqlite-opfs/singleton.d.ts +13 -0
  69. package/dest/sqlite-opfs/singleton.d.ts.map +1 -0
  70. package/dest/sqlite-opfs/singleton.js +48 -0
  71. package/dest/sqlite-opfs/store.d.ts +79 -0
  72. package/dest/sqlite-opfs/store.d.ts.map +1 -0
  73. package/dest/sqlite-opfs/store.js +281 -0
  74. package/dest/sqlite-opfs/worker.d.ts +2 -0
  75. package/dest/sqlite-opfs/worker.d.ts.map +1 -0
  76. package/dest/sqlite-opfs/worker.js +249 -0
  77. package/dest/stores/l2_tips_store.d.ts +3 -3
  78. package/dest/stores/l2_tips_store.d.ts.map +1 -1
  79. package/dest/stores/l2_tips_store.js +2 -2
  80. package/package.json +28 -26
  81. package/src/bench/shared_map_bench.ts +111 -0
  82. package/src/indexeddb/index.ts +2 -2
  83. package/src/indexeddb/map.ts +14 -2
  84. package/src/indexeddb/multi_map.ts +1 -1
  85. package/src/indexeddb/store.ts +6 -4
  86. package/src/interfaces/array_test_suite.ts +33 -35
  87. package/src/interfaces/index.ts +1 -1
  88. package/src/interfaces/map_test_suite.ts +32 -34
  89. package/src/interfaces/multi_map_test_suite.ts +65 -67
  90. package/src/interfaces/set_test_suite.ts +13 -15
  91. package/src/interfaces/singleton_test_suite.ts +6 -8
  92. package/src/lmdb/index.ts +3 -3
  93. package/src/lmdb/store.ts +12 -8
  94. package/src/lmdb-v2/factory.ts +80 -10
  95. package/src/lmdb-v2/read_transaction.ts +23 -23
  96. package/src/lmdb-v2/store.ts +4 -2
  97. package/src/sqlite-opfs/array.ts +124 -0
  98. package/src/sqlite-opfs/errors.ts +44 -0
  99. package/src/sqlite-opfs/index.ts +39 -0
  100. package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -0
  101. package/src/sqlite-opfs/map.ts +163 -0
  102. package/src/sqlite-opfs/messages.ts +39 -0
  103. package/src/sqlite-opfs/multi_map.ts +74 -0
  104. package/src/sqlite-opfs/set.ts +29 -0
  105. package/src/sqlite-opfs/singleton.ts +48 -0
  106. package/src/sqlite-opfs/store.ts +296 -0
  107. package/src/sqlite-opfs/worker.ts +231 -0
  108. package/src/stores/l2_tips_store.ts +3 -2
  109. package/dest/config.d.ts +0 -17
  110. package/dest/config.d.ts.map +0 -1
  111. package/dest/config.js +0 -26
  112. package/src/config.ts +0 -36
@@ -0,0 +1,281 @@
1
+ import { SerialQueue } from '@aztec/foundation/queue';
2
+ import { SQLiteOPFSAztecArray } from './array.js';
3
+ import { SqliteEncryptionError } from './errors.js';
4
+ import { SQLiteOPFSAztecMap } from './map.js';
5
+ import { SQLiteOPFSAztecMultiMap } from './multi_map.js';
6
+ import { SQLiteOPFSAztecSet } from './set.js';
7
+ import { SQLiteOPFSAztecSingleton } from './singleton.js';
8
+ /**
9
+ * Main-thread handle for a SQLite database persisted to OPFS via the `opfs-sahpool`
10
+ * VFS. Owns a dedicated Web Worker (the SAH Pool VFS requires Worker context) and
11
+ * routes every SQL op through it via typed postMessage RPC.
12
+ *
13
+ * Transaction ordering is guaranteed by a `SerialQueue` on the main thread combined
14
+ * with an `#inTx` flag: outside a `transactionAsync` block, each op acquires the
15
+ * queue for its own auto-commit; inside a block, the outer call holds the queue and
16
+ * nested ops bypass it to avoid deadlock.
17
+ */ export class AztecSQLiteOPFSStore {
18
+ isEphemeral;
19
+ #worker;
20
+ #pending;
21
+ #txQueue;
22
+ #name;
23
+ #log;
24
+ #nextId;
25
+ #inTx;
26
+ #closed;
27
+ constructor(worker, name, log, isEphemeral){
28
+ this.isEphemeral = isEphemeral;
29
+ this.#pending = new Map();
30
+ this.#txQueue = new SerialQueue();
31
+ this.#nextId = 0;
32
+ this.#inTx = false;
33
+ this.#closed = false;
34
+ this.#worker = worker;
35
+ this.#name = name;
36
+ this.#log = log;
37
+ this.#worker.onmessage = (ev)=>{
38
+ const { id } = ev.data;
39
+ const handler = this.#pending.get(id);
40
+ if (!handler) {
41
+ this.#log.warn(`SQLite worker: no pending handler for id ${id}`);
42
+ return;
43
+ }
44
+ this.#pending.delete(id);
45
+ handler.resolve(ev.data);
46
+ };
47
+ this.#worker.onerror = (ev)=>{
48
+ this.#log.error(`SQLite worker crashed: ${ev.message}`);
49
+ this.#rejectPending(`SQLite worker crashed: ${ev.message}`);
50
+ };
51
+ this.#txQueue.start();
52
+ }
53
+ /**
54
+ * Opens (or creates) a SQLite database stored in the OPFS SAH Pool. When `ephemeral`
55
+ * is true the database lives only in memory and is lost when the worker terminates.
56
+ * Pass `poolDirectory` to place the SAH Pool in a non-default OPFS subdirectory —
57
+ * required when multiple stores coexist in the same tab, because the SAH Pool holds
58
+ * an exclusive lock on its directory.
59
+ *
60
+ * Pass `encryptionKey` (exactly 32 bytes) to enable at-rest encryption via sqlite3mc's
61
+ * ChaCha20 page cipher. The key buffer is **transferred** to the worker — its
62
+ * ArrayBuffer detaches on the caller side after `postMessage`. This is intentional:
63
+ * the API encodes a one-key-one-owner invariant. A caller that wants to use the same
64
+ * key for multiple stores must explicitly clone it per call (e.g.
65
+ * `new Uint8Array(savedKey)`), making the duplication a visible, deliberate decision
66
+ * rather than a silent structured-clone operation. The default path (one `.open()`,
67
+ * one consumption of the key) leaves zero key bytes on the main thread after the call.
68
+ */ static async open(log, name, ephemeral = false, poolDirectory, encryptionKey) {
69
+ if (encryptionKey !== undefined && encryptionKey.length !== 32) {
70
+ throw new SqliteEncryptionError('invalid_key_length', `encryptionKey must be 32 bytes (got ${encryptionKey.length})`);
71
+ }
72
+ if (encryptionKey !== undefined && ephemeral) {
73
+ throw new SqliteEncryptionError('encryption_not_supported_for_ephemeral', 'encryptionKey is not supported for ephemeral (:memory:) stores');
74
+ }
75
+ const dbName = name && !ephemeral ? name : `tmp-${globalThis.crypto.getRandomValues(new Uint8Array(8)).join('')}`;
76
+ log.debug(`Opening SQLite-OPFS ${ephemeral ? 'ephemeral ' : ''}${encryptionKey ? 'encrypted ' : ''}database ${dbName}`);
77
+ const worker = new Worker(new URL('./worker.js', import.meta.url), {
78
+ type: 'module'
79
+ });
80
+ const store = new AztecSQLiteOPFSStore(worker, dbName, log, ephemeral);
81
+ // Transfer (not clone) the key buffer to the worker so we don't leave a
82
+ // second copy on the main thread. Caveat: this detaches the caller's
83
+ // encryptionKey.buffer — subsequent reads from the same Uint8Array are empty.
84
+ const transfer = encryptionKey ? [
85
+ encryptionKey.buffer
86
+ ] : undefined;
87
+ try {
88
+ await store.#sendRequest({
89
+ type: 'init',
90
+ id: store.#allocId(),
91
+ dbName,
92
+ ephemeral,
93
+ poolDirectory,
94
+ encryptionKey
95
+ }, transfer);
96
+ } catch (err) {
97
+ worker.terminate();
98
+ throw err;
99
+ }
100
+ return store;
101
+ }
102
+ openMap(name) {
103
+ return new SQLiteOPFSAztecMap(this, name);
104
+ }
105
+ openSet(name) {
106
+ return new SQLiteOPFSAztecSet(this, name);
107
+ }
108
+ openMultiMap(name) {
109
+ return new SQLiteOPFSAztecMultiMap(this, name);
110
+ }
111
+ openCounter(_name) {
112
+ throw new Error('Method not implemented.');
113
+ }
114
+ openArray(name) {
115
+ return new SQLiteOPFSAztecArray(this, name);
116
+ }
117
+ openSingleton(name) {
118
+ return new SQLiteOPFSAztecSingleton(this, name);
119
+ }
120
+ transactionAsync(callback) {
121
+ // Nested calls join the outer transaction — SQLite does not support nested BEGIN,
122
+ // and re-acquiring the SerialQueue while the outer call holds it would deadlock.
123
+ // Errors in the nested callback propagate to the outer catch, which rolls back the
124
+ // whole thing (the standard "nested tx = savepoint-free join" semantic).
125
+ if (this.#inTx) {
126
+ return callback();
127
+ }
128
+ return this.#txQueue.put(async ()=>{
129
+ this.#inTx = true;
130
+ await this.#sendRequest({
131
+ type: 'begin',
132
+ id: this.#allocId()
133
+ });
134
+ try {
135
+ const result = await callback();
136
+ await this.#sendRequest({
137
+ type: 'commit',
138
+ id: this.#allocId()
139
+ });
140
+ return result;
141
+ } catch (err) {
142
+ await this.#sendRequest({
143
+ type: 'rollback',
144
+ id: this.#allocId()
145
+ }).catch((rollbackErr)=>this.#log.warn(`SQLite ROLLBACK failed: ${rollbackErr instanceof Error ? rollbackErr.message : rollbackErr}`));
146
+ throw err;
147
+ } finally{
148
+ this.#inTx = false;
149
+ }
150
+ });
151
+ }
152
+ async clear() {
153
+ await this.runAsync('DELETE FROM data');
154
+ }
155
+ async delete() {
156
+ if (this.#closed) {
157
+ return;
158
+ }
159
+ this.#closed = true;
160
+ await this.#txQueue.end();
161
+ await this.#sendRequest({
162
+ type: 'deleteDb',
163
+ id: this.#allocId(),
164
+ dbName: this.#name
165
+ }).catch((err)=>this.#log.warn(`SQLite deleteDb failed: ${err instanceof Error ? err.message : err}`));
166
+ this.#worker.terminate();
167
+ this.#rejectPending('SQLite store deleted');
168
+ }
169
+ /**
170
+ * Placeholder — returns zeros to mirror the IndexedDB backend. SQLite exposes real
171
+ * numbers cheaply via `PRAGMA page_count` / `page_size` / `freelist_count` and
172
+ * `SELECT COUNT(*) FROM data`, which would populate `physicalFileSize`, `actualSize`,
173
+ * and `numItems` meaningfully (`mappingSize` stays 0 — it's an LMDB mmap concept).
174
+ * Upgrade when any caller actually consumes these values; all current consumers
175
+ * tolerate zeros.
176
+ */ estimateSize() {
177
+ return Promise.resolve({
178
+ mappingSize: 0,
179
+ physicalFileSize: 0,
180
+ actualSize: 0,
181
+ numItems: 0
182
+ });
183
+ }
184
+ async close() {
185
+ if (this.#closed) {
186
+ return;
187
+ }
188
+ this.#closed = true;
189
+ await this.#txQueue.end();
190
+ await this.#sendRequest({
191
+ type: 'close',
192
+ id: this.#allocId()
193
+ }).catch(()=>{});
194
+ this.#worker.terminate();
195
+ this.#rejectPending('SQLite store closed');
196
+ }
197
+ backupTo(_dstPath, _compact) {
198
+ throw new Error('Method not implemented.');
199
+ }
200
+ /**
201
+ * Returns a raw SQLite image (bytes suitable for writing as a `.sqlite` file and
202
+ * opening in any SQLite tool). Works only for non-ephemeral DBs because the OPFS
203
+ * SAH Pool has to be initialized. Useful for inspection/debugging.
204
+ */ async exportDb() {
205
+ const resp = await this.#sendRequest({
206
+ type: 'export',
207
+ id: this.#allocId()
208
+ });
209
+ if (!('bytes' in resp) || !resp.bytes) {
210
+ throw new Error('exportDb: worker returned no bytes');
211
+ }
212
+ return resp.bytes;
213
+ }
214
+ /**
215
+ * Runs a write statement (INSERT/UPDATE/DELETE/DDL). If called inside a
216
+ * `transactionAsync` block, bypasses the queue; otherwise acquires it so the
217
+ * op runs in its own auto-commit.
218
+ */ runAsync(sql, bind) {
219
+ const send = ()=>this.#sendRequest({
220
+ type: 'run',
221
+ id: this.#allocId(),
222
+ sql,
223
+ bind
224
+ }).then((r)=>({
225
+ changes: 'changes' in r ? r.changes ?? 0 : 0
226
+ }));
227
+ return this.#inTx ? send() : this.#txQueue.put(send);
228
+ }
229
+ /** Runs a SELECT statement and returns rows in array row-mode. */ allAsync(sql, bind) {
230
+ const send = ()=>this.#sendRequest({
231
+ type: 'all',
232
+ id: this.#allocId(),
233
+ sql,
234
+ bind
235
+ }).then((r)=>'rows' in r ? r.rows ?? [] : []);
236
+ return this.#inTx ? send() : this.#txQueue.put(send);
237
+ }
238
+ #allocId() {
239
+ return ++this.#nextId;
240
+ }
241
+ /**
242
+ * Reject any in-flight requests with `reason`, so callers awaiting a response to a
243
+ * request sent to a now-terminated worker don't hang forever. Called from
244
+ * close()/delete() and from the worker.onerror handler.
245
+ */ #rejectPending(reason) {
246
+ if (this.#pending.size === 0) {
247
+ return;
248
+ }
249
+ const err = new Error(reason);
250
+ for (const { reject } of this.#pending.values()){
251
+ reject(err);
252
+ }
253
+ this.#pending.clear();
254
+ }
255
+ #sendRequest(req, transfer) {
256
+ return new Promise((resolve, reject)=>{
257
+ this.#pending.set(req.id, {
258
+ resolve: (resp)=>{
259
+ if (resp.type === 'err') {
260
+ // Re-hydrate encryption-shaped errors as the typed class so consumers
261
+ // can pattern-match on `instanceof SqliteEncryptionError`. Plain
262
+ // errors stay plain — the wire protocol only tags encryption paths.
263
+ if (resp.encryptionCode !== undefined) {
264
+ reject(new SqliteEncryptionError(resp.encryptionCode, resp.message));
265
+ } else {
266
+ reject(new Error(resp.message));
267
+ }
268
+ } else {
269
+ resolve(resp);
270
+ }
271
+ },
272
+ reject
273
+ });
274
+ if (transfer && transfer.length > 0) {
275
+ this.#worker.postMessage(req, transfer);
276
+ } else {
277
+ this.#worker.postMessage(req);
278
+ }
279
+ });
280
+ }
281
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ya2VyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3FsaXRlLW9wZnMvd29ya2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/sqlite-opfs/worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,249 @@
1
+ /// <reference lib="webworker" />
2
+ import sqlite3InitModule from '@aztec/sqlite3mc-wasm';
3
+ import { SqliteEncryptionError, isDecryptFailureMessage } from './errors.js';
4
+ const SCHEMA_SQL = `
5
+ CREATE TABLE IF NOT EXISTS data (
6
+ slot TEXT NOT NULL PRIMARY KEY,
7
+ container TEXT NOT NULL,
8
+ key BLOB NOT NULL,
9
+ key_count INTEGER NOT NULL,
10
+ hash TEXT NOT NULL,
11
+ value BLOB
12
+ ) WITHOUT ROWID;
13
+
14
+ CREATE INDEX IF NOT EXISTS idx_container_key ON data(container, key);
15
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_container_key_count ON data(container, key, key_count);
16
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_container_key_hash ON data(container, key, hash);
17
+ `;
18
+ const DEFAULT_SAH_POOL_DIRECTORY = '.aztec-kv';
19
+ const SAH_POOL_VFS_NAME = 'aztec-kv-opfs';
20
+ const MC_SAH_POOL_VFS_NAME = `multipleciphers-${SAH_POOL_VFS_NAME}`;
21
+ let sqlite3;
22
+ let pool;
23
+ let db;
24
+ let dbPath;
25
+ async function ensurePool(directory) {
26
+ sqlite3 ??= await sqlite3InitModule();
27
+ const s = sqlite3;
28
+ if (!pool) {
29
+ pool = await s.installOpfsSAHPoolVfs({
30
+ name: SAH_POOL_VFS_NAME,
31
+ directory,
32
+ initialCapacity: 8
33
+ });
34
+ // Register a sqlite3mc-wrapped VFS pointing at our SAH Pool VFS.
35
+ // Encrypted DBs must be opened through this wrapper so sqlite3mc can
36
+ // intercept file I/O; plain DBs continue using the SAH Pool VFS directly.
37
+ // The wrapper name is `multipleciphers-<underlying>`.
38
+ s.capi.sqlite3mc_vfs_create(SAH_POOL_VFS_NAME, 0);
39
+ }
40
+ return pool;
41
+ }
42
+ /**
43
+ * Applies sqlite3mc's ChaCha20 page cipher using a pre-derived 32-byte key.
44
+ * The PRAGMAs must run before any schema DDL so sqlite3mc can decrypt existing
45
+ * pages and encrypt new ones. Zeroes the caller-held key array after the PRAGMA
46
+ * completes to minimize residency of the raw key bytes outside sqlite3mc's heap.
47
+ */ function applyEncryptionKey(conn, key) {
48
+ const hex = Array.from(key, (b)=>b.toString(16).padStart(2, '0')).join('');
49
+ conn.exec(`PRAGMA cipher = 'chacha20'`);
50
+ conn.exec(`PRAGMA key = "x'${hex}'"`);
51
+ key.fill(0);
52
+ }
53
+ async function handleInit(dbName, ephemeral, directory, encryptionKey) {
54
+ sqlite3 ??= await sqlite3InitModule();
55
+ const s = sqlite3;
56
+ if (encryptionKey !== undefined && ephemeral) {
57
+ throw new SqliteEncryptionError('encryption_not_supported_for_ephemeral', 'encryptionKey is not supported for ephemeral (:memory:) stores');
58
+ }
59
+ if (ephemeral) {
60
+ db = new s.oo1.DB(':memory:', 'c');
61
+ } else {
62
+ await ensurePool(directory ?? DEFAULT_SAH_POOL_DIRECTORY);
63
+ dbPath = normalizeDbPath(dbName);
64
+ if (encryptionKey !== undefined) {
65
+ db = new s.oo1.DB({
66
+ filename: dbPath,
67
+ flags: 'c',
68
+ vfs: MC_SAH_POOL_VFS_NAME
69
+ });
70
+ applyEncryptionKey(db, encryptionKey);
71
+ } else {
72
+ db = new pool.OpfsSAHPoolDb(dbPath);
73
+ }
74
+ }
75
+ runSql(SCHEMA_SQL);
76
+ }
77
+ function handleClose() {
78
+ db?.close();
79
+ db = undefined;
80
+ dbPath = undefined;
81
+ }
82
+ async function handleExport() {
83
+ if (!db || !dbPath) {
84
+ throw new Error('SQLite worker: no database open to export');
85
+ }
86
+ if (!pool) {
87
+ throw new Error('SQLite worker: no SAH Pool available (ephemeral DBs cannot be exported)');
88
+ }
89
+ return await pool.exportFile(dbPath);
90
+ }
91
+ function handleDeleteDb(dbName) {
92
+ const path = normalizeDbPath(dbName);
93
+ if (db && dbPath === path) {
94
+ db.close();
95
+ db = undefined;
96
+ dbPath = undefined;
97
+ }
98
+ // Ephemeral :memory: DBs never back a file — skip installing a pool just to unlink
99
+ // nothing. installOpfsSAHPoolVfs acquires an exclusive lock on the OPFS SAH
100
+ // directory, and under heavy test churn that can contend with workers from
101
+ // previous tests whose OPFS handles Chromium hasn't yet released, hanging the RPC
102
+ // and then the whole test run.
103
+ if (!pool) {
104
+ return;
105
+ }
106
+ try {
107
+ pool.unlink(path);
108
+ } catch {
109
+ // File may not exist; ignore.
110
+ }
111
+ }
112
+ function requireDb() {
113
+ if (!db) {
114
+ throw new Error('SQLite worker: no database open');
115
+ }
116
+ return db;
117
+ }
118
+ function runSql(sql, bind) {
119
+ const conn = requireDb();
120
+ conn.exec({
121
+ sql,
122
+ bind
123
+ });
124
+ return {
125
+ changes: conn.changes()
126
+ };
127
+ }
128
+ function selectAll(sql, bind) {
129
+ const conn = requireDb();
130
+ const rows = [];
131
+ conn.exec({
132
+ sql,
133
+ bind,
134
+ rowMode: 'array',
135
+ resultRows: rows
136
+ });
137
+ return rows;
138
+ }
139
+ function normalizeDbPath(dbName) {
140
+ return dbName.startsWith('/') ? dbName : `/${dbName}`;
141
+ }
142
+ function respond(msg) {
143
+ self.postMessage(msg);
144
+ }
145
+ self.onmessage = async (ev)=>{
146
+ const req = ev.data;
147
+ try {
148
+ switch(req.type){
149
+ case 'init':
150
+ await handleInit(req.dbName, req.ephemeral, req.poolDirectory, req.encryptionKey);
151
+ return respond({
152
+ type: 'ok',
153
+ id: req.id
154
+ });
155
+ case 'close':
156
+ handleClose();
157
+ return respond({
158
+ type: 'ok',
159
+ id: req.id
160
+ });
161
+ case 'deleteDb':
162
+ handleDeleteDb(req.dbName);
163
+ return respond({
164
+ type: 'ok',
165
+ id: req.id
166
+ });
167
+ case 'run':
168
+ {
169
+ const { changes } = runSql(req.sql, req.bind);
170
+ return respond({
171
+ type: 'ok',
172
+ id: req.id,
173
+ changes
174
+ });
175
+ }
176
+ case 'all':
177
+ {
178
+ const rows = selectAll(req.sql, req.bind);
179
+ return respond({
180
+ type: 'ok',
181
+ id: req.id,
182
+ rows
183
+ });
184
+ }
185
+ case 'export':
186
+ {
187
+ const bytes = await handleExport();
188
+ return respond({
189
+ type: 'ok',
190
+ id: req.id,
191
+ bytes
192
+ });
193
+ }
194
+ case 'begin':
195
+ runSql('BEGIN');
196
+ return respond({
197
+ type: 'ok',
198
+ id: req.id
199
+ });
200
+ case 'commit':
201
+ runSql('COMMIT');
202
+ return respond({
203
+ type: 'ok',
204
+ id: req.id
205
+ });
206
+ case 'rollback':
207
+ runSql('ROLLBACK');
208
+ return respond({
209
+ type: 'ok',
210
+ id: req.id
211
+ });
212
+ default:
213
+ {
214
+ const _exhaustive = req;
215
+ throw new Error(`Unknown request: ${JSON.stringify(_exhaustive)}`);
216
+ }
217
+ }
218
+ } catch (err) {
219
+ const message = err instanceof Error ? err.message : String(err);
220
+ respond({
221
+ type: 'err',
222
+ id: req.id,
223
+ message,
224
+ encryptionCode: detectEncryptionCode(req, err, message)
225
+ });
226
+ }
227
+ };
228
+ /**
229
+ * Maps a thrown error during request handling to a typed encryption code, so the
230
+ * main thread can re-hydrate it as a {@link SqliteEncryptionError}. Returns
231
+ * `undefined` for non-encryption errors (preserves the existing untyped path).
232
+ *
233
+ * Two sources:
234
+ * - The error was already a `SqliteEncryptionError` (pre-flight throws inside
235
+ * this worker — e.g. ephemeral + encryptionKey). Forward its code as-is.
236
+ * - The error came from SQLite/sqlite3mc with a known decrypt-failure message
237
+ * during an `init` request. Both "wrong key supplied" and "no key supplied
238
+ * to an encrypted DB" surface as SQLITE_NOTADB ("file is not a database") —
239
+ * we don't constrain on `req.encryptionKey` because the no-key-on-encrypted-DB
240
+ * case is exactly when the caller most needs the typed signal.
241
+ */ function detectEncryptionCode(req, err, message) {
242
+ if (err instanceof SqliteEncryptionError) {
243
+ return err.code;
244
+ }
245
+ if (req.type === 'init' && isDecryptFailureMessage(message)) {
246
+ return 'decrypt_failed';
247
+ }
248
+ return undefined;
249
+ }
@@ -1,5 +1,5 @@
1
1
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
- import { type L2BlockTag, L2TipsStoreBase } from '@aztec/stdlib/block';
2
+ import { type BlockHash, type L2BlockTag, L2TipsStoreBase } from '@aztec/stdlib/block';
3
3
  import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
4
4
  import type { AztecAsyncKVStore } from '../interfaces/store.js';
5
5
  /**
@@ -12,7 +12,7 @@ export declare class L2TipsKVStore extends L2TipsStoreBase {
12
12
  private readonly l2BlockHashesStore;
13
13
  private readonly l2BlockNumberToCheckpointNumberStore;
14
14
  private readonly l2CheckpointStore;
15
- constructor(store: AztecAsyncKVStore, namespace: string);
15
+ constructor(store: AztecAsyncKVStore, namespace: string, initialBlockHash: BlockHash);
16
16
  protected getTip(tag: L2BlockTag): Promise<BlockNumber | undefined>;
17
17
  protected setTip(tag: L2BlockTag, blockNumber: BlockNumber): Promise<void>;
18
18
  protected getStoredBlockHash(blockNumber: BlockNumber): Promise<string | undefined>;
@@ -26,4 +26,4 @@ export declare class L2TipsKVStore extends L2TipsStoreBase {
26
26
  protected deleteCheckpointsBefore(checkpointNumber: CheckpointNumber): Promise<void>;
27
27
  protected runInTransaction<T>(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,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAM1G;IAED,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3E;IAED,UAAgB,uBAAuB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAIzF;IAED,SAAS,CAAC,gBAAgB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE9D;CACF"}
@@ -9,8 +9,8 @@ import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
9
9
  l2BlockHashesStore;
10
10
  l2BlockNumberToCheckpointNumberStore;
11
11
  l2CheckpointStore;
12
- constructor(store, namespace){
13
- super(), this.store = store;
12
+ constructor(store, namespace, initialBlockHash){
13
+ super(initialBlockHash), this.store = store;
14
14
  this.l2TipsStore = store.openMap([
15
15
  namespace,
16
16
  'l2_tips'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/kv-store",
3
- "version": "0.0.1-commit.86469d5",
3
+ "version": "0.0.1-commit.8655d4a",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/interfaces/index.js",
@@ -8,16 +8,27 @@
8
8
  "./lmdb": "./dest/lmdb/index.js",
9
9
  "./lmdb-v2": "./dest/lmdb-v2/index.js",
10
10
  "./indexeddb": "./dest/indexeddb/index.js",
11
- "./stores": "./dest/stores/index.js",
12
- "./config": "./dest/config.js"
11
+ "./sqlite-opfs": "./dest/sqlite-opfs/index.js",
12
+ "./stores": "./dest/stores/index.js"
13
+ },
14
+ "imports": {
15
+ "#msgpackr": {
16
+ "browser": "msgpackr/index-no-eval",
17
+ "default": "msgpackr"
18
+ },
19
+ "#ordered-binary": {
20
+ "browser": "./dest/sqlite-opfs/internal/ordered-binary-browser.js",
21
+ "default": "ordered-binary"
22
+ }
13
23
  },
14
24
  "scripts": {
15
25
  "build": "yarn clean && ../scripts/tsc.sh",
16
26
  "build:dev": "../scripts/tsc.sh --watch",
17
27
  "clean": "rm -rf ./dest .tsbuildinfo",
18
- "test:node": "NODE_NO_WARNINGS=1 mocha --config ./.mocharc.json",
19
- "test:browser": "wtr --config ./web-test-runner.config.mjs",
20
- "test": "yarn test:node && yarn test:browser",
28
+ "test:node": "vitest run --project node",
29
+ "test:browser": "bash scripts/run-browser-tests.sh",
30
+ "bench:browser": "VITE_BENCH=1 vitest run --project browser src/bench",
31
+ "test": "vitest run",
21
32
  "test:jest": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
22
33
  },
23
34
  "inherits": [
@@ -25,11 +36,12 @@
25
36
  "./package.local.json"
26
37
  ],
27
38
  "dependencies": {
28
- "@aztec/constants": "0.0.1-commit.86469d5",
29
- "@aztec/ethereum": "0.0.1-commit.86469d5",
30
- "@aztec/foundation": "0.0.1-commit.86469d5",
31
- "@aztec/native": "0.0.1-commit.86469d5",
32
- "@aztec/stdlib": "0.0.1-commit.86469d5",
39
+ "@aztec/constants": "0.0.1-commit.8655d4a",
40
+ "@aztec/ethereum": "0.0.1-commit.8655d4a",
41
+ "@aztec/foundation": "0.0.1-commit.8655d4a",
42
+ "@aztec/native": "0.0.1-commit.8655d4a",
43
+ "@aztec/sqlite3mc-wasm": "0.0.1-commit.8655d4a",
44
+ "@aztec/stdlib": "0.0.1-commit.8655d4a",
33
45
  "idb": "^8.0.0",
34
46
  "lmdb": "^3.2.0",
35
47
  "msgpackr": "^1.11.2",
@@ -38,27 +50,17 @@
38
50
  },
39
51
  "devDependencies": {
40
52
  "@jest/globals": "^30.0.0",
41
- "@types/chai": "^5.0.1",
42
- "@types/chai-as-promised": "^8.0.1",
43
53
  "@types/jest": "^30.0.0",
44
- "@types/mocha": "^10.0.10",
45
- "@types/mocha-each": "^2.0.4",
46
54
  "@types/node": "^22.15.17",
47
- "@types/sinon": "^17.0.3",
48
55
  "@typescript/native-preview": "7.0.0-dev.20260113.1",
49
- "@web/dev-server-esbuild": "^1.0.3",
50
- "@web/dev-server-import-maps": "^0.2.1",
51
- "@web/test-runner": "^0.19.0",
52
- "@web/test-runner-playwright": "^0.11.0",
53
- "chai": "^5.1.2",
54
- "chai-as-promised": "^8.0.1",
56
+ "@vitest/browser-playwright": "^4.0.0",
57
+ "buffer": "^6.0.3",
55
58
  "jest": "^30.0.0",
56
- "mocha": "^10.8.2",
57
- "mocha-each": "^2.0.1",
58
- "sinon": "^19.0.2",
59
+ "playwright": "1.49.0",
59
60
  "ts-node": "^10.9.1",
60
61
  "typescript": "^5.3.3",
61
- "util": "^0.12.5"
62
+ "util": "^0.12.5",
63
+ "vitest": "^4.0.0"
62
64
  },
63
65
  "files": [
64
66
  "dest",