kage-baileys 3.0.6 → 3.2.3
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/Example/connection.cjs +4 -0
- package/README.MD +4726 -48
- package/WAProto/WAProto.proto +3395 -415
- package/WAProto/compat.cjs +12 -0
- package/WAProto/index.d.ts +47104 -19888
- package/WAProto/index.js +131979 -57361
- package/lib/Addon/http-error.js +43 -0
- package/lib/Addon/index.js +32 -0
- package/lib/Addon/keyed-db.js +250 -0
- package/lib/Addon/link-preview.js +82 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +110 -0
- package/lib/Defaults/constants.js +156 -0
- package/lib/Defaults/history.js +46 -0
- package/lib/Defaults/index.js +230 -0
- package/lib/Defaults/media.js +104 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +44 -0
- package/lib/Extensions/business-advanced.js +382 -0
- package/lib/Extensions/business.js +159 -0
- package/lib/Extensions/chats-advanced.js +1106 -0
- package/lib/Extensions/chats.js +349 -0
- package/lib/Extensions/communities-advanced.js +430 -0
- package/lib/Extensions/community.js +94 -0
- package/lib/Extensions/groups-advanced.js +343 -0
- package/lib/Extensions/index.js +30 -0
- package/lib/Extensions/messages-recv-advanced.js +1690 -0
- package/lib/Extensions/messages-send-advanced.js +622 -0
- package/lib/Extensions/messages-send.js +1380 -0
- package/lib/Extensions/newsletter-advanced.js +228 -0
- package/lib/Extensions/newsletter.js +72 -0
- package/lib/Extensions/socket.js +389 -0
- package/lib/Modded/message_builder.js +2084 -4
- package/lib/Signal/Group/ciphertext-message.js +54 -0
- package/lib/Signal/Group/group-session-builder.js +124 -0
- package/lib/Signal/Group/group_cipher.js +216 -0
- package/lib/Signal/Group/index.js +124 -0
- package/lib/Signal/Group/keyhelper.js +108 -0
- package/lib/Signal/Group/sender-chain-key.js +83 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
- package/lib/Signal/Group/sender-key-message.js +166 -0
- package/lib/Signal/Group/sender-key-name.js +130 -0
- package/lib/Signal/Group/sender-key-record.js +113 -0
- package/lib/Signal/Group/sender-key-state.js +208 -0
- package/lib/Signal/Group/sender-message-key.js +82 -0
- package/lib/Signal/libsignal.js +935 -0
- package/lib/Signal/lid-mapping.js +545 -1
- package/lib/Socket/Client/index.js +60 -0
- package/lib/Socket/Client/types.js +51 -0
- package/lib/Socket/Client/websocket.js +152 -0
- package/lib/Socket/business.js +831 -0
- package/lib/Socket/chats.js +2535 -49
- package/lib/Socket/communities.js +450 -1
- package/lib/Socket/community.js +1022 -0
- package/lib/Socket/dugong.js +1 -1
- package/lib/Socket/groups.js +747 -0
- package/lib/Socket/index.js +60 -2
- package/lib/Socket/messages-recv.js +3450 -5
- package/lib/Socket/messages-send.js +3123 -0
- package/lib/Socket/mex.js +126 -1
- package/lib/Socket/newsletter.js +465 -0
- package/lib/Socket/socket.js +2217 -1
- package/lib/Store/index.js +79 -0
- package/lib/Store/make-cache-manager-store.js +186 -0
- package/lib/Store/make-in-memory-store.js +878 -0
- package/lib/Store/make-ordered-dictionary.js +187 -0
- package/lib/Store/object-repository.js +78 -0
- package/lib/Types/Auth.js +25 -0
- package/lib/Types/Bussines.js +25 -1
- package/lib/Types/Call.js +25 -0
- package/lib/Types/Chat.js +39 -0
- package/lib/Types/Contact.js +25 -0
- package/lib/Types/Events.js +25 -0
- package/lib/Types/GroupMetadata.js +25 -0
- package/lib/Types/Label.js +76 -0
- package/lib/Types/LabelAssociation.js +40 -0
- package/lib/Types/Message.js +57 -0
- package/lib/Types/Mex.js +56 -1
- package/lib/Types/MexUpdates.js +46 -0
- package/lib/Types/Newsletter.js +56 -0
- package/lib/Types/Product.js +25 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.js +25 -0
- package/lib/Types/Socket.js +25 -0
- package/lib/Types/State.js +92 -0
- package/lib/Types/USync.js +25 -0
- package/lib/Types/index.js +133 -0
- package/lib/Utils/auth-utils.js +703 -0
- package/lib/Utils/automation-tools.js +51 -16
- package/lib/Utils/baileys-event-stream.js +146 -0
- package/lib/Utils/browser-utils.js +95 -0
- package/lib/Utils/business.js +525 -0
- package/lib/Utils/chat-utils.js +1861 -0
- package/lib/Utils/companion-reg-client-utils.js +55 -1
- package/lib/Utils/crypto.js +355 -0
- package/lib/Utils/decode-wa-message.js +709 -0
- package/lib/Utils/event-buffer.js +1323 -8
- package/lib/Utils/generics.js +945 -1
- package/lib/Utils/history.js +266 -0
- package/lib/Utils/identity-change-handler.js +62 -1
- package/lib/Utils/index.js +114 -0
- package/lib/Utils/link-preview.js +179 -0
- package/lib/Utils/logger.js +42 -0
- package/lib/Utils/lt-hash.js +73 -0
- package/lib/Utils/make-mutex.js +104 -0
- package/lib/Utils/message-inspector.js +110 -0
- package/lib/Utils/message-retry-manager.js +507 -2
- package/lib/Utils/messages-media.js +1931 -1
- package/lib/Utils/messages.js +3748 -0
- package/lib/Utils/noise-handler.js +423 -0
- package/lib/Utils/offline-node-processor.js +53 -1
- package/lib/Utils/pre-key-manager.js +255 -1
- package/lib/Utils/process-message.js +1592 -0
- package/lib/Utils/reporting-utils.js +272 -1
- package/lib/Utils/rich-message-utils.js +377 -0
- package/lib/Utils/rich-messages.js +1 -1
- package/lib/Utils/signal.js +437 -0
- package/lib/Utils/stanza-ack.js +51 -1
- package/lib/Utils/status-refresh.js +37 -0
- package/lib/Utils/status-tools.js +4 -2
- package/lib/Utils/sync-action-utils.js +63 -1
- package/lib/Utils/tc-token-utils.js +185 -1
- package/lib/Utils/terminal-banner.js +31 -0
- package/lib/Utils/use-multi-file-auth-state.js +271 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +142 -0
- package/lib/Utils/validate-connection.js +497 -1
- package/lib/Utils/view-once-compat.js +13 -5
- package/lib/VoIP/audio-feeder.js +150 -0
- package/lib/VoIP/index.js +289 -0
- package/lib/VoIP/relay-transport.js +608 -0
- package/lib/VoIP/signaling.js +583 -0
- package/lib/VoIP/types.js +30 -0
- package/lib/VoIP/wasm-engine.js +1261 -2
- package/lib/VoIP/worker-bootstrap.js +1090 -2
- package/lib/WABinary/constants.js +2805 -0
- package/lib/WABinary/decode.js +649 -2
- package/lib/WABinary/encode.js +564 -2
- package/lib/WABinary/generic-utils.js +401 -0
- package/lib/WABinary/index.js +82 -0
- package/lib/WABinary/jid-utils.js +290 -0
- package/lib/WABinary/types.js +25 -0
- package/lib/WAM/BinaryInfo.js +50 -0
- package/lib/WAM/constants.js +45747 -0
- package/lib/WAM/encode.js +393 -0
- package/lib/WAM/index.js +78 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
- package/lib/WAUSync/Protocols/index.js +83 -0
- package/lib/WAUSync/USyncQuery.js +241 -2
- package/lib/WAUSync/USyncUser.js +86 -0
- package/lib/WAUSync/index.js +78 -0
- package/lib/assets/wasm/loader.js +1875 -1
- package/lib/assets/wasm/worker-modules.js +11047 -1
- package/lib/index.d.ts +126 -0
- package/lib/index.js +53 -21
- package/lib/index.mjs +437 -0
- package/licenses/upstream-MIT.txt +22 -0
- package/maintenance/api-coverage.json +1642 -0
- package/maintenance/archivos-sha256.json +207 -0
- package/maintenance/consumer-validation.log +3 -0
- package/maintenance/dependency-audit.json +4 -4
- package/maintenance/extension-inventory.json +57 -0
- package/maintenance/protocol-update.json +1101 -0
- package/maintenance/protocol-wire-audit.json +4 -0
- package/maintenance/reference-socket-surface.json +209 -0
- package/maintenance/resumen-validacion.json +50 -0
- package/maintenance/validation.log +2725 -0
- package/maintenance/verification.json +566 -0
- package/package.json +107 -9
- package/scripts/check-imports.cjs +10 -0
- package/scripts/check-package.cjs +40 -0
- package/scripts/check-syntax.cjs +1 -1
- package/scripts/generate-protobuf.cjs +6 -1
- package/scripts/generate-public-types.cjs +9 -0
- package/scripts/kage-base64-fix.cjs +45 -0
- package/scripts/maintenance.cjs +10 -0
- package/test/advanced.test.cjs +24 -0
- package/test/base64-fix.test.cjs +49 -0
- package/test/maintenance.test.cjs +1 -1
- package/test/npm-publication.test.cjs +141 -0
- package/test/recepcion-reparada.test.cjs +98 -0
- package/test/resilience-binary.test.cjs +69 -0
- package/test/resilience-transport.test.cjs +34 -0
- package/test/types.test.ts +5 -0
- package/test/upgrade.test.cjs +104 -0
- package/tsconfig.json +20 -0
- package/WAProto/p.html +0 -1
- package/lib/KageExtra/Modded/message_builder.js +0 -2330
- package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
- package/lib/KageExtra/VoIP/index.js +0 -282
- package/lib/KageExtra/VoIP/relay-transport.js +0 -559
- package/lib/KageExtra/VoIP/signaling.js +0 -603
- package/lib/KageExtra/VoIP/types.js +0 -17
- package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
- package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
- package/lib/KageExtra/assets/wasm/loader.js +0 -5
- package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
- package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
- package/lib/KageExtra/index.js +0 -3
- package/lib/KageExtra/package.json +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- package/maintenance/revision-full-check.txt +0 -1097
- package/maintenance/revision-library-tests.tap +0 -1088
- package/maintenance/revision-protobuf.txt +0 -5
- package/maintenance/revision-syntax.txt +0 -5
- package/maintenance/schema-coverage.json +0 -23
- package/maintenance/schema-merge.json +0 -30
- package/maintenance/validation-node20.txt +0 -191
- package/maintenance/validation-node22.txt +0 -237
package/lib/WABinary/encode.js
CHANGED
|
@@ -179,7 +179,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
179
179
|
pushByte(TAGS.LIST_EMPTY);
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
|
-
const tokenIndex = TOKEN_MAP[str];
|
|
182
|
+
const tokenIndex = Object.hasOwn(TOKEN_MAP, str) ? TOKEN_MAP[str] : undefined;
|
|
183
183
|
if (tokenIndex) {
|
|
184
184
|
if (typeof tokenIndex.dict === 'number') {
|
|
185
185
|
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
|
|
@@ -217,7 +217,562 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
217
217
|
if (!tag) {
|
|
218
218
|
throw new Error('Invalid node: tag cannot be undefined');
|
|
219
219
|
}
|
|
220
|
-
const validAttributes = Object.keys(attrs || {}).filter(k =>
|
|
220
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] === 'string');
|
|
221
|
+
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
|
222
|
+
writeString(tag);
|
|
223
|
+
for (const key of validAttributes) {
|
|
224
|
+
if (typeof attrs[key] === 'string') {
|
|
225
|
+
writeString(key);
|
|
226
|
+
writeString(attrs[key]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (typeof content === 'string') {
|
|
230
|
+
writeString(content);
|
|
231
|
+
}
|
|
232
|
+
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
233
|
+
writeByteLength(content.length);
|
|
234
|
+
pushBytes(content);
|
|
235
|
+
}
|
|
236
|
+
else if (Array.isArray(content)) {
|
|
237
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
|
|
238
|
+
writeListStart(validContent.length);
|
|
239
|
+
for (const item of validContent) {
|
|
240
|
+
encodeBinaryNodeInner(item, opts, buffer);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else if (typeof content === 'undefined') {
|
|
244
|
+
// do nothing
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
248
|
+
}
|
|
249
|
+
return buffer;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// Kage: compatibilidad de API.
|
|
253
|
+
const __kageModule83 = (() => {
|
|
254
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
255
|
+
"use strict"
|
|
256
|
+
|
|
257
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
258
|
+
|
|
259
|
+
const { jidDecode } = require("./jid-utils")
|
|
260
|
+
const constants = require("./constants")
|
|
261
|
+
|
|
262
|
+
const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
263
|
+
const encoded = encodeBinaryNodeInner(node, opts, buffer)
|
|
264
|
+
return Buffer.from(encoded)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
268
|
+
const { TAGS, TOKEN_MAP } = opts
|
|
269
|
+
const pushByte = (value) => buffer.push(value & 0xff)
|
|
270
|
+
const pushInt = (value, n, littleEndian = false) => {
|
|
271
|
+
for (let i = 0; i < n; i++) {
|
|
272
|
+
const curShift = littleEndian ? i : n - 1 - i
|
|
273
|
+
buffer.push((value >> (curShift * 8)) & 0xff)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const pushBytes = (bytes) => {
|
|
278
|
+
for (const b of bytes) {
|
|
279
|
+
buffer.push(b)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const pushInt16 = (value) => {
|
|
284
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff])
|
|
288
|
+
const writeByteLength = (length) => {
|
|
289
|
+
if (length >= 4294967296) {
|
|
290
|
+
throw new Error('string too large to encode: ' + length);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (length >= 1 << 20) {
|
|
294
|
+
pushByte(TAGS.BINARY_32)
|
|
295
|
+
pushInt(length, 4) // 32 bit integer
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
else if (length >= 256) {
|
|
299
|
+
pushByte(TAGS.BINARY_20)
|
|
300
|
+
pushInt20(length)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
else {
|
|
304
|
+
pushByte(TAGS.BINARY_8)
|
|
305
|
+
pushByte(length)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const writeStringRaw = (str) => {
|
|
310
|
+
const bytes = Buffer.from(str, 'utf-8')
|
|
311
|
+
|
|
312
|
+
writeByteLength(bytes.length)
|
|
313
|
+
pushBytes(bytes)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const writeJid = ({ domainType, device, user, server }) => {
|
|
317
|
+
if (typeof device !== 'undefined') {
|
|
318
|
+
pushByte(TAGS.AD_JID)
|
|
319
|
+
pushByte(domainType || 0)
|
|
320
|
+
pushByte(device || 0)
|
|
321
|
+
writeString(user)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
else {
|
|
325
|
+
pushByte(TAGS.JID_PAIR)
|
|
326
|
+
|
|
327
|
+
if (user.length) {
|
|
328
|
+
writeString(user)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
else {
|
|
332
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
writeString(server)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const packNibble = (char) => {
|
|
340
|
+
switch (char) {
|
|
341
|
+
case '-':
|
|
342
|
+
return 10
|
|
343
|
+
case '.':
|
|
344
|
+
return 11
|
|
345
|
+
case '\0':
|
|
346
|
+
return 15
|
|
347
|
+
default:
|
|
348
|
+
if (char >= '0' && char <= '9') {
|
|
349
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
throw new Error(`invalid byte for nibble "${char}"`)
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const packHex = (char) => {
|
|
357
|
+
if (char >= '0' && char <= '9') {
|
|
358
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (char >= 'A' && char <= 'F') {
|
|
362
|
+
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (char >= 'a' && char <= 'f') {
|
|
366
|
+
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (char === '\0') {
|
|
370
|
+
return 15
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
throw new Error(`Invalid hex char "${char}"`)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const writePackedBytes = (str, type) => {
|
|
377
|
+
if (str.length > TAGS.PACKED_MAX) {
|
|
378
|
+
throw new Error('Too many bytes to pack')
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
|
|
382
|
+
|
|
383
|
+
let roundedLength = Math.ceil(str.length / 2.0)
|
|
384
|
+
|
|
385
|
+
if (str.length % 2 !== 0) {
|
|
386
|
+
roundedLength |= 128
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
pushByte(roundedLength)
|
|
390
|
+
|
|
391
|
+
const packFunction = type === 'nibble' ? packNibble : packHex
|
|
392
|
+
const packBytePair = (v1, v2) => {
|
|
393
|
+
const result = (packFunction(v1) << 4) | packFunction(v2)
|
|
394
|
+
return result
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const strLengthHalf = Math.floor(str.length / 2)
|
|
398
|
+
|
|
399
|
+
for (let i = 0; i < strLengthHalf; i++) {
|
|
400
|
+
pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (str.length % 2 !== 0) {
|
|
404
|
+
pushByte(packBytePair(str[str.length - 1], '\x00'))
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const isNibble = (str) => {
|
|
409
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
410
|
+
return false
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
for (const char of str) {
|
|
414
|
+
const isInNibbleRange = char >= '0' && char <= '9'
|
|
415
|
+
|
|
416
|
+
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
417
|
+
return false
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return true
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const isHex = (str) => {
|
|
425
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
426
|
+
return false
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
for (const char of str) {
|
|
430
|
+
const isInNibbleRange = char >= '0' && char <= '9'
|
|
431
|
+
|
|
432
|
+
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
433
|
+
return false
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return true
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const writeString = (str) => {
|
|
441
|
+
if (str === undefined || str === null) {
|
|
442
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
443
|
+
return
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const tokenIndex = TOKEN_MAP[str]
|
|
447
|
+
|
|
448
|
+
if (tokenIndex) {
|
|
449
|
+
if (typeof tokenIndex.dict === 'number') {
|
|
450
|
+
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
pushByte(tokenIndex.index)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
else if (isNibble(str)) {
|
|
457
|
+
writePackedBytes(str, 'nibble')
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
else if (isHex(str)) {
|
|
461
|
+
writePackedBytes(str, 'hex')
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
else if (str) {
|
|
465
|
+
const decodedJid = jidDecode(str)
|
|
466
|
+
|
|
467
|
+
if (decodedJid) {
|
|
468
|
+
writeJid(decodedJid)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
else {
|
|
472
|
+
writeStringRaw(str)
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const writeListStart = (listSize) => {
|
|
478
|
+
if (listSize === 0) {
|
|
479
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
else if (listSize < 256) {
|
|
483
|
+
pushBytes([TAGS.LIST_8, listSize])
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
else {
|
|
487
|
+
pushByte(TAGS.LIST_16)
|
|
488
|
+
pushInt16(listSize)
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (!tag) {
|
|
493
|
+
throw new Error('Invalid node: tag cannot be undefined')
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null)
|
|
497
|
+
|
|
498
|
+
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0))
|
|
499
|
+
writeString(tag)
|
|
500
|
+
|
|
501
|
+
for (const key of validAttributes) {
|
|
502
|
+
if (typeof attrs[key] === 'string') {
|
|
503
|
+
writeString(key)
|
|
504
|
+
writeString(attrs[key])
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (typeof content === 'string') {
|
|
509
|
+
writeString(content)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
513
|
+
writeByteLength(content.length)
|
|
514
|
+
pushBytes(content)
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
else if (Array.isArray(content)) {
|
|
518
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'))
|
|
519
|
+
|
|
520
|
+
writeListStart(validContent.length)
|
|
521
|
+
|
|
522
|
+
for (const item of validContent) {
|
|
523
|
+
encodeBinaryNodeInner(item, opts, buffer)
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
else if (typeof content === 'undefined') {
|
|
528
|
+
// do nothing
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
else {
|
|
532
|
+
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return buffer
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
module.exports = {
|
|
539
|
+
encodeBinaryNode
|
|
540
|
+
}
|
|
541
|
+
return module.exports;
|
|
542
|
+
})();
|
|
543
|
+
for (const key of Object.keys(__kageModule83)) {
|
|
544
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule83[key]});
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// Kage: funciones avanzadas.
|
|
548
|
+
const __kageModule192 = (() => {
|
|
549
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
550
|
+
"use strict";
|
|
551
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
552
|
+
if (k2 === undefined) k2 = k;
|
|
553
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
554
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
555
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
556
|
+
}
|
|
557
|
+
Object.defineProperty(o, k2, desc);
|
|
558
|
+
}) : (function(o, m, k, k2) {
|
|
559
|
+
if (k2 === undefined) k2 = k;
|
|
560
|
+
o[k2] = m[k];
|
|
561
|
+
}));
|
|
562
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
563
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
564
|
+
}) : function(o, v) {
|
|
565
|
+
o["default"] = v;
|
|
566
|
+
});
|
|
567
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
568
|
+
var ownKeys = function(o) {
|
|
569
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
570
|
+
var ar = [];
|
|
571
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
572
|
+
return ar;
|
|
573
|
+
};
|
|
574
|
+
return ownKeys(o);
|
|
575
|
+
};
|
|
576
|
+
return function (mod) {
|
|
577
|
+
if (mod && mod.__esModule) return mod;
|
|
578
|
+
var result = {};
|
|
579
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
580
|
+
__setModuleDefault(result, mod);
|
|
581
|
+
return result;
|
|
582
|
+
};
|
|
583
|
+
})();
|
|
584
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
585
|
+
exports.encodeBinaryNode = void 0;
|
|
586
|
+
const constants = __importStar(require("./constants.js"));
|
|
587
|
+
const jid_utils_js_1 = require("./jid-utils.js");
|
|
588
|
+
const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
589
|
+
const encoded = encodeBinaryNodeInner(node, opts, buffer);
|
|
590
|
+
return Buffer.from(encoded);
|
|
591
|
+
};
|
|
592
|
+
exports.encodeBinaryNode = encodeBinaryNode;
|
|
593
|
+
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
594
|
+
const { TAGS, TOKEN_MAP } = opts;
|
|
595
|
+
const pushByte = (value) => buffer.push(value & 0xff);
|
|
596
|
+
const pushInt = (value, n, littleEndian = false) => {
|
|
597
|
+
for (let i = 0; i < n; i++) {
|
|
598
|
+
const curShift = littleEndian ? i : n - 1 - i;
|
|
599
|
+
buffer.push((value >> (curShift * 8)) & 0xff);
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
const pushBytes = (bytes) => {
|
|
603
|
+
for (const b of bytes) {
|
|
604
|
+
buffer.push(b);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
const pushInt16 = (value) => {
|
|
608
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
609
|
+
};
|
|
610
|
+
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
|
|
611
|
+
const writeByteLength = (length) => {
|
|
612
|
+
if (length >= 4294967296) {
|
|
613
|
+
throw new Error('string too large to encode: ' + length);
|
|
614
|
+
}
|
|
615
|
+
if (length >= 1 << 20) {
|
|
616
|
+
pushByte(TAGS.BINARY_32);
|
|
617
|
+
pushInt(length, 4); // 32 bit integer
|
|
618
|
+
}
|
|
619
|
+
else if (length >= 256) {
|
|
620
|
+
pushByte(TAGS.BINARY_20);
|
|
621
|
+
pushInt20(length);
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
pushByte(TAGS.BINARY_8);
|
|
625
|
+
pushByte(length);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
const writeStringRaw = (str) => {
|
|
629
|
+
const bytes = Buffer.from(str, 'utf-8');
|
|
630
|
+
writeByteLength(bytes.length);
|
|
631
|
+
pushBytes(bytes);
|
|
632
|
+
};
|
|
633
|
+
const writeJid = ({ domainType, device, user, server }) => {
|
|
634
|
+
if (typeof device !== 'undefined') {
|
|
635
|
+
pushByte(TAGS.AD_JID);
|
|
636
|
+
pushByte(domainType || 0);
|
|
637
|
+
pushByte(device || 0);
|
|
638
|
+
writeString(user);
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
pushByte(TAGS.JID_PAIR);
|
|
642
|
+
if (user.length) {
|
|
643
|
+
writeString(user);
|
|
644
|
+
}
|
|
645
|
+
else {
|
|
646
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
647
|
+
}
|
|
648
|
+
writeString(server);
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
const packNibble = (char) => {
|
|
652
|
+
switch (char) {
|
|
653
|
+
case '-':
|
|
654
|
+
return 10;
|
|
655
|
+
case '.':
|
|
656
|
+
return 11;
|
|
657
|
+
case '\0':
|
|
658
|
+
return 15;
|
|
659
|
+
default:
|
|
660
|
+
if (char >= '0' && char <= '9') {
|
|
661
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
662
|
+
}
|
|
663
|
+
throw new Error(`invalid byte for nibble "${char}"`);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
const packHex = (char) => {
|
|
667
|
+
if (char >= '0' && char <= '9') {
|
|
668
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
669
|
+
}
|
|
670
|
+
if (char >= 'A' && char <= 'F') {
|
|
671
|
+
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
|
|
672
|
+
}
|
|
673
|
+
if (char >= 'a' && char <= 'f') {
|
|
674
|
+
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
|
|
675
|
+
}
|
|
676
|
+
if (char === '\0') {
|
|
677
|
+
return 15;
|
|
678
|
+
}
|
|
679
|
+
throw new Error(`Invalid hex char "${char}"`);
|
|
680
|
+
};
|
|
681
|
+
const writePackedBytes = (str, type) => {
|
|
682
|
+
if (str.length > TAGS.PACKED_MAX) {
|
|
683
|
+
throw new Error('Too many bytes to pack');
|
|
684
|
+
}
|
|
685
|
+
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
|
|
686
|
+
let roundedLength = Math.ceil(str.length / 2.0);
|
|
687
|
+
if (str.length % 2 !== 0) {
|
|
688
|
+
roundedLength |= 128;
|
|
689
|
+
}
|
|
690
|
+
pushByte(roundedLength);
|
|
691
|
+
const packFunction = type === 'nibble' ? packNibble : packHex;
|
|
692
|
+
const packBytePair = (v1, v2) => {
|
|
693
|
+
const result = (packFunction(v1) << 4) | packFunction(v2);
|
|
694
|
+
return result;
|
|
695
|
+
};
|
|
696
|
+
const strLengthHalf = Math.floor(str.length / 2);
|
|
697
|
+
for (let i = 0; i < strLengthHalf; i++) {
|
|
698
|
+
pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
|
|
699
|
+
}
|
|
700
|
+
if (str.length % 2 !== 0) {
|
|
701
|
+
pushByte(packBytePair(str[str.length - 1], '\x00'));
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
const isNibble = (str) => {
|
|
705
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
for (const char of str) {
|
|
709
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
710
|
+
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return true;
|
|
715
|
+
};
|
|
716
|
+
const isHex = (str) => {
|
|
717
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
for (const char of str) {
|
|
721
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
722
|
+
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
723
|
+
return false;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return true;
|
|
727
|
+
};
|
|
728
|
+
const writeString = (str) => {
|
|
729
|
+
if (str === undefined || str === null) {
|
|
730
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (str === '') {
|
|
734
|
+
writeStringRaw(str);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
const tokenIndex = TOKEN_MAP[str];
|
|
738
|
+
if (tokenIndex) {
|
|
739
|
+
if (typeof tokenIndex.dict === 'number') {
|
|
740
|
+
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
|
|
741
|
+
}
|
|
742
|
+
pushByte(tokenIndex.index);
|
|
743
|
+
}
|
|
744
|
+
else if (isNibble(str)) {
|
|
745
|
+
writePackedBytes(str, 'nibble');
|
|
746
|
+
}
|
|
747
|
+
else if (isHex(str)) {
|
|
748
|
+
writePackedBytes(str, 'hex');
|
|
749
|
+
}
|
|
750
|
+
else {
|
|
751
|
+
const decodedJid = (0, jid_utils_js_1.jidDecode)(str);
|
|
752
|
+
if (decodedJid) {
|
|
753
|
+
writeJid(decodedJid);
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
writeStringRaw(str);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
const writeListStart = (listSize) => {
|
|
761
|
+
if (listSize === 0) {
|
|
762
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
763
|
+
}
|
|
764
|
+
else if (listSize < 256) {
|
|
765
|
+
pushBytes([TAGS.LIST_8, listSize]);
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
pushByte(TAGS.LIST_16);
|
|
769
|
+
pushInt16(listSize);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
if (!tag) {
|
|
773
|
+
throw new Error('Invalid node: tag cannot be undefined');
|
|
774
|
+
}
|
|
775
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
|
|
221
776
|
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
|
222
777
|
writeString(tag);
|
|
223
778
|
for (const key of validAttributes) {
|
|
@@ -248,3 +803,10 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
248
803
|
}
|
|
249
804
|
return buffer;
|
|
250
805
|
};
|
|
806
|
+
|
|
807
|
+
return module.exports;
|
|
808
|
+
})();
|
|
809
|
+
for (const key of Object.keys(__kageModule192)) {
|
|
810
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule192[key]});
|
|
811
|
+
}
|
|
812
|
+
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule192, configurable:true});
|