@agora-sdk/secure-chat-core 0.2.0 → 0.4.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 (35) hide show
  1. package/dist/cjs/context/secure-chat-context.d.ts +10 -0
  2. package/dist/cjs/context/secure-chat-context.js +37 -1
  3. package/dist/cjs/context/secure-chat-context.js.map +1 -1
  4. package/dist/cjs/contract/index.d.ts +2 -150
  5. package/dist/cjs/contract/index.js +11 -10
  6. package/dist/cjs/contract/index.js.map +1 -1
  7. package/dist/cjs/hooks/useSecureHandshakes.d.ts +64 -0
  8. package/dist/cjs/hooks/useSecureHandshakes.js +215 -0
  9. package/dist/cjs/hooks/useSecureHandshakes.js.map +1 -0
  10. package/dist/cjs/hooks/useSecureMessages.js +12 -2
  11. package/dist/cjs/hooks/useSecureMessages.js.map +1 -1
  12. package/dist/cjs/index.d.ts +2 -0
  13. package/dist/cjs/index.js +3 -1
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/transport/socket.d.ts +15 -3
  16. package/dist/cjs/transport/socket.js +4 -2
  17. package/dist/cjs/transport/socket.js.map +1 -1
  18. package/dist/esm/context/secure-chat-context.d.ts +10 -0
  19. package/dist/esm/context/secure-chat-context.js +37 -1
  20. package/dist/esm/context/secure-chat-context.js.map +1 -1
  21. package/dist/esm/contract/index.d.ts +2 -150
  22. package/dist/esm/contract/index.js +11 -10
  23. package/dist/esm/contract/index.js.map +1 -1
  24. package/dist/esm/hooks/useSecureHandshakes.d.ts +64 -0
  25. package/dist/esm/hooks/useSecureHandshakes.js +212 -0
  26. package/dist/esm/hooks/useSecureHandshakes.js.map +1 -0
  27. package/dist/esm/hooks/useSecureMessages.js +12 -2
  28. package/dist/esm/hooks/useSecureMessages.js.map +1 -1
  29. package/dist/esm/index.d.ts +2 -0
  30. package/dist/esm/index.js +1 -0
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/transport/socket.d.ts +15 -3
  33. package/dist/esm/transport/socket.js +4 -2
  34. package/dist/esm/transport/socket.js.map +1 -1
  35. package/package.json +3 -2
@@ -21,6 +21,16 @@ export interface SecureChatContextValue {
21
21
  resolveGroup: (conversationId: string) => Promise<GroupHandle | null>;
22
22
  /** Cache + persist a conversation's group handle (after createGroup / processWelcome). */
23
23
  rememberGroup: (conversationId: string, handle: GroupHandle) => Promise<void>;
24
+ /**
25
+ * Current change-version for a conversation's group handle. Bumps every time the handle advances
26
+ * (a join or a processed Commit), so consumers can detect "the group moved" without diffing handles.
27
+ */
28
+ getGroupVersion: (conversationId: string) => number;
29
+ /**
30
+ * Subscribe to group-handle changes across all conversations (fired by {@link rememberGroup}).
31
+ * @returns An unsubscribe function.
32
+ */
33
+ subscribeGroupChange: (listener: () => void) => () => void;
24
34
  /** The Agora project id these clients are scoped to. */
25
35
  projectId: string;
26
36
  }
@@ -51,6 +51,12 @@ function SecureChatProvider({ crypto, projectId, store, accessToken, getAccessTo
51
51
  // NOTE: not cleared on a `store` prop swap — a store change in practice means a new provider
52
52
  // instance (fresh cache), not a live prop change on the same mounted provider.
53
53
  const groupCache = (0, react_1.useRef)(new Map());
54
+ // Per-conversation change counter, bumped whenever a group handle advances (a join or a processed
55
+ // Commit). Lets useSecureMessages re-resolve and flush buffered (undecrypted) rows without a
56
+ // re-fetch. Held in a ref + listener set so a bump notifies consumers WITHOUT re-rendering the
57
+ // provider (and thus rebuilding rest/socket/repo).
58
+ const groupVersion = (0, react_1.useRef)(new Map());
59
+ const groupListeners = (0, react_1.useRef)(new Set());
54
60
  const resolveGroup = (0, react_1.useCallback)(async (conversationId) => {
55
61
  const cached = groupCache.current.get(conversationId);
56
62
  if (cached)
@@ -66,11 +72,41 @@ function SecureChatProvider({ crypto, projectId, store, accessToken, getAccessTo
66
72
  groupCache.current.set(conversationId, handle);
67
73
  const bytes = await crypto.exportGroupState(handle);
68
74
  await repo.saveGroupState(conversationId, bytes);
75
+ // Signal that this conversation's group advanced, so message hooks re-resolve + flush.
76
+ groupVersion.current.set(conversationId, (groupVersion.current.get(conversationId) ?? 0) + 1);
77
+ groupListeners.current.forEach((l) => l());
69
78
  }, [repo, crypto]);
79
+ const getGroupVersion = (0, react_1.useCallback)((conversationId) => groupVersion.current.get(conversationId) ?? 0, []);
80
+ const subscribeGroupChange = (0, react_1.useCallback)((listener) => {
81
+ groupListeners.current.add(listener);
82
+ return () => {
83
+ groupListeners.current.delete(listener);
84
+ };
85
+ }, []);
70
86
  (0, react_1.useEffect)(() => {
71
87
  return () => socket.disconnect();
72
88
  }, [socket]);
73
- const value = (0, react_1.useMemo)(() => ({ rest, socket, crypto, repo, resolveGroup, rememberGroup, projectId }), [rest, socket, crypto, repo, resolveGroup, rememberGroup, projectId]);
89
+ const value = (0, react_1.useMemo)(() => ({
90
+ rest,
91
+ socket,
92
+ crypto,
93
+ repo,
94
+ resolveGroup,
95
+ rememberGroup,
96
+ getGroupVersion,
97
+ subscribeGroupChange,
98
+ projectId,
99
+ }), [
100
+ rest,
101
+ socket,
102
+ crypto,
103
+ repo,
104
+ resolveGroup,
105
+ rememberGroup,
106
+ getGroupVersion,
107
+ subscribeGroupChange,
108
+ projectId,
109
+ ]);
74
110
  return (0, jsx_runtime_1.jsx)(SecureChatContext.Provider, { value: value, children: children });
75
111
  }
76
112
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"secure-chat-context.js","sourceRoot":"","sources":["../../../src/context/secure-chat-context.tsx"],"names":[],"mappings":";;AA0EA,gDA8EC;AAQD,sCAMC;;AAtKD,yFAAyF;AACzF,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,+FAA+F;AAC/F,mGAAmG;AACnG,gEAAgE;AAEhE,iCAAkG;AAClG,0CAA8D;AAG9D,kDAA4D;AAC5D,sDAAgE;AAEhE,oEAA6D;AAC7D,gEAAoE;AAuBpE,MAAM,iBAAiB,GAAG,IAAA,qBAAa,EAAgC,IAAI,CAAC,CAAC;AAqB7E;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,C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AG,IAAA,mBAAW,EAAC,CAAC,QAAoB,EAAgB,EAAE;QAC9E,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrC,OAAO,GAAG,EAAE;YACV,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IACnC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,MAAM,KAAK,GAAG,IAAA,eAAO,EACnB,GAAG,EAAE,CAAC,CAAC;QACL,IAAI;QACJ,MAAM;QACN,MAAM;QACN,IAAI;QACJ,YAAY;QACZ,aAAa;QACb,eAAe;QACf,oBAAoB;QACpB,SAAS;KACV,CAAC,EACF;QACE,IAAI;QACJ,MAAM;QACN,MAAM;QACN,IAAI;QACJ,YAAY;QACZ,aAAa;QACb,eAAe;QACf,oBAAoB;QACpB,SAAS;KACV,CACF,CAAC;IAEF,OAAO,uBAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA8B,CAAC;AAC3F,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa;IAC3B,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,iBAAiB,CAAC,CAAC;IAC1C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,150 +1,2 @@
1
- export type SecureConversationType = "dm" | "group" | "channel";
2
- export type SecureMemberRole = "admin" | "member";
3
- export type SecureHandshakeKind = "welcome" | "commit" | "proposal";
4
- /** A Welcome targeted at the ONE device whose claimed KeyPackage was consumed. */
5
- export interface WelcomeEnvelope {
6
- targetDeviceId: string;
7
- payload: string;
8
- epoch: string;
9
- }
10
- /** A Commit/Proposal broadcast to the whole group (no target device). */
11
- export interface HandshakeBlob {
12
- payload: string;
13
- epoch: string;
14
- }
15
- export interface RegisterDeviceBody {
16
- deviceId: string;
17
- displayName?: string | null;
18
- signaturePublicKey: string;
19
- credential: string;
20
- ciphersuite: number;
21
- }
22
- export interface PublishKeyPackagesBody {
23
- keyPackages: {
24
- keyPackageRef: string;
25
- keyPackage: string;
26
- ciphersuite: number;
27
- expiresAt?: string | null;
28
- }[];
29
- }
30
- export interface CreateSecureConversationBody {
31
- type: SecureConversationType;
32
- mlsGroupId: string;
33
- spaceId?: string | null;
34
- name?: string | null;
35
- memberUserIds?: string[];
36
- welcomes?: WelcomeEnvelope[];
37
- }
38
- export interface AddSecureMemberBody {
39
- userId: string;
40
- commit: HandshakeBlob;
41
- welcomes: WelcomeEnvelope[];
42
- }
43
- export interface RemoveSecureMemberBody {
44
- commit: HandshakeBlob;
45
- }
46
- export interface SendSecureMessageBody {
47
- ciphertext: string;
48
- epoch: string;
49
- senderDeviceId: string;
50
- contentType?: string | null;
51
- }
52
- export interface UploadKeyBackupBody {
53
- deviceId?: string | null;
54
- blob: string;
55
- nonce: string;
56
- kdf: "argon2id" | "pbkdf2";
57
- kdfParams: Record<string, unknown>;
58
- cipher: "xchacha20poly1305" | "aes-256-gcm";
59
- version: number;
60
- }
61
- export interface SecureDeviceModel {
62
- id: string;
63
- projectId: string;
64
- userId: string;
65
- deviceId: string;
66
- displayName: string | null;
67
- signaturePublicKey: string;
68
- credential: string;
69
- ciphersuite: number;
70
- revokedAt: string | null;
71
- lastSeenAt: string | null;
72
- createdAt: string;
73
- updatedAt: string;
74
- }
75
- export interface SecureKeyPackageClaim {
76
- deviceId: string;
77
- keyPackageRef: string;
78
- keyPackage: string;
79
- ciphersuite: number;
80
- }
81
- export interface SecureConversationMemberModel {
82
- id: string;
83
- projectId: string;
84
- conversationId: string;
85
- userId: string;
86
- role: SecureMemberRole;
87
- isActive: boolean;
88
- joinedAtEpoch: string | null;
89
- lastReadAt: string | null;
90
- leftAt: string | null;
91
- createdAt: string;
92
- updatedAt: string;
93
- }
94
- export interface SecureConversationModel {
95
- id: string;
96
- projectId: string;
97
- type: SecureConversationType;
98
- mlsGroupId: string;
99
- spaceId: string | null;
100
- currentEpoch: string;
101
- name: string | null;
102
- createdById: string | null;
103
- lastMessageAt: string | null;
104
- memberCount?: number;
105
- unreadCount?: number;
106
- currentMember?: SecureConversationMemberModel;
107
- createdAt: string;
108
- updatedAt: string;
109
- }
110
- export interface SecureMessageModel {
111
- id: string;
112
- projectId: string;
113
- conversationId: string;
114
- senderUserId: string | null;
115
- senderDeviceId: string | null;
116
- epoch: string;
117
- ciphertext: string;
118
- contentType: string;
119
- createdAt: string;
120
- }
121
- export interface SecureHandshakeModel {
122
- id: string;
123
- seq: string;
124
- kind: SecureHandshakeKind;
125
- conversationId: string;
126
- epoch: string;
127
- payload: string;
128
- senderDeviceId: string | null;
129
- targetDeviceId: string | null;
130
- }
131
- export interface SecureKeyBackupModel {
132
- id: string;
133
- projectId: string;
134
- userId: string;
135
- deviceId: string | null;
136
- blob: string;
137
- nonce: string;
138
- kdf: string;
139
- kdfParams: Record<string, unknown>;
140
- cipher: string;
141
- version: number;
142
- createdAt: string;
143
- updatedAt: string;
144
- }
145
- /** Standard error envelope: `{ error, code, field? }` with `secure-chat/*` codes. */
146
- export interface SecureChatErrorBody {
147
- error: string;
148
- code: string;
149
- field?: string;
150
- }
1
+ export type { SecureDeviceModel, SecureKeyPackageClaim, SecureConversationMemberModel, SecureConversationModel, SecureMessageModel, SecureHandshakeModel, SecureKeyBackupModel, } from "@agora-server/contract";
2
+ export type { RegisterDeviceBody, PublishKeyPackagesBody, CreateSecureConversationBody, AddSecureMemberBody, RemoveSecureMemberBody, SendSecureMessageBody, UploadKeyBackupBody, WelcomeEnvelope, HandshakeBlob, } from "@agora-server/contract";
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
- // Secure-chat wire contractstand-in for @agora-server/contract (the Apache-2.0 server contract).
2
+ // Secure-chat wire typesre-exported from the published `@agora-server/contract` (Apache-2.0).
3
3
  //
4
- // Mirrors the response models + request bodies of agora-server's
5
- // `packages/contract/src/secure-chat.ts`. That package is the source of truth (zod + TS); the
6
- // client only needs the TypeScript shapes, so this copy is types-only.
4
+ // The dependency arrow is **SDK contract**: agora-server owns the wire contract, this SDK depends
5
+ // on it. This module used to hold a byte-faithful *copy* of the types (a stand-in until the contract
6
+ // published); now that `@agora-server/contract` is published, it is a thin **type-only re-export** so
7
+ // there is exactly one source of truth and zero drift. The internal import path
8
+ // (`../contract/index.js`) is kept stable so call sites don't churn, and the re-export is scoped to
9
+ // the secure-chat surface (not the contract's reactions/pagination/etc.).
7
10
  //
8
- // ⚠️ Keep this byte-faithful to the server contract. The arrow is SDK contract: once
9
- // `@agora-server/contract` is published, DELETE this file and `import type { ... } from "@agora-server/contract"`.
10
- // Do NOT publish a separate `@agora-sdk/secure-chat-contract` (that would invert the dependency —
11
- // see STATUS.md). Do not let this copy drift in the meantime.
11
+ // Type-only on purpose: `@agora-server/contract` is ESM-only, but these `export type` re-exports are
12
+ // erased from the emitted JS, so core's dual ESM/CJS build never `require()`s it at runtime.
12
13
  //
13
- // Wire conventions: every binary value is **base64** (the server stores/relays opaque blobs and
14
- // never parses them); MLS epochs are **decimal strings** (u64 exceeds JS safe-int range).
14
+ // Wire conventions (owned by the contract): every binary value is **base64**; MLS epochs are
15
+ // **decimal strings** (u64 exceeds JS safe-int range).
15
16
  Object.defineProperty(exports, "__esModule", { value: true });
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/index.ts"],"names":[],"mappings":";AAAA,oGAAoG;AACpG,EAAE;AACF,iEAAiE;AACjE,8FAA8F;AAC9F,uEAAuE;AACvE,EAAE;AACF,uFAAuF;AACvF,mHAAmH;AACnH,kGAAkG;AAClG,8DAA8D;AAC9D,EAAE;AACF,gGAAgG;AAChG,0FAA0F"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/index.ts"],"names":[],"mappings":";AAAA,iGAAiG;AACjG,EAAE;AACF,oGAAoG;AACpG,qGAAqG;AACrG,sGAAsG;AACtG,gFAAgF;AAChF,oGAAoG;AACpG,0EAA0E;AAC1E,EAAE;AACF,qGAAqG;AACrG,6FAA6F;AAC7F,EAAE;AACF,6FAA6F;AAC7F,uDAAuD"}
@@ -0,0 +1,64 @@
1
+ import { SecureHandshakeModel } from "../contract/index.js";
2
+ /** Options for {@link useSecureHandshakes}. */
3
+ export interface UseSecureHandshakesOptions {
4
+ /**
5
+ * The device row id whose inbox to drain. Defaults to the persisted device's `.id`. Pass the id
6
+ * from `useSecureDevice` so processing starts the moment the device registers (a persisted device
7
+ * is picked up automatically on reload even without this).
8
+ */
9
+ deviceId?: string;
10
+ /** Disable processing (e.g. before sign-in). Default true. */
11
+ enabled?: boolean;
12
+ /** Page size for the catch-up fetch loop. Default 100. */
13
+ pageSize?: number;
14
+ /** Called per handshake-processing error; the inbox skips the bad row and continues. */
15
+ onError?: (err: unknown, handshake?: SecureHandshakeModel) => void;
16
+ }
17
+ /** The state and actions returned by {@link useSecureHandshakes}. */
18
+ export interface UseSecureHandshakesValues {
19
+ /** True until the initial catch-up loop settles. */
20
+ catchingUp: boolean;
21
+ /** True once catch-up completed and live subscriptions are active. */
22
+ ready: boolean;
23
+ /** The last processed delivery cursor (`seq`), or `null`. */
24
+ cursor: string | null;
25
+ /** Count of handshakes applied this session. */
26
+ processedCount: number;
27
+ /** The last error surfaced (also delivered via `onError`), or `null`. */
28
+ error: unknown;
29
+ /**
30
+ * Re-run the catch-up loop from the persisted cursor. The reusable primitive a future 409
31
+ * epoch-conflict rebase (on a membership Commit) calls before rebuilding + retrying its Commit.
32
+ */
33
+ resync: () => Promise<void>;
34
+ }
35
+ /**
36
+ * Process this device's MLS handshake inbox so the recipient side of secure chat works.
37
+ *
38
+ * On mount (once a device id is available) it catches up via `fetchHandshakes(since=cursor)`, re-joins
39
+ * the socket rooms for groups it already holds, then processes live `secure:welcome` /
40
+ * `secure:handshake` events — all serialized in `seq` order, deduped, and cursor-persisted. Mount it
41
+ * exactly once near `useSecureDevice`.
42
+ *
43
+ * @param options - {@link UseSecureHandshakesOptions}.
44
+ * @returns {@link UseSecureHandshakesValues}.
45
+ *
46
+ * @remarks
47
+ * Single-device only (Phase 3 adds own-device fan-out + MLS generation-counter gap detection). A
48
+ * Commit for a group whose Welcome hasn't been seen is skipped — `seq` ordering puts the Welcome
49
+ * first, so an unknown group means this device is genuinely not a member.
50
+ *
51
+ * Mount it exactly once. Processing is serialized *within* a mount, and the cursor is re-read from
52
+ * storage at the start of each run, so a serialized re-mount (or `deviceId` change) resumes without
53
+ * reprocessing. It does NOT serialize across a *concurrent* re-mount whose prior catch-up is still
54
+ * in flight; that case relies on `processWelcome` / `processCommit` being idempotent for a replayed
55
+ * blob. The mock is idempotent (so dev StrictMode double-invoke is harmless); harden this when the
56
+ * real MLS core lands (Task 1) if its handshake processing is not replay-safe.
57
+ *
58
+ * @example
59
+ * ```tsx
60
+ * const { device } = useSecureDevice();
61
+ * useSecureHandshakes({ deviceId: device?.id });
62
+ * ```
63
+ */
64
+ export declare function useSecureHandshakes(options?: UseSecureHandshakesOptions): UseSecureHandshakesValues;
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ // useSecureHandshakes — drain and process this device's MLS handshake inbox (the recipient side).
3
+ //
4
+ // The blind DS delivers each device a stream of handshakes (Welcomes targeted at it, plus broadcast
5
+ // Commits/Proposals for its groups), ordered by a monotonic `seq`. This hook is what makes a
6
+ // RECIPIENT actually join and stay current: on connect it pulls `GET .../handshakes?since=<cursor>`
7
+ // to the end, then processes live `secure:welcome` / `secure:handshake` events — all funneled through
8
+ // ONE serialized, seq-ordered, idempotent path, persisting the cursor as it goes. A processed Welcome
9
+ // joins a group (rememberGroup); a processed Commit advances its epoch. Mount it once, near
10
+ // useSecureDevice.
11
+ //
12
+ // Ordering invariant: live events that arrive WHILE catching up are buffered and replayed in `seq`
13
+ // order AFTER catch-up — otherwise a high-seq live event would advance the cursor past not-yet-fetched
14
+ // rows and the dedupe check would drop them (data loss).
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.useSecureHandshakes = useSecureHandshakes;
17
+ const react_1 = require("react");
18
+ const base64_js_1 = require("../util/base64.js");
19
+ const secure_chat_context_js_1 = require("../context/secure-chat-context.js");
20
+ /** Compare two decimal-string `seq` cursors numerically (string compare is wrong across digit widths). */
21
+ function compareSeq(a, b) {
22
+ const d = BigInt(a) - BigInt(b);
23
+ return d > 0n ? 1 : d < 0n ? -1 : 0;
24
+ }
25
+ /**
26
+ * Process this device's MLS handshake inbox so the recipient side of secure chat works.
27
+ *
28
+ * On mount (once a device id is available) it catches up via `fetchHandshakes(since=cursor)`, re-joins
29
+ * the socket rooms for groups it already holds, then processes live `secure:welcome` /
30
+ * `secure:handshake` events — all serialized in `seq` order, deduped, and cursor-persisted. Mount it
31
+ * exactly once near `useSecureDevice`.
32
+ *
33
+ * @param options - {@link UseSecureHandshakesOptions}.
34
+ * @returns {@link UseSecureHandshakesValues}.
35
+ *
36
+ * @remarks
37
+ * Single-device only (Phase 3 adds own-device fan-out + MLS generation-counter gap detection). A
38
+ * Commit for a group whose Welcome hasn't been seen is skipped — `seq` ordering puts the Welcome
39
+ * first, so an unknown group means this device is genuinely not a member.
40
+ *
41
+ * Mount it exactly once. Processing is serialized *within* a mount, and the cursor is re-read from
42
+ * storage at the start of each run, so a serialized re-mount (or `deviceId` change) resumes without
43
+ * reprocessing. It does NOT serialize across a *concurrent* re-mount whose prior catch-up is still
44
+ * in flight; that case relies on `processWelcome` / `processCommit` being idempotent for a replayed
45
+ * blob. The mock is idempotent (so dev StrictMode double-invoke is harmless); harden this when the
46
+ * real MLS core lands (Task 1) if its handshake processing is not replay-safe.
47
+ *
48
+ * @example
49
+ * ```tsx
50
+ * const { device } = useSecureDevice();
51
+ * useSecureHandshakes({ deviceId: device?.id });
52
+ * ```
53
+ */
54
+ function useSecureHandshakes(options = {}) {
55
+ const { rest, crypto, socket, repo, resolveGroup, rememberGroup } = (0, secure_chat_context_js_1.useSecureChat)();
56
+ const { deviceId: deviceIdOption, pageSize = 100 } = options;
57
+ const enabled = options.enabled ?? true;
58
+ const [catchingUp, setCatchingUp] = (0, react_1.useState)(true);
59
+ const [ready, setReady] = (0, react_1.useState)(false);
60
+ const [cursor, setCursor] = (0, react_1.useState)(null);
61
+ const [processedCount, setProcessedCount] = (0, react_1.useState)(0);
62
+ const [error, setError] = (0, react_1.useState)(null);
63
+ // onError read through a ref so passing an inline callback doesn't re-run the effect.
64
+ const onErrorRef = (0, react_1.useRef)(options.onError);
65
+ onErrorRef.current = options.onError;
66
+ // The catch-up routine, published from the effect so `resync()` (stable) can invoke it.
67
+ const runCatchUpRef = (0, react_1.useRef)(null);
68
+ const resync = (0, react_1.useCallback)(async () => {
69
+ await runCatchUpRef.current?.();
70
+ }, []);
71
+ (0, react_1.useEffect)(() => {
72
+ if (!enabled)
73
+ return;
74
+ let alive = true;
75
+ const offFns = [];
76
+ // Async state shared across the catch-up loop, live handlers, and the serial apply queue.
77
+ const cursorRef = { current: null };
78
+ const catchingUpRef = { current: true };
79
+ const liveBuffer = [];
80
+ let queue = Promise.resolve();
81
+ let deviceId;
82
+ const report = (err, h) => {
83
+ if (alive)
84
+ setError(err);
85
+ onErrorRef.current?.(err, h);
86
+ };
87
+ const dispatchByKind = async (h) => {
88
+ const payload = (0, base64_js_1.fromBase64)(h.payload);
89
+ if (h.kind === "welcome") {
90
+ // Targeted at us → join the group, then join its room for future broadcast Commits.
91
+ if (h.targetDeviceId && h.targetDeviceId !== deviceId)
92
+ return;
93
+ const handle = await crypto.processWelcome(payload);
94
+ await rememberGroup(h.conversationId, handle);
95
+ socket.joinConversation(h.conversationId);
96
+ }
97
+ else if (h.kind === "commit") {
98
+ const group = await resolveGroup(h.conversationId);
99
+ if (!group) {
100
+ // Unknown group at a Commit: with seq ordering the Welcome precedes it, so we're not a
101
+ // member of this conversation. Skip (the cursor still advances so we don't re-fetch it).
102
+ report(new Error(`secure-chat: commit for unknown group ${h.conversationId}`), h);
103
+ return;
104
+ }
105
+ const advanced = await crypto.processCommit(group, payload);
106
+ await rememberGroup(h.conversationId, advanced);
107
+ }
108
+ else if (h.kind === "proposal") {
109
+ const group = await resolveGroup(h.conversationId);
110
+ if (group)
111
+ await crypto.processProposal(group, payload);
112
+ }
113
+ };
114
+ // The ONE place that mutates the cursor + crypto state. Dedupes by seq; advances the cursor even
115
+ // when a row is skipped or its dispatch throws, so a poison blob can never wedge the inbox. A hard
116
+ // crash mid-dispatch leaves the cursor unsaved, so the row replays on restart (no loss).
117
+ const applyOrdered = async (h) => {
118
+ if (cursorRef.current !== null && compareSeq(h.seq, cursorRef.current) <= 0)
119
+ return;
120
+ try {
121
+ await dispatchByKind(h);
122
+ }
123
+ catch (err) {
124
+ report(err, h);
125
+ }
126
+ cursorRef.current = h.seq;
127
+ await repo.saveHandshakeCursor(h.seq);
128
+ if (alive) {
129
+ setCursor(h.seq);
130
+ setProcessedCount((n) => n + 1);
131
+ }
132
+ };
133
+ const schedule = (h) => {
134
+ queue = queue.then(() => applyOrdered(h));
135
+ return queue;
136
+ };
137
+ const enqueueLive = (h) => {
138
+ // Buffer while catching up so a high-seq live event can't advance the cursor past rows the
139
+ // catch-up loop hasn't fetched yet (which the dedupe check would then drop).
140
+ if (catchingUpRef.current)
141
+ liveBuffer.push(h);
142
+ else
143
+ schedule(h);
144
+ };
145
+ // Coalesce overlapping invocations: a `resync()` fired while a catch-up is still draining returns
146
+ // the in-flight promise instead of starting a second drain (two drains would race the
147
+ // `catchingUpRef` gate + `liveBuffer` and could break seq ordering).
148
+ let catchUpInFlight = null;
149
+ const runCatchUp = () => {
150
+ if (catchUpInFlight)
151
+ return catchUpInFlight;
152
+ catchUpInFlight = (async () => {
153
+ catchingUpRef.current = true;
154
+ try {
155
+ for (;;) {
156
+ const page = await rest.fetchHandshakes(deviceId, {
157
+ since: cursorRef.current ?? undefined,
158
+ limit: pageSize,
159
+ });
160
+ for (const h of page.handshakes)
161
+ await schedule(h);
162
+ if (!page.hasMore)
163
+ break;
164
+ }
165
+ }
166
+ finally {
167
+ catchingUpRef.current = false;
168
+ // Replay anything that landed live during catch-up, in seq order, through the same queue.
169
+ const buffered = liveBuffer.splice(0).sort((a, b) => compareSeq(a.seq, b.seq));
170
+ for (const h of buffered)
171
+ schedule(h);
172
+ }
173
+ })().finally(() => {
174
+ catchUpInFlight = null;
175
+ });
176
+ return catchUpInFlight;
177
+ };
178
+ (async () => {
179
+ // Resolve the device row id (option wins; else the persisted device). Without one, there is no
180
+ // inbox to drain yet — the effect re-runs when `deviceId` is later supplied.
181
+ deviceId = deviceIdOption ?? (await repo.loadDevice())?.device?.id;
182
+ if (!alive || !deviceId)
183
+ return;
184
+ cursorRef.current = await repo.loadHandshakeCursor();
185
+ if (alive)
186
+ setCursor(cursorRef.current);
187
+ // Subscribe to live events BEFORE catch-up (buffered until catch-up completes).
188
+ offFns.push(socket.on("secure:welcome", enqueueLive));
189
+ offFns.push(socket.on("secure:handshake", enqueueLive));
190
+ runCatchUpRef.current = runCatchUp;
191
+ await runCatchUp();
192
+ // After a reload we hold group state but haven't joined the socket rooms, so broadcast Commits
193
+ // wouldn't arrive — re-join every known conversation.
194
+ try {
195
+ const convIds = await repo.listGroupConversationIds();
196
+ for (const c of convIds)
197
+ socket.joinConversation(c);
198
+ }
199
+ catch (err) {
200
+ report(err);
201
+ }
202
+ if (alive) {
203
+ setCatchingUp(false);
204
+ setReady(true);
205
+ }
206
+ })().catch((err) => report(err));
207
+ return () => {
208
+ alive = false;
209
+ offFns.forEach((off) => off());
210
+ runCatchUpRef.current = null;
211
+ };
212
+ }, [enabled, deviceIdOption, pageSize, rest, socket, repo, crypto, resolveGroup, rememberGroup]);
213
+ return { catchingUp, ready, cursor, processedCount, error, resync };
214
+ }
215
+ //# sourceMappingURL=useSecureHandshakes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSecureHandshakes.js","sourceRoot":"","sources":["../../../src/hooks/useSecureHandshakes.tsx"],"names":[],"mappings":";AAAA,kGAAkG;AAClG,EAAE;AACF,oGAAoG;AACpG,6FAA6F;AAC7F,oGAAoG;AACpG,sGAAsG;AACtG,sGAAsG;AACtG,4FAA4F;AAC5F,mBAAmB;AACnB,EAAE;AACF,mGAAmG;AACnG,uGAAuG;AACvG,yDAAyD;;AA6EzD,kDAmKC;AA9OD,iCAAiE;AAEjE,iDAA+C;AAC/C,8EAAkE;AAElE,0GAA0G;AAC1G,SAAS,UAAU,CAAC,CAAS,EAAE,CAAS;IACtC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAqCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,mBAAmB,CACjC,UAAsC,EAAE;IAExC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,IAAA,sCAAa,GAAE,CAAC;IACpF,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;IAExC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;IACnD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IA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,MAAM,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC;IAEjG,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AACtE,CAAC"}
@@ -28,7 +28,7 @@ const secure_chat_context_js_1 = require("../context/secure-chat-context.js");
28
28
  * ```
29
29
  */
30
30
  function useSecureMessages(conversationId, options = {}) {
31
- const { rest, crypto, socket, repo, resolveGroup } = (0, secure_chat_context_js_1.useSecureChat)();
31
+ const { rest, crypto, socket, repo, resolveGroup, getGroupVersion, subscribeGroupChange } = (0, secure_chat_context_js_1.useSecureChat)();
32
32
  const [messages, setMessages] = (0, react_1.useState)([]);
33
33
  const [before, setBefore] = (0, react_1.useState)(undefined);
34
34
  const [hasMore, setHasMore] = (0, react_1.useState)(true);
@@ -36,10 +36,19 @@ function useSecureMessages(conversationId, options = {}) {
36
36
  const [error, setError] = (0, react_1.useState)(null);
37
37
  const [group, setGroup] = (0, react_1.useState)(options.group ?? null);
38
38
  const [senderDeviceId, setSenderDeviceId] = (0, react_1.useState)(options.senderDeviceId);
39
+ // Bumps when THIS conversation's group handle advances (a join or a processed Commit, driven by
40
+ // useSecureHandshakes calling rememberGroup). Feeds the group-resolve effect's deps so we re-resolve
41
+ // the now-current handle and flush buffered (plaintext:null) rows.
42
+ const [groupVersion, setGroupVersion] = (0, react_1.useState)(0);
39
43
  // Latest messages, read by the "decrypt history once the group resolves" effect below without
40
44
  // making `messages` one of its deps (which would loop).
41
45
  const messagesRef = (0, react_1.useRef)(messages);
42
46
  messagesRef.current = messages;
47
+ // Subscribe to provider group-change signals; only a change to OUR conversation's version updates
48
+ // state (React bails on an unchanged primitive), so unrelated conversations don't re-resolve us.
49
+ (0, react_1.useEffect)(() => {
50
+ return subscribeGroupChange(() => setGroupVersion(getGroupVersion(conversationId)));
51
+ }, [subscribeGroupChange, getGroupVersion, conversationId]);
43
52
  // Resolve the group handle: explicit override, else persisted state.
44
53
  (0, react_1.useEffect)(() => {
45
54
  if (options.group) {
@@ -62,7 +71,8 @@ function useSecureMessages(conversationId, options = {}) {
62
71
  return () => {
63
72
  alive = false;
64
73
  };
65
- }, [options.group, conversationId, resolveGroup]);
74
+ // `groupVersion` re-runs this when a Commit/join advances the handle → flushes buffered rows.
75
+ }, [options.group, conversationId, resolveGroup, groupVersion]);
66
76
  // Resolve the sender device id: explicit override, else persisted device row.
67
77
  (0, react_1.useEffect)(() => {
68
78
  if (options.senderDeviceId) {
@@ -1 +1 @@
1
- {"version":3,"file":"useSecureMessages.js","sourceRoot":"","sources":["../../../src/hooks/useSecureMessages.tsx"],"names":[],"mappings":";AAAA,+FAA+F;AAC/F,EAAE;AACF,mGAAmG;AACnG,oGAAoG;AACpG,6FAA6F;AAC7F,6CAA6C;;AA2D7C,8CAoKC;AA7ND,iCAAiE;AAGjE,iDAAmF;AACnF,8EAAkE;AAoClE;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,iBAAiB,CAC/B,cAAsB,EACtB,UAAoC,EAAE;IAEtC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAA,sCAAa,GAAE,CAAC;IAErE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAA2B,EAAE,CAAC,CAAC;IACvE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAqB,SAAS,CAAC,CAAC;IACpE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAU,IAAI,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,Q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