@codexverified/baileys 2.7.5

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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -0
  3. package/WAProto/V +1 -0
  4. package/WAProto/WAProto.proto +8051 -0
  5. package/WAProto/index.js +289292 -0
  6. package/engine-requirements.js +13 -0
  7. package/lib/Defaults/index.js +158 -0
  8. package/lib/Signal/Group/ciphertext-message.js +11 -0
  9. package/lib/Signal/Group/group-session-builder.js +29 -0
  10. package/lib/Signal/Group/group_cipher.js +81 -0
  11. package/lib/Signal/Group/index.js +11 -0
  12. package/lib/Signal/Group/keyhelper.js +17 -0
  13. package/lib/Signal/Group/sender-chain-key.js +25 -0
  14. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  15. package/lib/Signal/Group/sender-key-message.js +65 -0
  16. package/lib/Signal/Group/sender-key-name.js +47 -0
  17. package/lib/Signal/Group/sender-key-record.js +40 -0
  18. package/lib/Signal/Group/sender-key-state.js +83 -0
  19. package/lib/Signal/Group/sender-message-key.js +25 -0
  20. package/lib/Signal/libsignal.js +428 -0
  21. package/lib/Signal/lid-mapping.js +280 -0
  22. package/lib/Socket/Client/index.js +2 -0
  23. package/lib/Socket/Client/types.js +10 -0
  24. package/lib/Socket/Client/websocket.js +53 -0
  25. package/lib/Socket/aigroups.js +315 -0
  26. package/lib/Socket/business.js +407 -0
  27. package/lib/Socket/chats.js +1831 -0
  28. package/lib/Socket/communities.js +431 -0
  29. package/lib/Socket/graphql.js +899 -0
  30. package/lib/Socket/groups.js +549 -0
  31. package/lib/Socket/index.js +79 -0
  32. package/lib/Socket/interactive-handler.js +600 -0
  33. package/lib/Socket/interop.js +563 -0
  34. package/lib/Socket/managed-account.js +208 -0
  35. package/lib/Socket/messages-recv.js +2144 -0
  36. package/lib/Socket/messages-send.js +2030 -0
  37. package/lib/Socket/mex.js +41 -0
  38. package/lib/Socket/newsletter.js +226 -0
  39. package/lib/Socket/privacy.js +446 -0
  40. package/lib/Socket/registration.js +428 -0
  41. package/lib/Socket/socket.js +1017 -0
  42. package/lib/Socket/username.js +229 -0
  43. package/lib/Store/index.js +4 -0
  44. package/lib/Store/make-cache-manager-store.js +89 -0
  45. package/lib/Store/make-in-memory-store.js +420 -0
  46. package/lib/Store/make-ordered-dictionary.js +78 -0
  47. package/lib/Store/object-repository.js +23 -0
  48. package/lib/Types/Auth.js +1 -0
  49. package/lib/Types/Bussines.js +1 -0
  50. package/lib/Types/Call.js +1 -0
  51. package/lib/Types/Chat.js +7 -0
  52. package/lib/Types/Contact.js +1 -0
  53. package/lib/Types/Events.js +1 -0
  54. package/lib/Types/GroupMetadata.js +1 -0
  55. package/lib/Types/Label.js +24 -0
  56. package/lib/Types/LabelAssociation.js +6 -0
  57. package/lib/Types/Message.js +17 -0
  58. package/lib/Types/Mex.js +39 -0
  59. package/lib/Types/Product.js +1 -0
  60. package/lib/Types/RichType.js +22 -0
  61. package/lib/Types/Signal.js +1 -0
  62. package/lib/Types/Socket.js +2 -0
  63. package/lib/Types/State.js +48 -0
  64. package/lib/Types/USync.js +1 -0
  65. package/lib/Types/index.js +25 -0
  66. package/lib/Utils/auth-utils.js +301 -0
  67. package/lib/Utils/bot-planning-replay.js +169 -0
  68. package/lib/Utils/browser-utils.js +28 -0
  69. package/lib/Utils/business.js +230 -0
  70. package/lib/Utils/chat-utils.js +885 -0
  71. package/lib/Utils/companion-reg-client-utils.js +32 -0
  72. package/lib/Utils/consumer-application.js +102 -0
  73. package/lib/Utils/crypto.js +117 -0
  74. package/lib/Utils/decode-wa-message.js +484 -0
  75. package/lib/Utils/event-buffer.js +589 -0
  76. package/lib/Utils/generics.js +388 -0
  77. package/lib/Utils/group-history.js +56 -0
  78. package/lib/Utils/history.js +130 -0
  79. package/lib/Utils/identity-change-handler.js +48 -0
  80. package/lib/Utils/index.js +34 -0
  81. package/lib/Utils/jid-display-normalization.js +209 -0
  82. package/lib/Utils/link-preview.js +84 -0
  83. package/lib/Utils/logger.js +2 -0
  84. package/lib/Utils/lt-hash.js +7 -0
  85. package/lib/Utils/make-mutex.js +32 -0
  86. package/lib/Utils/message-composer.js +467 -0
  87. package/lib/Utils/message-inspect.js +67 -0
  88. package/lib/Utils/message-retry-manager.js +241 -0
  89. package/lib/Utils/messages-media.js +1006 -0
  90. package/lib/Utils/messages.js +1851 -0
  91. package/lib/Utils/meta-ai-msmsg.js +130 -0
  92. package/lib/Utils/meta-compositing.js +194 -0
  93. package/lib/Utils/noise-handler.js +200 -0
  94. package/lib/Utils/offline-node-processor.js +39 -0
  95. package/lib/Utils/pre-key-manager.js +105 -0
  96. package/lib/Utils/process-message.js +527 -0
  97. package/lib/Utils/reporting-utils.js +257 -0
  98. package/lib/Utils/rich-message-utils.js +439 -0
  99. package/lib/Utils/signal.js +200 -0
  100. package/lib/Utils/stanza-ack.js +37 -0
  101. package/lib/Utils/sync-action-utils.js +47 -0
  102. package/lib/Utils/tc-token-utils.js +162 -0
  103. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  104. package/lib/Utils/use-single-file-auth-state.js +96 -0
  105. package/lib/Utils/use-sqlite-auth-state.js +108 -0
  106. package/lib/Utils/validate-connection.js +206 -0
  107. package/lib/Utils/voip-rekey.js +20 -0
  108. package/lib/Utils/welcome-flow.js +217 -0
  109. package/lib/WABinary/constants.js +1463 -0
  110. package/lib/WABinary/decode.js +261 -0
  111. package/lib/WABinary/encode.js +219 -0
  112. package/lib/WABinary/generic-utils.js +227 -0
  113. package/lib/WABinary/index.js +5 -0
  114. package/lib/WABinary/jid-utils.js +95 -0
  115. package/lib/WABinary/types.js +1 -0
  116. package/lib/WAM/BinaryInfo.js +9 -0
  117. package/lib/WAM/constants.js +22852 -0
  118. package/lib/WAM/encode.js +149 -0
  119. package/lib/WAM/index.js +3 -0
  120. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +96 -0
  121. package/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
  122. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  123. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  124. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
  125. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  126. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
  127. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  128. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
  129. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  130. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  131. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  132. package/lib/WAUSync/Protocols/index.js +12 -0
  133. package/lib/WAUSync/USyncQuery.js +201 -0
  134. package/lib/WAUSync/USyncUser.js +54 -0
  135. package/lib/WAUSync/index.js +3 -0
  136. package/lib/antiban.cjs +4726 -0
  137. package/lib/index.d.ts +286 -0
  138. package/lib/index.js +18 -0
  139. package/package.json +121 -0
@@ -0,0 +1,446 @@
1
+ import { executeWMexQuery } from './mex.js';
2
+
3
+ /**
4
+ * MEX query IDs for privacy, status/profile, account/auth, and misc operations.
5
+ * Source: assets/whatsapp-android-mex_client_persist_ids.json
6
+ */
7
+ const PRIVACY_MEX_IDS = {
8
+ // Privacy settings
9
+ GET_SETTINGS: '32774292262215379', // GetPrivacySettingsQuery
10
+ SET_SETTING: '26887749497493182', // SetPrivacySettingMutation
11
+ UPDATE_CONTACT_LIST: '26375158178762799', // UpdatePrivacyContactListMutation
12
+ GET_CONTACT_LIST: '25700444246275822', // GetPrivacyContactListQuery
13
+ // Status / profile
14
+ UPDATE_TEXT_STATUS: '25863197129975892', // UpdateTextStatus
15
+ GET_TEXT_STATUS_LIST: '25741205615468935', // GetTextStatusList
16
+ UPDATE_USER_STATUS: '7452341274886724', // UpdateUserStatus
17
+ FETCH_USER_PICTURE: '24983561624604407', // FetchUserPictureInfo
18
+ PROFILE_PICTURE_MUTATION: '24714239711610700', // ProfilePictureMutation
19
+ // Account / auth
20
+ ACCOUNT_LOGIN: '27298465499757127', // AccountLoginMutation
21
+ ACCOUNT_LOGOUT: '26863447609979194', // AccountLogoutMutation
22
+ MULTI_ACCOUNT_REVOKE: '25846242091639661', // MultiAccountRevokeAccount
23
+ ADD_MULTI_ACCOUNT_LINK: '25502812266025193', // AddMultiAccountLink
24
+ ADD_TRUSTED_DEVICE: '24522952587403287', // AddTrustedDeviceMutation
25
+ GET_TRUSTED_DEVICES: '27391232653862770', // GetTrustedDevicesQuery
26
+ UNTRUST_TRUSTED_DEVICE: '26574930682133620', // UntrustTrustedDeviceMutation
27
+ DELETE_TRUSTED_DEVICE: '33867503889559538', // DeleteTrustedDeviceMutation
28
+ // Misc
29
+ MOBILE_CONFIG_FETCH: '25676911271914597', // MobileConfigFetchQuery
30
+ NOTIFY_PUSH_NAME: '25900490552974543', // NotifyPushName
31
+ CONTACT_INTEGRITY: '25924358997169495', // ContactIntegrityQuery
32
+ BIZ_INTEGRITY: '25975613018777537', // BizIntegrityQuery
33
+ LINKED_PROFILES_SET: '25013968611531010', // LinkedProfilesSet
34
+ LINKED_PROFILES_REMOVE: '24537675509265525', // LinkedProfilesRemove
35
+ LINKED_PROFILES_UPDATE: '24876967165297614', // LinkedProfilesUpdate
36
+ MIGRATE_BLOCKLIST_LID: '25028600226770432', // MigrateBlocklistLid
37
+ QR_CODE_SCAN: '26287165600869744' // QRCodeScan
38
+ };
39
+
40
+ export const makePrivacySocket = (sock) => {
41
+ const { query, generateMessageTag } = sock;
42
+
43
+ const mexQuery = (variables, queryId, dataPath) =>
44
+ executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
45
+
46
+ // Privacy Settings
47
+
48
+ /**
49
+ * Fetch all privacy settings via MEX.
50
+ * Confirmed from C24395AkT.java variables: { users: [{ jid, privacy_features: [...] }] }
51
+ * dataPath: xwa2_fetch_wa_users (array of users, each with privacy_settings[])
52
+ *
53
+ * @param {string} jid - Own JID
54
+ * @param {string[]} [features] - Privacy features to fetch (default: all known)
55
+ */
56
+ const getPrivacySettings = (jid, features = null) => {
57
+ const users = [{ jid, ...(features ? { privacy_features: features } : {}) }];
58
+ return mexQuery({ users }, PRIVACY_MEX_IDS.GET_SETTINGS, 'xwa2_fetch_wa_users');
59
+ };
60
+
61
+ /**
62
+ * Set a privacy setting via MEX.
63
+ * Confirmed from C24403Akb.java variables: { feature, setting }
64
+ * dataPath: xwa2_privacy_feature_update
65
+ *
66
+ * Values are lowercase and case-sensitive on the wire NOT the uppercase values
67
+ * older docs list.
68
+ *
69
+ * Known features: "last" (last seen), "online", "profile" (photo), "status", "readreceipts",
70
+ * "groupadd" (who can add you to groups), "groupcreation", "calladd",
71
+ * "defense" (anti-scraping), "messages", "linked_profiles", "cover_photo",
72
+ * "dependentaccountmessages", "pix", "stickers"
73
+ * (the last 6 are business-account-only)
74
+ * Known settings: "all", "contacts", "contact_blacklist", "none" most features.
75
+ * "online" only accepts "all" | "match_last_seen".
76
+ * "calladd" only accepts "all" | "contacts" | "known".
77
+ * "defense" only accepts "off" | "on_standard".
78
+ *
79
+ * @param {string} feature - Privacy feature name
80
+ * @param {string} setting - New value
81
+ */
82
+ const setPrivacySetting = (feature, setting) =>
83
+ mexQuery({ feature, setting }, PRIVACY_MEX_IDS.SET_SETTING, 'xwa2_privacy_feature_update');
84
+
85
+ /**
86
+ * Update the contact list for a privacy setting (e.g. "GROUPS" with CONTACT_BLACKLIST).
87
+ * Confirmed from InteropPrivacySettingWithContactListUpdate pattern.
88
+ * dataPath: xwa2_privacy_contact_list_update
89
+ *
90
+ * @param {string} feature - Privacy feature
91
+ * @param {string} setting - "CONTACT_BLACKLIST" | "CONTACTS"
92
+ * @param {string[]} jids - List of JIDs to include in the list
93
+ */
94
+ const updatePrivacyContactList = (feature, setting, jids) =>
95
+ mexQuery(
96
+ { feature, setting, contacts: jids.map(jid => ({ jid })) },
97
+ PRIVACY_MEX_IDS.UPDATE_CONTACT_LIST,
98
+ 'xwa2_privacy_contact_list_update'
99
+ );
100
+
101
+ /**
102
+ * Fetch the contact list for a privacy setting.
103
+ * dataPath: xwa2_privacy_contact_list
104
+ *
105
+ * @param {string} feature - Privacy feature
106
+ * @param {string} setting - "CONTACT_BLACKLIST" | "CONTACTS"
107
+ */
108
+ const getPrivacyContactList = (feature, setting) =>
109
+ mexQuery({ feature, setting }, PRIVACY_MEX_IDS.GET_CONTACT_LIST, 'xwa2_privacy_contact_list');
110
+
111
+ // Status / Profile
112
+
113
+ /**
114
+ * Update own text status (About/Evolved About) via MEX.
115
+ * Confirmed from C227219wi.java:
116
+ * text_status_input: { text, emoji: { content } }
117
+ * dataPath: xwa2_text_status_update
118
+ *
119
+ * @param {string} text - Status text
120
+ * @param {string} [emoji] - Optional emoji to attach
121
+ */
122
+ const updateTextStatus = (text, emoji = null) => {
123
+ const input = { text };
124
+ if (emoji) input.emoji = { content: emoji };
125
+ return mexQuery({ text_status_input: input }, PRIVACY_MEX_IDS.UPDATE_TEXT_STATUS, 'xwa2_text_status_update');
126
+ };
127
+
128
+ /**
129
+ * Fetch text statuses (About) for a list of JIDs via MEX.
130
+ * Confirmed from C227219wi.java:
131
+ * input: [{ jid, last_update_time: null }]
132
+ * dataPath: xwa2_text_status_list
133
+ *
134
+ * @param {string[]} jids - JIDs to fetch statuses for
135
+ * @param {number|null} [lastUpdateTime] - Only return statuses newer than this timestamp
136
+ */
137
+ const getTextStatusList = (jids, lastUpdateTime = null) => {
138
+ const input = jids.map(jid => ({ jid, last_update_time: lastUpdateTime }));
139
+ return mexQuery({ input }, PRIVACY_MEX_IDS.GET_TEXT_STATUS_LIST, 'xwa2_text_status_list');
140
+ };
141
+
142
+ /**
143
+ * Update own user status string via MEX.
144
+ * Confirmed from UpdateUserStatus mutation variables: { status }
145
+ * dataPath: xwa2_update_user_status
146
+ *
147
+ * @param {string} status - New status string
148
+ */
149
+ const updateUserStatus = status => mexQuery({ status }, PRIVACY_MEX_IDS.UPDATE_USER_STATUS, 'xwa2_update_user_status');
150
+
151
+ /**
152
+ * Fetch picture info for a user via MEX.
153
+ * dataPath: xwa2_fetch_user_picture_info
154
+ *
155
+ * @param {string} jid - JID to fetch picture info for
156
+ */
157
+ const fetchUserPictureInfo = jid =>
158
+ mexQuery({ jid }, PRIVACY_MEX_IDS.FETCH_USER_PICTURE, 'xwa2_fetch_user_picture_info');
159
+
160
+ /**
161
+ * Set own profile picture via MEX.
162
+ * dataPath: xwa2_profile_picture_mutation
163
+ *
164
+ * @param {string} imageBase64 - Base64-encoded image data
165
+ * @param {'image'|'preview'} [type='image'] - Picture type
166
+ */
167
+ const setProfilePictureMex = (imageBase64, type = 'image') =>
168
+ mexQuery(
169
+ { input: { image: imageBase64, type } },
170
+ PRIVACY_MEX_IDS.PROFILE_PICTURE_MUTATION,
171
+ 'xwa2_profile_picture_mutation'
172
+ );
173
+
174
+ // Account / Auth
175
+
176
+ /**
177
+ * Mark account as logged-in via MEX (companion device registration flow).
178
+ * Confirmed from LogoutManager.java:
179
+ * input: { phone_number }
180
+ * dataPath: xwa2_account_login
181
+ *
182
+ * @param {string} phoneNumber - Phone number (raw, e.g. "491234567890")
183
+ */
184
+ const accountLogin = phoneNumber =>
185
+ mexQuery({ input: { phone_number: phoneNumber } }, PRIVACY_MEX_IDS.ACCOUNT_LOGIN, 'xwa2_account_login');
186
+
187
+ /**
188
+ * Mark account as logged-out via MEX.
189
+ * Confirmed from LogoutManager.java:
190
+ * input: { phone_number, enabled_biometric }
191
+ * dataPath: xwa2_account_logout
192
+ *
193
+ * @param {string} phoneNumber - Phone number
194
+ * @param {boolean} [enabledBiometric=false]
195
+ */
196
+ const accountLogout = (phoneNumber, enabledBiometric = false) =>
197
+ mexQuery(
198
+ { input: { phone_number: phoneNumber, enabled_biometric: enabledBiometric } },
199
+ PRIVACY_MEX_IDS.ACCOUNT_LOGOUT,
200
+ 'xwa2_account_logout'
201
+ );
202
+
203
+ /**
204
+ * Add a multi-account link (secondary account) via MEX.
205
+ * Confirmed from AddMultiAccountLink mutation:
206
+ * input: { phone_number }
207
+ * dataPath: xwa2_add_multi_account_link
208
+ *
209
+ * @param {string} phoneNumber - Phone number of account to link
210
+ */
211
+ const addMultiAccountLink = phoneNumber =>
212
+ mexQuery(
213
+ { input: { phone_number: phoneNumber } },
214
+ PRIVACY_MEX_IDS.ADD_MULTI_ACCOUNT_LINK,
215
+ 'xwa2_add_multi_account_link'
216
+ );
217
+
218
+ /**
219
+ * Add a trusted device (biometric/passkey) via MEX.
220
+ * Confirmed from RegTrustedDeviceGraphQLHelper.java:
221
+ * device_id, device_name
222
+ * dataPath: xwa2_add_trusted_device
223
+ *
224
+ * @param {string} deviceId - Device ID suffix
225
+ * @param {string} deviceName - Human-readable device name
226
+ */
227
+ const addTrustedDevice = (deviceId, deviceName) =>
228
+ mexQuery(
229
+ { device_id: deviceId, device_name: deviceName },
230
+ PRIVACY_MEX_IDS.ADD_TRUSTED_DEVICE,
231
+ 'xwa2_add_trusted_device'
232
+ );
233
+
234
+ /**
235
+ * Fetch list of trusted devices for the account via MEX.
236
+ * dataPath: xwa2_get_trusted_devices
237
+ */
238
+ const getTrustedDevices = () => mexQuery({}, PRIVACY_MEX_IDS.GET_TRUSTED_DEVICES, 'xwa2_get_trusted_devices');
239
+
240
+ /**
241
+ * Untrust (remove) a trusted device via MEX.
242
+ * Confirmed from RegTrustedDeviceGraphQLHelper.java:
243
+ * device_id, reason (default: "REREG")
244
+ * dataPath: xwa2_untrust_trusted_device
245
+ *
246
+ * @param {string} deviceId - Device ID to remove
247
+ * @param {string} [reason='USER_INITIATED']
248
+ */
249
+ const untrustTrustedDevice = (deviceId, reason = 'USER_INITIATED') =>
250
+ mexQuery({ device_id: deviceId, reason }, PRIVACY_MEX_IDS.UNTRUST_TRUSTED_DEVICE, 'xwa2_untrust_trusted_device');
251
+
252
+ /**
253
+ * Delete a trusted device entirely via MEX.
254
+ * dataPath: xwa2_delete_trusted_device
255
+ *
256
+ * @param {string} deviceId - Device ID to delete
257
+ */
258
+ const deleteTrustedDevice = deviceId =>
259
+ mexQuery({ device_id: deviceId }, PRIVACY_MEX_IDS.DELETE_TRUSTED_DEVICE, 'xwa2_delete_trusted_device');
260
+
261
+ /**
262
+ * Revoke multi-account link for a secondary account via MEX.
263
+ * dataPath: xwa2_multi_account_revoke
264
+ *
265
+ * @param {string} accountJid - JID of the account to revoke
266
+ */
267
+ const revokeMultiAccount = accountJid =>
268
+ mexQuery({ account_jid: accountJid }, PRIVACY_MEX_IDS.MULTI_ACCOUNT_REVOKE, 'xwa2_multi_account_revoke');
269
+
270
+ // Misc
271
+
272
+ /**
273
+ * Fetch mobile config via MEX.
274
+ * Confirmed from C28889Clt.java:
275
+ * api_version, ep_refresh_id, flags
276
+ * dataPath: xwa2_mobile_config_fetch
277
+ *
278
+ * @param {number} [apiVersion=0]
279
+ * @param {number} [epRefreshId=0]
280
+ * @param {string} [flags='']
281
+ */
282
+ const fetchMobileConfig = (apiVersion = 0, epRefreshId = 0, flags = '') =>
283
+ mexQuery(
284
+ { api_version: apiVersion, ep_refresh_id: epRefreshId, flags },
285
+ PRIVACY_MEX_IDS.MOBILE_CONFIG_FETCH,
286
+ 'xwa2_mobile_config_fetch'
287
+ );
288
+
289
+ /**
290
+ * Notify group members of your push name via MEX.
291
+ * Confirmed from C128275fj.java:
292
+ * input: { group_jid, participants: [{ jid, push_name }] }
293
+ * dataPath: xwa2_notify_push_name
294
+ *
295
+ * @param {string} groupJid - Group JID
296
+ * @param {{ jid: string, pushName: string }[]} participants
297
+ */
298
+ const notifyPushName = (groupJid, participants) =>
299
+ mexQuery(
300
+ {
301
+ input: {
302
+ group_jid: groupJid,
303
+ participants: participants.map(({ jid, pushName }) => ({ jid, push_name: pushName }))
304
+ }
305
+ },
306
+ PRIVACY_MEX_IDS.NOTIFY_PUSH_NAME,
307
+ 'xwa2_notify_push_name'
308
+ );
309
+
310
+ /**
311
+ * Run a contact integrity check via MEX.
312
+ * Confirmed from RunnableC24106Aep.java uses xwa2_fetch_wa_users path.
313
+ * use_case: "START_CHAT_CONTEXT"
314
+ *
315
+ * @param {string[]} jids - JIDs to check
316
+ * @param {string} [useCase='START_CHAT_CONTEXT']
317
+ */
318
+ const contactIntegrityQuery = (jids, useCase = 'START_CHAT_CONTEXT') =>
319
+ mexQuery(
320
+ { users: jids.map(jid => ({ jid })), use_case: useCase },
321
+ PRIVACY_MEX_IDS.CONTACT_INTEGRITY,
322
+ 'xwa2_fetch_wa_users'
323
+ );
324
+
325
+ /**
326
+ * Run a business integrity check via MEX.
327
+ * Confirmed from BizIntegrityQuery variables: { users: [{ jid }] }
328
+ * dataPath: xwa2_fetch_wa_users
329
+ *
330
+ * @param {string[]} jids - Business JIDs to check
331
+ */
332
+ const bizIntegrityQuery = jids =>
333
+ mexQuery({ users: jids.map(jid => ({ jid })) }, PRIVACY_MEX_IDS.BIZ_INTEGRITY, 'xwa2_fetch_wa_users');
334
+
335
+ /**
336
+ * Set linked social profiles (FB/IG) via MEX.
337
+ * Confirmed from C24386Ak3.java:
338
+ * profiles: [{ type: "FB"|"IG", username|vid, encrypted_metadata?, user_info? }]
339
+ * dataPath: xwa2_linked_profiles_set
340
+ *
341
+ * @param {{ type: 'FB'|'IG', username?: string, vid?: string }[]} profiles
342
+ */
343
+ const linkedProfilesSet = profiles => {
344
+ const mapped = profiles.map(p => {
345
+ const entry = { type: p.type };
346
+ if (p.vid) entry.vid = p.vid;
347
+ else if (p.username) entry.username = p.username;
348
+ return entry;
349
+ });
350
+ return mexQuery({ profiles: mapped }, PRIVACY_MEX_IDS.LINKED_PROFILES_SET, 'xwa2_linked_profiles_set');
351
+ };
352
+
353
+ /**
354
+ * Remove linked social profiles via MEX.
355
+ * dataPath: xwa2_linked_profiles_remove
356
+ *
357
+ * @param {('FB'|'IG')[]} types - Profile types to remove
358
+ */
359
+ const linkedProfilesRemove = types =>
360
+ mexQuery(
361
+ { profiles: types.map(type => ({ type })) },
362
+ PRIVACY_MEX_IDS.LINKED_PROFILES_REMOVE,
363
+ 'xwa2_linked_profiles_remove'
364
+ );
365
+
366
+ /**
367
+ * Update linked social profile visibility/settings via MEX.
368
+ * Confirmed from LinkedProfilesUpdate mutation:
369
+ * profiles: [{ type, show_on_profile }]
370
+ * dataPath: xwa2_linked_profiles_update
371
+ *
372
+ * @param {{ type: 'FB'|'IG', showOnProfile: boolean }[]} profiles
373
+ */
374
+ const linkedProfilesUpdate = profiles =>
375
+ mexQuery(
376
+ { profiles: profiles.map(({ type, showOnProfile }) => ({ type, show_on_profile: showOnProfile })) },
377
+ PRIVACY_MEX_IDS.LINKED_PROFILES_UPDATE,
378
+ 'xwa2_linked_profiles_update'
379
+ );
380
+
381
+ /**
382
+ * Migrate blocklist to LID addressing via MEX.
383
+ * Confirmed from C8Eu.java:
384
+ * input: { blocklist: [{ jid }], dhash, dirty_ack }
385
+ * dataPath: xwa2_migrate_blocklist_lid
386
+ *
387
+ * @param {string[]} jids - Blocked JIDs to migrate
388
+ * @param {string} [dhash=''] - Current blocklist hash
389
+ * @param {boolean} [dirtyAck=true]
390
+ */
391
+ const migrateBlocklistLid = (jids, dhash = '', dirtyAck = true) =>
392
+ mexQuery(
393
+ {
394
+ input: {
395
+ blocklist: jids.map(jid => ({ jid })),
396
+ dhash,
397
+ dirty_ack: dirtyAck
398
+ }
399
+ },
400
+ PRIVACY_MEX_IDS.MIGRATE_BLOCKLIST_LID,
401
+ 'xwa2_migrate_blocklist_lid'
402
+ );
403
+
404
+ /**
405
+ * Scan a QR code via MEX (used for linking companion devices).
406
+ * dataPath: xwa2_qr_code_scan
407
+ *
408
+ * @param {string} qrData - Raw QR code data string
409
+ */
410
+ const qrCodeScan = qrData => mexQuery({ qr_data: qrData }, PRIVACY_MEX_IDS.QR_CODE_SCAN, 'xwa2_qr_code_scan');
411
+
412
+ return {
413
+ ...sock,
414
+ // Privacy
415
+ getPrivacySettings,
416
+ setPrivacySetting,
417
+ updatePrivacyContactList,
418
+ getPrivacyContactList,
419
+ // Status / profile
420
+ updateTextStatus,
421
+ getTextStatusList,
422
+ updateUserStatus,
423
+ fetchUserPictureInfo,
424
+ setProfilePictureMex,
425
+ // Account / auth
426
+ accountLogin,
427
+ accountLogout,
428
+ addMultiAccountLink,
429
+ addTrustedDevice,
430
+ getTrustedDevices,
431
+ untrustTrustedDevice,
432
+ deleteTrustedDevice,
433
+ revokeMultiAccount,
434
+ // Misc
435
+ fetchMobileConfig,
436
+ notifyPushName,
437
+ contactIntegrityQuery,
438
+ bizIntegrityQuery,
439
+ linkedProfilesSet,
440
+ linkedProfilesRemove,
441
+ linkedProfilesUpdate,
442
+ migrateBlocklistLid,
443
+ qrCodeScan,
444
+ PRIVACY_MEX_IDS
445
+ };
446
+ };