@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.
- package/README.md +102 -0
- package/index.d.ts +558 -0
- package/index.js +394 -0
- package/package.json +43 -0
- package/pkg/chat_xdk_wasm.d.ts +315 -0
- package/pkg/chat_xdk_wasm.js +1437 -0
- package/pkg/chat_xdk_wasm_bg.wasm +0 -0
- package/pkg/chat_xdk_wasm_bg.wasm.d.ts +50 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The X Chat encryption SDK for JavaScript (crypto-only WASM layer).
|
|
6
|
+
*
|
|
7
|
+
* Provides all cryptographic operations: key generation, encrypt/decrypt,
|
|
8
|
+
* sign/verify. Juicebox key-storage lifecycle (setup/unlock/delete/changePin)
|
|
9
|
+
* is handled by the JS wrapper in `index.js`, which calls `exportKeys()` /
|
|
10
|
+
* `importKeys()` to shuttle raw key bytes across the boundary.
|
|
11
|
+
*/
|
|
12
|
+
export class Chat {
|
|
13
|
+
free(): void;
|
|
14
|
+
[Symbol.dispose](): void;
|
|
15
|
+
/**
|
|
16
|
+
* Decrypt a base64-encoded ciphertext and return the UTF-8 plaintext.
|
|
17
|
+
*
|
|
18
|
+
* Use for metadata fields like group names returned by the API.
|
|
19
|
+
*/
|
|
20
|
+
decrypt(ciphertext_b64: string, conversation_key: Uint8Array): string;
|
|
21
|
+
/**
|
|
22
|
+
* Decrypt an encrypted conversation key (ECIES).
|
|
23
|
+
*/
|
|
24
|
+
decryptConversationKey(encrypted_key_b64: string): Uint8Array;
|
|
25
|
+
/**
|
|
26
|
+
* Decrypt a raw webhook event payload.
|
|
27
|
+
*
|
|
28
|
+
* `conversationKeys` is the object returned by `extractConversationKeys`.
|
|
29
|
+
* `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
|
+
*/
|
|
34
|
+
decryptEvent(event_b64: string, conversation_keys: any, signing_keys: any): any;
|
|
35
|
+
/**
|
|
36
|
+
* Decrypt multiple events in batch.
|
|
37
|
+
*
|
|
38
|
+
* This is the recommended API for decrypting messages. It:
|
|
39
|
+
* 1. Extracts conversation keys from any KeyChange events
|
|
40
|
+
* 2. For each message, finds the correct signing key by matching userId + version
|
|
41
|
+
* 3. Decrypts the message using the appropriate conversation key
|
|
42
|
+
*
|
|
43
|
+
* `signingKeys` is an array of `{ userId, publicKeyVersion, publicKey,
|
|
44
|
+
* identityPublicKey, identityPublicKeySignature }` objects for ALL
|
|
45
|
+
* participants in the conversation (pass the X API response through).
|
|
46
|
+
*
|
|
47
|
+
* Returns `{ messages, conversationKeys, errors }`.
|
|
48
|
+
*/
|
|
49
|
+
decryptEvents(events: string[], signing_keys: any): any;
|
|
50
|
+
/**
|
|
51
|
+
* Decrypt a streaming-encrypted payload (e.g. media).
|
|
52
|
+
*/
|
|
53
|
+
decryptStream(encrypted: Uint8Array, conversation_key: Uint8Array): Uint8Array;
|
|
54
|
+
/**
|
|
55
|
+
* Encrypt a UTF-8 string and return base64 ciphertext.
|
|
56
|
+
*
|
|
57
|
+
* Use for metadata fields like group names before sending to the API.
|
|
58
|
+
*/
|
|
59
|
+
encrypt(plaintext: string, conversation_key: Uint8Array): string;
|
|
60
|
+
/**
|
|
61
|
+
* 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
|
+
*
|
|
67
|
+
* Each entry is `{ userId, publicKey, keyVersion }`.
|
|
68
|
+
*/
|
|
69
|
+
encryptConversationKeyForRecipients(conversation_key: Uint8Array, recipients: any): any;
|
|
70
|
+
/**
|
|
71
|
+
* Encrypt a text message for the X API.
|
|
72
|
+
*
|
|
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
|
+
*/
|
|
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;
|
|
80
|
+
/**
|
|
81
|
+
* Encrypt a reaction-remove.
|
|
82
|
+
*/
|
|
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;
|
|
84
|
+
/**
|
|
85
|
+
* Encrypt a reply message for the X API.
|
|
86
|
+
*/
|
|
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;
|
|
88
|
+
/**
|
|
89
|
+
* Encrypt a stream (e.g. media).
|
|
90
|
+
*/
|
|
91
|
+
encryptStream(plaintext: Uint8Array, conversation_key: Uint8Array): Uint8Array;
|
|
92
|
+
/**
|
|
93
|
+
* Export private keys as raw bytes (`Uint8Array`).
|
|
94
|
+
*/
|
|
95
|
+
exportKeys(): Uint8Array;
|
|
96
|
+
/**
|
|
97
|
+
* Extract and decrypt conversation keys from raw KeyChange event strings.
|
|
98
|
+
*
|
|
99
|
+
* Returns a `ConversationKeyResult` with:
|
|
100
|
+
* - `keys`: Object mapping key version strings to `Uint8Array` conversation keys
|
|
101
|
+
* - `latestVersion`: The highest key version (use for encrypting new messages)
|
|
102
|
+
*/
|
|
103
|
+
extractConversationKeys(events: string[]): any;
|
|
104
|
+
/**
|
|
105
|
+
* Generate a new conversation key.
|
|
106
|
+
*/
|
|
107
|
+
generateConversationKey(): Uint8Array;
|
|
108
|
+
/**
|
|
109
|
+
* Generate new keypairs and return the registration payload.
|
|
110
|
+
*
|
|
111
|
+
* The key version is read from the JS clock (`Date.now()`) because the
|
|
112
|
+
* `wasm32-unknown-unknown` target has no system clock.
|
|
113
|
+
*/
|
|
114
|
+
generateKeypairs(): any;
|
|
115
|
+
/**
|
|
116
|
+
* Get the fingerprint of the loaded identity public key.
|
|
117
|
+
*
|
|
118
|
+
* Returns a URL-safe base64 string that users can compare
|
|
119
|
+
* out-of-band (e.g. in person or over a trusted channel) to
|
|
120
|
+
* verify key authenticity.
|
|
121
|
+
*/
|
|
122
|
+
getPublicKeyFingerprint(): string;
|
|
123
|
+
/**
|
|
124
|
+
* Get current public keys.
|
|
125
|
+
*/
|
|
126
|
+
getPublicKeys(): any;
|
|
127
|
+
/**
|
|
128
|
+
* Returns `true` when the identity key is loaded (sufficient for decryption).
|
|
129
|
+
*/
|
|
130
|
+
hasIdentityKey(): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Import private keys from raw bytes (`Uint8Array`).
|
|
133
|
+
*
|
|
134
|
+
* The input bytes are zeroized after import.
|
|
135
|
+
*/
|
|
136
|
+
importKeys(keys: Uint8Array): void;
|
|
137
|
+
/**
|
|
138
|
+
* Returns `true` when both identity and signing keys are loaded.
|
|
139
|
+
*/
|
|
140
|
+
isUnlocked(): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Clear keys from memory.
|
|
143
|
+
*/
|
|
144
|
+
lock(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Create a new Chat instance.
|
|
147
|
+
*/
|
|
148
|
+
constructor();
|
|
149
|
+
/**
|
|
150
|
+
* Prepare conversation keys for all participants in one call.
|
|
151
|
+
*
|
|
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.
|
|
156
|
+
*
|
|
157
|
+
* Returns `{ conversationKey, conversationKeyVersion, participantKeys }`.
|
|
158
|
+
*/
|
|
159
|
+
prepareConversationKeys(public_keys: any): any;
|
|
160
|
+
/**
|
|
161
|
+
* Set the public key version for the loaded identity key.
|
|
162
|
+
*
|
|
163
|
+
* Call after `importKeys` (or unlock) with the version string the
|
|
164
|
+
* X API reports for your registered public key, so KeyChange
|
|
165
|
+
* participant entries for other key versions are skipped.
|
|
166
|
+
*/
|
|
167
|
+
setKeyVersion(version: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* When enabled, `decryptEvent` throws if signature verification fails
|
|
170
|
+
* instead of returning events with `verified: false`.
|
|
171
|
+
*/
|
|
172
|
+
setRejectUnverified(reject: boolean): void;
|
|
173
|
+
/**
|
|
174
|
+
* Sign data. Returns raw signature bytes (`Uint8Array`).
|
|
175
|
+
*/
|
|
176
|
+
sign(data: Uint8Array): Uint8Array;
|
|
177
|
+
/**
|
|
178
|
+
* Build and sign a GroupMemberAdd action signature.
|
|
179
|
+
*/
|
|
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;
|
|
181
|
+
/**
|
|
182
|
+
* Build and sign a ConversationKeyChange action signature.
|
|
183
|
+
*/
|
|
184
|
+
signKeyChange(public_key_version: string, message_id: string, sender_id: string, conversation_id: string, conversation_key_version: string, conversation_key: Uint8Array): any;
|
|
185
|
+
/**
|
|
186
|
+
* Verify a signature.
|
|
187
|
+
*/
|
|
188
|
+
verify(public_key_b64: string, signature: Uint8Array, data: Uint8Array): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Verify that a signing key is authentically bound to an identity key.
|
|
191
|
+
*
|
|
192
|
+
* Call this when you receive another user's public keys from the X API
|
|
193
|
+
* to detect server-side key substitution. All inputs are base64.
|
|
194
|
+
*/
|
|
195
|
+
verifyKeyBinding(identity_public_key_b64: string, signing_public_key_b64: string, identity_public_key_signature_b64: string): boolean;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Decode base64 string to bytes.
|
|
200
|
+
*
|
|
201
|
+
* Returns null if the input is not valid base64.
|
|
202
|
+
*/
|
|
203
|
+
export function base64ToBytes(b64: string): Uint8Array | undefined;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Encode bytes to base64 string.
|
|
207
|
+
*/
|
|
208
|
+
export function bytesToBase64(bytes: Uint8Array): string;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Encode bytes to lowercase hex string.
|
|
212
|
+
*/
|
|
213
|
+
export function bytesToHex(bytes: Uint8Array): string;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Detect image dimensions from file bytes.
|
|
217
|
+
*
|
|
218
|
+
* Supports PNG, JPEG, GIF, WebP, and BMP.
|
|
219
|
+
* Returns `{ width, height }` or null.
|
|
220
|
+
*/
|
|
221
|
+
export function detectImageDimensions(bytes: Uint8Array): any;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Detect MIME type from file bytes using magic numbers.
|
|
225
|
+
*
|
|
226
|
+
* Returns the MIME type string (e.g., "image/png", "video/mp4") or null.
|
|
227
|
+
*/
|
|
228
|
+
export function detectMimeType(bytes: Uint8Array): string | undefined;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Decode hex string to bytes.
|
|
232
|
+
*
|
|
233
|
+
* Returns null if the input is not valid hex.
|
|
234
|
+
*/
|
|
235
|
+
export function hexToBytes(hex: string): Uint8Array | undefined;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Initialize panic hook for better error messages in console.
|
|
239
|
+
*/
|
|
240
|
+
export function init(): void;
|
|
241
|
+
|
|
242
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
243
|
+
|
|
244
|
+
export interface InitOutput {
|
|
245
|
+
readonly memory: WebAssembly.Memory;
|
|
246
|
+
readonly __wbg_chat_free: (a: number, b: number) => void;
|
|
247
|
+
readonly base64ToBytes: (a: number, b: number) => [number, number];
|
|
248
|
+
readonly bytesToBase64: (a: number, b: number) => [number, number];
|
|
249
|
+
readonly bytesToHex: (a: number, b: number) => [number, number];
|
|
250
|
+
readonly chat_decrypt: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
251
|
+
readonly chat_decryptConversationKey: (a: number, b: number, c: number) => [number, number, number, number];
|
|
252
|
+
readonly chat_decryptEvent: (a: number, b: number, c: number, d: any, e: any) => [number, number, number];
|
|
253
|
+
readonly chat_decryptEvents: (a: number, b: number, c: number, d: any) => [number, number, number];
|
|
254
|
+
readonly chat_decryptStream: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
255
|
+
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];
|
|
261
|
+
readonly chat_encryptStream: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
262
|
+
readonly chat_exportKeys: (a: number) => [number, number, number, number];
|
|
263
|
+
readonly chat_extractConversationKeys: (a: number, b: number, c: number) => [number, number, number];
|
|
264
|
+
readonly chat_generateConversationKey: (a: number) => [number, number, number, number];
|
|
265
|
+
readonly chat_generateKeypairs: (a: number) => [number, number, number];
|
|
266
|
+
readonly chat_getPublicKeyFingerprint: (a: number) => [number, number, number, number];
|
|
267
|
+
readonly chat_getPublicKeys: (a: number) => [number, number, number];
|
|
268
|
+
readonly chat_hasIdentityKey: (a: number) => number;
|
|
269
|
+
readonly chat_importKeys: (a: number, b: number, c: number) => [number, number];
|
|
270
|
+
readonly chat_isUnlocked: (a: number) => number;
|
|
271
|
+
readonly chat_lock: (a: number) => void;
|
|
272
|
+
readonly chat_new: () => number;
|
|
273
|
+
readonly chat_prepareConversationKeys: (a: number, b: any) => [number, number, number];
|
|
274
|
+
readonly chat_setKeyVersion: (a: number, b: number, c: number) => void;
|
|
275
|
+
readonly chat_setRejectUnverified: (a: number, b: number) => void;
|
|
276
|
+
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];
|
|
279
|
+
readonly chat_verify: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
280
|
+
readonly chat_verifyKeyBinding: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
281
|
+
readonly detectImageDimensions: (a: number, b: number) => any;
|
|
282
|
+
readonly detectMimeType: (a: number, b: number) => [number, number];
|
|
283
|
+
readonly hexToBytes: (a: number, b: number) => [number, number];
|
|
284
|
+
readonly init: () => void;
|
|
285
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
286
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
287
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
288
|
+
readonly __externref_table_alloc: () => number;
|
|
289
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
290
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
291
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
292
|
+
readonly __wbindgen_start: () => void;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
299
|
+
* a precompiled `WebAssembly.Module`.
|
|
300
|
+
*
|
|
301
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
302
|
+
*
|
|
303
|
+
* @returns {InitOutput}
|
|
304
|
+
*/
|
|
305
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
309
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
310
|
+
*
|
|
311
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
312
|
+
*
|
|
313
|
+
* @returns {Promise<InitOutput>}
|
|
314
|
+
*/
|
|
315
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|