@queenanya/baileys 7.4.10 → 7.4.13
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 +26 -26
- package/WAProto/index.js +97194 -67957
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +231 -1
- package/lib/Defaults/index.js +23 -11
- package/lib/Defaults/phonenumber-mcc.json +223 -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} +2 -2
- package/lib/Socket/business.d.ts +28 -31
- package/lib/Socket/chats.d.ts +9 -17
- package/lib/Socket/chats.js +116 -115
- package/lib/Socket/groups.d.ts +10 -23
- package/lib/Socket/groups.js +1 -12
- package/lib/Socket/index.d.ts +38 -69
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +28 -30
- package/lib/Socket/messages-recv.js +180 -291
- package/lib/Socket/messages-send.d.ts +19 -25
- package/lib/Socket/messages-send.js +76 -110
- package/lib/Socket/newsletter.d.ts +13 -19
- package/lib/Socket/newsletter.js +54 -67
- package/lib/Socket/{communities.d.ts → registration.d.ts} +145 -94
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +1 -3
- package/lib/Socket/socket.js +17 -15
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.js +11 -13
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +6 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -15
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +1 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +30 -37
- package/lib/Types/Newsletter.d.ts +13 -0
- package/lib/Types/Newsletter.js +15 -1
- package/lib/Types/Socket.d.ts +3 -10
- package/lib/Types/index.d.ts +0 -8
- package/lib/Utils/auth-utils.js +7 -1
- package/lib/Utils/chat-utils.d.ts +4 -5
- package/lib/Utils/chat-utils.js +20 -52
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +2 -4
- package/lib/Utils/decode-wa-message.d.ts +0 -1
- package/lib/Utils/decode-wa-message.js +14 -34
- package/lib/Utils/event-buffer.js +8 -14
- package/lib/Utils/generics.d.ts +13 -37
- package/lib/Utils/generics.js +18 -103
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +0 -3
- package/lib/Utils/index.d.ts +0 -1
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +2 -3
- package/lib/Utils/messages-media.js +32 -17
- package/lib/Utils/messages.d.ts +0 -1
- package/lib/Utils/messages.js +72 -67
- package/lib/Utils/noise-handler.d.ts +3 -3
- package/lib/Utils/noise-handler.js +12 -7
- package/lib/Utils/process-message.d.ts +2 -3
- package/lib/Utils/process-message.js +21 -55
- package/lib/Utils/signal.js +16 -23
- package/lib/Utils/use-multi-file-auth-state.js +3 -17
- package/lib/Utils/validate-connection.d.ts +1 -0
- package/lib/Utils/validate-connection.js +44 -10
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +2 -3
- package/lib/WABinary/decode.js +4 -6
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +6 -8
- package/lib/WABinary/generic-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.d.ts +3 -3
- package/lib/WABinary/jid-utils.js +5 -5
- package/lib/WAM/BinaryInfo.d.ts +2 -3
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.d.ts +0 -1
- package/lib/WAM/encode.js +2 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +37 -39
- package/lib/Socket/communities.js +0 -354
- package/lib/Socket/usync.d.ts +0 -38
- package/lib/Socket/usync.js +0 -70
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/index.js +0 -20
- package/lib/WAUSync/USyncQuery.d.ts +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -79
- package/lib/WAUSync/USyncUser.d.ts +0 -10
- package/lib/WAUSync/USyncUser.js +0 -22
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -19
- /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
package/lib/Utils/messages.js
CHANGED
|
@@ -30,6 +30,7 @@ const MessageTypeProto = {
|
|
|
30
30
|
'sticker': Types_1.WAProto.Message.StickerMessage,
|
|
31
31
|
'document': Types_1.WAProto.Message.DocumentMessage,
|
|
32
32
|
};
|
|
33
|
+
const ButtonType = WAProto_1.proto.Message.ButtonsMessage.HeaderType;
|
|
33
34
|
/**
|
|
34
35
|
* Uses a regex to test whether the string contains a URL, and returns the URL if it does.
|
|
35
36
|
* @param text eg. hello https://google.com
|
|
@@ -239,7 +240,7 @@ const generateForwardMessageContent = (message, forceForward) => {
|
|
|
239
240
|
exports.generateForwardMessageContent = generateForwardMessageContent;
|
|
240
241
|
const generateWAMessageContent = async (message, options) => {
|
|
241
242
|
var _a;
|
|
242
|
-
var _b
|
|
243
|
+
var _b;
|
|
243
244
|
let m = {};
|
|
244
245
|
if ('text' in message) {
|
|
245
246
|
const extContent = { text: message.text };
|
|
@@ -309,41 +310,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
309
310
|
message.disappearingMessagesInChat;
|
|
310
311
|
m = (0, exports.prepareDisappearingMessageSettingContent)(exp);
|
|
311
312
|
}
|
|
312
|
-
else if ('groupInvite' in message) {
|
|
313
|
-
m.groupInviteMessage = {};
|
|
314
|
-
m.groupInviteMessage.inviteCode = message.groupInvite.inviteCode;
|
|
315
|
-
m.groupInviteMessage.inviteExpiration = message.groupInvite.inviteExpiration;
|
|
316
|
-
m.groupInviteMessage.caption = message.groupInvite.text;
|
|
317
|
-
m.groupInviteMessage.groupJid = message.groupInvite.jid;
|
|
318
|
-
m.groupInviteMessage.groupName = message.groupInvite.subject;
|
|
319
|
-
//TODO: use built-in interface and get disappearing mode info etc.
|
|
320
|
-
//TODO: cache / use store!?
|
|
321
|
-
if (options.getProfilePicUrl) {
|
|
322
|
-
const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview');
|
|
323
|
-
if (pfpUrl) {
|
|
324
|
-
const resp = await axios_1.default.get(pfpUrl, { responseType: 'arraybuffer' });
|
|
325
|
-
if (resp.status === 200) {
|
|
326
|
-
m.groupInviteMessage.jpegThumbnail = resp.data;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
else if ('pin' in message) {
|
|
332
|
-
m.pinInChatMessage = {};
|
|
333
|
-
m.messageContextInfo = {};
|
|
334
|
-
m.pinInChatMessage.key = message.pin;
|
|
335
|
-
m.pinInChatMessage.type = 1;
|
|
336
|
-
m.pinInChatMessage.senderTimestampMs = Date.now();
|
|
337
|
-
m.messageContextInfo.messageAddOnDurationInSecs = message.time || 86400;
|
|
338
|
-
}
|
|
339
|
-
else if ('unpin' in message) {
|
|
340
|
-
m.pinInChatMessage = {};
|
|
341
|
-
m.messageContextInfo = {};
|
|
342
|
-
m.pinInChatMessage.key = message.unpin;
|
|
343
|
-
m.pinInChatMessage.type = 2;
|
|
344
|
-
m.pinInChatMessage.senderTimestampMs = Date.now();
|
|
345
|
-
m.messageContextInfo.messageAddOnDurationInSecs = 0;
|
|
346
|
-
}
|
|
347
313
|
else if ('buttonReply' in message) {
|
|
348
314
|
switch (message.type) {
|
|
349
315
|
case 'template':
|
|
@@ -362,10 +328,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
362
328
|
break;
|
|
363
329
|
}
|
|
364
330
|
}
|
|
365
|
-
else if ('ptv' in message && message.ptv) {
|
|
366
|
-
const { videoMessage } = await (0, exports.prepareWAMessageMedia)({ video: message.video }, options);
|
|
367
|
-
m.ptvMessage = videoMessage;
|
|
368
|
-
}
|
|
369
331
|
else if ('product' in message) {
|
|
370
332
|
const { imageMessage } = await (0, exports.prepareWAMessageMedia)({ image: message.product.productImage }, options);
|
|
371
333
|
m.productMessage = Types_1.WAProto.Message.ProductMessage.fromObject({
|
|
@@ -381,7 +343,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
381
343
|
}
|
|
382
344
|
else if ('poll' in message) {
|
|
383
345
|
(_b = message.poll).selectableCount || (_b.selectableCount = 0);
|
|
384
|
-
(_c = message.poll).toAnnouncementGroup || (_c.toAnnouncementGroup = false);
|
|
385
346
|
if (!Array.isArray(message.poll.values)) {
|
|
386
347
|
throw new boom_1.Boom('Invalid poll values', { statusCode: 400 });
|
|
387
348
|
}
|
|
@@ -393,25 +354,11 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
393
354
|
// encKey
|
|
394
355
|
messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32),
|
|
395
356
|
};
|
|
396
|
-
|
|
357
|
+
m.pollCreationMessage = {
|
|
397
358
|
name: message.poll.name,
|
|
398
359
|
selectableOptionsCount: message.poll.selectableCount,
|
|
399
360
|
options: message.poll.values.map(optionName => ({ optionName })),
|
|
400
361
|
};
|
|
401
|
-
if (message.poll.toAnnouncementGroup) {
|
|
402
|
-
// poll v2 is for community announcement groups (single select and multiple)
|
|
403
|
-
m.pollCreationMessageV2 = pollCreationMessage;
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
if (message.poll.selectableCount > 0) {
|
|
407
|
-
//poll v3 is for single select polls
|
|
408
|
-
m.pollCreationMessageV3 = pollCreationMessage;
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
// poll v3 for multiple choice polls
|
|
412
|
-
m.pollCreationMessage = pollCreationMessage;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
362
|
}
|
|
416
363
|
else if ('sharePhoneNumber' in message) {
|
|
417
364
|
m.protocolMessage = {
|
|
@@ -424,6 +371,61 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
424
371
|
else {
|
|
425
372
|
m = await (0, exports.prepareWAMessageMedia)(message, options);
|
|
426
373
|
}
|
|
374
|
+
if ('buttons' in message && !!message.buttons) {
|
|
375
|
+
const buttonsMessage = {
|
|
376
|
+
buttons: message.buttons.map(b => ({ ...b, type: WAProto_1.proto.Message.ButtonsMessage.Button.Type.RESPONSE }))
|
|
377
|
+
};
|
|
378
|
+
if ('text' in message) {
|
|
379
|
+
buttonsMessage.contentText = message.text;
|
|
380
|
+
buttonsMessage.headerType = ButtonType.EMPTY;
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
if ('caption' in message) {
|
|
384
|
+
buttonsMessage.contentText = message.caption;
|
|
385
|
+
}
|
|
386
|
+
const type = Object.keys(m)[0].replace('Message', '').toUpperCase();
|
|
387
|
+
buttonsMessage.headerType = ButtonType[type];
|
|
388
|
+
Object.assign(buttonsMessage, m);
|
|
389
|
+
}
|
|
390
|
+
if ('footer' in message && !!message.footer) {
|
|
391
|
+
buttonsMessage.footerText = message.footer;
|
|
392
|
+
}
|
|
393
|
+
m = { buttonsMessage };
|
|
394
|
+
}
|
|
395
|
+
else if ('templateButtons' in message && !!message.templateButtons) {
|
|
396
|
+
const msg = {
|
|
397
|
+
hydratedButtons: message.templateButtons
|
|
398
|
+
};
|
|
399
|
+
if ('text' in message) {
|
|
400
|
+
msg.hydratedContentText = message.text;
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
if ('caption' in message) {
|
|
404
|
+
msg.hydratedContentText = message.caption;
|
|
405
|
+
}
|
|
406
|
+
Object.assign(msg, m);
|
|
407
|
+
}
|
|
408
|
+
if ('footer' in message && !!message.footer) {
|
|
409
|
+
msg.hydratedFooterText = message.footer;
|
|
410
|
+
}
|
|
411
|
+
m = {
|
|
412
|
+
templateMessage: {
|
|
413
|
+
fourRowTemplate: msg,
|
|
414
|
+
hydratedTemplate: msg
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
if ('sections' in message && !!message.sections) {
|
|
419
|
+
const listMessage = {
|
|
420
|
+
sections: message.sections,
|
|
421
|
+
buttonText: message.buttonText,
|
|
422
|
+
title: message.title,
|
|
423
|
+
footerText: message.footer,
|
|
424
|
+
description: message.text,
|
|
425
|
+
listType: WAProto_1.proto.Message.ListMessage.ListType.SINGLE_SELECT
|
|
426
|
+
};
|
|
427
|
+
m = { listMessage };
|
|
428
|
+
}
|
|
427
429
|
if ('viewOnce' in message && !!message.viewOnce) {
|
|
428
430
|
m = { viewOnceMessage: { message: m } };
|
|
429
431
|
}
|
|
@@ -460,8 +462,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
460
462
|
const key = (0, exports.getContentType)(innerMessage);
|
|
461
463
|
const timestamp = (0, generics_1.unixTimestampSeconds)(options.timestamp);
|
|
462
464
|
const { quoted, userJid } = options;
|
|
463
|
-
|
|
464
|
-
if (quoted && !(0, WABinary_1.isJidNewsletter)(jid)) {
|
|
465
|
+
if (quoted && !(0, WABinary_1.isJidNewsLetter)(jid)) {
|
|
465
466
|
const participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid);
|
|
466
467
|
let quotedMsg = (0, exports.normalizeMessageContent)(quoted.message);
|
|
467
468
|
const msgType = (0, exports.getContentType)(quotedMsg);
|
|
@@ -490,7 +491,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
490
491
|
// already not converted to disappearing message
|
|
491
492
|
key !== 'ephemeralMessage' &&
|
|
492
493
|
// newsletter not accept disappearing messages
|
|
493
|
-
!(0, WABinary_1.
|
|
494
|
+
!(0, WABinary_1.isJidNewsLetter)(jid)) {
|
|
494
495
|
innerMessage[key].contextInfo = {
|
|
495
496
|
...(innerMessage[key].contextInfo || {}),
|
|
496
497
|
expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL,
|
|
@@ -517,7 +518,7 @@ const generateWAMessage = async (jid, content, options) => {
|
|
|
517
518
|
var _a;
|
|
518
519
|
// ensure msg ID is with every log
|
|
519
520
|
options.logger = (_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.child({ msgId: options.messageId });
|
|
520
|
-
return (0, exports.generateWAMessageFromContent)(jid, await (0, exports.generateWAMessageContent)(content, { newsletter: (0, WABinary_1.
|
|
521
|
+
return (0, exports.generateWAMessageFromContent)(jid, await (0, exports.generateWAMessageContent)(content, { newsletter: (0, WABinary_1.isJidNewsLetter)(jid), ...options }), options);
|
|
521
522
|
};
|
|
522
523
|
exports.generateWAMessage = generateWAMessage;
|
|
523
524
|
/** Get the key to access the true type of content */
|
|
@@ -706,13 +707,17 @@ const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
|
706
707
|
const result = await downloadMsg()
|
|
707
708
|
.catch(async (error) => {
|
|
708
709
|
var _a;
|
|
709
|
-
if (ctx
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
710
|
+
if (ctx) {
|
|
711
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
712
|
+
// check if the message requires a reupload
|
|
713
|
+
if (REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
|
|
714
|
+
ctx.logger.info({ key: message.key }, 'sending reupload media request...');
|
|
715
|
+
// request reupload
|
|
716
|
+
message = await ctx.reuploadRequest(message);
|
|
717
|
+
const result = await downloadMsg();
|
|
718
|
+
return result;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
716
721
|
}
|
|
717
722
|
throw error;
|
|
718
723
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { Logger } from 'pino';
|
|
4
3
|
import { proto } from '../../WAProto';
|
|
5
4
|
import { KeyPair } from '../Types';
|
|
6
5
|
import { BinaryNode } from '../WABinary';
|
|
7
|
-
export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
|
|
6
|
+
export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
|
|
8
7
|
keyPair: KeyPair;
|
|
9
8
|
NOISE_HEADER: Uint8Array;
|
|
9
|
+
mobile: boolean;
|
|
10
10
|
logger: Logger;
|
|
11
11
|
routingInfo?: Buffer | undefined;
|
|
12
12
|
}) => {
|
|
@@ -17,5 +17,5 @@ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public
|
|
|
17
17
|
finishInit: () => void;
|
|
18
18
|
processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Buffer;
|
|
19
19
|
encodeFrame: (data: Buffer | Uint8Array) => Buffer;
|
|
20
|
-
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) =>
|
|
20
|
+
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
|
|
21
21
|
};
|
|
@@ -11,7 +11,7 @@ const generateIV = (counter) => {
|
|
|
11
11
|
new DataView(iv).setUint32(8, counter);
|
|
12
12
|
return new Uint8Array(iv);
|
|
13
13
|
};
|
|
14
|
-
const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
|
|
14
|
+
const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }) => {
|
|
15
15
|
logger = logger.child({ class: 'ns' });
|
|
16
16
|
const authenticate = (data) => {
|
|
17
17
|
if (!isFinished) {
|
|
@@ -83,10 +83,15 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
83
83
|
const decStaticContent = decrypt(serverHello.static);
|
|
84
84
|
mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
|
|
85
85
|
const certDecoded = decrypt(serverHello.payload);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
if (mobile) {
|
|
87
|
+
WAProto_1.proto.CertChain.NoiseCertificate.decode(certDecoded);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded);
|
|
91
|
+
const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
|
|
92
|
+
if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
|
|
93
|
+
throw new boom_1.Boom('certification match failed', { statusCode: 400 });
|
|
94
|
+
}
|
|
90
95
|
}
|
|
91
96
|
const keyEnc = encrypt(noiseKey.public);
|
|
92
97
|
mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
|
|
@@ -120,7 +125,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
120
125
|
frame.set(data, introSize + 3);
|
|
121
126
|
return frame;
|
|
122
127
|
},
|
|
123
|
-
decodeFrame:
|
|
128
|
+
decodeFrame: (newData, onFrame) => {
|
|
124
129
|
var _a;
|
|
125
130
|
// the binary protocol uses its own framing mechanism
|
|
126
131
|
// on top of the WS frames
|
|
@@ -138,7 +143,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
138
143
|
inBytes = inBytes.slice(size + 3);
|
|
139
144
|
if (isFinished) {
|
|
140
145
|
const result = decrypt(frame);
|
|
141
|
-
frame =
|
|
146
|
+
frame = (0, WABinary_1.decodeBinaryNode)(result);
|
|
142
147
|
}
|
|
143
148
|
logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
|
|
144
149
|
onFrame(frame);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type { Logger } from 'pino';
|
|
3
3
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { AuthenticationCreds, BaileysEventEmitter,
|
|
4
|
+
import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
5
5
|
type ProcessMessageContext = {
|
|
6
6
|
shouldProcessHistoryMsg: boolean;
|
|
7
|
-
placeholderResendCache?: CacheStore;
|
|
8
7
|
creds: AuthenticationCreds;
|
|
9
8
|
keyStore: SignalKeyStoreWithTransaction;
|
|
10
9
|
ev: BaileysEventEmitter;
|
|
@@ -38,5 +37,5 @@ type PollContext = {
|
|
|
38
37
|
* @returns list of SHA256 options
|
|
39
38
|
*/
|
|
40
39
|
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
|
|
41
|
-
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg,
|
|
40
|
+
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
42
41
|
export default processMessage;
|
|
@@ -102,8 +102,8 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
exports.decryptPollVote = decryptPollVote;
|
|
105
|
-
const processMessage = async (message, { shouldProcessHistoryMsg,
|
|
106
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
105
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
|
|
106
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
107
107
|
const meId = creds.me.id;
|
|
108
108
|
const { accountSettings } = creds;
|
|
109
109
|
const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
|
|
@@ -137,22 +137,14 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
137
137
|
isLatest,
|
|
138
138
|
}, 'got history notification');
|
|
139
139
|
if (process) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
processedHistoryMessages
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
]
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
149
|
-
ev.emit('messaging-history.set', {
|
|
150
|
-
...data,
|
|
151
|
-
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
152
|
-
? isLatest
|
|
153
|
-
: undefined,
|
|
154
|
-
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
140
|
+
ev.emit('creds.update', {
|
|
141
|
+
processedHistoryMessages: [
|
|
142
|
+
...(creds.processedHistoryMessages || []),
|
|
143
|
+
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
144
|
+
]
|
|
155
145
|
});
|
|
146
|
+
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
147
|
+
ev.emit('messaging-history.set', { ...data, isLatest });
|
|
156
148
|
}
|
|
157
149
|
break;
|
|
158
150
|
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
@@ -195,22 +187,14 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
195
187
|
case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
196
188
|
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
197
189
|
if (response) {
|
|
198
|
-
placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
|
|
199
|
-
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
|
200
190
|
const { peerDataOperationResult } = response;
|
|
201
191
|
for (const result of peerDataOperationResult) {
|
|
202
192
|
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
203
|
-
//eslint-disable-next-line max-depth
|
|
204
193
|
if (retryResponse) {
|
|
205
194
|
const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
messages: [webMessageInfo],
|
|
210
|
-
type: 'notify',
|
|
211
|
-
requestId: response.stanzaId
|
|
212
|
-
});
|
|
213
|
-
}, 500);
|
|
195
|
+
ev.emit('messages.update', [
|
|
196
|
+
{ key: webMessageInfo.key, update: { message: webMessageInfo.message } }
|
|
197
|
+
]);
|
|
214
198
|
}
|
|
215
199
|
}
|
|
216
200
|
}
|
|
@@ -224,11 +208,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
224
208
|
};
|
|
225
209
|
ev.emit('messages.reaction', [{
|
|
226
210
|
reaction,
|
|
227
|
-
key:
|
|
211
|
+
key: content.reactionMessage.key,
|
|
228
212
|
}]);
|
|
229
213
|
}
|
|
230
214
|
else if (message.messageStubType) {
|
|
231
|
-
const jid =
|
|
215
|
+
const jid = message.key.remoteJid;
|
|
232
216
|
//let actor = whatsappID (message.participant)
|
|
233
217
|
let participants;
|
|
234
218
|
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
@@ -236,15 +220,8 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
236
220
|
var _a;
|
|
237
221
|
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
|
238
222
|
};
|
|
239
|
-
const emitGroupRequestJoin = (participant, action, method) => {
|
|
240
|
-
ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
|
|
241
|
-
};
|
|
242
223
|
const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
|
|
243
224
|
switch (message.messageStubType) {
|
|
244
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
245
|
-
participants = message.messageStubParameters || [];
|
|
246
|
-
emitParticipantsUpdate('modify');
|
|
247
|
-
break;
|
|
248
225
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
249
226
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
250
227
|
participants = message.messageStubParameters || [];
|
|
@@ -272,41 +249,30 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
272
249
|
emitParticipantsUpdate('promote');
|
|
273
250
|
break;
|
|
274
251
|
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
275
|
-
const announceValue = (
|
|
252
|
+
const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
|
|
276
253
|
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
277
254
|
break;
|
|
278
255
|
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
279
|
-
const restrictValue = (
|
|
256
|
+
const restrictValue = (_e = message.messageStubParameters) === null || _e === void 0 ? void 0 : _e[0];
|
|
280
257
|
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
281
258
|
break;
|
|
282
259
|
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
283
|
-
const name = (
|
|
260
|
+
const name = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
|
|
284
261
|
chat.name = name;
|
|
285
262
|
emitGroupUpdate({ subject: name });
|
|
286
263
|
break;
|
|
287
|
-
case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
288
|
-
const description = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
289
|
-
chat.description = description;
|
|
290
|
-
emitGroupUpdate({ desc: description });
|
|
291
|
-
break;
|
|
292
264
|
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
293
|
-
const code = (
|
|
265
|
+
const code = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
294
266
|
emitGroupUpdate({ inviteCode: code });
|
|
295
267
|
break;
|
|
296
268
|
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
297
|
-
const memberAddValue = (
|
|
269
|
+
const memberAddValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
298
270
|
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
299
271
|
break;
|
|
300
272
|
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
301
|
-
const approvalMode = (
|
|
273
|
+
const approvalMode = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
302
274
|
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
303
275
|
break;
|
|
304
|
-
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
|
|
305
|
-
const participant = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
|
|
306
|
-
const action = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[1];
|
|
307
|
-
const method = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[2];
|
|
308
|
-
emitGroupRequestJoin(participant, action, method);
|
|
309
|
-
break;
|
|
310
276
|
}
|
|
311
277
|
}
|
|
312
278
|
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
@@ -317,7 +283,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
317
283
|
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
318
284
|
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
319
285
|
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
320
|
-
const pollEncKey = (
|
|
286
|
+
const pollEncKey = (_k = pollMsg.messageContextInfo) === null || _k === void 0 ? void 0 : _k.messageSecret;
|
|
321
287
|
try {
|
|
322
288
|
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
323
289
|
pollEncKey,
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
4
|
const Defaults_1 = require("../Defaults");
|
|
6
5
|
const WABinary_1 = require("../WABinary");
|
|
7
6
|
const crypto_1 = require("./crypto");
|
|
@@ -67,26 +66,22 @@ const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
67
66
|
for (const node of nodes) {
|
|
68
67
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
69
68
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
69
|
+
await Promise.all(nodes.map(async (node) => {
|
|
70
|
+
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
71
|
+
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
72
|
+
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
73
|
+
const jid = node.attrs.jid;
|
|
74
|
+
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
75
|
+
await repository.injectE2ESession({
|
|
76
|
+
jid,
|
|
77
|
+
session: {
|
|
78
|
+
registrationId: registrationId,
|
|
79
|
+
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
80
|
+
signedPreKey: extractKey(signedKey),
|
|
81
|
+
preKey: extractKey(key)
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}));
|
|
90
85
|
};
|
|
91
86
|
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
92
87
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
@@ -101,10 +96,8 @@ const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
|
101
96
|
const devicesNode = (0, WABinary_1.getBinaryNodeChild)(item, 'devices');
|
|
102
97
|
const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(devicesNode, 'device-list');
|
|
103
98
|
if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
|
|
104
|
-
//eslint-disable-next-line max-depth
|
|
105
99
|
for (const { tag, attrs } of deviceListNode.content) {
|
|
106
100
|
const device = +attrs.id;
|
|
107
|
-
//eslint-disable-next-line max-depth
|
|
108
101
|
if (tag === 'device' && // ensure the "device" tag
|
|
109
102
|
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
110
103
|
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useMultiFileAuthState = void 0;
|
|
7
|
-
const async_lock_1 = __importDefault(require("async-lock"));
|
|
8
4
|
const promises_1 = require("fs/promises");
|
|
9
5
|
const path_1 = require("path");
|
|
10
6
|
const WAProto_1 = require("../../WAProto");
|
|
11
7
|
const auth_utils_1 = require("./auth-utils");
|
|
12
8
|
const generics_1 = require("./generics");
|
|
13
|
-
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
14
|
-
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
15
|
-
// https://github.com/nodejs/node/issues/26338
|
|
16
|
-
// Default pending is 1000, set it to infinity
|
|
17
|
-
// https://github.com/rogierschouten/async-lock/issues/63
|
|
18
|
-
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
19
9
|
/**
|
|
20
10
|
* stores the full authentication state in a single folder.
|
|
21
11
|
* Far more efficient than singlefileauthstate
|
|
@@ -24,15 +14,12 @@ const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
|
24
14
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
25
15
|
* */
|
|
26
16
|
const useMultiFileAuthState = async (folder) => {
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
17
|
const writeData = (data, file) => {
|
|
29
|
-
|
|
30
|
-
return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
|
|
18
|
+
return (0, promises_1.writeFile)((0, path_1.join)(folder, fixFileName(file)), JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
31
19
|
};
|
|
32
20
|
const readData = async (file) => {
|
|
33
21
|
try {
|
|
34
|
-
const
|
|
35
|
-
const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
|
|
22
|
+
const data = await (0, promises_1.readFile)((0, path_1.join)(folder, fixFileName(file)), { encoding: 'utf-8' });
|
|
36
23
|
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
37
24
|
}
|
|
38
25
|
catch (error) {
|
|
@@ -41,8 +28,7 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
41
28
|
};
|
|
42
29
|
const removeData = async (file) => {
|
|
43
30
|
try {
|
|
44
|
-
|
|
45
|
-
await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
|
|
31
|
+
await (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
|
|
46
32
|
}
|
|
47
33
|
catch (_a) {
|
|
48
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { proto } from '../../WAProto';
|
|
2
2
|
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
|
|
3
3
|
import { BinaryNode } from '../WABinary';
|
|
4
|
+
export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
|
|
4
5
|
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
5
6
|
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
6
7
|
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
|