@hansaka02/baileys 7.3.2 → 7.3.4

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 (202) hide show
  1. package/README.md +247 -203
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +62 -0
  4. package/lib/Defaults/history.js +17 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +4 -4
  13. package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -7
  16. package/lib/Signal/Group/sender-key-state.js +4 -4
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +45 -69
  19. package/lib/Signal/lid-mapping.js +15 -11
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +16 -14
  22. package/lib/Socket/business.js +41 -32
  23. package/lib/Socket/chats.js +123 -98
  24. package/lib/Socket/community.js +50 -40
  25. package/lib/Socket/groups.js +59 -47
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +219 -172
  28. package/lib/Socket/messages-send.js +187 -143
  29. package/lib/Socket/newsletter.js +61 -47
  30. package/lib/Socket/socket.js +133 -90
  31. package/lib/Socket/usync.js +6 -6
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/State.js +4 -4
  39. package/lib/Types/index.js +28 -12
  40. package/lib/Utils/auth-utils.js +28 -26
  41. package/lib/Utils/baileys-event-stream.js +68 -69
  42. package/lib/Utils/business.js +63 -53
  43. package/lib/Utils/chat-utils.js +81 -71
  44. package/lib/Utils/crypto.js +25 -45
  45. package/lib/Utils/decode-wa-message.js +319 -311
  46. package/lib/Utils/event-buffer.js +21 -22
  47. package/lib/Utils/generics.js +65 -82
  48. package/lib/Utils/history.js +21 -21
  49. package/lib/Utils/index.js +27 -13
  50. package/lib/Utils/link-preview.js +7 -30
  51. package/lib/Utils/logger.js +5 -5
  52. package/lib/Utils/lt-hash.js +3 -3
  53. package/lib/Utils/message-retry-manager.js +4 -4
  54. package/lib/Utils/messages-media.js +104 -109
  55. package/lib/Utils/messages.js +203 -171
  56. package/lib/Utils/noise-handler.js +28 -19
  57. package/lib/Utils/process-message.js +111 -96
  58. package/lib/Utils/signal.js +36 -25
  59. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  60. package/lib/Utils/validate-connection.js +52 -45
  61. package/lib/WABinary/decode.js +6 -32
  62. package/lib/WABinary/encode.js +3 -29
  63. package/lib/WABinary/generic-utils.js +4 -4
  64. package/lib/WABinary/index.js +27 -11
  65. package/lib/WAM/encode.js +16 -8
  66. package/lib/WAM/index.js +27 -11
  67. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  68. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  69. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  70. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  71. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  72. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  73. package/lib/WAUSync/Protocols/index.js +27 -11
  74. package/lib/WAUSync/USyncQuery.js +17 -10
  75. package/lib/WAUSync/index.js +27 -11
  76. package/lib/index.js +60 -31
  77. package/package.json +8 -14
  78. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  79. package/WAProto/Adv/Adv.d.ts +0 -643
  80. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  81. package/WAProto/Cert/Cert.d.ts +0 -613
  82. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  83. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  84. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  85. package/WAProto/E2E/E2E.d.ts +0 -41724
  86. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  87. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  88. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  89. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  90. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  91. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  92. package/WAProto/Protocol/Protocol.d.ts +0 -270
  93. package/WAProto/Reporting/Reporting.d.ts +0 -371
  94. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  95. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  96. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  97. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  98. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  99. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  100. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  101. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  102. package/WAProto/Web/Web.d.ts +0 -46383
  103. package/WAProto/index.d.ts +0 -55
  104. package/lib/Defaults/index.d.ts +0 -77
  105. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  106. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  107. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  108. package/lib/Signal/Group/index.d.ts +0 -11
  109. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  110. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  112. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  113. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  114. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  115. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  116. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  117. package/lib/Signal/libsignal.d.ts +0 -8
  118. package/lib/Signal/lid-mapping.d.ts +0 -28
  119. package/lib/Socket/Client/index.d.ts +0 -2
  120. package/lib/Socket/Client/types.d.ts +0 -16
  121. package/lib/Socket/Client/websocket.d.ts +0 -13
  122. package/lib/Socket/business.d.ts +0 -187
  123. package/lib/Socket/chats.d.ts +0 -97
  124. package/lib/Socket/community.d.ts +0 -129
  125. package/lib/Socket/groups.d.ts +0 -129
  126. package/lib/Socket/index.d.ts +0 -191
  127. package/lib/Socket/messages-recv.d.ts +0 -174
  128. package/lib/Socket/messages-send.d.ts +0 -165
  129. package/lib/Socket/newsletter.d.ts +0 -145
  130. package/lib/Socket/socket.d.ts +0 -45
  131. package/lib/Socket/usync.d.ts +0 -37
  132. package/lib/Store/index.d.ts +0 -4
  133. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  134. package/lib/Store/make-in-memory-store.d.ts +0 -123
  135. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  136. package/lib/Store/object-repository.d.ts +0 -10
  137. package/lib/Types/Auth.d.ts +0 -121
  138. package/lib/Types/Bussiness.d.ts +0 -28
  139. package/lib/Types/Call.d.ts +0 -14
  140. package/lib/Types/Chat.d.ts +0 -143
  141. package/lib/Types/Contact.d.ts +0 -23
  142. package/lib/Types/Events.d.ts +0 -226
  143. package/lib/Types/GroupMetadata.d.ts +0 -66
  144. package/lib/Types/Label.d.ts +0 -48
  145. package/lib/Types/LabelAssociation.d.ts +0 -35
  146. package/lib/Types/Message.d.ts +0 -484
  147. package/lib/Types/MexUpdates.d.ts +0 -9
  148. package/lib/Types/Newsletter.d.ts +0 -109
  149. package/lib/Types/Product.d.ts +0 -92
  150. package/lib/Types/Signal.d.ts +0 -98
  151. package/lib/Types/Socket.d.ts +0 -141
  152. package/lib/Types/State.d.ts +0 -41
  153. package/lib/Types/USync.d.ts +0 -26
  154. package/lib/Types/index.d.ts +0 -80
  155. package/lib/Utils/auth-utils.d.ts +0 -21
  156. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  157. package/lib/Utils/business.d.ts +0 -29
  158. package/lib/Utils/chat-utils.d.ts +0 -82
  159. package/lib/Utils/crypto.d.ts +0 -56
  160. package/lib/Utils/decode-wa-message.d.ts +0 -53
  161. package/lib/Utils/event-buffer.d.ts +0 -39
  162. package/lib/Utils/generics.d.ts +0 -117
  163. package/lib/Utils/history.d.ts +0 -23
  164. package/lib/Utils/index.d.ts +0 -20
  165. package/lib/Utils/link-preview.d.ts +0 -23
  166. package/lib/Utils/logger.d.ts +0 -13
  167. package/lib/Utils/lt-hash.d.ts +0 -14
  168. package/lib/Utils/make-mutex.d.ts +0 -9
  169. package/lib/Utils/message-retry-manager.d.ts +0 -88
  170. package/lib/Utils/messages-media.d.ts +0 -135
  171. package/lib/Utils/messages.d.ts +0 -105
  172. package/lib/Utils/noise-handler.d.ts +0 -20
  173. package/lib/Utils/process-message.d.ts +0 -49
  174. package/lib/Utils/signal.d.ts +0 -42
  175. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  176. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  177. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  178. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  179. package/lib/Utils/use-single-file-auth-state.js +0 -80
  180. package/lib/Utils/validate-connection.d.ts +0 -13
  181. package/lib/WABinary/constants.d.ts +0 -30
  182. package/lib/WABinary/decode.d.ts +0 -9
  183. package/lib/WABinary/encode.d.ts +0 -3
  184. package/lib/WABinary/generic-utils.d.ts +0 -28
  185. package/lib/WABinary/index.d.ts +0 -5
  186. package/lib/WABinary/jid-utils.d.ts +0 -58
  187. package/lib/WABinary/types.d.ts +0 -22
  188. package/lib/WAM/BinaryInfo.d.ts +0 -16
  189. package/lib/WAM/constants.d.ts +0 -47
  190. package/lib/WAM/encode.d.ts +0 -3
  191. package/lib/WAM/index.d.ts +0 -3
  192. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  193. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  194. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  195. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  196. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  197. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  198. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  199. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  200. package/lib/WAUSync/USyncUser.d.ts +0 -12
  201. package/lib/WAUSync/index.d.ts +0 -3
  202. package/lib/index.d.ts +0 -13
@@ -1,39 +1,83 @@
1
1
  "use strict"
2
2
 
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
3
  Object.defineProperty(exports, "__esModule", { value: true })
8
4
 
9
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"))
10
- const boom_1 = require("@hapi/boom")
11
- const crypto_1 = require("crypto")
12
- const WAProto_1 = require("../../WAProto")
13
- const Defaults_1 = require("../Defaults")
14
- const Utils_1 = require("../Utils")
15
- const Types_1 = require("../Types")
16
- const WABinary_1 = require("../WABinary")
17
- const WAUSync_1 = require("../WAUSync")
18
- const newsletter_1 = require("./newsletter")
19
- const link_preview_1 = require("../Utils/link-preview")
20
- const make_keyed_mutex_1 = require("../Utils/make-mutex")
5
+ const { default: NodeCache } = require("@cacheable/node-cache")
6
+ const { Boom } = require("@hapi/boom")
7
+ const { randomBytes } = require("crypto")
8
+ const { proto } = require("../../WAProto")
9
+ const {
10
+ DEFAULT_CACHE_TTLS,
11
+ WA_DEFAULT_EPHEMERAL
12
+ } = require("../Defaults/constants")
13
+ const {
14
+ delay,
15
+ assertMediaContent,
16
+ bindWaitForEvent,
17
+ decryptMediaRetryData,
18
+ encodeNewsletterMessage,
19
+ encodeSignedDeviceIdentity,
20
+ encodeWAMessage,
21
+ encryptMediaRetryRequest,
22
+ extractDeviceJids,
23
+ generateMessageID,
24
+ generateParticipantHashV2,
25
+ generateWAMessage,
26
+ generateWAMessageFromContent,
27
+ getStatusCodeForMediaRetry,
28
+ getUrlFromDirectPath,
29
+ getWAUploadToServer,
30
+ MessageRetryManager,
31
+ normalizeMessageContent,
32
+ parseAndInjectE2ESessions,
33
+ unixTimestampSeconds,
34
+ prepareAlbumMessageContent,
35
+ aggregateMessageKeysNotFromMe
36
+ } = require("../Utils")
37
+ const {
38
+ QueryIds,
39
+ XWAPaths,
40
+ WAMessageAddressingMode
41
+ } = require("../Types")
42
+ const {
43
+ areJidsSameUser,
44
+ getBinaryNodeChild,
45
+ getBinaryNodeChildren,
46
+ getBinaryFilteredBizBot,
47
+ getBinaryFilteredButtons,
48
+ isJidNewsletter,
49
+ isJidGroup,
50
+ isLidUser,
51
+ isJidUser,
52
+ jidDecode,
53
+ jidEncode,
54
+ jidNormalizedUser,
55
+ STORIES_JID,
56
+ S_WHATSAPP_NET
57
+ } = require("../WABinary")
58
+ const {
59
+ USyncUser,
60
+ USyncQuery
61
+ } = require("../WAUSync")
62
+ const { makeNewsletterSocket } = require("./newsletter")
63
+ const { getUrlInfo } = require("../Utils/link-preview")
64
+ const { makeKeyedMutex } = require("../Utils/make-mutex")
21
65
 
22
66
  const makeMessagesSocket = (config) => {
23
67
  const { logger, maxMsgRetryCount, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache } = config
24
- const suki = newsletter_1.makeNewsletterSocket(config)
68
+ const suki = makeNewsletterSocket(config)
25
69
  const { ev, authState, processingMutex, signalRepository, upsertMessage, createCallLink, query, fetchPrivacySettings, sendNode, groupQuery, groupMetadata, groupToggleEphemeral, newsletterWMexQuery, executeUSyncQuery } = suki
26
70
 
27
- const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
28
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
71
+ const userDevicesCache = config.userDevicesCache || new NodeCache({
72
+ stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
29
73
  useClones: false
30
74
  })
31
75
 
32
76
  // Initialize message retry manager if enabled
33
- const messageRetryManager = enableRecentMessageCache ? new Utils_1.MessageRetryManager(logger, maxMsgRetryCount) : null
77
+ const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null
34
78
 
35
79
  // Prevent race conditions in Signal session encryption by user
36
- const encryptionMutex = make_keyed_mutex_1.makeKeyedMutex()
80
+ const encryptionMutex = makeKeyedMutex()
37
81
 
38
82
  let mediaConn
39
83
 
@@ -48,15 +92,15 @@ const makeMessagesSocket = (config) => {
48
92
  attrs: {
49
93
  type: 'set',
50
94
  xmlns: 'w:m',
51
- to: WABinary_1.S_WHATSAPP_NET,
95
+ to: S_WHATSAPP_NET,
52
96
  },
53
97
  content: [{ tag: 'media_conn', attrs: {} }]
54
98
  })
55
99
 
56
- const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn')
100
+ const mediaConnNode = getBinaryNodeChild(result, 'media_conn')
57
101
 
58
102
  const node = {
59
- hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
103
+ hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
60
104
  hostname: attrs.hostname,
61
105
  maxContentLengthBytes: +attrs.maxContentLengthBytes,
62
106
  })),
@@ -89,10 +133,10 @@ const makeMessagesSocket = (config) => {
89
133
  const isReadReceipt = type === 'read' || type === 'read-self'
90
134
 
91
135
  if (isReadReceipt) {
92
- node.attrs.t = Utils_1.unixTimestampSeconds().toString()
136
+ node.attrs.t = unixTimestampSeconds().toString()
93
137
  }
94
138
 
95
- if (type === 'sender' && WABinary_1.isJidUser(jid)) {
139
+ if (type === 'sender' && isJidUser(jid)) {
96
140
  node.attrs.recipient = jid
97
141
  node.attrs.to = participant
98
142
  }
@@ -105,7 +149,7 @@ const makeMessagesSocket = (config) => {
105
149
  }
106
150
 
107
151
  if (type) {
108
- node.attrs.type = WABinary_1.isJidNewsletter(jid) ? 'read-self' : type
152
+ node.attrs.type = isJidNewsletter(jid) ? 'read-self' : type
109
153
  }
110
154
 
111
155
  const remainingMessageIds = messageIds.slice(1)
@@ -130,7 +174,7 @@ const makeMessagesSocket = (config) => {
130
174
 
131
175
  /** Correctly bulk send receipts to multiple chats, participants */
132
176
  const sendReceipts = async (keys, type) => {
133
- const recps = Utils_1.aggregateMessageKeysNotFromMe(keys)
177
+ const recps = aggregateMessageKeysNotFromMe(keys)
134
178
 
135
179
  for (const { jid, participant, messageIds } of recps) {
136
180
  await sendReceipt(jid, participant, messageIds, type)
@@ -157,8 +201,8 @@ const makeMessagesSocket = (config) => {
157
201
 
158
202
  // Collect all LID users
159
203
  for (const jid of jids) {
160
- if (WABinary_1.isLidUser(jid)) {
161
- const user = WABinary_1.jidDecode(jid)?.user
204
+ if (isLidUser(jid)) {
205
+ const user = jidDecode(jid)?.user
162
206
  if (user)
163
207
  lidUsers.add(user)
164
208
  }
@@ -166,8 +210,8 @@ const makeMessagesSocket = (config) => {
166
210
 
167
211
  // Filter out PN versions when LID exists
168
212
  for (const jid of jids) {
169
- if (WABinary_1.isJidUser(jid)) {
170
- const user = WABinary_1.jidDecode(jid)?.user
213
+ if (isJidUser(jid)) {
214
+ const user = jidDecode(jid)?.user
171
215
  if (user && lidUsers.has(user)) {
172
216
  logger.debug({ jid }, 'Skipping PN - LID version exists')
173
217
  continue
@@ -180,9 +224,9 @@ const makeMessagesSocket = (config) => {
180
224
 
181
225
  /** Fetch image for groups, user, and newsletter **/
182
226
  const profilePictureUrl = async (jid) => {
183
- if (WABinary_1.isJidNewsletter(jid)) {
227
+ if (isJidNewsletter(jid)) {
184
228
 
185
- let node = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
229
+ let node = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
186
230
  input: {
187
231
  key: jid,
188
232
  type: 'JID',
@@ -193,11 +237,11 @@ const makeMessagesSocket = (config) => {
193
237
  fetch_creation_time: true
194
238
  })
195
239
 
196
- let result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
240
+ let result = getBinaryNodeChild(node, 'result')?.content?.toString()
197
241
 
198
- let metadata = JSON.parse(result).data[Types_1.XWAPaths.NEWSLETTER]
242
+ let metadata = JSON.parse(result).data[XWAPaths.NEWSLETTER]
199
243
 
200
- return Utils_1.getUrlFromDirectPath(metadata.thread_metadata.picture?.direct_path || '')
244
+ return getUrlFromDirectPath(metadata.thread_metadata.picture?.direct_path || '')
201
245
 
202
246
  }
203
247
 
@@ -205,8 +249,8 @@ const makeMessagesSocket = (config) => {
205
249
  const result = await query({
206
250
  tag: 'iq',
207
251
  attrs: {
208
- target: WABinary_1.jidNormalizedUser(jid),
209
- to: WABinary_1.S_WHATSAPP_NET,
252
+ target: jidNormalizedUser(jid),
253
+ to: S_WHATSAPP_NET,
210
254
  type: 'get',
211
255
  xmlns: 'w:profile:picture'
212
256
  },
@@ -219,7 +263,7 @@ const makeMessagesSocket = (config) => {
219
263
  }]
220
264
  })
221
265
 
222
- const child = WABinary_1.getBinaryNodeChild(result, 'picture')
266
+ const child = getBinaryNodeChild(result, 'picture')
223
267
 
224
268
  return child?.attrs?.url || null
225
269
  }
@@ -238,7 +282,7 @@ const makeMessagesSocket = (config) => {
238
282
  jids = deduplicateLidPnJids(Array.from(new Set(jids)))
239
283
  const jidsWithUser = jids
240
284
  .map(jid => {
241
- const decoded = WABinary_1.jidDecode(jid)
285
+ const decoded = jidDecode(jid)
242
286
  const user = decoded?.user
243
287
  const device = decoded?.device
244
288
  const isExplicitDevice = typeof device === 'number' && device >= 0
@@ -252,7 +296,7 @@ const makeMessagesSocket = (config) => {
252
296
  return null
253
297
  }
254
298
 
255
- jid = WABinary_1.jidNormalizedUser(jid)
299
+ jid = jidNormalizedUser(jid)
256
300
  return { jid, user }
257
301
  })
258
302
  .filter(jid => jid !== null)
@@ -270,10 +314,10 @@ const makeMessagesSocket = (config) => {
270
314
  (userDevicesCache.mget ? undefined : (await userDevicesCache.get(user)))
271
315
 
272
316
  if (devices) {
273
- const isLidJid = WABinary_1.isLidUser(jid)
317
+ const isLidJid = isLidUser(jid)
274
318
  const devicesWithWire = devices.map(d => ({
275
319
  ...d,
276
- wireJid: isLidJid ? WABinary_1.jidEncode(d.user, 'lid', d.device) : WABinary_1.jidEncode(d.user, 's.whatsapp.net', d.device)
320
+ wireJid: isLidJid ? jidEncode(d.user, 'lid', d.device) : jidEncode(d.user, 's.whatsapp.net', d.device)
277
321
  }))
278
322
 
279
323
  deviceResults.push(...devicesWithWire)
@@ -294,22 +338,22 @@ const makeMessagesSocket = (config) => {
294
338
 
295
339
  const requestedLidUsers = new Set()
296
340
  for (const jid of toFetch) {
297
- if (WABinary_1.isLidUser(jid)) {
298
- const user = WABinary_1.jidDecode(jid)?.user
341
+ if (isLidUser(jid)) {
342
+ const user = jidDecode(jid)?.user
299
343
  if (user)
300
344
  requestedLidUsers.add(user)
301
345
  }
302
346
  }
303
347
 
304
- const query = new WAUSync_1.USyncQuery().withContext('message').withDeviceProtocol()
348
+ const query = new USyncQuery().withContext('message').withDeviceProtocol()
305
349
  for (const jid of toFetch) {
306
- query.withUser(new WAUSync_1.USyncUser().withId(jid))
350
+ query.withUser(new USyncUser().withId(jid))
307
351
  }
308
352
 
309
353
  const result = await executeUSyncQuery(query)
310
354
 
311
355
  if (result) {
312
- const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
356
+ const extracted = extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
313
357
  const deviceMap = {}
314
358
 
315
359
  for (const item of extracted) {
@@ -324,8 +368,8 @@ const makeMessagesSocket = (config) => {
324
368
  // Process all devices for this user
325
369
  for (const item of userDevices) {
326
370
  const finalWireJid = isLidUser
327
- ? WABinary_1.jidEncode(user, 'lid', item.device)
328
- : WABinary_1.jidEncode(item.user, 's.whatsapp.net', item.device)
371
+ ? jidEncode(user, 'lid', item.device)
372
+ : jidEncode(item.user, 's.whatsapp.net', item.device)
329
373
  deviceResults.push({
330
374
  ...item,
331
375
  wireJid: finalWireJid
@@ -394,7 +438,7 @@ const makeMessagesSocket = (config) => {
394
438
  // Group JIDs by user for bulk migration
395
439
  const userGroups = new Map()
396
440
  for (const jid of jids) {
397
- const user = WABinary_1.jidNormalizedUser(jid)
441
+ const user = jidNormalizedUser(jid)
398
442
  if (!userGroups.has(user)) {
399
443
  userGroups.set(user, [])
400
444
  }
@@ -403,7 +447,7 @@ const makeMessagesSocket = (config) => {
403
447
 
404
448
  // Helper to check LID mapping for a user
405
449
  const checkUserLidMapping = async (user, userJids) => {
406
- if (!userJids.some(jid => WABinary_1.isJidUser(jid))) {
450
+ if (!userJids.some(jid => isJidUser(jid))) {
407
451
  return { shouldMigrate: false, lidForPN: undefined }
408
452
  }
409
453
 
@@ -462,8 +506,8 @@ const makeMessagesSocket = (config) => {
462
506
 
463
507
  // Determine correct JID to fetch (LID if mapping exists, otherwise original)
464
508
  if (jid.includes('@s.whatsapp.net') && shouldMigrateUser && lidForPN) {
465
- const decoded = WABinary_1.jidDecode(jid)
466
- const lidDeviceJid = decoded.device !== undefined ? `${WABinary_1.jidDecode(lidForPN).user}:${decoded.device}@lid` : lidForPN
509
+ const decoded = jidDecode(jid)
510
+ const lidDeviceJid = decoded.device !== undefined ? `${jidDecode(lidForPN).user}:${decoded.device}@lid` : lidForPN
467
511
 
468
512
  jidsRequiringFetch.push(lidDeviceJid)
469
513
  logger.debug({ pnJid: jid, lidJid: lidDeviceJid }, 'Adding LID JID to fetch list (conversion)')
@@ -487,13 +531,13 @@ const makeMessagesSocket = (config) => {
487
531
  const pnUsersBeingFetched = new Set()
488
532
 
489
533
  for (const jid of jidsRequiringFetch) {
490
- const user = WABinary_1.jidDecode(jid)?.user
534
+ const user = jidDecode(jid)?.user
491
535
 
492
536
  if (user) {
493
- if (WABinary_1.isLidUser(jid)) {
537
+ if (isLidUser(jid)) {
494
538
  lidUsersBeingFetched.add(user)
495
539
  }
496
- else if (WABinary_1.isJidUser(jid)) {
540
+ else if (isJidUser(jid)) {
497
541
  pnUsersBeingFetched.add(user)
498
542
  }
499
543
  }
@@ -514,7 +558,7 @@ const makeMessagesSocket = (config) => {
514
558
  attrs: {
515
559
  xmlns: 'encrypt',
516
560
  type: 'get',
517
- to: WABinary_1.S_WHATSAPP_NET
561
+ to: S_WHATSAPP_NET
518
562
  },
519
563
  content: [
520
564
  {
@@ -528,7 +572,7 @@ const makeMessagesSocket = (config) => {
528
572
  ]
529
573
  })
530
574
 
531
- await Utils_1.parseAndInjectE2ESessions(result, signalRepository)
575
+ await parseAndInjectE2ESessions(result, signalRepository)
532
576
  didFetchNewSession = true
533
577
  }
534
578
  return didFetchNewSession
@@ -538,17 +582,17 @@ const makeMessagesSocket = (config) => {
538
582
  const sendPeerDataOperationMessage = async (pdoMessage) => {
539
583
  //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
540
584
  if (!authState.creds.me?.id) {
541
- throw new boom_1.Boom('Not authenticated')
585
+ throw new Boom('Not authenticated')
542
586
  }
543
587
 
544
588
  const protocolMessage = {
545
589
  protocolMessage: {
546
590
  peerDataOperationRequestMessage: pdoMessage,
547
- type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
591
+ type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
548
592
  }
549
593
  }
550
594
 
551
- const meJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
595
+ const meJid = jidNormalizedUser(authState.creds.me.id)
552
596
 
553
597
  const msgId = await relayMessage(meJid, protocolMessage, {
554
598
  additionalAttributes: {
@@ -572,7 +616,7 @@ const makeMessagesSocket = (config) => {
572
616
 
573
617
  const meId = authState.creds.me.id
574
618
  const meLid = authState.creds.me?.lid
575
- const meLidUser = meLid ? WABinary_1.jidDecode(meLid)?.user : null
619
+ const meLidUser = meLid ? jidDecode(meLid)?.user : null
576
620
  const devicesByUser = new Map()
577
621
 
578
622
  for (const patchedMessageWithJid of patched) {
@@ -581,7 +625,7 @@ const makeMessagesSocket = (config) => {
581
625
  continue
582
626
 
583
627
  // Extract user from JID for grouping
584
- const decoded = WABinary_1.jidDecode(wireJid)
628
+ const decoded = jidDecode(wireJid)
585
629
  const user = decoded?.user
586
630
 
587
631
  if (!user)
@@ -601,7 +645,7 @@ const makeMessagesSocket = (config) => {
601
645
 
602
646
  // Helper to get encryption JID with LID migration
603
647
  const getEncryptionJid = async (wireJid) => {
604
- if (!WABinary_1.isJidUser(wireJid))
648
+ if (!isJidUser(wireJid))
605
649
  return wireJid
606
650
 
607
651
  try {
@@ -611,16 +655,16 @@ const makeMessagesSocket = (config) => {
611
655
  return wireJid
612
656
 
613
657
  // Preserve device ID from original wire JID
614
- const wireDecoded = WABinary_1.jidDecode(wireJid)
658
+ const wireDecoded = jidDecode(wireJid)
615
659
  const deviceId = wireDecoded?.device || 0
616
- const lidDecoded = WABinary_1.jidDecode(lidForPN)
617
- const lidWithDevice = WABinary_1.jidEncode(lidDecoded?.user, 'lid', deviceId)
660
+ const lidDecoded = jidDecode(lidForPN)
661
+ const lidWithDevice = jidEncode(lidDecoded?.user, 'lid', deviceId)
618
662
 
619
663
  // Migrate session to LID for unified encryption layer
620
664
  try {
621
665
  const migrationResult = await signalRepository.migrateSession([wireJid], lidWithDevice)
622
- const recipientUser = WABinary_1.jidNormalizedUser(wireJid)
623
- const ownPnUser = WABinary_1.jidNormalizedUser(meId)
666
+ const recipientUser = jidNormalizedUser(wireJid)
667
+ const ownPnUser = jidNormalizedUser(meId)
624
668
  const isOwnDevice = recipientUser === ownPnUser
625
669
  logger.info({ wireJid, lidWithDevice, isOwnDevice }, 'Migrated to LID encryption')
626
670
 
@@ -653,8 +697,8 @@ const makeMessagesSocket = (config) => {
653
697
  let messageToEncrypt = patchedMessage
654
698
 
655
699
  if (dsmMessage) {
656
- const { user: targetUser } = WABinary_1.jidDecode(wireJid)
657
- const { user: ownPnUser } = WABinary_1.jidDecode(meId)
700
+ const { user: targetUser } = jidDecode(wireJid)
701
+ const { user: ownPnUser } = jidDecode(meId)
658
702
  const ownLidUser = meLidUser
659
703
 
660
704
  // Check if this is our device (same user, different device)
@@ -669,7 +713,7 @@ const makeMessagesSocket = (config) => {
669
713
  }
670
714
  }
671
715
 
672
- const bytes = Utils_1.encodeWAMessage(messageToEncrypt)
716
+ const bytes = encodeWAMessage(messageToEncrypt)
673
717
 
674
718
  // Get encryption JID with LID migration
675
719
  const encryptionJid = await getEncryptionJid(wireJid)
@@ -718,7 +762,7 @@ const makeMessagesSocket = (config) => {
718
762
  let didPushAdditional = false
719
763
  let shouldIncludeDeviceIdentity = false
720
764
 
721
- const { user, server } = WABinary_1.jidDecode(jid)
765
+ const { user, server } = jidDecode(jid)
722
766
 
723
767
  const statusJid = 'status@broadcast'
724
768
  const isGroup = server === 'g.us'
@@ -741,7 +785,7 @@ const makeMessagesSocket = (config) => {
741
785
  logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation')
742
786
  }
743
787
 
744
- msgId = msgId || Utils_1.generateMessageID(authState.creds.me.id)
788
+ msgId = msgId || generateMessageID(authState.creds.me.id)
745
789
  useUserDevicesCache = useUserDevicesCache !== false
746
790
  useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
747
791
 
@@ -762,7 +806,7 @@ const makeMessagesSocket = (config) => {
762
806
 
763
807
  const regexGroupOld = /^(\d{1,15})-(\d+)@g\.us$/
764
808
 
765
- const messages = Utils_1.normalizeMessageContent(message)
809
+ const messages = normalizeMessageContent(message)
766
810
 
767
811
  const buttonType = getButtonType(messages)
768
812
  const pollMessage = messages.pollCreationMessage || messages.pollCreationMessageV2 || messages.pollCreationMessageV3
@@ -776,7 +820,7 @@ const makeMessagesSocket = (config) => {
776
820
  additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' }
777
821
  }
778
822
 
779
- const { user, device } = WABinary_1.jidDecode(participant.jid)
823
+ const { user, device } = jidDecode(participant.jid)
780
824
 
781
825
  devices.push({
782
826
  user,
@@ -835,7 +879,7 @@ const makeMessagesSocket = (config) => {
835
879
  }
836
880
 
837
881
  if (!isStatus) {
838
- const groupAddressingMode = groupData?.addressingMode || (isLid ? Types_1.WAMessageAddressingMode.LID : Types_1.WAMessageAddressingMode.PN)
882
+ const groupAddressingMode = groupData?.addressingMode || (isLid ? WAMessageAddressingMode.LID : WAMessageAddressingMode.PN)
839
883
  additionalAttributes = {
840
884
  ...additionalAttributes,
841
885
  addressing_mode: groupAddressingMode
@@ -846,8 +890,8 @@ const makeMessagesSocket = (config) => {
846
890
  devices.push(...additionalDevices)
847
891
  }
848
892
 
849
- const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)))
850
- const bytes = Utils_1.encodeWAMessage(patched)
893
+ const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)))
894
+ const bytes = encodeWAMessage(patched)
851
895
 
852
896
  // This should match the group's addressing mode and conversation context
853
897
  const groupAddressingMode = groupData?.addressingMode || (isLid ? 'lid' : 'pn')
@@ -910,13 +954,13 @@ const makeMessagesSocket = (config) => {
910
954
  }
911
955
 
912
956
  // Message delete
913
- if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
957
+ if (message.protocolMessage?.type === proto.Message.ProtocolMessage.Type.REVOKE) {
914
958
  msgId = message.protocolMessage.key?.id
915
959
  message = {}
916
960
  }
917
961
 
918
962
  const patched = await patchMessageBeforeSending(message, [])
919
- const bytes = Utils_1.encodeNewsletterMessage(patched)
963
+ const bytes = encodeNewsletterMessage(patched)
920
964
 
921
965
  binaryNodeContent.push({
922
966
  tag: 'plaintext',
@@ -926,24 +970,24 @@ const makeMessagesSocket = (config) => {
926
970
  }
927
971
 
928
972
  else {
929
- const { user: ownUser } = WABinary_1.jidDecode(ownId)
973
+ const { user: ownUser } = jidDecode(ownId)
930
974
 
931
975
  if (!participant) {
932
976
  const targetUserServer = isLid ? 'lid' : 's.whatsapp.net'
933
977
  devices.push({
934
978
  user,
935
979
  device: 0,
936
- wireJid: WABinary_1.jidEncode(user, targetUserServer, 0)
980
+ wireJid: jidEncode(user, targetUserServer, 0)
937
981
  })
938
982
 
939
983
  // Own user matches conversation addressing mode
940
984
  if (user !== ownUser) {
941
985
  const ownUserServer = isLid ? 'lid' : 's.whatsapp.net';
942
- const ownUserForAddressing = isLid && meLid ? WABinary_1.jidDecode(meLid).user : WABinary_1.jidDecode(meId).user
986
+ const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user
943
987
  devices.push({
944
988
  user: ownUserForAddressing,
945
989
  device: 0,
946
- wireJid: WABinary_1.jidEncode(ownUserForAddressing, ownUserServer, 0)
990
+ wireJid: jidEncode(ownUserForAddressing, ownUserServer, 0)
947
991
  })
948
992
  }
949
993
 
@@ -953,15 +997,15 @@ const makeMessagesSocket = (config) => {
953
997
 
954
998
  // Use conversation-appropriate sender identity
955
999
  const senderIdentity = isLid && meLid
956
- ? WABinary_1.jidEncode(WABinary_1.jidDecode(meLid)?.user, 'lid', undefined)
957
- : WABinary_1.jidEncode(WABinary_1.jidDecode(meId)?.user, 's.whatsapp.net', undefined)
1000
+ ? jidEncode(jidDecode(meLid)?.user, 'lid', undefined)
1001
+ : jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined)
958
1002
 
959
1003
  // Enumerate devices for sender and target with consistent addressing
960
1004
  const sessionDevices = await getUSyncDevices([senderIdentity, jid], false, false)
961
1005
  devices.push(...sessionDevices)
962
1006
  logger.debug({
963
1007
  deviceCount: devices.length,
964
- devices: devices.map(d => `${d.user}:${d.device}@${WABinary_1.jidDecode(d.wireJid)?.server}`)
1008
+ devices: devices.map(d => `${d.user}:${d.device}@${jidDecode(d.wireJid)?.server}`)
965
1009
  }, 'Device enumeration complete with unified addressing')
966
1010
  }
967
1011
  }
@@ -970,8 +1014,8 @@ const makeMessagesSocket = (config) => {
970
1014
  const meJids = []
971
1015
  const otherJids = []
972
1016
 
973
- const { user: mePnUser } = WABinary_1.jidDecode(meId)
974
- const { user: meLidUser } = meLid ? WABinary_1.jidDecode(meLid) : { user: null }
1017
+ const { user: mePnUser } = jidDecode(meId)
1018
+ const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null }
975
1019
 
976
1020
  for (const { user, wireJid } of devices) {
977
1021
  const isExactSenderDevice = wireJid === meId || (meLid && wireJid === meLid)
@@ -1008,7 +1052,7 @@ const makeMessagesSocket = (config) => {
1008
1052
  participants.push(...otherNodes)
1009
1053
 
1010
1054
  if (meJids.length > 0 || otherJids.length > 0) {
1011
- extraAttrs['phash'] = Utils_1.generateParticipantHashV2([...meJids, ...otherJids])
1055
+ extraAttrs['phash'] = generateParticipantHashV2([...meJids, ...otherJids])
1012
1056
  }
1013
1057
 
1014
1058
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2
@@ -1047,12 +1091,12 @@ const makeMessagesSocket = (config) => {
1047
1091
  // ensure the message is only sent to that person
1048
1092
  // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
1049
1093
  if (participant) {
1050
- if (WABinary_1.isJidGroup(destinationJid)) {
1094
+ if (isJidGroup(destinationJid)) {
1051
1095
  stanza.attrs.to = destinationJid
1052
1096
  stanza.attrs.participant = participant.jid
1053
1097
  }
1054
1098
 
1055
- else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
1099
+ else if (areJidsSameUser(participant.jid, meId)) {
1056
1100
  stanza.attrs.to = participant.jid
1057
1101
  stanza.attrs.recipient = destinationJid
1058
1102
  }
@@ -1070,7 +1114,7 @@ const makeMessagesSocket = (config) => {
1070
1114
  stanza.content.push({
1071
1115
  tag: 'device-identity',
1072
1116
  attrs: {},
1073
- content: Utils_1.encodeSignedDeviceIdentity(authState.creds.account, true)
1117
+ content: encodeSignedDeviceIdentity(authState.creds.account, true)
1074
1118
  })
1075
1119
 
1076
1120
  logger.debug({ jid }, 'adding device identity')
@@ -1099,7 +1143,7 @@ const makeMessagesSocket = (config) => {
1099
1143
 
1100
1144
  if (!isNewsletter && buttonType) {
1101
1145
  const buttonsNode = getButtonArgs(messages)
1102
- const filteredButtons = WABinary_1.getBinaryFilteredButtons(additionalNodes ? additionalNodes : [])
1146
+ const filteredButtons = getBinaryFilteredButtons(additionalNodes ? additionalNodes : [])
1103
1147
 
1104
1148
  if (filteredButtons) {
1105
1149
  stanza.content.push(...additionalNodes)
@@ -1119,7 +1163,7 @@ const makeMessagesSocket = (config) => {
1119
1163
  }
1120
1164
  }
1121
1165
 
1122
- const filteredBizBot = WABinary_1.getBinaryFilteredBizBot(additionalNodes ? additionalNodes : [])
1166
+ const filteredBizBot = getBinaryFilteredBizBot(additionalNodes ? additionalNodes : [])
1123
1167
 
1124
1168
  if (filteredBizBot) {
1125
1169
  stanza.content.push(...additionalNodes)
@@ -1149,7 +1193,7 @@ const makeMessagesSocket = (config) => {
1149
1193
  }
1150
1194
 
1151
1195
  const getTypeMessage = (msg) => {
1152
- const message = Utils_1.normalizeMessageContent(msg)
1196
+ const message = normalizeMessageContent(msg)
1153
1197
  if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
1154
1198
  return 'poll'
1155
1199
  }
@@ -1268,7 +1312,7 @@ const makeMessagesSocket = (config) => {
1268
1312
  attrs: {
1269
1313
  actual_actors: '2',
1270
1314
  host_storage: '2',
1271
- privacy_mode_ts: Utils_1.unixTimestampSeconds().toString()
1315
+ privacy_mode_ts: unixTimestampSeconds().toString()
1272
1316
  },
1273
1317
  content: [{
1274
1318
  tag: 'interactive',
@@ -1298,7 +1342,7 @@ const makeMessagesSocket = (config) => {
1298
1342
  attrs: {
1299
1343
  actual_actors: '2',
1300
1344
  host_storage: '2',
1301
- privacy_mode_ts: Utils_1.unixTimestampSeconds().toString()
1345
+ privacy_mode_ts: unixTimestampSeconds().toString()
1302
1346
  },
1303
1347
  content: [{
1304
1348
  tag: 'interactive',
@@ -1327,7 +1371,7 @@ const makeMessagesSocket = (config) => {
1327
1371
  attrs: {
1328
1372
  actual_actors: '2',
1329
1373
  host_storage: '2',
1330
- privacy_mode_ts: Utils_1.unixTimestampSeconds().toString()
1374
+ privacy_mode_ts: unixTimestampSeconds().toString()
1331
1375
  },
1332
1376
  content: [{
1333
1377
  tag: 'list',
@@ -1349,19 +1393,19 @@ const makeMessagesSocket = (config) => {
1349
1393
  attrs: {
1350
1394
  actual_actors: '2',
1351
1395
  host_storage: '2',
1352
- privacy_mode_ts: Utils_1.unixTimestampSeconds().toString()
1396
+ privacy_mode_ts: unixTimestampSeconds().toString()
1353
1397
  }
1354
1398
  }
1355
1399
  }
1356
1400
  }
1357
1401
 
1358
1402
  const getPrivacyTokens = async (jids) => {
1359
- const t = Utils_1.unixTimestampSeconds().toString()
1403
+ const t = unixTimestampSeconds().toString()
1360
1404
 
1361
1405
  const result = await query({
1362
1406
  tag: 'iq',
1363
1407
  attrs: {
1364
- to: WABinary_1.S_WHATSAPP_NET,
1408
+ to: S_WHATSAPP_NET,
1365
1409
  type: 'set',
1366
1410
  xmlns: 'privacy'
1367
1411
  },
@@ -1372,7 +1416,7 @@ const makeMessagesSocket = (config) => {
1372
1416
  content: jids.map(jid => ({
1373
1417
  tag: 'token',
1374
1418
  attrs: {
1375
- jid: WABinary_1.jidNormalizedUser(jid),
1419
+ jid: jidNormalizedUser(jid),
1376
1420
  t,
1377
1421
  type: 'trusted_contact'
1378
1422
  }
@@ -1385,7 +1429,7 @@ const makeMessagesSocket = (config) => {
1385
1429
  }
1386
1430
 
1387
1431
  const getEphemeralGroup = (jid) => {
1388
- if (!WABinary_1.isJidGroup(jid)) throw new TypeError("Jid should originate from a group!")
1432
+ if (!isJidGroup(jid)) throw new TypeError("Jid should originate from a group!")
1389
1433
 
1390
1434
  return groupQuery(jid, 'get', [{
1391
1435
  tag: 'query',
@@ -1393,13 +1437,13 @@ const makeMessagesSocket = (config) => {
1393
1437
  request: 'interactive'
1394
1438
  }
1395
1439
  }])
1396
- .then((groups) => WABinary_1.getBinaryNodeChild(groups, 'group'))
1397
- .then((metadata) => WABinary_1.getBinaryNodeChild(metadata, 'ephemeral')?.attrs?.expiration || 0)
1440
+ .then((groups) => getBinaryNodeChild(groups, 'group'))
1441
+ .then((metadata) => getBinaryNodeChild(metadata, 'ephemeral')?.attrs?.expiration || 0)
1398
1442
  }
1399
1443
 
1400
- const waUploadToServer = Utils_1.getWAUploadToServer(config, refreshMediaConn)
1444
+ const waUploadToServer = getWAUploadToServer(config, refreshMediaConn)
1401
1445
 
1402
- const waitForMsgMediaUpdate = Utils_1.bindWaitForEvent(ev, 'messages.media-update')
1446
+ const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update')
1403
1447
 
1404
1448
  return {
1405
1449
  ...suki,
@@ -1419,10 +1463,10 @@ const makeMessagesSocket = (config) => {
1419
1463
  createParticipantNodes,
1420
1464
  sendPeerDataOperationMessage,
1421
1465
  updateMediaMessage: async (message) => {
1422
- const content = Utils_1.assertMediaContent(message.message)
1466
+ const content = assertMediaContent(message.message)
1423
1467
  const mediaKey = content.mediaKey
1424
1468
  const meId = authState.creds.me.id
1425
- const node = await Utils_1.encryptMediaRetryRequest(message.key, mediaKey, meId)
1469
+ const node = await encryptMediaRetryRequest(message.key, mediaKey, meId)
1426
1470
  let error = undefined
1427
1471
 
1428
1472
  await Promise.all([
@@ -1436,17 +1480,17 @@ const makeMessagesSocket = (config) => {
1436
1480
 
1437
1481
  else {
1438
1482
  try {
1439
- const media = await Utils_1.decryptMediaRetryData(result.media, mediaKey, result.key.id)
1483
+ const media = await decryptMediaRetryData(result.media, mediaKey, result.key.id)
1440
1484
 
1441
- if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
1442
- const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result]
1485
+ if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
1486
+ const resultStr = proto.MediaRetryNotification.ResultType[media.result]
1443
1487
 
1444
- throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: Utils_1.getStatusCodeForMediaRetry(media.result) || 404 })
1488
+ throw new Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: getStatusCodeForMediaRetry(media.result) || 404 })
1445
1489
  }
1446
1490
 
1447
1491
  content.directPath = media.directPath
1448
1492
 
1449
- content.url = Utils_1.getUrlFromDirectPath(content.directPath)
1493
+ content.url = getUrlFromDirectPath(content.directPath)
1450
1494
 
1451
1495
  logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful')
1452
1496
  }
@@ -1472,24 +1516,24 @@ const makeMessagesSocket = (config) => {
1472
1516
  return message
1473
1517
  },
1474
1518
  sendStatusMentions: async (content, jids = []) => {
1475
- const userJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
1519
+ const userJid = jidNormalizedUser(authState.creds.me.id)
1476
1520
  let allUsers = new Set()
1477
1521
  allUsers.add(userJid)
1478
1522
 
1479
1523
  for (const id of jids) {
1480
- const isGroup = WABinary_1.isJidGroup(id)
1481
- const isPrivate = WABinary_1.isJidUser(id)
1524
+ const isGroup = isJidGroup(id)
1525
+ const isPrivate = isJidUser(id)
1482
1526
 
1483
1527
  if (isGroup) {
1484
1528
  try {
1485
1529
  const metadata = await cachedGroupMetadata(id) || await groupMetadata(id)
1486
- const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id))
1530
+ const participants = metadata.participants.map(p => jidNormalizedUser(p.id))
1487
1531
  participants.forEach(jid => allUsers.add(jid))
1488
1532
  } catch (error) {
1489
1533
  logger.error(`Error getting metadata for group ${id}: ${error}`)
1490
1534
  }
1491
1535
  } else if (isPrivate) {
1492
- allUsers.add(WABinary_1.jidNormalizedUser(id))
1536
+ allUsers.add(jidNormalizedUser(id))
1493
1537
  }
1494
1538
  }
1495
1539
 
@@ -1529,10 +1573,10 @@ const makeMessagesSocket = (config) => {
1529
1573
  let msg
1530
1574
  let mediaHandle
1531
1575
  try {
1532
- msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
1576
+ msg = await generateWAMessage(STORIES_JID, messageContent, {
1533
1577
  logger,
1534
1578
  userJid,
1535
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
1579
+ getUrlInfo: text => getUrlInfo(text, {
1536
1580
  thumbnailWidth: linkPreviewImageThumbnailWidth,
1537
1581
  fetchOpts: { timeout: 3000, ...axiosOptions || {} },
1538
1582
  logger,
@@ -1555,7 +1599,7 @@ const makeMessagesSocket = (config) => {
1555
1599
  throw error
1556
1600
  }
1557
1601
 
1558
- await relayMessage(WABinary_1.STORIES_JID, msg.message, {
1602
+ await relayMessage(STORIES_JID, msg.message, {
1559
1603
  messageId: msg.key.id,
1560
1604
  statusJidList: uniqueUsers,
1561
1605
  additionalNodes: [
@@ -1568,7 +1612,7 @@ const makeMessagesSocket = (config) => {
1568
1612
  attrs: {},
1569
1613
  content: jids.map(jid => ({
1570
1614
  tag: 'to',
1571
- attrs: { jid: WABinary_1.jidNormalizedUser(jid) }
1615
+ attrs: { jid: jidNormalizedUser(jid) }
1572
1616
  }))
1573
1617
  }]
1574
1618
  }]
@@ -1576,8 +1620,8 @@ const makeMessagesSocket = (config) => {
1576
1620
 
1577
1621
  for (const id of jids) {
1578
1622
  try {
1579
- const normalizedId = WABinary_1.jidNormalizedUser(id)
1580
- const isPrivate = WABinary_1.isJidUser(normalizedId)
1623
+ const normalizedId = jidNormalizedUser(id)
1624
+ const isPrivate = isJidUser(normalizedId)
1581
1625
  const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage'
1582
1626
 
1583
1627
  const protocolMessage = {
@@ -1590,11 +1634,11 @@ const makeMessagesSocket = (config) => {
1590
1634
  }
1591
1635
  },
1592
1636
  messageContextInfo: {
1593
- messageSecret: crypto_1.randomBytes(32)
1637
+ messageSecret: randomBytes(32)
1594
1638
  }
1595
1639
  }
1596
1640
 
1597
- const statusMsg = await Utils_1.generateWAMessageFromContent(normalizedId,
1641
+ const statusMsg = await generateWAMessageFromContent(normalizedId,
1598
1642
  protocolMessage,
1599
1643
  {}
1600
1644
  )
@@ -1612,7 +1656,7 @@ const makeMessagesSocket = (config) => {
1612
1656
  }
1613
1657
  )
1614
1658
 
1615
- await Utils_1.delay(2000)
1659
+ await delay(2000)
1616
1660
  } catch (error) {
1617
1661
  logger.error(`Error sending to ${id}: ${error}`)
1618
1662
  }
@@ -1625,7 +1669,7 @@ const makeMessagesSocket = (config) => {
1625
1669
  const additionalAttributes = {}
1626
1670
 
1627
1671
  if (!options.ephemeralExpiration) {
1628
- if (WABinary_1.isJidGroup(jid)) {
1672
+ if (isJidGroup(jid)) {
1629
1673
  const expiration = await getEphemeralGroup(jid)
1630
1674
  options.ephemeralExpiration = expiration
1631
1675
  }
@@ -1634,19 +1678,19 @@ const makeMessagesSocket = (config) => {
1634
1678
  if (typeof content === 'object' &&
1635
1679
  'disappearingMessagesInChat' in content &&
1636
1680
  typeof content['disappearingMessagesInChat'] !== 'undefined' &&
1637
- WABinary_1.isJidGroup(jid)) {
1681
+ isJidGroup(jid)) {
1638
1682
 
1639
1683
  const { disappearingMessagesInChat } = content
1640
1684
 
1641
1685
  const value = typeof disappearingMessagesInChat === 'boolean' ?
1642
- (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
1686
+ (disappearingMessagesInChat ? WA_DEFAULT_EPHEMERAL : 0) :
1643
1687
  disappearingMessagesInChat
1644
1688
 
1645
1689
  await groupToggleEphemeral(jid, value)
1646
1690
  }
1647
1691
 
1648
1692
  else if (typeof content === 'object' && 'album' in content && content.album) {
1649
- const albumMsg = await Utils_1.prepareAlbumMessageContent(jid, content.album, {
1693
+ const albumMsg = await prepareAlbumMessageContent(jid, content.album, {
1650
1694
  suki: {
1651
1695
  relayMessage,
1652
1696
  waUploadToServer
@@ -1656,7 +1700,7 @@ const makeMessagesSocket = (config) => {
1656
1700
  })
1657
1701
 
1658
1702
  for (const media of albumMsg) {
1659
- await Utils_1.delay(options.delay || 500)
1703
+ await delay(options.delay || 500)
1660
1704
  await relayMessage(jid, media.message, { messageId: media.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes: options.additionalNodes, AI: options.ai })
1661
1705
  }
1662
1706
 
@@ -1666,10 +1710,10 @@ const makeMessagesSocket = (config) => {
1666
1710
  else {
1667
1711
  let mediaHandle
1668
1712
 
1669
- const fullMsg = await Utils_1.generateWAMessage(jid, content, {
1713
+ const fullMsg = await generateWAMessage(jid, content, {
1670
1714
  logger,
1671
1715
  userJid,
1672
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
1716
+ getUrlInfo: text => getUrlInfo(text, {
1673
1717
  thumbnailWidth: linkPreviewImageThumbnailWidth,
1674
1718
  fetchOpts: {
1675
1719
  timeout: 3000,
@@ -1683,13 +1727,13 @@ const makeMessagesSocket = (config) => {
1683
1727
  getProfilePicUrl: profilePictureUrl,
1684
1728
  getCallLink: createCallLink,
1685
1729
  upload: async (encFilePath, opts) => {
1686
- const up = await waUploadToServer(encFilePath, { ...opts, newsletter: WABinary_1.isJidNewsletter(jid) })
1730
+ const up = await waUploadToServer(encFilePath, { ...opts, newsletter: isJidNewsletter(jid) })
1687
1731
  mediaHandle = up.handle
1688
1732
  return up
1689
1733
  },
1690
1734
  mediaCache: config.mediaCache,
1691
1735
  options: config.options,
1692
- messageId: Utils_1.generateMessageID(userJid),
1736
+ messageId: generateMessageID(userJid),
1693
1737
  ...options,
1694
1738
  })
1695
1739
 
@@ -1700,7 +1744,7 @@ const makeMessagesSocket = (config) => {
1700
1744
 
1701
1745
  if (isDelete || isKeep) {
1702
1746
  // if the chat is a group, and I am not the author, then delete the message as an admin
1703
- if (WABinary_1.isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe || WABinary_1.isJidNewsletter(jid)) {
1747
+ if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe || isJidNewsletter(jid)) {
1704
1748
  additionalAttributes.edit = '8'
1705
1749
  }
1706
1750
 
@@ -1710,7 +1754,7 @@ const makeMessagesSocket = (config) => {
1710
1754
  }
1711
1755
 
1712
1756
  else if (isEdit) {
1713
- additionalAttributes.edit = WABinary_1.isJidNewsletter(jid) ? '3' : '1'
1757
+ additionalAttributes.edit = isJidNewsletter(jid) ? '3' : '1'
1714
1758
  }
1715
1759
 
1716
1760
  else if (isPin) {