@fanzxnothuman/baileys 2.0.17
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 +21 -0
- package/README.md +479 -0
- package/WAProto/index.js +204542 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +158 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Function/Download/tiktok.js +19 -0
- package/lib/Function/Tools/bypass.js +19 -0
- package/lib/Function/index.js +13 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +99 -0
- package/lib/Signal/Group/group_cipher.js +131 -0
- package/lib/Signal/Group/index.js +141 -0
- package/lib/Signal/Group/keyhelper.js +78 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +76 -0
- package/lib/Signal/Group/sender-key-message.js +86 -0
- package/lib/Signal/Group/sender-key-name.js +53 -0
- package/lib/Signal/Group/sender-key-record.js +71 -0
- package/lib/Signal/Group/sender-key-state.js +123 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +223 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +35 -0
- package/lib/Socket/Client/mobile-socket-client.js +96 -0
- package/lib/Socket/Client/web-socket-client.js +96 -0
- package/lib/Socket/business.js +289 -0
- package/lib/Socket/chats.js +1230 -0
- package/lib/Socket/dugong.js +689 -0
- package/lib/Socket/groups.js +401 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/messages-recv.js +1531 -0
- package/lib/Socket/messages-send.js +1011 -0
- package/lib/Socket/newsletter.js +526 -0
- package/lib/Socket/registration.js +212 -0
- package/lib/Socket/socket.js +842 -0
- package/lib/Socket/usync.js +67 -0
- package/lib/Store/index.js +16 -0
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.js +520 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +12 -0
- package/lib/Types/Message.js +14 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +67 -0
- package/lib/Utils/auth-utils.js +223 -0
- package/lib/Utils/baileys-event-stream.js +67 -0
- package/lib/Utils/business.js +308 -0
- package/lib/Utils/chat-utils.js +1030 -0
- package/lib/Utils/crypto.js +210 -0
- package/lib/Utils/decode-wa-message.js +225 -0
- package/lib/Utils/event-buffer.js +559 -0
- package/lib/Utils/generics.js +599 -0
- package/lib/Utils/history.js +132 -0
- package/lib/Utils/index.js +49 -0
- package/lib/Utils/link-preview.js +112 -0
- package/lib/Utils/logger.js +11 -0
- package/lib/Utils/lt-hash.js +58 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/messages-media.js +978 -0
- package/lib/Utils/messages.js +1052 -0
- package/lib/Utils/noise-handler.js +185 -0
- package/lib/Utils/process-message.js +466 -0
- package/lib/Utils/signal.js +199 -0
- package/lib/Utils/use-multi-file-auth-state.js +129 -0
- package/lib/Utils/validate-connection.js +285 -0
- package/lib/WABinary/constants.js +1307 -0
- package/lib/WABinary/decode.js +287 -0
- package/lib/WABinary/encode.js +286 -0
- package/lib/WABinary/generic-utils.js +227 -0
- package/lib/WABinary/index.js +37 -0
- package/lib/WABinary/jid-utils.js +92 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15260 -0
- package/lib/WAM/encode.js +153 -0
- package/lib/WAM/index.js +35 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +78 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +35 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +36 -0
- package/lib/WAUSync/USyncQuery.js +105 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.js +35 -0
- package/lib/index.js +65 -0
- package/package.json +109 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHistoryMsg =
|
|
4
|
+
exports.downloadAndProcessHistorySyncNotification =
|
|
5
|
+
exports.processHistoryMessage =
|
|
6
|
+
exports.downloadHistory =
|
|
7
|
+
void 0;
|
|
8
|
+
const util_1 = require("util");
|
|
9
|
+
const zlib_1 = require("zlib");
|
|
10
|
+
const WAProto_1 = require("../../WAProto");
|
|
11
|
+
const Types_1 = require("../Types");
|
|
12
|
+
const WABinary_1 = require("../WABinary");
|
|
13
|
+
const generics_1 = require("./generics");
|
|
14
|
+
const messages_1 = require("./messages");
|
|
15
|
+
const messages_media_1 = require("./messages-media");
|
|
16
|
+
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
17
|
+
const downloadHistory = async (msg, options) => {
|
|
18
|
+
const stream = await (0, messages_media_1.downloadContentFromMessage)(
|
|
19
|
+
msg,
|
|
20
|
+
"md-msg-hist",
|
|
21
|
+
{ options },
|
|
22
|
+
);
|
|
23
|
+
const bufferArray = [];
|
|
24
|
+
for await (const chunk of stream) {
|
|
25
|
+
bufferArray.push(chunk);
|
|
26
|
+
}
|
|
27
|
+
let buffer = Buffer.concat(bufferArray);
|
|
28
|
+
// decompress buffer
|
|
29
|
+
buffer = await inflatePromise(buffer);
|
|
30
|
+
const syncData = WAProto_1.proto.HistorySync.decode(buffer);
|
|
31
|
+
return syncData;
|
|
32
|
+
};
|
|
33
|
+
exports.downloadHistory = downloadHistory;
|
|
34
|
+
const processHistoryMessage = (item) => {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
const messages = [];
|
|
37
|
+
const contacts = [];
|
|
38
|
+
const chats = [];
|
|
39
|
+
switch (item.syncType) {
|
|
40
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
41
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
42
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
43
|
+
for (const chat of item.conversations) {
|
|
44
|
+
contacts.push({
|
|
45
|
+
id: chat.id,
|
|
46
|
+
name: chat.name || undefined,
|
|
47
|
+
lid: chat.lidJid || undefined,
|
|
48
|
+
jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined,
|
|
49
|
+
});
|
|
50
|
+
const msgs = chat.messages || [];
|
|
51
|
+
delete chat.messages;
|
|
52
|
+
delete chat.archived;
|
|
53
|
+
delete chat.muteEndTime;
|
|
54
|
+
delete chat.pinned;
|
|
55
|
+
for (const item of msgs) {
|
|
56
|
+
const message = item.message;
|
|
57
|
+
messages.push(message);
|
|
58
|
+
if (
|
|
59
|
+
!((_a = chat.messages) === null || _a === void 0
|
|
60
|
+
? void 0
|
|
61
|
+
: _a.length)
|
|
62
|
+
) {
|
|
63
|
+
// keep only the most recent message in the chat array
|
|
64
|
+
chat.messages = [{ message }];
|
|
65
|
+
}
|
|
66
|
+
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
67
|
+
chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(
|
|
68
|
+
message.messageTimestamp,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (
|
|
72
|
+
(message.messageStubType ===
|
|
73
|
+
Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
74
|
+
message.messageStubType ===
|
|
75
|
+
Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
|
|
76
|
+
((_b = message.messageStubParameters) === null || _b === void 0
|
|
77
|
+
? void 0
|
|
78
|
+
: _b[0])
|
|
79
|
+
) {
|
|
80
|
+
contacts.push({
|
|
81
|
+
id: message.key.participant || message.key.remoteJid,
|
|
82
|
+
verifiedName:
|
|
83
|
+
(_c = message.messageStubParameters) === null || _c === void 0
|
|
84
|
+
? void 0
|
|
85
|
+
: _c[0],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (
|
|
90
|
+
(0, WABinary_1.isJidUser)(chat.id) &&
|
|
91
|
+
chat.readOnly &&
|
|
92
|
+
chat.archived
|
|
93
|
+
) {
|
|
94
|
+
delete chat.readOnly;
|
|
95
|
+
}
|
|
96
|
+
chats.push({ ...chat });
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
100
|
+
for (const c of item.pushnames) {
|
|
101
|
+
contacts.push({ id: c.id, notify: c.pushname });
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
chats,
|
|
107
|
+
contacts,
|
|
108
|
+
messages,
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
exports.processHistoryMessage = processHistoryMessage;
|
|
112
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
113
|
+
const historyMsg = await (0, exports.downloadHistory)(msg, options);
|
|
114
|
+
return (0, exports.processHistoryMessage)(historyMsg);
|
|
115
|
+
};
|
|
116
|
+
exports.downloadAndProcessHistorySyncNotification =
|
|
117
|
+
downloadAndProcessHistorySyncNotification;
|
|
118
|
+
const getHistoryMsg = (message) => {
|
|
119
|
+
var _a;
|
|
120
|
+
const normalizedContent = !!message
|
|
121
|
+
? (0, messages_1.normalizeMessageContent)(message)
|
|
122
|
+
: undefined;
|
|
123
|
+
const anyHistoryMsg =
|
|
124
|
+
(_a =
|
|
125
|
+
normalizedContent === null || normalizedContent === void 0
|
|
126
|
+
? void 0
|
|
127
|
+
: normalizedContent.protocolMessage) === null || _a === void 0
|
|
128
|
+
? void 0
|
|
129
|
+
: _a.historySyncNotification;
|
|
130
|
+
return anyHistoryMsg;
|
|
131
|
+
};
|
|
132
|
+
exports.getHistoryMsg = getHistoryMsg;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __exportStar =
|
|
26
|
+
(this && this.__exportStar) ||
|
|
27
|
+
function (m, exports) {
|
|
28
|
+
for (var p in m)
|
|
29
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
+
__createBinding(exports, m, p);
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
__exportStar(require("./generics"), exports);
|
|
34
|
+
__exportStar(require("./decode-wa-message"), exports);
|
|
35
|
+
__exportStar(require("./messages"), exports);
|
|
36
|
+
__exportStar(require("./messages-media"), exports);
|
|
37
|
+
__exportStar(require("./validate-connection"), exports);
|
|
38
|
+
__exportStar(require("./crypto"), exports);
|
|
39
|
+
__exportStar(require("./signal"), exports);
|
|
40
|
+
__exportStar(require("./noise-handler"), exports);
|
|
41
|
+
__exportStar(require("./history"), exports);
|
|
42
|
+
__exportStar(require("./chat-utils"), exports);
|
|
43
|
+
__exportStar(require("./lt-hash"), exports);
|
|
44
|
+
__exportStar(require("./auth-utils"), exports);
|
|
45
|
+
__exportStar(require("./baileys-event-stream"), exports);
|
|
46
|
+
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
47
|
+
__exportStar(require("./link-preview"), exports);
|
|
48
|
+
__exportStar(require("./event-buffer"), exports);
|
|
49
|
+
__exportStar(require("./process-message"), exports);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUrlInfo = void 0;
|
|
4
|
+
const messages_1 = require("./messages");
|
|
5
|
+
const messages_media_1 = require("./messages-media");
|
|
6
|
+
const THUMBNAIL_WIDTH_PX = 192;
|
|
7
|
+
/** Fetches an image and generates a thumbnail for it */
|
|
8
|
+
const getCompressedJpegThumbnail = async (
|
|
9
|
+
url,
|
|
10
|
+
{ thumbnailWidth, fetchOpts },
|
|
11
|
+
) => {
|
|
12
|
+
const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts);
|
|
13
|
+
const result = await (0, messages_media_1.extractImageThumb)(
|
|
14
|
+
stream,
|
|
15
|
+
thumbnailWidth,
|
|
16
|
+
);
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
21
|
+
* Return undefined if the fetch failed or no URL was found
|
|
22
|
+
* @param text first matched URL in text
|
|
23
|
+
* @returns the URL info required to generate link preview
|
|
24
|
+
*/
|
|
25
|
+
const getUrlInfo = async (
|
|
26
|
+
text,
|
|
27
|
+
opts = {
|
|
28
|
+
thumbnailWidth: THUMBNAIL_WIDTH_PX,
|
|
29
|
+
fetchOpts: { timeout: 3000 },
|
|
30
|
+
},
|
|
31
|
+
) => {
|
|
32
|
+
var _a;
|
|
33
|
+
try {
|
|
34
|
+
// retries
|
|
35
|
+
const retries = 0;
|
|
36
|
+
const maxRetry = 5;
|
|
37
|
+
const { getLinkPreview } = await import("link-preview-js");
|
|
38
|
+
let previewLink = text;
|
|
39
|
+
if (!text.startsWith("https://") && !text.startsWith("http://")) {
|
|
40
|
+
previewLink = "https://" + previewLink;
|
|
41
|
+
}
|
|
42
|
+
const info = await getLinkPreview(previewLink, {
|
|
43
|
+
...opts.fetchOpts,
|
|
44
|
+
followRedirects: "follow",
|
|
45
|
+
handleRedirects: (baseURL, forwardedURL) => {
|
|
46
|
+
const urlObj = new URL(baseURL);
|
|
47
|
+
const forwardedURLObj = new URL(forwardedURL);
|
|
48
|
+
if (retries >= maxRetry) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (
|
|
52
|
+
forwardedURLObj.hostname === urlObj.hostname ||
|
|
53
|
+
forwardedURLObj.hostname === "www." + urlObj.hostname ||
|
|
54
|
+
"www." + forwardedURLObj.hostname === urlObj.hostname
|
|
55
|
+
) {
|
|
56
|
+
retries + 1;
|
|
57
|
+
return true;
|
|
58
|
+
} else {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
headers: opts.fetchOpts,
|
|
63
|
+
});
|
|
64
|
+
if (info && "title" in info && info.title) {
|
|
65
|
+
const [image] = info.images;
|
|
66
|
+
const urlInfo = {
|
|
67
|
+
"canonical-url": info.url,
|
|
68
|
+
"matched-text": text,
|
|
69
|
+
title: info.title,
|
|
70
|
+
description: info.description,
|
|
71
|
+
originalThumbnailUrl: image,
|
|
72
|
+
};
|
|
73
|
+
if (opts.uploadImage) {
|
|
74
|
+
const { imageMessage } = await (0, messages_1.prepareWAMessageMedia)(
|
|
75
|
+
{ image: { url: image } },
|
|
76
|
+
{
|
|
77
|
+
upload: opts.uploadImage,
|
|
78
|
+
mediaTypeOverride: "thumbnail-link",
|
|
79
|
+
options: opts.fetchOpts,
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
urlInfo.jpegThumbnail = (
|
|
83
|
+
imageMessage === null || imageMessage === void 0
|
|
84
|
+
? void 0
|
|
85
|
+
: imageMessage.jpegThumbnail
|
|
86
|
+
)
|
|
87
|
+
? Buffer.from(imageMessage.jpegThumbnail)
|
|
88
|
+
: undefined;
|
|
89
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
90
|
+
} else {
|
|
91
|
+
try {
|
|
92
|
+
urlInfo.jpegThumbnail = image
|
|
93
|
+
? (await getCompressedJpegThumbnail(image, opts)).buffer
|
|
94
|
+
: undefined;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
(_a = opts.logger) === null || _a === void 0
|
|
97
|
+
? void 0
|
|
98
|
+
: _a.debug(
|
|
99
|
+
{ err: error.stack, url: previewLink },
|
|
100
|
+
"error in generating thumbnail",
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return urlInfo;
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (!error.message.includes("receive a valid")) {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
exports.getUrlInfo = getUrlInfo;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const pino_1 = __importDefault(require("pino"));
|
|
9
|
+
exports.default = (0, pino_1.default)({
|
|
10
|
+
timestamp: () => `,"time":"${new Date().toJSON()}"`,
|
|
11
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LT_HASH_ANTI_TAMPERING = void 0;
|
|
4
|
+
const crypto_1 = require("./crypto");
|
|
5
|
+
/**
|
|
6
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
7
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
8
|
+
* if the same series of mutations was made sequentially.
|
|
9
|
+
*/
|
|
10
|
+
const o = 128;
|
|
11
|
+
class d {
|
|
12
|
+
constructor(e) {
|
|
13
|
+
this.salt = e;
|
|
14
|
+
}
|
|
15
|
+
add(e, t) {
|
|
16
|
+
var r = this;
|
|
17
|
+
for (const item of t) {
|
|
18
|
+
e = r._addSingle(e, item);
|
|
19
|
+
}
|
|
20
|
+
return e;
|
|
21
|
+
}
|
|
22
|
+
subtract(e, t) {
|
|
23
|
+
var r = this;
|
|
24
|
+
for (const item of t) {
|
|
25
|
+
e = r._subtractSingle(e, item);
|
|
26
|
+
}
|
|
27
|
+
return e;
|
|
28
|
+
}
|
|
29
|
+
subtractThenAdd(e, t, r) {
|
|
30
|
+
var n = this;
|
|
31
|
+
return n.add(n.subtract(e, r), t);
|
|
32
|
+
}
|
|
33
|
+
_addSingle(e, t) {
|
|
34
|
+
var r = this;
|
|
35
|
+
const n = new Uint8Array(
|
|
36
|
+
(0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt }),
|
|
37
|
+
).buffer;
|
|
38
|
+
return r.performPointwiseWithOverflow(e, n, (e, t) => e + t);
|
|
39
|
+
}
|
|
40
|
+
_subtractSingle(e, t) {
|
|
41
|
+
var r = this;
|
|
42
|
+
const n = new Uint8Array(
|
|
43
|
+
(0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt }),
|
|
44
|
+
).buffer;
|
|
45
|
+
return r.performPointwiseWithOverflow(e, n, (e, t) => e - t);
|
|
46
|
+
}
|
|
47
|
+
performPointwiseWithOverflow(e, t, r) {
|
|
48
|
+
const n = new DataView(e),
|
|
49
|
+
i = new DataView(t),
|
|
50
|
+
a = new ArrayBuffer(n.byteLength),
|
|
51
|
+
s = new DataView(a);
|
|
52
|
+
for (let e = 0; e < n.byteLength; e += 2) {
|
|
53
|
+
s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0);
|
|
54
|
+
}
|
|
55
|
+
return a;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.LT_HASH_ANTI_TAMPERING = new d("WhatsApp Patch Integrity");
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeKeyedMutex = exports.makeMutex = void 0;
|
|
4
|
+
const makeMutex = () => {
|
|
5
|
+
let task = Promise.resolve();
|
|
6
|
+
let taskTimeout;
|
|
7
|
+
return {
|
|
8
|
+
mutex(code) {
|
|
9
|
+
task = (async () => {
|
|
10
|
+
// wait for the previous task to complete
|
|
11
|
+
// if there is an error, we swallow so as to not block the queue
|
|
12
|
+
try {
|
|
13
|
+
await task;
|
|
14
|
+
} catch (_a) {}
|
|
15
|
+
try {
|
|
16
|
+
// execute the current task
|
|
17
|
+
const result = await code();
|
|
18
|
+
return result;
|
|
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;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.makeMutex = makeMutex;
|
|
30
|
+
const makeKeyedMutex = () => {
|
|
31
|
+
const map = {};
|
|
32
|
+
return {
|
|
33
|
+
mutex(key, task) {
|
|
34
|
+
if (!map[key]) {
|
|
35
|
+
map[key] = (0, exports.makeMutex)();
|
|
36
|
+
}
|
|
37
|
+
return map[key].mutex(task);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.makeKeyedMutex = makeKeyedMutex;
|