@vinzsocket/baileys 2.8.10 → 2.8.30

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.
Files changed (83) hide show
  1. package/lib/Defaults/index.js +75 -73
  2. package/lib/Signal/Group/ciphertext-message.js +9 -9
  3. package/lib/Signal/Group/group-session-builder.js +21 -21
  4. package/lib/Signal/Group/group_cipher.js +79 -81
  5. package/lib/Signal/Group/index.js +2 -2
  6. package/lib/Signal/Group/keyhelper.js +9 -9
  7. package/lib/Signal/Group/queue-job.js +43 -46
  8. package/lib/Signal/Group/sender-chain-key.js +24 -25
  9. package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
  10. package/lib/Signal/Group/sender-key-message.js +55 -60
  11. package/lib/Signal/Group/sender-key-name.js +38 -39
  12. package/lib/Signal/Group/sender-key-record.js +39 -41
  13. package/lib/Signal/Group/sender-key-state.js +85 -89
  14. package/lib/Signal/Group/sender-message-key.js +22 -22
  15. package/lib/Signal/libsignal.js +387 -292
  16. package/lib/Signal/lid-mapping.js +98 -93
  17. package/lib/Socket/Client/types.js +6 -6
  18. package/lib/Socket/Client/websocket.js +44 -44
  19. package/lib/Socket/business.js +350 -365
  20. package/lib/Socket/chats.js +1019 -914
  21. package/lib/Socket/communities.js +454 -376
  22. package/lib/Socket/groups.js +378 -310
  23. package/lib/Socket/index.js +11 -11
  24. package/lib/Socket/messages-recv.js +1355 -1182
  25. package/lib/Socket/messages-send.js +1224 -1081
  26. package/lib/Socket/mex.js +40 -34
  27. package/lib/Socket/newsletter.js +212 -169
  28. package/lib/Socket/socket.js +896 -757
  29. package/lib/Store/index.js +1 -1
  30. package/lib/Store/make-cache-manager-store.js +75 -79
  31. package/lib/Store/make-in-memory-store.js +450 -389
  32. package/lib/Store/make-ordered-dictionary.js +73 -76
  33. package/lib/Store/object-repository.js +24 -22
  34. package/lib/Types/Chat.js +1 -7
  35. package/lib/Types/Label.js +20 -20
  36. package/lib/Types/LabelAssociation.js +2 -2
  37. package/lib/Types/Message.js +2 -2
  38. package/lib/Types/Newsletter.js +24 -24
  39. package/lib/Types/Socket.js +1 -1
  40. package/lib/Types/State.js +8 -8
  41. package/lib/Types/index.js +10 -10
  42. package/lib/Utils/auth-utils.js +408 -401
  43. package/lib/Utils/baileys-event-stream.js +44 -35
  44. package/lib/Utils/business.js +200 -197
  45. package/lib/Utils/chat-utils.js +775 -708
  46. package/lib/Utils/crypto.js +97 -85
  47. package/lib/Utils/decode-wa-message.js +240 -227
  48. package/lib/Utils/event-buffer.js +547 -518
  49. package/lib/Utils/extended-messages.js +250 -203
  50. package/lib/Utils/generics.js +300 -289
  51. package/lib/Utils/history.js +76 -69
  52. package/lib/Utils/lid-resolver.js +47 -42
  53. package/lib/Utils/link-preview.js +75 -65
  54. package/lib/Utils/logger.js +3 -1
  55. package/lib/Utils/lt-hash.js +38 -34
  56. package/lib/Utils/make-mutex.js +32 -34
  57. package/lib/Utils/mention.js +79 -86
  58. package/lib/Utils/message-retry-manager.js +148 -136
  59. package/lib/Utils/messages-media.js +652 -562
  60. package/lib/Utils/messages.js +753 -707
  61. package/lib/Utils/noise-handler.js +156 -135
  62. package/lib/Utils/process-message.js +404 -341
  63. package/lib/Utils/signal.js +180 -118
  64. package/lib/Utils/use-multi-file-auth-state.js +87 -91
  65. package/lib/Utils/validate-connection.js +167 -142
  66. package/lib/WABinary/constants.js +28 -1293
  67. package/lib/WABinary/decode.js +220 -218
  68. package/lib/WABinary/encode.js +199 -201
  69. package/lib/WABinary/generic-utils.js +80 -77
  70. package/lib/WABinary/jid-utils.js +41 -35
  71. package/lib/WAM/BinaryInfo.js +7 -7
  72. package/lib/WAM/constants.js +1 -15241
  73. package/lib/WAM/encode.js +124 -131
  74. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
  76. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
  77. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
  78. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
  81. package/lib/WAUSync/USyncQuery.js +82 -84
  82. package/lib/WAUSync/USyncUser.js +20 -20
  83. package/package.json +4 -2
@@ -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
- constructor(keys, onWhatsAppFunc) {
6
- this.keys = keys;
7
- this.onWhatsAppFunc = onWhatsAppFunc; // needed to get LID from PN if not found
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
- * Store LID-PN mapping - USER LEVEL
11
- */
12
- async storeLIDPNMapping(lid, pn) {
13
- return this.storeLIDPNMappings([{ lid, pn }]);
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
- * Store LID-PN mapping - USER LEVEL
17
- */
18
- async storeLIDPNMappings(pairs) {
19
- // Validate inputs
20
- const pairMap = {};
21
- for (const { lid, pn } of pairs) {
22
- if (!((isLidUser(lid) && isPnUser(pn)) || (isPnUser(lid) && isLidUser(pn)))) {
23
- logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
24
- continue;
25
- }
26
- const [lidJid, pnJid] = isLidUser(lid) ? [lid, pn] : [pn, lid];
27
- const lidDecoded = jidDecode(lidJid);
28
- const pnDecoded = jidDecode(pnJid);
29
- if (!lidDecoded || !pnDecoded)
30
- return;
31
- const pnUser = pnDecoded.user;
32
- const lidUser = lidDecoded.user;
33
- pairMap[pnUser] = lidUser;
34
- }
35
- logger.trace({ pairMap }, `Storing ${Object.keys(pairMap).length} pn mappings`);
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
- constructor(url, config) {
5
- super();
6
- this.url = url;
7
- this.config = config;
8
- this.setMaxListeners(0);
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
- 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
- }
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