@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.
Files changed (102) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +924 -1299
  3. package/lib/Defaults/baileys-version.json +6 -2
  4. package/lib/Defaults/index.js +172 -172
  5. package/lib/Signal/libsignal.js +380 -292
  6. package/lib/Signal/lid-mapping.js +264 -171
  7. package/lib/Socket/Client/index.js +2 -2
  8. package/lib/Socket/Client/types.js +10 -10
  9. package/lib/Socket/Client/websocket.js +45 -310
  10. package/lib/Socket/business.js +375 -375
  11. package/lib/Socket/chats.js +909 -963
  12. package/lib/Socket/communities.js +430 -430
  13. package/lib/Socket/groups.js +342 -342
  14. package/lib/Socket/index.js +22 -22
  15. package/lib/Socket/messages-recv.js +777 -743
  16. package/lib/Socket/messages-send.js +667 -393
  17. package/lib/Socket/mex.js +50 -50
  18. package/lib/Socket/newsletter.js +148 -148
  19. package/lib/Socket/nexus-handler.js +75 -261
  20. package/lib/Socket/socket.js +709 -1201
  21. package/lib/Store/index.js +5 -5
  22. package/lib/Store/make-cache-manager-store.js +81 -81
  23. package/lib/Store/make-in-memory-store.js +416 -416
  24. package/lib/Store/make-ordered-dictionary.js +81 -81
  25. package/lib/Store/object-repository.js +30 -30
  26. package/lib/Types/Auth.js +1 -1
  27. package/lib/Types/Bussines.js +1 -1
  28. package/lib/Types/Call.js +1 -1
  29. package/lib/Types/Chat.js +7 -7
  30. package/lib/Types/Contact.js +1 -1
  31. package/lib/Types/Events.js +1 -1
  32. package/lib/Types/GroupMetadata.js +1 -1
  33. package/lib/Types/Label.js +24 -24
  34. package/lib/Types/LabelAssociation.js +6 -6
  35. package/lib/Types/Message.js +10 -10
  36. package/lib/Types/Newsletter.js +28 -28
  37. package/lib/Types/Product.js +1 -1
  38. package/lib/Types/Signal.js +1 -1
  39. package/lib/Types/Socket.js +2 -2
  40. package/lib/Types/State.js +12 -12
  41. package/lib/Types/USync.js +1 -1
  42. package/lib/Types/index.js +25 -25
  43. package/lib/Utils/auth-utils.js +264 -256
  44. package/lib/Utils/baileys-event-stream.js +55 -55
  45. package/lib/Utils/browser-utils.js +27 -27
  46. package/lib/Utils/business.js +228 -230
  47. package/lib/Utils/chat-utils.js +694 -764
  48. package/lib/Utils/crypto.js +109 -135
  49. package/lib/Utils/decode-wa-message.js +310 -314
  50. package/lib/Utils/event-buffer.js +547 -547
  51. package/lib/Utils/generics.js +297 -297
  52. package/lib/Utils/history.js +91 -83
  53. package/lib/Utils/index.js +21 -20
  54. package/lib/Utils/key-store.js +17 -0
  55. package/lib/Utils/link-preview.js +97 -88
  56. package/lib/Utils/logger.js +2 -2
  57. package/lib/Utils/lt-hash.js +47 -47
  58. package/lib/Utils/make-mutex.js +39 -39
  59. package/lib/Utils/message-retry-manager.js +148 -148
  60. package/lib/Utils/messages-media.js +534 -532
  61. package/lib/Utils/messages.js +705 -705
  62. package/lib/Utils/noise-handler.js +255 -255
  63. package/lib/Utils/pre-key-manager.js +105 -105
  64. package/lib/Utils/process-message.js +412 -412
  65. package/lib/Utils/signal.js +160 -158
  66. package/lib/Utils/use-multi-file-auth-state.js +120 -120
  67. package/lib/Utils/validate-connection.js +194 -194
  68. package/lib/WABinary/constants.js +1300 -1300
  69. package/lib/WABinary/decode.js +237 -237
  70. package/lib/WABinary/encode.js +232 -232
  71. package/lib/WABinary/generic-utils.js +252 -211
  72. package/lib/WABinary/index.js +5 -5
  73. package/lib/WABinary/jid-utils.js +279 -95
  74. package/lib/WABinary/types.js +1 -1
  75. package/lib/WAM/BinaryInfo.js +9 -9
  76. package/lib/WAM/constants.js +22852 -22852
  77. package/lib/WAM/encode.js +149 -149
  78. package/lib/WAM/index.js +3 -3
  79. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
  80. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
  81. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
  82. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
  83. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  84. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
  85. package/lib/WAUSync/Protocols/index.js +4 -4
  86. package/lib/WAUSync/USyncQuery.js +93 -93
  87. package/lib/WAUSync/USyncUser.js +22 -22
  88. package/lib/WAUSync/index.js +3 -3
  89. package/lib/index.js +66 -66
  90. package/package.json +171 -144
  91. package/lib/Signal/Group/ciphertext-message.js +0 -12
  92. package/lib/Signal/Group/group-session-builder.js +0 -30
  93. package/lib/Signal/Group/group_cipher.js +0 -100
  94. package/lib/Signal/Group/index.js +0 -12
  95. package/lib/Signal/Group/keyhelper.js +0 -18
  96. package/lib/Signal/Group/sender-chain-key.js +0 -26
  97. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  98. package/lib/Signal/Group/sender-key-message.js +0 -66
  99. package/lib/Signal/Group/sender-key-name.js +0 -48
  100. package/lib/Signal/Group/sender-key-record.js +0 -41
  101. package/lib/Signal/Group/sender-key-state.js +0 -84
  102. package/lib/Signal/Group/sender-message-key.js +0 -26
@@ -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 { toNumber } from './generics.js';
6
- import { normalizeMessageContent } from './messages.js';
7
- import { downloadContentFromMessage } from './messages-media.js';
8
- const inflatePromise = promisify(inflate);
9
- export const downloadHistory = async (msg, options) => {
10
- const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options });
11
- const bufferArray = [];
12
- for await (const chunk of stream) {
13
- bufferArray.push(chunk);
14
- }
15
- let buffer = Buffer.concat(bufferArray);
16
- // decompress buffer
17
- buffer = await inflatePromise(buffer);
18
- const syncData = proto.HistorySync.decode(buffer);
19
- return syncData;
20
- };
21
- export const processHistoryMessage = (item) => {
22
- const messages = [];
23
- const contacts = [];
24
- const chats = [];
25
- switch (item.syncType) {
26
- case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
27
- case proto.HistorySync.HistorySyncType.RECENT:
28
- case proto.HistorySync.HistorySyncType.FULL:
29
- case proto.HistorySync.HistorySyncType.ON_DEMAND:
30
- for (const chat of item.conversations) {
31
- contacts.push({
32
- id: chat.id,
33
- name: chat.name || undefined,
34
- lid: chat.lidJid || undefined,
35
- phoneNumber: chat.pnJid || undefined
36
- });
37
- const msgs = chat.messages || [];
38
- delete chat.messages;
39
- for (const item of msgs) {
40
- const message = item.message;
41
- messages.push(message);
42
- if (!chat.messages?.length) {
43
- // keep only the most recent message in the chat array
44
- chat.messages = [{ message }];
45
- }
46
- if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
47
- chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
48
- }
49
- if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
50
- message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
51
- message.messageStubParameters?.[0]) {
52
- contacts.push({
53
- id: message.key.participant || message.key.remoteJid,
54
- verifiedName: message.messageStubParameters?.[0]
55
- });
56
- }
57
- }
58
- chats.push({ ...chat });
59
- }
60
- break;
61
- case proto.HistorySync.HistorySyncType.PUSH_NAME:
62
- for (const c of item.pushnames) {
63
- contacts.push({ id: c.id, notify: c.pushname });
64
- }
65
- break;
66
- }
67
- return {
68
- chats,
69
- contacts,
70
- messages,
71
- syncType: item.syncType,
72
- progress: item.progress
73
- };
74
- };
75
- export const downloadAndProcessHistorySyncNotification = async (msg, options) => {
76
- const historyMsg = await downloadHistory(msg, options);
77
- return processHistoryMessage(historyMsg);
78
- };
79
- export const getHistoryMsg = (message) => {
80
- const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
81
- const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
82
- return anyHistoryMsg;
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
@@ -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 { prepareWAMessageMedia } from './messages.js';
2
- import { extractImageThumb, getHttpStream } from './messages-media.js';
3
- const THUMBNAIL_WIDTH_PX = 192;
4
- /** Fetches an image and generates a thumbnail for it */
5
- const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
6
- const stream = await getHttpStream(url, fetchOpts);
7
- const result = await extractImageThumb(stream, thumbnailWidth);
8
- return result;
9
- };
10
- /**
11
- * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
12
- * Return undefined if the fetch failed or no URL was found
13
- * @param text first matched URL in text
14
- * @returns the URL info required to generate link preview
15
- */
16
- export const getUrlInfo = async (text, opts = {
17
- thumbnailWidth: THUMBNAIL_WIDTH_PX,
18
- fetchOpts: { timeout: 3000 }
19
- }) => {
20
- try {
21
- // retries
22
- const retries = 0;
23
- const maxRetry = 5;
24
- const { getLinkPreview } = await import('link-preview-js');
25
- let previewLink = text;
26
- if (!text.startsWith('https://') && !text.startsWith('http://')) {
27
- previewLink = 'https://' + previewLink;
28
- }
29
- const info = await getLinkPreview(previewLink, {
30
- ...opts.fetchOpts,
31
- followRedirects: 'follow',
32
- handleRedirects: (baseURL, forwardedURL) => {
33
- const urlObj = new URL(baseURL);
34
- const forwardedURLObj = new URL(forwardedURL);
35
- if (retries >= maxRetry) {
36
- return false;
37
- }
38
- if (forwardedURLObj.hostname === urlObj.hostname ||
39
- forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
40
- 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
41
- retries + 1;
42
- return true;
43
- }
44
- else {
45
- return false;
46
- }
47
- },
48
- headers: opts.fetchOpts?.headers
49
- });
50
- if (info && 'title' in info && info.title) {
51
- const [image] = info.images;
52
- const urlInfo = {
53
- 'canonical-url': info.url,
54
- 'matched-text': text,
55
- title: info.title,
56
- description: info.description,
57
- originalThumbnailUrl: image
58
- };
59
- if (opts.uploadImage) {
60
- try {
61
- const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
62
- upload: opts.uploadImage,
63
- mediaTypeOverride: 'thumbnail-link',
64
- options: opts.fetchOpts
65
- });
66
- urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
67
- urlInfo.highQualityThumbnail = imageMessage || undefined;
68
- } catch (error) {
69
- opts.logger?.warn({ err: error.message, url: image }, 'failed to upload link preview thumbnail, continuing without it');
70
- }
71
- }
72
- else {
73
- try {
74
- urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
75
- }
76
- catch (error) {
77
- opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
78
- }
79
- }
80
- return urlInfo;
81
- }
82
- }
83
- catch (error) {
84
- if (!error.message.includes('receive a valid')) {
85
- throw error;
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
@@ -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
@@ -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
@@ -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