@langitdeveloper/baileys 2.2.5 → 2.2.6

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.
@@ -55,8 +55,6 @@ function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
55
55
  updateAgeOnGet: true
56
56
  });
57
57
  const runInTransaction = async (work, label) => {
58
- // mahiru's addTransactionCapability().transaction() only takes one arg,
59
- // the label is accepted (and ignored) for compatibility with upstream.
60
58
  if (typeof parsedKeys.transaction === 'function') {
61
59
  return parsedKeys.transaction(work, label);
62
60
  }
@@ -175,9 +173,6 @@ function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
175
173
  }, `delete-${jids.length}-sessions`);
176
174
  },
177
175
  /**
178
- * Bulk-migrates every known device session of `fromJid`'s user from a PN
179
- * address to the corresponding LID address (`toJid`). Used when WhatsApp
180
- * upgrades a contact from phone-number identity to LID identity.
181
176
  */
182
177
  async migrateSession(fromJid, toJid) {
183
178
  if (!fromJid || (!(0, WABinary_1.isLidUser)(toJid) && !(0, WABinary_1.isHostedLidUser)(toJid))) {
@@ -283,9 +278,6 @@ const jidToSignalSenderKeyName = (group, user) => {
283
278
  };
284
279
  function signalStorage({ creds, keys }, lidMapping) {
285
280
  /**
286
- * If we're storing/loading a session keyed by a PN address but that user
287
- * has since been migrated to a LID, transparently redirect to the LID
288
- * session instead (so we don't keep two divergent sessions for one user).
289
281
  */
290
282
  const resolveLIDSignalAddress = async (id) => {
291
283
  if (id.includes('.')) {
@@ -10,9 +10,6 @@ const {
10
10
  WAJIDDomains,
11
11
  } = require("../WABinary");
12
12
  /**
13
- * Keeps a persistent + in-memory mapping between PN (phone number) jids and
14
- * LID jids. Needed because newer WhatsApp clients can address the same user
15
- * via either identifier, and signal sessions are tied to one or the other.
16
13
  */
17
14
  class LIDMappingStore {
18
15
  constructor(keys, logger, pnToLIDFunc) {
@@ -1036,9 +1036,65 @@ const makeChatsSocket = (config) => {
1036
1036
  const clearMessage = (jid, key, timeStamp) => chatModify({ delete: true, lastMessages: [{ key, messageTimestamp: timeStamp }] }, jid);
1037
1037
  const addOrEditQuickReply = (quickReply) => chatModify({ quickReply }, '');
1038
1038
  const removeQuickReply = (timestamp) => chatModify({ quickReply: { timestamp, deleted: true } }, '');
1039
+ /** convert jid ke format phone number (pn), pake lid mapping store kalo jid-nya lid */
1040
+ const toPn = async (jid) => {
1041
+ if (!jid) {
1042
+ return jid;
1043
+ }
1044
+ if (!WABinary_1.isLidUser(jid)) {
1045
+ return jid;
1046
+ }
1047
+ try {
1048
+ const pn = await sock.signalRepository?.lidMapping?.getPNForLID(jid);
1049
+ return pn || jid;
1050
+ }
1051
+ catch (error) {
1052
+ logger.debug({ jid, error }, 'toPn failed, returning original jid');
1053
+ return jid;
1054
+ }
1055
+ };
1056
+ /** convert jid ke format lid, pake lid mapping store kalo jid-nya pn */
1057
+ const toLID = async (jid) => {
1058
+ if (!jid) {
1059
+ return jid;
1060
+ }
1061
+ if (WABinary_1.isLidUser(jid)) {
1062
+ return jid;
1063
+ }
1064
+ try {
1065
+ const lid = await sock.signalRepository?.lidMapping?.getLIDForPN(jid);
1066
+ return lid || jid;
1067
+ }
1068
+ catch (error) {
1069
+ logger.debug({ jid, error }, 'toLID failed, returning original jid');
1070
+ return jid;
1071
+ }
1072
+ };
1073
+ /**
1074
+ * speculative - resolve username WA jadi jid asli via usync query.
1075
+ * NOTE: server WA lo kemungkinan blm support field ini (fitur username blm rollout ID),
1076
+ * jadi wajar kalo return null terus sampe ada rollout beneran / server support.
1077
+ */
1078
+ const fetchUsername = async (username) => {
1079
+ try {
1080
+ const usyncQuery = new WAUSync_1.USyncQuery()
1081
+ .withContactProtocol()
1082
+ .withUser(new WAUSync_1.USyncUser().withUsername(username));
1083
+ const result = await sock.executeUSyncQuery(usyncQuery);
1084
+ const found = result?.list?.find((a) => !!a.contact);
1085
+ return found ? found.id : null;
1086
+ }
1087
+ catch (error) {
1088
+ logger.debug({ username, error }, 'fetchUsername failed');
1089
+ return null;
1090
+ }
1091
+ };
1039
1092
  return {
1040
1093
  ...sock,
1041
1094
  getLidUser,
1095
+ toPn,
1096
+ toLID,
1097
+ fetchUsername,
1042
1098
  fetchDisappearingDuration,
1043
1099
  createCallLink,
1044
1100
  getBotListV2,
@@ -158,7 +158,6 @@ const makeMessagesSocket = (config) => {
158
158
  }
159
159
  let result = await executeUSyncQuery(query)
160
160
  if (!result) {
161
- // stability fix: query device kadang gagal transient (timeout/network), coba sekali lagi sebelum nyerah
162
161
  logger.debug({ toFetch }, 'usync device query empty, retrying once')
163
162
  result = await executeUSyncQuery(query)
164
163
  }
@@ -265,9 +264,6 @@ const makeMessagesSocket = (config) => {
265
264
  return node;
266
265
  }
267
266
  catch (error) {
268
- // fix: "SessionError: No sessions" (atau error encrypt lain) buat 1 device jangan
269
- // sampe nge-reject Promise.all dan bikin proses crash total - skip device ini aja,
270
- // device lain tetep kekirim normal.
271
267
  logger.warn({ jid, trace: error?.stack, err: error?.toString?.() ?? error }, 'failed to encrypt message for device, skipping (no session?)');
272
268
  return null;
273
269
  }
@@ -348,8 +344,6 @@ const makeMessagesSocket = (config) => {
348
344
  const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
349
345
  devices.push(...additionalDevices)
350
346
  }
351
- // fallback: kalo server ga ngasih addressingMode di group metadata (kadang kosong/null),
352
- // tebak dari suffix jid participant sendiri drpd langsung default ke pn - lebih akurat pas grup lid-only
353
347
  if (groupData && !groupData.addressingMode && groupData.participants?.length) {
354
348
  const lidCount = groupData.participants.filter(p => WABinary_1.isLidUser(p.id)).length
355
349
  if (lidCount > 0 && lidCount === groupData.participants.length) {
@@ -371,16 +365,12 @@ const makeMessagesSocket = (config) => {
371
365
  const { user: selfLidUser } = meLid ? WABinary_1.jidDecode(meLid) : { user: null };
372
366
  for (const { user, device } of devices) {
373
367
  const targetJid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
374
- // a device never needs its own sender-key re-sent to it - it already has it
375
368
  const isSendingDeviceItself = targetJid === meId || (meLid && targetJid === meLid);
376
369
  if (isSendingDeviceItself) {
377
370
  logger.debug({ targetJid, meId, meLid }, 'skipping sender\'s own device for sender-key distribution');
378
371
  continue;
379
372
  }
380
373
  const belongsToSelf = user === selfPnUser || user === selfLidUser;
381
- // when this call targets one specific participant (a retry resend),
382
- // our own other devices don't need it - they're already in sync via
383
- // the normal multi-device session, only the actual peer does
384
374
  const isSkippedAsOwnDeviceDuringTargetedResend = !!participant && !(0, WABinary_1.isJidGroup)(targetJid) && !isStatus && belongsToSelf;
385
375
  if (isSkippedAsOwnDeviceDuringTargetedResend) {
386
376
  continue;
@@ -542,9 +532,6 @@ const makeMessagesSocket = (config) => {
542
532
  if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
543
533
  stanza.content.push(...additionalNodes);
544
534
  }
545
- // TC (Trusted Contact) token: attach our stored token for this peer (if any
546
- // and not expired) onto the outgoing stanza - mirrors WA Web's reliability
547
- // mechanism for 1:1 chats. Ported from official Baileys v7.
548
535
  const is1on1Send = isPrivate && !isStatus;
549
536
  const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
550
537
  let tcTokenJid = jid;
@@ -568,9 +555,6 @@ const makeMessagesSocket = (config) => {
568
555
  }
569
556
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
570
557
  await sendNode(stanza);
571
- // Fire-and-forget: after sending, issue our own token to this contact so
572
- // future messages from them get the reliability benefit too. Skipped for
573
- // protocol messages, PSA, and bot/MetaAI contacts (matches WA Web behavior).
574
558
  if (is1on1Send) {
575
559
  try {
576
560
  const isProtocolMsg = !!Types_1.WAProto.Message.fromObject(message)?.protocolMessage;
@@ -695,6 +679,12 @@ const makeMessagesSocket = (config) => {
695
679
  else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
696
680
  return 'payment_method'
697
681
  }
682
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_key_info') {
683
+ return 'payment_key_info'
684
+ }
685
+ else if (message.listMessage?.listType === Types_1.WAProto.Message.ListMessage.ListType.PRODUCT_LIST) {
686
+ return 'catalog_message'
687
+ }
698
688
  else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
699
689
  return 'interactive'
700
690
  }
@@ -728,7 +718,7 @@ const makeMessagesSocket = (config) => {
728
718
  });
729
719
  return result;
730
720
  }
731
- /** issues our own TC (Trusted Contact) tokens to the given jids - used internally after sending, also callable directly */
721
+ /** */
732
722
  const issuePrivacyTokens = async (jids, timestamp) => {
733
723
  const t = (timestamp !== undefined ? timestamp : (0, Utils_1.unixTimestampSeconds)()).toString();
734
724
  const result = await query({
@@ -255,6 +255,27 @@ const generateMessageIDV2 = (userId) => {
255
255
  return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
256
256
  };
257
257
  exports.generateMessageIDV2 = generateMessageIDV2;
258
+ // alias biar jelas ini yg dipake device Android (format 3EB0 + hash)
259
+ const generateMessageIDAndroid = (userId) => generateMessageIDV2(userId);
260
+ exports.generateMessageIDAndroid = generateMessageIDAndroid;
261
+ // speculative - format id gaya iOS/Safari: hex uppercase polos tanpa prefix "3EB0"
262
+ // (dipake modded-baileys lain buat nyamain "keliatan kirim dari iPhone/Safari")
263
+ const generateMessageIDIos = (userId) => {
264
+ const data = Buffer.alloc(8 + 20 + 16);
265
+ data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
266
+ if (userId) {
267
+ const id = (0, WABinary_1.jidDecode)(userId);
268
+ if (id === null || id === void 0 ? void 0 : id.user) {
269
+ data.write(id.user, 8);
270
+ data.write('@c.us', 8 + id.user.length);
271
+ }
272
+ }
273
+ const random = (0, crypto_1.randomBytes)(16);
274
+ random.copy(data, 28);
275
+ const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
276
+ return hash.toString('hex').toUpperCase().substring(0, 20);
277
+ };
278
+ exports.generateMessageIDIos = generateMessageIDIos;
258
279
  // generate a random ID to attach to a message
259
280
  const generateMessageID = () => 'Z4PH-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
260
281
  exports.generateMessageID = generateMessageID;
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
- * TC (Trusted Contact) token helpers.
4
+ * token helpers.
5
5
  *
6
- * File ini sebelumnya HILANG dari lib (di-require di messages-send.js tapi ga pernah dibikin),
7
- * bikin proses crash instant pas start ("Cannot find module '../Utils/tc-token-utils'").
8
- *
9
- * Semua pemanggil fungsi-fungsi ini di messages-send.js udah dibungkus try/catch, jadi kalo
10
- * logic di sini meleset/gagal, efeknya cuma "kirim tanpa tctoken" - BUKAN crash. Implementasi
11
- * di bawah sengaja dibikin konservatif (aman & simpel) drpd nebak detail wire-format IQ result
12
- * WA yang ga kekonfirm, biar resiko rendah.
13
6
  */
14
- const TC_TOKEN_TTL_SECONDS = 30 * 24 * 60 * 60; // 30 hari, tebakan aman - token dianggap basi kalo lebih lama dari ini
15
- const TC_TOKEN_REISSUE_INTERVAL_SECONDS = 7 * 24 * 60 * 60; // 7 hari - jangan reissue token tiap kirim pesan
7
+ const token_second = 30 * 24 * 60 * 60;
8
+ const interval_second = 7 * 24 * 60 * 60;
16
9
  function nowSeconds() {
17
10
  return Math.floor(Date.now() / 1000);
18
11
  }
19
- /** cek apakah tctoken yg tersimpan udah kadaluarsa berdasarkan timestamp-nya */
12
+
20
13
  function isTcTokenExpired(timestamp) {
21
14
  if (!timestamp) {
22
15
  return true;
@@ -25,9 +18,9 @@ function isTcTokenExpired(timestamp) {
25
18
  if (!Number.isFinite(ts) || ts <= 0) {
26
19
  return true;
27
20
  }
28
- return (nowSeconds() - ts) > TC_TOKEN_TTL_SECONDS;
21
+ return (nowSeconds() - ts) > token_second;
29
22
  }
30
- /** cek apakah perlu issue token baru ke kontak ini (biar ga spam issue tiap kirim pesan) */
23
+
31
24
  function shouldSendNewTcToken(senderTimestamp) {
32
25
  if (!senderTimestamp) {
33
26
  return true;
@@ -36,9 +29,9 @@ function shouldSendNewTcToken(senderTimestamp) {
36
29
  if (!Number.isFinite(ts) || ts <= 0) {
37
30
  return true;
38
31
  }
39
- return (nowSeconds() - ts) > TC_TOKEN_REISSUE_INTERVAL_SECONDS;
32
+ return (nowSeconds() - ts) > interval_second;
40
33
  }
41
- /** tentuin jid mana yg dipake sbg key penyimpanan tctoken (prefer LID kalo ada mapping-nya) */
34
+
42
35
  async function resolveTcTokenJid(jid, getLIDForPN) {
43
36
  try {
44
37
  if (typeof getLIDForPN === 'function') {
@@ -49,11 +42,10 @@ async function resolveTcTokenJid(jid, getLIDForPN) {
49
42
  }
50
43
  }
51
44
  catch (_a) {
52
- // biarin fallback ke jid asli
53
45
  }
54
46
  return jid;
55
47
  }
56
- /** tentuin jid mana yg dituju pas issue token baru (lid atau pn, tergantung server props) */
48
+
57
49
  async function resolveIssuanceJid(jid, preferLid, getLIDForPN, getPNForLID) {
58
50
  try {
59
51
  if (preferLid && typeof getLIDForPN === 'function') {
@@ -70,11 +62,10 @@ async function resolveIssuanceJid(jid, preferLid, getLIDForPN, getPNForLID) {
70
62
  }
71
63
  }
72
64
  catch (_a) {
73
- // biarin fallback ke jid asli
74
65
  }
75
66
  return jid;
76
67
  }
77
- /** parse hasil IQ dari issuePrivacyTokens jadi entry token per-jid, konservatif - return {} kalo shape ga dikenal */
68
+
78
69
  async function storeTcTokensFromIqResult({ result, fallbackJid, keys, getLIDForPN }) {
79
70
  var _a, _b, _c;
80
71
  try {
@@ -96,11 +87,10 @@ async function storeTcTokensFromIqResult({ result, fallbackJid, keys, getLIDForP
96
87
  return entry;
97
88
  }
98
89
  catch (_d) {
99
- // ga dikenal formatnya / gagal parse - aman, cuma berarti token ga ke-simpen
100
90
  return {};
101
91
  }
102
92
  }
103
- /** gabungin entry tctoken yg udah ada di store dgn yg baru buat ditulis ulang via keys.set */
93
+
104
94
  async function buildMergedTcTokenIndexWrite(keys, jids) {
105
95
  var _a;
106
96
  const merged = {};
@@ -113,7 +103,6 @@ async function buildMergedTcTokenIndexWrite(keys, jids) {
113
103
  }
114
104
  }
115
105
  catch (_b) {
116
- // kalo gagal baca existing, ya udah return apa adanya (bisa kosong)
117
106
  }
118
107
  return merged;
119
108
  }
@@ -155,7 +155,7 @@ const getAdditionalNode = (name) => {
155
155
  payment_status: 'payment_status',
156
156
  payment_method: 'payment_method'
157
157
  }
158
-
158
+
159
159
  const flow_name = {
160
160
  cta_catalog: 'cta_catalog',
161
161
  mpm: 'mpm',
@@ -163,9 +163,25 @@ const getAdditionalNode = (name) => {
163
163
  view_catalog: 'automated_greeting_message_view_catalog',
164
164
  wa_pay_detail: 'wa_payment_transaction_details',
165
165
  send_location: 'send_location',
166
+ // speculative - blm ada konfirmasi resmi nama native_flow-nya, tebakan berdasarkan pola yg udah ada
167
+ payment_key_info: 'wa_payment_key_info',
166
168
  }
167
-
168
- if(order_response_name[name]) {
169
+
170
+ if (name === 'catalog_message') {
171
+ // list message isi produk katalog -> beda struktur dari native_flow, node <list> bukan <interactive>
172
+ return [{
173
+ tag: 'biz',
174
+ attrs: {},
175
+ content: [{
176
+ tag: 'list',
177
+ attrs: {
178
+ type: 'product_list',
179
+ v: '2'
180
+ },
181
+ content: []
182
+ }]
183
+ }]
184
+ } else if(order_response_name[name]) {
169
185
  return [{
170
186
  tag: 'biz',
171
187
  attrs: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langitdeveloper/baileys",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "description": "WhatsApp API Modification By Langit",
5
5
  "keywords": [
6
6
  "whatsapp",