@ping-app/ping-openmls-sdk 0.0.0-stage → 0.9.2
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.
- package/README.md +94 -2
- package/dist/index.cjs +2722 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1182 -0
- package/dist/index.d.ts +1182 -0
- package/dist/index.js +2655 -0
- package/dist/index.js.map +1 -0
- package/dist/notification-preview.cjs +137 -0
- package/dist/notification-preview.cjs.map +1 -0
- package/dist/notification-preview.d.cts +85 -0
- package/dist/notification-preview.d.ts +85 -0
- package/dist/notification-preview.js +98 -0
- package/dist/notification-preview.js.map +1 -0
- package/dist/storage/indexeddb.cjs +153 -0
- package/dist/storage/indexeddb.cjs.map +1 -0
- package/dist/storage/indexeddb.d.cts +21 -0
- package/dist/storage/indexeddb.d.ts +21 -0
- package/dist/storage/indexeddb.js +128 -0
- package/dist/storage/indexeddb.js.map +1 -0
- package/dist/transport/websocket.cjs +121 -0
- package/dist/transport/websocket.cjs.map +1 -0
- package/dist/transport/websocket.d.cts +23 -0
- package/dist/transport/websocket.d.ts +23 -0
- package/dist/transport/websocket.js +94 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/types-B1GFwNXa.d.cts +535 -0
- package/dist/types-B1GFwNXa.d.ts +535 -0
- package/dist/worker.cjs +686 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.cts +2 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +693 -0
- package/dist/worker.js.map +1 -0
- package/package.json +61 -4
- package/wasm/package.json +17 -0
- package/wasm/ping_wasm.d.ts +890 -0
- package/wasm/ping_wasm.js +2992 -0
- package/wasm/ping_wasm_bg.wasm +0 -0
- package/wasm/ping_wasm_bg.wasm.d.ts +111 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1182 @@
|
|
|
1
|
+
import { M as MessageEnvelope, S as Storage, T as Transport, E as ExpectedOwner, C as ConversationId, K as KeyPackageEntry, A as AddMembersReport, a as DeviceId, U as UserId, b as ConversationMeta, L as LinkingTicket, c as DeviceReauthProof, d as DeviceLinkApproval, e as DeviceLinkPossession, I as IdentityRotation, f as CommitInDoubt, g as MemberInfo, h as ConversationPolicy, i as IncomingMessage, j as SequencedEnvelope, k as ApplyBatchResult, l as SyncStepResult, m as LogPosition, n as LogHead, P as PendingApply, o as CatchupAppEvent, p as CatchupSnapshotView, R as RecoveryBackup, H as HistoryBundle, q as AdmitChatEntry, r as AdmitChatOutcome, s as DeviceRemovalReport, t as MessageBatchMeta } from './types-B1GFwNXa.cjs';
|
|
2
|
+
export { u as AddMemberStatus, v as AddMemberVerdict, B as BufferOverflow, w as Bytes, x as CatchupSnapshotEntry, y as ConversationRemoval, z as ConversationUpdate, F as DeviceInfo, G as DeviceRemovalFailure, D as DiscoveredDevice, J as HistoryAppEvent, N as Hlc, O as IdentityRotationFailure, Q as LogGap, V as MessageKind, W as OverflowReason, X as SenderRole, Y as StrandReason, Z as StrandedConversation, _ as WelcomeFailure, $ as WelcomeFailureReason } from './types-B1GFwNXa.cjs';
|
|
3
|
+
export { IndexedDbStorage } from './storage/indexeddb.cjs';
|
|
4
|
+
export { WebSocketTransport } from './transport/websocket.cjs';
|
|
5
|
+
export { NotificationPreviewOptions, NotificationPreviewSession, openNotificationPreview } from './notification-preview.cjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Ping wire contract version. Bumped on incompatible profile changes.
|
|
9
|
+
*
|
|
10
|
+
* Currently `2` — CR-6 changes the `content_hash` semantics for `Application` envelopes
|
|
11
|
+
* (now hashed over plaintext, not the MLS ciphertext). Receivers run a 90-day dual-accept
|
|
12
|
+
* window per Q-ARCH-02; see [[validate]] for the per-version routing.
|
|
13
|
+
*/
|
|
14
|
+
declare const PING_WIRE_CONTRACT_VERSION = 2;
|
|
15
|
+
/** Lowest envelope version accepted by [[validate]] during the dual-accept window. */
|
|
16
|
+
declare const WIRE_VERSION_MIN_ACCEPTED = 1;
|
|
17
|
+
/** Canonical CBOR content type. Production transports SHOULD use this. */
|
|
18
|
+
declare const CONTENT_TYPE_CBOR = "application/vnd.ping.wire.v2+cbor";
|
|
19
|
+
/** JSON projection — development and tooling only. Production MUST NOT use this. */
|
|
20
|
+
declare const CONTENT_TYPE_JSON = "application/vnd.ping.wire.v2+json";
|
|
21
|
+
/** Legacy v1 CBOR type, accepted during the CR-6 dual-accept window. */
|
|
22
|
+
declare const CONTENT_TYPE_CBOR_LEGACY_V1 = "application/vnd.ping.wire.v1+cbor";
|
|
23
|
+
/** Legacy v1 JSON type, accepted during the CR-6 dual-accept window. */
|
|
24
|
+
declare const CONTENT_TYPE_JSON_LEGACY_V1 = "application/vnd.ping.wire.v1+json";
|
|
25
|
+
/** Header used over transports that don't surface a content type (e.g. WebSocket). */
|
|
26
|
+
declare const PING_WIRE_CONTRACT_HEADER = "X-Ping-Wire-Contract";
|
|
27
|
+
/** Header value: `ping/<VERSION>`. */
|
|
28
|
+
declare const PING_WIRE_CONTRACT_HEADER_VALUE = "ping/2";
|
|
29
|
+
type ValidationErrorKind = "UnsupportedVersion" | "BadConversationIdLen" | "BadSenderDeviceLen" | "ContentHashMismatch";
|
|
30
|
+
declare class ValidationError extends Error {
|
|
31
|
+
readonly kind: ValidationErrorKind;
|
|
32
|
+
constructor(kind: ValidationErrorKind, message: string);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate an envelope against the ping-wire-contract.
|
|
36
|
+
*
|
|
37
|
+
* Receivers claiming contract conformance MUST call this before applying any envelope.
|
|
38
|
+
* External consumers using the raw envelope under their own profile are not bound by
|
|
39
|
+
* these rules.
|
|
40
|
+
*
|
|
41
|
+
* CR-6 dual-accept window: `v ∈ [WIRE_VERSION_MIN_ACCEPTED, PING_WIRE_CONTRACT_VERSION]`
|
|
42
|
+
* passes the version gate. For v=2 `Application` envelopes the content_hash is over
|
|
43
|
+
* plaintext, so this function skips that check — callers MUST run
|
|
44
|
+
* [[verifyApplicationContentHash]] after MLS decrypt to close the loop.
|
|
45
|
+
*/
|
|
46
|
+
declare function validate(env: MessageEnvelope): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Verify a v=2 `Application` envelope's content_hash against the decrypted plaintext.
|
|
49
|
+
*
|
|
50
|
+
* Caller MUST run this after MLS decrypt for application envelopes whose `v >= 2`. For
|
|
51
|
+
* v=1 envelopes or handshake kinds this is a no-op (those are covered by [[validate]]).
|
|
52
|
+
*/
|
|
53
|
+
declare function verifyApplicationContentHash(env: MessageEnvelope, plaintext: Uint8Array): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* True if the supplied content type negotiates the ping-wire-contract.
|
|
56
|
+
*
|
|
57
|
+
* Accepts the v2 canonical types AND the v1 legacy types during the CR-6 dual-accept
|
|
58
|
+
* window. Tolerates whitespace and parameters (e.g. `; charset=utf-8`).
|
|
59
|
+
*/
|
|
60
|
+
declare function negotiates(contentType: string | null | undefined): boolean;
|
|
61
|
+
|
|
62
|
+
interface ClientConfig {
|
|
63
|
+
identityExport: Uint8Array;
|
|
64
|
+
deviceLabel: string;
|
|
65
|
+
storage: Storage;
|
|
66
|
+
transport: Transport;
|
|
67
|
+
/** Override the wall clock (test/sim only). */
|
|
68
|
+
now?: () => number;
|
|
69
|
+
/**
|
|
70
|
+
* Optional 32-byte Ed25519 secret key. When supplied AND no
|
|
71
|
+
* `LocalDevice` is yet persisted in `storage`, the SDK adopts this
|
|
72
|
+
* as its device signing key — so `deviceId()` returns
|
|
73
|
+
* `SHA-256(public_key_of(secret))`, deterministic from what the
|
|
74
|
+
* caller passed.
|
|
75
|
+
*
|
|
76
|
+
* Use case: align the SDK's `device_id` (which the SDK stamps into
|
|
77
|
+
* every envelope's `sender_device` field) with an externally-
|
|
78
|
+
* computed device id — typically `SHA-256(device_signing_pubkey)`
|
|
79
|
+
* in the host's auth layer, where the JWT carries that same value
|
|
80
|
+
* as its `device_id` claim. Without this alignment, a server that
|
|
81
|
+
* validates `envelope.sender_device == jwt.device_id` rejects every
|
|
82
|
+
* upload with `sender_device_mismatch`.
|
|
83
|
+
*
|
|
84
|
+
* Ignored on subsequent inits (when `storage` already holds a
|
|
85
|
+
* persisted `LocalDevice`) — the on-disk identity is authoritative
|
|
86
|
+
* for stability across restarts.
|
|
87
|
+
*/
|
|
88
|
+
deviceSigningSecretKey?: Uint8Array;
|
|
89
|
+
/**
|
|
90
|
+
* Optional per-account storage scope. When set, the SDK prefixes EVERY
|
|
91
|
+
* storage namespace it reads/writes with `${accountNamespace}\0`, so
|
|
92
|
+
* multiple accounts that share one `Storage` backend can never read or
|
|
93
|
+
* overwrite each other's MLS group state, device identity, or key
|
|
94
|
+
* material. Hosts that already give each account its own physical store
|
|
95
|
+
* (e.g. a per-account IndexedDB database) can still set this as
|
|
96
|
+
* defense-in-depth — the prefix is stable across restarts and MUST be
|
|
97
|
+
* the same value every init for a given account or its data becomes
|
|
98
|
+
* unreachable. Use a stable, opaque per-account id (e.g. the account id
|
|
99
|
+
* hex); never a display name.
|
|
100
|
+
*/
|
|
101
|
+
accountNamespace?: string;
|
|
102
|
+
/**
|
|
103
|
+
* The owner each conversation's FIRST roles write must name (2026-11-04,
|
|
104
|
+
* round 2): the server's recorded creator, as an MLS user id (map the
|
|
105
|
+
* account id through the roster). Consulted only when a group without
|
|
106
|
+
* roles gains them; a first roles write naming another owner strands as
|
|
107
|
+
* `"notPermitted"`. A conversation with no entry accepts the first write
|
|
108
|
+
* from any member. Refresh later with `setExpectedOwners`.
|
|
109
|
+
*/
|
|
110
|
+
expectedOwners?: ExpectedOwner[];
|
|
111
|
+
}
|
|
112
|
+
interface Conversation {
|
|
113
|
+
readonly id: ConversationId;
|
|
114
|
+
send(plaintext: Uint8Array): Promise<MessageEnvelope>;
|
|
115
|
+
/** [CR-2] Add members by (device_id, KeyPackage) pair. Hosts typically pull these
|
|
116
|
+
* straight from `transport.discoverDevices(userId)`. All or nothing: one
|
|
117
|
+
* unusable entry fails the whole add (see `addMembersWithVerdicts`). */
|
|
118
|
+
addMembers(entries: KeyPackageEntry[]): Promise<void>;
|
|
119
|
+
/** Add members with one verdict per entry: every entry is screened on its
|
|
120
|
+
* own (KeyPackage verification, lifetime included; capabilities; an
|
|
121
|
+
* existing leaf; a repeat), the usable ones go into ONE Commit sent with
|
|
122
|
+
* its Welcome as one batch, and the rest are reported instead of failing
|
|
123
|
+
* the Commit for every other invitee. A device that already has a leaf is
|
|
124
|
+
* reported (`alreadyMember`, with its leaf), never evicted. */
|
|
125
|
+
addMembersWithVerdicts(entries: KeyPackageEntry[]): Promise<AddMembersReport>;
|
|
126
|
+
/** Re-admit a device that kept its signature key: ONE Commit that removes
|
|
127
|
+
* the leaf holding the KeyPackage's own key (the device's stale leaf: a
|
|
128
|
+
* stranded device, a restore over the same store) and adds its fresh
|
|
129
|
+
* KeyPackage. A re-admission never brings in an account and never makes an
|
|
130
|
+
* account's leaf count grow: with no leaf of that key it rejects
|
|
131
|
+
* "not permitted: ..." (`isNotPermittedError`) in EVERY conversation,
|
|
132
|
+
* before anything is sent. A device that came back with a NEW key is added
|
|
133
|
+
* (`addMembers`) by a device of its own account, the owner or an admin.
|
|
134
|
+
* In a conversation with roles the committer is a device of the same
|
|
135
|
+
* account as the device it re-admits, the owner, or an admin (never an
|
|
136
|
+
* admin for a device of the owner); anybody else is rejected the same way
|
|
137
|
+
* (2026-11-18: the `replace` argument is gone, and a plain member no
|
|
138
|
+
* longer re-admits another account's device). Ask the client's
|
|
139
|
+
* `mayReadmit` BEFORE claiming the device's KeyPackage.
|
|
140
|
+
* Resolves to the device id of the leaf the Commit replaced (the device
|
|
141
|
+
* that kept its key). `null`: no leaf was replaced. */
|
|
142
|
+
reAdmitDevice(entry: KeyPackageEntry): Promise<DeviceId | null>;
|
|
143
|
+
removeMembers(leafIndexes: number[]): Promise<void>;
|
|
144
|
+
/** Remove every OTHER leaf of this account from this conversation (step 2
|
|
145
|
+
* of an account's leave, before leaving): one Commit removing every leaf
|
|
146
|
+
* whose credential verifies for this client's own identity, except this
|
|
147
|
+
* device's. Resolves to how many leaves it removed; 0 sends nothing. The
|
|
148
|
+
* leaves are read from the tree on every call. Any role may call it. */
|
|
149
|
+
removeOwnOtherLeaves(): Promise<number>;
|
|
150
|
+
/** Remove an account from this conversation by identity: one Commit
|
|
151
|
+
* removing every leaf whose credential verifies for one of `identities`
|
|
152
|
+
* (MLS user ids, 32 bytes each: the account's current identity and any
|
|
153
|
+
* older ones the host names). Resolves to how many leaves ITS OWN
|
|
154
|
+
* Removes took (a leaf whose leave was already pending goes with the same
|
|
155
|
+
* Commit and is not counted): read the roster for the outcome, never the
|
|
156
|
+
* count. Read from the tree on every call, so a retry removes
|
|
157
|
+
* what the tree holds then. In a group with roles it is the owner's or an
|
|
158
|
+
* admin's call (rejects "not permitted: ..." otherwise) and it never
|
|
159
|
+
* removes the owner's leaves. */
|
|
160
|
+
removeMembersByIdentity(identities: UserId[]): Promise<number>;
|
|
161
|
+
/** Record the group's roles in its policy (2026-11-04, round 2): `owner` and
|
|
162
|
+
* `admins` as MLS user ids. One GroupContextExtensions Commit, no Welcome.
|
|
163
|
+
* Rejects with "not permitted ..." before anything is sent when this
|
|
164
|
+
* device's role does not allow the change (the first roles write is any
|
|
165
|
+
* member's unless an expected owner says otherwise; then the owner hands
|
|
166
|
+
* over, the owner or an admin changes the admins), when a member's app is
|
|
167
|
+
* too old for roles (`conversationPolicy().incapableMembers`), or in the
|
|
168
|
+
* DeviceGroup. Admins keep promotion order; the owner is never listed. */
|
|
169
|
+
setConversationRoles(owner: UserId, admins: UserId[]): Promise<void>;
|
|
170
|
+
/** Change the conversation `name` (carried in the GroupContext) via an MLS
|
|
171
|
+
* GroupContextExtensions commit — the rename / embedded avatar-media-id change
|
|
172
|
+
* propagates to every member and future joiner through group STATE, not a side
|
|
173
|
+
* broadcast. Pass `null` to clear. All members must have re-linked since the
|
|
174
|
+
* group-name capability shipped, else the SDK throws. */
|
|
175
|
+
setConversationName(name: string | null): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* The conversation's MLS GroupContext name, or `undefined` when the meta cache
|
|
178
|
+
* has not been primed (call `listConversations()` first).
|
|
179
|
+
*
|
|
180
|
+
* This accessor was MISSING, and hosts reasonably assumed it existed:
|
|
181
|
+
* `getConversation(id).name` read `undefined` on every call, so any host logic
|
|
182
|
+
* driven by group state — titles, rosters, avatars and roles carried in the
|
|
183
|
+
* GroupContext — saw nothing. A group then materialised unnamed until a
|
|
184
|
+
* best-effort broadcast happened to arrive, and never converged from group
|
|
185
|
+
* state at all. Prefer `meta()` when you need the full record; this is the
|
|
186
|
+
* one-field convenience that hosts were already reaching for.
|
|
187
|
+
*/
|
|
188
|
+
readonly name?: string | undefined;
|
|
189
|
+
/** The conversation's current MLS epoch, or `undefined` when the meta cache
|
|
190
|
+
* has not been primed. */
|
|
191
|
+
readonly epoch?: number | undefined;
|
|
192
|
+
meta(): ConversationMeta;
|
|
193
|
+
}
|
|
194
|
+
declare class MessagingClient {
|
|
195
|
+
private worker;
|
|
196
|
+
private nextId;
|
|
197
|
+
private pending;
|
|
198
|
+
private storage;
|
|
199
|
+
private transport;
|
|
200
|
+
private now;
|
|
201
|
+
/** `onMessage` / `onMessageBatch` handlers and the guarded delivery to them. */
|
|
202
|
+
private readonly fanout;
|
|
203
|
+
private conversationHandlers;
|
|
204
|
+
private subscription;
|
|
205
|
+
private metaCache;
|
|
206
|
+
/**
|
|
207
|
+
* Per-conversation batching of sequenced live frames: the first frame goes
|
|
208
|
+
* to the worker at once, frames that arrive while that batch is in flight
|
|
209
|
+
* go out as ONE `processSequencedBatch` when it returns. See
|
|
210
|
+
* {@link dispatchIncoming}.
|
|
211
|
+
*/
|
|
212
|
+
private readonly coalescer;
|
|
213
|
+
/** Single-flight gap fills, one `syncConversationStep` loop per conversation. */
|
|
214
|
+
private readonly gapFiller;
|
|
215
|
+
/** Set by {@link close}: every later call rejects instead of hanging. */
|
|
216
|
+
private closed;
|
|
217
|
+
private ownDeviceId;
|
|
218
|
+
/**
|
|
219
|
+
* Per-conversation dispatch chains. See {@link dispatchIncoming}.
|
|
220
|
+
*
|
|
221
|
+
* Keyed by lowercase-hex conversation id. Bounded: a chain is deleted the
|
|
222
|
+
* moment it settles and is still the tail, so an account with thousands of
|
|
223
|
+
* conversations holds at most one entry per conversation with work IN FLIGHT,
|
|
224
|
+
* not one per conversation it has ever seen.
|
|
225
|
+
*/
|
|
226
|
+
private dispatchChains;
|
|
227
|
+
private constructor();
|
|
228
|
+
/** Generate a fresh identity. The returned bytes are a secret — store them encrypted. */
|
|
229
|
+
static generateIdentity(): Promise<Uint8Array>;
|
|
230
|
+
/**
|
|
231
|
+
* HPKE-seal a `LinkingTicket` for delivery to a new device ([CR-3]).
|
|
232
|
+
*
|
|
233
|
+
* Returns CBOR-encoded bytes safe to relay through an untrusted inbox. The new device's
|
|
234
|
+
* X25519 public key (`newDevicePub`) is exchanged out-of-band — typically as part of a
|
|
235
|
+
* QR-encoded handshake on the linking screen. Pure function; runs in an ephemeral
|
|
236
|
+
* worker so no live `MessagingClient` is required on the sender side.
|
|
237
|
+
*
|
|
238
|
+
* Suite: `DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, AES-128-GCM` (matches MLS).
|
|
239
|
+
*/
|
|
240
|
+
static sealLinkingTicket(ticket: LinkingTicket, newDevicePub: Uint8Array): Promise<Uint8Array>;
|
|
241
|
+
/**
|
|
242
|
+
* HPKE-open a sealed `LinkingTicket` on the new device ([CR-3]).
|
|
243
|
+
*
|
|
244
|
+
* The receiving device hasn't booted a `MessagingClient` yet — it only has its X25519
|
|
245
|
+
* ephemeral keypair. This static method runs the open in an ephemeral worker, returning
|
|
246
|
+
* the cleartext ticket which the host then feeds to `init()` + `consumeLinkingTicket()`.
|
|
247
|
+
*
|
|
248
|
+
* On failure the error message is deliberately generic (no discriminator between "wrong
|
|
249
|
+
* key" vs "tampered ciphertext") so a probing attacker can't tell the new device's key
|
|
250
|
+
* was the issue.
|
|
251
|
+
*/
|
|
252
|
+
static openLinkingTicket(sealed: Uint8Array, newDevicePriv: Uint8Array): Promise<LinkingTicket>;
|
|
253
|
+
/**
|
|
254
|
+
* Generic HPKE-Base seal of arbitrary bytes to `recipientPub` (32-byte X25519)
|
|
255
|
+
* under a caller-supplied `info`. One shared HPKE implementation so app layers
|
|
256
|
+
* (e.g. the device-linking auth envelope) stop hand-rolling per-platform HPKE
|
|
257
|
+
* that drifts and breaks cross-platform. Runs in an ephemeral worker.
|
|
258
|
+
*/
|
|
259
|
+
static hpkeSeal(plaintext: Uint8Array, recipientPub: Uint8Array, info: Uint8Array): Promise<Uint8Array>;
|
|
260
|
+
/** Generic HPKE-Base open — inverse of {@link hpkeSeal}. `info` must match the sender. */
|
|
261
|
+
static hpkeOpen(sealed: Uint8Array, recipientPriv: Uint8Array, info: Uint8Array): Promise<Uint8Array>;
|
|
262
|
+
/**
|
|
263
|
+
* HPKE-Base seal in the RFC 9180 CANONICAL layout, `enc || ct||tag`, with no
|
|
264
|
+
* CBOR wrapper.
|
|
265
|
+
*
|
|
266
|
+
* Use this, not {@link hpkeSeal}, for anything the app layers already speak.
|
|
267
|
+
* `hpkeSeal` wraps its output in CBOR `{v, enc, ct}` for the linking ticket,
|
|
268
|
+
* and because that could not read the RFC layout, iOS, Android, web and the
|
|
269
|
+
* third-party `ping-notify` sender each ended up hand-composing their own
|
|
270
|
+
* HPKE for the same suite. This is the one they agree on.
|
|
271
|
+
*/
|
|
272
|
+
static hpkeSealRaw(plaintext: Uint8Array, recipientPub: Uint8Array, info: Uint8Array): Promise<Uint8Array>;
|
|
273
|
+
/**
|
|
274
|
+
* Inverse of {@link hpkeSealRaw}. `info` must match the sender's.
|
|
275
|
+
*
|
|
276
|
+
* Rejects with one uniform error whatever went wrong. This opens bytes from
|
|
277
|
+
* an unauthenticated inbox, so a caller that could tell "wrong key" from
|
|
278
|
+
* "tampered" from "truncated" would be an oracle for whoever wrote them.
|
|
279
|
+
*/
|
|
280
|
+
static hpkeOpenRaw(sealed: Uint8Array, recipientPriv: Uint8Array, info: Uint8Array): Promise<Uint8Array>;
|
|
281
|
+
/**
|
|
282
|
+
* A fresh X25519 keypair for the suite.
|
|
283
|
+
*
|
|
284
|
+
* Exposed so a caller minting a recipient key (a Ping Notify inbox, a linking
|
|
285
|
+
* handshake) does not reach for WebCrypto to do it, which is the same problem
|
|
286
|
+
* one layer down.
|
|
287
|
+
*/
|
|
288
|
+
static hpkeGenerateKeypair(): Promise<{
|
|
289
|
+
publicKey: Uint8Array;
|
|
290
|
+
privateKey: Uint8Array;
|
|
291
|
+
}>;
|
|
292
|
+
/**
|
|
293
|
+
* HPKE-seal a `LinkingTicket` under the new device's X-Wing public key
|
|
294
|
+
* ([CR-3], post-quantum). CBOR `{v: 2, enc, ct}` under `ping/link/v2`; the
|
|
295
|
+
* classical {@link openLinkingTicket} refuses it and {@link openLinkingTicketPq}
|
|
296
|
+
* refuses a `v: 1` blob, so there is no downgrade in either direction.
|
|
297
|
+
*/
|
|
298
|
+
static sealLinkingTicketPq(ticket: LinkingTicket, newDevicePub: Uint8Array): Promise<Uint8Array>;
|
|
299
|
+
/**
|
|
300
|
+
* HPKE-open a sealed `v: 2` ticket with the new device's 32-byte X-Wing seed
|
|
301
|
+
* ([CR-3], post-quantum). The error is deliberately generic, like
|
|
302
|
+
* {@link openLinkingTicket}.
|
|
303
|
+
*/
|
|
304
|
+
static openLinkingTicketPq(sealed: Uint8Array, newDevicePriv: Uint8Array): Promise<LinkingTicket>;
|
|
305
|
+
/** Post-quantum {@link hpkeSeal}: CBOR-wrapped (`v: 2`), `recipientPub` is 1216 bytes. */
|
|
306
|
+
static hpkeSealPq(plaintext: Uint8Array, recipientPub: Uint8Array, info: Uint8Array): Promise<Uint8Array>;
|
|
307
|
+
/** Inverse of {@link hpkeSealPq}. `recipientPriv` is the 32-byte seed; `info` must match. */
|
|
308
|
+
static hpkeOpenPq(sealed: Uint8Array, recipientPriv: Uint8Array, info: Uint8Array): Promise<Uint8Array>;
|
|
309
|
+
/**
|
|
310
|
+
* Post-quantum {@link hpkeSealRaw}: RFC 9180 canonical `enc(1120) || ct || tag`.
|
|
311
|
+
* The `v2` form of every app-layer envelope (`ping/link-auth/v2`,
|
|
312
|
+
* `ping/app-inbox/v2`).
|
|
313
|
+
*/
|
|
314
|
+
static hpkeSealRawPq(plaintext: Uint8Array, recipientPub: Uint8Array, info: Uint8Array): Promise<Uint8Array>;
|
|
315
|
+
/** Inverse of {@link hpkeSealRawPq}. One uniform error, as for {@link hpkeOpenRaw}. */
|
|
316
|
+
static hpkeOpenRawPq(sealed: Uint8Array, recipientPriv: Uint8Array, info: Uint8Array): Promise<Uint8Array>;
|
|
317
|
+
/**
|
|
318
|
+
* A fresh X-Wing keypair: `publicKey` is {@link HPKE_PQ_PUBLIC_KEY_BYTES} bytes,
|
|
319
|
+
* `privateKey` the 32-byte seed. Persist only the seed and recompute the public
|
|
320
|
+
* half with {@link hpkePublicKeyFromSeed}; wipe both buffers when done.
|
|
321
|
+
*/
|
|
322
|
+
static hpkeGenerateKeypairPq(): Promise<{
|
|
323
|
+
publicKey: Uint8Array;
|
|
324
|
+
privateKey: Uint8Array;
|
|
325
|
+
}>;
|
|
326
|
+
/**
|
|
327
|
+
* The X-Wing public key for a stored 32-byte seed. Deterministic: the pairing
|
|
328
|
+
* code carries SHA-256 of exactly these bytes, so what a device advertises
|
|
329
|
+
* always matches what it will open with.
|
|
330
|
+
*/
|
|
331
|
+
static hpkePublicKeyFromSeed(seed: Uint8Array): Promise<Uint8Array>;
|
|
332
|
+
/**
|
|
333
|
+
* The id of an account's DeviceGroup (the private sync group of the
|
|
334
|
+
* account's own devices), derived by the SDK core from the account's MLS
|
|
335
|
+
* user id: `userId` is `client.userId()` (32 bytes), NOT the server's
|
|
336
|
+
* account id. Deterministic: every device of the account derives the same
|
|
337
|
+
* id, so a host recognises the DeviceGroup without copying the derivation.
|
|
338
|
+
* Stateless (no client needed); bytes that are not an MLS user id derive an
|
|
339
|
+
* id no device uses.
|
|
340
|
+
*/
|
|
341
|
+
static deviceGroupIdFor(userId: UserId): Promise<ConversationId>;
|
|
342
|
+
/** The 32-byte X25519 public key for a stored classical private key. */
|
|
343
|
+
static hpkePublicKeyFromPrivate(privateKey: Uint8Array): Promise<Uint8Array>;
|
|
344
|
+
/**
|
|
345
|
+
* Answer a device re-authentication challenge (`POST /v1/auth/device/challenge`) with
|
|
346
|
+
* the device signing key, so a device whose session tokens are gone or dead gets fresh
|
|
347
|
+
* ones for the SAME device without a code (`POST /v1/auth/device/verify`).
|
|
348
|
+
*
|
|
349
|
+
* The SDK builds the signed bytes itself (`"ping/device-reauth/v1" || challengeId ||
|
|
350
|
+
* nonce || deviceId || accountId || audience`), so this cannot sign anything else with
|
|
351
|
+
* the device key. `deviceSigningSecretKey` is the 32-byte secret the host passes as
|
|
352
|
+
* `deviceSigningSecretKey` to {@link init}; `challengeId` (16 bytes) and `nonce`
|
|
353
|
+
* (32 bytes) come from the challenge response. `accountId` (16 bytes) is the account
|
|
354
|
+
* the host stored with its session; the server refuses a proof for any other account,
|
|
355
|
+
* so send the same id with the proof. `audience` is the canonical origin of the API
|
|
356
|
+
* THIS host is configured to reach (`new URL(apiBase).origin`, for example
|
|
357
|
+
* `https://api-prod.ping.live`), never the value the server returned: that is what
|
|
358
|
+
* makes a challenge relayed from another deployment useless there. The returned
|
|
359
|
+
* `deviceId` is SHA-256 of the key's public half; send it with the signature.
|
|
360
|
+
*
|
|
361
|
+
* Rejects wrong widths and a non-canonical audience. Runs in an ephemeral worker.
|
|
362
|
+
*/
|
|
363
|
+
static signDeviceReauth(params: {
|
|
364
|
+
deviceSigningSecretKey: Uint8Array;
|
|
365
|
+
challengeId: Uint8Array;
|
|
366
|
+
nonce: Uint8Array;
|
|
367
|
+
accountId: Uint8Array;
|
|
368
|
+
audience: string;
|
|
369
|
+
}): Promise<DeviceReauthProof>;
|
|
370
|
+
/**
|
|
371
|
+
* Link verification v2, on the APPROVING device: approve ONE new device on ONE
|
|
372
|
+
* server link session (`POST /v1/auth/link/sessions` returned `approvalSessionId`)
|
|
373
|
+
* with this device's signing key. The new device sends the result with its own
|
|
374
|
+
* {@link signDeviceLinkPossession} proof to `POST /v1/auth/link/verify`.
|
|
375
|
+
*
|
|
376
|
+
* The SDK builds the signed bytes itself (`"ping/device-link-approve/v1" ||
|
|
377
|
+
* approvalSessionId || accountId || approverDeviceId || newDeviceId ||
|
|
378
|
+
* newDevicePubkey || audience`, see docs/DEVICE_LINK_V2_VECTORS.md) and derives
|
|
379
|
+
* both device ids from the keys, so this cannot sign anything else with the device
|
|
380
|
+
* key. `deviceSigningSecretKey` is the 32-byte seed the host holds for THIS device
|
|
381
|
+
* (the one registered as its device signing key); `accountId` (16 bytes) is the
|
|
382
|
+
* account stored with this device's session; `newDevicePubkey` (32 bytes) is the
|
|
383
|
+
* new device's key from its handshake; `audience` is the canonical origin of the API
|
|
384
|
+
* THIS host is configured to reach (`new URL(apiBase).origin`), as for
|
|
385
|
+
* {@link signDeviceReauth}.
|
|
386
|
+
*
|
|
387
|
+
* Rejects wrong widths, a non-canonical audience, a new key that is not a canonical
|
|
388
|
+
* Ed25519 point outside the small-order subgroup, and this device's own key. Runs in
|
|
389
|
+
* an ephemeral worker.
|
|
390
|
+
*/
|
|
391
|
+
static signDeviceLinkApproval(params: {
|
|
392
|
+
deviceSigningSecretKey: Uint8Array;
|
|
393
|
+
approvalSessionId: Uint8Array;
|
|
394
|
+
accountId: Uint8Array;
|
|
395
|
+
newDevicePubkey: Uint8Array;
|
|
396
|
+
audience: string;
|
|
397
|
+
}): Promise<DeviceLinkApproval>;
|
|
398
|
+
/**
|
|
399
|
+
* Link verification v2, on the NEW device: prove that this device holds the key the
|
|
400
|
+
* link session names (`"ping/device-link-possess/v1" || approvalSessionId ||
|
|
401
|
+
* accountId || deviceId || audience`). `deviceSigningSecretKey` is this device's own
|
|
402
|
+
* 32-byte seed (the key its handshake advertised); `approvalSessionId` and
|
|
403
|
+
* `accountId` come from the approving device's sealed envelope; `audience` as for
|
|
404
|
+
* {@link signDeviceReauth}. Check `approval.newDeviceId` equals the returned
|
|
405
|
+
* `deviceId` before verifying: a substituted handshake is refused locally.
|
|
406
|
+
*
|
|
407
|
+
* Rejects wrong widths and a non-canonical audience. Runs in an ephemeral worker.
|
|
408
|
+
*/
|
|
409
|
+
static signDeviceLinkPossession(params: {
|
|
410
|
+
deviceSigningSecretKey: Uint8Array;
|
|
411
|
+
approvalSessionId: Uint8Array;
|
|
412
|
+
accountId: Uint8Array;
|
|
413
|
+
audience: string;
|
|
414
|
+
}): Promise<DeviceLinkPossession>;
|
|
415
|
+
private static ephemeralWorkerCall;
|
|
416
|
+
static init(cfg: ClientConfig): Promise<MessagingClient>;
|
|
417
|
+
/**
|
|
418
|
+
* Internal: route an inbound envelope to the right handler, IN ARRIVAL ORDER
|
|
419
|
+
* PER CONVERSATION.
|
|
420
|
+
*
|
|
421
|
+
* ## Why the ordering is load-bearing
|
|
422
|
+
*
|
|
423
|
+
* A group invitation arrives as a Welcome immediately followed by the
|
|
424
|
+
* inviter's hydration Application messages (group title, roster, avatar id).
|
|
425
|
+
* `joinConversation` is asynchronous — it is several round trips to the WASM
|
|
426
|
+
* worker — so a naive `void dispatchIncoming(...)` per frame let the
|
|
427
|
+
* Applications reach `processEnvelope` while the join was still in flight.
|
|
428
|
+
* The conversation did not exist yet, so every one of them was dropped with
|
|
429
|
+
* "envelope drop: unknown conversation".
|
|
430
|
+
*
|
|
431
|
+
* That loss is PERMANENT and silent: MLS ratchets forward, the transport has
|
|
432
|
+
* already marked the frames seen and advanced its cursor, and the server will
|
|
433
|
+
* not resend them. The visible symptom was an invitation landing as an
|
|
434
|
+
* unnamed "New chat" with no avatar and no roster, and — for the same reason —
|
|
435
|
+
* a rename, avatar change, member add/remove or role change being lost
|
|
436
|
+
* whenever it happened to land while a join or another commit for that group
|
|
437
|
+
* was still being applied.
|
|
438
|
+
*
|
|
439
|
+
* Chaining PER CONVERSATION (not globally) is deliberate: MLS state is
|
|
440
|
+
* per-group, so that is the granularity correctness actually requires, and a
|
|
441
|
+
* busy conversation must not be able to head-of-line block every other one.
|
|
442
|
+
* The chain is built synchronously on entry, so chain order is exactly frame
|
|
443
|
+
* arrival order.
|
|
444
|
+
*
|
|
445
|
+
* ## Sequenced frames
|
|
446
|
+
*
|
|
447
|
+
* A frame that carries its server position (`{ envelope, serverSeq }`,
|
|
448
|
+
* `serverSeq > 0`) does not need the chain: the core applies it at its
|
|
449
|
+
* position, holds it ahead of a hole and drops it at or below what was
|
|
450
|
+
* applied, whatever order it arrived in. What it needs is BATCHING: one
|
|
451
|
+
* MLS checkpoint and one host transaction per burst instead of one per
|
|
452
|
+
* frame. So the first frame for a conversation goes to the worker at once
|
|
453
|
+
* as a batch of one, and frames that arrive while that batch is in flight
|
|
454
|
+
* accumulate and go out as ONE `processSequencedBatch` when it returns; no
|
|
455
|
+
* timer ever delays a frame. Own-device echoes are NOT dropped on this
|
|
456
|
+
* path: the core advances the position past them without touching MLS,
|
|
457
|
+
* and dropping one would leave a hole the next frame reports as a gap. A
|
|
458
|
+
* sequenced frame at `serverSeq` 0 is a legacy frame in a wrapper and
|
|
459
|
+
* takes the legacy path unchanged.
|
|
460
|
+
*/
|
|
461
|
+
private dispatchIncoming;
|
|
462
|
+
/** The legacy per-envelope path: own-device drop, then the per-conversation chain. */
|
|
463
|
+
private dispatchLegacy;
|
|
464
|
+
/** The actual routing, run inside the per-conversation chain. */
|
|
465
|
+
private dispatchIncomingOrdered;
|
|
466
|
+
/**
|
|
467
|
+
* One coalesced batch of live frames. Errors are logged at debug and
|
|
468
|
+
* swallowed, exactly as the legacy path treats a failed envelope: the
|
|
469
|
+
* dispatch promise a transport may await resolves either way, and the
|
|
470
|
+
* core retains anything it could not apply yet.
|
|
471
|
+
*/
|
|
472
|
+
private applyLiveBatch;
|
|
473
|
+
/** Start a fill for every gap a batch reported; each is single-flight. */
|
|
474
|
+
private scheduleGapFills;
|
|
475
|
+
/** One page, delivered as a page, on the requested lane. */
|
|
476
|
+
private stepConversation;
|
|
477
|
+
userId(): Promise<UserId>;
|
|
478
|
+
/**
|
|
479
|
+
* Export the account identity seed (CBOR-wrapped Ed25519, **SECRET**).
|
|
480
|
+
* Transfer to a newly-linked device over the sealed linking channel so all of
|
|
481
|
+
* an account's devices share one `userId` — the basis for cross-device
|
|
482
|
+
* self-attribution (`IncomingMessage.sender_user_id === userId()`). Never log
|
|
483
|
+
* or persist in cleartext.
|
|
484
|
+
*/
|
|
485
|
+
exportIdentity(): Promise<Uint8Array>;
|
|
486
|
+
/**
|
|
487
|
+
* RETIRED (2026-11-03): always rejects (`Invalid`) and changes nothing.
|
|
488
|
+
*
|
|
489
|
+
* It moved every conversation's own leaf to a new account identity with a
|
|
490
|
+
* credential-changing Commit, the way out of `409 mls_identity_conflict`.
|
|
491
|
+
* Every Ping client now refuses a Commit that changes a member's leaf
|
|
492
|
+
* credential (a hostile linked device could otherwise move its leaf to a
|
|
493
|
+
* peer's identity and escape the account's removal), so a rotation would
|
|
494
|
+
* strand every conversation it touched. The way out of an identity conflict
|
|
495
|
+
* is to link this device again, or sign out and in. Kept so no caller
|
|
496
|
+
* breaks. See `docs/MULTIDEVICE.md` "Identity rotation".
|
|
497
|
+
*
|
|
498
|
+
* @deprecated Retired: always rejects. Link this device again instead.
|
|
499
|
+
*/
|
|
500
|
+
rotateIdentity(newIdentityExport: Uint8Array, nowMs?: number): Promise<IdentityRotation>;
|
|
501
|
+
/**
|
|
502
|
+
* RETIRED with [[rotateIdentity]]: always rejects (`Invalid`).
|
|
503
|
+
*
|
|
504
|
+
* @deprecated Retired: always rejects.
|
|
505
|
+
*/
|
|
506
|
+
rotateIdentityRetry(conv: ConversationId, nowMs?: number): Promise<void>;
|
|
507
|
+
deviceId(): Promise<DeviceId>;
|
|
508
|
+
/**
|
|
509
|
+
* Release every file lock the MLS store holds so the host process can be
|
|
510
|
+
* suspended. Resolves `true` when the locks are genuinely gone.
|
|
511
|
+
*
|
|
512
|
+
* Present on web for API parity, and a no-op returning `true` here: this build
|
|
513
|
+
* persists through the host's `Storage` (IndexedDB by default), which holds no
|
|
514
|
+
* file locks and has nothing to release. It is load-bearing on the native
|
|
515
|
+
* bindings, where iOS kills a backgrounded process that still holds a lock on
|
|
516
|
+
* a file in an App Group container. Exposed on every platform so a host
|
|
517
|
+
* sharing code across web and native does not have to branch on it.
|
|
518
|
+
*
|
|
519
|
+
* Pair with `resumeStorage()`.
|
|
520
|
+
*/
|
|
521
|
+
suspendStorage(): Promise<boolean>;
|
|
522
|
+
/** Undo `suspendStorage()`. Idempotent. */
|
|
523
|
+
resumeStorage(): Promise<void>;
|
|
524
|
+
freshKeyPackage(): Promise<Uint8Array>;
|
|
525
|
+
/**
|
|
526
|
+
* Generate a fresh LAST-RESORT KeyPackage (RFC 9420 §10). Publish exactly one
|
|
527
|
+
* per device so the server can serve it repeatedly as a fallback when the
|
|
528
|
+
* single-use pool empties — invites then never hard-fail purely because the
|
|
529
|
+
* peer ran out of KeyPackages.
|
|
530
|
+
*/
|
|
531
|
+
freshLastResortKeyPackage(): Promise<Uint8Array>;
|
|
532
|
+
createConversation(opts?: {
|
|
533
|
+
name?: string;
|
|
534
|
+
}): Promise<Conversation>;
|
|
535
|
+
/**
|
|
536
|
+
* Create an ephemeral per-call MLS group. Identical to {@link createConversation}
|
|
537
|
+
* except the id carries the `0xFF 0xCC` call-group sentinel, so every device
|
|
538
|
+
* recognises it structurally (by id alone — no name, no registry) and keeps it
|
|
539
|
+
* out of the chat list. Hosts MUST use this for call groups.
|
|
540
|
+
*/
|
|
541
|
+
createCallConversation(opts?: {
|
|
542
|
+
name?: string;
|
|
543
|
+
}): Promise<Conversation>;
|
|
544
|
+
joinConversation(welcome: MessageEnvelope): Promise<Conversation>;
|
|
545
|
+
/**
|
|
546
|
+
* Get a `Conversation` proxy for an already-known conversation. Use this when you have a
|
|
547
|
+
* conversation id (e.g., from `listConversations()`) and want to send/addMembers without
|
|
548
|
+
* re-creating it. Throws if the id isn't known to the worker — call `listConversations()`
|
|
549
|
+
* first to verify membership.
|
|
550
|
+
*/
|
|
551
|
+
getConversation(id: ConversationId): Conversation;
|
|
552
|
+
listConversations(): Promise<ConversationMeta[]>;
|
|
553
|
+
/**
|
|
554
|
+
* Conversations detected as STRANDED during catch-up — a Commit was missed
|
|
555
|
+
* and the group can no longer advance from local state, so new messages stop
|
|
556
|
+
* arriving. Poll after a sync and recover each (re-Welcome / state-snapshot
|
|
557
|
+
* import). Returns 16-byte conversation ids; the set self-clears as a
|
|
558
|
+
* conversation makes progress or is re-joined.
|
|
559
|
+
*/
|
|
560
|
+
strandedConversations(): Promise<ConversationId[]>;
|
|
561
|
+
/**
|
|
562
|
+
* Conversations this device asked to leave and is still a member of:
|
|
563
|
+
* the leave is OWED. The SDK holds their state and proposes the leave
|
|
564
|
+
* again by itself; the host only keeps delivering their rows (live
|
|
565
|
+
* frames and catch-up pages). An id leaves the list when the leave has
|
|
566
|
+
* completed: this device processed its own removal and the state is
|
|
567
|
+
* deleted. Sorted 16-byte conversation ids.
|
|
568
|
+
*/
|
|
569
|
+
conversationsLeaving(): Promise<ConversationId[]>;
|
|
570
|
+
/**
|
|
571
|
+
* The leaving conversations whose leave has STALLED: 8 sends of it
|
|
572
|
+
* FAILED and this device is still a member, or this device can no longer
|
|
573
|
+
* follow the group. Nothing more is proposed for them. The host may call
|
|
574
|
+
* {@link leaveConversation} again (the count starts over) or give up with
|
|
575
|
+
* {@link dropConversationLocal}, which leaves this device's leaf in the group
|
|
576
|
+
* until somebody removes it. Sorted 16-byte conversation ids.
|
|
577
|
+
*/
|
|
578
|
+
conversationsLeaveStalled(): Promise<ConversationId[]>;
|
|
579
|
+
/**
|
|
580
|
+
* Conversations this device was just torn down from by a SELF-RE-ADD Commit
|
|
581
|
+
* — a peer's `reAdmitDevice` of this device — whose Welcome for the new
|
|
582
|
+
* leaf is expected within seconds. Treat these as "re-admission in flight",
|
|
583
|
+
* not stranded or evicted: no repair advertise, no delivery-key rotation,
|
|
584
|
+
* no KeyPackage-pool replace, until the join lands or the entry ages out
|
|
585
|
+
* (ten minutes). Returns 16-byte conversation ids.
|
|
586
|
+
*/
|
|
587
|
+
readmitPendingConversations(nowMs?: number): Promise<ConversationId[]>;
|
|
588
|
+
/**
|
|
589
|
+
* How many inbound envelopes are currently RETAINED awaiting replay, across
|
|
590
|
+
* all conversations.
|
|
591
|
+
*
|
|
592
|
+
* An envelope that cannot be applied yet — its Welcome has not been processed,
|
|
593
|
+
* or a Commit that advances the epoch is missing — is buffered and replayed on
|
|
594
|
+
* join / epoch advance / catch-up sync rather than dropped (see
|
|
595
|
+
* docs/INVITE_HARDENING.md §S6).
|
|
596
|
+
*
|
|
597
|
+
* A non-zero count means "delivered but not yet applicable", which is
|
|
598
|
+
* materially different from "not delivered" and is the distinction a host
|
|
599
|
+
* needs to explain a chat that looks incomplete. Expected to be 0 at rest; a
|
|
600
|
+
* value that stays high points at a conversation whose handshake never
|
|
601
|
+
* arrived.
|
|
602
|
+
*/
|
|
603
|
+
undeliverableCount(): Promise<number>;
|
|
604
|
+
/**
|
|
605
|
+
* Leave a conversation: broadcasts a self-Remove PROPOSAL (MLS forbids
|
|
606
|
+
* committing your own removal: a remaining member commits it via
|
|
607
|
+
* `commitPendingProposals`) and answers at once. From then on the conversation is
|
|
608
|
+
* LEFT for the host: it is no longer listed, every call that names it
|
|
609
|
+
* answers `UnknownConversation`, and nothing of it is surfaced again.
|
|
610
|
+
*
|
|
611
|
+
* Do NOT delete it locally afterwards ({@link dropConversationLocal}). The SDK keeps the
|
|
612
|
+
* group's state, follows its Commits, and proposes the leave again after
|
|
613
|
+
* each Commit that did not carry it (a Commit built before the proposal
|
|
614
|
+
* arrived voids it), until this device is removed; then it deletes the
|
|
615
|
+
* state itself. Keep delivering the conversation's rows to the client
|
|
616
|
+
* while {@link conversationsLeaving} lists it. The bound is 8 FAILED sends;
|
|
617
|
+
* after that {@link conversationsLeaveStalled} lists the conversation and calling
|
|
618
|
+
* this again starts over.
|
|
619
|
+
*
|
|
620
|
+
* The group's OWNER hands over first: this call commits the successor (the
|
|
621
|
+
* one every device computes when the owner's last leaf goes) and only then
|
|
622
|
+
* proposes the leave. If that Commit cannot be made the call fails with the
|
|
623
|
+
* Commit's error and nothing is marked: call it again. Nothing is handed
|
|
624
|
+
* over when the owner's account keeps another device in the group or when
|
|
625
|
+
* no other member could take over.
|
|
626
|
+
*/
|
|
627
|
+
leaveConversation(id: ConversationId, nowMs?: number): Promise<void>;
|
|
628
|
+
/**
|
|
629
|
+
* Drop a conversation's local state with NO network side effect. Unlike
|
|
630
|
+
* {@link leaveConversation} (which broadcasts a self-Remove proposal), this
|
|
631
|
+
* sends nothing — use it for a group the SERVER does not back: an invite that
|
|
632
|
+
* minted the MLS group locally but never completed server-side, so the backend
|
|
633
|
+
* 404s `fetchSince` / 403s the member roster for it. Deletes the OpenMLS group
|
|
634
|
+
* state + the on-disk snapshot rows so the dead group stops rehydrating on the
|
|
635
|
+
* next restart (and re-materialising as a ghost "New chat"). Idempotent — safe
|
|
636
|
+
* on an unknown/already-dropped id.
|
|
637
|
+
*/
|
|
638
|
+
dropConversationLocal(id: ConversationId): Promise<void>;
|
|
639
|
+
/**
|
|
640
|
+
* Conversations with buffered pending proposals (e.g. a peer's leave). Poll
|
|
641
|
+
* after a sync; if you're the designated committer, call
|
|
642
|
+
* `commitPendingProposals` to evict the leaver.
|
|
643
|
+
*/
|
|
644
|
+
conversationsWithPendingProposals(): Promise<ConversationId[]>;
|
|
645
|
+
/**
|
|
646
|
+
* Commit buffered pending proposals for a conversation (evicts a peer who
|
|
647
|
+
* left). No-op if nothing is pending; on an epoch-advanced rejection re-sync
|
|
648
|
+
* (another member already committed). Call it on receipt (a batch or page
|
|
649
|
+
* result's `proposalsPending`), elected with
|
|
650
|
+
* {@link pendingProposalsCommitRank}. A `send` commits pending proposals
|
|
651
|
+
* itself first, so a proposal never blocks a message.
|
|
652
|
+
*/
|
|
653
|
+
commitPendingProposals(id: ConversationId, nowMs?: number): Promise<void>;
|
|
654
|
+
/**
|
|
655
|
+
* This device's rank in the deterministic election of who commits a
|
|
656
|
+
* conversation's pending proposals: members by leaf index, excluding any
|
|
657
|
+
* leaf a pending proposal removes; identical on every member. `0` means
|
|
658
|
+
* commit now; rank `n` means wait `n` intervals (a few seconds each), then
|
|
659
|
+
* commit if the proposals are still pending. `null` when nothing is pending
|
|
660
|
+
* or this device is not eligible.
|
|
661
|
+
*/
|
|
662
|
+
pendingProposalsCommitRank(id: ConversationId): Promise<number | null>;
|
|
663
|
+
/**
|
|
664
|
+
* The Commits this device holds in doubt: a Commit whose send got no
|
|
665
|
+
* definite answer (no response, a 5xx) is neither merged nor discarded; the
|
|
666
|
+
* SDK settles it on a capped exponential backoff, and every operation in
|
|
667
|
+
* that conversation fails with `commit in doubt` until it settles. Retry
|
|
668
|
+
* such an operation at `nextAttemptAtMs`.
|
|
669
|
+
*/
|
|
670
|
+
commitsInDoubt(): Promise<CommitInDoubt[]>;
|
|
671
|
+
/**
|
|
672
|
+
* Member roster for a conversation, recovered locally from the MLS
|
|
673
|
+
* group's leaf credentials (no network, no out-of-band message). Returns
|
|
674
|
+
* one entry per device leaf — a multi-device user appears multiple times,
|
|
675
|
+
* so dedup by `user_id` for a per-user roster. Empty for an unknown id.
|
|
676
|
+
*/
|
|
677
|
+
members(conv: ConversationId): Promise<MemberInfo[]>;
|
|
678
|
+
/**
|
|
679
|
+
* A conversation's credential policy (account-signed device credentials,
|
|
680
|
+
* 2026-11-04): whether every leaf must carry a credential the account key signed
|
|
681
|
+
* (`credentialsRequired`; a KeyPackage without one gets the add verdict
|
|
682
|
+
* `credentialMissing`), the roles once the policy records them (round 2), and
|
|
683
|
+
* `incapableMembers`, the accounts with a member on an app too old for this
|
|
684
|
+
* group, which is what blocks the upgrade. Rejects for a conversation this client
|
|
685
|
+
* does not hold. No host action is needed for the credentials themselves: the SDK
|
|
686
|
+
* signs and verifies them internally.
|
|
687
|
+
*/
|
|
688
|
+
conversationPolicy(conv: ConversationId): Promise<ConversationPolicy>;
|
|
689
|
+
/**
|
|
690
|
+
* Whether a Commit of THIS device that re-admits or adds the device `deviceId` of
|
|
691
|
+
* the account `identity` would pass the membership rules of the conversation in
|
|
692
|
+
* its state now, without building or sending anything (2026-11-18). True when
|
|
693
|
+
* this device may add a leaf of that account (the owner, an admin, or a device of
|
|
694
|
+
* that same account; a device of the OWNER only when this device is the owner's)
|
|
695
|
+
* and, if `deviceId` holds a leaf there, may also remove that leaf. Always true in
|
|
696
|
+
* a conversation without roles. Ask it BEFORE leasing a re-admission request or
|
|
697
|
+
* claiming a KeyPackage: a device that is not privileged never claims another
|
|
698
|
+
* account's KeyPackage. Advisory: the Commit is judged again when it is built and
|
|
699
|
+
* by every receiver. Rejects for a conversation this client does not hold.
|
|
700
|
+
*/
|
|
701
|
+
mayReadmit(conv: ConversationId, identity: UserId, deviceId: DeviceId): Promise<boolean>;
|
|
702
|
+
/**
|
|
703
|
+
* The identity (the account's user id) a KeyPackage's credential CLAIMS, read
|
|
704
|
+
* without changing anything (2026-11-18, rule R13). `null` for a credential that
|
|
705
|
+
* is not the project's. Rejects for bytes that are not a valid KeyPackage: the
|
|
706
|
+
* checks OpenMLS runs on a KeyPackage an add carries run first (both signatures
|
|
707
|
+
* under the leaf's own key, the version, the init key, the extensions against the
|
|
708
|
+
* capabilities, the lifetime: an expired KeyPackage rejects).
|
|
709
|
+
*
|
|
710
|
+
* Before adding ANOTHER account's device, read it and compare it with the account
|
|
711
|
+
* you meant to add, byte for byte; a different answer, or `null`, is enough to
|
|
712
|
+
* refuse the KeyPackage the server handed out, before any Commit.
|
|
713
|
+
*
|
|
714
|
+
* The read runs the SAME credential verdict the add runs (the device
|
|
715
|
+
* credential, then the leaf-ready check) and rejects for a claim the add
|
|
716
|
+
* would refuse, so an identity answered is one the account's key vouched
|
|
717
|
+
* for (rulings part 13, ruling 1; until then the answer was a bare claim).
|
|
718
|
+
*/
|
|
719
|
+
keyPackageIdentity(keyPackage: Uint8Array): Promise<UserId | null>;
|
|
720
|
+
/**
|
|
721
|
+
* Replace the owners this client expects first roles writes to name
|
|
722
|
+
* (2026-11-04, round 2; see `ClientConfig.expectedOwners`).
|
|
723
|
+
*/
|
|
724
|
+
setExpectedOwners(entries: ExpectedOwner[]): Promise<void>;
|
|
725
|
+
/**
|
|
726
|
+
* Record a group's roles in its policy (2026-11-04, round 2): `owner` and
|
|
727
|
+
* `admins` as MLS user ids (map account ids through the roster). One
|
|
728
|
+
* GroupContextExtensions Commit, no Welcome, send-then-merge. Rejects with
|
|
729
|
+
* "not permitted ..." before anything is sent when this device's role does not
|
|
730
|
+
* allow the change, when a member's app is too old for roles
|
|
731
|
+
* (`conversationPolicy().incapableMembers` names it), or in the DeviceGroup.
|
|
732
|
+
* The same call as `getConversation(id).setConversationRoles`.
|
|
733
|
+
*/
|
|
734
|
+
setConversationRoles(conv: ConversationId, owner: UserId, admins: UserId[]): Promise<void>;
|
|
735
|
+
/**
|
|
736
|
+
* Whole-account catch-up. The worker runs it one conversation at a time and
|
|
737
|
+
* lets every other request (a `send` the user is waiting on, a live frame)
|
|
738
|
+
* run between conversations, so a pass over many conversations never parks
|
|
739
|
+
* an interactive call behind all of them. Resolves when every conversation
|
|
740
|
+
* held at the start of the pass (plus any joined while it ran) has been
|
|
741
|
+
* paged, with the decrypted application messages in apply order.
|
|
742
|
+
*/
|
|
743
|
+
syncConversations(): Promise<IncomingMessage[]>;
|
|
744
|
+
/**
|
|
745
|
+
* Catch-up for ONE conversation: the unit `syncConversations` is built from.
|
|
746
|
+
* Use it to bring the conversation the user is looking at up to date ahead
|
|
747
|
+
* of the rest (a message must be encrypted at the epoch the group is really
|
|
748
|
+
* at, so a host calls this before the first send after a reconnect), or to
|
|
749
|
+
* step a pass in an order of its own. Rejects with the SDK's
|
|
750
|
+
* `unknown conversation` error for an id this client does not hold.
|
|
751
|
+
*/
|
|
752
|
+
syncConversation(id: ConversationId): Promise<IncomingMessage[]>;
|
|
753
|
+
processEnvelope(envelope: MessageEnvelope): Promise<IncomingMessage | null>;
|
|
754
|
+
/**
|
|
755
|
+
* Apply a batch of live frames, each with its server log position, and
|
|
756
|
+
* checkpoint once per touched conversation. Per conversation: the next
|
|
757
|
+
* position applies, one ahead of a hole is held and reported in `gaps`,
|
|
758
|
+
* one at or below the applied position is a duplicate. Welcomes are routed
|
|
759
|
+
* to a join inside the SDK (a join anchors the new conversation at the
|
|
760
|
+
* Welcome's position); own-device echoes advance the position without
|
|
761
|
+
* touching MLS, so pass them through. Frames at `serverSeq` 0 take the
|
|
762
|
+
* legacy per-sender path.
|
|
763
|
+
*
|
|
764
|
+
* The decrypted messages are returned AND delivered: to `onMessageBatch`
|
|
765
|
+
* handlers as one call (source `live`) when any is registered, else per
|
|
766
|
+
* message to `onMessage` handlers. `onConversationUpdated` fires once per
|
|
767
|
+
* entry of `updated`. A reported gap starts {@link fillGap} for that
|
|
768
|
+
* conversation.
|
|
769
|
+
*/
|
|
770
|
+
processSequencedBatch(items: SequencedEnvelope[]): Promise<ApplyBatchResult>;
|
|
771
|
+
/**
|
|
772
|
+
* ONE page of a conversation's server log through `Transport.fetchLogSince`,
|
|
773
|
+
* applied in order and checkpointed once, then whatever held frames the
|
|
774
|
+
* page made contiguous. `hasMore` means step again. Same delivery as
|
|
775
|
+
* {@link processSequencedBatch}, with source `page`. An ordinary request:
|
|
776
|
+
* it runs ahead of any background pass, so a host can bring the open chat
|
|
777
|
+
* current first. Rejects with the SDK's `unknown conversation` error for an
|
|
778
|
+
* id this client does not hold; the durable cursor is unchanged on a
|
|
779
|
+
* transport failure.
|
|
780
|
+
*/
|
|
781
|
+
syncConversationStep(id: ConversationId): Promise<SyncStepResult>;
|
|
782
|
+
/**
|
|
783
|
+
* Fill a conversation's gap: run {@link syncConversationStep} until
|
|
784
|
+
* `hasMore` is false, single-flight per conversation, on the worker's
|
|
785
|
+
* stepped lane so a send posted meanwhile goes between pages. The SDK
|
|
786
|
+
* starts this itself for every gap a batch reports; hosts call it for the
|
|
787
|
+
* heads a socket `resume_ack` shows above the local position. A call
|
|
788
|
+
* while a fill is running rides on it (and the loop runs once more after,
|
|
789
|
+
* in case the running one ended before the new gap's rows were appended).
|
|
790
|
+
*/
|
|
791
|
+
fillGap(conversationId: ConversationId): Promise<void>;
|
|
792
|
+
/**
|
|
793
|
+
* This device's applied position in every conversation it holds, sorted by
|
|
794
|
+
* conversation id: what a host puts in its socket resume frame and
|
|
795
|
+
* compares against the server's heads.
|
|
796
|
+
*/
|
|
797
|
+
logPositions(): Promise<LogPosition[]>;
|
|
798
|
+
/** This device's applied position in one conversation; `null` when not held. */
|
|
799
|
+
logPosition(id: ConversationId): Promise<LogPosition | null>;
|
|
800
|
+
/**
|
|
801
|
+
* Anchor a conversation whose cursor predates positions at the
|
|
802
|
+
* `(epoch, serverSeq)` the host had recorded for it, so an existing install
|
|
803
|
+
* does not page its whole current epoch again. Resolves `false` (a no-op)
|
|
804
|
+
* when the conversation is already anchored; the MLS epoch is never
|
|
805
|
+
* touched. Call it once at start-up for every conversation the host's own
|
|
806
|
+
* cursor store holds a position for.
|
|
807
|
+
*/
|
|
808
|
+
adoptLogPosition(id: ConversationId, epoch: number, serverSeq: number): Promise<boolean>;
|
|
809
|
+
/**
|
|
810
|
+
* Conversations the server's heads show this device is behind on: not
|
|
811
|
+
* anchored yet, a head above the applied position, or frames held in the
|
|
812
|
+
* reorder buffer. Sorted by id. A held conversation absent from `heads` is
|
|
813
|
+
* not listed.
|
|
814
|
+
*/
|
|
815
|
+
conversationsBehind(heads: LogHead[]): Promise<ConversationId[]>;
|
|
816
|
+
/** Frames held in reorder buffers right now (diagnostics). */
|
|
817
|
+
heldFrameCount(): Promise<number>;
|
|
818
|
+
/**
|
|
819
|
+
* {@link joinConversation} at the Welcome's log position, so the new
|
|
820
|
+
* conversation is anchored there and its first live frame applies without
|
|
821
|
+
* a page. Pass `null` (or omit) when the position is unknown.
|
|
822
|
+
*/
|
|
823
|
+
joinConversationAt(welcome: MessageEnvelope, position?: number | null): Promise<Conversation>;
|
|
824
|
+
/**
|
|
825
|
+
* The Welcome routing rule at a known position: joins when the conversation
|
|
826
|
+
* is unknown or held stranded and resolves to it, resolves `null` when it
|
|
827
|
+
* is held healthy (a relay duplicate), rejects when the Welcome is not
|
|
828
|
+
* addressed to this device.
|
|
829
|
+
*/
|
|
830
|
+
processWelcomeAt(welcome: MessageEnvelope, position?: number | null): Promise<Conversation | null>;
|
|
831
|
+
/**
|
|
832
|
+
* [D27] Decrypted-but-unconfirmed messages surviving in the pending-apply
|
|
833
|
+
* journal, oldest first.
|
|
834
|
+
*
|
|
835
|
+
* The MLS ratchet advances at decrypt, BEFORE the host persists its own row
|
|
836
|
+
* for the message; a crash inside that gap used to lose the message for good
|
|
837
|
+
* (the server re-delivers, but MLS cannot re-decrypt a consumed generation).
|
|
838
|
+
* The SDK now journals every decrypt in the same checkpoint that persists
|
|
839
|
+
* the ratchet advance.
|
|
840
|
+
*
|
|
841
|
+
* CRASH-RECOVERY CONTRACT: on boot, BEFORE advancing any sync cursor or
|
|
842
|
+
* sending any delivery ack, drain this list through the normal ingest —
|
|
843
|
+
* dedup by `content_hash` / envelope identity exactly as for a redelivered
|
|
844
|
+
* envelope — persist each message, then {@link confirmApplied} the drained
|
|
845
|
+
* ids. Reading does not consume; unconfirmed entries survive further
|
|
846
|
+
* restarts (bounded: 512 entries / 4 MiB, oldest evicted). See
|
|
847
|
+
* docs/PENDING_APPLIES.md.
|
|
848
|
+
*/
|
|
849
|
+
pendingApplies(): Promise<PendingApply[]>;
|
|
850
|
+
/**
|
|
851
|
+
* [D27] Delete journal entries whose messages the host has durably
|
|
852
|
+
* persisted (`IncomingMessage.journal_id` from live processing, or
|
|
853
|
+
* `PendingApply.journal_id` from a boot drain), and checkpoint so the
|
|
854
|
+
* deletion survives a reload. Unknown ids are ignored (idempotent).
|
|
855
|
+
*/
|
|
856
|
+
confirmApplied(journalIds: string[]): Promise<void>;
|
|
857
|
+
/**
|
|
858
|
+
* Build a `LinkingTicket` for a new device.
|
|
859
|
+
*
|
|
860
|
+
* [CR-13] `lastAppEvents` is host-supplied per-conversation "what you missed" data
|
|
861
|
+
* (decrypted AppEvent bytes the new device will render before sync catches up).
|
|
862
|
+
* Pass `[]` to suppress catchup data — the new device will see an empty conversation
|
|
863
|
+
* list until normal sync runs.
|
|
864
|
+
*
|
|
865
|
+
* Caller is responsible for HPKE-sealing the returned ticket via
|
|
866
|
+
* `MessagingClient.sealLinkingTicket` before transmitting (CR-3).
|
|
867
|
+
*
|
|
868
|
+
* Rejects (`Invalid`), before anything is sent, a KeyPackage that claims the
|
|
869
|
+
* identity of another account this client knows: a new device links under an
|
|
870
|
+
* identity of its own, or the account's.
|
|
871
|
+
*/
|
|
872
|
+
buildLinkingTicket(newDeviceId: DeviceId, newDeviceKp: Uint8Array, lastAppEvents?: CatchupAppEvent[]): Promise<LinkingTicket>;
|
|
873
|
+
/**
|
|
874
|
+
* Decode a `LinkingTicket.catchup_snapshot` blob ([CR-13]).
|
|
875
|
+
*
|
|
876
|
+
* Pure WASM — runs in an ephemeral worker so the new device can call this before
|
|
877
|
+
* `MessagingClient.init()` completes (just like `openLinkingTicket`). Returns the
|
|
878
|
+
* structured view: per-conversation metas + last-known AppEvent bytes.
|
|
879
|
+
*
|
|
880
|
+
* Throws on malformed or oversized inputs. Empty bytes return `null` — that's the
|
|
881
|
+
* "no catchup data" case (sender passed `[]` to buildLinkingTicket).
|
|
882
|
+
*/
|
|
883
|
+
static decodeCatchupSnapshot(snapshotBytes: Uint8Array): Promise<CatchupSnapshotView | null>;
|
|
884
|
+
consumeLinkingTicket(ticket: LinkingTicket): Promise<void>;
|
|
885
|
+
/** Generate a fresh 12-word BIP39 mnemonic, returned as its canonical phrase string. */
|
|
886
|
+
static generateMnemonicPhrase(): Promise<string>;
|
|
887
|
+
/** Validate + canonicalise a user-entered phrase (BIP39 wordlist + checksum). Rejects
|
|
888
|
+
* malformed input. Use on the recovery screen before calling `decryptBackup`. */
|
|
889
|
+
static normalizeMnemonicPhrase(phrase: string): Promise<string>;
|
|
890
|
+
/** Encrypt an IdentityBackup for `POST /v1/recovery/blobs`. `deviceGroupSnapshot` may be
|
|
891
|
+
* empty (Conservative path) or the DeviceGroup's `exportConversationStateSnapshot`. */
|
|
892
|
+
static encryptBackup(args: {
|
|
893
|
+
mnemonicPhrase: string;
|
|
894
|
+
accountId: Uint8Array;
|
|
895
|
+
identityExport: Uint8Array;
|
|
896
|
+
deviceGroupSnapshot: Uint8Array;
|
|
897
|
+
/** External conversations to embed so recovery restores them offline. Pass
|
|
898
|
+
* `[]` (the default) for identity + DeviceGroup only. Each `groupStateBytes`
|
|
899
|
+
* is `Conversation.exportConversationStateSnapshot` output. Forward-secrecy
|
|
900
|
+
* trade-off — see the SDK recovery docs. */
|
|
901
|
+
conversationSnapshots?: {
|
|
902
|
+
conversationId: Uint8Array;
|
|
903
|
+
groupStateBytes: Uint8Array;
|
|
904
|
+
}[];
|
|
905
|
+
createdAtMs: number;
|
|
906
|
+
}): Promise<Uint8Array>;
|
|
907
|
+
/** Decrypt a recovery blob from `GET /v1/recovery/blobs`. Throws on wrong mnemonic or a
|
|
908
|
+
* tampered blob. The returned `identity_export` is the secret seed for `init`. */
|
|
909
|
+
static decryptBackup(blob: Uint8Array, mnemonicPhrase: string): Promise<RecoveryBackup>;
|
|
910
|
+
/** Seal+sign a `HistoryBundle` for a recipient device. `recipientPub` (X25519, 32B) is the
|
|
911
|
+
* recipient's ephemeral pubkey from the linking QR; `senderIdentitySecret` (Ed25519 seed,
|
|
912
|
+
* 32B) is this account's identity key. Returns the blob to POST to /v1/history-transfers. */
|
|
913
|
+
static sealHistoryBundle(bundle: HistoryBundle, recipientPub: Uint8Array, senderIdentitySecret: Uint8Array): Promise<Uint8Array>;
|
|
914
|
+
/** Open+verify a sealed history bundle. `recipientPriv` (X25519, 32B) is this device's
|
|
915
|
+
* ephemeral private key; `senderIdentityPub` (Ed25519, 32B) is the account identity pubkey
|
|
916
|
+
* from the linking handshake. Throws if the signature doesn't verify. */
|
|
917
|
+
static openHistoryBundle(sealed: Uint8Array, recipientPriv: Uint8Array, senderIdentityPub: Uint8Array): Promise<HistoryBundle>;
|
|
918
|
+
/**
|
|
919
|
+
* Post-quantum {@link sealHistoryBundle}: `recipientPub` is the recipient's
|
|
920
|
+
* X-Wing public key ({@link HPKE_PQ_PUBLIC_KEY_BYTES} bytes). Wrapper `v: 2`;
|
|
921
|
+
* the classical open refuses it and vice versa.
|
|
922
|
+
*/
|
|
923
|
+
static sealHistoryBundlePq(bundle: HistoryBundle, recipientPub: Uint8Array, senderIdentitySecret: Uint8Array): Promise<Uint8Array>;
|
|
924
|
+
/** Post-quantum {@link openHistoryBundle}: `recipientPriv` is the 32-byte X-Wing seed. */
|
|
925
|
+
static openHistoryBundlePq(sealed: Uint8Array, recipientPriv: Uint8Array, senderIdentityPub: Uint8Array): Promise<HistoryBundle>;
|
|
926
|
+
/**
|
|
927
|
+
* Admit a freshly-linked device to every chat in `entries` — one MLS
|
|
928
|
+
* Commit + Welcome per chat, with the Welcome's `?recipient=` priming
|
|
929
|
+
* handled inside the SDK. This is the post-link reconciliation step
|
|
930
|
+
* that follows `consumeLinkingTicket`: the new device has the
|
|
931
|
+
* DeviceGroup (from the ticket) and metadata for external chats (from
|
|
932
|
+
* the catchup snapshot), but its leaf is not yet in any external
|
|
933
|
+
* MLS group. The host on the EXISTING device calls this once the
|
|
934
|
+
* new device shows up in `/v1/auth/sessions` and has uploaded its
|
|
935
|
+
* KeyPackage batch, passing one freshly-claimed KP per chat.
|
|
936
|
+
*
|
|
937
|
+
* Per-chat failures (stale KP, transport error, unknown chat) are
|
|
938
|
+
* captured in the returned outcomes rather than aborting — one bad
|
|
939
|
+
* chat shouldn't lose the user access to all the others.
|
|
940
|
+
*
|
|
941
|
+
* Each KeyPackage must carry this account's identity (a linked device
|
|
942
|
+
* adopts it with the link): one that claims any other identity fails its
|
|
943
|
+
* chat and nothing is sent there.
|
|
944
|
+
*/
|
|
945
|
+
admitDeviceToChats(deviceId: DeviceId, entries: AdmitChatEntry[]): Promise<AdmitChatOutcome[]>;
|
|
946
|
+
/**
|
|
947
|
+
* `admitDeviceToChats` with up to `concurrency` admissions in flight at
|
|
948
|
+
* once. Same input, same per-chat outcomes in INPUT order whatever order
|
|
949
|
+
* the sends finish in; `concurrency` 1 is exactly `admitDeviceToChats`,
|
|
950
|
+
* 0 is treated as 1. Safe because every admission is its own conversation
|
|
951
|
+
* (one Commit + Welcome per chat, the conversation lock is never held
|
|
952
|
+
* across the send), so two admissions never touch the same epoch.
|
|
953
|
+
*
|
|
954
|
+
* This is the ONLY way to overlap admissions on web: the worker runs one
|
|
955
|
+
* call at a time, so several `admitDeviceToChats` calls issued together
|
|
956
|
+
* still run one after another. The overlap happens inside this one call.
|
|
957
|
+
*/
|
|
958
|
+
admitDeviceToChatsConcurrent(deviceId: DeviceId, entries: AdmitChatEntry[], concurrency: number): Promise<AdmitChatOutcome[]>;
|
|
959
|
+
/**
|
|
960
|
+
* Revoke a device ([CR-2]).
|
|
961
|
+
*
|
|
962
|
+
* Removes `deviceId`'s leaf from every conversation where this client locally
|
|
963
|
+
* tracked the device→leaf mapping (i.e. conversations where this client itself
|
|
964
|
+
* admitted the device via `addMembers`, or where this client is the device being
|
|
965
|
+
* revoked). The SDK has already broadcast each Commit envelope via
|
|
966
|
+
* `transport.send`; the returned array is for any additional host-side handling
|
|
967
|
+
* (audit logs, UI). An empty array is a valid outcome — the device wasn't locally
|
|
968
|
+
* known anywhere.
|
|
969
|
+
*
|
|
970
|
+
* **Scope note.** Conversations where a peer admitted the device on this client's
|
|
971
|
+
* behalf are silently skipped — the leaf index isn't locally known. Host can fall
|
|
972
|
+
* back to `transport.discoverDevices` + a manual `remove_members(leafIndex)` for
|
|
973
|
+
* those, or wait for the affected user to revoke from a device that did the admit.
|
|
974
|
+
* See `docs/architecture/multi-device.md §Device removal`.
|
|
975
|
+
*/
|
|
976
|
+
revokeDevice(deviceId: DeviceId): Promise<MessageEnvelope[]>;
|
|
977
|
+
/**
|
|
978
|
+
* Remove one of THIS account's devices from every group this client is in, the
|
|
979
|
+
* DeviceGroup included, without stopping at a failure, and report where it stands.
|
|
980
|
+
*
|
|
981
|
+
* Unlike {@link revokeDevice}, the device's leaf is read from each ratchet tree (the
|
|
982
|
+
* leaf whose key hashes to the id), so this reaches leaves a sibling or a peer
|
|
983
|
+
* admitted. The id is the server's word that the device is this account's; outside
|
|
984
|
+
* the DeviceGroup a leaf is removed only when its credential names this account, or
|
|
985
|
+
* when the device was seen in the account's DeviceGroup and its credential names no
|
|
986
|
+
* other account this client knows (docs/MULTIDEVICE.md, "Which leaf"). An id that
|
|
987
|
+
* names no leaf of this account is rejected before anything is sent. Every held
|
|
988
|
+
* conversation is checked: a Commit of this device in doubt is settled first, and
|
|
989
|
+
* the log is read to its end before the device is reported absent (what that read
|
|
990
|
+
* applies comes with the next batch or page); a conversation that failed to load
|
|
991
|
+
* is a failure with reason `Unloadable`. The DeviceGroup goes first, then the
|
|
992
|
+
* conversations, a few at a time, each a send-then-merge Commit. Persist the report
|
|
993
|
+
* and call again until `failed` is empty and `deviceGroup !== "failed"`. A
|
|
994
|
+
* `CommitInDoubt` reason settles on its own backoff ({@link commitsInDoubt});
|
|
995
|
+
* `NotOwnAccount` and `RefusedCommit` never resolve by retrying (for
|
|
996
|
+
* `RefusedCommit`, offer to recreate the conversation). Groups this device joins
|
|
997
|
+
* later are checked for the device too.
|
|
998
|
+
*
|
|
999
|
+
* MLS only: revoke the device on the server yourself. Rejects for this device's own
|
|
1000
|
+
* id (leave a conversation with `leaveConversation` instead) and for a device that
|
|
1001
|
+
* is not this account's.
|
|
1002
|
+
*/
|
|
1003
|
+
removeDeviceEverywhere(deviceId: DeviceId, nowMs?: number): Promise<DeviceRemovalReport>;
|
|
1004
|
+
/**
|
|
1005
|
+
* Remove every other device of THIS account from every group this client is in,
|
|
1006
|
+
* except the devices in `keep` and this device: the "secure my account" sweep.
|
|
1007
|
+
*
|
|
1008
|
+
* `listed` is the server's list of this account's devices to remove (a reset's
|
|
1009
|
+
* `revoked_device_ids`). In the DeviceGroup every leaf but this device's and the
|
|
1010
|
+
* kept ones goes. Elsewhere a leaf goes when its credential names this client's
|
|
1011
|
+
* account (no device id has to match, so a device that moved its leaf to another
|
|
1012
|
+
* signature key is still reached), or when its device is in `listed` and was seen in
|
|
1013
|
+
* the account's DeviceGroup, whatever identity its leaf claims. A leaf the sweep
|
|
1014
|
+
* leaves although one of those two says it may be the account's (seen but not
|
|
1015
|
+
* listed, or listed but not seen) is reported: its conversation fails with
|
|
1016
|
+
* `NotOwnAccount`, so the report is never complete over it. Same pass and report as
|
|
1017
|
+
* {@link removeDeviceEverywhere}; call again until it is complete. MLS only.
|
|
1018
|
+
*/
|
|
1019
|
+
removeOwnDevicesExcept(keep: DeviceId[], listed: DeviceId[], nowMs?: number): Promise<DeviceRemovalReport>;
|
|
1020
|
+
/**
|
|
1021
|
+
* Export a portable MLS state snapshot for one conversation ([CR-7]).
|
|
1022
|
+
*
|
|
1023
|
+
* Returned bytes can be embedded in a recovery blob or shipped through a
|
|
1024
|
+
* linking ticket so another device of the same user identity can re-attach to
|
|
1025
|
+
* the group via [[importStateSnapshot]]. The bytes contain past epoch secrets;
|
|
1026
|
+
* never log, never persist unencrypted, wipe (`.fill(0)`) after use.
|
|
1027
|
+
*/
|
|
1028
|
+
exportConversationStateSnapshot(conv: ConversationId): Promise<Uint8Array>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Import a `GroupStateSnapshot` from another device of the same user identity
|
|
1031
|
+
* ([CR-7]).
|
|
1032
|
+
*
|
|
1033
|
+
* On success, the conversation appears in [[listConversations]] and decryption
|
|
1034
|
+
* of subsequent peer-originated traffic works against the imported state. For
|
|
1035
|
+
* full multi-device participation, the recovered device SHOULD then issue an
|
|
1036
|
+
* MLS Update Proposal to rotate onto a fresh leaf (post-v1 follow-up — see
|
|
1037
|
+
* `docs/design/CR4_CR7_PERSISTENCE.md` open question #3).
|
|
1038
|
+
*/
|
|
1039
|
+
importStateSnapshot(snapshotBytes: Uint8Array): Promise<ConversationId>;
|
|
1040
|
+
/**
|
|
1041
|
+
* Export a derived secret from a conversation's MLS exporter ([CR-8]).
|
|
1042
|
+
*
|
|
1043
|
+
* Used to seed the ephemeral channel (`ping/ephemeral`), call-media keys
|
|
1044
|
+
* (`ping/calls/media/<call_id>`), and call-ephemeral framer keys
|
|
1045
|
+
* (`ping/calls/ephemeral/<call_id>`). The returned bytes are a secret — never log,
|
|
1046
|
+
* persist only encrypted, and call `bytes.fill(0)` after use to wipe the typed array.
|
|
1047
|
+
*
|
|
1048
|
+
* Same `(conversationId, current_epoch, label, context, length)` produces the same
|
|
1049
|
+
* bytes across every binding (Rust core, native UniFFI, WASM/JS). Cross-platform
|
|
1050
|
+
* byte-equality is enforced by `protocol/conformance/export_secret/`.
|
|
1051
|
+
*/
|
|
1052
|
+
exportConversationSecret(conv: ConversationId, label: string, context: Uint8Array, length: number): Promise<Uint8Array>;
|
|
1053
|
+
/**
|
|
1054
|
+
* Subscribe to decrypted application messages, one call per message. A
|
|
1055
|
+
* batch or page result (the sequenced paths) is fanned out here per
|
|
1056
|
+
* message only while no {@link onMessageBatch} handler is registered.
|
|
1057
|
+
*/
|
|
1058
|
+
onMessage(handler: (m: IncomingMessage) => void): () => void;
|
|
1059
|
+
/**
|
|
1060
|
+
* Subscribe to decrypted messages one BATCH at a time: one call per
|
|
1061
|
+
* `processSequencedBatch` result (source `live`) or per page of the server
|
|
1062
|
+
* log (source `page`: a gap fill, or the whole-account catch-up), so the
|
|
1063
|
+
* host persists the batch in one store transaction. While at least one
|
|
1064
|
+
* batch handler is registered, batch and page results go ONLY here, never
|
|
1065
|
+
* per message to `onMessage`; the legacy per-envelope path still delivers
|
|
1066
|
+
* per message. An empty result is not delivered.
|
|
1067
|
+
*/
|
|
1068
|
+
onMessageBatch(handler: (messages: IncomingMessage[], meta: MessageBatchMeta) => void): () => void;
|
|
1069
|
+
/** Fired after every state-changing event for a conversation (Commit, member changes). */
|
|
1070
|
+
/**
|
|
1071
|
+
* Fires after every conversation state change — joining via Welcome, processing a Commit,
|
|
1072
|
+
* etc. `sender` carries the device id of whoever triggered the event when known (e.g. the
|
|
1073
|
+
* inviter's device on auto-join), so the host can label peers in its UI.
|
|
1074
|
+
*/
|
|
1075
|
+
onConversationUpdated(handler: (id: ConversationId, epoch: number, sender?: DeviceId) => void): () => void;
|
|
1076
|
+
/**
|
|
1077
|
+
* Stop the live subscription and terminate the worker. Every call still in
|
|
1078
|
+
* flight rejects with a {@link MessagingClientClosedError} (reason
|
|
1079
|
+
* `closed`), and every later call rejects the same way instead of waiting
|
|
1080
|
+
* on a worker that no longer exists. Idempotent.
|
|
1081
|
+
*/
|
|
1082
|
+
close(): Promise<void>;
|
|
1083
|
+
/** Reject every pending call with `error` and forget them. */
|
|
1084
|
+
private failPending;
|
|
1085
|
+
private conversationProxy;
|
|
1086
|
+
private call;
|
|
1087
|
+
/** Dispatch a worker-side transport proxy call onto the host transport.
|
|
1088
|
+
* `sendBatch` is the one method the worker proxy always declares but a
|
|
1089
|
+
* host may not implement: emulate it with sequential sends and report a
|
|
1090
|
+
* partial delivery with the sentinel the wasm bridge maps to
|
|
1091
|
+
* `TransportPartial`, so the SDK still learns the Commit landed while the
|
|
1092
|
+
* Welcome did not (and surfaces `WelcomeUndelivered`). The two
|
|
1093
|
+
* sequenced-log methods cross in the wasm's wire shape and are converted
|
|
1094
|
+
* to the public shape here, both ways; the worker only asks for them when
|
|
1095
|
+
* the host declared them at `init`. */
|
|
1096
|
+
private callTransportMethod;
|
|
1097
|
+
private handleWorker;
|
|
1098
|
+
}
|
|
1099
|
+
/** A stateless SDK call ran on a one-shot worker that failed before it could answer:
|
|
1100
|
+
* the worker could not be created (`spawn`), the request could not be posted (`post`),
|
|
1101
|
+
* the worker script failed to load, import or run (`error`), or its reply could not be
|
|
1102
|
+
* deserialised (`messageerror`). The worker has already been terminated; the event's
|
|
1103
|
+
* details (which may name a script URL) are not carried. */
|
|
1104
|
+
declare class EphemeralWorkerError extends Error {
|
|
1105
|
+
readonly reason: "spawn" | "post" | "error" | "messageerror";
|
|
1106
|
+
constructor(reason: "spawn" | "post" | "error" | "messageerror");
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* The typed rejection every call still pending gets when the client is
|
|
1110
|
+
* closed (`reason: "closed"`) or the worker reported an uncaught error
|
|
1111
|
+
* (`reason: "worker-error"`), and what every call made after `close()`
|
|
1112
|
+
* rejects with. Before this, `close()` terminated the worker and left those
|
|
1113
|
+
* promises pending forever.
|
|
1114
|
+
*/
|
|
1115
|
+
declare class MessagingClientClosedError extends Error {
|
|
1116
|
+
readonly reason: "closed" | "worker-error";
|
|
1117
|
+
constructor(reason: "closed" | "worker-error");
|
|
1118
|
+
}
|
|
1119
|
+
/** Sentinel prefix for an emulated batch that only partially landed. Kept in
|
|
1120
|
+
* lockstep with `core/ping-wasm/src/lib.rs` (`BATCH_PARTIAL_PREFIX`). */
|
|
1121
|
+
/** Width of an X-Wing (post-quantum HPKE) public key, `hpkeGenerateKeypairPq().publicKey`. */
|
|
1122
|
+
declare const HPKE_PQ_PUBLIC_KEY_BYTES = 1216;
|
|
1123
|
+
/** Width of the KEM encapsulation at the front of a post-quantum raw envelope. */
|
|
1124
|
+
declare const HPKE_PQ_ENC_BYTES = 1120;
|
|
1125
|
+
declare const BATCH_PARTIAL_PREFIX = "batch partial after ";
|
|
1126
|
+
/** How the rejection of a call reads when the conversation's roles do not
|
|
1127
|
+
* permit it (the core's `Error::NotPermitted`): this prefix, then the rule
|
|
1128
|
+
* that was broken (fixed text, no id, safe to log). No other failure starts
|
|
1129
|
+
* this way (a malformed request reads `invalid input: ...`). Kept in
|
|
1130
|
+
* lockstep with the core's display (`stringify` in
|
|
1131
|
+
* `core/ping-wasm/src/lib.rs`, pinned by `ping-core/tests/typed_errors.rs`). */
|
|
1132
|
+
declare const NOT_PERMITTED_PREFIX = "not permitted: ";
|
|
1133
|
+
/** The typed role refusal: what a `MessagingClient` call rejects with when
|
|
1134
|
+
* the encrypted group's roles do not permit it. Raised before anything was
|
|
1135
|
+
* built or sent, and final until the roles or the membership change: drop
|
|
1136
|
+
* the intent (never retry or queue it), read `conversationPolicy()` again.
|
|
1137
|
+
* A join from a Welcome and `importStateSnapshot` reject with it too, for a
|
|
1138
|
+
* state that names an owner or an admin without a verified leaf: drop that
|
|
1139
|
+
* invitation, or skip that conversation of the import. `message` stays the
|
|
1140
|
+
* core's text, so `isNotPermittedError` also reads a copy that lost its
|
|
1141
|
+
* class (a structured clone, another realm). */
|
|
1142
|
+
declare class NotPermittedError extends Error {
|
|
1143
|
+
/** The rule that was broken: fixed text, no id, safe to log. */
|
|
1144
|
+
readonly rule: string;
|
|
1145
|
+
constructor(message: string);
|
|
1146
|
+
}
|
|
1147
|
+
/** The rule a role refusal names, or `null` when `e` is any other failure.
|
|
1148
|
+
* Accepts the rejection itself, any object with a `message`, or the text. */
|
|
1149
|
+
declare function notPermittedRule(e: unknown): string | null;
|
|
1150
|
+
/** True when `e` is the typed role refusal ("the encrypted group's roles do
|
|
1151
|
+
* not permit this") and no other failure. */
|
|
1152
|
+
declare function isNotPermittedError(e: unknown): boolean;
|
|
1153
|
+
/** How the rejection of a call reads when an envelope names a sender device
|
|
1154
|
+
* other than the one that sealed its MLS message (the core's
|
|
1155
|
+
* `Error::SenderMismatch`). No other failure starts this way. Kept in
|
|
1156
|
+
* lockstep with the core's display (`stringify` in
|
|
1157
|
+
* `core/ping-wasm/src/lib.rs`, pinned by `ping-core/tests/typed_errors.rs`). */
|
|
1158
|
+
declare const SENDER_MISMATCH_PREFIX = "sender mismatch: ";
|
|
1159
|
+
/** The typed refusal of an envelope whose `senderDevice` is not the device
|
|
1160
|
+
* that sealed its message (checked after decryption against the sender
|
|
1161
|
+
* leaf's signature key). The message was not delivered, a Commit in it was
|
|
1162
|
+
* not applied, and no dedupe or ordering mark moved: the named device's own
|
|
1163
|
+
* messages are delivered as before. Drop the envelope, never retry it, show
|
|
1164
|
+
* nothing. `message` stays the core's text, so `isSenderMismatchError` also
|
|
1165
|
+
* reads a copy that lost its class. */
|
|
1166
|
+
declare class SenderMismatchError extends Error {
|
|
1167
|
+
constructor(message: string);
|
|
1168
|
+
}
|
|
1169
|
+
/** True when `e` is the typed sender refusal and no other failure. Accepts
|
|
1170
|
+
* the rejection itself, any object with a `message`, or the text. */
|
|
1171
|
+
declare function isSenderMismatchError(e: unknown): boolean;
|
|
1172
|
+
/** Sequential stand-in for a host transport without `sendBatch`: sends in
|
|
1173
|
+
* order and reports a failure after at least one success with the partial
|
|
1174
|
+
* sentinel, so the SDK learns the Commit landed while the Welcome did not. */
|
|
1175
|
+
declare function emulateSendBatch(transport: Pick<Transport, "send">, envelopes: MessageEnvelope[]): Promise<void>;
|
|
1176
|
+
/** Serialise a transport rejection for the worker so the wasm bridge can
|
|
1177
|
+
* still classify it: the HTTP status survives as `http <status>` in the
|
|
1178
|
+
* text (a definite 4xx lets the SDK roll a staged Commit back), and any
|
|
1179
|
+
* server error code rides along for diagnostics. */
|
|
1180
|
+
declare function describeTransportError(e: unknown): string;
|
|
1181
|
+
|
|
1182
|
+
export { AddMembersReport, AdmitChatEntry, AdmitChatOutcome, ApplyBatchResult, BATCH_PARTIAL_PREFIX, CONTENT_TYPE_CBOR, CONTENT_TYPE_CBOR_LEGACY_V1, CONTENT_TYPE_JSON, CONTENT_TYPE_JSON_LEGACY_V1, CatchupAppEvent, CatchupSnapshotView, type ClientConfig, CommitInDoubt, type Conversation, ConversationId, ConversationMeta, ConversationPolicy, DeviceId, DeviceLinkApproval, DeviceLinkPossession, DeviceReauthProof, DeviceRemovalReport, EphemeralWorkerError, ExpectedOwner, HPKE_PQ_ENC_BYTES, HPKE_PQ_PUBLIC_KEY_BYTES, HistoryBundle, IdentityRotation, IncomingMessage, KeyPackageEntry, LinkingTicket, LogHead, LogPosition, MemberInfo, MessageBatchMeta, MessageEnvelope, MessagingClient, MessagingClientClosedError, NOT_PERMITTED_PREFIX, NotPermittedError, PING_WIRE_CONTRACT_HEADER, PING_WIRE_CONTRACT_HEADER_VALUE, PING_WIRE_CONTRACT_VERSION, PendingApply, RecoveryBackup, SENDER_MISMATCH_PREFIX, SenderMismatchError, SequencedEnvelope, Storage, SyncStepResult, Transport, UserId, ValidationError, WIRE_VERSION_MIN_ACCEPTED, describeTransportError, emulateSendBatch, isNotPermittedError, isSenderMismatchError, negotiates, notPermittedRule, validate, verifyApplicationContentHash };
|