@prototypevip/baileys 0.0.9 → 0.1.1

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 (50) hide show
  1. package/lib/Socket/index.js +12 -135
  2. package/lib/Socket/messages-send.js +27 -44
  3. package/package.json +2 -2
  4. package/lib/AntiBan/antiban.js +0 -922
  5. package/lib/AntiBan/banRecoveryOrchestrator.js +0 -284
  6. package/lib/AntiBan/cli.js +0 -177
  7. package/lib/AntiBan/contactGraph.js +0 -236
  8. package/lib/AntiBan/contentVariator.js +0 -150
  9. package/lib/AntiBan/credsSnapshot.js +0 -121
  10. package/lib/AntiBan/deliveryTracker.js +0 -107
  11. package/lib/AntiBan/deviceFingerprint.js +0 -106
  12. package/lib/AntiBan/fleetEventStore.js +0 -157
  13. package/lib/AntiBan/groupOperationGuard.js +0 -116
  14. package/lib/AntiBan/health.js +0 -207
  15. package/lib/AntiBan/humanEntropy.js +0 -337
  16. package/lib/AntiBan/index.js +0 -77
  17. package/lib/AntiBan/instanceCoordinator.js +0 -175
  18. package/lib/AntiBan/jidCanonicalizer.js +0 -256
  19. package/lib/AntiBan/jidCircuitBreaker.js +0 -186
  20. package/lib/AntiBan/legitimacySignalInjector.js +0 -231
  21. package/lib/AntiBan/lidFirstResolver.js +0 -174
  22. package/lib/AntiBan/lidResolver.js +0 -324
  23. package/lib/AntiBan/messageQueue.js +0 -187
  24. package/lib/AntiBan/messageRecovery.js +0 -283
  25. package/lib/AntiBan/messageTypeRegistry.js +0 -369
  26. package/lib/AntiBan/observability.js +0 -145
  27. package/lib/AntiBan/patch.js +0 -302
  28. package/lib/AntiBan/persist.js +0 -87
  29. package/lib/AntiBan/presenceChoreographer.js +0 -430
  30. package/lib/AntiBan/presets.js +0 -105
  31. package/lib/AntiBan/profiles.js +0 -31
  32. package/lib/AntiBan/proxyRotator.js +0 -306
  33. package/lib/AntiBan/rateLimiter.js +0 -261
  34. package/lib/AntiBan/readReceiptVariance.js +0 -88
  35. package/lib/AntiBan/reconnectThrottle.js +0 -180
  36. package/lib/AntiBan/replyRatio.js +0 -161
  37. package/lib/AntiBan/reputationVoucher.js +0 -373
  38. package/lib/AntiBan/retryReason.js +0 -91
  39. package/lib/AntiBan/retryTracker.js +0 -172
  40. package/lib/AntiBan/scheduler.js +0 -111
  41. package/lib/AntiBan/sessionFingerprint.js +0 -248
  42. package/lib/AntiBan/sessionStability.js +0 -330
  43. package/lib/AntiBan/stateAdapter.js +0 -73
  44. package/lib/AntiBan/stateExport.js +0 -152
  45. package/lib/AntiBan/stealthConnect.js +0 -130
  46. package/lib/AntiBan/timelockGuard.js +0 -181
  47. package/lib/AntiBan/topologyThrottler.js +0 -339
  48. package/lib/AntiBan/warmup.js +0 -140
  49. package/lib/AntiBan/webhooks.js +0 -80
  50. package/lib/AntiBan/wrapper.js +0 -456
@@ -1,79 +1,19 @@
1
1
  import { DEFAULT_CONNECTION_CONFIG } from "../Defaults/index.js";
2
2
  import { makeCommunitiesSocket } from "./communities.js";
3
3
 
4
- /**
5
- * Optional AntiBan — مقفول افتراضياً.
6
- * لتفعيله مرّر في إعدادات makeWASocket:
7
- * makeWASocket({ antiBan: true }) // moderate preset
8
- * makeWASocket({ antiBan: 'conservative' }) // preset name
9
- * makeWASocket({ antiBan: { maxPerMinute: 8, ... } }) // config مخصص
10
- * makeWASocket({ antiBan: false }) // صراحة مقفول (الافتراضي)
11
- *
12
- * الحالة الاختيارية:
13
- * antiBanWarmUpState — حالة الـ warmup المحفوظة
14
- * antiBanWrapOptions — خيارات إضافية لـ wrapSocket
15
- */
16
-
17
- let _wrapSocket = null;
18
- let _wrapSocketWithFingerprint = null;
19
- let _PRESETS = {};
20
- let _antiBanLoadError = null;
21
-
22
- async function loadAntiBan() {
23
- if (_wrapSocket) return true;
24
- if (_antiBanLoadError) return false;
25
- try {
26
- const mod = await import("../AntiBan/index.js");
27
- _wrapSocket = mod.wrapSocket;
28
- _wrapSocketWithFingerprint = mod.wrapSocketWithFingerprint;
29
- _PRESETS = mod.PRESETS || {};
30
- return true;
31
- } catch (e) {
32
- // fallback: try wrapper export path
33
- try {
34
- const wrap = await import("../AntiBan/wrapper.js");
35
- const presets = await import("../AntiBan/presets.js").catch(() => ({}));
36
- _wrapSocket = wrap.wrapSocket;
37
- _wrapSocketWithFingerprint = wrap.wrapSocketWithFingerprint;
38
- _PRESETS = presets.PRESETS || {};
39
- return true;
40
- } catch (e2) {
41
- _antiBanLoadError = e2;
42
- console.warn(
43
- "[@prototypevip/baileys] AntiBan module failed to load — continuing without it:",
44
- e2?.message || e2
45
- );
46
- return false;
47
- }
48
- }
49
- }
50
-
51
- // Sync load attempt for ESM top-level (best-effort)
52
- try {
53
- const wrap = await import("../AntiBan/wrapper.js");
54
- _wrapSocket = wrap.wrapSocket;
55
- _wrapSocketWithFingerprint = wrap.wrapSocketWithFingerprint;
56
- try {
57
- const presets = await import("../AntiBan/presets.js");
58
- _PRESETS = presets.PRESETS || {};
59
- } catch {}
60
- } catch (e) {
61
- _antiBanLoadError = e;
62
- }
63
-
64
4
  /**
65
5
  * Create a WhatsApp socket.
66
- * AntiBan مقفول افتراضياً — فعّله عبر config.antiBan
6
+ * Clean version — without AntiBan.
67
7
  */
68
8
  const makeWASocket = (config = {}) => {
69
- const {
70
- antiBan = false, // مقفول افتراضياً
71
- antiBanWarmUpState,
72
- antiBanWrapOptions,
73
- ...restConfig
74
- } = config || {};
9
+ const restConfig = { ...(config || {}) };
75
10
 
11
+ // strip any leftover antiBan keys if present
12
+ delete restConfig.antiBan;
13
+ delete restConfig.antiBanWarmUpState;
14
+ delete restConfig.antiBanWrapOptions;
76
15
  delete restConfig.userDevicesCache;
16
+
77
17
  const newConfig = { ...DEFAULT_CONNECTION_CONFIG, ...restConfig };
78
18
 
79
19
  let sock;
@@ -85,77 +25,14 @@ const makeWASocket = (config = {}) => {
85
25
  }
86
26
 
87
27
  sock = makeCommunitiesSocket(newConfig);
88
-
89
- // ── AntiBan (اختياري) ──
90
- const enabled =
91
- antiBan === true ||
92
- (typeof antiBan === "string" && antiBan.length > 0) ||
93
- (antiBan && typeof antiBan === "object");
94
-
95
- if (enabled) {
96
- if (typeof _wrapSocket !== "function") {
97
- console.warn(
98
- "[@prototypevip/baileys] antiBan requested but module not available — socket without protection"
99
- );
100
- return sock;
101
- }
102
-
103
- const antiBanConfig =
104
- antiBan === true
105
- ? "moderate"
106
- : antiBan; // string preset or object config
107
-
108
- try {
109
- sock = _wrapSocket(
110
- sock,
111
- antiBanConfig,
112
- antiBanWarmUpState,
113
- antiBanWrapOptions || {}
114
- );
115
- if (newConfig.logger?.info) {
116
- newConfig.logger.info(
117
- { antiBan: typeof antiBanConfig === "string" ? antiBanConfig : "custom" },
118
- "AntiBan protection enabled"
119
- );
120
- }
121
- } catch (e) {
122
- console.warn(
123
- "[@prototypevip/baileys] AntiBan wrap failed — continuing without it:",
124
- e?.message || e
125
- );
126
- }
127
- }
128
-
129
28
  return sock;
130
29
  };
131
30
 
132
- /** Pass-through stubs when antiban is not loaded; real functions when loaded */
133
- const wrapSocket = (sock, ...args) =>
134
- typeof _wrapSocket === "function" ? _wrapSocket(sock, ...args) : sock;
135
-
136
- const wrapSocketWithFingerprint = (makeSock, opts, wrapOpts) => {
137
- if (typeof _wrapSocketWithFingerprint === "function") {
138
- return _wrapSocketWithFingerprint(makeSock, opts, wrapOpts);
139
- }
140
- return typeof makeSock === "function" ? makeSock(opts || {}) : makeSock;
141
- };
142
-
143
- const PRESETS = new Proxy(
144
- {},
145
- {
146
- get(_, prop) {
147
- return _PRESETS[prop];
148
- },
149
- ownKeys() {
150
- return Reflect.ownKeys(_PRESETS);
151
- },
152
- getOwnPropertyDescriptor(_, prop) {
153
- if (prop in _PRESETS) {
154
- return { enumerable: true, configurable: true, value: _PRESETS[prop] };
155
- }
156
- },
157
- }
158
- );
31
+ /** Stubs kept for API compatibility (no-op without AntiBan) */
32
+ const wrapSocket = (sock) => sock;
33
+ const wrapSocketWithFingerprint = (makeSock, opts) =>
34
+ typeof makeSock === "function" ? makeSock(opts || {}) : makeSock;
35
+ const PRESETS = {};
159
36
 
160
37
  export default makeWASocket;
161
38
  export { makeWASocket, wrapSocket, wrapSocketWithFingerprint, PRESETS };
@@ -845,31 +845,10 @@ export const makeMessagesSocket = (config) => {
845
845
  return {};
846
846
  })(),
847
847
  ]);
848
- // نبني قائمة المشاركين + بدائل LID/PN عشان حسابات اليوزرنيم
849
- // (اللي أحياناً USync بيرجع فاضي لو استعلمنا بصيغة واحدة بس)
850
- const participantsList = [];
851
- const seenParticipantUsers = new Set();
852
- const addParticipantJid = (jid) => {
853
- if (!jid || typeof jid !== "string") return;
854
- const normalized = jidNormalizedUser(jid);
855
- const user = jidDecode(normalized)?.user;
856
- if (!user || seenParticipantUsers.has(user + ":" + (normalized.split("@")[1] || ""))) {
857
- // نسمح بنفس الـ user بصيغتين مختلفتين (pn + lid) بس نمنع التكرار الحرفي
858
- }
859
- if (participantsList.includes(normalized) || participantsList.includes(jid)) return;
860
- participantsList.push(normalized);
861
- if (user) seenParticipantUsers.add(user);
862
- };
863
- if (groupData?.participants) {
864
- for (const p of groupData.participants) {
865
- addParticipantJid(p.id);
866
- // بديل LID لو الـ id رقم (PN) — مهم لحسابات اليوزرنيم
867
- if (p.lid) addParticipantJid(p.lid);
868
- // بديل الرقم لو الـ id LID
869
- if (p.phoneNumber) addParticipantJid(p.phoneNumber);
870
- if (p.jid && p.jid !== p.id) addParticipantJid(p.jid);
871
- }
872
- }
848
+ // قائمة المشاركين الأساسية (زي الرسمي) — p.id بس عشان ميأثرش على الناس العادية
849
+ const participantsList = groupData?.participants
850
+ ? groupData.participants.map((p) => p.id)
851
+ : [];
873
852
  if (groupData?.ephemeralDuration && groupData.ephemeralDuration > 0) {
874
853
  additionalAttributes = {
875
854
  ...additionalAttributes,
@@ -877,42 +856,46 @@ export const makeMessagesSocket = (config) => {
877
856
  };
878
857
  }
879
858
  if (isStatus && statusJidList) {
880
- for (const s of statusJidList) addParticipantJid(s);
859
+ participantsList.push(...statusJidList);
881
860
  }
882
861
  let additionalDevices = await getUSyncDevices(
883
862
  participantsList,
884
863
  !!useUserDevicesCache,
885
864
  false,
886
865
  );
887
- // لو في مشاركين معرفين في الميتاداتا ومفيش أي device ليهم في النتيجة
888
- // (شائع مع username/LID)، نعيد الاستعلام من غير كاش وبمهلة أطول
889
- // على الـ JIDs الناقصة فقط — من غير ما نأثر على باقي الجروب
866
+ // Fallback لأصحاب اليوزرنيم/LID اللي p.id بتاعهم مرجعش أجهزة:
867
+ // نجرب الصيغة البديلة (lid أو phoneNumber) بس للناقصين — من غير ما نلوّث القائمة الأساسية
890
868
  if (groupData?.participants?.length) {
891
869
  const coveredUsers = new Set(
892
870
  additionalDevices
893
871
  .map((d) => d.user || jidDecode(d.jid)?.user)
894
872
  .filter(Boolean),
895
873
  );
896
- const missingJids = [];
874
+ const missingAlts = [];
875
+ const seenAlt = new Set();
897
876
  for (const p of groupData.participants) {
898
- const candidates = [p.id, p.lid, p.phoneNumber, p.jid].filter(Boolean);
899
- const userIds = candidates
900
- .map((j) => jidDecode(jidNormalizedUser(j))?.user)
901
- .filter(Boolean);
902
- if (userIds.some((u) => coveredUsers.has(u))) continue;
903
- // جرب LID أولاً لو موجود (أحسن لليوزرنيم)، وإلا id الأصلي
904
- if (p.lid) missingJids.push(jidNormalizedUser(p.lid));
905
- else if (p.id) missingJids.push(jidNormalizedUser(p.id));
906
- else if (p.phoneNumber) missingJids.push(jidNormalizedUser(p.phoneNumber));
877
+ const idNorm = p.id ? jidNormalizedUser(p.id) : null;
878
+ const idUser = idNorm ? jidDecode(idNorm)?.user : null;
879
+ if (idUser && coveredUsers.has(idUser)) continue;
880
+ // جرب البدائل المختلفة عن p.id فقط
881
+ const alts = [p.lid, p.phoneNumber, p.jid].filter(Boolean);
882
+ for (const alt of alts) {
883
+ const altNorm = jidNormalizedUser(alt);
884
+ if (!altNorm || altNorm === idNorm || seenAlt.has(altNorm)) continue;
885
+ const altUser = jidDecode(altNorm)?.user;
886
+ if (altUser && coveredUsers.has(altUser)) continue;
887
+ seenAlt.add(altNorm);
888
+ missingAlts.push(altNorm);
889
+ }
907
890
  }
908
- if (missingJids.length > 0) {
891
+ if (missingAlts.length > 0) {
909
892
  logger.debug(
910
- { missing: missingJids.length, jids: missingJids.slice(0, 5) },
911
- "retrying USync for participants with no devices (likely username/LID)",
893
+ { missing: missingAlts.length, jids: missingAlts.slice(0, 5) },
894
+ "retrying USync for missing participants (username/LID fallback)",
912
895
  );
913
896
  try {
914
897
  const retryDevices = await getUSyncDevices(
915
- missingJids,
898
+ missingAlts,
916
899
  false, // no cache
917
900
  false,
918
901
  8000, // longer timeout
@@ -921,7 +904,7 @@ export const makeMessagesSocket = (config) => {
921
904
  additionalDevices = [...additionalDevices, ...retryDevices];
922
905
  }
923
906
  } catch (e) {
924
- logger.warn({ e }, "USync retry for missing participants failed");
907
+ logger.warn({ e }, "USync retry for missing username/LID participants failed");
925
908
  }
926
909
  }
927
910
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prototypevip/baileys",
3
- "version": "0.0.9",
4
- "description": "Baileys fork (@prototypevip/baileys) — clean, without anti-ban",
3
+ "version": "0.1.1",
4
+ "description": "Baileys fork (@prototypevip/baileys) — clean, without anti-ban, group encryption disabled (like 0.0.8)",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
7
7
  "scripts": {