@badzz88/baileys 8.5.7 → 8.5.9
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 +337 -1055
- package/WAProto/WAProto.proto +284 -264
- package/WAProto/index.js +5 -5
- package/engine-requirements.js +7 -15
- package/lib/Defaults/index.js +130 -187
- package/lib/Signal/Group/ciphertext-message.js +11 -14
- package/lib/Signal/Group/group-session-builder.js +29 -91
- package/lib/Signal/Group/group_cipher.js +81 -88
- package/lib/Signal/Group/index.js +12 -136
- package/lib/Signal/Group/keyhelper.js +15 -70
- package/lib/Signal/Group/sender-chain-key.js +25 -31
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
- package/lib/Signal/Group/sender-key-message.js +65 -68
- package/lib/Signal/Group/sender-key-name.js +41 -43
- package/lib/Signal/Group/sender-key-record.js +40 -43
- package/lib/Signal/Group/sender-key-state.js +83 -96
- package/lib/Signal/Group/sender-message-key.js +25 -29
- package/lib/Signal/libsignal.js +425 -453
- package/lib/Signal/lid-mapping.js +276 -259
- package/lib/Socket/Client/index.js +3 -30
- package/lib/Socket/Client/types.js +10 -12
- package/lib/Socket/Client/websocket.js +53 -61
- package/lib/Socket/business.js +379 -422
- package/lib/Socket/chats.js +1193 -1816
- package/lib/Socket/communities.js +431 -549
- package/lib/Socket/graphql.js +672 -612
- package/lib/Socket/groups.js +374 -764
- package/lib/Socket/index.js +17 -38
- package/lib/Socket/interop.js +417 -503
- package/lib/Socket/messages-recv.js +1915 -2441
- package/lib/Socket/messages-send.js +1213 -1630
- package/lib/Socket/mex.js +9 -15
- package/lib/Socket/newsletter.js +746 -808
- package/lib/Socket/privacy.js +310 -441
- package/lib/Socket/socket.js +1025 -1022
- package/lib/Socket/username.js +8 -15
- package/lib/Store/index.js +10 -36
- package/lib/Store/make-cache-manager-store.js +80 -85
- package/lib/Store/make-in-memory-store.js +231 -591
- package/lib/Store/make-ordered-dictionary.js +72 -78
- package/lib/Store/object-repository.js +28 -25
- package/lib/Types/Auth.js +2 -38
- package/lib/Types/Bussines.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +11 -95
- package/lib/Types/Mex.js +111 -112
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +56 -70
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +26 -55
- package/lib/Utils/auth-utils.js +288 -292
- package/lib/Utils/browser-utils.js +47 -113
- package/lib/Utils/business.js +224 -240
- package/lib/Utils/chat-utils.js +869 -1205
- package/lib/Utils/companion-reg-client-utils.js +34 -41
- package/lib/Utils/crypto.js +107 -144
- package/lib/Utils/decode-wa-message.js +308 -518
- package/lib/Utils/event-buffer.js +611 -596
- package/lib/Utils/generics.js +355 -515
- package/lib/Utils/history.js +134 -244
- package/lib/Utils/identity-change-handler.js +49 -51
- package/lib/Utils/index.js +23 -57
- package/lib/Utils/link-preview.js +77 -135
- package/lib/Utils/logger.js +3 -9
- package/lib/Utils/lt-hash.js +6 -37
- package/lib/Utils/make-mutex.js +33 -36
- package/lib/Utils/message-composer.js +233 -439
- package/lib/Utils/message-retry-manager.js +260 -265
- package/lib/Utils/messages-media.js +829 -855
- package/lib/Utils/messages.js +961 -2528
- package/lib/Utils/noise-handler.js +200 -195
- package/lib/Utils/offline-node-processor.js +33 -35
- package/lib/Utils/pre-key-manager.js +102 -103
- package/lib/Utils/process-message.js +560 -978
- package/lib/Utils/reporting-utils.js +253 -257
- package/lib/Utils/signal.js +195 -218
- package/lib/Utils/stanza-ack.js +29 -31
- package/lib/Utils/sticker.js +109 -144
- package/lib/Utils/sync-action-utils.js +45 -50
- package/lib/Utils/tc-token-utils.js +139 -137
- package/lib/Utils/use-multi-file-auth-state.js +109 -109
- package/lib/Utils/validate-connection.js +202 -218
- package/lib/WABinary/constants.js +1299 -1302
- package/lib/WABinary/decode.js +262 -343
- package/lib/WABinary/encode.js +4 -12
- package/lib/WABinary/generic-utils.js +187 -223
- package/lib/WABinary/index.js +6 -33
- package/lib/WABinary/jid-utils.js +88 -351
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +9 -12
- package/lib/WAM/constants.js +22853 -39486
- package/lib/WAM/encode.js +140 -132
- package/lib/WAM/index.js +4 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
- package/lib/WAUSync/Protocols/index.js +12 -39
- package/lib/WAUSync/USyncQuery.js +67 -49
- package/lib/WAUSync/USyncUser.js +11 -5
- package/lib/WAUSync/index.js +3 -31
- package/lib/index.js +15 -48
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/interactive-handler.js +0 -522
- package/lib/Socket/managed-account.js +0 -183
- package/lib/Socket/registration.js +0 -427
- package/lib/Socket/text-router.js +0 -83
- package/lib/Types/Newsletter.js +0 -121
- package/lib/Utils/command-loader.d.ts +0 -31
- package/lib/Utils/command-loader.js +0 -100
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/curve25519-js.js +0 -275
- package/lib/Utils/group-history.js +0 -60
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/meta-ai-msmsg.js +0 -262
- package/lib/Utils/native-bridge.js +0 -82
- package/lib/Utils/session-pool.d.ts +0 -16
- package/lib/Utils/session-pool.js +0 -94
- package/lib/Utils/sticker.d.ts +0 -17
- package/lib/Utils/view-once-cache.d.ts +0 -9
- package/lib/Utils/view-once-cache.js +0 -79
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/antiban.js +0 -4637
package/lib/WABinary/decode.js
CHANGED
|
@@ -1,343 +1,262 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
default:
|
|
264
|
-
// Unknown tag — token table may be outdated (new WA protocol version)
|
|
265
|
-
process.stderr.write(`[WABinary] unknown string tag 0x${tag.toString(16)} — token table outdated?\n`)
|
|
266
|
-
return ''
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
const readList = tag => {
|
|
270
|
-
const items = []
|
|
271
|
-
const size = readListSize(tag)
|
|
272
|
-
for (let i = 0; i < size; i++) {
|
|
273
|
-
items.push((0, exports.decodeDecompressedBinaryNode)(buffer, opts, indexRef))
|
|
274
|
-
}
|
|
275
|
-
return items
|
|
276
|
-
}
|
|
277
|
-
const getTokenDouble = (index1, index2) => {
|
|
278
|
-
const dict = DOUBLE_BYTE_TOKENS[index1]
|
|
279
|
-
if (!dict) {
|
|
280
|
-
// Unknown dictionary — token table may be outdated (new WA protocol version)
|
|
281
|
-
process.stderr.write(`[WABinary] unknown double-byte token dict ${index1} — token table outdated?\n`)
|
|
282
|
-
return ''
|
|
283
|
-
}
|
|
284
|
-
const value = dict[index2]
|
|
285
|
-
if (typeof value === 'undefined') {
|
|
286
|
-
// Unknown token in known dictionary — token table may be outdated
|
|
287
|
-
process.stderr.write(`[WABinary] unknown double-byte token dict=${index1} idx=${index2} — token table outdated?\n`)
|
|
288
|
-
return ''
|
|
289
|
-
}
|
|
290
|
-
return value
|
|
291
|
-
}
|
|
292
|
-
const listSize = readListSize(readByte())
|
|
293
|
-
const header = readString(readByte())
|
|
294
|
-
if (!listSize || !header.length) {
|
|
295
|
-
throw new Error('invalid node')
|
|
296
|
-
}
|
|
297
|
-
const attrs = {}
|
|
298
|
-
let data
|
|
299
|
-
if (listSize === 0 || !header) {
|
|
300
|
-
throw new Error('invalid node')
|
|
301
|
-
}
|
|
302
|
-
// read the attributes in
|
|
303
|
-
const attributesLength = (listSize - 1) >> 1
|
|
304
|
-
for (let i = 0; i < attributesLength; i++) {
|
|
305
|
-
const key = readString(readByte())
|
|
306
|
-
const value = readString(readByte())
|
|
307
|
-
attrs[key] = value
|
|
308
|
-
}
|
|
309
|
-
if (listSize % 2 === 0) {
|
|
310
|
-
const tag = readByte()
|
|
311
|
-
if (isListTag(tag)) {
|
|
312
|
-
data = readList(tag)
|
|
313
|
-
} else {
|
|
314
|
-
let decoded
|
|
315
|
-
switch (tag) {
|
|
316
|
-
case TAGS.BINARY_8:
|
|
317
|
-
decoded = readBytes(readByte())
|
|
318
|
-
break
|
|
319
|
-
case TAGS.BINARY_20:
|
|
320
|
-
decoded = readBytes(readInt20())
|
|
321
|
-
break
|
|
322
|
-
case TAGS.BINARY_32:
|
|
323
|
-
decoded = readBytes(readInt(4))
|
|
324
|
-
break
|
|
325
|
-
default:
|
|
326
|
-
decoded = readString(tag)
|
|
327
|
-
break
|
|
328
|
-
}
|
|
329
|
-
data = decoded
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return {
|
|
333
|
-
tag: header,
|
|
334
|
-
attrs,
|
|
335
|
-
content: data
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode
|
|
339
|
-
const decodeBinaryNode = buff => {
|
|
340
|
-
const buffer = Buffer.isBuffer(buff) ? buff : Buffer.from(buff)
|
|
341
|
-
return decodeDecompressedBinaryNode(buffer, constants)
|
|
342
|
-
}
|
|
343
|
-
exports.decodeBinaryNode = decodeBinaryNode
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import { inflate } from 'zlib';
|
|
3
|
+
import * as constants from './constants.js';
|
|
4
|
+
import { jidEncode, WAJIDDomains } from './jid-utils.js';
|
|
5
|
+
const inflatePromise = promisify(inflate);
|
|
6
|
+
export const decompressingIfRequired = async (buffer) => {
|
|
7
|
+
if (2 & buffer.readUInt8()) {
|
|
8
|
+
buffer = await inflatePromise(buffer.slice(1));
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
// nodes with no compression have a 0x00 prefix, we remove that
|
|
12
|
+
buffer = buffer.slice(1);
|
|
13
|
+
}
|
|
14
|
+
return buffer;
|
|
15
|
+
};
|
|
16
|
+
export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
17
|
+
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
|
|
18
|
+
const checkEOS = (length) => {
|
|
19
|
+
if (indexRef.index + length > buffer.length) {
|
|
20
|
+
throw new Error('end of stream');
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const next = () => {
|
|
24
|
+
const value = buffer[indexRef.index];
|
|
25
|
+
indexRef.index += 1;
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
const readByte = () => {
|
|
29
|
+
checkEOS(1);
|
|
30
|
+
return next();
|
|
31
|
+
};
|
|
32
|
+
const readBytes = (n) => {
|
|
33
|
+
checkEOS(n);
|
|
34
|
+
const value = buffer.slice(indexRef.index, indexRef.index + n);
|
|
35
|
+
indexRef.index += n;
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
const readStringFromChars = (length) => {
|
|
39
|
+
return readBytes(length).toString('utf-8');
|
|
40
|
+
};
|
|
41
|
+
const readInt = (n, littleEndian = false) => {
|
|
42
|
+
checkEOS(n);
|
|
43
|
+
let val = 0;
|
|
44
|
+
for (let i = 0; i < n; i++) {
|
|
45
|
+
const shift = littleEndian ? i : n - 1 - i;
|
|
46
|
+
val |= next() << (shift * 8);
|
|
47
|
+
}
|
|
48
|
+
return val;
|
|
49
|
+
};
|
|
50
|
+
const readInt20 = () => {
|
|
51
|
+
checkEOS(3);
|
|
52
|
+
return ((next() & 15) << 16) + (next() << 8) + next();
|
|
53
|
+
};
|
|
54
|
+
const unpackHex = (value) => {
|
|
55
|
+
if (value >= 0 && value < 16) {
|
|
56
|
+
return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10;
|
|
57
|
+
}
|
|
58
|
+
throw new Error('invalid hex: ' + value);
|
|
59
|
+
};
|
|
60
|
+
const unpackNibble = (value) => {
|
|
61
|
+
if (value >= 0 && value <= 9) {
|
|
62
|
+
return '0'.charCodeAt(0) + value;
|
|
63
|
+
}
|
|
64
|
+
switch (value) {
|
|
65
|
+
case 10:
|
|
66
|
+
return '-'.charCodeAt(0);
|
|
67
|
+
case 11:
|
|
68
|
+
return '.'.charCodeAt(0);
|
|
69
|
+
case 15:
|
|
70
|
+
return '\0'.charCodeAt(0);
|
|
71
|
+
default:
|
|
72
|
+
throw new Error('invalid nibble: ' + value);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const unpackByte = (tag, value) => {
|
|
76
|
+
if (tag === TAGS.NIBBLE_8) {
|
|
77
|
+
return unpackNibble(value);
|
|
78
|
+
}
|
|
79
|
+
else if (tag === TAGS.HEX_8) {
|
|
80
|
+
return unpackHex(value);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new Error('unknown tag: ' + tag);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const readPacked8 = (tag) => {
|
|
87
|
+
const startByte = readByte();
|
|
88
|
+
let value = '';
|
|
89
|
+
for (let i = 0; i < (startByte & 127); i++) {
|
|
90
|
+
const curByte = readByte();
|
|
91
|
+
value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4));
|
|
92
|
+
value += String.fromCharCode(unpackByte(tag, curByte & 0x0f));
|
|
93
|
+
}
|
|
94
|
+
if (startByte >> 7 !== 0) {
|
|
95
|
+
value = value.slice(0, -1);
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
};
|
|
99
|
+
const isListTag = (tag) => {
|
|
100
|
+
return tag === TAGS.LIST_EMPTY || tag === TAGS.LIST_8 || tag === TAGS.LIST_16;
|
|
101
|
+
};
|
|
102
|
+
const readListSize = (tag) => {
|
|
103
|
+
switch (tag) {
|
|
104
|
+
case TAGS.LIST_EMPTY:
|
|
105
|
+
return 0;
|
|
106
|
+
case TAGS.LIST_8:
|
|
107
|
+
return readByte();
|
|
108
|
+
case TAGS.LIST_16:
|
|
109
|
+
return readInt(2);
|
|
110
|
+
default:
|
|
111
|
+
throw new Error('invalid tag for list size: ' + tag);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const readJidPair = () => {
|
|
115
|
+
const i = readString(readByte());
|
|
116
|
+
const j = readString(readByte());
|
|
117
|
+
if (j) {
|
|
118
|
+
return (i || '') + '@' + j;
|
|
119
|
+
}
|
|
120
|
+
throw new Error('invalid jid pair: ' + i + ', ' + j);
|
|
121
|
+
};
|
|
122
|
+
const readAdJid = () => {
|
|
123
|
+
const rawDomainType = readByte();
|
|
124
|
+
const domainType = Number(rawDomainType);
|
|
125
|
+
const device = readByte();
|
|
126
|
+
const user = readString(readByte());
|
|
127
|
+
let server = 's.whatsapp.net'; // default whatsapp server
|
|
128
|
+
if (domainType === WAJIDDomains.LID) {
|
|
129
|
+
server = 'lid';
|
|
130
|
+
}
|
|
131
|
+
else if (domainType === WAJIDDomains.HOSTED) {
|
|
132
|
+
server = 'hosted';
|
|
133
|
+
}
|
|
134
|
+
else if (domainType === WAJIDDomains.HOSTED_LID) {
|
|
135
|
+
server = 'hosted.lid';
|
|
136
|
+
}
|
|
137
|
+
return jidEncode(user, server, device);
|
|
138
|
+
};
|
|
139
|
+
const readFbJid = () => {
|
|
140
|
+
const user = readString(readByte());
|
|
141
|
+
const device = readInt(2);
|
|
142
|
+
const server = readString(readByte());
|
|
143
|
+
return `${user}:${device}@${server}`;
|
|
144
|
+
};
|
|
145
|
+
const readInteropJid = () => {
|
|
146
|
+
const user = readString(readByte());
|
|
147
|
+
const device = readInt(2);
|
|
148
|
+
const integrator = readInt(2);
|
|
149
|
+
let server = 'interop';
|
|
150
|
+
const beforeServer = indexRef.index;
|
|
151
|
+
try {
|
|
152
|
+
server = readString(readByte());
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
indexRef.index = beforeServer;
|
|
156
|
+
}
|
|
157
|
+
return `${integrator}-${user}:${device}@${server}`;
|
|
158
|
+
};
|
|
159
|
+
const readString = (tag) => {
|
|
160
|
+
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
161
|
+
return SINGLE_BYTE_TOKENS[tag] || '';
|
|
162
|
+
}
|
|
163
|
+
switch (tag) {
|
|
164
|
+
case TAGS.DICTIONARY_0:
|
|
165
|
+
case TAGS.DICTIONARY_1:
|
|
166
|
+
case TAGS.DICTIONARY_2:
|
|
167
|
+
case TAGS.DICTIONARY_3:
|
|
168
|
+
return getTokenDouble(tag - TAGS.DICTIONARY_0, readByte());
|
|
169
|
+
case TAGS.LIST_EMPTY:
|
|
170
|
+
return '';
|
|
171
|
+
case TAGS.BINARY_8:
|
|
172
|
+
return readStringFromChars(readByte());
|
|
173
|
+
case TAGS.BINARY_20:
|
|
174
|
+
return readStringFromChars(readInt20());
|
|
175
|
+
case TAGS.BINARY_32:
|
|
176
|
+
return readStringFromChars(readInt(4));
|
|
177
|
+
case TAGS.JID_PAIR:
|
|
178
|
+
return readJidPair();
|
|
179
|
+
case TAGS.FB_JID:
|
|
180
|
+
return readFbJid();
|
|
181
|
+
case TAGS.INTEROP_JID:
|
|
182
|
+
return readInteropJid();
|
|
183
|
+
case TAGS.AD_JID:
|
|
184
|
+
return readAdJid();
|
|
185
|
+
case TAGS.HEX_8:
|
|
186
|
+
case TAGS.NIBBLE_8:
|
|
187
|
+
return readPacked8(tag);
|
|
188
|
+
default:
|
|
189
|
+
throw new Error('invalid string with tag: ' + tag);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const readList = (tag) => {
|
|
193
|
+
const items = [];
|
|
194
|
+
const size = readListSize(tag);
|
|
195
|
+
for (let i = 0; i < size; i++) {
|
|
196
|
+
items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef));
|
|
197
|
+
}
|
|
198
|
+
return items;
|
|
199
|
+
};
|
|
200
|
+
const getTokenDouble = (index1, index2) => {
|
|
201
|
+
const dict = DOUBLE_BYTE_TOKENS[index1];
|
|
202
|
+
if (!dict) {
|
|
203
|
+
throw new Error(`Invalid double token dict (${index1})`);
|
|
204
|
+
}
|
|
205
|
+
const value = dict[index2];
|
|
206
|
+
if (typeof value === 'undefined') {
|
|
207
|
+
throw new Error(`Invalid double token (${index2})`);
|
|
208
|
+
}
|
|
209
|
+
return value;
|
|
210
|
+
};
|
|
211
|
+
const listSize = readListSize(readByte());
|
|
212
|
+
const header = readString(readByte());
|
|
213
|
+
if (!listSize || !header.length) {
|
|
214
|
+
throw new Error('invalid node');
|
|
215
|
+
}
|
|
216
|
+
const attrs = {};
|
|
217
|
+
let data;
|
|
218
|
+
if (listSize === 0 || !header) {
|
|
219
|
+
throw new Error('invalid node');
|
|
220
|
+
}
|
|
221
|
+
// read the attributes in
|
|
222
|
+
const attributesLength = (listSize - 1) >> 1;
|
|
223
|
+
for (let i = 0; i < attributesLength; i++) {
|
|
224
|
+
const key = readString(readByte());
|
|
225
|
+
const value = readString(readByte());
|
|
226
|
+
attrs[key] = value;
|
|
227
|
+
}
|
|
228
|
+
if (listSize % 2 === 0) {
|
|
229
|
+
const tag = readByte();
|
|
230
|
+
if (isListTag(tag)) {
|
|
231
|
+
data = readList(tag);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
let decoded;
|
|
235
|
+
switch (tag) {
|
|
236
|
+
case TAGS.BINARY_8:
|
|
237
|
+
decoded = readBytes(readByte());
|
|
238
|
+
break;
|
|
239
|
+
case TAGS.BINARY_20:
|
|
240
|
+
decoded = readBytes(readInt20());
|
|
241
|
+
break;
|
|
242
|
+
case TAGS.BINARY_32:
|
|
243
|
+
decoded = readBytes(readInt(4));
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
decoded = readString(tag);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
data = decoded;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
tag: header,
|
|
254
|
+
attrs,
|
|
255
|
+
content: data
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
export const decodeBinaryNode = async (buff) => {
|
|
259
|
+
const decompBuff = await decompressingIfRequired(buff);
|
|
260
|
+
return decodeDecompressedBinaryNode(decompBuff, constants);
|
|
261
|
+
};
|
|
262
|
+
//# sourceMappingURL=decode.js.map
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const constants = require('./constants')
|
|
5
|
-
const { jidDecode } = require('./jid-utils')
|
|
6
|
-
|
|
7
|
-
const encodeBinaryNodeJS = (node, opts = constants, buffer = [0]) => {
|
|
1
|
+
import * as constants from './constants.js';
|
|
2
|
+
import { jidDecode } from './jid-utils.js';
|
|
3
|
+
export const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
8
4
|
const encoded = encodeBinaryNodeInner(node, opts, buffer);
|
|
9
5
|
return Buffer.from(encoded);
|
|
10
6
|
};
|
|
@@ -221,8 +217,4 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
221
217
|
}
|
|
222
218
|
return buffer;
|
|
223
219
|
};
|
|
224
|
-
|
|
225
|
-
const encodeBinaryNode = (node, opts, buffer) => {
|
|
226
|
-
return encodeBinaryNodeJS(node, opts || constants, buffer || [0])
|
|
227
|
-
}
|
|
228
|
-
exports.encodeBinaryNode = encodeBinaryNode
|
|
220
|
+
//# sourceMappingURL=encode.js.map
|