@aztec/kv-store 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240

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 (126) 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/array.js +18 -6
  5. package/dest/indexeddb/index.d.ts +3 -3
  6. package/dest/indexeddb/index.d.ts.map +1 -1
  7. package/dest/indexeddb/index.js +3 -6
  8. package/dest/indexeddb/map.d.ts +8 -2
  9. package/dest/indexeddb/map.d.ts.map +1 -1
  10. package/dest/indexeddb/map.js +23 -13
  11. package/dest/indexeddb/multi_map.d.ts +2 -1
  12. package/dest/indexeddb/multi_map.d.ts.map +1 -1
  13. package/dest/indexeddb/multi_map.js +16 -1
  14. package/dest/indexeddb/singleton.js +3 -1
  15. package/dest/indexeddb/store.d.ts +3 -3
  16. package/dest/indexeddb/store.d.ts.map +1 -1
  17. package/dest/indexeddb/store.js +6 -4
  18. package/dest/interfaces/array_test_suite.d.ts +1 -1
  19. package/dest/interfaces/array_test_suite.d.ts.map +1 -1
  20. package/dest/interfaces/array_test_suite.js +33 -34
  21. package/dest/interfaces/index.d.ts +2 -2
  22. package/dest/interfaces/index.d.ts.map +1 -1
  23. package/dest/interfaces/map_test_suite.d.ts +1 -1
  24. package/dest/interfaces/map_test_suite.d.ts.map +1 -1
  25. package/dest/interfaces/map_test_suite.js +74 -29
  26. package/dest/interfaces/multi_map_test_suite.d.ts +1 -1
  27. package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
  28. package/dest/interfaces/multi_map_test_suite.js +84 -60
  29. package/dest/interfaces/set_test_suite.d.ts +1 -1
  30. package/dest/interfaces/set_test_suite.d.ts.map +1 -1
  31. package/dest/interfaces/set_test_suite.js +13 -14
  32. package/dest/interfaces/singleton_test_suite.d.ts +1 -1
  33. package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
  34. package/dest/interfaces/singleton_test_suite.js +6 -7
  35. package/dest/interfaces/utils.d.ts +2 -1
  36. package/dest/interfaces/utils.d.ts.map +1 -1
  37. package/dest/interfaces/utils.js +2 -1
  38. package/dest/lmdb/index.d.ts +3 -3
  39. package/dest/lmdb/index.d.ts.map +1 -1
  40. package/dest/lmdb/index.js +4 -4
  41. package/dest/lmdb/store.d.ts +3 -3
  42. package/dest/lmdb/store.d.ts.map +1 -1
  43. package/dest/lmdb/store.js +12 -8
  44. package/dest/lmdb-v2/factory.d.ts +32 -7
  45. package/dest/lmdb-v2/factory.d.ts.map +1 -1
  46. package/dest/lmdb-v2/factory.js +71 -16
  47. package/dest/lmdb-v2/read_transaction.js +21 -19
  48. package/dest/lmdb-v2/store.d.ts +3 -3
  49. package/dest/lmdb-v2/store.d.ts.map +1 -1
  50. package/dest/lmdb-v2/store.js +5 -4
  51. package/dest/sqlite-opfs/array.d.ts +21 -0
  52. package/dest/sqlite-opfs/array.d.ts.map +1 -0
  53. package/dest/sqlite-opfs/array.js +128 -0
  54. package/dest/sqlite-opfs/errors.d.ts +27 -0
  55. package/dest/sqlite-opfs/errors.d.ts.map +1 -0
  56. package/dest/sqlite-opfs/errors.js +34 -0
  57. package/dest/sqlite-opfs/index.d.ts +16 -0
  58. package/dest/sqlite-opfs/index.d.ts.map +1 -0
  59. package/dest/sqlite-opfs/index.js +22 -0
  60. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts +32 -0
  61. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts.map +1 -0
  62. package/dest/sqlite-opfs/internal/ordered-binary-browser.js +448 -0
  63. package/dest/sqlite-opfs/map.d.ts +35 -0
  64. package/dest/sqlite-opfs/map.d.ts.map +1 -0
  65. package/dest/sqlite-opfs/map.js +163 -0
  66. package/dest/sqlite-opfs/messages.d.ts +66 -0
  67. package/dest/sqlite-opfs/messages.d.ts.map +1 -0
  68. package/dest/sqlite-opfs/messages.js +5 -0
  69. package/dest/sqlite-opfs/multi_map.d.ts +16 -0
  70. package/dest/sqlite-opfs/multi_map.d.ts.map +1 -0
  71. package/dest/sqlite-opfs/multi_map.js +67 -0
  72. package/dest/sqlite-opfs/set.d.ts +13 -0
  73. package/dest/sqlite-opfs/set.d.ts.map +1 -0
  74. package/dest/sqlite-opfs/set.js +19 -0
  75. package/dest/sqlite-opfs/singleton.d.ts +13 -0
  76. package/dest/sqlite-opfs/singleton.d.ts.map +1 -0
  77. package/dest/sqlite-opfs/singleton.js +48 -0
  78. package/dest/sqlite-opfs/store.d.ts +79 -0
  79. package/dest/sqlite-opfs/store.d.ts.map +1 -0
  80. package/dest/sqlite-opfs/store.js +281 -0
  81. package/dest/sqlite-opfs/worker.d.ts +2 -0
  82. package/dest/sqlite-opfs/worker.d.ts.map +1 -0
  83. package/dest/sqlite-opfs/worker.js +249 -0
  84. package/dest/stores/l2_tips_store.d.ts +3 -3
  85. package/dest/stores/l2_tips_store.d.ts.map +1 -1
  86. package/dest/stores/l2_tips_store.js +2 -2
  87. package/dest/utils.d.ts +9 -6
  88. package/dest/utils.d.ts.map +1 -1
  89. package/dest/utils.js +51 -16
  90. package/package.json +30 -26
  91. package/src/bench/shared_map_bench.ts +111 -0
  92. package/src/indexeddb/array.ts +4 -4
  93. package/src/indexeddb/index.ts +9 -7
  94. package/src/indexeddb/map.ts +24 -11
  95. package/src/indexeddb/multi_map.ts +15 -1
  96. package/src/indexeddb/singleton.ts +1 -1
  97. package/src/indexeddb/store.ts +13 -6
  98. package/src/interfaces/array_test_suite.ts +33 -35
  99. package/src/interfaces/index.ts +1 -1
  100. package/src/interfaces/map_test_suite.ts +56 -30
  101. package/src/interfaces/multi_map_test_suite.ts +88 -58
  102. package/src/interfaces/set_test_suite.ts +13 -15
  103. package/src/interfaces/singleton_test_suite.ts +6 -8
  104. package/src/interfaces/utils.ts +1 -0
  105. package/src/lmdb/index.ts +10 -5
  106. package/src/lmdb/store.ts +12 -8
  107. package/src/lmdb-v2/factory.ts +93 -19
  108. package/src/lmdb-v2/read_transaction.ts +23 -23
  109. package/src/lmdb-v2/store.ts +7 -4
  110. package/src/sqlite-opfs/array.ts +124 -0
  111. package/src/sqlite-opfs/errors.ts +44 -0
  112. package/src/sqlite-opfs/index.ts +39 -0
  113. package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -0
  114. package/src/sqlite-opfs/map.ts +163 -0
  115. package/src/sqlite-opfs/messages.ts +39 -0
  116. package/src/sqlite-opfs/multi_map.ts +74 -0
  117. package/src/sqlite-opfs/set.ts +29 -0
  118. package/src/sqlite-opfs/singleton.ts +48 -0
  119. package/src/sqlite-opfs/store.ts +296 -0
  120. package/src/sqlite-opfs/worker.ts +231 -0
  121. package/src/stores/l2_tips_store.ts +3 -2
  122. package/src/utils.ts +79 -21
  123. package/dest/config.d.ts +0 -17
  124. package/dest/config.d.ts.map +0 -1
  125. package/dest/config.js +0 -26
  126. package/src/config.ts +0 -36
@@ -0,0 +1,21 @@
1
+ import type { AztecAsyncArray } from '../interfaces/array.js';
2
+ import type { Value } from '../interfaces/common.js';
3
+ import type { AztecSQLiteOPFSStore } from './store.js';
4
+ /**
5
+ * Persistent array backed by SQLite. Entries share a common `key` (the array name)
6
+ * and are ordered by `key_count`, which doubles as the 1-indexed slot number.
7
+ */
8
+ export declare class SQLiteOPFSAztecArray<T extends Value> implements AztecAsyncArray<T> {
9
+ #private;
10
+ private readonly store;
11
+ constructor(store: AztecSQLiteOPFSStore, name: string);
12
+ lengthAsync(): Promise<number>;
13
+ push(...vals: T[]): Promise<number>;
14
+ pop(): Promise<T | undefined>;
15
+ atAsync(index: number): Promise<T | undefined>;
16
+ setAt(index: number, val: T): Promise<boolean>;
17
+ entriesAsync(): AsyncIterableIterator<[number, T]>;
18
+ valuesAsync(): AsyncIterableIterator<T>;
19
+ [Symbol.asyncIterator](): AsyncIterableIterator<T>;
20
+ }
21
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj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,CAAC,CAAC,CAEjD;CASF"}
@@ -0,0 +1,128 @@
1
+ var _computedKey;
2
+ import { Encoder } from '#msgpackr';
3
+ import { toBufferKey } from '#ordered-binary';
4
+ import { hash } from 'ohash';
5
+ _computedKey = Symbol.asyncIterator;
6
+ /**
7
+ * Persistent array backed by SQLite. Entries share a common `key` (the array name)
8
+ * and are ordered by `key_count`, which doubles as the 1-indexed slot number.
9
+ */ export class SQLiteOPFSAztecArray {
10
+ store;
11
+ #name;
12
+ #container;
13
+ #encoder;
14
+ constructor(store, name){
15
+ this.store = store;
16
+ this.#encoder = new Encoder();
17
+ this.#name = name;
18
+ this.#container = `array:${name}`;
19
+ }
20
+ async lengthAsync() {
21
+ const rows = await this.store.allAsync('SELECT COUNT(*) FROM data WHERE container = ? AND key = ?', [
22
+ this.#container,
23
+ this.#encodedKey()
24
+ ]);
25
+ return Number(rows[0]?.[0] ?? 0);
26
+ }
27
+ async push(...vals) {
28
+ if (vals.length === 0) {
29
+ return this.lengthAsync();
30
+ }
31
+ return await this.store.transactionAsync(async ()=>{
32
+ let length = await this.lengthAsync();
33
+ for (const val of vals){
34
+ await this.store.runAsync(`INSERT INTO data (slot, container, key, key_count, hash, value)
35
+ VALUES (?, ?, ?, ?, ?, ?)`, [
36
+ this.#slot(length),
37
+ this.#container,
38
+ this.#encodedKey(),
39
+ length + 1,
40
+ hash(val),
41
+ this.#encoder.pack(val)
42
+ ]);
43
+ length += 1;
44
+ }
45
+ return length;
46
+ });
47
+ }
48
+ async pop() {
49
+ return await this.store.transactionAsync(async ()=>{
50
+ const length = await this.lengthAsync();
51
+ if (length === 0) {
52
+ return undefined;
53
+ }
54
+ const slot = this.#slot(length - 1);
55
+ const rows = await this.store.allAsync('SELECT value FROM data WHERE slot = ? LIMIT 1', [
56
+ slot
57
+ ]);
58
+ await this.store.runAsync('DELETE FROM data WHERE slot = ?', [
59
+ slot
60
+ ]);
61
+ const raw = rows[0]?.[0];
62
+ return raw instanceof Uint8Array ? this.#encoder.unpack(raw) : undefined;
63
+ });
64
+ }
65
+ async atAsync(index) {
66
+ const length = await this.lengthAsync();
67
+ const resolved = index < 0 ? length + index : index;
68
+ if (resolved < 0 || resolved >= length) {
69
+ return undefined;
70
+ }
71
+ const rows = await this.store.allAsync('SELECT value FROM data WHERE slot = ? LIMIT 1', [
72
+ this.#slot(resolved)
73
+ ]);
74
+ const raw = rows[0]?.[0];
75
+ return raw instanceof Uint8Array ? this.#encoder.unpack(raw) : undefined;
76
+ }
77
+ async setAt(index, val) {
78
+ return await this.store.transactionAsync(async ()=>{
79
+ const length = await this.lengthAsync();
80
+ const resolved = index < 0 ? length + index : index;
81
+ if (resolved < 0 || resolved >= length) {
82
+ return false;
83
+ }
84
+ await this.store.runAsync(`INSERT OR REPLACE INTO data (slot, container, key, key_count, hash, value)
85
+ VALUES (?, ?, ?, ?, ?, ?)`, [
86
+ this.#slot(resolved),
87
+ this.#container,
88
+ this.#encodedKey(),
89
+ resolved + 1,
90
+ hash(val),
91
+ this.#encoder.pack(val)
92
+ ]);
93
+ return true;
94
+ });
95
+ }
96
+ async *entriesAsync() {
97
+ const rows = await this.store.allAsync('SELECT key_count, value FROM data WHERE container = ? AND key = ? ORDER BY key_count ASC', [
98
+ this.#container,
99
+ this.#encodedKey()
100
+ ]);
101
+ for (const row of rows){
102
+ const keyCount = Number(row[0]);
103
+ const raw = row[1];
104
+ if (raw instanceof Uint8Array) {
105
+ yield [
106
+ keyCount - 1,
107
+ this.#encoder.unpack(raw)
108
+ ];
109
+ }
110
+ }
111
+ }
112
+ async *valuesAsync() {
113
+ for await (const [, val] of this.entriesAsync()){
114
+ yield val;
115
+ }
116
+ }
117
+ [_computedKey]() {
118
+ return this.valuesAsync();
119
+ }
120
+ #encodedKey() {
121
+ return toBufferKey([
122
+ this.#name
123
+ ]);
124
+ }
125
+ #slot(index) {
126
+ return `array:${this.#name}:slot:${index}`;
127
+ }
128
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Typed error surface for sqlite3mc-backed page-level encryption failures.
3
+ *
4
+ * Three concrete failure modes are surfaced:
5
+ *
6
+ * - `invalid_key_length`: caller-side pre-flight (key not 32 bytes).
7
+ * - `encryption_not_supported_for_ephemeral`: caller-side pre-flight (encryption was requested on an ephemeral
8
+ * `:memory:` store, which sqlite3mc does not support).
9
+ * - `decrypt_failed`: runtime failure raised when sqlite3mc cannot decode page 1 of an existing database. Covers
10
+ * both "wrong key supplied" and "no key supplied to an encrypted DB".
11
+ */
12
+ export type SqliteEncryptionErrorCode = 'invalid_key_length' | 'encryption_not_supported_for_ephemeral' | 'decrypt_failed';
13
+ /**
14
+ * Error thrown by sqlite-opfs when an encryption operation fails.
15
+ **/
16
+ export declare class SqliteEncryptionError extends Error {
17
+ readonly code: SqliteEncryptionErrorCode;
18
+ constructor(code: SqliteEncryptionErrorCode, message: string, opts?: {
19
+ cause?: unknown;
20
+ });
21
+ }
22
+ /**
23
+ * Returns `true` if `message` matches one of the known sqlite3mc decrypt-failure
24
+ * strings.
25
+ **/
26
+ export declare function isDecryptFailureMessage(message: string): boolean;
27
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3FsaXRlLW9wZnMvZXJyb3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7O0dBVUc7QUFDSCxNQUFNLE1BQU0seUJBQXlCLEdBQ2pDLG9CQUFvQixHQUNwQix3Q0FBd0MsR0FDeEMsZ0JBQWdCLENBQUM7QUFFckI7O0lBRUk7QUFDSixxQkFBYSxxQkFBc0IsU0FBUSxLQUFLO0lBQzlDLFFBQVEsQ0FBQyxJQUFJLEVBQUUseUJBQXlCLENBQUM7SUFFekMsWUFBWSxJQUFJLEVBQUUseUJBQXlCLEVBQUUsT0FBTyxFQUFFLE1BQU0sRUFBRSxJQUFJLENBQUMsRUFBRTtRQUFFLEtBQUssQ0FBQyxFQUFFLE9BQU8sQ0FBQTtLQUFFLEVBSXZGO0NBQ0Y7QUFVRDs7O0lBR0k7QUFDSix3QkFBZ0IsdUJBQXVCLENBQUMsT0FBTyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBRWhFIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sqlite-opfs/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,yBAAyB,GACjC,oBAAoB,GACpB,wCAAwC,GACxC,gBAAgB,CAAC;AAErB;;IAEI;AACJ,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAC;IAEzC,YAAY,IAAI,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAIvF;CACF;AAUD;;;IAGI;AACJ,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEhE"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Typed error surface for sqlite3mc-backed page-level encryption failures.
3
+ *
4
+ * Three concrete failure modes are surfaced:
5
+ *
6
+ * - `invalid_key_length`: caller-side pre-flight (key not 32 bytes).
7
+ * - `encryption_not_supported_for_ephemeral`: caller-side pre-flight (encryption was requested on an ephemeral
8
+ * `:memory:` store, which sqlite3mc does not support).
9
+ * - `decrypt_failed`: runtime failure raised when sqlite3mc cannot decode page 1 of an existing database. Covers
10
+ * both "wrong key supplied" and "no key supplied to an encrypted DB".
11
+ */ /**
12
+ * Error thrown by sqlite-opfs when an encryption operation fails.
13
+ **/ export class SqliteEncryptionError extends Error {
14
+ code;
15
+ constructor(code, message, opts){
16
+ super(message, opts?.cause !== undefined ? {
17
+ cause: opts.cause
18
+ } : undefined);
19
+ this.name = 'SqliteEncryptionError';
20
+ this.code = code;
21
+ }
22
+ }
23
+ /**
24
+ * Strings raised by sqlite3mc when page 1 cannot be decoded.
25
+ **/ const SQLITE3MC_DECRYPT_ERROR_PATTERNS = [
26
+ /file is not a database/i,
27
+ /file is encrypted or is not a database/i
28
+ ];
29
+ /**
30
+ * Returns `true` if `message` matches one of the known sqlite3mc decrypt-failure
31
+ * strings.
32
+ **/ export function isDecryptFailureMessage(message) {
33
+ return SQLITE3MC_DECRYPT_ERROR_PATTERNS.some((p)=>p.test(message));
34
+ }
@@ -0,0 +1,16 @@
1
+ import { type Logger } from '@aztec/foundation/log';
2
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
3
+ import { AztecSQLiteOPFSStore } from './store.js';
4
+ export { AztecSQLiteOPFSStore } from './store.js';
5
+ export { SqliteEncryptionError } from './errors.js';
6
+ export type { SqliteEncryptionErrorCode } from './errors.js';
7
+ export declare function createStore(name: string, config: DataStoreConfig, schemaVersion?: number | undefined, log?: Logger): Promise<AztecSQLiteOPFSStore>;
8
+ export declare function openTmpStore(ephemeral?: boolean): Promise<AztecSQLiteOPFSStore>;
9
+ /**
10
+ * Convenience helper for tests and consumers that want an encrypted sqlite-opfs
11
+ * store without dealing with the full `open()` parameter order. Key must be 32
12
+ * bytes. Creates a fresh persistent store (sqlite3mc does not support encryption
13
+ * on ephemeral `:memory:` databases) in an auto-generated OPFS directory.
14
+ */
15
+ export declare function openEncryptedStore(encryptionKey: Uint8Array, name?: string, poolDirectory?: string): Promise<AztecSQLiteOPFSStore>;
16
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zcWxpdGUtb3Bmcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDb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E7D,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,EACvB,aAAa,GAAE,MAAM,GAAG,SAAqB,EAC7C,GAAG,GAAE,MAAiC,iCAUvC;AAED,wBAAgB,YAAY,CAAC,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAEtF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,iCAElG"}
@@ -0,0 +1,22 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { initStoreForRollupAndSchemaVersion } from '../utils.js';
3
+ import { AztecSQLiteOPFSStore } from './store.js';
4
+ export { AztecSQLiteOPFSStore } from './store.js';
5
+ export { SqliteEncryptionError } from './errors.js';
6
+ export async function createStore(name, config, schemaVersion = undefined, log = createLogger('kv-store')) {
7
+ const { dataDirectory } = config;
8
+ log.info(dataDirectory ? `Creating ${name} SQLite-OPFS data store with map size ${config.dataStoreMapSizeKb} KB` : `Creating ${name} ephemeral SQLite-OPFS data store with map size ${config.dataStoreMapSizeKb} KB`);
9
+ const store = await AztecSQLiteOPFSStore.open(createLogger('kv-store:sqlite-opfs'), name, false);
10
+ return initStoreForRollupAndSchemaVersion(store, schemaVersion, config.rollupAddress, log);
11
+ }
12
+ export function openTmpStore(ephemeral = false) {
13
+ return AztecSQLiteOPFSStore.open(createLogger('kv-store:sqlite-opfs'), undefined, ephemeral);
14
+ }
15
+ /**
16
+ * Convenience helper for tests and consumers that want an encrypted sqlite-opfs
17
+ * store without dealing with the full `open()` parameter order. Key must be 32
18
+ * bytes. Creates a fresh persistent store (sqlite3mc does not support encryption
19
+ * on ephemeral `:memory:` databases) in an auto-generated OPFS directory.
20
+ */ export function openEncryptedStore(encryptionKey, name, poolDirectory) {
21
+ return AztecSQLiteOPFSStore.open(createLogger('kv-store:sqlite-opfs'), name, false, poolDirectory, encryptionKey);
22
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Vendored from `ordered-binary@1.5.3/index.js` with one targeted edit:
3
+ * the `readString` definition (originally a dynamically-generated
4
+ * unrolled-loop function) is replaced with a hand-written interpreted
5
+ * equivalent that does the same work without code-generation-from-strings.
6
+ *
7
+ * Why vendor: upstream has no CSP-safe build, and the codegen is a
8
+ * module-init-time string-passed-to-evaluator that trips MV3 CSP
9
+ * (`script-src 'self' 'wasm-unsafe-eval'`). The codegen is a perf
10
+ * optimization on the string-decoding path only — the interpreted
11
+ * version is functionally identical, just slower per call.
12
+ *
13
+ * Parity with upstream is enforced by `ordered-binary-browser.test.ts`,
14
+ * which compares byte-exact output for a representative key set on every
15
+ * Node-mode test run. If `ordered-binary` is bumped, re-vendor by
16
+ * recopying upstream and reapplying the patch in the section marked
17
+ * `// CSP PATCH BEGIN` ... `// CSP PATCH END`.
18
+ */
19
+ export declare function writeKey(key: any, target: any, position: any, inSequence: any): any;
20
+ export declare function readKey(buffer: any, start: any, end: any, inSequence: any): any;
21
+ export declare const enableNullTermination: () => boolean;
22
+ export declare const encoder: {
23
+ writeKey: typeof writeKey;
24
+ readKey: typeof readKey;
25
+ enableNullTermination: () => boolean;
26
+ };
27
+ export declare const toBufferKey: (key: any) => any;
28
+ export declare const fromBufferKey: (sourceBuffer: any) => any;
29
+ export declare function compareKeys(a: any, b: any): any;
30
+ export declare const MINIMUM_KEY: null;
31
+ export declare const MAXIMUM_KEY: Uint8Array<ArrayBuffer>;
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3JkZXJlZC1iaW5hcnktYnJvd3Nlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3NxbGl0ZS1vcGZzL2ludGVybmFsL29yZGVyZWQtYmluYXJ5LWJyb3dzZXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0E7Ozs7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