@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.
Files changed (98) hide show
  1. package/dist/cli/bun/src/crypto.d.ts +2 -3
  2. package/dist/cli/index.mjs +4 -5
  3. package/dist/cli/shared/api/peek.d.ts +9 -1
  4. package/dist/cli/shared/api/pull.d.ts +9 -1
  5. package/dist/cli/shared/api/push.d.ts +3 -1
  6. package/dist/cli/shared/api/user.d.ts +1 -1
  7. package/dist/cli/shared/auth.d.ts +2 -2
  8. package/dist/cli/shared/bag.d.ts +11 -6
  9. package/dist/cli/shared/client.d.ts +18 -9
  10. package/dist/cli/shared/codec.d.ts +4 -0
  11. package/dist/cli/shared/codecs/kdm.d.ts +7 -0
  12. package/dist/cli/shared/codecs/notifItem.d.ts +2 -0
  13. package/dist/cli/shared/crypto/bagman.d.ts +19 -0
  14. package/dist/cli/shared/crypto/binary.d.ts +1 -0
  15. package/dist/cli/shared/crypto/derivation.d.ts +45 -0
  16. package/dist/cli/shared/crypto/enclave.d.ts +31 -102
  17. package/dist/cli/shared/crypto/largeBlob.d.ts +8 -0
  18. package/dist/cli/shared/crypto/noble.d.ts +15 -22
  19. package/dist/cli/shared/crypto/pairing.d.ts +19 -2
  20. package/dist/cli/shared/crypto/prf.d.ts +52 -0
  21. package/dist/cli/shared/crypto/realms.d.ts +7 -0
  22. package/dist/cli/shared/endpoint.d.ts +4 -5
  23. package/dist/cli/shared/http.d.ts +12 -12
  24. package/dist/cli/shared/sync.d.ts +3 -3
  25. package/dist/cli/shared/types.d.ts +24 -16
  26. package/dist/cli/shared/webauthn/prf.d.ts +8 -0
  27. package/dist/cli/src/index.d.ts +6 -5
  28. package/dist/web/client.d.ts +18 -7
  29. package/dist/web/crypto.d.ts +2 -3
  30. package/dist/web/entdb/cached.d.ts +4 -0
  31. package/dist/web/entdb/entdb.d.ts +3 -0
  32. package/dist/web/entdb/idb.d.ts +8 -5
  33. package/dist/web/index.d.ts +11 -5
  34. package/dist/web/index.mjs +1 -1
  35. package/dist/web/objEq.d.ts +1 -0
  36. package/dist/web/passkey/prf-store.d.ts +26 -10
  37. package/dist/web/passkey/seed.d.ts +12 -6
  38. package/dist/web/shared/api/peek.d.ts +9 -1
  39. package/dist/web/shared/api/pull.d.ts +9 -1
  40. package/dist/web/shared/api/push.d.ts +3 -1
  41. package/dist/web/shared/api/user.d.ts +1 -1
  42. package/dist/web/shared/auth.d.ts +2 -2
  43. package/dist/web/shared/bag.d.ts +11 -6
  44. package/dist/web/shared/blobs.d.ts +25 -0
  45. package/dist/web/shared/client.d.ts +18 -9
  46. package/dist/web/shared/codec.d.ts +4 -0
  47. package/dist/web/shared/codecs/ent.d.ts +5 -0
  48. package/dist/web/shared/codecs/kdm.d.ts +7 -0
  49. package/dist/web/shared/codecs/notifItem.d.ts +2 -0
  50. package/dist/web/shared/crypto/bagman.d.ts +19 -0
  51. package/dist/web/shared/crypto/binary.d.ts +1 -0
  52. package/dist/web/shared/crypto/derivation.d.ts +45 -0
  53. package/dist/web/shared/crypto/enclave.d.ts +31 -102
  54. package/dist/web/shared/crypto/largeBlob.d.ts +8 -0
  55. package/dist/web/shared/crypto/noble.d.ts +15 -22
  56. package/dist/web/shared/crypto/pairing.d.ts +19 -2
  57. package/dist/web/shared/crypto/prf.d.ts +52 -0
  58. package/dist/web/shared/crypto/realms.d.ts +7 -0
  59. package/dist/web/shared/crypto/tty.d.ts +3 -0
  60. package/dist/web/shared/endpoint.d.ts +4 -5
  61. package/dist/web/shared/exim.d.ts +5 -5
  62. package/dist/web/shared/http.d.ts +12 -12
  63. package/dist/web/shared/storage/memory.d.ts +2 -2
  64. package/dist/web/shared/sync.d.ts +3 -3
  65. package/dist/web/shared/types.d.ts +24 -16
  66. package/dist/web/shared/webauthn/prf.d.ts +8 -0
  67. package/dist/web/state.d.ts +1 -2
  68. package/dist/web/stores/cursor.d.ts +30 -0
  69. package/dist/web/stores/idb/account.d.ts +58 -0
  70. package/dist/web/stores/idb/catalog.d.ts +1 -0
  71. package/dist/web/stores/idb/dnlds.d.ts +3 -2
  72. package/dist/web/stores/idb/hosts.d.ts +8 -7
  73. package/dist/web/stores/idb/idbutil.d.ts +2 -0
  74. package/dist/web/stores/idb/migrate.d.ts +2 -0
  75. package/dist/web/stores/idb/msgs.d.ts +1 -1
  76. package/dist/web/stores/idb/names.d.ts +13 -0
  77. package/dist/web/stores/idb/realms.d.ts +11 -0
  78. package/dist/web/stores/idb/store.d.ts +26 -19
  79. package/dist/web/stores/idb/uplds.d.ts +1 -1
  80. package/dist/web/stores/keyTag.d.ts +14 -0
  81. package/dist/web/stores/label.d.ts +3 -0
  82. package/dist/web/stores/memory/account.d.ts +14 -0
  83. package/dist/web/stores/memory/dnlds.d.ts +4 -2
  84. package/dist/web/stores/memory/hosts.d.ts +8 -6
  85. package/dist/web/stores/memory/realms.d.ts +10 -0
  86. package/dist/web/stores/memory/store.d.ts +6 -2
  87. package/dist/web/stores/realm.d.ts +35 -0
  88. package/dist/web/sync.d.ts +18 -16
  89. package/dist/web/types.d.ts +59 -18
  90. package/dist/web/worker/client.d.ts +7 -3
  91. package/dist/web/worker/protocol.d.ts +6 -0
  92. package/dist/web/worker/runtime.d.ts +4 -2
  93. package/dist/web/worker.mjs +1 -1
  94. package/package.json +1 -2
  95. package/dist/cli/bun/src/codec.d.ts +0 -3
  96. package/dist/web/stores/idb/seed.d.ts +0 -32
  97. package/dist/web/stores/identityPin.d.ts +0 -19
  98. package/dist/web/stores/memory/seed.d.ts +0 -13
@@ -1,24 +1,17 @@
1
1
  import { type X25519Sk } from "./x25519.ts";
2
2
  import type { Blake3Opts, DerivationSeed, Hash, ICrypto, KeyPair } from "../types.ts";
3
- /**
4
- * ICrypto: noble for XSalsa20 + blake3; WebCrypto Ed25519 + X25519
5
- * (our scalar; RFC 7748 check before trusting pub/DH).
6
- */
7
- export declare class NobleCrypto implements ICrypto {
8
- private verifyKeys;
9
- genRandomBytes(bytes: number): Promise<Uint8Array>;
10
- gen256BitSecureRandomSeed(): Promise<Uint8Array>;
11
- encryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
12
- decryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
13
- deriveEd25519KeyPair(derivationSeed: DerivationSeed): Promise<KeyPair>;
14
- private importSignKey;
15
- private importVerifyKey;
16
- signEd25519(message: Uint8Array | string, secKey: Uint8Array): Promise<Uint8Array>;
17
- checkSigEd25519(sig: Uint8Array, message: Uint8Array | string, pubKey: Uint8Array): Promise<boolean>;
18
- blake3(data: Uint8Array, opts?: Blake3Opts): Promise<Hash>;
19
- genX25519(): Promise<{
20
- priv: X25519Sk;
21
- pub: Uint8Array;
22
- }>;
23
- x25519Shared(priv: X25519Sk, peerPub: Uint8Array): Promise<Uint8Array>;
24
- }
3
+ export declare function genRandomBytes(bytes: number): Promise<Uint8Array>;
4
+ export declare function gen256BitSecureRandomSeed(): Promise<Uint8Array>;
5
+ export declare function encryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
6
+ export declare function decryptXSalsa20Poly1305Combined(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
7
+ export declare function deriveEd25519KeyPair(derivationSeed: DerivationSeed): Promise<KeyPair>;
8
+ export declare function importVerifyKey(pubKey: Uint8Array): Promise<CryptoKey>;
9
+ export declare function signEd25519(message: Uint8Array | string, secKey: Uint8Array): Promise<Uint8Array>;
10
+ export declare function checkSigEd25519(sig: Uint8Array, message: Uint8Array | string, verifyKey: CryptoKey): Promise<boolean>;
11
+ export declare function blake3(data: Uint8Array, opts?: Blake3Opts): Promise<Hash>;
12
+ export declare function genX25519(): Promise<{
13
+ priv: X25519Sk;
14
+ pub: Uint8Array;
15
+ }>;
16
+ export declare function x25519Shared(priv: X25519Sk, peerPub: Uint8Array): Promise<Uint8Array>;
17
+ export declare const noble: ICrypto;
@@ -1,6 +1,8 @@
1
+ import type { BundleHost } from "../codecs/bundleHost.ts";
1
2
  import { type ValStat } from "../valstat.ts";
3
+ import { type PDK } from "./derivation.ts";
4
+ import type { Enclave } from "./enclave.ts";
2
5
  import type { X25519Sk } from "./x25519.ts";
3
- export declare const SEAL_PAIR_DOMAIN: Uint8Array<ArrayBufferLike>;
4
6
  export declare const X25519_PUB_LEN = 32;
5
7
  /** respPub (32) ‖ XSalsa nonce (24) ‖ tag (16); plaintext follows in the ct. */
6
8
  export declare const DHKE_RESP_MIN: number;
@@ -17,5 +19,20 @@ export declare function asDHKEResp(bytes: Uint8Array): ValStat<DHKEResp>;
17
19
  export declare function pairKey(sk: X25519Sk, // local X25519 priv
18
20
  peer: Uint8Array, // ECDH peer pub (enroller: dhkeReq; enrollee: respPub)
19
21
  reqPub: Uint8Array, // enrollee pub, bound into KDF
20
- respPub: Uint8Array): Promise<ValStat<Uint8Array>>;
22
+ respPub: Uint8Array): Promise<ValStat<PDK["Pair"]>>;
23
+ export declare function sealPair(dhkeReq: DHKEReq): Promise<ValStat<{
24
+ key: PDK["Pair"];
25
+ pub: Uint8Array;
26
+ }>>;
27
+ export declare class PairRequest {
28
+ #private;
29
+ private constructor();
30
+ static create(): Promise<ValStat<PairRequest>>;
31
+ wipe(): void;
32
+ dhkeReq(): ValStat<DHKEReq>;
33
+ finish(dhkeResp: DHKEResp): Promise<ValStat<{
34
+ enclave: Enclave;
35
+ hosts: BundleHost[];
36
+ }>>;
37
+ }
21
38
  export {};
@@ -0,0 +1,52 @@
1
+ import type { SealedMasterKey } from "../seed.ts";
2
+ import { type ValStat } from "../valstat.ts";
3
+ import { type PDK } from "./derivation.ts";
4
+ import { type PrfCeremony, type PrfCreateOpts, type PrfEvalOpts } from "../webauthn/prf.ts";
5
+ /** Options for PRF seal/unseal ceremonies (no raw PRF bytes). */
6
+ export type PasskeyPrfOpts = PrfCreateOpts & {
7
+ credId?: Uint8Array | readonly Uint8Array[];
8
+ /** Seal only: create a PRF credential first when no credId is known. */
9
+ createCredIfNeeded?: boolean;
10
+ };
11
+ /** One binding to try on unseal (cred id + sealed master). */
12
+ export type PrfBinding = {
13
+ sealedMaster: SealedMasterKey;
14
+ credId: Uint8Array;
15
+ /** PRF salt for this cred. Omitted salts use the ceremony salt. */
16
+ salt?: Uint8Array;
17
+ };
18
+ /** Durable PRF-sealed master + public ceremony facts (never includes PRF output). */
19
+ export type PrfSealedMaster = PrfCeremony & {
20
+ sealedMaster: SealedMasterKey;
21
+ salt: Uint8Array;
22
+ };
23
+ /** One existing keyring member used to prove this enclave matches the list. */
24
+ export type BindPrior = {
25
+ credId: Uint8Array;
26
+ tag: PDK["BindTag"];
27
+ };
28
+ /** Seal + bind-tag from {@link Enclave.bind} (tag is not a global fingerprint). */
29
+ export type PrfBound = PrfSealedMaster & {
30
+ tag: PDK["BindTag"];
31
+ };
32
+ type PrfCreateResult = PrfCeremony & {
33
+ prfEnabled: boolean;
34
+ prf?: Uint8Array;
35
+ };
36
+ type PrfEvalResult = PrfCeremony & {
37
+ prf: Uint8Array;
38
+ };
39
+ export declare function createPrfCred(opts?: PrfCreateOpts): Promise<ValStat<PrfCreateResult>>;
40
+ export declare function evalPrf(opts?: PrfEvalOpts): Promise<ValStat<PrfEvalResult>>;
41
+ export declare function sealPRF(opts: PasskeyPrfOpts | undefined): Promise<ValStat<PrfCeremony & {
42
+ prf: Uint8Array;
43
+ salt: Uint8Array;
44
+ }>>;
45
+ export declare function unsealPRF(bindings: readonly PrfBinding[], opts: PasskeyPrfOpts & {
46
+ salt: Uint8Array;
47
+ }): Promise<ValStat<{
48
+ prf: Uint8Array;
49
+ credId: Uint8Array;
50
+ order: readonly PrfBinding[];
51
+ }>>;
52
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type IKDM } from "../codecs/kdm.ts";
2
+ import { type MasterSeed } from "../seed.ts";
3
+ import { type ValStat } from "../valstat.ts";
4
+ import { type PDK } from "./derivation.ts";
5
+ export declare function deriveRealmKey(parent: MasterSeed, realmKDM: IKDM): Promise<ValStat<PDK["RealmKey"]>>;
6
+ export declare function deriveRealmID(parent: MasterSeed, realmKDM: IKDM): Promise<ValStat<PDK["RealmID"]>>;
7
+ export declare function deriveHostRLM(parent: PDK["RealmID"], hostKDM: IKDM): Promise<ValStat<PDK["HostRLM"]>>;
@@ -0,0 +1,3 @@
1
+ import { Status } from "../consts.ts";
2
+ import { type ValStat } from "../valstat.ts";
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
- export interface IAuthenticatedEndpoint<ReqItem, Resp> {
14
- encodeReq(client: IProtoClient, identity: Identity, authTS: IAuthTimestamp, body: Iterable<ReqItem>, reqEnc: Encoder): Promise<Status>;
12
+ export interface IAuthenticatedEndpoint<ReqInput, Resp> {
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,17 +1,17 @@
1
- import { Enclave } from "./crypto/enclave.ts";
1
+ import { BagManager } from "./crypto/bagman.ts";
2
2
  import { ICrypto, IMessageHead } from "./types.ts";
3
3
  import { ValStat } from "./valstat.ts";
4
4
  export declare namespace Exim {
5
5
  const defaultFileExtension = "dpl";
6
- function encodeFile(keyLbl: string, keyIdx: number, msgs: Iterable<{
6
+ function encodeFile(msgs: Iterable<{
7
7
  head: IMessageHead;
8
8
  body?: Uint8Array;
9
- }>, crypto: ICrypto, enclave: Enclave): Promise<ValStat<Uint8Array>>;
10
- function decodeFile(file: Uint8Array, crypto: ICrypto, enclave: Enclave): Promise<ValStat<{
9
+ }>, crypto: ICrypto, bagMgr: BagManager): Promise<ValStat<Uint8Array>>;
10
+ function decodeFile(file: Uint8Array, crypto: ICrypto, bagMgr: BagManager): Promise<ValStat<{
11
11
  head: IMessageHead;
12
12
  body?: Uint8Array;
13
13
  }[]>>;
14
- function migrateFile(file: Uint8Array, crypto: ICrypto, enclaveIn: Enclave, enclaveOut: Enclave, transform: (msgs: Iterable<{
14
+ function migrateFile(file: Uint8Array, crypto: ICrypto, bagMgrIn: BagManager, bagMgrOut: BagManager, transform: (msgs: Iterable<{
15
15
  head: IMessageHead;
16
16
  body?: Uint8Array;
17
17
  }>) => Iterable<{
@@ -6,66 +6,66 @@ import { ValStat } from "./valstat.ts";
6
6
  export declare const api: {
7
7
  readonly user: {
8
8
  readonly path: "/user";
9
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<never, void>;
9
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<void, void>;
10
10
  readonly name: APICallName.User;
11
11
  };
12
12
  readonly push: {
13
13
  readonly path: "/push";
14
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag, import("./codecs/pushItem.ts").IBagPushItem[]>;
14
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag[], import("./codecs/pushItem.ts").IBagPushItem[]>;
15
15
  readonly name: APICallName.Push;
16
16
  };
17
17
  readonly peek: {
18
18
  readonly path: "/peek";
19
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/peekItem.ts").IBagPeekItem[]>;
19
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./api/peek.ts").IPeekCursor, import("./codecs/peekItem.ts").IBagPeekItem[]>;
20
20
  readonly name: APICallName.Peek;
21
21
  };
22
22
  readonly pull: {
23
23
  readonly path: "/pull";
24
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/pullItem.ts").IBagPullItem[]>;
24
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./api/pull.ts").IPullReq, import("./codecs/pullItem.ts").IBagPullItem[]>;
25
25
  readonly name: APICallName.Pull;
26
26
  };
27
27
  };
28
28
  export declare const apiCalls: {
29
29
  readonly 0: {
30
30
  readonly path: "/user";
31
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<never, void>;
31
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<void, void>;
32
32
  readonly name: APICallName.User;
33
33
  };
34
34
  readonly 2: {
35
35
  readonly path: "/push";
36
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag, import("./codecs/pushItem.ts").IBagPushItem[]>;
36
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag[], import("./codecs/pushItem.ts").IBagPushItem[]>;
37
37
  readonly name: APICallName.Push;
38
38
  };
39
39
  readonly 1: {
40
40
  readonly path: "/peek";
41
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/peekItem.ts").IBagPeekItem[]>;
41
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./api/peek.ts").IPeekCursor, import("./codecs/peekItem.ts").IBagPeekItem[]>;
42
42
  readonly name: APICallName.Peek;
43
43
  };
44
44
  readonly 3: {
45
45
  readonly path: "/pull";
46
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/pullItem.ts").IBagPullItem[]>;
46
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./api/pull.ts").IPullReq, import("./codecs/pullItem.ts").IBagPullItem[]>;
47
47
  readonly name: APICallName.Pull;
48
48
  };
49
49
  };
50
50
  export declare const callPaths: {
51
51
  readonly "/user": {
52
52
  readonly path: "/user";
53
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<never, void>;
53
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<void, void>;
54
54
  readonly name: APICallName.User;
55
55
  };
56
56
  readonly "/push": {
57
57
  readonly path: "/push";
58
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag, import("./codecs/pushItem.ts").IBagPushItem[]>;
58
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./types.ts").IBag[], import("./codecs/pushItem.ts").IBagPushItem[]>;
59
59
  readonly name: APICallName.Push;
60
60
  };
61
61
  readonly "/peek": {
62
62
  readonly path: "/peek";
63
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/peekItem.ts").IBagPeekItem[]>;
63
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./api/peek.ts").IPeekCursor, import("./codecs/peekItem.ts").IBagPeekItem[]>;
64
64
  readonly name: APICallName.Peek;
65
65
  };
66
66
  readonly "/pull": {
67
67
  readonly path: "/pull";
68
- readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<number, import("./codecs/pullItem.ts").IBagPullItem[]>;
68
+ readonly endpoint: import("./endpoint.ts").IAuthenticatedEndpoint<import("./api/pull.ts").IPullReq, import("./codecs/pullItem.ts").IBagPullItem[]>;
69
69
  readonly name: APICallName.Pull;
70
70
  };
71
71
  };
@@ -1,10 +1,10 @@
1
1
  import { type IStorage } from "../types.ts";
2
2
  interface IMemoryStorage extends IStorage {
3
3
  users: Set<string>;
4
- bag: Map<string, Map<number, {
4
+ bag: Map<string, Map<string, Map<number, {
5
5
  headCph: Uint8Array;
6
6
  bodyCph: Uint8Array;
7
- }>>;
7
+ }>>>;
8
8
  }
9
9
  /** Fresh in-memory host storage (isolated bag/user maps). */
10
10
  export declare function createMemoryStorage(): IMemoryStorage;
@@ -1,9 +1,9 @@
1
1
  import { IBagPeekItem } from "./codecs/peekItem.ts";
2
- import { Enclave } from "./crypto/enclave.ts";
3
- import { ICrypto, PublicKey } from "./types.ts";
2
+ import { BagManager } from "./crypto/bagman.ts";
3
+ import { ICrypto } from "./types.ts";
4
4
  import { ValStat } from "./valstat.ts";
5
5
  export interface IDecryptedBagPeekItem {
6
6
  kdm: Uint8Array;
7
7
  headEnc: Uint8Array;
8
8
  }
9
- export declare function decryptPeekItem(item: IBagPeekItem, pubKey: PublicKey, enclave: Enclave, crypto: ICrypto): Promise<ValStat<IDecryptedBagPeekItem>>;
9
+ export declare function decryptPeekItem(item: IBagPeekItem, verifyKey: CryptoKey, bagMgr: BagManager, crypto: ICrypto): Promise<ValStat<IDecryptedBagPeekItem>>;
@@ -4,6 +4,7 @@ import { IAuthTimestamp } from "./codecs/authTimestamp.ts";
4
4
  import type { IBagPeekItem } from "./codecs/peekItem.ts";
5
5
  import { IUsageQuota } from "./codecs/usageQuota.ts";
6
6
  import { APICallName, Status } from "./consts.ts";
7
+ import type { HostRlm } from "./crypto/derivation.ts";
7
8
  import type { ValStat } from "./valstat.ts";
8
9
  /** Identity seed brands — defined in seed.ts; re-exported for convenience. */
9
10
  export type { MasterSeed, SealedMasterKey } from "./seed.ts";
@@ -75,27 +76,35 @@ export type IDeleteParams = {
75
76
  eid: EntityID;
76
77
  force?: boolean;
77
78
  };
79
+ /** One setBags outcome. Success carries the host seq in that bag's rlm. */
80
+ export type ISetBagResult = {
81
+ status: Status.Success;
82
+ seq: number;
83
+ } | {
84
+ status: Exclude<Status, Status.Success>;
85
+ };
78
86
  export interface IStorage {
79
87
  addUser: (pubKey: PublicKey) => Promise<ValStat<void>>;
80
88
  hasUser: (pubKey: PublicKey) => Promise<ValStat<boolean>>;
81
89
  subMeta: (pubKey: PublicKey) => Promise<ValStat<ISubscriptionMetadata>>;
82
90
  /**
83
- * Store bags for a user. Returns host seq for each bag in order.
84
- * Empty list succeeds with []. Implementations must assign contiguous
85
- * seqs atomically (transaction / single batch) so concurrent writers
86
- * cannot claim the same seq.
91
+ * Store bags for a user. One result per input bag, same order.
92
+ * An invalid rlm is InvalidParam for that bag; the others are still stored.
93
+ * Seqs are contiguous per rlm among stored bags, assigned atomically so
94
+ * concurrent writers cannot claim the same seq in the same rlm.
95
+ * Empty list succeeds with []. A storage failure fails the call.
87
96
  */
88
- setBags: (pubKey: PublicKey, bags: IBag[]) => Promise<ValStat<number[]>>;
97
+ setBags: (pubKey: PublicKey, bags: IBag[]) => Promise<ValStat<ISetBagResult[]>>;
89
98
  /**
90
- * Fetch ciphertext bodies for the given host seqs.
91
- * Returns only seqs that exist (missing seqs are omitted, not an error).
92
- * Empty `seqs` succeeds with [].
99
+ * Fetch ciphertext bodies for `seqs` in `rlm`.
100
+ * Missing seqs are omitted. Empty `seqs` succeeds with [].
93
101
  */
94
- getBodies: (pubKey: PublicKey, seqs: number[]) => Promise<ValStat<{
102
+ getBodies: (pubKey: PublicKey, rlm: HostRlm, seqs: number[]) => Promise<ValStat<{
95
103
  seq: number;
96
104
  bodyCph: Uint8Array;
97
105
  }[]>>;
98
- listHeads: (pubKey: PublicKey, minSeq: number) => Promise<ValStat<IBagPeekItem[]>>;
106
+ /** Heads in `rlm` with seq greater than minSeq, ordered by seq. */
107
+ listHeads: (pubKey: PublicKey, rlm: HostRlm, minSeq: number) => Promise<ValStat<IBagPeekItem[]>>;
99
108
  }
100
109
  export interface KeyPair {
101
110
  keyType: "ed25519";
@@ -123,7 +132,8 @@ export type Hash = Uint8Array & {
123
132
  readonly [hashSymbol]: true;
124
133
  };
125
134
  export interface IHostCrypto {
126
- checkSigEd25519: (sig: Uint8Array, message: Uint8Array | string, pubKey: PublicKey) => Promise<boolean>;
135
+ importVerifyKey: (pubKey: PublicKey) => Promise<CryptoKey>;
136
+ checkSigEd25519: (sig: Uint8Array, message: Uint8Array | string, verifyKey: CryptoKey) => Promise<boolean>;
127
137
  }
128
138
  /** BLAKE3 hash / MAC / KDF (noble: `key` XOR `context`, not both). */
129
139
  export type Blake3Opts = {
@@ -141,11 +151,6 @@ export interface ICrypto extends IHostCrypto {
141
151
  signEd25519: (message: Uint8Array | string, secKey: PrivateKey) => Promise<Uint8Array>;
142
152
  blake3: (data: Uint8Array, opts?: Blake3Opts) => Promise<Hash>;
143
153
  }
144
- export interface IMsgpackCodec {
145
- encode: (source: unknown) => Uint8Array;
146
- decode: (packed: ArrayBuffer | Uint8Array) => unknown;
147
- decodeAsync: (stream: ReadableStream<Uint8Array>) => Promise<unknown>;
148
- }
149
154
  export interface IProtoHost {
150
155
  storage: IStorage;
151
156
  crypto: IHostCrypto;
@@ -168,6 +173,9 @@ export interface IPushListener {
168
173
  disconnect(): void;
169
174
  }
170
175
  export interface IBagHeader {
176
+ /** HostRLM. Covered by sig, with headCph. */
177
+ rlm: HostRlm;
178
+ /** Ed25519 over rlm ‖ headCph. First field on the wire. */
171
179
  sig: Uint8Array;
172
180
  kdm: Uint8Array;
173
181
  }
@@ -29,6 +29,14 @@ export type PrfEvalOpts = PrfRp & {
29
29
  /** One id, or every bound id so a spare key can assert in one get(). */
30
30
  credId?: Uint8Array | readonly Uint8Array[];
31
31
  salt?: Uint8Array;
32
+ /**
33
+ * Salt for each cred when accounts do not share one.
34
+ * Sent as evalByCredential so the passkey the user picks evals its own.
35
+ */
36
+ salts?: readonly {
37
+ credId: Uint8Array;
38
+ salt: Uint8Array;
39
+ }[];
32
40
  };
33
41
  /** Best-effort: client advertises PRF extension. */
34
42
  export declare function prfCapable(): Promise<boolean>;
@@ -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 {
@@ -0,0 +1,30 @@
1
+ import type { IKDM } from "../shared/codecs/kdm";
2
+ import type { HostSeqsUpdate } from "../types";
3
+ import type { IRealm } from "./realm";
4
+ /** One host-realm cursor. The realm KDM plus the newest bag seq. */
5
+ export interface RealmCursor extends IKDM {
6
+ lastSeq: number;
7
+ }
8
+ declare const downloadKeySymbol: unique symbol;
9
+ /** Key of one queued download: host label, realm, and seq. */
10
+ export type DownloadKey = string & {
11
+ readonly [downloadKeySymbol]: true;
12
+ };
13
+ type CursorRow = {
14
+ lastSeq: number;
15
+ seqs?: RealmCursor[];
16
+ };
17
+ export declare function isDefaultRealm(realm?: IKDM): boolean;
18
+ export declare function sameRealm(a: IKDM, b: IKDM): boolean;
19
+ export declare function realmKey(realm: IKDM): string;
20
+ export declare function cursorOf(row: CursorRow, realm?: IKDM): number;
21
+ export declare function realmKDMs(rows: readonly IRealm[]): IKDM[];
22
+ export declare function realmKDM(label: string | undefined, rows: readonly IRealm[]): IKDM;
23
+ export declare function storedRealm(realm: IKDM): IKDM | undefined;
24
+ export declare function downloadKey(host: string, seq: number, realm?: IKDM): DownloadKey;
25
+ export declare function nextCursor(cur: number, u: HostSeqsUpdate): number | undefined;
26
+ export declare function projectCursors(cursors: readonly RealmCursor[]): {
27
+ lastSeq: number;
28
+ seqs?: RealmCursor[];
29
+ };
30
+ export {};
@@ -0,0 +1,58 @@
1
+ import { Status } from "../../shared/consts";
2
+ import { Enclave } from "../../shared/crypto/enclave";
3
+ import type { ICrypto } from "../../shared/types";
4
+ import { type ValStat } from "../../shared/valstat";
5
+ import type { PrfRp } from "../../shared/webauthn/prf";
6
+ import type { IAccountStore, SetSeedOpts } from "../../types";
7
+ import { type Keyring, PrfSeedStore, type PrfSeedStoreOpts } from "../../passkey/prf-store";
8
+ import { type KeyTag } from "../keyTag";
9
+ /**
10
+ * One account: its label, catalog id, database names, key tag, and the
11
+ * binding that unseals its key.
12
+ */
13
+ export type Account = {
14
+ label: string;
15
+ /** Stable id. Database names are derived from this. */
16
+ acct?: string;
17
+ /** Protocol database name. */
18
+ data?: string;
19
+ /** EntDB name. Absent until EntDB is opened. */
20
+ ents?: string;
21
+ keyTag?: KeyTag;
22
+ keyring?: Keyring;
23
+ };
24
+ export declare function decodeAccount(raw: unknown): Account | undefined;
25
+ export declare class IDBAccountStore implements IAccountStore {
26
+ #private;
27
+ db: IDBDatabase;
28
+ constructor(db: IDBDatabase, crypto: ICrypto);
29
+ setCloser(close: () => void): void;
30
+ /**
31
+ * Mint an account key with {@link Enclave.fromRandom} and store its key tag.
32
+ * A blank label is "". A label that already names a key is unchanged.
33
+ * An existing keyring on that row is kept. musec is wiped.
34
+ */
35
+ create(label: string, musec: Uint8Array): Promise<ValStat<Enclave>>;
36
+ /**
37
+ * Record the key tag for `opts.label`. Does not open the account.
38
+ * Durable identity is the account keyring
39
+ * ({@link openPrfStore} / {@link persistKeyring}), never plain seed.
40
+ * The row is created on the first save. A later save must match that
41
+ * account's key tag. `opts.persist` is ignored (kept for API compatibility).
42
+ *
43
+ * TODO(passphrase): when PRF is missing, seal under a passphrase KDF
44
+ * and store that ciphertext on this account row.
45
+ */
46
+ save(enclave: Enclave, opts?: SetSeedOpts): Promise<ValStat<Enclave>>;
47
+ dataName(label: string): Promise<string | undefined>;
48
+ ensureEnts(label: string): Promise<string>;
49
+ wipe(): Promise<void>;
50
+ loadKeyring(label?: string): Promise<Keyring | undefined>;
51
+ persistKeyring(ring: Keyring | undefined, label?: string): Promise<Status>;
52
+ hasKeyring(label?: string): Promise<boolean>;
53
+ unlock(opts: PrfRp): Promise<ValStat<{
54
+ enclave: Enclave;
55
+ label: string;
56
+ }>>;
57
+ openPrfStore(opts: Omit<PrfSeedStoreOpts, "persistKeyring" | "keyring" | "unlockAccount">, label?: string): Promise<ValStat<PrfSeedStore>>;
58
+ }
@@ -0,0 +1 @@
1
+ export declare function entsNameFor(label: string): Promise<string>;
@@ -1,9 +1,10 @@
1
+ import type { IKDM } from "../../shared/codecs/kdm";
1
2
  import { IDownloadMessage, IDownloadQueue } from "../../types";
2
3
  export declare class IDBDownloadQueue implements IDownloadQueue {
3
- db: IDBDatabase;
4
+ private db;
4
5
  constructor(db: IDBDatabase);
5
6
  enq(msgs: Iterable<IDownloadMessage>): Promise<void>;
6
- deq(host: string, seqs: Iterable<number>): Promise<void>;
7
+ deq(host: string, seqs: Iterable<number>, realm?: IKDM): Promise<void>;
7
8
  list(): Promise<IDownloadMessage[]>;
8
9
  count(): Promise<number>;
9
10
  wipe(): Promise<void>;
@@ -1,20 +1,21 @@
1
+ import type { IKDM } from "../../shared/codecs/kdm";
1
2
  import { Status } from "../../shared/consts";
2
3
  import { IHostConnectionInfo, IHostMetadata } from "../../shared/types";
3
- import type { HostStatsUpdate, IHostRow, IHostStore } from "../../types";
4
+ import type { HostSeqsUpdate, IHostRow, IHostStore } from "../../types";
4
5
  export declare class IDBHostStore implements IHostStore<URL> {
5
- db: IDBDatabase;
6
+ private db;
6
7
  constructor(db: IDBDatabase);
7
8
  /**
8
- * Upsert connection info. Same label + same handle/idx keeps lastSeq and
9
- * host meta (safe re-link). Changing handle/idx resets the peek cursor.
9
+ * Upsert connection info. Same label + same handle/idx keeps cursors and
10
+ * host meta (safe re-link). Changing handle/idx clears host_seqs.
10
11
  */
11
12
  add(info: IHostConnectionInfo<URL>): Promise<void>;
12
- private put;
13
- touch(label: string, seq: number): Promise<void>;
14
- recordStats(label: string, u: HostStatsUpdate): Promise<void>;
13
+ touch(label: string, seq: number, realm?: IKDM): Promise<void>;
14
+ recordSeqs(label: string, u: HostSeqsUpdate, realm?: IKDM): Promise<void>;
15
15
  get(label: string): Promise<IHostRow<URL> | undefined>;
16
16
  set(label: string, meta: IHostMetadata): Promise<Status.Success | Status.NotFound | Status.DatabaseError>;
17
17
  del(label: string): Promise<void>;
18
18
  list(): Promise<IHostRow<URL>[]>;
19
19
  wipe(): Promise<void>;
20
+ private put;
20
21
  }
@@ -0,0 +1,2 @@
1
+ export declare function deleteDatabase(name: string): Promise<void>;
2
+ export declare function openAt(name: string, version: number, upgrade: (db: IDBDatabase, tx: IDBTransaction) => void): Promise<IDBDatabase>;
@@ -0,0 +1,2 @@
1
+ export declare function openMetaDB(): Promise<IDBDatabase>;
2
+ export declare function openDataDB(name: string): Promise<IDBDatabase>;
@@ -3,8 +3,8 @@ import { ICrypto } from "../../shared/types";
3
3
  import { EntityID, Hash } from "../../shared/types";
4
4
  import { ApldState, IMessageStore, IStorableMessage, IStoredMessage, ListMsgsOpts } from "../../types";
5
5
  export declare class IDBMessageStore implements IMessageStore {
6
+ private db;
6
7
  private crypto;
7
- db: IDBDatabase;
8
8
  constructor(db: IDBDatabase, crypto: ICrypto);
9
9
  add(messages: IStorableMessage[]): Promise<Status[]>;
10
10
  del(keys: Iterable<Hash>): Promise<void>;
@@ -0,0 +1,13 @@
1
+ /** Account catalog. Unlock reads only this database. */
2
+ export declare const META_DB_NAME = "meta";
3
+ export declare const META_DB_VERSION = 1;
4
+ /** Protocol database: archive, queues, hosts, realm counters, host cursors. */
5
+ export declare const DATA_DB_VERSION = 9;
6
+ export declare function mintAcct(): string;
7
+ export declare function dataDbName(acct: string): string;
8
+ export declare function entsDbName(acct: string): string;
9
+ export declare function placeAccount(acct: string | undefined, data: string | undefined): {
10
+ acct: string;
11
+ data: string;
12
+ };
13
+ export declare function assignEnts(acct: string, current: string | undefined): string;
@@ -0,0 +1,11 @@
1
+ import { Status } from "../../shared/consts";
2
+ import { type IRealm, type IRealmStore } from "../realm";
3
+ /** Realm counters for the open account. The database is that account. */
4
+ export declare class IDBRealmStore implements IRealmStore {
5
+ private db;
6
+ constructor(db: IDBDatabase);
7
+ list(): Promise<IRealm[]>;
8
+ get(label: string): Promise<IRealm | undefined>;
9
+ put(label: string, index: number): Promise<Status>;
10
+ wipe(): Promise<void>;
11
+ }