@xdevplatform/chat-xdk 0.1.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.
@@ -0,0 +1,1437 @@
1
+ /* @ts-self-types="./chat_xdk_wasm.d.ts" */
2
+
3
+ /**
4
+ * The X Chat encryption SDK for JavaScript (crypto-only WASM layer).
5
+ *
6
+ * Provides all cryptographic operations: key generation, encrypt/decrypt,
7
+ * sign/verify. Juicebox key-storage lifecycle (setup/unlock/delete/changePin)
8
+ * is handled by the JS wrapper in `index.js`, which calls `exportKeys()` /
9
+ * `importKeys()` to shuttle raw key bytes across the boundary.
10
+ */
11
+ export class Chat {
12
+ __destroy_into_raw() {
13
+ const ptr = this.__wbg_ptr;
14
+ this.__wbg_ptr = 0;
15
+ ChatFinalization.unregister(this);
16
+ return ptr;
17
+ }
18
+ free() {
19
+ const ptr = this.__destroy_into_raw();
20
+ wasm.__wbg_chat_free(ptr, 0);
21
+ }
22
+ /**
23
+ * Decrypt a base64-encoded ciphertext and return the UTF-8 plaintext.
24
+ *
25
+ * Use for metadata fields like group names returned by the API.
26
+ * @param {string} ciphertext_b64
27
+ * @param {Uint8Array} conversation_key
28
+ * @returns {string}
29
+ */
30
+ decrypt(ciphertext_b64, conversation_key) {
31
+ let deferred4_0;
32
+ let deferred4_1;
33
+ try {
34
+ const ptr0 = passStringToWasm0(ciphertext_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35
+ const len0 = WASM_VECTOR_LEN;
36
+ const ptr1 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
37
+ const len1 = WASM_VECTOR_LEN;
38
+ const ret = wasm.chat_decrypt(this.__wbg_ptr, ptr0, len0, ptr1, len1);
39
+ var ptr3 = ret[0];
40
+ var len3 = ret[1];
41
+ if (ret[3]) {
42
+ ptr3 = 0; len3 = 0;
43
+ throw takeFromExternrefTable0(ret[2]);
44
+ }
45
+ deferred4_0 = ptr3;
46
+ deferred4_1 = len3;
47
+ return getStringFromWasm0(ptr3, len3);
48
+ } finally {
49
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
50
+ }
51
+ }
52
+ /**
53
+ * Decrypt an encrypted conversation key (ECIES).
54
+ * @param {string} encrypted_key_b64
55
+ * @returns {Uint8Array}
56
+ */
57
+ decryptConversationKey(encrypted_key_b64) {
58
+ const ptr0 = passStringToWasm0(encrypted_key_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
59
+ const len0 = WASM_VECTOR_LEN;
60
+ const ret = wasm.chat_decryptConversationKey(this.__wbg_ptr, ptr0, len0);
61
+ if (ret[3]) {
62
+ throw takeFromExternrefTable0(ret[2]);
63
+ }
64
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
65
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
66
+ return v2;
67
+ }
68
+ /**
69
+ * Decrypt a raw webhook event payload.
70
+ *
71
+ * `conversationKeys` is the object returned by `extractConversationKeys`.
72
+ * `signingKeys` is an array of `{ userId, publicKeyVersion, publicKey,
73
+ * identityPublicKey, identityPublicKeySignature }` objects for the sender;
74
+ * the SDK picks the matching version automatically.
75
+ * Pass an empty array to skip signature verification.
76
+ * @param {string} event_b64
77
+ * @param {any} conversation_keys
78
+ * @param {any} signing_keys
79
+ * @returns {any}
80
+ */
81
+ decryptEvent(event_b64, conversation_keys, signing_keys) {
82
+ const ptr0 = passStringToWasm0(event_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
83
+ const len0 = WASM_VECTOR_LEN;
84
+ const ret = wasm.chat_decryptEvent(this.__wbg_ptr, ptr0, len0, conversation_keys, signing_keys);
85
+ if (ret[2]) {
86
+ throw takeFromExternrefTable0(ret[1]);
87
+ }
88
+ return takeFromExternrefTable0(ret[0]);
89
+ }
90
+ /**
91
+ * Decrypt multiple events in batch.
92
+ *
93
+ * This is the recommended API for decrypting messages. It:
94
+ * 1. Extracts conversation keys from any KeyChange events
95
+ * 2. For each message, finds the correct signing key by matching userId + version
96
+ * 3. Decrypts the message using the appropriate conversation key
97
+ *
98
+ * `signingKeys` is an array of `{ userId, publicKeyVersion, publicKey,
99
+ * identityPublicKey, identityPublicKeySignature }` objects for ALL
100
+ * participants in the conversation (pass the X API response through).
101
+ *
102
+ * Returns `{ messages, conversationKeys, errors }`.
103
+ * @param {string[]} events
104
+ * @param {any} signing_keys
105
+ * @returns {any}
106
+ */
107
+ decryptEvents(events, signing_keys) {
108
+ const ptr0 = passArrayJsValueToWasm0(events, wasm.__wbindgen_malloc);
109
+ const len0 = WASM_VECTOR_LEN;
110
+ const ret = wasm.chat_decryptEvents(this.__wbg_ptr, ptr0, len0, signing_keys);
111
+ if (ret[2]) {
112
+ throw takeFromExternrefTable0(ret[1]);
113
+ }
114
+ return takeFromExternrefTable0(ret[0]);
115
+ }
116
+ /**
117
+ * Decrypt a streaming-encrypted payload (e.g. media).
118
+ * @param {Uint8Array} encrypted
119
+ * @param {Uint8Array} conversation_key
120
+ * @returns {Uint8Array}
121
+ */
122
+ decryptStream(encrypted, conversation_key) {
123
+ const ptr0 = passArray8ToWasm0(encrypted, wasm.__wbindgen_malloc);
124
+ const len0 = WASM_VECTOR_LEN;
125
+ const ptr1 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
126
+ const len1 = WASM_VECTOR_LEN;
127
+ const ret = wasm.chat_decryptStream(this.__wbg_ptr, ptr0, len0, ptr1, len1);
128
+ if (ret[3]) {
129
+ throw takeFromExternrefTable0(ret[2]);
130
+ }
131
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
132
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
133
+ return v3;
134
+ }
135
+ /**
136
+ * Encrypt a UTF-8 string and return base64 ciphertext.
137
+ *
138
+ * Use for metadata fields like group names before sending to the API.
139
+ * @param {string} plaintext
140
+ * @param {Uint8Array} conversation_key
141
+ * @returns {string}
142
+ */
143
+ encrypt(plaintext, conversation_key) {
144
+ let deferred4_0;
145
+ let deferred4_1;
146
+ try {
147
+ const ptr0 = passStringToWasm0(plaintext, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
148
+ const len0 = WASM_VECTOR_LEN;
149
+ const ptr1 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
150
+ const len1 = WASM_VECTOR_LEN;
151
+ const ret = wasm.chat_encrypt(this.__wbg_ptr, ptr0, len0, ptr1, len1);
152
+ var ptr3 = ret[0];
153
+ var len3 = ret[1];
154
+ if (ret[3]) {
155
+ ptr3 = 0; len3 = 0;
156
+ throw takeFromExternrefTable0(ret[2]);
157
+ }
158
+ deferred4_0 = ptr3;
159
+ deferred4_1 = len3;
160
+ return getStringFromWasm0(ptr3, len3);
161
+ } finally {
162
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
163
+ }
164
+ }
165
+ /**
166
+ * Encrypt a reaction-add.
167
+ * @param {string} message_id
168
+ * @param {string} sender_id
169
+ * @param {string} conversation_id
170
+ * @param {Uint8Array} conversation_key
171
+ * @param {string} target_message_sequence_id
172
+ * @param {string} emoji
173
+ * @param {string} conversation_key_version
174
+ * @param {string} signing_key_version
175
+ * @returns {any}
176
+ */
177
+ encryptAddReaction(message_id, sender_id, conversation_id, conversation_key, target_message_sequence_id, emoji, conversation_key_version, signing_key_version) {
178
+ const ptr0 = passStringToWasm0(message_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
179
+ const len0 = WASM_VECTOR_LEN;
180
+ const ptr1 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
181
+ const len1 = WASM_VECTOR_LEN;
182
+ const ptr2 = passStringToWasm0(conversation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
183
+ const len2 = WASM_VECTOR_LEN;
184
+ const ptr3 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
185
+ const len3 = WASM_VECTOR_LEN;
186
+ const ptr4 = passStringToWasm0(target_message_sequence_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
187
+ const len4 = WASM_VECTOR_LEN;
188
+ const ptr5 = passStringToWasm0(emoji, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
189
+ const len5 = WASM_VECTOR_LEN;
190
+ const ptr6 = passStringToWasm0(conversation_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
191
+ const len6 = WASM_VECTOR_LEN;
192
+ const ptr7 = passStringToWasm0(signing_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
193
+ const len7 = WASM_VECTOR_LEN;
194
+ const ret = wasm.chat_encryptAddReaction(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7);
195
+ if (ret[2]) {
196
+ throw takeFromExternrefTable0(ret[1]);
197
+ }
198
+ return takeFromExternrefTable0(ret[0]);
199
+ }
200
+ /**
201
+ * Encrypt a conversation key for one or more recipients.
202
+ *
203
+ * Each entry is `{ userId, publicKey, keyVersion }`.
204
+ * @param {Uint8Array} conversation_key
205
+ * @param {any} recipients
206
+ * @returns {any}
207
+ */
208
+ encryptConversationKeyForRecipients(conversation_key, recipients) {
209
+ const ptr0 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
210
+ const len0 = WASM_VECTOR_LEN;
211
+ const ret = wasm.chat_encryptConversationKeyForRecipients(this.__wbg_ptr, ptr0, len0, recipients);
212
+ if (ret[2]) {
213
+ throw takeFromExternrefTable0(ret[1]);
214
+ }
215
+ return takeFromExternrefTable0(ret[0]);
216
+ }
217
+ /**
218
+ * Encrypt a text message for the X API.
219
+ *
220
+ * `entities` accepts a JS array of `[start, end, "type"]` tuples, e.g.
221
+ * `[[0, 23, "url"], [25, 30, "mention"]]`.
222
+ *
223
+ * `attachments` accepts a JS array of attachment objects, e.g.
224
+ * `[{ attachment_type: "media", media_hash_key: "...", width: 1024, ... }]`.
225
+ * @param {string} message_id
226
+ * @param {string} sender_id
227
+ * @param {string} conversation_id
228
+ * @param {Uint8Array} conversation_key
229
+ * @param {string} text
230
+ * @param {string} conversation_key_version
231
+ * @param {string} signing_key_version
232
+ * @param {any | null} [entities]
233
+ * @param {any | null} [attachments]
234
+ * @param {boolean | null} [should_notify]
235
+ * @param {number | null} [ttl_msec]
236
+ * @returns {any}
237
+ */
238
+ encryptMessage(message_id, sender_id, conversation_id, conversation_key, text, conversation_key_version, signing_key_version, entities, attachments, should_notify, ttl_msec) {
239
+ const ptr0 = passStringToWasm0(message_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
+ const len0 = WASM_VECTOR_LEN;
241
+ const ptr1 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
242
+ const len1 = WASM_VECTOR_LEN;
243
+ const ptr2 = passStringToWasm0(conversation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
244
+ const len2 = WASM_VECTOR_LEN;
245
+ const ptr3 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
246
+ const len3 = WASM_VECTOR_LEN;
247
+ const ptr4 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
248
+ const len4 = WASM_VECTOR_LEN;
249
+ const ptr5 = passStringToWasm0(conversation_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
250
+ const len5 = WASM_VECTOR_LEN;
251
+ const ptr6 = passStringToWasm0(signing_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
252
+ const len6 = WASM_VECTOR_LEN;
253
+ const ret = wasm.chat_encryptMessage(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, isLikeNone(entities) ? 0 : addToExternrefTable0(entities), isLikeNone(attachments) ? 0 : addToExternrefTable0(attachments), isLikeNone(should_notify) ? 0xFFFFFF : should_notify ? 1 : 0, !isLikeNone(ttl_msec), isLikeNone(ttl_msec) ? 0 : ttl_msec);
254
+ if (ret[2]) {
255
+ throw takeFromExternrefTable0(ret[1]);
256
+ }
257
+ return takeFromExternrefTable0(ret[0]);
258
+ }
259
+ /**
260
+ * Encrypt a reaction-remove.
261
+ * @param {string} message_id
262
+ * @param {string} sender_id
263
+ * @param {string} conversation_id
264
+ * @param {Uint8Array} conversation_key
265
+ * @param {string} target_message_sequence_id
266
+ * @param {string} emoji
267
+ * @param {string} conversation_key_version
268
+ * @param {string} signing_key_version
269
+ * @returns {any}
270
+ */
271
+ encryptRemoveReaction(message_id, sender_id, conversation_id, conversation_key, target_message_sequence_id, emoji, conversation_key_version, signing_key_version) {
272
+ const ptr0 = passStringToWasm0(message_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
273
+ const len0 = WASM_VECTOR_LEN;
274
+ const ptr1 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
275
+ const len1 = WASM_VECTOR_LEN;
276
+ const ptr2 = passStringToWasm0(conversation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
277
+ const len2 = WASM_VECTOR_LEN;
278
+ const ptr3 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
279
+ const len3 = WASM_VECTOR_LEN;
280
+ const ptr4 = passStringToWasm0(target_message_sequence_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
281
+ const len4 = WASM_VECTOR_LEN;
282
+ const ptr5 = passStringToWasm0(emoji, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
283
+ const len5 = WASM_VECTOR_LEN;
284
+ const ptr6 = passStringToWasm0(conversation_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
285
+ const len6 = WASM_VECTOR_LEN;
286
+ const ptr7 = passStringToWasm0(signing_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
287
+ const len7 = WASM_VECTOR_LEN;
288
+ const ret = wasm.chat_encryptRemoveReaction(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7);
289
+ if (ret[2]) {
290
+ throw takeFromExternrefTable0(ret[1]);
291
+ }
292
+ return takeFromExternrefTable0(ret[0]);
293
+ }
294
+ /**
295
+ * Encrypt a reply message for the X API.
296
+ * @param {string} message_id
297
+ * @param {string} sender_id
298
+ * @param {string} conversation_id
299
+ * @param {Uint8Array} conversation_key
300
+ * @param {string} text
301
+ * @param {string} conversation_key_version
302
+ * @param {string} signing_key_version
303
+ * @param {string} reply_to_sequence_id
304
+ * @param {number | null} [reply_to_sender_id]
305
+ * @param {string | null} [reply_to_text]
306
+ * @param {any | null} [entities]
307
+ * @param {any | null} [attachments]
308
+ * @param {any | null} [reply_to_entities]
309
+ * @param {any | null} [reply_to_attachments]
310
+ * @param {boolean | null} [should_notify]
311
+ * @param {number | null} [ttl_msec]
312
+ * @returns {any}
313
+ */
314
+ encryptReply(message_id, sender_id, conversation_id, conversation_key, text, conversation_key_version, signing_key_version, reply_to_sequence_id, reply_to_sender_id, reply_to_text, entities, attachments, reply_to_entities, reply_to_attachments, should_notify, ttl_msec) {
315
+ const ptr0 = passStringToWasm0(message_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
316
+ const len0 = WASM_VECTOR_LEN;
317
+ const ptr1 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
318
+ const len1 = WASM_VECTOR_LEN;
319
+ const ptr2 = passStringToWasm0(conversation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
320
+ const len2 = WASM_VECTOR_LEN;
321
+ const ptr3 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
322
+ const len3 = WASM_VECTOR_LEN;
323
+ const ptr4 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
324
+ const len4 = WASM_VECTOR_LEN;
325
+ const ptr5 = passStringToWasm0(conversation_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
326
+ const len5 = WASM_VECTOR_LEN;
327
+ const ptr6 = passStringToWasm0(signing_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
328
+ const len6 = WASM_VECTOR_LEN;
329
+ const ptr7 = passStringToWasm0(reply_to_sequence_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
330
+ const len7 = WASM_VECTOR_LEN;
331
+ var ptr8 = isLikeNone(reply_to_text) ? 0 : passStringToWasm0(reply_to_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
332
+ var len8 = WASM_VECTOR_LEN;
333
+ const ret = wasm.chat_encryptReply(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7, !isLikeNone(reply_to_sender_id), isLikeNone(reply_to_sender_id) ? 0 : reply_to_sender_id, ptr8, len8, isLikeNone(entities) ? 0 : addToExternrefTable0(entities), isLikeNone(attachments) ? 0 : addToExternrefTable0(attachments), isLikeNone(reply_to_entities) ? 0 : addToExternrefTable0(reply_to_entities), isLikeNone(reply_to_attachments) ? 0 : addToExternrefTable0(reply_to_attachments), isLikeNone(should_notify) ? 0xFFFFFF : should_notify ? 1 : 0, !isLikeNone(ttl_msec), isLikeNone(ttl_msec) ? 0 : ttl_msec);
334
+ if (ret[2]) {
335
+ throw takeFromExternrefTable0(ret[1]);
336
+ }
337
+ return takeFromExternrefTable0(ret[0]);
338
+ }
339
+ /**
340
+ * Encrypt a stream (e.g. media).
341
+ * @param {Uint8Array} plaintext
342
+ * @param {Uint8Array} conversation_key
343
+ * @returns {Uint8Array}
344
+ */
345
+ encryptStream(plaintext, conversation_key) {
346
+ const ptr0 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
347
+ const len0 = WASM_VECTOR_LEN;
348
+ const ptr1 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
349
+ const len1 = WASM_VECTOR_LEN;
350
+ const ret = wasm.chat_encryptStream(this.__wbg_ptr, ptr0, len0, ptr1, len1);
351
+ if (ret[3]) {
352
+ throw takeFromExternrefTable0(ret[2]);
353
+ }
354
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
355
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
356
+ return v3;
357
+ }
358
+ /**
359
+ * Export private keys as raw bytes (`Uint8Array`).
360
+ * @returns {Uint8Array}
361
+ */
362
+ exportKeys() {
363
+ const ret = wasm.chat_exportKeys(this.__wbg_ptr);
364
+ if (ret[3]) {
365
+ throw takeFromExternrefTable0(ret[2]);
366
+ }
367
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
368
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
369
+ return v1;
370
+ }
371
+ /**
372
+ * Extract and decrypt conversation keys from raw KeyChange event strings.
373
+ *
374
+ * Returns a `ConversationKeyResult` with:
375
+ * - `keys`: Object mapping key version strings to `Uint8Array` conversation keys
376
+ * - `latestVersion`: The highest key version (use for encrypting new messages)
377
+ * @param {string[]} events
378
+ * @returns {any}
379
+ */
380
+ extractConversationKeys(events) {
381
+ const ptr0 = passArrayJsValueToWasm0(events, wasm.__wbindgen_malloc);
382
+ const len0 = WASM_VECTOR_LEN;
383
+ const ret = wasm.chat_extractConversationKeys(this.__wbg_ptr, ptr0, len0);
384
+ if (ret[2]) {
385
+ throw takeFromExternrefTable0(ret[1]);
386
+ }
387
+ return takeFromExternrefTable0(ret[0]);
388
+ }
389
+ /**
390
+ * Generate a new conversation key.
391
+ * @returns {Uint8Array}
392
+ */
393
+ generateConversationKey() {
394
+ const ret = wasm.chat_generateConversationKey(this.__wbg_ptr);
395
+ if (ret[3]) {
396
+ throw takeFromExternrefTable0(ret[2]);
397
+ }
398
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
399
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
400
+ return v1;
401
+ }
402
+ /**
403
+ * Generate new keypairs and return the registration payload.
404
+ *
405
+ * The key version is read from the JS clock (`Date.now()`) because the
406
+ * `wasm32-unknown-unknown` target has no system clock.
407
+ * @returns {any}
408
+ */
409
+ generateKeypairs() {
410
+ const ret = wasm.chat_generateKeypairs(this.__wbg_ptr);
411
+ if (ret[2]) {
412
+ throw takeFromExternrefTable0(ret[1]);
413
+ }
414
+ return takeFromExternrefTable0(ret[0]);
415
+ }
416
+ /**
417
+ * Get the fingerprint of the loaded identity public key.
418
+ *
419
+ * Returns a URL-safe base64 string that users can compare
420
+ * out-of-band (e.g. in person or over a trusted channel) to
421
+ * verify key authenticity.
422
+ * @returns {string}
423
+ */
424
+ getPublicKeyFingerprint() {
425
+ let deferred2_0;
426
+ let deferred2_1;
427
+ try {
428
+ const ret = wasm.chat_getPublicKeyFingerprint(this.__wbg_ptr);
429
+ var ptr1 = ret[0];
430
+ var len1 = ret[1];
431
+ if (ret[3]) {
432
+ ptr1 = 0; len1 = 0;
433
+ throw takeFromExternrefTable0(ret[2]);
434
+ }
435
+ deferred2_0 = ptr1;
436
+ deferred2_1 = len1;
437
+ return getStringFromWasm0(ptr1, len1);
438
+ } finally {
439
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
440
+ }
441
+ }
442
+ /**
443
+ * Get current public keys.
444
+ * @returns {any}
445
+ */
446
+ getPublicKeys() {
447
+ const ret = wasm.chat_getPublicKeys(this.__wbg_ptr);
448
+ if (ret[2]) {
449
+ throw takeFromExternrefTable0(ret[1]);
450
+ }
451
+ return takeFromExternrefTable0(ret[0]);
452
+ }
453
+ /**
454
+ * Returns `true` when the identity key is loaded (sufficient for decryption).
455
+ * @returns {boolean}
456
+ */
457
+ hasIdentityKey() {
458
+ const ret = wasm.chat_hasIdentityKey(this.__wbg_ptr);
459
+ return ret !== 0;
460
+ }
461
+ /**
462
+ * Import private keys from raw bytes (`Uint8Array`).
463
+ *
464
+ * The input bytes are zeroized after import.
465
+ * @param {Uint8Array} keys
466
+ */
467
+ importKeys(keys) {
468
+ const ptr0 = passArray8ToWasm0(keys, wasm.__wbindgen_malloc);
469
+ const len0 = WASM_VECTOR_LEN;
470
+ const ret = wasm.chat_importKeys(this.__wbg_ptr, ptr0, len0);
471
+ if (ret[1]) {
472
+ throw takeFromExternrefTable0(ret[0]);
473
+ }
474
+ }
475
+ /**
476
+ * Returns `true` when both identity and signing keys are loaded.
477
+ * @returns {boolean}
478
+ */
479
+ isUnlocked() {
480
+ const ret = wasm.chat_isUnlocked(this.__wbg_ptr);
481
+ return ret !== 0;
482
+ }
483
+ /**
484
+ * Clear keys from memory.
485
+ */
486
+ lock() {
487
+ wasm.chat_lock(this.__wbg_ptr);
488
+ }
489
+ /**
490
+ * Create a new Chat instance.
491
+ */
492
+ constructor() {
493
+ const ret = wasm.chat_new();
494
+ this.__wbg_ptr = ret >>> 0;
495
+ ChatFinalization.register(this, this.__wbg_ptr, this);
496
+ return this;
497
+ }
498
+ /**
499
+ * Prepare conversation keys for all participants in one call.
500
+ *
501
+ * This is the recommended method for both group creation and key
502
+ * initialization. Pass the flat array of public keys from the X API;
503
+ * the SDK groups by userId, picks the latest version per user,
504
+ * generates a fresh conversation key, and encrypts it for everyone.
505
+ *
506
+ * Returns `{ conversationKey, conversationKeyVersion, participantKeys }`.
507
+ * @param {any} public_keys
508
+ * @returns {any}
509
+ */
510
+ prepareConversationKeys(public_keys) {
511
+ const ret = wasm.chat_prepareConversationKeys(this.__wbg_ptr, public_keys);
512
+ if (ret[2]) {
513
+ throw takeFromExternrefTable0(ret[1]);
514
+ }
515
+ return takeFromExternrefTable0(ret[0]);
516
+ }
517
+ /**
518
+ * Set the public key version for the loaded identity key.
519
+ *
520
+ * Call after `importKeys` (or unlock) with the version string the
521
+ * X API reports for your registered public key, so KeyChange
522
+ * participant entries for other key versions are skipped.
523
+ * @param {string} version
524
+ */
525
+ setKeyVersion(version) {
526
+ const ptr0 = passStringToWasm0(version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
527
+ const len0 = WASM_VECTOR_LEN;
528
+ wasm.chat_setKeyVersion(this.__wbg_ptr, ptr0, len0);
529
+ }
530
+ /**
531
+ * When enabled, `decryptEvent` throws if signature verification fails
532
+ * instead of returning events with `verified: false`.
533
+ * @param {boolean} reject
534
+ */
535
+ setRejectUnverified(reject) {
536
+ wasm.chat_setRejectUnverified(this.__wbg_ptr, reject);
537
+ }
538
+ /**
539
+ * Sign data. Returns raw signature bytes (`Uint8Array`).
540
+ * @param {Uint8Array} data
541
+ * @returns {Uint8Array}
542
+ */
543
+ sign(data) {
544
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
545
+ const len0 = WASM_VECTOR_LEN;
546
+ const ret = wasm.chat_sign(this.__wbg_ptr, ptr0, len0);
547
+ if (ret[3]) {
548
+ throw takeFromExternrefTable0(ret[2]);
549
+ }
550
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
551
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
552
+ return v2;
553
+ }
554
+ /**
555
+ * Build and sign a GroupMemberAdd action signature.
556
+ * @param {string} public_key_version
557
+ * @param {string} message_id
558
+ * @param {string} sender_id
559
+ * @param {string} conversation_id
560
+ * @param {string[]} new_member_ids
561
+ * @param {string[]} current_member_ids
562
+ * @param {string[]} current_admin_ids
563
+ * @param {string[]} current_pending_member_ids
564
+ * @param {string} conversation_key_version
565
+ * @param {string | null} [current_title]
566
+ * @param {string | null} [current_avatar_url]
567
+ * @param {number | null} [current_ttl_msec]
568
+ * @returns {any}
569
+ */
570
+ signAddMembers(public_key_version, message_id, sender_id, conversation_id, new_member_ids, current_member_ids, current_admin_ids, current_pending_member_ids, conversation_key_version, current_title, current_avatar_url, current_ttl_msec) {
571
+ const ptr0 = passStringToWasm0(public_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
572
+ const len0 = WASM_VECTOR_LEN;
573
+ const ptr1 = passStringToWasm0(message_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
574
+ const len1 = WASM_VECTOR_LEN;
575
+ const ptr2 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
576
+ const len2 = WASM_VECTOR_LEN;
577
+ const ptr3 = passStringToWasm0(conversation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
578
+ const len3 = WASM_VECTOR_LEN;
579
+ const ptr4 = passArrayJsValueToWasm0(new_member_ids, wasm.__wbindgen_malloc);
580
+ const len4 = WASM_VECTOR_LEN;
581
+ const ptr5 = passArrayJsValueToWasm0(current_member_ids, wasm.__wbindgen_malloc);
582
+ const len5 = WASM_VECTOR_LEN;
583
+ const ptr6 = passArrayJsValueToWasm0(current_admin_ids, wasm.__wbindgen_malloc);
584
+ const len6 = WASM_VECTOR_LEN;
585
+ const ptr7 = passArrayJsValueToWasm0(current_pending_member_ids, wasm.__wbindgen_malloc);
586
+ const len7 = WASM_VECTOR_LEN;
587
+ const ptr8 = passStringToWasm0(conversation_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
588
+ const len8 = WASM_VECTOR_LEN;
589
+ var ptr9 = isLikeNone(current_title) ? 0 : passStringToWasm0(current_title, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
590
+ var len9 = WASM_VECTOR_LEN;
591
+ var ptr10 = isLikeNone(current_avatar_url) ? 0 : passStringToWasm0(current_avatar_url, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
592
+ var len10 = WASM_VECTOR_LEN;
593
+ const ret = wasm.chat_signAddMembers(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7, ptr8, len8, ptr9, len9, ptr10, len10, !isLikeNone(current_ttl_msec), isLikeNone(current_ttl_msec) ? 0 : current_ttl_msec);
594
+ if (ret[2]) {
595
+ throw takeFromExternrefTable0(ret[1]);
596
+ }
597
+ return takeFromExternrefTable0(ret[0]);
598
+ }
599
+ /**
600
+ * Build and sign a ConversationKeyChange action signature.
601
+ * @param {string} public_key_version
602
+ * @param {string} message_id
603
+ * @param {string} sender_id
604
+ * @param {string} conversation_id
605
+ * @param {string} conversation_key_version
606
+ * @param {Uint8Array} conversation_key
607
+ * @returns {any}
608
+ */
609
+ signKeyChange(public_key_version, message_id, sender_id, conversation_id, conversation_key_version, conversation_key) {
610
+ const ptr0 = passStringToWasm0(public_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
611
+ const len0 = WASM_VECTOR_LEN;
612
+ const ptr1 = passStringToWasm0(message_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
613
+ const len1 = WASM_VECTOR_LEN;
614
+ const ptr2 = passStringToWasm0(sender_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
615
+ const len2 = WASM_VECTOR_LEN;
616
+ const ptr3 = passStringToWasm0(conversation_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
617
+ const len3 = WASM_VECTOR_LEN;
618
+ const ptr4 = passStringToWasm0(conversation_key_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
619
+ const len4 = WASM_VECTOR_LEN;
620
+ const ptr5 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
621
+ const len5 = WASM_VECTOR_LEN;
622
+ const ret = wasm.chat_signKeyChange(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
623
+ if (ret[2]) {
624
+ throw takeFromExternrefTable0(ret[1]);
625
+ }
626
+ return takeFromExternrefTable0(ret[0]);
627
+ }
628
+ /**
629
+ * Verify a signature.
630
+ * @param {string} public_key_b64
631
+ * @param {Uint8Array} signature
632
+ * @param {Uint8Array} data
633
+ * @returns {boolean}
634
+ */
635
+ verify(public_key_b64, signature, data) {
636
+ const ptr0 = passStringToWasm0(public_key_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
637
+ const len0 = WASM_VECTOR_LEN;
638
+ const ptr1 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc);
639
+ const len1 = WASM_VECTOR_LEN;
640
+ const ptr2 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
641
+ const len2 = WASM_VECTOR_LEN;
642
+ const ret = wasm.chat_verify(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
643
+ if (ret[2]) {
644
+ throw takeFromExternrefTable0(ret[1]);
645
+ }
646
+ return ret[0] !== 0;
647
+ }
648
+ /**
649
+ * Verify that a signing key is authentically bound to an identity key.
650
+ *
651
+ * Call this when you receive another user's public keys from the X API
652
+ * to detect server-side key substitution. All inputs are base64.
653
+ * @param {string} identity_public_key_b64
654
+ * @param {string} signing_public_key_b64
655
+ * @param {string} identity_public_key_signature_b64
656
+ * @returns {boolean}
657
+ */
658
+ verifyKeyBinding(identity_public_key_b64, signing_public_key_b64, identity_public_key_signature_b64) {
659
+ const ptr0 = passStringToWasm0(identity_public_key_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
660
+ const len0 = WASM_VECTOR_LEN;
661
+ const ptr1 = passStringToWasm0(signing_public_key_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
662
+ const len1 = WASM_VECTOR_LEN;
663
+ const ptr2 = passStringToWasm0(identity_public_key_signature_b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
664
+ const len2 = WASM_VECTOR_LEN;
665
+ const ret = wasm.chat_verifyKeyBinding(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
666
+ if (ret[2]) {
667
+ throw takeFromExternrefTable0(ret[1]);
668
+ }
669
+ return ret[0] !== 0;
670
+ }
671
+ }
672
+ if (Symbol.dispose) Chat.prototype[Symbol.dispose] = Chat.prototype.free;
673
+
674
+ /**
675
+ * Decode base64 string to bytes.
676
+ *
677
+ * Returns null if the input is not valid base64.
678
+ * @param {string} b64
679
+ * @returns {Uint8Array | undefined}
680
+ */
681
+ export function base64ToBytes(b64) {
682
+ const ptr0 = passStringToWasm0(b64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
683
+ const len0 = WASM_VECTOR_LEN;
684
+ const ret = wasm.base64ToBytes(ptr0, len0);
685
+ let v2;
686
+ if (ret[0] !== 0) {
687
+ v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
688
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
689
+ }
690
+ return v2;
691
+ }
692
+
693
+ /**
694
+ * Encode bytes to base64 string.
695
+ * @param {Uint8Array} bytes
696
+ * @returns {string}
697
+ */
698
+ export function bytesToBase64(bytes) {
699
+ let deferred2_0;
700
+ let deferred2_1;
701
+ try {
702
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
703
+ const len0 = WASM_VECTOR_LEN;
704
+ const ret = wasm.bytesToBase64(ptr0, len0);
705
+ deferred2_0 = ret[0];
706
+ deferred2_1 = ret[1];
707
+ return getStringFromWasm0(ret[0], ret[1]);
708
+ } finally {
709
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
710
+ }
711
+ }
712
+
713
+ /**
714
+ * Encode bytes to lowercase hex string.
715
+ * @param {Uint8Array} bytes
716
+ * @returns {string}
717
+ */
718
+ export function bytesToHex(bytes) {
719
+ let deferred2_0;
720
+ let deferred2_1;
721
+ try {
722
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
723
+ const len0 = WASM_VECTOR_LEN;
724
+ const ret = wasm.bytesToHex(ptr0, len0);
725
+ deferred2_0 = ret[0];
726
+ deferred2_1 = ret[1];
727
+ return getStringFromWasm0(ret[0], ret[1]);
728
+ } finally {
729
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
730
+ }
731
+ }
732
+
733
+ /**
734
+ * Detect image dimensions from file bytes.
735
+ *
736
+ * Supports PNG, JPEG, GIF, WebP, and BMP.
737
+ * Returns `{ width, height }` or null.
738
+ * @param {Uint8Array} bytes
739
+ * @returns {any}
740
+ */
741
+ export function detectImageDimensions(bytes) {
742
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
743
+ const len0 = WASM_VECTOR_LEN;
744
+ const ret = wasm.detectImageDimensions(ptr0, len0);
745
+ return ret;
746
+ }
747
+
748
+ /**
749
+ * Detect MIME type from file bytes using magic numbers.
750
+ *
751
+ * Returns the MIME type string (e.g., "image/png", "video/mp4") or null.
752
+ * @param {Uint8Array} bytes
753
+ * @returns {string | undefined}
754
+ */
755
+ export function detectMimeType(bytes) {
756
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
757
+ const len0 = WASM_VECTOR_LEN;
758
+ const ret = wasm.detectMimeType(ptr0, len0);
759
+ let v2;
760
+ if (ret[0] !== 0) {
761
+ v2 = getStringFromWasm0(ret[0], ret[1]).slice();
762
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
763
+ }
764
+ return v2;
765
+ }
766
+
767
+ /**
768
+ * Decode hex string to bytes.
769
+ *
770
+ * Returns null if the input is not valid hex.
771
+ * @param {string} hex
772
+ * @returns {Uint8Array | undefined}
773
+ */
774
+ export function hexToBytes(hex) {
775
+ const ptr0 = passStringToWasm0(hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
776
+ const len0 = WASM_VECTOR_LEN;
777
+ const ret = wasm.hexToBytes(ptr0, len0);
778
+ let v2;
779
+ if (ret[0] !== 0) {
780
+ v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
781
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
782
+ }
783
+ return v2;
784
+ }
785
+
786
+ /**
787
+ * Initialize panic hook for better error messages in console.
788
+ */
789
+ export function init() {
790
+ wasm.init();
791
+ }
792
+
793
+ function __wbg_get_imports() {
794
+ const import0 = {
795
+ __proto__: null,
796
+ __wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
797
+ const ret = Error(getStringFromWasm0(arg0, arg1));
798
+ return ret;
799
+ },
800
+ __wbg_Number_a5a435bd7bbec835: function(arg0) {
801
+ const ret = Number(arg0);
802
+ return ret;
803
+ },
804
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
805
+ const ret = String(arg1);
806
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
807
+ const len1 = WASM_VECTOR_LEN;
808
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
809
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
810
+ },
811
+ __wbg___wbindgen_bigint_get_as_i64_447a76b5c6ef7bda: function(arg0, arg1) {
812
+ const v = arg1;
813
+ const ret = typeof(v) === 'bigint' ? v : undefined;
814
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
815
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
816
+ },
817
+ __wbg___wbindgen_boolean_get_c0f3f60bac5a78d1: function(arg0) {
818
+ const v = arg0;
819
+ const ret = typeof(v) === 'boolean' ? v : undefined;
820
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
821
+ },
822
+ __wbg___wbindgen_debug_string_5398f5bb970e0daa: function(arg0, arg1) {
823
+ const ret = debugString(arg1);
824
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
825
+ const len1 = WASM_VECTOR_LEN;
826
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
827
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
828
+ },
829
+ __wbg___wbindgen_in_41dbb8413020e076: function(arg0, arg1) {
830
+ const ret = arg0 in arg1;
831
+ return ret;
832
+ },
833
+ __wbg___wbindgen_is_bigint_e2141d4f045b7eda: function(arg0) {
834
+ const ret = typeof(arg0) === 'bigint';
835
+ return ret;
836
+ },
837
+ __wbg___wbindgen_is_function_3c846841762788c1: function(arg0) {
838
+ const ret = typeof(arg0) === 'function';
839
+ return ret;
840
+ },
841
+ __wbg___wbindgen_is_null_0b605fc6b167c56f: function(arg0) {
842
+ const ret = arg0 === null;
843
+ return ret;
844
+ },
845
+ __wbg___wbindgen_is_object_781bc9f159099513: function(arg0) {
846
+ const val = arg0;
847
+ const ret = typeof(val) === 'object' && val !== null;
848
+ return ret;
849
+ },
850
+ __wbg___wbindgen_is_string_7ef6b97b02428fae: function(arg0) {
851
+ const ret = typeof(arg0) === 'string';
852
+ return ret;
853
+ },
854
+ __wbg___wbindgen_is_undefined_52709e72fb9f179c: function(arg0) {
855
+ const ret = arg0 === undefined;
856
+ return ret;
857
+ },
858
+ __wbg___wbindgen_jsval_eq_ee31bfad3e536463: function(arg0, arg1) {
859
+ const ret = arg0 === arg1;
860
+ return ret;
861
+ },
862
+ __wbg___wbindgen_jsval_loose_eq_5bcc3bed3c69e72b: function(arg0, arg1) {
863
+ const ret = arg0 == arg1;
864
+ return ret;
865
+ },
866
+ __wbg___wbindgen_number_get_34bb9d9dcfa21373: function(arg0, arg1) {
867
+ const obj = arg1;
868
+ const ret = typeof(obj) === 'number' ? obj : undefined;
869
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
870
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
871
+ },
872
+ __wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
873
+ const obj = arg1;
874
+ const ret = typeof(obj) === 'string' ? obj : undefined;
875
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
876
+ var len1 = WASM_VECTOR_LEN;
877
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
878
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
879
+ },
880
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
881
+ throw new Error(getStringFromWasm0(arg0, arg1));
882
+ },
883
+ __wbg_call_2d781c1f4d5c0ef8: function() { return handleError(function (arg0, arg1, arg2) {
884
+ const ret = arg0.call(arg1, arg2);
885
+ return ret;
886
+ }, arguments); },
887
+ __wbg_call_e133b57c9155d22c: function() { return handleError(function (arg0, arg1) {
888
+ const ret = arg0.call(arg1);
889
+ return ret;
890
+ }, arguments); },
891
+ __wbg_crypto_38df2bab126b63dc: function(arg0) {
892
+ const ret = arg0.crypto;
893
+ return ret;
894
+ },
895
+ __wbg_done_08ce71ee07e3bd17: function(arg0) {
896
+ const ret = arg0.done;
897
+ return ret;
898
+ },
899
+ __wbg_entries_e8a20ff8c9757101: function(arg0) {
900
+ const ret = Object.entries(arg0);
901
+ return ret;
902
+ },
903
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
904
+ let deferred0_0;
905
+ let deferred0_1;
906
+ try {
907
+ deferred0_0 = arg0;
908
+ deferred0_1 = arg1;
909
+ console.error(getStringFromWasm0(arg0, arg1));
910
+ } finally {
911
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
912
+ }
913
+ },
914
+ __wbg_from_4bdf88943703fd48: function(arg0) {
915
+ const ret = Array.from(arg0);
916
+ return ret;
917
+ },
918
+ __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
919
+ arg0.getRandomValues(arg1);
920
+ }, arguments); },
921
+ __wbg_get_326e41e095fb2575: function() { return handleError(function (arg0, arg1) {
922
+ const ret = Reflect.get(arg0, arg1);
923
+ return ret;
924
+ }, arguments); },
925
+ __wbg_get_a8ee5c45dabc1b3b: function(arg0, arg1) {
926
+ const ret = arg0[arg1 >>> 0];
927
+ return ret;
928
+ },
929
+ __wbg_get_unchecked_329cfe50afab7352: function(arg0, arg1) {
930
+ const ret = arg0[arg1 >>> 0];
931
+ return ret;
932
+ },
933
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
934
+ const ret = arg0[arg1];
935
+ return ret;
936
+ },
937
+ __wbg_instanceof_ArrayBuffer_101e2bf31071a9f6: function(arg0) {
938
+ let result;
939
+ try {
940
+ result = arg0 instanceof ArrayBuffer;
941
+ } catch (_) {
942
+ result = false;
943
+ }
944
+ const ret = result;
945
+ return ret;
946
+ },
947
+ __wbg_instanceof_Map_f194b366846aca0c: function(arg0) {
948
+ let result;
949
+ try {
950
+ result = arg0 instanceof Map;
951
+ } catch (_) {
952
+ result = false;
953
+ }
954
+ const ret = result;
955
+ return ret;
956
+ },
957
+ __wbg_instanceof_Uint8Array_740438561a5b956d: function(arg0) {
958
+ let result;
959
+ try {
960
+ result = arg0 instanceof Uint8Array;
961
+ } catch (_) {
962
+ result = false;
963
+ }
964
+ const ret = result;
965
+ return ret;
966
+ },
967
+ __wbg_isArray_33b91feb269ff46e: function(arg0) {
968
+ const ret = Array.isArray(arg0);
969
+ return ret;
970
+ },
971
+ __wbg_isSafeInteger_ecd6a7f9c3e053cd: function(arg0) {
972
+ const ret = Number.isSafeInteger(arg0);
973
+ return ret;
974
+ },
975
+ __wbg_iterator_d8f549ec8fb061b1: function() {
976
+ const ret = Symbol.iterator;
977
+ return ret;
978
+ },
979
+ __wbg_length_b3416cf66a5452c8: function(arg0) {
980
+ const ret = arg0.length;
981
+ return ret;
982
+ },
983
+ __wbg_length_ea16607d7b61445b: function(arg0) {
984
+ const ret = arg0.length;
985
+ return ret;
986
+ },
987
+ __wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
988
+ const ret = arg0.msCrypto;
989
+ return ret;
990
+ },
991
+ __wbg_new_227d7c05414eb861: function() {
992
+ const ret = new Error();
993
+ return ret;
994
+ },
995
+ __wbg_new_49d5571bd3f0c4d4: function() {
996
+ const ret = new Map();
997
+ return ret;
998
+ },
999
+ __wbg_new_5f486cdf45a04d78: function(arg0) {
1000
+ const ret = new Uint8Array(arg0);
1001
+ return ret;
1002
+ },
1003
+ __wbg_new_a70fbab9066b301f: function() {
1004
+ const ret = new Array();
1005
+ return ret;
1006
+ },
1007
+ __wbg_new_ab79df5bd7c26067: function() {
1008
+ const ret = new Object();
1009
+ return ret;
1010
+ },
1011
+ __wbg_new_from_slice_22da9388ac046e50: function(arg0, arg1) {
1012
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
1013
+ return ret;
1014
+ },
1015
+ __wbg_new_with_length_825018a1616e9e55: function(arg0) {
1016
+ const ret = new Uint8Array(arg0 >>> 0);
1017
+ return ret;
1018
+ },
1019
+ __wbg_next_11b99ee6237339e3: function() { return handleError(function (arg0) {
1020
+ const ret = arg0.next();
1021
+ return ret;
1022
+ }, arguments); },
1023
+ __wbg_next_e01a967809d1aa68: function(arg0) {
1024
+ const ret = arg0.next;
1025
+ return ret;
1026
+ },
1027
+ __wbg_node_84ea875411254db1: function(arg0) {
1028
+ const ret = arg0.node;
1029
+ return ret;
1030
+ },
1031
+ __wbg_now_16f0c993d5dd6c27: function() {
1032
+ const ret = Date.now();
1033
+ return ret;
1034
+ },
1035
+ __wbg_process_44c7a14e11e9f69e: function(arg0) {
1036
+ const ret = arg0.process;
1037
+ return ret;
1038
+ },
1039
+ __wbg_prototypesetcall_d62e5099504357e6: function(arg0, arg1, arg2) {
1040
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
1041
+ },
1042
+ __wbg_push_e87b0e732085a946: function(arg0, arg1) {
1043
+ const ret = arg0.push(arg1);
1044
+ return ret;
1045
+ },
1046
+ __wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
1047
+ arg0.randomFillSync(arg1);
1048
+ }, arguments); },
1049
+ __wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
1050
+ const ret = module.require;
1051
+ return ret;
1052
+ }, arguments); },
1053
+ __wbg_set_282384002438957f: function(arg0, arg1, arg2) {
1054
+ arg0[arg1 >>> 0] = arg2;
1055
+ },
1056
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
1057
+ arg0[arg1] = arg2;
1058
+ },
1059
+ __wbg_set_7eaa4f96924fd6b3: function() { return handleError(function (arg0, arg1, arg2) {
1060
+ const ret = Reflect.set(arg0, arg1, arg2);
1061
+ return ret;
1062
+ }, arguments); },
1063
+ __wbg_set_bf7251625df30a02: function(arg0, arg1, arg2) {
1064
+ const ret = arg0.set(arg1, arg2);
1065
+ return ret;
1066
+ },
1067
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
1068
+ const ret = arg1.stack;
1069
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1070
+ const len1 = WASM_VECTOR_LEN;
1071
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1072
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1073
+ },
1074
+ __wbg_static_accessor_GLOBAL_8adb955bd33fac2f: function() {
1075
+ const ret = typeof global === 'undefined' ? null : global;
1076
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1077
+ },
1078
+ __wbg_static_accessor_GLOBAL_THIS_ad356e0db91c7913: function() {
1079
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
1080
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1081
+ },
1082
+ __wbg_static_accessor_SELF_f207c857566db248: function() {
1083
+ const ret = typeof self === 'undefined' ? null : self;
1084
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1085
+ },
1086
+ __wbg_static_accessor_WINDOW_bb9f1ba69d61b386: function() {
1087
+ const ret = typeof window === 'undefined' ? null : window;
1088
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1089
+ },
1090
+ __wbg_subarray_a068d24e39478a8a: function(arg0, arg1, arg2) {
1091
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
1092
+ return ret;
1093
+ },
1094
+ __wbg_value_21fc78aab0322612: function(arg0) {
1095
+ const ret = arg0.value;
1096
+ return ret;
1097
+ },
1098
+ __wbg_versions_276b2795b1c6a219: function(arg0) {
1099
+ const ret = arg0.versions;
1100
+ return ret;
1101
+ },
1102
+ __wbindgen_cast_0000000000000001: function(arg0) {
1103
+ // Cast intrinsic for `F64 -> Externref`.
1104
+ const ret = arg0;
1105
+ return ret;
1106
+ },
1107
+ __wbindgen_cast_0000000000000002: function(arg0) {
1108
+ // Cast intrinsic for `I64 -> Externref`.
1109
+ const ret = arg0;
1110
+ return ret;
1111
+ },
1112
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
1113
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
1114
+ const ret = getArrayU8FromWasm0(arg0, arg1);
1115
+ return ret;
1116
+ },
1117
+ __wbindgen_cast_0000000000000004: function(arg0, arg1) {
1118
+ // Cast intrinsic for `Ref(String) -> Externref`.
1119
+ const ret = getStringFromWasm0(arg0, arg1);
1120
+ return ret;
1121
+ },
1122
+ __wbindgen_cast_0000000000000005: function(arg0) {
1123
+ // Cast intrinsic for `U64 -> Externref`.
1124
+ const ret = BigInt.asUintN(64, arg0);
1125
+ return ret;
1126
+ },
1127
+ __wbindgen_init_externref_table: function() {
1128
+ const table = wasm.__wbindgen_externrefs;
1129
+ const offset = table.grow(4);
1130
+ table.set(0, undefined);
1131
+ table.set(offset + 0, undefined);
1132
+ table.set(offset + 1, null);
1133
+ table.set(offset + 2, true);
1134
+ table.set(offset + 3, false);
1135
+ },
1136
+ };
1137
+ return {
1138
+ __proto__: null,
1139
+ "./chat_xdk_wasm_bg.js": import0,
1140
+ };
1141
+ }
1142
+
1143
+ const ChatFinalization = (typeof FinalizationRegistry === 'undefined')
1144
+ ? { register: () => {}, unregister: () => {} }
1145
+ : new FinalizationRegistry(ptr => wasm.__wbg_chat_free(ptr >>> 0, 1));
1146
+
1147
+ function addToExternrefTable0(obj) {
1148
+ const idx = wasm.__externref_table_alloc();
1149
+ wasm.__wbindgen_externrefs.set(idx, obj);
1150
+ return idx;
1151
+ }
1152
+
1153
+ function debugString(val) {
1154
+ // primitive types
1155
+ const type = typeof val;
1156
+ if (type == 'number' || type == 'boolean' || val == null) {
1157
+ return `${val}`;
1158
+ }
1159
+ if (type == 'string') {
1160
+ return `"${val}"`;
1161
+ }
1162
+ if (type == 'symbol') {
1163
+ const description = val.description;
1164
+ if (description == null) {
1165
+ return 'Symbol';
1166
+ } else {
1167
+ return `Symbol(${description})`;
1168
+ }
1169
+ }
1170
+ if (type == 'function') {
1171
+ const name = val.name;
1172
+ if (typeof name == 'string' && name.length > 0) {
1173
+ return `Function(${name})`;
1174
+ } else {
1175
+ return 'Function';
1176
+ }
1177
+ }
1178
+ // objects
1179
+ if (Array.isArray(val)) {
1180
+ const length = val.length;
1181
+ let debug = '[';
1182
+ if (length > 0) {
1183
+ debug += debugString(val[0]);
1184
+ }
1185
+ for(let i = 1; i < length; i++) {
1186
+ debug += ', ' + debugString(val[i]);
1187
+ }
1188
+ debug += ']';
1189
+ return debug;
1190
+ }
1191
+ // Test for built-in
1192
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
1193
+ let className;
1194
+ if (builtInMatches && builtInMatches.length > 1) {
1195
+ className = builtInMatches[1];
1196
+ } else {
1197
+ // Failed to match the standard '[object ClassName]'
1198
+ return toString.call(val);
1199
+ }
1200
+ if (className == 'Object') {
1201
+ // we're a user defined class or Object
1202
+ // JSON.stringify avoids problems with cycles, and is generally much
1203
+ // easier than looping through ownProperties of `val`.
1204
+ try {
1205
+ return 'Object(' + JSON.stringify(val) + ')';
1206
+ } catch (_) {
1207
+ return 'Object';
1208
+ }
1209
+ }
1210
+ // errors
1211
+ if (val instanceof Error) {
1212
+ return `${val.name}: ${val.message}\n${val.stack}`;
1213
+ }
1214
+ // TODO we could test for more things here, like `Set`s and `Map`s.
1215
+ return className;
1216
+ }
1217
+
1218
+ function getArrayU8FromWasm0(ptr, len) {
1219
+ ptr = ptr >>> 0;
1220
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1221
+ }
1222
+
1223
+ let cachedDataViewMemory0 = null;
1224
+ function getDataViewMemory0() {
1225
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
1226
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
1227
+ }
1228
+ return cachedDataViewMemory0;
1229
+ }
1230
+
1231
+ function getStringFromWasm0(ptr, len) {
1232
+ ptr = ptr >>> 0;
1233
+ return decodeText(ptr, len);
1234
+ }
1235
+
1236
+ let cachedUint8ArrayMemory0 = null;
1237
+ function getUint8ArrayMemory0() {
1238
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1239
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1240
+ }
1241
+ return cachedUint8ArrayMemory0;
1242
+ }
1243
+
1244
+ function handleError(f, args) {
1245
+ try {
1246
+ return f.apply(this, args);
1247
+ } catch (e) {
1248
+ const idx = addToExternrefTable0(e);
1249
+ wasm.__wbindgen_exn_store(idx);
1250
+ }
1251
+ }
1252
+
1253
+ function isLikeNone(x) {
1254
+ return x === undefined || x === null;
1255
+ }
1256
+
1257
+ function passArray8ToWasm0(arg, malloc) {
1258
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
1259
+ getUint8ArrayMemory0().set(arg, ptr / 1);
1260
+ WASM_VECTOR_LEN = arg.length;
1261
+ return ptr;
1262
+ }
1263
+
1264
+ function passArrayJsValueToWasm0(array, malloc) {
1265
+ const ptr = malloc(array.length * 4, 4) >>> 0;
1266
+ for (let i = 0; i < array.length; i++) {
1267
+ const add = addToExternrefTable0(array[i]);
1268
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
1269
+ }
1270
+ WASM_VECTOR_LEN = array.length;
1271
+ return ptr;
1272
+ }
1273
+
1274
+ function passStringToWasm0(arg, malloc, realloc) {
1275
+ if (realloc === undefined) {
1276
+ const buf = cachedTextEncoder.encode(arg);
1277
+ const ptr = malloc(buf.length, 1) >>> 0;
1278
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
1279
+ WASM_VECTOR_LEN = buf.length;
1280
+ return ptr;
1281
+ }
1282
+
1283
+ let len = arg.length;
1284
+ let ptr = malloc(len, 1) >>> 0;
1285
+
1286
+ const mem = getUint8ArrayMemory0();
1287
+
1288
+ let offset = 0;
1289
+
1290
+ for (; offset < len; offset++) {
1291
+ const code = arg.charCodeAt(offset);
1292
+ if (code > 0x7F) break;
1293
+ mem[ptr + offset] = code;
1294
+ }
1295
+ if (offset !== len) {
1296
+ if (offset !== 0) {
1297
+ arg = arg.slice(offset);
1298
+ }
1299
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1300
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1301
+ const ret = cachedTextEncoder.encodeInto(arg, view);
1302
+
1303
+ offset += ret.written;
1304
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
1305
+ }
1306
+
1307
+ WASM_VECTOR_LEN = offset;
1308
+ return ptr;
1309
+ }
1310
+
1311
+ function takeFromExternrefTable0(idx) {
1312
+ const value = wasm.__wbindgen_externrefs.get(idx);
1313
+ wasm.__externref_table_dealloc(idx);
1314
+ return value;
1315
+ }
1316
+
1317
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1318
+ cachedTextDecoder.decode();
1319
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
1320
+ let numBytesDecoded = 0;
1321
+ function decodeText(ptr, len) {
1322
+ numBytesDecoded += len;
1323
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1324
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1325
+ cachedTextDecoder.decode();
1326
+ numBytesDecoded = len;
1327
+ }
1328
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1329
+ }
1330
+
1331
+ const cachedTextEncoder = new TextEncoder();
1332
+
1333
+ if (!('encodeInto' in cachedTextEncoder)) {
1334
+ cachedTextEncoder.encodeInto = function (arg, view) {
1335
+ const buf = cachedTextEncoder.encode(arg);
1336
+ view.set(buf);
1337
+ return {
1338
+ read: arg.length,
1339
+ written: buf.length
1340
+ };
1341
+ };
1342
+ }
1343
+
1344
+ let WASM_VECTOR_LEN = 0;
1345
+
1346
+ let wasmModule, wasm;
1347
+ function __wbg_finalize_init(instance, module) {
1348
+ wasm = instance.exports;
1349
+ wasmModule = module;
1350
+ cachedDataViewMemory0 = null;
1351
+ cachedUint8ArrayMemory0 = null;
1352
+ wasm.__wbindgen_start();
1353
+ return wasm;
1354
+ }
1355
+
1356
+ async function __wbg_load(module, imports) {
1357
+ if (typeof Response === 'function' && module instanceof Response) {
1358
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1359
+ try {
1360
+ return await WebAssembly.instantiateStreaming(module, imports);
1361
+ } catch (e) {
1362
+ const validResponse = module.ok && expectedResponseType(module.type);
1363
+
1364
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1365
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
1366
+
1367
+ } else { throw e; }
1368
+ }
1369
+ }
1370
+
1371
+ const bytes = await module.arrayBuffer();
1372
+ return await WebAssembly.instantiate(bytes, imports);
1373
+ } else {
1374
+ const instance = await WebAssembly.instantiate(module, imports);
1375
+
1376
+ if (instance instanceof WebAssembly.Instance) {
1377
+ return { instance, module };
1378
+ } else {
1379
+ return instance;
1380
+ }
1381
+ }
1382
+
1383
+ function expectedResponseType(type) {
1384
+ switch (type) {
1385
+ case 'basic': case 'cors': case 'default': return true;
1386
+ }
1387
+ return false;
1388
+ }
1389
+ }
1390
+
1391
+ function initSync(module) {
1392
+ if (wasm !== undefined) return wasm;
1393
+
1394
+
1395
+ if (module !== undefined) {
1396
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1397
+ ({module} = module)
1398
+ } else {
1399
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1400
+ }
1401
+ }
1402
+
1403
+ const imports = __wbg_get_imports();
1404
+ if (!(module instanceof WebAssembly.Module)) {
1405
+ module = new WebAssembly.Module(module);
1406
+ }
1407
+ const instance = new WebAssembly.Instance(module, imports);
1408
+ return __wbg_finalize_init(instance, module);
1409
+ }
1410
+
1411
+ async function __wbg_init(module_or_path) {
1412
+ if (wasm !== undefined) return wasm;
1413
+
1414
+
1415
+ if (module_or_path !== undefined) {
1416
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1417
+ ({module_or_path} = module_or_path)
1418
+ } else {
1419
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1420
+ }
1421
+ }
1422
+
1423
+ if (module_or_path === undefined) {
1424
+ module_or_path = new URL('chat_xdk_wasm_bg.wasm', import.meta.url);
1425
+ }
1426
+ const imports = __wbg_get_imports();
1427
+
1428
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1429
+ module_or_path = fetch(module_or_path);
1430
+ }
1431
+
1432
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1433
+
1434
+ return __wbg_finalize_init(instance, module);
1435
+ }
1436
+
1437
+ export { initSync, __wbg_init as default };