@genuxofficial/baileys 1.0.0 → 3.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/README.md +5 -1
- package/WAProto/WAProto.proto +1385 -96
- package/WAProto/index.d.ts +19244 -2787
- package/WAProto/index.js +138202 -74217
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -0
- package/lib/Socket/business.d.ts +47 -17
- package/lib/Socket/chats.d.ts +10 -9
- package/lib/Socket/chats.js +36 -16
- package/lib/Socket/groups.d.ts +12 -11
- package/lib/Socket/groups.js +16 -3
- package/lib/Socket/index.d.ts +52 -22
- package/lib/Socket/messages-recv.d.ts +46 -15
- package/lib/Socket/messages-recv.js +158 -23
- package/lib/Socket/messages-send.d.ts +39 -11
- package/lib/Socket/messages-send.js +188 -22
- package/lib/Socket/newsletter.d.ts +137 -0
- package/lib/Socket/newsletter.js +256 -0
- package/lib/Socket/socket.d.ts +4 -4
- package/lib/Socket/socket.js +25 -12
- package/lib/Socket/usync.d.ts +5 -5
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +14 -5
- package/lib/Types/Chat.d.ts +6 -5
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +6 -0
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +150 -12
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Socket.d.ts +8 -3
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +3 -4
- package/lib/Utils/business.js +15 -3
- package/lib/Utils/chat-utils.js +0 -16
- package/lib/Utils/crypto.js +6 -4
- package/lib/Utils/decode-wa-message.d.ts +5 -3
- package/lib/Utils/decode-wa-message.js +158 -31
- package/lib/Utils/event-buffer.js +1 -3
- package/lib/Utils/generics.d.ts +3 -2
- package/lib/Utils/generics.js +16 -36
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +14 -5
- package/lib/Utils/messages-media.js +130 -69
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +309 -57
- package/lib/Utils/noise-handler.d.ts +1 -1
- package/lib/Utils/process-message.js +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +44 -13
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/decode.js +3 -2
- package/lib/WABinary/encode.js +13 -5
- package/lib/WABinary/generic-utils.d.ts +3 -5
- package/lib/WABinary/generic-utils.js +34 -19
- package/lib/WABinary/jid-utils.d.ts +12 -3
- package/lib/WABinary/jid-utils.js +29 -4
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +21 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +10 -0
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/package.json +20 -12
- package/WAProto/GenerateStatics.sh +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
@@ -1,7 +1,7 @@
|
|
1
1
|
import { proto } from '../../WAProto';
|
2
|
-
import { SignalRepository } from '../Types';
|
3
|
-
import { BinaryNode } from '../WABinary';
|
4
2
|
import { ILogger } from './logger';
|
3
|
+
import { SignalRepository, WAMessageKey } from '../Types';
|
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";
|
7
7
|
export declare const NACK_REASONS: {
|
@@ -28,9 +28,11 @@ export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLi
|
|
28
28
|
author: string;
|
29
29
|
sender: string;
|
30
30
|
};
|
31
|
-
|
31
|
+
type GetMessage = (key: WAMessageKey) => Promise<proto.IMessage | undefined>;
|
32
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger, getMessage: GetMessage) => {
|
32
33
|
fullMessage: proto.IWebMessageInfo;
|
33
34
|
category: string;
|
34
35
|
author: string;
|
35
36
|
decrypt(): Promise<void>;
|
36
37
|
};
|
38
|
+
export {};
|
@@ -1,12 +1,19 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.decryptMessageNode = exports.decodeMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
4
7
|
const boom_1 = require("@hapi/boom");
|
5
8
|
const WAProto_1 = require("../../WAProto");
|
6
9
|
const WABinary_1 = require("../WABinary");
|
7
10
|
const generics_1 = require("./generics");
|
11
|
+
const crypto_1 = require("crypto");
|
12
|
+
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
8
13
|
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
9
14
|
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
15
|
+
const BOT_MESSAGE_CONSTANT = "Bot Message";
|
16
|
+
const KEY_LENGTH = 32;
|
10
17
|
exports.NACK_REASONS = {
|
11
18
|
ParsingError: 487,
|
12
19
|
UnrecognizedStanza: 488,
|
@@ -22,37 +29,103 @@ exports.NACK_REASONS = {
|
|
22
29
|
UnsupportedLIDGroup: 551,
|
23
30
|
DBOperationFailed: 552
|
24
31
|
};
|
32
|
+
const deriveMessageSecret = async (messageSecret) => {
|
33
|
+
// Always convert to Buffer to ensure compatibility
|
34
|
+
const secretBuffer = Buffer.isBuffer(messageSecret)
|
35
|
+
? messageSecret
|
36
|
+
: Buffer.from(messageSecret.buffer, messageSecret.byteOffset, messageSecret.length);
|
37
|
+
return await (0, futoin_hkdf_1.default)(secretBuffer, KEY_LENGTH, { salt: undefined, info: BOT_MESSAGE_CONSTANT, hash: "SHA-256" });
|
38
|
+
};
|
39
|
+
const buildDecryptionKey = async (messageID, botJID, targetJID, messageSecret) => {
|
40
|
+
const derivedSecret = await deriveMessageSecret(messageSecret);
|
41
|
+
const useCaseSecret = Buffer.concat([
|
42
|
+
Buffer.from(messageID),
|
43
|
+
Buffer.from(targetJID),
|
44
|
+
Buffer.from(botJID),
|
45
|
+
Buffer.from("")
|
46
|
+
]);
|
47
|
+
return await (0, futoin_hkdf_1.default)(derivedSecret, KEY_LENGTH, { salt: undefined, info: useCaseSecret, hash: "SHA-256" });
|
48
|
+
};
|
49
|
+
const decryptBotMessage = async (encPayload, encIv, messageID, botJID, decryptionKey) => {
|
50
|
+
encPayload = Buffer.isBuffer(encPayload) ? encPayload : Buffer.from(encPayload);
|
51
|
+
encIv = Buffer.isBuffer(encIv) ? encIv : Buffer.from(encIv);
|
52
|
+
decryptionKey = Buffer.isBuffer(decryptionKey) ? decryptionKey : Buffer.from(decryptionKey);
|
53
|
+
if (encIv.length !== 12) {
|
54
|
+
throw new Error(`IV size incorrect: expected 12, got ${encIv.length}`);
|
55
|
+
}
|
56
|
+
const authTag = encPayload.slice(-16);
|
57
|
+
const encryptedData = encPayload.slice(0, -16);
|
58
|
+
if (encryptedData.length < 16) {
|
59
|
+
throw new Error(`Encrypted data too short: ${encryptedData.length} bytes`);
|
60
|
+
}
|
61
|
+
const aad = Buffer.concat([
|
62
|
+
Buffer.from(messageID),
|
63
|
+
Buffer.from([0]),
|
64
|
+
Buffer.from(botJID)
|
65
|
+
]);
|
66
|
+
try {
|
67
|
+
const decipher = (0, crypto_1.createDecipheriv)("aes-256-gcm", decryptionKey, encIv);
|
68
|
+
decipher.setAAD(aad);
|
69
|
+
decipher.setAuthTag(authTag);
|
70
|
+
const decrypted = Buffer.concat([
|
71
|
+
decipher.update(encryptedData),
|
72
|
+
decipher.final()
|
73
|
+
]);
|
74
|
+
return decrypted;
|
75
|
+
}
|
76
|
+
catch (error) {
|
77
|
+
console.error("Decrypt - Failed with:", error.message);
|
78
|
+
throw error;
|
79
|
+
}
|
80
|
+
};
|
81
|
+
const decryptMsmsgBotMessage = async (messageSecret, messageKey, msMsg) => {
|
82
|
+
try {
|
83
|
+
const { targetId, participant: botJID, meId: targetJID } = messageKey;
|
84
|
+
if (!targetId || !botJID || !targetJID || !messageSecret) {
|
85
|
+
throw new Error("Missing required components for decryption");
|
86
|
+
}
|
87
|
+
const decryptionKey = await buildDecryptionKey(targetId, botJID, targetJID, messageSecret);
|
88
|
+
if (!msMsg.encPayload) {
|
89
|
+
throw new Error('Missing encPayload');
|
90
|
+
}
|
91
|
+
if (!msMsg.encIv) {
|
92
|
+
throw new Error('Missing encIv');
|
93
|
+
}
|
94
|
+
return await decryptBotMessage(msMsg.encPayload, msMsg.encIv, targetId, botJID, decryptionKey);
|
95
|
+
}
|
96
|
+
catch (error) {
|
97
|
+
console.error("Failed to decrypt bot message:", error);
|
98
|
+
throw error;
|
99
|
+
}
|
100
|
+
};
|
101
|
+
const decryptBotMsg = async (content, { messageKey, messageSecret }) => {
|
102
|
+
try {
|
103
|
+
const msMsg = WAProto_1.proto.MessageSecretMessage.decode(content);
|
104
|
+
return await decryptMsmsgBotMessage(messageSecret, messageKey, msMsg);
|
105
|
+
}
|
106
|
+
catch (error) {
|
107
|
+
console.error("Error in decryptBotMsg:", error);
|
108
|
+
throw error;
|
109
|
+
}
|
110
|
+
};
|
25
111
|
/**
|
26
112
|
* Decode the received node as a message.
|
27
113
|
* @note this will only parse the message, not decrypt it
|
28
114
|
*/
|
29
115
|
function decodeMessageNode(stanza, meId, meLid) {
|
30
|
-
var _a;
|
116
|
+
var _a, _b, _c, _d;
|
31
117
|
let msgType;
|
32
118
|
let chatId;
|
33
119
|
let author;
|
34
120
|
const msgId = stanza.attrs.id;
|
35
121
|
const from = stanza.attrs.from;
|
36
|
-
const participant = stanza.attrs.participant;
|
122
|
+
const participant = stanza.attrs.participant_pn || stanza.attrs.participant;
|
37
123
|
const recipient = stanza.attrs.recipient;
|
38
124
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
39
125
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
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)) {
|
126
|
+
if ((0, WABinary_1.isJidMetaAI)(from) || (0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
|
127
|
+
if (recipient && !(0, WABinary_1.isJidMetaAI)(recipient)) {
|
128
|
+
if (!isMe(from) && !isMeLid(from)) {
|
56
129
|
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
57
130
|
}
|
58
131
|
chatId = recipient;
|
@@ -71,6 +144,11 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
71
144
|
author = participant;
|
72
145
|
chatId = from;
|
73
146
|
}
|
147
|
+
else if ((0, WABinary_1.isJidNewsletter)(from)) {
|
148
|
+
msgType = 'newsletter';
|
149
|
+
author = from;
|
150
|
+
chatId = from;
|
151
|
+
}
|
74
152
|
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
75
153
|
if (!participant) {
|
76
154
|
throw new boom_1.Boom('No participant in group message');
|
@@ -85,21 +163,17 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
85
163
|
chatId = from;
|
86
164
|
author = participant;
|
87
165
|
}
|
88
|
-
else if ((0, WABinary_1.isJidNewsletter)(from)) {
|
89
|
-
msgType = 'newsletter';
|
90
|
-
chatId = from;
|
91
|
-
author = from;
|
92
|
-
}
|
93
166
|
else {
|
94
167
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
95
168
|
}
|
96
|
-
const fromMe = ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
97
|
-
const pushname = (
|
169
|
+
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);
|
170
|
+
const pushname = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.notify;
|
98
171
|
const key = {
|
99
172
|
remoteJid: chatId,
|
100
173
|
fromMe,
|
101
174
|
id: msgId,
|
102
|
-
participant
|
175
|
+
participant,
|
176
|
+
server_id: (_c = stanza.attrs) === null || _c === void 0 ? void 0 : _c.server_id
|
103
177
|
};
|
104
178
|
const fullMessage = {
|
105
179
|
key,
|
@@ -107,6 +181,9 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
107
181
|
pushName: pushname,
|
108
182
|
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
109
183
|
};
|
184
|
+
if (msgType === 'newsletter') {
|
185
|
+
fullMessage.newsletterServerId = +((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.server_id);
|
186
|
+
}
|
110
187
|
if (key.fromMe) {
|
111
188
|
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
112
189
|
}
|
@@ -117,16 +194,39 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
117
194
|
};
|
118
195
|
}
|
119
196
|
exports.decodeMessageNode = decodeMessageNode;
|
120
|
-
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
197
|
+
const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage) => {
|
121
198
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
199
|
+
let metaTargetId = null;
|
200
|
+
let botEditTargetId = null;
|
201
|
+
let botType = null;
|
122
202
|
return {
|
123
203
|
fullMessage,
|
124
204
|
category: stanza.attrs.category,
|
125
205
|
author,
|
126
206
|
async decrypt() {
|
127
|
-
var _a;
|
207
|
+
var _a, _b;
|
128
208
|
let decryptables = 0;
|
129
209
|
if (Array.isArray(stanza.content)) {
|
210
|
+
let hasMsmsg = false;
|
211
|
+
for (const { attrs } of stanza.content) {
|
212
|
+
if ((attrs === null || attrs === void 0 ? void 0 : attrs.type) === 'msmsg') {
|
213
|
+
hasMsmsg = true;
|
214
|
+
break;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
if (hasMsmsg) {
|
218
|
+
for (const { tag, attrs } of stanza.content) {
|
219
|
+
if (tag === 'meta' && (attrs === null || attrs === void 0 ? void 0 : attrs.target_id)) {
|
220
|
+
metaTargetId = attrs.target_id;
|
221
|
+
}
|
222
|
+
if (tag === 'bot' && (attrs === null || attrs === void 0 ? void 0 : attrs.edit_target_id)) {
|
223
|
+
botEditTargetId = attrs.edit_target_id;
|
224
|
+
}
|
225
|
+
if (tag === 'bot' && (attrs === null || attrs === void 0 ? void 0 : attrs.edit)) {
|
226
|
+
botType = attrs.edit;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
}
|
130
230
|
for (const { tag, attrs, content } of stanza.content) {
|
131
231
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
132
232
|
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
@@ -160,16 +260,43 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
160
260
|
ciphertext: content
|
161
261
|
});
|
162
262
|
break;
|
263
|
+
case 'msmsg': //Message Secret Message
|
264
|
+
let msgRequestkey = {
|
265
|
+
remoteJid: stanza.attrs.from,
|
266
|
+
id: metaTargetId
|
267
|
+
};
|
268
|
+
const message = await getMessage(msgRequestkey);
|
269
|
+
const messageSecret = (_a = message === null || message === void 0 ? void 0 : message.messageContextInfo) === null || _a === void 0 ? void 0 : _a.messageSecret;
|
270
|
+
if (!messageSecret) {
|
271
|
+
throw new Error('Message secret not found');
|
272
|
+
}
|
273
|
+
//Only decrypts when it is the complete message
|
274
|
+
if (botType == 'last') {
|
275
|
+
const newkey = {
|
276
|
+
participant: stanza.attrs.from,
|
277
|
+
meId: stanza.attrs.from.endsWith(`@bot`) ?
|
278
|
+
`${meLid.split(`:`)[0]}@lid` :
|
279
|
+
`${meId.split(`:`)[0]}@s.whatsapp.net`,
|
280
|
+
targetId: botEditTargetId
|
281
|
+
};
|
282
|
+
msgBuffer = await decryptBotMsg(content, {
|
283
|
+
messageKey: newkey,
|
284
|
+
messageSecret
|
285
|
+
});
|
286
|
+
}
|
287
|
+
else
|
288
|
+
return;
|
289
|
+
break;
|
163
290
|
case 'plaintext':
|
164
291
|
msgBuffer = content;
|
165
292
|
break;
|
166
293
|
default:
|
167
294
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
168
295
|
}
|
169
|
-
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
170
|
-
|
296
|
+
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' && !hasMsmsg ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
297
|
+
//It's necessary to save the messageContextInfo in the store to decrypt messages from bots
|
298
|
+
msg = ((_b = msg.deviceSentMessage) === null || _b === void 0 ? void 0 : _b.message) ? { ...msg.deviceSentMessage.message, messageContextInfo: msg.messageContextInfo } : msg;
|
171
299
|
if (msg.senderKeyDistributionMessage) {
|
172
|
-
//eslint-disable-next-line max-depth
|
173
300
|
try {
|
174
301
|
await repository.processSenderKeyDistributionMessage({
|
175
302
|
authorJid: author,
|
@@ -138,9 +138,7 @@ const makeBufferData = () => {
|
|
138
138
|
groupUpdates: {}
|
139
139
|
};
|
140
140
|
};
|
141
|
-
function append(data, historyCache, event,
|
142
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
143
|
-
eventData, logger) {
|
141
|
+
function append(data, historyCache, event, eventData, logger) {
|
144
142
|
var _a, _b, _c;
|
145
143
|
switch (event) {
|
146
144
|
case 'messaging-history.set':
|
package/lib/Utils/generics.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/// <reference types="node" />
|
3
3
|
import { AxiosRequestConfig } from 'axios';
|
4
|
+
import { ILogger } from './logger';
|
4
5
|
import { proto } from '../../WAProto';
|
5
6
|
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
|
6
7
|
import { BinaryNode } from '../WABinary';
|
7
|
-
import { ILogger } from './logger';
|
8
8
|
export declare const Browsers: BrowsersMap;
|
9
9
|
export declare const getPlatformId: (browser: string) => any;
|
10
10
|
export declare const BufferJSON: {
|
@@ -15,6 +15,7 @@ export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, m
|
|
15
15
|
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
16
16
|
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
17
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
20
|
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
20
21
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
@@ -42,7 +43,7 @@ export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logge
|
|
42
43
|
* utility that fetches latest baileys version from the master branch.
|
43
44
|
* Use to ensure your WA connection is always on the latest version
|
44
45
|
*/
|
45
|
-
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<
|
46
|
+
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
46
47
|
version: WAVersion;
|
47
48
|
isLatest: boolean;
|
48
49
|
error?: undefined;
|
package/lib/Utils/generics.js
CHANGED
@@ -1,32 +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 (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
4
|
};
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
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.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
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.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;
|
30
7
|
const boom_1 = require("@hapi/boom");
|
31
8
|
const axios_1 = __importDefault(require("axios"));
|
32
9
|
const crypto_1 = require("crypto");
|
@@ -35,6 +12,13 @@ const WAProto_1 = require("../../WAProto");
|
|
35
12
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
36
13
|
const Types_1 = require("../Types");
|
37
14
|
const WABinary_1 = require("../WABinary");
|
15
|
+
const COMPANION_PLATFORM_MAP = {
|
16
|
+
'Chrome': '49',
|
17
|
+
'Edge': '50',
|
18
|
+
'Firefox': '51',
|
19
|
+
'Opera': '53',
|
20
|
+
'Safari': '54'
|
21
|
+
};
|
38
22
|
const PLATFORM_MAP = {
|
39
23
|
'aix': 'AIX',
|
40
24
|
'darwin': 'Mac OS',
|
@@ -54,18 +38,16 @@ exports.Browsers = {
|
|
54
38
|
};
|
55
39
|
const getPlatformId = (browser) => {
|
56
40
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
57
|
-
return platformType ? platformType.toString()
|
41
|
+
return platformType ? platformType.toString() : '49'; //chrome
|
58
42
|
};
|
59
43
|
exports.getPlatformId = getPlatformId;
|
60
44
|
exports.BufferJSON = {
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
62
45
|
replacer: (k, value) => {
|
63
46
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
64
47
|
return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
|
65
48
|
}
|
66
49
|
return value;
|
67
50
|
},
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
69
51
|
reviver: (_, value) => {
|
70
52
|
if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
|
71
53
|
const val = value.data || value.value;
|
@@ -99,6 +81,8 @@ const unpadRandomMax16 = (e) => {
|
|
99
81
|
exports.unpadRandomMax16 = unpadRandomMax16;
|
100
82
|
const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
|
101
83
|
exports.encodeWAMessage = encodeWAMessage;
|
84
|
+
const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
|
85
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
102
86
|
const generateRegistrationId = () => {
|
103
87
|
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
104
88
|
};
|
@@ -180,8 +164,6 @@ async function promiseTimeout(ms, promise) {
|
|
180
164
|
return p;
|
181
165
|
}
|
182
166
|
exports.promiseTimeout = promiseTimeout;
|
183
|
-
// inspired from whatsmeow code
|
184
|
-
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
185
167
|
const generateMessageIDV2 = (userId) => {
|
186
168
|
const data = Buffer.alloc(8 + 20 + 16);
|
187
169
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
@@ -232,7 +214,8 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
232
214
|
const printQRIfNecessaryListener = (ev, logger) => {
|
233
215
|
ev.on('connection.update', async ({ qr }) => {
|
234
216
|
if (qr) {
|
235
|
-
const QR = await
|
217
|
+
const QR = await import('qrcode-terminal')
|
218
|
+
.then(m => m.default || m)
|
236
219
|
.catch(() => {
|
237
220
|
logger.error('QR code terminal not added as dependency');
|
238
221
|
});
|
@@ -246,7 +229,7 @@ exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
246
229
|
* Use to ensure your WA connection is always on the latest version
|
247
230
|
*/
|
248
231
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
249
|
-
const URL = 'https://raw.githubusercontent.com/
|
232
|
+
const URL = 'https://raw.githubusercontent.com/nstar-y/bail/master/src/Defaults/baileys-version.json';
|
250
233
|
try {
|
251
234
|
const result = await axios_1.default.get(URL, {
|
252
235
|
...options,
|
@@ -358,7 +341,7 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
358
341
|
status = 'timeout';
|
359
342
|
}
|
360
343
|
else {
|
361
|
-
//fired when accepted/rejected/timeout/caller hangs up
|
344
|
+
// fired when accepted/rejected/timeout/caller hangs up
|
362
345
|
status = 'terminate';
|
363
346
|
}
|
364
347
|
break;
|
@@ -385,9 +368,7 @@ const getCodeFromWSError = (error) => {
|
|
385
368
|
statusCode = code;
|
386
369
|
}
|
387
370
|
}
|
388
|
-
else if (
|
389
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
390
|
-
((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
371
|
+
else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
|
391
372
|
|| ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
|
392
373
|
statusCode = 408;
|
393
374
|
}
|
@@ -402,7 +383,6 @@ const isWABusinessPlatform = (platform) => {
|
|
402
383
|
return platform === 'smbi' || platform === 'smba';
|
403
384
|
};
|
404
385
|
exports.isWABusinessPlatform = isWABusinessPlatform;
|
405
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
406
386
|
function trimUndefined(obj) {
|
407
387
|
for (const key in obj) {
|
408
388
|
if (typeof obj[key] === 'undefined') {
|
package/lib/Utils/history.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
2
2
|
import { proto } from '../../WAProto';
|
3
3
|
import { Chat, Contact } from '../Types';
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
6
6
|
chats: Chat[];
|
7
7
|
contacts: Contact[];
|
@@ -9,7 +9,7 @@ export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
9
9
|
syncType: proto.HistorySync.HistorySyncType;
|
10
10
|
progress: number | null | undefined;
|
11
11
|
};
|
12
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
12
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
|
13
13
|
chats: Chat[];
|
14
14
|
contacts: Contact[];
|
15
15
|
messages: proto.IWebMessageInfo[];
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
2
|
-
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
3
2
|
import { ILogger } from './logger';
|
3
|
+
import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
|
4
4
|
export type URLGenerationOptions = {
|
5
5
|
thumbnailWidth: number;
|
6
6
|
fetchOpts: {
|
@@ -1,27 +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 (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
3
|
exports.getUrlInfo = void 0;
|
27
4
|
const messages_1 = require("./messages");
|
@@ -48,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
48
25
|
// retries
|
49
26
|
const retries = 0;
|
50
27
|
const maxRetry = 5;
|
51
|
-
const { getLinkPreview } = await
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
52
29
|
let previewLink = text;
|
53
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
54
31
|
previewLink = 'https://' + previewLink;
|
package/lib/Utils/make-mutex.js
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.makeKeyedMutex = exports.makeMutex = void 0;
|
4
4
|
const makeMutex = () => {
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
6
5
|
let task = Promise.resolve();
|
7
6
|
let taskTimeout;
|
8
7
|
return {
|
@@ -64,20 +64,29 @@ type EncryptedStreamOptions = {
|
|
64
64
|
logger?: ILogger;
|
65
65
|
opts?: AxiosRequestConfig;
|
66
66
|
};
|
67
|
+
export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
68
|
+
mediaKey: undefined;
|
69
|
+
encFilePath: string;
|
70
|
+
originalFilePath: string | undefined;
|
71
|
+
fileLength: number;
|
72
|
+
fileSha256: Buffer;
|
73
|
+
fileEncSha256: undefined;
|
74
|
+
bodyPath: string | undefined;
|
75
|
+
didSaveToTmpPath: boolean;
|
76
|
+
}>;
|
67
77
|
export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
|
68
78
|
mediaKey: Buffer;
|
69
|
-
|
70
|
-
|
79
|
+
originalFilePath: string | undefined;
|
80
|
+
encFilePath: string;
|
71
81
|
mac: Buffer;
|
72
82
|
fileEncSha256: Buffer;
|
73
83
|
fileSha256: Buffer;
|
74
84
|
fileLength: number;
|
75
|
-
didSaveToTmpPath: boolean;
|
76
85
|
}>;
|
77
86
|
export type MediaDownloadOptions = {
|
78
87
|
startByte?: number;
|
79
88
|
endByte?: number;
|
80
|
-
options?: AxiosRequestConfig<
|
89
|
+
options?: AxiosRequestConfig<any>;
|
81
90
|
};
|
82
91
|
export declare const getUrlFromDirectPath: (directPath: string) => string;
|
83
92
|
export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
|
@@ -93,7 +102,7 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
|
|
93
102
|
*/
|
94
103
|
export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => Promise<BinaryNode>;
|
95
104
|
export declare const decodeMediaRetryNode: (node: BinaryNode) => {
|
96
|
-
key:
|
105
|
+
key: import("../Types").WAMessageKey;
|
97
106
|
media?: {
|
98
107
|
ciphertext: Uint8Array;
|
99
108
|
iv: Uint8Array;
|