@x4r1s3/baileys 0.0.0-stage → 1.0.0

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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1262 -2
  3. package/SECURITY.md +47 -0
  4. package/WAProto/V +1 -0
  5. package/WAProto/WAProto.proto +8892 -0
  6. package/WAProto/index.d.ts +104128 -0
  7. package/WAProto/index.js +334920 -0
  8. package/assets/rolling-circle.svg +133 -0
  9. package/assets/x4r1s3-banner.svg +32 -0
  10. package/engine-requirements.js +27 -0
  11. package/lib/Builders/A2UI.js +245 -0
  12. package/lib/Builders/AIRich.js +179 -0
  13. package/lib/Builders/Button.js +108 -0
  14. package/lib/Builders/CFC.js +284 -0
  15. package/lib/Builders/Carousel.js +81 -0
  16. package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
  17. package/lib/Call/audio-feeder.mjs +179 -0
  18. package/lib/Call/audio-recorder.mjs +250 -0
  19. package/lib/Call/fetch-wasm-resources.mjs +104 -0
  20. package/lib/Call/index.mjs +680 -0
  21. package/lib/Call/relay-transport.mjs +563 -0
  22. package/lib/Call/signaling.mjs +641 -0
  23. package/lib/Call/types.mjs +17 -0
  24. package/lib/Call/video-feeder.mjs +94 -0
  25. package/lib/Call/wasm-engine.mjs +1372 -0
  26. package/lib/Call/worker-bootstrap.mjs +1042 -0
  27. package/lib/Defaults/ban-checker.js +56 -0
  28. package/lib/Defaults/index.js +170 -0
  29. package/lib/Signal/Group/ciphertext-message.js +23 -0
  30. package/lib/Signal/Group/group-session-builder.js +41 -0
  31. package/lib/Signal/Group/group_cipher.js +93 -0
  32. package/lib/Signal/Group/index.js +23 -0
  33. package/lib/Signal/Group/keyhelper.js +29 -0
  34. package/lib/Signal/Group/sender-chain-key.js +37 -0
  35. package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
  36. package/lib/Signal/Group/sender-key-message.js +77 -0
  37. package/lib/Signal/Group/sender-key-name.js +59 -0
  38. package/lib/Signal/Group/sender-key-record.js +52 -0
  39. package/lib/Signal/Group/sender-key-state.js +95 -0
  40. package/lib/Signal/Group/sender-message-key.js +37 -0
  41. package/lib/Signal/libsignal.js +440 -0
  42. package/lib/Signal/lid-mapping.js +292 -0
  43. package/lib/Socket/Client/index.js +14 -0
  44. package/lib/Socket/Client/types.js +22 -0
  45. package/lib/Socket/Client/websocket.js +65 -0
  46. package/lib/Socket/aigroups.js +327 -0
  47. package/lib/Socket/ban-checker.js +165 -0
  48. package/lib/Socket/business.js +419 -0
  49. package/lib/Socket/chats.js +1921 -0
  50. package/lib/Socket/communities.js +443 -0
  51. package/lib/Socket/graphql.js +911 -0
  52. package/lib/Socket/groups.js +561 -0
  53. package/lib/Socket/index.js +49 -0
  54. package/lib/Socket/interactive-handler.js +612 -0
  55. package/lib/Socket/interop.js +575 -0
  56. package/lib/Socket/managed-account.js +220 -0
  57. package/lib/Socket/messages-recv.js +2191 -0
  58. package/lib/Socket/messages-send.js +4104 -0
  59. package/lib/Socket/mex.js +53 -0
  60. package/lib/Socket/newsletter.js +291 -0
  61. package/lib/Socket/privacy.js +458 -0
  62. package/lib/Socket/registration.js +440 -0
  63. package/lib/Socket/socket.js +1029 -0
  64. package/lib/Socket/status-actions.js +287 -0
  65. package/lib/Socket/username.js +241 -0
  66. package/lib/Store/index.js +16 -0
  67. package/lib/Store/make-cache-manager-store.js +101 -0
  68. package/lib/Store/make-in-memory-store.js +432 -0
  69. package/lib/Store/make-ordered-dictionary.js +90 -0
  70. package/lib/Store/object-repository.js +35 -0
  71. package/lib/Types/Auth.js +13 -0
  72. package/lib/Types/Bussines.js +13 -0
  73. package/lib/Types/Call.js +13 -0
  74. package/lib/Types/Chat.js +19 -0
  75. package/lib/Types/Contact.js +13 -0
  76. package/lib/Types/Events.js +13 -0
  77. package/lib/Types/GroupMetadata.js +13 -0
  78. package/lib/Types/Label.js +36 -0
  79. package/lib/Types/LabelAssociation.js +18 -0
  80. package/lib/Types/Message.js +30 -0
  81. package/lib/Types/Mex.js +53 -0
  82. package/lib/Types/Product.js +13 -0
  83. package/lib/Types/RichType.js +34 -0
  84. package/lib/Types/Signal.js +13 -0
  85. package/lib/Types/Socket.js +14 -0
  86. package/lib/Types/State.js +60 -0
  87. package/lib/Types/USync.js +13 -0
  88. package/lib/Types/index.js +37 -0
  89. package/lib/Utils/auth-utils.js +313 -0
  90. package/lib/Utils/ban-checker.js +48 -0
  91. package/lib/Utils/bot-capabilities.js +96 -0
  92. package/lib/Utils/bot-planning-replay.js +177 -0
  93. package/lib/Utils/browser-utils.js +40 -0
  94. package/lib/Utils/business.js +242 -0
  95. package/lib/Utils/c2582.js +147 -0
  96. package/lib/Utils/chat-utils.js +905 -0
  97. package/lib/Utils/companion-reg-client-utils.js +44 -0
  98. package/lib/Utils/consumer-application.js +114 -0
  99. package/lib/Utils/crypto.js +129 -0
  100. package/lib/Utils/decode-wa-message.js +496 -0
  101. package/lib/Utils/direct-chat-theme.js +164 -0
  102. package/lib/Utils/event-buffer.js +601 -0
  103. package/lib/Utils/experimental-proto.js +206 -0
  104. package/lib/Utils/games/miniapp.js +17 -0
  105. package/lib/Utils/games/slot-machine.js +270 -0
  106. package/lib/Utils/games/website-preview.js +306 -0
  107. package/lib/Utils/generics.js +402 -0
  108. package/lib/Utils/group-history.js +68 -0
  109. package/lib/Utils/group-wallpaper.js +168 -0
  110. package/lib/Utils/history.js +162 -0
  111. package/lib/Utils/identity-change-handler.js +60 -0
  112. package/lib/Utils/index.js +61 -0
  113. package/lib/Utils/jid-display-normalization.js +221 -0
  114. package/lib/Utils/link-preview.js +96 -0
  115. package/lib/Utils/logger.js +14 -0
  116. package/lib/Utils/lt-hash.js +19 -0
  117. package/lib/Utils/make-mutex.js +44 -0
  118. package/lib/Utils/message-composer.js +709 -0
  119. package/lib/Utils/message-inspect.js +79 -0
  120. package/lib/Utils/message-retry-manager.js +253 -0
  121. package/lib/Utils/message-security.js +167 -0
  122. package/lib/Utils/messages-media.js +1027 -0
  123. package/lib/Utils/messages.js +2467 -0
  124. package/lib/Utils/meta-ai-msmsg.js +215 -0
  125. package/lib/Utils/meta-compositing.js +239 -0
  126. package/lib/Utils/native-flow.js +158 -0
  127. package/lib/Utils/newsletter-live-update-utils.js +74 -0
  128. package/lib/Utils/newsletter-status-utils.js +152 -0
  129. package/lib/Utils/noise-handler.js +212 -0
  130. package/lib/Utils/offline-node-processor.js +51 -0
  131. package/lib/Utils/poll-manager.js +206 -0
  132. package/lib/Utils/portable-compat.js +12 -0
  133. package/lib/Utils/pre-key-manager.js +117 -0
  134. package/lib/Utils/process-message.js +610 -0
  135. package/lib/Utils/reporting-utils.js +269 -0
  136. package/lib/Utils/rich-message-utils.js +2841 -0
  137. package/lib/Utils/scheduled-message.js +107 -0
  138. package/lib/Utils/signal.js +212 -0
  139. package/lib/Utils/source-grep.js +57 -0
  140. package/lib/Utils/stanza-ack.js +49 -0
  141. package/lib/Utils/sticker-annotation.js +87 -0
  142. package/lib/Utils/sync-action-utils.js +59 -0
  143. package/lib/Utils/tc-token-utils.js +174 -0
  144. package/lib/Utils/use-multi-file-auth-state.js +132 -0
  145. package/lib/Utils/use-single-file-auth-state.js +108 -0
  146. package/lib/Utils/use-sqlite-auth-state.js +120 -0
  147. package/lib/Utils/validate-connection.js +220 -0
  148. package/lib/Utils/view-once-utils.js +218 -0
  149. package/lib/Utils/voip-rekey.js +32 -0
  150. package/lib/Utils/website-preview.js +27 -0
  151. package/lib/Utils/welcome-flow.js +228 -0
  152. package/lib/Utils/x4r1s3.js +144 -0
  153. package/lib/WABinary/constants.js +1475 -0
  154. package/lib/WABinary/decode.js +273 -0
  155. package/lib/WABinary/encode.js +231 -0
  156. package/lib/WABinary/generic-utils.js +242 -0
  157. package/lib/WABinary/index.js +17 -0
  158. package/lib/WABinary/jid-utils.js +107 -0
  159. package/lib/WABinary/types.js +13 -0
  160. package/lib/WAM/BinaryInfo.js +21 -0
  161. package/lib/WAM/constants.js +22864 -0
  162. package/lib/WAM/encode.js +161 -0
  163. package/lib/WAM/index.js +15 -0
  164. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
  165. package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
  166. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
  167. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
  168. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
  169. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
  170. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
  171. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
  172. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
  173. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
  174. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
  175. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
  176. package/lib/WAUSync/Protocols/index.js +24 -0
  177. package/lib/WAUSync/USyncQuery.js +213 -0
  178. package/lib/WAUSync/USyncUser.js +66 -0
  179. package/lib/WAUSync/index.js +15 -0
  180. package/lib/antiban.cjs +4726 -0
  181. package/lib/index.d.ts +1285 -0
  182. package/lib/index.js +30 -0
  183. package/package.json +125 -4
@@ -0,0 +1,269 @@
1
+ /**
2
+ * @X4R1S3
3
+ *
4
+ * File: lib/Utils/reporting-utils.js
5
+ * About: Reporting utils module for the X4R1S3 WhatsApp protocol client.
6
+ * Important exports: shouldIncludeReportingToken, getMessageReportingToken
7
+ * Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
8
+ *
9
+ * Copyright and attribution notice.
10
+ * Do not copy, reproduce, redistribute, modify, or create derivative works
11
+ * from this source without explicit written permission.
12
+ */
13
+ import { createHmac } from 'crypto';
14
+ import { proto } from '../../WAProto/index.js';
15
+ import { hkdf } from './crypto.js';
16
+ const reportingFields = [
17
+ { f: 1 },
18
+ {
19
+ f: 3,
20
+ s: [{ f: 2 }, { f: 3 }, { f: 8 }, { f: 11 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 25 }]
21
+ },
22
+ { f: 4, s: [{ f: 1 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
23
+ { f: 5, s: [{ f: 3 }, { f: 4 }, { f: 5 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
24
+ { f: 6, s: [{ f: 1 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 30 }] },
25
+ { f: 7, s: [{ f: 2 }, { f: 7 }, { f: 10 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
26
+ { f: 8, s: [{ f: 2 }, { f: 7 }, { f: 9 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 21 }] },
27
+ { f: 9, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
28
+ { f: 12, s: [{ f: 1 }, { f: 2 }, { f: 14, m: true }, { f: 15 }] },
29
+ { f: 18, s: [{ f: 6 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
30
+ { f: 26, s: [{ f: 4 }, { f: 5 }, { f: 8 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
31
+ { f: 28, s: [{ f: 1 }, { f: 2 }, { f: 4 }, { f: 5 }, { f: 6 }, { f: 7, s: [{ f: 21 }, { f: 22 }] }] },
32
+ { f: 37, s: [{ f: 1, m: true }] },
33
+ {
34
+ f: 49,
35
+ s: [
36
+ { f: 2 },
37
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
38
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
39
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
40
+ ]
41
+ },
42
+ { f: 53, s: [{ f: 1, m: true }] },
43
+ { f: 55, s: [{ f: 1, m: true }] },
44
+ { f: 58, s: [{ f: 1, m: true }] },
45
+ { f: 59, s: [{ f: 1, m: true }] },
46
+ {
47
+ f: 60,
48
+ s: [
49
+ { f: 2 },
50
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
51
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
52
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
53
+ ]
54
+ },
55
+ {
56
+ f: 64,
57
+ s: [
58
+ { f: 2 },
59
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
60
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
61
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
62
+ ]
63
+ },
64
+ { f: 66, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
65
+ { f: 74, s: [{ f: 1, m: true }] },
66
+ { f: 87, s: [{ f: 1, m: true }] },
67
+ { f: 88, s: [{ f: 1 }, { f: 2, s: [{ f: 1 }] }, { f: 3, s: [{ f: 21 }, { f: 22 }] }] },
68
+ { f: 92, s: [{ f: 1, m: true }] },
69
+ { f: 93, s: [{ f: 1, m: true }] },
70
+ { f: 94, s: [{ f: 1, m: true }] }
71
+ ];
72
+ const compileReportingFields = (fields) => {
73
+ const map = new Map();
74
+ for (const f of fields) {
75
+ map.set(f.f, {
76
+ m: f.m,
77
+ children: f.s ? compileReportingFields(f.s) : undefined
78
+ });
79
+ }
80
+ return map;
81
+ };
82
+ const compiledReportingFields = compileReportingFields(reportingFields);
83
+ const EMPTY_MAP = new Map();
84
+ const ENC_SECRET_REPORT_TOKEN = 'Report Token';
85
+ const WIRE = {
86
+ VARINT: 0,
87
+ FIXED64: 1,
88
+ BYTES: 2,
89
+ FIXED32: 5
90
+ };
91
+ export const shouldIncludeReportingToken = (message) => !message.reactionMessage &&
92
+ !message.encReactionMessage &&
93
+ !message.encEventResponseMessage &&
94
+ !message.pollUpdateMessage;
95
+ const generateMsgSecretKey = (modificationType, origMsgId, origMsgSender, modificationSender, origMsgSecret) => {
96
+ const useCaseSecret = Buffer.concat([
97
+ Buffer.from(origMsgId, 'utf8'),
98
+ Buffer.from(origMsgSender, 'utf8'),
99
+ Buffer.from(modificationSender, 'utf8'),
100
+ Buffer.from(modificationType, 'utf8')
101
+ ]);
102
+ return hkdf(origMsgSecret, 32, { info: useCaseSecret.toString('latin1') });
103
+ };
104
+ const extractReportingTokenContent = (data, cfg) => {
105
+ const out = [];
106
+ let i = 0;
107
+ while (i < data.length) {
108
+ const tag = decodeVarint(data, i);
109
+ if (!tag.ok) {
110
+ return null;
111
+ }
112
+ const fieldNum = tag.value >> 3;
113
+ const wireType = tag.value & 0x7;
114
+ const fieldStart = i;
115
+ i += tag.bytes;
116
+ const fieldCfg = cfg.get(fieldNum);
117
+ const pushSlice = (end) => {
118
+ if (end > data.length) {
119
+ return false;
120
+ }
121
+ out.push({ num: fieldNum, bytes: data.subarray(fieldStart, end) });
122
+ i = end;
123
+ return true;
124
+ };
125
+ const skip = (end) => {
126
+ if (end > data.length) {
127
+ return false;
128
+ }
129
+ i = end;
130
+ return true;
131
+ };
132
+ if (wireType === WIRE.VARINT) {
133
+ const v = decodeVarint(data, i);
134
+ if (!v.ok) {
135
+ return null;
136
+ }
137
+ const end = i + v.bytes;
138
+ if (!fieldCfg) {
139
+ if (!skip(end)) {
140
+ return null;
141
+ }
142
+ continue;
143
+ }
144
+ if (!pushSlice(end)) {
145
+ return null;
146
+ }
147
+ continue;
148
+ }
149
+ if (wireType === WIRE.FIXED64) {
150
+ const end = i + 8;
151
+ if (!fieldCfg) {
152
+ if (!skip(end)) {
153
+ return null;
154
+ }
155
+ continue;
156
+ }
157
+ if (!pushSlice(end)) {
158
+ return null;
159
+ }
160
+ continue;
161
+ }
162
+ if (wireType === WIRE.FIXED32) {
163
+ const end = i + 4;
164
+ if (!fieldCfg) {
165
+ if (!skip(end)) {
166
+ return null;
167
+ }
168
+ continue;
169
+ }
170
+ if (!pushSlice(end)) {
171
+ return null;
172
+ }
173
+ continue;
174
+ }
175
+ if (wireType === WIRE.BYTES) {
176
+ const len = decodeVarint(data, i);
177
+ if (!len.ok) {
178
+ return null;
179
+ }
180
+ const valStart = i + len.bytes;
181
+ const valEnd = valStart + len.value;
182
+ if (valEnd > data.length) {
183
+ return null;
184
+ }
185
+ if (!fieldCfg) {
186
+ i = valEnd;
187
+ continue;
188
+ }
189
+ if (fieldCfg.m || fieldCfg.children) {
190
+ const sub = extractReportingTokenContent(data.subarray(valStart, valEnd), fieldCfg.children ?? EMPTY_MAP);
191
+ if (sub === null) {
192
+ return null;
193
+ }
194
+ if (sub.length > 0) {
195
+ const newTag = encodeVarint(tag.value);
196
+ const newLen = encodeVarint(sub.length);
197
+ out.push({
198
+ num: fieldNum,
199
+ bytes: Buffer.concat([newTag, newLen, sub])
200
+ });
201
+ }
202
+ i = valEnd;
203
+ continue;
204
+ }
205
+ out.push({ num: fieldNum, bytes: data.subarray(fieldStart, valEnd) });
206
+ i = valEnd;
207
+ continue;
208
+ }
209
+ return null;
210
+ }
211
+ if (out.length === 0) {
212
+ return Buffer.alloc(0);
213
+ }
214
+ out.sort((a, b) => a.num - b.num);
215
+ return Buffer.concat(out.map(f => f.bytes));
216
+ };
217
+ const decodeVarint = (buffer, offset) => {
218
+ let value = 0;
219
+ let bytes = 0;
220
+ let shift = 0;
221
+ while (offset + bytes < buffer.length) {
222
+ const current = buffer[offset + bytes];
223
+ value |= (current & 0x7f) << shift;
224
+ bytes++;
225
+ if ((current & 0x80) === 0) {
226
+ return { value, bytes, ok: true };
227
+ }
228
+ shift += 7;
229
+ if (shift > 35) {
230
+ return { value: 0, bytes: 0, ok: false };
231
+ }
232
+ }
233
+ return { value: 0, bytes: 0, ok: false };
234
+ };
235
+ const encodeVarint = (value) => {
236
+ const parts = [];
237
+ let remaining = value >>> 0;
238
+ while (remaining > 0x7f) {
239
+ parts.push((remaining & 0x7f) | 0x80);
240
+ remaining >>>= 7;
241
+ }
242
+ parts.push(remaining);
243
+ return Buffer.from(parts);
244
+ };
245
+ export const getMessageReportingToken = async (msgProtobuf, message, key) => {
246
+ const msgSecret = message.messageContextInfo?.messageSecret;
247
+ if (!msgSecret || !key.id) {
248
+ return null;
249
+ }
250
+ const from = key.fromMe ? key.remoteJid : key.participant || key.remoteJid;
251
+ const to = key.fromMe ? key.participant || key.remoteJid : key.remoteJid;
252
+ const reportingSecret = generateMsgSecretKey(ENC_SECRET_REPORT_TOKEN, key.id, from, to, msgSecret);
253
+ const content = extractReportingTokenContent(msgProtobuf, compiledReportingFields);
254
+ if (!content || content.length === 0) {
255
+ return null;
256
+ }
257
+ const reportingToken = createHmac('sha256', reportingSecret).update(content).digest().subarray(0, 16);
258
+ return {
259
+ tag: 'reporting',
260
+ attrs: {},
261
+ content: [
262
+ {
263
+ tag: 'reporting_token',
264
+ attrs: { v: '2' },
265
+ content: reportingToken
266
+ }
267
+ ]
268
+ };
269
+ };