@pontalabs/baileys 1.0.11 → 1.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/README.md +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +2 -1
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
package/lib/Utils/history.js
CHANGED
|
@@ -1,104 +1,100 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const messages_1 = require("./messages")
|
|
12
|
-
const messages_media_1 = require("./messages-media")
|
|
13
|
-
const inflatePromise = util_1.promisify(zlib_1.inflate)
|
|
14
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { promisify: promisify } = require("util");
|
|
4
|
+
const { inflate: inflate } = require("zlib");
|
|
5
|
+
const { proto: proto } = require("../../WAProto");
|
|
6
|
+
const { WAMessageStubType: WAMessageStubType } = require("../Types");
|
|
7
|
+
const { toNumber: toNumber } = require("./generics");
|
|
8
|
+
const { normalizeMessageContent: normalizeMessageContent } = require("./messages");
|
|
9
|
+
const { downloadContentFromMessage: downloadContentFromMessage } = require("./messages-media");
|
|
10
|
+
const inflatePromise = promisify(inflate);
|
|
15
11
|
const downloadHistory = async (msg, options) => {
|
|
16
|
-
const stream = await
|
|
17
|
-
|
|
12
|
+
const stream = await downloadContentFromMessage(msg, "md-msg-hist", {
|
|
13
|
+
options: options,
|
|
14
|
+
});
|
|
15
|
+
const bufferArray = [];
|
|
18
16
|
for await (const chunk of stream) {
|
|
19
|
-
bufferArray.push(chunk)
|
|
17
|
+
bufferArray.push(chunk);
|
|
20
18
|
}
|
|
21
|
-
let buffer = Buffer.concat(bufferArray)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
19
|
+
let buffer = Buffer.concat(bufferArray);
|
|
20
|
+
buffer = await inflatePromise(buffer);
|
|
21
|
+
const syncData = proto.HistorySync.decode(buffer);
|
|
22
|
+
return syncData;
|
|
23
|
+
};
|
|
28
24
|
const processHistoryMessage = (item) => {
|
|
29
|
-
const messages = []
|
|
30
|
-
const contacts = []
|
|
31
|
-
const chats = []
|
|
25
|
+
const messages = [];
|
|
26
|
+
const contacts = [];
|
|
27
|
+
const chats = [];
|
|
32
28
|
switch (item.syncType) {
|
|
33
|
-
case
|
|
34
|
-
case
|
|
35
|
-
case
|
|
36
|
-
case
|
|
29
|
+
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
30
|
+
case proto.HistorySync.HistorySyncType.RECENT:
|
|
31
|
+
case proto.HistorySync.HistorySyncType.FULL:
|
|
32
|
+
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
37
33
|
for (const chat of item.conversations) {
|
|
38
34
|
contacts.push({
|
|
39
35
|
id: chat.id,
|
|
40
36
|
name: chat.name || undefined,
|
|
41
37
|
lid: chat.lidJid || undefined,
|
|
42
|
-
phoneNumber: chat.pnJid || undefined
|
|
43
|
-
})
|
|
44
|
-
const msgs = chat.messages || []
|
|
45
|
-
delete chat.messages
|
|
38
|
+
phoneNumber: chat.pnJid || undefined,
|
|
39
|
+
});
|
|
40
|
+
const msgs = chat.messages || [];
|
|
41
|
+
delete chat.messages;
|
|
46
42
|
for (const item of msgs) {
|
|
47
|
-
const message = item.message
|
|
48
|
-
messages.push(message)
|
|
43
|
+
const message = item.message;
|
|
44
|
+
messages.push(message);
|
|
49
45
|
if (!chat.messages?.length) {
|
|
50
|
-
|
|
51
|
-
chat.messages = [{ message }]
|
|
46
|
+
chat.messages = [{ message: message }];
|
|
52
47
|
}
|
|
53
48
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
54
|
-
chat.lastMessageRecvTimestamp =
|
|
49
|
+
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
55
50
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
if (
|
|
52
|
+
message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
53
|
+
(message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB &&
|
|
54
|
+
message.messageStubParameters?.[0])
|
|
55
|
+
) {
|
|
59
56
|
contacts.push({
|
|
60
57
|
id: message.key.participant || message.key.remoteJid,
|
|
61
|
-
verifiedName: message.messageStubParameters?.[0]
|
|
62
|
-
})
|
|
58
|
+
verifiedName: message.messageStubParameters?.[0],
|
|
59
|
+
});
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
chats.push({ ...chat })
|
|
62
|
+
chats.push({ ...chat });
|
|
66
63
|
}
|
|
67
|
-
break
|
|
68
|
-
case
|
|
64
|
+
break;
|
|
65
|
+
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
69
66
|
for (const c of item.pushnames) {
|
|
70
|
-
contacts.push({
|
|
71
|
-
id: c.id,
|
|
72
|
-
name: c.name || undefined,
|
|
73
|
-
lid: c.lidJid || undefined,
|
|
74
|
-
jid: WABinary_1.isJidUser(c.id) ? c.id : undefined
|
|
75
|
-
})
|
|
67
|
+
contacts.push({ id: c.id, notify: c.pushname });
|
|
76
68
|
}
|
|
77
|
-
break
|
|
69
|
+
break;
|
|
78
70
|
}
|
|
79
71
|
return {
|
|
80
|
-
chats,
|
|
81
|
-
contacts,
|
|
82
|
-
messages,
|
|
72
|
+
chats: chats,
|
|
73
|
+
contacts: contacts,
|
|
74
|
+
messages: messages,
|
|
83
75
|
syncType: item.syncType,
|
|
84
|
-
progress: item.progress
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
76
|
+
progress: item.progress,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
88
79
|
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
80
|
+
let historyMsg;
|
|
81
|
+
if (msg.initialHistBootstrapInlinePayload) {
|
|
82
|
+
historyMsg = proto.HistorySync.decode(
|
|
83
|
+
await inflatePromise(msg.initialHistBootstrapInlinePayload)
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
historyMsg = await downloadHistory(msg, options);
|
|
87
|
+
}
|
|
88
|
+
return processHistoryMessage(historyMsg);
|
|
89
|
+
};
|
|
93
90
|
const getHistoryMsg = (message) => {
|
|
94
|
-
const normalizedContent = !!message ?
|
|
95
|
-
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
|
|
96
|
-
return anyHistoryMsg
|
|
97
|
-
}
|
|
98
|
-
|
|
91
|
+
const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
|
|
92
|
+
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
|
|
93
|
+
return anyHistoryMsg;
|
|
94
|
+
};
|
|
99
95
|
module.exports = {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
96
|
+
downloadHistory: downloadHistory,
|
|
97
|
+
processHistoryMessage: processHistoryMessage,
|
|
98
|
+
downloadAndProcessHistorySyncNotification: downloadAndProcessHistorySyncNotification,
|
|
99
|
+
getHistoryMsg: getHistoryMsg,
|
|
100
|
+
};
|
package/lib/Utils/index.js
CHANGED
|
@@ -1,41 +1,49 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
__exportStar
|
|
23
|
-
__exportStar
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
__exportStar(require("./
|
|
33
|
-
__exportStar(require("./
|
|
34
|
-
__exportStar(require("./
|
|
35
|
-
__exportStar(require("./
|
|
36
|
-
__exportStar(require("./
|
|
37
|
-
__exportStar(require("./
|
|
38
|
-
__exportStar(require("./
|
|
39
|
-
__exportStar(require("./
|
|
40
|
-
__exportStar(require("./
|
|
41
|
-
__exportStar(require("./
|
|
1
|
+
"use strict";
|
|
2
|
+
const __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
let desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
const __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m) {
|
|
26
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
27
|
+
__createBinding(exports, m, p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./generics"), exports);
|
|
33
|
+
__exportStar(require("./decode-wa-message"), exports);
|
|
34
|
+
__exportStar(require("./messages"), exports);
|
|
35
|
+
__exportStar(require("./messages-media"), exports);
|
|
36
|
+
__exportStar(require("./message-retry-manager"), 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("./browser-utils"), 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);
|
|
@@ -1,120 +1,76 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
|
-
|
|
31
|
-
const messages_1 = require("./messages")
|
|
32
|
-
const messages_media_1 = require("./messages-media")
|
|
33
|
-
const THUMBNAIL_WIDTH_PX = 192
|
|
34
|
-
|
|
35
|
-
/** Fetches an image and generates a thumbnail for it */
|
|
36
|
-
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
37
|
-
const stream = await messages_media_1.getHttpStream(url, fetchOpts)
|
|
38
|
-
const result = await messages_media_1.extractImageThumb(stream, thumbnailWidth)
|
|
39
|
-
return result
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
44
|
-
* Return undefined if the fetch failed or no URL was found
|
|
45
|
-
* @param text first matched URL in text
|
|
46
|
-
* @returns the URL info required to generate link preview
|
|
47
|
-
*/
|
|
48
|
-
const getUrlInfo = async (text, opts = { thumbnailWidth: THUMBNAIL_WIDTH_PX, fetchOpts: { timeout: 3000 }}) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { unfurl: unfurl } = require("unfurl.js");
|
|
4
|
+
const { prepareWAMessageMedia: prepareWAMessageMedia } = require("./messages");
|
|
5
|
+
const {
|
|
6
|
+
getHttpStream: getHttpStream,
|
|
7
|
+
extractImageThumb: extractImageThumb,
|
|
8
|
+
} = require("./messages-media");
|
|
9
|
+
const THUMBNAIL_WIDTH_PX = 192;
|
|
10
|
+
const getCompressedJpegThumbnail = async (
|
|
11
|
+
url,
|
|
12
|
+
{ thumbnailWidth: thumbnailWidth, fetchOpts: fetchOpts }
|
|
13
|
+
) => {
|
|
14
|
+
const stream = await getHttpStream(url, fetchOpts);
|
|
15
|
+
const result = await extractImageThumb(stream, thumbnailWidth);
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
const getUrlInfo = async (
|
|
19
|
+
text,
|
|
20
|
+
opts = { thumbnailWidth: THUMBNAIL_WIDTH_PX, fetchOpts: { timeout: 3e3 } }
|
|
21
|
+
) => {
|
|
49
22
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
let previewLink = text
|
|
54
|
-
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
|
55
|
-
previewLink = 'https://' + previewLink
|
|
23
|
+
let previewLink = text;
|
|
24
|
+
if (!text.startsWith("https://") && !text.startsWith("http://")) {
|
|
25
|
+
previewLink = "https://" + previewLink;
|
|
56
26
|
}
|
|
57
|
-
const info = await
|
|
27
|
+
const { open_graph: info } = await unfurl(previewLink, {
|
|
58
28
|
...opts.fetchOpts,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (forwardedURLObj.hostname === urlObj.hostname
|
|
67
|
-
|| forwardedURLObj.hostname === 'www.' + urlObj.hostname
|
|
68
|
-
|| 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
|
|
69
|
-
retries + 1
|
|
70
|
-
return true
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return false
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
headers: opts.fetchOpts
|
|
77
|
-
})
|
|
78
|
-
if (info && 'title' in info && info.title) {
|
|
79
|
-
const [image] = info.images
|
|
29
|
+
oembed: false,
|
|
30
|
+
compress: true,
|
|
31
|
+
size: 0,
|
|
32
|
+
follow: 50,
|
|
33
|
+
});
|
|
34
|
+
if (info && "title" in info && info.title) {
|
|
35
|
+
const image = info.images?.[0]?.url;
|
|
80
36
|
const urlInfo = {
|
|
81
|
-
|
|
82
|
-
|
|
37
|
+
"canonical-url": info.url,
|
|
38
|
+
"matched-text": text,
|
|
83
39
|
title: info.title,
|
|
84
40
|
description: info.description,
|
|
85
|
-
originalThumbnailUrl: image
|
|
86
|
-
}
|
|
41
|
+
originalThumbnailUrl: image,
|
|
42
|
+
};
|
|
87
43
|
if (opts.uploadImage) {
|
|
88
|
-
const { imageMessage } = await
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
44
|
+
const { imageMessage: imageMessage } = await prepareWAMessageMedia(
|
|
45
|
+
{ image: { url: image } },
|
|
46
|
+
{
|
|
47
|
+
upload: opts.uploadImage,
|
|
48
|
+
mediaTypeOverride: "thumbnail-link",
|
|
49
|
+
options: opts.fetchOpts,
|
|
50
|
+
}
|
|
51
|
+
);
|
|
93
52
|
urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
|
|
94
53
|
? Buffer.from(imageMessage.jpegThumbnail)
|
|
95
|
-
: undefined
|
|
96
|
-
urlInfo.highQualityThumbnail = imageMessage || undefined
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
54
|
+
: undefined;
|
|
55
|
+
urlInfo.highQualityThumbnail = imageMessage || undefined;
|
|
56
|
+
} else {
|
|
99
57
|
try {
|
|
100
58
|
urlInfo.jpegThumbnail = image
|
|
101
59
|
? (await getCompressedJpegThumbnail(image, opts)).buffer
|
|
102
|
-
: undefined
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
60
|
+
: undefined;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
opts.logger?.debug(
|
|
63
|
+
{ err: error.stack, url: previewLink },
|
|
64
|
+
"error in generating thumbnail"
|
|
65
|
+
);
|
|
106
66
|
}
|
|
107
67
|
}
|
|
108
|
-
return urlInfo
|
|
68
|
+
return urlInfo;
|
|
109
69
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
throw error
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (!error.message.includes("receive a valid")) {
|
|
72
|
+
throw error;
|
|
114
73
|
}
|
|
115
74
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = {
|
|
119
|
-
getUrlInfo
|
|
120
|
-
}
|
|
75
|
+
};
|
|
76
|
+
module.exports = { getUrlInfo: getUrlInfo };
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
6
|
-
const pino_1 = __importDefault(require("pino"))
|
|
7
|
-
exports.default = pino_1.default({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pino = require("pino");
|
|
4
|
+
exports.default = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
|
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -1,58 +1,45 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
9
|
-
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
10
|
-
* if the same series of mutations was made sequentially.
|
|
11
|
-
*/
|
|
12
|
-
const o = 128
|
|
13
|
-
class d {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { hkdf: hkdf } = require("./crypto");
|
|
4
|
+
const o = 128;
|
|
5
|
+
class LTHash {
|
|
14
6
|
constructor(e) {
|
|
15
|
-
this.salt = e
|
|
7
|
+
this.salt = e;
|
|
16
8
|
}
|
|
17
|
-
add(e, t) {
|
|
18
|
-
var r = this
|
|
9
|
+
async add(e, t) {
|
|
19
10
|
for (const item of t) {
|
|
20
|
-
e =
|
|
11
|
+
e = await this._addSingle(e, item);
|
|
21
12
|
}
|
|
22
|
-
return e
|
|
13
|
+
return e;
|
|
23
14
|
}
|
|
24
|
-
subtract(e, t) {
|
|
25
|
-
var r = this
|
|
15
|
+
async subtract(e, t) {
|
|
26
16
|
for (const item of t) {
|
|
27
|
-
e =
|
|
17
|
+
e = await this._subtractSingle(e, item);
|
|
28
18
|
}
|
|
29
|
-
return e
|
|
19
|
+
return e;
|
|
30
20
|
}
|
|
31
|
-
subtractThenAdd(e,
|
|
32
|
-
|
|
33
|
-
return
|
|
21
|
+
async subtractThenAdd(e, addList, subtractList) {
|
|
22
|
+
const subtracted = await this.subtract(e, subtractList);
|
|
23
|
+
return this.add(subtracted, addList);
|
|
34
24
|
}
|
|
35
25
|
async _addSingle(e, t) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t))
|
|
26
|
+
const derived = new Uint8Array(await hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
27
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a + b);
|
|
39
28
|
}
|
|
40
29
|
async _subtractSingle(e, t) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t))
|
|
30
|
+
const derived = new Uint8Array(await hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
31
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a - b);
|
|
44
32
|
}
|
|
45
|
-
performPointwiseWithOverflow(e, t,
|
|
46
|
-
const n = new DataView(e)
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
performPointwiseWithOverflow(e, t, op) {
|
|
34
|
+
const n = new DataView(e);
|
|
35
|
+
const i = new DataView(t);
|
|
36
|
+
const out = new ArrayBuffer(n.byteLength);
|
|
37
|
+
const s = new DataView(out);
|
|
38
|
+
for (let offset = 0; offset < n.byteLength; offset += 2) {
|
|
39
|
+
s.setUint16(offset, op(n.getUint16(offset, true), i.getUint16(offset, true)), true);
|
|
49
40
|
}
|
|
50
|
-
return
|
|
41
|
+
return out;
|
|
51
42
|
}
|
|
52
43
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
module.exports = {
|
|
57
|
-
LT_HASH_ANTI_TAMPERING
|
|
58
|
-
}
|
|
44
|
+
const LT_HASH_ANTI_TAMPERING = new LTHash("WhatsApp Patch Integrity");
|
|
45
|
+
module.exports = { LT_HASH_ANTI_TAMPERING: LT_HASH_ANTI_TAMPERING };
|
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -1,49 +1,33 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { Mutex: AsyncMutex } = require("async-mutex");
|
|
5
4
|
const makeMutex = () => {
|
|
6
|
-
|
|
7
|
-
let task = Promise.resolve()
|
|
8
|
-
let taskTimeout
|
|
5
|
+
const mutex = new AsyncMutex();
|
|
9
6
|
return {
|
|
10
7
|
mutex(code) {
|
|
11
|
-
|
|
12
|
-
// wait for the previous task to complete
|
|
13
|
-
// if there is an error, we swallow so as to not block the queue
|
|
14
|
-
try {
|
|
15
|
-
await task
|
|
16
|
-
}
|
|
17
|
-
catch (_a) { }
|
|
18
|
-
try {
|
|
19
|
-
// execute the current task
|
|
20
|
-
const result = await code()
|
|
21
|
-
return result
|
|
22
|
-
}
|
|
23
|
-
finally {
|
|
24
|
-
clearTimeout(taskTimeout)
|
|
25
|
-
}
|
|
26
|
-
})()
|
|
27
|
-
// we replace the existing task, appending the new piece of execution to it
|
|
28
|
-
// so the next task will have to wait for this one to finish
|
|
29
|
-
return task
|
|
8
|
+
return mutex.runExclusive(code);
|
|
30
9
|
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
10
|
+
};
|
|
11
|
+
};
|
|
34
12
|
const makeKeyedMutex = () => {
|
|
35
|
-
const map =
|
|
13
|
+
const map = new Map();
|
|
36
14
|
return {
|
|
37
|
-
mutex(key, task) {
|
|
38
|
-
|
|
39
|
-
|
|
15
|
+
async mutex(key, task) {
|
|
16
|
+
let entry = map.get(key);
|
|
17
|
+
if (!entry) {
|
|
18
|
+
entry = { mutex: new AsyncMutex(), refCount: 0 };
|
|
19
|
+
map.set(key, entry);
|
|
40
20
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
21
|
+
entry.refCount++;
|
|
22
|
+
try {
|
|
23
|
+
return await entry.mutex.runExclusive(task);
|
|
24
|
+
} finally {
|
|
25
|
+
entry.refCount--;
|
|
26
|
+
if (entry.refCount === 0 && map.get(key) === entry) {
|
|
27
|
+
map.delete(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
module.exports = { makeMutex: makeMutex, makeKeyedMutex: makeKeyedMutex };
|