@datafog/core-sqlite-browser 0.0.0-stage → 1.1.0
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.
- package/LICENSE +21 -0
- package/README.md +25 -2
- package/SQLITE3MC-LICENSE +21 -0
- package/THIRD_PARTY_NOTICES.md +23 -0
- package/binding.mjs +62 -0
- package/credentials.mjs +102 -0
- package/index.d.ts +92 -0
- package/index.mjs +361 -0
- package/package.json +41 -4
- package/sqlite3mc-lock.json +9 -0
- package/vault.mjs +80 -0
- package/vendor/sqlite3.mjs +14727 -0
- package/vendor/sqlite3.wasm +0 -0
- package/worker.mjs +108 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DataFog
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SQLite3 Multiple Ciphers browser Workspace owner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Optional encrypted browser persistence alongside FogVault. Core owns reversible mappings and review; the adapter saves the exact bundle before activation. This package uses SQLite3MC 2.6.1, authenticated ChaCha20-Poly1305, dedicated Worker, OPFS synchronous-access-handle pool, DELETE journal and FULL synchronization. It requires OPFS in a dedicated Worker; no memory or plaintext fallback is offered. Cross-origin isolation is not required by this profile.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import {init, Workspace} from '@datafog/wasm';
|
|
7
|
+
import {SQLiteVault, SQLiteWorkspace} from '@datafog/core-sqlite-browser';
|
|
8
|
+
await init();
|
|
9
|
+
const vault = await SQLiteVault.create({id: crypto.randomUUID().replaceAll('-', ''), password});
|
|
10
|
+
const owner = await SQLiteWorkspace.create({Workspace, vault, recordId, namespace});
|
|
11
|
+
const plan = owner.prepareReview(inputs, operationId);
|
|
12
|
+
showLocalReview(plan.preview());
|
|
13
|
+
// Only after explicit local approval of this exact plan:
|
|
14
|
+
const saved = await owner.commit(plan, {approved: true});
|
|
15
|
+
await owner.lock();
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Give the adapter exclusive ownership of the vault handle. Lock revokes Core immediately and terminates the database Worker. Reopen with `SQLiteVault.open`, then `SQLiteWorkspace.open` and trusted expected namespace/head. Passwords must be 12–1024 UTF-8 bytes; key wrapping uses PBKDF2-SHA256 (600,000 iterations) and AES-256-GCM. An optional independent random 32-byte `recoveryKey` can unwrap the database key on open. Store it separately. Browser IndexedDB stores authenticated wrapped keys; OPFS stores encrypted database pages. Neither store contains an unwrapped database key.
|
|
19
|
+
|
|
20
|
+
The host owns UI approval, credential entry, routing and actual transport. The adapter never sends a message. Conflicts and uncertain saves close the owner and authorize no handoff. Reopen durable state and reconcile the request ID; prepare and approve fresh work. Restoring a complete older valid browser profile is outside the unanchored offline rollback guarantee. Browser eviction and user deletion require separately retained backups.
|
|
21
|
+
|
|
22
|
+
Bundle `worker.mjs`, its imports and `vendor/sqlite3.mjs`/`.wasm` under the extension's own origin. Configure `workerUrl` if a bundler relocates assets. MV3 CSP needs `script-src 'self' 'wasm-unsafe-eval'; worker-src 'self'; connect-src 'self'`. Keep the owning page alive; service-worker memory is not persistence. The detector's Worker supplies findings and never owns this database.
|
|
23
|
+
|
|
24
|
+
Provision with `python3 scripts/provision-sqlite-browser.py`, build Core WASM, then run `node integrations/sqlite-browser/test/run-installed.mjs`. The check packs and installs candidates into a clean extension consumer; it does not provision assets. Keep package versions unchanged until release approval.
|
|
25
|
+
|
|
26
|
+
SQLite3MC upstream: https://github.com/utelle/SQLite3MultipleCiphers . Third-party notices must accompany shipped artifacts. Actual shipping-extension/device qualification remains distinct from synthetic Chromium tests.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2026 Ulrich Telle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Browser SQLite distribution
|
|
2
|
+
|
|
3
|
+
SQLite3 Multiple Ciphers 2.6.1: Copyright (c) 2019–2026 Ulrich Telle, MIT. See SQLITE3MC-LICENSE. Source and constituent cipher implementations: https://github.com/utelle/SQLite3MultipleCiphers/tree/v2.6.1 . SQLite is public domain. The distributed sqlite3.mjs preserves the upstream SQLite and Emscripten copyright and license notices.
|
|
4
|
+
|
|
5
|
+
The bundled upstream build includes cipher implementations beyond the one admitted by this adapter. Their notices remain applicable even though our supported API selects only authenticated ChaCha20-Poly1305. ChaCha20 sources: https://github.com/utelle/SQLite3MultipleCiphers/tree/v2.6.1/src/chacha20 . Emscripten glue is covered by the MIT and University of Illinois/NCSA licenses: https://emscripten.org/docs/introducing_emscripten/emscripten_license.html . The following files carry the upstream license texts for redistribution.
|
|
6
|
+
/*
|
|
7
|
+
* ISC License
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2013-2026
|
|
10
|
+
* Frank Denis <j at pureftpd dot org>
|
|
11
|
+
*
|
|
12
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
13
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
14
|
+
* copyright notice and this permission notice appear in all copies.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
17
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
19
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
20
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
21
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
22
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
23
|
+
*/
|
package/binding.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const DOMAIN = new TextEncoder().encode('DFSQL001');
|
|
2
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
3
|
+
|
|
4
|
+
export class WorkspaceVaultError extends Error {
|
|
5
|
+
constructor(code, requestId) {
|
|
6
|
+
super(`Core–SQLite integration: ${code}`);
|
|
7
|
+
this.name = 'WorkspaceVaultError';
|
|
8
|
+
this.code = code;
|
|
9
|
+
if (requestId instanceof Uint8Array && requestId.length === 16) this.requestId = requestId.slice();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function bytes16(value) {
|
|
14
|
+
if (!(value instanceof Uint8Array) || value.length !== 16 || !value.some(Boolean)) {
|
|
15
|
+
throw new WorkspaceVaultError('invalid_identity');
|
|
16
|
+
}
|
|
17
|
+
return value.slice();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function equalBytes(a, b) {
|
|
21
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function head(value) {
|
|
25
|
+
if (!value || typeof value.revision !== 'string' || value.revision.length > 20 || !/^(0|[1-9][0-9]*)$/.test(value.revision)) {
|
|
26
|
+
throw new WorkspaceVaultError('invalid_head');
|
|
27
|
+
}
|
|
28
|
+
const revision = BigInt(value.revision);
|
|
29
|
+
const commit = value.commitId;
|
|
30
|
+
if (revision > U64_MAX || !(commit instanceof Uint8Array || Array.isArray(commit)) ||
|
|
31
|
+
commit.length !== 16 || !Array.from(commit).every(x => Number.isInteger(x) && x >= 0 && x <= 255)) {
|
|
32
|
+
throw new WorkspaceVaultError('invalid_head');
|
|
33
|
+
}
|
|
34
|
+
return {revision: revision.toString(), commitId: Array.from(commit)};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function sameHead(a, b) {
|
|
38
|
+
const left = head(a), right = head(b);
|
|
39
|
+
return left.revision === right.revision && equalBytes(left.commitId, right.commitId);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function encodeBinding(namespace, recordId, parent, saved) {
|
|
43
|
+
const data = new Uint8Array(88), view = new DataView(data.buffer);
|
|
44
|
+
const before = head(parent), after = head(saved);
|
|
45
|
+
data.set(DOMAIN); data.set(bytes16(namespace), 8); data.set(bytes16(recordId), 24);
|
|
46
|
+
view.setBigUint64(40, BigInt(before.revision), true); data.set(before.commitId, 48);
|
|
47
|
+
view.setBigUint64(64, BigInt(after.revision), true); data.set(after.commitId, 72);
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function decodeBinding(value) {
|
|
52
|
+
if (!(value instanceof Uint8Array) || value.length !== 88 || !equalBytes(value.subarray(0, 8), DOMAIN) ||
|
|
53
|
+
!value.subarray(8, 24).some(Boolean) || !value.subarray(24, 40).some(Boolean)) {
|
|
54
|
+
throw new WorkspaceVaultError('invalid_binding');
|
|
55
|
+
}
|
|
56
|
+
const view = new DataView(value.buffer, value.byteOffset, value.byteLength);
|
|
57
|
+
return {
|
|
58
|
+
namespace: bytes16(value.subarray(8, 24)), recordId: bytes16(value.subarray(24, 40)),
|
|
59
|
+
parent: {revision: view.getBigUint64(40, true).toString(), commitId: Array.from(value.subarray(48, 64))},
|
|
60
|
+
saved: {revision: view.getBigUint64(64, true).toString(), commitId: Array.from(value.subarray(72, 88))},
|
|
61
|
+
};
|
|
62
|
+
}
|
package/credentials.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const ITERATIONS = 600000;
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
const fail = () => { throw Object.assign(new Error('Invalid vault credentials'), {code: 'invalid_credentials'}); };
|
|
4
|
+
const random = length => crypto.getRandomValues(new Uint8Array(length));
|
|
5
|
+
const context = id => encoder.encode(`datafog-sqlite-credentials-v1:${id}`);
|
|
6
|
+
async function wrappingKey(secret, salt, recovery) {
|
|
7
|
+
if (recovery) {
|
|
8
|
+
if (!(secret instanceof Uint8Array) || secret.length !== 32) fail();
|
|
9
|
+
return crypto.subtle.importKey('raw', secret, 'AES-GCM', false, ['encrypt', 'decrypt']);
|
|
10
|
+
}
|
|
11
|
+
if (typeof secret !== 'string' || secret.length < 12 || encoder.encode(secret).length > 1024) fail();
|
|
12
|
+
const bytes = encoder.encode(secret);
|
|
13
|
+
try {
|
|
14
|
+
const base = await crypto.subtle.importKey('raw', bytes, 'PBKDF2', false, ['deriveKey']);
|
|
15
|
+
return crypto.subtle.deriveKey({name: 'PBKDF2', hash: 'SHA-256', salt, iterations: ITERATIONS}, base,
|
|
16
|
+
{name: 'AES-GCM', length: 256}, false, ['encrypt', 'decrypt']);
|
|
17
|
+
} finally { bytes.fill(0); }
|
|
18
|
+
}
|
|
19
|
+
async function wrap(id, key, secret, recovery = false) {
|
|
20
|
+
const salt = random(16), iv = random(12), wrapping = await wrappingKey(secret, salt, recovery);
|
|
21
|
+
return {salt, iv, data: new Uint8Array(await crypto.subtle.encrypt({name: 'AES-GCM', iv, additionalData: context(id)}, wrapping, key))};
|
|
22
|
+
}
|
|
23
|
+
export async function makeEnvelope(id, key, password, recoveryKey, initialized) {
|
|
24
|
+
const envelope = {format: 1, id, iterations: ITERATIONS, password: await wrap(id, key, password),
|
|
25
|
+
...(recoveryKey ? {recovery: await wrap(id, key, recoveryKey, true)} : {})};
|
|
26
|
+
return initialized === undefined ? envelope : sealState(envelope, key, initialized);
|
|
27
|
+
}
|
|
28
|
+
export async function unlockEnvelope(id, envelope, password, recoveryKey) {
|
|
29
|
+
if (!envelope || envelope.format !== 1 || envelope.id !== id || envelope.iterations !== ITERATIONS) fail();
|
|
30
|
+
const recovery = recoveryKey !== undefined, entry = recovery ? envelope.recovery : envelope.password;
|
|
31
|
+
if (!entry || !(entry.salt instanceof Uint8Array) || entry.salt.length !== 16 ||
|
|
32
|
+
!(entry.iv instanceof Uint8Array) || entry.iv.length !== 12 || !(entry.data instanceof Uint8Array) || entry.data.length !== 48) fail();
|
|
33
|
+
try {
|
|
34
|
+
const wrapping = await wrappingKey(recovery ? recoveryKey : password, entry.salt, recovery);
|
|
35
|
+
const decoded = new Uint8Array(await crypto.subtle.decrypt({name: 'AES-GCM', iv: entry.iv, additionalData: context(id)}, wrapping, entry.data));
|
|
36
|
+
if (envelope.initialized !== undefined) {
|
|
37
|
+
try {
|
|
38
|
+
if (typeof envelope.initialized !== 'boolean' || !(envelope.stateTag instanceof Uint8Array) || envelope.stateTag.length !== 32) fail();
|
|
39
|
+
const stateKey = await crypto.subtle.importKey('raw', decoded, {name: 'HMAC', hash: 'SHA-256'}, false, ['verify']);
|
|
40
|
+
if (!await crypto.subtle.verify('HMAC', stateKey, envelope.stateTag, stateContext(envelope))) fail();
|
|
41
|
+
} catch { decoded.fill(0); fail(); }
|
|
42
|
+
}
|
|
43
|
+
return decoded;
|
|
44
|
+
} catch { fail(); }
|
|
45
|
+
}
|
|
46
|
+
export async function envelopeStore(id, value, replace = false) {
|
|
47
|
+
const db = await new Promise((resolve, reject) => {
|
|
48
|
+
const request = indexedDB.open('datafog-sqlite-credentials-v1', 1);
|
|
49
|
+
request.onupgradeneeded = () => request.result.createObjectStore('vaults');
|
|
50
|
+
request.onsuccess = () => resolve(request.result); request.onerror = () => reject(request.error);
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
return await new Promise((resolve, reject) => {
|
|
54
|
+
const transaction = db.transaction('vaults', value ? 'readwrite' : 'readonly');
|
|
55
|
+
const request = value ? transaction.objectStore('vaults')[replace ? 'put' : 'add'](value, id) : transaction.objectStore('vaults').get(id);
|
|
56
|
+
let result;
|
|
57
|
+
request.onsuccess = () => { result = request.result; };
|
|
58
|
+
transaction.oncomplete = () => resolve(result);
|
|
59
|
+
transaction.onabort = () => reject(Object.assign(new Error('Credential storage failed'), {code: 'credential_storage_failed'}));
|
|
60
|
+
transaction.onerror = () => {};
|
|
61
|
+
});
|
|
62
|
+
} finally { db.close(); }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const archiveContext = id => encoder.encode(`datafog-sqlite-backup-v1:${id}`);
|
|
66
|
+
export async function encryptArchive(id, data, password) {
|
|
67
|
+
const key = random(32), iv = random(12);
|
|
68
|
+
try {
|
|
69
|
+
const envelope = await makeEnvelope(id, key, password);
|
|
70
|
+
const cryptoKey = await crypto.subtle.importKey('raw', key, 'AES-GCM', false, ['encrypt']);
|
|
71
|
+
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({name: 'AES-GCM', iv, additionalData: archiveContext(id)}, cryptoKey, data));
|
|
72
|
+
const json = JSON.stringify({format: 'datafog-sqlite-backup-v1', id, envelope, iv, ciphertext}, (_, value) => value instanceof Uint8Array ? {$bytes: Array.from(value)} : value);
|
|
73
|
+
return encoder.encode(json);
|
|
74
|
+
} finally { key.fill(0); }
|
|
75
|
+
}
|
|
76
|
+
export async function decryptArchive(bytes, password) {
|
|
77
|
+
if (!(bytes instanceof Uint8Array) || bytes.length > 128 * 1024 * 1024) fail();
|
|
78
|
+
let archive;
|
|
79
|
+
try {
|
|
80
|
+
archive = JSON.parse(new TextDecoder('utf-8', {fatal: true}).decode(bytes), (_, value) => {
|
|
81
|
+
if (value && Object.hasOwn(value, '$bytes')) {
|
|
82
|
+
if (Object.keys(value).length !== 1 || !Array.isArray(value.$bytes) || !value.$bytes.every(x => Number.isInteger(x) && x >= 0 && x <= 255)) fail();
|
|
83
|
+
return Uint8Array.from(value.$bytes);
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
});
|
|
87
|
+
if (archive.format !== 'datafog-sqlite-backup-v1' || !/^[a-f0-9]{32}$/.test(archive.id) || !(archive.iv instanceof Uint8Array) || archive.iv.length !== 12 || !(archive.ciphertext instanceof Uint8Array)) fail();
|
|
88
|
+
const key = await unlockEnvelope(archive.id, archive.envelope, password);
|
|
89
|
+
try {
|
|
90
|
+
const cryptoKey = await crypto.subtle.importKey('raw', key, 'AES-GCM', false, ['decrypt']);
|
|
91
|
+
return new Uint8Array(await crypto.subtle.decrypt({name: 'AES-GCM', iv: archive.iv, additionalData: archiveContext(archive.id)}, cryptoKey, archive.ciphertext));
|
|
92
|
+
} finally { key.fill(0); }
|
|
93
|
+
} catch { fail(); }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const stateContext = envelope => encoder.encode(`datafog-sqlite-state-v1:${envelope.id}:${envelope.initialized}`);
|
|
97
|
+
export async function sealState(envelope, key, initialized) {
|
|
98
|
+
const value = {...envelope, initialized};
|
|
99
|
+
const stateKey = await crypto.subtle.importKey('raw', key, {name: 'HMAC', hash: 'SHA-256'}, false, ['sign']);
|
|
100
|
+
value.stateTag = new Uint8Array(await crypto.subtle.sign('HMAC', stateKey, stateContext(value)));
|
|
101
|
+
return value;
|
|
102
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Workspace, WorkspaceHead, PreparedWorkspaceChange, WorkspacePreview,
|
|
3
|
+
} from '@datafog/wasm';
|
|
4
|
+
export interface SQLiteReceipt {readonly revision: bigint;}
|
|
5
|
+
export class SQLiteVault {
|
|
6
|
+
private constructor();
|
|
7
|
+
static create(options: {id: string; password: string; recoveryKey?: Uint8Array; workerUrl?: URL; maxPayloadBytes?: number}): Promise<SQLiteVault>;
|
|
8
|
+
static open(options: {id: string; password?: string; recoveryKey?: Uint8Array; workerUrl?: URL; maxPayloadBytes?: number}): Promise<SQLiteVault>;
|
|
9
|
+
changePassword(options: {password: string; recoveryKey?: Uint8Array}): Promise<void>;
|
|
10
|
+
readonly locked: boolean;
|
|
11
|
+
readonly closed: boolean;
|
|
12
|
+
lock(): Promise<void>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
reconcileLatest(requestId: Uint8Array): Promise<{revision: bigint; found: boolean}>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class WorkspaceVaultError extends Error {readonly code: string; readonly requestId?: Uint8Array;}
|
|
18
|
+
/** One live prepared change per owner; discard unused plans promptly. */
|
|
19
|
+
export interface WorkspaceVaultPlan {
|
|
20
|
+
preview(): WorkspacePreview;
|
|
21
|
+
previews(): readonly WorkspacePreview[];
|
|
22
|
+
heads(): ReturnType<PreparedWorkspaceChange['heads']>;
|
|
23
|
+
snapshotFormat(): ReturnType<PreparedWorkspaceChange['snapshotFormat']>;
|
|
24
|
+
policyPreview(): ReturnType<PreparedWorkspaceChange['policyPreview']>;
|
|
25
|
+
sendIntents(): ReturnType<PreparedWorkspaceChange['sendIntents']>;
|
|
26
|
+
discard(): void;
|
|
27
|
+
}
|
|
28
|
+
export interface SavedWorkspaceChange {
|
|
29
|
+
readonly previews: readonly WorkspacePreview[];
|
|
30
|
+
readonly head: WorkspaceHead;
|
|
31
|
+
readonly recordRevision: bigint;
|
|
32
|
+
readonly receipt: SQLiteReceipt;
|
|
33
|
+
}
|
|
34
|
+
export interface WorkspaceVaultOptions {
|
|
35
|
+
/** Initialize the actual @datafog/wasm module before supplying its Workspace class. */
|
|
36
|
+
Workspace: typeof Workspace;
|
|
37
|
+
/** Already created/opened and unlocked owner; give the adapter exclusive mutation ownership. */
|
|
38
|
+
vault: SQLiteVault;
|
|
39
|
+
recordId: Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
export class SQLiteWorkspace {
|
|
42
|
+
private constructor();
|
|
43
|
+
static create(options: WorkspaceVaultOptions & {namespace: Uint8Array; operationId?: Uint8Array; requestId?: Uint8Array}): Promise<SQLiteWorkspace>;
|
|
44
|
+
static open(options: WorkspaceVaultOptions & {expectedNamespace?: Uint8Array; expectedHead?: WorkspaceHead}): Promise<SQLiteWorkspace>;
|
|
45
|
+
/** Host first authenticates/decrypts the source; this does not decrypt legacy encrypted backups. Destination record must be empty. */
|
|
46
|
+
static importAuthenticatedBundle(options: WorkspaceVaultOptions & {bundle: Uint8Array; expectedNamespace: Uint8Array; expectedHead: WorkspaceHead; operationId?: Uint8Array; requestId?: Uint8Array; approved: true}): Promise<SQLiteWorkspace>;
|
|
47
|
+
static importBackup(options: WorkspaceVaultOptions & {backup: Uint8Array; password: string; approved: true; operationId?: Uint8Array; requestId?: Uint8Array}): Promise<SQLiteWorkspace>;
|
|
48
|
+
exportBackup(options: {password: string}): Promise<Uint8Array>;
|
|
49
|
+
/** Replaces password wrapper and optional recovery wrapper atomically; omitted recoveryKey removes recovery. */
|
|
50
|
+
changePassword(options: {password: string; recoveryKey?: Uint8Array}): Promise<void>;
|
|
51
|
+
readonly closed: boolean;
|
|
52
|
+
commit(plan: WorkspaceVaultPlan, approval: {approved: true; requestId?: Uint8Array}): Promise<SavedWorkspaceChange>;
|
|
53
|
+
head: Workspace['head'];
|
|
54
|
+
namespace: Workspace['namespace'];
|
|
55
|
+
recordRevision(): bigint;
|
|
56
|
+
policy: Workspace['policy'];
|
|
57
|
+
recall: Workspace['recall'];
|
|
58
|
+
review: Workspace['review'];
|
|
59
|
+
operations: Workspace['operations'];
|
|
60
|
+
operationsPage: Workspace['operationsPage'];
|
|
61
|
+
counts: Workspace['counts'];
|
|
62
|
+
historyCoverage: Workspace['historyCoverage'];
|
|
63
|
+
conversation: Workspace['conversation'];
|
|
64
|
+
conversationForSite: Workspace['conversationForSite'];
|
|
65
|
+
sendIntentStatus: Workspace['sendIntentStatus'];
|
|
66
|
+
restore: Workspace['restore'];
|
|
67
|
+
restoreReport: Workspace['restoreReport'];
|
|
68
|
+
restoreInConversation: Workspace['restoreInConversation'];
|
|
69
|
+
restoreReportInConversation: Workspace['restoreReportInConversation'];
|
|
70
|
+
bufferedRestore: Workspace['bufferedRestore'];
|
|
71
|
+
progressiveRestore: Workspace['progressiveRestore'];
|
|
72
|
+
bufferedRestoreInConversation: Workspace['bufferedRestoreInConversation'];
|
|
73
|
+
progressiveRestoreInConversation: Workspace['progressiveRestoreInConversation'];
|
|
74
|
+
/** A second live preparation fails with resource_limit before Core clones state. */
|
|
75
|
+
prepare(...args: Parameters<Workspace['prepare']>): WorkspaceVaultPlan;
|
|
76
|
+
prepareBatch(...args: Parameters<Workspace['prepareBatch']>): WorkspaceVaultPlan;
|
|
77
|
+
prepareReview(...args: Parameters<Workspace['prepareReview']>): WorkspaceVaultPlan;
|
|
78
|
+
prepareConversationSend(...args: Parameters<Workspace['prepareConversationSend']>): WorkspaceVaultPlan;
|
|
79
|
+
prepareObservedSend(...args: Parameters<Workspace['prepareObservedSend']>): WorkspaceVaultPlan;
|
|
80
|
+
prepareDefinitelyNotSent(...args: Parameters<Workspace['prepareDefinitelyNotSent']>): WorkspaceVaultPlan;
|
|
81
|
+
preparePolicyChanges(...args: Parameters<Workspace['preparePolicyChanges']>): WorkspaceVaultPlan;
|
|
82
|
+
prepareOutcome(...args: Parameters<Workspace['prepareOutcome']>): WorkspaceVaultPlan;
|
|
83
|
+
/** Persist mapping retirement before activating it; old markers remain expired after reopen. */
|
|
84
|
+
prepareForget(...args: Parameters<Workspace['prepareForget']>): WorkspaceVaultPlan;
|
|
85
|
+
prepareRecovery(...args: Parameters<Workspace['prepareRecovery']>): WorkspaceVaultPlan;
|
|
86
|
+
prepareWithOperation(...args: Parameters<Workspace['prepareWithOperation']>): WorkspaceVaultPlan;
|
|
87
|
+
prepareBatchWithOperation(...args: Parameters<Workspace['prepareBatchWithOperation']>): WorkspaceVaultPlan;
|
|
88
|
+
prepareRecoveryWithOperation(...args: Parameters<Workspace['prepareRecoveryWithOperation']>): WorkspaceVaultPlan;
|
|
89
|
+
/** Close Core synchronously; Promise covers only SQLite cleanup. Caller copies remain caller owned. */
|
|
90
|
+
lock(): Promise<void>;
|
|
91
|
+
close(): Promise<void>;
|
|
92
|
+
}
|