@queenanya/baileys 7.4.7 → 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 +22 -29
- package/lib/Socket/chats.d.ts +3 -14
- package/lib/Socket/chats.js +48 -76
- package/lib/Socket/groups.d.ts +4 -21
- package/lib/Socket/groups.js +1 -12
- package/lib/Socket/index.d.ts +32 -37
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +22 -28
- package/lib/Socket/messages-recv.js +180 -291
- package/lib/Socket/messages-send.d.ts +13 -23
- package/lib/Socket/messages-send.js +76 -110
- package/lib/Socket/newsletter.d.ts +7 -17
- package/lib/Socket/newsletter.js +54 -67
- package/lib/Socket/registration.d.ts +267 -0
- 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 -12
- package/lib/Types/Contact.d.ts +1 -1
- 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 -41
- 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 -102
- 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/package.json +37 -39
- /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
|
@@ -0,0 +1,166 @@
|
|
|
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.mobileRegisterFetch = exports.mobileRegisterEncrypt = exports.mobileRegister = exports.mobileRegisterExists = exports.mobileRegisterCode = exports.registrationParams = exports.makeRegistrationSocket = void 0;
|
|
7
|
+
/* eslint-disable camelcase */
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const Defaults_1 = require("../Defaults");
|
|
10
|
+
const crypto_1 = require("../Utils/crypto");
|
|
11
|
+
const WABinary_1 = require("../WABinary");
|
|
12
|
+
const business_1 = require("./business");
|
|
13
|
+
function urlencode(str) {
|
|
14
|
+
return str.replace(/-/g, '%2d').replace(/_/g, '%5f').replace(/~/g, '%7e');
|
|
15
|
+
}
|
|
16
|
+
const validRegistrationOptions = (config) => (config === null || config === void 0 ? void 0 : config.phoneNumberCountryCode) &&
|
|
17
|
+
config.phoneNumberNationalNumber &&
|
|
18
|
+
config.phoneNumberMobileCountryCode;
|
|
19
|
+
const makeRegistrationSocket = (config) => {
|
|
20
|
+
const sock = (0, business_1.makeBusinessSocket)(config);
|
|
21
|
+
const register = async (code) => {
|
|
22
|
+
if (!validRegistrationOptions(config.auth.creds.registration)) {
|
|
23
|
+
throw new Error('please specify the registration options');
|
|
24
|
+
}
|
|
25
|
+
const result = await mobileRegister({ ...sock.authState.creds, ...sock.authState.creds.registration, code }, config.options);
|
|
26
|
+
sock.authState.creds.me = {
|
|
27
|
+
id: (0, WABinary_1.jidEncode)(result.login, 's.whatsapp.net'),
|
|
28
|
+
name: '~'
|
|
29
|
+
};
|
|
30
|
+
sock.authState.creds.registered = true;
|
|
31
|
+
sock.ev.emit('creds.update', sock.authState.creds);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
const requestRegistrationCode = async (registrationOptions) => {
|
|
35
|
+
registrationOptions = registrationOptions || config.auth.creds.registration;
|
|
36
|
+
if (!validRegistrationOptions(registrationOptions)) {
|
|
37
|
+
throw new Error('Invalid registration options');
|
|
38
|
+
}
|
|
39
|
+
sock.authState.creds.registration = registrationOptions;
|
|
40
|
+
sock.ev.emit('creds.update', sock.authState.creds);
|
|
41
|
+
return mobileRegisterCode({ ...config.auth.creds, ...registrationOptions }, config.options);
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
...sock,
|
|
45
|
+
register,
|
|
46
|
+
requestRegistrationCode,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.makeRegistrationSocket = makeRegistrationSocket;
|
|
50
|
+
function convertBufferToUrlHex(buffer) {
|
|
51
|
+
var id = '';
|
|
52
|
+
buffer.forEach((x) => {
|
|
53
|
+
// encode random identity_id buffer as percentage url encoding
|
|
54
|
+
id += `%${x.toString(16).padStart(2, '0').toLowerCase()}`;
|
|
55
|
+
});
|
|
56
|
+
return id;
|
|
57
|
+
}
|
|
58
|
+
function registrationParams(params) {
|
|
59
|
+
const e_regid = Buffer.alloc(4);
|
|
60
|
+
e_regid.writeInt32BE(params.registrationId);
|
|
61
|
+
const e_skey_id = Buffer.alloc(3);
|
|
62
|
+
e_skey_id.writeInt16BE(params.signedPreKey.keyId);
|
|
63
|
+
params.phoneNumberCountryCode = params.phoneNumberCountryCode.replace('+', '').trim();
|
|
64
|
+
params.phoneNumberNationalNumber = params.phoneNumberNationalNumber.replace(/[/-\s)(]/g, '').trim();
|
|
65
|
+
return {
|
|
66
|
+
cc: params.phoneNumberCountryCode,
|
|
67
|
+
in: params.phoneNumberNationalNumber,
|
|
68
|
+
Rc: '0',
|
|
69
|
+
lg: 'en',
|
|
70
|
+
lc: 'GB',
|
|
71
|
+
mistyped: '6',
|
|
72
|
+
authkey: Buffer.from(params.noiseKey.public).toString('base64url'),
|
|
73
|
+
e_regid: e_regid.toString('base64url'),
|
|
74
|
+
e_keytype: 'BQ',
|
|
75
|
+
e_ident: Buffer.from(params.signedIdentityKey.public).toString('base64url'),
|
|
76
|
+
// e_skey_id: e_skey_id.toString('base64url'),
|
|
77
|
+
e_skey_id: 'AAAA',
|
|
78
|
+
e_skey_val: Buffer.from(params.signedPreKey.keyPair.public).toString('base64url'),
|
|
79
|
+
e_skey_sig: Buffer.from(params.signedPreKey.signature).toString('base64url'),
|
|
80
|
+
fdid: params.phoneId,
|
|
81
|
+
network_ratio_type: '1',
|
|
82
|
+
expid: params.deviceId,
|
|
83
|
+
simnum: '1',
|
|
84
|
+
hasinrc: '1',
|
|
85
|
+
pid: Math.floor(Math.random() * 1000).toString(),
|
|
86
|
+
id: convertBufferToUrlHex(params.identityId),
|
|
87
|
+
backup_token: convertBufferToUrlHex(params.backupToken),
|
|
88
|
+
token: (0, crypto_1.md5)(Buffer.concat([Defaults_1.MOBILE_TOKEN, Buffer.from(params.phoneNumberNationalNumber)])).toString('hex'),
|
|
89
|
+
fraud_checkpoint_code: params.captcha,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
exports.registrationParams = registrationParams;
|
|
93
|
+
/**
|
|
94
|
+
* Requests a registration code for the given phone number.
|
|
95
|
+
*/
|
|
96
|
+
function mobileRegisterCode(params, fetchOptions) {
|
|
97
|
+
return mobileRegisterFetch('/code', {
|
|
98
|
+
params: {
|
|
99
|
+
...registrationParams(params),
|
|
100
|
+
mcc: `${params.phoneNumberMobileCountryCode}`.padStart(3, '0'),
|
|
101
|
+
mnc: `${params.phoneNumberMobileNetworkCode || '001'}`.padStart(3, '0'),
|
|
102
|
+
sim_mcc: '000',
|
|
103
|
+
sim_mnc: '000',
|
|
104
|
+
method: (params === null || params === void 0 ? void 0 : params.method) || 'sms',
|
|
105
|
+
reason: '',
|
|
106
|
+
hasav: '1'
|
|
107
|
+
},
|
|
108
|
+
...fetchOptions,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
exports.mobileRegisterCode = mobileRegisterCode;
|
|
112
|
+
function mobileRegisterExists(params, fetchOptions) {
|
|
113
|
+
return mobileRegisterFetch('/exist', {
|
|
114
|
+
params: registrationParams(params),
|
|
115
|
+
...fetchOptions
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.mobileRegisterExists = mobileRegisterExists;
|
|
119
|
+
/**
|
|
120
|
+
* Registers the phone number on whatsapp with the received OTP code.
|
|
121
|
+
*/
|
|
122
|
+
async function mobileRegister(params, fetchOptions) {
|
|
123
|
+
//const result = await mobileRegisterFetch(`/reg_onboard_abprop?cc=${params.phoneNumberCountryCode}&in=${params.phoneNumberNationalNumber}&rc=0`)
|
|
124
|
+
return mobileRegisterFetch('/register', {
|
|
125
|
+
params: { ...registrationParams(params), code: params.code.replace('-', '') },
|
|
126
|
+
...fetchOptions,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
exports.mobileRegister = mobileRegister;
|
|
130
|
+
/**
|
|
131
|
+
* Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
|
|
132
|
+
*/
|
|
133
|
+
function mobileRegisterEncrypt(data) {
|
|
134
|
+
const keypair = crypto_1.Curve.generateKeyPair();
|
|
135
|
+
const key = crypto_1.Curve.sharedKey(keypair.private, Defaults_1.REGISTRATION_PUBLIC_KEY);
|
|
136
|
+
const buffer = (0, crypto_1.aesEncryptGCM)(Buffer.from(data), new Uint8Array(key), Buffer.alloc(12), Buffer.alloc(0));
|
|
137
|
+
return Buffer.concat([Buffer.from(keypair.public), buffer]).toString('base64url');
|
|
138
|
+
}
|
|
139
|
+
exports.mobileRegisterEncrypt = mobileRegisterEncrypt;
|
|
140
|
+
async function mobileRegisterFetch(path, opts = {}) {
|
|
141
|
+
let url = `${Defaults_1.MOBILE_REGISTRATION_ENDPOINT}${path}`;
|
|
142
|
+
if (opts.params) {
|
|
143
|
+
const parameter = [];
|
|
144
|
+
for (const param in opts.params) {
|
|
145
|
+
if (opts.params[param] !== null && opts.params[param] !== undefined) {
|
|
146
|
+
parameter.push(param + '=' + urlencode(opts.params[param]));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
url += `?${parameter.join('&')}`;
|
|
150
|
+
delete opts.params;
|
|
151
|
+
}
|
|
152
|
+
if (!opts.headers) {
|
|
153
|
+
opts.headers = {};
|
|
154
|
+
}
|
|
155
|
+
opts.headers['User-Agent'] = Defaults_1.MOBILE_USERAGENT;
|
|
156
|
+
const response = await (0, axios_1.default)(url, opts);
|
|
157
|
+
var json = response.data;
|
|
158
|
+
if (response.status > 300 || json.reason) {
|
|
159
|
+
throw json;
|
|
160
|
+
}
|
|
161
|
+
if (json.status && !['ok', 'sent'].includes(json.status)) {
|
|
162
|
+
throw json;
|
|
163
|
+
}
|
|
164
|
+
return json;
|
|
165
|
+
}
|
|
166
|
+
exports.mobileRegisterFetch = mobileRegisterFetch;
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { Boom } from '@hapi/boom';
|
|
4
3
|
import { SocketConfig } from '../Types';
|
|
5
4
|
import { BinaryNode } from '../WABinary';
|
|
6
|
-
import { WebSocketClient } from './Client';
|
|
7
5
|
/**
|
|
8
6
|
* Connects to WA servers and performs:
|
|
9
7
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
@@ -12,7 +10,7 @@ import { WebSocketClient } from './Client';
|
|
|
12
10
|
*/
|
|
13
11
|
export declare const makeSocket: (config: SocketConfig) => {
|
|
14
12
|
type: "md";
|
|
15
|
-
ws:
|
|
13
|
+
ws: any;
|
|
16
14
|
ev: import("../Types").BaileysEventEmitter & {
|
|
17
15
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
18
16
|
buffer(): void;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -20,14 +20,15 @@ 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
|
-
|
|
23
|
+
let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
|
+
config.mobile = config.mobile || url.protocol === 'tcp:';
|
|
25
|
+
if (config.mobile && url.protocol !== 'tcp:') {
|
|
26
|
+
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
26
27
|
}
|
|
27
|
-
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
28
|
+
if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
28
29
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
29
30
|
}
|
|
30
|
-
const ws = new Client_1.WebSocketClient(url, config);
|
|
31
|
+
const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
31
32
|
ws.connect();
|
|
32
33
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
33
34
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -35,7 +36,8 @@ const makeSocket = (config) => {
|
|
|
35
36
|
/** WA noise protocol wrapper */
|
|
36
37
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
37
38
|
keyPair: ephemeralKeyPair,
|
|
38
|
-
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
39
|
+
NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
|
|
40
|
+
mobile: config.mobile,
|
|
39
41
|
logger,
|
|
40
42
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
41
43
|
});
|
|
@@ -72,8 +74,7 @@ const makeSocket = (config) => {
|
|
|
72
74
|
if (logger.level === 'trace') {
|
|
73
75
|
logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
|
|
74
76
|
}
|
|
75
|
-
const
|
|
76
|
-
const buff = Buffer.from(node);
|
|
77
|
+
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
77
78
|
return sendRawMessage(buff);
|
|
78
79
|
};
|
|
79
80
|
/** log & process any unexpected errors */
|
|
@@ -158,7 +159,10 @@ const makeSocket = (config) => {
|
|
|
158
159
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
159
160
|
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
160
161
|
let node;
|
|
161
|
-
if (
|
|
162
|
+
if (config.mobile) {
|
|
163
|
+
node = (0, Utils_1.generateMobileNode)(config);
|
|
164
|
+
}
|
|
165
|
+
else if (!creds.me) {
|
|
162
166
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
163
167
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
164
168
|
}
|
|
@@ -228,11 +232,11 @@ const makeSocket = (config) => {
|
|
|
228
232
|
const l0 = frame.tag;
|
|
229
233
|
const l1 = frame.attrs || {};
|
|
230
234
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
231
|
-
|
|
235
|
+
Object.keys(l1).forEach(key => {
|
|
232
236
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
233
237
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
234
238
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
235
|
-
}
|
|
239
|
+
});
|
|
236
240
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
237
241
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
238
242
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -362,7 +366,6 @@ const makeSocket = (config) => {
|
|
|
362
366
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
363
367
|
};
|
|
364
368
|
const requestPairingCode = async (phoneNumber) => {
|
|
365
|
-
await waitForSocketOpen();
|
|
366
369
|
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
367
370
|
authState.creds.me = {
|
|
368
371
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
@@ -400,7 +403,7 @@ const makeSocket = (config) => {
|
|
|
400
403
|
{
|
|
401
404
|
tag: 'companion_platform_id',
|
|
402
405
|
attrs: {},
|
|
403
|
-
content:
|
|
406
|
+
content: '49' // Chrome
|
|
404
407
|
},
|
|
405
408
|
{
|
|
406
409
|
tag: 'companion_platform_display',
|
|
@@ -421,7 +424,7 @@ const makeSocket = (config) => {
|
|
|
421
424
|
async function generatePairingKey() {
|
|
422
425
|
const salt = (0, crypto_1.randomBytes)(32);
|
|
423
426
|
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
424
|
-
const key =
|
|
427
|
+
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
425
428
|
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
426
429
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
427
430
|
}
|
|
@@ -533,7 +536,6 @@ const makeSocket = (config) => {
|
|
|
533
536
|
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
534
537
|
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
535
538
|
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
536
|
-
ev.emit('creds.update', authState.creds);
|
|
537
539
|
}
|
|
538
540
|
});
|
|
539
541
|
let didStartBuffer = false;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Store } from 'cache-manager';
|
|
2
1
|
import { AuthenticationCreds } from '../Types';
|
|
3
|
-
declare const makeCacheManagerAuthState: (store:
|
|
2
|
+
declare const makeCacheManagerAuthState: (store: Storage, sessionKey: string) => Promise<{
|
|
4
3
|
clearState: () => Promise<void>;
|
|
5
4
|
saveCreds: () => Promise<void>;
|
|
6
5
|
state: {
|
|
@@ -66,11 +66,7 @@ exports.default = (config) => {
|
|
|
66
66
|
ev.on('connection.update', update => {
|
|
67
67
|
Object.assign(state, update);
|
|
68
68
|
});
|
|
69
|
-
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest
|
|
70
|
-
if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
71
|
-
return; // FOR NOW,
|
|
72
|
-
//TODO: HANDLE
|
|
73
|
-
}
|
|
69
|
+
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
|
|
74
70
|
if (isLatest) {
|
|
75
71
|
chats.clear();
|
|
76
72
|
for (const id in messages) {
|
|
@@ -182,14 +178,16 @@ exports.default = (config) => {
|
|
|
182
178
|
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
183
179
|
const list = assertMessageList(jid);
|
|
184
180
|
list.upsert(msg, 'append');
|
|
185
|
-
if (type === 'notify'
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
181
|
+
if (type === 'notify') {
|
|
182
|
+
if (!chats.get(jid)) {
|
|
183
|
+
ev.emit('chats.upsert', [
|
|
184
|
+
{
|
|
185
|
+
id: jid,
|
|
186
|
+
conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
|
|
187
|
+
unreadCount: 1
|
|
188
|
+
}
|
|
189
|
+
]);
|
|
190
|
+
}
|
|
193
191
|
}
|
|
194
192
|
}
|
|
195
193
|
break;
|
|
@@ -56,9 +56,9 @@ function makeOrderedDictionary(idGetter) {
|
|
|
56
56
|
},
|
|
57
57
|
clear: () => {
|
|
58
58
|
array.splice(0, array.length);
|
|
59
|
-
|
|
59
|
+
Object.keys(dict).forEach(key => {
|
|
60
60
|
delete dict[key];
|
|
61
|
-
}
|
|
61
|
+
});
|
|
62
62
|
},
|
|
63
63
|
filter: (contain) => {
|
|
64
64
|
let i = 0;
|
package/lib/Types/Auth.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import type { proto } from '../../WAProto';
|
|
3
|
+
import { RegistrationOptions } from '../Socket/registration';
|
|
4
4
|
import type { Contact } from './Contact';
|
|
5
5
|
import type { MinimalMessage } from './Message';
|
|
6
6
|
export type KeyPair = {
|
|
@@ -57,7 +57,12 @@ export type AuthenticationCreds = SignalCreds & {
|
|
|
57
57
|
/** number of times history & app state has been synced */
|
|
58
58
|
accountSyncCounter: number;
|
|
59
59
|
accountSettings: AccountSettings;
|
|
60
|
+
deviceId: string;
|
|
61
|
+
phoneId: string;
|
|
62
|
+
identityId: Buffer;
|
|
60
63
|
registered: boolean;
|
|
64
|
+
backupToken: Buffer;
|
|
65
|
+
registration: RegistrationOptions;
|
|
61
66
|
pairingCode: string | undefined;
|
|
62
67
|
lastPropHash: string | undefined;
|
|
63
68
|
routingInfo: Buffer | undefined;
|
package/lib/Types/Call.d.ts
CHANGED
package/lib/Types/Chat.d.ts
CHANGED
|
@@ -3,14 +3,11 @@ import type { AccountSettings } from './Auth';
|
|
|
3
3
|
import type { BufferedEventData } from './Events';
|
|
4
4
|
import type { ChatLabelAssociationActionBody } from './LabelAssociation';
|
|
5
5
|
import type { MessageLabelAssociationActionBody } from './LabelAssociation';
|
|
6
|
-
import type { MinimalMessage
|
|
7
|
-
import type { LabelActionBody } from './Label';
|
|
6
|
+
import type { MinimalMessage } from './Message';
|
|
8
7
|
/** privacy settings in WhatsApp Web */
|
|
9
8
|
export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
|
|
10
9
|
export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
|
|
11
|
-
export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
|
|
12
10
|
export type WAReadReceiptsValue = 'all' | 'none';
|
|
13
|
-
export type WAPrivacyCallValue = 'all' | 'known';
|
|
14
11
|
/** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
|
|
15
12
|
export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
|
|
16
13
|
export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
|
|
@@ -62,12 +59,12 @@ export type ChatModification = {
|
|
|
62
59
|
/** mute for duration, or provide timestamp of mute to remove*/
|
|
63
60
|
mute: number | null;
|
|
64
61
|
} | {
|
|
65
|
-
clear:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
clear: 'all' | {
|
|
63
|
+
messages: {
|
|
64
|
+
id: string;
|
|
65
|
+
fromMe?: boolean;
|
|
66
|
+
timestamp: number;
|
|
67
|
+
}[];
|
|
71
68
|
};
|
|
72
69
|
} | {
|
|
73
70
|
star: {
|
|
@@ -83,8 +80,6 @@ export type ChatModification = {
|
|
|
83
80
|
} | {
|
|
84
81
|
delete: true;
|
|
85
82
|
lastMessages: LastMessageList;
|
|
86
|
-
} | {
|
|
87
|
-
addLabel: LabelActionBody;
|
|
88
83
|
} | {
|
|
89
84
|
addChatLabel: ChatLabelAssociationActionBody;
|
|
90
85
|
} | {
|
package/lib/Types/Contact.d.ts
CHANGED
package/lib/Types/Events.d.ts
CHANGED
|
@@ -4,12 +4,11 @@ import { AuthenticationCreds } from './Auth';
|
|
|
4
4
|
import { WACallEvent } from './Call';
|
|
5
5
|
import { Chat, ChatUpdate, PresenceData } from './Chat';
|
|
6
6
|
import { Contact } from './Contact';
|
|
7
|
-
import { GroupMetadata, ParticipantAction
|
|
7
|
+
import { GroupMetadata, ParticipantAction } from './GroupMetadata';
|
|
8
8
|
import { Label } from './Label';
|
|
9
9
|
import { LabelAssociation } from './LabelAssociation';
|
|
10
10
|
import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message';
|
|
11
11
|
import { ConnectionState } from './State';
|
|
12
|
-
import { NewsletterSettingsUpdate, SubscriberAction, NewsletterViewRole } from './Newsletter';
|
|
13
12
|
export type BaileysEventMap = {
|
|
14
13
|
/** connection state has been updated -- WS closed, opened, connecting etc. */
|
|
15
14
|
'connection.update': Partial<ConnectionState>;
|
|
@@ -20,10 +19,7 @@ export type BaileysEventMap = {
|
|
|
20
19
|
chats: Chat[];
|
|
21
20
|
contacts: Contact[];
|
|
22
21
|
messages: WAMessage[];
|
|
23
|
-
isLatest
|
|
24
|
-
progress?: number | null;
|
|
25
|
-
syncType?: proto.HistorySync.HistorySyncType;
|
|
26
|
-
peerDataRequestSessionId?: string | null;
|
|
22
|
+
isLatest: boolean;
|
|
27
23
|
};
|
|
28
24
|
/** upsert chats */
|
|
29
25
|
'chats.upsert': Chat[];
|
|
@@ -62,12 +58,10 @@ export type BaileysEventMap = {
|
|
|
62
58
|
/**
|
|
63
59
|
* add/update the given messages. If they were received while the connection was online,
|
|
64
60
|
* the update will have type: "notify"
|
|
65
|
-
* if requestId is provided, then the messages was received from the phone due to it being unavailable
|
|
66
61
|
* */
|
|
67
62
|
'messages.upsert': {
|
|
68
63
|
messages: WAMessage[];
|
|
69
64
|
type: MessageUpsertType;
|
|
70
|
-
requestId?: string;
|
|
71
65
|
};
|
|
72
66
|
/** message was reacted to. If reaction was removed -- then "reaction.text" will be falsey */
|
|
73
67
|
'messages.reaction': {
|
|
@@ -84,39 +78,6 @@ export type BaileysEventMap = {
|
|
|
84
78
|
participants: string[];
|
|
85
79
|
action: ParticipantAction;
|
|
86
80
|
};
|
|
87
|
-
'group.join-request': {
|
|
88
|
-
id: string;
|
|
89
|
-
author: string;
|
|
90
|
-
participant: string;
|
|
91
|
-
action: RequestJoinAction;
|
|
92
|
-
method: RequestJoinMethod;
|
|
93
|
-
};
|
|
94
|
-
'newsletter.reaction': {
|
|
95
|
-
id: string;
|
|
96
|
-
server_id: string;
|
|
97
|
-
reaction: {
|
|
98
|
-
code?: string;
|
|
99
|
-
count?: number;
|
|
100
|
-
removed?: boolean;
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
'newsletter.view': {
|
|
104
|
-
id: string;
|
|
105
|
-
server_id: string;
|
|
106
|
-
count: number;
|
|
107
|
-
};
|
|
108
|
-
/**don't handles subscribe/unsubscribe actions */
|
|
109
|
-
'newsletter-participants.update': {
|
|
110
|
-
id: string;
|
|
111
|
-
author: string;
|
|
112
|
-
user: string;
|
|
113
|
-
new_role: NewsletterViewRole;
|
|
114
|
-
action: SubscriberAction;
|
|
115
|
-
};
|
|
116
|
-
'newsletter-settings.update': {
|
|
117
|
-
id: string;
|
|
118
|
-
update: NewsletterSettingsUpdate;
|
|
119
|
-
};
|
|
120
81
|
'blocklist.set': {
|
|
121
82
|
blocklist: string[];
|
|
122
83
|
};
|
|
@@ -145,9 +106,6 @@ export type BufferedEventData = {
|
|
|
145
106
|
};
|
|
146
107
|
empty: boolean;
|
|
147
108
|
isLatest: boolean;
|
|
148
|
-
progress?: number | null;
|
|
149
|
-
syncType?: proto.HistorySync.HistorySyncType;
|
|
150
|
-
peerDataRequestSessionId?: string;
|
|
151
109
|
};
|
|
152
110
|
chatUpserts: {
|
|
153
111
|
[jid: string]: Chat;
|
|
@@ -4,9 +4,7 @@ export type GroupParticipant = (Contact & {
|
|
|
4
4
|
isSuperAdmin?: boolean;
|
|
5
5
|
admin?: 'admin' | 'superadmin' | null;
|
|
6
6
|
});
|
|
7
|
-
export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote'
|
|
8
|
-
export type RequestJoinAction = 'created' | 'revoked' | 'rejected';
|
|
9
|
-
export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin_add' | undefined;
|
|
7
|
+
export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote';
|
|
10
8
|
export interface GroupMetadata {
|
|
11
9
|
id: string;
|
|
12
10
|
owner: string | undefined;
|
package/lib/Types/Label.d.ts
CHANGED
|
@@ -10,17 +10,6 @@ export interface Label {
|
|
|
10
10
|
/** WhatsApp has 5 predefined labels (New customer, New order & etc) */
|
|
11
11
|
predefinedId?: string;
|
|
12
12
|
}
|
|
13
|
-
export interface LabelActionBody {
|
|
14
|
-
id: string;
|
|
15
|
-
/** Label name */
|
|
16
|
-
name?: string;
|
|
17
|
-
/** Label color ID */
|
|
18
|
-
color?: number;
|
|
19
|
-
/** Is label has been deleted */
|
|
20
|
-
deleted?: boolean;
|
|
21
|
-
/** WhatsApp has 5 predefined labels (New customer, New order & etc) */
|
|
22
|
-
predefinedId?: number;
|
|
23
|
-
}
|
|
24
13
|
/** WhatsApp has 20 predefined colors */
|
|
25
14
|
export declare enum LabelColor {
|
|
26
15
|
Color1 = 0,
|