@fhynella/baileys 2.0.5 → 2.1.7

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 (204) hide show
  1. package/lib/Defaults/connection.js +51 -0
  2. package/lib/Defaults/constants.js +62 -0
  3. package/lib/Defaults/history.js +17 -0
  4. package/lib/Defaults/index.js +36 -142
  5. package/lib/Defaults/media.js +48 -0
  6. package/lib/Defaults/prefix.js +18 -0
  7. package/lib/Signal/Group/group-session-builder.js +10 -42
  8. package/lib/Signal/Group/group_cipher.js +9 -6
  9. package/lib/Signal/Group/index.js +39 -53
  10. package/lib/Signal/Group/keyhelper.js +8 -41
  11. package/lib/Signal/Group/sender-chain-key.js +4 -4
  12. package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
  13. package/lib/Signal/Group/sender-key-message.js +12 -8
  14. package/lib/Signal/Group/sender-key-record.js +7 -7
  15. package/lib/Signal/Group/sender-key-state.js +4 -4
  16. package/lib/Signal/Group/sender-message-key.js +2 -2
  17. package/lib/Signal/libsignal.js +45 -69
  18. package/lib/Signal/lid-mapping.js +15 -11
  19. package/lib/Socket/Client/types.js +2 -2
  20. package/lib/Socket/Client/websocket.js +16 -14
  21. package/lib/Socket/business.js +41 -32
  22. package/lib/Socket/chats.js +123 -98
  23. package/lib/Socket/community.js +50 -40
  24. package/lib/Socket/groups.js +59 -47
  25. package/lib/Socket/index.js +4 -4
  26. package/lib/Socket/messages-recv.js +219 -172
  27. package/lib/Socket/messages-send.js +187 -211
  28. package/lib/Socket/newsletter.js +61 -47
  29. package/lib/Socket/socket.js +133 -90
  30. package/lib/Socket/usync.js +6 -6
  31. package/lib/Store/index.js +27 -11
  32. package/lib/Store/make-cache-manager-store.js +14 -15
  33. package/lib/Store/make-in-memory-store.js +28 -24
  34. package/lib/Types/LabelAssociation.js +2 -2
  35. package/lib/Types/Message.js +6 -6
  36. package/lib/Types/MexUpdates.js +5 -5
  37. package/lib/Types/State.js +4 -4
  38. package/lib/Types/index.js +28 -12
  39. package/lib/Utils/auth-utils.js +28 -26
  40. package/lib/Utils/baileys-event-stream.js +68 -69
  41. package/lib/Utils/business.js +63 -53
  42. package/lib/Utils/chat-utils.js +81 -71
  43. package/lib/Utils/crypto.js +25 -45
  44. package/lib/Utils/decode-wa-message.js +319 -311
  45. package/lib/Utils/event-buffer.js +21 -22
  46. package/lib/Utils/generics.js +52 -75
  47. package/lib/Utils/history.js +21 -21
  48. package/lib/Utils/index.js +27 -13
  49. package/lib/Utils/link-preview.js +7 -30
  50. package/lib/Utils/logger.js +5 -5
  51. package/lib/Utils/lt-hash.js +3 -3
  52. package/lib/Utils/message-retry-manager.js +4 -4
  53. package/lib/Utils/messages-media.js +104 -109
  54. package/lib/Utils/messages.js +203 -171
  55. package/lib/Utils/noise-handler.js +28 -19
  56. package/lib/Utils/process-message.js +111 -96
  57. package/lib/Utils/signal.js +36 -25
  58. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  59. package/lib/Utils/validate-connection.js +52 -45
  60. package/lib/WABinary/decode.js +6 -32
  61. package/lib/WABinary/encode.js +3 -29
  62. package/lib/WABinary/generic-utils.js +4 -4
  63. package/lib/WABinary/index.js +27 -11
  64. package/lib/WAM/encode.js +16 -8
  65. package/lib/WAM/index.js +27 -11
  66. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  67. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  68. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  69. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  70. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  71. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  72. package/lib/WAUSync/Protocols/index.js +27 -11
  73. package/lib/WAUSync/USyncQuery.js +17 -10
  74. package/lib/WAUSync/index.js +27 -11
  75. package/lib/index.js +60 -31
  76. package/package.json +15 -6
  77. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  78. package/WAProto/Adv/Adv.d.ts +0 -643
  79. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  80. package/WAProto/Cert/Cert.d.ts +0 -613
  81. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  82. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  83. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  84. package/WAProto/E2E/E2E.d.ts +0 -41724
  85. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  86. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  87. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  88. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  89. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  90. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  91. package/WAProto/Protocol/Protocol.d.ts +0 -270
  92. package/WAProto/Reporting/Reporting.d.ts +0 -371
  93. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  94. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  95. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  96. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  97. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  98. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  99. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  100. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  101. package/WAProto/Web/Web.d.ts +0 -46383
  102. package/WAProto/index.d.ts +0 -55
  103. package/lib/Defaults/index.d.ts +0 -77
  104. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  105. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  106. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  107. package/lib/Signal/Group/index.d.ts +0 -11
  108. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  109. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  110. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  111. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  112. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  113. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  114. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  115. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  116. package/lib/Signal/libsignal.d.ts +0 -8
  117. package/lib/Signal/lid-mapping.d.ts +0 -28
  118. package/lib/Socket/.nomedia +0 -0
  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 -197
  127. package/lib/Socket/messages-recv.d.ts +0 -180
  128. package/lib/Socket/messages-send.d.ts +0 -169
  129. package/lib/Socket/messages-send.d.ts.bak +0 -165
  130. package/lib/Socket/messages-send.js.bak +0 -1812
  131. package/lib/Socket/newsletter.d.ts +0 -145
  132. package/lib/Socket/socket.d.ts +0 -45
  133. package/lib/Socket/usync.d.ts +0 -37
  134. package/lib/Store/index.d.ts +0 -4
  135. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  136. package/lib/Store/make-in-memory-store.d.ts +0 -123
  137. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  138. package/lib/Store/object-repository.d.ts +0 -10
  139. package/lib/Types/Auth.d.ts +0 -121
  140. package/lib/Types/Bussiness.d.ts +0 -28
  141. package/lib/Types/Call.d.ts +0 -14
  142. package/lib/Types/Chat.d.ts +0 -143
  143. package/lib/Types/Contact.d.ts +0 -23
  144. package/lib/Types/Events.d.ts +0 -226
  145. package/lib/Types/GroupMetadata.d.ts +0 -66
  146. package/lib/Types/Label.d.ts +0 -48
  147. package/lib/Types/LabelAssociation.d.ts +0 -35
  148. package/lib/Types/Message.d.ts +0 -484
  149. package/lib/Types/MexUpdates.d.ts +0 -9
  150. package/lib/Types/Newsletter.d.ts +0 -109
  151. package/lib/Types/Product.d.ts +0 -92
  152. package/lib/Types/Signal.d.ts +0 -98
  153. package/lib/Types/Socket.d.ts +0 -141
  154. package/lib/Types/State.d.ts +0 -41
  155. package/lib/Types/USync.d.ts +0 -26
  156. package/lib/Types/index.d.ts +0 -80
  157. package/lib/Utils/auth-utils.d.ts +0 -21
  158. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  159. package/lib/Utils/business.d.ts +0 -29
  160. package/lib/Utils/chat-utils.d.ts +0 -82
  161. package/lib/Utils/crypto.d.ts +0 -56
  162. package/lib/Utils/decode-wa-message.d.ts +0 -53
  163. package/lib/Utils/event-buffer.d.ts +0 -39
  164. package/lib/Utils/generics.d.ts +0 -117
  165. package/lib/Utils/history.d.ts +0 -23
  166. package/lib/Utils/index.d.ts +0 -20
  167. package/lib/Utils/link-preview.d.ts +0 -23
  168. package/lib/Utils/logger.d.ts +0 -13
  169. package/lib/Utils/lt-hash.d.ts +0 -14
  170. package/lib/Utils/make-mutex.d.ts +0 -9
  171. package/lib/Utils/message-retry-manager.d.ts +0 -88
  172. package/lib/Utils/messages-media.d.ts +0 -135
  173. package/lib/Utils/messages.d.ts +0 -105
  174. package/lib/Utils/noise-handler.d.ts +0 -20
  175. package/lib/Utils/process-message.d.ts +0 -49
  176. package/lib/Utils/signal.d.ts +0 -42
  177. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  178. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  179. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  180. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  181. package/lib/Utils/use-single-file-auth-state.js +0 -80
  182. package/lib/Utils/validate-connection.d.ts +0 -13
  183. package/lib/WABinary/constants.d.ts +0 -30
  184. package/lib/WABinary/decode.d.ts +0 -9
  185. package/lib/WABinary/encode.d.ts +0 -3
  186. package/lib/WABinary/generic-utils.d.ts +0 -28
  187. package/lib/WABinary/index.d.ts +0 -5
  188. package/lib/WABinary/jid-utils.d.ts +0 -58
  189. package/lib/WABinary/types.d.ts +0 -22
  190. package/lib/WAM/BinaryInfo.d.ts +0 -16
  191. package/lib/WAM/constants.d.ts +0 -47
  192. package/lib/WAM/encode.d.ts +0 -3
  193. package/lib/WAM/index.d.ts +0 -3
  194. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  195. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  196. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  197. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  198. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  199. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  200. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  201. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  202. package/lib/WAUSync/USyncUser.d.ts +0 -12
  203. package/lib/WAUSync/index.d.ts +0 -3
  204. package/lib/index.d.ts +0 -13
@@ -1,16 +1,15 @@
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 events_1 = __importDefault(require("events"))
10
- const Types_1 = require("../Types")
11
- const generics_1 = require("./generics")
12
- const messages_1 = require("./messages")
13
- const process_message_1 = require("./process-message")
5
+ const Events = require("events")
6
+ const { WAMessageStatus } = require("../Types")
7
+ const { trimUndefined } = require("./generics")
8
+ const {
9
+ updateMessageWithReceipt,
10
+ updateMessageWithReaction
11
+ } = require("./messages")
12
+ const { isRealMessage } = require("./process-message")
14
13
 
15
14
  const BUFFERABLE_EVENT = [
16
15
  'messaging-history.set',
@@ -35,7 +34,7 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT)
35
34
  * making the data processing more efficient.
36
35
  */
37
36
  const makeEventBuffer = (logger) => {
38
- const ev = new events_1.default()
37
+ const ev = new Events()
39
38
  const historyCache = new Set()
40
39
  let data = makeBufferData()
41
40
  let isBuffering = false
@@ -210,7 +209,7 @@ function append(data, historyCache, event, eventData, logger) {
210
209
  for (const contact of eventData.contacts) {
211
210
  const existingContact = data.historySets.contacts[contact.id]
212
211
  if (existingContact) {
213
- Object.assign(existingContact, generics_1.trimUndefined(contact))
212
+ Object.assign(existingContact, trimUndefined(contact))
214
213
  }
215
214
  else {
216
215
  const historyContactId = `c:${contact.id}`
@@ -313,14 +312,14 @@ function append(data, historyCache, event, eventData, logger) {
313
312
  }
314
313
  }
315
314
  if (upsert) {
316
- upsert = Object.assign(upsert, generics_1.trimUndefined(contact))
315
+ upsert = Object.assign(upsert, trimUndefined(contact))
317
316
  }
318
317
  else {
319
318
  upsert = contact
320
319
  data.contactUpserts[contact.id] = upsert
321
320
  }
322
321
  if (data.contactUpdates[contact.id]) {
323
- upsert = Object.assign(data.contactUpdates[contact.id], generics_1.trimUndefined(contact))
322
+ upsert = Object.assign(data.contactUpdates[contact.id], trimUndefined(contact))
324
323
  delete data.contactUpdates[contact.id]
325
324
  }
326
325
  }
@@ -383,7 +382,7 @@ function append(data, historyCache, event, eventData, logger) {
383
382
  // if the message was received & read by us
384
383
  // the chat counter must have been incremented
385
384
  // so we need to decrement it
386
- if (update.status === Types_1.WAMessageStatus.READ && !key.fromMe) {
385
+ if (update.status === WAMessageStatus.READ && !key.fromMe) {
387
386
  decrementChatReadCounterIfMsgDidUnread(existing)
388
387
  }
389
388
  }
@@ -421,11 +420,11 @@ function append(data, historyCache, event, eventData, logger) {
421
420
  // const keyStr = stringifyMessageKey(pollUpdateMessageKey)
422
421
  // const existing = data.messagePollings[keyStr]
423
422
  // if(existing) {
424
- // messages_1.updateMessageWithPollUpdate(existing.message, pollUpdates)
423
+ // updateMessageWithPollUpdate(existing.message, pollUpdates)
425
424
  // } else {
426
425
  // data.messagePollings[keyStr] = data.messagePollings[keyStr]
427
426
  // || { pollUpdateMessageKey, pollUpdates: [] }
428
- // messages_1.updateMessageWithPollUpdate(data.messagePollings[keyStr], vote)
427
+ // updateMessageWithPollUpdate(data.messagePollings[keyStr], vote)
429
428
  // }
430
429
  // }
431
430
  // break
@@ -435,12 +434,12 @@ function append(data, historyCache, event, eventData, logger) {
435
434
  const keyStr = stringifyMessageKey(key)
436
435
  const existing = data.messageUpserts[keyStr]
437
436
  if (existing) {
438
- messages_1.updateMessageWithReaction(existing.message, reaction)
437
+ updateMessageWithReaction(existing.message, reaction)
439
438
  }
440
439
  else {
441
440
  data.messageReactions[keyStr] = data.messageReactions[keyStr]
442
441
  || { key, reactions: [] }
443
- messages_1.updateMessageWithReaction(data.messageReactions[keyStr], reaction)
442
+ updateMessageWithReaction(data.messageReactions[keyStr], reaction)
444
443
  }
445
444
  }
446
445
  break
@@ -450,12 +449,12 @@ function append(data, historyCache, event, eventData, logger) {
450
449
  const keyStr = stringifyMessageKey(key)
451
450
  const existing = data.messageUpserts[keyStr]
452
451
  if (existing) {
453
- messages_1.updateMessageWithReceipt(existing.message, receipt)
452
+ updateMessageWithReceipt(existing.message, receipt)
454
453
  }
455
454
  else {
456
455
  data.messageReceipts[keyStr] = data.messageReceipts[keyStr]
457
456
  || { key, userReceipt: [] }
458
- messages_1.updateMessageWithReceipt(data.messageReceipts[keyStr], receipt)
457
+ updateMessageWithReceipt(data.messageReceipts[keyStr], receipt)
459
458
  }
460
459
  }
461
460
  break
@@ -494,8 +493,8 @@ function append(data, historyCache, event, eventData, logger) {
494
493
  // if the message has already been marked read by us
495
494
  const chatId = message.key.remoteJid
496
495
  const chat = data.chatUpdates[chatId] || data.chatUpserts[chatId]
497
- if (process_message_1.isRealMessage(message, '')
498
- && process_message_1.shouldIncrementChatUnread(message)
496
+ if (isRealMessage(message, '')
497
+ && shouldIncrementChatUnread(message)
499
498
  && typeof (chat?.unreadCount) === 'number'
500
499
  && chat.unreadCount > 0) {
501
500
  logger.debug({ chatId: chat.id }, 'decrementing chat counter')
@@ -1,46 +1,21 @@
1
1
  "use strict"
2
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
30
- return (mod && mod.__esModule) ? mod : { "default": mod }
31
- }
32
-
33
3
  Object.defineProperty(exports, "__esModule", { value: true })
34
4
 
35
- const boom_1 = require("@hapi/boom")
36
- const axios_1 = __importDefault(require("axios"))
37
- const crypto_1 = require("crypto")
38
- const crypto_2 = require("./crypto")
39
- const os_1 = require("os")
40
- const WAProto_1 = require("../../WAProto")
41
- const baileys_version_json_1 = require("../Defaults/baileys-version.json")
42
- const Types_1 = require("../Types")
43
- const WABinary_1 = require("../WABinary")
5
+ const { Boom } = require("@hapi/boom")
6
+ const {
7
+ createHash,
8
+ randomBytes
9
+ } = require("crypto")
10
+ const {
11
+ jidDecode,
12
+ getAllBinaryNodeChildren
13
+ } = require("../WABinary")
14
+ const { sha256 } = require("./crypto")
15
+ const { platform } = require("os")
16
+ const { proto } = require("../../WAProto")
17
+ const { version } = require("../Defaults/baileys-version.json")
18
+ const { DisconnectReason } = require("../Types")
44
19
 
45
20
  const COMPANION_PLATFORM_MAP = {
46
21
  'Chrome': '49',
@@ -137,7 +112,7 @@ const Browsers = {
137
112
  return [PLATFORM_MAP['chromeos'], browser, PLATFORM_VERSIONS['chromeos']]
138
113
  },
139
114
  appropriate: (browser) => {
140
- const platform = os_1.platform()
115
+ const platform = platform()
141
116
  const platformName = PLATFORM_MAP[platform] || 'Unknown OS'
142
117
  return [platformName, browser, PLATFORM_VERSIONS[platform] || 'latest']
143
118
  },
@@ -149,17 +124,18 @@ const Browsers = {
149
124
 
150
125
  const Itsuki = async () => {
151
126
  try {
152
- const { data } = await axios_1.default.get('https://raw.githubusercontent.com/Itsukichann/database/refs/heads/main/itsuki.json', {
153
- responseType: 'json'
154
- })
127
+ const response = await fetch('https://raw.githubusercontent.com/Itsukichann/database/refs/heads/main/itsuki.json', {
128
+ method: 'GET'
129
+ })
130
+ const data = await response.json()
155
131
  if (Array.isArray(data)) {
156
132
  const itsukichann = data[Math.floor(Math.random() * data.length)]
157
133
  return itsukichann
158
134
  } else {
159
- throw new boom_1.Boom('Data is not in array format.')
135
+ throw new Boom('Data is not in array format.')
160
136
  }
161
137
  } catch (error) {
162
- throw new boom_1.Boom(error.message)
138
+ throw new Boom(error.message)
163
139
  }
164
140
  }
165
141
 
@@ -182,7 +158,7 @@ const BufferJSON = {
182
158
  }
183
159
 
184
160
  const getPlatformId = (browser) => {
185
- const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()]
161
+ const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()]
186
162
  return platformType ? platformType.toString() : '1'
187
163
  }
188
164
 
@@ -191,7 +167,7 @@ const getKeyAuthor = (key, meId = 'me') => {
191
167
  }
192
168
 
193
169
  const writeRandomPadMax16 = (msg) => {
194
- const pad = crypto_1.randomBytes(1)
170
+ const pad = randomBytes(1)
195
171
  const padLength = (pad[0] & 0x0f) + 1
196
172
 
197
173
  return Buffer.concat([msg, Buffer.alloc(padLength, padLength)])
@@ -210,15 +186,15 @@ const unpadRandomMax16 = (e) => {
210
186
  }
211
187
 
212
188
  const encodeWAMessage = (message) => {
213
- return writeRandomPadMax16(WAProto_1.proto.Message.encode(message).finish())
189
+ return writeRandomPadMax16(proto.Message.encode(message).finish())
214
190
  }
215
191
 
216
192
  const encodeNewsletterMessage = (message) => {
217
- return WAProto_1.proto.Message.encode(message).finish()
193
+ return proto.Message.encode(message).finish()
218
194
  }
219
195
 
220
196
  const generateRegistrationId = () => {
221
- return Uint16Array.from(crypto_1.randomBytes(2))[0] & 16383
197
+ return Uint16Array.from(randomBytes(2))[0] & 16383
222
198
  }
223
199
 
224
200
  const encodeBigEndian = (e, t = 4) => {
@@ -268,7 +244,7 @@ const delayCancellable = (ms) => {
268
244
  })
269
245
  const cancel = () => {
270
246
  clearTimeout(timeout)
271
- reject(new boom_1.Boom('Cancelled', {
247
+ reject(new Boom('Cancelled', {
272
248
  statusCode: 500,
273
249
  data: {
274
250
  stack
@@ -286,8 +262,8 @@ async function promiseTimeout(ms, promise) {
286
262
  // Create a promise that rejects in <ms> milliseconds
287
263
  const { delay, cancel } = delayCancellable(ms)
288
264
  const p = new Promise((resolve, reject) => {
289
- delay.then(() => reject(new boom_1.Boom('Timed Out', {
290
- statusCode: Types_1.DisconnectReason.timedOut,
265
+ delay.then(() => reject(new Boom('Timed Out', {
266
+ statusCode: DisconnectReason.timedOut,
291
267
  data: {
292
268
  stack
293
269
  }
@@ -301,23 +277,23 @@ const generateMessageID = (userId) => {
301
277
  const data = Buffer.alloc(8 + 20 + 16)
302
278
  data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
303
279
  if (userId) {
304
- const id = WABinary_1.jidDecode(userId)
280
+ const id = jidDecode(userId)
305
281
  if (id?.user) {
306
282
  data.write(id.user, 8)
307
283
  data.write('@c.us', 8 + id.user.length)
308
284
  }
309
285
  }
310
- const random = crypto_1.randomBytes(20)
286
+ const random = randomBytes(20)
311
287
  random.copy(data, 28)
312
288
  const sha = asciiDecode([ 83, 85, 75, 73 ])
313
- const hash = crypto_1.createHash('sha256').update(data).digest()
289
+ const hash = createHash('sha256').update(data).digest()
314
290
  return sha + hash.toString('hex').toUpperCase().substring(0, 16)
315
291
  }
316
292
 
317
293
  // code is inspired by whatsmeow
318
294
  const generateParticipantHashV2 = (participants) => {
319
295
  participants.sort()
320
- const sha256Hash = crypto_2.sha256(Buffer.from(participants.join(''))).toString('base64')
296
+ const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64')
321
297
  return '2:' + sha256Hash.slice(0, 6)
322
298
  };
323
299
 
@@ -329,7 +305,7 @@ function bindWaitForEvent(ev, event) {
329
305
  closeListener = ({ connection, lastDisconnect }) => {
330
306
  if (connection === 'close') {
331
307
  reject((lastDisconnect?.error)
332
- || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }))
308
+ || new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }))
333
309
  }
334
310
  }
335
311
  ev.on('connection.update', closeListener)
@@ -369,18 +345,19 @@ const printQRIfNecessaryListener = (ev, logger) => {
369
345
  const fetchLatestBaileysVersion = async (options = {}) => {
370
346
  const URL = 'https://raw.githubusercontent.com/Itsukichann/Baileys/refs/heads/master/lib/Defaults/baileys-version.json'
371
347
  try {
372
- const result = await axios_1.default.get(URL, {
348
+ const result = await fetch(URL, {
373
349
  ...options,
374
- responseType: 'json'
350
+ method: 'GET'
375
351
  })
352
+ const json = await result.json()
376
353
  return {
377
- version: result.data.version,
354
+ version: json.version,
378
355
  isLatest: true
379
356
  }
380
357
  }
381
358
  catch (error) {
382
359
  return {
383
- version: baileys_version_json_1.version,
360
+ version: version,
384
361
  isLatest: false,
385
362
  error
386
363
  }
@@ -407,7 +384,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
407
384
  })
408
385
 
409
386
  if (!response.ok) {
410
- throw new boom_1.Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status })
387
+ throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status })
411
388
  }
412
389
 
413
390
  const data = await response.text()
@@ -416,7 +393,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
416
393
 
417
394
  if (!match?.[1]) {
418
395
  return {
419
- version: baileys_version_json_1,
396
+ version: version,
420
397
  isLatest: false,
421
398
  error: {
422
399
  message: 'Could not find client revision in the fetched content'
@@ -432,7 +409,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
432
409
  }
433
410
  catch (error) {
434
411
  return {
435
- version: baileys_version_json_1,
412
+ version: version,
436
413
  isLatest: false,
437
414
  error
438
415
  }
@@ -441,15 +418,15 @@ const fetchLatestWaWebVersion = async (options = {}) => {
441
418
 
442
419
  /** unique message tag prefix for MD clients */
443
420
  const generateMdTagPrefix = () => {
444
- const bytes = crypto_1.randomBytes(4)
421
+ const bytes = randomBytes(4)
445
422
  return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`
446
423
  }
447
424
 
448
425
  const STATUS_MAP = {
449
- 'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
450
- 'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
451
- 'read': WAProto_1.proto.WebMessageInfo.Status.READ,
452
- 'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
426
+ 'sender': proto.WebMessageInfo.Status.SERVER_ACK,
427
+ 'played': proto.WebMessageInfo.Status.PLAYED,
428
+ 'read': proto.WebMessageInfo.Status.READ,
429
+ 'read-self': proto.WebMessageInfo.Status.READ
453
430
  }
454
431
 
455
432
  /**
@@ -459,13 +436,13 @@ const STATUS_MAP = {
459
436
  const getStatusFromReceiptType = (type) => {
460
437
  const status = STATUS_MAP[type]
461
438
  if (typeof type === 'undefined') {
462
- return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK
439
+ return proto.WebMessageInfo.Status.DELIVERY_ACK
463
440
  }
464
441
  return status
465
442
  }
466
443
 
467
444
  const CODE_MAP = {
468
- conflict: Types_1.DisconnectReason.connectionReplaced
445
+ conflict: DisconnectReason.connectionReplaced
469
446
  }
470
447
 
471
448
  /**
@@ -473,10 +450,10 @@ const CODE_MAP = {
473
450
  * @param reason the string reason given, eg. "conflict"
474
451
  */
475
452
  const getErrorCodeFromStreamError = (node) => {
476
- const [reasonNode] = WABinary_1.getAllBinaryNodeChildren(node)
453
+ const [reasonNode] = getAllBinaryNodeChildren(node)
477
454
  let reason = reasonNode?.tag || 'unknown'
478
- const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession)
479
- if (statusCode === Types_1.DisconnectReason.restartRequired) {
455
+ const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession)
456
+ if (statusCode === DisconnectReason.restartRequired) {
480
457
  reason = 'restart required'
481
458
  }
482
459
  return {
@@ -2,18 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
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)
5
+ const { promisify } = require("util")
6
+ const { inflate } = require("zlib")
7
+ const { proto } = require("../../WAProto")
8
+ const { WAMessageStubType } = require("../Types")
9
+ const { isJidUser } = require("../WABinary")
10
+ const { toNumber } = require("./generics")
11
+ const { normalizeMessageContent } = require("./messages")
12
+ const { downloadContentFromMessage } = require("./messages-media")
13
+ const inflatePromise = promisify(inflate)
14
14
 
15
15
  const downloadHistory = async (msg, options) => {
16
- const stream = await messages_media_1.downloadContentFromMessage(msg, 'md-msg-hist', { options })
16
+ const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options })
17
17
  const bufferArray = []
18
18
  for await (const chunk of stream) {
19
19
  bufferArray.push(chunk)
@@ -21,7 +21,7 @@ const downloadHistory = async (msg, options) => {
21
21
  let buffer = Buffer.concat(bufferArray)
22
22
  // decompress buffer
23
23
  buffer = await inflatePromise(buffer)
24
- const syncData = WAProto_1.proto.HistorySync.decode(buffer)
24
+ const syncData = proto.HistorySync.decode(buffer)
25
25
  return syncData
26
26
  }
27
27
 
@@ -30,10 +30,10 @@ const processHistoryMessage = (item) => {
30
30
  const contacts = []
31
31
  const chats = []
32
32
  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:
33
+ case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
34
+ case proto.HistorySync.HistorySyncType.RECENT:
35
+ case proto.HistorySync.HistorySyncType.FULL:
36
+ case proto.HistorySync.HistorySyncType.ON_DEMAND:
37
37
  for (const chat of item.conversations) {
38
38
  contacts.push({
39
39
  id: chat.id,
@@ -51,10 +51,10 @@ const processHistoryMessage = (item) => {
51
51
  chat.messages = [{ message }]
52
52
  }
53
53
  if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
54
- chat.lastMessageRecvTimestamp = generics_1.toNumber(message.messageTimestamp)
54
+ chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp)
55
55
  }
56
- if (message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
57
- || message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
56
+ if (message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
57
+ || message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
58
58
  && message.messageStubParameters?.[0]) {
59
59
  contacts.push({
60
60
  id: message.key.participant || message.key.remoteJid,
@@ -65,13 +65,13 @@ const processHistoryMessage = (item) => {
65
65
  chats.push({ ...chat })
66
66
  }
67
67
  break
68
- case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
68
+ case proto.HistorySync.HistorySyncType.PUSH_NAME:
69
69
  for (const c of item.pushnames) {
70
70
  contacts.push({
71
71
  id: c.id,
72
72
  name: c.name || undefined,
73
73
  lid: c.lidJid || undefined,
74
- jid: WABinary_1.isJidUser(c.id) ? c.id : undefined
74
+ jid: isJidUser(c.id) ? c.id : undefined
75
75
  })
76
76
  }
77
77
  break
@@ -91,7 +91,7 @@ const downloadAndProcessHistorySyncNotification = async (msg, options) => {
91
91
  }
92
92
 
93
93
  const getHistoryMsg = (message) => {
94
- const normalizedContent = !!message ? messages_1.normalizeMessageContent(message) : undefined
94
+ const normalizedContent = !!message ? normalizeMessageContent(message) : undefined
95
95
  const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
96
96
  return anyHistoryMsg
97
97
  }
@@ -1,22 +1,38 @@
1
1
  "use strict"
2
2
 
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
+
6
+ let desc = Object.getOwnPropertyDescriptor(m, k)
7
+
6
8
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
9
+ desc = {
10
+ enumerable: true,
11
+ get: function() {
12
+ return m[k]
13
+ }
14
+ }
8
15
  }
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
16
 
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
+ Object.defineProperty(o, k2, desc)
18
+
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k
21
+ o[k2] = m[k]
22
+ }
23
+ ))
24
+
25
+ const __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) {
27
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
28
+ __createBinding(exports, m, p)
29
+ }
30
+ }
17
31
  }
18
32
 
19
- Object.defineProperty(exports, "__esModule", { value: true })
33
+ Object.defineProperty(exports, "__esModule", {
34
+ value: true
35
+ })
20
36
 
21
37
  __exportStar(require("./generics"), exports)
22
38
  __exportStar(require("./decode-wa-message"), exports)
@@ -32,8 +48,6 @@ __exportStar(require("./chat-utils"), exports)
32
48
  __exportStar(require("./lt-hash"), exports)
33
49
  __exportStar(require("./auth-utils"), exports)
34
50
  __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
51
  __exportStar(require("./use-multi-file-auth-state"), exports)
38
52
  __exportStar(require("./link-preview"), exports)
39
53
  __exportStar(require("./event-buffer"), exports)
@@ -1,41 +1,18 @@
1
1
  "use strict"
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true })
30
4
 
31
- const messages_1 = require("./messages")
32
- const messages_media_1 = require("./messages-media")
5
+ const { prepareWAMessageMedia } = require("./messages")
6
+ const {
7
+ getHttpStream,
8
+ extractImageThumb
9
+ } = require("./messages-media")
33
10
  const THUMBNAIL_WIDTH_PX = 192
34
11
 
35
12
  /** Fetches an image and generates a thumbnail for it */
36
13
  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)
14
+ const stream = await getHttpStream(url, fetchOpts)
15
+ const result = await extractImageThumb(stream, thumbnailWidth)
39
16
  return result
40
17
  }
41
18
 
@@ -1,7 +1,7 @@
1
1
  "use strict"
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod }
4
- }
2
+
5
3
  Object.defineProperty(exports, "__esModule", { value: true })
6
- const pino_1 = __importDefault(require("pino"))
7
- exports.default = pino_1.default({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
4
+
5
+ const pino = require("pino")
6
+
7
+ exports.default = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const crypto_1 = require("./crypto")
5
+ const { hkdf } = require("./crypto")
6
6
 
7
7
  /**
8
8
  * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
@@ -34,12 +34,12 @@ class d {
34
34
  }
35
35
  async _addSingle(e, t) {
36
36
  var r = this
37
- const n = new Uint8Array(await crypto_1.hkdf(Buffer.from(t), o, { info: r.salt })).buffer
37
+ const n = new Uint8Array(await hkdf(Buffer.from(t), o, { info: r.salt })).buffer
38
38
  return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t))
39
39
  }
40
40
  async _subtractSingle(e, t) {
41
41
  var r = this
42
- const n = new Uint8Array(await crypto_1.hkdf(Buffer.from(t), o, { info: r.salt })).buffer
42
+ const n = new Uint8Array(await hkdf(Buffer.from(t), o, { info: r.salt })).buffer
43
43
  return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t))
44
44
  }
45
45
  performPointwiseWithOverflow(e, t, r) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const LRUCache_1 = require("lru-cache")
5
+ const { LRUCache } = require("lru-cache")
6
6
 
7
7
  /** Number of sent messages to cache in memory for handling retry receipts */
8
8
  const RECENT_MESSAGES_SIZE = 512
@@ -15,14 +15,14 @@ const PHONE_REQUEST_DELAY = 3000
15
15
  class MessageRetryManager {
16
16
  constructor(logger, maxMsgRetryCount) {
17
17
  this.logger = logger
18
- this.recentMessagesMap = new LRUCache_1.LRUCache({
18
+ this.recentMessagesMap = new LRUCache({
19
19
  max: RECENT_MESSAGES_SIZE
20
20
  })
21
- this.sessionRecreateHistory = new LRUCache_1.LRUCache({
21
+ this.sessionRecreateHistory = new LRUCache({
22
22
  ttl: RECREATE_SESSION_TIMEOUT * 2,
23
23
  ttlAutopurge: true
24
24
  })
25
- this.retryCounters = new LRUCache_1.LRUCache({
25
+ this.retryCounters = new LRUCache({
26
26
  ttl: 15 * 60 * 1000,
27
27
  ttlAutopurge: true,
28
28
  updateAgeOnGet: true