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