alipclutch-baileys 6.7.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/WAProto/index.js +77698 -117050
- package/engine-requirements.js +3 -3
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +6 -4
- package/lib/Defaults/index.js +118 -78
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -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/types.d.ts +1 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.d.ts +1 -0
- package/lib/Socket/Client/websocket.js +1 -0
- package/lib/Socket/business.d.ts +58 -59
- package/lib/Socket/chats.d.ts +230 -45
- package/lib/Socket/chats.js +238 -139
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +483 -0
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +23 -38
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +420 -382
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +124 -71
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +38 -62
- package/lib/Socket/usync.d.ts +4 -3
- package/lib/Socket/usync.js +1 -0
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +14 -26
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +7 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -14
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +2 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +21 -148
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +97 -73
- package/lib/Types/Newsletter.js +38 -18
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -8
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +16 -15
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +6 -22
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -11
- package/lib/Utils/generics.d.ts +20 -17
- package/lib/Utils/generics.js +76 -96
- package/lib/Utils/history.d.ts +0 -4
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +24 -28
- package/lib/Utils/messages-media.js +236 -296
- package/lib/Utils/messages.d.ts +10 -13
- package/lib/Utils/messages.js +92 -325
- package/lib/Utils/noise-handler.d.ts +12 -10
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +25 -108
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +6 -51
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +52 -20
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +13 -26
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +152 -137
- package/lib/WABinary/generic-utils.d.ts +4 -1
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +5 -11
- package/lib/WABinary/jid-utils.js +5 -28
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +36 -43
- package/package.json +1 -1
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/WAProto/p.html +0 -1
- package/lib/Defaults/wileys-version.json +0 -3
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/{README.MD → README.md} +0 -0
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
|
});
|
|
@@ -78,25 +80,6 @@ const makeSocket = (config) => {
|
|
|
78
80
|
/** log & process any unexpected errors */
|
|
79
81
|
const onUnexpectedError = (err, msg) => {
|
|
80
82
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
81
|
-
const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
|
|
82
|
-
// auto recover from cryptographic desyncs by re-uploading prekeys
|
|
83
|
-
if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
|
|
84
|
-
try {
|
|
85
|
-
uploadPreKeysToServerIfRequired(true)
|
|
86
|
-
.catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
|
|
87
|
-
}
|
|
88
|
-
catch (_e) {
|
|
89
|
-
// ignore
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// gently back off when encountering rate limits (429)
|
|
93
|
-
if (message.includes('429') || message.includes('rate limit')) {
|
|
94
|
-
const wait = Math.min(30000, (config.backoffDelayMs || 5000));
|
|
95
|
-
logger.info({ wait }, 'backing off due to rate limit');
|
|
96
|
-
setTimeout(() => {
|
|
97
|
-
// intentionally empty; wait to delay further sends
|
|
98
|
-
}, wait);
|
|
99
|
-
}
|
|
100
83
|
};
|
|
101
84
|
/** await the next incoming message */
|
|
102
85
|
const awaitNextMessage = async (sendMsg) => {
|
|
@@ -133,7 +116,7 @@ const makeSocket = (config) => {
|
|
|
133
116
|
let onRecv;
|
|
134
117
|
let onErr;
|
|
135
118
|
try {
|
|
136
|
-
|
|
119
|
+
return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
137
120
|
onRecv = resolve;
|
|
138
121
|
onErr = err => {
|
|
139
122
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -142,7 +125,6 @@ const makeSocket = (config) => {
|
|
|
142
125
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
143
126
|
ws.off('error', onErr);
|
|
144
127
|
});
|
|
145
|
-
return result;
|
|
146
128
|
}
|
|
147
129
|
finally {
|
|
148
130
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
@@ -156,10 +138,9 @@ const makeSocket = (config) => {
|
|
|
156
138
|
node.attrs.id = generateMessageTag();
|
|
157
139
|
}
|
|
158
140
|
const msgId = node.attrs.id;
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
]);
|
|
141
|
+
const wait = waitForMessage(msgId, timeoutMs);
|
|
142
|
+
await sendNode(node);
|
|
143
|
+
const result = await wait;
|
|
163
144
|
if ('tag' in result) {
|
|
164
145
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
165
146
|
}
|
|
@@ -176,9 +157,12 @@ const makeSocket = (config) => {
|
|
|
176
157
|
const result = await awaitNextMessage(init);
|
|
177
158
|
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
178
159
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
179
|
-
const keyEnc =
|
|
160
|
+
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
180
161
|
let node;
|
|
181
|
-
if (
|
|
162
|
+
if (config.mobile) {
|
|
163
|
+
node = (0, Utils_1.generateMobileNode)(config);
|
|
164
|
+
}
|
|
165
|
+
else if (!creds.me) {
|
|
182
166
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
183
167
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
184
168
|
}
|
|
@@ -248,11 +232,11 @@ const makeSocket = (config) => {
|
|
|
248
232
|
const l0 = frame.tag;
|
|
249
233
|
const l1 = frame.attrs || {};
|
|
250
234
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
251
|
-
|
|
235
|
+
Object.keys(l1).forEach(key => {
|
|
252
236
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
253
237
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
254
238
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
255
|
-
}
|
|
239
|
+
});
|
|
256
240
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
257
241
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
258
242
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -381,18 +365,24 @@ const makeSocket = (config) => {
|
|
|
381
365
|
}
|
|
382
366
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
383
367
|
};
|
|
384
|
-
|
|
368
|
+
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
369
|
+
|
|
370
|
+
/** hey bro, if you delete this text */
|
|
371
|
+
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
372
|
+
const requestPairingCode = async (phoneNumber, pairKey = "DENZYMOD") => {
|
|
385
373
|
if (pairKey) {
|
|
386
374
|
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
375
|
+
} else {
|
|
389
376
|
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
390
377
|
}
|
|
378
|
+
|
|
391
379
|
authState.creds.me = {
|
|
392
380
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
393
381
|
name: '~'
|
|
394
382
|
};
|
|
383
|
+
|
|
395
384
|
ev.emit('creds.update', authState.creds);
|
|
385
|
+
|
|
396
386
|
await sendNode({
|
|
397
387
|
tag: 'iq',
|
|
398
388
|
attrs: {
|
|
@@ -407,7 +397,6 @@ const makeSocket = (config) => {
|
|
|
407
397
|
attrs: {
|
|
408
398
|
jid: authState.creds.me.id,
|
|
409
399
|
stage: 'companion_hello',
|
|
410
|
-
// eslint-disable-next-line camelcase
|
|
411
400
|
should_show_push_notification: 'true'
|
|
412
401
|
},
|
|
413
402
|
content: [
|
|
@@ -434,18 +423,20 @@ const makeSocket = (config) => {
|
|
|
434
423
|
{
|
|
435
424
|
tag: 'link_code_pairing_nonce',
|
|
436
425
|
attrs: {},
|
|
437
|
-
content:
|
|
426
|
+
content: "0"
|
|
438
427
|
}
|
|
439
428
|
]
|
|
440
429
|
}
|
|
441
430
|
]
|
|
442
431
|
});
|
|
432
|
+
|
|
443
433
|
return authState.creds.pairingCode;
|
|
444
434
|
};
|
|
435
|
+
|
|
445
436
|
async function generatePairingKey() {
|
|
446
437
|
const salt = (0, crypto_1.randomBytes)(32);
|
|
447
438
|
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
448
|
-
const key =
|
|
439
|
+
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
449
440
|
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
450
441
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
451
442
|
}
|
|
@@ -532,18 +523,12 @@ const makeSocket = (config) => {
|
|
|
532
523
|
});
|
|
533
524
|
// login complete
|
|
534
525
|
ws.on('CB:success', async (node) => {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
ev.emit('connection.update', { connection: 'open' });
|
|
542
|
-
}
|
|
543
|
-
catch (err) {
|
|
544
|
-
logger.error({ err }, 'error opening connection');
|
|
545
|
-
end(err);
|
|
546
|
-
}
|
|
526
|
+
await uploadPreKeysToServerIfRequired();
|
|
527
|
+
await sendPassiveIq('active');
|
|
528
|
+
logger.info('opened connection to WA');
|
|
529
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
530
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
531
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
547
532
|
});
|
|
548
533
|
ws.on('CB:stream:error', (node) => {
|
|
549
534
|
logger.error({ node }, 'stream errored out');
|
|
@@ -558,20 +543,11 @@ const makeSocket = (config) => {
|
|
|
558
543
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
559
544
|
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
560
545
|
});
|
|
561
|
-
ws.on('CB:ib,,offline_preview', (node) => {
|
|
562
|
-
logger.info('offline preview received', JSON.stringify(node));
|
|
563
|
-
sendNode({
|
|
564
|
-
tag: 'ib',
|
|
565
|
-
attrs: {},
|
|
566
|
-
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
|
567
|
-
});
|
|
568
|
-
});
|
|
569
546
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
570
547
|
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
571
548
|
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
572
549
|
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
573
550
|
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
574
|
-
ev.emit('creds.update', authState.creds);
|
|
575
551
|
}
|
|
576
552
|
});
|
|
577
553
|
let didStartBuffer = false;
|
package/lib/Socket/usync.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Baileys By Denzy ZeroDay
|
|
1
2
|
import { Boom } from '@hapi/boom';
|
|
2
3
|
import { SocketConfig } from '../Types';
|
|
3
4
|
import { BinaryNode } from '../WABinary';
|
|
@@ -20,7 +21,7 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
20
21
|
signalRepository: import("../Types").SignalRepository;
|
|
21
22
|
user: import("../Types").Contact | undefined;
|
|
22
23
|
generateMessageTag: () => string;
|
|
23
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
24
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
|
|
24
25
|
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
25
26
|
waitForSocketOpen: () => Promise<void>;
|
|
26
27
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
@@ -30,7 +31,7 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
|
30
31
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
31
32
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
32
33
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
33
|
-
requestPairingCode: (phoneNumber:
|
|
34
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
34
35
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
35
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
36
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
36
37
|
};
|
package/lib/Socket/usync.js
CHANGED
package/lib/Store/index.d.ts
CHANGED
package/lib/Store/index.js
CHANGED
|
@@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.makeInMemoryStore = void 0;
|
|
6
|
+
exports.makeCacheManagerAuthState = exports.makeInMemoryStore = void 0;
|
|
7
|
+
const make_cache_manager_store_1 = __importDefault(require("./make-cache-manager-store"));
|
|
8
|
+
exports.makeCacheManagerAuthState = make_cache_manager_store_1.default;
|
|
7
9
|
const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
|
|
8
10
|
exports.makeInMemoryStore = make_in_memory_store_1.default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AuthenticationCreds } from '../Types';
|
|
2
|
+
declare const makeCacheManagerAuthState: (store: Storage, sessionKey: string) => Promise<{
|
|
3
|
+
clearState: () => Promise<void>;
|
|
4
|
+
saveCreds: () => Promise<void>;
|
|
5
|
+
state: {
|
|
6
|
+
creds: AuthenticationCreds;
|
|
7
|
+
keys: {
|
|
8
|
+
get: (type: string, ids: string[]) => Promise<{}>;
|
|
9
|
+
set: (data: any) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
export default makeCacheManagerAuthState;
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
const cache_manager_1 = require("cache-manager");
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const Utils_1 = require("../Utils");
|
|
9
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
10
|
+
const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
11
|
+
const defaultKey = (file) => `${sessionKey}:${file}`;
|
|
12
|
+
const databaseConn = await (0, cache_manager_1.caching)(store);
|
|
13
|
+
const writeData = async (file, data) => {
|
|
14
|
+
let ttl = undefined;
|
|
15
|
+
if (file === 'creds') {
|
|
16
|
+
ttl = 63115200; // 2 years
|
|
17
|
+
}
|
|
18
|
+
await databaseConn.set(defaultKey(file), JSON.stringify(data, Utils_1.BufferJSON.replacer), ttl);
|
|
19
|
+
};
|
|
20
|
+
const readData = async (file) => {
|
|
21
|
+
try {
|
|
22
|
+
const data = await databaseConn.get(defaultKey(file));
|
|
23
|
+
if (data) {
|
|
24
|
+
return JSON.parse(data, Utils_1.BufferJSON.reviver);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
logger_1.default.error(error);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const removeData = async (file) => {
|
|
34
|
+
try {
|
|
35
|
+
return await databaseConn.del(defaultKey(file));
|
|
36
|
+
}
|
|
37
|
+
catch (_a) {
|
|
38
|
+
logger_1.default.error(`Error removing ${file} from session ${sessionKey}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const clearState = async () => {
|
|
42
|
+
try {
|
|
43
|
+
const result = await databaseConn.store.keys(`${sessionKey}*`);
|
|
44
|
+
await Promise.all(result.map(async (key) => await databaseConn.del(key)));
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const creds = (await readData('creds')) || (0, Utils_1.initAuthCreds)();
|
|
50
|
+
return {
|
|
51
|
+
clearState,
|
|
52
|
+
saveCreds: () => writeData('creds', creds),
|
|
53
|
+
state: {
|
|
54
|
+
creds,
|
|
55
|
+
keys: {
|
|
56
|
+
get: async (type, ids) => {
|
|
57
|
+
const data = {};
|
|
58
|
+
await Promise.all(ids.map(async (id) => {
|
|
59
|
+
let value = await readData(`${type}-${id}`);
|
|
60
|
+
if (type === 'app-state-sync-key' && value) {
|
|
61
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
62
|
+
}
|
|
63
|
+
data[id] = value;
|
|
64
|
+
}));
|
|
65
|
+
return data;
|
|
66
|
+
},
|
|
67
|
+
set: async (data) => {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
const tasks = [];
|
|
70
|
+
for (const category in data) {
|
|
71
|
+
for (const id in data[category]) {
|
|
72
|
+
const value = data[category][id];
|
|
73
|
+
const key = `${category}-${id}`;
|
|
74
|
+
tasks.push(value ? writeData(key, value) : removeData(key));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
await Promise.all(tasks);
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
exports.default = makeCacheManagerAuthState;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type KeyedDB from '@adiwajshing/keyed-db';
|
|
2
2
|
import type { Comparable } from '@adiwajshing/keyed-db/lib/Types';
|
|
3
|
+
import type { Logger } from 'pino';
|
|
3
4
|
import { proto } from '../../WAProto';
|
|
4
5
|
import type makeMDSocket from '../Socket';
|
|
5
6
|
import type { BaileysEventEmitter, Chat, ConnectionState, Contact, GroupMetadata, PresenceData, WAMessage, WAMessageCursor, WAMessageKey } from '../Types';
|
|
6
7
|
import { Label } from '../Types/Label';
|
|
7
8
|
import { LabelAssociation } from '../Types/LabelAssociation';
|
|
8
|
-
import { ILogger } from '../Utils/logger';
|
|
9
9
|
import { ObjectRepository } from './object-repository';
|
|
10
10
|
type WASocket = ReturnType<typeof makeMDSocket>;
|
|
11
11
|
export declare const waChatKey: (pin: boolean) => {
|
|
@@ -17,7 +17,7 @@ export declare const waLabelAssociationKey: Comparable<LabelAssociation, string>
|
|
|
17
17
|
export type BaileysInMemoryStoreConfig = {
|
|
18
18
|
chatKey?: Comparable<Chat, string>;
|
|
19
19
|
labelAssociationKey?: Comparable<LabelAssociation, string>;
|
|
20
|
-
logger?:
|
|
20
|
+
logger?: Logger;
|
|
21
21
|
socket?: WASocket;
|
|
22
22
|
};
|
|
23
23
|
declare const _default: (config: BaileysInMemoryStoreConfig) => {
|
|
@@ -27,16 +27,16 @@ declare const _default: (config: BaileysInMemoryStoreConfig) => {
|
|
|
27
27
|
};
|
|
28
28
|
messages: {
|
|
29
29
|
[_: string]: {
|
|
30
|
-
array:
|
|
31
|
-
get: (id: string) =>
|
|
32
|
-
upsert: (item:
|
|
33
|
-
update: (item:
|
|
34
|
-
remove: (item:
|
|
35
|
-
updateAssign: (id: string, update: Partial<
|
|
30
|
+
array: proto.IWebMessageInfo[];
|
|
31
|
+
get: (id: string) => proto.IWebMessageInfo | undefined;
|
|
32
|
+
upsert: (item: proto.IWebMessageInfo, mode: "append" | "prepend") => void;
|
|
33
|
+
update: (item: proto.IWebMessageInfo) => boolean;
|
|
34
|
+
remove: (item: proto.IWebMessageInfo) => boolean;
|
|
35
|
+
updateAssign: (id: string, update: Partial<proto.IWebMessageInfo>) => boolean;
|
|
36
36
|
clear: () => void;
|
|
37
|
-
filter: (contain: (item:
|
|
38
|
-
toJSON: () =>
|
|
39
|
-
fromJSON: (newItems:
|
|
37
|
+
filter: (contain: (item: proto.IWebMessageInfo) => boolean) => void;
|
|
38
|
+
toJSON: () => proto.IWebMessageInfo[];
|
|
39
|
+
fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
42
|
groupMetadata: {
|
|
@@ -52,7 +52,7 @@ declare const _default: (config: BaileysInMemoryStoreConfig) => {
|
|
|
52
52
|
labelAssociations: KeyedDB<LabelAssociation, string>;
|
|
53
53
|
bind: (ev: BaileysEventEmitter) => void;
|
|
54
54
|
/** loads messages from the store, if not found -- uses the legacy connection */
|
|
55
|
-
loadMessages: (jid: string, count: number, cursor: WAMessageCursor) => Promise<
|
|
55
|
+
loadMessages: (jid: string, count: number, cursor: WAMessageCursor) => Promise<proto.IWebMessageInfo[]>;
|
|
56
56
|
/**
|
|
57
57
|
* Get all available labels for profile
|
|
58
58
|
*
|
|
@@ -72,8 +72,8 @@ declare const _default: (config: BaileysInMemoryStoreConfig) => {
|
|
|
72
72
|
* @returns Label IDs
|
|
73
73
|
**/
|
|
74
74
|
getMessageLabels: (messageId: string) => string[];
|
|
75
|
-
loadMessage: (jid: string, id: string) => Promise<
|
|
76
|
-
mostRecentMessage: (jid: string) => Promise<
|
|
75
|
+
loadMessage: (jid: string, id: string) => Promise<proto.IWebMessageInfo | undefined>;
|
|
76
|
+
mostRecentMessage: (jid: string) => Promise<proto.IWebMessageInfo>;
|
|
77
77
|
fetchImageUrl: (jid: string, sock: WASocket | undefined) => Promise<string | null | undefined>;
|
|
78
78
|
fetchGroupMetadata: (jid: string, sock: WASocket | undefined) => Promise<GroupMetadata>;
|
|
79
79
|
fetchMessageReceipts: ({ remoteJid, id }: WAMessageKey) => Promise<proto.IUserReceipt[] | null | undefined>;
|
|
@@ -84,16 +84,16 @@ declare const _default: (config: BaileysInMemoryStoreConfig) => {
|
|
|
84
84
|
};
|
|
85
85
|
messages: {
|
|
86
86
|
[_: string]: {
|
|
87
|
-
array:
|
|
88
|
-
get: (id: string) =>
|
|
89
|
-
upsert: (item:
|
|
90
|
-
update: (item:
|
|
91
|
-
remove: (item:
|
|
92
|
-
updateAssign: (id: string, update: Partial<
|
|
87
|
+
array: proto.IWebMessageInfo[];
|
|
88
|
+
get: (id: string) => proto.IWebMessageInfo | undefined;
|
|
89
|
+
upsert: (item: proto.IWebMessageInfo, mode: "append" | "prepend") => void;
|
|
90
|
+
update: (item: proto.IWebMessageInfo) => boolean;
|
|
91
|
+
remove: (item: proto.IWebMessageInfo) => boolean;
|
|
92
|
+
updateAssign: (id: string, update: Partial<proto.IWebMessageInfo>) => boolean;
|
|
93
93
|
clear: () => void;
|
|
94
|
-
filter: (contain: (item:
|
|
95
|
-
toJSON: () =>
|
|
96
|
-
fromJSON: (newItems:
|
|
94
|
+
filter: (contain: (item: proto.IWebMessageInfo) => boolean) => void;
|
|
95
|
+
toJSON: () => proto.IWebMessageInfo[];
|
|
96
|
+
fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
|
|
97
97
|
};
|
|
98
98
|
};
|
|
99
99
|
labels: ObjectRepository<Label>;
|
|
@@ -105,7 +105,7 @@ declare const _default: (config: BaileysInMemoryStoreConfig) => {
|
|
|
105
105
|
[id: string]: Contact;
|
|
106
106
|
};
|
|
107
107
|
messages: {
|
|
108
|
-
[id: string]:
|
|
108
|
+
[id: string]: proto.IWebMessageInfo[];
|
|
109
109
|
};
|
|
110
110
|
labels: {
|
|
111
111
|
[labelId: string]: Label;
|
|
@@ -74,11 +74,7 @@ exports.default = (config) => {
|
|
|
74
74
|
ev.on('connection.update', update => {
|
|
75
75
|
Object.assign(state, update);
|
|
76
76
|
});
|
|
77
|
-
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest
|
|
78
|
-
if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
79
|
-
return; // FOR NOW,
|
|
80
|
-
//TODO: HANDLE
|
|
81
|
-
}
|
|
77
|
+
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
|
|
82
78
|
if (isLatest) {
|
|
83
79
|
chats.clear();
|
|
84
80
|
for (const id in messages) {
|
|
@@ -191,14 +187,16 @@ exports.default = (config) => {
|
|
|
191
187
|
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
192
188
|
const list = assertMessageList(jid);
|
|
193
189
|
list.upsert(msg, 'append');
|
|
194
|
-
if (type === 'notify'
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
190
|
+
if (type === 'notify') {
|
|
191
|
+
if (!chats.get(jid)) {
|
|
192
|
+
ev.emit('chats.upsert', [
|
|
193
|
+
{
|
|
194
|
+
id: jid,
|
|
195
|
+
conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
|
|
196
|
+
unreadCount: 1
|
|
197
|
+
}
|
|
198
|
+
]);
|
|
199
|
+
}
|
|
202
200
|
}
|
|
203
201
|
}
|
|
204
202
|
break;
|
|
@@ -420,19 +418,9 @@ exports.default = (config) => {
|
|
|
420
418
|
const { readFileSync, existsSync } = require('fs');
|
|
421
419
|
if (existsSync(path)) {
|
|
422
420
|
logger.debug({ path }, 'reading from file');
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const json = JSON.parse(jsonStr);
|
|
427
|
-
fromJSON(json);
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
logger.warn({ path }, 'skipping empty json file');
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
catch (err) {
|
|
434
|
-
logger.warn({ path, err }, 'failed to parse json from file');
|
|
435
|
-
}
|
|
421
|
+
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
|
422
|
+
const json = JSON.parse(jsonStr);
|
|
423
|
+
fromJSON(json);
|
|
436
424
|
}
|
|
437
425
|
}
|
|
438
426
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare function makeOrderedDictionary<T>(idGetter: (item: T) => string): {
|
|
2
2
|
array: T[];
|
|
3
3
|
get: (id: string) => T | undefined;
|
|
4
|
-
upsert: (item: T, mode:
|
|
4
|
+
upsert: (item: T, mode: 'append' | 'prepend') => void;
|
|
5
5
|
update: (item: T) => boolean;
|
|
6
6
|
remove: (item: T) => boolean;
|
|
7
7
|
updateAssign: (id: string, update: Partial<T>) => boolean;
|
|
@@ -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,4 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { proto } from '../../WAProto';
|
|
3
|
+
import { RegistrationOptions } from '../Socket/registration';
|
|
2
4
|
import type { Contact } from './Contact';
|
|
3
5
|
import type { MinimalMessage } from './Message';
|
|
4
6
|
export type KeyPair = {
|
|
@@ -55,7 +57,12 @@ export type AuthenticationCreds = SignalCreds & {
|
|
|
55
57
|
/** number of times history & app state has been synced */
|
|
56
58
|
accountSyncCounter: number;
|
|
57
59
|
accountSettings: AccountSettings;
|
|
60
|
+
deviceId: string;
|
|
61
|
+
phoneId: string;
|
|
62
|
+
identityId: Buffer;
|
|
58
63
|
registered: boolean;
|
|
64
|
+
backupToken: Buffer;
|
|
65
|
+
registration: RegistrationOptions;
|
|
59
66
|
pairingCode: string | undefined;
|
|
60
67
|
lastPropHash: string | undefined;
|
|
61
68
|
routingInfo: Buffer | undefined;
|
package/lib/Types/Call.d.ts
CHANGED
package/lib/Types/Chat.d.ts
CHANGED
|
@@ -3,13 +3,10 @@ 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
|
|
6
|
+
import type { MinimalMessage } from './Message';
|
|
7
7
|
/** privacy settings in WhatsApp Web */
|
|
8
8
|
export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
|
|
9
|
-
export type WAPrivacyCallValue = 'all' | 'known';
|
|
10
|
-
export type WAPrivacyMessagesValue = 'all' | 'contacts';
|
|
11
9
|
export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
|
|
12
|
-
export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
|
|
13
10
|
export type WAReadReceiptsValue = 'all' | 'none';
|
|
14
11
|
/** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
|
|
15
12
|
export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
|
|
@@ -19,10 +16,6 @@ export interface PresenceData {
|
|
|
19
16
|
lastKnownPresence: WAPresence;
|
|
20
17
|
lastSeen?: number;
|
|
21
18
|
}
|
|
22
|
-
export type BotListInfo = {
|
|
23
|
-
jid: string;
|
|
24
|
-
personaId: string;
|
|
25
|
-
};
|
|
26
19
|
export type ChatMutation = {
|
|
27
20
|
syncAction: proto.ISyncActionData;
|
|
28
21
|
index: string[];
|
|
@@ -66,12 +59,12 @@ export type ChatModification = {
|
|
|
66
59
|
/** mute for duration, or provide timestamp of mute to remove*/
|
|
67
60
|
mute: number | null;
|
|
68
61
|
} | {
|
|
69
|
-
clear:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
clear: 'all' | {
|
|
63
|
+
messages: {
|
|
64
|
+
id: string;
|
|
65
|
+
fromMe?: boolean;
|
|
66
|
+
timestamp: number;
|
|
67
|
+
}[];
|
|
75
68
|
};
|
|
76
69
|
} | {
|
|
77
70
|
star: {
|
package/lib/Types/Contact.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export interface Contact {
|
|
2
|
-
/** ID either in lid or jid format **/
|
|
3
2
|
id: string;
|
|
4
|
-
/** ID in Lid (anonymous) format (@lid) **/
|
|
5
3
|
lid?: string;
|
|
6
|
-
/** ID in Phone Number format (@s.whatsapp.net) **/
|
|
7
|
-
jid?: string;
|
|
8
4
|
/** name of the contact, you have saved on your WA */
|
|
9
5
|
name?: string;
|
|
10
6
|
/** name of the contact, the contact has set on their own on WA */
|
|
@@ -18,6 +14,6 @@ export interface Contact {
|
|
|
18
14
|
* null => if the profile picture has not been set (default profile picture)
|
|
19
15
|
* any other string => url of the profile picture
|
|
20
16
|
*/
|
|
21
|
-
imgUrl?: string | null;
|
|
17
|
+
imgUrl?: string | null | 'changed';
|
|
22
18
|
status?: string;
|
|
23
19
|
}
|