@queenanya/baileys 8.2.7-beta → 8.3.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.
Files changed (78) hide show
  1. package/WAProto/index.d.ts +1590 -6
  2. package/WAProto/index.js +4635 -3
  3. package/engine-requirements.js +1 -1
  4. package/lib/Defaults/baileys-version.json +1 -1
  5. package/lib/Defaults/index.d.ts +232 -1
  6. package/lib/Defaults/index.js +21 -6
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/Socket/Client/index.d.ts +3 -2
  9. package/lib/Socket/Client/index.js +3 -2
  10. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  11. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  12. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  13. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +3 -3
  14. package/lib/Socket/business.d.ts +4 -9
  15. package/lib/Socket/chats.d.ts +3 -9
  16. package/lib/Socket/chats.js +6 -89
  17. package/lib/Socket/groups.d.ts +3 -7
  18. package/lib/Socket/groups.js +13 -9
  19. package/lib/Socket/index.d.ts +6 -9
  20. package/lib/Socket/index.js +2 -2
  21. package/lib/Socket/messages-recv.d.ts +4 -9
  22. package/lib/Socket/messages-recv.js +13 -23
  23. package/lib/Socket/messages-send.d.ts +3 -8
  24. package/lib/Socket/messages-send.js +55 -86
  25. package/lib/Socket/newsletter.d.ts +3 -7
  26. package/lib/Socket/newsletter.js +2 -4
  27. package/lib/Socket/registration.d.ts +266 -0
  28. package/lib/Socket/registration.js +166 -0
  29. package/lib/Socket/socket.d.ts +1 -2
  30. package/lib/Socket/socket.js +15 -10
  31. package/lib/Socket/usync.d.ts +1 -1
  32. package/lib/Socket/usync.js +15 -10
  33. package/lib/Store/make-in-memory-store.js +10 -8
  34. package/lib/Types/Auth.d.ts +6 -0
  35. package/lib/Types/Chat.d.ts +2 -8
  36. package/lib/Types/Contact.d.ts +4 -5
  37. package/lib/Types/GroupMetadata.d.ts +4 -3
  38. package/lib/Types/Label.d.ts +0 -11
  39. package/lib/Types/Message.d.ts +5 -5
  40. package/lib/Types/Socket.d.ts +3 -5
  41. package/lib/Utils/auth-utils.js +7 -0
  42. package/lib/Utils/chat-utils.d.ts +8 -8
  43. package/lib/Utils/chat-utils.js +4 -30
  44. package/lib/Utils/crypto.d.ts +1 -1
  45. package/lib/Utils/crypto.js +1 -3
  46. package/lib/Utils/decode-wa-message.d.ts +2 -4
  47. package/lib/Utils/decode-wa-message.js +18 -161
  48. package/lib/Utils/event-buffer.js +6 -4
  49. package/lib/Utils/generics.d.ts +18 -8
  50. package/lib/Utils/generics.js +93 -7
  51. package/lib/Utils/history.js +1 -1
  52. package/lib/Utils/messages-media.d.ts +9 -16
  53. package/lib/Utils/messages-media.js +175 -88
  54. package/lib/Utils/messages.d.ts +1 -1
  55. package/lib/Utils/messages.js +17 -15
  56. package/lib/Utils/noise-handler.d.ts +2 -1
  57. package/lib/Utils/noise-handler.js +10 -5
  58. package/lib/Utils/validate-connection.d.ts +1 -0
  59. package/lib/Utils/validate-connection.js +50 -16
  60. package/lib/WABinary/constants.d.ts +4 -4
  61. package/lib/WABinary/constants.js +1271 -8
  62. package/lib/WABinary/encode.js +5 -7
  63. package/lib/WABinary/jid-utils.d.ts +4 -4
  64. package/lib/WABinary/jid-utils.js +19 -19
  65. package/lib/WAM/constants.d.ts +2 -3
  66. package/lib/WAM/encode.js +2 -2
  67. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  68. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  69. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +3 -3
  70. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  71. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  72. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
  73. package/lib/WAUSync/USyncQuery.js +13 -17
  74. package/package.json +25 -23
  75. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  76. package/lib/Store/make-cache-manager-store.js +0 -83
  77. /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
  78. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processSyncAction = exports.chatModificationToAppPatch = exports.decodePatches = exports.decodeSyncdSnapshot = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.extractSyncdPatches = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.encodeSyncdPatch = exports.newLTHashState = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
5
  const WAProto_1 = require("../../WAProto");
6
- const LabelAssociation_1 = require("../Types/LabelAssociation");
7
6
  const WABinary_1 = require("../WABinary");
7
+ const LabelAssociation_1 = require("../Types/LabelAssociation");
8
8
  const crypto_1 = require("./crypto");
9
9
  const generics_1 = require("./generics");
10
10
  const lt_hash_1 = require("./lt-hash");
@@ -305,7 +305,8 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
305
305
  indexValueMap: { ...initial.indexValueMap }
306
306
  };
307
307
  const mutationMap = {};
308
- for (const syncd of syncds) {
308
+ for (let i = 0; i < syncds.length; i++) {
309
+ const syncd = syncds[i];
309
310
  const { version, keyId, snapshotMac } = syncd;
310
311
  if (syncd.externalMutations) {
311
312
  logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
@@ -456,17 +457,6 @@ const chatModificationToAppPatch = (mod, jid) => {
456
457
  operation: OP.SET
457
458
  };
458
459
  }
459
- else if ('contact' in mod) {
460
- patch = {
461
- syncAction: {
462
- contactAction: mod.contact || {}
463
- },
464
- index: ['contact', jid],
465
- type: 'critical_unblock_low',
466
- apiVersion: 2,
467
- operation: mod.contact ? OP.SET : OP.REMOVE
468
- };
469
- }
470
460
  else if ('star' in mod) {
471
461
  const key = mod.star.messages[0];
472
462
  patch = {
@@ -507,22 +497,6 @@ const chatModificationToAppPatch = (mod, jid) => {
507
497
  operation: OP.SET,
508
498
  };
509
499
  }
510
- else if ('addLabel' in mod) {
511
- patch = {
512
- syncAction: {
513
- labelEditAction: {
514
- name: mod.addLabel.name,
515
- color: mod.addLabel.color,
516
- predefinedId: mod.addLabel.predefinedId,
517
- deleted: mod.addLabel.deleted
518
- }
519
- },
520
- index: ['label_edit', mod.addLabel.id],
521
- type: 'regular',
522
- apiVersion: 3,
523
- operation: OP.SET,
524
- };
525
- }
526
500
  else if ('addChatLabel' in mod) {
527
501
  patch = {
528
502
  syncAction: {
@@ -665,7 +639,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
665
639
  });
666
640
  }
667
641
  else if (action === null || action === void 0 ? void 0 : action.contactAction) {
668
- ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName }]);
642
+ ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName, lid: action.contactAction.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(id) ? id : action.contactAction.pnJid }]);
669
643
  }
670
644
  else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
671
645
  const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
@@ -35,6 +35,6 @@ export declare function sha256(buffer: Buffer): Buffer<ArrayBufferLike>;
35
35
  export declare function md5(buffer: Buffer): Buffer<ArrayBufferLike>;
36
36
  export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
37
37
  salt?: Buffer;
38
- info?: string | Buffer;
38
+ info?: string;
39
39
  }): Promise<Buffer>;
40
40
  export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
@@ -159,9 +159,7 @@ async function hkdf(buffer, expandedLength, info) {
159
159
  // Set default values if not provided
160
160
  const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
161
161
  const infoBytes = info.info
162
- ? (typeof info.info === 'string'
163
- ? new TextEncoder().encode(info.info)
164
- : new Uint8Array(info.info))
162
+ ? new TextEncoder().encode(info.info)
165
163
  : new Uint8Array(0);
166
164
  // Import the input key material
167
165
  const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
@@ -1,6 +1,6 @@
1
1
  import { proto } from '../../WAProto';
2
2
  import { ILogger } from './logger';
3
- import { SignalRepository, WAMessageKey } from '../Types';
3
+ import { SignalRepository } from '../Types';
4
4
  import { BinaryNode } from '../WABinary';
5
5
  export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
6
6
  export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
@@ -19,7 +19,6 @@ export declare const NACK_REASONS: {
19
19
  UnsupportedLIDGroup: number;
20
20
  DBOperationFailed: number;
21
21
  };
22
- type GetMessage = (key: WAMessageKey) => Promise<proto.IMessage | undefined>;
23
22
  /**
24
23
  * Decode the received node as a message.
25
24
  * @note this will only parse the message, not decrypt it
@@ -29,10 +28,9 @@ export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLi
29
28
  author: string;
30
29
  sender: string;
31
30
  };
32
- export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger, getMessage: GetMessage) => {
31
+ export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
33
32
  fullMessage: proto.IWebMessageInfo;
34
33
  category: string;
35
34
  author: string;
36
35
  decrypt(): Promise<void>;
37
36
  };
38
- export {};
@@ -6,12 +6,8 @@ const boom_1 = require("@hapi/boom");
6
6
  const WAProto_1 = require("../../WAProto");
7
7
  const WABinary_1 = require("../WABinary");
8
8
  const generics_1 = require("./generics");
9
- const crypto_1 = require("./crypto");
10
- const crypto_2 = require("crypto");
11
9
  exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
12
10
  exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
13
- const BOT_MESSAGE_CONSTANT = "Bot Message";
14
- const KEY_LENGTH = 32;
15
11
  exports.NACK_REASONS = {
16
12
  ParsingError: 487,
17
13
  UnrecognizedStanza: 488,
@@ -27,115 +23,33 @@ exports.NACK_REASONS = {
27
23
  UnsupportedLIDGroup: 551,
28
24
  DBOperationFailed: 552
29
25
  };
30
- const deriveMessageSecret = async (messageSecret) => {
31
- // Always convert to Buffer to ensure compatibility
32
- const secretBuffer = Buffer.isBuffer(messageSecret)
33
- ? messageSecret
34
- : Buffer.from(messageSecret.buffer, messageSecret.byteOffset, messageSecret.length);
35
- return await (0, crypto_1.hkdf)(secretBuffer, KEY_LENGTH, { info: BOT_MESSAGE_CONSTANT });
36
- };
37
- const buildDecryptionKey = async (messageID, botJID, targetJID, messageSecret) => {
38
- const derivedSecret = await deriveMessageSecret(messageSecret);
39
- const useCaseSecret = Buffer.concat([
40
- Buffer.from(messageID),
41
- Buffer.from(targetJID),
42
- Buffer.from(botJID),
43
- Buffer.from("")
44
- ]);
45
- return await (0, crypto_1.hkdf)(derivedSecret, KEY_LENGTH, { info: useCaseSecret });
46
- };
47
- const decryptBotMessage = async (encPayload, encIv, messageID, botJID, decryptionKey) => {
48
- encPayload = Buffer.isBuffer(encPayload) ? encPayload : Buffer.from(encPayload);
49
- encIv = Buffer.isBuffer(encIv) ? encIv : Buffer.from(encIv);
50
- decryptionKey = Buffer.isBuffer(decryptionKey) ? decryptionKey : Buffer.from(decryptionKey);
51
- if (encIv.length !== 12) {
52
- throw new Error(`IV size incorrect: expected 12, got ${encIv.length}`);
53
- }
54
- const authTag = encPayload.slice(-16);
55
- const encryptedData = encPayload.slice(0, -16);
56
- if (encryptedData.length < 16) {
57
- throw new Error(`Encrypted data too short: ${encryptedData.length} bytes`);
58
- }
59
- const aad = Buffer.concat([
60
- Buffer.from(messageID),
61
- Buffer.from([0]),
62
- Buffer.from(botJID)
63
- ]);
64
- try {
65
- const decipher = (0, crypto_2.createDecipheriv)("aes-256-gcm", decryptionKey, encIv);
66
- decipher.setAAD(aad);
67
- decipher.setAuthTag(authTag);
68
- const decrypted = Buffer.concat([
69
- decipher.update(encryptedData),
70
- decipher.final()
71
- ]);
72
- return decrypted;
73
- }
74
- catch (error) {
75
- console.error("Decrypt - Failed with:", error.message);
76
- throw error;
77
- }
78
- };
79
- const decryptMsmsgBotMessage = async (messageSecret, messageKey, msMsg) => {
80
- try {
81
- const { targetId, participant: botJID, meId: targetJID } = messageKey;
82
- if (!targetId || !botJID || !targetJID || !messageSecret) {
83
- throw new Error("Missing required components for decryption");
84
- }
85
- const decryptionKey = await buildDecryptionKey(targetId, botJID, targetJID, messageSecret);
86
- if (!msMsg.encPayload) {
87
- throw new Error('Missing encPayload');
88
- }
89
- if (!msMsg.encIv) {
90
- throw new Error('Missing encIv');
91
- }
92
- return await decryptBotMessage(msMsg.encPayload, msMsg.encIv, targetId, botJID, decryptionKey);
93
- }
94
- catch (error) {
95
- console.error("Failed to decrypt bot message:", error);
96
- throw error;
97
- }
98
- };
99
- const decryptBotMsg = async (content, { messageKey, messageSecret }) => {
100
- try {
101
- const msMsg = WAProto_1.proto.MessageSecretMessage.decode(content);
102
- return await decryptMsmsgBotMessage(messageSecret, messageKey, msMsg);
103
- }
104
- catch (error) {
105
- console.error("Error in decryptBotMsg:", error);
106
- throw error;
107
- }
108
- };
109
26
  /**
110
27
  * Decode the received node as a message.
111
28
  * @note this will only parse the message, not decrypt it
112
29
  */
113
30
  function decodeMessageNode(stanza, meId, meLid) {
114
- var _a, _b, _c, _d;
31
+ var _a, _b, _c, _d, _e, _f, _g;
115
32
  let msgType;
116
33
  let chatId;
117
34
  let author;
118
- let userLid;
119
35
  const msgId = stanza.attrs.id;
120
36
  const from = stanza.attrs.from;
37
+ const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
38
+ const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
121
39
  const participant = stanza.attrs.participant;
122
- const participantLid = stanza.attrs.participant_lid;
40
+ const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
123
41
  const recipient = stanza.attrs.recipient;
124
- const peerRecipientLid = stanza.attrs.peer_recipient_lid;
125
- const senderLid = stanza.attrs.sender_lid;
126
42
  const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
127
43
  const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
128
- if ((0, WABinary_1.isJidMetaAI)(from) || (0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
129
- if (recipient && !(0, WABinary_1.isJidMetaAI)(recipient)) {
44
+ if ((0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
45
+ if (recipient && !(0, WABinary_1.isJidMetaAi)(recipient)) {
130
46
  if (!isMe(from) && !isMeLid(from)) {
131
47
  throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
132
48
  }
133
49
  chatId = recipient;
134
- userLid = peerRecipientLid;
135
50
  }
136
51
  else {
137
52
  chatId = from;
138
- userLid = senderLid;
139
53
  }
140
54
  msgType = 'chat';
141
55
  author = from;
@@ -147,7 +61,6 @@ function decodeMessageNode(stanza, meId, meLid) {
147
61
  msgType = 'group';
148
62
  author = participant;
149
63
  chatId = from;
150
- userLid = participantLid;
151
64
  }
152
65
  else if ((0, WABinary_1.isJidNewsletter)(from)) {
153
66
  msgType = 'newsletter';
@@ -156,7 +69,7 @@ function decodeMessageNode(stanza, meId, meLid) {
156
69
  }
157
70
  else if ((0, WABinary_1.isJidBroadcast)(from)) {
158
71
  if (!participant) {
159
- throw new boom_1.Boom('No participant in broadcast message');
72
+ throw new boom_1.Boom('No participant in group message');
160
73
  }
161
74
  const isParticipantMe = isMe(participant);
162
75
  if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
@@ -167,26 +80,21 @@ function decodeMessageNode(stanza, meId, meLid) {
167
80
  }
168
81
  chatId = from;
169
82
  author = participant;
170
- userLid = participantLid;
171
- }
172
- else if ((0, WABinary_1.isJidNewsletter)(from)) {
173
- msgType = 'newsletter';
174
- author = from;
175
- chatId = from;
176
- userLid = participantLid;
177
83
  }
178
84
  else {
179
85
  throw new boom_1.Boom('Unknown message type', { data: stanza });
180
86
  }
181
- const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) || false : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
182
- const pushname = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.notify;
87
+ const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.is_sender) || false : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
88
+ const pushname = (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.notify;
183
89
  const key = {
184
90
  remoteJid: chatId,
185
91
  fromMe,
186
92
  id: msgId,
93
+ senderPn,
94
+ senderLid,
187
95
  participant,
188
- lid: userLid,
189
- 'server_id': (_c = stanza.attrs) === null || _c === void 0 ? void 0 : _c.server_id
96
+ participantLid,
97
+ 'server_id': (_f = stanza.attrs) === null || _f === void 0 ? void 0 : _f.server_id
190
98
  };
191
99
  const fullMessage = {
192
100
  key,
@@ -195,7 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
195
103
  broadcast: (0, WABinary_1.isJidBroadcast)(from)
196
104
  };
197
105
  if (msgType === 'newsletter') {
198
- fullMessage.newsletterServerId = +((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.server_id);
106
+ fullMessage.newsletterServerId = +((_g = stanza.attrs) === null || _g === void 0 ? void 0 : _g.server_id);
199
107
  }
200
108
  if (key.fromMe) {
201
109
  fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
@@ -206,39 +114,16 @@ function decodeMessageNode(stanza, meId, meLid) {
206
114
  sender: msgType === 'chat' ? author : chatId
207
115
  };
208
116
  }
209
- const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage) => {
117
+ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
210
118
  const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
211
- let metaTargetId = null;
212
- let botEditTargetId = null;
213
- let botType = null;
214
119
  return {
215
120
  fullMessage,
216
121
  category: stanza.attrs.category,
217
122
  author,
218
123
  async decrypt() {
219
- var _a, _b;
124
+ var _a;
220
125
  let decryptables = 0;
221
126
  if (Array.isArray(stanza.content)) {
222
- let hasMsmsg = false;
223
- for (const { attrs } of stanza.content) {
224
- if ((attrs === null || attrs === void 0 ? void 0 : attrs.type) === 'msmsg') {
225
- hasMsmsg = true;
226
- break;
227
- }
228
- }
229
- if (hasMsmsg) {
230
- for (const { tag, attrs } of stanza.content) {
231
- if (tag === 'meta' && (attrs === null || attrs === void 0 ? void 0 : attrs.target_id)) {
232
- metaTargetId = attrs.target_id;
233
- }
234
- if (tag === 'bot' && (attrs === null || attrs === void 0 ? void 0 : attrs.edit_target_id)) {
235
- botEditTargetId = attrs.edit_target_id;
236
- }
237
- if (tag === 'bot' && (attrs === null || attrs === void 0 ? void 0 : attrs.edit)) {
238
- botType = attrs.edit;
239
- }
240
- }
241
- }
242
127
  for (const { tag, attrs, content } of stanza.content) {
243
128
  if (tag === 'verified_name' && content instanceof Uint8Array) {
244
129
  const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
@@ -272,33 +157,6 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage)
272
157
  ciphertext: content
273
158
  });
274
159
  break;
275
- case 'msmsg':
276
- let msgRequestkey = {
277
- remoteJid: stanza.attrs.from,
278
- id: metaTargetId
279
- };
280
- const message = await getMessage(msgRequestkey);
281
- const messageSecret = (_a = message === null || message === void 0 ? void 0 : message.messageContextInfo) === null || _a === void 0 ? void 0 : _a.messageSecret;
282
- if (!messageSecret) {
283
- throw new Error('Message secret not found');
284
- }
285
- // Only decrypts when it is the complete message
286
- if (botType == 'last') {
287
- const newkey = {
288
- participant: stanza.attrs.from,
289
- meId: stanza.attrs.from.endsWith(`@bot`) ?
290
- `${meLid.split(`:`)[0]}@lid` :
291
- `${meId.split(`:`)[0]}@s.whatsapp.net`,
292
- targetId: botEditTargetId
293
- };
294
- msgBuffer = await decryptBotMsg(content, {
295
- messageKey: newkey,
296
- messageSecret
297
- });
298
- }
299
- else
300
- return;
301
- break;
302
160
  case 'plaintext':
303
161
  msgBuffer = content;
304
162
  break;
@@ -308,9 +166,8 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage)
308
166
  default:
309
167
  throw new Error(`Unknown e2e type: ${e2eType}`);
310
168
  }
311
- let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' && !hasMsmsg ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
312
- // It's necessary to save the messageContextInfo in the store to decrypt messages from bots
313
- msg = ((_b = msg.deviceSentMessage) === null || _b === void 0 ? void 0 : _b.message) ? { ...msg.deviceSentMessage.message, messageContextInfo: msg.messageContextInfo } : msg;
169
+ let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
170
+ msg = ((_a = msg === null || msg === void 0 ? void 0 : msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
314
171
  if (msg.senderKeyDistributionMessage) {
315
172
  try {
316
173
  await repository.processSenderKeyDistributionMessage({
@@ -502,10 +502,12 @@ function consolidateEvents(data) {
502
502
  return map;
503
503
  }
504
504
  function concatChats(a, b) {
505
- if (b.unreadCount === null && // neutralize unread counter
506
- a.unreadCount < 0) {
507
- a.unreadCount = undefined;
508
- b.unreadCount = undefined;
505
+ if (b.unreadCount === null) {
506
+ // neutralize unread counter
507
+ if (a.unreadCount < 0) {
508
+ a.unreadCount = undefined;
509
+ b.unreadCount = undefined;
510
+ }
509
511
  }
510
512
  if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
511
513
  b = { ...b };
@@ -1,9 +1,23 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { ILogger } from './logger';
3
3
  import { proto } from '../../WAProto';
4
- import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
4
+ import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, WACallUpdateType, WAVersion } from '../Types';
5
5
  import { BinaryNode } from '../WABinary';
6
6
  export declare const Browsers: BrowsersMap;
7
+ export declare const Browserrs: {
8
+ ubuntu: (browser: any) => any[];
9
+ macOS: (browser: any) => any[];
10
+ windows: (browser: any) => any[];
11
+ linux: (browser: any) => any[];
12
+ solaris: (browser: any) => any[];
13
+ baileys: (browser: any) => any[];
14
+ android: (browser: any) => any[];
15
+ iOS: (browser: any) => any[];
16
+ kaiOS: (browser: any) => any[];
17
+ chromeOS: (browser: any) => any[];
18
+ appropriate: (browser: any) => any[];
19
+ custom: (platform: any, browser: any, version: any) => any[];
20
+ };
7
21
  /** Other Browser Support for Paircode */
8
22
  export declare const getPlatformId: (browser: string) => any;
9
23
  export declare const BufferJSON: {
@@ -36,7 +50,7 @@ export declare function promiseTimeout<T>(ms: number | undefined, promise: (reso
36
50
  export declare const generateMessageIDV2: (userId?: string) => string;
37
51
  export declare const generateMessageID: () => string;
38
52
  export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
39
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
53
+ export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
40
54
  export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: ILogger) => void;
41
55
  /**
42
56
  * utility that fetches latest baileys version from the master branch.
@@ -111,10 +125,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
111
125
  * Is the given platform WA business
112
126
  * @param platform AuthenticationCreds.platform
113
127
  */
114
- export declare const isWABusinessPlatform: (platform: string) => platform is "smbi" | "smba";
115
- export declare function trimUndefined(obj: {
116
- [_: string]: any;
117
- }): {
118
- [_: string]: any;
119
- };
128
+ export declare const isWABusinessPlatform: (platform: string) => platform is "smba" | "smbi";
129
+ export declare function trimUndefined(obj: any): any;
120
130
  export declare function bytesToCrockford(buffer: Buffer): string;
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion2 = exports.fetchLatestBaileysVersion3 = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
39
+ exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion2 = exports.fetchLatestBaileysVersion3 = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browserrs = exports.Browsers = void 0;
40
40
  exports.promiseTimeout = promiseTimeout;
41
41
  exports.bindWaitForEvent = bindWaitForEvent;
42
42
  exports.trimUndefined = trimUndefined;
@@ -44,7 +44,8 @@ exports.bytesToCrockford = bytesToCrockford;
44
44
  const boom_1 = require("@hapi/boom");
45
45
  const axios_1 = __importDefault(require("axios"));
46
46
  const crypto_1 = require("crypto");
47
- const os_1 = require("os");
47
+ const os_1 = __importDefault(require("os"));
48
+ const os_2 = require("os");
48
49
  const WAProto_1 = require("../../WAProto");
49
50
  const baileys_version_json_1 = require("../Defaults/baileys-version.json");
50
51
  const Types_1 = require("../Types");
@@ -54,7 +55,13 @@ const COMPANION_PLATFORM_MAP = {
54
55
  'Edge': '50',
55
56
  'Firefox': '51',
56
57
  'Opera': '53',
57
- 'Safari': '54'
58
+ 'Safari': '54',
59
+ 'Brave': '1.79.112',
60
+ 'Vivaldi': '6.2.3105.58',
61
+ 'Tor': '12.5.3',
62
+ 'Yandex': '23.7.1',
63
+ 'Falkon': '22.08.3',
64
+ 'Epiphany': '44.2'
58
65
  };
59
66
  const PLATFORM_MAP = {
60
67
  'aix': 'AIX',
@@ -63,7 +70,45 @@ const PLATFORM_MAP = {
63
70
  'android': 'Android',
64
71
  'freebsd': 'FreeBSD',
65
72
  'openbsd': 'OpenBSD',
66
- 'sunos': 'Solaris'
73
+ 'sunos': 'Solaris',
74
+ 'linux': 'Linux',
75
+ 'ubuntu': 'Ubuntu',
76
+ 'ios': 'iOS',
77
+ 'baileys': 'Baileys',
78
+ 'chromeos': 'Chrome OS',
79
+ 'tizen': 'Tizen',
80
+ 'watchos': 'watchOS',
81
+ 'wearos': 'Wear OS',
82
+ 'harmonyos': 'HarmonyOS',
83
+ 'kaios': 'KaiOS',
84
+ 'smarttv': 'Smart TV',
85
+ 'raspberrypi': 'Raspberry Pi OS',
86
+ 'symbian': 'Symbian',
87
+ 'blackberry': 'Blackberry OS',
88
+ 'windowsphone': 'Windows Phone'
89
+ };
90
+ const PLATFORM_VERSIONS = {
91
+ 'ubuntu': '22.04.4',
92
+ 'darwin': '14.4.1',
93
+ 'win32': '10.0.22631',
94
+ 'android': '14.0.0',
95
+ 'freebsd': '13.2',
96
+ 'openbsd': '7.3',
97
+ 'sunos': '11',
98
+ 'linux': '6.5',
99
+ 'ios': '18.2',
100
+ 'baileys': '6.5.0',
101
+ 'chromeos': '117.0.5938.132',
102
+ 'tizen': '6.5',
103
+ 'watchos': '10.1',
104
+ 'wearos': '4.1',
105
+ 'harmonyos': '4.0.0',
106
+ 'kaios': '3.1',
107
+ 'smarttv': '23.3.1',
108
+ 'raspberrypi': '11 (Bullseye)',
109
+ 'symbian': '3',
110
+ 'blackberry': '10.3.3',
111
+ 'windowsphone': '8.1'
67
112
  };
68
113
  exports.Browsers = {
69
114
  ubuntu: (browser) => ['Ubuntu', browser, '24.04.1'],
@@ -72,7 +117,48 @@ exports.Browsers = {
72
117
  windows: (browser) => ['Windows', browser, '10.0.22631'],
73
118
  // iOS: (browser) => ['iOS', browser, '18.1'],
74
119
  /** The appropriate browser based on your OS & release */
75
- appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
120
+ appropriate: (browser) => [PLATFORM_MAP[(0, os_2.platform)()] || 'Ubuntu', browser, (0, os_2.release)()]
121
+ };
122
+ exports.Browserrs = {
123
+ ubuntu: (browser) => {
124
+ return [PLATFORM_MAP['ubuntu'], browser, PLATFORM_VERSIONS['ubuntu']];
125
+ },
126
+ macOS: (browser) => {
127
+ return [PLATFORM_MAP['darwin'], browser, PLATFORM_VERSIONS['darwin']];
128
+ },
129
+ windows: (browser) => {
130
+ return [PLATFORM_MAP['win32'], browser, PLATFORM_VERSIONS['win32']];
131
+ },
132
+ linux: (browser) => {
133
+ return [PLATFORM_MAP['linux'], browser, PLATFORM_VERSIONS['linux']];
134
+ },
135
+ solaris: (browser) => {
136
+ return [PLATFORM_MAP['sunos'], browser, PLATFORM_VERSIONS['sunos']];
137
+ },
138
+ baileys: (browser) => {
139
+ return [PLATFORM_MAP['baileys'], browser, PLATFORM_VERSIONS['baileys']];
140
+ },
141
+ android: (browser) => {
142
+ return [PLATFORM_MAP['android'], browser, PLATFORM_VERSIONS['android']];
143
+ },
144
+ iOS: (browser) => {
145
+ return [PLATFORM_MAP['ios'], browser, PLATFORM_VERSIONS['ios']];
146
+ },
147
+ kaiOS: (browser) => {
148
+ return [PLATFORM_MAP['kaios'], browser, PLATFORM_VERSIONS['kaios']];
149
+ },
150
+ chromeOS: (browser) => {
151
+ return [PLATFORM_MAP['chromeos'], browser, PLATFORM_VERSIONS['chromeos']];
152
+ },
153
+ appropriate: (browser) => {
154
+ const platform = os_1.default.platform();
155
+ const platformName = PLATFORM_MAP[platform] || 'Unknown OS';
156
+ return [platformName, browser, PLATFORM_VERSIONS[platform] || 'latest'];
157
+ },
158
+ custom: (platform, browser, version) => {
159
+ const platformName = PLATFORM_MAP[platform.toLowerCase()] || platform;
160
+ return [platformName, browser, version || PLATFORM_VERSIONS[platform] || 'latest'];
161
+ }
76
162
  };
77
163
  /** Other Browser Support for Paircode */
78
164
  const getPlatformId = (browser) => {
@@ -484,8 +570,8 @@ function bytesToCrockford(buffer) {
484
570
  let value = 0;
485
571
  let bitCount = 0;
486
572
  const crockford = [];
487
- for (const element of buffer) {
488
- value = (value << 8) | (element & 0xff);
573
+ for (let i = 0; i < buffer.length; i++) {
574
+ value = (value << 8) | (buffer[i] & 0xff);
489
575
  bitCount += 8;
490
576
  while (bitCount >= 5) {
491
577
  crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
@@ -34,7 +34,7 @@ const processHistoryMessage = (item) => {
34
34
  case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
35
35
  case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
36
36
  for (const chat of item.conversations) {
37
- contacts.push({ id: chat.id, name: chat.name || undefined });
37
+ contacts.push({ id: chat.id, name: chat.name || undefined, lid: chat.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : chat.pnJid });
38
38
  const msgs = chat.messages || [];
39
39
  delete chat.messages;
40
40
  delete chat.archived;
@@ -9,31 +9,24 @@ import { ILogger } from './logger';
9
9
  export declare const hkdfInfoKey: (type: MediaType) => string;
10
10
  /** generates all the keys required to encrypt/decrypt & sign a media message */
11
11
  export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
12
+ export declare function uploadFile(buffer: Buffer, logger?: ILogger): Promise<string>;
13
+ export declare function vid2jpg(videoUrl: string): Promise<string>;
14
+ /**
15
+ * Originally written by Techwiz (https://github.com/techwiz37)
16
+ * Modified for customization and improvements
17
+ */
18
+ export declare const extractVideoThumb: (videoPath: string) => Promise<Buffer<ArrayBufferLike>>;
12
19
  export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
13
20
  buffer: Buffer<ArrayBufferLike>;
14
21
  original: {
15
- width: number | undefined;
16
- height: number | undefined;
22
+ width: number;
23
+ height: number;
17
24
  };
18
25
  }>;
19
26
  export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
20
27
  export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Promise<{
21
28
  img: Buffer<ArrayBufferLike>;
22
29
  }>;
23
- export declare const generateProfilePictureFull: (img: any) => Promise<{
24
- img: any;
25
- }>;
26
- export declare const generateProfilePictureFP: (buffer: any) => Promise<{
27
- img: any;
28
- preview: any;
29
- }>;
30
- export declare const generatePP: (buffer: any) => Promise<{
31
- img: any;
32
- preview: any;
33
- }>;
34
- export declare const changeprofileFull: (img: any) => Promise<{
35
- img: any;
36
- }>;
37
30
  /** gets the SHA256 of the given media message */
38
31
  export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
39
32
  export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;