@xdevplatform/chat-xdk 0.1.0 → 0.2.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.
@@ -25,11 +25,17 @@ export class Chat {
25
25
  /**
26
26
  * Decrypt a raw webhook event payload.
27
27
  *
28
- * `conversationKeys` is the object returned by `extractConversationKeys`.
28
+ * `conversationKeys` is a plain `version key bytes` map — the `.keys`
29
+ * property of the object returned by `extractConversationKeys` (passing
30
+ * the whole result object yields an empty map and every decrypt fails
31
+ * with "no matching key found").
29
32
  * `signingKeys` is an array of `{ userId, publicKeyVersion, publicKey,
30
- * identityPublicKey, identityPublicKeySignature }` objects for the sender;
31
- * the SDK picks the matching version automatically.
32
- * Pass an empty array to skip signature verification.
33
+ * identityPublicKey, identityPublicKeySignature }` objects; entries are
34
+ * filtered to the event's sender and the SDK picks the matching version
35
+ * automatically. Under the default reject-unverified policy an empty
36
+ * array makes every signed event throw; only after
37
+ * `setRejectUnverified(false)` are such events returned with
38
+ * `verified: false`.
33
39
  */
34
40
  decryptEvent(event_b64: string, conversation_keys: any, signing_keys: any): any;
35
41
  /**
@@ -59,32 +65,37 @@ export class Chat {
59
65
  encrypt(plaintext: string, conversation_key: Uint8Array): string;
60
66
  /**
61
67
  * Encrypt a reaction-add.
62
- */
63
- encryptAddReaction(message_id: string, sender_id: string, conversation_id: string, conversation_key: Uint8Array, target_message_sequence_id: string, emoji: string, conversation_key_version: string, signing_key_version: string): any;
64
- /**
65
- * Encrypt a conversation key for one or more recipients.
66
68
  *
67
- * Each entry is `{ userId, publicKey, keyVersion }`.
69
+ * Takes a single params object with camelCase keys: `messageId`,
70
+ * `senderId`, `conversationId`, `conversationKey` (Uint8Array),
71
+ * `targetMessageSequenceId`, `emoji`, `conversationKeyVersion`,
72
+ * `signingKeyVersion`. The same shape works for `encryptRemoveReaction`.
68
73
  */
69
- encryptConversationKeyForRecipients(conversation_key: Uint8Array, recipients: any): any;
74
+ encryptAddReaction(params: any): any;
70
75
  /**
71
76
  * Encrypt a text message for the X API.
72
77
  *
73
- * `entities` accepts a JS array of `[start, end, "type"]` tuples, e.g.
74
- * `[[0, 23, "url"], [25, 30, "mention"]]`.
75
- *
76
- * `attachments` accepts a JS array of attachment objects, e.g.
77
- * `[{ attachment_type: "media", media_hash_key: "...", width: 1024, ... }]`.
78
+ * Takes a single params object with camelCase keys: `messageId`,
79
+ * `senderId`, `conversationId`, `conversationKey` (Uint8Array), `text`,
80
+ * `conversationKeyVersion`, `signingKeyVersion`, plus optional
81
+ * `entities` (array of `[start, end, "type"]` tuples), `attachments`
82
+ * (array of attachment objects), `shouldNotify`, and `ttlMsec`.
78
83
  */
79
- encryptMessage(message_id: string, sender_id: string, conversation_id: string, conversation_key: Uint8Array, text: string, conversation_key_version: string, signing_key_version: string, entities?: any | null, attachments?: any | null, should_notify?: boolean | null, ttl_msec?: number | null): any;
84
+ encryptMessage(params: any): any;
80
85
  /**
81
86
  * Encrypt a reaction-remove.
87
+ *
88
+ * Takes the same params object shape as `encryptAddReaction`.
82
89
  */
83
- encryptRemoveReaction(message_id: string, sender_id: string, conversation_id: string, conversation_key: Uint8Array, target_message_sequence_id: string, emoji: string, conversation_key_version: string, signing_key_version: string): any;
90
+ encryptRemoveReaction(params: any): any;
84
91
  /**
85
92
  * Encrypt a reply message for the X API.
93
+ *
94
+ * Takes a single params object: the same fields as `encryptMessage` plus
95
+ * required `replyToSequenceId` and optional `replyToSenderId`,
96
+ * `replyToText`, `replyToEntities`, and `replyToAttachments`.
86
97
  */
87
- encryptReply(message_id: string, sender_id: string, conversation_id: string, conversation_key: Uint8Array, text: string, conversation_key_version: string, signing_key_version: string, reply_to_sequence_id: string, reply_to_sender_id?: number | null, reply_to_text?: string | null, entities?: any | null, attachments?: any | null, reply_to_entities?: any | null, reply_to_attachments?: any | null, should_notify?: boolean | null, ttl_msec?: number | null): any;
98
+ encryptReply(params: any): any;
88
99
  /**
89
100
  * Encrypt a stream (e.g. media).
90
101
  */
@@ -101,10 +112,6 @@ export class Chat {
101
112
  * - `latestVersion`: The highest key version (use for encrypting new messages)
102
113
  */
103
114
  extractConversationKeys(events: string[]): any;
104
- /**
105
- * Generate a new conversation key.
106
- */
107
- generateConversationKey(): Uint8Array;
108
115
  /**
109
116
  * Generate new keypairs and return the registration payload.
110
117
  *
@@ -147,16 +154,42 @@ export class Chat {
147
154
  */
148
155
  constructor();
149
156
  /**
150
- * Prepare conversation keys for all participants in one call.
157
+ * Prepare a signed conversation-key change, ready to send to the X API.
158
+ *
159
+ * Takes a single params object with camelCase keys: `senderId`,
160
+ * `signingKeyVersion`, `publicKeys` (the flat array of public keys —
161
+ * self plus recipients — from the X API), plus optional
162
+ * `conversationId`. Omit `conversationId` for a one-to-one and it is
163
+ * derived from the two participants; pass the existing id for a group
164
+ * key rotation.
165
+ *
166
+ * Returns `{ conversationId, conversationKey, conversationKeyVersion,
167
+ * participantKeys, actionSignatures }`.
168
+ */
169
+ prepareConversationKeyChange(params: any): any;
170
+ /**
171
+ * Prepare a signed group create, ready to send to the X API.
151
172
  *
152
- * This is the recommended method for both group creation and key
153
- * initialization. Pass the flat array of public keys from the X API;
154
- * the SDK groups by userId, picks the latest version per user,
155
- * generates a fresh conversation key, and encrypts it for everyone.
173
+ * Takes a single params object with camelCase keys: `senderId`,
174
+ * `signingKeyVersion`, `publicKeys` (for the new roster),
175
+ * `conversationId`, `memberIds`, `adminIds`, plus optional `title`,
176
+ * `avatarUrl`, and `ttlMsec`. Emits two action signatures (a
177
+ * conversation-key change and the group create). Returns the same shape
178
+ * as [`Chat::prepare_conversation_key_change`].
179
+ */
180
+ prepareGroupCreate(params: any): any;
181
+ /**
182
+ * Prepare a signed group member-add change, ready to send to the X API.
156
183
  *
157
- * Returns `{ conversationKey, conversationKeyVersion, participantKeys }`.
184
+ * Takes a single params object with camelCase keys: `senderId`,
185
+ * `signingKeyVersion`, `publicKeys` (for the updated roster),
186
+ * `conversationId`, `newMemberIds`, `currentMemberIds`,
187
+ * `currentAdminIds`, `currentPendingMemberIds`, plus optional
188
+ * `currentTitle`, `currentAvatarUrl`, `currentTtlMsec`, and
189
+ * `currentScreenCaptureBlockingEnabled`. Returns the same shape as
190
+ * [`Chat::prepare_conversation_key_change`].
158
191
  */
159
- prepareConversationKeys(public_keys: any): any;
192
+ prepareGroupMembersChange(params: any): any;
160
193
  /**
161
194
  * Set the public key version for the loaded identity key.
162
195
  *
@@ -166,8 +199,9 @@ export class Chat {
166
199
  */
167
200
  setKeyVersion(version: string): void;
168
201
  /**
169
- * When enabled, `decryptEvent` throws if signature verification fails
170
- * instead of returning events with `verified: false`.
202
+ * When enabled — the default — `decryptEvent` throws for any signed
203
+ * event whose signature cannot be verified (invalid, missing, or no
204
+ * matching signing key) instead of returning it with `verified: false`.
171
205
  */
172
206
  setRejectUnverified(reject: boolean): void;
173
207
  /**
@@ -175,13 +209,13 @@ export class Chat {
175
209
  */
176
210
  sign(data: Uint8Array): Uint8Array;
177
211
  /**
178
- * Build and sign a GroupMemberAdd action signature.
212
+ * Create an incremental stream decryptor for large payloads.
179
213
  */
180
- signAddMembers(public_key_version: string, message_id: string, sender_id: string, conversation_id: string, new_member_ids: string[], current_member_ids: string[], current_admin_ids: string[], current_pending_member_ids: string[], conversation_key_version: string, current_title?: string | null, current_avatar_url?: string | null, current_ttl_msec?: number | null): any;
214
+ streamDecryptor(conversation_key: Uint8Array): StreamDecryptor;
181
215
  /**
182
- * Build and sign a ConversationKeyChange action signature.
216
+ * Create an incremental stream encryptor for large payloads.
183
217
  */
184
- signKeyChange(public_key_version: string, message_id: string, sender_id: string, conversation_id: string, conversation_key_version: string, conversation_key: Uint8Array): any;
218
+ streamEncryptor(conversation_key: Uint8Array): StreamEncryptor;
185
219
  /**
186
220
  * Verify a signature.
187
221
  */
@@ -195,6 +229,46 @@ export class Chat {
195
229
  verifyKeyBinding(identity_public_key_b64: string, signing_public_key_b64: string, identity_public_key_signature_b64: string): boolean;
196
230
  }
197
231
 
232
+ /**
233
+ * Incremental stream decryptor for large payloads.
234
+ *
235
+ * Feed ciphertext with `push`; call `finish` once at end of input. `finish`
236
+ * throws if the stream ended before its final frame (truncation), so callers
237
+ * must not treat plaintext as complete until `finish` succeeds.
238
+ */
239
+ export class StreamDecryptor {
240
+ private constructor();
241
+ free(): void;
242
+ [Symbol.dispose](): void;
243
+ /**
244
+ * Decrypt the final frame and consume the decryptor.
245
+ */
246
+ finish(): Uint8Array;
247
+ /**
248
+ * Decrypt a ciphertext chunk, returning plaintext available so far.
249
+ */
250
+ push(ciphertext: Uint8Array): Uint8Array;
251
+ }
252
+
253
+ /**
254
+ * Incremental stream encryptor for large payloads.
255
+ *
256
+ * Feed plaintext with `push`; call `finish` once to emit the final frame.
257
+ */
258
+ export class StreamEncryptor {
259
+ private constructor();
260
+ free(): void;
261
+ [Symbol.dispose](): void;
262
+ /**
263
+ * Emit the final frame and consume the encryptor.
264
+ */
265
+ finish(): Uint8Array;
266
+ /**
267
+ * Encrypt a plaintext chunk, returning ciphertext available so far.
268
+ */
269
+ push(plaintext: Uint8Array): Uint8Array;
270
+ }
271
+
198
272
  /**
199
273
  * Decode base64 string to bytes.
200
274
  *
@@ -244,6 +318,8 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
244
318
  export interface InitOutput {
245
319
  readonly memory: WebAssembly.Memory;
246
320
  readonly __wbg_chat_free: (a: number, b: number) => void;
321
+ readonly __wbg_streamdecryptor_free: (a: number, b: number) => void;
322
+ readonly __wbg_streamencryptor_free: (a: number, b: number) => void;
247
323
  readonly base64ToBytes: (a: number, b: number) => [number, number];
248
324
  readonly bytesToBase64: (a: number, b: number) => [number, number];
249
325
  readonly bytesToHex: (a: number, b: number) => [number, number];
@@ -253,15 +329,13 @@ export interface InitOutput {
253
329
  readonly chat_decryptEvents: (a: number, b: number, c: number, d: any) => [number, number, number];
254
330
  readonly chat_decryptStream: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
255
331
  readonly chat_encrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
256
- readonly chat_encryptAddReaction: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number) => [number, number, number];
257
- readonly chat_encryptConversationKeyForRecipients: (a: number, b: number, c: number, d: any) => [number, number, number];
258
- readonly chat_encryptMessage: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number) => [number, number, number];
259
- readonly chat_encryptRemoveReaction: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number) => [number, number, number];
260
- readonly chat_encryptReply: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number, w: number, x: number, y: number, z: number, a1: number, b1: number) => [number, number, number];
332
+ readonly chat_encryptAddReaction: (a: number, b: any) => [number, number, number];
333
+ readonly chat_encryptMessage: (a: number, b: any) => [number, number, number];
334
+ readonly chat_encryptRemoveReaction: (a: number, b: any) => [number, number, number];
335
+ readonly chat_encryptReply: (a: number, b: any) => [number, number, number];
261
336
  readonly chat_encryptStream: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
262
337
  readonly chat_exportKeys: (a: number) => [number, number, number, number];
263
338
  readonly chat_extractConversationKeys: (a: number, b: number, c: number) => [number, number, number];
264
- readonly chat_generateConversationKey: (a: number) => [number, number, number, number];
265
339
  readonly chat_generateKeypairs: (a: number) => [number, number, number];
266
340
  readonly chat_getPublicKeyFingerprint: (a: number) => [number, number, number, number];
267
341
  readonly chat_getPublicKeys: (a: number) => [number, number, number];
@@ -270,17 +344,23 @@ export interface InitOutput {
270
344
  readonly chat_isUnlocked: (a: number) => number;
271
345
  readonly chat_lock: (a: number) => void;
272
346
  readonly chat_new: () => number;
273
- readonly chat_prepareConversationKeys: (a: number, b: any) => [number, number, number];
347
+ readonly chat_prepareConversationKeyChange: (a: number, b: any) => [number, number, number];
348
+ readonly chat_prepareGroupCreate: (a: number, b: any) => [number, number, number];
349
+ readonly chat_prepareGroupMembersChange: (a: number, b: any) => [number, number, number];
274
350
  readonly chat_setKeyVersion: (a: number, b: number, c: number) => void;
275
351
  readonly chat_setRejectUnverified: (a: number, b: number) => void;
276
352
  readonly chat_sign: (a: number, b: number, c: number) => [number, number, number, number];
277
- readonly chat_signAddMembers: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number, r: number, s: number, t: number, u: number, v: number, w: number, x: number, y: number) => [number, number, number];
278
- readonly chat_signKeyChange: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => [number, number, number];
353
+ readonly chat_streamDecryptor: (a: number, b: number, c: number) => [number, number, number];
354
+ readonly chat_streamEncryptor: (a: number, b: number, c: number) => [number, number, number];
279
355
  readonly chat_verify: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
280
356
  readonly chat_verifyKeyBinding: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
281
357
  readonly detectImageDimensions: (a: number, b: number) => any;
282
358
  readonly detectMimeType: (a: number, b: number) => [number, number];
283
359
  readonly hexToBytes: (a: number, b: number) => [number, number];
360
+ readonly streamdecryptor_finish: (a: number) => [number, number, number, number];
361
+ readonly streamdecryptor_push: (a: number, b: number, c: number) => [number, number, number, number];
362
+ readonly streamencryptor_finish: (a: number) => [number, number, number, number];
363
+ readonly streamencryptor_push: (a: number, b: number, c: number) => [number, number, number, number];
284
364
  readonly init: () => void;
285
365
  readonly __wbindgen_malloc: (a: number, b: number) => number;
286
366
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;