@interncom/diplomatic 0.22.0 → 0.24.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/dist/cli/bun/src/crypto.d.ts +2 -3
- package/dist/cli/index.mjs +4 -5
- package/dist/cli/shared/api/peek.d.ts +9 -1
- package/dist/cli/shared/api/pull.d.ts +9 -1
- package/dist/cli/shared/api/push.d.ts +3 -1
- package/dist/cli/shared/api/user.d.ts +1 -1
- package/dist/cli/shared/auth.d.ts +2 -2
- package/dist/cli/shared/bag.d.ts +11 -6
- package/dist/cli/shared/client.d.ts +18 -9
- package/dist/cli/shared/codec.d.ts +4 -0
- package/dist/cli/shared/codecs/kdm.d.ts +7 -0
- package/dist/cli/shared/codecs/notifItem.d.ts +2 -0
- package/dist/cli/shared/crypto/bagman.d.ts +19 -0
- package/dist/cli/shared/crypto/binary.d.ts +1 -0
- package/dist/cli/shared/crypto/derivation.d.ts +45 -0
- package/dist/cli/shared/crypto/enclave.d.ts +31 -102
- package/dist/cli/shared/crypto/largeBlob.d.ts +8 -0
- package/dist/cli/shared/crypto/noble.d.ts +15 -22
- package/dist/cli/shared/crypto/pairing.d.ts +19 -2
- package/dist/cli/shared/crypto/prf.d.ts +52 -0
- package/dist/cli/shared/crypto/realms.d.ts +7 -0
- package/dist/cli/shared/endpoint.d.ts +4 -5
- package/dist/cli/shared/http.d.ts +12 -12
- package/dist/cli/shared/sync.d.ts +3 -3
- package/dist/cli/shared/types.d.ts +24 -16
- package/dist/cli/shared/webauthn/prf.d.ts +8 -0
- package/dist/cli/src/index.d.ts +6 -5
- package/dist/web/client.d.ts +18 -7
- package/dist/web/crypto.d.ts +2 -3
- package/dist/web/entdb/cached.d.ts +4 -0
- package/dist/web/entdb/entdb.d.ts +3 -0
- package/dist/web/entdb/idb.d.ts +8 -5
- package/dist/web/index.d.ts +11 -5
- package/dist/web/index.mjs +1 -1
- package/dist/web/objEq.d.ts +1 -0
- package/dist/web/passkey/prf-store.d.ts +26 -10
- package/dist/web/passkey/seed.d.ts +12 -6
- package/dist/web/shared/api/peek.d.ts +9 -1
- package/dist/web/shared/api/pull.d.ts +9 -1
- package/dist/web/shared/api/push.d.ts +3 -1
- package/dist/web/shared/api/user.d.ts +1 -1
- package/dist/web/shared/auth.d.ts +2 -2
- package/dist/web/shared/bag.d.ts +11 -6
- package/dist/web/shared/blobs.d.ts +25 -0
- package/dist/web/shared/client.d.ts +18 -9
- package/dist/web/shared/codec.d.ts +4 -0
- package/dist/web/shared/codecs/ent.d.ts +5 -0
- package/dist/web/shared/codecs/kdm.d.ts +7 -0
- package/dist/web/shared/codecs/notifItem.d.ts +2 -0
- package/dist/web/shared/crypto/bagman.d.ts +19 -0
- package/dist/web/shared/crypto/binary.d.ts +1 -0
- package/dist/web/shared/crypto/derivation.d.ts +45 -0
- package/dist/web/shared/crypto/enclave.d.ts +31 -102
- package/dist/web/shared/crypto/largeBlob.d.ts +8 -0
- package/dist/web/shared/crypto/noble.d.ts +15 -22
- package/dist/web/shared/crypto/pairing.d.ts +19 -2
- package/dist/web/shared/crypto/prf.d.ts +52 -0
- package/dist/web/shared/crypto/realms.d.ts +7 -0
- package/dist/web/shared/crypto/tty.d.ts +3 -0
- package/dist/web/shared/endpoint.d.ts +4 -5
- package/dist/web/shared/exim.d.ts +5 -5
- package/dist/web/shared/http.d.ts +12 -12
- package/dist/web/shared/storage/memory.d.ts +2 -2
- package/dist/web/shared/sync.d.ts +3 -3
- package/dist/web/shared/types.d.ts +24 -16
- package/dist/web/shared/webauthn/prf.d.ts +8 -0
- package/dist/web/state.d.ts +1 -2
- package/dist/web/stores/cursor.d.ts +30 -0
- package/dist/web/stores/idb/account.d.ts +58 -0
- package/dist/web/stores/idb/catalog.d.ts +1 -0
- package/dist/web/stores/idb/dnlds.d.ts +3 -2
- package/dist/web/stores/idb/hosts.d.ts +8 -7
- package/dist/web/stores/idb/idbutil.d.ts +2 -0
- package/dist/web/stores/idb/migrate.d.ts +2 -0
- package/dist/web/stores/idb/msgs.d.ts +1 -1
- package/dist/web/stores/idb/names.d.ts +13 -0
- package/dist/web/stores/idb/realms.d.ts +11 -0
- package/dist/web/stores/idb/store.d.ts +26 -19
- package/dist/web/stores/idb/uplds.d.ts +1 -1
- package/dist/web/stores/keyTag.d.ts +14 -0
- package/dist/web/stores/label.d.ts +3 -0
- package/dist/web/stores/memory/account.d.ts +14 -0
- package/dist/web/stores/memory/dnlds.d.ts +4 -2
- package/dist/web/stores/memory/hosts.d.ts +8 -6
- package/dist/web/stores/memory/realms.d.ts +10 -0
- package/dist/web/stores/memory/store.d.ts +6 -2
- package/dist/web/stores/realm.d.ts +35 -0
- package/dist/web/sync.d.ts +18 -16
- package/dist/web/types.d.ts +59 -18
- package/dist/web/worker/client.d.ts +7 -3
- package/dist/web/worker/protocol.d.ts +6 -0
- package/dist/web/worker/runtime.d.ts +4 -2
- package/dist/web/worker.mjs +1 -1
- package/package.json +1 -2
- package/dist/cli/bun/src/codec.d.ts +0 -3
- package/dist/web/stores/idb/seed.d.ts +0 -32
- package/dist/web/stores/identityPin.d.ts +0 -19
- package/dist/web/stores/memory/seed.d.ts +0 -13
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { Status } from "../../shared/consts";
|
|
1
2
|
import { ICrypto } from "../../shared/types";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { IDBSeedStore } from "./seed";
|
|
7
|
-
import { IDBUploadQueue } from "./uplds";
|
|
8
|
-
export declare const SEED_META_TABLE = "seedMeta";
|
|
3
|
+
import { type ValStat } from "../../shared/valstat";
|
|
4
|
+
import { IAccountStore, IDownloadQueue, IHostStore, IMessageStore, IStore, IUploadQueue } from "../../types";
|
|
5
|
+
import type { IRealmStore } from "../realm";
|
|
6
|
+
export declare const ACCOUNTS_TABLE = "accounts";
|
|
9
7
|
export declare const HOSTS_TABLE = "hosts";
|
|
8
|
+
/** Host-realm cursors. Key is host, realm label, realm index. */
|
|
9
|
+
export declare const HOST_SEQS_TABLE = "host_seqs";
|
|
10
10
|
export declare const UPLOAD_QUEUE_TABLE = "uploadQueue";
|
|
11
11
|
export declare const DOWNLOAD_QUEUE_TABLE = "downloadQueue";
|
|
12
12
|
export declare const MESSAGES_TABLE = "messages";
|
|
@@ -16,22 +16,29 @@ export declare const MESSAGES_TABLE = "messages";
|
|
|
16
16
|
* strings keep keys compact.
|
|
17
17
|
*/
|
|
18
18
|
export declare const MESSAGES_APLD_INDEX = "apld";
|
|
19
|
-
/**
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
19
|
+
/** Realm label. Default-realm rows omit rlm and are not in this index. */
|
|
20
|
+
export declare const MESSAGES_RLM_INDEX = "rlm";
|
|
21
|
+
export declare const REALMS_TABLE = "realms";
|
|
22
22
|
export declare class IDBStore implements IStore<URL> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
#private;
|
|
24
|
+
account: IAccountStore;
|
|
25
|
+
realms: IRealmStore;
|
|
26
|
+
hosts: IHostStore<URL>;
|
|
27
|
+
uploads: IUploadQueue;
|
|
28
|
+
downloads: IDownloadQueue;
|
|
29
|
+
messages: IMessageStore;
|
|
30
|
+
constructor(account: IAccountStore, crypto: ICrypto, lookup?: (label: string) => Promise<string | undefined>, db?: IDBDatabase);
|
|
31
|
+
bind(label: string): Promise<Status>;
|
|
32
|
+
prepareWorker(label: string): Promise<ValStat<{
|
|
33
|
+
data: string;
|
|
34
|
+
ents: string;
|
|
35
|
+
}>>;
|
|
36
|
+
close(): void;
|
|
30
37
|
/**
|
|
31
38
|
* Clear protocol tables only (not seed). Seed is wiped only via
|
|
32
|
-
* {@link
|
|
39
|
+
* {@link IAccountStore.wipe} when client.wipe({ seed: true }).
|
|
33
40
|
*/
|
|
34
41
|
wipe(): Promise<void>;
|
|
35
42
|
}
|
|
36
|
-
export declare function openIDBStoreDB(): Promise<IDBDatabase>;
|
|
37
43
|
export declare function openIDBStore(crypto: ICrypto): Promise<IDBStore>;
|
|
44
|
+
export declare function openBoundStore(crypto: ICrypto, data: string): Promise<IDBStore>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hash } from "../../shared/types";
|
|
2
2
|
import { IUploadQueue } from "../../types";
|
|
3
3
|
export declare class IDBUploadQueue implements IUploadQueue {
|
|
4
|
-
db
|
|
4
|
+
private db;
|
|
5
5
|
constructor(db: IDBDatabase);
|
|
6
6
|
enq(host: string, hshs: Iterable<Hash>): Promise<void>;
|
|
7
7
|
deq(host: string, hshs: Iterable<Hash>): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PDK } from "../shared/crypto/derivation";
|
|
2
|
+
import type { Enclave } from "../shared/crypto/enclave";
|
|
3
|
+
import type { ICrypto } from "../shared/types";
|
|
4
|
+
import { type ValStat } from "../shared/valstat";
|
|
5
|
+
/** Nonce plus the fingerprint child that names the master. */
|
|
6
|
+
export type KeyTag = {
|
|
7
|
+
n: Uint8Array;
|
|
8
|
+
h: PDK["Fingerprint"];
|
|
9
|
+
};
|
|
10
|
+
export declare function keyTagDigest(enclave: Enclave, nonce: Uint8Array): Promise<ValStat<PDK["Fingerprint"]>>;
|
|
11
|
+
export declare function makeKeyTag(crypto: ICrypto, enclave: Enclave): Promise<ValStat<KeyTag>>;
|
|
12
|
+
export declare function keyTagMatches(enclave: Enclave, tag: KeyTag): Promise<boolean>;
|
|
13
|
+
export declare function decodeKeyTag(raw: unknown): KeyTag | undefined;
|
|
14
|
+
export declare function cloneKeyTag(tag: KeyTag): KeyTag;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Enclave } from "../../shared/crypto/enclave";
|
|
2
|
+
import type { ICrypto } from "../../shared/types";
|
|
3
|
+
import { type ValStat } from "../../shared/valstat";
|
|
4
|
+
import type { IAccountStore, SetSeedOpts } from "../../types";
|
|
5
|
+
import { type KeyTag } from "../keyTag";
|
|
6
|
+
/** Account list in memory. One slot per label. The client holds the open account. */
|
|
7
|
+
export declare class MemoryAccountStore implements IAccountStore {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(crypto: ICrypto);
|
|
10
|
+
save(enclave: Enclave, opts?: SetSeedOpts): Promise<ValStat<Enclave>>;
|
|
11
|
+
wipe(): Promise<void>;
|
|
12
|
+
/** Test helper: snapshot of one account's key tag. Omitted label is "". */
|
|
13
|
+
peekKeyTag(label?: string): KeyTag | undefined;
|
|
14
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { IKDM } from "../../shared/codecs/kdm";
|
|
1
2
|
import { IDownloadMessage, IDownloadQueue } from "../../types";
|
|
3
|
+
import { type DownloadKey } from "../cursor";
|
|
2
4
|
export declare class MemoryDownloadQueue implements IDownloadQueue {
|
|
3
|
-
queue: Map<
|
|
5
|
+
queue: Map<DownloadKey, IDownloadMessage>;
|
|
4
6
|
enq(msgs: Iterable<IDownloadMessage>): Promise<void>;
|
|
5
|
-
deq(host: string, seqs: Iterable<number
|
|
7
|
+
deq(host: string, seqs: Iterable<number>, realm?: IKDM): Promise<void>;
|
|
6
8
|
list(): Promise<IDownloadMessage[]>;
|
|
7
9
|
count(): Promise<number>;
|
|
8
10
|
wipe(): Promise<void>;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
import type { IKDM } from "../../shared/codecs/kdm";
|
|
1
2
|
import { Status } from "../../shared/consts";
|
|
2
3
|
import { HostHandle, IHostConnectionInfo, IHostMetadata } from "../../shared/types";
|
|
3
|
-
import type {
|
|
4
|
+
import type { HostSeqsUpdate, IHostRow, IHostStore } from "../../types";
|
|
4
5
|
export declare class MemoryHostStore<Handle extends HostHandle> implements IHostStore<Handle> {
|
|
6
|
+
#private;
|
|
5
7
|
hosts: Map<string, IHostRow<Handle>>;
|
|
6
8
|
/**
|
|
7
|
-
* Upsert connection info. Same label + same handle/idx keeps
|
|
8
|
-
* host meta (safe re-link). Changing handle/idx
|
|
9
|
+
* Upsert connection info. Same label + same handle/idx keeps cursors and
|
|
10
|
+
* host meta (safe re-link). Changing handle/idx clears cursors.
|
|
9
11
|
*/
|
|
10
12
|
add(info: IHostConnectionInfo<Handle>): Promise<void>;
|
|
11
|
-
touch(label: string, seq: number): Promise<void>;
|
|
12
|
-
|
|
13
|
+
touch(label: string, seq: number, realm?: IKDM): Promise<void>;
|
|
14
|
+
recordSeqs(label: string, u: HostSeqsUpdate, realm?: IKDM): Promise<void>;
|
|
13
15
|
get(label: string): Promise<IHostRow<Handle> | undefined>;
|
|
14
16
|
set(label: string, meta: IHostMetadata): Promise<Status.Success | Status.NotFound>;
|
|
15
17
|
del(label: string): Promise<void>;
|
|
16
|
-
list(): Promise<
|
|
18
|
+
list(): Promise<IHostRow<Handle>[]>;
|
|
17
19
|
wipe(): Promise<void>;
|
|
18
20
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Status } from "../../shared/consts";
|
|
2
|
+
import { type IRealm, type IRealmStore } from "../realm";
|
|
3
|
+
/** Realm counters in memory. One store is one account. */
|
|
4
|
+
export declare class MemoryRealmStore implements IRealmStore {
|
|
5
|
+
#private;
|
|
6
|
+
list(): Promise<IRealm[]>;
|
|
7
|
+
get(label: string): Promise<IRealm | undefined>;
|
|
8
|
+
put(label: string, index: number): Promise<Status>;
|
|
9
|
+
wipe(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import { Status } from "../../shared/consts";
|
|
1
2
|
import { HostHandle, ICrypto } from "../../shared/types";
|
|
2
3
|
import { IStore } from "../../types";
|
|
3
4
|
import { MemoryDownloadQueue } from "./dnlds";
|
|
4
5
|
import { MemoryHostStore } from "./hosts";
|
|
5
6
|
import { MemoryMessageStore } from "./msgs";
|
|
6
|
-
import {
|
|
7
|
+
import { MemoryAccountStore } from "./account";
|
|
8
|
+
import { MemoryRealmStore } from "./realms";
|
|
7
9
|
import { MemoryUploadQueue } from "./uplds";
|
|
8
10
|
export declare class MemoryStore<Handle extends HostHandle> implements IStore<Handle> {
|
|
9
|
-
|
|
11
|
+
account: MemoryAccountStore;
|
|
12
|
+
realms: MemoryRealmStore;
|
|
10
13
|
hosts: MemoryHostStore<Handle>;
|
|
11
14
|
uploads: MemoryUploadQueue;
|
|
12
15
|
downloads: MemoryDownloadQueue;
|
|
13
16
|
messages: MemoryMessageStore;
|
|
14
17
|
constructor(crypto: ICrypto);
|
|
18
|
+
bind(): Promise<Status>;
|
|
15
19
|
wipe(): Promise<void>;
|
|
16
20
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Status } from "../shared/consts";
|
|
2
|
+
import { type ValStat } from "../shared/valstat";
|
|
3
|
+
declare const entRlmSymbol: unique symbol;
|
|
4
|
+
/** Non-empty realm label on an ent or archived message. */
|
|
5
|
+
export type EntRlm = string & {
|
|
6
|
+
readonly [entRlmSymbol]: true;
|
|
7
|
+
};
|
|
8
|
+
/** One realm. `index` is the current KDM counter; `prior` are older ones. */
|
|
9
|
+
export interface IRealm {
|
|
10
|
+
label: string;
|
|
11
|
+
index: number;
|
|
12
|
+
/** Counters older than `index` whose bags may still exist. */
|
|
13
|
+
prior?: number[];
|
|
14
|
+
}
|
|
15
|
+
/** Realm label for a row. The default realm ("" or missing) is omitted. */
|
|
16
|
+
export declare function realmLabel(raw: unknown): EntRlm | undefined;
|
|
17
|
+
/** Drops `rlm` when this row is in the default realm. */
|
|
18
|
+
export declare function omitDefaultRealm<T extends {
|
|
19
|
+
rlm?: EntRlm | string;
|
|
20
|
+
}>(row: T): T;
|
|
21
|
+
export declare function decodeRealm(raw: unknown): IRealm | undefined;
|
|
22
|
+
export declare function advanceRealm(label: string, prev: IRealm | undefined, index: number): ValStat<IRealm>;
|
|
23
|
+
/** Realm counters for one account. The store is that account. */
|
|
24
|
+
export interface IRealmStore {
|
|
25
|
+
list(): Promise<IRealm[]>;
|
|
26
|
+
/** One realm, or undefined when this account has no row for the label. */
|
|
27
|
+
get(label: string): Promise<IRealm | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Set the current index.
|
|
30
|
+
* A higher index keeps the previous one in `prior`.
|
|
31
|
+
*/
|
|
32
|
+
put(label: string, index: number): Promise<Status>;
|
|
33
|
+
wipe(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
package/dist/web/sync.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import DiplomaticClientAPI from "./shared/client";
|
|
2
|
+
import { type IKDM } from "./shared/codecs/kdm";
|
|
2
3
|
import { Status } from "./shared/consts";
|
|
3
|
-
import {
|
|
4
|
+
import type { BagManager } from "./shared/crypto/bagman";
|
|
4
5
|
import { Hash, HostHandle, IBag, ICrypto } from "./shared/types";
|
|
5
6
|
import { ValStat } from "./shared/valstat";
|
|
6
7
|
import { ProgressFn } from "./progress";
|
|
@@ -20,11 +21,10 @@ export type IPulled = {
|
|
|
20
21
|
bodyCph?: Uint8Array;
|
|
21
22
|
};
|
|
22
23
|
/** Host connection methods used by sync phases. */
|
|
23
|
-
export type SyncConn<Handle extends HostHandle> = Pick<DiplomaticClientAPI<Handle>, "pull" | "push" | "peek" | "seal" | "identity">;
|
|
24
|
+
export type SyncConn<Handle extends HostHandle> = Pick<DiplomaticClientAPI<Handle>, "pull" | "push" | "peek" | "seal" | "identity" | "hostRlm" | "bagMgrFor" | "bagMgrs">;
|
|
24
25
|
export interface ISyncParams<Handle extends HostHandle> {
|
|
25
26
|
conn: SyncConn<Handle>;
|
|
26
27
|
store: IStore<Handle>;
|
|
27
|
-
enclave: Enclave;
|
|
28
28
|
host: IHostRow<Handle>;
|
|
29
29
|
crypto: ICrypto;
|
|
30
30
|
/** Soft max sealed-bag bytes per push request. Oversized bags go alone. */
|
|
@@ -40,9 +40,11 @@ export interface ISyncParams<Handle extends HostHandle> {
|
|
|
40
40
|
* Default `defaultPeekConcurrency`. Set 1 for fully serial.
|
|
41
41
|
*/
|
|
42
42
|
peekConcurrency?: number;
|
|
43
|
+
/** Realm for this peek. Push and pull use each item's own realm. */
|
|
44
|
+
realm?: IKDM;
|
|
43
45
|
}
|
|
44
|
-
/** Push one batch of sealed bags; deq successes; advance
|
|
45
|
-
export declare function pushBatch<Handle extends HostHandle>(conn: Pick<DiplomaticClientAPI<Handle>, "push">, store: IStore<Handle>, hostLabel: string, bags: IBag[], hashes: Hash[]): Promise<Status>;
|
|
46
|
+
/** Push one batch of sealed bags; deq successes; advance that realm's cursor. */
|
|
47
|
+
export declare function pushBatch<Handle extends HostHandle>(conn: Pick<DiplomaticClientAPI<Handle>, "push">, store: IStore<Handle>, hostLabel: string, bags: IBag[], hashes: Hash[], realm?: IKDM): Promise<Status>;
|
|
46
48
|
/** pull: network only. Download-queue items → ciphertext (still enqueued). */
|
|
47
49
|
export declare function pullBodies<Handle extends HostHandle>(conn: Pick<DiplomaticClientAPI<Handle>, "pull">, items: IDownloadMessage[]): Promise<ValStat<IPulled[]>>;
|
|
48
50
|
export type IOpened = {
|
|
@@ -54,14 +56,14 @@ export type IOpened = {
|
|
|
54
56
|
* Bad bags are dequeued and skipped (not retry-able).
|
|
55
57
|
* Does not exec or push.
|
|
56
58
|
*/
|
|
57
|
-
export declare function openPulled<Handle extends HostHandle>(store: IStore<Handle>,
|
|
59
|
+
export declare function openPulled<Handle extends HostHandle>(store: IStore<Handle>, bagMgrs: readonly BagManager[], crypto: ICrypto, items: IPulled[]): Promise<ValStat<IOpened>>;
|
|
58
60
|
/**
|
|
59
61
|
* Drop download-queue rows whose head matches archive keys we just stored
|
|
60
62
|
* (import / local apply). One list() + batched deq — not per-row messages.has.
|
|
61
63
|
*/
|
|
62
64
|
export declare function deqDownloadsForHeadHashes<Handle extends HostHandle>(store: Pick<IStore<Handle>, "downloads">, hashes: Iterable<Hash>, crypto: ICrypto): Promise<void>;
|
|
63
65
|
/** Discover unseen bags and enqueue download work; advance host lastSeq. */
|
|
64
|
-
export declare function syncPeek<Handle extends HostHandle>({ conn, store,
|
|
66
|
+
export declare function syncPeek<Handle extends HostHandle>({ conn, store, host, crypto, onProgress, peekProgressEvery, peekConcurrency, realm: realmArg, }: ISyncParams<Handle>): Promise<Status>;
|
|
65
67
|
/** Seal and upload pending msgs; list once so concurrent enqs wait for next sync. */
|
|
66
68
|
export declare function syncPush<Handle extends HostHandle>({ conn, store, host, maxPushBytes, onProgress }: ISyncParams<Handle>): Promise<Status>;
|
|
67
69
|
/**
|
|
@@ -73,22 +75,22 @@ export declare function syncPush<Handle extends HostHandle>({ conn, store, host,
|
|
|
73
75
|
* All bags are still pulled/opened; EntDB LWW already ignores obsolete ops.
|
|
74
76
|
* Newest-first exec reaches final app state early in a large catch-up.
|
|
75
77
|
*/
|
|
76
|
-
export declare function syncPull<Handle extends HostHandle>({ conn, store,
|
|
78
|
+
export declare function syncPull<Handle extends HostHandle>({ conn, store, host, crypto, maxPullBytes, onProgress, }: ISyncParams<Handle>,
|
|
77
79
|
/** After each opened pull batch (e.g. drainApplyQueue / exec). */
|
|
78
80
|
afterOpen?: () => Promise<void>): Promise<Status>;
|
|
79
|
-
export declare function msg2StoredMsgData({ head, body }: IMsgParts): IStoredMessageWrite;
|
|
81
|
+
export declare function msg2StoredMsgData({ head, body }: IMsgParts, realm?: IKDM): IStoredMessageWrite;
|
|
80
82
|
/**
|
|
81
83
|
* notif → open inline bodies into archive; enq incomplete → scheduleSync.
|
|
82
84
|
* `scheduleSync` runs full peek/push/pull (or worker handoff).
|
|
83
85
|
*/
|
|
84
|
-
export declare function handleNotif<Handle extends HostHandle>(bytes: Uint8Array, { conn, store,
|
|
86
|
+
export declare function handleNotif<Handle extends HostHandle>(bytes: Uint8Array, { conn, store, host, crypto, onProgress, }: ISyncParams<Handle>, scheduleSync: () => void): Promise<void>;
|
|
85
87
|
/**
|
|
86
|
-
* Full host inventory (PEEK from seq 0): set
|
|
87
|
-
* downloads (msgs on host missing locally) and/or uploads
|
|
88
|
-
* on host). Returns ephemeral bag tallies + msgcheck (not
|
|
89
|
-
* pull/push beyond peek — caller should sync() to drain
|
|
88
|
+
* Full host inventory (PEEK from seq 0 in each realm): set that realm's cursor;
|
|
89
|
+
* optionally enqueue downloads (msgs on host missing locally) and/or uploads
|
|
90
|
+
* (local msgs missing on host). Returns ephemeral bag tallies + msgcheck (not
|
|
91
|
+
* persisted). Does not pull/push beyond peek — caller should sync() to drain.
|
|
90
92
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
+
* Each cursor is the max bag seq in that realm (0 if empty), including rewind
|
|
94
|
+
* when the host has fewer bags than a prior cursor believed.
|
|
93
95
|
*/
|
|
94
96
|
export declare function reconcileHost<Handle extends HostHandle>(params: ISyncParams<Handle>, opts?: ReconcileOpts): Promise<ValStat<ReconcileResult>>;
|
package/dist/web/types.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { SyncProgressEvent } from "./progress";
|
|
2
|
+
import type { IKDM } from "./shared/codecs/kdm";
|
|
2
3
|
import { Status } from "./shared/consts";
|
|
3
4
|
import type { Enclave } from "./shared/crypto/enclave";
|
|
5
|
+
import type { IBlobUpdate, IBlobWrite } from "./shared/blobs";
|
|
4
6
|
import type { EncodedMessage } from "./shared/message";
|
|
5
7
|
import type { EntityID, Hash, HostHandle, IDeleteParams, IEntRev, IHostConnectionInfo, IHostMetadata, IInsertParams, IMessageHead, IOp, IUpdateParams, SerializedContent } from "./shared/types";
|
|
6
8
|
import { ValStat } from "./shared/valstat";
|
|
7
9
|
import { ICrypto } from "./shared/types";
|
|
10
|
+
import { type EntRlm, type IRealm, type IRealmStore } from "./stores/realm";
|
|
8
11
|
export interface IMsgParts {
|
|
9
12
|
head: IMessageHead;
|
|
10
13
|
body?: EncodedMessage;
|
|
@@ -36,13 +39,18 @@ export type SetSeedOpts = {
|
|
|
36
39
|
* When true, request durable storage **if the store supports a non-plaintext
|
|
37
40
|
* durable form** (e.g. passkey largeBlob as IdentityBundle wire).
|
|
38
41
|
* IDB holds the enclave in memory only — durable identity is the PRF keyring
|
|
39
|
-
* via {@link
|
|
42
|
+
* via {@link IDBAccountStore.openPrfStore}, never plain seed.
|
|
40
43
|
* Default false (session enclave only).
|
|
41
44
|
*
|
|
42
45
|
* Future: when PRF is unavailable, durable path is passphrase-sealed meta
|
|
43
46
|
* (KDF + AEAD inside Enclave), not plain seed on disk.
|
|
44
47
|
*/
|
|
45
48
|
persist?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Account to install into. Omitted means the default account, "".
|
|
51
|
+
* A new label creates that account. An existing key tag must match.
|
|
52
|
+
*/
|
|
53
|
+
label?: string;
|
|
46
54
|
};
|
|
47
55
|
/**
|
|
48
56
|
* Selective wipe for {@link IClient.wipe}.
|
|
@@ -60,28 +68,44 @@ export type WipeOpts = {
|
|
|
60
68
|
/** Hosts + upload/download queues. Default true. */
|
|
61
69
|
meta?: boolean;
|
|
62
70
|
/**
|
|
63
|
-
* Seed / identity ({@link
|
|
71
|
+
* Seed / identity ({@link IAccountStore.wipe}). Default **false**.
|
|
64
72
|
* When true, passkey stores overwrite largeBlob (UV ceremony).
|
|
65
73
|
*/
|
|
66
74
|
seed?: boolean;
|
|
67
75
|
};
|
|
68
|
-
export interface
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
export interface IAccountStore {
|
|
77
|
+
/** Record this enclave's key tag under `opts.label`. Does not open the account. */
|
|
78
|
+
save: (enclave: Enclave, opts?: SetSeedOpts) => Promise<ValStat<Enclave>>;
|
|
71
79
|
/**
|
|
72
|
-
* Clear durable
|
|
73
|
-
*
|
|
80
|
+
* Clear durable account material (IDB rows, largeBlob overwrite, …).
|
|
81
|
+
* Called only when client.wipe({ seed: true }).
|
|
74
82
|
*/
|
|
75
83
|
wipe: () => Promise<void>;
|
|
76
84
|
}
|
|
85
|
+
/** Account the client is operating as. */
|
|
86
|
+
export type OpenAccount<H extends HostHandle> = {
|
|
87
|
+
label: string;
|
|
88
|
+
enclave: Enclave;
|
|
89
|
+
/** Host rows as of the last open, link, or unlink. */
|
|
90
|
+
hosts: IHostRow<H>[];
|
|
91
|
+
/** Realm rows from the realms table, refreshed with hosts and before sync. */
|
|
92
|
+
realms: IRealm[];
|
|
93
|
+
};
|
|
77
94
|
export interface IHostRow<Handle extends HostHandle> extends IHostConnectionInfo<Handle>, Partial<IHostMetadata> {
|
|
95
|
+
/** Default-realm cursor, joined from host_seqs on read. */
|
|
78
96
|
lastSeq: number;
|
|
97
|
+
/** Other realm cursors, joined from host_seqs on read. */
|
|
98
|
+
seqs?: {
|
|
99
|
+
label: string;
|
|
100
|
+
index: number;
|
|
101
|
+
lastSeq: number;
|
|
102
|
+
}[];
|
|
79
103
|
}
|
|
80
104
|
/**
|
|
81
105
|
* Host row cursor write (one store transaction).
|
|
82
106
|
* `lastSeq` only advances unless `setLastSeq` is set.
|
|
83
107
|
*/
|
|
84
|
-
export type
|
|
108
|
+
export type HostSeqsUpdate = {
|
|
85
109
|
/** New lastSeq if greater than current (incremental peek/push). */
|
|
86
110
|
lastSeq?: number;
|
|
87
111
|
/** Absolute lastSeq, including rewind (full inventory). */
|
|
@@ -94,9 +118,9 @@ export interface IHostStore<Handle extends HostHandle> {
|
|
|
94
118
|
set: (label: string, meta: IHostMetadata) => Promise<Status>;
|
|
95
119
|
list: () => Promise<Iterable<IHostRow<Handle>>>;
|
|
96
120
|
wipe: () => Promise<void>;
|
|
97
|
-
touch: (label: string, seq: number) => Promise<void>;
|
|
98
|
-
/** Apply
|
|
99
|
-
|
|
121
|
+
touch: (label: string, seq: number, realm?: IKDM) => Promise<void>;
|
|
122
|
+
/** Apply one host_seqs cursor. The default realm is nullKDM. */
|
|
123
|
+
recordSeqs: (label: string, u: HostSeqsUpdate, realm?: IKDM) => Promise<void>;
|
|
100
124
|
}
|
|
101
125
|
/** Options for {@link IClient.reconcile}. */
|
|
102
126
|
export type ReconcileOpts = {
|
|
@@ -152,10 +176,12 @@ export interface IDownloadMessage {
|
|
|
152
176
|
* blake3(headEnc). When set with headEnc, open skips re-hashing the head.
|
|
153
177
|
*/
|
|
154
178
|
headEncHash?: Hash;
|
|
179
|
+
/** Realm KDM. Omit for the default realm. */
|
|
180
|
+
realm?: IKDM;
|
|
155
181
|
}
|
|
156
182
|
export interface IDownloadQueue {
|
|
157
183
|
enq: (msgs: Iterable<IDownloadMessage>) => Promise<void>;
|
|
158
|
-
deq: (host: string, seqs: Iterable<number
|
|
184
|
+
deq: (host: string, seqs: Iterable<number>, realm?: IKDM) => Promise<void>;
|
|
159
185
|
list: () => Promise<Iterable<IDownloadMessage>>;
|
|
160
186
|
count: () => Promise<number>;
|
|
161
187
|
wipe(): Promise<void>;
|
|
@@ -180,6 +206,8 @@ export interface IStoredMessageFields {
|
|
|
180
206
|
/** Msg head typ. Omit when empty (raw). */
|
|
181
207
|
typ?: string;
|
|
182
208
|
body?: EncodedMessage;
|
|
209
|
+
/** Realm label. Omit for the default realm. */
|
|
210
|
+
rlm?: EntRlm;
|
|
183
211
|
}
|
|
184
212
|
/**
|
|
185
213
|
* What may come back from storage (pre-apld rows can omit the field).
|
|
@@ -194,7 +222,7 @@ export interface IStoredMessageData extends IStoredMessageFields {
|
|
|
194
222
|
/**
|
|
195
223
|
* Required shape for every put into the message archive (app/API layer).
|
|
196
224
|
* `apld` is required and must be one of the three {@link ApldState} values.
|
|
197
|
-
* Omit optional fields (`off`, `ctr`, `typ`, `body`, `err`) rather than storing empties.
|
|
225
|
+
* Omit optional fields (`off`, `ctr`, `typ`, `body`, `err`, `rlm`) rather than storing empties.
|
|
198
226
|
*/
|
|
199
227
|
export type IStoredMessageWrite = IStoredMessageFields & {
|
|
200
228
|
apld: ApldState;
|
|
@@ -211,6 +239,8 @@ export interface IStoredMessage {
|
|
|
211
239
|
body?: EncodedMessage;
|
|
212
240
|
/** Apply lifecycle — same {@link ApldState} as the archive row. */
|
|
213
241
|
apld: ApldState;
|
|
242
|
+
/** Realm label. Omitted for the default realm. */
|
|
243
|
+
rlm?: EntRlm;
|
|
214
244
|
/** Status code when apld is {@link APLD_ERROR}. */
|
|
215
245
|
err?: number;
|
|
216
246
|
}
|
|
@@ -276,13 +306,20 @@ export interface IMessageStore {
|
|
|
276
306
|
wipe(): Promise<void>;
|
|
277
307
|
}
|
|
278
308
|
export interface IStore<Handle extends HostHandle> {
|
|
279
|
-
|
|
309
|
+
account: IAccountStore;
|
|
310
|
+
/** Realm counters. Not cleared by {@link IStore.wipe}. */
|
|
311
|
+
realms: IRealmStore;
|
|
280
312
|
hosts: IHostStore<Handle>;
|
|
281
313
|
uploads: IUploadQueue;
|
|
282
314
|
downloads: IDownloadQueue;
|
|
283
315
|
messages: IMessageStore;
|
|
284
316
|
/**
|
|
285
|
-
*
|
|
317
|
+
* Open the protocol database for `label`.
|
|
318
|
+
* A store with one database returns Success.
|
|
319
|
+
*/
|
|
320
|
+
bind(label: string): Promise<Status>;
|
|
321
|
+
/**
|
|
322
|
+
* Clear protocol tables (hosts, queues, messages). Does not call account.wipe.
|
|
286
323
|
*/
|
|
287
324
|
wipe(): Promise<void>;
|
|
288
325
|
}
|
|
@@ -294,7 +331,7 @@ export interface IStateEmitter<T> {
|
|
|
294
331
|
}
|
|
295
332
|
export interface IClient<Handle extends HostHandle> {
|
|
296
333
|
/** Install session enclave (master seed stays inside enclave). */
|
|
297
|
-
setSeed(enclave: Enclave, opts?: SetSeedOpts): Promise<
|
|
334
|
+
setSeed(enclave: Enclave, opts?: SetSeedOpts): Promise<Status>;
|
|
298
335
|
link(host: IHostConnectionInfo<Handle>, connect?: boolean): Promise<void>;
|
|
299
336
|
unlink(label: string): Promise<void>;
|
|
300
337
|
/** Linked hosts from the protocol store (handle, label, lastSeq, …). */
|
|
@@ -303,12 +340,16 @@ export interface IClient<Handle extends HostHandle> {
|
|
|
303
340
|
disconnect(): Promise<void>;
|
|
304
341
|
insertRaw(content: SerializedContent, typ?: string): Promise<ValStat<IMessageHead>>;
|
|
305
342
|
updateRaw(prior: IEntRev, content: SerializedContent | undefined, force?: boolean, typ?: string): Promise<ValStat<IMessageHead>>;
|
|
306
|
-
insert
|
|
307
|
-
update
|
|
343
|
+
insert(op: IInsertParams<Uint8Array>): Promise<ValStat<IMessageHead>>;
|
|
344
|
+
update(op: IUpdateParams<Uint8Array>): Promise<ValStat<IMessageHead>>;
|
|
308
345
|
/**
|
|
309
346
|
* Delete by `{ prior }` (preferred) or `{ eid }` (archive lookup).
|
|
310
347
|
*/
|
|
311
348
|
delete(op: IDeleteParams): Promise<ValStat<IMessageHead>>;
|
|
349
|
+
insertBlob(mime: string, bytes: Uint8Array, opts?: IBlobWrite): Promise<ValStat<IMessageHead>>;
|
|
350
|
+
updateBlob(eid: EntityID, bytes: Uint8Array, opts?: IBlobUpdate): Promise<ValStat<IMessageHead>>;
|
|
351
|
+
deleteBlob(eid: EntityID): Promise<ValStat<IMessageHead>>;
|
|
352
|
+
readBlob(eid: EntityID): Promise<ValStat<Uint8Array>>;
|
|
312
353
|
/** Allocate an entity id (optional 8-byte id material; else random). */
|
|
313
354
|
genEID(id?: Uint8Array): Promise<ValStat<EntityID>>;
|
|
314
355
|
sync(): Promise<Status>;
|
|
@@ -30,6 +30,10 @@ export declare class WorkerClient implements IClient<URL> {
|
|
|
30
30
|
private store;
|
|
31
31
|
/** Main-thread writer: msg archive + local apply for fast UI. */
|
|
32
32
|
private local;
|
|
33
|
+
insertBlob: IClient<URL>["insertBlob"];
|
|
34
|
+
updateBlob: IClient<URL>["updateBlob"];
|
|
35
|
+
deleteBlob: IClient<URL>["deleteBlob"];
|
|
36
|
+
readBlob: IClient<URL>["readBlob"];
|
|
33
37
|
private nextId;
|
|
34
38
|
private pending;
|
|
35
39
|
/** Max wait for setSeed worker handshake. */
|
|
@@ -78,7 +82,7 @@ export declare class WorkerClient implements IClient<URL> {
|
|
|
78
82
|
* Persist seed on main, then Enclave.spawnSyncWorker (only worker spawn path).
|
|
79
83
|
* Awaits the worker's setSeed reply (worker boots, then applies seed).
|
|
80
84
|
*/
|
|
81
|
-
setSeed(enclave: Enclave, opts?: SetSeedOpts): Promise<
|
|
85
|
+
setSeed(enclave: Enclave, opts?: SetSeedOpts): Promise<Status>;
|
|
82
86
|
link(host: IHostConnectionInfo<URL>, connect?: boolean): Promise<void>;
|
|
83
87
|
unlink(label: string): Promise<void>;
|
|
84
88
|
/** Hosts live in shared main IDB (same as local writer). */
|
|
@@ -88,8 +92,8 @@ export declare class WorkerClient implements IClient<URL> {
|
|
|
88
92
|
/** Local UI write on main (cache notifies in apply's sync prefix); sync via worker. */
|
|
89
93
|
insertRaw(content: SerializedContent, typ?: string): Promise<ValStat<IMessageHead>>;
|
|
90
94
|
updateRaw(prior: IEntRev, content: SerializedContent | undefined, force?: boolean, typ?: string): Promise<ValStat<IMessageHead>>;
|
|
91
|
-
insert
|
|
92
|
-
update
|
|
95
|
+
insert(op: IInsertParams<Uint8Array>): Promise<ValStat<IMessageHead>>;
|
|
96
|
+
update(op: IUpdateParams<Uint8Array>): Promise<ValStat<IMessageHead>>;
|
|
93
97
|
delete(op: IDeleteParams): Promise<ValStat<IMessageHead>>;
|
|
94
98
|
genEID(id?: Uint8Array): Promise<ValStat<EntityID>>;
|
|
95
99
|
sync(): Promise<Status>;
|
|
@@ -3,14 +3,16 @@ import type { WorkerCmd, WorkerEvent } from "./protocol";
|
|
|
3
3
|
export type PostFn = (msg: WorkerEvent, transfer?: Transferable[]) => void;
|
|
4
4
|
export declare class WorkerRuntime {
|
|
5
5
|
private client;
|
|
6
|
+
private store;
|
|
6
7
|
private entDB;
|
|
8
|
+
private boundLabel;
|
|
7
9
|
private post;
|
|
8
|
-
/** Resolves when
|
|
10
|
+
/** Resolves when bind finishes (success or failure). Cmds wait on this. */
|
|
9
11
|
private whenReady;
|
|
10
12
|
private resolveReady;
|
|
11
13
|
private rejectReady;
|
|
12
14
|
constructor(post: PostFn);
|
|
13
|
-
|
|
15
|
+
private bindStores;
|
|
14
16
|
private markReady;
|
|
15
17
|
private failReady;
|
|
16
18
|
private requireClient;
|