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