@vinzsocket/baileys 2.8.10 → 2.8.30
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.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +4 -2
package/lib/Utils/history.js
CHANGED
|
@@ -7,78 +7,85 @@ import { normalizeMessageContent } from './messages.js';
|
|
|
7
7
|
import { downloadContentFromMessage } from './messages-media.js';
|
|
8
8
|
const inflatePromise = promisify(inflate);
|
|
9
9
|
export const downloadHistory = async (msg, options) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
const stream = await downloadContentFromMessage(msg, 'md-msg-hist', {
|
|
11
|
+
options
|
|
12
|
+
});
|
|
13
|
+
const bufferArray = [];
|
|
14
|
+
for await (const chunk of stream) {
|
|
15
|
+
bufferArray.push(chunk);
|
|
16
|
+
}
|
|
17
|
+
let buffer = Buffer.concat(bufferArray);
|
|
18
|
+
// decompress buffer
|
|
19
|
+
buffer = await inflatePromise(buffer);
|
|
20
|
+
const syncData = proto.HistorySync.decode(buffer);
|
|
21
|
+
return syncData;
|
|
20
22
|
};
|
|
21
|
-
export const processHistoryMessage =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
23
|
+
export const processHistoryMessage = item => {
|
|
24
|
+
const messages = [];
|
|
25
|
+
const contacts = [];
|
|
26
|
+
const chats = [];
|
|
27
|
+
switch (item.syncType) {
|
|
28
|
+
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
29
|
+
case proto.HistorySync.HistorySyncType.RECENT:
|
|
30
|
+
case proto.HistorySync.HistorySyncType.FULL:
|
|
31
|
+
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
32
|
+
for (const chat of item.conversations) {
|
|
33
|
+
contacts.push({
|
|
34
|
+
id: chat.id,
|
|
35
|
+
name: chat.name || undefined,
|
|
36
|
+
lid: chat.lidJid || undefined,
|
|
37
|
+
phoneNumber: chat.pnJid || undefined
|
|
38
|
+
});
|
|
39
|
+
const msgs = chat.messages || [];
|
|
40
|
+
delete chat.messages;
|
|
41
|
+
for (const item of msgs) {
|
|
42
|
+
const message = item.message;
|
|
43
|
+
messages.push(message);
|
|
44
|
+
if (!chat.messages?.length) {
|
|
45
|
+
// keep only the most recent message in the chat array
|
|
46
|
+
chat.messages = [{
|
|
47
|
+
message
|
|
48
|
+
}];
|
|
49
|
+
}
|
|
50
|
+
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
51
|
+
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
52
|
+
}
|
|
53
|
+
if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP || message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) && message.messageStubParameters?.[0]) {
|
|
54
|
+
contacts.push({
|
|
55
|
+
id: message.key.participant || message.key.remoteJid,
|
|
56
|
+
verifiedName: message.messageStubParameters?.[0]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
chats.push({
|
|
61
|
+
...chat
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
66
|
+
for (const c of item.pushnames) {
|
|
67
|
+
contacts.push({
|
|
68
|
+
id: c.id,
|
|
69
|
+
notify: c.pushname
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
chats,
|
|
76
|
+
contacts,
|
|
77
|
+
messages,
|
|
78
|
+
syncType: item.syncType,
|
|
79
|
+
progress: item.progress
|
|
80
|
+
};
|
|
74
81
|
};
|
|
75
82
|
export const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
const historyMsg = await downloadHistory(msg, options);
|
|
84
|
+
return processHistoryMessage(historyMsg);
|
|
78
85
|
};
|
|
79
|
-
export const getHistoryMsg =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
export const getHistoryMsg = message => {
|
|
87
|
+
const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
|
|
88
|
+
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
|
|
89
|
+
return anyHistoryMsg;
|
|
83
90
|
};
|
|
84
91
|
//# sourceMappingURL=history.js.map
|
|
@@ -16,52 +16,57 @@
|
|
|
16
16
|
//
|
|
17
17
|
// After that, buildTagAllText() (mention.js) will use it automatically.
|
|
18
18
|
export function createLidResolver() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
const nameByJid = new Map(); // exact jid string -> display name
|
|
20
|
+
const MAX_ENTRIES = 5000;
|
|
21
|
+
function remember(jid, name) {
|
|
22
|
+
if (!jid || !name) return;
|
|
23
|
+
if (nameByJid.size > MAX_ENTRIES) nameByJid.clear();
|
|
24
|
+
nameByJid.set(jid, name);
|
|
25
|
+
}
|
|
26
|
+
function getDisplayName(jid) {
|
|
27
|
+
return jid ? nameByJid.get(jid) : undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Feed it whatever groupMetadata() gave you (call this is optional — groups.js already does it automatically) */
|
|
30
|
+
function feedGroupMetadata(metadata) {
|
|
31
|
+
for (const p of metadata && metadata.participants || []) {
|
|
32
|
+
if (p.username) remember(p.id, p.username);
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return { attach, getDisplayName, feedGroupMetadata, remember };
|
|
34
|
+
}
|
|
35
|
+
function attach(sock) {
|
|
36
|
+
if (!sock || !sock.ev || typeof sock.ev.on !== 'function') return {
|
|
37
|
+
getDisplayName,
|
|
38
|
+
feedGroupMetadata,
|
|
39
|
+
remember
|
|
40
|
+
};
|
|
41
|
+
sock.ev.on('contacts.update', updates => {
|
|
42
|
+
for (const c of updates || []) {
|
|
43
|
+
if (c.notify) remember(c.id, c.notify);
|
|
44
|
+
if (c.name) remember(c.id, c.name);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
sock.ev.on('contacts.upsert', contacts => {
|
|
48
|
+
for (const c of contacts || []) {
|
|
49
|
+
if (c.name) remember(c.id, c.name);
|
|
50
|
+
if (c.notify) remember(c.id, c.notify);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
getDisplayName,
|
|
55
|
+
feedGroupMetadata,
|
|
56
|
+
remember
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
attach,
|
|
61
|
+
getDisplayName,
|
|
62
|
+
feedGroupMetadata,
|
|
63
|
+
remember
|
|
64
|
+
};
|
|
60
65
|
}
|
|
61
66
|
// Module-level singleton so other utils (e.g. mention.js) can share the same
|
|
62
67
|
// cache without every caller having to pass a resolver instance around.
|
|
63
68
|
const defaultResolver = createLidResolver();
|
|
64
|
-
export const attachLidResolver =
|
|
69
|
+
export const attachLidResolver = sock => defaultResolver.attach(sock);
|
|
65
70
|
export const getDisplayName = defaultResolver.getDisplayName;
|
|
66
71
|
export const feedGroupMetadata = defaultResolver.feedGroupMetadata;
|
|
67
|
-
export const remember = defaultResolver.remember;
|
|
72
|
+
export const remember = defaultResolver.remember;
|
|
@@ -2,10 +2,13 @@ import { prepareWAMessageMedia } from './messages.js';
|
|
|
2
2
|
import { extractImageThumb, getHttpStream } from './messages-media.js';
|
|
3
3
|
const THUMBNAIL_WIDTH_PX = 192;
|
|
4
4
|
/** Fetches an image and generates a thumbnail for it */
|
|
5
|
-
const getCompressedJpegThumbnail = async (url, {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const getCompressedJpegThumbnail = async (url, {
|
|
6
|
+
thumbnailWidth,
|
|
7
|
+
fetchOpts
|
|
8
|
+
}) => {
|
|
9
|
+
const stream = await getHttpStream(url, fetchOpts);
|
|
10
|
+
const result = await extractImageThumb(stream, thumbnailWidth);
|
|
11
|
+
return result;
|
|
9
12
|
};
|
|
10
13
|
/**
|
|
11
14
|
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
@@ -14,72 +17,79 @@ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) =>
|
|
|
14
17
|
* @returns the URL info required to generate link preview
|
|
15
18
|
*/
|
|
16
19
|
export const getUrlInfo = async (text, opts = {
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
21
|
+
fetchOpts: {
|
|
22
|
+
timeout: 3000
|
|
23
|
+
}
|
|
19
24
|
}) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
try {
|
|
26
|
+
// retries
|
|
27
|
+
const retries = 0;
|
|
28
|
+
const maxRetry = 5;
|
|
29
|
+
const {
|
|
30
|
+
getLinkPreview
|
|
31
|
+
} = await import('link-preview-js');
|
|
32
|
+
let previewLink = text;
|
|
33
|
+
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
34
|
+
previewLink = 'https://' + previewLink;
|
|
35
|
+
}
|
|
36
|
+
const info = await getLinkPreview(previewLink, {
|
|
37
|
+
...opts.fetchOpts,
|
|
38
|
+
followRedirects: 'follow',
|
|
39
|
+
handleRedirects: (baseURL, forwardedURL) => {
|
|
40
|
+
const urlObj = new URL(baseURL);
|
|
41
|
+
const forwardedURLObj = new URL(forwardedURL);
|
|
42
|
+
if (retries >= maxRetry) {
|
|
43
|
+
return false;
|
|
28
44
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
if (forwardedURLObj.hostname === urlObj.hostname || forwardedURLObj.hostname === 'www.' + urlObj.hostname || 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
46
|
+
retries + 1;
|
|
47
|
+
return true;
|
|
48
|
+
} else {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
headers: opts.fetchOpts
|
|
53
|
+
});
|
|
54
|
+
if (info && 'title' in info && info.title) {
|
|
55
|
+
const [image] = info.images;
|
|
56
|
+
const urlInfo = {
|
|
57
|
+
'canonical-url': info.url,
|
|
58
|
+
'matched-text': text,
|
|
59
|
+
title: info.title,
|
|
60
|
+
description: info.description,
|
|
61
|
+
originalThumbnailUrl: image
|
|
62
|
+
};
|
|
63
|
+
if (opts.uploadImage) {
|
|
64
|
+
const {
|
|
65
|
+
imageMessage
|
|
66
|
+
} = await prepareWAMessageMedia({
|
|
67
|
+
image: {
|
|
68
|
+
url: image
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
upload: opts.uploadImage,
|
|
72
|
+
mediaTypeOverride: 'thumbnail-link',
|
|
73
|
+
options: opts.fetchOpts
|
|
49
74
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
|
|
61
|
-
upload: opts.uploadImage,
|
|
62
|
-
mediaTypeOverride: 'thumbnail-link',
|
|
63
|
-
options: opts.fetchOpts
|
|
64
|
-
});
|
|
65
|
-
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
|
|
66
|
-
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
try {
|
|
70
|
-
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return urlInfo;
|
|
75
|
+
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
|
|
76
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
77
|
+
} else {
|
|
78
|
+
try {
|
|
79
|
+
urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
opts.logger?.debug({
|
|
82
|
+
err: error.stack,
|
|
83
|
+
url: previewLink
|
|
84
|
+
}, 'error in generating thumbnail');
|
|
77
85
|
}
|
|
86
|
+
}
|
|
87
|
+
return urlInfo;
|
|
78
88
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (!error.message.includes('receive a valid')) {
|
|
91
|
+
throw error;
|
|
83
92
|
}
|
|
93
|
+
}
|
|
84
94
|
};
|
|
85
95
|
//# sourceMappingURL=link-preview.js.map
|
package/lib/Utils/logger.js
CHANGED
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -6,43 +6,47 @@ import { hkdf } from './crypto.js';
|
|
|
6
6
|
*/
|
|
7
7
|
const o = 128;
|
|
8
8
|
class LTHash {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
constructor(e) {
|
|
10
|
+
this.salt = e;
|
|
11
|
+
}
|
|
12
|
+
async add(e, t) {
|
|
13
|
+
for (const item of t) {
|
|
14
|
+
e = await this._addSingle(e, item);
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
return e;
|
|
17
|
+
}
|
|
18
|
+
async subtract(e, t) {
|
|
19
|
+
for (const item of t) {
|
|
20
|
+
e = await this._subtractSingle(e, item);
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return out;
|
|
22
|
+
return e;
|
|
23
|
+
}
|
|
24
|
+
async subtractThenAdd(e, addList, subtractList) {
|
|
25
|
+
const subtracted = await this.subtract(e, subtractList);
|
|
26
|
+
return this.add(subtracted, addList);
|
|
27
|
+
}
|
|
28
|
+
async _addSingle(e, t) {
|
|
29
|
+
const derived = new Uint8Array(await hkdf(Buffer.from(t), o, {
|
|
30
|
+
info: this.salt
|
|
31
|
+
})).buffer;
|
|
32
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a + b);
|
|
33
|
+
}
|
|
34
|
+
async _subtractSingle(e, t) {
|
|
35
|
+
const derived = new Uint8Array(await hkdf(Buffer.from(t), o, {
|
|
36
|
+
info: this.salt
|
|
37
|
+
})).buffer;
|
|
38
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a - b);
|
|
39
|
+
}
|
|
40
|
+
performPointwiseWithOverflow(e, t, op) {
|
|
41
|
+
const n = new DataView(e);
|
|
42
|
+
const i = new DataView(t);
|
|
43
|
+
const out = new ArrayBuffer(n.byteLength);
|
|
44
|
+
const s = new DataView(out);
|
|
45
|
+
for (let offset = 0; offset < n.byteLength; offset += 2) {
|
|
46
|
+
s.setUint16(offset, op(n.getUint16(offset, true), i.getUint16(offset, true)), true);
|
|
45
47
|
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
51
|
export const LT_HASH_ANTI_TAMPERING = new LTHash('WhatsApp Patch Integrity');
|
|
48
52
|
//# sourceMappingURL=lt-hash.js.map
|
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
1
|
export const makeMutex = () => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
finally {
|
|
20
|
-
clearTimeout(taskTimeout);
|
|
21
|
-
}
|
|
22
|
-
})();
|
|
23
|
-
// we replace the existing task, appending the new piece of execution to it
|
|
24
|
-
// so the next task will have to wait for this one to finish
|
|
25
|
-
return task;
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
|
+
let task = Promise.resolve();
|
|
4
|
+
let taskTimeout;
|
|
5
|
+
return {
|
|
6
|
+
mutex(code) {
|
|
7
|
+
task = (async () => {
|
|
8
|
+
// wait for the previous task to complete
|
|
9
|
+
// if there is an error, we swallow so as to not block the queue
|
|
10
|
+
try {
|
|
11
|
+
await task;
|
|
12
|
+
} catch {}
|
|
13
|
+
try {
|
|
14
|
+
// execute the current task
|
|
15
|
+
const result = await code();
|
|
16
|
+
return result;
|
|
17
|
+
} finally {
|
|
18
|
+
clearTimeout(taskTimeout);
|
|
26
19
|
}
|
|
27
|
-
|
|
20
|
+
})();
|
|
21
|
+
// we replace the existing task, appending the new piece of execution to it
|
|
22
|
+
// so the next task will have to wait for this one to finish
|
|
23
|
+
return task;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
28
26
|
};
|
|
29
27
|
export const makeKeyedMutex = () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
const map = {};
|
|
29
|
+
return {
|
|
30
|
+
mutex(key, task) {
|
|
31
|
+
if (!map[key]) {
|
|
32
|
+
map[key] = makeMutex();
|
|
33
|
+
}
|
|
34
|
+
return map[key].mutex(task);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
39
37
|
};
|
|
40
38
|
//# sourceMappingURL=make-mutex.js.map
|