@baileys-md/baileys 10.1.0 → 11.0.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/README.md +1303 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +13516 -4182
- package/lib/Defaults/baileys-version.js +1 -0
- package/lib/Defaults/index.js +51 -72
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +94 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +19 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +67 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +50 -0
- package/lib/Signal/Group/sender-key-state.js +96 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +4 -16
- package/lib/Signal/libsignal.js +41 -61
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +50 -0
- package/lib/Socket/business.js +37 -42
- package/lib/Socket/chats.js +194 -187
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/groups.js +87 -90
- package/lib/Socket/index.js +7 -8
- package/lib/Socket/messages-recv.js +360 -335
- package/lib/Socket/messages-send.js +156 -279
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +144 -213
- package/lib/Socket/socket.js +128 -161
- package/lib/Socket/usync.js +19 -26
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +30 -17
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.js +31 -47
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.js +200 -195
- package/lib/Utils/crypto.js +70 -85
- package/lib/Utils/decode-wa-message.js +47 -51
- package/lib/Utils/event-buffer.js +36 -46
- package/lib/Utils/generics.js +116 -188
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -55
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/{Store → Utils}/make-in-memory-store.js +19 -27
- package/lib/Utils/make-mutex.js +7 -10
- package/lib/{Store → Utils}/make-ordered-dictionary.js +1 -3
- package/lib/Utils/messages-media.js +236 -368
- package/lib/Utils/messages.js +278 -510
- package/lib/Utils/noise-handler.js +22 -31
- package/lib/{Store → Utils}/object-repository.js +1 -4
- package/lib/Utils/process-message.js +144 -148
- package/lib/Utils/signal.js +71 -64
- package/lib/Utils/use-multi-file-auth-state.js +112 -84
- package/lib/Utils/validate-connection.js +72 -115
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.js +15 -52
- package/lib/WABinary/encode.js +14 -48
- package/lib/WABinary/generic-utils.js +31 -39
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.js +23 -40
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.js +2257 -2366
- package/lib/WAM/encode.js +17 -21
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/USyncQuery.js +34 -32
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.js +11 -33
- package/package.json +25 -54
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/index.js +0 -8
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-mongo-store.js +0 -567
package/lib/WABinary/decode.js
CHANGED
|
@@ -1,55 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
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.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
|
|
37
|
-
const util_1 = require("util");
|
|
38
|
-
const zlib_1 = require("zlib");
|
|
39
|
-
const constants = __importStar(require("./constants"));
|
|
40
|
-
const jid_utils_1 = require("./jid-utils");
|
|
41
|
-
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
42
|
-
const decompressingIfRequired = async (buffer) => {
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import { inflate } from 'zlib';
|
|
3
|
+
import * as constants from './constants.js';
|
|
4
|
+
import { jidEncode } from './jid-utils.js';
|
|
5
|
+
const inflatePromise = promisify(inflate);
|
|
6
|
+
export const decompressingIfRequired = async (buffer) => {
|
|
43
7
|
if (2 & buffer.readUInt8()) {
|
|
44
8
|
buffer = await inflatePromise(buffer.slice(1));
|
|
45
9
|
}
|
|
46
|
-
else {
|
|
10
|
+
else {
|
|
11
|
+
// nodes with no compression have a 0x00 prefix, we remove that
|
|
47
12
|
buffer = buffer.slice(1);
|
|
48
13
|
}
|
|
49
14
|
return buffer;
|
|
50
15
|
};
|
|
51
|
-
|
|
52
|
-
const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
16
|
+
export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
53
17
|
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
|
|
54
18
|
const checkEOS = (length) => {
|
|
55
19
|
if (indexRef.index + length > buffer.length) {
|
|
@@ -160,7 +124,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
160
124
|
const domainType = Number(rawDomainType);
|
|
161
125
|
const device = readByte();
|
|
162
126
|
const user = readString(readByte());
|
|
163
|
-
return
|
|
127
|
+
return jidEncode(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
|
|
164
128
|
};
|
|
165
129
|
const readString = (tag) => {
|
|
166
130
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
@@ -195,7 +159,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
195
159
|
const items = [];
|
|
196
160
|
const size = readListSize(tag);
|
|
197
161
|
for (let i = 0; i < size; i++) {
|
|
198
|
-
items.push(
|
|
162
|
+
items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef));
|
|
199
163
|
}
|
|
200
164
|
return items;
|
|
201
165
|
};
|
|
@@ -257,9 +221,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
257
221
|
content: data
|
|
258
222
|
};
|
|
259
223
|
};
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
|
|
224
|
+
export const decodeBinaryNode = async (buff) => {
|
|
225
|
+
const decompBuff = await decompressingIfRequired(buff);
|
|
226
|
+
return decodeDecompressedBinaryNode(decompBuff, constants);
|
|
264
227
|
};
|
|
265
|
-
|
|
228
|
+
//# sourceMappingURL=decode.js.map
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -1,46 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
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");
|
|
39
|
-
const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
1
|
+
import * as constants from './constants.js';
|
|
2
|
+
import { jidDecode } from './jid-utils.js';
|
|
3
|
+
export const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
40
4
|
const encoded = encodeBinaryNodeInner(node, opts, buffer);
|
|
41
5
|
return Buffer.from(encoded);
|
|
42
6
|
};
|
|
43
|
-
exports.encodeBinaryNode = encodeBinaryNode;
|
|
44
7
|
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
45
8
|
const { TAGS, TOKEN_MAP } = opts;
|
|
46
9
|
const pushByte = (value) => buffer.push(value & 0xff);
|
|
@@ -50,11 +13,15 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
50
13
|
buffer.push((value >> (curShift * 8)) & 0xff);
|
|
51
14
|
}
|
|
52
15
|
};
|
|
53
|
-
const pushBytes = (bytes) =>
|
|
16
|
+
const pushBytes = (bytes) => {
|
|
17
|
+
for (const b of bytes) {
|
|
18
|
+
buffer.push(b);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
54
21
|
const pushInt16 = (value) => {
|
|
55
22
|
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
56
23
|
};
|
|
57
|
-
const pushInt20 = (value) =>
|
|
24
|
+
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
|
|
58
25
|
const writeByteLength = (length) => {
|
|
59
26
|
if (length >= 4294967296) {
|
|
60
27
|
throw new Error('string too large to encode: ' + length);
|
|
@@ -152,8 +119,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
152
119
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
153
120
|
return false;
|
|
154
121
|
}
|
|
155
|
-
for (
|
|
156
|
-
const char = str[i];
|
|
122
|
+
for (const char of str) {
|
|
157
123
|
const isInNibbleRange = char >= '0' && char <= '9';
|
|
158
124
|
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
159
125
|
return false;
|
|
@@ -165,8 +131,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
165
131
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
166
132
|
return false;
|
|
167
133
|
}
|
|
168
|
-
for (
|
|
169
|
-
const char = str[i];
|
|
134
|
+
for (const char of str) {
|
|
170
135
|
const isInNibbleRange = char >= '0' && char <= '9';
|
|
171
136
|
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
172
137
|
return false;
|
|
@@ -193,7 +158,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
193
158
|
writePackedBytes(str, 'hex');
|
|
194
159
|
}
|
|
195
160
|
else if (str) {
|
|
196
|
-
const decodedJid =
|
|
161
|
+
const decodedJid = jidDecode(str);
|
|
197
162
|
if (decodedJid) {
|
|
198
163
|
writeJid(decodedJid);
|
|
199
164
|
}
|
|
@@ -217,7 +182,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
217
182
|
if (!tag) {
|
|
218
183
|
throw new Error('Invalid node: tag cannot be undefined');
|
|
219
184
|
}
|
|
220
|
-
const validAttributes = Object.keys(attrs || {}).filter(k =>
|
|
185
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
|
|
221
186
|
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
|
222
187
|
writeString(tag);
|
|
223
188
|
for (const key of validAttributes) {
|
|
@@ -248,3 +213,4 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
248
213
|
}
|
|
249
214
|
return buffer;
|
|
250
215
|
};
|
|
216
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.binaryNodeToString = binaryNodeToString;
|
|
5
|
-
const boom_1 = require("@hapi/boom");
|
|
6
|
-
const WAProto_1 = require("../../WAProto");
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import {} from './types.js';
|
|
7
4
|
// some extra useful utilities
|
|
8
|
-
const getBinaryNodeChildren = (node, childTag) => {
|
|
9
|
-
if (Array.isArray(node
|
|
5
|
+
export const getBinaryNodeChildren = (node, childTag) => {
|
|
6
|
+
if (Array.isArray(node?.content)) {
|
|
10
7
|
return node.content.filter(item => item.tag === childTag);
|
|
11
8
|
}
|
|
12
9
|
return [];
|
|
13
10
|
};
|
|
14
|
-
|
|
15
|
-
const getAllBinaryNodeChildren = ({ content }) => {
|
|
11
|
+
export const getAllBinaryNodeChildren = ({ content }) => {
|
|
16
12
|
if (Array.isArray(content)) {
|
|
17
13
|
return content;
|
|
18
14
|
}
|
|
19
15
|
return [];
|
|
20
16
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return node === null || node === void 0 ? void 0 : node.content.find(item => item.tag === childTag);
|
|
17
|
+
export const getBinaryNodeChild = (node, childTag) => {
|
|
18
|
+
if (Array.isArray(node?.content)) {
|
|
19
|
+
return node?.content.find(item => item.tag === childTag);
|
|
25
20
|
}
|
|
26
21
|
};
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
var _a;
|
|
30
|
-
const child = (_a = (0, exports.getBinaryNodeChild)(node, childTag)) === null || _a === void 0 ? void 0 : _a.content;
|
|
22
|
+
export const getBinaryNodeChildBuffer = (node, childTag) => {
|
|
23
|
+
const child = getBinaryNodeChild(node, childTag)?.content;
|
|
31
24
|
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
32
25
|
return child;
|
|
33
26
|
}
|
|
34
27
|
};
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
var _a;
|
|
38
|
-
const child = (_a = (0, exports.getBinaryNodeChild)(node, childTag)) === null || _a === void 0 ? void 0 : _a.content;
|
|
28
|
+
export const getBinaryNodeChildString = (node, childTag) => {
|
|
29
|
+
const child = getBinaryNodeChild(node, childTag)?.content;
|
|
39
30
|
if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
|
|
40
31
|
return Buffer.from(child).toString('utf-8');
|
|
41
32
|
}
|
|
@@ -43,42 +34,42 @@ const getBinaryNodeChildString = (node, childTag) => {
|
|
|
43
34
|
return child;
|
|
44
35
|
}
|
|
45
36
|
};
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const buff = (0, exports.getBinaryNodeChildBuffer)(node, childTag);
|
|
37
|
+
export const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
38
|
+
const buff = getBinaryNodeChildBuffer(node, childTag);
|
|
49
39
|
if (buff) {
|
|
50
40
|
return bufferToUInt(buff, length);
|
|
51
41
|
}
|
|
52
42
|
};
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
|
|
43
|
+
export const assertNodeErrorFree = (node) => {
|
|
44
|
+
const errNode = getBinaryNodeChild(node, 'error');
|
|
56
45
|
if (errNode) {
|
|
57
|
-
throw new
|
|
46
|
+
throw new Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
|
|
58
47
|
}
|
|
59
48
|
};
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
|
|
49
|
+
export const reduceBinaryNodeToDictionary = (node, tag) => {
|
|
50
|
+
const nodes = getBinaryNodeChildren(node, tag);
|
|
63
51
|
const dict = nodes.reduce((dict, { attrs }) => {
|
|
64
|
-
|
|
52
|
+
if (typeof attrs.name === 'string') {
|
|
53
|
+
dict[attrs.name] = attrs.value || attrs.config_value;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
dict[attrs.config_code] = attrs.value || attrs.config_value;
|
|
57
|
+
}
|
|
65
58
|
return dict;
|
|
66
59
|
}, {});
|
|
67
60
|
return dict;
|
|
68
61
|
};
|
|
69
|
-
|
|
70
|
-
const getBinaryNodeMessages = ({ content }) => {
|
|
62
|
+
export const getBinaryNodeMessages = ({ content }) => {
|
|
71
63
|
const msgs = [];
|
|
72
64
|
if (Array.isArray(content)) {
|
|
73
65
|
for (const item of content) {
|
|
74
66
|
if (item.tag === 'message') {
|
|
75
|
-
msgs.push(
|
|
67
|
+
msgs.push(proto.WebMessageInfo.decode(item.content));
|
|
76
68
|
}
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
71
|
return msgs;
|
|
80
72
|
};
|
|
81
|
-
exports.getBinaryNodeMessages = getBinaryNodeMessages;
|
|
82
73
|
function bufferToUInt(e, t) {
|
|
83
74
|
let a = 0;
|
|
84
75
|
for (let i = 0; i < t; i++) {
|
|
@@ -87,7 +78,7 @@ function bufferToUInt(e, t) {
|
|
|
87
78
|
return a;
|
|
88
79
|
}
|
|
89
80
|
const tabs = (n) => '\t'.repeat(n);
|
|
90
|
-
function binaryNodeToString(node, i = 0) {
|
|
81
|
+
export function binaryNodeToString(node, i = 0) {
|
|
91
82
|
if (!node) {
|
|
92
83
|
return node;
|
|
93
84
|
}
|
|
@@ -98,7 +89,7 @@ function binaryNodeToString(node, i = 0) {
|
|
|
98
89
|
return tabs(i) + Buffer.from(node).toString('hex');
|
|
99
90
|
}
|
|
100
91
|
if (Array.isArray(node)) {
|
|
101
|
-
return node.map(
|
|
92
|
+
return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
|
|
102
93
|
}
|
|
103
94
|
const children = binaryNodeToString(node.content, i + 1);
|
|
104
95
|
const tag = `<${node.tag} ${Object.entries(node.attrs || {})
|
|
@@ -108,3 +99,4 @@ function binaryNodeToString(node, i = 0) {
|
|
|
108
99
|
const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
|
|
109
100
|
return tag + content;
|
|
110
101
|
}
|
|
102
|
+
//# sourceMappingURL=generic-utils.js.map
|
package/lib/WABinary/index.js
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./encode"), exports);
|
|
18
|
-
__exportStar(require("./decode"), exports);
|
|
19
|
-
__exportStar(require("./generic-utils"), exports);
|
|
20
|
-
__exportStar(require("./jid-utils"), exports);
|
|
21
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export * from './encode.js';
|
|
2
|
+
export * from './decode.js';
|
|
3
|
+
export * from './generic-utils.js';
|
|
4
|
+
export * from './jid-utils.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.STORIES_JID = 'status@broadcast';
|
|
9
|
-
exports.META_AI_JID = '13135550002@c.us';
|
|
10
|
-
const jidEncode = (user, server, device, agent) => {
|
|
1
|
+
export const S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
2
|
+
export const OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
3
|
+
export const SERVER_JID = 'server@c.us';
|
|
4
|
+
export const PSA_WID = '0@c.us';
|
|
5
|
+
export const STORIES_JID = 'status@broadcast';
|
|
6
|
+
export const META_AI_JID = '13135550002@c.us';
|
|
7
|
+
export const jidEncode = (user, server, device, agent) => {
|
|
11
8
|
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
const jidDecode = (jid) => {
|
|
10
|
+
export const jidDecode = (jid) => {
|
|
15
11
|
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
|
|
16
12
|
if (sepIdx < 0) {
|
|
17
13
|
return undefined;
|
|
@@ -21,49 +17,36 @@ const jidDecode = (jid) => {
|
|
|
21
17
|
const [userAgent, device] = userCombined.split(':');
|
|
22
18
|
const user = userAgent.split('_')[0];
|
|
23
19
|
return {
|
|
24
|
-
server,
|
|
20
|
+
server: server,
|
|
25
21
|
user,
|
|
26
22
|
domainType: server === 'lid' ? 1 : 0,
|
|
27
23
|
device: device ? +device : undefined
|
|
28
24
|
};
|
|
29
25
|
};
|
|
30
|
-
exports.jidDecode = jidDecode;
|
|
31
26
|
/** is the jid a user */
|
|
32
|
-
const areJidsSameUser = (jid1, jid2) =>
|
|
33
|
-
var _a, _b;
|
|
34
|
-
return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
|
|
35
|
-
};
|
|
36
|
-
exports.areJidsSameUser = areJidsSameUser;
|
|
27
|
+
export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
|
|
37
28
|
/** is the jid Meta IA */
|
|
38
|
-
const isJidMetaIa = (jid) =>
|
|
39
|
-
exports.isJidMetaIa = isJidMetaIa;
|
|
29
|
+
export const isJidMetaIa = (jid) => jid?.endsWith('@bot');
|
|
40
30
|
/** is the jid a user */
|
|
41
|
-
const isJidUser = (jid) =>
|
|
42
|
-
exports.isJidUser = isJidUser;
|
|
31
|
+
export const isJidUser = (jid) => jid?.endsWith('@s.whatsapp.net');
|
|
43
32
|
/** is the jid a group */
|
|
44
|
-
const isLidUser = (jid) =>
|
|
45
|
-
exports.isLidUser = isLidUser;
|
|
33
|
+
export const isLidUser = (jid) => jid?.endsWith('@lid');
|
|
46
34
|
/** is the jid a broadcast */
|
|
47
|
-
const isJidBroadcast = (jid) =>
|
|
48
|
-
exports.isJidBroadcast = isJidBroadcast;
|
|
49
|
-
/** is the jid a newsletter */
|
|
50
|
-
const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
|
|
51
|
-
exports.isJidNewsletter = isJidNewsletter;
|
|
35
|
+
export const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
|
|
52
36
|
/** is the jid a group */
|
|
53
|
-
const isJidGroup = (jid) =>
|
|
54
|
-
exports.isJidGroup = isJidGroup;
|
|
37
|
+
export const isJidGroup = (jid) => jid?.endsWith('@g.us');
|
|
55
38
|
/** is the jid the status broadcast */
|
|
56
|
-
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
57
|
-
|
|
39
|
+
export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
40
|
+
/** is the jid a newsletter */
|
|
41
|
+
export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
|
|
58
42
|
const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
|
|
59
|
-
const isJidBot = (jid) =>
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const result = (0, exports.jidDecode)(jid);
|
|
43
|
+
export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
|
|
44
|
+
export const jidNormalizedUser = (jid) => {
|
|
45
|
+
const result = jidDecode(jid);
|
|
63
46
|
if (!result) {
|
|
64
47
|
return '';
|
|
65
48
|
}
|
|
66
49
|
const { user, server } = result;
|
|
67
|
-
return
|
|
50
|
+
return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
|
|
68
51
|
};
|
|
69
|
-
|
|
52
|
+
//# sourceMappingURL=jid-utils.js.map
|
package/lib/WABinary/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as constants from './constants.js';
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
package/lib/WAM/BinaryInfo.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BinaryInfo = void 0;
|
|
4
|
-
class BinaryInfo {
|
|
1
|
+
export class BinaryInfo {
|
|
5
2
|
constructor(options = {}) {
|
|
6
3
|
this.protocolVersion = 5;
|
|
7
4
|
this.sequence = 0;
|
|
@@ -10,4 +7,4 @@ class BinaryInfo {
|
|
|
10
7
|
Object.assign(this, options);
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
|
|
10
|
+
//# sourceMappingURL=BinaryInfo.js.map
|