alipclutch-baileys 6.7.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/WAProto/index.js +77698 -117050
- package/engine-requirements.js +3 -3
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +6 -4
- package/lib/Defaults/index.js +118 -78
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- 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/types.d.ts +1 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.d.ts +1 -0
- package/lib/Socket/Client/websocket.js +1 -0
- package/lib/Socket/business.d.ts +58 -59
- package/lib/Socket/chats.d.ts +230 -45
- package/lib/Socket/chats.js +238 -139
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +483 -0
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +23 -38
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +420 -382
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +124 -71
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +38 -62
- package/lib/Socket/usync.d.ts +4 -3
- package/lib/Socket/usync.js +1 -0
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +14 -26
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +7 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -14
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +2 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +21 -148
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +97 -73
- package/lib/Types/Newsletter.js +38 -18
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -8
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +16 -15
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +6 -22
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -11
- package/lib/Utils/generics.d.ts +20 -17
- package/lib/Utils/generics.js +76 -96
- package/lib/Utils/history.d.ts +0 -4
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +24 -28
- package/lib/Utils/messages-media.js +236 -296
- package/lib/Utils/messages.d.ts +10 -13
- package/lib/Utils/messages.js +92 -325
- package/lib/Utils/noise-handler.d.ts +12 -10
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +25 -108
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +6 -51
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +52 -20
- 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 +13 -26
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +152 -137
- package/lib/WABinary/generic-utils.d.ts +4 -1
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +5 -11
- package/lib/WABinary/jid-utils.js +5 -28
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +36 -43
- package/package.json +1 -1
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/WAProto/p.html +0 -1
- package/lib/Defaults/wileys-version.json +0 -3
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/{README.MD → README.md} +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,33 +15,21 @@ 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
34
|
else { // nodes with no compression have a 0x00 prefix, we remove that
|
|
47
35
|
buffer = buffer.slice(1);
|
|
@@ -156,11 +144,10 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
156
144
|
throw new Error('invalid jid pair: ' + i + ', ' + j);
|
|
157
145
|
};
|
|
158
146
|
const readAdJid = () => {
|
|
159
|
-
const
|
|
160
|
-
const domainType = Number(rawDomainType);
|
|
147
|
+
const agent = readByte();
|
|
161
148
|
const device = readByte();
|
|
162
149
|
const user = readString(readByte());
|
|
163
|
-
return (0, jid_utils_1.jidEncode)(user,
|
|
150
|
+
return (0, jid_utils_1.jidEncode)(user, agent === 0 ? 's.whatsapp.net' : 'lid', device);
|
|
164
151
|
};
|
|
165
152
|
const readString = (tag) => {
|
|
166
153
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
@@ -258,8 +245,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
258
245
|
};
|
|
259
246
|
};
|
|
260
247
|
exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
|
|
261
|
-
const decodeBinaryNode =
|
|
262
|
-
const decompBuff =
|
|
248
|
+
const decodeBinaryNode = (buff) => {
|
|
249
|
+
const decompBuff = (0, exports.decompressingIfRequired)(buff);
|
|
263
250
|
return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
|
|
264
251
|
};
|
|
265
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,250 +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
|
-
}
|
|
53
|
-
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const pushBytes = (bytes) => {
|
|
50
|
+
for (const b of bytes) {
|
|
51
|
+
buffer.push(b)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
54
55
|
const pushInt16 = (value) => {
|
|
55
|
-
pushBytes([(value >> 8) & 0xff, value & 0xff])
|
|
56
|
-
}
|
|
57
|
-
|
|
56
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]))
|
|
58
60
|
const writeByteLength = (length) => {
|
|
59
61
|
if (length >= 4294967296) {
|
|
60
|
-
throw new Error('string too large to encode: ' + length)
|
|
62
|
+
throw new Error('string too large to encode: ' + length)
|
|
61
63
|
}
|
|
62
64
|
if (length >= 1 << 20) {
|
|
63
|
-
pushByte(TAGS.BINARY_32)
|
|
64
|
-
pushInt(length, 4)
|
|
65
|
+
pushByte(TAGS.BINARY_32)
|
|
66
|
+
pushInt(length, 4) // 32 bit integer
|
|
65
67
|
}
|
|
66
68
|
else if (length >= 256) {
|
|
67
|
-
pushByte(TAGS.BINARY_20)
|
|
68
|
-
pushInt20(length)
|
|
69
|
+
pushByte(TAGS.BINARY_20)
|
|
70
|
+
pushInt20(length)
|
|
69
71
|
}
|
|
70
72
|
else {
|
|
71
|
-
pushByte(TAGS.BINARY_8)
|
|
72
|
-
pushByte(length)
|
|
73
|
+
pushByte(TAGS.BINARY_8)
|
|
74
|
+
pushByte(length)
|
|
73
75
|
}
|
|
74
|
-
}
|
|
76
|
+
}
|
|
77
|
+
|
|
75
78
|
const writeStringRaw = (str) => {
|
|
76
|
-
const bytes = Buffer.from(str, 'utf-8')
|
|
77
|
-
writeByteLength(bytes.length)
|
|
78
|
-
pushBytes(bytes)
|
|
79
|
-
}
|
|
79
|
+
const bytes = Buffer.from(str, 'utf-8')
|
|
80
|
+
writeByteLength(bytes.length)
|
|
81
|
+
pushBytes(bytes)
|
|
82
|
+
}
|
|
83
|
+
|
|
80
84
|
const writeJid = ({ domainType, device, user, server }) => {
|
|
81
85
|
if (typeof device !== 'undefined') {
|
|
82
|
-
pushByte(TAGS.AD_JID)
|
|
83
|
-
pushByte(domainType || 0)
|
|
84
|
-
pushByte(device || 0)
|
|
85
|
-
writeString(user)
|
|
86
|
+
pushByte(TAGS.AD_JID)
|
|
87
|
+
pushByte(domainType || 0)
|
|
88
|
+
pushByte(device || 0)
|
|
89
|
+
writeString(user)
|
|
86
90
|
}
|
|
87
91
|
else {
|
|
88
|
-
pushByte(TAGS.JID_PAIR)
|
|
92
|
+
pushByte(TAGS.JID_PAIR)
|
|
89
93
|
if (user.length) {
|
|
90
|
-
writeString(user)
|
|
94
|
+
writeString(user)
|
|
91
95
|
}
|
|
92
96
|
else {
|
|
93
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
97
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
94
98
|
}
|
|
95
|
-
writeString(server)
|
|
99
|
+
writeString(server)
|
|
96
100
|
}
|
|
97
|
-
}
|
|
101
|
+
}
|
|
102
|
+
|
|
98
103
|
const packNibble = (char) => {
|
|
99
104
|
switch (char) {
|
|
100
105
|
case '-':
|
|
101
|
-
return 10
|
|
106
|
+
return 10
|
|
102
107
|
case '.':
|
|
103
|
-
return 11
|
|
108
|
+
return 11
|
|
104
109
|
case '\0':
|
|
105
|
-
return 15
|
|
110
|
+
return 15
|
|
106
111
|
default:
|
|
107
112
|
if (char >= '0' && char <= '9') {
|
|
108
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
113
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
109
114
|
}
|
|
110
|
-
throw new Error(`invalid byte for nibble "${char}"`)
|
|
115
|
+
throw new Error(`invalid byte for nibble "${char}"`)
|
|
111
116
|
}
|
|
112
|
-
}
|
|
117
|
+
}
|
|
118
|
+
|
|
113
119
|
const packHex = (char) => {
|
|
114
120
|
if (char >= '0' && char <= '9') {
|
|
115
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
121
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
116
122
|
}
|
|
117
123
|
if (char >= 'A' && char <= 'F') {
|
|
118
|
-
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
|
|
124
|
+
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
|
|
119
125
|
}
|
|
120
126
|
if (char >= 'a' && char <= 'f') {
|
|
121
|
-
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
|
|
127
|
+
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
|
|
122
128
|
}
|
|
123
129
|
if (char === '\0') {
|
|
124
|
-
return 15
|
|
130
|
+
return 15
|
|
125
131
|
}
|
|
126
|
-
throw new Error(`Invalid hex char "${char}"`)
|
|
127
|
-
}
|
|
132
|
+
throw new Error(`Invalid hex char "${char}"`)
|
|
133
|
+
}
|
|
134
|
+
|
|
128
135
|
const writePackedBytes = (str, type) => {
|
|
129
136
|
if (str.length > TAGS.PACKED_MAX) {
|
|
130
|
-
throw new Error('Too many bytes to pack')
|
|
137
|
+
throw new Error('Too many bytes to pack')
|
|
131
138
|
}
|
|
132
|
-
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
|
|
133
|
-
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)
|
|
134
141
|
if (str.length % 2 !== 0) {
|
|
135
|
-
roundedLength |= 128
|
|
142
|
+
roundedLength |= 128
|
|
136
143
|
}
|
|
137
|
-
pushByte(roundedLength)
|
|
138
|
-
const packFunction = type === 'nibble' ? packNibble : packHex
|
|
144
|
+
pushByte(roundedLength)
|
|
145
|
+
const packFunction = type === 'nibble' ? packNibble : packHex
|
|
139
146
|
const packBytePair = (v1, v2) => {
|
|
140
|
-
const result = (packFunction(v1) << 4) | packFunction(v2)
|
|
141
|
-
return result
|
|
142
|
-
}
|
|
143
|
-
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)
|
|
144
151
|
for (let i = 0; i < strLengthHalf; i++) {
|
|
145
|
-
pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
|
|
152
|
+
pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
|
|
146
153
|
}
|
|
147
154
|
if (str.length % 2 !== 0) {
|
|
148
|
-
pushByte(packBytePair(str[str.length - 1], '\x00'))
|
|
155
|
+
pushByte(packBytePair(str[str.length - 1], '\x00'))
|
|
149
156
|
}
|
|
150
|
-
}
|
|
157
|
+
}
|
|
158
|
+
|
|
151
159
|
const isNibble = (str) => {
|
|
152
160
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
153
|
-
return false
|
|
161
|
+
return false
|
|
154
162
|
}
|
|
155
|
-
for (
|
|
156
|
-
const
|
|
157
|
-
const isInNibbleRange = char >= '0' && char <= '9';
|
|
163
|
+
for (const char of str) {
|
|
164
|
+
const isInNibbleRange = char >= '0' && char <= '9'
|
|
158
165
|
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
159
|
-
return false
|
|
166
|
+
return false
|
|
160
167
|
}
|
|
161
168
|
}
|
|
162
|
-
return true
|
|
163
|
-
}
|
|
169
|
+
return true
|
|
170
|
+
}
|
|
171
|
+
|
|
164
172
|
const isHex = (str) => {
|
|
165
173
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
166
|
-
return false
|
|
174
|
+
return false
|
|
167
175
|
}
|
|
168
|
-
for (
|
|
169
|
-
const
|
|
170
|
-
const isInNibbleRange = char >= '0' && char <= '9';
|
|
176
|
+
for (const char of str) {
|
|
177
|
+
const isInNibbleRange = char >= '0' && char <= '9'
|
|
171
178
|
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
172
|
-
return false
|
|
179
|
+
return false
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
|
-
return true
|
|
176
|
-
}
|
|
182
|
+
return true
|
|
183
|
+
}
|
|
184
|
+
|
|
177
185
|
const writeString = (str) => {
|
|
178
|
-
|
|
179
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
180
|
-
return
|
|
186
|
+
if (str === undefined || str === null) {
|
|
187
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
188
|
+
return
|
|
181
189
|
}
|
|
182
|
-
const tokenIndex = TOKEN_MAP[str]
|
|
190
|
+
const tokenIndex = TOKEN_MAP[str]
|
|
183
191
|
if (tokenIndex) {
|
|
184
192
|
if (typeof tokenIndex.dict === 'number') {
|
|
185
|
-
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
|
|
193
|
+
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
|
|
186
194
|
}
|
|
187
|
-
pushByte(tokenIndex.index)
|
|
195
|
+
pushByte(tokenIndex.index)
|
|
188
196
|
}
|
|
189
197
|
else if (isNibble(str)) {
|
|
190
|
-
writePackedBytes(str, 'nibble')
|
|
198
|
+
writePackedBytes(str, 'nibble')
|
|
191
199
|
}
|
|
192
200
|
else if (isHex(str)) {
|
|
193
|
-
writePackedBytes(str, 'hex')
|
|
201
|
+
writePackedBytes(str, 'hex')
|
|
194
202
|
}
|
|
195
203
|
else if (str) {
|
|
196
|
-
const decodedJid = (0, jid_utils_1.jidDecode)(str)
|
|
204
|
+
const decodedJid = (0, jid_utils_1.jidDecode)(str)
|
|
197
205
|
if (decodedJid) {
|
|
198
|
-
writeJid(decodedJid)
|
|
206
|
+
writeJid(decodedJid)
|
|
199
207
|
}
|
|
200
208
|
else {
|
|
201
|
-
writeStringRaw(str)
|
|
209
|
+
writeStringRaw(str)
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
|
-
}
|
|
212
|
+
}
|
|
213
|
+
|
|
205
214
|
const writeListStart = (listSize) => {
|
|
206
215
|
if (listSize === 0) {
|
|
207
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
216
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
208
217
|
}
|
|
209
218
|
else if (listSize < 256) {
|
|
210
|
-
pushBytes([TAGS.LIST_8, listSize])
|
|
219
|
+
pushBytes([TAGS.LIST_8, listSize])
|
|
211
220
|
}
|
|
212
221
|
else {
|
|
213
|
-
pushByte(TAGS.LIST_16)
|
|
214
|
-
pushInt16(listSize)
|
|
222
|
+
pushByte(TAGS.LIST_16)
|
|
223
|
+
pushInt16(listSize)
|
|
215
224
|
}
|
|
216
|
-
}
|
|
225
|
+
}
|
|
226
|
+
|
|
217
227
|
if (!tag) {
|
|
218
|
-
throw new Error('Invalid node: tag cannot be undefined')
|
|
228
|
+
throw new Error('Invalid node: tag cannot be undefined')
|
|
219
229
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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)
|
|
223
234
|
for (const key of validAttributes) {
|
|
224
235
|
if (typeof attrs[key] === 'string') {
|
|
225
|
-
writeString(key)
|
|
226
|
-
writeString(attrs[key])
|
|
236
|
+
writeString(key)
|
|
237
|
+
writeString(attrs[key])
|
|
227
238
|
}
|
|
228
239
|
}
|
|
229
240
|
if (typeof content === 'string') {
|
|
230
|
-
writeString(content)
|
|
241
|
+
writeString(content)
|
|
231
242
|
}
|
|
232
243
|
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
233
|
-
writeByteLength(content.length)
|
|
234
|
-
pushBytes(content)
|
|
244
|
+
writeByteLength(content.length)
|
|
245
|
+
pushBytes(content)
|
|
235
246
|
}
|
|
236
247
|
else if (Array.isArray(content)) {
|
|
237
|
-
|
|
238
|
-
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)
|
|
239
250
|
for (const item of validContent) {
|
|
240
|
-
encodeBinaryNodeInner(item, opts, buffer)
|
|
251
|
+
encodeBinaryNodeInner(item, opts, buffer)
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
254
|
else if (typeof content === 'undefined') {
|
|
244
255
|
// do nothing
|
|
245
256
|
}
|
|
246
257
|
else {
|
|
247
|
-
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
258
|
+
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
248
259
|
}
|
|
249
|
-
return buffer
|
|
250
|
-
}
|
|
260
|
+
return buffer
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
module.exports = {
|
|
264
|
+
encodeBinaryNode
|
|
265
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { proto } from '../../WAProto';
|
|
2
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;
|
|
@@ -12,3 +13,5 @@ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: strin
|
|
|
12
13
|
};
|
|
13
14
|
export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
|
|
14
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[];
|