@prototypevip/baileys 0.1.0 → 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.
- package/lib/Socket/index.js +12 -128
- package/lib/Socket/messages-send.js +27 -44
- package/package.json +2 -2
- package/lib/AntiBan/antiban.js +0 -922
- package/lib/AntiBan/banRecoveryOrchestrator.js +0 -284
- package/lib/AntiBan/cli.js +0 -177
- package/lib/AntiBan/contactGraph.js +0 -236
- package/lib/AntiBan/contentVariator.js +0 -150
- package/lib/AntiBan/credsSnapshot.js +0 -121
- package/lib/AntiBan/deliveryTracker.js +0 -107
- package/lib/AntiBan/deviceFingerprint.js +0 -106
- package/lib/AntiBan/fleetEventStore.js +0 -157
- package/lib/AntiBan/groupOperationGuard.js +0 -116
- package/lib/AntiBan/health.js +0 -207
- package/lib/AntiBan/humanEntropy.js +0 -337
- package/lib/AntiBan/index.js +0 -77
- package/lib/AntiBan/instanceCoordinator.js +0 -175
- package/lib/AntiBan/jidCanonicalizer.js +0 -256
- package/lib/AntiBan/jidCircuitBreaker.js +0 -186
- package/lib/AntiBan/legitimacySignalInjector.js +0 -231
- package/lib/AntiBan/lidFirstResolver.js +0 -174
- package/lib/AntiBan/lidResolver.js +0 -324
- package/lib/AntiBan/messageQueue.js +0 -187
- package/lib/AntiBan/messageRecovery.js +0 -283
- package/lib/AntiBan/messageTypeRegistry.js +0 -369
- package/lib/AntiBan/observability.js +0 -145
- package/lib/AntiBan/patch.js +0 -302
- package/lib/AntiBan/persist.js +0 -87
- package/lib/AntiBan/presenceChoreographer.js +0 -430
- package/lib/AntiBan/presets.js +0 -105
- package/lib/AntiBan/profiles.js +0 -31
- package/lib/AntiBan/proxyRotator.js +0 -306
- package/lib/AntiBan/rateLimiter.js +0 -261
- package/lib/AntiBan/readReceiptVariance.js +0 -88
- package/lib/AntiBan/reconnectThrottle.js +0 -180
- package/lib/AntiBan/replyRatio.js +0 -161
- package/lib/AntiBan/reputationVoucher.js +0 -373
- package/lib/AntiBan/retryReason.js +0 -91
- package/lib/AntiBan/retryTracker.js +0 -172
- package/lib/AntiBan/scheduler.js +0 -111
- package/lib/AntiBan/sessionFingerprint.js +0 -248
- package/lib/AntiBan/sessionStability.js +0 -330
- package/lib/AntiBan/stateAdapter.js +0 -73
- package/lib/AntiBan/stateExport.js +0 -152
- package/lib/AntiBan/stealthConnect.js +0 -130
- package/lib/AntiBan/timelockGuard.js +0 -181
- package/lib/AntiBan/topologyThrottler.js +0 -339
- package/lib/AntiBan/warmup.js +0 -140
- package/lib/AntiBan/webhooks.js +0 -80
- package/lib/AntiBan/wrapper.js +0 -456
package/lib/Socket/index.js
CHANGED
|
@@ -1,72 +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
|
-
// Best-effort background load (fire-and-forget, NOT top-level await —
|
|
52
|
-
// awaiting here breaks require() on this ESM package with ERR_REQUIRE_ASYNC_MODULE).
|
|
53
|
-
// If antiBan is requested before this finishes, makeWASocket() below will just
|
|
54
|
-
// warn and skip protection instead of crashing.
|
|
55
|
-
loadAntiBan();
|
|
56
|
-
|
|
57
4
|
/**
|
|
58
5
|
* Create a WhatsApp socket.
|
|
59
|
-
*
|
|
6
|
+
* Clean version — without AntiBan.
|
|
60
7
|
*/
|
|
61
8
|
const makeWASocket = (config = {}) => {
|
|
62
|
-
const {
|
|
63
|
-
antiBan = false, // مقفول افتراضياً
|
|
64
|
-
antiBanWarmUpState,
|
|
65
|
-
antiBanWrapOptions,
|
|
66
|
-
...restConfig
|
|
67
|
-
} = config || {};
|
|
9
|
+
const restConfig = { ...(config || {}) };
|
|
68
10
|
|
|
11
|
+
// strip any leftover antiBan keys if present
|
|
12
|
+
delete restConfig.antiBan;
|
|
13
|
+
delete restConfig.antiBanWarmUpState;
|
|
14
|
+
delete restConfig.antiBanWrapOptions;
|
|
69
15
|
delete restConfig.userDevicesCache;
|
|
16
|
+
|
|
70
17
|
const newConfig = { ...DEFAULT_CONNECTION_CONFIG, ...restConfig };
|
|
71
18
|
|
|
72
19
|
let sock;
|
|
@@ -78,77 +25,14 @@ const makeWASocket = (config = {}) => {
|
|
|
78
25
|
}
|
|
79
26
|
|
|
80
27
|
sock = makeCommunitiesSocket(newConfig);
|
|
81
|
-
|
|
82
|
-
// ── AntiBan (اختياري) ──
|
|
83
|
-
const enabled =
|
|
84
|
-
antiBan === true ||
|
|
85
|
-
(typeof antiBan === "string" && antiBan.length > 0) ||
|
|
86
|
-
(antiBan && typeof antiBan === "object");
|
|
87
|
-
|
|
88
|
-
if (enabled) {
|
|
89
|
-
if (typeof _wrapSocket !== "function") {
|
|
90
|
-
console.warn(
|
|
91
|
-
"[@prototypevip/baileys] antiBan requested but module not available — socket without protection"
|
|
92
|
-
);
|
|
93
|
-
return sock;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const antiBanConfig =
|
|
97
|
-
antiBan === true
|
|
98
|
-
? "moderate"
|
|
99
|
-
: antiBan; // string preset or object config
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
sock = _wrapSocket(
|
|
103
|
-
sock,
|
|
104
|
-
antiBanConfig,
|
|
105
|
-
antiBanWarmUpState,
|
|
106
|
-
antiBanWrapOptions || {}
|
|
107
|
-
);
|
|
108
|
-
if (newConfig.logger?.info) {
|
|
109
|
-
newConfig.logger.info(
|
|
110
|
-
{ antiBan: typeof antiBanConfig === "string" ? antiBanConfig : "custom" },
|
|
111
|
-
"AntiBan protection enabled"
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
} catch (e) {
|
|
115
|
-
console.warn(
|
|
116
|
-
"[@prototypevip/baileys] AntiBan wrap failed — continuing without it:",
|
|
117
|
-
e?.message || e
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
28
|
return sock;
|
|
123
29
|
};
|
|
124
30
|
|
|
125
|
-
/**
|
|
126
|
-
const wrapSocket = (sock
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
if (typeof _wrapSocketWithFingerprint === "function") {
|
|
131
|
-
return _wrapSocketWithFingerprint(makeSock, opts, wrapOpts);
|
|
132
|
-
}
|
|
133
|
-
return typeof makeSock === "function" ? makeSock(opts || {}) : makeSock;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const PRESETS = new Proxy(
|
|
137
|
-
{},
|
|
138
|
-
{
|
|
139
|
-
get(_, prop) {
|
|
140
|
-
return _PRESETS[prop];
|
|
141
|
-
},
|
|
142
|
-
ownKeys() {
|
|
143
|
-
return Reflect.ownKeys(_PRESETS);
|
|
144
|
-
},
|
|
145
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
146
|
-
if (prop in _PRESETS) {
|
|
147
|
-
return { enumerable: true, configurable: true, value: _PRESETS[prop] };
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
}
|
|
151
|
-
);
|
|
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 = {};
|
|
152
36
|
|
|
153
37
|
export default makeWASocket;
|
|
154
38
|
export { makeWASocket, wrapSocket, wrapSocketWithFingerprint, PRESETS };
|
|
@@ -845,31 +845,10 @@ export const makeMessagesSocket = (config) => {
|
|
|
845
845
|
return {};
|
|
846
846
|
})(),
|
|
847
847
|
]);
|
|
848
|
-
//
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
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
|
-
|
|
859
|
+
participantsList.push(...statusJidList);
|
|
881
860
|
}
|
|
882
861
|
let additionalDevices = await getUSyncDevices(
|
|
883
862
|
participantsList,
|
|
884
863
|
!!useUserDevicesCache,
|
|
885
864
|
false,
|
|
886
865
|
);
|
|
887
|
-
//
|
|
888
|
-
// (
|
|
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
|
|
874
|
+
const missingAlts = [];
|
|
875
|
+
const seenAlt = new Set();
|
|
897
876
|
for (const p of groupData.participants) {
|
|
898
|
-
const
|
|
899
|
-
const
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
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 (
|
|
891
|
+
if (missingAlts.length > 0) {
|
|
909
892
|
logger.debug(
|
|
910
|
-
{ missing:
|
|
911
|
-
"retrying USync for participants
|
|
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
|
-
|
|
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.1.
|
|
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": {
|