@ruthless-imperium/baileys 1.0.2 → 1.0.3
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.
- package/lib/Socket/communities.js +437 -0
- package/lib/Socket/graphql.js +724 -0
- package/lib/Socket/index.js +25 -5
- package/lib/Socket/interop.js +468 -0
- package/lib/Socket/luxu.js +392 -0
- package/lib/Socket/message-builder-core.js +3737 -0
- package/lib/Socket/message-builder.js +561 -0
- package/lib/Socket/messages-send.js +2 -1
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +650 -255
- package/lib/Socket/privacy.js +323 -0
- package/lib/Socket/username.js +241 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/keyed-db.js +113 -0
- package/lib/Store/make-cache-manager-store.js +89 -0
- package/lib/Types/Mex.js +117 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/index.js +4 -1
- package/lib/Utils/message-composer.js +290 -0
- package/lib/Utils/sticker.js +143 -0
- package/lib/Utils/use-sqlite-auth-state.js +168 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +65 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +34 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +44 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +33 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/package.json +11 -48
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __def = (m) => (m && m.__esModule) ? m.default : m;
|
|
4
|
+
const __exportStar = (m, e) => { for (const k in m) if (k !== "default" && !Object.prototype.hasOwnProperty.call(e, k)) e[k] = m[k]; };
|
|
5
|
+
const { executeWMexQuery } = require("./mex.js");
|
|
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
|
+
*/
|
|
55
|
+
const getPrivacySettings = (jid, features = null) => {
|
|
56
|
+
const users = [{ jid, ...(features ? { privacy_features: features } : {}) }]
|
|
57
|
+
return mexQuery({ users }, PRIVACY_MEX_IDS.GET_SETTINGS, 'xwa2_fetch_wa_users')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Set a privacy setting via MEX.
|
|
62
|
+
* Features: "LAST_SEEN", "ONLINE", "PROFILE_PHOTO", "STATUS", "READ_RECEIPTS", "GROUPS", "CALLS", "SCREENSHOT", "LIVE_LOCATION"
|
|
63
|
+
* Settings: "ALL", "CONTACTS", "CONTACT_BLACKLIST", "NONE"
|
|
64
|
+
*/
|
|
65
|
+
const setPrivacySetting = (feature, setting) =>
|
|
66
|
+
mexQuery({ feature, setting }, PRIVACY_MEX_IDS.SET_SETTING, 'xwa2_privacy_feature_update')
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Update the contact list for a privacy setting.
|
|
70
|
+
*/
|
|
71
|
+
const updatePrivacyContactList = (feature, setting, jids) =>
|
|
72
|
+
mexQuery(
|
|
73
|
+
{ feature, setting, contacts: jids.map(jid => ({ jid })) },
|
|
74
|
+
PRIVACY_MEX_IDS.UPDATE_CONTACT_LIST,
|
|
75
|
+
'xwa2_privacy_contact_list_update'
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Fetch the contact list for a privacy setting.
|
|
80
|
+
*/
|
|
81
|
+
const getPrivacyContactList = (feature, setting) =>
|
|
82
|
+
mexQuery({ feature, setting }, PRIVACY_MEX_IDS.GET_CONTACT_LIST, 'xwa2_privacy_contact_list')
|
|
83
|
+
|
|
84
|
+
// ── Status / Profile ───────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Update own text status About via MEX.
|
|
88
|
+
*/
|
|
89
|
+
const updateTextStatus = (text, emoji = null) => {
|
|
90
|
+
const input = { text }
|
|
91
|
+
if (emoji) input.emoji = { content: emoji }
|
|
92
|
+
return mexQuery({ text_status_input: input }, PRIVACY_MEX_IDS.UPDATE_TEXT_STATUS, 'xwa2_text_status_update')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Fetch text statuses About for a list of JIDs via MEX.
|
|
97
|
+
*/
|
|
98
|
+
const getTextStatusList = (jids, lastUpdateTime = null) => {
|
|
99
|
+
const input = jids.map(jid => ({ jid, last_update_time: lastUpdateTime }))
|
|
100
|
+
return mexQuery({ input }, PRIVACY_MEX_IDS.GET_TEXT_STATUS_LIST, 'xwa2_text_status_list')
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Update own user status string via MEX.
|
|
105
|
+
*/
|
|
106
|
+
const updateUserStatus = status =>
|
|
107
|
+
mexQuery({ status }, PRIVACY_MEX_IDS.UPDATE_USER_STATUS, 'xwa2_update_user_status')
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Fetch picture info for a user via MEX.
|
|
111
|
+
*/
|
|
112
|
+
const fetchUserPictureInfo = jid =>
|
|
113
|
+
mexQuery({ jid }, PRIVACY_MEX_IDS.FETCH_USER_PICTURE, 'xwa2_fetch_user_picture_info')
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Set own profile picture via MEX.
|
|
117
|
+
*/
|
|
118
|
+
const setProfilePictureMex = (imageBase64, type = 'image') =>
|
|
119
|
+
mexQuery(
|
|
120
|
+
{ input: { image: imageBase64, type } },
|
|
121
|
+
PRIVACY_MEX_IDS.PROFILE_PICTURE_MUTATION,
|
|
122
|
+
'xwa2_profile_picture_mutation'
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
// ── Account / Auth ─────────────────────────────────────────────────────
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Mark account as logged-in via MEX.
|
|
129
|
+
*/
|
|
130
|
+
const accountLogin = phoneNumber =>
|
|
131
|
+
mexQuery({ input: { phone_number: phoneNumber } }, PRIVACY_MEX_IDS.ACCOUNT_LOGIN, 'xwa2_account_login')
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Mark account as logged-out via MEX.
|
|
135
|
+
*/
|
|
136
|
+
const accountLogout = (phoneNumber, enabledBiometric = false) =>
|
|
137
|
+
mexQuery(
|
|
138
|
+
{ input: { phone_number: phoneNumber, enabled_biometric: enabledBiometric } },
|
|
139
|
+
PRIVACY_MEX_IDS.ACCOUNT_LOGOUT,
|
|
140
|
+
'xwa2_account_logout'
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Add a multi-account link via MEX.
|
|
145
|
+
*/
|
|
146
|
+
const addMultiAccountLink = phoneNumber =>
|
|
147
|
+
mexQuery(
|
|
148
|
+
{ input: { phone_number: phoneNumber } },
|
|
149
|
+
PRIVACY_MEX_IDS.ADD_MULTI_ACCOUNT_LINK,
|
|
150
|
+
'xwa2_add_multi_account_link'
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Add a trusted device via MEX.
|
|
155
|
+
*/
|
|
156
|
+
const addTrustedDevice = (deviceId, deviceName) =>
|
|
157
|
+
mexQuery({ device_id: deviceId, device_name: deviceName }, PRIVACY_MEX_IDS.ADD_TRUSTED_DEVICE, 'xwa2_add_trusted_device')
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Fetch list of trusted devices for the account via MEX.
|
|
161
|
+
*/
|
|
162
|
+
const getTrustedDevices = () => mexQuery({}, PRIVACY_MEX_IDS.GET_TRUSTED_DEVICES, 'xwa2_get_trusted_devices')
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Untrust a trusted device via MEX.
|
|
166
|
+
*/
|
|
167
|
+
const untrustTrustedDevice = (deviceId, reason = 'USER_INITIATED') =>
|
|
168
|
+
mexQuery(
|
|
169
|
+
{ device_id: deviceId, reason },
|
|
170
|
+
PRIVACY_MEX_IDS.UNTRUST_TRUSTED_DEVICE,
|
|
171
|
+
'xwa2_untrust_trusted_device'
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Delete a trusted device entirely via MEX.
|
|
176
|
+
*/
|
|
177
|
+
const deleteTrustedDevice = deviceId =>
|
|
178
|
+
mexQuery({ device_id: deviceId }, PRIVACY_MEX_IDS.DELETE_TRUSTED_DEVICE, 'xwa2_delete_trusted_device')
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Revoke multi-account link for a secondary account via MEX.
|
|
182
|
+
*/
|
|
183
|
+
const revokeMultiAccount = accountJid =>
|
|
184
|
+
mexQuery({ account_jid: accountJid }, PRIVACY_MEX_IDS.MULTI_ACCOUNT_REVOKE, 'xwa2_multi_account_revoke')
|
|
185
|
+
|
|
186
|
+
// ── Misc ───────────────────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Fetch mobile config via MEX.
|
|
190
|
+
*/
|
|
191
|
+
const fetchMobileConfig = (apiVersion = 0, epRefreshId = 0, flags = '') =>
|
|
192
|
+
mexQuery(
|
|
193
|
+
{ api_version: apiVersion, ep_refresh_id: epRefreshId, flags },
|
|
194
|
+
PRIVACY_MEX_IDS.MOBILE_CONFIG_FETCH,
|
|
195
|
+
'xwa2_mobile_config_fetch'
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Notify group members of your push name via MEX.
|
|
200
|
+
*/
|
|
201
|
+
const notifyPushName = (groupJid, participants) =>
|
|
202
|
+
mexQuery(
|
|
203
|
+
{
|
|
204
|
+
input: {
|
|
205
|
+
group_jid: groupJid,
|
|
206
|
+
participants: participants.map(({ jid, pushName }) => ({ jid, push_name: pushName }))
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
PRIVACY_MEX_IDS.NOTIFY_PUSH_NAME,
|
|
210
|
+
'xwa2_notify_push_name'
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Run a contact integrity check via MEX.
|
|
215
|
+
*/
|
|
216
|
+
const contactIntegrityQuery = (jids, useCase = 'START_CHAT_CONTEXT') =>
|
|
217
|
+
mexQuery(
|
|
218
|
+
{ users: jids.map(jid => ({ jid })), use_case: useCase },
|
|
219
|
+
PRIVACY_MEX_IDS.CONTACT_INTEGRITY,
|
|
220
|
+
'xwa2_fetch_wa_users'
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Run a business integrity check via MEX.
|
|
225
|
+
*/
|
|
226
|
+
const bizIntegrityQuery = jids =>
|
|
227
|
+
mexQuery(
|
|
228
|
+
{ users: jids.map(jid => ({ jid })) },
|
|
229
|
+
PRIVACY_MEX_IDS.BIZ_INTEGRITY,
|
|
230
|
+
'xwa2_fetch_wa_users'
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Set linked social profiles FB IG via MEX.
|
|
235
|
+
*/
|
|
236
|
+
const linkedProfilesSet = profiles => {
|
|
237
|
+
const mapped = profiles.map(p => {
|
|
238
|
+
const entry = { type: p.type }
|
|
239
|
+
if (p.vid) entry.vid = p.vid
|
|
240
|
+
else if (p.username) entry.username = p.username
|
|
241
|
+
return entry
|
|
242
|
+
})
|
|
243
|
+
return mexQuery({ profiles: mapped }, PRIVACY_MEX_IDS.LINKED_PROFILES_SET, 'xwa2_linked_profiles_set')
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Remove linked social profiles via MEX.
|
|
248
|
+
*/
|
|
249
|
+
const linkedProfilesRemove = types =>
|
|
250
|
+
mexQuery(
|
|
251
|
+
{ profiles: types.map(type => ({ type })) },
|
|
252
|
+
PRIVACY_MEX_IDS.LINKED_PROFILES_REMOVE,
|
|
253
|
+
'xwa2_linked_profiles_remove'
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Update linked social profile visibility settings via MEX.
|
|
258
|
+
*/
|
|
259
|
+
const linkedProfilesUpdate = profiles =>
|
|
260
|
+
mexQuery(
|
|
261
|
+
{ profiles: profiles.map(({ type, showOnProfile }) => ({ type, show_on_profile: showOnProfile })) },
|
|
262
|
+
PRIVACY_MEX_IDS.LINKED_PROFILES_UPDATE,
|
|
263
|
+
'xwa2_linked_profiles_update'
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Migrate blocklist to LID addressing via MEX.
|
|
268
|
+
*/
|
|
269
|
+
const migrateBlocklistLid = (jids, dhash = '', dirtyAck = true) =>
|
|
270
|
+
mexQuery(
|
|
271
|
+
{
|
|
272
|
+
input: {
|
|
273
|
+
blocklist: jids.map(jid => ({ jid })),
|
|
274
|
+
dhash,
|
|
275
|
+
dirty_ack: dirtyAck
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
PRIVACY_MEX_IDS.MIGRATE_BLOCKLIST_LID,
|
|
279
|
+
'xwa2_migrate_blocklist_lid'
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Scan a QR code via MEX.
|
|
284
|
+
*/
|
|
285
|
+
const qrCodeScan = qrData =>
|
|
286
|
+
mexQuery({ qr_data: qrData }, PRIVACY_MEX_IDS.QR_CODE_SCAN, 'xwa2_qr_code_scan')
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
...sock,
|
|
290
|
+
// Privacy
|
|
291
|
+
getPrivacySettings,
|
|
292
|
+
setPrivacySetting,
|
|
293
|
+
updatePrivacyContactList,
|
|
294
|
+
getPrivacyContactList,
|
|
295
|
+
// Status / profile
|
|
296
|
+
updateTextStatus,
|
|
297
|
+
getTextStatusList,
|
|
298
|
+
updateUserStatus,
|
|
299
|
+
fetchUserPictureInfo,
|
|
300
|
+
setProfilePictureMex,
|
|
301
|
+
// Account / auth
|
|
302
|
+
accountLogin,
|
|
303
|
+
accountLogout,
|
|
304
|
+
addMultiAccountLink,
|
|
305
|
+
addTrustedDevice,
|
|
306
|
+
getTrustedDevices,
|
|
307
|
+
untrustTrustedDevice,
|
|
308
|
+
deleteTrustedDevice,
|
|
309
|
+
revokeMultiAccount,
|
|
310
|
+
// Misc
|
|
311
|
+
fetchMobileConfig,
|
|
312
|
+
notifyPushName,
|
|
313
|
+
contactIntegrityQuery,
|
|
314
|
+
bizIntegrityQuery,
|
|
315
|
+
linkedProfilesSet,
|
|
316
|
+
linkedProfilesRemove,
|
|
317
|
+
linkedProfilesUpdate,
|
|
318
|
+
migrateBlocklistLid,
|
|
319
|
+
qrCodeScan,
|
|
320
|
+
PRIVACY_MEX_IDS
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
exports.makePrivacySocket = makePrivacySocket;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __def = (m) => (m && m.__esModule) ? m.default : m;
|
|
4
|
+
const __exportStar = (m, e) => { for (const k in m) if (k !== "default" && !Object.prototype.hasOwnProperty.call(e, k)) e[k] = m[k]; };
|
|
5
|
+
const { executeWMexQuery } = require("./mex.js");
|
|
6
|
+
const { USyncQuery, USyncUser } = require("../WAUSync/index.js");
|
|
7
|
+
const { makeNewsletterSocket } = require("./newsletter.js");
|
|
8
|
+
const crypto = __def(require("crypto"));
|
|
9
|
+
/**
|
|
10
|
+
* w:mex query IDs for username operations.
|
|
11
|
+
*
|
|
12
|
+
* Source: whatsapp-android-mex_client_persist_ids.json (WA 2.26.26.4 APK assets)
|
|
13
|
+
* Cross-checked: live Frida capture on real device (wa-logger-2.26.26.4.js, 2026-06-30)
|
|
14
|
+
*/
|
|
15
|
+
const USERNAME_QUERY_IDS = {
|
|
16
|
+
CHECK: '26124072630599518', // UsernameCheck
|
|
17
|
+
CHECK_MULTI: '27134626522840286', // UsernameCheckMulti
|
|
18
|
+
SET: '27108705368767936', // UsernameSet
|
|
19
|
+
GET: '32618050064506055', // UsernameGet
|
|
20
|
+
GET_RECOMMENDATIONS: '26077456248616957', // UsernameGetRecommendationsQuery
|
|
21
|
+
PIN_SET: '25529696019976770' // UsernamePinSet
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Source enum values from EnumC141106Vn (UsernameCheck result)
|
|
26
|
+
* and EnumC141056Vi (rejection reasons) confirmed via C164057Wg.java
|
|
27
|
+
*/
|
|
28
|
+
const USERNAME_CHECK_RESULT = {
|
|
29
|
+
SUCCESS: 'SUCCESS',
|
|
30
|
+
INVALID: 'INVALID'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const USERNAME_SOURCE = {
|
|
34
|
+
FB: 'FB',
|
|
35
|
+
IG: 'IG',
|
|
36
|
+
USER_INPUT: 'USER_INPUT',
|
|
37
|
+
SUGGESTION: 'SUGGESTION'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const makeUsernameSocket = config => {
|
|
41
|
+
const sock = makeNewsletterSocket(config)
|
|
42
|
+
const { query, generateMessageTag, executeUSyncQuery } = sock
|
|
43
|
+
|
|
44
|
+
const mexQuery = (variables, queryId, dataPath) =>
|
|
45
|
+
executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Check whether a username is available.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} username - The @username to check (without @)
|
|
51
|
+
* @param {boolean} includeSuggestions - Request alternative suggestions when taken
|
|
52
|
+
* @returns {object}
|
|
53
|
+
* On success: { available: true, username }
|
|
54
|
+
* On taken: { available: false, username, suggestions: string[], rejectionReasons: string[], suggestionsEligible: boolean }
|
|
55
|
+
* On rate-limit: throws Boom with statusCode 429
|
|
56
|
+
*
|
|
57
|
+
* Confirmed fields from C164057Wg.java:
|
|
58
|
+
* data.xwa2_username_check.result → 'SUCCESS' | 'INVALID'
|
|
59
|
+
* data.xwa2_username_check.suggestions
|
|
60
|
+
* data.xwa2_username_check.rejection_reasons
|
|
61
|
+
* data.xwa2_username_check.suggestions_eligible
|
|
62
|
+
*/
|
|
63
|
+
const checkUsername = async (username, includeSuggestions = true, sessionId) => {
|
|
64
|
+
// session_id ties this check to the subsequent set step — caller can pass one in
|
|
65
|
+
// so both use the same UUID (confirmed from live WA 2.26.26.4 capture).
|
|
66
|
+
const session_id = sessionId || crypto.randomUUID()
|
|
67
|
+
const data = await mexQuery(
|
|
68
|
+
{
|
|
69
|
+
username,
|
|
70
|
+
include_suggestions: includeSuggestions,
|
|
71
|
+
session_id,
|
|
72
|
+
source: USERNAME_SOURCE.USER_INPUT
|
|
73
|
+
},
|
|
74
|
+
USERNAME_QUERY_IDS.CHECK,
|
|
75
|
+
'xwa2_username_check'
|
|
76
|
+
)
|
|
77
|
+
if (data?.includes(USERNAME_CHECK_RESULT.SUCCESS) || data?.result === USERNAME_CHECK_RESULT.SUCCESS) {
|
|
78
|
+
return { available: true, username, session_id }
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
available: false,
|
|
82
|
+
username,
|
|
83
|
+
session_id,
|
|
84
|
+
suggestions: data?.suggestions?? [],
|
|
85
|
+
rejectionReasons: data?.rejection_reasons?? [],
|
|
86
|
+
suggestionsEligible: data?.suggestions_eligible?? true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Set your own username.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} username - The username to set (without @)
|
|
94
|
+
* @param {object} options
|
|
95
|
+
* @param {string} [options.source] - 'USER_INPUT' | 'FB' | 'IG' | 'SUGGESTION'
|
|
96
|
+
* @param {string} [options.sessionId] - Optional session tracking ID
|
|
97
|
+
* @param {string} [options.pin] - Optional PIN for protected usernames
|
|
98
|
+
*
|
|
99
|
+
* Confirmed variables from C1568872p.java A00():
|
|
100
|
+
* username, reserved (bool), session_id, source, pin
|
|
101
|
+
*/
|
|
102
|
+
const setUsername = async (username, options = {}) => {
|
|
103
|
+
const { source = USERNAME_SOURCE.USER_INPUT, sessionId, pin } = options
|
|
104
|
+
// session_id links the check and set steps — generate one if caller doesn't supply it.
|
|
105
|
+
// reserved:true confirmed from live WA 2.26.26.4 capture (was wrongly false before).
|
|
106
|
+
const session_id = sessionId || crypto.randomUUID()
|
|
107
|
+
const variables = {
|
|
108
|
+
username,
|
|
109
|
+
reserved: true,
|
|
110
|
+
source,
|
|
111
|
+
session_id,
|
|
112
|
+
...(pin? { pin } : {})
|
|
113
|
+
}
|
|
114
|
+
return mexQuery(variables, USERNAME_QUERY_IDS.SET, 'xwa2_username_set')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const checkAndSetUsername = async (username) => {
|
|
118
|
+
const r = await checkUsername(username);
|
|
119
|
+
if (r.available) {
|
|
120
|
+
return await setUsername(username)
|
|
121
|
+
}
|
|
122
|
+
return r
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Delete (unset) your own username.
|
|
127
|
+
*
|
|
128
|
+
* Confirmed from C1568872p.java:
|
|
129
|
+
* str4 = str == null? "delete" : "set"
|
|
130
|
+
* → sending username=null triggers the delete path on the server.
|
|
131
|
+
*/
|
|
132
|
+
const deleteUsername = async () => {
|
|
133
|
+
return mexQuery({ username: null }, USERNAME_QUERY_IDS.SET, 'xwa2_username_delete')
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get your own current username.
|
|
138
|
+
*
|
|
139
|
+
* Confirmed from C1568872p.java A02():
|
|
140
|
+
* AbstractC41851rT.A0L(AbstractC130045pa.A0T(), C1363664w.class, "UsernameGet", false)
|
|
141
|
+
*/
|
|
142
|
+
const getMyUsername = async () => {
|
|
143
|
+
const data = await mexQuery({}, USERNAME_QUERY_IDS.GET, 'xwa2_username_get')
|
|
144
|
+
return data?.username?? null
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Set or delete the PIN that protects your username.
|
|
149
|
+
*
|
|
150
|
+
* @param {string|null} pin - New PIN, or null to delete the PIN
|
|
151
|
+
*
|
|
152
|
+
* Confirmed from MexUsernamePinProtocolApi.java:
|
|
153
|
+
* operation "UsernamePinSet", variable "pin"
|
|
154
|
+
* pin=null triggers the "delete" path on the server.
|
|
155
|
+
*/
|
|
156
|
+
const setUsernamePin = async pin => {
|
|
157
|
+
// pin=null → delete PIN (server interprets empty/null variables as delete)
|
|
158
|
+
const variables = pin!= null? { pin } : {}
|
|
159
|
+
return mexQuery(variables, USERNAME_QUERY_IDS.PIN_SET, 'xwa2_username_pin_set')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Look up a contact by their @username via USync.
|
|
164
|
+
*
|
|
165
|
+
* Confirmed via USyncContactProtocol.getUserElement():
|
|
166
|
+
* { tag: 'contact', attrs: { username, pin? } }
|
|
167
|
+
*
|
|
168
|
+
* @param {string} username - The username to look up (without @)
|
|
169
|
+
* @param {string} [pin] - Optional PIN if the username is PIN-protected
|
|
170
|
+
* @returns {{ jid, lid?, contact: boolean }|null}
|
|
171
|
+
*/
|
|
172
|
+
const findUserByUsername = async (username, pin) => {
|
|
173
|
+
const usyncQuery = new USyncQuery().withContactProtocol()
|
|
174
|
+
const user = new USyncUser().withUsername(username)
|
|
175
|
+
if (pin) user.withUsernameKey(pin)
|
|
176
|
+
usyncQuery.withUser(user)
|
|
177
|
+
const result = await executeUSyncQuery(usyncQuery)
|
|
178
|
+
if (!result?.list?.length) return null
|
|
179
|
+
const entry = result.list[0]
|
|
180
|
+
return {
|
|
181
|
+
jid: entry.id,
|
|
182
|
+
contact: entry.contact?? false
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Fetch the username of one or more contacts by their JID.
|
|
188
|
+
* Uses USync with the username protocol.
|
|
189
|
+
*
|
|
190
|
+
* @param {...string} jids - One or more JIDs
|
|
191
|
+
* @returns {Array<{ id, username: string|null }>}
|
|
192
|
+
*/
|
|
193
|
+
const fetchContactUsernames = async (...jids) => {
|
|
194
|
+
const usyncQuery = new USyncQuery().withUsernameProtocol()
|
|
195
|
+
for (const jid of jids) {
|
|
196
|
+
usyncQuery.withUser(new USyncUser().withId(jid))
|
|
197
|
+
}
|
|
198
|
+
const result = await executeUSyncQuery(usyncQuery)
|
|
199
|
+
return result?.list?? []
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Check multiple usernames for availability at once.
|
|
204
|
+
* @param {string[]} usernames - Array of usernames (without @)
|
|
205
|
+
*/
|
|
206
|
+
const checkUsernameMulti = async usernames => {
|
|
207
|
+
const data = await mexQuery(
|
|
208
|
+
{ usernames },
|
|
209
|
+
USERNAME_QUERY_IDS.CHECK_MULTI,
|
|
210
|
+
'xwa2_username_check_multi'
|
|
211
|
+
)
|
|
212
|
+
return data
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Fetch username recommendations for the current user.
|
|
217
|
+
* @param {string} [source] - Source hint: 'FB' | 'IG' | 'USER_INPUT'
|
|
218
|
+
*/
|
|
219
|
+
const getUsernameRecommendations = async (source = null) => {
|
|
220
|
+
const variables = {}
|
|
221
|
+
if (source) variables.source = source
|
|
222
|
+
return mexQuery(variables, USERNAME_QUERY_IDS.GET_RECOMMENDATIONS, 'xwa2_username_get_recommendations')
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
...sock,
|
|
227
|
+
checkUsername,
|
|
228
|
+
checkUsernameMulti,
|
|
229
|
+
setUsername,
|
|
230
|
+
deleteUsername,
|
|
231
|
+
getMyUsername,
|
|
232
|
+
getUsernameRecommendations,
|
|
233
|
+
setUsernamePin,
|
|
234
|
+
findUserByUsername,
|
|
235
|
+
fetchContactUsernames,
|
|
236
|
+
USERNAME_QUERY_IDS,
|
|
237
|
+
USERNAME_CHECK_RESULT,
|
|
238
|
+
USERNAME_SOURCE
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.makeUsernameSocket = makeUsernameSocket;
|
package/lib/Store/index.js
CHANGED
|
@@ -3,6 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
|
|
6
7
|
exports.makeInMemoryStore = void 0;
|
|
7
8
|
const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
|
|
8
9
|
exports.makeInMemoryStore = make_in_memory_store_1.default;
|
|
10
|
+
exports.KeyedDB = require("./keyed-db").default;
|
|
11
|
+
exports.makeCacheManagerAuthState = require("./make-cache-manager-store").default;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __def = (m) => (m && m.__esModule) ? m.default : m;
|
|
4
|
+
const __exportStar = (m, e) => { for (const k in m) if (k !== "default" && !Object.prototype.hasOwnProperty.call(e, k)) e[k] = m[k]; };
|
|
5
|
+
class KeyedDB {
|
|
6
|
+
constructor(compareFn, idGetter) {
|
|
7
|
+
if (typeof compareFn !== "function" || typeof idGetter !== "function") {
|
|
8
|
+
throw new Error("KeyedDB requires compare and idGetter functions");
|
|
9
|
+
}
|
|
10
|
+
this._compare = compareFn;
|
|
11
|
+
this._idGetter = idGetter;
|
|
12
|
+
this._array = [];
|
|
13
|
+
this._dict = {};
|
|
14
|
+
}
|
|
15
|
+
get length() {
|
|
16
|
+
return this._array.length;
|
|
17
|
+
}
|
|
18
|
+
get(id) {
|
|
19
|
+
return this._dict[id];
|
|
20
|
+
}
|
|
21
|
+
insert(entry, mode = "insert") {
|
|
22
|
+
const id = this._idGetter(entry);
|
|
23
|
+
const existing = this._dict[id];
|
|
24
|
+
if (existing && mode === "insert") {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
this._dict[id] = entry;
|
|
28
|
+
let inserted = false;
|
|
29
|
+
for (let i = 0; i < this._array.length; i++) {
|
|
30
|
+
const cmp = this._compare(this._idGetter(this._array[i]), id);
|
|
31
|
+
if (cmp < 0) {
|
|
32
|
+
this._array.splice(i, 0, entry);
|
|
33
|
+
inserted = true;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!inserted) this._array.push(entry);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
insertIfAbsent(...entries) {
|
|
41
|
+
const added = [];
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
if (!this._dict[this._idGetter(entry)]) {
|
|
44
|
+
this.insert(entry);
|
|
45
|
+
added.push(entry);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return added;
|
|
49
|
+
}
|
|
50
|
+
upsert(...entries) {
|
|
51
|
+
const added = [];
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
const id = this._idGetter(entry);
|
|
54
|
+
if (this._dict[id]) {
|
|
55
|
+
const idx = this._array.findIndex(e => this._idGetter(e) === id);
|
|
56
|
+
if (idx >= 0) this._array[idx] = entry;
|
|
57
|
+
this._dict[id] = entry;
|
|
58
|
+
} else {
|
|
59
|
+
this.insert(entry);
|
|
60
|
+
added.push(entry);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return added;
|
|
64
|
+
}
|
|
65
|
+
update(id, updater) {
|
|
66
|
+
const item = this._dict[id];
|
|
67
|
+
if (!item) return false;
|
|
68
|
+
updater(item);
|
|
69
|
+
const idx = this._array.findIndex(e => this._idGetter(e) === id);
|
|
70
|
+
if (idx >= 0) this._array[idx] = item;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
updateAssign(id, update) {
|
|
74
|
+
const item = this._dict[id];
|
|
75
|
+
if (!item) return false;
|
|
76
|
+
Object.assign(item, update);
|
|
77
|
+
const idx = this._array.findIndex(e => this._idGetter(e) === id);
|
|
78
|
+
if (idx >= 0) this._array[idx] = item;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
deleteById(id) {
|
|
82
|
+
if (!this._dict[id]) return false;
|
|
83
|
+
delete this._dict[id];
|
|
84
|
+
const idx = this._array.findIndex(e => this._idGetter(e) === id);
|
|
85
|
+
if (idx >= 0) this._array.splice(idx, 1);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
clear() {
|
|
89
|
+
this._array = [];
|
|
90
|
+
this._dict = {};
|
|
91
|
+
}
|
|
92
|
+
all() {
|
|
93
|
+
return [...this._array];
|
|
94
|
+
}
|
|
95
|
+
filter(predicate) {
|
|
96
|
+
this._array = this._array.filter(predicate);
|
|
97
|
+
this._dict = {};
|
|
98
|
+
for (const entry of this._array) {
|
|
99
|
+
this._dict[this._idGetter(entry)] = entry;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
count() {
|
|
103
|
+
return this._array.length;
|
|
104
|
+
}
|
|
105
|
+
toJSON() {
|
|
106
|
+
return this._array;
|
|
107
|
+
}
|
|
108
|
+
fromJSON(array) {
|
|
109
|
+
this.clear();
|
|
110
|
+
for (const entry of array) this.insert(entry);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.default = KeyedDB;
|