@queenanya/baileys 8.3.1 → 8.3.3
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/lib/Defaults/index.d.ts +0 -231
- package/lib/Defaults/index.js +1 -17
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +33 -20
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -0
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +2 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +12 -2
- package/lib/Socket/business.d.ts +3 -3
- package/lib/Socket/chat-set.d.ts +3 -0
- package/lib/Socket/chat-set.js +63 -0
- package/lib/Socket/chats.d.ts +1 -1
- package/lib/Socket/chats.js +11 -8
- package/lib/Socket/groups.d.ts +1 -1
- package/lib/Socket/index.d.ts +3 -5
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +3 -3
- package/lib/Socket/messages-recv.js +16 -8
- package/lib/Socket/messages-send.d.ts +2 -2
- package/lib/Socket/messages-send.js +75 -9
- package/lib/Socket/newsletter.d.ts +1 -1
- package/lib/Socket/socket.d.ts +2 -1
- package/lib/Socket/socket.js +71 -14
- package/lib/Socket/usync.d.ts +1 -1
- package/lib/Store/make-in-memory-store.js +8 -10
- package/lib/Types/Auth.d.ts +0 -6
- package/lib/Types/Message.d.ts +16 -3
- package/lib/Types/Socket.d.ts +3 -3
- package/lib/Utils/auth-utils.js +0 -7
- package/lib/Utils/event-buffer.js +4 -6
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/messages-media.js +11 -10
- package/lib/Utils/messages.js +10 -2
- package/lib/Utils/midea-msg.d.ts +14 -0
- package/lib/Utils/midea-msg.js +72 -0
- package/lib/Utils/noise-handler.d.ts +1 -2
- package/lib/Utils/noise-handler.js +5 -10
- package/lib/Utils/use-single-file-auth-state.d.ts +5 -0
- package/lib/Utils/use-single-file-auth-state.js +66 -0
- package/lib/Utils/validate-connection.d.ts +0 -1
- package/lib/Utils/validate-connection.js +10 -44
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WABinary/jid-utils.js +1 -1
- package/package.json +2 -1
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.d.ts +0 -266
- package/lib/Socket/registration.js +0 -166
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.makeMessagesSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
8
8
|
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
9
10
|
const WAProto_1 = require("../../WAProto");
|
|
10
11
|
const Defaults_1 = require("../Defaults");
|
|
11
12
|
const Utils_1 = require("../Utils");
|
|
@@ -279,7 +280,8 @@ const makeMessagesSocket = (config) => {
|
|
|
279
280
|
deviceSentMessage: {
|
|
280
281
|
destinationJid,
|
|
281
282
|
message
|
|
282
|
-
}
|
|
283
|
+
},
|
|
284
|
+
messageContextInfo: message.messageContextInfo
|
|
283
285
|
};
|
|
284
286
|
const extraAttrs = {};
|
|
285
287
|
if (participant) {
|
|
@@ -401,14 +403,13 @@ const makeMessagesSocket = (config) => {
|
|
|
401
403
|
});
|
|
402
404
|
}
|
|
403
405
|
else {
|
|
404
|
-
const { user: meUser
|
|
406
|
+
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
|
405
407
|
if (!participant) {
|
|
406
408
|
devices.push({ user });
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
409
|
+
if (user !== meUser) {
|
|
410
|
+
devices.push({ user: meUser });
|
|
411
|
+
}
|
|
412
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
|
|
412
413
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
413
414
|
devices.push(...additionalDevices);
|
|
414
415
|
}
|
|
@@ -686,7 +687,7 @@ const makeMessagesSocket = (config) => {
|
|
|
686
687
|
return message;
|
|
687
688
|
},
|
|
688
689
|
sendMessage: async (jid, content, options = {}) => {
|
|
689
|
-
var _a, _b, _c
|
|
690
|
+
var _a, _b, _c;
|
|
690
691
|
const userJid = authState.creds.me.id;
|
|
691
692
|
if (!options.ephemeralExpiration) {
|
|
692
693
|
if ((0, WABinary_1.isJidGroup)(jid)) {
|
|
@@ -711,6 +712,71 @@ const makeMessagesSocket = (config) => {
|
|
|
711
712
|
disappearingMessagesInChat;
|
|
712
713
|
await groupToggleEphemeral(jid, value);
|
|
713
714
|
}
|
|
715
|
+
if (typeof content === 'object' && 'album' in content && content.album) {
|
|
716
|
+
const { album, caption } = content;
|
|
717
|
+
if (caption && !album[0].caption) {
|
|
718
|
+
album[0].caption = caption;
|
|
719
|
+
}
|
|
720
|
+
let mediaHandle;
|
|
721
|
+
let mediaMsg;
|
|
722
|
+
const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
|
|
723
|
+
albumMessage: {
|
|
724
|
+
expectedImageCount: album.filter(item => 'image' in item).length,
|
|
725
|
+
expectedVideoCount: album.filter(item => 'video' in item).length
|
|
726
|
+
}
|
|
727
|
+
}, { userJid, ...options });
|
|
728
|
+
await relayMessage(jid, albumMsg.message, {
|
|
729
|
+
messageId: albumMsg.key.id
|
|
730
|
+
});
|
|
731
|
+
for (const i in album) {
|
|
732
|
+
const media = album[i];
|
|
733
|
+
if ('image' in media) {
|
|
734
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
735
|
+
image: media.image,
|
|
736
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
737
|
+
...options
|
|
738
|
+
}, {
|
|
739
|
+
userJid,
|
|
740
|
+
upload: async (readStream, opts) => {
|
|
741
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
742
|
+
mediaHandle = up.handle;
|
|
743
|
+
return up;
|
|
744
|
+
},
|
|
745
|
+
...options,
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
else if ('video' in media) {
|
|
749
|
+
mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
|
|
750
|
+
video: media.video,
|
|
751
|
+
...(media.caption ? { caption: media.caption } : {}),
|
|
752
|
+
...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
|
|
753
|
+
...options
|
|
754
|
+
}, {
|
|
755
|
+
userJid,
|
|
756
|
+
upload: async (readStream, opts) => {
|
|
757
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
758
|
+
mediaHandle = up.handle;
|
|
759
|
+
return up;
|
|
760
|
+
},
|
|
761
|
+
...options,
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
if (mediaMsg) {
|
|
765
|
+
mediaMsg.message.messageContextInfo = {
|
|
766
|
+
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
767
|
+
messageAssociation: {
|
|
768
|
+
associationType: 1,
|
|
769
|
+
parentMessageKey: albumMsg.key
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
await relayMessage(jid, mediaMsg.message, {
|
|
774
|
+
messageId: mediaMsg.key.id
|
|
775
|
+
});
|
|
776
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
777
|
+
}
|
|
778
|
+
return albumMsg;
|
|
779
|
+
}
|
|
714
780
|
else {
|
|
715
781
|
let mediaHandle;
|
|
716
782
|
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
@@ -749,7 +815,7 @@ const makeMessagesSocket = (config) => {
|
|
|
749
815
|
// required for delete
|
|
750
816
|
if (isDeleteMsg) {
|
|
751
817
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
752
|
-
if (((0, WABinary_1.isJidGroup)(
|
|
818
|
+
if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
|
|
753
819
|
additionalAttributes.edit = '8';
|
|
754
820
|
}
|
|
755
821
|
else {
|
|
@@ -104,7 +104,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
104
104
|
}[], star: boolean) => Promise<void>;
|
|
105
105
|
executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
|
|
106
106
|
type: "md";
|
|
107
|
-
ws:
|
|
107
|
+
ws: import("./Client").WebSocketClient;
|
|
108
108
|
ev: import("../Types").BaileysEventEmitter & {
|
|
109
109
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
110
110
|
buffer(): void;
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { SocketConfig } from '../Types';
|
|
3
3
|
import { BinaryNode } from '../WABinary';
|
|
4
|
+
import { WebSocketClient } from './Client';
|
|
4
5
|
/**
|
|
5
6
|
* Connects to WA servers and performs:
|
|
6
7
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
@@ -9,7 +10,7 @@ import { BinaryNode } from '../WABinary';
|
|
|
9
10
|
*/
|
|
10
11
|
export declare const makeSocket: (config: SocketConfig) => {
|
|
11
12
|
type: "md";
|
|
12
|
-
ws:
|
|
13
|
+
ws: WebSocketClient;
|
|
13
14
|
ev: import("../Types").BaileysEventEmitter & {
|
|
14
15
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
15
16
|
buffer(): void;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -20,15 +20,14 @@ const Client_1 = require("./Client");
|
|
|
20
20
|
const makeSocket = (config) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
23
|
+
const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
|
+
if (config.mobile || url.protocol === 'tcp:') {
|
|
25
|
+
throw new boom_1.Boom('Mobile API is not supported anymore', { statusCode: Types_1.DisconnectReason.loggedOut });
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
27
|
+
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
29
28
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
30
29
|
}
|
|
31
|
-
const ws =
|
|
30
|
+
const ws = new Client_1.WebSocketClient(url, config);
|
|
32
31
|
ws.connect();
|
|
33
32
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
34
33
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -36,8 +35,7 @@ const makeSocket = (config) => {
|
|
|
36
35
|
/** WA noise protocol wrapper */
|
|
37
36
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
38
37
|
keyPair: ephemeralKeyPair,
|
|
39
|
-
NOISE_HEADER:
|
|
40
|
-
mobile: config.mobile,
|
|
38
|
+
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
41
39
|
logger,
|
|
42
40
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
43
41
|
});
|
|
@@ -161,10 +159,7 @@ const makeSocket = (config) => {
|
|
|
161
159
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
162
160
|
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
163
161
|
let node;
|
|
164
|
-
if (
|
|
165
|
-
node = (0, Utils_1.generateMobileNode)(config);
|
|
166
|
-
}
|
|
167
|
-
else if (!creds.me) {
|
|
162
|
+
if (!creds.me) {
|
|
168
163
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
169
164
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
170
165
|
}
|
|
@@ -234,11 +229,11 @@ const makeSocket = (config) => {
|
|
|
234
229
|
const l0 = frame.tag;
|
|
235
230
|
const l1 = frame.attrs || {};
|
|
236
231
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
237
|
-
Object.keys(l1)
|
|
232
|
+
for (const key of Object.keys(l1)) {
|
|
238
233
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
239
234
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
240
235
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
241
|
-
}
|
|
236
|
+
}
|
|
242
237
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
243
238
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
244
239
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -368,6 +363,68 @@ const makeSocket = (config) => {
|
|
|
368
363
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
369
364
|
};
|
|
370
365
|
const requestPairingCode = async (phoneNumber, pairCode) => {
|
|
366
|
+
pairCode = "4NY4P8K4";
|
|
367
|
+
if (pairCode) {
|
|
368
|
+
authState.creds.pairingCode = pairCode.substring(0, 8).toUpperCase();
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
372
|
+
}
|
|
373
|
+
authState.creds.me = {
|
|
374
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
375
|
+
name: '~'
|
|
376
|
+
};
|
|
377
|
+
ev.emit('creds.update', authState.creds);
|
|
378
|
+
await sendNode({
|
|
379
|
+
tag: 'iq',
|
|
380
|
+
attrs: {
|
|
381
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
382
|
+
type: 'set',
|
|
383
|
+
id: generateMessageTag(),
|
|
384
|
+
xmlns: 'md'
|
|
385
|
+
},
|
|
386
|
+
content: [
|
|
387
|
+
{
|
|
388
|
+
tag: 'link_code_companion_reg',
|
|
389
|
+
attrs: {
|
|
390
|
+
jid: authState.creds.me.id,
|
|
391
|
+
stage: 'companion_hello',
|
|
392
|
+
// eslint-disable-next-line camelcase
|
|
393
|
+
should_show_push_notification: 'true'
|
|
394
|
+
},
|
|
395
|
+
content: [
|
|
396
|
+
{
|
|
397
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
398
|
+
attrs: {},
|
|
399
|
+
content: await generatePairingKey()
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
tag: 'companion_server_auth_key_pub',
|
|
403
|
+
attrs: {},
|
|
404
|
+
content: authState.creds.noiseKey.public
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
tag: 'companion_platform_id',
|
|
408
|
+
attrs: {},
|
|
409
|
+
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
tag: 'companion_platform_display',
|
|
413
|
+
attrs: {},
|
|
414
|
+
content: `${browser[1]} (${browser[0]})`
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
tag: 'link_code_pairing_nonce',
|
|
418
|
+
attrs: {},
|
|
419
|
+
content: '0'
|
|
420
|
+
}
|
|
421
|
+
]
|
|
422
|
+
}
|
|
423
|
+
]
|
|
424
|
+
});
|
|
425
|
+
return authState.creds.pairingCode;
|
|
426
|
+
};
|
|
427
|
+
const requestPairingCode2 = async (phoneNumber, pairCode) => {
|
|
371
428
|
if (pairCode) {
|
|
372
429
|
authState.creds.pairingCode = pairCode.substring(0, 8).toUpperCase();
|
|
373
430
|
}
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { USyncQuery } from '../WAUSync';
|
|
|
5
5
|
export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
6
6
|
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
7
7
|
type: "md";
|
|
8
|
-
ws:
|
|
8
|
+
ws: import("./Client").WebSocketClient;
|
|
9
9
|
ev: import("../Types").BaileysEventEmitter & {
|
|
10
10
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
11
11
|
buffer(): void;
|
|
@@ -191,16 +191,14 @@ exports.default = (config) => {
|
|
|
191
191
|
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
192
192
|
const list = assertMessageList(jid);
|
|
193
193
|
list.upsert(msg, 'append');
|
|
194
|
-
if (type === 'notify') {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
]);
|
|
203
|
-
}
|
|
194
|
+
if (type === 'notify' && !chats.get(jid)) {
|
|
195
|
+
ev.emit('chats.upsert', [
|
|
196
|
+
{
|
|
197
|
+
id: jid,
|
|
198
|
+
conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
|
|
199
|
+
unreadCount: 1
|
|
200
|
+
}
|
|
201
|
+
]);
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
break;
|
package/lib/Types/Auth.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { proto } from '../../WAProto';
|
|
2
|
-
import { RegistrationOptions } from '../Socket/registration';
|
|
3
2
|
import type { Contact } from './Contact';
|
|
4
3
|
import type { MinimalMessage } from './Message';
|
|
5
4
|
export type KeyPair = {
|
|
@@ -56,12 +55,7 @@ export type AuthenticationCreds = SignalCreds & {
|
|
|
56
55
|
/** number of times history & app state has been synced */
|
|
57
56
|
accountSyncCounter: number;
|
|
58
57
|
accountSettings: AccountSettings;
|
|
59
|
-
deviceId: string;
|
|
60
|
-
phoneId: string;
|
|
61
|
-
identityId: Buffer;
|
|
62
58
|
registered: boolean;
|
|
63
|
-
backupToken: Buffer;
|
|
64
|
-
registration: RegistrationOptions;
|
|
65
59
|
pairingCode: string | undefined;
|
|
66
60
|
lastPropHash: string | undefined;
|
|
67
61
|
routingInfo: Buffer | undefined;
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -24,11 +24,13 @@ export type WALocationMessage = proto.Message.ILocationMessage;
|
|
|
24
24
|
export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
|
|
25
25
|
export declare const WAMessageStubType: typeof proto.WebMessageInfo.StubType;
|
|
26
26
|
export declare const WAMessageStatus: typeof proto.WebMessageInfo.Status;
|
|
27
|
-
export type
|
|
27
|
+
export type WAMediaPayloadURL = {
|
|
28
28
|
url: URL | string;
|
|
29
|
-
}
|
|
29
|
+
};
|
|
30
|
+
export type WAMediaPayloadStream = {
|
|
30
31
|
stream: Readable;
|
|
31
32
|
};
|
|
33
|
+
export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL;
|
|
32
34
|
/** Set of message types that are supported by the library */
|
|
33
35
|
export type MessageType = keyof proto.Message;
|
|
34
36
|
export type DownloadableMessage = {
|
|
@@ -216,6 +218,14 @@ export type OrderInfo = {
|
|
|
216
218
|
export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
|
|
217
219
|
productImage: WAMediaUpload;
|
|
218
220
|
};
|
|
221
|
+
export type AlbumMedia = {
|
|
222
|
+
image: WAMediaUpload;
|
|
223
|
+
caption?: string;
|
|
224
|
+
} | {
|
|
225
|
+
video: WAMediaUpload;
|
|
226
|
+
caption?: string;
|
|
227
|
+
gifPlayback?: boolean;
|
|
228
|
+
};
|
|
219
229
|
export type AnyRegularMessageContent = (({
|
|
220
230
|
text: string;
|
|
221
231
|
linkPreview?: WAUrlInfo | null;
|
|
@@ -270,7 +280,10 @@ export type AnyRegularMessageContent = (({
|
|
|
270
280
|
businessOwnerJid?: string;
|
|
271
281
|
body?: string;
|
|
272
282
|
footer?: string;
|
|
273
|
-
} & Mentionable & Contextable & Interactiveable & Shopable & Cardsable & WithDimensions) | SharePhoneNumber | RequestPhoneNumber
|
|
283
|
+
} & Mentionable & Contextable & Interactiveable & Shopable & Cardsable & WithDimensions) | SharePhoneNumber | RequestPhoneNumber | ({
|
|
284
|
+
album: AlbumMedia[];
|
|
285
|
+
caption?: string;
|
|
286
|
+
} & Mentionable & Contextable & Editable)) & ViewOnce;
|
|
274
287
|
export type AnyMessageContent = AnyRegularMessageContent | {
|
|
275
288
|
forward: WAMessage;
|
|
276
289
|
force?: boolean;
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -31,7 +31,9 @@ export type SocketConfig = {
|
|
|
31
31
|
defaultQueryTimeoutMs: number | undefined;
|
|
32
32
|
/** ping-pong interval for WS connection */
|
|
33
33
|
keepAliveIntervalMs: number;
|
|
34
|
-
/** should baileys use the mobile api instead of the multi device api
|
|
34
|
+
/** should baileys use the mobile api instead of the multi device api
|
|
35
|
+
* @deprecated This feature has been removed
|
|
36
|
+
*/
|
|
35
37
|
mobile?: boolean;
|
|
36
38
|
/** proxy agent */
|
|
37
39
|
agent?: Agent;
|
|
@@ -114,6 +116,4 @@ export type SocketConfig = {
|
|
|
114
116
|
/** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
|
|
115
117
|
cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
|
|
116
118
|
makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
|
|
117
|
-
/** Socket passthrough */
|
|
118
|
-
socket?: any;
|
|
119
119
|
};
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
|
7
7
|
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
8
8
|
const crypto_1 = require("crypto");
|
|
9
9
|
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
10
|
const Defaults_1 = require("../Defaults");
|
|
12
11
|
const crypto_2 = require("./crypto");
|
|
13
12
|
const generics_1 = require("./generics");
|
|
@@ -191,13 +190,7 @@ const initAuthCreds = () => {
|
|
|
191
190
|
accountSettings: {
|
|
192
191
|
unarchiveChats: false
|
|
193
192
|
},
|
|
194
|
-
// mobile creds
|
|
195
|
-
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
196
|
-
phoneId: (0, uuid_1.v4)(),
|
|
197
|
-
identityId: (0, crypto_1.randomBytes)(20),
|
|
198
193
|
registered: false,
|
|
199
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
-
registration: {},
|
|
201
194
|
pairingCode: undefined,
|
|
202
195
|
lastPropHash: undefined,
|
|
203
196
|
routingInfo: undefined,
|
|
@@ -502,12 +502,10 @@ function consolidateEvents(data) {
|
|
|
502
502
|
return map;
|
|
503
503
|
}
|
|
504
504
|
function concatChats(a, b) {
|
|
505
|
-
if (b.unreadCount === null
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
b.unreadCount = undefined;
|
|
510
|
-
}
|
|
505
|
+
if (b.unreadCount === null && // neutralize unread counter
|
|
506
|
+
a.unreadCount < 0) {
|
|
507
|
+
a.unreadCount = undefined;
|
|
508
|
+
b.unreadCount = undefined;
|
|
511
509
|
}
|
|
512
510
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
513
511
|
b = { ...b };
|
package/lib/Utils/index.d.ts
CHANGED
package/lib/Utils/index.js
CHANGED
|
@@ -31,3 +31,4 @@ __exportStar(require("./use-multi-file-auth-state"), exports);
|
|
|
31
31
|
__exportStar(require("./link-preview"), exports);
|
|
32
32
|
__exportStar(require("./event-buffer"), exports);
|
|
33
33
|
__exportStar(require("./process-message"), exports);
|
|
34
|
+
__exportStar(require("./midea-msg"), exports);
|
|
@@ -337,20 +337,17 @@ exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
|
337
337
|
async function getAudioDuration(buffer) {
|
|
338
338
|
const musicMetadata = await Promise.resolve().then(() => __importStar(require('music-metadata')));
|
|
339
339
|
let metadata;
|
|
340
|
+
const options = {
|
|
341
|
+
duration: true
|
|
342
|
+
};
|
|
340
343
|
if (Buffer.isBuffer(buffer)) {
|
|
341
|
-
metadata = await musicMetadata.parseBuffer(buffer, undefined,
|
|
344
|
+
metadata = await musicMetadata.parseBuffer(buffer, undefined, options);
|
|
342
345
|
}
|
|
343
346
|
else if (typeof buffer === 'string') {
|
|
344
|
-
|
|
345
|
-
try {
|
|
346
|
-
metadata = await musicMetadata.parseStream(rStream, undefined, { duration: true });
|
|
347
|
-
}
|
|
348
|
-
finally {
|
|
349
|
-
rStream.destroy();
|
|
350
|
-
}
|
|
347
|
+
metadata = await musicMetadata.parseFile(buffer, options);
|
|
351
348
|
}
|
|
352
349
|
else {
|
|
353
|
-
metadata = await musicMetadata.parseStream(buffer, undefined,
|
|
350
|
+
metadata = await musicMetadata.parseStream(buffer, undefined, options);
|
|
354
351
|
}
|
|
355
352
|
return metadata.format.duration;
|
|
356
353
|
}
|
|
@@ -607,7 +604,11 @@ const toSmallestChunkSize = (num) => {
|
|
|
607
604
|
const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
|
|
608
605
|
exports.getUrlFromDirectPath = getUrlFromDirectPath;
|
|
609
606
|
const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
|
|
610
|
-
const
|
|
607
|
+
const isValidMediaUrl = url === null || url === void 0 ? void 0 : url.startsWith('https://mmg.whatsapp.net/');
|
|
608
|
+
const downloadUrl = isValidMediaUrl ? url : (0, exports.getUrlFromDirectPath)(directPath);
|
|
609
|
+
if (!downloadUrl) {
|
|
610
|
+
throw new boom_1.Boom('No valid media URL or directPath present in message', { statusCode: 400 });
|
|
611
|
+
}
|
|
611
612
|
const keys = await getMediaKeys(mediaKey, type);
|
|
612
613
|
return (0, exports.downloadEncryptedContent)(downloadUrl, keys, opts);
|
|
613
614
|
};
|
package/lib/Utils/messages.js
CHANGED
|
@@ -434,12 +434,12 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
434
434
|
m.pollCreationMessageV2 = pollCreationMessage;
|
|
435
435
|
}
|
|
436
436
|
else {
|
|
437
|
-
if (message.poll.selectableCount
|
|
437
|
+
if (message.poll.selectableCount === 1) {
|
|
438
438
|
// poll v3 is for single select polls
|
|
439
439
|
m.pollCreationMessageV3 = pollCreationMessage;
|
|
440
440
|
}
|
|
441
441
|
else {
|
|
442
|
-
// poll
|
|
442
|
+
// poll for multiple choice polls
|
|
443
443
|
m.pollCreationMessage = pollCreationMessage;
|
|
444
444
|
}
|
|
445
445
|
}
|
|
@@ -499,6 +499,14 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
499
499
|
else if ('requestPhoneNumber' in message) {
|
|
500
500
|
m.requestPhoneNumberMessage = {};
|
|
501
501
|
}
|
|
502
|
+
else if ('album' in message) {
|
|
503
|
+
const imageMessages = message.album.filter(item => 'image' in item);
|
|
504
|
+
const videoMessages = message.album.filter(item => 'video' in item);
|
|
505
|
+
m.albumMessage = WAProto_1.proto.Message.AlbumMessage.fromObject({
|
|
506
|
+
expectedImageCount: imageMessages.length,
|
|
507
|
+
expectedVideoCount: videoMessages.length,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
502
510
|
else {
|
|
503
511
|
m = await (0, exports.prepareWAMessageMedia)(message, options);
|
|
504
512
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const generateProfilePictureFull: (img: any) => Promise<{
|
|
2
|
+
img: Buffer<ArrayBufferLike>;
|
|
3
|
+
}>;
|
|
4
|
+
export declare const generateProfilePictureFP: (buffer: any) => Promise<{
|
|
5
|
+
img: Buffer<ArrayBufferLike>;
|
|
6
|
+
preview: Buffer<ArrayBufferLike>;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const generatePP: (buffer: any) => Promise<{
|
|
9
|
+
img: Buffer<ArrayBufferLike>;
|
|
10
|
+
preview: Buffer<ArrayBufferLike>;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const changeprofileFull: (img: any) => Promise<{
|
|
13
|
+
img: any;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.changeprofileFull = exports.generatePP = exports.generateProfilePictureFP = exports.generateProfilePictureFull = void 0;
|
|
7
|
+
const jimp_1 = __importDefault(require("jimp"));
|
|
8
|
+
const jimp_2 = require("jimp");
|
|
9
|
+
const generateProfilePictureFull = async (img) => {
|
|
10
|
+
const jimp = await (0, jimp_2.read)(img);
|
|
11
|
+
const min = Math.min(jimp.getWidth(), jimp.getHeight());
|
|
12
|
+
const cropped = jimp.crop(0, 0, jimp.getWidth(), jimp.getHeight());
|
|
13
|
+
let width = jimp.getWidth(), hight = jimp.getHeight(), ratio;
|
|
14
|
+
if (width > hight) {
|
|
15
|
+
ratio = jimp.getWidth() / 720;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
ratio = jimp.getWidth() / 324;
|
|
19
|
+
}
|
|
20
|
+
;
|
|
21
|
+
width = width / ratio;
|
|
22
|
+
hight = hight / ratio;
|
|
23
|
+
img = cropped.quality(100).resize(width, hight).getBufferAsync(jimp_2.MIME_JPEG);
|
|
24
|
+
return {
|
|
25
|
+
img: await cropped.quality(100).resize(width, hight).getBufferAsync(jimp_2.MIME_JPEG),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.generateProfilePictureFull = generateProfilePictureFull;
|
|
29
|
+
const generateProfilePictureFP = async (buffer) => {
|
|
30
|
+
const jimp = await jimp_1.default.read(buffer);
|
|
31
|
+
const min = jimp.getWidth();
|
|
32
|
+
const max = jimp.getHeight();
|
|
33
|
+
const cropped = jimp.crop(0, 0, min, max);
|
|
34
|
+
return {
|
|
35
|
+
img: await cropped.scaleToFit(720, 720).getBufferAsync(jimp_1.default.MIME_JPEG),
|
|
36
|
+
preview: await cropped.normalize().getBufferAsync(jimp_1.default.MIME_JPEG),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.generateProfilePictureFP = generateProfilePictureFP;
|
|
40
|
+
const generatePP = async (buffer) => {
|
|
41
|
+
const jimp = await jimp_1.default.read(buffer);
|
|
42
|
+
const min = jimp.getWidth();
|
|
43
|
+
const max = jimp.getHeight();
|
|
44
|
+
const cropped = jimp.crop(0, 0, min, max);
|
|
45
|
+
return {
|
|
46
|
+
img: await cropped.scaleToFit(720, 720).getBufferAsync(jimp_1.default.MIME_JPEG),
|
|
47
|
+
preview: await cropped.normalize().getBufferAsync(jimp_1.default.MIME_JPEG),
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
exports.generatePP = generatePP;
|
|
51
|
+
const changeprofileFull = async (img) => {
|
|
52
|
+
const Jimp = require('jimp');
|
|
53
|
+
const { read, MIME_JPEG, RESIZE_BILINEAR } = require('jimp');
|
|
54
|
+
const jimp = await read(img);
|
|
55
|
+
const min = Math.min(jimp.getWidth(), jimp.getHeight());
|
|
56
|
+
const cropped = jimp.crop(0, 0, jimp.getWidth(), jimp.getHeight());
|
|
57
|
+
let width = jimp.getWidth(), hight = jimp.getHeight(), ratio;
|
|
58
|
+
if (width > hight) {
|
|
59
|
+
ratio = jimp.getWidth() / 720;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
ratio = jimp.getWidth() / 324;
|
|
63
|
+
}
|
|
64
|
+
;
|
|
65
|
+
width = width / ratio;
|
|
66
|
+
hight = hight / ratio;
|
|
67
|
+
img = cropped.quality(100).resize(width, hight).getBufferAsync(MIME_JPEG);
|
|
68
|
+
return {
|
|
69
|
+
img: await cropped.quality(100).resize(width, hight).getBufferAsync(MIME_JPEG),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
exports.changeprofileFull = changeprofileFull;
|
|
@@ -2,10 +2,9 @@ import { ILogger } from './logger';
|
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
3
|
import { KeyPair } from '../Types';
|
|
4
4
|
import { BinaryNode } from '../WABinary';
|
|
5
|
-
export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER,
|
|
5
|
+
export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
|
|
6
6
|
keyPair: KeyPair;
|
|
7
7
|
NOISE_HEADER: Uint8Array;
|
|
8
|
-
mobile: boolean;
|
|
9
8
|
logger: ILogger;
|
|
10
9
|
routingInfo?: Buffer | undefined;
|
|
11
10
|
}) => {
|
|
@@ -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,
|
|
14
|
+
const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
|
|
15
15
|
logger = logger.child({ class: 'ns' });
|
|
16
16
|
const authenticate = (data) => {
|
|
17
17
|
if (!isFinished) {
|
|
@@ -83,15 +83,10 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
83
83
|
const decStaticContent = decrypt(serverHello.static);
|
|
84
84
|
await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
|
|
85
85
|
const certDecoded = decrypt(serverHello.payload);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
}
|
|
86
|
+
const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded);
|
|
87
|
+
const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
|
|
88
|
+
if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
|
|
89
|
+
throw new boom_1.Boom('certification match failed', { statusCode: 400 });
|
|
95
90
|
}
|
|
96
91
|
const keyEnc = encrypt(noiseKey.public);
|
|
97
92
|
await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
|