@badzz88/baileys 8.5.3 → 8.5.4

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 (110) hide show
  1. package/README.md +1 -1
  2. package/WAProto/WAProto.proto +1256 -75
  3. package/WAProto/index.d.ts +36042 -19649
  4. package/WAProto/index.js +181990 -135645
  5. package/engine-requirements.js +7 -15
  6. package/lib/Defaults/index.js +22 -17
  7. package/lib/Signal/Group/group_cipher.js +5 -5
  8. package/lib/Signal/Group/keyhelper.js +4 -4
  9. package/lib/Signal/Group/sender-chain-key.js +2 -2
  10. package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
  11. package/lib/Signal/Group/sender-key-message.js +3 -3
  12. package/lib/Signal/Group/sender-key-record.js +1 -1
  13. package/lib/Signal/Group/sender-message-key.js +5 -5
  14. package/lib/Signal/libsignal.js +39 -59
  15. package/lib/Signal/lid-mapping.js +28 -10
  16. package/lib/Socket/aigroups.js +5 -5
  17. package/lib/Socket/business.js +3 -11
  18. package/lib/Socket/chats.js +668 -319
  19. package/lib/Socket/communities.js +85 -89
  20. package/lib/Socket/graphql.js +435 -228
  21. package/lib/Socket/groups.js +132 -211
  22. package/lib/Socket/index.js +9 -7
  23. package/lib/Socket/interactive-handler.js +117 -60
  24. package/lib/Socket/interop.js +56 -175
  25. package/lib/Socket/managed-account.js +79 -48
  26. package/lib/Socket/messages-recv.js +898 -340
  27. package/lib/Socket/messages-send.js +462 -160
  28. package/lib/Socket/mex.js +40 -53
  29. package/lib/Socket/newsletter.js +291 -295
  30. package/lib/Socket/privacy.js +77 -265
  31. package/lib/Socket/registration.js +164 -157
  32. package/lib/Socket/socket.js +181 -199
  33. package/lib/Socket/username.js +144 -227
  34. package/lib/Store/make-cache-manager-store.js +2 -2
  35. package/lib/Store/make-in-memory-store.js +25 -141
  36. package/lib/Types/Auth.js +3 -3
  37. package/lib/Types/Label.js +1 -1
  38. package/lib/Types/LabelAssociation.js +1 -1
  39. package/lib/Types/Newsletter.js +96 -65
  40. package/lib/Types/State.js +4 -4
  41. package/lib/Types/index.js +1 -1
  42. package/lib/Utils/auth-utils.js +52 -57
  43. package/lib/Utils/browser-utils.js +1 -1
  44. package/lib/Utils/business.js +2 -6
  45. package/lib/Utils/chat-utils.js +102 -38
  46. package/lib/Utils/crypto.js +54 -84
  47. package/lib/Utils/decode-wa-message.js +316 -83
  48. package/lib/Utils/event-buffer.js +37 -61
  49. package/lib/Utils/generics.js +157 -103
  50. package/lib/Utils/group-history.js +3 -12
  51. package/lib/Utils/history.js +15 -15
  52. package/lib/Utils/index.js +1 -5
  53. package/lib/Utils/link-preview.js +3 -8
  54. package/lib/Utils/lt-hash.js +2 -35
  55. package/lib/Utils/make-mutex.js +1 -1
  56. package/lib/Utils/message-inspect.js +393 -0
  57. package/lib/Utils/message-retry-manager.js +27 -92
  58. package/lib/Utils/messages-media.js +159 -130
  59. package/lib/Utils/messages.js +144 -566
  60. package/lib/Utils/meta-ai-msmsg.js +62 -202
  61. package/lib/Utils/noise-handler.js +19 -21
  62. package/lib/Utils/offline-node-processor.js +3 -8
  63. package/lib/Utils/pre-key-manager.js +13 -23
  64. package/lib/Utils/process-message.js +197 -106
  65. package/lib/Utils/reporting-utils.js +2 -2
  66. package/lib/Utils/signal.js +28 -63
  67. package/lib/Utils/stanza-ack.js +39 -12
  68. package/lib/Utils/sync-action-utils.js +4 -7
  69. package/lib/Utils/tc-token-utils.js +20 -25
  70. package/lib/Utils/use-multi-file-auth-state.js +30 -14
  71. package/lib/Utils/validate-connection.js +59 -19
  72. package/lib/WABinary/decode.js +50 -16
  73. package/lib/WABinary/encode.js +54 -224
  74. package/lib/WABinary/generic-utils.js +7 -97
  75. package/lib/WABinary/jid-utils.js +27 -14
  76. package/lib/WAM/encode.js +7 -7
  77. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +58 -1
  78. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -1
  79. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +13 -5
  80. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -4
  81. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +20 -7
  82. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +865 -0
  83. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +1 -1
  84. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +2 -2
  85. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -2
  86. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +1 -1
  87. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -1
  88. package/lib/WAUSync/Protocols/index.js +1 -0
  89. package/lib/WAUSync/USyncBackoff.js +26 -0
  90. package/lib/WAUSync/USyncQuery.js +77 -6
  91. package/lib/WAUSync/USyncUser.js +16 -8
  92. package/lib/WAUSync/index.js +1 -0
  93. package/lib/antiban.js +608 -854
  94. package/lib/index.js +1 -1
  95. package/package.json +16 -20
  96. package/lib/Socket/luxu.js +0 -387
  97. package/lib/Socket/text-router.js +0 -83
  98. package/lib/Store/keyed-db.js +0 -108
  99. package/lib/Types/Mex.js +0 -112
  100. package/lib/Utils/command-loader.d.ts +0 -31
  101. package/lib/Utils/command-loader.js +0 -100
  102. package/lib/Utils/companion-reg-client-utils.js +0 -42
  103. package/lib/Utils/curve25519-js.js +0 -275
  104. package/lib/Utils/native-bridge.js +0 -82
  105. package/lib/Utils/session-pool.d.ts +0 -16
  106. package/lib/Utils/session-pool.js +0 -94
  107. package/lib/Utils/sticker.d.ts +0 -17
  108. package/lib/Utils/sticker.js +0 -145
  109. package/lib/Utils/view-once-cache.d.ts +0 -9
  110. package/lib/Utils/view-once-cache.js +0 -79
@@ -2,242 +2,159 @@
2
2
  Object.defineProperty(exports, '__esModule', { value: true })
3
3
  exports.makeUsernameSocket = void 0
4
4
 
5
- const { executeWMexQuery } = require('./mex.js')
6
- const { USyncQuery, USyncUser } = require('../WAUSync/index.js')
7
- const { makeNewsletterSocket } = require('./newsletter.js')
8
- const crypto = 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
- */
5
+ const { executeWMexQuery } = require('./mex')
6
+ const { USyncQuery, USyncUser } = require('../WAUSync')
7
+ const { makeNewsletterSocket } = require('../WAUSync/Protocols/USyncNewsletterProtocol')
8
+
9
+
15
10
  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
11
+ CHECK: '26124072630599518',
12
+ CHECK_MULTI: '27134626522840286',
13
+ SET: '27108705368767936',
14
+ GET: '32618050064506055',
15
+ GET_RECOMMENDATIONS: '26077456248616957',
16
+ PIN_SET: '25529696019976770'
22
17
  }
23
18
 
24
- /**
25
- * Source enum values from EnumC141106Vn (UsernameCheck result)
26
- * and EnumC141056Vi (rejection reasons) confirmed via C164057Wg.java
27
- */
19
+
28
20
  const USERNAME_CHECK_RESULT = {
29
- SUCCESS: 'SUCCESS',
30
- INVALID: 'INVALID'
21
+ SUCCESS: 'SUCCESS',
22
+ INVALID: 'INVALID'
31
23
  }
32
24
 
33
25
  const USERNAME_SOURCE = {
34
- FB: 'FB',
35
- IG: 'IG',
36
- USER_INPUT: 'USER_INPUT',
37
- SUGGESTION: 'SUGGESTION'
26
+ FB: 'FB',
27
+ IG: 'IG',
28
+ USER_INPUT: 'USER_INPUT',
29
+ SUGGESTION: 'SUGGESTION'
38
30
  }
39
31
 
40
32
  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
- checkAndSetUsername,
237
- USERNAME_QUERY_IDS,
238
- USERNAME_CHECK_RESULT,
239
- USERNAME_SOURCE
240
- }
33
+ const sock = makeNewsletterSocket(config)
34
+ const { query, generateMessageTag, executeUSyncQuery } = sock
35
+
36
+ const mexQuery = (variables, queryId, dataPath) =>
37
+ executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
38
+
39
+
40
+ const checkUsername = async (username, includeSuggestions = true, sessionId) => {
41
+
42
+
43
+ const session_id = sessionId || require('crypto').randomUUID()
44
+ const data = await mexQuery(
45
+ {
46
+ username,
47
+ include_suggestions: includeSuggestions,
48
+ session_id,
49
+ source: USERNAME_SOURCE.USER_INPUT
50
+ },
51
+ USERNAME_QUERY_IDS.CHECK,
52
+ 'xwa2_username_check'
53
+ )
54
+ if (data?.result === USERNAME_CHECK_RESULT.SUCCESS) {
55
+ return { available: true, username, session_id }
56
+ }
57
+ return {
58
+ available: false,
59
+ username,
60
+ session_id,
61
+ suggestions: data?.suggestions ?? [],
62
+ rejectionReasons: data?.rejection_reasons ?? [],
63
+ suggestionsEligible: data?.suggestions_eligible ?? true
64
+ }
65
+ }
66
+
67
+
68
+ const setUsername = async (username, options = {}) => {
69
+ const { source = USERNAME_SOURCE.USER_INPUT, sessionId, pin } = options
70
+
71
+
72
+ const session_id = sessionId || require('crypto').randomUUID()
73
+ const variables = {
74
+ username,
75
+ reserved: true,
76
+ source,
77
+ session_id,
78
+ ...(pin ? { pin } : {})
79
+ }
80
+ return mexQuery(variables, USERNAME_QUERY_IDS.SET, 'xwa2_username_set')
81
+ }
82
+
83
+
84
+ const deleteUsername = async () => {
85
+ return mexQuery({ username: null }, USERNAME_QUERY_IDS.SET, 'xwa2_username_delete')
86
+ }
87
+
88
+
89
+ const getMyUsername = async () => {
90
+ const data = await mexQuery({}, USERNAME_QUERY_IDS.GET, 'xwa2_username_get')
91
+ return data?.username ?? null
92
+ }
93
+
94
+
95
+ const setUsernamePin = async pin => {
96
+
97
+ const variables = pin != null ? { pin } : {}
98
+ return mexQuery(variables, USERNAME_QUERY_IDS.PIN_SET, 'xwa2_username_pin_set')
99
+ }
100
+
101
+
102
+ const findUserByUsername = async (username, pin) => {
103
+ const usyncQuery = new USyncQuery().withContactProtocol()
104
+ const user = new USyncUser().withUsername(username)
105
+ if (pin) user.withUsernameKey(pin)
106
+ usyncQuery.withUser(user)
107
+ const result = await executeUSyncQuery(usyncQuery)
108
+ if (!result?.list?.length) return null
109
+ const entry = result.list[0]
110
+ return {
111
+ jid: entry.id,
112
+ contact: entry.contact ?? false
113
+ }
114
+ }
115
+
116
+
117
+ const fetchContactUsernames = async (...jids) => {
118
+ const usyncQuery = new USyncQuery().withUsernameProtocol()
119
+ for (const jid of jids) {
120
+ usyncQuery.withUser(new USyncUser().withId(jid))
121
+ }
122
+ const result = await executeUSyncQuery(usyncQuery)
123
+ return result?.list ?? []
124
+ }
125
+
126
+
127
+ const checkUsernameMulti = async usernames => {
128
+ const data = await mexQuery(
129
+ { usernames },
130
+ USERNAME_QUERY_IDS.CHECK_MULTI,
131
+ 'xwa2_username_check_multi'
132
+ )
133
+ return data
134
+ }
135
+
136
+
137
+ const getUsernameRecommendations = async (source = null) => {
138
+ const variables = {}
139
+ if (source) variables.source = source
140
+ return mexQuery(variables, USERNAME_QUERY_IDS.GET_RECOMMENDATIONS, 'xwa2_username_get_recommendations')
141
+ }
142
+
143
+ return {
144
+ ...sock,
145
+ checkUsername,
146
+ checkUsernameMulti,
147
+ setUsername,
148
+ deleteUsername,
149
+ getMyUsername,
150
+ getUsernameRecommendations,
151
+ setUsernamePin,
152
+ findUserByUsername,
153
+ fetchContactUsernames,
154
+ USERNAME_QUERY_IDS,
155
+ USERNAME_CHECK_RESULT,
156
+ USERNAME_SOURCE
157
+ }
241
158
  }
242
159
 
243
- exports.makeUsernameSocket = makeUsernameSocket
160
+ exports.makeUsernameSocket = makeUsernameSocket
@@ -19,7 +19,7 @@ const makeCacheManagerAuthState = async (store, sessionKey) => {
19
19
  const writeData = async (file, data) => {
20
20
  let ttl = undefined
21
21
  if (file === 'creds') {
22
- ttl = 63115200 // 2 years
22
+ ttl = 63115200
23
23
  }
24
24
  await databaseConn.set(defaultKey(file), JSON.stringify(data, Utils_1.BufferJSON.replacer), ttl)
25
25
  }
@@ -71,7 +71,7 @@ const makeCacheManagerAuthState = async (store, sessionKey) => {
71
71
  return data
72
72
  },
73
73
  set: async data => {
74
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+
75
75
  const tasks = []
76
76
  for (const category in data) {
77
77
  for (const id in data[category]) {