@mrlegendbot/baileys 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/WAProto/GenerateStatics.sh +3 -0
  2. package/WAProto/fix-imports.js +85 -0
  3. package/WAProto/index.d.ts +14017 -0
  4. package/WAProto/index.js +97691 -2
  5. package/lib/Defaults/index.d.ts +75 -0
  6. package/lib/Defaults/index.js +92 -89
  7. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  8. package/lib/Signal/Group/ciphertext-message.js +10 -9
  9. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  10. package/lib/Signal/Group/group-session-builder.js +22 -21
  11. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  12. package/lib/Signal/Group/group_cipher.js +69 -75
  13. package/lib/Signal/Group/index.d.ts +12 -0
  14. package/lib/Signal/Group/index.js +1 -0
  15. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  16. package/lib/Signal/Group/keyhelper.js +10 -9
  17. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  18. package/lib/Signal/Group/sender-chain-key.js +22 -21
  19. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
  21. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  22. package/lib/Signal/Group/sender-key-message.js +62 -56
  23. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  24. package/lib/Signal/Group/sender-key-name.js +40 -38
  25. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  26. package/lib/Signal/Group/sender-key-record.js +34 -33
  27. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  28. package/lib/Signal/Group/sender-key-state.js +76 -72
  29. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  30. package/lib/Signal/Group/sender-message-key.js +23 -22
  31. package/lib/Signal/libsignal.d.ts +5 -0
  32. package/lib/Signal/libsignal.js +405 -506
  33. package/lib/Signal/lid-mapping.d.ts +23 -0
  34. package/lib/Signal/lid-mapping.js +258 -276
  35. package/lib/Socket/Client/index.d.ts +3 -0
  36. package/lib/Socket/Client/index.js +1 -0
  37. package/lib/Socket/Client/types.d.ts +16 -0
  38. package/lib/Socket/Client/types.js +7 -6
  39. package/lib/Socket/Client/websocket.d.ts +13 -0
  40. package/lib/Socket/Client/websocket.js +49 -48
  41. package/lib/Socket/business.d.ts +217 -0
  42. package/lib/Socket/business.js +369 -349
  43. package/lib/Socket/chats.d.ts +125 -0
  44. package/lib/Socket/chats.js +1148 -1172
  45. package/lib/Socket/communities.d.ts +273 -0
  46. package/lib/Socket/communities.js +413 -473
  47. package/lib/Socket/groups.d.ts +161 -0
  48. package/lib/Socket/groups.js +331 -387
  49. package/lib/Socket/index.d.ts +260 -0
  50. package/lib/Socket/index.js +8 -6
  51. package/lib/Socket/messages-recv.d.ts +203 -0
  52. package/lib/Socket/messages-recv.js +1719 -1782
  53. package/lib/Socket/messages-send.d.ts +200 -0
  54. package/lib/Socket/messages-send.js +2508 -1384
  55. package/lib/Socket/mex.d.ts +3 -0
  56. package/lib/Socket/mex.js +35 -40
  57. package/lib/Socket/newsletter.d.ts +170 -0
  58. package/lib/Socket/newsletter.js +191 -239
  59. package/lib/Socket/socket.d.ts +59 -0
  60. package/lib/Socket/socket.js +923 -992
  61. package/lib/Types/Auth.d.ts +117 -0
  62. package/lib/Types/Auth.js +1 -0
  63. package/lib/Types/Bussines.d.ts +25 -0
  64. package/lib/Types/Bussines.js +1 -0
  65. package/lib/Types/Call.d.ts +15 -0
  66. package/lib/Types/Call.js +1 -0
  67. package/lib/Types/Chat.d.ts +124 -0
  68. package/lib/Types/Chat.js +8 -1
  69. package/lib/Types/Contact.d.ts +26 -0
  70. package/lib/Types/Contact.js +1 -0
  71. package/lib/Types/Events.d.ts +256 -0
  72. package/lib/Types/Events.js +2 -1
  73. package/lib/Types/GroupMetadata.d.ts +71 -0
  74. package/lib/Types/GroupMetadata.js +1 -0
  75. package/lib/Types/Label.d.ts +47 -0
  76. package/lib/Types/Label.js +22 -20
  77. package/lib/Types/LabelAssociation.d.ts +30 -0
  78. package/lib/Types/LabelAssociation.js +4 -2
  79. package/lib/Types/Message.d.ts +320 -0
  80. package/lib/Types/Message.js +5 -3
  81. package/lib/Types/Mex.d.ts +141 -0
  82. package/lib/Types/Mex.js +31 -26
  83. package/lib/Types/Product.d.ts +79 -0
  84. package/lib/Types/Product.js +1 -0
  85. package/lib/Types/Signal.d.ts +87 -0
  86. package/lib/Types/Signal.js +2 -1
  87. package/lib/Types/Socket.d.ts +136 -0
  88. package/lib/Types/Socket.js +3 -2
  89. package/lib/Types/State.d.ts +97 -0
  90. package/lib/Types/State.js +52 -4
  91. package/lib/Types/USync.d.ts +26 -0
  92. package/lib/Types/USync.js +1 -0
  93. package/lib/Types/index.d.ts +66 -0
  94. package/lib/Types/index.js +11 -10
  95. package/lib/Utils/auth-utils.d.ts +24 -0
  96. package/lib/Utils/auth-utils.js +277 -240
  97. package/lib/Utils/browser-utils.d.ts +4 -0
  98. package/lib/Utils/browser-utils.js +23 -20
  99. package/lib/Utils/business.d.ts +23 -0
  100. package/lib/Utils/business.js +204 -200
  101. package/lib/Utils/chat-utils.d.ts +100 -0
  102. package/lib/Utils/chat-utils.js +810 -836
  103. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  104. package/lib/Utils/companion-reg-client-utils.js +25 -23
  105. package/lib/Utils/crypto.d.ts +37 -0
  106. package/lib/Utils/crypto.js +86 -70
  107. package/lib/Utils/decode-wa-message.d.ts +66 -0
  108. package/lib/Utils/decode-wa-message.js +284 -277
  109. package/lib/Utils/event-buffer.d.ts +36 -0
  110. package/lib/Utils/event-buffer.js +595 -592
  111. package/lib/Utils/generics.d.ts +92 -0
  112. package/lib/Utils/generics.js +335 -312
  113. package/lib/Utils/history.d.ts +24 -0
  114. package/lib/Utils/history.js +115 -123
  115. package/lib/Utils/identity-change-handler.d.ts +44 -0
  116. package/lib/Utils/identity-change-handler.js +50 -0
  117. package/lib/Utils/index.d.ts +22 -0
  118. package/lib/Utils/index.js +2 -1
  119. package/lib/Utils/link-preview.d.ts +21 -0
  120. package/lib/Utils/link-preview.js +73 -74
  121. package/lib/Utils/logger.d.ts +12 -0
  122. package/lib/Utils/logger.js +2 -3
  123. package/lib/Utils/lt-hash.d.ts +8 -0
  124. package/lib/Utils/lt-hash.js +6 -0
  125. package/lib/Utils/make-mutex.d.ts +9 -0
  126. package/lib/Utils/make-mutex.js +27 -27
  127. package/lib/Utils/message-retry-manager.d.ts +115 -0
  128. package/lib/Utils/message-retry-manager.js +254 -213
  129. package/lib/Utils/messages-media.d.ts +133 -0
  130. package/lib/Utils/messages-media.js +715 -741
  131. package/lib/Utils/messages.d.ts +91 -0
  132. package/lib/Utils/messages.js +827 -791
  133. package/lib/Utils/noise-handler.d.ts +20 -0
  134. package/lib/Utils/noise-handler.js +187 -215
  135. package/lib/Utils/offline-node-processor.d.ts +17 -0
  136. package/lib/Utils/offline-node-processor.js +40 -0
  137. package/lib/Utils/pre-key-manager.d.ts +28 -0
  138. package/lib/Utils/pre-key-manager.js +98 -69
  139. package/lib/Utils/process-message.d.ts +60 -0
  140. package/lib/Utils/process-message.js +586 -617
  141. package/lib/Utils/reporting-utils.d.ts +11 -0
  142. package/lib/Utils/reporting-utils.js +234 -553
  143. package/lib/Utils/signal.d.ts +47 -0
  144. package/lib/Utils/signal.js +170 -217
  145. package/lib/Utils/stanza-ack.d.ts +11 -0
  146. package/lib/Utils/stanza-ack.js +35 -27
  147. package/lib/Utils/sync-action-utils.d.ts +19 -0
  148. package/lib/Utils/sync-action-utils.js +41 -37
  149. package/lib/Utils/tc-token-utils.d.ts +37 -0
  150. package/lib/Utils/tc-token-utils.js +141 -120
  151. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  152. package/lib/Utils/use-multi-file-auth-state.js +105 -87
  153. package/lib/Utils/validate-connection.d.ts +11 -0
  154. package/lib/Utils/validate-connection.js +188 -190
  155. package/lib/WABinary/constants.d.ts +28 -0
  156. package/lib/WABinary/constants.js +1294 -28
  157. package/lib/WABinary/decode.d.ts +7 -0
  158. package/lib/WABinary/decode.js +249 -245
  159. package/lib/WABinary/encode.d.ts +3 -0
  160. package/lib/WABinary/encode.js +206 -201
  161. package/lib/WABinary/generic-utils.d.ts +15 -0
  162. package/lib/WABinary/generic-utils.js +89 -86
  163. package/lib/WABinary/index.d.ts +6 -0
  164. package/lib/WABinary/index.js +1 -0
  165. package/lib/WABinary/jid-utils.d.ts +48 -0
  166. package/lib/WABinary/jid-utils.js +77 -68
  167. package/lib/WABinary/types.d.ts +19 -0
  168. package/lib/WABinary/types.js +1 -0
  169. package/lib/WAM/BinaryInfo.d.ts +9 -0
  170. package/lib/WAM/BinaryInfo.js +8 -7
  171. package/lib/WAM/constants.d.ts +40 -0
  172. package/lib/WAM/constants.js +22853 -19892
  173. package/lib/WAM/encode.d.ts +3 -0
  174. package/lib/WAM/encode.js +132 -121
  175. package/lib/WAM/index.d.ts +4 -0
  176. package/lib/WAM/index.js +1 -0
  177. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  178. package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
  179. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  180. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
  181. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  182. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
  183. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  184. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
  185. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  186. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
  187. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  188. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
  189. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  190. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
  191. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  192. package/lib/WAUSync/Protocols/index.js +1 -0
  193. package/lib/WAUSync/USyncQuery.d.ts +30 -0
  194. package/lib/WAUSync/USyncQuery.js +88 -79
  195. package/lib/WAUSync/USyncUser.d.ts +17 -0
  196. package/lib/WAUSync/USyncUser.js +29 -28
  197. package/lib/WAUSync/index.d.ts +4 -0
  198. package/lib/WAUSync/index.js +1 -0
  199. package/lib/index.d.ts +12 -0
  200. package/lib/index.js +2 -2
  201. package/package.json +86 -22
  202. package/README.upstream.md +0 -1312
  203. package/WAProto/WAProto.json +0 -1
  204. package/WAProto/WAProto.proto +0 -6275
  205. package/WAProto/compiler.js +0 -550
  206. package/lib/Store/index.js +0 -8
  207. package/lib/Store/keyed-db.js +0 -108
  208. package/lib/Store/make-cache-manager-store.js +0 -70
  209. package/lib/Store/make-in-memory-store.js +0 -417
  210. package/lib/Store/make-ordered-dictionary.js +0 -69
  211. package/lib/Store/object-repository.js +0 -27
  212. package/lib/Utils/use-sqlite-auth-state.js +0 -162
@@ -1,577 +1,258 @@
1
1
  import { createHmac } from 'crypto';
2
- import { proto } from '../../WAProto/compiler.js';
2
+ import { proto } from '../../WAProto/index.js';
3
3
  import { hkdf } from './crypto.js';
4
- const reportingFields = [{
5
- f: 1
6
- }, {
7
- f: 3,
8
- s: [{
9
- f: 2
10
- }, {
11
- f: 3
12
- }, {
13
- f: 8
14
- }, {
15
- f: 11
16
- }, {
17
- f: 17,
18
- s: [{
19
- f: 21
20
- }, {
21
- f: 22
22
- }]
23
- }, {
24
- f: 25
25
- }]
26
- }, {
27
- f: 4,
28
- s: [{
29
- f: 1
30
- }, {
31
- f: 16
32
- }, {
33
- f: 17,
34
- s: [{
35
- f: 21
36
- }, {
37
- f: 22
38
- }]
39
- }]
40
- }, {
41
- f: 5,
42
- s: [{
43
- f: 3
44
- }, {
45
- f: 4
46
- }, {
47
- f: 5
48
- }, {
49
- f: 16
50
- }, {
51
- f: 17,
52
- s: [{
53
- f: 21
54
- }, {
55
- f: 22
56
- }]
57
- }]
58
- }, {
59
- f: 6,
60
- s: [{
61
- f: 1
62
- }, {
63
- f: 17,
64
- s: [{
65
- f: 21
66
- }, {
67
- f: 22
68
- }]
69
- }, {
70
- f: 30
71
- }]
72
- }, {
73
- f: 7,
74
- s: [{
75
- f: 2
76
- }, {
77
- f: 7
78
- }, {
79
- f: 10
80
- }, {
81
- f: 17,
82
- s: [{
83
- f: 21
84
- }, {
85
- f: 22
86
- }]
87
- }, {
88
- f: 20
89
- }]
90
- }, {
91
- f: 8,
92
- s: [{
93
- f: 2
94
- }, {
95
- f: 7
96
- }, {
97
- f: 9
98
- }, {
99
- f: 17,
100
- s: [{
101
- f: 21
102
- }, {
103
- f: 22
104
- }]
105
- }, {
106
- f: 21
107
- }]
108
- }, {
109
- f: 9,
110
- s: [{
111
- f: 2
112
- }, {
113
- f: 6
114
- }, {
115
- f: 7
116
- }, {
117
- f: 13
118
- }, {
119
- f: 17,
120
- s: [{
121
- f: 21
122
- }, {
123
- f: 22
124
- }]
125
- }, {
126
- f: 20
127
- }]
128
- }, {
129
- f: 12,
130
- s: [{
131
- f: 1
132
- }, {
133
- f: 2
134
- }, {
135
- f: 14,
136
- m: true
137
- }, {
138
- f: 15
139
- }]
140
- }, {
141
- f: 18,
142
- s: [{
143
- f: 6
144
- }, {
145
- f: 16
146
- }, {
147
- f: 17,
148
- s: [{
149
- f: 21
150
- }, {
151
- f: 22
152
- }]
153
- }]
154
- }, {
155
- f: 26,
156
- s: [{
157
- f: 4
158
- }, {
159
- f: 5
160
- }, {
161
- f: 8
162
- }, {
163
- f: 13
164
- }, {
165
- f: 17,
166
- s: [{
167
- f: 21
168
- }, {
169
- f: 22
170
- }]
171
- }]
172
- }, {
173
- f: 28,
174
- s: [{
175
- f: 1
176
- }, {
177
- f: 2
178
- }, {
179
- f: 4
180
- }, {
181
- f: 5
182
- }, {
183
- f: 6
184
- }, {
185
- f: 7,
186
- s: [{
187
- f: 21
188
- }, {
189
- f: 22
190
- }]
191
- }]
192
- }, {
193
- f: 37,
194
- s: [{
195
- f: 1,
196
- m: true
197
- }]
198
- }, {
199
- f: 49,
200
- s: [{
201
- f: 2
202
- }, {
203
- f: 3,
204
- s: [{
205
- f: 1
206
- }, {
207
- f: 2
208
- }]
209
- }, {
210
- f: 5,
211
- s: [{
212
- f: 21
213
- }, {
214
- f: 22
215
- }]
216
- }, {
217
- f: 8,
218
- s: [{
219
- f: 1
220
- }, {
221
- f: 2
222
- }]
223
- }]
224
- }, {
225
- f: 53,
226
- s: [{
227
- f: 1,
228
- m: true
229
- }]
230
- }, {
231
- f: 55,
232
- s: [{
233
- f: 1,
234
- m: true
235
- }]
236
- }, {
237
- f: 58,
238
- s: [{
239
- f: 1,
240
- m: true
241
- }]
242
- }, {
243
- f: 59,
244
- s: [{
245
- f: 1,
246
- m: true
247
- }]
248
- }, {
249
- f: 60,
250
- s: [{
251
- f: 2
252
- }, {
253
- f: 3,
254
- s: [{
255
- f: 1
256
- }, {
257
- f: 2
258
- }]
259
- }, {
260
- f: 5,
261
- s: [{
262
- f: 21
263
- }, {
264
- f: 22
265
- }]
266
- }, {
267
- f: 8,
268
- s: [{
269
- f: 1
270
- }, {
271
- f: 2
272
- }]
273
- }]
274
- }, {
275
- f: 64,
276
- s: [{
277
- f: 2
278
- }, {
279
- f: 3,
280
- s: [{
281
- f: 1
282
- }, {
283
- f: 2
284
- }]
285
- }, {
286
- f: 5,
287
- s: [{
288
- f: 21
289
- }, {
290
- f: 22
291
- }]
292
- }, {
293
- f: 8,
294
- s: [{
295
- f: 1
296
- }, {
297
- f: 2
298
- }]
299
- }]
300
- }, {
301
- f: 66,
302
- s: [{
303
- f: 2
304
- }, {
305
- f: 6
306
- }, {
307
- f: 7
308
- }, {
309
- f: 13
310
- }, {
311
- f: 17,
312
- s: [{
313
- f: 21
314
- }, {
315
- f: 22
316
- }]
317
- }, {
318
- f: 20
319
- }]
320
- }, {
321
- f: 74,
322
- s: [{
323
- f: 1,
324
- m: true
325
- }]
326
- }, {
327
- f: 87,
328
- s: [{
329
- f: 1,
330
- m: true
331
- }]
332
- }, {
333
- f: 88,
334
- s: [{
335
- f: 1
336
- }, {
337
- f: 2,
338
- s: [{
339
- f: 1
340
- }]
341
- }, {
342
- f: 3,
343
- s: [{
344
- f: 21
345
- }, {
346
- f: 22
347
- }]
348
- }]
349
- }, {
350
- f: 92,
351
- s: [{
352
- f: 1,
353
- m: true
354
- }]
355
- }, {
356
- f: 93,
357
- s: [{
358
- f: 1,
359
- m: true
360
- }]
361
- }, {
362
- f: 94,
363
- s: [{
364
- f: 1,
365
- m: true
366
- }]
367
- }];
368
- const compileReportingFields = fields => {
369
- const map = new Map();
370
- for (const f of fields) {
371
- map.set(f.f, {
372
- m: f.m,
373
- children: f.s ? compileReportingFields(f.s) : undefined
374
- });
375
- }
376
- return map;
4
+ const reportingFields = [
5
+ { f: 1 },
6
+ {
7
+ f: 3,
8
+ s: [{ f: 2 }, { f: 3 }, { f: 8 }, { f: 11 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 25 }]
9
+ },
10
+ { f: 4, s: [{ f: 1 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
11
+ { f: 5, s: [{ f: 3 }, { f: 4 }, { f: 5 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
12
+ { f: 6, s: [{ f: 1 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 30 }] },
13
+ { f: 7, s: [{ f: 2 }, { f: 7 }, { f: 10 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
14
+ { f: 8, s: [{ f: 2 }, { f: 7 }, { f: 9 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 21 }] },
15
+ { f: 9, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
16
+ { f: 12, s: [{ f: 1 }, { f: 2 }, { f: 14, m: true }, { f: 15 }] },
17
+ { f: 18, s: [{ f: 6 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
18
+ { f: 26, s: [{ f: 4 }, { f: 5 }, { f: 8 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
19
+ { f: 28, s: [{ f: 1 }, { f: 2 }, { f: 4 }, { f: 5 }, { f: 6 }, { f: 7, s: [{ f: 21 }, { f: 22 }] }] },
20
+ { f: 37, s: [{ f: 1, m: true }] },
21
+ {
22
+ f: 49,
23
+ s: [
24
+ { f: 2 },
25
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
26
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
27
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
28
+ ]
29
+ },
30
+ { f: 53, s: [{ f: 1, m: true }] },
31
+ { f: 55, s: [{ f: 1, m: true }] },
32
+ { f: 58, s: [{ f: 1, m: true }] },
33
+ { f: 59, s: [{ f: 1, m: true }] },
34
+ {
35
+ f: 60,
36
+ s: [
37
+ { f: 2 },
38
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
39
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
40
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
41
+ ]
42
+ },
43
+ {
44
+ f: 64,
45
+ s: [
46
+ { f: 2 },
47
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
48
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
49
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
50
+ ]
51
+ },
52
+ { f: 66, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
53
+ { f: 74, s: [{ f: 1, m: true }] },
54
+ { f: 87, s: [{ f: 1, m: true }] },
55
+ { f: 88, s: [{ f: 1 }, { f: 2, s: [{ f: 1 }] }, { f: 3, s: [{ f: 21 }, { f: 22 }] }] },
56
+ { f: 92, s: [{ f: 1, m: true }] },
57
+ { f: 93, s: [{ f: 1, m: true }] },
58
+ { f: 94, s: [{ f: 1, m: true }] }
59
+ ];
60
+ const compileReportingFields = (fields) => {
61
+ const map = new Map();
62
+ for (const f of fields) {
63
+ map.set(f.f, {
64
+ m: f.m,
65
+ children: f.s ? compileReportingFields(f.s) : undefined
66
+ });
67
+ }
68
+ return map;
377
69
  };
378
70
  const compiledReportingFields = compileReportingFields(reportingFields);
379
71
  const EMPTY_MAP = new Map();
380
72
  const ENC_SECRET_REPORT_TOKEN = 'Report Token';
381
73
  const WIRE = {
382
- VARINT: 0,
383
- FIXED64: 1,
384
- BYTES: 2,
385
- FIXED32: 5
74
+ VARINT: 0,
75
+ FIXED64: 1,
76
+ BYTES: 2,
77
+ FIXED32: 5
386
78
  };
387
- export const shouldIncludeReportingToken = message => !message.reactionMessage && !message.encReactionMessage && !message.encEventResponseMessage && !message.pollUpdateMessage;
79
+ export const shouldIncludeReportingToken = (message) => !message.reactionMessage &&
80
+ !message.encReactionMessage &&
81
+ !message.encEventResponseMessage &&
82
+ !message.pollUpdateMessage;
388
83
  const generateMsgSecretKey = (modificationType, origMsgId, origMsgSender, modificationSender, origMsgSecret) => {
389
- const useCaseSecret = Buffer.concat([Buffer.from(origMsgId, 'utf8'), Buffer.from(origMsgSender, 'utf8'), Buffer.from(modificationSender, 'utf8'), Buffer.from(modificationType, 'utf8')]);
390
- return hkdf(origMsgSecret, 32, {
391
- info: useCaseSecret.toString('latin1')
392
- });
84
+ const useCaseSecret = Buffer.concat([
85
+ Buffer.from(origMsgId, 'utf8'),
86
+ Buffer.from(origMsgSender, 'utf8'),
87
+ Buffer.from(modificationSender, 'utf8'),
88
+ Buffer.from(modificationType, 'utf8')
89
+ ]);
90
+ return hkdf(origMsgSecret, 32, { info: useCaseSecret.toString('latin1') });
393
91
  };
394
92
  const extractReportingTokenContent = (data, cfg) => {
395
- const out = [];
396
- let i = 0;
397
- while (i < data.length) {
398
- const tag = decodeVarint(data, i);
399
- if (!tag.ok) {
400
- return null;
401
- }
402
- const fieldNum = tag.value >> 3;
403
- const wireType = tag.value & 0x7;
404
- const fieldStart = i;
405
- i += tag.bytes;
406
- const fieldCfg = cfg.get(fieldNum);
407
- const pushSlice = end => {
408
- if (end > data.length) {
409
- return false;
410
- }
411
- out.push({
412
- num: fieldNum,
413
- bytes: data.subarray(fieldStart, end)
414
- });
415
- i = end;
416
- return true;
417
- };
418
- const skip = end => {
419
- if (end > data.length) {
420
- return false;
421
- }
422
- i = end;
423
- return true;
424
- };
425
- if (wireType === WIRE.VARINT) {
426
- const v = decodeVarint(data, i);
427
- if (!v.ok) {
428
- return null;
429
- }
430
- const end = i + v.bytes;
431
- if (!fieldCfg) {
432
- if (!skip(end)) {
433
- return null;
93
+ const out = [];
94
+ let i = 0;
95
+ while (i < data.length) {
96
+ const tag = decodeVarint(data, i);
97
+ if (!tag.ok) {
98
+ return null;
434
99
  }
435
- continue;
436
- }
437
- if (!pushSlice(end)) {
438
- return null;
439
- }
440
- continue;
441
- }
442
- if (wireType === WIRE.FIXED64) {
443
- const end = i + 8;
444
- if (!fieldCfg) {
445
- if (!skip(end)) {
446
- return null;
100
+ const fieldNum = tag.value >> 3;
101
+ const wireType = tag.value & 0x7;
102
+ const fieldStart = i;
103
+ i += tag.bytes;
104
+ const fieldCfg = cfg.get(fieldNum);
105
+ const pushSlice = (end) => {
106
+ if (end > data.length) {
107
+ return false;
108
+ }
109
+ out.push({ num: fieldNum, bytes: data.subarray(fieldStart, end) });
110
+ i = end;
111
+ return true;
112
+ };
113
+ const skip = (end) => {
114
+ if (end > data.length) {
115
+ return false;
116
+ }
117
+ i = end;
118
+ return true;
119
+ };
120
+ if (wireType === WIRE.VARINT) {
121
+ const v = decodeVarint(data, i);
122
+ if (!v.ok) {
123
+ return null;
124
+ }
125
+ const end = i + v.bytes;
126
+ if (!fieldCfg) {
127
+ if (!skip(end)) {
128
+ return null;
129
+ }
130
+ continue;
131
+ }
132
+ if (!pushSlice(end)) {
133
+ return null;
134
+ }
135
+ continue;
447
136
  }
448
- continue;
449
- }
450
- if (!pushSlice(end)) {
451
- return null;
452
- }
453
- continue;
454
- }
455
- if (wireType === WIRE.FIXED32) {
456
- const end = i + 4;
457
- if (!fieldCfg) {
458
- if (!skip(end)) {
459
- return null;
137
+ if (wireType === WIRE.FIXED64) {
138
+ const end = i + 8;
139
+ if (!fieldCfg) {
140
+ if (!skip(end)) {
141
+ return null;
142
+ }
143
+ continue;
144
+ }
145
+ if (!pushSlice(end)) {
146
+ return null;
147
+ }
148
+ continue;
460
149
  }
461
- continue;
462
- }
463
- if (!pushSlice(end)) {
464
- return null;
465
- }
466
- continue;
467
- }
468
- if (wireType === WIRE.BYTES) {
469
- const len = decodeVarint(data, i);
470
- if (!len.ok) {
471
- return null;
472
- }
473
- const valStart = i + len.bytes;
474
- const valEnd = valStart + len.value;
475
- if (valEnd > data.length) {
476
- return null;
477
- }
478
- if (!fieldCfg) {
479
- i = valEnd;
480
- continue;
481
- }
482
- if (fieldCfg.m || fieldCfg.children) {
483
- const sub = extractReportingTokenContent(data.subarray(valStart, valEnd), fieldCfg.children ?? EMPTY_MAP);
484
- if (sub === null) {
485
- return null;
150
+ if (wireType === WIRE.FIXED32) {
151
+ const end = i + 4;
152
+ if (!fieldCfg) {
153
+ if (!skip(end)) {
154
+ return null;
155
+ }
156
+ continue;
157
+ }
158
+ if (!pushSlice(end)) {
159
+ return null;
160
+ }
161
+ continue;
486
162
  }
487
- if (sub.length > 0) {
488
- const newTag = encodeVarint(tag.value);
489
- const newLen = encodeVarint(sub.length);
490
- out.push({
491
- num: fieldNum,
492
- bytes: Buffer.concat([newTag, newLen, sub])
493
- });
163
+ if (wireType === WIRE.BYTES) {
164
+ const len = decodeVarint(data, i);
165
+ if (!len.ok) {
166
+ return null;
167
+ }
168
+ const valStart = i + len.bytes;
169
+ const valEnd = valStart + len.value;
170
+ if (valEnd > data.length) {
171
+ return null;
172
+ }
173
+ if (!fieldCfg) {
174
+ i = valEnd;
175
+ continue;
176
+ }
177
+ if (fieldCfg.m || fieldCfg.children) {
178
+ const sub = extractReportingTokenContent(data.subarray(valStart, valEnd), fieldCfg.children ?? EMPTY_MAP);
179
+ if (sub === null) {
180
+ return null;
181
+ }
182
+ if (sub.length > 0) {
183
+ const newTag = encodeVarint(tag.value);
184
+ const newLen = encodeVarint(sub.length);
185
+ out.push({
186
+ num: fieldNum,
187
+ bytes: Buffer.concat([newTag, newLen, sub])
188
+ });
189
+ }
190
+ i = valEnd;
191
+ continue;
192
+ }
193
+ out.push({ num: fieldNum, bytes: data.subarray(fieldStart, valEnd) });
194
+ i = valEnd;
195
+ continue;
494
196
  }
495
- i = valEnd;
496
- continue;
497
- }
498
- out.push({
499
- num: fieldNum,
500
- bytes: data.subarray(fieldStart, valEnd)
501
- });
502
- i = valEnd;
503
- continue;
197
+ return null;
198
+ }
199
+ if (out.length === 0) {
200
+ return Buffer.alloc(0);
504
201
  }
505
- return null;
506
- }
507
- if (out.length === 0) {
508
- return Buffer.alloc(0);
509
- }
510
- out.sort((a, b) => a.num - b.num);
511
- return Buffer.concat(out.map(f => f.bytes));
202
+ out.sort((a, b) => a.num - b.num);
203
+ return Buffer.concat(out.map(f => f.bytes));
512
204
  };
513
205
  const decodeVarint = (buffer, offset) => {
514
- let value = 0;
515
- let bytes = 0;
516
- let shift = 0;
517
- while (offset + bytes < buffer.length) {
518
- const current = buffer[offset + bytes];
519
- value |= (current & 0x7f) << shift;
520
- bytes++;
521
- if ((current & 0x80) === 0) {
522
- return {
523
- value,
524
- bytes,
525
- ok: true
526
- };
527
- }
528
- shift += 7;
529
- if (shift > 35) {
530
- return {
531
- value: 0,
532
- bytes: 0,
533
- ok: false
534
- };
206
+ let value = 0;
207
+ let bytes = 0;
208
+ let shift = 0;
209
+ while (offset + bytes < buffer.length) {
210
+ const current = buffer[offset + bytes];
211
+ value |= (current & 0x7f) << shift;
212
+ bytes++;
213
+ if ((current & 0x80) === 0) {
214
+ return { value, bytes, ok: true };
215
+ }
216
+ shift += 7;
217
+ if (shift > 35) {
218
+ return { value: 0, bytes: 0, ok: false };
219
+ }
535
220
  }
536
- }
537
- return {
538
- value: 0,
539
- bytes: 0,
540
- ok: false
541
- };
221
+ return { value: 0, bytes: 0, ok: false };
542
222
  };
543
- const encodeVarint = value => {
544
- const parts = [];
545
- let remaining = value >>> 0;
546
- while (remaining > 0x7f) {
547
- parts.push(remaining & 0x7f | 0x80);
548
- remaining >>>= 7;
549
- }
550
- parts.push(remaining);
551
- return Buffer.from(parts);
223
+ const encodeVarint = (value) => {
224
+ const parts = [];
225
+ let remaining = value >>> 0;
226
+ while (remaining > 0x7f) {
227
+ parts.push((remaining & 0x7f) | 0x80);
228
+ remaining >>>= 7;
229
+ }
230
+ parts.push(remaining);
231
+ return Buffer.from(parts);
552
232
  };
553
233
  export const getMessageReportingToken = async (msgProtobuf, message, key) => {
554
- const msgSecret = message.messageContextInfo?.messageSecret;
555
- if (!msgSecret || !key.id) {
556
- return null;
557
- }
558
- const from = key.fromMe ? key.remoteJid : key.participant || key.remoteJid;
559
- const to = key.fromMe ? key.participant || key.remoteJid : key.remoteJid;
560
- const reportingSecret = generateMsgSecretKey(ENC_SECRET_REPORT_TOKEN, key.id, from, to, msgSecret);
561
- const content = extractReportingTokenContent(msgProtobuf, compiledReportingFields);
562
- if (!content || content.length === 0) {
563
- return null;
564
- }
565
- const reportingToken = createHmac('sha256', reportingSecret).update(content).digest().subarray(0, 16);
566
- return {
567
- tag: 'reporting',
568
- attrs: {},
569
- content: [{
570
- tag: 'reporting_token',
571
- attrs: {
572
- v: '2'
573
- },
574
- content: reportingToken
575
- }]
576
- };
234
+ const msgSecret = message.messageContextInfo?.messageSecret;
235
+ if (!msgSecret || !key.id) {
236
+ return null;
237
+ }
238
+ const from = key.fromMe ? key.remoteJid : key.participant || key.remoteJid;
239
+ const to = key.fromMe ? key.participant || key.remoteJid : key.remoteJid;
240
+ const reportingSecret = generateMsgSecretKey(ENC_SECRET_REPORT_TOKEN, key.id, from, to, msgSecret);
241
+ const content = extractReportingTokenContent(msgProtobuf, compiledReportingFields);
242
+ if (!content || content.length === 0) {
243
+ return null;
244
+ }
245
+ const reportingToken = createHmac('sha256', reportingSecret).update(content).digest().subarray(0, 16);
246
+ return {
247
+ tag: 'reporting',
248
+ attrs: {},
249
+ content: [
250
+ {
251
+ tag: 'reporting_token',
252
+ attrs: { v: '2' },
253
+ content: reportingToken
254
+ }
255
+ ]
256
+ };
577
257
  };
258
+ //# sourceMappingURL=reporting-utils.js.map