@celestial-community/baileys 0.0.1-security → 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.

Potentially problematic release.


This version of @celestial-community/baileys might be problematic. Click here for more details.

Files changed (175) hide show
  1. package/WAProto/index.js +138933 -0
  2. package/engine-requirements.js +10 -0
  3. package/lib/Defaults/baileys-version.json +7 -0
  4. package/lib/Defaults/index.js +157 -0
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +15 -0
  7. package/lib/Signal/Group/group-session-builder.js +94 -0
  8. package/lib/Signal/Group/group_cipher.js +118 -0
  9. package/lib/Signal/Group/index.js +138 -0
  10. package/lib/Signal/Group/keyhelper.js +75 -0
  11. package/lib/Signal/Group/queue-job.js +54 -0
  12. package/lib/Signal/Group/sender-chain-key.js +39 -0
  13. package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
  14. package/lib/Signal/Group/sender-key-message.js +76 -0
  15. package/lib/Signal/Group/sender-key-name.js +50 -0
  16. package/lib/Signal/Group/sender-key-record.js +65 -0
  17. package/lib/Signal/Group/sender-key-state.js +114 -0
  18. package/lib/Signal/Group/sender-message-key.js +33 -0
  19. package/lib/Signal/libsignal.js +204 -0
  20. package/lib/Signal/lid-mapping.js +267 -0
  21. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  22. package/lib/Socket/Client/index.js +32 -0
  23. package/lib/Socket/Client/mobile-socket-client.js +82 -0
  24. package/lib/Socket/Client/web-socket-client.js +89 -0
  25. package/lib/Socket/Denzy-ZeroDay.js +805 -0
  26. package/lib/Socket/business.js +279 -0
  27. package/lib/Socket/chats.js +1169 -0
  28. package/lib/Socket/community.d.ts +120 -0
  29. package/lib/Socket/community.js +388 -0
  30. package/lib/Socket/graphql.js +1122 -0
  31. package/lib/Socket/groups.js +345 -0
  32. package/lib/Socket/index.js +22 -0
  33. package/lib/Socket/interop.js +265 -0
  34. package/lib/Socket/lid-mapping.js +111 -0
  35. package/lib/Socket/messages-recv.js +1385 -0
  36. package/lib/Socket/messages-send.js +956 -0
  37. package/lib/Socket/mex.js +69 -0
  38. package/lib/Socket/newsletter.js +424 -0
  39. package/lib/Socket/privacy.js +229 -0
  40. package/lib/Socket/registration.js +190 -0
  41. package/lib/Socket/socket.js +783 -0
  42. package/lib/Socket/username.d.ts +185 -0
  43. package/lib/Socket/username.js +168 -0
  44. package/lib/Socket/usync.js +80 -0
  45. package/lib/Store/index.js +14 -0
  46. package/lib/Store/keyed-db.js +158 -0
  47. package/lib/Store/make-cache-manager-store.js +88 -0
  48. package/lib/Store/make-in-memory-store.js +484 -0
  49. package/lib/Store/make-ordered-dictionary.js +78 -0
  50. package/lib/Store/object-repository.js +27 -0
  51. package/lib/Types/Auth.js +2 -0
  52. package/lib/Types/Call.js +2 -0
  53. package/lib/Types/Chat.js +10 -0
  54. package/lib/Types/Contact.js +2 -0
  55. package/lib/Types/Events.js +2 -0
  56. package/lib/Types/GroupMetadata.js +2 -0
  57. package/lib/Types/Label.js +27 -0
  58. package/lib/Types/LabelAssociation.js +9 -0
  59. package/lib/Types/Message.js +14 -0
  60. package/lib/Types/MexUpdates.js +19 -0
  61. package/lib/Types/Newsletter.js +38 -0
  62. package/lib/Types/Product.js +2 -0
  63. package/lib/Types/RichType.js +30 -0
  64. package/lib/Types/Signal.js +2 -0
  65. package/lib/Types/Socket.js +2 -0
  66. package/lib/Types/State.js +2 -0
  67. package/lib/Types/USync.js +2 -0
  68. package/lib/Types/index.js +58 -0
  69. package/lib/Utils/anti-ban.js +339 -0
  70. package/lib/Utils/anti-delete.d.ts +158 -0
  71. package/lib/Utils/anti-delete.js +293 -0
  72. package/lib/Utils/antiban-presets.js +91 -0
  73. package/lib/Utils/antiban-profiles.js +43 -0
  74. package/lib/Utils/auth-utils.js +210 -0
  75. package/lib/Utils/baileys-event-stream.js +66 -0
  76. package/lib/Utils/browser-utils.js +52 -0
  77. package/lib/Utils/business.js +261 -0
  78. package/lib/Utils/chat-control.d.ts +113 -0
  79. package/lib/Utils/chat-control.js +230 -0
  80. package/lib/Utils/chat-utils.js +922 -0
  81. package/lib/Utils/companion-reg-client-utils.js +37 -0
  82. package/lib/Utils/contact-graph-warmer.js +208 -0
  83. package/lib/Utils/crypto.js +196 -0
  84. package/lib/Utils/decode-wa-message.js +208 -0
  85. package/lib/Utils/delivery-tracker.js +110 -0
  86. package/lib/Utils/device-fingerprint.js +135 -0
  87. package/lib/Utils/event-buffer.js +531 -0
  88. package/lib/Utils/generics.js +571 -0
  89. package/lib/Utils/group-operation-guard.js +147 -0
  90. package/lib/Utils/health-monitor.js +207 -0
  91. package/lib/Utils/history.js +122 -0
  92. package/lib/Utils/human-entropy.js +226 -0
  93. package/lib/Utils/identity-change-handler.js +72 -0
  94. package/lib/Utils/index.js +83 -0
  95. package/lib/Utils/interactive-message.d.ts +139 -0
  96. package/lib/Utils/interactive-message.js +273 -0
  97. package/lib/Utils/legitimacy-signal-injector.js +180 -0
  98. package/lib/Utils/link-preview.js +106 -0
  99. package/lib/Utils/logger.d.ts +13 -0
  100. package/lib/Utils/logger.js +9 -0
  101. package/lib/Utils/lt-hash.js +54 -0
  102. package/lib/Utils/make-mutex.js +41 -0
  103. package/lib/Utils/message-composer.d.ts +106 -0
  104. package/lib/Utils/message-composer.js +721 -0
  105. package/lib/Utils/message-retry-manager.d.ts +88 -0
  106. package/lib/Utils/message-retry-manager.js +160 -0
  107. package/lib/Utils/message-search.d.ts +52 -0
  108. package/lib/Utils/message-search.js +226 -0
  109. package/lib/Utils/messages-media.js +899 -0
  110. package/lib/Utils/messages.js +2698 -0
  111. package/lib/Utils/noise-handler.js +175 -0
  112. package/lib/Utils/offline-node-processor.js +45 -0
  113. package/lib/Utils/pre-key-manager.js +131 -0
  114. package/lib/Utils/presence-choreographer.js +438 -0
  115. package/lib/Utils/process-message.js +423 -0
  116. package/lib/Utils/rate-limiter.js +232 -0
  117. package/lib/Utils/reconnect-throttle.js +157 -0
  118. package/lib/Utils/reply-ratio-guard.js +137 -0
  119. package/lib/Utils/reporting-utils.js +307 -0
  120. package/lib/Utils/retry-reason-tracker.js +140 -0
  121. package/lib/Utils/rich-message-utils.d.ts +48 -0
  122. package/lib/Utils/rich-message-utils.js +400 -0
  123. package/lib/Utils/rich-response-utils.js +461 -0
  124. package/lib/Utils/scheduling.d.ts +135 -0
  125. package/lib/Utils/scheduling.js +246 -0
  126. package/lib/Utils/session-fingerprint.js +226 -0
  127. package/lib/Utils/session-stability.js +224 -0
  128. package/lib/Utils/signal.js +188 -0
  129. package/lib/Utils/stanza-ack.js +38 -0
  130. package/lib/Utils/state-manager.js +91 -0
  131. package/lib/Utils/status-posting.d.ts +81 -0
  132. package/lib/Utils/status-posting.js +187 -0
  133. package/lib/Utils/stealth-connect.js +124 -0
  134. package/lib/Utils/sync-action-utils.js +55 -0
  135. package/lib/Utils/tc-token-utils.js +171 -0
  136. package/lib/Utils/templates.d.ts +54 -0
  137. package/lib/Utils/templates.js +244 -0
  138. package/lib/Utils/timelock-guard.js +162 -0
  139. package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
  140. package/lib/Utils/use-mongo-file-auth-state.js +81 -0
  141. package/lib/Utils/use-multi-file-auth-state.js +125 -0
  142. package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
  143. package/lib/Utils/use-single-file-auth-state.js +86 -0
  144. package/lib/Utils/use-sqlite-auth-state.js +187 -0
  145. package/lib/Utils/vCard.d.ts +71 -0
  146. package/lib/Utils/vCard.js +196 -0
  147. package/lib/Utils/validate-connection.js +253 -0
  148. package/lib/Utils/warmup.js +154 -0
  149. package/lib/WABinary/constants.js +1303 -0
  150. package/lib/WABinary/decode.js +270 -0
  151. package/lib/WABinary/encode.js +279 -0
  152. package/lib/WABinary/generic-utils.js +223 -0
  153. package/lib/WABinary/index.js +34 -0
  154. package/lib/WABinary/jid-utils.js +84 -0
  155. package/lib/WABinary/types.js +2 -0
  156. package/lib/WAM/BinaryInfo.js +13 -0
  157. package/lib/WAM/constants.js +15254 -0
  158. package/lib/WAM/encode.js +149 -0
  159. package/lib/WAM/index.js +32 -0
  160. package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
  161. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
  162. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
  163. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
  164. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
  165. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
  166. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  167. package/lib/WAUSync/Protocols/index.js +34 -0
  168. package/lib/WAUSync/USyncQuery.js +99 -0
  169. package/lib/WAUSync/USyncUser.js +26 -0
  170. package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
  171. package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
  172. package/lib/WAUSync/index.js +32 -0
  173. package/lib/index.js +59 -0
  174. package/package.json +105 -5
  175. package/README.md +0 -5
@@ -0,0 +1,110 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.DeliveryTracker = void 0
4
+
5
+ /**
6
+ * @file delivery-tracker.js
7
+ * @description Tracks actual WA message delivery rate vs sent.
8
+ * Low delivery rate (<60%) = strong soft-ban signal.
9
+ * Hook into messages.update event to track delivery receipts.
10
+ * Ported from baileys-antiban to CJS for bilis.
11
+ * @author Denzy ZeroDay (port), original by baileys-antiban contributors
12
+ */
13
+
14
+ const DEFAULT_CONFIG = {
15
+ windowMs: 3600000, // 1 hour
16
+ minSampleSize: 10,
17
+ onLowDeliveryRate: () => {},
18
+ lowRateThreshold: 0.6 // 60%
19
+ }
20
+
21
+ class DeliveryTracker {
22
+ /**
23
+ * @param {object} config - Optional config overrides
24
+ * @param {number} config.windowMs - Window for rate calculation in ms (default: 1h)
25
+ * @param {number} config.minSampleSize - Min messages before rate is meaningful (default: 10)
26
+ * @param {number} config.lowRateThreshold - Low delivery rate threshold (default: 0.6)
27
+ * @param {function} config.onLowDeliveryRate - Callback when delivery rate drops below threshold
28
+ */
29
+ constructor(config = {}) {
30
+ this.config = { ...DEFAULT_CONFIG, ...config }
31
+ this.messages = new Map()
32
+ this.lastLowRateAlert = 0
33
+ }
34
+
35
+ /**
36
+ * Register a sent message.
37
+ * Call this after sock.sendMessage() succeeds.
38
+ * @param {string} msgId - Message ID from msg.key.id
39
+ */
40
+ onMessageSent(msgId) {
41
+ this.messages.set(msgId, { sentAt: Date.now(), delivered: false })
42
+ this._prune()
43
+ }
44
+
45
+ /**
46
+ * Mark a message as delivered.
47
+ * Hook into sock.ev.on('messages.update') and check update.update.status === 3 or 4.
48
+ * @param {string} msgId - Message ID
49
+ */
50
+ onDeliveryReceipt(msgId) {
51
+ const record = this.messages.get(msgId)
52
+ if (record) record.delivered = true
53
+ this._prune()
54
+ this._checkRate()
55
+ }
56
+
57
+ /**
58
+ * Get current delivery statistics.
59
+ * @returns {{ sentInWindow, deliveredInWindow, deliveryRate, windowMs }}
60
+ */
61
+ getStats() {
62
+ this._prune()
63
+ const now = Date.now()
64
+ const cutoff = now - this.config.windowMs
65
+ let sentInWindow = 0
66
+ let deliveredInWindow = 0
67
+ for (const record of this.messages.values()) {
68
+ if (record.sentAt >= cutoff) {
69
+ sentInWindow++
70
+ if (record.delivered) deliveredInWindow++
71
+ }
72
+ }
73
+ return {
74
+ sentInWindow,
75
+ deliveredInWindow,
76
+ deliveryRate:
77
+ sentInWindow >= this.config.minSampleSize ? deliveredInWindow / sentInWindow : null,
78
+ windowMs: this.config.windowMs
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Reset all tracked messages.
84
+ */
85
+ reset() {
86
+ this.messages.clear()
87
+ this.lastLowRateAlert = 0
88
+ }
89
+
90
+ _prune() {
91
+ const cutoff = Date.now() - this.config.windowMs
92
+ for (const [msgId, record] of this.messages.entries()) {
93
+ if (record.sentAt < cutoff) this.messages.delete(msgId)
94
+ }
95
+ }
96
+
97
+ _checkRate() {
98
+ const stats = this.getStats()
99
+ if (stats.deliveryRate === null) return
100
+ const now = Date.now()
101
+ if (now - this.lastLowRateAlert < 3600000) return
102
+ if (stats.deliveryRate < this.config.lowRateThreshold) {
103
+ this.lastLowRateAlert = now
104
+ this.config.onLowDeliveryRate(stats.deliveryRate)
105
+ }
106
+ }
107
+ }
108
+
109
+ exports.DeliveryTracker = DeliveryTracker
110
+ module.exports = { DeliveryTracker }
@@ -0,0 +1,135 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.applyFingerprint = exports.generateFingerprint = void 0
4
+
5
+ /**
6
+ * @file device-fingerprint.js
7
+ * @description Device fingerprint randomization for WhatsApp connections.
8
+ * Randomizes appVersion, osVersion, and deviceModel to prevent Meta's
9
+ * clientPayload fingerprinting — addresses the #1 gap in anti-ban coverage.
10
+ * Ported from baileys-antiban to CJS for bilis.
11
+ * @author Denzy ZeroDay (port), Kobus Wentzel (original)
12
+ */
13
+
14
+ const DEFAULT_APP_VERSION_POOL = [
15
+ [2, 24, 5, 18],
16
+ [2, 24, 5, 17],
17
+ [2, 24, 4, 77],
18
+ [2, 24, 5, 15],
19
+ [2, 24, 3, 91],
20
+ [2, 24, 5, 20]
21
+ ]
22
+
23
+ const DEFAULT_OS_VERSION_POOL = ['10', '11', '12', '13', '14']
24
+
25
+ const DEFAULT_DEVICE_MODEL_POOL = [
26
+ 'Pixel 6',
27
+ 'Pixel 7',
28
+ 'Galaxy S22',
29
+ 'Galaxy S23',
30
+ 'Xiaomi 13',
31
+ 'Xiaomi 12',
32
+ 'OnePlus 11',
33
+ 'Moto G84',
34
+ 'Moto G54',
35
+ 'Realme 11',
36
+ 'Vivo V29',
37
+ 'Oppo Find X6'
38
+ ]
39
+
40
+ /** Simple deterministic PRNG using mulberry32, seeded from string hash */
41
+ class SeededRandom {
42
+ constructor(seed) {
43
+ let hash = 0
44
+ for (let i = 0; i < seed.length; i++) {
45
+ hash = (hash << 5) - hash + seed.charCodeAt(i)
46
+ hash = hash & hash
47
+ }
48
+ this.state = Math.abs(hash) || 1
49
+ }
50
+
51
+ next() {
52
+ let t = (this.state += 0x6d2b79f5)
53
+ t = Math.imul(t ^ (t >>> 15), t | 1)
54
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
55
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296
56
+ }
57
+
58
+ pick(array) {
59
+ return array[Math.floor(this.next() * array.length)]
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Generate a randomized device fingerprint for one session.
65
+ * Stable for the same sessionId — call once per socket init.
66
+ *
67
+ * @param {object} config - Optional config
68
+ * @param {boolean} config.enabled - Master switch (default: true)
69
+ * @param {boolean} config.randomizeAppVersion - Vary app version (default: true)
70
+ * @param {boolean} config.randomizeOsVersion - Vary OS version (default: true)
71
+ * @param {boolean} config.randomizeDeviceModel - Pick random device (default: true)
72
+ * @param {string} config.seed - Optional seed for deterministic results
73
+ * @param {Array} config.appVersionPool - Custom app version pool
74
+ * @param {Array} config.osVersionPool - Custom OS version pool
75
+ * @param {Array} config.deviceModelPool - Custom device model pool
76
+ * @param {string} sessionId - Optional session ID for stable results
77
+ * @returns {{ appVersion, osVersion, deviceModel, sessionId }}
78
+ */
79
+ const generateFingerprint = (config = {}, sessionId) => {
80
+ const {
81
+ enabled = true,
82
+ randomizeAppVersion = true,
83
+ randomizeOsVersion = true,
84
+ randomizeDeviceModel = true,
85
+ seed,
86
+ appVersionPool = DEFAULT_APP_VERSION_POOL,
87
+ osVersionPool = DEFAULT_OS_VERSION_POOL,
88
+ deviceModelPool = DEFAULT_DEVICE_MODEL_POOL
89
+ } = config
90
+
91
+ const finalSessionId = sessionId || `session-${Date.now()}-${Math.random()}`
92
+ const rng = new SeededRandom(seed || finalSessionId)
93
+
94
+ const appVersion = enabled && randomizeAppVersion ? rng.pick(appVersionPool) : appVersionPool[0]
95
+
96
+ const osVersion = enabled && randomizeOsVersion ? rng.pick(osVersionPool) : osVersionPool[0]
97
+
98
+ const deviceModel =
99
+ enabled && randomizeDeviceModel ? rng.pick(deviceModelPool) : deviceModelPool[0]
100
+
101
+ return {
102
+ appVersion: [...appVersion],
103
+ osVersion,
104
+ deviceModel,
105
+ sessionId: finalSessionId
106
+ }
107
+ }
108
+ exports.generateFingerprint = generateFingerprint
109
+
110
+ /**
111
+ * Apply fingerprint to a Baileys SocketConfig before makeWASocket().
112
+ *
113
+ * @example
114
+ * const fp = generateFingerprint({})
115
+ * const sock = makeWASocket(applyFingerprint(config, fp))
116
+ *
117
+ * @param {object} socketConfig - Baileys socket config
118
+ * @param {{ appVersion, osVersion, deviceModel }} fp - Fingerprint from generateFingerprint()
119
+ * @returns {object} Modified socket config
120
+ */
121
+ const applyFingerprint = (socketConfig, fp) => {
122
+ const config = { ...socketConfig }
123
+ config.version = fp.appVersion
124
+ config.browser = [fp.deviceModel, fp.osVersion, `WhatsApp/${fp.appVersion.join('.')}`]
125
+ return config
126
+ }
127
+ exports.applyFingerprint = applyFingerprint
128
+
129
+ module.exports = {
130
+ generateFingerprint,
131
+ applyFingerprint,
132
+ DEFAULT_APP_VERSION_POOL,
133
+ DEFAULT_OS_VERSION_POOL,
134
+ DEFAULT_DEVICE_MODEL_POOL
135
+ }