@denzy-official/baileys 1.1.3 → 1.1.5
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/WAProto/index.js +77698 -117051
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +6 -5
- package/lib/Defaults/index.js +118 -79
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts +0 -1
- package/lib/Signal/Group/group-session-builder.js +0 -1
- package/lib/Signal/Group/group_cipher.d.ts +0 -1
- package/lib/Signal/Group/group_cipher.js +0 -1
- package/lib/Signal/Group/index.d.ts +0 -1
- package/lib/Signal/Group/index.js +0 -1
- package/lib/Signal/Group/keyhelper.d.ts +0 -1
- package/lib/Signal/Group/keyhelper.js +0 -1
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.js +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts +0 -1
- package/lib/Signal/Group/sender-key-message.js +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts +0 -1
- package/lib/Signal/Group/sender-key-record.js +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts +0 -1
- package/lib/Signal/Group/sender-key-state.js +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +0 -1
- package/lib/Signal/libsignal.d.ts +0 -1
- package/lib/Signal/libsignal.js +0 -1
- package/lib/Store/index.d.ts +2 -2
- package/lib/Store/index.js +3 -2
- 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 -25
- package/lib/Store/make-in-memory-store.js +14 -27
- package/lib/Store/make-ordered-dictionary.d.ts +1 -2
- package/lib/Store/make-ordered-dictionary.js +2 -3
- package/lib/Store/object-repository.d.ts +0 -1
- package/lib/Store/object-repository.js +0 -1
- package/lib/Types/Auth.d.ts +7 -1
- package/lib/Types/Auth.js +0 -1
- package/lib/Types/Call.d.ts +1 -2
- package/lib/Types/Call.js +0 -1
- package/lib/Types/Chat.d.ts +7 -15
- package/lib/Types/Chat.js +0 -1
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Contact.js +0 -1
- package/lib/Types/Events.d.ts +2 -45
- package/lib/Types/Events.js +0 -1
- package/lib/Types/GroupMetadata.d.ts +2 -12
- package/lib/Types/GroupMetadata.js +0 -1
- package/lib/Types/Label.d.ts +0 -1
- package/lib/Types/Label.js +1 -2
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +1 -2
- package/lib/Types/Message.d.ts +21 -149
- package/lib/Types/Message.js +2 -1
- package/lib/Types/Newsletter.d.ts +97 -74
- package/lib/Types/Newsletter.js +38 -19
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -9
- package/lib/Types/index.js +2 -3
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +13 -1277
- package/lib/WABinary/decode.d.ts +4 -4
- package/lib/WABinary/decode.js +13 -27
- package/lib/WABinary/encode.d.ts +2 -2
- package/lib/WABinary/encode.js +152 -138
- package/lib/WABinary/generic-utils.d.ts +4 -2
- package/lib/WABinary/generic-utils.js +125 -38
- package/lib/WABinary/index.d.ts +0 -1
- package/lib/WABinary/index.js +0 -1
- package/lib/WABinary/jid-utils.d.ts +5 -11
- package/lib/WABinary/jid-utils.js +5 -27
- package/lib/WABinary/types.d.ts +0 -1
- package/lib/WABinary/types.js +0 -1
- package/lib/WAM/BinaryInfo.d.ts +11 -3
- package/lib/WAM/BinaryInfo.js +0 -1
- package/lib/WAM/constants.d.ts +0 -1
- package/lib/WAM/constants.js +0 -1
- package/lib/WAM/encode.d.ts +2 -2
- package/lib/WAM/encode.js +0 -1
- package/lib/WAM/index.d.ts +0 -1
- package/lib/WAM/index.js +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.js +23 -36
- package/package.json +94 -97
- package/WAProto/GenerateStatics.sh +0 -5
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/bocah rename tolol, baileys by denzy +0 -0
- package/WAProto/index.d.ts +0 -55058
- package/WAProto/index.ts.ts +0 -53474
- package/WAProto/p.html +0 -1
package/lib/WABinary/decode.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
2
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
|
3
|
-
export declare const decompressingIfRequired: (buffer: Buffer) =>
|
|
4
|
-
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?: {
|
|
5
5
|
index: number;
|
|
6
6
|
}) => BinaryNode;
|
|
7
|
-
export declare const decodeBinaryNode: (buff: Buffer) =>
|
|
7
|
+
export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// baileys by denzy
|
|
2
1
|
"use strict";
|
|
3
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
3
|
if (k2 === undefined) k2 = k;
|
|
@@ -16,33 +15,21 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
15
|
}) : function(o, v) {
|
|
17
16
|
o["default"] = v;
|
|
18
17
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) ||
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
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
|
+
};
|
|
36
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
26
|
exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
|
|
38
|
-
const util_1 = require("util");
|
|
39
27
|
const zlib_1 = require("zlib");
|
|
40
28
|
const constants = __importStar(require("./constants"));
|
|
41
29
|
const jid_utils_1 = require("./jid-utils");
|
|
42
|
-
const
|
|
43
|
-
const decompressingIfRequired = async (buffer) => {
|
|
30
|
+
const decompressingIfRequired = (buffer) => {
|
|
44
31
|
if (2 & buffer.readUInt8()) {
|
|
45
|
-
buffer =
|
|
32
|
+
buffer = (0, zlib_1.inflateSync)(buffer.slice(1));
|
|
46
33
|
}
|
|
47
34
|
else { // nodes with no compression have a 0x00 prefix, we remove that
|
|
48
35
|
buffer = buffer.slice(1);
|
|
@@ -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,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
2
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
|
3
|
-
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,251 +1,265 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
3
|
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)
|
|
4
|
+
if (k2 === undefined) k2 = k
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
6
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
8
|
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
9
|
+
Object.defineProperty(o, k2, desc)
|
|
10
10
|
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
11
|
+
if (k2 === undefined) k2 = k
|
|
12
|
+
o[k2] = m[k]
|
|
13
|
+
}))
|
|
14
|
+
|
|
14
15
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
16
17
|
}) : function(o, v) {
|
|
17
|
-
o["default"] = v
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.encodeBinaryNode = void 0;
|
|
38
|
-
const constants = __importStar(require("./constants"));
|
|
39
|
-
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
|
+
|
|
40
34
|
const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
41
|
-
const encoded = encodeBinaryNodeInner(node, opts, buffer)
|
|
42
|
-
return Buffer.from(encoded)
|
|
43
|
-
}
|
|
44
|
-
|
|
35
|
+
const encoded = encodeBinaryNodeInner(node, opts, buffer)
|
|
36
|
+
return Buffer.from(encoded)
|
|
37
|
+
}
|
|
38
|
+
|
|
45
39
|
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
46
|
-
const { TAGS, TOKEN_MAP } = opts
|
|
47
|
-
const pushByte = (value) => buffer.push(value & 0xff)
|
|
40
|
+
const { TAGS, TOKEN_MAP } = opts
|
|
41
|
+
const pushByte = (value) => buffer.push(value & 0xff)
|
|
48
42
|
const pushInt = (value, n, littleEndian = false) => {
|
|
49
43
|
for (let i = 0; i < n; i++) {
|
|
50
|
-
const curShift = littleEndian ? i : n - 1 - i
|
|
51
|
-
buffer.push((value >> (curShift * 8)) & 0xff)
|
|
44
|
+
const curShift = littleEndian ? i : n - 1 - i
|
|
45
|
+
buffer.push((value >> (curShift * 8)) & 0xff)
|
|
52
46
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const pushBytes = (bytes) => {
|
|
50
|
+
for (const b of bytes) {
|
|
51
|
+
buffer.push(b)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
55
|
const pushInt16 = (value) => {
|
|
56
|
-
pushBytes([(value >> 8) & 0xff, value & 0xff])
|
|
57
|
-
}
|
|
58
|
-
|
|
56
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]))
|
|
59
60
|
const writeByteLength = (length) => {
|
|
60
61
|
if (length >= 4294967296) {
|
|
61
|
-
throw new Error('string too large to encode: ' + length)
|
|
62
|
+
throw new Error('string too large to encode: ' + length)
|
|
62
63
|
}
|
|
63
64
|
if (length >= 1 << 20) {
|
|
64
|
-
pushByte(TAGS.BINARY_32)
|
|
65
|
-
pushInt(length, 4)
|
|
65
|
+
pushByte(TAGS.BINARY_32)
|
|
66
|
+
pushInt(length, 4) // 32 bit integer
|
|
66
67
|
}
|
|
67
68
|
else if (length >= 256) {
|
|
68
|
-
pushByte(TAGS.BINARY_20)
|
|
69
|
-
pushInt20(length)
|
|
69
|
+
pushByte(TAGS.BINARY_20)
|
|
70
|
+
pushInt20(length)
|
|
70
71
|
}
|
|
71
72
|
else {
|
|
72
|
-
pushByte(TAGS.BINARY_8)
|
|
73
|
-
pushByte(length)
|
|
73
|
+
pushByte(TAGS.BINARY_8)
|
|
74
|
+
pushByte(length)
|
|
74
75
|
}
|
|
75
|
-
}
|
|
76
|
+
}
|
|
77
|
+
|
|
76
78
|
const writeStringRaw = (str) => {
|
|
77
|
-
const bytes = Buffer.from(str, 'utf-8')
|
|
78
|
-
writeByteLength(bytes.length)
|
|
79
|
-
pushBytes(bytes)
|
|
80
|
-
}
|
|
79
|
+
const bytes = Buffer.from(str, 'utf-8')
|
|
80
|
+
writeByteLength(bytes.length)
|
|
81
|
+
pushBytes(bytes)
|
|
82
|
+
}
|
|
83
|
+
|
|
81
84
|
const writeJid = ({ domainType, device, user, server }) => {
|
|
82
85
|
if (typeof device !== 'undefined') {
|
|
83
|
-
pushByte(TAGS.AD_JID)
|
|
84
|
-
pushByte(domainType || 0)
|
|
85
|
-
pushByte(device || 0)
|
|
86
|
-
writeString(user)
|
|
86
|
+
pushByte(TAGS.AD_JID)
|
|
87
|
+
pushByte(domainType || 0)
|
|
88
|
+
pushByte(device || 0)
|
|
89
|
+
writeString(user)
|
|
87
90
|
}
|
|
88
91
|
else {
|
|
89
|
-
pushByte(TAGS.JID_PAIR)
|
|
92
|
+
pushByte(TAGS.JID_PAIR)
|
|
90
93
|
if (user.length) {
|
|
91
|
-
writeString(user)
|
|
94
|
+
writeString(user)
|
|
92
95
|
}
|
|
93
96
|
else {
|
|
94
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
97
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
95
98
|
}
|
|
96
|
-
writeString(server)
|
|
99
|
+
writeString(server)
|
|
97
100
|
}
|
|
98
|
-
}
|
|
101
|
+
}
|
|
102
|
+
|
|
99
103
|
const packNibble = (char) => {
|
|
100
104
|
switch (char) {
|
|
101
105
|
case '-':
|
|
102
|
-
return 10
|
|
106
|
+
return 10
|
|
103
107
|
case '.':
|
|
104
|
-
return 11
|
|
108
|
+
return 11
|
|
105
109
|
case '\0':
|
|
106
|
-
return 15
|
|
110
|
+
return 15
|
|
107
111
|
default:
|
|
108
112
|
if (char >= '0' && char <= '9') {
|
|
109
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
113
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
110
114
|
}
|
|
111
|
-
throw new Error(`invalid byte for nibble "${char}"`)
|
|
115
|
+
throw new Error(`invalid byte for nibble "${char}"`)
|
|
112
116
|
}
|
|
113
|
-
}
|
|
117
|
+
}
|
|
118
|
+
|
|
114
119
|
const packHex = (char) => {
|
|
115
120
|
if (char >= '0' && char <= '9') {
|
|
116
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
121
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
117
122
|
}
|
|
118
123
|
if (char >= 'A' && char <= 'F') {
|
|
119
|
-
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
|
|
124
|
+
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
|
|
120
125
|
}
|
|
121
126
|
if (char >= 'a' && char <= 'f') {
|
|
122
|
-
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
|
|
127
|
+
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
|
|
123
128
|
}
|
|
124
129
|
if (char === '\0') {
|
|
125
|
-
return 15
|
|
130
|
+
return 15
|
|
126
131
|
}
|
|
127
|
-
throw new Error(`Invalid hex char "${char}"`)
|
|
128
|
-
}
|
|
132
|
+
throw new Error(`Invalid hex char "${char}"`)
|
|
133
|
+
}
|
|
134
|
+
|
|
129
135
|
const writePackedBytes = (str, type) => {
|
|
130
136
|
if (str.length > TAGS.PACKED_MAX) {
|
|
131
|
-
throw new Error('Too many bytes to pack')
|
|
137
|
+
throw new Error('Too many bytes to pack')
|
|
132
138
|
}
|
|
133
|
-
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
|
|
134
|
-
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)
|
|
135
141
|
if (str.length % 2 !== 0) {
|
|
136
|
-
roundedLength |= 128
|
|
142
|
+
roundedLength |= 128
|
|
137
143
|
}
|
|
138
|
-
pushByte(roundedLength)
|
|
139
|
-
const packFunction = type === 'nibble' ? packNibble : packHex
|
|
144
|
+
pushByte(roundedLength)
|
|
145
|
+
const packFunction = type === 'nibble' ? packNibble : packHex
|
|
140
146
|
const packBytePair = (v1, v2) => {
|
|
141
|
-
const result = (packFunction(v1) << 4) | packFunction(v2)
|
|
142
|
-
return result
|
|
143
|
-
}
|
|
144
|
-
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)
|
|
145
151
|
for (let i = 0; i < strLengthHalf; i++) {
|
|
146
|
-
pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
|
|
152
|
+
pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
|
|
147
153
|
}
|
|
148
154
|
if (str.length % 2 !== 0) {
|
|
149
|
-
pushByte(packBytePair(str[str.length - 1], '\x00'))
|
|
155
|
+
pushByte(packBytePair(str[str.length - 1], '\x00'))
|
|
150
156
|
}
|
|
151
|
-
}
|
|
157
|
+
}
|
|
158
|
+
|
|
152
159
|
const isNibble = (str) => {
|
|
153
160
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
154
|
-
return false
|
|
161
|
+
return false
|
|
155
162
|
}
|
|
156
|
-
for (
|
|
157
|
-
const
|
|
158
|
-
const isInNibbleRange = char >= '0' && char <= '9';
|
|
163
|
+
for (const char of str) {
|
|
164
|
+
const isInNibbleRange = char >= '0' && char <= '9'
|
|
159
165
|
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
160
|
-
return false
|
|
166
|
+
return false
|
|
161
167
|
}
|
|
162
168
|
}
|
|
163
|
-
return true
|
|
164
|
-
}
|
|
169
|
+
return true
|
|
170
|
+
}
|
|
171
|
+
|
|
165
172
|
const isHex = (str) => {
|
|
166
173
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
167
|
-
return false
|
|
174
|
+
return false
|
|
168
175
|
}
|
|
169
|
-
for (
|
|
170
|
-
const
|
|
171
|
-
const isInNibbleRange = char >= '0' && char <= '9';
|
|
176
|
+
for (const char of str) {
|
|
177
|
+
const isInNibbleRange = char >= '0' && char <= '9'
|
|
172
178
|
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
173
|
-
return false
|
|
179
|
+
return false
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
|
-
return true
|
|
177
|
-
}
|
|
182
|
+
return true
|
|
183
|
+
}
|
|
184
|
+
|
|
178
185
|
const writeString = (str) => {
|
|
179
|
-
|
|
180
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
181
|
-
return
|
|
186
|
+
if (str === undefined || str === null) {
|
|
187
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
188
|
+
return
|
|
182
189
|
}
|
|
183
|
-
const tokenIndex = TOKEN_MAP[str]
|
|
190
|
+
const tokenIndex = TOKEN_MAP[str]
|
|
184
191
|
if (tokenIndex) {
|
|
185
192
|
if (typeof tokenIndex.dict === 'number') {
|
|
186
|
-
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
|
|
193
|
+
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
|
|
187
194
|
}
|
|
188
|
-
pushByte(tokenIndex.index)
|
|
195
|
+
pushByte(tokenIndex.index)
|
|
189
196
|
}
|
|
190
197
|
else if (isNibble(str)) {
|
|
191
|
-
writePackedBytes(str, 'nibble')
|
|
198
|
+
writePackedBytes(str, 'nibble')
|
|
192
199
|
}
|
|
193
200
|
else if (isHex(str)) {
|
|
194
|
-
writePackedBytes(str, 'hex')
|
|
201
|
+
writePackedBytes(str, 'hex')
|
|
195
202
|
}
|
|
196
203
|
else if (str) {
|
|
197
|
-
const decodedJid = (0, jid_utils_1.jidDecode)(str)
|
|
204
|
+
const decodedJid = (0, jid_utils_1.jidDecode)(str)
|
|
198
205
|
if (decodedJid) {
|
|
199
|
-
writeJid(decodedJid)
|
|
206
|
+
writeJid(decodedJid)
|
|
200
207
|
}
|
|
201
208
|
else {
|
|
202
|
-
writeStringRaw(str)
|
|
209
|
+
writeStringRaw(str)
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
|
-
}
|
|
212
|
+
}
|
|
213
|
+
|
|
206
214
|
const writeListStart = (listSize) => {
|
|
207
215
|
if (listSize === 0) {
|
|
208
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
216
|
+
pushByte(TAGS.LIST_EMPTY)
|
|
209
217
|
}
|
|
210
218
|
else if (listSize < 256) {
|
|
211
|
-
pushBytes([TAGS.LIST_8, listSize])
|
|
219
|
+
pushBytes([TAGS.LIST_8, listSize])
|
|
212
220
|
}
|
|
213
221
|
else {
|
|
214
|
-
pushByte(TAGS.LIST_16)
|
|
215
|
-
pushInt16(listSize)
|
|
222
|
+
pushByte(TAGS.LIST_16)
|
|
223
|
+
pushInt16(listSize)
|
|
216
224
|
}
|
|
217
|
-
}
|
|
225
|
+
}
|
|
226
|
+
|
|
218
227
|
if (!tag) {
|
|
219
|
-
throw new Error('Invalid node: tag cannot be undefined')
|
|
228
|
+
throw new Error('Invalid node: tag cannot be undefined')
|
|
220
229
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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)
|
|
224
234
|
for (const key of validAttributes) {
|
|
225
235
|
if (typeof attrs[key] === 'string') {
|
|
226
|
-
writeString(key)
|
|
227
|
-
writeString(attrs[key])
|
|
236
|
+
writeString(key)
|
|
237
|
+
writeString(attrs[key])
|
|
228
238
|
}
|
|
229
239
|
}
|
|
230
240
|
if (typeof content === 'string') {
|
|
231
|
-
writeString(content)
|
|
241
|
+
writeString(content)
|
|
232
242
|
}
|
|
233
243
|
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
234
|
-
writeByteLength(content.length)
|
|
235
|
-
pushBytes(content)
|
|
244
|
+
writeByteLength(content.length)
|
|
245
|
+
pushBytes(content)
|
|
236
246
|
}
|
|
237
247
|
else if (Array.isArray(content)) {
|
|
238
|
-
|
|
239
|
-
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)
|
|
240
250
|
for (const item of validContent) {
|
|
241
|
-
encodeBinaryNodeInner(item, opts, buffer)
|
|
251
|
+
encodeBinaryNodeInner(item, opts, buffer)
|
|
242
252
|
}
|
|
243
253
|
}
|
|
244
254
|
else if (typeof content === 'undefined') {
|
|
245
255
|
// do nothing
|
|
246
256
|
}
|
|
247
257
|
else {
|
|
248
|
-
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
258
|
+
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
249
259
|
}
|
|
250
|
-
return buffer
|
|
251
|
-
}
|
|
260
|
+
return buffer
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
module.exports = {
|
|
264
|
+
encodeBinaryNode
|
|
265
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
3
|
import { BinaryNode } from './types';
|
|
4
4
|
export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
|
|
5
5
|
export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
|
|
6
6
|
export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
|
|
7
|
-
export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array
|
|
7
|
+
export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
|
|
8
8
|
export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
|
|
9
9
|
export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
|
|
10
10
|
export declare const assertNodeErrorFree: (node: BinaryNode) => void;
|
|
@@ -13,3 +13,5 @@ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: strin
|
|
|
13
13
|
};
|
|
14
14
|
export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
|
|
15
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[];
|