@genuxofficial/baileys 2.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/WAProto.proto +4451 -0
- package/WAProto/index.d.ts +219 -2233
- package/WAProto/index.js +525 -6773
- package/WAProto/shizo.x +1 -0
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +236 -3
- package/lib/Defaults/index.js +24 -8
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.js +9 -18
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +3 -3
- package/lib/Socket/business.d.ts +43 -43
- package/lib/Socket/chats.d.ts +17 -23
- package/lib/Socket/chats.js +9 -123
- package/lib/Socket/groups.d.ts +27 -32
- package/lib/Socket/groups.js +5 -18
- package/lib/Socket/index.d.ts +51 -49
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +41 -42
- package/lib/Socket/messages-recv.js +20 -39
- package/lib/Socket/messages-send.d.ts +33 -38
- package/lib/Socket/messages-send.js +16 -37
- package/lib/Socket/newsletter.d.ts +30 -35
- package/lib/Socket/newsletter.js +22 -26
- package/lib/Socket/registration.d.ts +271 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -9
- package/lib/Socket/socket.js +19 -16
- package/lib/Socket/usync.d.ts +12 -10
- package/lib/Socket/usync.js +15 -10
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-in-memory-store.d.ts +1 -1
- package/lib/Store/make-in-memory-store.js +10 -8
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +8 -0
- package/lib/Types/Chat.d.ts +2 -12
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/GroupMetadata.d.ts +0 -7
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +8 -7
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.js +2 -2
- package/lib/Types/Socket.d.ts +6 -7
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +12 -5
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +13 -11
- package/lib/Utils/chat-utils.js +2 -28
- package/lib/Utils/crypto.d.ts +16 -14
- package/lib/Utils/crypto.js +22 -34
- package/lib/Utils/decode-wa-message.d.ts +2 -4
- package/lib/Utils/decode-wa-message.js +24 -160
- package/lib/Utils/event-buffer.js +6 -4
- package/lib/Utils/generics.d.ts +12 -40
- package/lib/Utils/generics.js +25 -103
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/lt-hash.d.ts +3 -3
- package/lib/Utils/lt-hash.js +45 -11
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +16 -26
- package/lib/Utils/messages-media.js +26 -102
- package/lib/Utils/messages.d.ts +8 -5
- package/lib/Utils/messages.js +15 -17
- package/lib/Utils/noise-handler.d.ts +8 -5
- package/lib/Utils/noise-handler.js +10 -5
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +11 -48
- package/lib/Utils/validate-connection.d.ts +3 -2
- package/lib/Utils/validate-connection.js +44 -10
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +4 -2
- package/lib/WABinary/decode.js +7 -17
- package/lib/WABinary/encode.d.ts +3 -1
- package/lib/WABinary/encode.js +17 -40
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +3 -8
- package/lib/WABinary/jid-utils.js +2 -23
- package/lib/WAM/BinaryInfo.d.ts +12 -2
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.d.ts +3 -1
- package/lib/WAM/encode.js +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
- package/lib/WAUSync/USyncQuery.d.ts +0 -2
- package/lib/WAUSync/USyncQuery.js +13 -27
- package/lib/WAUSync/USyncUser.d.ts +0 -2
- package/lib/WAUSync/USyncUser.js +0 -4
- package/package.json +60 -55
- package/LICENSE +0 -21
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,17 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
4
|
-
exports.decodeMessageNode = decodeMessageNode;
|
3
|
+
exports.decryptMessageNode = exports.decodeMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
5
4
|
const boom_1 = require("@hapi/boom");
|
6
5
|
const WAProto_1 = require("../../WAProto");
|
7
6
|
const WABinary_1 = require("../WABinary");
|
8
7
|
const generics_1 = require("./generics");
|
9
|
-
const crypto_1 = require("./crypto");
|
10
|
-
const crypto_2 = require("crypto");
|
11
8
|
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
12
9
|
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
13
|
-
const BOT_MESSAGE_CONSTANT = "Bot Message";
|
14
|
-
const KEY_LENGTH = 32;
|
15
10
|
exports.NACK_REASONS = {
|
16
11
|
ParsingError: 487,
|
17
12
|
UnrecognizedStanza: 488,
|
@@ -27,85 +22,6 @@ exports.NACK_REASONS = {
|
|
27
22
|
UnsupportedLIDGroup: 551,
|
28
23
|
DBOperationFailed: 552
|
29
24
|
};
|
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
25
|
/**
|
110
26
|
* Decode the received node as a message.
|
111
27
|
* @note this will only parse the message, not decrypt it
|
@@ -115,27 +31,34 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
115
31
|
let msgType;
|
116
32
|
let chatId;
|
117
33
|
let author;
|
118
|
-
let userLid;
|
119
34
|
const msgId = stanza.attrs.id;
|
120
35
|
const from = stanza.attrs.from;
|
121
36
|
const participant = stanza.attrs.participant;
|
122
|
-
const participantLid = stanza.attrs.participant_lid;
|
123
37
|
const recipient = stanza.attrs.recipient;
|
124
|
-
const peerRecipientLid = stanza.attrs.peer_recipient_lid;
|
125
|
-
const senderLid = stanza.attrs.sender_lid;
|
126
38
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
127
39
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
128
|
-
if ((0, WABinary_1.
|
129
|
-
if (recipient
|
130
|
-
if (!isMe(from)
|
40
|
+
if ((0, WABinary_1.isJidUser)(from)) {
|
41
|
+
if (recipient) {
|
42
|
+
if (!isMe(from)) {
|
43
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
44
|
+
}
|
45
|
+
chatId = recipient;
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
chatId = from;
|
49
|
+
}
|
50
|
+
msgType = 'chat';
|
51
|
+
author = from;
|
52
|
+
}
|
53
|
+
else if ((0, WABinary_1.isLidUser)(from)) {
|
54
|
+
if (recipient) {
|
55
|
+
if (!isMeLid(from)) {
|
131
56
|
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
132
57
|
}
|
133
58
|
chatId = recipient;
|
134
|
-
userLid = peerRecipientLid;
|
135
59
|
}
|
136
60
|
else {
|
137
61
|
chatId = from;
|
138
|
-
userLid = senderLid;
|
139
62
|
}
|
140
63
|
msgType = 'chat';
|
141
64
|
author = from;
|
@@ -147,7 +70,6 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
147
70
|
msgType = 'group';
|
148
71
|
author = participant;
|
149
72
|
chatId = from;
|
150
|
-
userLid = participantLid;
|
151
73
|
}
|
152
74
|
else if ((0, WABinary_1.isJidNewsletter)(from)) {
|
153
75
|
msgType = 'newsletter';
|
@@ -156,7 +78,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
156
78
|
}
|
157
79
|
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
158
80
|
if (!participant) {
|
159
|
-
throw new boom_1.Boom('No participant in
|
81
|
+
throw new boom_1.Boom('No participant in group message');
|
160
82
|
}
|
161
83
|
const isParticipantMe = isMe(participant);
|
162
84
|
if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
|
@@ -167,13 +89,6 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
167
89
|
}
|
168
90
|
chatId = from;
|
169
91
|
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
92
|
}
|
178
93
|
else {
|
179
94
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
@@ -185,8 +100,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
185
100
|
fromMe,
|
186
101
|
id: msgId,
|
187
102
|
participant,
|
188
|
-
|
189
|
-
'server_id': (_c = stanza.attrs) === null || _c === void 0 ? void 0 : _c.server_id
|
103
|
+
server_id: (_c = stanza.attrs) === null || _c === void 0 ? void 0 : _c.server_id
|
190
104
|
};
|
191
105
|
const fullMessage = {
|
192
106
|
key,
|
@@ -206,39 +120,17 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
206
120
|
sender: msgType === 'chat' ? author : chatId
|
207
121
|
};
|
208
122
|
}
|
209
|
-
|
123
|
+
exports.decodeMessageNode = decodeMessageNode;
|
124
|
+
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
210
125
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
211
|
-
let metaTargetId = null;
|
212
|
-
let botEditTargetId = null;
|
213
|
-
let botType = null;
|
214
126
|
return {
|
215
127
|
fullMessage,
|
216
128
|
category: stanza.attrs.category,
|
217
129
|
author,
|
218
130
|
async decrypt() {
|
219
|
-
var _a
|
131
|
+
var _a;
|
220
132
|
let decryptables = 0;
|
221
133
|
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
134
|
for (const { tag, attrs, content } of stanza.content) {
|
243
135
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
244
136
|
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
@@ -272,33 +164,6 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage)
|
|
272
164
|
ciphertext: content
|
273
165
|
});
|
274
166
|
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
167
|
case 'plaintext':
|
303
168
|
msgBuffer = content;
|
304
169
|
break;
|
@@ -308,9 +173,8 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage)
|
|
308
173
|
default:
|
309
174
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
310
175
|
}
|
311
|
-
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext'
|
312
|
-
|
313
|
-
msg = ((_b = msg.deviceSentMessage) === null || _b === void 0 ? void 0 : _b.message) ? { ...msg.deviceSentMessage.message, messageContextInfo: msg.messageContextInfo } : msg;
|
176
|
+
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
177
|
+
msg = ((_a = msg === null || msg === void 0 ? void 0 : msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
314
178
|
if (msg.senderKeyDistributionMessage) {
|
315
179
|
try {
|
316
180
|
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
|
506
|
-
|
507
|
-
a.unreadCount
|
508
|
-
|
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 };
|
package/lib/Utils/generics.d.ts
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
1
3
|
import { AxiosRequestConfig } from 'axios';
|
2
4
|
import { ILogger } from './logger';
|
3
5
|
import { proto } from '../../WAProto';
|
4
|
-
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap,
|
6
|
+
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, WACallUpdateType, WAVersion } from '../Types';
|
5
7
|
import { BinaryNode } from '../WABinary';
|
6
8
|
export declare const Browsers: BrowsersMap;
|
7
|
-
/** Other Browser Support for Paircode */
|
8
9
|
export declare const getPlatformId: (browser: string) => any;
|
9
10
|
export declare const BufferJSON: {
|
10
11
|
replacer: (k: any, value: any) => any;
|
11
12
|
reviver: (_: any, value: any) => any;
|
12
13
|
};
|
13
14
|
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
14
|
-
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer
|
15
|
-
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array
|
16
|
-
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer
|
17
|
-
export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array
|
15
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
16
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
17
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
18
|
+
export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array;
|
18
19
|
export declare const generateRegistrationId: () => number;
|
19
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
|
20
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
20
21
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
21
22
|
/** unix timestamp of a date in seconds */
|
22
23
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
@@ -34,9 +35,10 @@ export declare const delayCancellable: (ms: number) => {
|
|
34
35
|
};
|
35
36
|
export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
|
36
37
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
38
|
+
export declare const generateMessageIDV3: (userId?: string) => string;
|
37
39
|
export declare const generateMessageID: () => string;
|
38
40
|
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>;
|
41
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
40
42
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: ILogger) => void;
|
41
43
|
/**
|
42
44
|
* utility that fetches latest baileys version from the master branch.
|
@@ -51,32 +53,6 @@ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<an
|
|
51
53
|
isLatest: boolean;
|
52
54
|
error: any;
|
53
55
|
}>;
|
54
|
-
/**
|
55
|
-
* utility that fetches latest baileys version from the main branch.
|
56
|
-
* Use to ensure your WA connection is always on the latest version
|
57
|
-
*/
|
58
|
-
export declare const fetchLatestBaileysVersion3: (options?: AxiosRequestConfig<any>) => Promise<{
|
59
|
-
version: number[];
|
60
|
-
isLatest: boolean;
|
61
|
-
error?: undefined;
|
62
|
-
} | {
|
63
|
-
version: WAVersion;
|
64
|
-
isLatest: boolean;
|
65
|
-
error: any;
|
66
|
-
}>;
|
67
|
-
/**
|
68
|
-
* utility that fetches latest baileys version from the master branch.
|
69
|
-
* Use to ensure your WA connection is always on the latest version
|
70
|
-
*/
|
71
|
-
export declare const fetchLatestBaileysVersion2: (options?: AxiosRequestConfig<any>) => Promise<{
|
72
|
-
version: WAVersion;
|
73
|
-
isLatest: boolean;
|
74
|
-
error?: undefined;
|
75
|
-
} | {
|
76
|
-
version: WAVersion;
|
77
|
-
isLatest: boolean;
|
78
|
-
error: any;
|
79
|
-
}>;
|
80
56
|
/**
|
81
57
|
* A utility that fetches the latest web version of whatsapp.
|
82
58
|
* Use to ensure your WA connection is always on the latest version
|
@@ -111,10 +87,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
111
87
|
* Is the given platform WA business
|
112
88
|
* @param platform AuthenticationCreds.platform
|
113
89
|
*/
|
114
|
-
export declare const isWABusinessPlatform: (platform: string) =>
|
115
|
-
export declare function trimUndefined(obj:
|
116
|
-
[_: string]: any;
|
117
|
-
}): {
|
118
|
-
[_: string]: any;
|
119
|
-
};
|
90
|
+
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
91
|
+
export declare function trimUndefined(obj: any): any;
|
120
92
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
package/lib/Utils/generics.js
CHANGED
@@ -1,46 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
19
|
-
var ownKeys = function(o) {
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
-
var ar = [];
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
-
return ar;
|
24
|
-
};
|
25
|
-
return ownKeys(o);
|
26
|
-
};
|
27
|
-
return function (mod) {
|
28
|
-
if (mod && mod.__esModule) return mod;
|
29
|
-
var result = {};
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
-
__setModuleDefault(result, mod);
|
32
|
-
return result;
|
33
|
-
};
|
34
|
-
})();
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
37
4
|
};
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.
|
40
|
-
exports.promiseTimeout = promiseTimeout;
|
41
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
42
|
-
exports.trimUndefined = trimUndefined;
|
43
|
-
exports.bytesToCrockford = bytesToCrockford;
|
6
|
+
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV3 = exports.generateMessageIDV2 = exports.promiseTimeout = 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;
|
44
7
|
const boom_1 = require("@hapi/boom");
|
45
8
|
const axios_1 = __importDefault(require("axios"));
|
46
9
|
const crypto_1 = require("crypto");
|
@@ -66,18 +29,16 @@ const PLATFORM_MAP = {
|
|
66
29
|
'sunos': 'Solaris'
|
67
30
|
};
|
68
31
|
exports.Browsers = {
|
69
|
-
ubuntu: (browser) => ['Ubuntu', browser, '
|
32
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
70
33
|
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
71
|
-
baileys: (browser) => ['Baileys', browser, '6.
|
34
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
72
35
|
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
73
|
-
// iOS: (browser) => ['iOS', browser, '18.1'],
|
74
36
|
/** The appropriate browser based on your OS & release */
|
75
37
|
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
76
38
|
};
|
77
|
-
/** Other Browser Support for Paircode */
|
78
39
|
const getPlatformId = (browser) => {
|
79
40
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
80
|
-
return platformType ? platformType.toString() : '
|
41
|
+
return platformType ? platformType.toString().charCodeAt(0).toString() : '49'; // chrome
|
81
42
|
};
|
82
43
|
exports.getPlatformId = getPlatformId;
|
83
44
|
exports.BufferJSON = {
|
@@ -136,7 +97,7 @@ const encodeBigEndian = (e, t = 4) => {
|
|
136
97
|
return a;
|
137
98
|
};
|
138
99
|
exports.encodeBigEndian = encodeBigEndian;
|
139
|
-
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t
|
100
|
+
const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
|
140
101
|
exports.toNumber = toNumber;
|
141
102
|
/** unix timestamp of a date in seconds */
|
142
103
|
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
@@ -202,6 +163,7 @@ async function promiseTimeout(ms, promise) {
|
|
202
163
|
.finally(cancel);
|
203
164
|
return p;
|
204
165
|
}
|
166
|
+
exports.promiseTimeout = promiseTimeout;
|
205
167
|
const generateMessageIDV2 = (userId) => {
|
206
168
|
const data = Buffer.alloc(8 + 20 + 16);
|
207
169
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
@@ -212,14 +174,22 @@ const generateMessageIDV2 = (userId) => {
|
|
212
174
|
data.write('@c.us', 8 + id.user.length);
|
213
175
|
}
|
214
176
|
}
|
215
|
-
const random = (0, crypto_1.randomBytes)(
|
177
|
+
const random = (0, crypto_1.randomBytes)(20);
|
216
178
|
random.copy(data, 28);
|
217
179
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
218
|
-
return '
|
180
|
+
return '3L1T3' + hash.toString('hex').toUpperCase().substring(0, 16);
|
219
181
|
};
|
220
182
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
183
|
+
//Message ID function for Baileys Elite
|
184
|
+
//This V3 is RollBack Update to old Message ID
|
185
|
+
const generateMessageIDV3 = (userId) => {
|
186
|
+
let swebfix = '3L1T3';
|
187
|
+
let swebRandom = (0, crypto_1.randomBytes)(5).toString('hex').toUpperCase().substring(0, 10);
|
188
|
+
return swebfix + swebRandom;
|
189
|
+
};
|
190
|
+
exports.generateMessageIDV3 = generateMessageIDV3;
|
221
191
|
// generate a random ID to attach to a message
|
222
|
-
const generateMessageID = () => '
|
192
|
+
const generateMessageID = () => '3L1T3' + (0, crypto_1.randomBytes)(8).toString('hex').toUpperCase();
|
223
193
|
exports.generateMessageID = generateMessageID;
|
224
194
|
function bindWaitForEvent(ev, event) {
|
225
195
|
return async (check, timeoutMs) => {
|
@@ -246,12 +216,14 @@ function bindWaitForEvent(ev, event) {
|
|
246
216
|
}));
|
247
217
|
};
|
248
218
|
}
|
219
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
249
220
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
250
221
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
251
222
|
const printQRIfNecessaryListener = (ev, logger) => {
|
252
223
|
ev.on('connection.update', async ({ qr }) => {
|
253
224
|
if (qr) {
|
254
|
-
const QR = await
|
225
|
+
const QR = await import('qrcode-terminal')
|
226
|
+
.then(m => m.default || m)
|
255
227
|
.catch(() => {
|
256
228
|
logger.error('QR code terminal not added as dependency');
|
257
229
|
});
|
@@ -265,7 +237,7 @@ exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
265
237
|
* Use to ensure your WA connection is always on the latest version
|
266
238
|
*/
|
267
239
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
268
|
-
const URL = 'https://raw.githubusercontent.com/
|
240
|
+
const URL = 'https://raw.githubusercontent.com/shizo-devs/baileys/master/src/Defaults/baileys-version.json';
|
269
241
|
try {
|
270
242
|
const result = await axios_1.default.get(URL, {
|
271
243
|
...options,
|
@@ -285,57 +257,6 @@ const fetchLatestBaileysVersion = async (options = {}) => {
|
|
285
257
|
}
|
286
258
|
};
|
287
259
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
288
|
-
/**
|
289
|
-
* utility that fetches latest baileys version from the main branch.
|
290
|
-
* Use to ensure your WA connection is always on the latest version
|
291
|
-
*/
|
292
|
-
const fetchLatestBaileysVersion3 = async (options = {}) => {
|
293
|
-
try {
|
294
|
-
const result = await axios_1.default.get('https://raw.githubusercontent.com/wppconnect-team/wa-version/main/versions.json', {
|
295
|
-
...options,
|
296
|
-
responseType: 'json'
|
297
|
-
});
|
298
|
-
const version = result.data.versions[result.data.versions.length - 1].version.split('.');
|
299
|
-
const version2 = version[2].replace('-alpha', '');
|
300
|
-
return {
|
301
|
-
version: [+version[0], +version[1], +version2],
|
302
|
-
isLatest: true
|
303
|
-
};
|
304
|
-
}
|
305
|
-
catch (error) {
|
306
|
-
return {
|
307
|
-
version: baileys_version_json_1.version,
|
308
|
-
isLatest: false,
|
309
|
-
error
|
310
|
-
};
|
311
|
-
}
|
312
|
-
};
|
313
|
-
exports.fetchLatestBaileysVersion3 = fetchLatestBaileysVersion3;
|
314
|
-
/**
|
315
|
-
* utility that fetches latest baileys version from the master branch.
|
316
|
-
* Use to ensure your WA connection is always on the latest version
|
317
|
-
*/
|
318
|
-
const fetchLatestBaileysVersion2 = async (options = {}) => {
|
319
|
-
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
|
320
|
-
try {
|
321
|
-
const result = await axios_1.default.get(URL, {
|
322
|
-
...options,
|
323
|
-
responseType: 'json'
|
324
|
-
});
|
325
|
-
return {
|
326
|
-
version: result.data.version,
|
327
|
-
isLatest: true
|
328
|
-
};
|
329
|
-
}
|
330
|
-
catch (error) {
|
331
|
-
return {
|
332
|
-
version: baileys_version_json_1.version,
|
333
|
-
isLatest: false,
|
334
|
-
error
|
335
|
-
};
|
336
|
-
}
|
337
|
-
};
|
338
|
-
exports.fetchLatestBaileysVersion2 = fetchLatestBaileysVersion2;
|
339
260
|
/**
|
340
261
|
* A utility that fetches the latest web version of whatsapp.
|
341
262
|
* Use to ensure your WA connection is always on the latest version
|
@@ -347,7 +268,6 @@ const fetchLatestWaWebVersion = async (options) => {
|
|
347
268
|
responseType: 'json'
|
348
269
|
});
|
349
270
|
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
350
|
-
const regexx = /\\?"server_revision\\?":\s*(\d+)/;
|
351
271
|
const match = data.match(regex);
|
352
272
|
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
353
273
|
return {
|
@@ -479,13 +399,14 @@ function trimUndefined(obj) {
|
|
479
399
|
}
|
480
400
|
return obj;
|
481
401
|
}
|
402
|
+
exports.trimUndefined = trimUndefined;
|
482
403
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
483
404
|
function bytesToCrockford(buffer) {
|
484
405
|
let value = 0;
|
485
406
|
let bitCount = 0;
|
486
407
|
const crockford = [];
|
487
|
-
for (
|
488
|
-
value = (value << 8) | (
|
408
|
+
for (let i = 0; i < buffer.length; i++) {
|
409
|
+
value = (value << 8) | (buffer[i] & 0xff);
|
489
410
|
bitCount += 8;
|
490
411
|
while (bitCount >= 5) {
|
491
412
|
crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
|
@@ -497,3 +418,4 @@ function bytesToCrockford(buffer) {
|
|
497
418
|
}
|
498
419
|
return crockford.join('');
|
499
420
|
}
|
421
|
+
exports.bytesToCrockford = bytesToCrockford;
|
@@ -1,37 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
19
|
-
var ownKeys = function(o) {
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
-
var ar = [];
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
-
return ar;
|
24
|
-
};
|
25
|
-
return ownKeys(o);
|
26
|
-
};
|
27
|
-
return function (mod) {
|
28
|
-
if (mod && mod.__esModule) return mod;
|
29
|
-
var result = {};
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
-
__setModuleDefault(result, mod);
|
32
|
-
return result;
|
33
|
-
};
|
34
|
-
})();
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
36
3
|
exports.getUrlInfo = void 0;
|
37
4
|
const messages_1 = require("./messages");
|
@@ -58,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
58
25
|
// retries
|
59
26
|
const retries = 0;
|
60
27
|
const maxRetry = 5;
|
61
|
-
const { getLinkPreview } = await
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
62
29
|
let previewLink = text;
|
63
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
64
31
|
previewLink = 'https://' + previewLink;
|
package/lib/Utils/lt-hash.d.ts
CHANGED
@@ -4,9 +4,9 @@ declare class d {
|
|
4
4
|
add(e: any, t: any): any;
|
5
5
|
subtract(e: any, t: any): any;
|
6
6
|
subtractThenAdd(e: any, t: any, r: any): any;
|
7
|
-
_addSingle(e: any, t: any): Promise<
|
8
|
-
_subtractSingle(e: any, t: any): Promise<
|
9
|
-
performPointwiseWithOverflow(e: any, t: any, r: any):
|
7
|
+
_addSingle(e: any, t: any): Promise<any>;
|
8
|
+
_subtractSingle(e: any, t: any): Promise<any>;
|
9
|
+
performPointwiseWithOverflow(e: any, t: any, r: any): any;
|
10
10
|
}
|
11
11
|
export declare const LT_HASH_ANTI_TAMPERING: d;
|
12
12
|
export {};
|