@badzz88/baileys 8.5.7 → 8.5.9

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 (142) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +284 -264
  3. package/WAProto/index.js +5 -5
  4. package/engine-requirements.js +7 -15
  5. package/lib/Defaults/index.js +130 -187
  6. package/lib/Signal/Group/ciphertext-message.js +11 -14
  7. package/lib/Signal/Group/group-session-builder.js +29 -91
  8. package/lib/Signal/Group/group_cipher.js +81 -88
  9. package/lib/Signal/Group/index.js +12 -136
  10. package/lib/Signal/Group/keyhelper.js +15 -70
  11. package/lib/Signal/Group/sender-chain-key.js +25 -31
  12. package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
  13. package/lib/Signal/Group/sender-key-message.js +65 -68
  14. package/lib/Signal/Group/sender-key-name.js +41 -43
  15. package/lib/Signal/Group/sender-key-record.js +40 -43
  16. package/lib/Signal/Group/sender-key-state.js +83 -96
  17. package/lib/Signal/Group/sender-message-key.js +25 -29
  18. package/lib/Signal/libsignal.js +425 -453
  19. package/lib/Signal/lid-mapping.js +276 -259
  20. package/lib/Socket/Client/index.js +3 -30
  21. package/lib/Socket/Client/types.js +10 -12
  22. package/lib/Socket/Client/websocket.js +53 -61
  23. package/lib/Socket/business.js +379 -422
  24. package/lib/Socket/chats.js +1193 -1816
  25. package/lib/Socket/communities.js +431 -549
  26. package/lib/Socket/graphql.js +672 -612
  27. package/lib/Socket/groups.js +374 -764
  28. package/lib/Socket/index.js +17 -38
  29. package/lib/Socket/interop.js +417 -503
  30. package/lib/Socket/messages-recv.js +1915 -2441
  31. package/lib/Socket/messages-send.js +1213 -1630
  32. package/lib/Socket/mex.js +9 -15
  33. package/lib/Socket/newsletter.js +746 -808
  34. package/lib/Socket/privacy.js +310 -441
  35. package/lib/Socket/socket.js +1025 -1022
  36. package/lib/Socket/username.js +8 -15
  37. package/lib/Store/index.js +10 -36
  38. package/lib/Store/make-cache-manager-store.js +80 -85
  39. package/lib/Store/make-in-memory-store.js +231 -591
  40. package/lib/Store/make-ordered-dictionary.js +72 -78
  41. package/lib/Store/object-repository.js +28 -25
  42. package/lib/Types/Auth.js +2 -38
  43. package/lib/Types/Bussines.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +8 -4
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +11 -95
  52. package/lib/Types/Mex.js +111 -112
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +3 -2
  56. package/lib/Types/State.js +56 -70
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +26 -55
  59. package/lib/Utils/auth-utils.js +288 -292
  60. package/lib/Utils/browser-utils.js +47 -113
  61. package/lib/Utils/business.js +224 -240
  62. package/lib/Utils/chat-utils.js +869 -1205
  63. package/lib/Utils/companion-reg-client-utils.js +34 -41
  64. package/lib/Utils/crypto.js +107 -144
  65. package/lib/Utils/decode-wa-message.js +308 -518
  66. package/lib/Utils/event-buffer.js +611 -596
  67. package/lib/Utils/generics.js +355 -515
  68. package/lib/Utils/history.js +134 -244
  69. package/lib/Utils/identity-change-handler.js +49 -51
  70. package/lib/Utils/index.js +23 -57
  71. package/lib/Utils/link-preview.js +77 -135
  72. package/lib/Utils/logger.js +3 -9
  73. package/lib/Utils/lt-hash.js +6 -37
  74. package/lib/Utils/make-mutex.js +33 -36
  75. package/lib/Utils/message-composer.js +233 -439
  76. package/lib/Utils/message-retry-manager.js +260 -265
  77. package/lib/Utils/messages-media.js +829 -855
  78. package/lib/Utils/messages.js +961 -2528
  79. package/lib/Utils/noise-handler.js +200 -195
  80. package/lib/Utils/offline-node-processor.js +33 -35
  81. package/lib/Utils/pre-key-manager.js +102 -103
  82. package/lib/Utils/process-message.js +560 -978
  83. package/lib/Utils/reporting-utils.js +253 -257
  84. package/lib/Utils/signal.js +195 -218
  85. package/lib/Utils/stanza-ack.js +29 -31
  86. package/lib/Utils/sticker.js +109 -144
  87. package/lib/Utils/sync-action-utils.js +45 -50
  88. package/lib/Utils/tc-token-utils.js +139 -137
  89. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  90. package/lib/Utils/validate-connection.js +202 -218
  91. package/lib/WABinary/constants.js +1299 -1302
  92. package/lib/WABinary/decode.js +262 -343
  93. package/lib/WABinary/encode.js +4 -12
  94. package/lib/WABinary/generic-utils.js +187 -223
  95. package/lib/WABinary/index.js +6 -33
  96. package/lib/WABinary/jid-utils.js +88 -351
  97. package/lib/WABinary/types.js +2 -2
  98. package/lib/WAM/BinaryInfo.js +9 -12
  99. package/lib/WAM/constants.js +22853 -39486
  100. package/lib/WAM/encode.js +140 -132
  101. package/lib/WAM/index.js +4 -31
  102. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
  103. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
  104. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
  105. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
  107. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
  108. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
  109. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
  110. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
  112. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
  113. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
  114. package/lib/WAUSync/Protocols/index.js +12 -39
  115. package/lib/WAUSync/USyncQuery.js +67 -49
  116. package/lib/WAUSync/USyncUser.js +11 -5
  117. package/lib/WAUSync/index.js +3 -31
  118. package/lib/index.js +15 -48
  119. package/package.json +129 -99
  120. package/LICENSE +0 -21
  121. package/lib/Defaults/phonenumber-mcc.json +0 -223
  122. package/lib/Socket/aigroups.js +0 -240
  123. package/lib/Socket/interactive-handler.js +0 -522
  124. package/lib/Socket/managed-account.js +0 -183
  125. package/lib/Socket/registration.js +0 -427
  126. package/lib/Socket/text-router.js +0 -83
  127. package/lib/Types/Newsletter.js +0 -121
  128. package/lib/Utils/command-loader.d.ts +0 -31
  129. package/lib/Utils/command-loader.js +0 -100
  130. package/lib/Utils/consumer-application.js +0 -107
  131. package/lib/Utils/curve25519-js.js +0 -275
  132. package/lib/Utils/group-history.js +0 -60
  133. package/lib/Utils/jid-display-normalization.js +0 -218
  134. package/lib/Utils/meta-ai-msmsg.js +0 -262
  135. package/lib/Utils/native-bridge.js +0 -82
  136. package/lib/Utils/session-pool.d.ts +0 -16
  137. package/lib/Utils/session-pool.js +0 -94
  138. package/lib/Utils/sticker.d.ts +0 -17
  139. package/lib/Utils/view-once-cache.d.ts +0 -9
  140. package/lib/Utils/view-once-cache.js +0 -79
  141. package/lib/Utils/voip-rekey.js +0 -22
  142. package/lib/antiban.js +0 -4637
@@ -1,449 +1,318 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.makePrivacySocket = void 0
4
-
5
- const { executeWMexQuery } = require('./mex')
1
+ import { executeWMexQuery } from './mex.js'
6
2
 
7
3
  /**
8
4
  * MEX query IDs for privacy, status/profile, account/auth, and misc operations.
9
5
  * Source: assets/whatsapp-android-mex_client_persist_ids.json
10
6
  */
11
7
  const PRIVACY_MEX_IDS = {
12
- // Privacy settings
13
- GET_SETTINGS: '32774292262215380', // GetPrivacySettingsQuery
14
- SET_SETTING: '26887749497493184', // SetPrivacySettingMutation
15
- UPDATE_CONTACT_LIST: '26375158178762800', // UpdatePrivacyContactListMutation
16
- GET_CONTACT_LIST: '25700444246275824', // GetPrivacyContactListQuery
17
- // Status / profile
18
- UPDATE_TEXT_STATUS: '25863197129975892', // UpdateTextStatus
19
- GET_TEXT_STATUS_LIST: '25741205615468936', // GetTextStatusList
20
- UPDATE_USER_STATUS: '7452341274886724', // UpdateUserStatus
21
- FETCH_USER_PICTURE: '24983561624604410', // FetchUserPictureInfo
22
- PROFILE_PICTURE_MUTATION: '24714239711610700', // ProfilePictureMutation
23
- // Account / auth
24
- ACCOUNT_LOGIN: '27298465499757130', // AccountLoginMutation
25
- ACCOUNT_LOGOUT: '26863447609979190', // AccountLogoutMutation
26
- MULTI_ACCOUNT_REVOKE: '25846242091639660', // MultiAccountRevokeAccount
27
- ADD_MULTI_ACCOUNT_LINK: '25502812266025190', // AddMultiAccountLink
28
- ADD_TRUSTED_DEVICE: '24522952587403290', // AddTrustedDeviceMutation
29
- GET_TRUSTED_DEVICES: '25123358920671964', // GetTrustedDevicesQuery
30
- UNTRUST_TRUSTED_DEVICE: '26574930682133620', // UntrustTrustedDeviceMutation
31
- DELETE_TRUSTED_DEVICE: '33867503889559536', // DeleteTrustedDeviceMutation
32
- // Misc
33
- MOBILE_CONFIG_FETCH: '25676911271914596', // MobileConfigFetchQuery
34
- NOTIFY_PUSH_NAME: '25900490552974544', // NotifyPushName
35
- CONTACT_INTEGRITY: '25924358997169496', // ContactIntegrityQuery
36
- BIZ_INTEGRITY: '25975613018777536', // BizIntegrityQuery
37
- LINKED_PROFILES_SET: '25013968611531010', // LinkedProfilesSet
38
- LINKED_PROFILES_REMOVE: '24537675509265524', // LinkedProfilesRemove
39
- LINKED_PROFILES_UPDATE: '24876967165297616', // LinkedProfilesUpdate
40
- MIGRATE_BLOCKLIST_LID: '25028600226770430', // MigrateBlocklistLid
41
- QR_CODE_SCAN: '26287165600869744' // QRCodeScan
42
- }
43
-
44
- const makePrivacySocket = sock => {
45
- const { query, generateMessageTag } = sock
46
-
47
- const mexQuery = (variables, queryId, dataPath) =>
48
- executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
49
-
50
- // ── Privacy Settings ────────────────────────────────────────────────────
51
-
52
- /**
53
- * Fetch all privacy settings via MEX.
54
- * Confirmed from C24395AkT.java — variables: { users: [{ jid, privacy_features: [...] }] }
55
- * dataPath: xwa2_fetch_wa_users (array of users, each with privacy_settings[])
56
- *
57
- * @param {string} jid - Own JID
58
- * @param {string[]} [features] - Privacy features to fetch (default: all known)
59
- */
60
- const getPrivacySettings = (jid, features = null) => {
61
- const users = [{ jid, ...(features ? { privacy_features: features } : {}) }]
62
- return mexQuery({ users }, PRIVACY_MEX_IDS.GET_SETTINGS, 'xwa2_fetch_wa_users')
63
- }
64
-
65
- /**
66
- * Set a privacy setting via MEX.
67
- * Confirmed from C24403Akb.java — variables: { feature, setting }
68
- * dataPath: xwa2_privacy_feature_update
69
- *
70
- * Known features: "LAST_SEEN", "ONLINE", "PROFILE_PHOTO", "STATUS", "READ_RECEIPTS",
71
- * "GROUPS", "CALLS", "SCREENSHOT", "LIVE_LOCATION"
72
- * Known settings: "ALL", "CONTACTS", "CONTACT_BLACKLIST", "NONE"
73
- *
74
- * @param {string} feature - Privacy feature name
75
- * @param {string} setting - New value
76
- */
77
- const setPrivacySetting = (feature, setting) =>
78
- mexQuery({ feature, setting }, PRIVACY_MEX_IDS.SET_SETTING, 'xwa2_privacy_feature_update')
79
-
80
- /**
81
- * Update the contact list for a privacy setting (e.g. "GROUPS" with CONTACT_BLACKLIST).
82
- * Confirmed from InteropPrivacySettingWithContactListUpdate pattern.
83
- * dataPath: xwa2_privacy_contact_list_update
84
- *
85
- * @param {string} feature - Privacy feature
86
- * @param {string} setting - "CONTACT_BLACKLIST" | "CONTACTS"
87
- * @param {string[]} jids - List of JIDs to include in the list
88
- */
89
- const updatePrivacyContactList = (feature, setting, jids) =>
90
- mexQuery(
91
- { feature, setting, contacts: jids.map(jid => ({ jid })) },
92
- PRIVACY_MEX_IDS.UPDATE_CONTACT_LIST,
93
- 'xwa2_privacy_contact_list_update'
94
- )
95
-
96
- /**
97
- * Fetch the contact list for a privacy setting.
98
- * dataPath: xwa2_privacy_contact_list
99
- *
100
- * @param {string} feature - Privacy feature
101
- * @param {string} setting - "CONTACT_BLACKLIST" | "CONTACTS"
102
- */
103
- const getPrivacyContactList = (feature, setting) =>
104
- mexQuery({ feature, setting }, PRIVACY_MEX_IDS.GET_CONTACT_LIST, 'xwa2_privacy_contact_list')
105
-
106
- // ── Status / Profile ───────────────────────────────────────────────────
107
-
108
- /**
109
- * Update own text status (About/Evolved About) via MEX.
110
- * Confirmed from C227219wi.java:
111
- * text_status_input: { text, emoji: { content } }
112
- * dataPath: xwa2_text_status_update
113
- *
114
- * @param {string} text - Status text
115
- * @param {string} [emoji] - Optional emoji to attach
116
- */
117
- const updateTextStatus = (text, emoji = null) => {
118
- const input = { text }
119
- if (emoji) input.emoji = { content: emoji }
120
- return mexQuery({ text_status_input: input }, PRIVACY_MEX_IDS.UPDATE_TEXT_STATUS, 'xwa2_text_status_update')
121
- }
122
-
123
- /**
124
- * Fetch text statuses (About) for a list of JIDs via MEX.
125
- * Confirmed from C227219wi.java:
126
- * input: [{ jid, last_update_time: null }]
127
- * dataPath: xwa2_text_status_list
128
- *
129
- * @param {string[]} jids - JIDs to fetch statuses for
130
- * @param {number|null} [lastUpdateTime] - Only return statuses newer than this timestamp
131
- */
132
- const getTextStatusList = (jids, lastUpdateTime = null) => {
133
- const input = jids.map(jid => ({ jid, last_update_time: lastUpdateTime }))
134
- return mexQuery({ input }, PRIVACY_MEX_IDS.GET_TEXT_STATUS_LIST, 'xwa2_text_status_list')
135
- }
136
-
137
- /**
138
- * Update own user status string via MEX.
139
- * Confirmed from UpdateUserStatus mutation — variables: { status }
140
- * dataPath: xwa2_update_user_status
141
- *
142
- * @param {string} status - New status string
143
- */
144
- const updateUserStatus = status =>
145
- mexQuery({ status }, PRIVACY_MEX_IDS.UPDATE_USER_STATUS, 'xwa2_update_user_status')
146
-
147
- /**
148
- * Fetch picture info for a user via MEX.
149
- * dataPath: xwa2_fetch_user_picture_info
150
- *
151
- * @param {string} jid - JID to fetch picture info for
152
- */
153
- const fetchUserPictureInfo = jid =>
154
- mexQuery({ jid }, PRIVACY_MEX_IDS.FETCH_USER_PICTURE, 'xwa2_fetch_user_picture_info')
155
-
156
- /**
157
- * Set own profile picture via MEX.
158
- * dataPath: xwa2_profile_picture_mutation
159
- *
160
- * @param {string} imageBase64 - Base64-encoded image data
161
- * @param {'image'|'preview'} [type='image'] - Picture type
162
- */
163
- const setProfilePictureMex = (imageBase64, type = 'image') =>
164
- mexQuery(
165
- { input: { image: imageBase64, type } },
166
- PRIVACY_MEX_IDS.PROFILE_PICTURE_MUTATION,
167
- 'xwa2_profile_picture_mutation'
168
- )
169
-
170
- // ── Account / Auth ─────────────────────────────────────────────────────
171
-
172
- /**
173
- * Mark account as logged-in via MEX (companion device registration flow).
174
- * Confirmed from LogoutManager.java:
175
- * input: { phone_number }
176
- * dataPath: xwa2_account_login
177
- *
178
- * @param {string} phoneNumber - Phone number (raw, e.g. "491234567890")
179
- */
180
- const accountLogin = phoneNumber =>
181
- mexQuery({ input: { phone_number: phoneNumber } }, PRIVACY_MEX_IDS.ACCOUNT_LOGIN, 'xwa2_account_login')
182
-
183
- /**
184
- * Mark account as logged-out via MEX.
185
- * Confirmed from LogoutManager.java:
186
- * input: { phone_number, enabled_biometric }
187
- * dataPath: xwa2_account_logout
188
- *
189
- * @param {string} phoneNumber - Phone number
190
- * @param {boolean} [enabledBiometric=false]
191
- */
192
- const accountLogout = (phoneNumber, enabledBiometric = false) =>
193
- mexQuery(
194
- { input: { phone_number: phoneNumber, enabled_biometric: enabledBiometric } },
195
- PRIVACY_MEX_IDS.ACCOUNT_LOGOUT,
196
- 'xwa2_account_logout'
197
- )
198
-
199
- /**
200
- * Add a multi-account link (secondary account) via MEX.
201
- * Confirmed from AddMultiAccountLink mutation:
202
- * input: { phone_number }
203
- * dataPath: xwa2_add_multi_account_link
204
- *
205
- * @param {string} phoneNumber - Phone number of account to link
206
- */
207
- const addMultiAccountLink = phoneNumber =>
208
- mexQuery(
209
- { input: { phone_number: phoneNumber } },
210
- PRIVACY_MEX_IDS.ADD_MULTI_ACCOUNT_LINK,
211
- 'xwa2_add_multi_account_link'
212
- )
213
-
214
- /**
215
- * Add a trusted device (biometric/passkey) via MEX.
216
- * Confirmed from RegTrustedDeviceGraphQLHelper.java:
217
- * device_id, device_name
218
- * dataPath: xwa2_add_trusted_device
219
- *
220
- * @param {string} deviceId - Device ID suffix
221
- * @param {string} deviceName - Human-readable device name
222
- */
223
- const addTrustedDevice = (deviceId, deviceName) =>
224
- mexQuery({ device_id: deviceId, device_name: deviceName }, PRIVACY_MEX_IDS.ADD_TRUSTED_DEVICE, 'xwa2_add_trusted_device')
225
-
226
- /**
227
- * Fetch list of trusted devices for the account via MEX.
228
- * dataPath: xwa2_get_trusted_devices
229
- */
230
- const getTrustedDevices = () => mexQuery({}, PRIVACY_MEX_IDS.GET_TRUSTED_DEVICES, 'xwa2_get_trusted_devices')
231
-
232
- /**
233
- * Untrust (remove) a trusted device via MEX.
234
- * Confirmed from RegTrustedDeviceGraphQLHelper.java:
235
- * device_id, reason (default: "REREG")
236
- * dataPath: xwa2_untrust_trusted_device
237
- *
238
- * @param {string} deviceId - Device ID to remove
239
- * @param {string} [reason='USER_INITIATED']
240
- */
241
- const untrustTrustedDevice = (deviceId, reason = 'USER_INITIATED') =>
242
- mexQuery(
243
- { device_id: deviceId, reason },
244
- PRIVACY_MEX_IDS.UNTRUST_TRUSTED_DEVICE,
245
- 'xwa2_untrust_trusted_device'
246
- )
247
-
248
- /**
249
- * Delete a trusted device entirely via MEX.
250
- * dataPath: xwa2_delete_trusted_device
251
- *
252
- * @param {string} deviceId - Device ID to delete
253
- */
254
- const deleteTrustedDevice = deviceId =>
255
- mexQuery({ device_id: deviceId }, PRIVACY_MEX_IDS.DELETE_TRUSTED_DEVICE, 'xwa2_delete_trusted_device')
256
-
257
- /**
258
- * Revoke multi-account link for a secondary account via MEX.
259
- * dataPath: xwa2_multi_account_revoke
260
- *
261
- * @param {string} accountJid - JID of the account to revoke
262
- */
263
- const revokeMultiAccount = accountJid =>
264
- mexQuery({ account_jid: accountJid }, PRIVACY_MEX_IDS.MULTI_ACCOUNT_REVOKE, 'xwa2_multi_account_revoke')
265
-
266
- // ── Misc ───────────────────────────────────────────────────────────────
267
-
268
- /**
269
- * Fetch mobile config via MEX.
270
- * Confirmed from C28889Clt.java:
271
- * api_version, ep_refresh_id, flags
272
- * dataPath: xwa2_mobile_config_fetch
273
- *
274
- * @param {number} [apiVersion=0]
275
- * @param {number} [epRefreshId=0]
276
- * @param {string} [flags='']
277
- */
278
- const fetchMobileConfig = (apiVersion = 0, epRefreshId = 0, flags = '') =>
279
- mexQuery(
280
- { api_version: apiVersion, ep_refresh_id: epRefreshId, flags },
281
- PRIVACY_MEX_IDS.MOBILE_CONFIG_FETCH,
282
- 'xwa2_mobile_config_fetch'
283
- )
284
-
285
- /**
286
- * Notify group members of your push name via MEX.
287
- * Confirmed from C128275fj.java:
288
- * input: { group_jid, participants: [{ jid, push_name }] }
289
- * dataPath: xwa2_notify_push_name
290
- *
291
- * @param {string} groupJid - Group JID
292
- * @param {{ jid: string, pushName: string }[]} participants
293
- */
294
- const notifyPushName = (groupJid, participants) =>
295
- mexQuery(
296
- {
297
- input: {
298
- group_jid: groupJid,
299
- participants: participants.map(({ jid, pushName }) => ({ jid, push_name: pushName }))
300
- }
301
- },
302
- PRIVACY_MEX_IDS.NOTIFY_PUSH_NAME,
303
- 'xwa2_notify_push_name'
304
- )
305
-
306
- /**
307
- * Run a contact integrity check via MEX.
308
- * Confirmed from RunnableC24106Aep.java — uses xwa2_fetch_wa_users path.
309
- * use_case: "START_CHAT_CONTEXT"
310
- *
311
- * @param {string[]} jids - JIDs to check
312
- * @param {string} [useCase='START_CHAT_CONTEXT']
313
- */
314
- const contactIntegrityQuery = (jids, useCase = 'START_CHAT_CONTEXT') =>
315
- mexQuery(
316
- { users: jids.map(jid => ({ jid })), use_case: useCase },
317
- PRIVACY_MEX_IDS.CONTACT_INTEGRITY,
318
- 'xwa2_fetch_wa_users'
319
- )
320
-
321
- /**
322
- * Run a business integrity check via MEX.
323
- * Confirmed from BizIntegrityQuery — variables: { users: [{ jid }] }
324
- * dataPath: xwa2_fetch_wa_users
325
- *
326
- * @param {string[]} jids - Business JIDs to check
327
- */
328
- const bizIntegrityQuery = jids =>
329
- mexQuery(
330
- { users: jids.map(jid => ({ jid })) },
331
- PRIVACY_MEX_IDS.BIZ_INTEGRITY,
332
- 'xwa2_fetch_wa_users'
333
- )
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 =>
411
- mexQuery({ qr_data: qrData }, PRIVACY_MEX_IDS.QR_CODE_SCAN, 'xwa2_qr_code_scan')
412
-
413
- return {
414
- ...sock,
415
- // Privacy
416
- getPrivacySettings,
417
- setPrivacySetting,
418
- updatePrivacyContactList,
419
- getPrivacyContactList,
420
- // Status / profile
421
- updateTextStatus,
422
- getTextStatusList,
423
- updateUserStatus,
424
- fetchUserPictureInfo,
425
- setProfilePictureMex,
426
- // Account / auth
427
- accountLogin,
428
- accountLogout,
429
- addMultiAccountLink,
430
- addTrustedDevice,
431
- getTrustedDevices,
432
- untrustTrustedDevice,
433
- deleteTrustedDevice,
434
- revokeMultiAccount,
435
- // Misc
436
- fetchMobileConfig,
437
- notifyPushName,
438
- contactIntegrityQuery,
439
- bizIntegrityQuery,
440
- linkedProfilesSet,
441
- linkedProfilesRemove,
442
- linkedProfilesUpdate,
443
- migrateBlocklistLid,
444
- qrCodeScan,
445
- PRIVACY_MEX_IDS
446
- }
8
+ // Privacy settings
9
+ GET_SETTINGS: '32774292262215380', // GetPrivacySettingsQuery
10
+ SET_SETTING: '26887749497493184', // SetPrivacySettingMutation
11
+ UPDATE_CONTACT_LIST: '26375158178762800', // UpdatePrivacyContactListMutation
12
+ GET_CONTACT_LIST: '25700444246275824', // GetPrivacyContactListQuery
13
+ // Status / profile
14
+ UPDATE_TEXT_STATUS: '25863197129975892', // UpdateTextStatus
15
+ GET_TEXT_STATUS_LIST: '25741205615468936', // GetTextStatusList
16
+ UPDATE_USER_STATUS: '7452341274886724', // UpdateUserStatus
17
+ FETCH_USER_PICTURE: '24983561624604410', // FetchUserPictureInfo
18
+ PROFILE_PICTURE_MUTATION: '24714239711610700', // ProfilePictureMutation
19
+ // Account / auth
20
+ ACCOUNT_LOGIN: '27298465499757130', // AccountLoginMutation
21
+ ACCOUNT_LOGOUT: '26863447609979190', // AccountLogoutMutation
22
+ MULTI_ACCOUNT_REVOKE: '25846242091639660', // MultiAccountRevokeAccount
23
+ ADD_MULTI_ACCOUNT_LINK: '25502812266025190', // AddMultiAccountLink
24
+ ADD_TRUSTED_DEVICE: '24522952587403290', // AddTrustedDeviceMutation
25
+ GET_TRUSTED_DEVICES: '25123358920671964', // GetTrustedDevicesQuery
26
+ UNTRUST_TRUSTED_DEVICE: '26574930682133620', // UntrustTrustedDeviceMutation
27
+ DELETE_TRUSTED_DEVICE: '33867503889559536', // DeleteTrustedDeviceMutation
28
+ // Misc
29
+ MOBILE_CONFIG_FETCH: '25676911271914596', // MobileConfigFetchQuery
30
+ NOTIFY_PUSH_NAME: '25900490552974544', // NotifyPushName
31
+ CONTACT_INTEGRITY: '25924358997169496', // ContactIntegrityQuery
32
+ BIZ_INTEGRITY: '25975613018777536', // BizIntegrityQuery
33
+ LINKED_PROFILES_SET: '25013968611531010', // LinkedProfilesSet
34
+ LINKED_PROFILES_REMOVE: '24537675509265524', // LinkedProfilesRemove
35
+ LINKED_PROFILES_UPDATE: '24876967165297616', // LinkedProfilesUpdate
36
+ MIGRATE_BLOCKLIST_LID: '25028600226770430', // MigrateBlocklistLid
37
+ QR_CODE_SCAN: '26287165600869744' // QRCodeScan
447
38
  }
448
39
 
449
- exports.makePrivacySocket = makePrivacySocket
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
+ */
51
+ const getPrivacySettings = (jid, features = null) => {
52
+ const users = [{ jid, ...(features ? { privacy_features: features } : {}) }]
53
+ return mexQuery({ users }, PRIVACY_MEX_IDS.GET_SETTINGS, 'xwa2_fetch_wa_users')
54
+ }
55
+
56
+ /**
57
+ * Set a privacy setting via MEX.
58
+ * Features: "LAST_SEEN", "ONLINE", "PROFILE_PHOTO", "STATUS", "READ_RECEIPTS", "GROUPS", "CALLS", "SCREENSHOT", "LIVE_LOCATION"
59
+ * Settings: "ALL", "CONTACTS", "CONTACT_BLACKLIST", "NONE"
60
+ */
61
+ const setPrivacySetting = (feature, setting) =>
62
+ mexQuery({ feature, setting }, PRIVACY_MEX_IDS.SET_SETTING, 'xwa2_privacy_feature_update')
63
+
64
+ /**
65
+ * Update the contact list for a privacy setting.
66
+ */
67
+ const updatePrivacyContactList = (feature, setting, jids) =>
68
+ mexQuery(
69
+ { feature, setting, contacts: jids.map(jid => ({ jid })) },
70
+ PRIVACY_MEX_IDS.UPDATE_CONTACT_LIST,
71
+ 'xwa2_privacy_contact_list_update'
72
+ )
73
+
74
+ /**
75
+ * Fetch the contact list for a privacy setting.
76
+ */
77
+ const getPrivacyContactList = (feature, setting) =>
78
+ mexQuery({ feature, setting }, PRIVACY_MEX_IDS.GET_CONTACT_LIST, 'xwa2_privacy_contact_list')
79
+
80
+ // ── Status / Profile ───────────────────────────────────────────────────
81
+
82
+ /**
83
+ * Update own text status About via MEX.
84
+ */
85
+ const updateTextStatus = (text, emoji = null) => {
86
+ const input = { text }
87
+ if (emoji) input.emoji = { content: emoji }
88
+ return mexQuery({ text_status_input: input }, PRIVACY_MEX_IDS.UPDATE_TEXT_STATUS, 'xwa2_text_status_update')
89
+ }
90
+
91
+ /**
92
+ * Fetch text statuses About for a list of JIDs via MEX.
93
+ */
94
+ const getTextStatusList = (jids, lastUpdateTime = null) => {
95
+ const input = jids.map(jid => ({ jid, last_update_time: lastUpdateTime }))
96
+ return mexQuery({ input }, PRIVACY_MEX_IDS.GET_TEXT_STATUS_LIST, 'xwa2_text_status_list')
97
+ }
98
+
99
+ /**
100
+ * Update own user status string via MEX.
101
+ */
102
+ const updateUserStatus = status =>
103
+ mexQuery({ status }, PRIVACY_MEX_IDS.UPDATE_USER_STATUS, 'xwa2_update_user_status')
104
+
105
+ /**
106
+ * Fetch picture info for a user via MEX.
107
+ */
108
+ const fetchUserPictureInfo = jid =>
109
+ mexQuery({ jid }, PRIVACY_MEX_IDS.FETCH_USER_PICTURE, 'xwa2_fetch_user_picture_info')
110
+
111
+ /**
112
+ * Set own profile picture via MEX.
113
+ */
114
+ const setProfilePictureMex = (imageBase64, type = 'image') =>
115
+ mexQuery(
116
+ { input: { image: imageBase64, type } },
117
+ PRIVACY_MEX_IDS.PROFILE_PICTURE_MUTATION,
118
+ 'xwa2_profile_picture_mutation'
119
+ )
120
+
121
+ // ── Account / Auth ─────────────────────────────────────────────────────
122
+
123
+ /**
124
+ * Mark account as logged-in via MEX.
125
+ */
126
+ const accountLogin = phoneNumber =>
127
+ mexQuery({ input: { phone_number: phoneNumber } }, PRIVACY_MEX_IDS.ACCOUNT_LOGIN, 'xwa2_account_login')
128
+
129
+ /**
130
+ * Mark account as logged-out via MEX.
131
+ */
132
+ const accountLogout = (phoneNumber, enabledBiometric = false) =>
133
+ mexQuery(
134
+ { input: { phone_number: phoneNumber, enabled_biometric: enabledBiometric } },
135
+ PRIVACY_MEX_IDS.ACCOUNT_LOGOUT,
136
+ 'xwa2_account_logout'
137
+ )
138
+
139
+ /**
140
+ * Add a multi-account link via MEX.
141
+ */
142
+ const addMultiAccountLink = phoneNumber =>
143
+ mexQuery(
144
+ { input: { phone_number: phoneNumber } },
145
+ PRIVACY_MEX_IDS.ADD_MULTI_ACCOUNT_LINK,
146
+ 'xwa2_add_multi_account_link'
147
+ )
148
+
149
+ /**
150
+ * Add a trusted device via MEX.
151
+ */
152
+ const addTrustedDevice = (deviceId, deviceName) =>
153
+ mexQuery({ device_id: deviceId, device_name: deviceName }, PRIVACY_MEX_IDS.ADD_TRUSTED_DEVICE, 'xwa2_add_trusted_device')
154
+
155
+ /**
156
+ * Fetch list of trusted devices for the account via MEX.
157
+ */
158
+ const getTrustedDevices = () => mexQuery({}, PRIVACY_MEX_IDS.GET_TRUSTED_DEVICES, 'xwa2_get_trusted_devices')
159
+
160
+ /**
161
+ * Untrust a trusted device via MEX.
162
+ */
163
+ const untrustTrustedDevice = (deviceId, reason = 'USER_INITIATED') =>
164
+ mexQuery(
165
+ { device_id: deviceId, reason },
166
+ PRIVACY_MEX_IDS.UNTRUST_TRUSTED_DEVICE,
167
+ 'xwa2_untrust_trusted_device'
168
+ )
169
+
170
+ /**
171
+ * Delete a trusted device entirely via MEX.
172
+ */
173
+ const deleteTrustedDevice = deviceId =>
174
+ mexQuery({ device_id: deviceId }, PRIVACY_MEX_IDS.DELETE_TRUSTED_DEVICE, 'xwa2_delete_trusted_device')
175
+
176
+ /**
177
+ * Revoke multi-account link for a secondary account via MEX.
178
+ */
179
+ const revokeMultiAccount = accountJid =>
180
+ mexQuery({ account_jid: accountJid }, PRIVACY_MEX_IDS.MULTI_ACCOUNT_REVOKE, 'xwa2_multi_account_revoke')
181
+
182
+ // ── Misc ───────────────────────────────────────────────────────────────
183
+
184
+ /**
185
+ * Fetch mobile config via MEX.
186
+ */
187
+ const fetchMobileConfig = (apiVersion = 0, epRefreshId = 0, flags = '') =>
188
+ mexQuery(
189
+ { api_version: apiVersion, ep_refresh_id: epRefreshId, flags },
190
+ PRIVACY_MEX_IDS.MOBILE_CONFIG_FETCH,
191
+ 'xwa2_mobile_config_fetch'
192
+ )
193
+
194
+ /**
195
+ * Notify group members of your push name via MEX.
196
+ */
197
+ const notifyPushName = (groupJid, participants) =>
198
+ mexQuery(
199
+ {
200
+ input: {
201
+ group_jid: groupJid,
202
+ participants: participants.map(({ jid, pushName }) => ({ jid, push_name: pushName }))
203
+ }
204
+ },
205
+ PRIVACY_MEX_IDS.NOTIFY_PUSH_NAME,
206
+ 'xwa2_notify_push_name'
207
+ )
208
+
209
+ /**
210
+ * Run a contact integrity check via MEX.
211
+ */
212
+ const contactIntegrityQuery = (jids, useCase = 'START_CHAT_CONTEXT') =>
213
+ mexQuery(
214
+ { users: jids.map(jid => ({ jid })), use_case: useCase },
215
+ PRIVACY_MEX_IDS.CONTACT_INTEGRITY,
216
+ 'xwa2_fetch_wa_users'
217
+ )
218
+
219
+ /**
220
+ * Run a business integrity check via MEX.
221
+ */
222
+ const bizIntegrityQuery = jids =>
223
+ mexQuery(
224
+ { users: jids.map(jid => ({ jid })) },
225
+ PRIVACY_MEX_IDS.BIZ_INTEGRITY,
226
+ 'xwa2_fetch_wa_users'
227
+ )
228
+
229
+ /**
230
+ * Set linked social profiles FB IG via MEX.
231
+ */
232
+ const linkedProfilesSet = profiles => {
233
+ const mapped = profiles.map(p => {
234
+ const entry = { type: p.type }
235
+ if (p.vid) entry.vid = p.vid
236
+ else if (p.username) entry.username = p.username
237
+ return entry
238
+ })
239
+ return mexQuery({ profiles: mapped }, PRIVACY_MEX_IDS.LINKED_PROFILES_SET, 'xwa2_linked_profiles_set')
240
+ }
241
+
242
+ /**
243
+ * Remove linked social profiles via MEX.
244
+ */
245
+ const linkedProfilesRemove = types =>
246
+ mexQuery(
247
+ { profiles: types.map(type => ({ type })) },
248
+ PRIVACY_MEX_IDS.LINKED_PROFILES_REMOVE,
249
+ 'xwa2_linked_profiles_remove'
250
+ )
251
+
252
+ /**
253
+ * Update linked social profile visibility settings via MEX.
254
+ */
255
+ const linkedProfilesUpdate = profiles =>
256
+ mexQuery(
257
+ { profiles: profiles.map(({ type, showOnProfile }) => ({ type, show_on_profile: showOnProfile })) },
258
+ PRIVACY_MEX_IDS.LINKED_PROFILES_UPDATE,
259
+ 'xwa2_linked_profiles_update'
260
+ )
261
+
262
+ /**
263
+ * Migrate blocklist to LID addressing via MEX.
264
+ */
265
+ const migrateBlocklistLid = (jids, dhash = '', dirtyAck = true) =>
266
+ mexQuery(
267
+ {
268
+ input: {
269
+ blocklist: jids.map(jid => ({ jid })),
270
+ dhash,
271
+ dirty_ack: dirtyAck
272
+ }
273
+ },
274
+ PRIVACY_MEX_IDS.MIGRATE_BLOCKLIST_LID,
275
+ 'xwa2_migrate_blocklist_lid'
276
+ )
277
+
278
+ /**
279
+ * Scan a QR code via MEX.
280
+ */
281
+ const qrCodeScan = qrData =>
282
+ mexQuery({ qr_data: qrData }, PRIVACY_MEX_IDS.QR_CODE_SCAN, 'xwa2_qr_code_scan')
283
+
284
+ return {
285
+ ...sock,
286
+ // Privacy
287
+ getPrivacySettings,
288
+ setPrivacySetting,
289
+ updatePrivacyContactList,
290
+ getPrivacyContactList,
291
+ // Status / profile
292
+ updateTextStatus,
293
+ getTextStatusList,
294
+ updateUserStatus,
295
+ fetchUserPictureInfo,
296
+ setProfilePictureMex,
297
+ // Account / auth
298
+ accountLogin,
299
+ accountLogout,
300
+ addMultiAccountLink,
301
+ addTrustedDevice,
302
+ getTrustedDevices,
303
+ untrustTrustedDevice,
304
+ deleteTrustedDevice,
305
+ revokeMultiAccount,
306
+ // Misc
307
+ fetchMobileConfig,
308
+ notifyPushName,
309
+ contactIntegrityQuery,
310
+ bizIntegrityQuery,
311
+ linkedProfilesSet,
312
+ linkedProfilesRemove,
313
+ linkedProfilesUpdate,
314
+ migrateBlocklistLid,
315
+ qrCodeScan,
316
+ PRIVACY_MEX_IDS
317
+ }
318
+ }