@celestial-community/baileys 0.0.1-security → 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.

Potentially problematic release.


This version of @celestial-community/baileys might be problematic. Click here for more details.

Files changed (175) hide show
  1. package/WAProto/index.js +138933 -0
  2. package/engine-requirements.js +10 -0
  3. package/lib/Defaults/baileys-version.json +7 -0
  4. package/lib/Defaults/index.js +157 -0
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +15 -0
  7. package/lib/Signal/Group/group-session-builder.js +94 -0
  8. package/lib/Signal/Group/group_cipher.js +118 -0
  9. package/lib/Signal/Group/index.js +138 -0
  10. package/lib/Signal/Group/keyhelper.js +75 -0
  11. package/lib/Signal/Group/queue-job.js +54 -0
  12. package/lib/Signal/Group/sender-chain-key.js +39 -0
  13. package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
  14. package/lib/Signal/Group/sender-key-message.js +76 -0
  15. package/lib/Signal/Group/sender-key-name.js +50 -0
  16. package/lib/Signal/Group/sender-key-record.js +65 -0
  17. package/lib/Signal/Group/sender-key-state.js +114 -0
  18. package/lib/Signal/Group/sender-message-key.js +33 -0
  19. package/lib/Signal/libsignal.js +204 -0
  20. package/lib/Signal/lid-mapping.js +267 -0
  21. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  22. package/lib/Socket/Client/index.js +32 -0
  23. package/lib/Socket/Client/mobile-socket-client.js +82 -0
  24. package/lib/Socket/Client/web-socket-client.js +89 -0
  25. package/lib/Socket/Denzy-ZeroDay.js +805 -0
  26. package/lib/Socket/business.js +279 -0
  27. package/lib/Socket/chats.js +1169 -0
  28. package/lib/Socket/community.d.ts +120 -0
  29. package/lib/Socket/community.js +388 -0
  30. package/lib/Socket/graphql.js +1122 -0
  31. package/lib/Socket/groups.js +345 -0
  32. package/lib/Socket/index.js +22 -0
  33. package/lib/Socket/interop.js +265 -0
  34. package/lib/Socket/lid-mapping.js +111 -0
  35. package/lib/Socket/messages-recv.js +1385 -0
  36. package/lib/Socket/messages-send.js +956 -0
  37. package/lib/Socket/mex.js +69 -0
  38. package/lib/Socket/newsletter.js +424 -0
  39. package/lib/Socket/privacy.js +229 -0
  40. package/lib/Socket/registration.js +190 -0
  41. package/lib/Socket/socket.js +783 -0
  42. package/lib/Socket/username.d.ts +185 -0
  43. package/lib/Socket/username.js +168 -0
  44. package/lib/Socket/usync.js +80 -0
  45. package/lib/Store/index.js +14 -0
  46. package/lib/Store/keyed-db.js +158 -0
  47. package/lib/Store/make-cache-manager-store.js +88 -0
  48. package/lib/Store/make-in-memory-store.js +484 -0
  49. package/lib/Store/make-ordered-dictionary.js +78 -0
  50. package/lib/Store/object-repository.js +27 -0
  51. package/lib/Types/Auth.js +2 -0
  52. package/lib/Types/Call.js +2 -0
  53. package/lib/Types/Chat.js +10 -0
  54. package/lib/Types/Contact.js +2 -0
  55. package/lib/Types/Events.js +2 -0
  56. package/lib/Types/GroupMetadata.js +2 -0
  57. package/lib/Types/Label.js +27 -0
  58. package/lib/Types/LabelAssociation.js +9 -0
  59. package/lib/Types/Message.js +14 -0
  60. package/lib/Types/MexUpdates.js +19 -0
  61. package/lib/Types/Newsletter.js +38 -0
  62. package/lib/Types/Product.js +2 -0
  63. package/lib/Types/RichType.js +30 -0
  64. package/lib/Types/Signal.js +2 -0
  65. package/lib/Types/Socket.js +2 -0
  66. package/lib/Types/State.js +2 -0
  67. package/lib/Types/USync.js +2 -0
  68. package/lib/Types/index.js +58 -0
  69. package/lib/Utils/anti-ban.js +339 -0
  70. package/lib/Utils/anti-delete.d.ts +158 -0
  71. package/lib/Utils/anti-delete.js +293 -0
  72. package/lib/Utils/antiban-presets.js +91 -0
  73. package/lib/Utils/antiban-profiles.js +43 -0
  74. package/lib/Utils/auth-utils.js +210 -0
  75. package/lib/Utils/baileys-event-stream.js +66 -0
  76. package/lib/Utils/browser-utils.js +52 -0
  77. package/lib/Utils/business.js +261 -0
  78. package/lib/Utils/chat-control.d.ts +113 -0
  79. package/lib/Utils/chat-control.js +230 -0
  80. package/lib/Utils/chat-utils.js +922 -0
  81. package/lib/Utils/companion-reg-client-utils.js +37 -0
  82. package/lib/Utils/contact-graph-warmer.js +208 -0
  83. package/lib/Utils/crypto.js +196 -0
  84. package/lib/Utils/decode-wa-message.js +208 -0
  85. package/lib/Utils/delivery-tracker.js +110 -0
  86. package/lib/Utils/device-fingerprint.js +135 -0
  87. package/lib/Utils/event-buffer.js +531 -0
  88. package/lib/Utils/generics.js +571 -0
  89. package/lib/Utils/group-operation-guard.js +147 -0
  90. package/lib/Utils/health-monitor.js +207 -0
  91. package/lib/Utils/history.js +122 -0
  92. package/lib/Utils/human-entropy.js +226 -0
  93. package/lib/Utils/identity-change-handler.js +72 -0
  94. package/lib/Utils/index.js +83 -0
  95. package/lib/Utils/interactive-message.d.ts +139 -0
  96. package/lib/Utils/interactive-message.js +273 -0
  97. package/lib/Utils/legitimacy-signal-injector.js +180 -0
  98. package/lib/Utils/link-preview.js +106 -0
  99. package/lib/Utils/logger.d.ts +13 -0
  100. package/lib/Utils/logger.js +9 -0
  101. package/lib/Utils/lt-hash.js +54 -0
  102. package/lib/Utils/make-mutex.js +41 -0
  103. package/lib/Utils/message-composer.d.ts +106 -0
  104. package/lib/Utils/message-composer.js +721 -0
  105. package/lib/Utils/message-retry-manager.d.ts +88 -0
  106. package/lib/Utils/message-retry-manager.js +160 -0
  107. package/lib/Utils/message-search.d.ts +52 -0
  108. package/lib/Utils/message-search.js +226 -0
  109. package/lib/Utils/messages-media.js +899 -0
  110. package/lib/Utils/messages.js +2698 -0
  111. package/lib/Utils/noise-handler.js +175 -0
  112. package/lib/Utils/offline-node-processor.js +45 -0
  113. package/lib/Utils/pre-key-manager.js +131 -0
  114. package/lib/Utils/presence-choreographer.js +438 -0
  115. package/lib/Utils/process-message.js +423 -0
  116. package/lib/Utils/rate-limiter.js +232 -0
  117. package/lib/Utils/reconnect-throttle.js +157 -0
  118. package/lib/Utils/reply-ratio-guard.js +137 -0
  119. package/lib/Utils/reporting-utils.js +307 -0
  120. package/lib/Utils/retry-reason-tracker.js +140 -0
  121. package/lib/Utils/rich-message-utils.d.ts +48 -0
  122. package/lib/Utils/rich-message-utils.js +400 -0
  123. package/lib/Utils/rich-response-utils.js +461 -0
  124. package/lib/Utils/scheduling.d.ts +135 -0
  125. package/lib/Utils/scheduling.js +246 -0
  126. package/lib/Utils/session-fingerprint.js +226 -0
  127. package/lib/Utils/session-stability.js +224 -0
  128. package/lib/Utils/signal.js +188 -0
  129. package/lib/Utils/stanza-ack.js +38 -0
  130. package/lib/Utils/state-manager.js +91 -0
  131. package/lib/Utils/status-posting.d.ts +81 -0
  132. package/lib/Utils/status-posting.js +187 -0
  133. package/lib/Utils/stealth-connect.js +124 -0
  134. package/lib/Utils/sync-action-utils.js +55 -0
  135. package/lib/Utils/tc-token-utils.js +171 -0
  136. package/lib/Utils/templates.d.ts +54 -0
  137. package/lib/Utils/templates.js +244 -0
  138. package/lib/Utils/timelock-guard.js +162 -0
  139. package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
  140. package/lib/Utils/use-mongo-file-auth-state.js +81 -0
  141. package/lib/Utils/use-multi-file-auth-state.js +125 -0
  142. package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
  143. package/lib/Utils/use-single-file-auth-state.js +86 -0
  144. package/lib/Utils/use-sqlite-auth-state.js +187 -0
  145. package/lib/Utils/vCard.d.ts +71 -0
  146. package/lib/Utils/vCard.js +196 -0
  147. package/lib/Utils/validate-connection.js +253 -0
  148. package/lib/Utils/warmup.js +154 -0
  149. package/lib/WABinary/constants.js +1303 -0
  150. package/lib/WABinary/decode.js +270 -0
  151. package/lib/WABinary/encode.js +279 -0
  152. package/lib/WABinary/generic-utils.js +223 -0
  153. package/lib/WABinary/index.js +34 -0
  154. package/lib/WABinary/jid-utils.js +84 -0
  155. package/lib/WABinary/types.js +2 -0
  156. package/lib/WAM/BinaryInfo.js +13 -0
  157. package/lib/WAM/constants.js +15254 -0
  158. package/lib/WAM/encode.js +149 -0
  159. package/lib/WAM/index.js +32 -0
  160. package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
  161. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
  162. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
  163. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
  164. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
  165. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
  166. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  167. package/lib/WAUSync/Protocols/index.js +34 -0
  168. package/lib/WAUSync/USyncQuery.js +99 -0
  169. package/lib/WAUSync/USyncUser.js +26 -0
  170. package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
  171. package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
  172. package/lib/WAUSync/index.js +32 -0
  173. package/lib/index.js +59 -0
  174. package/package.json +105 -5
  175. package/README.md +0 -5
@@ -0,0 +1,345 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.extractGroupMetadata = exports.makeGroupsSocket = void 0
4
+ const WAProto_1 = require('../../WAProto')
5
+ const Types_1 = require('../Types')
6
+ const Utils_1 = require('../Utils')
7
+ const WABinary_1 = require('../WABinary')
8
+ const chats_1 = require('./chats')
9
+ const WAUSync_1 = require('../WAUSync')
10
+ const makeGroupsSocket = (config) => {
11
+ const sock = (0, chats_1.makeChatsSocket)(config)
12
+ const { authState, ev, query, upsertMessage } = sock
13
+ const groupQuery = async (jid, type, content) =>
14
+ query({
15
+ tag: 'iq',
16
+ attrs: {
17
+ type,
18
+ xmlns: 'w:g2',
19
+ to: jid
20
+ },
21
+ content
22
+ })
23
+ const groupMetadata = async (jid) => {
24
+ const result = await groupQuery(jid, 'get', [
25
+ { tag: 'query', attrs: { request: 'interactive' } }
26
+ ])
27
+ return (0, exports.extractGroupMetadata)(result)
28
+ }
29
+ const groupFetchAllParticipating = async () => {
30
+ const result = await query({
31
+ tag: 'iq',
32
+ attrs: {
33
+ to: '@g.us',
34
+ xmlns: 'w:g2',
35
+ type: 'get'
36
+ },
37
+ content: [
38
+ {
39
+ tag: 'participating',
40
+ attrs: {},
41
+ content: [
42
+ { tag: 'participants', attrs: {} },
43
+ { tag: 'description', attrs: {} }
44
+ ]
45
+ }
46
+ ]
47
+ })
48
+ const data = {}
49
+ const groupsChild = (0, WABinary_1.getBinaryNodeChild)(result, 'groups')
50
+ if (groupsChild) {
51
+ const groups = (0, WABinary_1.getBinaryNodeChildren)(groupsChild, 'group')
52
+ for (const groupNode of groups) {
53
+ const meta = (0, exports.extractGroupMetadata)({
54
+ tag: 'result',
55
+ attrs: {},
56
+ content: [groupNode]
57
+ })
58
+ data[meta.id] = meta
59
+ }
60
+ }
61
+ sock.ev.emit('groups.update', Object.values(data))
62
+ return data
63
+ }
64
+ sock.ws.on('CB:ib,,dirty', async (node) => {
65
+ const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty')
66
+ if (attrs.type !== 'groups') {
67
+ return
68
+ }
69
+ await groupFetchAllParticipating()
70
+ await sock.cleanDirtyBits('groups')
71
+ })
72
+ return {
73
+ ...sock,
74
+ groupMetadata,
75
+ groupCreate: async (subject, participants) => {
76
+ const key = (0, Utils_1.generateMessageID)()
77
+ const result = await groupQuery('@g.us', 'set', [
78
+ {
79
+ tag: 'create',
80
+ attrs: {
81
+ subject,
82
+ key
83
+ },
84
+ content: participants.map((jid) => ({
85
+ tag: 'participant',
86
+ attrs: { jid }
87
+ }))
88
+ }
89
+ ])
90
+ return (0, exports.extractGroupMetadata)(result)
91
+ },
92
+ groupLeave: async (id) => {
93
+ await groupQuery('@g.us', 'set', [
94
+ {
95
+ tag: 'leave',
96
+ attrs: {},
97
+ content: [{ tag: 'group', attrs: { id } }]
98
+ }
99
+ ])
100
+ },
101
+ groupUpdateSubject: async (jid, subject) => {
102
+ await groupQuery(jid, 'set', [
103
+ {
104
+ tag: 'subject',
105
+ attrs: {},
106
+ content: Buffer.from(subject, 'utf-8')
107
+ }
108
+ ])
109
+ },
110
+ groupRequestParticipantsList: async (jid) => {
111
+ const result = await groupQuery(jid, 'get', [
112
+ {
113
+ tag: 'membership_approval_requests',
114
+ attrs: {}
115
+ }
116
+ ])
117
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests')
118
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(
119
+ node,
120
+ 'membership_approval_request'
121
+ )
122
+ return participants.map((v) => v.attrs)
123
+ },
124
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
125
+ const result = await groupQuery(jid, 'set', [
126
+ {
127
+ tag: 'membership_requests_action',
128
+ attrs: {},
129
+ content: [
130
+ {
131
+ tag: action,
132
+ attrs: {},
133
+ content: participants.map((jid) => ({
134
+ tag: 'participant',
135
+ attrs: { jid }
136
+ }))
137
+ }
138
+ ]
139
+ }
140
+ ])
141
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action')
142
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action)
143
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(
144
+ nodeAction,
145
+ 'participant'
146
+ )
147
+ return participantsAffected.map((p) => {
148
+ return { status: p.attrs.error || '200', jid: p.attrs.jid }
149
+ })
150
+ },
151
+ groupParticipantsUpdate: async (jid, participants, action) => {
152
+ const result = await groupQuery(jid, 'set', [
153
+ {
154
+ tag: action,
155
+ attrs: {},
156
+ content: participants.map((jid) => ({
157
+ tag: 'participant',
158
+ attrs: { jid }
159
+ }))
160
+ }
161
+ ])
162
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action)
163
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant')
164
+ return participantsAffected.map((p) => {
165
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
166
+ })
167
+ },
168
+ groupUpdateDescription: async (jid, description) => {
169
+ var _a
170
+ const metadata = await groupMetadata(jid)
171
+ const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null
172
+ await groupQuery(jid, 'set', [
173
+ {
174
+ tag: 'description',
175
+ attrs: {
176
+ ...(description
177
+ ? { id: (0, Utils_1.generateMessageID)() }
178
+ : { delete: 'true' }),
179
+ ...(prev ? { prev } : {})
180
+ },
181
+ content: description
182
+ ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }]
183
+ : undefined
184
+ }
185
+ ])
186
+ },
187
+ groupInviteCode: async (jid) => {
188
+ const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
189
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite')
190
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code
191
+ },
192
+ groupRevokeInvite: async (jid) => {
193
+ const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
194
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite')
195
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code
196
+ },
197
+ groupAcceptInvite: async (code) => {
198
+ const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
199
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group')
200
+ return result === null || result === void 0 ? void 0 : result.attrs.jid
201
+ },
202
+ /**
203
+ * accept a GroupInviteMessage
204
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
205
+ * @param inviteMessage the message to accept
206
+ */
207
+ groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
208
+ key = typeof key === 'string' ? { remoteJid: key } : key
209
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
210
+ {
211
+ tag: 'accept',
212
+ attrs: {
213
+ code: inviteMessage.inviteCode,
214
+ expiration: inviteMessage.inviteExpiration.toString(),
215
+ admin: key.remoteJid
216
+ }
217
+ }
218
+ ])
219
+ // if we have the full message key
220
+ // update the invite message to be expired
221
+ if (key.id) {
222
+ // create new invite message that is expired
223
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
224
+ inviteMessage.inviteExpiration = 0
225
+ inviteMessage.inviteCode = ''
226
+ ev.emit('messages.update', [
227
+ {
228
+ key,
229
+ update: {
230
+ message: {
231
+ groupInviteMessage: inviteMessage
232
+ }
233
+ }
234
+ }
235
+ ])
236
+ }
237
+ // generate the group add message
238
+ await upsertMessage(
239
+ {
240
+ key: {
241
+ remoteJid: inviteMessage.groupJid,
242
+ id: (0, Utils_1.generateMessageID)(),
243
+ fromMe: false,
244
+ participant: key.remoteJid
245
+ },
246
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
247
+ messageStubParameters: [authState.creds.me.id],
248
+ participant: key.remoteJid,
249
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
250
+ },
251
+ 'notify'
252
+ )
253
+ return results.attrs.from
254
+ }),
255
+ groupGetInviteInfo: async (code) => {
256
+ const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
257
+ return (0, exports.extractGroupMetadata)(results)
258
+ },
259
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
260
+ const content = ephemeralExpiration
261
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
262
+ : { tag: 'not_ephemeral', attrs: {} }
263
+ await groupQuery(jid, 'set', [content])
264
+ },
265
+ groupSettingUpdate: async (jid, setting) => {
266
+ await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }])
267
+ },
268
+ groupMemberAddMode: async (jid, mode) => {
269
+ await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
270
+ },
271
+ groupJoinApprovalMode: async (jid, mode) => {
272
+ await groupQuery(jid, 'set', [
273
+ {
274
+ tag: 'membership_approval_mode',
275
+ attrs: {},
276
+ content: [{ tag: 'group_join', attrs: { state: mode } }]
277
+ }
278
+ ])
279
+ },
280
+ groupFetchAllParticipating
281
+ }
282
+ }
283
+ exports.makeGroupsSocket = makeGroupsSocket
284
+ const extractGroupMetadata = (result) => {
285
+ var _a, _b
286
+ const group = WABinary_1.getBinaryNodeChild(result, 'group')
287
+ const descChild = WABinary_1.getBinaryNodeChild(group, 'description')
288
+ let desc
289
+ let descId
290
+ let descOwner
291
+ let descOwnerLid
292
+ let descTime
293
+ if (descChild) {
294
+ desc = WABinary_1.getBinaryNodeChildString(descChild, 'body')
295
+ descOwner = WABinary_1.jidNormalizedUser(
296
+ descChild.attrs.participant_pn || descChild.attrs.participant
297
+ )
298
+ if (group.attrs.addressing_mode === 'lid') {
299
+ descOwnerLid = WABinary_1.jidNormalizedUser(descChild.attrs.participant)
300
+ }
301
+ descId = descChild.attrs.id
302
+ descTime = descChild.attrs.t ? +descChild.attrs.t : undefined
303
+ }
304
+ const groupSize = group.attrs.size ? Number(group.attrs.size) : undefined
305
+ const groupId = group.attrs.id.includes('@')
306
+ ? group.attrs.id
307
+ : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us')
308
+ const eph = WABinary_1.getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
309
+ const memberAddMode =
310
+ WABinary_1.getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
311
+ const metadata = {
312
+ id: groupId,
313
+ addressingMode: group.attrs.addressing_mode,
314
+ subject: group.attrs.subject,
315
+ subjectOwner: WABinary_1.jidNormalizedUser(group.attrs.s_o_pn || group.attrs.s_o),
316
+ ...(group.attrs.addressing_mode === 'lid'
317
+ ? { subjectOwnerLid: WABinary_1.jidNormalizedUser(group.attrs.s_o) }
318
+ : {}),
319
+ subjectTime: group.attrs.s_t ? +group.attrs.s_t : undefined,
320
+ size: groupSize || WABinary_1.getBinaryNodeChildren(group, 'participant').length,
321
+ creation: group.attrs.creation ? +group.attrs.creation : undefined,
322
+ owner: WABinary_1.jidNormalizedUser(group.attrs.creator_pn || group.attrs.creator),
323
+ ...(group.attrs.addressing_mode === 'lid'
324
+ ? { ownerLid: WABinary_1.jidNormalizedUser(group.attrs.creator) }
325
+ : {}),
326
+ descOwner,
327
+ descOwnerLid,
328
+ restrict: !!WABinary_1.getBinaryNodeChild(group, 'locked'),
329
+ announce: !!WABinary_1.getBinaryNodeChild(group, 'announcement'),
330
+ isCommunity: !!WABinary_1.getBinaryNodeChild(group, 'parent'),
331
+ isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(group, 'default_sub_group'),
332
+ joinApprovalMode: !!WABinary_1.getBinaryNodeChild(group, 'membership_approval_mode'),
333
+ memberAddMode,
334
+ participants: WABinary_1.getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
335
+ return {
336
+ id: attrs.jid,
337
+ jid: attrs.phone_number || attrs.jid,
338
+ admin: attrs.type || null
339
+ }
340
+ }),
341
+ ephemeralDuration: eph ? +eph : undefined
342
+ }
343
+ return metadata
344
+ }
345
+ exports.extractGroupMetadata = extractGroupMetadata
@@ -0,0 +1,22 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ const Defaults_1 = require('../Defaults')
4
+ const registration_1 = require('./registration')
5
+ const lid_mapping_1 = require('./lid-mapping')
6
+ // export the last socket layer
7
+ const makeWASocket = (config) => {
8
+ const fullConfig = {
9
+ ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
10
+ ...config
11
+ }
12
+ const sock = (0, registration_1.makeRegistrationSocket)(fullConfig)
13
+ // LID/PN helpers are lazy (nothing runs until called); enableLidMapping only adds passive learning
14
+ try {
15
+ return (0, lid_mapping_1.attachLidMapping)(sock, fullConfig)
16
+ } catch (err) {
17
+ fullConfig.logger?.warn?.({ err }, 'LID mapping helpers unavailable')
18
+ return sock
19
+ }
20
+ }
21
+ exports.default = makeWASocket
22
+ exports.makeWASocket = makeWASocket
@@ -0,0 +1,265 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.makeInteropSocket = void 0
4
+
5
+ const { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } = require('../WABinary')
6
+ const { executeWMexQuery } = require('./mex')
7
+
8
+ const INTEROP_MEX_QUERY_IDS = {
9
+ CREATE_GROUP: '25726817620301611',
10
+ LEAVE_GROUP: '25346167795013271',
11
+ ADD_PARTICIPANTS: '25732168276369451',
12
+ QUERY_GROUP_INFO: '32734144032867938',
13
+ PRIVACY_SETTINGS_QUERY: '24849123668112654',
14
+ PRIVACY_SETTINGS_UPDATE: '25421856497452763',
15
+ PRIVACY_SETTINGS_WITH_CONTACT_LIST: '24913399124998598'
16
+ }
17
+
18
+ const INTEGRATOR_BIRDYCHAT = 12
19
+ const INTEGRATOR_HAIKET = 13
20
+
21
+ const makeInteropSocket = (sock) => {
22
+ const { query, generateMessageTag, logger, signalRepository } = sock
23
+ const mexQuery = (variables, queryId, dataPath) =>
24
+ executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
25
+
26
+ const fetchIntegrators = async () => {
27
+ const result = await query({
28
+ tag: 'iq',
29
+ attrs: { type: 'get', xmlns: 'w:interop', to: S_WHATSAPP_NET },
30
+ content: [{ tag: 'integrator', attrs: { fetch: 'all' } }]
31
+ })
32
+ const listNode = getBinaryNodeChild(result, 'integrator_list')
33
+ if (!listNode) return []
34
+ const globalOptedIn = listNode.attrs?.opted_in === 'true'
35
+ return getBinaryNodeChildren(listNode, 'integrator').map((node) => {
36
+ const featuresNode = getBinaryNodeChild(node, 'features')
37
+ return {
38
+ id: parseInt(node.attrs.id, 10),
39
+ name: node.attrs.name,
40
+ status: node.attrs.status,
41
+ icon: node.attrs.icon,
42
+ identifierType: node.attrs.identifier_type,
43
+ optedIn: node.attrs.opted_in === 'true' || globalOptedIn,
44
+ features: { groupMessaging: featuresNode?.attrs?.group_messaging === 'true' }
45
+ }
46
+ })
47
+ }
48
+
49
+ const acceptInteropTOS = async () => {
50
+ const sendTOS = async (id, result) =>
51
+ await query({
52
+ tag: 'iq',
53
+ attrs: { to: S_WHATSAPP_NET, type: 'set', xmlns: 'tos' },
54
+ content: [{ tag: 'trackable', attrs: { id, result } }]
55
+ })
56
+ await sendTOS('20240306', '105')
57
+ await sendTOS('20240306', '160')
58
+ }
59
+
60
+ const optInIntegrators = async (integratorIds = [INTEGRATOR_BIRDYCHAT, INTEGRATOR_HAIKET]) => {
61
+ await query({
62
+ tag: 'iq',
63
+ attrs: { type: 'set', xmlns: 'w:interop', to: S_WHATSAPP_NET },
64
+ content: [
65
+ {
66
+ tag: 'opt_integrators',
67
+ attrs: {},
68
+ content: [
69
+ {
70
+ tag: 'integrator_list',
71
+ attrs: {},
72
+ content: integratorIds.map((id) => ({
73
+ tag: 'integrator',
74
+ attrs: { id: id.toString() }
75
+ }))
76
+ }
77
+ ]
78
+ }
79
+ ]
80
+ })
81
+ }
82
+
83
+ const optOutIntegrators = async (integratorIds = [INTEGRATOR_BIRDYCHAT, INTEGRATOR_HAIKET]) => {
84
+ await query({
85
+ tag: 'iq',
86
+ attrs: { type: 'set', xmlns: 'w:interop', to: S_WHATSAPP_NET },
87
+ content: [
88
+ {
89
+ tag: 'opt_out_integrators',
90
+ attrs: {},
91
+ content: [
92
+ {
93
+ tag: 'integrator_list',
94
+ attrs: {},
95
+ content: integratorIds.map((id) => ({
96
+ tag: 'integrator',
97
+ attrs: { id: id.toString() }
98
+ }))
99
+ }
100
+ ]
101
+ }
102
+ ]
103
+ })
104
+ }
105
+
106
+ const resolveInteropUsers = async (users) => {
107
+ if (!users || users.length === 0) return []
108
+ const result = await query({
109
+ tag: 'iq',
110
+ attrs: { type: 'get', xmlns: 'w:interop', to: S_WHATSAPP_NET },
111
+ content: [
112
+ {
113
+ tag: 'users',
114
+ attrs: {},
115
+ content: users.map(({ externalId, integratorId }) => ({
116
+ tag: 'user',
117
+ attrs: { external_id: externalId, integrator_id: integratorId.toString() }
118
+ }))
119
+ }
120
+ ]
121
+ })
122
+ const usersNode = getBinaryNodeChild(result, 'users')
123
+ if (!usersNode) return []
124
+ return getBinaryNodeChildren(usersNode, 'user').map((userNode) => {
125
+ const errorNode = getBinaryNodeChild(userNode, 'error')
126
+ if (errorNode)
127
+ return {
128
+ externalId: userNode.attrs.external_id,
129
+ integratorId: parseInt(userNode.attrs.integrator_id, 10),
130
+ error: { code: parseInt(errorNode.attrs.code, 10), text: errorNode.attrs.text }
131
+ }
132
+ return {
133
+ jid: userNode.attrs.jid,
134
+ externalId: userNode.attrs.external_id,
135
+ normalizedExternalId: userNode.attrs.normalized_external_id,
136
+ integratorId: parseInt(userNode.attrs.integrator_id, 10)
137
+ }
138
+ })
139
+ }
140
+
141
+ const resolveInteropUser = async (externalId, integratorId) => {
142
+ const results = await resolveInteropUsers([{ externalId, integratorId }])
143
+ return results[0] ?? null
144
+ }
145
+
146
+ const blockInteropUser = async (jid) =>
147
+ await query({
148
+ tag: 'iq',
149
+ attrs: { type: 'set', xmlns: 'w:interop', to: S_WHATSAPP_NET },
150
+ content: [
151
+ {
152
+ tag: 'blocklist',
153
+ attrs: {},
154
+ content: [{ tag: 'item', attrs: { action: 'block', jid } }]
155
+ }
156
+ ]
157
+ })
158
+ const unblockInteropUser = async (jid) =>
159
+ await query({
160
+ tag: 'iq',
161
+ attrs: { type: 'set', xmlns: 'w:interop', to: S_WHATSAPP_NET },
162
+ content: [
163
+ {
164
+ tag: 'blocklist',
165
+ attrs: {},
166
+ content: [{ tag: 'item', attrs: { action: 'unblock', jid } }]
167
+ }
168
+ ]
169
+ })
170
+
171
+ const initInterop = async () => {
172
+ let integrators
173
+ try {
174
+ integrators = await fetchIntegrators()
175
+ } catch (err) {
176
+ logger.warn({ err }, 'interop: failed to fetch integrators')
177
+ return []
178
+ }
179
+ const toOptIn = integrators.filter(
180
+ (i) => i.status === 'active' || i.status === 'onboarding'
181
+ )
182
+ if (toOptIn.length === 0) return integrators
183
+ try {
184
+ await acceptInteropTOS()
185
+ } catch (err) {
186
+ logger.warn({ err }, 'interop: failed to accept TOS')
187
+ }
188
+ try {
189
+ await optInIntegrators(toOptIn.map((i) => i.id))
190
+ } catch (err) {
191
+ logger.warn({ err }, 'interop: failed to opt-in integrators')
192
+ }
193
+ return integrators
194
+ }
195
+
196
+ const createInteropGroup = async (participants) =>
197
+ mexQuery(
198
+ { input: { participants: participants.map((jid) => ({ jid })) } },
199
+ INTEROP_MEX_QUERY_IDS.CREATE_GROUP,
200
+ 'xwa2_interop_group_create'
201
+ )
202
+
203
+ const leaveInteropGroup = async (jids) => {
204
+ const ids = Array.isArray(jids) ? jids : [jids]
205
+ return mexQuery(
206
+ { input: { groups_to_leave: ids.map((jid) => ({ gid: jid.split('@')[0] })) } },
207
+ INTEROP_MEX_QUERY_IDS.LEAVE_GROUP,
208
+ 'xwa2_interop_group_leave'
209
+ )
210
+ }
211
+
212
+ const addParticipantsToInteropGroup = async (groupJid, participants) =>
213
+ mexQuery(
214
+ {
215
+ input: {
216
+ gid: groupJid.split('@')[0],
217
+ participants: participants.map((jid) => ({ jid }))
218
+ }
219
+ },
220
+ INTEROP_MEX_QUERY_IDS.ADD_PARTICIPANTS,
221
+ 'xwa2_interop_add_participants_to_group'
222
+ )
223
+
224
+ const queryInteropGroupInfo = async (groupJid) =>
225
+ mexQuery(
226
+ { group_input: { gid: groupJid.split('@')[0] } },
227
+ INTEROP_MEX_QUERY_IDS.QUERY_GROUP_INFO,
228
+ 'xwa2_interop_group_query_by_id'
229
+ )
230
+
231
+ const updateInteropPrivacySetting = async (feature, setting) =>
232
+ mexQuery(
233
+ { feature, setting },
234
+ INTEROP_MEX_QUERY_IDS.PRIVACY_SETTINGS_UPDATE,
235
+ 'xwa2_interop_privacy_setting_update'
236
+ )
237
+
238
+ return {
239
+ ...sock,
240
+ fetchIntegrators,
241
+ acceptInteropTOS,
242
+ optInIntegrators,
243
+ optOutIntegrators,
244
+ resolveInteropUser,
245
+ resolveInteropUsers,
246
+ blockInteropUser,
247
+ unblockInteropUser,
248
+ initInterop,
249
+ createInteropGroup,
250
+ leaveInteropGroup,
251
+ addParticipantsToInteropGroup,
252
+ queryInteropGroupInfo,
253
+ updateInteropPrivacySetting,
254
+ INTEGRATOR_BIRDYCHAT,
255
+ INTEGRATOR_HAIKET,
256
+ INTEROP_MEX_QUERY_IDS
257
+ }
258
+ }
259
+
260
+ module.exports = {
261
+ makeInteropSocket,
262
+ INTEGRATOR_BIRDYCHAT,
263
+ INTEGRATOR_HAIKET,
264
+ INTEROP_MEX_QUERY_IDS
265
+ }