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