@ping-app/ping-openmls-sdk 0.0.0-stage → 0.10.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 (39) hide show
  1. package/README.md +94 -2
  2. package/dist/index.cjs +2782 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +1229 -0
  5. package/dist/index.d.ts +1229 -0
  6. package/dist/index.js +2715 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/notification-preview.cjs +137 -0
  9. package/dist/notification-preview.cjs.map +1 -0
  10. package/dist/notification-preview.d.cts +85 -0
  11. package/dist/notification-preview.d.ts +85 -0
  12. package/dist/notification-preview.js +98 -0
  13. package/dist/notification-preview.js.map +1 -0
  14. package/dist/storage/indexeddb.cjs +153 -0
  15. package/dist/storage/indexeddb.cjs.map +1 -0
  16. package/dist/storage/indexeddb.d.cts +21 -0
  17. package/dist/storage/indexeddb.d.ts +21 -0
  18. package/dist/storage/indexeddb.js +128 -0
  19. package/dist/storage/indexeddb.js.map +1 -0
  20. package/dist/transport/websocket.cjs +121 -0
  21. package/dist/transport/websocket.cjs.map +1 -0
  22. package/dist/transport/websocket.d.cts +23 -0
  23. package/dist/transport/websocket.d.ts +23 -0
  24. package/dist/transport/websocket.js +94 -0
  25. package/dist/transport/websocket.js.map +1 -0
  26. package/dist/types-B1GFwNXa.d.cts +535 -0
  27. package/dist/types-B1GFwNXa.d.ts +535 -0
  28. package/dist/worker.cjs +841 -0
  29. package/dist/worker.cjs.map +1 -0
  30. package/dist/worker.d.cts +2 -0
  31. package/dist/worker.d.ts +2 -0
  32. package/dist/worker.js +848 -0
  33. package/dist/worker.js.map +1 -0
  34. package/package.json +61 -4
  35. package/wasm/package.json +17 -0
  36. package/wasm/ping_wasm.d.ts +909 -0
  37. package/wasm/ping_wasm.js +3028 -0
  38. package/wasm/ping_wasm_bg.wasm +0 -0
  39. package/wasm/ping_wasm_bg.wasm.d.ts +112 -0
@@ -0,0 +1,535 @@
1
+ type Bytes = Uint8Array;
2
+ type UserId = Bytes;
3
+ type DeviceId = Bytes;
4
+ type ConversationId = Bytes;
5
+ interface Hlc {
6
+ wall_ms: number;
7
+ logical: number;
8
+ }
9
+ type MessageKind = "Application" | "Commit" | "Welcome" | "Proposal" | "KeyPackage";
10
+ interface MessageEnvelope {
11
+ v: number;
12
+ conversation_id: ConversationId;
13
+ epoch: number;
14
+ kind: MessageKind;
15
+ sender_device: DeviceId;
16
+ seq: number;
17
+ hlc: Hlc;
18
+ payload: Bytes;
19
+ content_hash: Bytes;
20
+ }
21
+ /** The sender's EFFECTIVE role (2026-11-18): the LOWER of the role it held at
22
+ * the MLS epoch its message was sent in and the role its identity holds in
23
+ * this device's group state at the message's position in the delivery order. The
24
+ * conversation's recorded owner, one of its admins, or a member (also a
25
+ * sender whose role this device cannot prove, and an admin demoted or
26
+ * removed by the time its message is processed). */
27
+ type SenderRole = "owner" | "admin" | "member";
28
+ interface IncomingMessage {
29
+ conversation_id: ConversationId;
30
+ sender_device: DeviceId;
31
+ sender_user_id: UserId;
32
+ epoch: number;
33
+ hlc: Hlc;
34
+ plaintext: Bytes;
35
+ content_hash: Bytes;
36
+ sender_role?: SenderRole | null;
37
+ journal_id?: string;
38
+ }
39
+ /** [D27] One journaled decrypt — a message the SDK decrypted (advancing the
40
+ * MLS ratchet) whose host-side persist has not yet been confirmed. Returned
41
+ * by `pendingApplies()`; removed by `confirmApplied()`. `plaintext` is
42
+ * message content: never log, persist only through the host's message
43
+ * store. See docs/PENDING_APPLIES.md for the crash-recovery drain contract. */
44
+ interface PendingApply {
45
+ journal_id: string;
46
+ conversation_id: ConversationId;
47
+ sender_device: DeviceId;
48
+ sender_user_id: UserId;
49
+ epoch: number;
50
+ hlc: Hlc;
51
+ plaintext: Bytes;
52
+ content_hash: Bytes;
53
+ queued_at_ms: number;
54
+ sender_role?: SenderRole | null;
55
+ }
56
+ interface ConversationMeta {
57
+ id: ConversationId;
58
+ name: string | null;
59
+ epoch: number;
60
+ member_count: number;
61
+ is_device_group: boolean;
62
+ created_at_ms: number;
63
+ }
64
+ interface MemberInfo {
65
+ user_id: UserId;
66
+ leaf_index: number;
67
+ }
68
+ /** A conversation's credential policy (`conversationPolicy`, 2026-11-04:
69
+ * account-signed device credentials). */
70
+ interface ConversationPolicy {
71
+ /** Every leaf must carry a device credential the account key signed; a
72
+ * KeyPackage without one gets the add verdict `"credentialMissing"`. */
73
+ credentialsRequired: boolean;
74
+ /** The group's owner, once the policy records roles (round 2); `null` until then. */
75
+ owner: UserId | null;
76
+ /** The group's admins, once the policy records roles (round 2). */
77
+ admins: UserId[];
78
+ /** Accounts with a member whose leaf cannot carry the policy (an app too old
79
+ * for this group). While any is listed the group cannot upgrade to
80
+ * `credentialsRequired`: show it as the upgrade blocker. */
81
+ incapableMembers: UserId[];
82
+ /** The policy records an owner other than the one passed in `expectedOwners`
83
+ * for this conversation (a hand-over, a succession, or a group that arrived
84
+ * already carrying roles): show "ownership of this group changed" and
85
+ * decide; the SDK never refuses on it (2026-11-04, V-D). */
86
+ ownerDiffersFromExpected: boolean;
87
+ }
88
+ /** The owner a host expects a conversation's FIRST roles write to name
89
+ * (2026-11-04, round 2): the server's recorded creator, as an MLS user id.
90
+ * Passed at init (`ClientConfig.expectedOwners`) or refreshed with
91
+ * `setExpectedOwners`; consulted only when a group without roles gains them.
92
+ * A first roles write naming another owner strands as `"notPermitted"`; a
93
+ * conversation with no entry accepts the first write from any member. */
94
+ interface ExpectedOwner {
95
+ conversationId: ConversationId;
96
+ owner: UserId;
97
+ }
98
+ interface DeviceInfo {
99
+ device_id: DeviceId;
100
+ user_id: UserId;
101
+ label: string;
102
+ created_at_ms: number;
103
+ last_seen_ms: number;
104
+ revoked: boolean;
105
+ }
106
+ /** A signed answer to one device re-authentication challenge
107
+ * (`POST /v1/auth/device/challenge`, answered at `POST /v1/auth/device/verify`).
108
+ * Produced by `MessagingClient.signDeviceReauth`. Neither field is secret, and
109
+ * neither belongs in a log line. */
110
+ interface DeviceReauthProof {
111
+ /** SHA-256 of the device signing key's public half (32 bytes). Send it with the signature. */
112
+ deviceId: Uint8Array;
113
+ /** Ed25519 signature over the SDK-built message (64 bytes). */
114
+ signature: Uint8Array;
115
+ }
116
+ /** Link verification v2: an approving device's signed consent to ONE new device on
117
+ * ONE server link session (`POST /v1/auth/link/sessions`). Produced by
118
+ * `MessagingClient.signDeviceLinkApproval`. Not secret, but none of it belongs in a
119
+ * log line. */
120
+ interface DeviceLinkApproval {
121
+ /** SHA-256 of the approving device's public key (32 bytes). */
122
+ approverDeviceId: Uint8Array;
123
+ /** SHA-256 of the new device's public key (32 bytes). */
124
+ newDeviceId: Uint8Array;
125
+ /** Ed25519 signature over the SDK-built approval message (64 bytes). */
126
+ signature: Uint8Array;
127
+ }
128
+ /** Link verification v2: a new device's proof that it holds the key the session
129
+ * names. Produced by `MessagingClient.signDeviceLinkPossession`. */
130
+ interface DeviceLinkPossession {
131
+ /** SHA-256 of the new device's public key (32 bytes). */
132
+ deviceId: Uint8Array;
133
+ /** Ed25519 signature over the SDK-built possession message (64 bytes). */
134
+ signature: Uint8Array;
135
+ }
136
+ interface LinkingTicket {
137
+ v: number;
138
+ user_id: UserId;
139
+ user_pubkey: Bytes;
140
+ new_device_id: DeviceId;
141
+ device_binding_sig: Bytes;
142
+ device_group_welcome: Bytes;
143
+ catchup_snapshot: Bytes;
144
+ }
145
+ interface DiscoveredDevice {
146
+ device_id: DeviceId;
147
+ key_package: Bytes;
148
+ }
149
+ /** [CR-2] Pair supplied to `addMembers`. Maps 1:1 to `DiscoveredDevice` so hosts can
150
+ * rename a directory result and pass it through unchanged. */
151
+ interface KeyPackageEntry {
152
+ deviceId: DeviceId;
153
+ keyPackage: Bytes;
154
+ }
155
+ /** One per-chat KP supplied to `admitDeviceToChats`. Hosts claim these
156
+ * from the auth-layer's per-account KP pool (`GET /v1/devices/{accountId}`)
157
+ * after the newly-linked device has bootstrapped and uploaded its KP batch. */
158
+ interface AdmitChatEntry {
159
+ conversationId: ConversationId;
160
+ keyPackage: Bytes;
161
+ }
162
+ /** Per-chat result returned by `admitDeviceToChats`. */
163
+ interface AdmitChatOutcome {
164
+ conversationId: ConversationId;
165
+ status: "admitted" | "skipped" | "failed";
166
+ /** Set when `status === "skipped"` (e.g. DeviceGroup filtered out). */
167
+ reason?: string;
168
+ /** Set when `status === "failed"`. The underlying transport / MLS error. */
169
+ error?: string;
170
+ }
171
+ /** One conversation `rotateIdentity` could not rotate, with the error that
172
+ * stopped it. Kept for type compatibility: `rotateIdentity` is retired and
173
+ * always rejects. */
174
+ interface IdentityRotationFailure {
175
+ conversationId: ConversationId;
176
+ /** The underlying transport / MLS error. */
177
+ error: string;
178
+ }
179
+ /** Result of `rotateIdentity`. Kept for type compatibility: `rotateIdentity`
180
+ * is retired and always rejects, so no call returns one. */
181
+ interface IdentityRotation {
182
+ /** The account id this client now presents in every new leaf, KeyPackage
183
+ * and linking ticket. Equal to `userId()` after the call. */
184
+ newUserId: UserId;
185
+ /** The fresh DeviceGroup created for the new identity, with this device as
186
+ * its sole member. The host re-registers DeviceGroup membership for it. */
187
+ deviceGroupId: ConversationId;
188
+ /** Conversations whose rotation Commit the server accepted. */
189
+ rotated: ConversationId[];
190
+ /** Conversations that keep their old leaf credential, with the error. */
191
+ failed: IdentityRotationFailure[];
192
+ }
193
+ /** One conversation where a removed device still holds its leaf, or that this
194
+ * device could not check, after `removeDeviceEverywhere` or
195
+ * `removeOwnDevicesExcept`. */
196
+ interface DeviceRemovalFailure {
197
+ conversationId: ConversationId;
198
+ /** The error's variant name (`"CommitInDoubt"`, `"Transport"`,
199
+ * `"TransportRejected"`, `"EpochStranded"`, ...), or `"NotOwnAccount"` (the
200
+ * leaf is not this account's: never removed), `"Unloadable"` (the
201
+ * conversation's state could not be loaded on this device, so it was not
202
+ * checked) or `"RefusedCommit"` (the conversation is stranded on a Commit Ping
203
+ * refuses: no retry or re-admission repairs it, stop retrying it and offer to
204
+ * recreate the conversation): no id, no detail, safe to persist and log. */
205
+ reason: string;
206
+ }
207
+ /** Result of `removeDeviceEverywhere` and `removeOwnDevicesExcept`: what the host
208
+ * persists and retries from (a retry is the same call; it only commits where a
209
+ * targeted leaf is still there). Complete when `failed` is empty and
210
+ * `deviceGroup !== "failed"`. */
211
+ interface DeviceRemovalReport {
212
+ /** Conversations (not the DeviceGroup) where the device held a leaf when the call
213
+ * started and holds none now. Sorted by id. */
214
+ removed: ConversationId[];
215
+ /** Conversations (not the DeviceGroup) where it still holds one. */
216
+ failed: DeviceRemovalFailure[];
217
+ /** The account's own DeviceGroup. */
218
+ deviceGroup: "notMember" | "removed" | "failed";
219
+ /** Set when `deviceGroup === "failed"`: the error's variant name. */
220
+ deviceGroupReason?: string;
221
+ }
222
+ /** [CR-13] One host-supplied (conversation, last-AppEvent) pair for
223
+ * `buildLinkingTicket`. The new device renders these as "what you missed". */
224
+ interface CatchupAppEvent {
225
+ conversationId: ConversationId;
226
+ appEventBytes: Bytes;
227
+ }
228
+ /** [CR-13] Decoded `LinkingTicket.catchup_snapshot`. The `group_state_bytes` field is
229
+ * reserved for CR-7 — empty until that ships. */
230
+ interface CatchupSnapshotEntry {
231
+ conversation_id: ConversationId;
232
+ meta: ConversationMeta;
233
+ group_state_bytes: Bytes;
234
+ }
235
+ interface CatchupSnapshotView {
236
+ v: number;
237
+ conversation_metas: CatchupSnapshotEntry[];
238
+ last_app_events_per_conv: {
239
+ conversation_id: ConversationId;
240
+ app_event_bytes: Bytes;
241
+ }[];
242
+ }
243
+ /** One decrypted application event inside a peer-history bundle. `payload` is the host's
244
+ * opaque AppEvent bytes; replay it through the same dedup (`event_id`) + reducer path. */
245
+ interface HistoryAppEvent {
246
+ event_id: Bytes;
247
+ wall_ms: number;
248
+ payload: Bytes;
249
+ /** Original author (account id for self-authored, peer device id otherwise) so the
250
+ * recipient renders self-vs-peer bubbles correctly. Empty/omitted when unknown or
251
+ * produced by a pre-`author` sender — replay falls back to the bundle sender id. */
252
+ author?: string;
253
+ }
254
+ /** A conversation's decrypted history shipped device-to-device (linking / peer re-add).
255
+ * Sealed+signed by `sealHistoryBundle`, opened+verified by `openHistoryBundle`. */
256
+ interface HistoryBundle {
257
+ v: number;
258
+ sender_device_id: Bytes;
259
+ recipient_device_id: Bytes;
260
+ conversation_id: Bytes;
261
+ window_start_ms: number;
262
+ window_end_ms: number;
263
+ events: HistoryAppEvent[];
264
+ }
265
+ /** Decrypted recovery backup returned by `MessagingClient.decryptBackup`. `identity_export`
266
+ * is the secret Ed25519 seed — pass it straight into `init({ identityExport })`. */
267
+ interface RecoveryBackup {
268
+ v: number;
269
+ account_id: Bytes;
270
+ identity_export: Bytes;
271
+ device_group_snapshot: Bytes;
272
+ /** External-conversation MLS state embedded in the backup. Empty unless the
273
+ * backup was written with conversations included. Import each via
274
+ * `importStateSnapshot` after restore to bring the chat + history back. */
275
+ conversation_snapshots: {
276
+ conversation_id: Bytes;
277
+ group_state_bytes: Bytes;
278
+ }[];
279
+ created_at_ms: number;
280
+ }
281
+ /** An envelope together with the server's log position for it. `serverSeq`
282
+ * 0 means the host does not know the position (a transport that predates
283
+ * positions); the envelope then takes the legacy per-sender path. */
284
+ interface SequencedEnvelope {
285
+ envelope: MessageEnvelope;
286
+ serverSeq: number;
287
+ }
288
+ /** This device's applied position in one conversation's server log.
289
+ * `anchored` false means `serverSeq` is not a real position yet (a
290
+ * conversation joined through a linking ticket, or a cursor written before
291
+ * positions existed): a page of the log, or `adoptLogPosition`, anchors it. */
292
+ interface LogPosition {
293
+ conversationId: ConversationId;
294
+ /** MLS epoch of the applied state. */
295
+ epoch: number;
296
+ /** Last applied `server_seq`; 0 when nothing has been applied yet. */
297
+ serverSeq: number;
298
+ anchored: boolean;
299
+ }
300
+ /** The server's current head of one conversation's log, as reported by
301
+ * `GET /v1/messages/heads` or the socket's `resume_ack`. */
302
+ interface LogHead {
303
+ conversationId: ConversationId;
304
+ headServerSeq: number;
305
+ headEpoch: number;
306
+ }
307
+ /** A hole between what this device has applied and a live frame the SDK
308
+ * holds: the rows from `appliedServerSeq + 1` to `firstBufferedServerSeq - 1`
309
+ * must be fetched from the log before the held frames can apply. The SDK
310
+ * fills it itself (`fillGap`); `appliedServerSeq` is 0 when not anchored. */
311
+ interface LogGap {
312
+ conversationId: ConversationId;
313
+ appliedServerSeq: number;
314
+ firstBufferedServerSeq: number;
315
+ }
316
+ /** A conversation whose MLS epoch moved, or that was joined, during a batch.
317
+ * What `onConversationUpdated` reported for that batch. */
318
+ interface ConversationUpdate {
319
+ conversationId: ConversationId;
320
+ epoch: number;
321
+ }
322
+ /** A Commit that removed this device's leaf during a batch or page. The
323
+ * conversation was torn down at that point; whether it is held again at the
324
+ * end (a Welcome addressed to this device later in the same batch re-joined
325
+ * it) is what `joined` says. */
326
+ interface ConversationRemoval {
327
+ conversationId: ConversationId;
328
+ /** Log position of the removing Commit; 0 when unknown. */
329
+ serverSeq: number;
330
+ /** The epoch the Commit was sealed at. */
331
+ epoch: number;
332
+ /** The same Commit added a fresh KeyPackage of this device (a member
333
+ * re-admitted it): a Welcome for the new leaf follows. */
334
+ readmitted: boolean;
335
+ }
336
+ /** Why a Welcome sealed to this device's own KeyPackage did not join. The
337
+ * KeyPackage is kept either way. `rejected`: file ONE scoped re-admission
338
+ * request with this outcome as evidence. `storage`: retry later.
339
+ * `notPermitted` (2026-11-18): the joiner's check refused the state the
340
+ * Welcome leads into (its policy names an owner or an admin that holds no
341
+ * verified leaf). Final for that Welcome: drop the invitation, never retry
342
+ * it, file NO re-admission request, show nothing. */
343
+ type WelcomeFailureReason = "rejected" | "storage" | "notPermitted";
344
+ interface WelcomeFailure {
345
+ conversationId: ConversationId;
346
+ serverSeq: number;
347
+ reason: WelcomeFailureReason;
348
+ }
349
+ /** Why a conversation became stranded (it needs a re-admission).
350
+ * `addedKeyPackageExpired` / `addedKeyPackageNotYetValid`: a Commit adds a
351
+ * KeyPackage whose lifetime is not valid at this device's clock (OpenMLS
352
+ * refuses it; the second case means the device clock is behind). */
353
+ /** `credentialInvalid`: a Commit would put a leaf in the tree without the device
354
+ * credential the group requires, with one that does not verify, or moves a
355
+ * member's credential without one; `policyDowngrade`: a Commit removes the
356
+ * conversation policy, sets `credentialsRequired` back to false, or installs a
357
+ * policy this build cannot read. Both are refused for good (`RefusedCommit` in
358
+ * a removal report): recreate the conversation. */
359
+ /** `notPermitted` (2026-11-04, round 2): a Commit does what the committer's role
360
+ * does not permit in a group whose policy records an owner (a member removing or
361
+ * adding somebody else's device, rewriting the name blob, changing the roles
362
+ * beyond its role, not naming the owner's successor, a first roles write naming
363
+ * an owner other than the expected one). Refused the same way: show it like a
364
+ * refused Commit ("recreate this chat"). */
365
+ type StrandReason = "noProgress" | "addedKeyPackageExpired" | "addedKeyPackageNotYetValid" | "credentialInvalid" | "policyDowngrade" | "notPermitted";
366
+ interface StrandedConversation {
367
+ conversationId: ConversationId;
368
+ serverSeq: number;
369
+ epoch: number;
370
+ reason: StrandReason;
371
+ }
372
+ /** Which bounded buffer refused or evicted frames: `heldFrames` (a gap is
373
+ * reported and the fill re-fetches them) or `retainedFrames` (page the
374
+ * conversation to its end once it is held again). */
375
+ type OverflowReason = "heldFrames" | "retainedFrames";
376
+ interface BufferOverflow {
377
+ conversationId: ConversationId;
378
+ reason: OverflowReason;
379
+ dropped: number;
380
+ }
381
+ /** What `addMembersWithVerdicts` did with one entry. */
382
+ type AddMemberStatus = "added" | "alreadyMember" | "duplicateEntry" | "malformed" | "expired" | "notYetValid" | "invalid" | "unsupported" | "rejected"
383
+ /** No device credential where the group (or the KeyPackage's own capabilities)
384
+ * requires one: claim one from a build that signs. */
385
+ | "credentialMissing"
386
+ /** Its device credential does not verify. Never added. */
387
+ | "credentialInvalid"
388
+ /** This account's role does not permit the add (2026-11-04, round 2): the
389
+ * group's policy records an owner, this account is neither the owner nor
390
+ * an admin, and the entry is not one of its own devices. Nothing is sent
391
+ * for it; show "only an admin can do this". */
392
+ | "notPermitted";
393
+ interface AddMemberVerdict {
394
+ deviceId: DeviceId;
395
+ status: AddMemberStatus;
396
+ /** The new leaf for `added`, the existing one for `alreadyMember`. */
397
+ leafIndex: number | null;
398
+ }
399
+ /** One verdict per entry, in request order. `epoch` is the epoch after the
400
+ * admitting Commit, `null` when no entry was addable (no Commit was made). */
401
+ interface AddMembersReport {
402
+ verdicts: AddMemberVerdict[];
403
+ epoch: number | null;
404
+ }
405
+ /** A Commit this device holds in doubt (an ambiguous send). Retry an
406
+ * operation that failed with `commit in doubt` at `nextAttemptAtMs`. */
407
+ interface CommitInDoubt {
408
+ conversationId: ConversationId;
409
+ attempts: number;
410
+ nextAttemptAtMs: number;
411
+ }
412
+ /** Outcome of `processSequencedBatch`. `messages` are the decrypted
413
+ * application messages in apply order. */
414
+ interface ApplyBatchResult {
415
+ messages: IncomingMessage[];
416
+ /** Envelopes applied to MLS state (handshakes included). */
417
+ applied: number;
418
+ /** Envelopes at or below the applied position, dropped without MLS work. */
419
+ duplicates: number;
420
+ /** Envelopes held in the reorder buffer because of a gap. */
421
+ buffered: number;
422
+ /** Envelopes at their position that MLS could not apply; retained for
423
+ * replay, position advanced past them. */
424
+ failed: number;
425
+ /** Conversations that need a server-log fill before their held frames can
426
+ * be applied; the SDK starts the fill itself. */
427
+ gaps: LogGap[];
428
+ /** Conversations joined by a Welcome in this batch AND held at its end. */
429
+ joined: ConversationId[];
430
+ updated: ConversationUpdate[];
431
+ /** Commits that removed this device's leaf, in apply order. */
432
+ removed: ConversationRemoval[];
433
+ /** Welcomes sealed to this device that failed to join. */
434
+ welcomeFailures: WelcomeFailure[];
435
+ /** Conversations this batch stranded. */
436
+ stranded: StrandedConversation[];
437
+ /** Held conversations with proposals this device can commit: commit them
438
+ * on receipt (`commitPendingProposals`), elected by
439
+ * `pendingProposalsCommitRank`. */
440
+ proposalsPending: ConversationId[];
441
+ /** Frames the bounded buffers could not keep. */
442
+ overflow: BufferOverflow[];
443
+ }
444
+ /** Outcome of one page of `syncConversationStep`. */
445
+ interface SyncStepResult {
446
+ messages: IncomingMessage[];
447
+ /** Whether the server may hold more rows after this page: step again. */
448
+ hasMore: boolean;
449
+ /** Rows the page returned. */
450
+ fetched: number;
451
+ /** The position after the page (zeroed and unanchored when the page
452
+ * removed this device and nothing re-joined it). */
453
+ position: LogPosition;
454
+ updated: ConversationUpdate[];
455
+ joined: ConversationId[];
456
+ removed: ConversationRemoval[];
457
+ welcomeFailures: WelcomeFailure[];
458
+ stranded: StrandedConversation[];
459
+ proposalsPending: ConversationId[];
460
+ overflow: BufferOverflow[];
461
+ }
462
+ /** Where a batch delivered to `onMessageBatch` came from: a live socket
463
+ * batch, or a page of the server log (a gap fill, or the whole-account
464
+ * catch-up). */
465
+ interface MessageBatchMeta {
466
+ source: "live" | "page";
467
+ }
468
+ interface Storage {
469
+ get(namespace: string, key: string): Promise<Uint8Array | null>;
470
+ put(namespace: string, key: string, value: Uint8Array): Promise<void>;
471
+ del(namespace: string, key: string): Promise<void>;
472
+ listKeys(namespace: string, prefix: string): Promise<string[]>;
473
+ /**
474
+ * Optional. Apply `puts` and `deletes` in ONE namespace as one atomic
475
+ * unit: after it resolves every put is visible and every deleted key is
476
+ * gone, and a crash in the middle leaves none of them applied (one
477
+ * IndexedDB `readwrite` transaction, every request issued with no await
478
+ * in between). The per-row MLS store hands its checkpoint deltas here;
479
+ * a host without it gets the SDK's own journalled fallback over the four
480
+ * basic methods, which is correct but costs a write per row plus one.
481
+ */
482
+ applyBatch?(namespace: string, puts: Array<[key: string, value: Uint8Array]>, deletes: string[]): Promise<void>;
483
+ /**
484
+ * Optional. Every `[key, value]` in `namespace` whose key starts with
485
+ * `prefix`, in one read. Opening the per-row MLS store then costs one
486
+ * host call instead of one `get` per row.
487
+ */
488
+ listEntries?(namespace: string, prefix: string): Promise<Array<[key: string, value: Uint8Array]>>;
489
+ }
490
+ interface Transport {
491
+ send(envelope: MessageEnvelope): Promise<void>;
492
+ /** Optional. Publish several envelopes of ONE conversation as an atomic
493
+ * unit, in order (the admitting Commit + its addressed Welcome). The web
494
+ * host posts them to `POST /v1/messages/batch`, one server transaction,
495
+ * so both persist or neither. A host that implements it MUST reject
496
+ * with an error carrying a numeric `status` (or a message containing
497
+ * `http 4xx`) for a definite server rejection, so the SDK can roll the
498
+ * staged Commit back, and SHOULD retry transient failures itself (the
499
+ * server append is idempotent by content hash). Hosts that leave it
500
+ * unimplemented get sequential sends with partial-delivery reporting. */
501
+ sendBatch?(envelopes: MessageEnvelope[]): Promise<void>;
502
+ fetchSince(conversationId: ConversationId, cursor: Uint8Array, limit: number): Promise<MessageEnvelope[]>;
503
+ /** Optional. One page of a conversation's server log after `position`,
504
+ * each row with its `serverSeq`, ordered ascending
505
+ * (`GET /v1/messages?positions=1`). Cursor to send: anchored ->
506
+ * `(epoch 0, serverSeq)`; not anchored -> `(epoch, 0)`, the join seed.
507
+ * A host that leaves it unimplemented stays on the legacy path: the SDK
508
+ * pages `fetchSince` and applies every row at position 0. */
509
+ fetchLogSince?(position: LogPosition, limit: number): Promise<SequencedEnvelope[]>;
510
+ /** Optional. The server's current head for every conversation this device
511
+ * is a member of (`GET /v1/messages/heads`). Lets `syncConversations`
512
+ * step only the conversations that are behind instead of paging every
513
+ * one; `null` (or leaving it unimplemented) means "unknown", the
514
+ * whole-account walk. */
515
+ fetchLogHeads?(): Promise<LogHead[] | null>;
516
+ /** Live-stream subscribe. The TS SDK runs its own loop: a bare
517
+ * `MessageEnvelope` takes the legacy per-envelope path (`processEnvelope`
518
+ * / `joinConversation`); a `SequencedEnvelope` with `serverSeq > 0` is
519
+ * coalesced per conversation into `processSequencedBatch`. The callback
520
+ * returns the dispatch promise, so a transport may await application
521
+ * before acking a watermark. */
522
+ subscribe(onEvent: (frame: MessageEnvelope | SequencedEnvelope) => void | Promise<void>): {
523
+ unsubscribe(): void;
524
+ };
525
+ discoverDevices(userId: UserId): Promise<DiscoveredDevice[]>;
526
+ /** Optional. Prime the host with the recipient device id(s) the NEXT
527
+ * Welcome on `conversationId` should address — the web host uses this
528
+ * to populate the `?recipient=` query param for `POST /v1/messages`.
529
+ * Called by the SDK's `admitDeviceToChats` before each per-chat
530
+ * Welcome send. Hosts that route Welcomes differently (or don't need
531
+ * per-recipient routing) may leave this unimplemented. */
532
+ setNextWelcomeRecipients?(conversationId: ConversationId, recipientDeviceIds: DeviceId[]): Promise<void>;
533
+ }
534
+
535
+ export type { WelcomeFailureReason as $, AddMembersReport as A, BufferOverflow as B, ConversationId as C, DiscoveredDevice as D, ExpectedOwner as E, DeviceInfo as F, DeviceRemovalFailure as G, HistoryBundle as H, IdentityRotation as I, HistoryAppEvent as J, KeyPackageEntry as K, LinkingTicket as L, MessageEnvelope as M, Hlc as N, IdentityRotationFailure as O, PendingApply as P, LogGap as Q, RecoveryBackup as R, Storage as S, Transport as T, UserId as U, MessageKind as V, OverflowReason as W, SenderRole as X, StrandReason as Y, StrandedConversation as Z, WelcomeFailure as _, DeviceId as a, ConversationMeta as b, DeviceReauthProof as c, DeviceLinkApproval as d, DeviceLinkPossession as e, CommitInDoubt as f, MemberInfo as g, ConversationPolicy as h, IncomingMessage as i, SequencedEnvelope as j, ApplyBatchResult as k, SyncStepResult as l, LogPosition as m, LogHead as n, CatchupAppEvent as o, CatchupSnapshotView as p, AdmitChatEntry as q, AdmitChatOutcome as r, DeviceRemovalReport as s, MessageBatchMeta as t, AddMemberStatus as u, AddMemberVerdict as v, Bytes as w, CatchupSnapshotEntry as x, ConversationRemoval as y, ConversationUpdate as z };