@bellaxchuu/flowred 0.8.6

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/LICENSE +21 -0
  2. package/README.md +214 -0
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +6902 -0
  5. package/WAProto/fix-imports.js +85 -0
  6. package/WAProto/index.js +242946 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/index.js +190 -0
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Signal/Group/ciphertext-message.js +15 -0
  11. package/lib/Signal/Group/group-session-builder.js +92 -0
  12. package/lib/Signal/Group/group_cipher.js +89 -0
  13. package/lib/Signal/Group/index.js +136 -0
  14. package/lib/Signal/Group/keyhelper.js +73 -0
  15. package/lib/Signal/Group/sender-chain-key.js +32 -0
  16. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  17. package/lib/Signal/Group/sender-key-message.js +69 -0
  18. package/lib/Signal/Group/sender-key-name.js +50 -0
  19. package/lib/Signal/Group/sender-key-record.js +44 -0
  20. package/lib/Signal/Group/sender-key-state.js +97 -0
  21. package/lib/Signal/Group/sender-message-key.js +30 -0
  22. package/lib/Signal/libsignal.js +490 -0
  23. package/lib/Signal/lid-mapping.js +262 -0
  24. package/lib/Socket/Client/index.js +30 -0
  25. package/lib/Socket/Client/types.js +13 -0
  26. package/lib/Socket/Client/websocket.js +62 -0
  27. package/lib/Socket/aigroups.js +240 -0
  28. package/lib/Socket/business.js +422 -0
  29. package/lib/Socket/chats.js +1816 -0
  30. package/lib/Socket/communities.js +549 -0
  31. package/lib/Socket/graphql.js +656 -0
  32. package/lib/Socket/groups.js +764 -0
  33. package/lib/Socket/index.js +39 -0
  34. package/lib/Socket/interactive-handler.js +522 -0
  35. package/lib/Socket/interop.js +549 -0
  36. package/lib/Socket/luxu.js +387 -0
  37. package/lib/Socket/managed-account.js +183 -0
  38. package/lib/Socket/messages-recv.js +2440 -0
  39. package/lib/Socket/messages-send.js +1853 -0
  40. package/lib/Socket/mex.js +60 -0
  41. package/lib/Socket/newsletter.js +820 -0
  42. package/lib/Socket/privacy.js +449 -0
  43. package/lib/Socket/registration.js +427 -0
  44. package/lib/Socket/socket.js +1092 -0
  45. package/lib/Socket/text-router.js +83 -0
  46. package/lib/Socket/username.js +243 -0
  47. package/lib/Store/index.js +36 -0
  48. package/lib/Store/keyed-db.js +108 -0
  49. package/lib/Store/make-cache-manager-store.js +90 -0
  50. package/lib/Store/make-in-memory-store.js +604 -0
  51. package/lib/Store/make-ordered-dictionary.js +81 -0
  52. package/lib/Store/object-repository.js +29 -0
  53. package/lib/Types/Auth.js +38 -0
  54. package/lib/Types/Bussines.js +2 -0
  55. package/lib/Types/Call.js +2 -0
  56. package/lib/Types/Chat.js +4 -0
  57. package/lib/Types/Contact.js +2 -0
  58. package/lib/Types/Events.js +2 -0
  59. package/lib/Types/GroupMetadata.js +2 -0
  60. package/lib/Types/Label.js +27 -0
  61. package/lib/Types/LabelAssociation.js +9 -0
  62. package/lib/Types/Message.js +95 -0
  63. package/lib/Types/Mex.js +112 -0
  64. package/lib/Types/Newsletter.js +121 -0
  65. package/lib/Types/Product.js +2 -0
  66. package/lib/Types/Signal.js +2 -0
  67. package/lib/Types/Socket.js +2 -0
  68. package/lib/Types/State.js +70 -0
  69. package/lib/Types/USync.js +2 -0
  70. package/lib/Types/index.js +55 -0
  71. package/lib/Utils/auth-utils.js +306 -0
  72. package/lib/Utils/browser-utils.js +114 -0
  73. package/lib/Utils/business.js +247 -0
  74. package/lib/Utils/chat-utils.js +1208 -0
  75. package/lib/Utils/command-loader.js +100 -0
  76. package/lib/Utils/companion-reg-client-utils.js +42 -0
  77. package/lib/Utils/consumer-application.js +107 -0
  78. package/lib/Utils/crypto.js +155 -0
  79. package/lib/Utils/curve25519-js.js +275 -0
  80. package/lib/Utils/decode-wa-message.js +560 -0
  81. package/lib/Utils/event-buffer.js +607 -0
  82. package/lib/Utils/generics.js +563 -0
  83. package/lib/Utils/group-history.js +60 -0
  84. package/lib/Utils/history.js +244 -0
  85. package/lib/Utils/identity-change-handler.js +52 -0
  86. package/lib/Utils/index.js +57 -0
  87. package/lib/Utils/jid-display-normalization.js +218 -0
  88. package/lib/Utils/link-preview.js +143 -0
  89. package/lib/Utils/logger.js +9 -0
  90. package/lib/Utils/lt-hash.js +39 -0
  91. package/lib/Utils/make-mutex.js +36 -0
  92. package/lib/Utils/message-composer.js +479 -0
  93. package/lib/Utils/message-retry-manager.js +270 -0
  94. package/lib/Utils/messages-media.js +896 -0
  95. package/lib/Utils/messages.js +2904 -0
  96. package/lib/Utils/meta-ai-msmsg.js +262 -0
  97. package/lib/Utils/native-bridge.js +82 -0
  98. package/lib/Utils/noise-handler.js +196 -0
  99. package/lib/Utils/offline-node-processor.js +42 -0
  100. package/lib/Utils/pre-key-manager.js +107 -0
  101. package/lib/Utils/process-message.js +1048 -0
  102. package/lib/Utils/reporting-utils.js +262 -0
  103. package/lib/Utils/session-pool.js +94 -0
  104. package/lib/Utils/signal.js +224 -0
  105. package/lib/Utils/stanza-ack.js +40 -0
  106. package/lib/Utils/sticker.js +145 -0
  107. package/lib/Utils/sync-action-utils.js +54 -0
  108. package/lib/Utils/tc-token-utils.js +161 -0
  109. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  110. package/lib/Utils/validate-connection.js +219 -0
  111. package/lib/Utils/view-once-cache.js +79 -0
  112. package/lib/Utils/voip-rekey.js +22 -0
  113. package/lib/WABinary/constants.js +1304 -0
  114. package/lib/WABinary/decode.js +343 -0
  115. package/lib/WABinary/encode.js +228 -0
  116. package/lib/WABinary/generic-utils.js +240 -0
  117. package/lib/WABinary/index.js +33 -0
  118. package/lib/WABinary/jid-utils.js +361 -0
  119. package/lib/WABinary/types.js +2 -0
  120. package/lib/WAM/BinaryInfo.js +13 -0
  121. package/lib/WAM/constants.js +39486 -0
  122. package/lib/WAM/encode.js +142 -0
  123. package/lib/WAM/index.js +31 -0
  124. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  125. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  126. package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
  127. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  128. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  129. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
  130. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  131. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  132. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  133. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  134. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  135. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  136. package/lib/WAUSync/Protocols/index.js +39 -0
  137. package/lib/WAUSync/USyncQuery.js +133 -0
  138. package/lib/WAUSync/USyncUser.js +50 -0
  139. package/lib/WAUSync/index.js +31 -0
  140. package/lib/antiban.js +4637 -0
  141. package/lib/index.js +45 -0
  142. package/package.json +107 -0
@@ -0,0 +1,449 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.makePrivacySocket = void 0
4
+
5
+ const { executeWMexQuery } = require('./mex')
6
+
7
+ /**
8
+ * MEX query IDs for privacy, status/profile, account/auth, and misc operations.
9
+ * Source: assets/whatsapp-android-mex_client_persist_ids.json
10
+ */
11
+ 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
+ }
447
+ }
448
+
449
+ exports.makePrivacySocket = makePrivacySocket