@fanzxnothuman/baileys 2.0.17

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