@mrlegendbot/baileys 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.upstream.md +1312 -0
  2. package/WAProto/WAProto.json +1 -0
  3. package/WAProto/WAProto.proto +6275 -0
  4. package/WAProto/compiler.js +550 -0
  5. package/WAProto/index.js +2 -97691
  6. package/lib/Defaults/index.js +89 -92
  7. package/lib/Signal/Group/ciphertext-message.js +9 -10
  8. package/lib/Signal/Group/group-session-builder.js +21 -22
  9. package/lib/Signal/Group/group_cipher.js +75 -69
  10. package/lib/Signal/Group/index.js +0 -1
  11. package/lib/Signal/Group/keyhelper.js +9 -10
  12. package/lib/Signal/Group/sender-chain-key.js +21 -22
  13. package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
  14. package/lib/Signal/Group/sender-key-message.js +56 -62
  15. package/lib/Signal/Group/sender-key-name.js +38 -40
  16. package/lib/Signal/Group/sender-key-record.js +33 -34
  17. package/lib/Signal/Group/sender-key-state.js +72 -76
  18. package/lib/Signal/Group/sender-message-key.js +22 -23
  19. package/lib/Signal/libsignal.js +506 -405
  20. package/lib/Signal/lid-mapping.js +276 -258
  21. package/lib/Socket/Client/index.js +0 -1
  22. package/lib/Socket/Client/types.js +6 -7
  23. package/lib/Socket/Client/websocket.js +48 -49
  24. package/lib/Socket/business.js +349 -369
  25. package/lib/Socket/chats.js +1172 -1148
  26. package/lib/Socket/communities.js +473 -413
  27. package/lib/Socket/groups.js +387 -331
  28. package/lib/Socket/index.js +6 -8
  29. package/lib/Socket/messages-recv.js +1782 -1719
  30. package/lib/Socket/messages-send.js +1503 -2450
  31. package/lib/Socket/mex.js +40 -35
  32. package/lib/Socket/newsletter.js +239 -191
  33. package/lib/Socket/socket.js +992 -923
  34. package/lib/Store/index.js +8 -0
  35. package/lib/Store/keyed-db.js +108 -0
  36. package/lib/Store/make-cache-manager-store.js +70 -0
  37. package/lib/Store/make-in-memory-store.js +417 -0
  38. package/lib/Store/make-ordered-dictionary.js +69 -0
  39. package/lib/Store/object-repository.js +27 -0
  40. package/lib/Types/Auth.js +0 -1
  41. package/lib/Types/Bussines.js +0 -1
  42. package/lib/Types/Call.js +0 -1
  43. package/lib/Types/Chat.js +1 -8
  44. package/lib/Types/Contact.js +0 -1
  45. package/lib/Types/Events.js +1 -2
  46. package/lib/Types/GroupMetadata.js +0 -1
  47. package/lib/Types/Label.js +20 -22
  48. package/lib/Types/LabelAssociation.js +2 -4
  49. package/lib/Types/Message.js +3 -5
  50. package/lib/Types/Mex.js +26 -31
  51. package/lib/Types/Product.js +0 -1
  52. package/lib/Types/Signal.js +1 -2
  53. package/lib/Types/Socket.js +2 -3
  54. package/lib/Types/State.js +4 -52
  55. package/lib/Types/USync.js +0 -1
  56. package/lib/Types/index.js +10 -11
  57. package/lib/Utils/auth-utils.js +240 -277
  58. package/lib/Utils/browser-utils.js +20 -23
  59. package/lib/Utils/business.js +200 -204
  60. package/lib/Utils/chat-utils.js +836 -810
  61. package/lib/Utils/companion-reg-client-utils.js +23 -25
  62. package/lib/Utils/crypto.js +70 -86
  63. package/lib/Utils/decode-wa-message.js +277 -284
  64. package/lib/Utils/event-buffer.js +592 -595
  65. package/lib/Utils/generics.js +312 -335
  66. package/lib/Utils/history.js +123 -115
  67. package/lib/Utils/index.js +1 -2
  68. package/lib/Utils/link-preview.js +74 -73
  69. package/lib/Utils/logger.js +3 -2
  70. package/lib/Utils/lt-hash.js +0 -6
  71. package/lib/Utils/make-mutex.js +27 -27
  72. package/lib/Utils/message-retry-manager.js +213 -254
  73. package/lib/Utils/messages-media.js +741 -715
  74. package/lib/Utils/messages.js +791 -827
  75. package/lib/Utils/noise-handler.js +215 -187
  76. package/lib/Utils/pre-key-manager.js +69 -98
  77. package/lib/Utils/process-message.js +617 -586
  78. package/lib/Utils/reporting-utils.js +553 -234
  79. package/lib/Utils/signal.js +217 -170
  80. package/lib/Utils/stanza-ack.js +27 -35
  81. package/lib/Utils/sync-action-utils.js +37 -41
  82. package/lib/Utils/tc-token-utils.js +120 -141
  83. package/lib/Utils/use-multi-file-auth-state.js +87 -105
  84. package/lib/Utils/use-sqlite-auth-state.js +162 -0
  85. package/lib/Utils/validate-connection.js +190 -188
  86. package/lib/WABinary/constants.js +28 -1294
  87. package/lib/WABinary/decode.js +245 -249
  88. package/lib/WABinary/encode.js +201 -206
  89. package/lib/WABinary/generic-utils.js +86 -89
  90. package/lib/WABinary/index.js +0 -1
  91. package/lib/WABinary/jid-utils.js +68 -77
  92. package/lib/WABinary/types.js +0 -1
  93. package/lib/WAM/BinaryInfo.js +7 -8
  94. package/lib/WAM/constants.js +19892 -22853
  95. package/lib/WAM/encode.js +121 -132
  96. package/lib/WAM/index.js +0 -1
  97. package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
  98. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
  99. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
  101. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
  102. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
  103. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
  104. package/lib/WAUSync/Protocols/index.js +0 -1
  105. package/lib/WAUSync/USyncQuery.js +79 -88
  106. package/lib/WAUSync/USyncUser.js +28 -29
  107. package/lib/WAUSync/index.js +0 -1
  108. package/lib/index.js +2 -2
  109. package/package.json +22 -86
  110. package/WAProto/GenerateStatics.sh +0 -3
  111. package/WAProto/fix-imports.js +0 -85
  112. package/WAProto/index.d.ts +0 -14017
  113. package/lib/Defaults/index.d.ts +0 -75
  114. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  115. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  116. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  117. package/lib/Signal/Group/index.d.ts +0 -12
  118. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  119. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  120. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  121. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  122. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  123. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  124. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  125. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  126. package/lib/Signal/libsignal.d.ts +0 -5
  127. package/lib/Signal/lid-mapping.d.ts +0 -23
  128. package/lib/Socket/Client/index.d.ts +0 -3
  129. package/lib/Socket/Client/types.d.ts +0 -16
  130. package/lib/Socket/Client/websocket.d.ts +0 -13
  131. package/lib/Socket/business.d.ts +0 -217
  132. package/lib/Socket/chats.d.ts +0 -125
  133. package/lib/Socket/communities.d.ts +0 -273
  134. package/lib/Socket/groups.d.ts +0 -161
  135. package/lib/Socket/index.d.ts +0 -260
  136. package/lib/Socket/messages-recv.d.ts +0 -203
  137. package/lib/Socket/messages-send.d.ts +0 -199
  138. package/lib/Socket/mex.d.ts +0 -3
  139. package/lib/Socket/newsletter.d.ts +0 -170
  140. package/lib/Socket/socket.d.ts +0 -59
  141. package/lib/Types/Auth.d.ts +0 -117
  142. package/lib/Types/Bussines.d.ts +0 -25
  143. package/lib/Types/Call.d.ts +0 -15
  144. package/lib/Types/Chat.d.ts +0 -124
  145. package/lib/Types/Contact.d.ts +0 -26
  146. package/lib/Types/Events.d.ts +0 -256
  147. package/lib/Types/GroupMetadata.d.ts +0 -71
  148. package/lib/Types/Label.d.ts +0 -47
  149. package/lib/Types/LabelAssociation.d.ts +0 -30
  150. package/lib/Types/Message.d.ts +0 -320
  151. package/lib/Types/Mex.d.ts +0 -141
  152. package/lib/Types/Product.d.ts +0 -79
  153. package/lib/Types/Signal.d.ts +0 -87
  154. package/lib/Types/Socket.d.ts +0 -136
  155. package/lib/Types/State.d.ts +0 -97
  156. package/lib/Types/USync.d.ts +0 -26
  157. package/lib/Types/index.d.ts +0 -66
  158. package/lib/Utils/auth-utils.d.ts +0 -24
  159. package/lib/Utils/browser-utils.d.ts +0 -4
  160. package/lib/Utils/business.d.ts +0 -23
  161. package/lib/Utils/chat-utils.d.ts +0 -100
  162. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  163. package/lib/Utils/crypto.d.ts +0 -37
  164. package/lib/Utils/decode-wa-message.d.ts +0 -66
  165. package/lib/Utils/event-buffer.d.ts +0 -36
  166. package/lib/Utils/generics.d.ts +0 -92
  167. package/lib/Utils/history.d.ts +0 -24
  168. package/lib/Utils/identity-change-handler.d.ts +0 -44
  169. package/lib/Utils/identity-change-handler.js +0 -50
  170. package/lib/Utils/index.d.ts +0 -22
  171. package/lib/Utils/link-preview.d.ts +0 -21
  172. package/lib/Utils/logger.d.ts +0 -12
  173. package/lib/Utils/lt-hash.d.ts +0 -8
  174. package/lib/Utils/make-mutex.d.ts +0 -9
  175. package/lib/Utils/message-retry-manager.d.ts +0 -115
  176. package/lib/Utils/messages-media.d.ts +0 -133
  177. package/lib/Utils/messages.d.ts +0 -91
  178. package/lib/Utils/noise-handler.d.ts +0 -20
  179. package/lib/Utils/offline-node-processor.d.ts +0 -17
  180. package/lib/Utils/offline-node-processor.js +0 -40
  181. package/lib/Utils/pre-key-manager.d.ts +0 -28
  182. package/lib/Utils/process-message.d.ts +0 -60
  183. package/lib/Utils/reporting-utils.d.ts +0 -11
  184. package/lib/Utils/signal.d.ts +0 -47
  185. package/lib/Utils/stanza-ack.d.ts +0 -11
  186. package/lib/Utils/sync-action-utils.d.ts +0 -19
  187. package/lib/Utils/tc-token-utils.d.ts +0 -37
  188. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  189. package/lib/Utils/validate-connection.d.ts +0 -11
  190. package/lib/WABinary/constants.d.ts +0 -28
  191. package/lib/WABinary/decode.d.ts +0 -7
  192. package/lib/WABinary/encode.d.ts +0 -3
  193. package/lib/WABinary/generic-utils.d.ts +0 -15
  194. package/lib/WABinary/index.d.ts +0 -6
  195. package/lib/WABinary/jid-utils.d.ts +0 -48
  196. package/lib/WABinary/types.d.ts +0 -19
  197. package/lib/WAM/BinaryInfo.d.ts +0 -9
  198. package/lib/WAM/constants.d.ts +0 -40
  199. package/lib/WAM/encode.d.ts +0 -3
  200. package/lib/WAM/index.d.ts +0 -4
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  204. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  205. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  206. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  208. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  209. package/lib/WAUSync/USyncQuery.d.ts +0 -30
  210. package/lib/WAUSync/USyncUser.d.ts +0 -17
  211. package/lib/WAUSync/index.d.ts +0 -4
  212. package/lib/index.d.ts +0 -12
@@ -1,258 +1,577 @@
1
1
  import { createHmac } from 'crypto';
2
- import { proto } from '../../WAProto/index.js';
2
+ import { proto } from '../../WAProto/compiler.js';
3
3
  import { hkdf } from './crypto.js';
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;
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;
69
377
  };
70
378
  const compiledReportingFields = compileReportingFields(reportingFields);
71
379
  const EMPTY_MAP = new Map();
72
380
  const ENC_SECRET_REPORT_TOKEN = 'Report Token';
73
381
  const WIRE = {
74
- VARINT: 0,
75
- FIXED64: 1,
76
- BYTES: 2,
77
- FIXED32: 5
382
+ VARINT: 0,
383
+ FIXED64: 1,
384
+ BYTES: 2,
385
+ FIXED32: 5
78
386
  };
79
- export const shouldIncludeReportingToken = (message) => !message.reactionMessage &&
80
- !message.encReactionMessage &&
81
- !message.encEventResponseMessage &&
82
- !message.pollUpdateMessage;
387
+ export const shouldIncludeReportingToken = message => !message.reactionMessage && !message.encReactionMessage && !message.encEventResponseMessage && !message.pollUpdateMessage;
83
388
  const generateMsgSecretKey = (modificationType, origMsgId, origMsgSender, modificationSender, origMsgSecret) => {
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') });
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
+ });
91
393
  };
92
394
  const extractReportingTokenContent = (data, cfg) => {
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;
99
- }
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;
136
- }
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;
149
- }
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;
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;
162
434
  }
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;
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;
196
447
  }
448
+ continue;
449
+ }
450
+ if (!pushSlice(end)) {
197
451
  return null;
452
+ }
453
+ continue;
198
454
  }
199
- if (out.length === 0) {
200
- return Buffer.alloc(0);
455
+ if (wireType === WIRE.FIXED32) {
456
+ const end = i + 4;
457
+ if (!fieldCfg) {
458
+ if (!skip(end)) {
459
+ return null;
460
+ }
461
+ continue;
462
+ }
463
+ if (!pushSlice(end)) {
464
+ return null;
465
+ }
466
+ continue;
201
467
  }
202
- out.sort((a, b) => a.num - b.num);
203
- return Buffer.concat(out.map(f => f.bytes));
204
- };
205
- const decodeVarint = (buffer, offset) => {
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 };
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;
215
486
  }
216
- shift += 7;
217
- if (shift > 35) {
218
- return { value: 0, bytes: 0, ok: false };
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
+ });
219
494
  }
495
+ i = valEnd;
496
+ continue;
497
+ }
498
+ out.push({
499
+ num: fieldNum,
500
+ bytes: data.subarray(fieldStart, valEnd)
501
+ });
502
+ i = valEnd;
503
+ continue;
220
504
  }
221
- return { value: 0, bytes: 0, ok: false };
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));
222
512
  };
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;
513
+ 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
+ };
229
535
  }
230
- parts.push(remaining);
231
- return Buffer.from(parts);
536
+ }
537
+ return {
538
+ value: 0,
539
+ bytes: 0,
540
+ ok: false
541
+ };
542
+ };
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);
232
552
  };
233
553
  export const getMessageReportingToken = async (msgProtobuf, message, key) => {
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
- };
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
+ };
257
577
  };
258
- //# sourceMappingURL=reporting-utils.js.map