@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.
Files changed (119) hide show
  1. package/README.md +96 -85
  2. package/lib/Defaults/connection.js +39 -0
  3. package/lib/Defaults/constants.js +50 -0
  4. package/lib/Defaults/history.js +13 -0
  5. package/lib/Defaults/index.js +36 -151
  6. package/lib/Defaults/media.js +43 -0
  7. package/lib/Defaults/phonenumber-mcc.json +221 -221
  8. package/lib/Defaults/prefix.js +12 -0
  9. package/lib/Defaults/vialeys-version.json +7 -0
  10. package/lib/Signal/Group/ciphertext-message.js +10 -15
  11. package/lib/Signal/Group/group-session-builder.js +34 -60
  12. package/lib/Signal/Group/group_cipher.js +69 -76
  13. package/lib/Signal/Group/index.js +41 -60
  14. package/lib/Signal/Group/keyhelper.js +12 -57
  15. package/lib/Signal/Group/sender-chain-key.js +20 -33
  16. package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
  17. package/lib/Signal/Group/sender-key-message.js +58 -53
  18. package/lib/Signal/Group/sender-key-name.js +21 -31
  19. package/lib/Signal/Group/sender-key-record.js +21 -34
  20. package/lib/Signal/Group/sender-key-state.js +59 -106
  21. package/lib/Signal/Group/sender-message-key.js +16 -21
  22. package/lib/Signal/libsignal.js +282 -203
  23. package/lib/Signal/lid-mapping.js +164 -184
  24. package/lib/Socket/Client/index.js +31 -22
  25. package/lib/Socket/Client/types.js +9 -15
  26. package/lib/Socket/Client/websocket.js +42 -37
  27. package/lib/Socket/business.js +212 -336
  28. package/lib/Socket/chats.js +696 -940
  29. package/lib/Socket/community.js +454 -369
  30. package/lib/Socket/groups.js +278 -280
  31. package/lib/Socket/index.js +9 -21
  32. package/lib/Socket/messages-recv.js +1027 -1570
  33. package/lib/Socket/messages-send.js +1180 -1136
  34. package/lib/Socket/mex.js +59 -0
  35. package/lib/Socket/newsletter.js +193 -251
  36. package/lib/Socket/socket.js +758 -898
  37. package/lib/Store/index.js +35 -24
  38. package/lib/Store/make-cache-manager-store.js +53 -66
  39. package/lib/Store/make-in-memory-store.js +319 -325
  40. package/lib/Store/make-ordered-dictionary.js +49 -57
  41. package/lib/Store/object-repository.js +10 -15
  42. package/lib/Types/Auth.js +2 -3
  43. package/lib/Types/Bussines.js +2 -3
  44. package/lib/Types/Call.js +2 -3
  45. package/lib/Types/Chat.js +10 -9
  46. package/lib/Types/Contact.js +2 -3
  47. package/lib/Types/Events.js +2 -3
  48. package/lib/Types/GroupMetadata.js +2 -3
  49. package/lib/Types/Label.js +6 -12
  50. package/lib/Types/LabelAssociation.js +4 -13
  51. package/lib/Types/Message.js +10 -18
  52. package/lib/Types/MexUpdates.js +15 -18
  53. package/lib/Types/Newsletter.js +26 -34
  54. package/lib/Types/Product.js +2 -3
  55. package/lib/Types/Signal.js +2 -3
  56. package/lib/Types/Socket.js +2 -3
  57. package/lib/Types/State.js +8 -13
  58. package/lib/Types/USync.js +2 -3
  59. package/lib/Types/index.js +49 -40
  60. package/lib/Utils/auth-utils.js +190 -495
  61. package/lib/Utils/browser-utils.js +29 -0
  62. package/lib/Utils/business.js +177 -199
  63. package/lib/Utils/chat-utils.js +711 -624
  64. package/lib/Utils/crypto.js +116 -161
  65. package/lib/Utils/decode-wa-message.js +225 -321
  66. package/lib/Utils/event-buffer.js +363 -405
  67. package/lib/Utils/generics.js +318 -472
  68. package/lib/Utils/history.js +72 -76
  69. package/lib/Utils/index.js +49 -41
  70. package/lib/Utils/link-preview.js +59 -103
  71. package/lib/Utils/logger.js +4 -7
  72. package/lib/Utils/lt-hash.js +29 -42
  73. package/lib/Utils/make-mutex.js +26 -42
  74. package/lib/Utils/message-retry-manager.js +134 -160
  75. package/lib/Utils/messages-media.js +665 -731
  76. package/lib/Utils/messages.js +518 -1
  77. package/lib/Utils/noise-handler.js +127 -125
  78. package/lib/Utils/pre-key-manager.js +86 -0
  79. package/lib/Utils/process-message.js +739 -351
  80. package/lib/Utils/signal.js +146 -129
  81. package/lib/Utils/use-multi-file-auth-state.js +68 -135
  82. package/lib/Utils/validate-connection.js +183 -142
  83. package/lib/Utils/vialeys-event-stream.js +41 -0
  84. package/lib/WABinary/constants.js +1281 -1289
  85. package/lib/WABinary/decode.js +145 -200
  86. package/lib/WABinary/encode.js +149 -202
  87. package/lib/WABinary/generic-utils.js +79 -97
  88. package/lib/WABinary/index.js +36 -25
  89. package/lib/WABinary/jid-utils.js +91 -123
  90. package/lib/WABinary/types.js +2 -3
  91. package/lib/WAM/BinaryInfo.js +8 -13
  92. package/lib/WAM/constants.js +16584 -11464
  93. package/lib/WAM/encode.js +117 -133
  94. package/lib/WAM/index.js +34 -23
  95. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
  96. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
  97. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
  98. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
  99. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
  101. package/lib/WAUSync/Protocols/index.js +37 -26
  102. package/lib/WAUSync/USyncQuery.js +66 -66
  103. package/lib/WAUSync/USyncUser.js +13 -18
  104. package/lib/WAUSync/index.js +34 -23
  105. package/lib/index.js +95 -28
  106. package/package.json +2 -1
  107. package/lib/Defaults/baileys-version.json +0 -3
  108. package/lib/Signal/Group/queue-job.d.ts +0 -1
  109. package/lib/Signal/Group/queue-job.js +0 -57
  110. package/lib/Socket/usync.d.ts +0 -37
  111. package/lib/Socket/usync.js +0 -83
  112. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  113. package/lib/Utils/baileys-event-stream.js +0 -70
  114. package/lib/Utils/signal-housekeeping.d.ts +0 -19
  115. package/lib/Utils/signal-housekeeping.js +0 -73
  116. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  117. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  118. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  119. package/lib/Utils/use-single-file-auth-state.js +0 -80
@@ -1,104 +1,100 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const util_1 = require("util")
6
- const zlib_1 = require("zlib")
7
- const WAProto_1 = require("../../WAProto")
8
- const Types_1 = require("../Types")
9
- const WABinary_1 = require("../WABinary")
10
- const generics_1 = require("./generics")
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 messages_media_1.downloadContentFromMessage(msg, 'md-msg-hist', { options })
17
- const bufferArray = []
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
- // decompress buffer
23
- buffer = await inflatePromise(buffer)
24
- const syncData = WAProto_1.proto.HistorySync.decode(buffer)
25
- return syncData
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 WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
34
- case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
35
- case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
36
- case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
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
- // keep only the most recent message in the chat array
51
- chat.messages = [{ message }]
46
+ chat.messages = [{ message: message }];
52
47
  }
53
48
  if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
54
- chat.lastMessageRecvTimestamp = generics_1.toNumber(message.messageTimestamp)
49
+ chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
55
50
  }
56
- if (message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
57
- || message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
58
- && message.messageStubParameters?.[0]) {
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 WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
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
- const historyMsg = await downloadHistory(msg, options)
90
- return processHistoryMessage(historyMsg)
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 ? messages_1.normalizeMessageContent(message) : undefined
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
- downloadHistory,
101
- processHistoryMessage,
102
- downloadAndProcessHistorySyncNotification,
103
- getHistoryMsg
104
- }
96
+ downloadHistory: downloadHistory,
97
+ processHistoryMessage: processHistoryMessage,
98
+ downloadAndProcessHistorySyncNotification: downloadAndProcessHistorySyncNotification,
99
+ getHistoryMsg: getHistoryMsg,
100
+ };
@@ -1,41 +1,49 @@
1
- "use strict"
2
-
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
8
- }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
-
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
- }
18
-
19
- Object.defineProperty(exports, "__esModule", { value: true })
20
-
21
- __exportStar(require("./generics"), exports)
22
- __exportStar(require("./decode-wa-message"), exports)
23
- __exportStar(require("./messages"), exports)
24
- __exportStar(require("./messages-media"), exports)
25
- __exportStar(require("./message-retry-manager"), exports)
26
- __exportStar(require("./validate-connection"), exports)
27
- __exportStar(require("./crypto"), exports)
28
- __exportStar(require("./signal"), exports)
29
- __exportStar(require("./noise-handler"), exports)
30
- __exportStar(require("./history"), exports)
31
- __exportStar(require("./chat-utils"), exports)
32
- __exportStar(require("./lt-hash"), exports)
33
- __exportStar(require("./auth-utils"), exports)
34
- __exportStar(require("./baileys-event-stream"), exports)
35
- __exportStar(require("./use-mongo-file-auth-state"), exports)
36
- __exportStar(require("./use-single-file-auth-state"), exports)
37
- __exportStar(require("./use-multi-file-auth-state"), exports)
38
- __exportStar(require("./link-preview"), exports)
39
- __exportStar(require("./event-buffer"), exports)
40
- __exportStar(require("./process-message"), exports)
41
- __exportStar(require("./signal-housekeeping"), exports)
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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
8
- }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
-
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v })
17
- }) : function(o, v) {
18
- o["default"] = v
19
- })
20
-
21
- var __importStar = (this && this.__importStar) || function (mod) {
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
- const retries = 0
51
- const maxRetry = 5
52
- const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')))
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 getLinkPreview(previewLink, {
27
+ const { open_graph: info } = await unfurl(previewLink, {
58
28
  ...opts.fetchOpts,
59
- followRedirects: 'follow',
60
- handleRedirects: (baseURL, forwardedURL) => {
61
- const urlObj = new URL(baseURL)
62
- const forwardedURLObj = new URL(forwardedURL)
63
- if (retries >= maxRetry) {
64
- return false
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
- 'canonical-url': info.url,
82
- 'matched-text': text,
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 messages_1.prepareWAMessageMedia({ image: { url: image } }, {
89
- upload: opts.uploadImage,
90
- mediaTypeOverride: 'thumbnail-link',
91
- options: opts.fetchOpts
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
- catch (error) {
105
- opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
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
- catch (error) {
112
- if (!error.message.includes('receive a valid')) {
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 };
@@ -1,7 +1,4 @@
1
- "use strict"
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod }
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()}"` });
@@ -1,58 +1,45 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const crypto_1 = require("./crypto")
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 = r._addSingle(e, item)
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 = r._subtractSingle(e, item)
17
+ e = await this._subtractSingle(e, item);
28
18
  }
29
- return e
19
+ return e;
30
20
  }
31
- subtractThenAdd(e, t, r) {
32
- var n = this
33
- return n.add(n.subtract(e, r), t)
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
- var r = this
37
- const n = new Uint8Array(await crypto_1.hkdf(Buffer.from(t), o, { info: r.salt })).buffer
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
- var r = this
42
- const n = new Uint8Array(await crypto_1.hkdf(Buffer.from(t), o, { info: r.salt })).buffer
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, r) {
46
- const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a)
47
- for (let e = 0; e < n.byteLength; e += 2) {
48
- s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0)
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 a
41
+ return out;
51
42
  }
52
43
  }
53
-
54
- const LT_HASH_ANTI_TAMPERING = new d('WhatsApp Patch Integrity')
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 };
@@ -1,49 +1,33 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { Mutex: AsyncMutex } = require("async-mutex");
5
4
  const makeMutex = () => {
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- let task = Promise.resolve()
8
- let taskTimeout
5
+ const mutex = new AsyncMutex();
9
6
  return {
10
7
  mutex(code) {
11
- task = (async () => {
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
- if (!map[key]) {
39
- map[key] = makeMutex()
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
- return map[key].mutex(task)
42
- }
43
- }
44
- }
45
-
46
- module.exports = {
47
- makeMutex,
48
- makeKeyedMutex
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 };