@badzz88/baileys 8.5.6 → 8.5.8

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