@nexustechpro/baileys 2.0.1 → 2.0.5
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/README.md +924 -1299
- package/lib/Defaults/baileys-version.json +6 -2
- package/lib/Defaults/index.js +172 -172
- package/lib/Signal/libsignal.js +380 -292
- package/lib/Signal/lid-mapping.js +264 -171
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.js +10 -10
- package/lib/Socket/Client/websocket.js +45 -310
- package/lib/Socket/business.js +375 -375
- package/lib/Socket/chats.js +909 -963
- package/lib/Socket/communities.js +430 -430
- package/lib/Socket/groups.js +342 -342
- package/lib/Socket/index.js +22 -22
- package/lib/Socket/messages-recv.js +777 -743
- package/lib/Socket/messages-send.js +667 -393
- package/lib/Socket/mex.js +50 -50
- package/lib/Socket/newsletter.js +148 -148
- package/lib/Socket/nexus-handler.js +75 -261
- package/lib/Socket/socket.js +709 -1201
- package/lib/Store/index.js +5 -5
- package/lib/Store/make-cache-manager-store.js +81 -81
- package/lib/Store/make-in-memory-store.js +416 -416
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- package/lib/Types/Auth.js +1 -1
- package/lib/Types/Bussines.js +1 -1
- package/lib/Types/Call.js +1 -1
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Contact.js +1 -1
- package/lib/Types/Events.js +1 -1
- package/lib/Types/GroupMetadata.js +1 -1
- package/lib/Types/Label.js +24 -24
- package/lib/Types/LabelAssociation.js +6 -6
- package/lib/Types/Message.js +10 -10
- package/lib/Types/Newsletter.js +28 -28
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -12
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +25 -25
- package/lib/Utils/auth-utils.js +264 -256
- package/lib/Utils/baileys-event-stream.js +55 -55
- package/lib/Utils/browser-utils.js +27 -27
- package/lib/Utils/business.js +228 -230
- package/lib/Utils/chat-utils.js +694 -764
- package/lib/Utils/crypto.js +109 -135
- package/lib/Utils/decode-wa-message.js +310 -314
- package/lib/Utils/event-buffer.js +547 -547
- package/lib/Utils/generics.js +297 -297
- package/lib/Utils/history.js +91 -83
- package/lib/Utils/index.js +21 -20
- package/lib/Utils/key-store.js +17 -0
- package/lib/Utils/link-preview.js +97 -88
- package/lib/Utils/logger.js +2 -2
- package/lib/Utils/lt-hash.js +47 -47
- package/lib/Utils/make-mutex.js +39 -39
- package/lib/Utils/message-retry-manager.js +148 -148
- package/lib/Utils/messages-media.js +534 -532
- package/lib/Utils/messages.js +705 -705
- package/lib/Utils/noise-handler.js +255 -255
- package/lib/Utils/pre-key-manager.js +105 -105
- package/lib/Utils/process-message.js +412 -412
- package/lib/Utils/signal.js +160 -158
- package/lib/Utils/use-multi-file-auth-state.js +120 -120
- package/lib/Utils/validate-connection.js +194 -194
- package/lib/WABinary/constants.js +1300 -1300
- package/lib/WABinary/decode.js +237 -237
- package/lib/WABinary/encode.js +232 -232
- package/lib/WABinary/generic-utils.js +252 -211
- package/lib/WABinary/index.js +5 -5
- package/lib/WABinary/jid-utils.js +279 -95
- package/lib/WABinary/types.js +1 -1
- package/lib/WAM/BinaryInfo.js +9 -9
- package/lib/WAM/constants.js +22852 -22852
- package/lib/WAM/encode.js +149 -149
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
- package/lib/WAUSync/Protocols/index.js +4 -4
- package/lib/WAUSync/USyncQuery.js +93 -93
- package/lib/WAUSync/USyncUser.js +22 -22
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +171 -144
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -100
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-message-key.js +0 -26
package/lib/Utils/history.js
CHANGED
|
@@ -1,84 +1,92 @@
|
|
|
1
|
-
import { promisify } from 'util';
|
|
2
|
-
import { inflate } from 'zlib';
|
|
3
|
-
import { proto } from '../../WAProto/index.js';
|
|
4
|
-
import { WAMessageStubType } from '../Types/index.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
case proto.HistorySync.HistorySyncType.
|
|
28
|
-
case proto.HistorySync.HistorySyncType.
|
|
29
|
-
case proto.HistorySync.HistorySyncType.
|
|
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
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import { inflate } from 'zlib';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { WAMessageStubType } from '../Types/index.js';
|
|
5
|
+
import { isJidUser } from '../WABinary/index.js';
|
|
6
|
+
import { toNumber } from './generics.js';
|
|
7
|
+
import { normalizeMessageContent } from './messages.js';
|
|
8
|
+
import { downloadContentFromMessage } from './messages-media.js';
|
|
9
|
+
const inflatePromise = promisify(inflate);
|
|
10
|
+
export const downloadHistory = async (msg, options) => {
|
|
11
|
+
const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options });
|
|
12
|
+
const bufferArray = [];
|
|
13
|
+
for await (const chunk of stream) {
|
|
14
|
+
bufferArray.push(chunk);
|
|
15
|
+
}
|
|
16
|
+
let buffer = Buffer.concat(bufferArray);
|
|
17
|
+
// decompress buffer
|
|
18
|
+
buffer = await inflatePromise(buffer);
|
|
19
|
+
const syncData = proto.HistorySync.decode(buffer);
|
|
20
|
+
return syncData;
|
|
21
|
+
};
|
|
22
|
+
export const processHistoryMessage = (item) => {
|
|
23
|
+
const messages = [];
|
|
24
|
+
const contacts = [];
|
|
25
|
+
const chats = [];
|
|
26
|
+
switch (item.syncType) {
|
|
27
|
+
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
28
|
+
case proto.HistorySync.HistorySyncType.RECENT:
|
|
29
|
+
case proto.HistorySync.HistorySyncType.FULL:
|
|
30
|
+
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
31
|
+
for (const chat of item.conversations) {
|
|
32
|
+
contacts.push({
|
|
33
|
+
id: chat.id,
|
|
34
|
+
name: chat.name || undefined,
|
|
35
|
+
lid: chat.lidJid || undefined,
|
|
36
|
+
phoneNumber: chat.pnJid || undefined,
|
|
37
|
+
jid: isJidUser(chat.id) ? chat.id : undefined
|
|
38
|
+
});
|
|
39
|
+
const msgs = chat.messages || [];
|
|
40
|
+
delete chat.messages;
|
|
41
|
+
delete chat.archived;
|
|
42
|
+
delete chat.muteEndTime;
|
|
43
|
+
delete chat.pinned;
|
|
44
|
+
for (const item of msgs) {
|
|
45
|
+
const message = item.message;
|
|
46
|
+
messages.push(message);
|
|
47
|
+
if (!chat.messages?.length) {
|
|
48
|
+
// keep only the most recent message in the chat array
|
|
49
|
+
chat.messages = [{ message }];
|
|
50
|
+
}
|
|
51
|
+
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
52
|
+
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
53
|
+
}
|
|
54
|
+
if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
55
|
+
message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
|
|
56
|
+
message.messageStubParameters?.[0]) {
|
|
57
|
+
contacts.push({
|
|
58
|
+
id: message.key.participant || message.key.remoteJid,
|
|
59
|
+
verifiedName: message.messageStubParameters?.[0]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (isJidUser(chat.id) && chat.readOnly && chat.archived) {
|
|
64
|
+
delete chat.readOnly;
|
|
65
|
+
}
|
|
66
|
+
chats.push({ ...chat });
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
70
|
+
for (const c of item.pushnames) {
|
|
71
|
+
contacts.push({ id: c.id, notify: c.pushname });
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
chats,
|
|
77
|
+
contacts,
|
|
78
|
+
messages,
|
|
79
|
+
syncType: item.syncType,
|
|
80
|
+
progress: item.progress
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
84
|
+
const historyMsg = await downloadHistory(msg, options);
|
|
85
|
+
return processHistoryMessage(historyMsg);
|
|
86
|
+
};
|
|
87
|
+
export const getHistoryMsg = (message) => {
|
|
88
|
+
const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
|
|
89
|
+
const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
|
|
90
|
+
return anyHistoryMsg;
|
|
91
|
+
};
|
|
84
92
|
//# sourceMappingURL=history.js.map
|
package/lib/Utils/index.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
export * from './generics.js';
|
|
2
|
-
export * from './decode-wa-message.js';
|
|
3
|
-
export * from './messages.js';
|
|
4
|
-
export * from './messages-media.js';
|
|
5
|
-
export * from './validate-connection.js';
|
|
6
|
-
export * from './crypto.js';
|
|
7
|
-
export * from './signal.js';
|
|
8
|
-
export * from './noise-handler.js';
|
|
9
|
-
export * from './history.js';
|
|
10
|
-
export * from './chat-utils.js';
|
|
11
|
-
export * from './lt-hash.js';
|
|
12
|
-
export * from './auth-utils.js';
|
|
13
|
-
export * from './baileys-event-stream.js';
|
|
14
|
-
export * from './use-multi-file-auth-state.js';
|
|
15
|
-
export * from './link-preview.js';
|
|
16
|
-
export * from './event-buffer.js';
|
|
17
|
-
export * from './process-message.js';
|
|
18
|
-
export * from './message-retry-manager.js';
|
|
19
|
-
export * from './browser-utils.js';
|
|
20
|
-
export * from './identity-chnage-handler.js';
|
|
1
|
+
export * from './generics.js';
|
|
2
|
+
export * from './decode-wa-message.js';
|
|
3
|
+
export * from './messages.js';
|
|
4
|
+
export * from './messages-media.js';
|
|
5
|
+
export * from './validate-connection.js';
|
|
6
|
+
export * from './crypto.js';
|
|
7
|
+
export * from './signal.js';
|
|
8
|
+
export * from './noise-handler.js';
|
|
9
|
+
export * from './history.js';
|
|
10
|
+
export * from './chat-utils.js';
|
|
11
|
+
export * from './lt-hash.js';
|
|
12
|
+
export * from './auth-utils.js';
|
|
13
|
+
export * from './baileys-event-stream.js';
|
|
14
|
+
export * from './use-multi-file-auth-state.js';
|
|
15
|
+
export * from './link-preview.js';
|
|
16
|
+
export * from './event-buffer.js';
|
|
17
|
+
export * from './process-message.js';
|
|
18
|
+
export * from './message-retry-manager.js';
|
|
19
|
+
export * from './browser-utils.js';
|
|
20
|
+
export * from './identity-chnage-handler.js';
|
|
21
|
+
export * from './key-store.js';
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// ─── Key Store Helpers ─────────────────────────────────────────────────────────
|
|
2
|
+
// Single source of truth for blob key names — change here, changes everywhere
|
|
3
|
+
export const SESSION_INDEX_KEY = 'index'
|
|
4
|
+
export const DEVICE_LIST_INDEX_KEY = 'index'
|
|
5
|
+
|
|
6
|
+
// Migrates old _index blob to new index key in-place, returns the batch data
|
|
7
|
+
export const migrateIndexKey = async (keys, type) => {
|
|
8
|
+
const oldKey = '_index'
|
|
9
|
+
const newKey = 'index'
|
|
10
|
+
const oldData = await keys.get(type, [oldKey])
|
|
11
|
+
if (oldData?.[oldKey] && typeof oldData[oldKey] === 'object') { // only migrate if old blob actually exists and has data
|
|
12
|
+
await keys.set({ [type]: { [newKey]: oldData[oldKey], [oldKey]: null } })
|
|
13
|
+
return oldData[oldKey]
|
|
14
|
+
}
|
|
15
|
+
const newData = await keys.get(type, [newKey])
|
|
16
|
+
return newData?.[newKey] || {}
|
|
17
|
+
}
|
|
@@ -1,89 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
1
|
+
import { getLinkPreview } from 'link-preview-js'
|
|
2
|
+
import { prepareWAMessageMedia } from './messages.js'
|
|
3
|
+
import { extractImageThumb, getHttpStream } from './messages-media.js'
|
|
4
|
+
|
|
5
|
+
const THUMBNAIL_WIDTH_PX = 192
|
|
6
|
+
const MAX_REDIRECTS = 5
|
|
7
|
+
const PREVIEW_TIMEOUT = 5000
|
|
8
|
+
// Concurrency pool — max simultaneous link preview fetches
|
|
9
|
+
const MAX_CONCURRENT = 20
|
|
10
|
+
let _active = 0
|
|
11
|
+
const _queue = []
|
|
12
|
+
const _drain = () => {
|
|
13
|
+
if (_queue.length === 0 || _active >= MAX_CONCURRENT) return
|
|
14
|
+
_active++
|
|
15
|
+
const { fn, resolve, reject } = _queue.shift()
|
|
16
|
+
fn().then(resolve).catch(reject).finally(() => { _active--; _drain() })
|
|
17
|
+
}
|
|
18
|
+
const _enqueue = fn => new Promise((resolve, reject) => { _queue.push({ fn, resolve, reject }); _drain() })
|
|
19
|
+
|
|
20
|
+
/** Fetches a remote image and compresses it to a JPEG thumbnail buffer */
|
|
21
|
+
const _compressedThumb = async (url, opts) => {
|
|
22
|
+
const stream = await getHttpStream(url, opts.fetchOpts)
|
|
23
|
+
const result = await extractImageThumb(stream, opts.thumbnailWidth ?? THUMBNAIL_WIDTH_PX)
|
|
24
|
+
return result.buffer
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Resolves jpegThumbnail + highQualityThumbnail from an image URL, never throws */
|
|
28
|
+
const _resolveThumbnail = async (image, opts) => {
|
|
29
|
+
if (!image) return {}
|
|
30
|
+
if (opts.uploadImage) {
|
|
31
|
+
try {
|
|
32
|
+
const { imageMessage } = await prepareWAMessageMedia(
|
|
33
|
+
{ image: { url: image } },
|
|
34
|
+
{ upload: opts.uploadImage, mediaTypeOverride: 'thumbnail-link', options: opts.fetchOpts }
|
|
35
|
+
)
|
|
36
|
+
return {
|
|
37
|
+
jpegThumbnail: imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined,
|
|
38
|
+
highQualityThumbnail: imageMessage ?? undefined
|
|
39
|
+
}
|
|
40
|
+
} catch (err) {
|
|
41
|
+
opts.logger?.warn({ err: err.message, url: image }, 'upload failed, falling back to compressed thumb')
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Fallback: local compression (also used when no uploadImage provided)
|
|
45
|
+
try {
|
|
46
|
+
return { jpegThumbnail: await _compressedThumb(image, opts) }
|
|
47
|
+
} catch (err) {
|
|
48
|
+
opts.logger?.debug({ err: err.stack }, 'compressed thumb failed')
|
|
49
|
+
return {}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Extracts link preview info from a text string or URL.
|
|
55
|
+
* Queued for concurrency control — never throws on preview failure.
|
|
56
|
+
* @param {string} text - Raw text or URL to preview
|
|
57
|
+
* @param {object} opts - Options: thumbnailWidth, fetchOpts, uploadImage, logger
|
|
58
|
+
* @returns {Promise<object|undefined>} urlInfo or undefined if no valid URL/title found
|
|
59
|
+
*/
|
|
60
|
+
export const getUrlInfo = (text, opts = {}) => _enqueue(async () => {
|
|
61
|
+
const fetchOpts = opts.fetchOpts ?? { timeout: PREVIEW_TIMEOUT }
|
|
62
|
+
const thumbnailWidth = opts.thumbnailWidth ?? THUMBNAIL_WIDTH_PX
|
|
63
|
+
const resolvedOpts = { ...opts, fetchOpts, thumbnailWidth }
|
|
64
|
+
try {
|
|
65
|
+
let retries = 0
|
|
66
|
+
const previewLink = (text.startsWith('https://') || text.startsWith('http://')) ? text : 'https://' + text
|
|
67
|
+
const info = await getLinkPreview(previewLink, {
|
|
68
|
+
...fetchOpts,
|
|
69
|
+
followRedirects: 'manual',
|
|
70
|
+
handleRedirects: (baseURL, forwardedURL) => {
|
|
71
|
+
if (retries >= MAX_REDIRECTS) return false
|
|
72
|
+
const base = new URL(baseURL)
|
|
73
|
+
const fwd = new URL(forwardedURL)
|
|
74
|
+
const sameHost = fwd.hostname === base.hostname || fwd.hostname === 'www.' + base.hostname || 'www.' + fwd.hostname === base.hostname
|
|
75
|
+
if (sameHost) { retries++; return true }
|
|
76
|
+
return false
|
|
77
|
+
},
|
|
78
|
+
headers: fetchOpts.headers
|
|
79
|
+
})
|
|
80
|
+
if (!info || !('title' in info) || !info.title) return undefined
|
|
81
|
+
const [image] = info.images ?? []
|
|
82
|
+
const thumbs = await _resolveThumbnail(image, resolvedOpts)
|
|
83
|
+
return {
|
|
84
|
+
'canonical-url': info.url,
|
|
85
|
+
'matched-text': text,
|
|
86
|
+
title: info.title,
|
|
87
|
+
description: info.description,
|
|
88
|
+
originalThumbnailUrl: image,
|
|
89
|
+
...thumbs
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
// Suppress "no valid URL" and missing module errors; re-throw everything else
|
|
93
|
+
if (!err.message?.includes('receive a valid') && err.code !== 'ERR_MODULE_NOT_FOUND' && err.code !== 'MODULE_NOT_FOUND') {
|
|
94
|
+
throw err
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
})
|
|
89
98
|
//# sourceMappingURL=link-preview.js.map
|
package/lib/Utils/logger.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import P from 'pino';
|
|
2
|
-
export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
|
|
1
|
+
import P from 'pino';
|
|
2
|
+
export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
|
|
3
3
|
//# sourceMappingURL=logger.js.map
|
package/lib/Utils/lt-hash.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { hkdf } from './crypto.js';
|
|
2
|
-
/**
|
|
3
|
-
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
4
|
-
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
5
|
-
* if the same series of mutations was made sequentially.
|
|
6
|
-
*/
|
|
7
|
-
const o = 128;
|
|
8
|
-
class LTHash {
|
|
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);
|
|
15
|
-
}
|
|
16
|
-
return e;
|
|
17
|
-
}
|
|
18
|
-
async subtract(e, t) {
|
|
19
|
-
for (const item of t) {
|
|
20
|
-
e = await this._subtractSingle(e, item);
|
|
21
|
-
}
|
|
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(hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
30
|
-
return this.performPointwiseWithOverflow(e, derived, (a, b) => a + b);
|
|
31
|
-
}
|
|
32
|
-
async _subtractSingle(e, t) {
|
|
33
|
-
const derived = new Uint8Array(hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
34
|
-
return this.performPointwiseWithOverflow(e, derived, (a, b) => a - b);
|
|
35
|
-
}
|
|
36
|
-
performPointwiseWithOverflow(e, t, op) {
|
|
37
|
-
const n = new DataView(e);
|
|
38
|
-
const i = new DataView(t);
|
|
39
|
-
const out = new ArrayBuffer(n.byteLength);
|
|
40
|
-
const s = new DataView(out);
|
|
41
|
-
for (let offset = 0; offset < n.byteLength; offset += 2) {
|
|
42
|
-
s.setUint16(offset, op(n.getUint16(offset, true), i.getUint16(offset, true)), true);
|
|
43
|
-
}
|
|
44
|
-
return out;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export const LT_HASH_ANTI_TAMPERING = new LTHash('WhatsApp Patch Integrity');
|
|
1
|
+
import { hkdf } from './crypto.js';
|
|
2
|
+
/**
|
|
3
|
+
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
|
|
4
|
+
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
|
|
5
|
+
* if the same series of mutations was made sequentially.
|
|
6
|
+
*/
|
|
7
|
+
const o = 128;
|
|
8
|
+
class LTHash {
|
|
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);
|
|
15
|
+
}
|
|
16
|
+
return e;
|
|
17
|
+
}
|
|
18
|
+
async subtract(e, t) {
|
|
19
|
+
for (const item of t) {
|
|
20
|
+
e = await this._subtractSingle(e, item);
|
|
21
|
+
}
|
|
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(hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
30
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a + b);
|
|
31
|
+
}
|
|
32
|
+
async _subtractSingle(e, t) {
|
|
33
|
+
const derived = new Uint8Array(hkdf(Buffer.from(t), o, { info: this.salt })).buffer;
|
|
34
|
+
return this.performPointwiseWithOverflow(e, derived, (a, b) => a - b);
|
|
35
|
+
}
|
|
36
|
+
performPointwiseWithOverflow(e, t, op) {
|
|
37
|
+
const n = new DataView(e);
|
|
38
|
+
const i = new DataView(t);
|
|
39
|
+
const out = new ArrayBuffer(n.byteLength);
|
|
40
|
+
const s = new DataView(out);
|
|
41
|
+
for (let offset = 0; offset < n.byteLength; offset += 2) {
|
|
42
|
+
s.setUint16(offset, op(n.getUint16(offset, true), i.getUint16(offset, true)), true);
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export const LT_HASH_ANTI_TAMPERING = new LTHash('WhatsApp Patch Integrity');
|
|
48
48
|
//# sourceMappingURL=lt-hash.js.map
|
package/lib/Utils/make-mutex.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
export const makeMutex = () => {
|
|
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
|
-
}
|
|
13
|
-
catch { }
|
|
14
|
-
try {
|
|
15
|
-
// execute the current task
|
|
16
|
-
const result = await code();
|
|
17
|
-
return result;
|
|
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;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
export const makeKeyedMutex = () => {
|
|
30
|
-
const map = {};
|
|
31
|
-
return {
|
|
32
|
-
mutex(key, task) {
|
|
33
|
-
if (!map[key]) {
|
|
34
|
-
map[key] = makeMutex();
|
|
35
|
-
}
|
|
36
|
-
return map[key].mutex(task);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
};
|
|
1
|
+
export const makeMutex = () => {
|
|
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
|
+
}
|
|
13
|
+
catch { }
|
|
14
|
+
try {
|
|
15
|
+
// execute the current task
|
|
16
|
+
const result = await code();
|
|
17
|
+
return result;
|
|
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;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export const makeKeyedMutex = () => {
|
|
30
|
+
const map = {};
|
|
31
|
+
return {
|
|
32
|
+
mutex(key, task) {
|
|
33
|
+
if (!map[key]) {
|
|
34
|
+
map[key] = makeMutex();
|
|
35
|
+
}
|
|
36
|
+
return map[key].mutex(task);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
40
|
//# sourceMappingURL=make-mutex.js.map
|