@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.
- package/LICENSE +21 -0
- package/README.md +27 -23
- package/index.d.ts +365 -77
- package/index.js +178 -47
- package/package.json +6 -2
- package/pkg/chat_xdk_wasm.d.ts +124 -44
- package/pkg/chat_xdk_wasm.js +224 -223
- package/pkg/chat_xdk_wasm_bg.wasm +0 -0
- package/pkg/chat_xdk_wasm_bg.wasm.d.ts +15 -9
- package/pkg/package.json +21 -0
package/pkg/chat_xdk_wasm.js
CHANGED
|
@@ -68,11 +68,17 @@ export class Chat {
|
|
|
68
68
|
/**
|
|
69
69
|
* Decrypt a raw webhook event payload.
|
|
70
70
|
*
|
|
71
|
-
* `conversationKeys` is
|
|
71
|
+
* `conversationKeys` is a plain `version → key bytes` map — the `.keys`
|
|
72
|
+
* property of the object returned by `extractConversationKeys` (passing
|
|
73
|
+
* the whole result object yields an empty map and every decrypt fails
|
|
74
|
+
* with "no matching key found").
|
|
72
75
|
* `signingKeys` is an array of `{ userId, publicKeyVersion, publicKey,
|
|
73
|
-
* identityPublicKey, identityPublicKeySignature }` objects
|
|
74
|
-
* the SDK picks the matching version
|
|
75
|
-
*
|
|
76
|
+
* identityPublicKey, identityPublicKeySignature }` objects; entries are
|
|
77
|
+
* filtered to the event's sender and the SDK picks the matching version
|
|
78
|
+
* automatically. Under the default reject-unverified policy an empty
|
|
79
|
+
* array makes every signed event throw; only after
|
|
80
|
+
* `setRejectUnverified(false)` are such events returned with
|
|
81
|
+
* `verified: false`.
|
|
76
82
|
* @param {string} event_b64
|
|
77
83
|
* @param {any} conversation_keys
|
|
78
84
|
* @param {any} signing_keys
|
|
@@ -164,51 +170,16 @@ export class Chat {
|
|
|
164
170
|
}
|
|
165
171
|
/**
|
|
166
172
|
* 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
173
|
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
174
|
+
* Takes a single params object with camelCase keys: `messageId`,
|
|
175
|
+
* `senderId`, `conversationId`, `conversationKey` (Uint8Array),
|
|
176
|
+
* `targetMessageSequenceId`, `emoji`, `conversationKeyVersion`,
|
|
177
|
+
* `signingKeyVersion`. The same shape works for `encryptRemoveReaction`.
|
|
178
|
+
* @param {any} params
|
|
206
179
|
* @returns {any}
|
|
207
180
|
*/
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
const len0 = WASM_VECTOR_LEN;
|
|
211
|
-
const ret = wasm.chat_encryptConversationKeyForRecipients(this.__wbg_ptr, ptr0, len0, recipients);
|
|
181
|
+
encryptAddReaction(params) {
|
|
182
|
+
const ret = wasm.chat_encryptAddReaction(this.__wbg_ptr, params);
|
|
212
183
|
if (ret[2]) {
|
|
213
184
|
throw takeFromExternrefTable0(ret[1]);
|
|
214
185
|
}
|
|
@@ -217,40 +188,16 @@ export class Chat {
|
|
|
217
188
|
/**
|
|
218
189
|
* Encrypt a text message for the X API.
|
|
219
190
|
*
|
|
220
|
-
*
|
|
221
|
-
* `
|
|
222
|
-
*
|
|
223
|
-
* `
|
|
224
|
-
*
|
|
225
|
-
* @param {
|
|
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]
|
|
191
|
+
* Takes a single params object with camelCase keys: `messageId`,
|
|
192
|
+
* `senderId`, `conversationId`, `conversationKey` (Uint8Array), `text`,
|
|
193
|
+
* `conversationKeyVersion`, `signingKeyVersion`, plus optional
|
|
194
|
+
* `entities` (array of `[start, end, "type"]` tuples), `attachments`
|
|
195
|
+
* (array of attachment objects), `shouldNotify`, and `ttlMsec`.
|
|
196
|
+
* @param {any} params
|
|
236
197
|
* @returns {any}
|
|
237
198
|
*/
|
|
238
|
-
encryptMessage(
|
|
239
|
-
const
|
|
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);
|
|
199
|
+
encryptMessage(params) {
|
|
200
|
+
const ret = wasm.chat_encryptMessage(this.__wbg_ptr, params);
|
|
254
201
|
if (ret[2]) {
|
|
255
202
|
throw takeFromExternrefTable0(ret[1]);
|
|
256
203
|
}
|
|
@@ -258,34 +205,13 @@ export class Chat {
|
|
|
258
205
|
}
|
|
259
206
|
/**
|
|
260
207
|
* Encrypt a reaction-remove.
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* @param {
|
|
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
|
|
208
|
+
*
|
|
209
|
+
* Takes the same params object shape as `encryptAddReaction`.
|
|
210
|
+
* @param {any} params
|
|
269
211
|
* @returns {any}
|
|
270
212
|
*/
|
|
271
|
-
encryptRemoveReaction(
|
|
272
|
-
const
|
|
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);
|
|
213
|
+
encryptRemoveReaction(params) {
|
|
214
|
+
const ret = wasm.chat_encryptRemoveReaction(this.__wbg_ptr, params);
|
|
289
215
|
if (ret[2]) {
|
|
290
216
|
throw takeFromExternrefTable0(ret[1]);
|
|
291
217
|
}
|
|
@@ -293,44 +219,15 @@ export class Chat {
|
|
|
293
219
|
}
|
|
294
220
|
/**
|
|
295
221
|
* Encrypt a reply message for the X API.
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* @param {
|
|
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]
|
|
222
|
+
*
|
|
223
|
+
* Takes a single params object: the same fields as `encryptMessage` plus
|
|
224
|
+
* required `replyToSequenceId` and optional `replyToSenderId`,
|
|
225
|
+
* `replyToText`, `replyToEntities`, and `replyToAttachments`.
|
|
226
|
+
* @param {any} params
|
|
312
227
|
* @returns {any}
|
|
313
228
|
*/
|
|
314
|
-
encryptReply(
|
|
315
|
-
const
|
|
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);
|
|
229
|
+
encryptReply(params) {
|
|
230
|
+
const ret = wasm.chat_encryptReply(this.__wbg_ptr, params);
|
|
334
231
|
if (ret[2]) {
|
|
335
232
|
throw takeFromExternrefTable0(ret[1]);
|
|
336
233
|
}
|
|
@@ -386,19 +283,6 @@ export class Chat {
|
|
|
386
283
|
}
|
|
387
284
|
return takeFromExternrefTable0(ret[0]);
|
|
388
285
|
}
|
|
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
286
|
/**
|
|
403
287
|
* Generate new keypairs and return the registration payload.
|
|
404
288
|
*
|
|
@@ -496,19 +380,61 @@ export class Chat {
|
|
|
496
380
|
return this;
|
|
497
381
|
}
|
|
498
382
|
/**
|
|
499
|
-
* Prepare conversation
|
|
383
|
+
* Prepare a signed conversation-key change, ready to send to the X API.
|
|
384
|
+
*
|
|
385
|
+
* Takes a single params object with camelCase keys: `senderId`,
|
|
386
|
+
* `signingKeyVersion`, `publicKeys` (the flat array of public keys —
|
|
387
|
+
* self plus recipients — from the X API), plus optional
|
|
388
|
+
* `conversationId`. Omit `conversationId` for a one-to-one and it is
|
|
389
|
+
* derived from the two participants; pass the existing id for a group
|
|
390
|
+
* key rotation.
|
|
391
|
+
*
|
|
392
|
+
* Returns `{ conversationId, conversationKey, conversationKeyVersion,
|
|
393
|
+
* participantKeys, actionSignatures }`.
|
|
394
|
+
* @param {any} params
|
|
395
|
+
* @returns {any}
|
|
396
|
+
*/
|
|
397
|
+
prepareConversationKeyChange(params) {
|
|
398
|
+
const ret = wasm.chat_prepareConversationKeyChange(this.__wbg_ptr, params);
|
|
399
|
+
if (ret[2]) {
|
|
400
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
401
|
+
}
|
|
402
|
+
return takeFromExternrefTable0(ret[0]);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Prepare a signed group create, ready to send to the X API.
|
|
500
406
|
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
407
|
+
* Takes a single params object with camelCase keys: `senderId`,
|
|
408
|
+
* `signingKeyVersion`, `publicKeys` (for the new roster),
|
|
409
|
+
* `conversationId`, `memberIds`, `adminIds`, plus optional `title`,
|
|
410
|
+
* `avatarUrl`, and `ttlMsec`. Emits two action signatures (a
|
|
411
|
+
* conversation-key change and the group create). Returns the same shape
|
|
412
|
+
* as [`Chat::prepare_conversation_key_change`].
|
|
413
|
+
* @param {any} params
|
|
414
|
+
* @returns {any}
|
|
415
|
+
*/
|
|
416
|
+
prepareGroupCreate(params) {
|
|
417
|
+
const ret = wasm.chat_prepareGroupCreate(this.__wbg_ptr, params);
|
|
418
|
+
if (ret[2]) {
|
|
419
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
420
|
+
}
|
|
421
|
+
return takeFromExternrefTable0(ret[0]);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Prepare a signed group member-add change, ready to send to the X API.
|
|
505
425
|
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
426
|
+
* Takes a single params object with camelCase keys: `senderId`,
|
|
427
|
+
* `signingKeyVersion`, `publicKeys` (for the updated roster),
|
|
428
|
+
* `conversationId`, `newMemberIds`, `currentMemberIds`,
|
|
429
|
+
* `currentAdminIds`, `currentPendingMemberIds`, plus optional
|
|
430
|
+
* `currentTitle`, `currentAvatarUrl`, `currentTtlMsec`, and
|
|
431
|
+
* `currentScreenCaptureBlockingEnabled`. Returns the same shape as
|
|
432
|
+
* [`Chat::prepare_conversation_key_change`].
|
|
433
|
+
* @param {any} params
|
|
508
434
|
* @returns {any}
|
|
509
435
|
*/
|
|
510
|
-
|
|
511
|
-
const ret = wasm.
|
|
436
|
+
prepareGroupMembersChange(params) {
|
|
437
|
+
const ret = wasm.chat_prepareGroupMembersChange(this.__wbg_ptr, params);
|
|
512
438
|
if (ret[2]) {
|
|
513
439
|
throw takeFromExternrefTable0(ret[1]);
|
|
514
440
|
}
|
|
@@ -528,8 +454,9 @@ export class Chat {
|
|
|
528
454
|
wasm.chat_setKeyVersion(this.__wbg_ptr, ptr0, len0);
|
|
529
455
|
}
|
|
530
456
|
/**
|
|
531
|
-
* When enabled
|
|
532
|
-
*
|
|
457
|
+
* When enabled — the default — `decryptEvent` throws for any signed
|
|
458
|
+
* event whose signature cannot be verified (invalid, missing, or no
|
|
459
|
+
* matching signing key) instead of returning it with `verified: false`.
|
|
533
460
|
* @param {boolean} reject
|
|
534
461
|
*/
|
|
535
462
|
setRejectUnverified(reject) {
|
|
@@ -552,78 +479,32 @@ export class Chat {
|
|
|
552
479
|
return v2;
|
|
553
480
|
}
|
|
554
481
|
/**
|
|
555
|
-
*
|
|
556
|
-
* @param {
|
|
557
|
-
* @
|
|
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}
|
|
482
|
+
* Create an incremental stream decryptor for large payloads.
|
|
483
|
+
* @param {Uint8Array} conversation_key
|
|
484
|
+
* @returns {StreamDecryptor}
|
|
569
485
|
*/
|
|
570
|
-
|
|
571
|
-
const ptr0 =
|
|
486
|
+
streamDecryptor(conversation_key) {
|
|
487
|
+
const ptr0 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
|
|
572
488
|
const len0 = WASM_VECTOR_LEN;
|
|
573
|
-
const
|
|
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);
|
|
489
|
+
const ret = wasm.chat_streamDecryptor(this.__wbg_ptr, ptr0, len0);
|
|
594
490
|
if (ret[2]) {
|
|
595
491
|
throw takeFromExternrefTable0(ret[1]);
|
|
596
492
|
}
|
|
597
|
-
return
|
|
493
|
+
return StreamDecryptor.__wrap(ret[0]);
|
|
598
494
|
}
|
|
599
495
|
/**
|
|
600
|
-
*
|
|
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
|
|
496
|
+
* Create an incremental stream encryptor for large payloads.
|
|
606
497
|
* @param {Uint8Array} conversation_key
|
|
607
|
-
* @returns {
|
|
498
|
+
* @returns {StreamEncryptor}
|
|
608
499
|
*/
|
|
609
|
-
|
|
610
|
-
const ptr0 =
|
|
500
|
+
streamEncryptor(conversation_key) {
|
|
501
|
+
const ptr0 = passArray8ToWasm0(conversation_key, wasm.__wbindgen_malloc);
|
|
611
502
|
const len0 = WASM_VECTOR_LEN;
|
|
612
|
-
const
|
|
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);
|
|
503
|
+
const ret = wasm.chat_streamEncryptor(this.__wbg_ptr, ptr0, len0);
|
|
623
504
|
if (ret[2]) {
|
|
624
505
|
throw takeFromExternrefTable0(ret[1]);
|
|
625
506
|
}
|
|
626
|
-
return
|
|
507
|
+
return StreamEncryptor.__wrap(ret[0]);
|
|
627
508
|
}
|
|
628
509
|
/**
|
|
629
510
|
* Verify a signature.
|
|
@@ -671,6 +552,120 @@ export class Chat {
|
|
|
671
552
|
}
|
|
672
553
|
if (Symbol.dispose) Chat.prototype[Symbol.dispose] = Chat.prototype.free;
|
|
673
554
|
|
|
555
|
+
/**
|
|
556
|
+
* Incremental stream decryptor for large payloads.
|
|
557
|
+
*
|
|
558
|
+
* Feed ciphertext with `push`; call `finish` once at end of input. `finish`
|
|
559
|
+
* throws if the stream ended before its final frame (truncation), so callers
|
|
560
|
+
* must not treat plaintext as complete until `finish` succeeds.
|
|
561
|
+
*/
|
|
562
|
+
export class StreamDecryptor {
|
|
563
|
+
static __wrap(ptr) {
|
|
564
|
+
ptr = ptr >>> 0;
|
|
565
|
+
const obj = Object.create(StreamDecryptor.prototype);
|
|
566
|
+
obj.__wbg_ptr = ptr;
|
|
567
|
+
StreamDecryptorFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
568
|
+
return obj;
|
|
569
|
+
}
|
|
570
|
+
__destroy_into_raw() {
|
|
571
|
+
const ptr = this.__wbg_ptr;
|
|
572
|
+
this.__wbg_ptr = 0;
|
|
573
|
+
StreamDecryptorFinalization.unregister(this);
|
|
574
|
+
return ptr;
|
|
575
|
+
}
|
|
576
|
+
free() {
|
|
577
|
+
const ptr = this.__destroy_into_raw();
|
|
578
|
+
wasm.__wbg_streamdecryptor_free(ptr, 0);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Decrypt the final frame and consume the decryptor.
|
|
582
|
+
* @returns {Uint8Array}
|
|
583
|
+
*/
|
|
584
|
+
finish() {
|
|
585
|
+
const ptr = this.__destroy_into_raw();
|
|
586
|
+
const ret = wasm.streamdecryptor_finish(ptr);
|
|
587
|
+
if (ret[3]) {
|
|
588
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
589
|
+
}
|
|
590
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
591
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
592
|
+
return v1;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Decrypt a ciphertext chunk, returning plaintext available so far.
|
|
596
|
+
* @param {Uint8Array} ciphertext
|
|
597
|
+
* @returns {Uint8Array}
|
|
598
|
+
*/
|
|
599
|
+
push(ciphertext) {
|
|
600
|
+
const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
|
|
601
|
+
const len0 = WASM_VECTOR_LEN;
|
|
602
|
+
const ret = wasm.streamdecryptor_push(this.__wbg_ptr, ptr0, len0);
|
|
603
|
+
if (ret[3]) {
|
|
604
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
605
|
+
}
|
|
606
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
607
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
608
|
+
return v2;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (Symbol.dispose) StreamDecryptor.prototype[Symbol.dispose] = StreamDecryptor.prototype.free;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Incremental stream encryptor for large payloads.
|
|
615
|
+
*
|
|
616
|
+
* Feed plaintext with `push`; call `finish` once to emit the final frame.
|
|
617
|
+
*/
|
|
618
|
+
export class StreamEncryptor {
|
|
619
|
+
static __wrap(ptr) {
|
|
620
|
+
ptr = ptr >>> 0;
|
|
621
|
+
const obj = Object.create(StreamEncryptor.prototype);
|
|
622
|
+
obj.__wbg_ptr = ptr;
|
|
623
|
+
StreamEncryptorFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
624
|
+
return obj;
|
|
625
|
+
}
|
|
626
|
+
__destroy_into_raw() {
|
|
627
|
+
const ptr = this.__wbg_ptr;
|
|
628
|
+
this.__wbg_ptr = 0;
|
|
629
|
+
StreamEncryptorFinalization.unregister(this);
|
|
630
|
+
return ptr;
|
|
631
|
+
}
|
|
632
|
+
free() {
|
|
633
|
+
const ptr = this.__destroy_into_raw();
|
|
634
|
+
wasm.__wbg_streamencryptor_free(ptr, 0);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Emit the final frame and consume the encryptor.
|
|
638
|
+
* @returns {Uint8Array}
|
|
639
|
+
*/
|
|
640
|
+
finish() {
|
|
641
|
+
const ptr = this.__destroy_into_raw();
|
|
642
|
+
const ret = wasm.streamencryptor_finish(ptr);
|
|
643
|
+
if (ret[3]) {
|
|
644
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
645
|
+
}
|
|
646
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
647
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
648
|
+
return v1;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Encrypt a plaintext chunk, returning ciphertext available so far.
|
|
652
|
+
* @param {Uint8Array} plaintext
|
|
653
|
+
* @returns {Uint8Array}
|
|
654
|
+
*/
|
|
655
|
+
push(plaintext) {
|
|
656
|
+
const ptr0 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
|
|
657
|
+
const len0 = WASM_VECTOR_LEN;
|
|
658
|
+
const ret = wasm.streamencryptor_push(this.__wbg_ptr, ptr0, len0);
|
|
659
|
+
if (ret[3]) {
|
|
660
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
661
|
+
}
|
|
662
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
663
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
664
|
+
return v2;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (Symbol.dispose) StreamEncryptor.prototype[Symbol.dispose] = StreamEncryptor.prototype.free;
|
|
668
|
+
|
|
674
669
|
/**
|
|
675
670
|
* Decode base64 string to bytes.
|
|
676
671
|
*
|
|
@@ -1143,6 +1138,12 @@ function __wbg_get_imports() {
|
|
|
1143
1138
|
const ChatFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1144
1139
|
? { register: () => {}, unregister: () => {} }
|
|
1145
1140
|
: new FinalizationRegistry(ptr => wasm.__wbg_chat_free(ptr >>> 0, 1));
|
|
1141
|
+
const StreamDecryptorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1142
|
+
? { register: () => {}, unregister: () => {} }
|
|
1143
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_streamdecryptor_free(ptr >>> 0, 1));
|
|
1144
|
+
const StreamEncryptorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1145
|
+
? { register: () => {}, unregister: () => {} }
|
|
1146
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_streamencryptor_free(ptr >>> 0, 1));
|
|
1146
1147
|
|
|
1147
1148
|
function addToExternrefTable0(obj) {
|
|
1148
1149
|
const idx = wasm.__externref_table_alloc();
|
|
Binary file
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_chat_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_streamdecryptor_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_streamencryptor_free: (a: number, b: number) => void;
|
|
5
7
|
export const base64ToBytes: (a: number, b: number) => [number, number];
|
|
6
8
|
export const bytesToBase64: (a: number, b: number) => [number, number];
|
|
7
9
|
export const bytesToHex: (a: number, b: number) => [number, number];
|
|
@@ -11,15 +13,13 @@ export const chat_decryptEvent: (a: number, b: number, c: number, d: any, e: any
|
|
|
11
13
|
export const chat_decryptEvents: (a: number, b: number, c: number, d: any) => [number, number, number];
|
|
12
14
|
export const chat_decryptStream: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
13
15
|
export const chat_encrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
14
|
-
export const chat_encryptAddReaction: (a: number, b:
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
17
|
-
export const
|
|
18
|
-
export const 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];
|
|
16
|
+
export const chat_encryptAddReaction: (a: number, b: any) => [number, number, number];
|
|
17
|
+
export const chat_encryptMessage: (a: number, b: any) => [number, number, number];
|
|
18
|
+
export const chat_encryptRemoveReaction: (a: number, b: any) => [number, number, number];
|
|
19
|
+
export const chat_encryptReply: (a: number, b: any) => [number, number, number];
|
|
19
20
|
export const chat_encryptStream: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
20
21
|
export const chat_exportKeys: (a: number) => [number, number, number, number];
|
|
21
22
|
export const chat_extractConversationKeys: (a: number, b: number, c: number) => [number, number, number];
|
|
22
|
-
export const chat_generateConversationKey: (a: number) => [number, number, number, number];
|
|
23
23
|
export const chat_generateKeypairs: (a: number) => [number, number, number];
|
|
24
24
|
export const chat_getPublicKeyFingerprint: (a: number) => [number, number, number, number];
|
|
25
25
|
export const chat_getPublicKeys: (a: number) => [number, number, number];
|
|
@@ -28,17 +28,23 @@ export const chat_importKeys: (a: number, b: number, c: number) => [number, numb
|
|
|
28
28
|
export const chat_isUnlocked: (a: number) => number;
|
|
29
29
|
export const chat_lock: (a: number) => void;
|
|
30
30
|
export const chat_new: () => number;
|
|
31
|
-
export const
|
|
31
|
+
export const chat_prepareConversationKeyChange: (a: number, b: any) => [number, number, number];
|
|
32
|
+
export const chat_prepareGroupCreate: (a: number, b: any) => [number, number, number];
|
|
33
|
+
export const chat_prepareGroupMembersChange: (a: number, b: any) => [number, number, number];
|
|
32
34
|
export const chat_setKeyVersion: (a: number, b: number, c: number) => void;
|
|
33
35
|
export const chat_setRejectUnverified: (a: number, b: number) => void;
|
|
34
36
|
export const chat_sign: (a: number, b: number, c: number) => [number, number, number, number];
|
|
35
|
-
export const
|
|
36
|
-
export const
|
|
37
|
+
export const chat_streamDecryptor: (a: number, b: number, c: number) => [number, number, number];
|
|
38
|
+
export const chat_streamEncryptor: (a: number, b: number, c: number) => [number, number, number];
|
|
37
39
|
export const chat_verify: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
38
40
|
export const chat_verifyKeyBinding: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
39
41
|
export const detectImageDimensions: (a: number, b: number) => any;
|
|
40
42
|
export const detectMimeType: (a: number, b: number) => [number, number];
|
|
41
43
|
export const hexToBytes: (a: number, b: number) => [number, number];
|
|
44
|
+
export const streamdecryptor_finish: (a: number) => [number, number, number, number];
|
|
45
|
+
export const streamdecryptor_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
46
|
+
export const streamencryptor_finish: (a: number) => [number, number, number, number];
|
|
47
|
+
export const streamencryptor_push: (a: number, b: number, c: number) => [number, number, number, number];
|
|
42
48
|
export const init: () => void;
|
|
43
49
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
44
50
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
package/pkg/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "chat-xdk-wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "X Chat SDK - WebAssembly bindings for JavaScript/TypeScript",
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/xdevplatform/chat-xdk"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"chat_xdk_wasm_bg.wasm",
|
|
13
|
+
"chat_xdk_wasm.js",
|
|
14
|
+
"chat_xdk_wasm.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "chat_xdk_wasm.js",
|
|
17
|
+
"types": "chat_xdk_wasm.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|