sanka-baileyss 2.6.2 → 2.6.4

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.
@@ -35,7 +35,7 @@ const WAProto_1 = require("../../WAProto"),
35
35
  phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
36
36
 
37
37
  exports.UNAUTHORIZED_CODES = [401, 403, 419];
38
- exports.version = [2,3000,1035194821];
38
+ exports.version = baileys_version_json_1.version;
39
39
  exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
40
40
  exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
41
41
  exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
@@ -37,17 +37,11 @@ class GroupCipher {
37
37
  return await this.queueJob(async () => {
38
38
  const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
39
39
  if (!record) {
40
- console.error('[GroupCipher] No SenderKeyRecord found for:', this.senderKeyName.toString());
41
40
  throw new Error('No SenderKeyRecord found for decryption');
42
41
  }
43
42
  const senderKeyMessage = new sender_key_message_1.SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
44
43
  const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
45
44
  if (!senderKeyState) {
46
- console.error('[GroupCipher] No session state found for:', {
47
- senderKeyName: this.senderKeyName.toString(),
48
- keyId: senderKeyMessage.getKeyId(),
49
- availableStates: record.getSenderKeyStates ? record.getSenderKeyStates().length : 'unknown'
50
- });
51
45
  throw new Error(`No session found to decrypt message from ${this.senderKeyName.toString()} with keyId ${senderKeyMessage.getKeyId()}`);
52
46
  }
53
47
  senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
@@ -42,6 +42,7 @@ const sender_key_record_1 = require("./Group/sender-key-record");
42
42
  const Group_1 = require("./Group");
43
43
  function makeLibSignalRepository(auth) {
44
44
  const storage = signalStorage(auth);
45
+ const badMacCounts = new Map();
45
46
  return {
46
47
  decryptGroupMessage({ group, authorJid, msg }) {
47
48
  const senderName = jidToSignalSenderKeyName(group, authorJid);
@@ -64,19 +65,36 @@ function makeLibSignalRepository(auth) {
64
65
  },
65
66
  async decryptMessage({ jid, type, ciphertext }) {
66
67
  const addr = jidToSignalProtocolAddress(jid);
68
+ const addrStr = addr.toString();
67
69
  const session = new libsignal.SessionCipher(storage, addr);
68
70
  let result;
69
- switch (type) {
70
- case 'pkmsg':
71
- result = await session.decryptPreKeyWhisperMessage(ciphertext);
72
- break;
73
- case 'msg':
74
- result = await session.decryptWhisperMessage(ciphertext);
75
- break;
76
- default:
77
- throw new Error(`Unknown message type: ${type}`);
71
+ try {
72
+ switch (type) {
73
+ case 'pkmsg':
74
+ result = await session.decryptPreKeyWhisperMessage(ciphertext);
75
+ break;
76
+ case 'msg':
77
+ result = await session.decryptWhisperMessage(ciphertext);
78
+ break;
79
+ default:
80
+ throw new Error(`Unknown message type: ${type}`);
81
+ }
82
+ badMacCounts.delete(addrStr);
83
+ return result;
84
+ }
85
+ catch (err) {
86
+ if (/Bad MAC|No matching sessions/i.test((err === null || err === void 0 ? void 0 : err.message) || '')) {
87
+ const count = (badMacCounts.get(addrStr) || 0) + 1;
88
+ if (count >= 3) {
89
+ badMacCounts.delete(addrStr);
90
+ await auth.keys.set({ session: { [addrStr]: null } }).catch(() => { });
91
+ }
92
+ else {
93
+ badMacCounts.set(addrStr, count);
94
+ }
95
+ }
96
+ throw err;
78
97
  }
79
- return result;
80
98
  },
81
99
  async encryptMessage({ jid, data }) {
82
100
  const addr = jidToSignalProtocolAddress(jid);
@@ -155,7 +173,6 @@ function signalStorage({ creds, keys }) {
155
173
  if (key) {
156
174
  return sender_key_record_1.SenderKeyRecord.deserialize(key);
157
175
  }
158
- console.warn('[libsignal] No sender key found for:', keyId, '- returning empty SenderKeyRecord');
159
176
  return new sender_key_record_1.SenderKeyRecord();
160
177
  },
161
178
  storeSenderKey: async (senderKeyName, key) => {
@@ -211,8 +211,9 @@ const makeMessagesRecvSocket = (config) => {
211
211
  msgRetryCache.set(key, retryCount);
212
212
  const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
213
213
  if (retryCount === 1) {
214
- const msgId = await requestPlaceholderResend(msgKey);
215
- logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
214
+ requestPlaceholderResend(msgKey)
215
+ .then(id => logger.debug(`sendRetryRequest: requested placeholder resend for message ${id}`))
216
+ .catch(err => logger.debug({ err, msgId }, 'placeholder resend failed'));
216
217
  }
217
218
  const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
218
219
  await authState.keys.transaction(async () => {
@@ -620,7 +621,10 @@ const makeMessagesRecvSocket = (config) => {
620
621
  const sendToAll = !((_a = (0, WABinary_1.jidDecode)(participant)) === null || _a === void 0 ? void 0 : _a.device);
621
622
  await assertSessions([participant], true);
622
623
  if ((0, WABinary_1.isJidGroup)(remoteJid)) {
623
- const senderKeyName = `${remoteJid}::${participant}`;
624
+ const decodedParticipant = (0, WABinary_1.jidDecode)(participant);
625
+ const senderKeyName = decodedParticipant
626
+ ? `${remoteJid}::${decodedParticipant.user}::${decodedParticipant.device || 0}`
627
+ : `${remoteJid}::${participant}`;
624
628
  logger.debug({ remoteJid, participant, senderKeyName }, 'clearing sender key for specific participant on retry');
625
629
  await authState.keys.set({ 'sender-key': { [senderKeyName]: null } });
626
630
 
@@ -813,7 +817,9 @@ const makeMessagesRecvSocket = (config) => {
813
817
  return;
814
818
  }
815
819
  const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
816
- await sendRetryRequest(node, !encNode);
820
+ const stubReason = ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) || '';
821
+ const shouldIncludeKeys = !encNode || /Bad MAC|No matching sessions|No session found/i.test(stubReason);
822
+ await sendRetryRequest(node, shouldIncludeKeys);
817
823
  if (retryRequestDelayMs) {
818
824
  await (0, Utils_1.delay)(retryRequestDelayMs);
819
825
  }
@@ -826,18 +832,18 @@ const makeMessagesRecvSocket = (config) => {
826
832
  else {
827
833
  let type = undefined;
828
834
  if ((_b = msg.key.participant) === null || _b === void 0 ? void 0 : _b.endsWith('@lid')) {
829
- msg.key.participant = node.attrs.participant_pn || authState.creds.me.id;
835
+ msg.key.participant = node.attrs.participant_pn || (msg.key.fromMe ? authState.creds.me.id : msg.key.participant);
830
836
  }
831
837
  if ((0, WABinary_1.isJidGroup)(msg.key.remoteJid) && ((_f = (_e = (_d = (_c = msg.message) === null || _c === void 0 ? void 0 : _c.extendedTextMessage) === null || _d === void 0 ? void 0 : _d.contextInfo) === null || _e === void 0 ? void 0 : _e.participant) === null || _f === void 0 ? void 0 : _f.endsWith('@lid'))) {
832
838
  if (msg.message.extendedTextMessage.contextInfo) {
833
839
  const metadata = await groupMetadata(msg.key.remoteJid);
834
840
  const sender = msg.message.extendedTextMessage.contextInfo.participant;
835
- const found = metadata.participants.find(p => p.id === sender);
841
+ const found = metadata?.participants?.find(p => p.id === sender);
836
842
  msg.message.extendedTextMessage.contextInfo.participant = (found === null || found === void 0 ? void 0 : found.jid) || sender;
837
843
  }
838
844
  }
839
845
  if (!(0, WABinary_1.isJidGroup)(msg.key.remoteJid) && (0, WABinary_1.isLidUser)(msg.key.remoteJid)) {
840
- msg.key.remoteJid = node.attrs.sender_pn || node.attrs.peer_recipient_pn;
846
+ msg.key.remoteJid = node.attrs.sender_pn || node.attrs.peer_recipient_pn || msg.key.remoteJid;
841
847
  }
842
848
  let participant = msg.key.participant;
843
849
  if (category === 'peer') {
@@ -382,7 +382,7 @@ const makeMessagesSocket = (config) => {
382
382
  devices.push(...additionalDevices)
383
383
  }
384
384
 
385
- const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
385
+ const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, (isLid || (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid') ? 'lid' : 's.whatsapp.net', d.device)));
386
386
  const bytes = Utils_1.encodeWAMessage(patched);
387
387
 
388
388
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
@@ -146,7 +146,7 @@ const toPn = async (pn) => {
146
146
  };
147
147
  ws.on(`TAG:${msgId}`, onRecv);
148
148
  ws.on('close', onErr);
149
- ws.off('error', onErr);
149
+ ws.on('error', onErr);
150
150
  });
151
151
  return result;
152
152
  }
@@ -22,7 +22,7 @@ const getUrlInfo = async (text, opts = {
22
22
  }) => {
23
23
  var _a;
24
24
  try {
25
- const retries = 0;
25
+ let retries = 0;
26
26
  const maxRetry = 5;
27
27
  const { getLinkPreview } = await import('link-preview-js');
28
28
  let previewLink = text;
@@ -41,14 +41,14 @@ const getUrlInfo = async (text, opts = {
41
41
  if (forwardedURLObj.hostname === urlObj.hostname
42
42
  || forwardedURLObj.hostname === 'www.' + urlObj.hostname
43
43
  || 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
44
- retries + 1;
44
+ retries += 1;
45
45
  return true;
46
46
  }
47
47
  else {
48
48
  return false;
49
49
  }
50
50
  },
51
- headers: opts.fetchOpts
51
+ headers: opts.fetchOpts?.headers
52
52
  });
53
53
  if (info && 'title' in info && info.title) {
54
54
  const [image] = info.images;
@@ -661,7 +661,8 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
661
661
  const hosts = [...customUploadHosts, ...uploadInfo.hosts];
662
662
  const chunks = [];
663
663
  if (!Buffer.isBuffer(stream)) {
664
- for await (const chunk of stream) {
664
+ const readable = typeof stream === 'string' ? (0, fs_1.createReadStream)(stream) : stream;
665
+ for await (const chunk of readable) {
665
666
  chunks.push(chunk);
666
667
  }
667
668
  }
package/lib/index.js CHANGED
@@ -12,18 +12,18 @@ console.log(`
12
12
  \x1b[90mCopyright © 2026 Sanka Vollerei\n\x1b[0m
13
13
  `)
14
14
 
15
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
16
16
  if (k2 === undefined) k2 = k;
17
17
  var desc = Object.getOwnPropertyDescriptor(m, k);
18
18
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
- desc = { enumerable: true, get: function() { return m[k]; } };
19
+ desc = { enumerable: true, get: function () { return m[k]; } };
20
20
  }
21
21
  Object.defineProperty(o, k2, desc);
22
- }) : (function(o, m, k, k2) {
22
+ }) : (function (o, m, k, k2) {
23
23
  if (k2 === undefined) k2 = k;
24
24
  o[k2] = m[k];
25
25
  }));
26
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ var __exportStar = (this && this.__exportStar) || function (m, exports) {
27
27
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
28
  };
29
29
  var __importDefault = (this && this.__importDefault) || function (mod) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanka-baileyss",
3
- "version": "2.6.2",
3
+ "version": "2.6.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -20,9 +20,11 @@
20
20
  "whatsapp-group",
21
21
  "automation",
22
22
  "multi-device",
23
- "sanka-baileys"
23
+ "sanka-baileys",
24
+ "sanka-wabot",
25
+ "sanka-wabot-md"
24
26
  ],
25
- "homepage": "https://sankavollerei.com",
27
+ "homepage": "https://sankavollerei.web.id",
26
28
  "repository": {
27
29
  "url": "git+ssh://git@github.com/SankaVollereii/Sanka-Baileys.git"
28
30
  },
@@ -122,4 +124,4 @@
122
124
  "bugs": {
123
125
  "url": "https://github.com/WhiskeySockets/baileys/issues"
124
126
  }
125
- }
127
+ }