@queenanya/baileys 8.3.1 → 8.3.2
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 +5 -3
- package/lib/Socket/chats.d.ts +3 -1
- package/lib/Socket/chats.js +11 -8
- package/lib/Socket/groups.d.ts +3 -1
- package/lib/Socket/index.d.ts +5 -5
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +5 -3
- package/lib/Socket/messages-recv.js +16 -8
- package/lib/Socket/messages-send.d.ts +4 -2
- package/lib/Socket/messages-send.js +75 -9
- package/lib/Socket/newsletter.d.ts +3 -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/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
|
@@ -77,6 +77,8 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
77
77
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
78
78
|
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
|
|
79
79
|
updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
|
80
|
+
updateProfilePictureFull: any;
|
|
81
|
+
updateProfilePictureFull2: any;
|
|
80
82
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
81
83
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
82
84
|
updateProfileName: (name: string) => Promise<void>;
|
|
@@ -104,7 +106,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
|
104
106
|
}[], star: boolean) => Promise<void>;
|
|
105
107
|
executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
|
|
106
108
|
type: "md";
|
|
107
|
-
ws:
|
|
109
|
+
ws: import("./Client").WebSocketClient;
|
|
108
110
|
ev: import("../Types").BaileysEventEmitter & {
|
|
109
111
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
110
112
|
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
|
}
|
|
@@ -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));
|
|
@@ -0,0 +1,66 @@
|
|
|
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.useSingleFileAuthState = void 0;
|
|
7
|
+
const async_lock_1 = __importDefault(require("async-lock"));
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
9
|
+
const index_1 = require("../../WAProto/index");
|
|
10
|
+
const auth_utils_1 = require("./auth-utils");
|
|
11
|
+
const generics_1 = require("./generics");
|
|
12
|
+
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
13
|
+
const useSingleFileAuthState = async (filepath) => {
|
|
14
|
+
const filePath = filepath + '.json';
|
|
15
|
+
const writeData = (data) => {
|
|
16
|
+
return fileLock.acquire(filePath, () => (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer)));
|
|
17
|
+
};
|
|
18
|
+
const readData = async () => {
|
|
19
|
+
try {
|
|
20
|
+
const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
|
|
21
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const fileInfo = await (0, promises_1.stat)(filePath).catch(() => null);
|
|
28
|
+
if (fileInfo && !fileInfo.isFile()) {
|
|
29
|
+
throw new Error(`A non-file exists at ${filePath}, please delete it or specify a different path.`);
|
|
30
|
+
}
|
|
31
|
+
// Initialize with default credentials if the file is empty or doesn't exist
|
|
32
|
+
const { creds = (0, auth_utils_1.initAuthCreds)(), keys = {} } = await readData() || {};
|
|
33
|
+
return {
|
|
34
|
+
state: {
|
|
35
|
+
creds,
|
|
36
|
+
keys: {
|
|
37
|
+
get: async (type, ids) => {
|
|
38
|
+
const data = {};
|
|
39
|
+
for (const id of ids) {
|
|
40
|
+
const value = keys[`${type}-${id}`];
|
|
41
|
+
data[id] = type === 'app-state-sync-key' && value
|
|
42
|
+
? index_1.proto.Message.AppStateSyncKeyData.fromObject(value)
|
|
43
|
+
: value;
|
|
44
|
+
}
|
|
45
|
+
return data;
|
|
46
|
+
},
|
|
47
|
+
set: async (data) => {
|
|
48
|
+
for (const category in data) {
|
|
49
|
+
for (const id in data[category]) {
|
|
50
|
+
const value = data[category][id];
|
|
51
|
+
if (value) {
|
|
52
|
+
keys[`${category}-${id}`] = value;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
delete keys[`${category}-${id}`];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
await writeData({ creds, keys });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
saveCreds: () => writeData({ creds, keys })
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.useSingleFileAuthState = useSingleFileAuthState;
|
|
@@ -1,7 +1,6 @@
|
|
|
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;
|
|
5
4
|
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
6
5
|
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
7
6
|
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, "advSecretKey" | "signedIdentityKey" | "signalIdentities">) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode =
|
|
3
|
+
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const WAProto_1 = require("../../WAProto");
|
|
@@ -10,30 +10,19 @@ const crypto_2 = require("./crypto");
|
|
|
10
10
|
const generics_1 = require("./generics");
|
|
11
11
|
const signal_1 = require("./signal");
|
|
12
12
|
const getUserAgent = (config) => {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const osVersion = config.mobile ? '15.3.1' : '0.1';
|
|
15
|
-
const version = config.mobile ? [2, 24, 6] : config.version;
|
|
16
|
-
const device = config.mobile ? 'iPhone_7' : 'Desktop';
|
|
17
|
-
const manufacturer = config.mobile ? 'Apple' : '';
|
|
18
|
-
const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
|
|
19
|
-
const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
|
|
20
13
|
return {
|
|
21
14
|
appVersion: {
|
|
22
|
-
primary: version[0],
|
|
23
|
-
secondary: version[1],
|
|
24
|
-
tertiary: version[2],
|
|
15
|
+
primary: config.version[0],
|
|
16
|
+
secondary: config.version[1],
|
|
17
|
+
tertiary: config.version[2],
|
|
25
18
|
},
|
|
26
|
-
platform,
|
|
19
|
+
platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
27
20
|
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
manufacturer,
|
|
32
|
-
device,
|
|
33
|
-
osBuildNumber: osVersion,
|
|
21
|
+
osVersion: '0.1',
|
|
22
|
+
device: 'Desktop',
|
|
23
|
+
osBuildNumber: '0.1',
|
|
34
24
|
localeLanguageIso6391: 'en',
|
|
35
|
-
localeCountryIso31661Alpha2:
|
|
36
|
-
...phoneId
|
|
25
|
+
localeCountryIso31661Alpha2: 'US'
|
|
37
26
|
};
|
|
38
27
|
};
|
|
39
28
|
const PLATFORM_MAP = {
|
|
@@ -53,32 +42,9 @@ const getClientPayload = (config) => {
|
|
|
53
42
|
connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
54
43
|
userAgent: getUserAgent(config),
|
|
55
44
|
};
|
|
56
|
-
|
|
57
|
-
payload.webInfo = getWebInfo(config);
|
|
58
|
-
}
|
|
45
|
+
payload.webInfo = getWebInfo(config);
|
|
59
46
|
return payload;
|
|
60
47
|
};
|
|
61
|
-
const generateMobileNode = (config) => {
|
|
62
|
-
if (!config.auth.creds) {
|
|
63
|
-
throw new boom_1.Boom('No registration data found', { data: config });
|
|
64
|
-
}
|
|
65
|
-
const payload = {
|
|
66
|
-
...getClientPayload(config),
|
|
67
|
-
sessionId: Math.floor(Math.random() * 999999999 + 1),
|
|
68
|
-
shortConnect: true,
|
|
69
|
-
connectAttemptCount: 0,
|
|
70
|
-
device: 0,
|
|
71
|
-
dnsSource: {
|
|
72
|
-
appCached: false,
|
|
73
|
-
dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
|
|
74
|
-
},
|
|
75
|
-
passive: false, // XMPP heartbeat setting (false: server actively pings) (true: client actively pings)
|
|
76
|
-
pushName: 'test',
|
|
77
|
-
username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
|
|
78
|
-
};
|
|
79
|
-
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
80
|
-
};
|
|
81
|
-
exports.generateMobileNode = generateMobileNode;
|
|
82
48
|
const generateLoginNode = (userJid, config) => {
|
|
83
49
|
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
84
50
|
const payload = {
|
|
@@ -10,7 +10,7 @@ export type JidWithDevice = {
|
|
|
10
10
|
device?: number;
|
|
11
11
|
};
|
|
12
12
|
export type FullJid = JidWithDevice & {
|
|
13
|
-
server: JidServer
|
|
13
|
+
server: JidServer;
|
|
14
14
|
domainType?: number;
|
|
15
15
|
};
|
|
16
16
|
export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@queenanya/baileys",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.2",
|
|
4
4
|
"description": "Custom Baileys WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"audio-decode": "^2.1.3",
|
|
39
39
|
"axios": "^1.7.3",
|
|
40
40
|
"cache-manager": "^5.7.6",
|
|
41
|
+
"cheerio": "^1.0.0 || ^1.0.0_rc.12 || ^1.0.0-rc.10",
|
|
41
42
|
"libphonenumber-js": "^1.10.20",
|
|
42
43
|
"libsignal": "github:nstar-y/libsignal",
|
|
43
44
|
"lodash": "^4.17.21",
|