@gara31/void-baileys 7.0.0-rc.14

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 (95) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/index.js +117292 -0
  3. package/lib/Defaults/baileys-version.json +3 -0
  4. package/lib/Defaults/index.js +116 -0
  5. package/lib/Signal/Group/ciphertext-message.js +12 -0
  6. package/lib/Signal/Group/group-session-builder.js +42 -0
  7. package/lib/Signal/Group/group_cipher.js +109 -0
  8. package/lib/Signal/Group/index.js +12 -0
  9. package/lib/Signal/Group/keyhelper.js +18 -0
  10. package/lib/Signal/Group/sender-chain-key.js +32 -0
  11. package/lib/Signal/Group/sender-key-distribution-message.js +67 -0
  12. package/lib/Signal/Group/sender-key-message.js +80 -0
  13. package/lib/Signal/Group/sender-key-name.js +50 -0
  14. package/lib/Signal/Group/sender-key-record.js +47 -0
  15. package/lib/Signal/Group/sender-key-state.js +105 -0
  16. package/lib/Signal/Group/sender-message-key.js +30 -0
  17. package/lib/Signal/libsignal.js +416 -0
  18. package/lib/Signal/lid-mapping.js +189 -0
  19. package/lib/Socket/Client/index.js +3 -0
  20. package/lib/Socket/Client/types.js +11 -0
  21. package/lib/Socket/Client/websocket.js +61 -0
  22. package/lib/Socket/business.js +404 -0
  23. package/lib/Socket/chats.js +1146 -0
  24. package/lib/Socket/communities.js +505 -0
  25. package/lib/Socket/groups.js +404 -0
  26. package/lib/Socket/index.js +18 -0
  27. package/lib/Socket/messages-recv.js +1600 -0
  28. package/lib/Socket/messages-send.js +1203 -0
  29. package/lib/Socket/mex.js +56 -0
  30. package/lib/Socket/newsletter.js +240 -0
  31. package/lib/Socket/socket.js +1060 -0
  32. package/lib/Types/Auth.js +2 -0
  33. package/lib/Types/Bussines.js +2 -0
  34. package/lib/Types/Call.js +2 -0
  35. package/lib/Types/Chat.js +8 -0
  36. package/lib/Types/Contact.js +2 -0
  37. package/lib/Types/Events.js +2 -0
  38. package/lib/Types/GroupMetadata.js +2 -0
  39. package/lib/Types/Label.js +25 -0
  40. package/lib/Types/LabelAssociation.js +7 -0
  41. package/lib/Types/Message.js +11 -0
  42. package/lib/Types/Newsletter.js +31 -0
  43. package/lib/Types/Product.js +2 -0
  44. package/lib/Types/Signal.js +2 -0
  45. package/lib/Types/Socket.js +3 -0
  46. package/lib/Types/State.js +13 -0
  47. package/lib/Types/USync.js +2 -0
  48. package/lib/Types/index.js +32 -0
  49. package/lib/Utils/auth-utils.js +276 -0
  50. package/lib/Utils/browser-utils.js +32 -0
  51. package/lib/Utils/business.js +262 -0
  52. package/lib/Utils/chat-utils.js +941 -0
  53. package/lib/Utils/crypto.js +179 -0
  54. package/lib/Utils/decode-wa-message.js +333 -0
  55. package/lib/Utils/event-buffer.js +580 -0
  56. package/lib/Utils/generics.js +436 -0
  57. package/lib/Utils/history.js +103 -0
  58. package/lib/Utils/index.js +19 -0
  59. package/lib/Utils/link-preview.js +99 -0
  60. package/lib/Utils/logger.js +3 -0
  61. package/lib/Utils/lt-hash.js +56 -0
  62. package/lib/Utils/make-mutex.js +38 -0
  63. package/lib/Utils/message-retry-manager.js +181 -0
  64. package/lib/Utils/messages-media.js +727 -0
  65. package/lib/Utils/messages.js +1309 -0
  66. package/lib/Utils/noise-handler.js +162 -0
  67. package/lib/Utils/pre-key-manager.js +125 -0
  68. package/lib/Utils/process-message.js +594 -0
  69. package/lib/Utils/signal.js +194 -0
  70. package/lib/Utils/use-multi-file-auth-state.js +118 -0
  71. package/lib/Utils/validate-connection.js +240 -0
  72. package/lib/WABinary/constants.js +1301 -0
  73. package/lib/WABinary/decode.js +240 -0
  74. package/lib/WABinary/encode.js +216 -0
  75. package/lib/WABinary/generic-utils.js +104 -0
  76. package/lib/WABinary/index.js +6 -0
  77. package/lib/WABinary/jid-utils.js +95 -0
  78. package/lib/WABinary/types.js +2 -0
  79. package/lib/WAM/BinaryInfo.js +10 -0
  80. package/lib/WAM/constants.js +22863 -0
  81. package/lib/WAM/encode.js +152 -0
  82. package/lib/WAM/index.js +4 -0
  83. package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
  84. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -0
  85. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  86. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -0
  87. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +60 -0
  88. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  89. package/lib/WAUSync/Protocols/index.js +5 -0
  90. package/lib/WAUSync/USyncQuery.js +104 -0
  91. package/lib/WAUSync/USyncUser.js +23 -0
  92. package/lib/WAUSync/index.js +4 -0
  93. package/lib/index.js +11 -0
  94. package/package.json +32 -0
  95. package/readme.md +1452 -0
@@ -0,0 +1,404 @@
1
+ import { proto } from "../../WAProto/index.js";
2
+ import { WAMessageAddressingMode, WAMessageStubType } from "../Types/index.js";
3
+ import { generateMessageIDV2, unixTimestampSeconds } from "../Utils/index.js";
4
+ import {
5
+ getBinaryNodeChild,
6
+ getBinaryNodeChildren,
7
+ getBinaryNodeChildString,
8
+ isLidUser,
9
+ isPnUser,
10
+ jidEncode,
11
+ jidNormalizedUser,
12
+ } from "../WABinary/index.js";
13
+ import { makeChatsSocket } from "./chats.js";
14
+ export const makeGroupsSocket = (config) => {
15
+ const sock = makeChatsSocket(config);
16
+ const { authState, ev, query, upsertMessage } = sock;
17
+ const groupQuery = async (jid, type, content) =>
18
+ query({
19
+ tag: "iq",
20
+ attrs: {
21
+ type,
22
+ xmlns: "w:g2",
23
+ to: jid,
24
+ },
25
+ content,
26
+ });
27
+ const groupMetadata = async (jid) => {
28
+ const result = await groupQuery(jid, "get", [
29
+ { tag: "query", attrs: { request: "interactive" } },
30
+ ]);
31
+ return extractGroupMetadata(result);
32
+ };
33
+ const groupFetchAllParticipating = async () => {
34
+ const result = await query({
35
+ tag: "iq",
36
+ attrs: {
37
+ to: "@g.us",
38
+ xmlns: "w:g2",
39
+ type: "get",
40
+ },
41
+ content: [
42
+ {
43
+ tag: "participating",
44
+ attrs: {},
45
+ content: [
46
+ { tag: "participants", attrs: {} },
47
+ { tag: "description", attrs: {} },
48
+ ],
49
+ },
50
+ ],
51
+ });
52
+ const data = {};
53
+ const groupsChild = getBinaryNodeChild(result, "groups");
54
+ if (groupsChild) {
55
+ const groups = getBinaryNodeChildren(groupsChild, "group");
56
+ for (const groupNode of groups) {
57
+ const meta = extractGroupMetadata({
58
+ tag: "result",
59
+ attrs: {},
60
+ content: [groupNode],
61
+ });
62
+ data[meta.id] = meta;
63
+ }
64
+ }
65
+ // TODO: properly parse LID / PN DATA
66
+ sock.ev.emit("groups.update", Object.values(data));
67
+ return data;
68
+ };
69
+ sock.ws.on("CB:ib,,dirty", async (node) => {
70
+ const { attrs } = getBinaryNodeChild(node, "dirty");
71
+ if (attrs.type !== "groups") {
72
+ return;
73
+ }
74
+ await groupFetchAllParticipating();
75
+ await sock.cleanDirtyBits("groups");
76
+ });
77
+ return {
78
+ ...sock,
79
+ groupMetadata,
80
+ groupCreate: async (subject, participants) => {
81
+ const key = generateMessageIDV2();
82
+ const result = await groupQuery("@g.us", "set", [
83
+ {
84
+ tag: "create",
85
+ attrs: {
86
+ subject,
87
+ key,
88
+ },
89
+ content: participants.map((jid) => ({
90
+ tag: "participant",
91
+ attrs: { jid },
92
+ })),
93
+ },
94
+ ]);
95
+ return extractGroupMetadata(result);
96
+ },
97
+ groupLeave: async (id) => {
98
+ await groupQuery("@g.us", "set", [
99
+ {
100
+ tag: "leave",
101
+ attrs: {},
102
+ content: [{ tag: "group", attrs: { id } }],
103
+ },
104
+ ]);
105
+ },
106
+ groupUpdateSubject: async (jid, subject) => {
107
+ await groupQuery(jid, "set", [
108
+ {
109
+ tag: "subject",
110
+ attrs: {},
111
+ content: Buffer.from(subject, "utf-8"),
112
+ },
113
+ ]);
114
+ },
115
+ groupRequestParticipantsList: async (jid) => {
116
+ const result = await groupQuery(jid, "get", [
117
+ {
118
+ tag: "membership_approval_requests",
119
+ attrs: {},
120
+ },
121
+ ]);
122
+ const node = getBinaryNodeChild(result, "membership_approval_requests");
123
+ const participants = getBinaryNodeChildren(
124
+ node,
125
+ "membership_approval_request",
126
+ );
127
+ return participants.map((v) => v.attrs);
128
+ },
129
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
130
+ const result = await groupQuery(jid, "set", [
131
+ {
132
+ tag: "membership_requests_action",
133
+ attrs: {},
134
+ content: [
135
+ {
136
+ tag: action,
137
+ attrs: {},
138
+ content: participants.map((jid) => ({
139
+ tag: "participant",
140
+ attrs: { jid },
141
+ })),
142
+ },
143
+ ],
144
+ },
145
+ ]);
146
+ const node = getBinaryNodeChild(result, "membership_requests_action");
147
+ const nodeAction = getBinaryNodeChild(node, action);
148
+ const participantsAffected = getBinaryNodeChildren(
149
+ nodeAction,
150
+ "participant",
151
+ );
152
+ return participantsAffected.map((p) => {
153
+ return { status: p.attrs.error || "200", jid: p.attrs.jid };
154
+ });
155
+ },
156
+ groupParticipantsUpdate: async (jid, participants, action) => {
157
+ const result = await groupQuery(jid, "set", [
158
+ {
159
+ tag: action,
160
+ attrs: {},
161
+ content: participants.map((jid) => ({
162
+ tag: "participant",
163
+ attrs: { jid },
164
+ })),
165
+ },
166
+ ]);
167
+ const node = getBinaryNodeChild(result, action);
168
+ const participantsAffected = getBinaryNodeChildren(node, "participant");
169
+ return participantsAffected.map((p) => {
170
+ return { status: p.attrs.error || "200", jid: p.attrs.jid, content: p };
171
+ });
172
+ },
173
+ groupUpdateDescription: async (jid, description) => {
174
+ const metadata = await groupMetadata(jid);
175
+ const prev = metadata.descId ?? null;
176
+ await groupQuery(jid, "set", [
177
+ {
178
+ tag: "description",
179
+ attrs: {
180
+ ...(description
181
+ ? { id: generateMessageIDV2() }
182
+ : { delete: "true" }),
183
+ ...(prev ? { prev } : {}),
184
+ },
185
+ content: description
186
+ ? [
187
+ {
188
+ tag: "body",
189
+ attrs: {},
190
+ content: Buffer.from(description, "utf-8"),
191
+ },
192
+ ]
193
+ : undefined,
194
+ },
195
+ ]);
196
+ },
197
+ groupInviteCode: async (jid) => {
198
+ const result = await groupQuery(jid, "get", [
199
+ { tag: "invite", attrs: {} },
200
+ ]);
201
+ const inviteNode = getBinaryNodeChild(result, "invite");
202
+ return inviteNode?.attrs.code;
203
+ },
204
+ groupRevokeInvite: async (jid) => {
205
+ const result = await groupQuery(jid, "set", [
206
+ { tag: "invite", attrs: {} },
207
+ ]);
208
+ const inviteNode = getBinaryNodeChild(result, "invite");
209
+ return inviteNode?.attrs.code;
210
+ },
211
+ groupAcceptInvite: async (code) => {
212
+ const results = await groupQuery("@g.us", "set", [
213
+ { tag: "invite", attrs: { code } },
214
+ ]);
215
+ const result = getBinaryNodeChild(results, "group");
216
+ return result?.attrs.jid;
217
+ },
218
+ /**
219
+ * revoke a v4 invite for someone
220
+ * @param groupJid group jid
221
+ * @param invitedJid jid of person you invited
222
+ * @returns true if successful
223
+ */
224
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
225
+ const result = await groupQuery(groupJid, "set", [
226
+ {
227
+ tag: "revoke",
228
+ attrs: {},
229
+ content: [{ tag: "participant", attrs: { jid: invitedJid } }],
230
+ },
231
+ ]);
232
+ return !!result;
233
+ },
234
+ /**
235
+ * accept a GroupInviteMessage
236
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
237
+ * @param inviteMessage the message to accept
238
+ */
239
+ groupAcceptInviteV4: ev.createBufferedFunction(
240
+ async (key, inviteMessage) => {
241
+ key = typeof key === "string" ? { remoteJid: key } : key;
242
+ const results = await groupQuery(inviteMessage.groupJid, "set", [
243
+ {
244
+ tag: "accept",
245
+ attrs: {
246
+ code: inviteMessage.inviteCode,
247
+ expiration: inviteMessage.inviteExpiration.toString(),
248
+ admin: key.remoteJid,
249
+ },
250
+ },
251
+ ]);
252
+ // if we have the full message key
253
+ // update the invite message to be expired
254
+ if (key.id) {
255
+ // create new invite message that is expired
256
+ inviteMessage =
257
+ proto.Message.GroupInviteMessage.fromObject(inviteMessage);
258
+ inviteMessage.inviteExpiration = 0;
259
+ inviteMessage.inviteCode = "";
260
+ ev.emit("messages.update", [
261
+ {
262
+ key,
263
+ update: {
264
+ message: {
265
+ groupInviteMessage: inviteMessage,
266
+ },
267
+ },
268
+ },
269
+ ]);
270
+ }
271
+ // generate the group add message
272
+ await upsertMessage(
273
+ {
274
+ key: {
275
+ remoteJid: inviteMessage.groupJid,
276
+ id: generateMessageIDV2(sock.user?.id),
277
+ fromMe: false,
278
+ participant: key.remoteJid,
279
+ },
280
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
281
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
282
+ participant: key.remoteJid,
283
+ messageTimestamp: unixTimestampSeconds(),
284
+ },
285
+ "notify",
286
+ );
287
+ return results.attrs.from;
288
+ },
289
+ ),
290
+ groupGetInviteInfo: async (code) => {
291
+ const results = await groupQuery("@g.us", "get", [
292
+ { tag: "invite", attrs: { code } },
293
+ ]);
294
+ return extractGroupMetadata(results);
295
+ },
296
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
297
+ const content = ephemeralExpiration
298
+ ? {
299
+ tag: "ephemeral",
300
+ attrs: { expiration: ephemeralExpiration.toString() },
301
+ }
302
+ : { tag: "not_ephemeral", attrs: {} };
303
+ await groupQuery(jid, "set", [content]);
304
+ },
305
+ groupSettingUpdate: async (jid, setting) => {
306
+ await groupQuery(jid, "set", [{ tag: setting, attrs: {} }]);
307
+ },
308
+ groupMemberAddMode: async (jid, mode) => {
309
+ await groupQuery(jid, "set", [
310
+ { tag: "member_add_mode", attrs: {}, content: mode },
311
+ ]);
312
+ },
313
+ groupJoinApprovalMode: async (jid, mode) => {
314
+ await groupQuery(jid, "set", [
315
+ {
316
+ tag: "membership_approval_mode",
317
+ attrs: {},
318
+ content: [{ tag: "group_join", attrs: { state: mode } }],
319
+ },
320
+ ]);
321
+ },
322
+ groupFetchAllParticipating,
323
+ };
324
+ };
325
+ export const extractGroupMetadata = (result) => {
326
+ const group = getBinaryNodeChild(result, "group");
327
+ const descChild = getBinaryNodeChild(group, "description");
328
+ let desc;
329
+ let descId;
330
+ let descOwner;
331
+ let descOwnerPn;
332
+ let descTime;
333
+ if (descChild) {
334
+ desc = getBinaryNodeChildString(descChild, "body");
335
+ descOwner = descChild.attrs.participant
336
+ ? jidNormalizedUser(descChild.attrs.participant)
337
+ : undefined;
338
+ descOwnerPn = descChild.attrs.participant_pn
339
+ ? jidNormalizedUser(descChild.attrs.participant_pn)
340
+ : undefined;
341
+ descTime = +descChild.attrs.t;
342
+ descId = descChild.attrs.id;
343
+ }
344
+ const groupId = group.attrs.id.includes("@")
345
+ ? group.attrs.id
346
+ : jidEncode(group.attrs.id, "g.us");
347
+ const eph = getBinaryNodeChild(group, "ephemeral")?.attrs.expiration;
348
+ const memberAddMode =
349
+ getBinaryNodeChildString(group, "member_add_mode") === "all_member_add";
350
+ const metadata = {
351
+ id: groupId,
352
+ notify: group.attrs.notify,
353
+ addressingMode:
354
+ group.attrs.addressing_mode === "lid"
355
+ ? WAMessageAddressingMode.LID
356
+ : WAMessageAddressingMode.PN,
357
+ subject: group.attrs.subject,
358
+ subjectOwner: group.attrs.s_o,
359
+ subjectOwnerPn: group.attrs.s_o_pn,
360
+ subjectTime: +group.attrs.s_t,
361
+ size: group.attrs.size
362
+ ? +group.attrs.size
363
+ : getBinaryNodeChildren(group, "participant").length,
364
+ creation: +group.attrs.creation,
365
+ owner: group.attrs.creator
366
+ ? jidNormalizedUser(group.attrs.creator)
367
+ : undefined,
368
+ ownerPn: group.attrs.creator_pn
369
+ ? jidNormalizedUser(group.attrs.creator_pn)
370
+ : undefined,
371
+ owner_country_code: group.attrs.creator_country_code,
372
+ desc,
373
+ descId,
374
+ descOwner,
375
+ descOwnerPn,
376
+ descTime,
377
+ linkedParent:
378
+ getBinaryNodeChild(group, "linked_parent")?.attrs.jid || undefined,
379
+ restrict: !!getBinaryNodeChild(group, "locked"),
380
+ announce: !!getBinaryNodeChild(group, "announcement"),
381
+ isCommunity: !!getBinaryNodeChild(group, "parent"),
382
+ isCommunityAnnounce: !!getBinaryNodeChild(group, "default_sub_group"),
383
+ joinApprovalMode: !!getBinaryNodeChild(group, "membership_approval_mode"),
384
+ memberAddMode,
385
+ participants: getBinaryNodeChildren(group, "participant").map(
386
+ ({ attrs }) => {
387
+ // TODO: Store LID MAPPINGS
388
+ return {
389
+ id: attrs.jid,
390
+ phoneNumber:
391
+ isLidUser(attrs.jid) && isPnUser(attrs.phone_number)
392
+ ? attrs.phone_number
393
+ : undefined,
394
+ lid:
395
+ isPnUser(attrs.jid) && isLidUser(attrs.lid) ? attrs.lid : undefined,
396
+ admin: attrs.type || null,
397
+ };
398
+ },
399
+ ),
400
+ ephemeralDuration: eph ? +eph : undefined,
401
+ };
402
+ return metadata;
403
+ };
404
+ //# sourceMappingURL=groups.js.map
@@ -0,0 +1,18 @@
1
+ import { DEFAULT_CONNECTION_CONFIG } from "../Defaults/index.js";
2
+ import { makeCommunitiesSocket } from "./communities.js";
3
+ // export the last socket layer
4
+ const makeWASocket = (config) => {
5
+ const newConfig = {
6
+ ...DEFAULT_CONNECTION_CONFIG,
7
+ ...config,
8
+ };
9
+ // If the user hasn't provided their own history sync function,
10
+ // let's create a default one that respects the syncFullHistory flag.
11
+ // TODO: Change
12
+ if (config.shouldSyncHistoryMessage === undefined) {
13
+ newConfig.shouldSyncHistoryMessage = () => !!newConfig.syncFullHistory;
14
+ }
15
+ return makeCommunitiesSocket(newConfig);
16
+ };
17
+ export default makeWASocket;
18
+ //# sourceMappingURL=index.js.map