@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,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
  }
@@ -298,20 +274,26 @@ async function promiseTimeout(ms, promise) {
298
274
  }
299
275
 
300
276
  const generateMessageID = (userId) => {
301
- const timestamp = Date.now().toString();
302
- const user = userId || 'unknown';
303
- const random = crypto_1.randomBytes(16).toString('hex');
304
-
305
- const hash = crypto_1.createHash('sha256')
306
- .update(timestamp + user + random)
307
- .digest('hex')
308
- .toUpperCase();
309
-
310
- return 'A' + hash.substring(0, 31);
277
+ const data = Buffer.alloc(8 + 20 + 16)
278
+ data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
279
+ if (userId) {
280
+ const id = jidDecode(userId)
281
+ if (id?.user) {
282
+ data.write(id.user, 8)
283
+ data.write('@c.us', 8 + id.user.length)
284
+ }
285
+ }
286
+ const random = randomBytes(20)
287
+ random.copy(data, 28)
288
+ const sha = asciiDecode([ 83, 85, 75, 73 ])
289
+ const hash = createHash('sha256').update(data).digest()
290
+ return sha + hash.toString('hex').toUpperCase().substring(0, 16)
311
291
  }
292
+
293
+ // code is inspired by whatsmeow
312
294
  const generateParticipantHashV2 = (participants) => {
313
295
  participants.sort()
314
- const sha256Hash = crypto_2.sha256(Buffer.from(participants.join(''))).toString('base64')
296
+ const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64')
315
297
  return '2:' + sha256Hash.slice(0, 6)
316
298
  };
317
299
 
@@ -323,7 +305,7 @@ function bindWaitForEvent(ev, event) {
323
305
  closeListener = ({ connection, lastDisconnect }) => {
324
306
  if (connection === 'close') {
325
307
  reject((lastDisconnect?.error)
326
- || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }))
308
+ || new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }))
327
309
  }
328
310
  }
329
311
  ev.on('connection.update', closeListener)
@@ -363,18 +345,19 @@ const printQRIfNecessaryListener = (ev, logger) => {
363
345
  const fetchLatestBaileysVersion = async (options = {}) => {
364
346
  const URL = 'https://raw.githubusercontent.com/Itsukichann/Baileys/refs/heads/master/lib/Defaults/baileys-version.json'
365
347
  try {
366
- const result = await axios_1.default.get(URL, {
348
+ const result = await fetch(URL, {
367
349
  ...options,
368
- responseType: 'json'
350
+ method: 'GET'
369
351
  })
352
+ const json = await result.json()
370
353
  return {
371
- version: result.data.version,
354
+ version: json.version,
372
355
  isLatest: true
373
356
  }
374
357
  }
375
358
  catch (error) {
376
359
  return {
377
- version: baileys_version_json_1.version,
360
+ version: version,
378
361
  isLatest: false,
379
362
  error
380
363
  }
@@ -401,7 +384,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
401
384
  })
402
385
 
403
386
  if (!response.ok) {
404
- 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 })
405
388
  }
406
389
 
407
390
  const data = await response.text()
@@ -410,7 +393,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
410
393
 
411
394
  if (!match?.[1]) {
412
395
  return {
413
- version: baileys_version_json_1,
396
+ version: version,
414
397
  isLatest: false,
415
398
  error: {
416
399
  message: 'Could not find client revision in the fetched content'
@@ -426,7 +409,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
426
409
  }
427
410
  catch (error) {
428
411
  return {
429
- version: baileys_version_json_1,
412
+ version: version,
430
413
  isLatest: false,
431
414
  error
432
415
  }
@@ -435,15 +418,15 @@ const fetchLatestWaWebVersion = async (options = {}) => {
435
418
 
436
419
  /** unique message tag prefix for MD clients */
437
420
  const generateMdTagPrefix = () => {
438
- const bytes = crypto_1.randomBytes(4)
421
+ const bytes = randomBytes(4)
439
422
  return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`
440
423
  }
441
424
 
442
425
  const STATUS_MAP = {
443
- 'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
444
- 'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
445
- 'read': WAProto_1.proto.WebMessageInfo.Status.READ,
446
- '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
447
430
  }
448
431
 
449
432
  /**
@@ -453,13 +436,13 @@ const STATUS_MAP = {
453
436
  const getStatusFromReceiptType = (type) => {
454
437
  const status = STATUS_MAP[type]
455
438
  if (typeof type === 'undefined') {
456
- return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK
439
+ return proto.WebMessageInfo.Status.DELIVERY_ACK
457
440
  }
458
441
  return status
459
442
  }
460
443
 
461
444
  const CODE_MAP = {
462
- conflict: Types_1.DisconnectReason.connectionReplaced
445
+ conflict: DisconnectReason.connectionReplaced
463
446
  }
464
447
 
465
448
  /**
@@ -467,10 +450,10 @@ const CODE_MAP = {
467
450
  * @param reason the string reason given, eg. "conflict"
468
451
  */
469
452
  const getErrorCodeFromStreamError = (node) => {
470
- const [reasonNode] = WABinary_1.getAllBinaryNodeChildren(node)
453
+ const [reasonNode] = getAllBinaryNodeChildren(node)
471
454
  let reason = reasonNode?.tag || 'unknown'
472
- const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession)
473
- if (statusCode === Types_1.DisconnectReason.restartRequired) {
455
+ const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession)
456
+ if (statusCode === DisconnectReason.restartRequired) {
474
457
  reason = 'restart required'
475
458
  }
476
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) {