@yannajah/baileys 0.0.0-stage → 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.
Files changed (145) hide show
  1. package/LICENSE +23 -0
  2. package/LICENSE.jexkcode +21 -0
  3. package/README.md +41 -2
  4. package/THIRD_PARTY_NOTICES.md +15 -0
  5. package/WAProto/index.d.ts +16922 -0
  6. package/WAProto/index.js +122451 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/baileys-version.json +3 -0
  9. package/lib/Defaults/index.js +156 -0
  10. package/lib/Defaults/phonenumber-mcc.json +223 -0
  11. package/lib/Signal/Group/ciphertext-message.js +15 -0
  12. package/lib/Signal/Group/group-session-builder.js +64 -0
  13. package/lib/Signal/Group/group_cipher.js +96 -0
  14. package/lib/Signal/Group/index.js +57 -0
  15. package/lib/Signal/Group/keyhelper.js +55 -0
  16. package/lib/Signal/Group/queue-job.js +57 -0
  17. package/lib/Signal/Group/sender-chain-key.js +34 -0
  18. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  19. package/lib/Signal/Group/sender-key-message.js +69 -0
  20. package/lib/Signal/Group/sender-key-name.js +51 -0
  21. package/lib/Signal/Group/sender-key-record.js +53 -0
  22. package/lib/Signal/Group/sender-key-state.js +99 -0
  23. package/lib/Signal/Group/sender-message-key.js +29 -0
  24. package/lib/Signal/libsignal.js +174 -0
  25. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  26. package/lib/Socket/Client/index.js +19 -0
  27. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  28. package/lib/Socket/Client/web-socket-client.js +87 -0
  29. package/lib/Socket/business.js +260 -0
  30. package/lib/Socket/chats.js +1002 -0
  31. package/lib/Socket/clutch-handler.d.ts +27 -0
  32. package/lib/Socket/clutch-handler.js +880 -0
  33. package/lib/Socket/groups.js +317 -0
  34. package/lib/Socket/index.js +97 -0
  35. package/lib/Socket/messages-recv.js +1154 -0
  36. package/lib/Socket/messages-send.js +946 -0
  37. package/lib/Socket/newsletter.js +411 -0
  38. package/lib/Socket/registration.js +166 -0
  39. package/lib/Socket/socket.js +688 -0
  40. package/lib/Socket/usync.js +70 -0
  41. package/lib/Store/index.js +10 -0
  42. package/lib/Store/make-cache-manager-store.js +83 -0
  43. package/lib/Store/make-in-memory-store.js +457 -0
  44. package/lib/Store/make-ordered-dictionary.js +81 -0
  45. package/lib/Store/object-repository.js +27 -0
  46. package/lib/Types/Auth.js +2 -0
  47. package/lib/Types/Call.js +2 -0
  48. package/lib/Types/Chat.js +4 -0
  49. package/lib/Types/Contact.js +2 -0
  50. package/lib/Types/Events.js +2 -0
  51. package/lib/Types/GroupMetadata.js +2 -0
  52. package/lib/Types/Label.js +27 -0
  53. package/lib/Types/LabelAssociation.js +9 -0
  54. package/lib/Types/Message.js +10 -0
  55. package/lib/Types/Mex.d.ts +2 -0
  56. package/lib/Types/Mex.js +98 -0
  57. package/lib/Types/Newsletter.js +41 -0
  58. package/lib/Types/Product.js +2 -0
  59. package/lib/Types/Signal.js +2 -0
  60. package/lib/Types/Socket.js +2 -0
  61. package/lib/Types/State.js +2 -0
  62. package/lib/Types/USync.js +2 -0
  63. package/lib/Types/index.js +43 -0
  64. package/lib/Utils/MessageBuilder.d.ts +215 -0
  65. package/lib/Utils/MessageBuilder.js +4001 -0
  66. package/lib/Utils/a2ui.d.ts +202 -0
  67. package/lib/Utils/a2ui.js +770 -0
  68. package/lib/Utils/auth-utils.js +206 -0
  69. package/lib/Utils/baileys-event-stream.js +63 -0
  70. package/lib/Utils/bot-signature.d.ts +22 -0
  71. package/lib/Utils/bot-signature.js +125 -0
  72. package/lib/Utils/business.js +234 -0
  73. package/lib/Utils/channel-manager.d.ts +39 -0
  74. package/lib/Utils/channel-manager.js +312 -0
  75. package/lib/Utils/chat-utils.js +729 -0
  76. package/lib/Utils/crypto.js +151 -0
  77. package/lib/Utils/decode-wa-message.js +198 -0
  78. package/lib/Utils/event-buffer.js +514 -0
  79. package/lib/Utils/extras.d.ts +449 -0
  80. package/lib/Utils/extras.js +1377 -0
  81. package/lib/Utils/generics.js +574 -0
  82. package/lib/Utils/history.js +96 -0
  83. package/lib/Utils/html-app.d.ts +39 -0
  84. package/lib/Utils/html-app.js +307 -0
  85. package/lib/Utils/index.d.ts +23 -0
  86. package/lib/Utils/index.js +51 -0
  87. package/lib/Utils/link-preview.js +93 -0
  88. package/lib/Utils/logger.js +7 -0
  89. package/lib/Utils/lt-hash.js +51 -0
  90. package/lib/Utils/make-mutex.js +43 -0
  91. package/lib/Utils/message-retry-manager.d.ts +42 -0
  92. package/lib/Utils/message-retry-manager.js +309 -0
  93. package/lib/Utils/messages-media.js +861 -0
  94. package/lib/Utils/messages.js +1085 -0
  95. package/lib/Utils/metaai.d.ts +438 -0
  96. package/lib/Utils/metaai.js +911 -0
  97. package/lib/Utils/mini-app.d.ts +93 -0
  98. package/lib/Utils/mini-app.js +453 -0
  99. package/lib/Utils/modern-messages.d.ts +150 -0
  100. package/lib/Utils/modern-messages.js +498 -0
  101. package/lib/Utils/native-flow.d.ts +14 -0
  102. package/lib/Utils/native-flow.js +122 -0
  103. package/lib/Utils/newsletter-status.d.ts +163 -0
  104. package/lib/Utils/newsletter-status.js +695 -0
  105. package/lib/Utils/noise-handler.js +155 -0
  106. package/lib/Utils/payment-messages.d.ts +59 -0
  107. package/lib/Utils/payment-messages.js +164 -0
  108. package/lib/Utils/process-message.js +334 -0
  109. package/lib/Utils/reporting-utils.d.ts +12 -0
  110. package/lib/Utils/reporting-utils.js +271 -0
  111. package/lib/Utils/scheduled-message.d.ts +82 -0
  112. package/lib/Utils/scheduled-message.js +126 -0
  113. package/lib/Utils/signal.js +153 -0
  114. package/lib/Utils/spr.d.ts +26 -0
  115. package/lib/Utils/spr.js +525 -0
  116. package/lib/Utils/status-stickers.d.ts +78 -0
  117. package/lib/Utils/status-stickers.js +275 -0
  118. package/lib/Utils/telegram-adapter.d.ts +28 -0
  119. package/lib/Utils/telegram-adapter.js +285 -0
  120. package/lib/Utils/use-multi-file-auth-state.js +153 -0
  121. package/lib/Utils/validate-connection.js +235 -0
  122. package/lib/WABinary/constants.js +40 -0
  123. package/lib/WABinary/decode.js +252 -0
  124. package/lib/WABinary/encode.js +265 -0
  125. package/lib/WABinary/generic-utils.js +178 -0
  126. package/lib/WABinary/index.js +21 -0
  127. package/lib/WABinary/jid-utils.js +81 -0
  128. package/lib/WABinary/types.js +2 -0
  129. package/lib/WAM/BinaryInfo.js +13 -0
  130. package/lib/WAM/constants.js +15350 -0
  131. package/lib/WAM/encode.js +155 -0
  132. package/lib/WAM/index.js +19 -0
  133. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  134. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  135. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  136. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  137. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  138. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  139. package/lib/WAUSync/Protocols/index.js +20 -0
  140. package/lib/WAUSync/USyncQuery.js +89 -0
  141. package/lib/WAUSync/USyncUser.js +26 -0
  142. package/lib/WAUSync/index.js +19 -0
  143. package/lib/index.d.ts +20 -0
  144. package/lib/index.js +99 -0
  145. package/package.json +110 -4
@@ -0,0 +1,525 @@
1
+ /**
2
+ * Do not remove this watermark.
3
+ *
4
+ * NIXCODE - Advanced WhatsApp Send Private Relay
5
+ *
6
+ * Runtime:
7
+ * - Baileys: @yannajah/baileys
8
+ *
9
+ * Created by Nixel
10
+ * Channel: https://whatsapp.com/channel/0029VbCV1ck8fewpdNb2TY2k
11
+ *
12
+ * Copyright (c) 2026 Nixel
13
+ *
14
+ * Permission is granted to use and modify this library
15
+ * for personal or commercial projects.
16
+ *
17
+ * Reuploading, reselling, relicensing, or redistributing
18
+ * this library as a standalone product is prohibited.
19
+ *
20
+ * Do not claim this project as your own original work.
21
+ */
22
+
23
+ "use strict";
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.sPR = exports.selectiveRelay = exports.createSKDM = exports.encryptGroupMessage = exports.deriveReportingTag = exports.getMessageKey = exports.generateSigningKeyPair = void 0;
26
+
27
+ const generics_1 = require("./generics");
28
+ const crypto_1 = require("./crypto");
29
+ const messages_1 = require("./messages");
30
+ const WABinary_1 = require("../WABinary");
31
+ const WAProto_1 = require("../../WAProto");
32
+ const boom_1 = require("@hapi/boom");
33
+ const crypto = require("crypto");
34
+
35
+ function encodeVarint(value) {
36
+ const bytes = [];
37
+ while (value >= 128) {
38
+ bytes.push((value & 127) | 128);
39
+ value >>>= 7;
40
+ }
41
+ bytes.push(value);
42
+ return Buffer.from(bytes);
43
+ }
44
+
45
+ function generateSigningKeyPair() {
46
+ const keys = crypto_1.Curve.generateKeyPair();
47
+ const pubBuffer = Buffer.concat([Buffer.from([0x05]), Buffer.from(keys.public)]);
48
+ return { privateKey: Buffer.from(keys.private), publicKey: pubBuffer };
49
+ }
50
+ exports.generateSigningKeyPair = generateSigningKeyPair;
51
+
52
+ function getMessageKey(seed) {
53
+ const messageKey = crypto.createHmac("sha256", seed).update(Buffer.from([0x01])).digest();
54
+ const salt = Buffer.alloc(32, 0);
55
+ const info = Buffer.from("WhisperGroup");
56
+ const prk = crypto.createHmac("sha256", salt).update(messageKey).digest();
57
+ const t1 = crypto.createHmac("sha256", prk).update(Buffer.concat([info, Buffer.from([0x01])])).digest();
58
+ const t2 = crypto.createHmac("sha256", prk).update(Buffer.concat([t1, info, Buffer.from([0x02])])).digest();
59
+ const okm = Buffer.concat([t1, t2]);
60
+ const iv = okm.slice(0, 16);
61
+ const cipherKey = okm.slice(16, 48);
62
+ return { iv, cipherKey };
63
+ }
64
+ exports.getMessageKey = getMessageKey;
65
+
66
+ function deriveReportingTag(message, msgId, remoteJid) {
67
+ if (!message.messageContextInfo) message.messageContextInfo = {};
68
+ if (!Buffer.isBuffer(message.messageContextInfo.messageSecret) || message.messageContextInfo.messageSecret.length !== 32) {
69
+ message.messageContextInfo.messageSecret = crypto.randomBytes(32);
70
+ }
71
+ const seed = message.messageContextInfo.messageSecret;
72
+ const payload = Buffer.from(WAProto_1.proto.Message.encode(message).finish());
73
+ const salt = Buffer.alloc(32, 0);
74
+ const info = Buffer.concat([
75
+ Buffer.from(msgId, "utf8"),
76
+ Buffer.from(remoteJid, "utf8"),
77
+ Buffer.from(remoteJid, "utf8"),
78
+ Buffer.from("Report Token", "utf8")
79
+ ]);
80
+ const prk = crypto.createHmac("sha256", salt).update(seed).digest();
81
+ const t1 = crypto.createHmac("sha256", prk).update(Buffer.concat([info, Buffer.from([0x01])])).digest();
82
+ const mac = crypto.createHmac("sha256", t1).update(payload).digest();
83
+
84
+ const iv = Buffer.from([0x7a, 0x3b, 0x91, 0xc4, 0x2e, 0x1f, 0xd0, 0x63]);
85
+ const vec = Buffer.from([0x29, 0x6b, 0xc3, 0x8a, 0x67, 0x47, 0x95, 0x2f, 0x2c, 0x0a]);
86
+ const nonce = mac.subarray(0, 4);
87
+ const stream = crypto.createHmac("sha256", iv).update(nonce).digest();
88
+
89
+ const raw = Buffer.alloc(10);
90
+ for (let i = 0; i < 10; i++) {
91
+ raw[i] = vec[i] ^ iv[i & 7];
92
+ }
93
+
94
+ const sig = crypto.createHmac("sha256", iv).update(Buffer.concat([nonce, raw])).digest().subarray(0, 2);
95
+ const block = Buffer.concat([raw, sig]);
96
+
97
+ for (let i = 0; i < 12; i++) {
98
+ block[i] ^= stream[i];
99
+ }
100
+
101
+ return Buffer.concat([nonce, block]);
102
+ }
103
+ exports.deriveReportingTag = deriveReportingTag;
104
+
105
+ function encryptGroupMessage(plaintext, chainSeed, privateKeyObject, keyId) {
106
+ const iteration = 0;
107
+ const { iv, cipherKey } = getMessageKey(chainSeed);
108
+ const cipher = crypto.createCipheriv("aes-256-cbc", cipherKey, iv);
109
+ const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
110
+ const idBuf = Buffer.concat([Buffer.from([0x08]), encodeVarint(keyId)]);
111
+ const iterBuf = Buffer.concat([Buffer.from([0x10]), encodeVarint(iteration)]);
112
+ const cipherBuf = Buffer.concat([Buffer.from([0x1A]), encodeVarint(ciphertext.length), ciphertext]);
113
+ const messageProto = Buffer.concat([idBuf, iterBuf, cipherBuf]);
114
+ const messageToSign = Buffer.concat([Buffer.from([0x33]), messageProto]);
115
+ const signature = crypto_1.Curve.sign(privateKeyObject, messageToSign);
116
+ return Buffer.concat([messageToSign, Buffer.from(signature)]);
117
+ }
118
+ exports.encryptGroupMessage = encryptGroupMessage;
119
+
120
+ function createSKDM(keyId, iteration, chainSeed, signingPubKey) {
121
+ const idBuf = Buffer.concat([Buffer.from([0x08]), encodeVarint(keyId)]);
122
+ const iterBuf = Buffer.concat([Buffer.from([0x10]), encodeVarint(iteration)]);
123
+ const chainBuf = Buffer.concat([Buffer.from([0x1A]), encodeVarint(chainSeed.length), chainSeed]);
124
+ const signBuf = Buffer.concat([Buffer.from([0x22]), encodeVarint(signingPubKey.length), signingPubKey]);
125
+ const message = Buffer.concat([idBuf, iterBuf, chainBuf, signBuf]);
126
+ return Buffer.concat([Buffer.from([0x33]), message]);
127
+ }
128
+ exports.createSKDM = createSKDM;
129
+
130
+ const getMessageType = (message) => {
131
+ const normalizedMessage = (0, messages_1.normalizeMessageContent)(message);
132
+ if (!normalizedMessage) return "text";
133
+ if (normalizedMessage.reactionMessage || normalizedMessage.encReactionMessage) return "reaction";
134
+ if (
135
+ normalizedMessage.pollCreationMessage ||
136
+ normalizedMessage.pollCreationMessageV2 ||
137
+ normalizedMessage.pollCreationMessageV3 ||
138
+ normalizedMessage.pollUpdateMessage
139
+ ) return "poll";
140
+ if (normalizedMessage.eventMessage) return "event";
141
+ if (getMediaType(normalizedMessage) !== "") return "media";
142
+ return "text";
143
+ };
144
+
145
+ const getMediaType = (message) => {
146
+ if (message.imageMessage) return "image";
147
+ if (message.videoMessage) return message.videoMessage.gifPlayback ? "gif" : "video";
148
+ if (message.audioMessage) return message.audioMessage.ptt ? "ptt" : "audio";
149
+ if (message.contactMessage) return "vcard";
150
+ if (message.documentMessage) return "document";
151
+ if (message.contactsArrayMessage) return "contact_array";
152
+ if (message.liveLocationMessage) return "livelocation";
153
+ if (message.stickerMessage) return "sticker";
154
+ if (message.listMessage) return "list";
155
+ if (message.listResponseMessage) return "list_response";
156
+ if (message.buttonsResponseMessage) return "buttons_response";
157
+ if (message.orderMessage) return "order";
158
+ if (message.productMessage) return "product";
159
+ if (message.interactiveResponseMessage) return "native_flow_response";
160
+ if (message.groupInviteMessage) return "url";
161
+ return "";
162
+ };
163
+
164
+ async function sPR(conn, jid, message, {
165
+ messageId: msgId,
166
+ additionalAttributes,
167
+ useUserDevicesCache,
168
+ useCachedGroupMetadata,
169
+ statusJidList,
170
+ additionalNodes,
171
+ targetMe,
172
+ mode = "exclude",
173
+ target = [],
174
+ hideDecryptFail = true,
175
+ deviceMode = "all"
176
+ } = {}) {
177
+ const meId = conn.authState?.creds?.me?.id || conn.user?.id || "";
178
+ const meLid = conn.authState?.creds?.me?.lid || conn.user?.lid || "";
179
+
180
+ const getLidForPn = async (pnJid) => {
181
+ try {
182
+ return await conn.signalRepository?.lidMapping?.getLIDForPN(pnJid);
183
+ } catch {
184
+ return null;
185
+ }
186
+ };
187
+
188
+ const getPnForLid = async (lidJid) => {
189
+ try {
190
+ return await conn.signalRepository?.lidMapping?.getPNForLID(lidJid);
191
+ } catch {
192
+ return null;
193
+ }
194
+ };
195
+
196
+ const processFilters = async (list) => {
197
+ const rules = [];
198
+ if (!Array.isArray(list)) return rules;
199
+ for (const item of list) {
200
+ if (!item) continue;
201
+ const decoded = (0, WABinary_1.jidDecode)(item);
202
+ if (!decoded) continue;
203
+
204
+ const hasDevice = item.includes(":");
205
+ const targetDevice = hasDevice ? (decoded.device !== undefined ? decoded.device : 0) : null;
206
+
207
+ rules.push({
208
+ user: decoded.user,
209
+ device: targetDevice,
210
+ server: decoded.server
211
+ });
212
+
213
+ if (decoded.server === "s.whatsapp.net") {
214
+ const lidJid = await getLidForPn(item);
215
+ if (lidJid) {
216
+ const lidDecoded = (0, WABinary_1.jidDecode)(lidJid);
217
+ if (lidDecoded) {
218
+ rules.push({
219
+ user: lidDecoded.user,
220
+ device: targetDevice,
221
+ server: lidDecoded.server
222
+ });
223
+ }
224
+ }
225
+ } else if (decoded.server === "lid") {
226
+ const pnJid = await getPnForLid(item);
227
+ if (pnJid) {
228
+ const pnDecoded = (0, WABinary_1.jidDecode)(pnJid);
229
+ if (pnDecoded) {
230
+ rules.push({
231
+ user: pnDecoded.user,
232
+ device: targetDevice,
233
+ server: pnDecoded.server
234
+ });
235
+ }
236
+ }
237
+ }
238
+ }
239
+ return rules;
240
+ };
241
+
242
+ const parsedTargets = await processFilters(target);
243
+
244
+ const isMatch = (targetJid, rules) => {
245
+ const decoded = (0, WABinary_1.jidDecode)(targetJid);
246
+ if (!decoded) return false;
247
+
248
+ const targetDevice = decoded.device !== undefined ? decoded.device : 0;
249
+
250
+ for (const rule of rules) {
251
+ if (rule.user === decoded.user) {
252
+ if (rule.device === null) return true;
253
+ if (rule.device === targetDevice) return true;
254
+ }
255
+ }
256
+ return false;
257
+ };
258
+
259
+ let shouldIncludeDeviceIdentity = false;
260
+ const statusJid = "status@broadcast";
261
+ const { user, server } = (0, WABinary_1.jidDecode)(jid);
262
+ const isNewsletter = server === "newsletter";
263
+ const isGroup = server === "g.us";
264
+ const isStatus = jid === statusJid;
265
+ const isGroupOrStatus = isGroup || isStatus;
266
+ msgId = msgId || (0, generics_1.generateMessageIDV2)(meId);
267
+ useUserDevicesCache = useUserDevicesCache !== false;
268
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
269
+ const participants = [];
270
+ const destinationJid = !isStatus ? jid : statusJid;
271
+ const binaryNodeContent = [];
272
+ const devices = [];
273
+
274
+ const reportingToken = !isNewsletter && !isStatus ? deriveReportingTag(message, msgId, destinationJid) : null;
275
+
276
+ const meMsg = { deviceSentMessage: { destinationJid, message }, messageContextInfo: message.messageContextInfo };
277
+ const extraAttrs = {};
278
+ const messages = (0, messages_1.normalizeMessageContent)(message);
279
+
280
+ if (isNewsletter) {
281
+ const patched = conn.patchMessageBeforeSending ? await conn.patchMessageBeforeSending(message, []) : message;
282
+ const bytes = (0, generics_1.encodeNewsletterMessage)(patched);
283
+ binaryNodeContent.push({ tag: "plaintext", attrs: {}, content: bytes });
284
+ const stanza = {
285
+ tag: "message",
286
+ attrs: {
287
+ to: jid,
288
+ id: msgId,
289
+ type: getMessageType(message),
290
+ ...(additionalAttributes || {})
291
+ },
292
+ content: binaryNodeContent
293
+ };
294
+ await conn.sendNode(stanza);
295
+ return msgId;
296
+ }
297
+
298
+ if (hideDecryptFail === true) {
299
+ extraAttrs["decrypt-fail"] = "hide";
300
+ }
301
+
302
+ const mediaType = getMediaType(messages);
303
+ if (mediaType) extraAttrs["mediatype"] = mediaType;
304
+
305
+ if (messages?.pinInChatMessage || messages?.reactionMessage) {
306
+ extraAttrs["decrypt-fail"] = "hide";
307
+ }
308
+
309
+ if (isGroupOrStatus) {
310
+ let groupData = useCachedGroupMetadata && conn.cachedGroupMetadata ? await conn.cachedGroupMetadata(jid) : undefined;
311
+ if (!(groupData && Array.isArray(groupData?.participants)) && !isStatus) groupData = await conn.groupMetadata(jid);
312
+
313
+ if (groupData?.participants && Array.isArray(target)) {
314
+ for (const p of groupData.participants) {
315
+ const pId = p.id || p.jid;
316
+ const pLid = p.lid;
317
+ const pPn = p.phoneNumber || p.pn;
318
+ for (const item of target) {
319
+ if (!item) continue;
320
+ const decItem = (0, WABinary_1.jidDecode)(item);
321
+ if (!decItem) continue;
322
+ const hasDevice = item.includes(":");
323
+ const targetDevice = hasDevice ? (decItem.device !== undefined ? decItem.device : 0) : null;
324
+ if (
325
+ decItem.user === (0, WABinary_1.jidDecode)(pId)?.user ||
326
+ (pLid && decItem.user === (0, WABinary_1.jidDecode)(pLid)?.user) ||
327
+ (pPn && decItem.user === (0, WABinary_1.jidDecode)(pPn)?.user)
328
+ ) {
329
+ for (const candidate of [pId, pLid, pPn]) {
330
+ const decCand = candidate ? (0, WABinary_1.jidDecode)(candidate) : null;
331
+ if (decCand) {
332
+ parsedTargets.push({
333
+ user: decCand.user,
334
+ device: targetDevice,
335
+ server: decCand.server
336
+ });
337
+ }
338
+ }
339
+ }
340
+ }
341
+ }
342
+ }
343
+
344
+ const participantsList = groupData ? groupData.participants.map((p) => p.id) : [];
345
+ if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
346
+ additionalAttributes = { ...additionalAttributes, expiration: groupData.ephemeralDuration.toString() };
347
+ }
348
+ if (isStatus && statusJidList) participantsList.push(...statusJidList);
349
+ devices.push(...(await conn.getUSyncDevices(participantsList, !!useUserDevicesCache, false)));
350
+ if (isGroup) additionalAttributes = { ...additionalAttributes, addressing_mode: groupData?.addressingMode || "lid" };
351
+
352
+ const patched = conn.patchMessageBeforeSending ? await conn.patchMessageBeforeSending(message) : message;
353
+ if (Array.isArray(patched)) throw new boom_1.Boom("Per-jid patching is not supported in groups");
354
+ const bytes = (0, generics_1.encodeWAMessage)(patched);
355
+
356
+ const chainSeed = crypto.randomBytes(32);
357
+ const { privateKey: signingKey, publicKey: signingPubKey } = generateSigningKeyPair();
358
+ const keyId = crypto.randomBytes(4).readUInt32BE(0) & 0x7FFFFFFF;
359
+
360
+ const skmsg = encryptGroupMessage(bytes, chainSeed, signingKey, keyId);
361
+ const skdm = createSKDM(keyId, 0, chainSeed, signingPubKey);
362
+
363
+ const senderKeyRecipients = [];
364
+ const mePnUserDec = (0, WABinary_1.jidDecode)(meId);
365
+ const meLidUserDec = meLid ? (0, WABinary_1.jidDecode)(meLid) : null;
366
+
367
+ for (const device of devices) {
368
+ const deviceJid = device.jid;
369
+ const isOwnDevice = ((0, WABinary_1.jidDecode)(deviceJid)?.user === mePnUserDec?.user) || (meLidUserDec && (0, WABinary_1.jidDecode)(deviceJid)?.user === meLidUserDec?.user);
370
+
371
+ let shouldSendRealKey = true;
372
+ if (mode === "include") {
373
+ shouldSendRealKey = isMatch(deviceJid, parsedTargets);
374
+ } else {
375
+ shouldSendRealKey = !isMatch(deviceJid, parsedTargets);
376
+ }
377
+
378
+ if (isOwnDevice && typeof targetMe === "boolean") {
379
+ shouldSendRealKey = targetMe;
380
+ }
381
+
382
+ const decDev = (0, WABinary_1.jidDecode)(deviceJid);
383
+ const dId = decDev?.device !== undefined ? decDev.device : 0;
384
+ if (deviceMode === "primary" && dId !== 0) shouldSendRealKey = false;
385
+ if (deviceMode === "secondary" && dId === 0) shouldSendRealKey = false;
386
+
387
+ if (shouldSendRealKey && !(0, WABinary_1.isHostedLidUser)(deviceJid) && !(0, WABinary_1.isHostedPnUser)(deviceJid) && device.device !== 99) {
388
+ senderKeyRecipients.push(deviceJid);
389
+ }
390
+ }
391
+
392
+ const groupParticipantsNodes = [];
393
+
394
+ if (senderKeyRecipients.length > 0) {
395
+ await conn.assertSessions(senderKeyRecipients);
396
+
397
+ const senderKeyMsg = {
398
+ senderKeyDistributionMessage: {
399
+ groupId: destinationJid,
400
+ axolotlSenderKeyDistributionMessage: skdm
401
+ }
402
+ };
403
+ const { nodes: skdmNodes, shouldIncludeDeviceIdentity: s1 } = await conn.createParticipantNodes(senderKeyRecipients, senderKeyMsg);
404
+ shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1;
405
+ groupParticipantsNodes.push(...skdmNodes);
406
+ }
407
+
408
+ if (groupParticipantsNodes.length > 0) {
409
+ binaryNodeContent.push({ tag: "participants", attrs: {}, content: groupParticipantsNodes });
410
+ }
411
+
412
+ binaryNodeContent.push({ tag: "enc", attrs: { v: "2", type: "skmsg", ...extraAttrs }, content: skmsg });
413
+ } else {
414
+ let ownId = (0, WABinary_1.isLidUser)(jid) && meLid ? meLid : meId;
415
+ const { user: ownUser } = (0, WABinary_1.jidDecode)(ownId);
416
+ const targetUserServer = (0, WABinary_1.isLidUser)(jid) ? "lid" : "s.whatsapp.net";
417
+ devices.push({ user, device: 0, jid: (0, WABinary_1.jidEncode)(user, targetUserServer, 0) });
418
+ if (user !== ownUser) {
419
+ const ownUserServer = (0, WABinary_1.isLidUser)(jid) ? "lid" : "s.whatsapp.net";
420
+ const ownUserForAddressing = (0, WABinary_1.isLidUser)(jid) && meLid ? (0, WABinary_1.jidDecode)(meLid).user : (0, WABinary_1.jidDecode)(meId).user;
421
+ devices.push({ user: ownUserForAddressing, device: 0, jid: (0, WABinary_1.jidEncode)(ownUserForAddressing, ownUserServer, 0) });
422
+ }
423
+ if (additionalAttributes?.["category"] !== "peer") {
424
+ devices.length = 0;
425
+ const senderIdentity = (0, WABinary_1.isLidUser)(jid) && meLid ? (0, WABinary_1.jidEncode)((0, WABinary_1.jidDecode)(meLid)?.user, "lid", undefined) : (0, WABinary_1.jidEncode)((0, WABinary_1.jidDecode)(meId)?.user, "s.whatsapp.net", undefined);
426
+ devices.push(...(await conn.getUSyncDevices([senderIdentity, jid], true, false)));
427
+ }
428
+
429
+ const allRecipients = [];
430
+ const meRecipients = [];
431
+ const otherRecipients = [];
432
+ const mePnUserDec = (0, WABinary_1.jidDecode)(meId);
433
+ const meLidUserDec = meLid ? (0, WABinary_1.jidDecode)(meLid) : null;
434
+
435
+ for (const device of devices) {
436
+ const deviceJid = device.jid;
437
+ const isExactSenderDevice = deviceJid === meId || (meLid && deviceJid === meLid);
438
+ if (isExactSenderDevice) continue;
439
+
440
+ let shouldSend = true;
441
+ if (mode === "include") {
442
+ shouldSend = isMatch(deviceJid, parsedTargets);
443
+ } else {
444
+ shouldSend = !isMatch(deviceJid, parsedTargets);
445
+ }
446
+
447
+ const isMe = (device.user === mePnUserDec?.user) || (meLidUserDec && device.user === meLidUserDec?.user);
448
+
449
+ if (isMe && typeof targetMe === "boolean") {
450
+ shouldSend = targetMe;
451
+ }
452
+
453
+ const decDev = (0, WABinary_1.jidDecode)(deviceJid);
454
+ const dId = decDev?.device !== undefined ? decDev.device : 0;
455
+ if (deviceMode === "primary" && dId !== 0) shouldSend = false;
456
+ if (deviceMode === "secondary" && dId === 0) shouldSend = false;
457
+
458
+ if (!shouldSend) continue;
459
+
460
+ if (isMe) {
461
+ meRecipients.push(deviceJid);
462
+ allRecipients.push(deviceJid);
463
+ } else {
464
+ otherRecipients.push(deviceJid);
465
+ allRecipients.push(deviceJid);
466
+ }
467
+ }
468
+
469
+ await conn.assertSessions(allRecipients);
470
+ const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
471
+ conn.createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
472
+ conn.createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
473
+ ]);
474
+ participants.push(...meNodes, ...otherNodes);
475
+ if (meRecipients.length || otherRecipients.length) extraAttrs["phash"] = (0, generics_1.generateParticipantHashV2)([...meRecipients, ...otherRecipients]);
476
+ shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
477
+ }
478
+
479
+ if (participants.length) {
480
+ if (additionalAttributes?.["category"] === "peer") {
481
+ const peerNode = participants[0]?.content?.[0];
482
+ if (peerNode) binaryNodeContent.push(peerNode);
483
+ } else {
484
+ binaryNodeContent.push({ tag: "participants", attrs: {}, content: participants });
485
+ }
486
+ }
487
+
488
+ const stanza = {
489
+ tag: "message",
490
+ attrs: { id: msgId, to: destinationJid, type: getMessageType(message), ...(additionalAttributes || {}) },
491
+ content: binaryNodeContent
492
+ };
493
+
494
+ if (shouldIncludeDeviceIdentity) {
495
+ stanza.content.push({ tag: "device-identity", attrs: {}, content: (0, generics_1.encodeSignedDeviceIdentity)(conn.authState.creds.account, true) });
496
+ }
497
+
498
+ if (reportingToken && !(additionalNodes && additionalNodes.some((n) => n.tag === "reporting"))) {
499
+ stanza.content.push({
500
+ tag: "reporting",
501
+ attrs: {},
502
+ content: [
503
+ {
504
+ tag: "reporting_token",
505
+ attrs: { v: "2" },
506
+ content: reportingToken
507
+ }
508
+ ]
509
+ });
510
+ }
511
+
512
+ const contactTcTokenData = !isGroup && !isStatus ? await conn.authState.keys.get("tctoken", [destinationJid]) : {};
513
+ const tcTokenBuffer = contactTcTokenData[destinationJid]?.token;
514
+ if (tcTokenBuffer) stanza.content.push({ tag: "tctoken", attrs: {}, content: tcTokenBuffer });
515
+
516
+ if (additionalNodes && additionalNodes.length > 0) stanza.content.push(...additionalNodes);
517
+
518
+ await conn.sendNode(stanza);
519
+
520
+ return msgId;
521
+ }
522
+
523
+ exports.sPR = sPR;
524
+ exports.selectiveRelay = sPR;
525
+ exports.default = sPR;
@@ -0,0 +1,78 @@
1
+ import { proto } from "../../WAProto";
2
+ export const StatusLinkType: {
3
+ readonly RASTERIZED_LINK_PREVIEW: 1;
4
+ readonly RASTERIZED_LINK_TRUNCATED: 2;
5
+ readonly RASTERIZED_LINK_FULL_URL: 3;
6
+ };
7
+ export const STICKER_DEFAULT_AREA: {
8
+ readonly x: 0.25;
9
+ readonly y: 0.4;
10
+ readonly width: 0.5;
11
+ readonly height: 0.2;
12
+ };
13
+ export const stickerArea: ({ x, y, width, height }?: {
14
+ x?: number | undefined;
15
+ y?: number | undefined;
16
+ width?: number | undefined;
17
+ height?: number | undefined;
18
+ }) => {
19
+ x: number;
20
+ y: number;
21
+ }[];
22
+ export const locationSticker: ({ latitude, longitude, name, area, skipConfirmation }?: {
23
+ latitude?: any;
24
+ longitude?: any;
25
+ name?: any;
26
+ area?: any;
27
+ skipConfirmation?: any;
28
+ }) => any;
29
+ export const channelSticker: ({ jid, name, serverMessageId, accessibilityText, area }?: {
30
+ jid?: any;
31
+ name?: any;
32
+ serverMessageId?: number | undefined;
33
+ accessibilityText?: any;
34
+ area?: any;
35
+ }) => any;
36
+ export const linkSticker: ({ url, title, area, linkType }?: {
37
+ url?: any;
38
+ title?: any;
39
+ area?: any;
40
+ linkType?: number | undefined;
41
+ }) => any;
42
+ export const musicSticker: ({ songId, title, author, mediaId, artworkDirectPath, artworkSha256, artworkEncSha256, artworkMediaKey, artistAttribution, countryBlocklist, isExplicit, startTimeMs, derivedStartTimeMs, durationMs, area }?: {
43
+ songId?: any;
44
+ title?: any;
45
+ author?: any;
46
+ mediaId?: any;
47
+ artworkDirectPath?: any;
48
+ artworkSha256?: any;
49
+ artworkEncSha256?: any;
50
+ artworkMediaKey?: any;
51
+ artistAttribution?: any;
52
+ countryBlocklist?: any;
53
+ isExplicit?: any;
54
+ startTimeMs?: number | undefined;
55
+ derivedStartTimeMs?: any;
56
+ durationMs?: any;
57
+ area?: any;
58
+ }) => any;
59
+ export const messageSticker: ({ stanzaId, message, area }?: {
60
+ stanzaId?: any;
61
+ message?: any;
62
+ area?: any;
63
+ }) => any;
64
+ export const normalizeStickers: (stickers: any) => proto.InteractiveAnnotation[];
65
+ export const readStickers: (message: any) => any[];
66
+ export const MusicMessageStyle: {
67
+ readonly UNKNOWN: 0;
68
+ readonly VINYL: 1;
69
+ };
70
+ export const MUSIC_ALLOWED_HOSTS: readonly string[];
71
+ export const isMusicHostAllowed: (value: any) => boolean;
72
+ export const buildMusicMessage: ({ songUri, artworkUri, style, contextInfo, ...music }?: {
73
+ songUri?: any;
74
+ artworkUri?: any;
75
+ style?: number | undefined;
76
+ contextInfo?: any;
77
+ }) => any;
78
+ export const readMusicMessage: (msg: any) => any;