@queenanya/baileys 7.4.14 → 7.5.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/README.md +26 -26
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -231
- package/lib/Defaults/index.js +11 -23
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
- package/lib/Socket/business.d.ts +31 -28
- package/lib/Socket/chats.d.ts +17 -9
- package/lib/Socket/chats.js +115 -116
- package/lib/Socket/{registration.d.ts → communities.d.ts} +94 -145
- package/lib/Socket/communities.js +354 -0
- package/lib/Socket/groups.d.ts +23 -10
- package/lib/Socket/groups.js +12 -1
- package/lib/Socket/index.d.ts +69 -38
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +30 -28
- package/lib/Socket/messages-recv.js +291 -180
- package/lib/Socket/messages-send.d.ts +25 -19
- package/lib/Socket/messages-send.js +110 -76
- package/lib/Socket/newsletter.d.ts +19 -13
- package/lib/Socket/newsletter.js +67 -54
- package/lib/Socket/socket.d.ts +3 -1
- package/lib/Socket/socket.js +15 -17
- package/lib/Socket/usync.d.ts +38 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/make-cache-manager-store.d.ts +2 -1
- package/lib/Store/make-in-memory-store.js +13 -11
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +1 -6
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +15 -7
- package/lib/Types/Contact.d.ts +6 -1
- package/lib/Types/Events.d.ts +44 -2
- package/lib/Types/GroupMetadata.d.ts +3 -1
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Message.d.ts +37 -30
- package/lib/Types/Newsletter.d.ts +0 -13
- package/lib/Types/Newsletter.js +1 -15
- package/lib/Types/Socket.d.ts +10 -3
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +8 -0
- package/lib/Utils/auth-utils.js +1 -7
- package/lib/Utils/chat-utils.d.ts +5 -4
- package/lib/Utils/chat-utils.js +52 -20
- package/lib/Utils/crypto.d.ts +2 -1
- package/lib/Utils/crypto.js +4 -2
- package/lib/Utils/decode-wa-message.d.ts +1 -0
- package/lib/Utils/decode-wa-message.js +34 -14
- package/lib/Utils/event-buffer.js +14 -8
- package/lib/Utils/generics.d.ts +37 -13
- package/lib/Utils/generics.js +103 -18
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/link-preview.js +24 -1
- package/lib/Utils/logger.d.ts +1 -3
- package/lib/Utils/make-mutex.js +1 -0
- package/lib/Utils/messages-media.d.ts +3 -2
- package/lib/Utils/messages-media.js +17 -32
- package/lib/Utils/messages.d.ts +1 -0
- package/lib/Utils/messages.js +67 -72
- package/lib/Utils/noise-handler.d.ts +3 -3
- package/lib/Utils/noise-handler.js +7 -12
- package/lib/Utils/process-message.d.ts +3 -2
- package/lib/Utils/process-message.js +55 -21
- package/lib/Utils/signal.js +23 -16
- package/lib/Utils/use-multi-file-auth-state.js +17 -3
- package/lib/Utils/validate-connection.d.ts +0 -1
- package/lib/Utils/validate-connection.js +10 -44
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +3 -2
- package/lib/WABinary/decode.js +6 -4
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +8 -6
- package/lib/WABinary/generic-utils.d.ts +1 -0
- package/lib/WABinary/jid-utils.d.ts +3 -3
- package/lib/WABinary/jid-utils.js +5 -5
- package/lib/WAM/BinaryInfo.d.ts +3 -2
- package/lib/WAM/constants.d.ts +3 -2
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +36 -34
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.js +0 -166
- /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
package/lib/Utils/signal.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
4
5
|
const Defaults_1 = require("../Defaults");
|
|
5
6
|
const WABinary_1 = require("../WABinary");
|
|
6
7
|
const crypto_1 = require("./crypto");
|
|
@@ -66,22 +67,26 @@ const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
66
67
|
for (const node of nodes) {
|
|
67
68
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
jid
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
const chunkSize = 100;
|
|
71
|
+
const chunks = (0, lodash_1.chunk)(nodes, chunkSize);
|
|
72
|
+
for (const nodesChunk of chunks) {
|
|
73
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
74
|
+
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
75
|
+
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
76
|
+
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
77
|
+
const jid = node.attrs.jid;
|
|
78
|
+
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
79
|
+
await repository.injectE2ESession({
|
|
80
|
+
jid,
|
|
81
|
+
session: {
|
|
82
|
+
registrationId: registrationId,
|
|
83
|
+
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
84
|
+
signedPreKey: extractKey(signedKey),
|
|
85
|
+
preKey: extractKey(key)
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
85
90
|
};
|
|
86
91
|
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
87
92
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
@@ -96,8 +101,10 @@ const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
|
96
101
|
const devicesNode = (0, WABinary_1.getBinaryNodeChild)(item, 'devices');
|
|
97
102
|
const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(devicesNode, 'device-list');
|
|
98
103
|
if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
|
|
104
|
+
//eslint-disable-next-line max-depth
|
|
99
105
|
for (const { tag, attrs } of deviceListNode.content) {
|
|
100
106
|
const device = +attrs.id;
|
|
107
|
+
//eslint-disable-next-line max-depth
|
|
101
108
|
if (tag === 'device' && // ensure the "device" tag
|
|
102
109
|
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
103
110
|
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.useMultiFileAuthState = void 0;
|
|
7
|
+
const async_lock_1 = __importDefault(require("async-lock"));
|
|
4
8
|
const promises_1 = require("fs/promises");
|
|
5
9
|
const path_1 = require("path");
|
|
6
10
|
const WAProto_1 = require("../../WAProto");
|
|
7
11
|
const auth_utils_1 = require("./auth-utils");
|
|
8
12
|
const generics_1 = require("./generics");
|
|
13
|
+
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
14
|
+
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
15
|
+
// https://github.com/nodejs/node/issues/26338
|
|
16
|
+
// Default pending is 1000, set it to infinity
|
|
17
|
+
// https://github.com/rogierschouten/async-lock/issues/63
|
|
18
|
+
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
9
19
|
/**
|
|
10
20
|
* stores the full authentication state in a single folder.
|
|
11
21
|
* Far more efficient than singlefileauthstate
|
|
@@ -14,12 +24,15 @@ const generics_1 = require("./generics");
|
|
|
14
24
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
15
25
|
* */
|
|
16
26
|
const useMultiFileAuthState = async (folder) => {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
28
|
const writeData = (data, file) => {
|
|
18
|
-
|
|
29
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
30
|
+
return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
|
|
19
31
|
};
|
|
20
32
|
const readData = async (file) => {
|
|
21
33
|
try {
|
|
22
|
-
const
|
|
34
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
35
|
+
const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
|
|
23
36
|
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
24
37
|
}
|
|
25
38
|
catch (error) {
|
|
@@ -28,7 +41,8 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
28
41
|
};
|
|
29
42
|
const removeData = async (file) => {
|
|
30
43
|
try {
|
|
31
|
-
|
|
44
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
45
|
+
await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
|
|
32
46
|
}
|
|
33
47
|
catch (_a) {
|
|
34
48
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { proto } from '../../WAProto';
|
|
2
2
|
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
|
|
3
3
|
import { BinaryNode } from '../WABinary';
|
|
4
|
-
export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
|
|
5
4
|
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
6
5
|
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
7
6
|
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode =
|
|
3
|
+
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const WAProto_1 = require("../../WAProto");
|
|
@@ -10,30 +10,19 @@ const crypto_2 = require("./crypto");
|
|
|
10
10
|
const generics_1 = require("./generics");
|
|
11
11
|
const signal_1 = require("./signal");
|
|
12
12
|
const getUserAgent = (config) => {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const osVersion = config.mobile ? '15.3.1' : '0.1';
|
|
15
|
-
const version = config.mobile ? [2, 24, 6] : config.version;
|
|
16
|
-
const device = config.mobile ? 'iPhone_7' : 'Desktop';
|
|
17
|
-
const manufacturer = config.mobile ? 'Apple' : '';
|
|
18
|
-
const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
|
|
19
|
-
const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
|
|
20
13
|
return {
|
|
21
14
|
appVersion: {
|
|
22
|
-
primary: version[0],
|
|
23
|
-
secondary: version[1],
|
|
24
|
-
tertiary: version[2],
|
|
15
|
+
primary: config.version[0],
|
|
16
|
+
secondary: config.version[1],
|
|
17
|
+
tertiary: config.version[2],
|
|
25
18
|
},
|
|
26
|
-
platform,
|
|
19
|
+
platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
27
20
|
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
manufacturer,
|
|
32
|
-
device,
|
|
33
|
-
osBuildNumber: osVersion,
|
|
21
|
+
osVersion: '0.1',
|
|
22
|
+
device: 'Desktop',
|
|
23
|
+
osBuildNumber: '0.1',
|
|
34
24
|
localeLanguageIso6391: 'en',
|
|
35
|
-
localeCountryIso31661Alpha2: 'US'
|
|
36
|
-
...phoneId
|
|
25
|
+
localeCountryIso31661Alpha2: 'US'
|
|
37
26
|
};
|
|
38
27
|
};
|
|
39
28
|
const PLATFORM_MAP = {
|
|
@@ -53,32 +42,9 @@ const getClientPayload = (config) => {
|
|
|
53
42
|
connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
54
43
|
userAgent: getUserAgent(config),
|
|
55
44
|
};
|
|
56
|
-
|
|
57
|
-
payload.webInfo = getWebInfo(config);
|
|
58
|
-
}
|
|
45
|
+
payload.webInfo = getWebInfo(config);
|
|
59
46
|
return payload;
|
|
60
47
|
};
|
|
61
|
-
const generateMobileNode = (config) => {
|
|
62
|
-
if (!config.auth.creds) {
|
|
63
|
-
throw new boom_1.Boom('No registration data found', { data: config });
|
|
64
|
-
}
|
|
65
|
-
const payload = {
|
|
66
|
-
...getClientPayload(config),
|
|
67
|
-
sessionId: Math.floor(Math.random() * 999999999 + 1),
|
|
68
|
-
shortConnect: true,
|
|
69
|
-
connectAttemptCount: 0,
|
|
70
|
-
device: 0,
|
|
71
|
-
dnsSource: {
|
|
72
|
-
appCached: false,
|
|
73
|
-
dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
|
|
74
|
-
},
|
|
75
|
-
passive: false,
|
|
76
|
-
pushName: 'test',
|
|
77
|
-
username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
|
|
78
|
-
};
|
|
79
|
-
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
80
|
-
};
|
|
81
|
-
exports.generateMobileNode = generateMobileNode;
|
|
82
48
|
const generateLoginNode = (userJid, config) => {
|
|
83
49
|
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
84
50
|
const payload = {
|
|
@@ -30,11 +30,11 @@ exports.SINGLE_BYTE_TOKENS = [
|
|
|
30
30
|
'', 'xmlstreamstart', 'xmlstreamend', 's.whatsapp.net', 'type', 'participant', 'from', 'receipt', 'id', 'broadcast', 'status', 'message', 'notification', 'notify', 'to', 'jid', 'user', 'class', 'offline', 'g.us', 'result', 'mediatype', 'enc', 'skmsg', 'off_cnt', 'xmlns', 'presence', 'participants', 'ack', 't', 'iq', 'device_hash', 'read', 'value', 'media', 'picture', 'chatstate', 'unavailable', 'text', 'urn:xmpp:whatsapp:push', 'devices', 'verified_name', 'contact', 'composing', 'edge_routing', 'routing_info', 'item', 'image', 'verified_level', 'get', 'fallback_hostname', '2', 'media_conn', '1', 'v', 'handshake', 'fallback_class', 'count', 'config', 'offline_preview', 'download_buckets', 'w:profile:picture', 'set', 'creation', 'location', 'fallback_ip4', 'msg', 'urn:xmpp:ping', 'fallback_ip6', 'call-creator', 'relaylatency', 'success', 'subscribe', 'video', 'business_hours_config', 'platform', 'hostname', 'version', 'unknown', '0', 'ping', 'hash', 'edit', 'subject', 'max_buckets', 'download', 'delivery', 'props', 'sticker', 'name', 'last', 'contacts', 'business', 'primary', 'preview', 'w:p', 'pkmsg', 'call-id', 'retry', 'prop', 'call', 'auth_ttl', 'available', 'relay_id', 'last_id', 'day_of_week', 'w', 'host', 'seen', 'bits', 'list', 'atn', 'upload', 'is_new', 'w:stats', 'key', 'paused', 'specific_hours', 'multicast', 'stream:error', 'mmg.whatsapp.net', 'code', 'deny', 'played', 'profile', 'fna', 'device-list', 'close_time', 'latency', 'gcm', 'pop', 'audio', '26', 'w:web', 'open_time', 'error', 'auth', 'ip4', 'update', 'profile_options', 'config_value', 'category', 'catalog_not_created', '00', 'config_code', 'mode', 'catalog_status', 'ip6', 'blocklist', 'registration', '7', 'web', 'fail', 'w:m', 'cart_enabled', 'ttl', 'gif', '300', 'device_orientation', 'identity', 'query', '401', 'media-gig2-1.cdn.whatsapp.net', 'in', '3', 'te2', 'add', 'fallback', 'categories', 'ptt', 'encrypt', 'notice', 'thumbnail-document', 'item-not-found', '12', 'thumbnail-image', 'stage', 'thumbnail-link', 'usync', 'out', 'thumbnail-video', '8', '01', 'context', 'sidelist', 'thumbnail-gif', 'terminate', 'not-authorized', 'orientation', 'dhash', 'capability', 'side_list', 'md-app-state', 'description', 'serial', 'readreceipts', 'te', 'business_hours', 'md-msg-hist', 'tag', 'attribute_padding', 'document', 'open_24h', 'delete', 'expiration', 'active', 'prev_v_id', 'true', 'passive', 'index', '4', 'conflict', 'remove', 'w:gp2', 'config_expo_key', 'screen_height', 'replaced', '02', 'screen_width', 'uploadfieldstat', '2:47DEQpj8', 'media-bog1-1.cdn.whatsapp.net', 'encopt', 'url', 'catalog_exists', 'keygen', 'rate', 'offer', 'opus', 'media-mia3-1.cdn.whatsapp.net', 'privacy', 'media-mia3-2.cdn.whatsapp.net', 'signature', 'preaccept', 'token_id', 'media-eze1-1.cdn.whatsapp.net'
|
|
31
31
|
];
|
|
32
32
|
exports.TOKEN_MAP = {};
|
|
33
|
-
for (
|
|
34
|
-
exports.TOKEN_MAP[
|
|
33
|
+
for (const [i, SINGLE_BYTE_TOKEN] of exports.SINGLE_BYTE_TOKENS.entries()) {
|
|
34
|
+
exports.TOKEN_MAP[SINGLE_BYTE_TOKEN] = { index: i };
|
|
35
35
|
}
|
|
36
|
-
for (
|
|
37
|
-
for (
|
|
38
|
-
exports.TOKEN_MAP[
|
|
36
|
+
for (const [i, DOUBLE_BYTE_TOKEN] of exports.DOUBLE_BYTE_TOKENS.entries()) {
|
|
37
|
+
for (const [j, element] of DOUBLE_BYTE_TOKEN.entries()) {
|
|
38
|
+
exports.TOKEN_MAP[element] = { dict: i, index: j };
|
|
39
39
|
}
|
|
40
40
|
}
|
package/lib/WABinary/decode.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
|
3
|
-
export declare const decompressingIfRequired: (buffer: Buffer) => Buffer
|
|
4
|
+
export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer>;
|
|
4
5
|
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
|
|
5
6
|
index: number;
|
|
6
7
|
}) => BinaryNode;
|
|
7
|
-
export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode
|
|
8
|
+
export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -24,12 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
|
|
27
|
+
const util_1 = require("util");
|
|
27
28
|
const zlib_1 = require("zlib");
|
|
28
29
|
const constants = __importStar(require("./constants"));
|
|
29
30
|
const jid_utils_1 = require("./jid-utils");
|
|
30
|
-
const
|
|
31
|
+
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
32
|
+
const decompressingIfRequired = async (buffer) => {
|
|
31
33
|
if (2 & buffer.readUInt8()) {
|
|
32
|
-
buffer =
|
|
34
|
+
buffer = await inflatePromise(buffer.slice(1));
|
|
33
35
|
}
|
|
34
36
|
else { // nodes with no compression have a 0x00 prefix, we remove that
|
|
35
37
|
buffer = buffer.slice(1);
|
|
@@ -245,8 +247,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
245
247
|
};
|
|
246
248
|
};
|
|
247
249
|
exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
|
|
248
|
-
const decodeBinaryNode = (buff) => {
|
|
249
|
-
const decompBuff = (0, exports.decompressingIfRequired)(buff);
|
|
250
|
+
const decodeBinaryNode = async (buff) => {
|
|
251
|
+
const decompBuff = await (0, exports.decompressingIfRequired)(buff);
|
|
250
252
|
return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
|
|
251
253
|
};
|
|
252
254
|
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: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) =>
|
|
2
|
+
export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => number[];
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -35,7 +35,11 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
|
|
|
35
35
|
buffer.push((value >> (curShift * 8)) & 0xff);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
const pushBytes = (bytes) =>
|
|
38
|
+
const pushBytes = (bytes) => {
|
|
39
|
+
for (const b of bytes) {
|
|
40
|
+
buffer.push(b);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
39
43
|
const pushInt16 = (value) => {
|
|
40
44
|
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
41
45
|
};
|
|
@@ -137,8 +141,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
|
|
|
137
141
|
if (str.length > TAGS.PACKED_MAX) {
|
|
138
142
|
return false;
|
|
139
143
|
}
|
|
140
|
-
for (
|
|
141
|
-
const char = str[i];
|
|
144
|
+
for (const char of str) {
|
|
142
145
|
const isInNibbleRange = char >= '0' && char <= '9';
|
|
143
146
|
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
144
147
|
return false;
|
|
@@ -150,8 +153,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
|
|
|
150
153
|
if (str.length > TAGS.PACKED_MAX) {
|
|
151
154
|
return false;
|
|
152
155
|
}
|
|
153
|
-
for (
|
|
154
|
-
const char = str[i];
|
|
156
|
+
for (const char of str) {
|
|
155
157
|
const isInNibbleRange = char >= '0' && char <= '9';
|
|
156
158
|
if (!isInNibbleRange && !(char >= 'A' && char <= 'F') && !(char >= 'a' && char <= 'f')) {
|
|
157
159
|
return false;
|
|
@@ -223,6 +225,6 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
|
|
|
223
225
|
else {
|
|
224
226
|
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
225
227
|
}
|
|
226
|
-
return
|
|
228
|
+
return buffer;
|
|
227
229
|
};
|
|
228
230
|
exports.encodeBinaryNode = encodeBinaryNode;
|
|
@@ -9,7 +9,7 @@ export type JidWithDevice = {
|
|
|
9
9
|
device?: number;
|
|
10
10
|
};
|
|
11
11
|
export type FullJid = JidWithDevice & {
|
|
12
|
-
server: JidServer
|
|
12
|
+
server: JidServer;
|
|
13
13
|
domainType?: number;
|
|
14
14
|
};
|
|
15
15
|
export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
|
|
@@ -26,6 +26,6 @@ export declare const isJidBroadcast: (jid: string | undefined) => boolean | unde
|
|
|
26
26
|
export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
|
|
27
27
|
/** is the jid the status broadcast */
|
|
28
28
|
export declare const isJidStatusBroadcast: (jid: string) => boolean;
|
|
29
|
-
/** is the jid
|
|
30
|
-
export declare const
|
|
29
|
+
/** is the jid a newsletter */
|
|
30
|
+
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
|
31
31
|
export declare const jidNormalizedUser: (jid: string | undefined) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jidNormalizedUser = exports.
|
|
3
|
+
exports.jidNormalizedUser = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
4
4
|
exports.S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
5
5
|
exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
6
6
|
exports.SERVER_JID = 'server@c.us';
|
|
@@ -20,7 +20,7 @@ const jidDecode = (jid) => {
|
|
|
20
20
|
const [userAgent, device] = userCombined.split(':');
|
|
21
21
|
const user = userAgent.split('_')[0];
|
|
22
22
|
return {
|
|
23
|
-
server,
|
|
23
|
+
server: server,
|
|
24
24
|
user,
|
|
25
25
|
domainType: server === 'lid' ? 1 : 0,
|
|
26
26
|
device: device ? +device : undefined
|
|
@@ -48,9 +48,9 @@ exports.isJidGroup = isJidGroup;
|
|
|
48
48
|
/** is the jid the status broadcast */
|
|
49
49
|
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
50
50
|
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
|
51
|
-
/** is the jid
|
|
52
|
-
const
|
|
53
|
-
exports.
|
|
51
|
+
/** is the jid a newsletter */
|
|
52
|
+
const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
|
|
53
|
+
exports.isJidNewsletter = isJidNewsletter;
|
|
54
54
|
const jidNormalizedUser = (jid) => {
|
|
55
55
|
const result = (0, exports.jidDecode)(jid);
|
|
56
56
|
if (!result) {
|
package/lib/WAM/BinaryInfo.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
export declare class BinaryInfo {
|
|
3
4
|
protocolVersion: number;
|
|
4
5
|
sequence: number;
|
|
5
6
|
events: {
|
|
6
7
|
[x: string]: {
|
|
7
8
|
props: {
|
|
8
|
-
[x: string]:
|
|
9
|
+
[x: string]: import("./constants").Value;
|
|
9
10
|
};
|
|
10
11
|
globals: {
|
|
11
|
-
[x: string]:
|
|
12
|
+
[x: string]: import("./constants").Value;
|
|
12
13
|
};
|
|
13
14
|
};
|
|
14
15
|
}[];
|
package/lib/WAM/constants.d.ts
CHANGED
|
@@ -28,11 +28,12 @@ type EventByName<T extends Event['name']> = Extract<Event, {
|
|
|
28
28
|
export type EventInputType = {
|
|
29
29
|
[key in Event['name']]: {
|
|
30
30
|
props: {
|
|
31
|
-
[k in keyof EventByName<key>['props']]:
|
|
31
|
+
[k in keyof EventByName<key>['props']]: Value;
|
|
32
32
|
};
|
|
33
33
|
globals: {
|
|
34
|
-
[x: string]:
|
|
34
|
+
[x: string]: Value;
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
} & {};
|
|
38
|
+
export type Value = number | null | string;
|
|
38
39
|
export {};
|
package/lib/WAM/encode.d.ts
CHANGED
package/lib/WAM/encode.js
CHANGED
|
@@ -13,10 +13,10 @@ const encodeWAM = (binaryInfo) => {
|
|
|
13
13
|
.reduce((a, b) => a + b);
|
|
14
14
|
const buffer = Buffer.alloc(totalSize);
|
|
15
15
|
let offset = 0;
|
|
16
|
-
binaryInfo.buffer
|
|
16
|
+
for (const buffer_ of binaryInfo.buffer) {
|
|
17
17
|
buffer_.copy(buffer, offset);
|
|
18
18
|
offset += buffer_.length;
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
return buffer;
|
|
21
21
|
};
|
|
22
22
|
exports.encodeWAM = encodeWAM;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
|
3
|
+
import { USyncUser } from '../USyncUser';
|
|
4
|
+
export declare class USyncContactProtocol implements USyncQueryProtocol {
|
|
5
|
+
name: string;
|
|
6
|
+
getQueryElement(): BinaryNode;
|
|
7
|
+
getUserElement(user: USyncUser): BinaryNode;
|
|
8
|
+
parser(node: BinaryNode): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USyncContactProtocol = void 0;
|
|
4
|
+
const WABinary_1 = require("../../WABinary");
|
|
5
|
+
class USyncContactProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'contact';
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'contact',
|
|
12
|
+
attrs: {},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getUserElement(user) {
|
|
16
|
+
//TODO: Implement type / username fields (not yet supported)
|
|
17
|
+
return {
|
|
18
|
+
tag: 'contact',
|
|
19
|
+
attrs: {},
|
|
20
|
+
content: user.phone,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
parser(node) {
|
|
24
|
+
var _a;
|
|
25
|
+
if (node.tag === 'contact') {
|
|
26
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
27
|
+
return ((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'in';
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.USyncContactProtocol = USyncContactProtocol;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
|
3
|
+
export type KeyIndexData = {
|
|
4
|
+
timestamp: number;
|
|
5
|
+
signedKeyIndex?: Uint8Array;
|
|
6
|
+
expectedTimestamp?: number;
|
|
7
|
+
};
|
|
8
|
+
export type DeviceListData = {
|
|
9
|
+
id: number;
|
|
10
|
+
keyIndex?: number;
|
|
11
|
+
isHosted?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type ParsedDeviceInfo = {
|
|
14
|
+
deviceList?: DeviceListData[];
|
|
15
|
+
keyIndex?: KeyIndexData;
|
|
16
|
+
};
|
|
17
|
+
export declare class USyncDeviceProtocol implements USyncQueryProtocol {
|
|
18
|
+
name: string;
|
|
19
|
+
getQueryElement(): BinaryNode;
|
|
20
|
+
getUserElement(): BinaryNode | null;
|
|
21
|
+
parser(node: BinaryNode): ParsedDeviceInfo;
|
|
22
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USyncDeviceProtocol = void 0;
|
|
4
|
+
const WABinary_1 = require("../../WABinary");
|
|
5
|
+
class USyncDeviceProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'devices';
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'devices',
|
|
12
|
+
attrs: {
|
|
13
|
+
version: '2',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
getUserElement( /* user: USyncUser */) {
|
|
18
|
+
//TODO: Implement device phashing, ts and expectedTs
|
|
19
|
+
//TODO: if all are not present, return null <- current behavior
|
|
20
|
+
//TODO: otherwise return a node w tag 'devices' w those as attrs
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
parser(node) {
|
|
24
|
+
const deviceList = [];
|
|
25
|
+
let keyIndex = undefined;
|
|
26
|
+
if (node.tag === 'devices') {
|
|
27
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
28
|
+
const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list');
|
|
29
|
+
const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list');
|
|
30
|
+
if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
|
|
31
|
+
for (const { tag, attrs } of deviceListNode.content) {
|
|
32
|
+
const id = +attrs.id;
|
|
33
|
+
const keyIndex = +attrs['key-index'];
|
|
34
|
+
if (tag === 'device') {
|
|
35
|
+
deviceList.push({
|
|
36
|
+
id,
|
|
37
|
+
keyIndex,
|
|
38
|
+
isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list') {
|
|
44
|
+
keyIndex = {
|
|
45
|
+
timestamp: +keyIndexNode.attrs['ts'],
|
|
46
|
+
signedKeyIndex: keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.content,
|
|
47
|
+
expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
deviceList,
|
|
53
|
+
keyIndex
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.USyncDeviceProtocol = USyncDeviceProtocol;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
|
3
|
+
export type DisappearingModeData = {
|
|
4
|
+
duration: number;
|
|
5
|
+
setAt?: Date;
|
|
6
|
+
};
|
|
7
|
+
export declare class USyncDisappearingModeProtocol implements USyncQueryProtocol {
|
|
8
|
+
name: string;
|
|
9
|
+
getQueryElement(): BinaryNode;
|
|
10
|
+
getUserElement(): null;
|
|
11
|
+
parser(node: BinaryNode): DisappearingModeData | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USyncDisappearingModeProtocol = void 0;
|
|
4
|
+
const WABinary_1 = require("../../WABinary");
|
|
5
|
+
class USyncDisappearingModeProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'disappearing_mode';
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'disappearing_mode',
|
|
12
|
+
attrs: {},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getUserElement() {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
parser(node) {
|
|
19
|
+
if (node.tag === 'status') {
|
|
20
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
21
|
+
const duration = +(node === null || node === void 0 ? void 0 : node.attrs.duration);
|
|
22
|
+
const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
|
|
23
|
+
return {
|
|
24
|
+
duration,
|
|
25
|
+
setAt,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
|
3
|
+
export type StatusData = {
|
|
4
|
+
status?: string | null;
|
|
5
|
+
setAt?: Date;
|
|
6
|
+
};
|
|
7
|
+
export declare class USyncStatusProtocol implements USyncQueryProtocol {
|
|
8
|
+
name: string;
|
|
9
|
+
getQueryElement(): BinaryNode;
|
|
10
|
+
getUserElement(): null;
|
|
11
|
+
parser(node: BinaryNode): StatusData | undefined;
|
|
12
|
+
}
|