@badzz88/baileys 8.5.4 → 8.5.6

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 (269) hide show
  1. package/README.md +2 -2
  2. package/WAProto/fix-imports.js +69 -79
  3. package/WAProto/index.d.ts +15305 -87935
  4. package/WAProto/index.js +41109 -194076
  5. package/engine-requirements.js +15 -8
  6. package/package.json +23 -19
  7. package/src/Defaults/index.js +186 -0
  8. package/src/Signal/Group/ciphertext-message.js +15 -0
  9. package/src/Signal/Group/group-session-builder.js +86 -0
  10. package/src/Signal/Group/group_cipher.js +82 -0
  11. package/src/Signal/Group/index.js +140 -0
  12. package/src/Signal/Group/keyhelper.js +77 -0
  13. package/src/Signal/Group/sender-chain-key.js +29 -0
  14. package/src/Signal/Group/sender-key-distribution-message.js +66 -0
  15. package/src/Signal/Group/sender-key-message.js +69 -0
  16. package/src/Signal/Group/sender-key-name.js +51 -0
  17. package/src/Signal/Group/sender-key-record.js +44 -0
  18. package/src/Signal/Group/sender-key-state.js +87 -0
  19. package/src/Signal/Group/sender-message-key.js +29 -0
  20. package/src/Signal/libsignal.js +455 -0
  21. package/src/Signal/lid-mapping.js +273 -0
  22. package/src/Socket/Client/index.js +31 -0
  23. package/src/Socket/Client/types.js +13 -0
  24. package/src/Socket/Client/websocket.js +61 -0
  25. package/src/Socket/aigroups.js +221 -0
  26. package/src/Socket/business.js +411 -0
  27. package/src/Socket/chats.js +1449 -0
  28. package/src/Socket/communities.js +463 -0
  29. package/src/Socket/graphql.js +523 -0
  30. package/src/Socket/groups.js +516 -0
  31. package/src/Socket/index.js +31 -0
  32. package/src/Socket/interactive-handler.js +527 -0
  33. package/src/Socket/interop.js +339 -0
  34. package/src/Socket/luxu.js +349 -0
  35. package/src/Socket/managed-account.js +98 -0
  36. package/src/Socket/messages-recv.js +2685 -0
  37. package/src/Socket/messages-send.js +2047 -0
  38. package/src/Socket/mex.js +57 -0
  39. package/src/Socket/newsletter.js +455 -0
  40. package/src/Socket/privacy.js +125 -0
  41. package/src/Socket/registration.js +236 -0
  42. package/src/Socket/socket.js +983 -0
  43. package/src/Socket/text-router.js +65 -0
  44. package/src/Socket/username.js +130 -0
  45. package/src/Store/index.js +33 -0
  46. package/src/Store/keyed-db.js +118 -0
  47. package/src/Store/make-cache-manager-store.js +84 -0
  48. package/src/Store/make-in-memory-store.js +551 -0
  49. package/src/Store/make-ordered-dictionary.js +81 -0
  50. package/src/Store/object-repository.js +26 -0
  51. package/src/Types/Auth.js +31 -0
  52. package/src/Types/Bussines.js +2 -0
  53. package/src/Types/Call.js +2 -0
  54. package/src/Types/Chat.js +4 -0
  55. package/src/Types/Contact.js +2 -0
  56. package/src/Types/Events.js +2 -0
  57. package/src/Types/GroupMetadata.js +2 -0
  58. package/src/Types/Label.js +26 -0
  59. package/src/Types/LabelAssociation.js +8 -0
  60. package/src/Types/Message.js +93 -0
  61. package/src/Types/Mex.js +112 -0
  62. package/src/Types/Newsletter.js +109 -0
  63. package/src/Types/Product.js +2 -0
  64. package/src/Types/Signal.js +2 -0
  65. package/src/Types/Socket.js +2 -0
  66. package/src/Types/State.js +62 -0
  67. package/src/Types/USync.js +2 -0
  68. package/src/Types/index.js +56 -0
  69. package/src/Utils/auth-utils.js +254 -0
  70. package/src/Utils/browser-utils.js +112 -0
  71. package/src/Utils/business.js +240 -0
  72. package/src/Utils/chat-utils.js +1230 -0
  73. package/src/Utils/command-loader.d.ts +27 -0
  74. package/src/Utils/command-loader.js +89 -0
  75. package/src/Utils/companion-reg-client-utils.js +40 -0
  76. package/src/Utils/consumer-application.js +105 -0
  77. package/src/Utils/crypto.js +118 -0
  78. package/src/Utils/curve25519-js.js +242 -0
  79. package/src/Utils/decode-wa-message.js +529 -0
  80. package/src/Utils/event-buffer.js +580 -0
  81. package/src/Utils/generics.js +483 -0
  82. package/src/Utils/group-history.js +44 -0
  83. package/src/Utils/history.js +232 -0
  84. package/src/Utils/identity-change-handler.js +52 -0
  85. package/src/Utils/index.js +58 -0
  86. package/src/Utils/jid-display-normalization.js +195 -0
  87. package/src/Utils/link-preview.js +135 -0
  88. package/src/Utils/logger.js +8 -0
  89. package/src/Utils/lt-hash.js +25 -0
  90. package/src/Utils/make-mutex.js +36 -0
  91. package/src/Utils/message-composer.js +471 -0
  92. package/src/Utils/message-retry-manager.js +217 -0
  93. package/src/Utils/messages-media.js +843 -0
  94. package/src/Utils/messages.js +2817 -0
  95. package/src/Utils/meta-ai-msmsg.js +222 -0
  96. package/src/Utils/native-bridge.js +68 -0
  97. package/src/Utils/noise-handler.js +169 -0
  98. package/src/Utils/offline-node-processor.js +34 -0
  99. package/src/Utils/pre-key-manager.js +90 -0
  100. package/src/Utils/process-message.js +950 -0
  101. package/src/Utils/reporting-utils.js +261 -0
  102. package/src/Utils/session-pool.d.ts +14 -0
  103. package/src/Utils/session-pool.js +70 -0
  104. package/src/Utils/signal.js +217 -0
  105. package/src/Utils/stanza-ack.js +30 -0
  106. package/src/Utils/sticker.d.ts +13 -0
  107. package/src/Utils/sticker.js +123 -0
  108. package/src/Utils/sync-action-utils.js +45 -0
  109. package/src/Utils/tc-token-utils.js +158 -0
  110. package/src/Utils/use-multi-file-auth-state.js +111 -0
  111. package/src/Utils/validate-connection.js +209 -0
  112. package/src/Utils/view-once-cache.d.ts +12 -0
  113. package/src/Utils/view-once-cache.js +63 -0
  114. package/src/Utils/voip-rekey.js +22 -0
  115. package/src/WABinary/constants.js +1304 -0
  116. package/src/WABinary/decode.js +342 -0
  117. package/src/WABinary/encode.js +225 -0
  118. package/src/WABinary/generic-utils.js +238 -0
  119. package/src/WABinary/index.js +34 -0
  120. package/src/WABinary/jid-utils.js +351 -0
  121. package/src/WABinary/types.js +2 -0
  122. package/src/WAM/BinaryInfo.js +13 -0
  123. package/src/WAM/constants.js +39484 -0
  124. package/src/WAM/encode.js +149 -0
  125. package/src/WAM/index.js +32 -0
  126. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  127. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
  128. package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
  129. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
  130. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  131. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
  132. package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
  133. package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
  134. package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
  135. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  136. package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  137. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  138. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
  139. package/src/WAUSync/Protocols/index.js +40 -0
  140. package/src/WAUSync/USyncQuery.js +126 -0
  141. package/src/WAUSync/USyncUser.js +50 -0
  142. package/src/WAUSync/index.js +32 -0
  143. package/src/antiban.js +4152 -0
  144. package/{lib → src}/index.js +51 -49
  145. package/lib/Defaults/index.js +0 -195
  146. package/lib/Signal/Group/ciphertext-message.js +0 -15
  147. package/lib/Signal/Group/group-session-builder.js +0 -92
  148. package/lib/Signal/Group/group_cipher.js +0 -89
  149. package/lib/Signal/Group/index.js +0 -136
  150. package/lib/Signal/Group/keyhelper.js +0 -73
  151. package/lib/Signal/Group/sender-chain-key.js +0 -32
  152. package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
  153. package/lib/Signal/Group/sender-key-message.js +0 -69
  154. package/lib/Signal/Group/sender-key-name.js +0 -50
  155. package/lib/Signal/Group/sender-key-record.js +0 -44
  156. package/lib/Signal/Group/sender-key-state.js +0 -97
  157. package/lib/Signal/Group/sender-message-key.js +0 -30
  158. package/lib/Signal/libsignal.js +0 -470
  159. package/lib/Signal/lid-mapping.js +0 -280
  160. package/lib/Socket/Client/index.js +0 -30
  161. package/lib/Socket/Client/types.js +0 -13
  162. package/lib/Socket/Client/websocket.js +0 -62
  163. package/lib/Socket/aigroups.js +0 -240
  164. package/lib/Socket/business.js +0 -414
  165. package/lib/Socket/chats.js +0 -2165
  166. package/lib/Socket/communities.js +0 -545
  167. package/lib/Socket/graphql.js +0 -863
  168. package/lib/Socket/groups.js +0 -685
  169. package/lib/Socket/index.js +0 -41
  170. package/lib/Socket/interactive-handler.js +0 -579
  171. package/lib/Socket/interop.js +0 -430
  172. package/lib/Socket/managed-account.js +0 -214
  173. package/lib/Socket/messages-recv.js +0 -3000
  174. package/lib/Socket/messages-send.js +0 -2155
  175. package/lib/Socket/mex.js +0 -47
  176. package/lib/Socket/newsletter.js +0 -814
  177. package/lib/Socket/privacy.js +0 -261
  178. package/lib/Socket/registration.js +0 -434
  179. package/lib/Socket/socket.js +0 -1074
  180. package/lib/Socket/username.js +0 -160
  181. package/lib/Store/index.js +0 -36
  182. package/lib/Store/make-cache-manager-store.js +0 -90
  183. package/lib/Store/make-in-memory-store.js +0 -488
  184. package/lib/Store/make-ordered-dictionary.js +0 -81
  185. package/lib/Store/object-repository.js +0 -29
  186. package/lib/Types/Auth.js +0 -38
  187. package/lib/Types/Bussines.js +0 -2
  188. package/lib/Types/Call.js +0 -2
  189. package/lib/Types/Chat.js +0 -4
  190. package/lib/Types/Contact.js +0 -2
  191. package/lib/Types/Events.js +0 -2
  192. package/lib/Types/GroupMetadata.js +0 -2
  193. package/lib/Types/Label.js +0 -27
  194. package/lib/Types/LabelAssociation.js +0 -9
  195. package/lib/Types/Message.js +0 -95
  196. package/lib/Types/Newsletter.js +0 -152
  197. package/lib/Types/Product.js +0 -2
  198. package/lib/Types/Signal.js +0 -2
  199. package/lib/Types/Socket.js +0 -2
  200. package/lib/Types/State.js +0 -70
  201. package/lib/Types/USync.js +0 -2
  202. package/lib/Types/index.js +0 -55
  203. package/lib/Utils/auth-utils.js +0 -301
  204. package/lib/Utils/browser-utils.js +0 -114
  205. package/lib/Utils/business.js +0 -243
  206. package/lib/Utils/chat-utils.js +0 -1272
  207. package/lib/Utils/consumer-application.js +0 -107
  208. package/lib/Utils/crypto.js +0 -125
  209. package/lib/Utils/decode-wa-message.js +0 -793
  210. package/lib/Utils/event-buffer.js +0 -583
  211. package/lib/Utils/generics.js +0 -617
  212. package/lib/Utils/group-history.js +0 -51
  213. package/lib/Utils/history.js +0 -244
  214. package/lib/Utils/identity-change-handler.js +0 -52
  215. package/lib/Utils/index.js +0 -53
  216. package/lib/Utils/jid-display-normalization.js +0 -218
  217. package/lib/Utils/link-preview.js +0 -138
  218. package/lib/Utils/logger.js +0 -9
  219. package/lib/Utils/lt-hash.js +0 -6
  220. package/lib/Utils/make-mutex.js +0 -36
  221. package/lib/Utils/message-composer.js +0 -479
  222. package/lib/Utils/message-inspect.js +0 -393
  223. package/lib/Utils/message-retry-manager.js +0 -205
  224. package/lib/Utils/messages-media.js +0 -925
  225. package/lib/Utils/messages.js +0 -2482
  226. package/lib/Utils/meta-ai-msmsg.js +0 -122
  227. package/lib/Utils/noise-handler.js +0 -194
  228. package/lib/Utils/offline-node-processor.js +0 -37
  229. package/lib/Utils/pre-key-manager.js +0 -97
  230. package/lib/Utils/process-message.js +0 -1139
  231. package/lib/Utils/reporting-utils.js +0 -262
  232. package/lib/Utils/signal.js +0 -189
  233. package/lib/Utils/stanza-ack.js +0 -67
  234. package/lib/Utils/sync-action-utils.js +0 -51
  235. package/lib/Utils/tc-token-utils.js +0 -156
  236. package/lib/Utils/use-multi-file-auth-state.js +0 -137
  237. package/lib/Utils/validate-connection.js +0 -259
  238. package/lib/Utils/voip-rekey.js +0 -22
  239. package/lib/WABinary/constants.js +0 -1304
  240. package/lib/WABinary/decode.js +0 -377
  241. package/lib/WABinary/encode.js +0 -58
  242. package/lib/WABinary/generic-utils.js +0 -150
  243. package/lib/WABinary/index.js +0 -33
  244. package/lib/WABinary/jid-utils.js +0 -374
  245. package/lib/WABinary/types.js +0 -2
  246. package/lib/WAM/BinaryInfo.js +0 -13
  247. package/lib/WAM/constants.js +0 -39486
  248. package/lib/WAM/encode.js +0 -142
  249. package/lib/WAM/index.js +0 -31
  250. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
  251. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
  252. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -60
  253. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -65
  254. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
  255. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -72
  256. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
  257. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
  258. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
  259. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
  260. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -44
  261. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
  262. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
  263. package/lib/WAUSync/Protocols/index.js +0 -40
  264. package/lib/WAUSync/USyncBackoff.js +0 -26
  265. package/lib/WAUSync/USyncQuery.js +0 -204
  266. package/lib/WAUSync/USyncUser.js +0 -58
  267. package/lib/WAUSync/index.js +0 -32
  268. package/lib/antiban.js +0 -4391
  269. /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
@@ -1,617 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.isWABusinessPlatform =
4
- exports.getCodeFromWSError =
5
- exports.getCallStatusFromNode =
6
- exports.getErrorCodeFromStreamError =
7
- exports.getStatusFromReceiptType =
8
- exports.generateMdTagPrefix =
9
- exports.fetchLatestWaWebVersion =
10
- exports.fetchLatestBaileysVersion =
11
- exports.bindWaitForConnectionUpdate =
12
- exports.generateMessageID =
13
- exports.generateMessageIDV2 =
14
- exports.delayCancellable =
15
- exports.delay =
16
- exports.debouncedTimeout =
17
- exports.unixTimestampSeconds =
18
- exports.toNumber =
19
- exports.encodeBigEndian =
20
- exports.generateRegistrationId =
21
- exports.encodeWAMessage =
22
- exports.generateParticipantHashV2 =
23
- exports.unpadRandomMax16 =
24
- exports.writeRandomPadMax16 =
25
- exports.isStringNullOrEmpty =
26
- exports.getKeyAuthor =
27
- exports.BufferJSON =
28
- exports.jitterDelay =
29
- exports.exponentialBackoff =
30
- exports.bytesToHex =
31
- exports.hexToBytes =
32
- exports.bytesToBase64Url =
33
- exports.sha256Hex =
34
- exports.hmacSha256 =
35
- exports.normalizeJidBatch =
36
- exports.sleep =
37
- exports.withRetry =
38
- void 0
39
- exports.promiseTimeout = promiseTimeout
40
- exports.bindWaitForEvent = bindWaitForEvent
41
- exports.trimUndefined = trimUndefined
42
- exports.bytesToCrockford = bytesToCrockford
43
- exports.encodeNewsletterMessage = encodeNewsletterMessage
44
- const boom_1 = require('@hapi/boom')
45
- const crypto_1 = require('crypto')
46
- const rb = require('whatsapp-rust-bridge')
47
- const DEFAULTS_1 = require('../Defaults')
48
- const index_js_1 = require('../../WAProto/index.js')
49
- const baileysVersion = DEFAULTS_1.VERSION
50
- const Types_1 = require('../Types')
51
- const WABinary_1 = require('../WABinary')
52
- const crypto_2 = require('./crypto')
53
- exports.BufferJSON = {
54
-
55
- replacer: (k, value) => {
56
- if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
57
- return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') }
58
- }
59
- return value
60
- },
61
-
62
- reviver: (_, value) => {
63
- if (typeof value === 'object' && value !== null && value.type === 'Buffer' && typeof value.data === 'string') {
64
- return Buffer.from(value.data, 'base64')
65
- }
66
- if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
67
- const keys = Object.keys(value)
68
- if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
69
- const values = Object.values(value)
70
- if (values.every(v => typeof v === 'number')) {
71
- return Buffer.from(values)
72
- }
73
- }
74
- }
75
- return value
76
- }
77
- }
78
- const getKeyAuthor = (key, meId = 'me') =>
79
- (key?.fromMe ? meId : key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || ''
80
- exports.getKeyAuthor = getKeyAuthor
81
- const isStringNullOrEmpty = value =>
82
-
83
- value == null || value === ''
84
- exports.isStringNullOrEmpty = isStringNullOrEmpty
85
- const writeRandomPadMax16 = msg => {
86
- const pad = (0, crypto_1.randomBytes)(1)
87
- const padLength = (pad[0] & 0x0f) + 1
88
- return Buffer.concat([msg, Buffer.alloc(padLength, padLength)])
89
- }
90
- exports.writeRandomPadMax16 = writeRandomPadMax16
91
- const unpadRandomMax16 = e => {
92
- const t = new Uint8Array(e)
93
- if (0 === t.length) {
94
- throw new Error('unpadPkcs7 given empty bytes')
95
- }
96
- var r = t[t.length - 1]
97
- if (r > t.length) {
98
- throw new Error(`unpad given ${t.length} bytes, but pad is ${r}`)
99
- }
100
- return new Uint8Array(t.buffer, t.byteOffset, t.length - r)
101
- }
102
- exports.unpadRandomMax16 = unpadRandomMax16
103
-
104
- const generateParticipantHashV2 = participants => {
105
- participants.sort()
106
- const sha256Hash = (0, crypto_2.sha256)(Buffer.from(participants.join(''))).toString('base64')
107
- return '2:' + sha256Hash.slice(0, 6)
108
- }
109
- exports.generateParticipantHashV2 = generateParticipantHashV2
110
- const encodeWAMessage = message => (0, exports.writeRandomPadMax16)(index_js_1.proto.Message.encode(message).finish())
111
- exports.encodeWAMessage = encodeWAMessage
112
- const generateRegistrationId = () => {
113
- return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383
114
- }
115
- exports.generateRegistrationId = generateRegistrationId
116
- const encodeBigEndian = (e, t = 4) => {
117
- let r = e
118
- const a = new Uint8Array(t)
119
- for (let i = t - 1; i >= 0; i--) {
120
- a[i] = 255 & r
121
- r >>>= 8
122
- }
123
- return a
124
- }
125
- exports.encodeBigEndian = encodeBigEndian
126
- const toNumber = t => (typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0)
127
- exports.toNumber = toNumber
128
-
129
- const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000)
130
- exports.unixTimestampSeconds = unixTimestampSeconds
131
- const debouncedTimeout = (intervalMs = 1000, task) => {
132
- let timeout
133
- return {
134
- start: (newIntervalMs, newTask) => {
135
- task = newTask || task
136
- intervalMs = newIntervalMs || intervalMs
137
- timeout && clearTimeout(timeout)
138
- timeout = setTimeout(() => task?.(), intervalMs)
139
- },
140
- cancel: () => {
141
- timeout && clearTimeout(timeout)
142
- timeout = undefined
143
- },
144
- setTask: newTask => (task = newTask),
145
- setInterval: newInterval => (intervalMs = newInterval)
146
- }
147
- }
148
- exports.debouncedTimeout = debouncedTimeout
149
- const delay = ms => (0, exports.delayCancellable)(ms).delay
150
- exports.delay = delay
151
- const delayCancellable = ms => {
152
- const stack = new Error().stack
153
- let timeout
154
- let reject
155
- const delay = new Promise((resolve, _reject) => {
156
- timeout = setTimeout(resolve, ms)
157
- reject = _reject
158
- })
159
- const cancel = () => {
160
- clearTimeout(timeout)
161
- reject(
162
- new boom_1.Boom('Cancelled', {
163
- statusCode: 500,
164
- data: {
165
- stack
166
- }
167
- })
168
- )
169
- }
170
- return { delay, cancel }
171
- }
172
- exports.delayCancellable = delayCancellable
173
- async function promiseTimeout(ms, promise) {
174
- if (!ms) {
175
- return new Promise(promise)
176
- }
177
- const stack = new Error().stack
178
-
179
- const { delay, cancel } = (0, exports.delayCancellable)(ms)
180
- const p = new Promise((resolve, reject) => {
181
- delay
182
- .then(() =>
183
- reject(
184
- new boom_1.Boom('Timed Out', {
185
- statusCode: Types_1.DisconnectReason.timedOut,
186
- data: {
187
- stack
188
- }
189
- })
190
- )
191
- )
192
- .catch(err => reject(err))
193
- promise(resolve, reject)
194
- }).finally(cancel)
195
- return p
196
- }
197
-
198
-
199
- const generateMessageIDV2 = userId => {
200
- const data = Buffer.alloc(8 + 20 + 16)
201
- data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
202
- if (userId) {
203
- const id = (0, WABinary_1.jidDecode)(userId)
204
- if (id?.user) {
205
- data.write(id.user, 8)
206
- data.write('@c.us', 8 + id.user.length)
207
- }
208
- }
209
- const random = (0, crypto_1.randomBytes)(16)
210
- random.copy(data, 28)
211
- const hash = Buffer.from(rb.sha256(data))
212
- return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18)
213
- }
214
- exports.generateMessageIDV2 = generateMessageIDV2
215
-
216
- const generateMessageID = () => '3EB0' + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase()
217
- exports.generateMessageID = generateMessageID
218
- function bindWaitForEvent(ev, event) {
219
- return async (check, timeoutMs) => {
220
- let listener
221
- let closeListener
222
- await promiseTimeout(timeoutMs, (resolve, reject) => {
223
- closeListener = ({ connection, lastDisconnect }) => {
224
- if (connection === 'close') {
225
- reject(
226
- lastDisconnect?.error ||
227
- new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed })
228
- )
229
- }
230
- }
231
- ev.on('connection.update', closeListener)
232
- listener = async update => {
233
- if (await check(update)) {
234
- resolve()
235
- }
236
- }
237
- ev.on(event, listener)
238
- }).finally(() => {
239
- ev.off(event, listener)
240
- ev.off('connection.update', closeListener)
241
- })
242
- }
243
- }
244
- const bindWaitForConnectionUpdate = ev => bindWaitForEvent(ev, 'connection.update')
245
- exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate
246
-
247
- const fetchLatestBaileysVersion = async (options = {}) => {
248
- const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts'
249
- try {
250
-
251
-
252
- const controller = new AbortController()
253
- const timer = setTimeout(() => controller.abort(), options.timeout ?? 5000)
254
- const response = await fetch(URL, {
255
- dispatcher: options.dispatcher,
256
- method: 'GET',
257
- headers: options.headers,
258
- signal: controller.signal
259
- })
260
- clearTimeout(timer)
261
- if (!response.ok) {
262
- throw new boom_1.Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, {
263
- statusCode: response.status
264
- })
265
- }
266
- const text = await response.text()
267
-
268
- const lines = text.split('\n')
269
- const versionLine = lines[6]
270
- const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/)
271
- if (versionMatch) {
272
- const version = [parseInt(versionMatch[1], 10), parseInt(versionMatch[2], 10), parseInt(versionMatch[3], 10)]
273
- return {
274
- version,
275
- isLatest: true
276
- }
277
- } else {
278
- throw new Error('Could not parse version from Defaults/index.ts')
279
- }
280
- } catch (error) {
281
- return {
282
- version: baileysVersion,
283
- isLatest: false,
284
- error
285
- }
286
- }
287
- }
288
- exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion
289
-
290
- const fetchLatestWaWebVersion = async (options = {}) => {
291
- try {
292
-
293
- const defaultHeaders = {
294
- 'sec-fetch-site': 'none',
295
- 'user-agent':
296
- 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
297
- }
298
- const headers = { ...defaultHeaders, ...options.headers }
299
- const controller = new AbortController()
300
- const timer = setTimeout(() => controller.abort(), options.timeout ?? 5000)
301
- const response = await fetch('https://web.whatsapp.com/sw.js', {
302
- ...options,
303
- method: 'GET',
304
- headers,
305
- signal: controller.signal
306
- })
307
- clearTimeout(timer)
308
- if (!response.ok) {
309
- throw new boom_1.Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status })
310
- }
311
- const data = await response.text()
312
- const regex = /\\?"client_revision\\?":\s*(\d+)/
313
- const match = data.match(regex)
314
- if (!match?.[1]) {
315
- return {
316
- version: baileysVersion,
317
- isLatest: false,
318
- error: {
319
- message: 'Could not find client revision in the fetched content'
320
- }
321
- }
322
- }
323
- const clientRevision = match[1]
324
- return {
325
- version: [2, 3000, +clientRevision],
326
- isLatest: true
327
- }
328
- } catch (error) {
329
- return {
330
- version: baileysVersion,
331
- isLatest: false,
332
- error
333
- }
334
- }
335
- }
336
- exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion
337
-
338
- const generateMdTagPrefix = () => {
339
- const bytes = (0, crypto_1.randomBytes)(4)
340
- return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`
341
- }
342
- exports.generateMdTagPrefix = generateMdTagPrefix
343
- const STATUS_MAP = {
344
- sender: index_js_1.proto.WebMessageInfo.Status.SERVER_ACK,
345
- played: index_js_1.proto.WebMessageInfo.Status.PLAYED,
346
- 'played-self': index_js_1.proto.WebMessageInfo.Status.PLAYED,
347
- read: index_js_1.proto.WebMessageInfo.Status.READ,
348
- 'read-self': index_js_1.proto.WebMessageInfo.Status.READ
349
- }
350
-
351
- const getStatusFromReceiptType = type => {
352
- const status = STATUS_MAP[type]
353
- if (typeof type === 'undefined') {
354
- return index_js_1.proto.WebMessageInfo.Status.DELIVERY_ACK
355
- }
356
- return status
357
- }
358
- exports.getStatusFromReceiptType = getStatusFromReceiptType
359
- const CODE_MAP = {
360
- conflict: Types_1.DisconnectReason.connectionReplaced
361
- }
362
-
363
- const getErrorCodeFromStreamError = node => {
364
- const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node)
365
- let reason = reasonNode?.tag || 'unknown'
366
- const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession)
367
- if (statusCode === Types_1.DisconnectReason.restartRequired) {
368
- reason = 'restart required'
369
- }
370
- return {
371
- reason,
372
- statusCode
373
- }
374
- }
375
- exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError
376
- const getCallStatusFromNode = ({ tag, attrs }) => {
377
- let status
378
- switch (tag) {
379
- case 'offer':
380
- case 'offer_notice':
381
- status = 'offer'
382
- break
383
- case 'terminate':
384
-
385
- switch (attrs.reason) {
386
- case 'timeout':
387
- case 'Timeout':
388
- status = 'timeout'
389
- break
390
- case 'RejectDoNotDisturb':
391
- status = 'reject_do_not_disturb'
392
- break
393
- case 'MicPermissionDenied':
394
- status = 'mic_permission_denied'
395
- break
396
- case 'CameraPermissionDenied':
397
- status = 'camera_permission_denied'
398
- break
399
- case 'RemoteBusy':
400
- status = 'remote_busy'
401
- break
402
- case 'RemoteOffline':
403
- status = 'remote_offline'
404
- break
405
- default:
406
-
407
- status = 'terminate'
408
- break
409
- }
410
- break
411
- case 'reject':
412
- status = 'reject'
413
- break
414
- case 'accept':
415
- status = 'accept'
416
- break
417
- case 'preaccept':
418
- status = 'preaccept'
419
- break
420
- case 'accept_ack':
421
- status = 'accept_ack'
422
- break
423
- case 'enc-rekey':
424
- case 'enc_rekey':
425
- status = 'enc_rekey'
426
- break
427
- case 'peer_state':
428
- status = 'peer_state'
429
- break
430
- case 'group_info':
431
- status = 'group_info'
432
- break
433
- case 'video_state':
434
- status = 'video_state'
435
- break
436
- case 'video_state_ack':
437
- status = 'video_state_ack'
438
- break
439
- case 'flow_control':
440
- status = 'flow_control'
441
- break
442
- case 'relaylatency':
443
- status = 'relaylatency'
444
- break
445
- case 'mute_v2':
446
- status = 'mute'
447
- break
448
- case 'waiting_room_request':
449
- status = 'waiting_room_request'
450
- break
451
- case 'signal':
452
-
453
- switch (attrs.type) {
454
- case '13':
455
- status = 'preaccept'
456
- break
457
- case '15':
458
- status = 'video_state'
459
- break
460
- case '17':
461
- status = 'group_info'
462
- break
463
- case '20':
464
- status = 'video_state_ack'
465
- break
466
- case '21':
467
- status = 'flow_control'
468
- break
469
- case '23':
470
- status = 'accept_ack'
471
- break
472
- case '1002':
473
- case '1007':
474
- status = 'peer_state'
475
- break
476
- case '1008':
477
- status = 'enc_rekey'
478
- break
479
- case '12':
480
- status = 'mute'
481
- break
482
- default:
483
- status = 'ringing'
484
- break
485
- }
486
- break
487
- default:
488
- status = 'ringing'
489
- break
490
- }
491
- return status
492
- }
493
- exports.getCallStatusFromNode = getCallStatusFromNode
494
- const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: '
495
- const getCodeFromWSError = error => {
496
- let statusCode = 500
497
- if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
498
- const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length)
499
- if (!Number.isNaN(code) && code >= 400) {
500
- statusCode = code
501
- }
502
- } else if (
503
-
504
- error?.code?.startsWith('E') ||
505
- error?.message?.includes('timed out')
506
- ) {
507
-
508
- statusCode = 408
509
- }
510
- return statusCode
511
- }
512
- exports.getCodeFromWSError = getCodeFromWSError
513
-
514
- const isWABusinessPlatform = platform => {
515
- return platform === 'smbi' || platform === 'smba'
516
- }
517
- exports.isWABusinessPlatform = isWABusinessPlatform
518
-
519
- function trimUndefined(obj) {
520
- for (const key in obj) {
521
- if (typeof obj[key] === 'undefined') {
522
- delete obj[key]
523
- }
524
- }
525
- return obj
526
- }
527
- const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ'
528
- function bytesToCrockford(buffer) {
529
- let value = 0
530
- let bitCount = 0
531
- const crockford = []
532
- for (const element of buffer) {
533
- value = (value << 8) | (element & 0xff)
534
- bitCount += 8
535
- while (bitCount >= 5) {
536
- crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31))
537
- bitCount -= 5
538
- }
539
- }
540
- if (bitCount > 0) {
541
- crockford.push(CROCKFORD_CHARACTERS.charAt((value << (5 - bitCount)) & 31))
542
- }
543
- return crockford.join('')
544
- }
545
- function encodeNewsletterMessage(message) {
546
- return index_js_1.proto.Message.encode(message).finish()
547
- }
548
-
549
-
550
- const jitterDelay = (baseMs, varianceFraction = 0.3) => {
551
- const variance = baseMs * varianceFraction
552
- return baseMs + (Math.random() * 2 - 1) * variance
553
- }
554
- exports.jitterDelay = jitterDelay
555
-
556
-
557
- const exponentialBackoff = (attempt, baseMs = 500, maxMs = 30000) => {
558
- return Math.min(baseMs * Math.pow(2, attempt), maxMs)
559
- }
560
- exports.exponentialBackoff = exponentialBackoff
561
-
562
-
563
- const bytesToHex = buf => Buffer.from(buf).toString('hex')
564
- exports.bytesToHex = bytesToHex
565
-
566
-
567
- const hexToBytes = hex => Buffer.from(hex, 'hex')
568
- exports.hexToBytes = hexToBytes
569
-
570
-
571
- const bytesToBase64Url = buf => Buffer.from(buf).toString('base64url')
572
- exports.bytesToBase64Url = bytesToBase64Url
573
-
574
-
575
- const sha256Hex = data => (0, crypto_1.createHash)('sha256').update(data).digest('hex')
576
- exports.sha256Hex = sha256Hex
577
-
578
-
579
- const hmacSha256 = (data, key) => (0, crypto_1.createHmac)('sha256', key).update(data).digest()
580
- exports.hmacSha256 = hmacSha256
581
-
582
-
583
- const normalizeJidBatch = (jids, normalizer) => {
584
- const seen = new Set()
585
- const result = []
586
- for (const jid of jids) {
587
- if (!jid) continue
588
- const normalized = normalizer ? normalizer(jid) : jid
589
- if (!seen.has(normalized)) {
590
- seen.add(normalized)
591
- result.push(normalized)
592
- }
593
- }
594
- return result
595
- }
596
- exports.normalizeJidBatch = normalizeJidBatch
597
-
598
-
599
- const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
600
- exports.sleep = sleep
601
-
602
-
603
- const withRetry = async (fn, maxAttempts = 3, baseDelayMs = 500) => {
604
- let lastErr
605
- for (let i = 0; i < maxAttempts; i++) {
606
- try {
607
- return await fn()
608
- } catch (err) {
609
- lastErr = err
610
- if (i < maxAttempts - 1) {
611
- await sleep(exponentialBackoff(i, baseDelayMs))
612
- }
613
- }
614
- }
615
- throw lastErr
616
- }
617
- exports.withRetry = withRetry
@@ -1,51 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.processGroupHistory = exports.decodeGroupHistory = void 0
4
- const zlib_1 = require('zlib')
5
- const index_js_1 = require('../../WAProto/index.js')
6
-
7
-
8
- const decodeGroupHistory = (buffer, options = {}) => {
9
- const { inflate = true, withMessageBytes = false } = options
10
- if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
11
- throw new TypeError('decodeGroupHistory: buffer must be Buffer or Uint8Array')
12
- }
13
- let data = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer)
14
- if (inflate) {
15
- try {
16
- data = zlib_1.inflateSync(data)
17
- } catch {
18
-
19
- }
20
- }
21
- if (withMessageBytes) {
22
- const decoded = index_js_1.proto.GroupHistoryWithMessageBytes.decode(data)
23
- const expand = list =>
24
- (list || []).map(entry =>
25
- entry?.messageBytes ? index_js_1.proto.WebMessageInfo.decode(entry.messageBytes) : { key: entry?.key }
26
- )
27
- return {
28
- messages: expand(decoded.messages),
29
- commentMessages: expand(decoded.commentMessages),
30
- outOfWindowPinnedMessages: expand(decoded.outOfWindowPinnedMessages),
31
- uncountedAssociatedMessageLists: (decoded.uncountedAssociatedMessageLists || []).map(l => ({
32
- parentMessage: l.parentMessage,
33
- messages: expand(l.messages)
34
- }))
35
- }
36
- }
37
- return index_js_1.proto.GroupHistory.decode(data)
38
- }
39
- exports.decodeGroupHistory = decodeGroupHistory
40
-
41
-
42
- const processGroupHistory = groupHistory => {
43
- const gh = groupHistory || {}
44
- return {
45
- messages: gh.messages || [],
46
- commentMessages: gh.commentMessages || [],
47
- outOfWindowPinnedMessages: gh.outOfWindowPinnedMessages || [],
48
- uncountedAssociatedMessageLists: gh.uncountedAssociatedMessageLists || []
49
- }
50
- }
51
- exports.processGroupHistory = processGroupHistory