@agora-sdk/secure-chat-core 0.7.0 → 0.8.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 (53) hide show
  1. package/dist/cjs/content/builders.d.ts +40 -0
  2. package/dist/cjs/content/builders.js +85 -0
  3. package/dist/cjs/content/builders.js.map +1 -0
  4. package/dist/cjs/content/cbor.d.ts +48 -0
  5. package/dist/cjs/content/cbor.js +298 -0
  6. package/dist/cjs/content/cbor.js.map +1 -0
  7. package/dist/cjs/content/frame.d.ts +24 -0
  8. package/dist/cjs/content/frame.js +39 -0
  9. package/dist/cjs/content/frame.js.map +1 -0
  10. package/dist/cjs/content/mimi-content.d.ts +194 -0
  11. package/dist/cjs/content/mimi-content.js +289 -0
  12. package/dist/cjs/content/mimi-content.js.map +1 -0
  13. package/dist/cjs/hooks/message-fold.d.ts +91 -0
  14. package/dist/cjs/hooks/message-fold.js +218 -0
  15. package/dist/cjs/hooks/message-fold.js.map +1 -0
  16. package/dist/cjs/hooks/useSecureMessages.d.ts +30 -18
  17. package/dist/cjs/hooks/useSecureMessages.js +190 -238
  18. package/dist/cjs/hooks/useSecureMessages.js.map +1 -1
  19. package/dist/cjs/index.d.ts +7 -0
  20. package/dist/cjs/index.js +27 -1
  21. package/dist/cjs/index.js.map +1 -1
  22. package/dist/cjs/persistence/repository.d.ts +11 -11
  23. package/dist/cjs/persistence/repository.js +19 -19
  24. package/dist/cjs/persistence/repository.js.map +1 -1
  25. package/dist/cjs/version.d.ts +1 -1
  26. package/dist/cjs/version.js +1 -1
  27. package/dist/esm/content/builders.d.ts +40 -0
  28. package/dist/esm/content/builders.js +77 -0
  29. package/dist/esm/content/builders.js.map +1 -0
  30. package/dist/esm/content/cbor.d.ts +48 -0
  31. package/dist/esm/content/cbor.js +292 -0
  32. package/dist/esm/content/cbor.js.map +1 -0
  33. package/dist/esm/content/frame.d.ts +24 -0
  34. package/dist/esm/content/frame.js +34 -0
  35. package/dist/esm/content/frame.js.map +1 -0
  36. package/dist/esm/content/mimi-content.d.ts +194 -0
  37. package/dist/esm/content/mimi-content.js +283 -0
  38. package/dist/esm/content/mimi-content.js.map +1 -0
  39. package/dist/esm/hooks/message-fold.d.ts +91 -0
  40. package/dist/esm/hooks/message-fold.js +214 -0
  41. package/dist/esm/hooks/message-fold.js.map +1 -0
  42. package/dist/esm/hooks/useSecureMessages.d.ts +30 -18
  43. package/dist/esm/hooks/useSecureMessages.js +192 -240
  44. package/dist/esm/hooks/useSecureMessages.js.map +1 -1
  45. package/dist/esm/index.d.ts +7 -0
  46. package/dist/esm/index.js +6 -0
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/persistence/repository.d.ts +11 -11
  49. package/dist/esm/persistence/repository.js +19 -19
  50. package/dist/esm/persistence/repository.js.map +1 -1
  51. package/dist/esm/version.d.ts +1 -1
  52. package/dist/esm/version.js +1 -1
  53. package/package.json +3 -2
@@ -1,45 +1,58 @@
1
- // useSecureMessages — load, decrypt, send, and live-receive messages in a secure conversation.
1
+ // useSecureMessages — load, decrypt, send, and live-receive MIMI-content messages in a secure conversation.
2
2
  //
3
- // Self-sufficient once a store is wired: the MLS GroupHandle is auto-resolved from persistence via
4
- // resolveGroup, and senderDeviceId is read from the persisted device. Both stay overridable through
5
- // options for advanced use. Without a resolvable handle, ciphertext is still listed/received
6
- // (plaintext: null) and sending is disabled.
7
- import { useCallback, useEffect, useRef, useState } from "react";
3
+ // Content is the IETF MimiContent format (CBOR) inside a [kind][payload] routing frame inside the
4
+ // size-bucket padding frame all ABOVE the unchanged SecureChatCrypto seam (which still exchanges
5
+ // Uint8Array). The hook owns message-list STATE (dedup, ordering, decrypt-once, write-through) keyed by
6
+ // server messageId; a MessageFold collapses reaction/edit/delete/un-react messages onto their target by
7
+ // MIMI content-hash. The durable source of truth stays REST; realtime is a notification optimization.
8
+ import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from "react";
8
9
  import { SecureChatDecryptError, } from "@agora-sdk/secure-chat-crypto";
9
- import { toBase64, fromBase64, utf8ToBytes, bytesToUtf8 } from "../util/base64.js";
10
+ import { toBase64, fromBase64 } from "../util/base64.js";
10
11
  import { padPlaintext, unpadPlaintext } from "../util/padding.js";
11
12
  import { createDebugLogger } from "../util/debug.js";
12
13
  import { useSecureChat } from "../context/secure-chat-context.js";
14
+ import { frameContent, unframe, ContentKind } from "../content/frame.js";
15
+ import { encodeMimiContent, decodeMimiContent, contentHash, } from "../content/mimi-content.js";
16
+ import { buildPost, buildReply, buildEdit, buildDelete, buildReaction, buildUnreact, } from "../content/builders.js";
17
+ import { MessageFold, } from "./message-fold.js";
13
18
  const log = createDebugLogger("messages");
14
- /**
15
- * Merge two copies of the SAME message (same id) seen via different paths (REST load, retry, live
16
- * echo), keeping the more-resolved one. A row's status may only ever IMPROVE.
17
- *
18
- * This is load-bearing for E2EE correctness, not just de-dup hygiene: MLS application-message keys are
19
- * single-use (forward secrecy), so the ONE decrypt attempt that succeeds is the only one that ever
20
- * will — that attempt also *consumes* the key, so a later re-attempt necessarily fails. If a message
21
- * is loaded as `pending` (group not resolved yet) and then the live echo decrypts it `ok`, naively
22
- * "keep the first-seen row" would discard the only successful decryption and strand the message on
23
- * "waiting for key update" forever. So `ok` always wins; a failed re-attempt (`pending`/`rejected`)
24
- * must never overwrite an `ok`; otherwise keep the existing row (the retry effect handles `pending`).
25
- *
26
- * @param existing - The row already in state.
27
- * @param incoming - A freshly-produced row for the same message id.
28
- * @returns Whichever row is more resolved (`ok` \> anything; else `existing`).
29
- */
30
- function preferResolved(existing, incoming) {
31
- if (existing.status === "ok")
32
- return existing; // never downgrade a successful decrypt
33
- if (incoming.status === "ok")
34
- return incoming; // upgrade pending/rejected → ok
35
- return existing; // both unresolved: keep existing (a `pending` row is retried by the group effect)
19
+ const REJECT_MALFORMED = { status: "rejected", rejectedReason: "malformed" };
20
+ /** Decode a content-frame to a typed outcome. Pure; fails closed on any framing/schema error. */
21
+ function decodeFrame(frameBytes, model, senderDeviceId) {
22
+ let unf;
23
+ try {
24
+ unf = unframe(frameBytes);
25
+ }
26
+ catch {
27
+ return REJECT_MALFORMED;
28
+ }
29
+ // kind 1 = IUC control (reserved; out of scope here): authenticate + hide, never render, never error.
30
+ if (unf.kind === ContentKind.IucControl)
31
+ return { status: "ok", control: true };
32
+ if (unf.kind !== ContentKind.Mimi)
33
+ return REJECT_MALFORMED;
34
+ let mimi;
35
+ try {
36
+ mimi = decodeMimiContent(unf.payload);
37
+ }
38
+ catch {
39
+ return REJECT_MALFORMED;
40
+ }
41
+ return {
42
+ status: "ok",
43
+ control: false,
44
+ decoded: {
45
+ messageId: model.id,
46
+ createdAt: model.createdAt,
47
+ senderDeviceId,
48
+ contentHash: contentHash(mimi),
49
+ mimi,
50
+ },
51
+ };
36
52
  }
53
+ const cmpStr = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
37
54
  /**
38
- * Load, decrypt, send, and live-receive messages in one secure conversation.
39
- *
40
- * Auto-resolves the MLS group handle (via `resolveGroup`) and the sender device id (from the
41
- * persisted device) unless overridden in `options`. Joins the conversation socket room for live
42
- * `secure:message` events.
55
+ * Load, decrypt, send, and live-receive MIMI-content messages in one secure conversation.
43
56
  *
44
57
  * @param conversationId - The conversation to read and send within.
45
58
  * @param options - {@link UseSecureMessagesOptions}.
@@ -47,82 +60,54 @@ function preferResolved(existing, incoming) {
47
60
  *
48
61
  * @example
49
62
  * ```tsx
50
- * const { messages, sendMessage } = useSecureMessages(conversationId);
63
+ * const { messages, sendMessage, react } = useSecureMessages(conversationId);
51
64
  * await sendMessage("hello 💜");
65
+ * await react(messages[0].contentHash!, "👍");
52
66
  * ```
53
67
  */
54
68
  export function useSecureMessages(conversationId, options = {}) {
55
69
  const { rest, crypto, socket, repo, resolveGroup, persistGroupState, getGroupVersion, subscribeGroupChange, padding, } = useSecureChat();
56
- const [messages, setMessages] = useState([]);
57
70
  const [before, setBefore] = useState(undefined);
58
71
  const [hasMore, setHasMore] = useState(true);
59
72
  const [loading, setLoading] = useState(false);
60
73
  const [error, setError] = useState(null);
61
74
  const [group, setGroup] = useState(options.group ?? null);
62
75
  const [senderDeviceId, setSenderDeviceId] = useState(options.senderDeviceId);
63
- // Bumps when THIS conversation's group handle advances (a join or a processed Commit, driven by
64
- // useSecureHandshakes calling rememberGroup). Feeds the group-resolve effect's deps so we re-resolve
65
- // the now-current handle and flush buffered (plaintext:null) rows.
66
76
  const [groupVersion, setGroupVersion] = useState(0);
67
- // Latest messages, read by the "decrypt history once the group resolves" effect below without
68
- // making `messages` one of its deps (which would loop).
69
- const messagesRef = useRef(messages);
70
- messagesRef.current = messages;
71
- // `decrypt` reads the LIVE group through this ref, not its closure. A message page that finishes
72
- // loading AFTER the group resolves must decrypt with the now-current handle instead of stranding as
73
- // `pending` the load's closure may have captured `group` while it was still null.
77
+ // Rendered state lives in refs (the fold mutates target rows in place); `bump` forces a re-derive.
78
+ const byIdRef = useRef(new Map());
79
+ const foldRef = useRef(new MessageFold());
80
+ // Decrypt-once cache by id: MLS application keys are single-use, so the one decrypt that succeeds is
81
+ // the only one that ever will. Survives StrictMode double-invokes and multi-effect decrypts.
82
+ const okCache = useRef(new Map());
83
+ const [version, bump] = useReducer((x) => x + 1, 0);
74
84
  const groupRef = useRef(group);
75
85
  groupRef.current = group;
76
- // Decrypt-once cache, by message id — the in-memory tier of a TWO-tier store. MLS application keys
77
- // are SINGLE-USE (forward secrecy): the one decrypt that succeeds consumes the key, so any later
78
- // attempt fails (`"Desired gen in the past"`). The hook decrypts the same message from several
79
- // effects (load, retry, live echo) and React StrictMode double-invokes them — so without this cache
80
- // the key could be consumed on a run whose `ok` result is then discarded, leaving the message
81
- // permanently un-decryptable. This cache covers within-session repeats; `decrypt` ALSO write-throughs
82
- // each `ok` to the durable plaintext store (repo.saveMessagePlaintext) so history survives reload
83
- // without ever replaying the consumed ratchet. Only `ok` is cached (terminal); `pending`/`rejected`
84
- // stay retryable. Ids are globally-unique server uuids, so this never needs clearing per-conversation.
85
- const okCache = useRef(new Map());
86
- // Subscribe to provider group-change signals; only a change to OUR conversation's version updates
87
- // state (React bails on an unchanged primitive), so unrelated conversations don't re-resolve us.
88
86
  useEffect(() => {
89
87
  return subscribeGroupChange(() => setGroupVersion(getGroupVersion(conversationId)));
90
88
  }, [subscribeGroupChange, getGroupVersion, conversationId]);
91
- // Resolve the group handle: explicit override, else persisted state.
89
+ // Resolve the group handle: explicit override, else persisted state. (Same as before.)
92
90
  useEffect(() => {
93
91
  if (options.group) {
94
92
  setGroup(options.group);
95
93
  return;
96
94
  }
97
- // Clear any stale handle from the previous conversation before re-resolving, so live messages
98
- // for the new conversation never decrypt against the old group during the async window.
99
95
  setGroup(null);
100
96
  let alive = true;
101
97
  resolveGroup(conversationId)
102
98
  .then((g) => {
103
- if (alive) {
99
+ if (alive)
104
100
  setGroup(g);
105
- log.debug("group handle set in messages hook", {
106
- conversationId,
107
- resolved: !!g,
108
- epoch: g?.epoch?.toString(),
109
- });
110
- }
111
101
  })
112
- .catch((err) => {
102
+ .catch(() => {
113
103
  if (alive)
114
104
  setGroup(null);
115
- log.debug("group resolve failed in messages hook", {
116
- conversationId,
117
- error: err instanceof Error ? err.message : String(err),
118
- });
119
105
  });
120
106
  return () => {
121
107
  alive = false;
122
108
  };
123
- // `groupVersion` re-runs this when a Commit/join advances the handle → flushes buffered rows.
124
109
  }, [options.group, conversationId, resolveGroup, groupVersion]);
125
- // Resolve the sender device id: explicit override, else persisted device row.
110
+ // Resolve the sender device id: explicit override, else persisted device row. (Same as before.)
126
111
  useEffect(() => {
127
112
  if (options.senderDeviceId) {
128
113
  setSenderDeviceId(options.senderDeviceId);
@@ -143,132 +128,127 @@ export function useSecureMessages(conversationId, options = {}) {
143
128
  alive = false;
144
129
  };
145
130
  }, [options.senderDeviceId, repo]);
131
+ // Decrypt one message to a typed outcome. Two short-circuits BEFORE the single-use ratchet: the
132
+ // in-memory okCache and the durable content-frame store. A store/cache hit re-decodes locally and
133
+ // NEVER touches the ratchet (re-decrypting a consumed key throws "Desired gen in the past").
146
134
  const decrypt = useCallback(async (model) => {
147
- // Decrypt-once (in-memory tier): a message decoded earlier this session is returned from cache —
148
- // never re-run the MLS decrypt (its single-use key is already consumed; a second attempt fails).
149
135
  const cached = okCache.current.get(model.id);
150
136
  if (cached)
151
137
  return cached;
152
- // Decrypt-once (durable tier): a message decoded in a PRIOR session is served from the local
153
- // plaintext store. This is what makes history survive reload — the re-imported ratchet can't
154
- // reproduce a consumed key, so re-decrypting would throw "Desired gen in the past". A store hit
155
- // therefore must NOT touch the ratchet. (The blind server never sees this plaintext.)
156
- const stored = await repo.loadMessagePlaintext(conversationId, model.id);
157
- if (stored !== null) {
158
- const restored = { model, plaintext: stored, status: "ok" };
159
- okCache.current.set(model.id, restored);
160
- return restored;
161
- }
162
- // Read the LIVE group via the ref (not a stale closure): a load that finishes after the group
163
- // resolved must decrypt with the now-current handle, not the null it captured when it started.
164
- const group = groupRef.current;
165
- // No handle yet (still resolving) → retryable once it arrives.
166
- if (!group) {
167
- log.trace("decrypt deferred — no group handle yet", { messageId: model.id, epoch: model.epoch });
168
- return { model, plaintext: null, status: "pending" };
138
+ const storedFrame = await repo.loadMessageContent(conversationId, model.id);
139
+ if (storedFrame !== null) {
140
+ // The frame was already authenticated when first decrypted (and write-through only happens on an
141
+ // `ok` decrypt). The server-reported senderDeviceId is just a render label here; coalesce its
142
+ // possible null to "" so the fold's DecodedContentMessage stays a plain string.
143
+ const outcome = decodeFrame(storedFrame, model, model.senderDeviceId ?? "");
144
+ if (outcome.status === "ok")
145
+ okCache.current.set(model.id, outcome);
146
+ return outcome;
169
147
  }
148
+ const grp = groupRef.current;
149
+ if (!grp)
150
+ return { status: "pending" };
170
151
  let plaintext;
152
+ let sender;
171
153
  try {
172
- ({ plaintext } = await crypto.decryptMessage(group, fromBase64(model.ciphertext)));
154
+ ({ plaintext, senderDeviceId: sender } = await crypto.decryptMessage(grp, fromBase64(model.ciphertext)));
173
155
  }
174
156
  catch (err) {
175
- // Classify, don't conflate. A message from an epoch we HAVEN'T reached yet is legitimately
176
- // buffered (a future Commit will advance us, then this re-decrypts). Anything else that fails
177
- // at an epoch we HAVE reached is a terminal rejection — the MLS core refused it (replay,
178
- // over-window gap, bad auth, malformed, too-old epoch). Fail closed: never show it as text and
179
- // never silently retry it forever (the old behavior masked replays/forgeries as "pending").
180
- if (BigInt(model.epoch) > group.epoch) {
181
- log.debug("decrypt buffered — message epoch ahead of ours", {
182
- messageId: model.id,
183
- messageEpoch: model.epoch,
184
- groupEpoch: group.epoch.toString(),
185
- });
186
- return { model, plaintext: null, status: "pending" };
187
- }
157
+ if (BigInt(model.epoch) > grp.epoch)
158
+ return { status: "pending" }; // epoch ahead buffer
188
159
  const rejectedReason = err instanceof SecureChatDecryptError ? err.reason : "unknown";
189
- log.debug("decrypt rejected (fail closed)", {
190
- messageId: model.id,
191
- messageEpoch: model.epoch,
192
- groupEpoch: group.epoch.toString(),
193
- rejectedReason,
194
- });
195
- return { model, plaintext: null, status: "rejected", rejectedReason };
160
+ return { status: "rejected", rejectedReason };
196
161
  }
197
- // Decrypt + MLS authentication succeeded, so the bytes are from a real group member. Strip the
198
- // size-bucket padding frame (see util/padding). A bad frame here is NOT a decrypt failure — it's a
199
- // framing/version mismatch from an authenticated sender — so fail closed as "malformed" rather
200
- // than rendering raw padded bytes as text.
201
- let text;
162
+ let frameBytes;
202
163
  try {
203
- text = bytesToUtf8(unpadPlaintext(plaintext));
164
+ frameBytes = unpadPlaintext(plaintext); // authenticated sender, bad padding ⇒ malformed (fail closed)
204
165
  }
205
166
  catch {
206
- return { model, plaintext: null, status: "rejected", rejectedReason: "malformed" };
167
+ return REJECT_MALFORMED;
207
168
  }
208
- const ok = { model, plaintext: text, status: "ok" };
209
- okCache.current.set(model.id, ok); // cache the (single) successful decode for all later callers
210
- // Write-through to the durable store so this decode survives reload, and persist the now-advanced
211
- // RECEIVE ratchet: decrypt moved the group's generation in memory, so if we don't persist it a
212
- // reload rewinds the ratchet and the next send/receive desyncs. Persist plaintext FIRST if the
213
- // group-state write somehow fails, the message is still recoverable from the plaintext store.
214
- await repo.saveMessagePlaintext(conversationId, model.id, text);
215
- await persistGroupState(conversationId, group);
216
- return ok;
169
+ const outcome = decodeFrame(frameBytes, model, sender);
170
+ if (outcome.status === "ok") {
171
+ okCache.current.set(model.id, outcome);
172
+ // Write-through the raw content-frame bytes (re-decoded + re-folded on reload), then persist the
173
+ // advanced RECEIVE ratchet (decrypt moved the generation in memory; a reload must not rewind it).
174
+ await repo.saveMessageContent(conversationId, model.id, frameBytes);
175
+ await persistGroupState(conversationId, grp);
176
+ }
177
+ return outcome;
217
178
  }, [crypto, repo, conversationId, persistGroupState]);
179
+ // Fold one outcome into rendered state. `ok` is terminal (never downgraded — forward secrecy).
180
+ const ingest = useCallback((model, outcome) => {
181
+ const entries = byIdRef.current;
182
+ const prev = entries.get(model.id);
183
+ if (prev?.status === "ok")
184
+ return;
185
+ if (outcome.status === "ok") {
186
+ if (outcome.control) {
187
+ entries.set(model.id, { model, status: "ok", renderable: false });
188
+ }
189
+ else {
190
+ const { renderable } = foldRef.current.apply(outcome.decoded);
191
+ entries.set(model.id, { model, status: "ok", renderable, decoded: outcome.decoded });
192
+ }
193
+ }
194
+ else if (outcome.status === "pending") {
195
+ if (!prev)
196
+ entries.set(model.id, { model, status: "pending", renderable: false });
197
+ }
198
+ else {
199
+ if (!prev || prev.status === "pending")
200
+ entries.set(model.id, { model, status: "rejected", renderable: false, rejectedReason: outcome.rejectedReason });
201
+ }
202
+ bump();
203
+ }, []);
204
+ // Derive the rendered list: only renderable (post/reply) rows + non-ok rows, newest-first. Mutation
205
+ // and control rows are folded/hidden. Recomputed on every `bump` (fold mutates rows in place).
206
+ const messages = useMemo(() => {
207
+ const rows = [];
208
+ for (const e of byIdRef.current.values()) {
209
+ if (e.status === "ok") {
210
+ if (!e.renderable)
211
+ continue;
212
+ rows.push({
213
+ model: e.model,
214
+ content: foldRef.current.getContent(e.model.id),
215
+ mimi: e.decoded?.mimi ?? null,
216
+ contentHash: e.decoded?.contentHash ?? null,
217
+ status: "ok",
218
+ });
219
+ }
220
+ else {
221
+ rows.push({ model: e.model, content: null, mimi: null, contentHash: null, status: e.status, rejectedReason: e.rejectedReason });
222
+ }
223
+ }
224
+ rows.sort((a, b) => cmpStr(b.model.createdAt, a.model.createdAt) || cmpStr(b.model.id, a.model.id));
225
+ return rows;
226
+ // eslint-disable-next-line react-hooks/exhaustive-deps
227
+ }, [version]);
218
228
  const load = useCallback(async (reset) => {
219
229
  setLoading(true);
220
230
  setError(null);
221
231
  try {
222
- const page = await rest.listMessages(conversationId, {
223
- before: reset ? undefined : before,
224
- limit: 40,
225
- });
226
- const decrypted = await Promise.all(page.messages.map(decrypt));
232
+ const page = await rest.listMessages(conversationId, { before: reset ? undefined : before, limit: 40 });
233
+ if (reset) {
234
+ byIdRef.current.clear();
235
+ foldRef.current.reset();
236
+ }
227
237
  const oldest = page.messages[page.messages.length - 1];
228
238
  setBefore(oldest ? oldest.createdAt : before);
229
239
  setHasMore(page.hasMore);
230
- // Server returns created_at DESC; keep newest-first in state. Merge by id when appending an
231
- // older page: a row already in state (one that arrived live, or an overlap at the page
232
- // boundary) must not be appended twice (duplicate React key) — but if this page decrypted a row
233
- // we're still holding as `pending`, UPGRADE it in place rather than dropping the decode (same
234
- // forward-secrecy reasoning as the live path). `reset` replaces wholesale.
235
- setMessages((prev) => {
236
- if (reset)
237
- return decrypted;
238
- const indexById = new Map(prev.map((p, idx) => [p.model.id, idx]));
239
- const next = prev.slice();
240
- const appended = [];
241
- for (const m of decrypted) {
242
- const idx = indexById.get(m.model.id);
243
- if (idx === undefined)
244
- appended.push(m);
245
- else
246
- next[idx] = preferResolved(next[idx], m);
247
- }
248
- return [...next, ...appended];
249
- });
250
- log.debug("loaded message page", {
251
- conversationId,
252
- reset,
253
- before: reset ? undefined : before,
254
- count: decrypted.length,
255
- hasMore: page.hasMore,
256
- ok: decrypted.filter((m) => m.status === "ok").length,
257
- pending: decrypted.filter((m) => m.status === "pending").length,
258
- rejected: decrypted.filter((m) => m.status === "rejected").length,
259
- });
240
+ for (const model of page.messages)
241
+ ingest(model, await decrypt(model));
242
+ bump();
243
+ log.debug("loaded message page", { conversationId, reset, count: page.messages.length, hasMore: page.hasMore });
260
244
  }
261
245
  catch (err) {
262
- log.debug("load message page failed", {
263
- conversationId,
264
- error: err instanceof Error ? err.message : String(err),
265
- });
266
246
  setError(err);
267
247
  }
268
248
  finally {
269
249
  setLoading(false);
270
250
  }
271
- }, [rest, conversationId, before, decrypt]);
251
+ }, [rest, conversationId, before, decrypt, ingest]);
272
252
  const refresh = useCallback(async () => {
273
253
  setBefore(undefined);
274
254
  await load(true);
@@ -278,103 +258,75 @@ export function useSecureMessages(conversationId, options = {}) {
278
258
  return;
279
259
  await load(false);
280
260
  }, [hasMore, loading, load]);
281
- const sendMessage = useCallback(async (text) => {
282
- // Assumes the crypto identity is already hydrated (mount `useSecureDevice` under the same
283
- // provider): the crypto layer tags the sender from the restored device identity, so after a
284
- // reload the first send must wait for useSecureDevice's importDeviceState to complete.
261
+ // Shared send: encode frame → pad → encrypt → persist ratchet → POST → persist content → optimistic.
262
+ const sendContent = useCallback(async (mimi) => {
285
263
  if (!group)
286
264
  throw new Error("Cannot send: no MLS group handle for this conversation.");
287
265
  if (!senderDeviceId)
288
266
  throw new Error("Cannot send: senderDeviceId is required.");
289
- // Pad the plaintext to a size bucket BEFORE encryption so the ciphertext length leaks less
290
- // (the receiver strips the frame in `decrypt`). See util/padding for the framing.
291
- const { ciphertext, epoch } = await crypto.encryptMessage(group, padPlaintext(utf8ToBytes(text), padding));
292
- // The send ratchet just advanced in memory. Persist NOW — BEFORE the network send — because the
293
- // ratchet moved regardless of whether the send succeeds. If we skipped this, a reload would
294
- // re-import the last-committed state, rewind the send ratchet to a consumed generation, and the
295
- // peer would reject our next message as a replay (the exact bug this fixes). A failed network
296
- // send instead leaves at most a one-generation forward gap, which the peer tolerates within its
297
- // key-retention window — fail-safe-forward, never a replay.
267
+ const frame = frameContent(ContentKind.Mimi, encodeMimiContent(mimi));
268
+ const { ciphertext, epoch } = await crypto.encryptMessage(group, padPlaintext(frame, padding));
269
+ // Persist the advanced SEND ratchet BEFORE the network send (it moved regardless of success).
298
270
  await persistGroupState(conversationId, group);
299
271
  const sent = await rest.sendMessage(conversationId, {
300
272
  ciphertext: toBase64(ciphertext),
301
273
  epoch: epoch.toString(),
302
274
  senderDeviceId,
303
275
  });
304
- // Persist our own plaintext: we can't re-decrypt our own single-use MLS message after reload (and
305
- // the server's echo of it self-rejects), so without this our own history would blank on reload.
306
- await repo.saveMessagePlaintext(conversationId, sent.id, text);
307
- log.debug("sent message", {
308
- conversationId,
309
- messageId: sent.id,
310
- epoch: epoch.toString(),
311
- senderDeviceId,
312
- });
313
- // Optimistic: we know our own plaintext without a round-trip through decrypt. Dedup by id while
314
- // prepending: the server echoes this same row back over `secure:message`, and a sender can't
315
- // decrypt their own MLS message, so that echo decrypts as `rejected`. If the echo wins the race
316
- // against this HTTP response it's already in `prev` — drop it and keep this authoritative `ok`
317
- // copy, so the list never holds two rows with the same id (React duplicate-key) and the user
318
- // never sees their own message as `rejected`. (The live-receive path dedups the other ordering.)
319
- setMessages((prev) => [
320
- { model: sent, plaintext: text, status: "ok" },
321
- ...prev.filter((p) => p.model.id !== sent.id),
322
- ]);
323
- }, [crypto, rest, repo, conversationId, group, senderDeviceId, padding, persistGroupState]);
276
+ await repo.saveMessageContent(conversationId, sent.id, frame);
277
+ // Optimistic: we can't decrypt our own MLS message, so seed the decoded content directly and cache
278
+ // it so the server echo short-circuits (no rejected flicker).
279
+ const decoded = {
280
+ messageId: sent.id, createdAt: sent.createdAt, senderDeviceId, contentHash: contentHash(mimi), mimi,
281
+ };
282
+ const outcome = { status: "ok", control: false, decoded };
283
+ okCache.current.set(sent.id, outcome);
284
+ ingest(sent, outcome);
285
+ log.debug("sent content", { conversationId, messageId: sent.id, epoch: epoch.toString() });
286
+ }, [crypto, rest, repo, conversationId, group, senderDeviceId, padding, persistGroupState, ingest]);
287
+ const sendMessage = useCallback((text) => sendContent(buildPost(text)), [sendContent]);
288
+ const reply = useCallback((t, text) => sendContent(buildReply(text, t)), [sendContent]);
289
+ const react = useCallback((t, token) => sendContent(buildReaction(t, token)), [sendContent]);
290
+ const editMessage = useCallback((t, text) => sendContent(buildEdit(t, text)), [sendContent]);
291
+ const deleteMessage = useCallback((t) => sendContent(buildDelete(t)), [sendContent]);
292
+ const unreact = useCallback((reactionHash) => sendContent(buildUnreact(reactionHash)), [sendContent]);
324
293
  useEffect(() => {
325
294
  refresh();
326
295
  // eslint-disable-next-line react-hooks/exhaustive-deps
327
296
  }, [conversationId]);
328
- // Re-decrypt buffered rows when the group handle advances. On reload the first page loads while
329
- // resolveGroup is still in flight (those rows come back `pending`); a Commit/join also advances the
330
- // epoch, letting previously-ahead rows decrypt. Retry ONLY `pending` rows — never `rejected` ones, so
331
- // a replay/forgery the core already refused isn't retried on every epoch bump. `ok` rows are kept.
297
+ // Retry buffered (pending) rows when the group handle advances.
332
298
  useEffect(() => {
333
299
  if (!group)
334
300
  return;
335
- if (!messagesRef.current.some((m) => m.status === "pending"))
301
+ const pendingModels = [...byIdRef.current.values()].filter((e) => e.status === "pending").map((e) => e.model);
302
+ if (pendingModels.length === 0)
336
303
  return;
337
304
  let alive = true;
338
- Promise.all(messagesRef.current.map((m) => (m.status === "pending" ? decrypt(m.model) : Promise.resolve(m)))).then((next) => {
339
- if (alive)
340
- setMessages(next);
341
- });
305
+ (async () => {
306
+ for (const m of pendingModels) {
307
+ const outcome = await decrypt(m);
308
+ if (!alive)
309
+ return;
310
+ ingest(m, outcome);
311
+ }
312
+ })();
342
313
  return () => {
343
314
  alive = false;
344
315
  };
345
- }, [group, decrypt]);
346
- // Live receive: join the conversation room and decrypt inbound ciphertext.
316
+ }, [group, decrypt, ingest]);
317
+ // Live receive: join the conversation room and decrypt+ingest inbound ciphertext.
347
318
  useEffect(() => {
348
319
  socket.joinConversation(conversationId);
349
320
  const off = socket.on("secure:message", (model) => {
350
321
  if (model.conversationId !== conversationId)
351
322
  return;
352
- decrypt(model).then((m) => setMessages((prev) => {
353
- const i = prev.findIndex((p) => p.model.id === m.model.id);
354
- if (i === -1) {
355
- log.debug("live message received", {
356
- conversationId,
357
- messageId: m.model.id,
358
- status: m.status,
359
- });
360
- return [m, ...prev];
361
- }
362
- // Already present (e.g. loaded as `pending` before the group resolved): keep the more-resolved
363
- // copy in place — NEVER drop this `ok` for a stale `pending`. The decrypt above consumed the
364
- // single-use MLS key, so this may be the only successful decode the message ever gets.
365
- const merged = preferResolved(prev[i], m);
366
- if (merged === prev[i]) {
367
- log.trace("live message deduped (kept existing)", { messageId: m.model.id, status: prev[i].status });
368
- return prev;
369
- }
370
- log.debug("live message upgraded", { conversationId, messageId: m.model.id, status: merged.status });
371
- const next = prev.slice();
372
- next[i] = merged;
373
- return next;
374
- }));
323
+ decrypt(model).then((outcome) => ingest(model, outcome));
375
324
  });
376
325
  return off;
377
- }, [socket, conversationId, decrypt]);
378
- return { messages, loading, hasMore, error, loadMore, refresh, sendMessage };
326
+ }, [socket, conversationId, decrypt, ingest]);
327
+ return {
328
+ messages, loading, hasMore, error, loadMore, refresh,
329
+ sendMessage, reply, react, editMessage, deleteMessage, unreact,
330
+ };
379
331
  }
380
332
  //# sourceMappingURL=useSecureMessages.js.map
@@ -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;AAE7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAEL,sBAAsB,GAEvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MA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