@hbmodsofc/baileys 1.5.2 → 1.7.6
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 +1 -1
- package/WAProto/index.js +19671 -152026
- package/engine-requirements.js +4 -4
- package/lib/Defaults/index.d.ts +12 -8
- package/lib/Defaults/index.js +90 -124
- package/lib/Signal/Group/group_cipher.d.ts +0 -1
- package/lib/Signal/Group/group_cipher.js +28 -39
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.js +9 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-state.d.ts +4 -4
- package/lib/Signal/Group/sender-key-state.js +47 -16
- package/lib/Signal/libsignal.d.ts +7 -3
- package/lib/Signal/libsignal.js +224 -39
- package/lib/Signal/lid-mapping.d.ts +26 -0
- package/lib/Signal/lid-mapping.js +146 -0
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -3
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +10 -16
- package/lib/Socket/business.d.ts +94 -78
- package/lib/Socket/business.js +130 -11
- package/lib/Socket/chats.d.ts +63 -233
- package/lib/Socket/chats.js +234 -184
- package/lib/Socket/communities.d.ts +232 -0
- package/lib/Socket/communities.js +402 -0
- package/lib/Socket/groups.d.ts +62 -41
- package/lib/Socket/groups.js +76 -64
- package/lib/Socket/index.d.ts +129 -83
- package/lib/Socket/index.js +13 -6
- package/lib/Socket/messages-recv.d.ts +59 -48
- package/lib/Socket/messages-recv.js +516 -371
- package/lib/Socket/messages-send.d.ts +86 -67
- package/lib/Socket/messages-send.js +1091 -1
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +76 -64
- package/lib/Socket/newsletter.js +184 -1
- package/lib/Socket/socket.d.ts +19 -13
- package/lib/Socket/socket.js +805 -1
- package/lib/Types/Auth.d.ts +4 -10
- package/lib/Types/Bussines.d.ts +24 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +29 -9
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +5 -1
- package/lib/Types/Events.d.ts +55 -14
- package/lib/Types/GroupMetadata.d.ts +15 -5
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +75 -49
- package/lib/Types/Message.js +10 -7
- package/lib/Types/Newsletter.d.ts +129 -98
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +29 -1
- package/lib/Types/Socket.d.ts +48 -22
- package/lib/Types/State.d.ts +13 -2
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +1 -1
- package/lib/Types/index.d.ts +10 -3
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +378 -102
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.d.ts +2 -2
- package/lib/Utils/business.js +19 -13
- package/lib/Utils/chat-utils.d.ts +21 -22
- package/lib/Utils/chat-utils.js +201 -154
- package/lib/Utils/crypto.d.ts +18 -19
- package/lib/Utils/crypto.js +78 -37
- package/lib/Utils/decode-wa-message.d.ts +34 -7
- package/lib/Utils/decode-wa-message.js +138 -66
- package/lib/Utils/event-buffer.d.ts +6 -8
- package/lib/Utils/event-buffer.js +81 -43
- package/lib/Utils/generics.d.ts +27 -27
- package/lib/Utils/generics.js +128 -133
- package/lib/Utils/history.d.ts +9 -5
- package/lib/Utils/history.js +17 -23
- package/lib/Utils/index.d.ts +2 -0
- package/lib/Utils/index.js +2 -0
- package/lib/Utils/lidToJid-test.d.ts +11 -0
- package/lib/Utils/lidToJid-test.js +27 -0
- package/lib/Utils/link-preview.d.ts +4 -4
- package/lib/Utils/link-preview.js +40 -12
- package/lib/Utils/logger.d.ts +11 -3
- package/lib/Utils/lt-hash.d.ts +8 -8
- package/lib/Utils/lt-hash.js +23 -24
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +3 -2
- package/lib/Utils/message-retry-manager.d.ts +81 -0
- package/lib/Utils/message-retry-manager.js +152 -0
- package/lib/Utils/messages-media.d.ts +37 -41
- package/lib/Utils/messages-media.js +252 -368
- package/lib/Utils/messages.d.ts +13 -15
- package/lib/Utils/messages.js +274 -261
- package/lib/Utils/noise-handler.d.ts +13 -15
- package/lib/Utils/noise-handler.js +20 -26
- package/lib/Utils/process-message.d.ts +9 -8
- package/lib/Utils/process-message.js +157 -93
- package/lib/Utils/signal.d.ts +6 -5
- package/lib/Utils/signal.js +37 -29
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +12 -7
- package/lib/Utils/validate-connection.d.ts +5 -6
- package/lib/Utils/validate-connection.js +39 -97
- package/lib/WABinary/constants.d.ts +24 -27
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.d.ts +3 -4
- package/lib/WABinary/decode.js +28 -14
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +134 -147
- package/lib/WABinary/generic-utils.d.ts +4 -7
- package/lib/WABinary/generic-utils.js +40 -125
- package/lib/WABinary/jid-utils.d.ts +13 -8
- package/lib/WABinary/jid-utils.js +27 -16
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/constants.d.ts +3 -2
- package/lib/WAM/constants.js +2252 -2359
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.js +8 -11
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -4
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -6
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/USyncQuery.d.ts +2 -2
- package/lib/WAUSync/USyncQuery.js +19 -15
- package/lib/WAUSync/USyncUser.d.ts +5 -5
- package/lib/WAUSync/index.d.ts +1 -1
- package/lib/WAUSync/index.js +1 -1
- package/package.json +102 -102
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/hbmods.d.ts +0 -253
- package/lib/Socket/hbmods.js +0 -1
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
package/lib/WABinary/decode.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
|
3
|
-
export declare const decompressingIfRequired: (buffer: Buffer) => Buffer
|
|
4
|
-
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions,
|
|
2
|
+
export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer<ArrayBufferLike>>;
|
|
3
|
+
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
|
|
5
4
|
index: number;
|
|
6
5
|
}) => BinaryNode;
|
|
7
|
-
export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode
|
|
6
|
+
export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -15,23 +15,36 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
|
|
37
|
+
const util_1 = require("util");
|
|
27
38
|
const zlib_1 = require("zlib");
|
|
28
39
|
const constants = __importStar(require("./constants"));
|
|
29
40
|
const jid_utils_1 = require("./jid-utils");
|
|
30
|
-
const
|
|
41
|
+
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
42
|
+
const decompressingIfRequired = async (buffer) => {
|
|
31
43
|
if (2 & buffer.readUInt8()) {
|
|
32
|
-
buffer =
|
|
44
|
+
buffer = await inflatePromise(buffer.slice(1));
|
|
33
45
|
}
|
|
34
|
-
else {
|
|
46
|
+
else {
|
|
47
|
+
// nodes with no compression have a 0x00 prefix, we remove that
|
|
35
48
|
buffer = buffer.slice(1);
|
|
36
49
|
}
|
|
37
50
|
return buffer;
|
|
@@ -144,10 +157,11 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
144
157
|
throw new Error('invalid jid pair: ' + i + ', ' + j);
|
|
145
158
|
};
|
|
146
159
|
const readAdJid = () => {
|
|
147
|
-
const
|
|
160
|
+
const rawDomainType = readByte();
|
|
161
|
+
const domainType = Number(rawDomainType);
|
|
148
162
|
const device = readByte();
|
|
149
163
|
const user = readString(readByte());
|
|
150
|
-
return (0, jid_utils_1.jidEncode)(user,
|
|
164
|
+
return (0, jid_utils_1.jidEncode)(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
|
|
151
165
|
};
|
|
152
166
|
const readString = (tag) => {
|
|
153
167
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
@@ -245,8 +259,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
245
259
|
};
|
|
246
260
|
};
|
|
247
261
|
exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
|
|
248
|
-
const decodeBinaryNode = (buff) => {
|
|
249
|
-
const decompBuff = (0, exports.decompressingIfRequired)(buff);
|
|
262
|
+
const decodeBinaryNode = async (buff) => {
|
|
263
|
+
const decompBuff = await (0, exports.decompressingIfRequired)(buff);
|
|
250
264
|
return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
|
|
251
265
|
};
|
|
252
266
|
exports.decodeBinaryNode = decodeBinaryNode;
|
package/lib/WABinary/encode.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
|
3
|
-
export declare const encodeBinaryNode: (
|
|
2
|
+
export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -1,265 +1,252 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
3
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
5
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
7
|
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
10
9
|
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
15
13
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
15
|
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.encodeBinaryNode = void 0;
|
|
37
|
+
const constants = __importStar(require("./constants"));
|
|
38
|
+
const jid_utils_1 = require("./jid-utils");
|
|
34
39
|
const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
35
|
-
const encoded = encodeBinaryNodeInner(node, opts, buffer)
|
|
36
|
-
return Buffer.from(encoded)
|
|
37
|
-
}
|
|
38
|
-
|
|
40
|
+
const encoded = encodeBinaryNodeInner(node, opts, buffer);
|
|
41
|
+
return Buffer.from(encoded);
|
|
42
|
+
};
|
|
43
|
+
exports.encodeBinaryNode = encodeBinaryNode;
|
|
39
44
|
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
40
|
-
const { TAGS, TOKEN_MAP } = opts
|
|
41
|
-
const pushByte = (value) => buffer.push(value & 0xff)
|
|
45
|
+
const { TAGS, TOKEN_MAP } = opts;
|
|
46
|
+
const pushByte = (value) => buffer.push(value & 0xff);
|
|
42
47
|
const pushInt = (value, n, littleEndian = false) => {
|
|
43
48
|
for (let i = 0; i < n; i++) {
|
|
44
|
-
const curShift = littleEndian ? i : n - 1 - i
|
|
45
|
-
buffer.push((value >> (curShift * 8)) & 0xff)
|
|
49
|
+
const curShift = littleEndian ? i : n - 1 - i;
|
|
50
|
+
buffer.push((value >> (curShift * 8)) & 0xff);
|
|
46
51
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
52
|
+
};
|
|
49
53
|
const pushBytes = (bytes) => {
|
|
50
54
|
for (const b of bytes) {
|
|
51
|
-
buffer.push(b)
|
|
55
|
+
buffer.push(b);
|
|
52
56
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
57
|
+
};
|
|
55
58
|
const pushInt16 = (value) => {
|
|
56
|
-
pushBytes([(value >> 8) & 0xff, value & 0xff])
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]))
|
|
59
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
60
|
+
};
|
|
61
|
+
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
|
|
60
62
|
const writeByteLength = (length) => {
|
|
61
63
|
if (length >= 4294967296) {
|
|
62
|
-
throw new Error('string too large to encode: ' + length)
|
|
64
|
+
throw new Error('string too large to encode: ' + length);
|
|
63
65
|
}
|
|
64
66
|
if (length >= 1 << 20) {
|
|
65
|
-
pushByte(TAGS.BINARY_32)
|
|
66
|
-
pushInt(length, 4) // 32 bit integer
|
|
67
|
+
pushByte(TAGS.BINARY_32);
|
|
68
|
+
pushInt(length, 4); // 32 bit integer
|
|
67
69
|
}
|
|
68
70
|
else if (length >= 256) {
|
|
69
|
-
pushByte(TAGS.BINARY_20)
|
|
70
|
-
pushInt20(length)
|
|
71
|
+
pushByte(TAGS.BINARY_20);
|
|
72
|
+
pushInt20(length);
|
|
71
73
|
}
|
|
72
74
|
else {
|
|
73
|
-
pushByte(TAGS.BINARY_8)
|
|
74
|
-
pushByte(length)
|
|
75
|
+
pushByte(TAGS.BINARY_8);
|
|
76
|
+
pushByte(length);
|
|
75
77
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
+
};
|
|
78
79
|
const writeStringRaw = (str) => {
|
|
79
|
-
const bytes = Buffer.from(str, 'utf-8')
|
|
80
|
-
writeByteLength(bytes.length)
|
|
81
|
-
pushBytes(bytes)
|
|
82
|
-
}
|
|
83
|
-
|
|
80
|
+
const bytes = Buffer.from(str, 'utf-8');
|
|
81
|
+
writeByteLength(bytes.length);
|
|
82
|
+
pushBytes(bytes);
|
|
83
|
+
};
|
|
84
84
|
const writeJid = ({ domainType, device, user, server }) => {
|
|
85
85
|
if (typeof device !== 'undefined') {
|
|
86
|
-
pushByte(TAGS.AD_JID)
|
|
87
|
-
pushByte(domainType || 0)
|
|
88
|
-
pushByte(device || 0)
|
|
89
|
-
writeString(user)
|
|
86
|
+
pushByte(TAGS.AD_JID);
|
|
87
|
+
pushByte(domainType || 0);
|
|
88
|
+
pushByte(device || 0);
|
|
89
|
+
writeString(user);
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
|
-
pushByte(TAGS.JID_PAIR)
|
|
92
|
+
pushByte(TAGS.JID_PAIR);
|
|
93
93
|
if (user.length) {
|
|
94
|
-
writeString(user)
|
|
94
|
+
writeString(user);
|
|
95
95
|
}
|
|
96
96
|
else {
|
|
97
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
97
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
98
98
|
}
|
|
99
|
-
writeString(server)
|
|
99
|
+
writeString(server);
|
|
100
100
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
101
|
+
};
|
|
103
102
|
const packNibble = (char) => {
|
|
104
103
|
switch (char) {
|
|
105
104
|
case '-':
|
|
106
|
-
return 10
|
|
105
|
+
return 10;
|
|
107
106
|
case '.':
|
|
108
|
-
return 11
|
|
107
|
+
return 11;
|
|
109
108
|
case '\0':
|
|
110
|
-
return 15
|
|
109
|
+
return 15;
|
|
111
110
|
default:
|
|
112
111
|
if (char >= '0' && char <= '9') {
|
|
113
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
112
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
114
113
|
}
|
|
115
|
-
throw new Error(`invalid byte for nibble "${char}"`)
|
|
114
|
+
throw new Error(`invalid byte for nibble "${char}"`);
|
|
116
115
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
116
|
+
};
|
|
119
117
|
const packHex = (char) => {
|
|
120
118
|
if (char >= '0' && char <= '9') {
|
|
121
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
119
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
122
120
|
}
|
|
123
121
|
if (char >= 'A' && char <= 'F') {
|
|
124
|
-
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
|
|
122
|
+
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
|
|
125
123
|
}
|
|
126
124
|
if (char >= 'a' && char <= 'f') {
|
|
127
|
-
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
|
|
125
|
+
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
|
|
128
126
|
}
|
|
129
127
|
if (char === '\0') {
|
|
130
|
-
return 15
|
|
128
|
+
return 15;
|
|
131
129
|
}
|
|
132
|
-
throw new Error(`Invalid hex char "${char}"`)
|
|
133
|
-
}
|
|
134
|
-
|
|
130
|
+
throw new Error(`Invalid hex char "${char}"`);
|
|
131
|
+
};
|
|
135
132
|
const writePackedBytes = (str, type) => {
|
|
136
133
|
if (str.length > TAGS.PACKED_MAX) {
|
|
137
|
-
throw new Error('Too many bytes to pack')
|
|
134
|
+
throw new Error('Too many bytes to pack');
|
|
138
135
|
}
|
|
139
|
-
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
|
|
140
|
-
let roundedLength = Math.ceil(str.length / 2.0)
|
|
136
|
+
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
|
|
137
|
+
let roundedLength = Math.ceil(str.length / 2.0);
|
|
141
138
|
if (str.length % 2 !== 0) {
|
|
142
|
-
roundedLength |= 128
|
|
139
|
+
roundedLength |= 128;
|
|
143
140
|
}
|
|
144
|
-
pushByte(roundedLength)
|
|
145
|
-
const packFunction = type === 'nibble' ? packNibble : packHex
|
|
141
|
+
pushByte(roundedLength);
|
|
142
|
+
const packFunction = type === 'nibble' ? packNibble : packHex;
|
|
146
143
|
const packBytePair = (v1, v2) => {
|
|
147
|
-
const result = (packFunction(v1) << 4) | packFunction(v2)
|
|
148
|
-
return result
|
|
149
|
-
}
|
|
150
|
-
const strLengthHalf = Math.floor(str.length / 2)
|
|
144
|
+
const result = (packFunction(v1) << 4) | packFunction(v2);
|
|
145
|
+
return result;
|
|
146
|
+
};
|
|
147
|
+
const strLengthHalf = Math.floor(str.length / 2);
|
|
151
148
|
for (let i = 0; i < strLengthHalf; i++) {
|
|
152
|
-
pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
|
|
149
|
+
pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
|
|
153
150
|
}
|
|
154
151
|
if (str.length % 2 !== 0) {
|
|
155
|
-
pushByte(packBytePair(str[str.length - 1], '\x00'))
|
|
152
|
+
pushByte(packBytePair(str[str.length - 1], '\x00'));
|
|
156
153
|
}
|
|
157
|
-
}
|
|
158
|
-
|
|
154
|
+
};
|
|
159
155
|
const isNibble = (str) => {
|
|
160
156
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
161
|
-
return false
|
|
157
|
+
return false;
|
|
162
158
|
}
|
|
163
159
|
for (const char of str) {
|
|
164
|
-
const isInNibbleRange = char >= '0' && char <= '9'
|
|
160
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
165
161
|
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
166
|
-
return false
|
|
162
|
+
return false;
|
|
167
163
|
}
|
|
168
164
|
}
|
|
169
|
-
return true
|
|
170
|
-
}
|
|
171
|
-
|
|
165
|
+
return true;
|
|
166
|
+
};
|
|
172
167
|
const isHex = (str) => {
|
|
173
168
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
174
|
-
return false
|
|
169
|
+
return false;
|
|
175
170
|
}
|
|
176
171
|
for (const char of str) {
|
|
177
|
-
const isInNibbleRange = char >= '0' && char <= '9'
|
|
172
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
178
173
|
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
179
|
-
return false
|
|
174
|
+
return false;
|
|
180
175
|
}
|
|
181
176
|
}
|
|
182
|
-
return true
|
|
183
|
-
}
|
|
184
|
-
|
|
177
|
+
return true;
|
|
178
|
+
};
|
|
185
179
|
const writeString = (str) => {
|
|
186
|
-
|
|
187
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
188
|
-
return
|
|
180
|
+
if (str === undefined || str === null) {
|
|
181
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
182
|
+
return;
|
|
189
183
|
}
|
|
190
|
-
const tokenIndex = TOKEN_MAP[str]
|
|
184
|
+
const tokenIndex = TOKEN_MAP[str];
|
|
191
185
|
if (tokenIndex) {
|
|
192
186
|
if (typeof tokenIndex.dict === 'number') {
|
|
193
|
-
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
|
|
187
|
+
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
|
|
194
188
|
}
|
|
195
|
-
pushByte(tokenIndex.index)
|
|
189
|
+
pushByte(tokenIndex.index);
|
|
196
190
|
}
|
|
197
191
|
else if (isNibble(str)) {
|
|
198
|
-
writePackedBytes(str, 'nibble')
|
|
192
|
+
writePackedBytes(str, 'nibble');
|
|
199
193
|
}
|
|
200
194
|
else if (isHex(str)) {
|
|
201
|
-
writePackedBytes(str, 'hex')
|
|
195
|
+
writePackedBytes(str, 'hex');
|
|
202
196
|
}
|
|
203
197
|
else if (str) {
|
|
204
|
-
const decodedJid = (0, jid_utils_1.jidDecode)(str)
|
|
198
|
+
const decodedJid = (0, jid_utils_1.jidDecode)(str);
|
|
205
199
|
if (decodedJid) {
|
|
206
|
-
writeJid(decodedJid)
|
|
200
|
+
writeJid(decodedJid);
|
|
207
201
|
}
|
|
208
202
|
else {
|
|
209
|
-
writeStringRaw(str)
|
|
203
|
+
writeStringRaw(str);
|
|
210
204
|
}
|
|
211
205
|
}
|
|
212
|
-
}
|
|
213
|
-
|
|
206
|
+
};
|
|
214
207
|
const writeListStart = (listSize) => {
|
|
215
208
|
if (listSize === 0) {
|
|
216
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
209
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
217
210
|
}
|
|
218
211
|
else if (listSize < 256) {
|
|
219
|
-
pushBytes([TAGS.LIST_8, listSize])
|
|
212
|
+
pushBytes([TAGS.LIST_8, listSize]);
|
|
220
213
|
}
|
|
221
214
|
else {
|
|
222
|
-
pushByte(TAGS.LIST_16)
|
|
223
|
-
pushInt16(listSize)
|
|
215
|
+
pushByte(TAGS.LIST_16);
|
|
216
|
+
pushInt16(listSize);
|
|
224
217
|
}
|
|
225
|
-
}
|
|
226
|
-
|
|
218
|
+
};
|
|
227
219
|
if (!tag) {
|
|
228
|
-
throw new Error('Invalid node: tag cannot be undefined')
|
|
220
|
+
throw new Error('Invalid node: tag cannot be undefined');
|
|
229
221
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
writeString(tag)
|
|
222
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
|
|
223
|
+
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
|
224
|
+
writeString(tag);
|
|
234
225
|
for (const key of validAttributes) {
|
|
235
226
|
if (typeof attrs[key] === 'string') {
|
|
236
|
-
writeString(key)
|
|
237
|
-
writeString(attrs[key])
|
|
227
|
+
writeString(key);
|
|
228
|
+
writeString(attrs[key]);
|
|
238
229
|
}
|
|
239
230
|
}
|
|
240
231
|
if (typeof content === 'string') {
|
|
241
|
-
writeString(content)
|
|
232
|
+
writeString(content);
|
|
242
233
|
}
|
|
243
234
|
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
244
|
-
writeByteLength(content.length)
|
|
245
|
-
pushBytes(content)
|
|
235
|
+
writeByteLength(content.length);
|
|
236
|
+
pushBytes(content);
|
|
246
237
|
}
|
|
247
238
|
else if (Array.isArray(content)) {
|
|
248
|
-
|
|
249
|
-
writeListStart(validContent.length)
|
|
239
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
|
|
240
|
+
writeListStart(validContent.length);
|
|
250
241
|
for (const item of validContent) {
|
|
251
|
-
encodeBinaryNodeInner(item, opts, buffer)
|
|
242
|
+
encodeBinaryNodeInner(item, opts, buffer);
|
|
252
243
|
}
|
|
253
244
|
}
|
|
254
245
|
else if (typeof content === 'undefined') {
|
|
255
246
|
// do nothing
|
|
256
247
|
}
|
|
257
248
|
else {
|
|
258
|
-
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
249
|
+
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
259
250
|
}
|
|
260
|
-
return buffer
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
module.exports = {
|
|
264
|
-
encodeBinaryNode
|
|
265
|
-
}
|
|
251
|
+
return buffer;
|
|
252
|
+
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { BinaryNode } from './types';
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { type BinaryNode } from './types';
|
|
4
3
|
export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
|
|
5
4
|
export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
|
|
6
5
|
export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
|
|
7
|
-
export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
|
|
6
|
+
export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | undefined;
|
|
8
7
|
export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
|
|
9
8
|
export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
|
|
10
9
|
export declare const assertNodeErrorFree: (node: BinaryNode) => void;
|
|
@@ -12,6 +11,4 @@ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: strin
|
|
|
12
11
|
[_: string]: string;
|
|
13
12
|
};
|
|
14
13
|
export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
|
|
15
|
-
export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number):
|
|
16
|
-
export declare const getBinaryNodeFilter: (node: BinaryNode[]) => boolean;
|
|
17
|
-
export declare const getAdditionalNode: (name: string) => BinaryNode[];
|
|
14
|
+
export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): string;
|