@vinzsocket/baileys 2.8.9 → 2.8.20
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/lib/Defaults/index.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +4 -1
|
@@ -2,101 +2,106 @@ import logger from '../Utils/logger.js';
|
|
|
2
2
|
import { isLidUser, isPnUser, jidDecode } from '../WABinary/index.js';
|
|
3
3
|
//TODO: Caching
|
|
4
4
|
export class LIDMappingStore {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
constructor(keys, onWhatsAppFunc) {
|
|
6
|
+
this.keys = keys;
|
|
7
|
+
this.onWhatsAppFunc = onWhatsAppFunc; // needed to get LID from PN if not found
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Store LID-PN mapping - USER LEVEL
|
|
11
|
+
*/
|
|
12
|
+
async storeLIDPNMapping(lid, pn) {
|
|
13
|
+
return this.storeLIDPNMappings([{
|
|
14
|
+
lid,
|
|
15
|
+
pn
|
|
16
|
+
}]);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Store LID-PN mapping - USER LEVEL
|
|
20
|
+
*/
|
|
21
|
+
async storeLIDPNMappings(pairs) {
|
|
22
|
+
// Validate inputs
|
|
23
|
+
const pairMap = {};
|
|
24
|
+
for (const {
|
|
25
|
+
lid,
|
|
26
|
+
pn
|
|
27
|
+
} of pairs) {
|
|
28
|
+
if (!(isLidUser(lid) && isPnUser(pn) || isPnUser(lid) && isLidUser(pn))) {
|
|
29
|
+
logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const [lidJid, pnJid] = isLidUser(lid) ? [lid, pn] : [pn, lid];
|
|
33
|
+
const lidDecoded = jidDecode(lidJid);
|
|
34
|
+
const pnDecoded = jidDecode(pnJid);
|
|
35
|
+
if (!lidDecoded || !pnDecoded) return;
|
|
36
|
+
const pnUser = pnDecoded.user;
|
|
37
|
+
const lidUser = lidDecoded.user;
|
|
38
|
+
pairMap[pnUser] = lidUser;
|
|
8
39
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
async
|
|
13
|
-
|
|
40
|
+
logger.trace({
|
|
41
|
+
pairMap
|
|
42
|
+
}, `Storing ${Object.keys(pairMap).length} pn mappings`);
|
|
43
|
+
await this.keys.transaction(async () => {
|
|
44
|
+
for (const [pnUser, lidUser] of Object.entries(pairMap)) {
|
|
45
|
+
await this.keys.set({
|
|
46
|
+
'lid-mapping': {
|
|
47
|
+
[pnUser]: lidUser,
|
|
48
|
+
// "554396160286" -> "102765716062358"
|
|
49
|
+
[`${lidUser}_reverse`]: pnUser // "102765716062358_reverse" -> "554396160286"
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}, 'lid-mapping');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get LID for PN - Returns device-specific LID based on user mapping
|
|
57
|
+
*/
|
|
58
|
+
async getLIDForPN(pn) {
|
|
59
|
+
if (!isPnUser(pn)) return null;
|
|
60
|
+
const decoded = jidDecode(pn);
|
|
61
|
+
if (!decoded) return null;
|
|
62
|
+
// Look up user-level mapping (whatsmeow approach)
|
|
63
|
+
const pnUser = decoded.user;
|
|
64
|
+
const stored = await this.keys.get('lid-mapping', [pnUser]);
|
|
65
|
+
let lidUser = stored[pnUser];
|
|
66
|
+
if (!lidUser) {
|
|
67
|
+
logger.trace(`No LID mapping found for PN user ${pnUser}; getting from USync`);
|
|
68
|
+
const {
|
|
69
|
+
exists,
|
|
70
|
+
lid
|
|
71
|
+
} = (await this.onWhatsAppFunc?.(pn))?.[0];
|
|
72
|
+
if (exists) {
|
|
73
|
+
lidUser = jidDecode(lid)?.user;
|
|
74
|
+
} else {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
14
77
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
await this.keys.transaction(async () => {
|
|
37
|
-
for (const [pnUser, lidUser] of Object.entries(pairMap)) {
|
|
38
|
-
await this.keys.set({
|
|
39
|
-
'lid-mapping': {
|
|
40
|
-
[pnUser]: lidUser, // "554396160286" -> "102765716062358"
|
|
41
|
-
[`${lidUser}_reverse`]: pnUser // "102765716062358_reverse" -> "554396160286"
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}, 'lid-mapping');
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Get LID for PN - Returns device-specific LID based on user mapping
|
|
49
|
-
*/
|
|
50
|
-
async getLIDForPN(pn) {
|
|
51
|
-
if (!isPnUser(pn))
|
|
52
|
-
return null;
|
|
53
|
-
const decoded = jidDecode(pn);
|
|
54
|
-
if (!decoded)
|
|
55
|
-
return null;
|
|
56
|
-
// Look up user-level mapping (whatsmeow approach)
|
|
57
|
-
const pnUser = decoded.user;
|
|
58
|
-
const stored = await this.keys.get('lid-mapping', [pnUser]);
|
|
59
|
-
let lidUser = stored[pnUser];
|
|
60
|
-
if (!lidUser) {
|
|
61
|
-
logger.trace(`No LID mapping found for PN user ${pnUser}; getting from USync`);
|
|
62
|
-
const { exists, lid } = (await this.onWhatsAppFunc?.(pn))?.[0];
|
|
63
|
-
if (exists) {
|
|
64
|
-
lidUser = jidDecode(lid)?.user;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (typeof lidUser !== 'string')
|
|
71
|
-
return null;
|
|
72
|
-
// Push the PN device ID to the LID to maintain device separation
|
|
73
|
-
const pnDevice = decoded.device !== undefined ? decoded.device : 0;
|
|
74
|
-
const deviceSpecificLid = `${lidUser}:${pnDevice}@lid`;
|
|
75
|
-
logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`);
|
|
76
|
-
return deviceSpecificLid;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Get PN for LID - USER LEVEL with device construction
|
|
80
|
-
*/
|
|
81
|
-
async getPNForLID(lid) {
|
|
82
|
-
if (!isLidUser(lid))
|
|
83
|
-
return null;
|
|
84
|
-
const decoded = jidDecode(lid);
|
|
85
|
-
if (!decoded)
|
|
86
|
-
return null;
|
|
87
|
-
// Look up reverse user mapping
|
|
88
|
-
const lidUser = decoded.user;
|
|
89
|
-
const stored = await this.keys.get('lid-mapping', [`${lidUser}_reverse`]);
|
|
90
|
-
const pnUser = stored[`${lidUser}_reverse`];
|
|
91
|
-
if (!pnUser || typeof pnUser !== 'string') {
|
|
92
|
-
logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
// Construct device-specific PN JID
|
|
96
|
-
const lidDevice = decoded.device !== undefined ? decoded.device : 0;
|
|
97
|
-
const pnJid = `${pnUser}:${lidDevice}@s.whatsapp.net`;
|
|
98
|
-
logger.trace(`Found reverse mapping: ${lid} → ${pnJid}`);
|
|
99
|
-
return pnJid;
|
|
78
|
+
if (typeof lidUser !== 'string') return null;
|
|
79
|
+
// Push the PN device ID to the LID to maintain device separation
|
|
80
|
+
const pnDevice = decoded.device !== undefined ? decoded.device : 0;
|
|
81
|
+
const deviceSpecificLid = `${lidUser}:${pnDevice}@lid`;
|
|
82
|
+
logger.trace(`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`);
|
|
83
|
+
return deviceSpecificLid;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get PN for LID - USER LEVEL with device construction
|
|
87
|
+
*/
|
|
88
|
+
async getPNForLID(lid) {
|
|
89
|
+
if (!isLidUser(lid)) return null;
|
|
90
|
+
const decoded = jidDecode(lid);
|
|
91
|
+
if (!decoded) return null;
|
|
92
|
+
// Look up reverse user mapping
|
|
93
|
+
const lidUser = decoded.user;
|
|
94
|
+
const stored = await this.keys.get('lid-mapping', [`${lidUser}_reverse`]);
|
|
95
|
+
const pnUser = stored[`${lidUser}_reverse`];
|
|
96
|
+
if (!pnUser || typeof pnUser !== 'string') {
|
|
97
|
+
logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
|
|
98
|
+
return null;
|
|
100
99
|
}
|
|
100
|
+
// Construct device-specific PN JID
|
|
101
|
+
const lidDevice = decoded.device !== undefined ? decoded.device : 0;
|
|
102
|
+
const pnJid = `${pnUser}:${lidDevice}@s.whatsapp.net`;
|
|
103
|
+
logger.trace(`Found reverse mapping: ${lid} → ${pnJid}`);
|
|
104
|
+
return pnJid;
|
|
105
|
+
}
|
|
101
106
|
}
|
|
102
107
|
//# sourceMappingURL=lid-mapping.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { URL } from 'url';
|
|
3
3
|
export class AbstractSocketClient extends EventEmitter {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
constructor(url, config) {
|
|
5
|
+
super();
|
|
6
|
+
this.url = url;
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.setMaxListeners(0);
|
|
9
|
+
}
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=types.js.map
|
|
@@ -2,49 +2,49 @@ import WebSocket from 'ws';
|
|
|
2
2
|
import { DEFAULT_ORIGIN } from '../../Defaults/index.js';
|
|
3
3
|
import { AbstractSocketClient } from './types.js';
|
|
4
4
|
export class WebSocketClient extends AbstractSocketClient {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.socket = null;
|
|
8
|
+
}
|
|
9
|
+
get isOpen() {
|
|
10
|
+
return this.socket?.readyState === WebSocket.OPEN;
|
|
11
|
+
}
|
|
12
|
+
get isClosed() {
|
|
13
|
+
return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
|
|
14
|
+
}
|
|
15
|
+
get isClosing() {
|
|
16
|
+
return this.socket === null || this.socket?.readyState === WebSocket.CLOSING;
|
|
17
|
+
}
|
|
18
|
+
get isConnecting() {
|
|
19
|
+
return this.socket?.readyState === WebSocket.CONNECTING;
|
|
20
|
+
}
|
|
21
|
+
async connect() {
|
|
22
|
+
if (this.socket) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.socket = new WebSocket(this.url, {
|
|
26
|
+
origin: DEFAULT_ORIGIN,
|
|
27
|
+
headers: this.config.options?.headers,
|
|
28
|
+
handshakeTimeout: this.config.connectTimeoutMs,
|
|
29
|
+
timeout: this.config.connectTimeoutMs,
|
|
30
|
+
agent: this.config.agent
|
|
31
|
+
});
|
|
32
|
+
this.socket.setMaxListeners(0);
|
|
33
|
+
const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
|
|
34
|
+
for (const event of events) {
|
|
35
|
+
this.socket?.on(event, (...args) => this.emit(event, ...args));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async close() {
|
|
39
|
+
if (!this.socket) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.socket.close();
|
|
43
|
+
this.socket = null;
|
|
44
|
+
}
|
|
45
|
+
send(str, cb) {
|
|
46
|
+
this.socket?.send(str, cb);
|
|
47
|
+
return Boolean(this.socket);
|
|
48
|
+
}
|
|
49
49
|
}
|
|
50
50
|
//# sourceMappingURL=websocket.js.map
|