@interncom/diplomatic 0.23.0 → 0.25.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.
Files changed (48) hide show
  1. package/dist/cli/index.mjs +2 -2
  2. package/dist/cli/shared/auth.d.ts +2 -2
  3. package/dist/cli/shared/bag.d.ts +7 -5
  4. package/dist/cli/shared/client.d.ts +10 -7
  5. package/dist/cli/shared/codec.d.ts +4 -0
  6. package/dist/cli/shared/codecs/kdm.d.ts +1 -0
  7. package/dist/cli/shared/crypto/bagman.d.ts +19 -0
  8. package/dist/cli/shared/crypto/binary.d.ts +1 -0
  9. package/dist/cli/shared/crypto/derivation.d.ts +1 -0
  10. package/dist/cli/shared/crypto/enclave.d.ts +25 -59
  11. package/dist/cli/shared/endpoint.d.ts +3 -4
  12. package/dist/cli/shared/sync.d.ts +2 -4
  13. package/dist/cli/shared/types.d.ts +0 -5
  14. package/dist/cli/src/index.d.ts +1 -1
  15. package/dist/web/client.d.ts +8 -2
  16. package/dist/web/entdb/idb.d.ts +1 -3
  17. package/dist/web/index.d.ts +5 -3
  18. package/dist/web/index.mjs +1 -1
  19. package/dist/web/objEq.d.ts +1 -0
  20. package/dist/web/shared/auth.d.ts +2 -2
  21. package/dist/web/shared/bag.d.ts +7 -5
  22. package/dist/web/shared/blobs.d.ts +25 -0
  23. package/dist/web/shared/client.d.ts +10 -7
  24. package/dist/web/shared/codec.d.ts +4 -0
  25. package/dist/web/shared/codecs/ent.d.ts +5 -0
  26. package/dist/web/shared/codecs/file.d.ts +2 -3
  27. package/dist/web/shared/codecs/fileHead.d.ts +6 -4
  28. package/dist/web/shared/codecs/fileIndexItem.d.ts +0 -1
  29. package/dist/web/shared/codecs/fileRealm.d.ts +9 -0
  30. package/dist/web/shared/codecs/kdm.d.ts +1 -0
  31. package/dist/web/shared/crypto/bagman.d.ts +19 -0
  32. package/dist/web/shared/crypto/binary.d.ts +1 -0
  33. package/dist/web/shared/crypto/derivation.d.ts +1 -0
  34. package/dist/web/shared/crypto/enclave.d.ts +25 -59
  35. package/dist/web/shared/crypto/exim.d.ts +22 -0
  36. package/dist/web/shared/crypto/export.d.ts +5 -0
  37. package/dist/web/shared/crypto/tty.d.ts +1 -1
  38. package/dist/web/shared/endpoint.d.ts +3 -4
  39. package/dist/web/shared/sync.d.ts +2 -4
  40. package/dist/web/shared/types.d.ts +0 -5
  41. package/dist/web/state.d.ts +1 -2
  42. package/dist/web/sync.d.ts +7 -8
  43. package/dist/web/types.d.ts +7 -2
  44. package/dist/web/worker/client.d.ts +6 -2
  45. package/dist/web/worker.mjs +1 -1
  46. package/package.json +1 -2
  47. package/dist/cli/bun/src/codec.d.ts +0 -3
  48. package/dist/web/shared/exim.d.ts +0 -24
@@ -0,0 +1 @@
1
+ export declare function objEq(a: unknown, b: unknown): boolean;
@@ -1,9 +1,9 @@
1
1
  import { IClock } from "./clock.ts";
2
2
  import { type IAuthTimestamp } from "./codecs/authTimestamp.ts";
3
3
  import { Status } from "./consts.ts";
4
- import type { Identity } from "./crypto/enclave.ts";
4
+ import type { BagManager } from "./crypto/bagman.ts";
5
5
  import type { IHostCrypto } from "./types.ts";
6
6
  import { ValStat } from "./valstat.ts";
7
7
  export type EncodedAuthTimestamp = Uint8Array;
8
- export declare function makeAuthTimestamp(identity: Pick<Identity, "publicKey" | "sign">, ts: Date): Promise<ValStat<IAuthTimestamp>>;
8
+ export declare function makeAuthTimestamp(identity: BagManager, ts: Date): Promise<ValStat<IAuthTimestamp>>;
9
9
  export declare function validateAuthTimestamp(authTS: IAuthTimestamp, crypto: IHostCrypto, clock: IClock): Promise<Status>;
@@ -1,19 +1,21 @@
1
- import type { IKDM } from "./codecs/kdm.ts";
2
1
  import { IMessageHead } from "./codecs/messageHead.ts";
3
2
  import type { HostRlm } from "./crypto/derivation.ts";
4
- import { type DecryptCipher, Enclave, type Identity } from "./crypto/enclave.ts";
3
+ import { BagManager } from "./crypto/bagman.ts";
5
4
  import { EncodedMessage } from "./message.ts";
6
5
  import { type ValStat } from "./valstat.ts";
7
6
  import type { Hash, IBag, ICrypto, IHostCrypto, IMessage, IMessageWithHash } from "./types.ts";
8
7
  export declare function bagSigMsg(rlm: HostRlm, headCph: Uint8Array): Uint8Array;
9
8
  export declare function bagSigValid(bag: IBag, verifyKey: CryptoKey, crypto: IHostCrypto): Promise<boolean>;
10
- export declare function sealBag(msg: IMessage, identity: Identity, crypto: ICrypto, enclave: Enclave, hostKDM?: IKDM, realmKDM?: IKDM): Promise<ValStat<IBag>>;
9
+ export declare function sealBag(msg: IMessage, bagMgr: BagManager, crypto: ICrypto): Promise<ValStat<IBag>>;
11
10
  export interface IOpenBag {
12
11
  msgHead: IMessageHead;
13
12
  bod?: EncodedMessage;
14
13
  headHash: Hash;
15
14
  }
16
- export declare function openBagBody(headEnc: Uint8Array, bodyCph: Uint8Array | undefined, cipher: DecryptCipher, crypto: ICrypto,
15
+ export type BagDecrypt = {
16
+ decrypt: (data: Uint8Array) => Promise<ValStat<Uint8Array>>;
17
+ };
18
+ export declare function openBagBody(headEnc: Uint8Array, bodyCph: Uint8Array | undefined, cipher: BagDecrypt, crypto: ICrypto,
17
19
  /** When set (e.g. from peek), skip blake3(headEnc). */
18
20
  headHashKnown?: Hash): Promise<ValStat<IOpenBag>>;
19
- export declare function openBag(bag: IBag, verifyKey: CryptoKey, crypto: ICrypto, enclave: Enclave, hostKDM?: IKDM, realms?: readonly IKDM[]): Promise<ValStat<IMessageWithHash>>;
21
+ export declare function openBag(bag: IBag, verifyKey: CryptoKey, crypto: ICrypto, bagMgr: BagManager): Promise<ValStat<IMessageWithHash>>;
@@ -0,0 +1,25 @@
1
+ import type { EntityID, IEntRev, IMessage, IMsgEntBody } from "./types.ts";
2
+ import { ValStat } from "./valstat.ts";
3
+ /** Head typ prefix. The rest is an app mime, such as "image/jpeg". */
4
+ export declare const blobPrefix = "blob:";
5
+ export declare function blobTyp(mime: string): string;
6
+ export declare function isBlobTyp(typ: string | undefined): typ is string;
7
+ export declare function mimeOf(typ: string | undefined): string | undefined;
8
+ export interface IBlobWrite {
9
+ tags?: string[];
10
+ pid?: EntityID;
11
+ }
12
+ export interface IBlobUpdate extends IBlobWrite {
13
+ mime?: string;
14
+ }
15
+ type BlobMsg = {
16
+ typ: string;
17
+ bod: Uint8Array;
18
+ };
19
+ export declare function openBlob(bod: Uint8Array): ValStat<IMsgEntBody<Uint8Array>>;
20
+ export declare function insertBlobMsg(mime: string, bytes: Uint8Array, opts?: IBlobWrite): ValStat<BlobMsg>;
21
+ export declare function updateBlobMsg(prev: IMessage | undefined, bytes: Uint8Array, opts?: IBlobUpdate): ValStat<BlobMsg & {
22
+ prior: IEntRev;
23
+ }>;
24
+ export declare function blobBytes(msg: IMessage | undefined): ValStat<Uint8Array>;
25
+ export {};
@@ -1,23 +1,26 @@
1
1
  import { IClock } from "./clock.ts";
2
- import type { IKDM } from "./codecs/kdm.ts";
2
+ import { type IKDM } from "./codecs/kdm.ts";
3
3
  import type { IBagPeekItem } from "./codecs/peekItem.ts";
4
4
  import type { IBagPullItem } from "./codecs/pullItem.ts";
5
5
  import { Status } from "./consts.ts";
6
- import { Enclave, type Identity } from "./crypto/enclave.ts";
6
+ import type { BagManager } from "./crypto/bagman.ts";
7
+ import type { Enclave } from "./crypto/enclave.ts";
7
8
  import { type HostRlm } from "./crypto/derivation.ts";
8
- import type { HostHandle, IBag, ICrypto, IHostConnectionInfo, IHostMetadata, IMessage, ITransport, PushReceiver } from "./types.ts";
9
+ import type { HostHandle, IBag, ICrypto, IHostMetadata, IMessage, ITransport, PushReceiver } from "./types.ts";
9
10
  import { ValStat } from "./valstat.ts";
11
+ export declare function hostBagMgrs(enclave: Enclave, idKDM: IKDM, realms?: readonly IKDM[]): Promise<ValStat<BagManager[]>>;
10
12
  export default class DiplomaticClientAPI<Handle extends HostHandle> {
11
13
  #private;
12
- enclave: Enclave;
13
14
  crypto: ICrypto;
14
- private host;
15
15
  clock: IClock;
16
16
  private transport;
17
17
  private updateHostMeta;
18
- constructor(enclave: Enclave, crypto: ICrypto, host: IHostConnectionInfo<Handle>, clock: IClock, transport: ITransport, updateHostMeta: (meta: IHostMetadata) => Promise<Status>);
18
+ constructor(bagMgrs: BagManager[], crypto: ICrypto, clock: IClock, transport: ITransport, updateHostMeta: (meta: IHostMetadata) => Promise<Status>);
19
19
  private call;
20
- identity: () => Promise<ValStat<Identity>>;
20
+ bagMgrFor(realm?: IKDM): BagManager | undefined;
21
+ bagMgrs(): readonly BagManager[];
22
+ add(bagMgr: BagManager): void;
23
+ identity: () => Promise<ValStat<BagManager>>;
21
24
  hostRlm: (realm?: IKDM) => Promise<ValStat<HostRlm>>;
22
25
  seal: (msg: IMessage, realm?: IKDM) => Promise<ValStat<IBag>>;
23
26
  register: () => Promise<ValStat<void>>;
@@ -14,12 +14,15 @@ export declare class Decoder {
14
14
  readDate(): ValStat<Date>;
15
15
  readVarInt(): ValStat<number>;
16
16
  readVarString(): ValStat<string>;
17
+ readVarStrings(): ValStat<string[]>;
17
18
  readBytes(num: number): ValStat<Uint8Array>;
18
19
  readVarBytes(): ValStat<Uint8Array>;
19
20
  readStruct<T>(codec: ICodecStruct<T>): ValStat<T>;
20
21
  readStructs<T>(codec: ICodecStruct<T>): ValStat<T[]>;
21
22
  readBytesSeq(len: number): ValStat<Uint8Array[]>;
22
23
  done(): boolean;
24
+ remaining(): number;
25
+ readRest(): Uint8Array;
23
26
  consumed(): number;
24
27
  }
25
28
  export declare class Encoder {
@@ -28,6 +31,7 @@ export declare class Encoder {
28
31
  writeDate(ts: Date): Status;
29
32
  writeVarInt(n: number): Status;
30
33
  writeVarString(s: string): Status;
34
+ writeVarStrings(strs: string[]): Status;
31
35
  prependBytes(bytes: Uint8Array): void;
32
36
  /**
33
37
  * Append a copy of `bytes`. Parts must not alias caller buffers — callers
@@ -0,0 +1,5 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ import { IMsgEntBody } from "../types.ts";
3
+ import { ValStat } from "../valstat.ts";
4
+ export declare const entCodec: ICodecStruct<IMsgEntBody<Uint8Array>>;
5
+ export declare function encodeEnt(ent: IMsgEntBody<Uint8Array>): ValStat<Uint8Array>;
@@ -1,8 +1,7 @@
1
1
  import { ICodecStruct } from "../codec.ts";
2
- import { IFileHead } from "./fileHead.ts";
2
+ import { type IFileHead } from "./fileHead.ts";
3
3
  export interface IFile {
4
4
  head: IFileHead;
5
- indexEnc: Uint8Array;
6
- bodyEnc: Uint8Array;
5
+ chunks: Uint8Array;
7
6
  }
8
7
  export declare const fileCodec: ICodecStruct<IFile>;
@@ -1,10 +1,12 @@
1
1
  import { ICodecStruct } from "../codec.ts";
2
- import { Hash } from "../types.ts";
2
+ import type { Hash } from "../types.ts";
3
+ import { type ValStat } from "../valstat.ts";
4
+ import { type IFileRealm } from "./fileRealm.ts";
3
5
  export interface IFileHead {
4
- lbl: string;
5
- idx: number;
6
- num: number;
6
+ nonce: Uint8Array;
7
+ realms: IFileRealm[];
7
8
  hsh: Hash;
8
9
  sig: Uint8Array;
9
10
  }
11
+ export declare function fileHeadPreimage(nonce: Uint8Array, realms: readonly IFileRealm[]): ValStat<Uint8Array>;
10
12
  export declare const fileHeadCodec: ICodecStruct<IFileHead>;
@@ -3,6 +3,5 @@ export interface IFileIndexItem {
3
3
  kdm: Uint8Array;
4
4
  headCph: Uint8Array;
5
5
  lenBody: number;
6
- offBody?: number;
7
6
  }
8
7
  export declare const fileIndexItemCodec: ICodecStruct<IFileIndexItem>;
@@ -0,0 +1,9 @@
1
+ import { ICodecStruct } from "../codec.ts";
2
+ import type { Hash } from "../types.ts";
3
+ import { type IKDM } from "./kdm.ts";
4
+ export interface IFileRealm {
5
+ realm: IKDM;
6
+ num: number;
7
+ hsh: Hash;
8
+ }
9
+ export declare const fileRealmCodec: ICodecStruct<IFileRealm>;
@@ -3,4 +3,5 @@ export interface IKDM {
3
3
  label: string;
4
4
  index: number;
5
5
  }
6
+ export declare function kdmEq(k1: IKDM, k2: IKDM): boolean;
6
7
  export declare const kdmCodec: ICodecStruct<IKDM>;
@@ -0,0 +1,19 @@
1
+ import type { IKDM } from "../codecs/kdm.ts";
2
+ import type { PublicKey } from "../types.ts";
3
+ import { type ValStat } from "../valstat.ts";
4
+ import type { HostRlm, PDK } from "./derivation.ts";
5
+ export declare class BagManager {
6
+ #private;
7
+ readonly publicKey: PublicKey;
8
+ private idnt;
9
+ private realm;
10
+ readonly rlm: HostRlm;
11
+ readonly idKDM: Readonly<IKDM>;
12
+ readonly realmKDM: Readonly<IKDM>;
13
+ private constructor();
14
+ static init(idnt: PDK["Identity"], realm: PDK["RealmKey"], rlm: HostRlm, idKDM: IKDM, realmKDM: IKDM): Promise<ValStat<BagManager>>;
15
+ sign(message: Uint8Array | string): Promise<ValStat<Uint8Array>>;
16
+ bagKDM(msgHeadEnc: Uint8Array): Promise<ValStat<Uint8Array>>;
17
+ encrypt(kdm: Uint8Array, data: Uint8Array): Promise<ValStat<Uint8Array>>;
18
+ decrypt(kdm: Uint8Array, data: Uint8Array): Promise<ValStat<Uint8Array>>;
19
+ }
@@ -0,0 +1 @@
1
+ export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
@@ -11,6 +11,7 @@ export declare const Purpose: {
11
11
  readonly RealmKey: "diplomatic.realmKey.v1";
12
12
  readonly RealmID: "diplomatic.realmID.v1";
13
13
  readonly HostRLM: "diplomatic.hostRLM.v1";
14
+ readonly Export: "diplomatic.export.v1";
14
15
  };
15
16
  export type Purpose = typeof Purpose[keyof typeof Purpose];
16
17
  declare const pdkSymbol: unique symbol;
@@ -1,61 +1,38 @@
1
1
  import type { BundleHost } from "../codecs/bundleHost.ts";
2
2
  import type { IKDM } from "../codecs/kdm.ts";
3
+ import type { MasterSeed, SealedMasterKey } from "../seed.ts";
4
+ import type { ValStat } from "../valstat.ts";
5
+ import type { PDK } from "./derivation.ts";
6
+ import type { DHKEReq, DHKEResp } from "./pairing.ts";
7
+ import type { LargeBlobCreateOpts, LargeBlobRp } from "../webauthn/largeBlob.ts";
8
+ import type { BindPrior, PasskeyPrfOpts, PrfBinding, PrfBound, PrfSealedMaster } from "./prf.ts";
3
9
  import { Status } from "../consts.ts";
4
- import { type MasterSeed, type SealedMasterKey } from "../seed.ts";
5
- import type { PublicKey } from "../types.ts";
6
- import { type ValStat } from "../valstat.ts";
7
- import { type HostRlm, type PDK } from "./derivation.ts";
8
- import { type DHKEReq, type DHKEResp, PairRequest } from "./pairing.ts";
9
- import { type LargeBlobCreateOpts, type LargeBlobRp } from "../webauthn/largeBlob.ts";
10
- import { type BindPrior, type PasskeyPrfOpts, type PrfBinding, type PrfBound, type PrfSealedMaster } from "./prf.ts";
11
- export type EncryptCipher = {
12
- encrypt: (data: Uint8Array) => Promise<ValStat<Uint8Array>>;
13
- };
14
- export type DecryptCipher = {
15
- decrypt: (data: Uint8Array) => Promise<ValStat<Uint8Array>>;
16
- };
17
- /** Encrypt + decrypt capability for one KDM. */
18
- export type DerivedCipher = EncryptCipher & DecryptCipher;
19
- /** Which ops the caller needs; only those methods are present on the handle. */
20
- export type CipherUsage = "encrypt" | "decrypt" | "both";
21
- /** Return shape of `deriveCipher` for a given usage (type-level enforcement). */
22
- export type CipherForUsage<U extends CipherUsage> = {
23
- encrypt: EncryptCipher;
24
- decrypt: DecryptCipher;
25
- both: DerivedCipher;
26
- }[U];
27
- /**
28
- * KDM-scoped signing identity: public key is public; sign/kdmFor re-enter
29
- * the enclave so the private key never leaves. Used for hosts, export files, etc.
30
- */
31
- export type Identity = {
32
- readonly publicKey: PublicKey;
33
- sign: (message: Uint8Array | string) => Promise<ValStat<Uint8Array>>;
34
- /** Per-bag 8-byte KDM (bag-kdm PDK child keyed by the encoded head). */
35
- kdmFor: (msgHeadEnc: Uint8Array) => Promise<ValStat<Uint8Array>>;
36
- };
10
+ import { PairRequest } from "./pairing.ts";
11
+ import { BagManager } from "./bagman.ts";
37
12
  /** Minimum musec length (Mandatory User-Space Entropy Contribution). */
38
13
  export declare const MUSEC_MIN_LEN = 32;
39
14
  export declare function fromSeedHosts(buf: Uint8Array): ValStat<{
40
- enclave: Enclave;
15
+ enclave: OuterEnclave;
41
16
  hosts: BundleHost[];
42
17
  }>;
43
18
  /** Brand `bytes` as {@link MasterSeed} only if length is {@link MASTER_SEED_LEN}. */
44
19
  export declare function asMasterSeed(bytes: Uint8Array): ValStat<MasterSeed>;
45
- export declare class Enclave {
20
+ declare class OuterEnclave {
46
21
  #private;
47
22
  private constructor();
48
23
  /**
49
24
  * New enclave: blake3(OS CSPRNG ‖ musec). musec is required (MUSEC_MIN_LEN).
50
- * Mix stays in this method; musec is wiped before return.
25
+ * Musec is wiped on every return, including rejection and a throw from the
26
+ * OS generator. A rejected digest is wiped. The stored seed is that digest
27
+ * buffer, so the success path must not wipe it.
51
28
  */
52
- static fromRandom(musec: Uint8Array): Promise<ValStat<Enclave>>;
29
+ static fromRandom(musec: Uint8Array): Promise<ValStat<OuterEnclave>>;
53
30
  /**
54
31
  * Construct from raw master seed bytes (import / bootstrap only).
55
32
  * Copies the seed so callers may zero their buffer after success.
56
33
  * Prefer {@link fromRandom} or {@link unsealWithPasskey} for normal flows.
57
34
  */
58
- static fromBytes(bytes: Uint8Array): ValStat<Enclave>;
35
+ static fromBytes(bytes: Uint8Array): ValStat<OuterEnclave>;
59
36
  /**
60
37
  * UV + PRF ceremony, then AEAD-seal master. Returns sealed ciphertext + public
61
38
  * meta only — never PRF output. Sealed blob on disk is useless without a
@@ -77,23 +54,23 @@ export declare class Enclave {
77
54
  static unsealWithPasskey(bindings: readonly PrfBinding[], opts: PasskeyPrfOpts & {
78
55
  salt: Uint8Array;
79
56
  }): Promise<ValStat<{
80
- enclave: Enclave;
57
+ enclave: OuterEnclave;
81
58
  credId: Uint8Array;
82
59
  }>>;
83
60
  /**
84
61
  * AEAD-seal master under caller-supplied PRF IKM (CLI hmac-secret).
85
62
  * Wipes `ikm` before return. Ciphertext only — never the seed.
86
63
  */
87
- sealWithIkm(ikm: Uint8Array): Promise<ValStat<SealedMasterKey>>;
64
+ sealWithIKM(ikm: Uint8Array): Promise<ValStat<SealedMasterKey>>;
88
65
  /**
89
66
  * Unseal a PRF binding given IKM (CLI hmac-secret eval). Returns Enclave.
90
67
  * Wipes `ikm` before return.
91
68
  */
92
- static unsealWithIkm(sealed: SealedMasterKey, ikm: Uint8Array): Promise<ValStat<Enclave>>;
69
+ static unsealWithIKM(sealed: SealedMasterKey, ikm: Uint8Array): Promise<ValStat<OuterEnclave>>;
93
70
  /**
94
71
  * UV + write IdentityBundle (seed + hosts) to largeBlob.
95
- * Encode stays here; {@link writeLargeBlob} does the UV write. Nothing
96
- * seed-bearing is returned. Prefer empty `hosts` for seed-only backup.
72
+ * Inner encodes the wire and {@link writeLargeBlob} does the UV write.
73
+ * Nothing seed-bearing is returned. Prefer empty `hosts` for seed-only backup.
97
74
  *
98
75
  * Pass `opts.credId` to write an existing credential (one UV). Omit it to
99
76
  * create a largeBlob-capable credential then write (two UV). Returns the
@@ -112,7 +89,7 @@ export declare class Enclave {
112
89
  static fromLargeBlob(opts?: LargeBlobRp & {
113
90
  credId?: Uint8Array;
114
91
  }): Promise<ValStat<{
115
- enclave: Enclave;
92
+ enclave: OuterEnclave;
116
93
  hosts: BundleHost[];
117
94
  credId: Uint8Array;
118
95
  }>>;
@@ -123,7 +100,7 @@ export declare class Enclave {
123
100
  * Paced mode erases the previous line before the next (Enter between).
124
101
  * Web bundles set DIP_CLI_DUMP=false; the write is compiled out.
125
102
  */
126
- dumpToTty(): Promise<Status>;
103
+ dumpToTTY(): Promise<Status>;
127
104
  static pairRequest(): Promise<ValStat<PairRequest>>;
128
105
  /**
129
106
  * Seals seed+hosts for dhkeReq. Returns dhkeResp to send back.
@@ -149,19 +126,8 @@ export declare class Enclave {
149
126
  id: number;
150
127
  persist?: boolean;
151
128
  }): Worker;
152
- realmID(realmKDM: IKDM): Promise<ValStat<PDK["RealmID"]>>;
153
- hostRlm(realmKDM: IKDM, hostKDM: IKDM): Promise<ValStat<PDK["HostRLM"]>>;
154
- realmForRlm(hostKDM: IKDM, rlm: HostRlm, realms: readonly IKDM[]): Promise<ValStat<IKDM>>;
155
- /**
156
- * Cipher for public KDM under a realm (default: nullKDM). Does not hold
157
- * key bytes; each op re-enters the enclave. `usage` selects the shape:
158
- * `"encrypt"` → `{ encrypt }`, `"decrypt"` → `{ decrypt }`, `"both"` → both.
159
- */
160
- deriveCipher<U extends CipherUsage>(kdm: Uint8Array, usage: U, realmKDM?: IKDM): CipherForUsage<U>;
161
- /**
162
- * Identity from the identity PDK + KDM. Private key stays in the enclave;
163
- * only publicKey and capability methods are returned.
164
- */
165
- deriveIdentity(kdm: IKDM): Promise<ValStat<Identity>>;
129
+ exportKey(nonce: Uint8Array): Promise<ValStat<PDK["Export"]>>;
130
+ bagman(idKDM: IKDM, realmKDM: IKDM): Promise<ValStat<BagManager>>;
166
131
  fingerprint(kdm?: Uint8Array | IKDM): Promise<ValStat<PDK["Fingerprint"]>>;
167
132
  }
133
+ export { OuterEnclave as Enclave };
@@ -0,0 +1,22 @@
1
+ import { type IKDM } from "../codecs/kdm.ts";
2
+ import { ICrypto, IMessageHead } from "../types.ts";
3
+ import { ValStat } from "../valstat.ts";
4
+ import { type PDK } from "./derivation.ts";
5
+ import { Enclave } from "./enclave.ts";
6
+ export interface IExportMsg {
7
+ head: IMessageHead;
8
+ body?: Uint8Array;
9
+ }
10
+ export interface IExportRealm {
11
+ realm: IKDM;
12
+ msgs: IExportMsg[];
13
+ }
14
+ export declare namespace Exim {
15
+ const defaultFileExtension = "dpl";
16
+ function exportNonce(file: Uint8Array): ValStat<Uint8Array>;
17
+ function sealExport(realms: Iterable<IExportRealm>, crypto: ICrypto, key: PDK["Export"], nonce: Uint8Array): Promise<ValStat<Uint8Array>>;
18
+ function exportFile(enclave: Enclave, crypto: ICrypto, realms: Iterable<IExportRealm>): Promise<ValStat<Uint8Array>>;
19
+ function encodeFile(realms: Iterable<IExportRealm>, crypto: ICrypto, key: PDK["Export"], nonce: Uint8Array): Promise<ValStat<Uint8Array>>;
20
+ function decodeFile(file: Uint8Array, crypto: ICrypto, key: PDK["Export"]): Promise<ValStat<IExportRealm[]>>;
21
+ function migrateFile(file: Uint8Array, crypto: ICrypto, keyIn: PDK["Export"], keyOut: PDK["Export"], nonce: Uint8Array, transform: (realms: Iterable<IExportRealm>) => Iterable<IExportRealm> | Promise<Iterable<IExportRealm>>): Promise<ValStat<Uint8Array>>;
22
+ }
@@ -0,0 +1,5 @@
1
+ import type { IKDM } from "../codecs/kdm.ts";
2
+ import { type ValStat } from "../valstat.ts";
3
+ import { BagManager } from "./bagman.ts";
4
+ import { type PDK } from "./derivation.ts";
5
+ export declare function bagmanForExport(key: PDK["Export"], realmKDM: IKDM): Promise<ValStat<BagManager>>;
@@ -1,3 +1,3 @@
1
1
  import { Status } from "../consts.ts";
2
2
  import { type ValStat } from "../valstat.ts";
3
- export declare function dumpToTty(seed: Uint8Array, fingerprint: () => Promise<ValStat<Uint8Array>>): Promise<Status>;
3
+ export declare function dumpToTTY(seed: Uint8Array, fingerprint: () => Promise<ValStat<Uint8Array>>): Promise<Status>;
@@ -2,21 +2,20 @@ import { IClock } from "./clock.ts";
2
2
  import { Decoder, Encoder } from "./codec.ts";
3
3
  import { IAuthTimestamp } from "./codecs/authTimestamp.ts";
4
4
  import { Status } from "./consts.ts";
5
- import { Enclave, type Identity } from "./crypto/enclave.ts";
5
+ import type { BagManager } from "./crypto/bagman.ts";
6
6
  import { ICrypto, IProtoHost } from "./types.ts";
7
7
  import { ValStat } from "./valstat.ts";
8
8
  interface IProtoClient {
9
9
  crypto: ICrypto;
10
- enclave: Enclave;
11
10
  clock: IClock;
12
11
  }
13
12
  export interface IAuthenticatedEndpoint<ReqInput, Resp> {
14
- encodeReq(client: IProtoClient, identity: Identity, authTS: IAuthTimestamp, body: ReqInput, reqEnc: Encoder): Promise<Status>;
13
+ encodeReq(client: IProtoClient, identity: BagManager, authTS: IAuthTimestamp, body: ReqInput, reqEnc: Encoder): Promise<Status>;
15
14
  handleReq(host: IProtoHost, reqDec: Decoder, respEnc: Encoder): Promise<Status>;
16
15
  decodeResp(respDec: Decoder): ValStat<Resp>;
17
16
  }
18
17
  export interface IAuthData {
19
- identity: Identity;
18
+ identity: BagManager;
20
19
  authTS: IAuthTimestamp;
21
20
  }
22
21
  export {};
@@ -1,11 +1,9 @@
1
1
  import { IBagPeekItem } from "./codecs/peekItem.ts";
2
- import type { IKDM } from "./codecs/kdm.ts";
3
- import { type HostRlm } from "./crypto/derivation.ts";
4
- import { Enclave } from "./crypto/enclave.ts";
2
+ import { BagManager } from "./crypto/bagman.ts";
5
3
  import { ICrypto } from "./types.ts";
6
4
  import { ValStat } from "./valstat.ts";
7
5
  export interface IDecryptedBagPeekItem {
8
6
  kdm: Uint8Array;
9
7
  headEnc: Uint8Array;
10
8
  }
11
- export declare function decryptPeekItem(item: IBagPeekItem, verifyKey: CryptoKey, enclave: Enclave, crypto: ICrypto, rlm: HostRlm, realm?: IKDM): Promise<ValStat<IDecryptedBagPeekItem>>;
9
+ export declare function decryptPeekItem(item: IBagPeekItem, verifyKey: CryptoKey, bagMgr: BagManager, crypto: ICrypto): Promise<ValStat<IDecryptedBagPeekItem>>;
@@ -151,11 +151,6 @@ export interface ICrypto extends IHostCrypto {
151
151
  signEd25519: (message: Uint8Array | string, secKey: PrivateKey) => Promise<Uint8Array>;
152
152
  blake3: (data: Uint8Array, opts?: Blake3Opts) => Promise<Hash>;
153
153
  }
154
- export interface IMsgpackCodec {
155
- encode: (source: unknown) => Uint8Array;
156
- decode: (packed: ArrayBuffer | Uint8Array) => unknown;
157
- decodeAsync: (stream: ReadableStream<Uint8Array>) => Promise<unknown>;
158
- }
159
154
  export interface IProtoHost {
160
155
  storage: IStorage;
161
156
  crypto: IHostCrypto;
@@ -1,8 +1,7 @@
1
1
  import { Status } from "./shared/consts";
2
- import { EntityID, IMessage, IMsgEntBody, IOp, IStateManager } from "./shared/types";
2
+ import { EntityID, IMessage, IOp, IStateManager } from "./shared/types";
3
3
  import { ValStat } from "./shared/valstat";
4
4
  import type { Applier } from "./types";
5
- export declare function isMsgEntBody(bodDec: unknown): bodDec is IMsgEntBody;
6
5
  export declare function msgToOp(msg: IMessage): ValStat<IOp>;
7
6
  type PeerIngestFn = (eids: Iterable<EntityID>) => Promise<void>;
8
7
  export declare class StateManager implements IStateManager {
@@ -1,7 +1,7 @@
1
1
  import DiplomaticClientAPI from "./shared/client";
2
- import type { IKDM } from "./shared/codecs/kdm";
2
+ import { type IKDM } from "./shared/codecs/kdm";
3
3
  import { Status } from "./shared/consts";
4
- import { Enclave } from "./shared/crypto/enclave";
4
+ import type { BagManager } from "./shared/crypto/bagman";
5
5
  import { Hash, HostHandle, IBag, ICrypto } from "./shared/types";
6
6
  import { ValStat } from "./shared/valstat";
7
7
  import { ProgressFn } from "./progress";
@@ -21,11 +21,10 @@ export type IPulled = {
21
21
  bodyCph?: Uint8Array;
22
22
  };
23
23
  /** Host connection methods used by sync phases. */
24
- export type SyncConn<Handle extends HostHandle> = Pick<DiplomaticClientAPI<Handle>, "pull" | "push" | "peek" | "seal" | "identity" | "hostRlm">;
24
+ export type SyncConn<Handle extends HostHandle> = Pick<DiplomaticClientAPI<Handle>, "pull" | "push" | "peek" | "seal" | "identity" | "hostRlm" | "bagMgrFor" | "bagMgrs">;
25
25
  export interface ISyncParams<Handle extends HostHandle> {
26
26
  conn: SyncConn<Handle>;
27
27
  store: IStore<Handle>;
28
- enclave: Enclave;
29
28
  host: IHostRow<Handle>;
30
29
  crypto: ICrypto;
31
30
  /** Soft max sealed-bag bytes per push request. Oversized bags go alone. */
@@ -57,14 +56,14 @@ export type IOpened = {
57
56
  * Bad bags are dequeued and skipped (not retry-able).
58
57
  * Does not exec or push.
59
58
  */
60
- export declare function openPulled<Handle extends HostHandle>(store: IStore<Handle>, enclave: Enclave, crypto: ICrypto, items: IPulled[]): Promise<ValStat<IOpened>>;
59
+ export declare function openPulled<Handle extends HostHandle>(store: IStore<Handle>, bagMgrs: readonly BagManager[], crypto: ICrypto, items: IPulled[]): Promise<ValStat<IOpened>>;
61
60
  /**
62
61
  * Drop download-queue rows whose head matches archive keys we just stored
63
62
  * (import / local apply). One list() + batched deq — not per-row messages.has.
64
63
  */
65
64
  export declare function deqDownloadsForHeadHashes<Handle extends HostHandle>(store: Pick<IStore<Handle>, "downloads">, hashes: Iterable<Hash>, crypto: ICrypto): Promise<void>;
66
65
  /** Discover unseen bags and enqueue download work; advance host lastSeq. */
67
- export declare function syncPeek<Handle extends HostHandle>({ conn, store, enclave, host, crypto, onProgress, peekProgressEvery, peekConcurrency, realm: realmArg, }: ISyncParams<Handle>): Promise<Status>;
66
+ export declare function syncPeek<Handle extends HostHandle>({ conn, store, host, crypto, onProgress, peekProgressEvery, peekConcurrency, realm: realmArg, }: ISyncParams<Handle>): Promise<Status>;
68
67
  /** Seal and upload pending msgs; list once so concurrent enqs wait for next sync. */
69
68
  export declare function syncPush<Handle extends HostHandle>({ conn, store, host, maxPushBytes, onProgress }: ISyncParams<Handle>): Promise<Status>;
70
69
  /**
@@ -76,7 +75,7 @@ export declare function syncPush<Handle extends HostHandle>({ conn, store, host,
76
75
  * All bags are still pulled/opened; EntDB LWW already ignores obsolete ops.
77
76
  * Newest-first exec reaches final app state early in a large catch-up.
78
77
  */
79
- export declare function syncPull<Handle extends HostHandle>({ conn, store, enclave, host, crypto, maxPullBytes, onProgress, }: ISyncParams<Handle>,
78
+ export declare function syncPull<Handle extends HostHandle>({ conn, store, host, crypto, maxPullBytes, onProgress, }: ISyncParams<Handle>,
80
79
  /** After each opened pull batch (e.g. drainApplyQueue / exec). */
81
80
  afterOpen?: () => Promise<void>): Promise<Status>;
82
81
  export declare function msg2StoredMsgData({ head, body }: IMsgParts, realm?: IKDM): IStoredMessageWrite;
@@ -84,7 +83,7 @@ export declare function msg2StoredMsgData({ head, body }: IMsgParts, realm?: IKD
84
83
  * notif → open inline bodies into archive; enq incomplete → scheduleSync.
85
84
  * `scheduleSync` runs full peek/push/pull (or worker handoff).
86
85
  */
87
- export declare function handleNotif<Handle extends HostHandle>(bytes: Uint8Array, { conn, store, enclave, host, crypto, onProgress, }: ISyncParams<Handle>, scheduleSync: () => void): Promise<void>;
86
+ export declare function handleNotif<Handle extends HostHandle>(bytes: Uint8Array, { conn, store, host, crypto, onProgress, }: ISyncParams<Handle>, scheduleSync: () => void): Promise<void>;
88
87
  /**
89
88
  * Full host inventory (PEEK from seq 0 in each realm): set that realm's cursor;
90
89
  * optionally enqueue downloads (msgs on host missing locally) and/or uploads
@@ -2,6 +2,7 @@ import type { SyncProgressEvent } from "./progress";
2
2
  import type { IKDM } from "./shared/codecs/kdm";
3
3
  import { Status } from "./shared/consts";
4
4
  import type { Enclave } from "./shared/crypto/enclave";
5
+ import type { IBlobUpdate, IBlobWrite } from "./shared/blobs";
5
6
  import type { EncodedMessage } from "./shared/message";
6
7
  import type { EntityID, Hash, HostHandle, IDeleteParams, IEntRev, IHostConnectionInfo, IHostMetadata, IInsertParams, IMessageHead, IOp, IUpdateParams, SerializedContent } from "./shared/types";
7
8
  import { ValStat } from "./shared/valstat";
@@ -339,12 +340,16 @@ export interface IClient<Handle extends HostHandle> {
339
340
  disconnect(): Promise<void>;
340
341
  insertRaw(content: SerializedContent, typ?: string): Promise<ValStat<IMessageHead>>;
341
342
  updateRaw(prior: IEntRev, content: SerializedContent | undefined, force?: boolean, typ?: string): Promise<ValStat<IMessageHead>>;
342
- insert<T = unknown>(op: IInsertParams<T>): Promise<ValStat<IMessageHead>>;
343
- update<T = unknown>(op: IUpdateParams<T>): Promise<ValStat<IMessageHead>>;
343
+ insert(op: IInsertParams<Uint8Array>): Promise<ValStat<IMessageHead>>;
344
+ update(op: IUpdateParams<Uint8Array>): Promise<ValStat<IMessageHead>>;
344
345
  /**
345
346
  * Delete by `{ prior }` (preferred) or `{ eid }` (archive lookup).
346
347
  */
347
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>>;
348
353
  /** Allocate an entity id (optional 8-byte id material; else random). */
349
354
  genEID(id?: Uint8Array): Promise<ValStat<EntityID>>;
350
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. */
@@ -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<T = unknown>(op: IInsertParams<T>): Promise<ValStat<IMessageHead>>;
92
- update<T = unknown>(op: IUpdateParams<T>): Promise<ValStat<IMessageHead>>;
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>;