@hansaka02/baileys 7.3.2 → 7.3.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.
Files changed (210) hide show
  1. package/lib/Defaults/baileys-version.json +2 -2
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +74 -0
  4. package/lib/Defaults/history.js +19 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +5 -18
  13. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -16
  16. package/lib/Signal/Group/sender-key-state.js +15 -61
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +237 -177
  19. package/lib/Signal/lid-mapping.js +128 -71
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +25 -16
  22. package/lib/Socket/business.js +46 -33
  23. package/lib/Socket/chats.js +286 -170
  24. package/lib/Socket/community.js +215 -77
  25. package/lib/Socket/groups.js +77 -61
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +629 -457
  28. package/lib/Socket/messages-send.js +645 -656
  29. package/lib/Socket/mex.js +61 -0
  30. package/lib/Socket/newsletter.js +166 -245
  31. package/lib/Socket/socket.js +396 -170
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/Newsletter.js +32 -25
  39. package/lib/Types/State.js +4 -4
  40. package/lib/Types/index.js +28 -12
  41. package/lib/Utils/auth-utils.js +212 -375
  42. package/lib/Utils/baileys-event-stream.js +68 -69
  43. package/lib/Utils/browser-utils.js +43 -0
  44. package/lib/Utils/business.js +63 -53
  45. package/lib/Utils/chat-utils.js +241 -106
  46. package/lib/Utils/crypto.js +25 -45
  47. package/lib/Utils/decode-wa-message.js +361 -311
  48. package/lib/Utils/event-buffer.js +97 -42
  49. package/lib/Utils/generics.js +90 -207
  50. package/lib/Utils/history.js +29 -27
  51. package/lib/Utils/index.js +28 -14
  52. package/lib/Utils/link-preview.js +24 -62
  53. package/lib/Utils/logger.js +5 -5
  54. package/lib/Utils/lt-hash.js +29 -23
  55. package/lib/Utils/make-mutex.js +26 -28
  56. package/lib/Utils/message-retry-manager.js +55 -7
  57. package/lib/Utils/messages-media.js +434 -247
  58. package/lib/Utils/messages.js +963 -917
  59. package/lib/Utils/noise-handler.js +60 -20
  60. package/lib/Utils/pre-key-manager.js +126 -0
  61. package/lib/Utils/process-message.js +216 -141
  62. package/lib/Utils/signal.js +75 -37
  63. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  64. package/lib/Utils/validate-connection.js +96 -66
  65. package/lib/WABinary/constants.js +1268 -1268
  66. package/lib/WABinary/decode.js +62 -34
  67. package/lib/WABinary/encode.js +57 -36
  68. package/lib/WABinary/generic-utils.js +4 -4
  69. package/lib/WABinary/index.js +27 -11
  70. package/lib/WABinary/jid-utils.js +58 -11
  71. package/lib/WAM/constants.js +19064 -11563
  72. package/lib/WAM/encode.js +71 -14
  73. package/lib/WAM/index.js +27 -11
  74. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  75. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  76. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  77. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  78. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  79. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  80. package/lib/WAUSync/Protocols/index.js +27 -11
  81. package/lib/WAUSync/USyncQuery.js +51 -28
  82. package/lib/WAUSync/index.js +27 -11
  83. package/lib/index.js +60 -31
  84. package/package.json +12 -17
  85. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  86. package/WAProto/Adv/Adv.d.ts +0 -643
  87. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  88. package/WAProto/Cert/Cert.d.ts +0 -613
  89. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  90. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  91. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  92. package/WAProto/E2E/E2E.d.ts +0 -41724
  93. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  94. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  95. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  96. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  97. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  98. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  99. package/WAProto/Protocol/Protocol.d.ts +0 -270
  100. package/WAProto/Reporting/Reporting.d.ts +0 -371
  101. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  102. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  103. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  104. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  105. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  106. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  107. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  108. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  109. package/WAProto/Web/Web.d.ts +0 -46383
  110. package/WAProto/index.d.ts +0 -55
  111. package/lib/Defaults/index.d.ts +0 -77
  112. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  113. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  114. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  115. package/lib/Signal/Group/index.d.ts +0 -11
  116. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  117. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  118. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  119. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  120. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  121. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  122. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  123. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  124. package/lib/Signal/libsignal.d.ts +0 -8
  125. package/lib/Signal/lid-mapping.d.ts +0 -28
  126. package/lib/Socket/Client/index.d.ts +0 -2
  127. package/lib/Socket/Client/types.d.ts +0 -16
  128. package/lib/Socket/Client/websocket.d.ts +0 -13
  129. package/lib/Socket/business.d.ts +0 -187
  130. package/lib/Socket/chats.d.ts +0 -97
  131. package/lib/Socket/community.d.ts +0 -129
  132. package/lib/Socket/groups.d.ts +0 -129
  133. package/lib/Socket/index.d.ts +0 -191
  134. package/lib/Socket/messages-recv.d.ts +0 -174
  135. package/lib/Socket/messages-send.d.ts +0 -165
  136. package/lib/Socket/newsletter.d.ts +0 -145
  137. package/lib/Socket/socket.d.ts +0 -45
  138. package/lib/Socket/usync.d.ts +0 -37
  139. package/lib/Socket/usync.js +0 -83
  140. package/lib/Store/index.d.ts +0 -4
  141. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  142. package/lib/Store/make-in-memory-store.d.ts +0 -123
  143. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  144. package/lib/Store/object-repository.d.ts +0 -10
  145. package/lib/Types/Auth.d.ts +0 -121
  146. package/lib/Types/Bussiness.d.ts +0 -28
  147. package/lib/Types/Call.d.ts +0 -14
  148. package/lib/Types/Chat.d.ts +0 -143
  149. package/lib/Types/Contact.d.ts +0 -23
  150. package/lib/Types/Events.d.ts +0 -226
  151. package/lib/Types/GroupMetadata.d.ts +0 -66
  152. package/lib/Types/Label.d.ts +0 -48
  153. package/lib/Types/LabelAssociation.d.ts +0 -35
  154. package/lib/Types/Message.d.ts +0 -484
  155. package/lib/Types/MexUpdates.d.ts +0 -9
  156. package/lib/Types/Newsletter.d.ts +0 -109
  157. package/lib/Types/Product.d.ts +0 -92
  158. package/lib/Types/Signal.d.ts +0 -98
  159. package/lib/Types/Socket.d.ts +0 -141
  160. package/lib/Types/State.d.ts +0 -41
  161. package/lib/Types/USync.d.ts +0 -26
  162. package/lib/Types/index.d.ts +0 -80
  163. package/lib/Utils/auth-utils.d.ts +0 -21
  164. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  165. package/lib/Utils/business.d.ts +0 -29
  166. package/lib/Utils/chat-utils.d.ts +0 -82
  167. package/lib/Utils/crypto.d.ts +0 -56
  168. package/lib/Utils/decode-wa-message.d.ts +0 -53
  169. package/lib/Utils/event-buffer.d.ts +0 -39
  170. package/lib/Utils/generics.d.ts +0 -117
  171. package/lib/Utils/history.d.ts +0 -23
  172. package/lib/Utils/index.d.ts +0 -20
  173. package/lib/Utils/link-preview.d.ts +0 -23
  174. package/lib/Utils/logger.d.ts +0 -13
  175. package/lib/Utils/lt-hash.d.ts +0 -14
  176. package/lib/Utils/make-mutex.d.ts +0 -9
  177. package/lib/Utils/message-retry-manager.d.ts +0 -88
  178. package/lib/Utils/messages-media.d.ts +0 -135
  179. package/lib/Utils/messages.d.ts +0 -105
  180. package/lib/Utils/noise-handler.d.ts +0 -20
  181. package/lib/Utils/process-message.d.ts +0 -49
  182. package/lib/Utils/signal.d.ts +0 -42
  183. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  184. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  185. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  186. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  187. package/lib/Utils/use-single-file-auth-state.js +0 -80
  188. package/lib/Utils/validate-connection.d.ts +0 -13
  189. package/lib/WABinary/constants.d.ts +0 -30
  190. package/lib/WABinary/decode.d.ts +0 -9
  191. package/lib/WABinary/encode.d.ts +0 -3
  192. package/lib/WABinary/generic-utils.d.ts +0 -28
  193. package/lib/WABinary/index.d.ts +0 -5
  194. package/lib/WABinary/jid-utils.d.ts +0 -58
  195. package/lib/WABinary/types.d.ts +0 -22
  196. package/lib/WAM/BinaryInfo.d.ts +0 -16
  197. package/lib/WAM/constants.d.ts +0 -47
  198. package/lib/WAM/encode.d.ts +0 -3
  199. package/lib/WAM/index.d.ts +0 -3
  200. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  204. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  205. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  206. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  207. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  208. package/lib/WAUSync/USyncUser.d.ts +0 -12
  209. package/lib/WAUSync/index.d.ts +0 -3
  210. package/lib/index.d.ts +0 -13
@@ -1,197 +1,70 @@
1
1
  "use strict"
2
2
 
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
8
- }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
-
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v })
17
- }) : function(o, v) {
18
- o["default"] = v
19
- })
20
-
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod
23
- var result = {}
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
25
- __setModuleDefault(result, mod)
26
- return result
27
- }
28
-
29
- var __importDefault = (this && this.__importDefault) || function (mod) {
30
- return (mod && mod.__esModule) ? mod : { "default": mod }
31
- }
32
-
33
3
  Object.defineProperty(exports, "__esModule", { value: true })
34
4
 
35
- const boom_1 = require("@hapi/boom")
36
- const axios_1 = __importDefault(require("axios"))
37
- const crypto_1 = require("crypto")
38
- const crypto_2 = require("./crypto")
39
- const os_1 = require("os")
40
- const WAProto_1 = require("../../WAProto")
41
- const baileys_version_json_1 = require("../Defaults/baileys-version.json")
42
- const Types_1 = require("../Types")
43
- const WABinary_1 = require("../WABinary")
44
-
45
- const COMPANION_PLATFORM_MAP = {
46
- 'Chrome': '49',
47
- 'Edge': '50',
48
- 'Firefox': '51',
49
- 'Opera': '53',
50
- 'Safari': '54',
51
- 'Brave': '1.79.112',
52
- 'Vivaldi': '6.2.3105.58',
53
- 'Tor': '12.5.3',
54
- 'Yandex': '23.7.1',
55
- 'Falkon': '22.08.3',
56
- 'Epiphany': '44.2'
57
- }
58
-
59
- const PLATFORM_MAP = {
60
- 'aix': 'AIX',
61
- 'darwin': 'Mac OS',
62
- 'win32': 'Windows',
63
- 'android': 'Android',
64
- 'freebsd': 'FreeBSD',
65
- 'openbsd': 'OpenBSD',
66
- 'sunos': 'Solaris',
67
- 'linux': 'Linux',
68
- 'ubuntu': 'Ubuntu',
69
- 'ios': 'iOS',
70
- 'baileys': 'Baileys',
71
- 'chromeos': 'Chrome OS',
72
- 'tizen': 'Tizen',
73
- 'watchos': 'watchOS',
74
- 'wearos': 'Wear OS',
75
- 'harmonyos': 'HarmonyOS',
76
- 'kaios': 'KaiOS',
77
- 'smarttv': 'Smart TV',
78
- 'raspberrypi': 'Raspberry Pi OS',
79
- 'symbian': 'Symbian',
80
- 'blackberry': 'Blackberry OS',
81
- 'windowsphone': 'Windows Phone'
82
- }
83
-
84
- const PLATFORM_VERSIONS = {
85
- 'ubuntu': '22.04.4',
86
- 'darwin': '18.5',
87
- 'win32': '10.0.22631',
88
- 'android': '14.0.0',
89
- 'freebsd': '13.2',
90
- 'openbsd': '7.3',
91
- 'sunos': '11',
92
- 'linux': '6.5',
93
- 'ios': '18.2',
94
- 'baileys': '6.5.0',
95
- 'chromeos': '117.0.5938.132',
96
- 'tizen': '6.5',
97
- 'watchos': '10.1',
98
- 'wearos': '4.1',
99
- 'harmonyos': '4.0.0',
100
- 'kaios': '3.1',
101
- 'smarttv': '23.3.1',
102
- 'raspberrypi': '11 (Bullseye)',
103
- 'symbian': '3',
104
- 'blackberry': '10.3.3',
105
- 'windowsphone': '8.1'
106
- }
107
-
108
- const Browsers = {
109
- ubuntu: (browser) => {
110
- return [PLATFORM_MAP['ubuntu'], browser, PLATFORM_VERSIONS['ubuntu']]
111
- },
112
- macOS: (browser) => {
113
- return [PLATFORM_MAP['darwin'], browser, PLATFORM_VERSIONS['darwin']]
114
- },
115
- windows: (browser) => {
116
- return [PLATFORM_MAP['win32'], browser, PLATFORM_VERSIONS['win32']]
117
- },
118
- linux: (browser) => {
119
- return [PLATFORM_MAP['linux'], browser, PLATFORM_VERSIONS['linux']]
120
- },
121
- solaris: (browser) => {
122
- return [PLATFORM_MAP['sunos'], browser, PLATFORM_VERSIONS['sunos']]
123
- },
124
- baileys: (browser) => {
125
- return [PLATFORM_MAP['baileys'], browser, PLATFORM_VERSIONS['baileys']]
126
- },
127
- android: (browser) => {
128
- return [PLATFORM_MAP['android'], browser, PLATFORM_VERSIONS['android']]
129
- },
130
- iOS: (browser) => {
131
- return [PLATFORM_MAP['ios'], browser, PLATFORM_VERSIONS['ios']]
132
- },
133
- kaiOS: (browser) => {
134
- return [PLATFORM_MAP['kaios'], browser, PLATFORM_VERSIONS['kaios']]
135
- },
136
- chromeOS: (browser) => {
137
- return [PLATFORM_MAP['chromeos'], browser, PLATFORM_VERSIONS['chromeos']]
138
- },
139
- appropriate: (browser) => {
140
- const platform = os_1.platform()
141
- const platformName = PLATFORM_MAP[platform] || 'Unknown OS'
142
- return [platformName, browser, PLATFORM_VERSIONS[platform] || 'latest']
143
- },
144
- custom: (platform, browser, version) => {
145
- const platformName = PLATFORM_MAP[platform.toLowerCase()] || platform
146
- return [platformName, browser, version || PLATFORM_VERSIONS[platform] || 'latest']
147
- }
148
- }
5
+ const { Boom } = require("@hapi/boom")
6
+ const {
7
+ createHash,
8
+ randomBytes
9
+ } = require("crypto")
10
+ const {
11
+ jidDecode,
12
+ getAllBinaryNodeChildren
13
+ } = require("../WABinary")
14
+ const { sha256 } = require("./crypto")
15
+ const { proto } = require("../../WAProto")
16
+ const { version } = require("../Defaults/baileys-version.json")
17
+ const { DisconnectReason } = require("../Types")
149
18
 
150
19
  const Itsuki = async () => {
151
20
  try {
152
- const { data } = await axios_1.default.get('https://raw.githubusercontent.com/Itsukichann/database/refs/heads/main/itsuki.json', {
153
- responseType: 'json'
154
- })
21
+ const response = await fetch('https://raw.githubusercontent.com/Itsukichann/database/refs/heads/main/itsuki.json', {
22
+ method: 'GET'
23
+ })
24
+ const data = await response.json()
155
25
  if (Array.isArray(data)) {
156
26
  const itsukichann = data[Math.floor(Math.random() * data.length)]
157
27
  return itsukichann
158
28
  } else {
159
- throw new boom_1.Boom('Data is not in array format.')
29
+ throw new Boom('Data is not in array format.')
160
30
  }
161
31
  } catch (error) {
162
- throw new boom_1.Boom(error.message)
32
+ throw new Boom(error.message)
163
33
  }
164
34
  }
165
35
 
166
36
  const BufferJSON = {
167
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
37
  replacer: (k, value) => {
169
38
  if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
170
39
  return { type: 'Buffer', data: Buffer.from(value?.data || value).toString('base64') }
171
40
  }
172
41
  return value
173
42
  },
174
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
175
43
  reviver: (_, value) => {
176
- if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
177
- const val = value.data || value.value
178
- return typeof val === 'string' ? Buffer.from(val, 'base64') : Buffer.from(val || [])
44
+ if (typeof value === 'object' && value !== null && value.type === 'Buffer' && typeof value.data === 'string') {
45
+ return Buffer.from(value.data, 'base64')
46
+ }
47
+
48
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
49
+ const keys = Object.keys(value)
50
+
51
+ if (keys.length > 0 && keys.every(k => !isNaN(parseInt(k, 10)))) {
52
+ const values = Object.values(value)
53
+
54
+ if (values.every(v => typeof v === 'number')) {
55
+ return Buffer.from(values)
56
+ }
57
+ }
179
58
  }
59
+
180
60
  return value
181
61
  }
182
62
  }
183
63
 
184
- const getPlatformId = (browser) => {
185
- const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()]
186
- return platformType ? platformType.toString() : '1'
187
- }
188
-
189
- const getKeyAuthor = (key, meId = 'me') => {
190
- return key?.fromMe ? meId : key?.participant || key?.remoteJid || ''
191
- }
64
+ const getKeyAuthor = (key, meId = 'me') => (key?.fromMe ? meId : key?.participantAlt || key?.remoteJidAlt || key?.participant || key?.remoteJid) || ''
192
65
 
193
66
  const writeRandomPadMax16 = (msg) => {
194
- const pad = crypto_1.randomBytes(1)
67
+ const pad = randomBytes(1)
195
68
  const padLength = (pad[0] & 0x0f) + 1
196
69
 
197
70
  return Buffer.concat([msg, Buffer.alloc(padLength, padLength)])
@@ -210,15 +83,15 @@ const unpadRandomMax16 = (e) => {
210
83
  }
211
84
 
212
85
  const encodeWAMessage = (message) => {
213
- return writeRandomPadMax16(WAProto_1.proto.Message.encode(message).finish())
86
+ return writeRandomPadMax16(proto.Message.encode(message).finish())
214
87
  }
215
88
 
216
89
  const encodeNewsletterMessage = (message) => {
217
- return WAProto_1.proto.Message.encode(message).finish()
90
+ return proto.Message.encode(message).finish()
218
91
  }
219
92
 
220
93
  const generateRegistrationId = () => {
221
- return Uint16Array.from(crypto_1.randomBytes(2))[0] & 16383
94
+ return Uint16Array.from(randomBytes(2))[0] & 16383
222
95
  }
223
96
 
224
97
  const encodeBigEndian = (e, t = 4) => {
@@ -254,9 +127,7 @@ const debouncedTimeout = (intervalMs = 1000, task) => {
254
127
  }
255
128
  }
256
129
 
257
- const delay = (ms) => {
258
- return delayCancellable(ms).delay
259
- }
130
+ const delay = (ms) => delayCancellable(ms).delay
260
131
 
261
132
  const delayCancellable = (ms) => {
262
133
  const stack = new Error().stack
@@ -268,7 +139,7 @@ const delayCancellable = (ms) => {
268
139
  })
269
140
  const cancel = () => {
270
141
  clearTimeout(timeout)
271
- reject(new boom_1.Boom('Cancelled', {
142
+ reject(new Boom('Cancelled', {
272
143
  statusCode: 500,
273
144
  data: {
274
145
  stack
@@ -286,8 +157,8 @@ async function promiseTimeout(ms, promise) {
286
157
  // Create a promise that rejects in <ms> milliseconds
287
158
  const { delay, cancel } = delayCancellable(ms)
288
159
  const p = new Promise((resolve, reject) => {
289
- delay.then(() => reject(new boom_1.Boom('Timed Out', {
290
- statusCode: Types_1.DisconnectReason.timedOut,
160
+ delay.then(() => reject(new Boom('Timed Out', {
161
+ statusCode: DisconnectReason.timedOut,
291
162
  data: {
292
163
  stack
293
164
  }
@@ -298,22 +169,28 @@ async function promiseTimeout(ms, promise) {
298
169
  }
299
170
 
300
171
  const generateMessageID = (userId) => {
301
- const timestamp = Date.now().toString();
302
- const user = userId || 'unknown';
303
- const random = crypto_1.randomBytes(16).toString('hex');
304
-
305
- const hash = crypto_1.createHash('sha256')
306
- .update(timestamp + user + random)
307
- .digest('hex')
308
- .toUpperCase();
309
-
310
- return 'A' + hash.substring(0, 31);
172
+ const data = Buffer.alloc(8 + 20 + 16)
173
+ data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
174
+ if (userId) {
175
+ const id = jidDecode(userId)
176
+ if (id?.user) {
177
+ data.write(id.user, 8)
178
+ data.write('@c.us', 8 + id.user.length)
179
+ }
180
+ }
181
+ const random = randomBytes(20)
182
+ random.copy(data, 28)
183
+ const sha = asciiDecode([ 83, 85, 75, 73 ])
184
+ const hash = createHash('sha256').update(data).digest()
185
+ return sha + hash.toString('hex').toUpperCase().substring(0, 16)
311
186
  }
187
+
188
+ // code is inspired by whatsmeow
312
189
  const generateParticipantHashV2 = (participants) => {
313
190
  participants.sort()
314
- const sha256Hash = crypto_2.sha256(Buffer.from(participants.join(''))).toString('base64')
191
+ const sha256Hash = sha256(Buffer.from(participants.join(''))).toString('base64')
315
192
  return '2:' + sha256Hash.slice(0, 6)
316
- };
193
+ }
317
194
 
318
195
  function bindWaitForEvent(ev, event) {
319
196
  return async (check, timeoutMs) => {
@@ -323,7 +200,7 @@ function bindWaitForEvent(ev, event) {
323
200
  closeListener = ({ connection, lastDisconnect }) => {
324
201
  if (connection === 'close') {
325
202
  reject((lastDisconnect?.error)
326
- || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }))
203
+ || new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed }))
327
204
  }
328
205
  }
329
206
  ev.on('connection.update', closeListener)
@@ -363,18 +240,19 @@ const printQRIfNecessaryListener = (ev, logger) => {
363
240
  const fetchLatestBaileysVersion = async (options = {}) => {
364
241
  const URL = 'https://raw.githubusercontent.com/Itsukichann/Baileys/refs/heads/master/lib/Defaults/baileys-version.json'
365
242
  try {
366
- const result = await axios_1.default.get(URL, {
243
+ const result = await fetch(URL, {
367
244
  ...options,
368
- responseType: 'json'
245
+ method: 'GET'
369
246
  })
247
+ const json = await result.json()
370
248
  return {
371
- version: result.data.version,
249
+ version: json.version,
372
250
  isLatest: true
373
251
  }
374
252
  }
375
253
  catch (error) {
376
254
  return {
377
- version: baileys_version_json_1.version,
255
+ version: version,
378
256
  isLatest: false,
379
257
  error
380
258
  }
@@ -401,7 +279,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
401
279
  })
402
280
 
403
281
  if (!response.ok) {
404
- throw new boom_1.Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status })
282
+ throw new Boom(`Failed to fetch sw.js: ${response.statusText}`, { statusCode: response.status })
405
283
  }
406
284
 
407
285
  const data = await response.text()
@@ -410,7 +288,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
410
288
 
411
289
  if (!match?.[1]) {
412
290
  return {
413
- version: baileys_version_json_1,
291
+ version: version,
414
292
  isLatest: false,
415
293
  error: {
416
294
  message: 'Could not find client revision in the fetched content'
@@ -426,7 +304,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
426
304
  }
427
305
  catch (error) {
428
306
  return {
429
- version: baileys_version_json_1,
307
+ version: version,
430
308
  isLatest: false,
431
309
  error
432
310
  }
@@ -435,15 +313,15 @@ const fetchLatestWaWebVersion = async (options = {}) => {
435
313
 
436
314
  /** unique message tag prefix for MD clients */
437
315
  const generateMdTagPrefix = () => {
438
- const bytes = crypto_1.randomBytes(4)
316
+ const bytes = randomBytes(4)
439
317
  return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`
440
318
  }
441
319
 
442
320
  const STATUS_MAP = {
443
- 'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
444
- 'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
445
- 'read': WAProto_1.proto.WebMessageInfo.Status.READ,
446
- 'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
321
+ 'sender': proto.WebMessageInfo.Status.SERVER_ACK,
322
+ 'played': proto.WebMessageInfo.Status.PLAYED,
323
+ 'read': proto.WebMessageInfo.Status.READ,
324
+ 'read-self': proto.WebMessageInfo.Status.READ
447
325
  }
448
326
 
449
327
  /**
@@ -453,13 +331,13 @@ const STATUS_MAP = {
453
331
  const getStatusFromReceiptType = (type) => {
454
332
  const status = STATUS_MAP[type]
455
333
  if (typeof type === 'undefined') {
456
- return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK
334
+ return proto.WebMessageInfo.Status.DELIVERY_ACK
457
335
  }
458
336
  return status
459
337
  }
460
338
 
461
339
  const CODE_MAP = {
462
- conflict: Types_1.DisconnectReason.connectionReplaced
340
+ conflict: DisconnectReason.connectionReplaced
463
341
  }
464
342
 
465
343
  /**
@@ -467,10 +345,10 @@ const CODE_MAP = {
467
345
  * @param reason the string reason given, eg. "conflict"
468
346
  */
469
347
  const getErrorCodeFromStreamError = (node) => {
470
- const [reasonNode] = WABinary_1.getAllBinaryNodeChildren(node)
348
+ const [reasonNode] = getAllBinaryNodeChildren(node)
471
349
  let reason = reasonNode?.tag || 'unknown'
472
- const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession)
473
- if (statusCode === Types_1.DisconnectReason.restartRequired) {
350
+ const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession)
351
+ if (statusCode === DisconnectReason.restartRequired) {
474
352
  reason = 'restart required'
475
353
  }
476
354
  return {
@@ -508,15 +386,22 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
508
386
  return status
509
387
  }
510
388
 
389
+ const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: '
390
+
511
391
  const getCodeFromWSError = (error) => {
512
392
  let statusCode = 500
513
- if (error?.message?.includes('Unexpected server response: ')) {
514
- const code = +(error?.message.slice('Unexpected server response: '.length))
393
+
394
+ if (error?.message?.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
395
+ const code = +error?.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length)
396
+
515
397
  if (!Number.isNaN(code) && code >= 400) {
516
398
  statusCode = code
517
399
  }
518
400
  }
519
- else if (error?.code?.startsWith('E') || error?.message?.includes('time out')) {
401
+ else if (
402
+ error?.code?.startsWith('E') ||
403
+ error?.message?.includes('timed out')) {
404
+ // handle ETIMEOUT, ENOTFOUND etc
520
405
  statusCode = 408
521
406
  }
522
407
  return statusCode
@@ -577,10 +462,8 @@ const asciiDecode = (...codes) => {
577
462
  }
578
463
 
579
464
  module.exports = {
580
- Browsers,
581
465
  Itsuki,
582
466
  BufferJSON,
583
- getPlatformId,
584
467
  getKeyAuthor,
585
468
  writeRandomPadMax16,
586
469
  unpadRandomMax16,
@@ -2,18 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const util_1 = require("util")
6
- const zlib_1 = require("zlib")
7
- const WAProto_1 = require("../../WAProto")
8
- const Types_1 = require("../Types")
9
- const WABinary_1 = require("../WABinary")
10
- const generics_1 = require("./generics")
11
- const messages_1 = require("./messages")
12
- const messages_media_1 = require("./messages-media")
13
- const inflatePromise = util_1.promisify(zlib_1.inflate)
5
+ const { promisify } = require("util")
6
+ const { inflate } = require("zlib")
7
+ const { proto } = require("../../WAProto")
8
+ const { WAMessageStubType } = require("../Types")
9
+ const { toNumber } = require("./generics")
10
+ const { normalizeMessageContent } = require("./messages")
11
+ const { downloadContentFromMessage } = require("./messages-media")
12
+ const inflatePromise = promisify(inflate)
14
13
 
15
14
  const downloadHistory = async (msg, options) => {
16
- const stream = await messages_media_1.downloadContentFromMessage(msg, 'md-msg-hist', { options })
15
+ const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options })
17
16
  const bufferArray = []
18
17
  for await (const chunk of stream) {
19
18
  bufferArray.push(chunk)
@@ -21,7 +20,7 @@ const downloadHistory = async (msg, options) => {
21
20
  let buffer = Buffer.concat(bufferArray)
22
21
  // decompress buffer
23
22
  buffer = await inflatePromise(buffer)
24
- const syncData = WAProto_1.proto.HistorySync.decode(buffer)
23
+ const syncData = proto.HistorySync.decode(buffer)
25
24
  return syncData
26
25
  }
27
26
 
@@ -30,10 +29,10 @@ const processHistoryMessage = (item) => {
30
29
  const contacts = []
31
30
  const chats = []
32
31
  switch (item.syncType) {
33
- case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
34
- case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
35
- case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
36
- case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
32
+ case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
33
+ case proto.HistorySync.HistorySyncType.RECENT:
34
+ case proto.HistorySync.HistorySyncType.FULL:
35
+ case proto.HistorySync.HistorySyncType.ON_DEMAND:
37
36
  for (const chat of item.conversations) {
38
37
  contacts.push({
39
38
  id: chat.id,
@@ -51,10 +50,10 @@ const processHistoryMessage = (item) => {
51
50
  chat.messages = [{ message }]
52
51
  }
53
52
  if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
54
- chat.lastMessageRecvTimestamp = generics_1.toNumber(message.messageTimestamp)
53
+ chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp)
55
54
  }
56
- if (message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
57
- || message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
55
+ if (message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP
56
+ || message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB
58
57
  && message.messageStubParameters?.[0]) {
59
58
  contacts.push({
60
59
  id: message.key.participant || message.key.remoteJid,
@@ -65,14 +64,9 @@ const processHistoryMessage = (item) => {
65
64
  chats.push({ ...chat })
66
65
  }
67
66
  break
68
- case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
67
+ case proto.HistorySync.HistorySyncType.PUSH_NAME:
69
68
  for (const c of item.pushnames) {
70
- contacts.push({
71
- id: c.id,
72
- name: c.name || undefined,
73
- lid: c.lidJid || undefined,
74
- jid: WABinary_1.isJidUser(c.id) ? c.id : undefined
75
- })
69
+ contacts.push({ id: c.id, notify: c.pushname })
76
70
  }
77
71
  break
78
72
  }
@@ -86,12 +80,20 @@ const processHistoryMessage = (item) => {
86
80
  }
87
81
 
88
82
  const downloadAndProcessHistorySyncNotification = async (msg, options) => {
89
- const historyMsg = await downloadHistory(msg, options)
83
+ let historyMsg
84
+
85
+ if (msg.initialHistBootstrapInlinePayload) {
86
+ historyMsg = proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload))
87
+ }
88
+ else {
89
+ historyMsg = await downloadHistory(msg, options)
90
+ }
91
+
90
92
  return processHistoryMessage(historyMsg)
91
93
  }
92
94
 
93
95
  const getHistoryMsg = (message) => {
94
- const normalizedContent = !!message ? messages_1.normalizeMessageContent(message) : undefined
96
+ const normalizedContent = !!message ? normalizeMessageContent(message) : undefined
95
97
  const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification
96
98
  return anyHistoryMsg
97
99
  }
@@ -1,22 +1,38 @@
1
1
  "use strict"
2
2
 
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
+
6
+ let desc = Object.getOwnPropertyDescriptor(m, k)
7
+
6
8
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
9
+ desc = {
10
+ enumerable: true,
11
+ get: function() {
12
+ return m[k]
13
+ }
14
+ }
8
15
  }
9
- Object.defineProperty(o, k2, desc)
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- }))
14
16
 
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ Object.defineProperty(o, k2, desc)
18
+
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k
21
+ o[k2] = m[k]
22
+ }
23
+ ))
24
+
25
+ const __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) {
27
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
28
+ __createBinding(exports, m, p)
29
+ }
30
+ }
17
31
  }
18
32
 
19
- Object.defineProperty(exports, "__esModule", { value: true })
33
+ Object.defineProperty(exports, "__esModule", {
34
+ value: true
35
+ })
20
36
 
21
37
  __exportStar(require("./generics"), exports)
22
38
  __exportStar(require("./decode-wa-message"), exports)
@@ -31,9 +47,7 @@ __exportStar(require("./history"), exports)
31
47
  __exportStar(require("./chat-utils"), exports)
32
48
  __exportStar(require("./lt-hash"), exports)
33
49
  __exportStar(require("./auth-utils"), exports)
34
- __exportStar(require("./baileys-event-stream"), exports)
35
- __exportStar(require("./use-mongo-file-auth-state"), exports)
36
- __exportStar(require("./use-single-file-auth-state"), exports)
50
+ __exportStar(require("./browser-utils"), exports)
37
51
  __exportStar(require("./use-multi-file-auth-state"), exports)
38
52
  __exportStar(require("./link-preview"), exports)
39
53
  __exportStar(require("./event-buffer"), exports)