@hansaka02/baileys 7.3.2 → 7.3.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.
Files changed (202) hide show
  1. package/README.md +247 -203
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +62 -0
  4. package/lib/Defaults/history.js +17 -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 +4 -4
  13. package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -7
  16. package/lib/Signal/Group/sender-key-state.js +4 -4
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +45 -69
  19. package/lib/Signal/lid-mapping.js +15 -11
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +16 -14
  22. package/lib/Socket/business.js +41 -32
  23. package/lib/Socket/chats.js +123 -98
  24. package/lib/Socket/community.js +50 -40
  25. package/lib/Socket/groups.js +59 -47
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +219 -172
  28. package/lib/Socket/messages-send.js +187 -143
  29. package/lib/Socket/newsletter.js +61 -47
  30. package/lib/Socket/socket.js +133 -90
  31. package/lib/Socket/usync.js +6 -6
  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/State.js +4 -4
  39. package/lib/Types/index.js +28 -12
  40. package/lib/Utils/auth-utils.js +28 -26
  41. package/lib/Utils/baileys-event-stream.js +68 -69
  42. package/lib/Utils/business.js +63 -53
  43. package/lib/Utils/chat-utils.js +81 -71
  44. package/lib/Utils/crypto.js +25 -45
  45. package/lib/Utils/decode-wa-message.js +319 -311
  46. package/lib/Utils/event-buffer.js +21 -22
  47. package/lib/Utils/generics.js +65 -82
  48. package/lib/Utils/history.js +21 -21
  49. package/lib/Utils/index.js +27 -13
  50. package/lib/Utils/link-preview.js +7 -30
  51. package/lib/Utils/logger.js +5 -5
  52. package/lib/Utils/lt-hash.js +3 -3
  53. package/lib/Utils/message-retry-manager.js +4 -4
  54. package/lib/Utils/messages-media.js +104 -109
  55. package/lib/Utils/messages.js +203 -171
  56. package/lib/Utils/noise-handler.js +28 -19
  57. package/lib/Utils/process-message.js +111 -96
  58. package/lib/Utils/signal.js +36 -25
  59. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  60. package/lib/Utils/validate-connection.js +52 -45
  61. package/lib/WABinary/decode.js +6 -32
  62. package/lib/WABinary/encode.js +3 -29
  63. package/lib/WABinary/generic-utils.js +4 -4
  64. package/lib/WABinary/index.js +27 -11
  65. package/lib/WAM/encode.js +16 -8
  66. package/lib/WAM/index.js +27 -11
  67. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  68. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  69. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  70. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  71. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  72. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  73. package/lib/WAUSync/Protocols/index.js +27 -11
  74. package/lib/WAUSync/USyncQuery.js +17 -10
  75. package/lib/WAUSync/index.js +27 -11
  76. package/lib/index.js +60 -31
  77. package/package.json +8 -14
  78. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  79. package/WAProto/Adv/Adv.d.ts +0 -643
  80. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  81. package/WAProto/Cert/Cert.d.ts +0 -613
  82. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  83. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  84. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  85. package/WAProto/E2E/E2E.d.ts +0 -41724
  86. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  87. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  88. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  89. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  90. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  91. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  92. package/WAProto/Protocol/Protocol.d.ts +0 -270
  93. package/WAProto/Reporting/Reporting.d.ts +0 -371
  94. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  95. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  96. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  97. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  98. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  99. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  100. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  101. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  102. package/WAProto/Web/Web.d.ts +0 -46383
  103. package/WAProto/index.d.ts +0 -55
  104. package/lib/Defaults/index.d.ts +0 -77
  105. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  106. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  107. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  108. package/lib/Signal/Group/index.d.ts +0 -11
  109. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  110. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  112. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  113. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  114. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  115. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  116. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  117. package/lib/Signal/libsignal.d.ts +0 -8
  118. package/lib/Signal/lid-mapping.d.ts +0 -28
  119. package/lib/Socket/Client/index.d.ts +0 -2
  120. package/lib/Socket/Client/types.d.ts +0 -16
  121. package/lib/Socket/Client/websocket.d.ts +0 -13
  122. package/lib/Socket/business.d.ts +0 -187
  123. package/lib/Socket/chats.d.ts +0 -97
  124. package/lib/Socket/community.d.ts +0 -129
  125. package/lib/Socket/groups.d.ts +0 -129
  126. package/lib/Socket/index.d.ts +0 -191
  127. package/lib/Socket/messages-recv.d.ts +0 -174
  128. package/lib/Socket/messages-send.d.ts +0 -165
  129. package/lib/Socket/newsletter.d.ts +0 -145
  130. package/lib/Socket/socket.d.ts +0 -45
  131. package/lib/Socket/usync.d.ts +0 -37
  132. package/lib/Store/index.d.ts +0 -4
  133. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  134. package/lib/Store/make-in-memory-store.d.ts +0 -123
  135. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  136. package/lib/Store/object-repository.d.ts +0 -10
  137. package/lib/Types/Auth.d.ts +0 -121
  138. package/lib/Types/Bussiness.d.ts +0 -28
  139. package/lib/Types/Call.d.ts +0 -14
  140. package/lib/Types/Chat.d.ts +0 -143
  141. package/lib/Types/Contact.d.ts +0 -23
  142. package/lib/Types/Events.d.ts +0 -226
  143. package/lib/Types/GroupMetadata.d.ts +0 -66
  144. package/lib/Types/Label.d.ts +0 -48
  145. package/lib/Types/LabelAssociation.d.ts +0 -35
  146. package/lib/Types/Message.d.ts +0 -484
  147. package/lib/Types/MexUpdates.d.ts +0 -9
  148. package/lib/Types/Newsletter.d.ts +0 -109
  149. package/lib/Types/Product.d.ts +0 -92
  150. package/lib/Types/Signal.d.ts +0 -98
  151. package/lib/Types/Socket.d.ts +0 -141
  152. package/lib/Types/State.d.ts +0 -41
  153. package/lib/Types/USync.d.ts +0 -26
  154. package/lib/Types/index.d.ts +0 -80
  155. package/lib/Utils/auth-utils.d.ts +0 -21
  156. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  157. package/lib/Utils/business.d.ts +0 -29
  158. package/lib/Utils/chat-utils.d.ts +0 -82
  159. package/lib/Utils/crypto.d.ts +0 -56
  160. package/lib/Utils/decode-wa-message.d.ts +0 -53
  161. package/lib/Utils/event-buffer.d.ts +0 -39
  162. package/lib/Utils/generics.d.ts +0 -117
  163. package/lib/Utils/history.d.ts +0 -23
  164. package/lib/Utils/index.d.ts +0 -20
  165. package/lib/Utils/link-preview.d.ts +0 -23
  166. package/lib/Utils/logger.d.ts +0 -13
  167. package/lib/Utils/lt-hash.d.ts +0 -14
  168. package/lib/Utils/make-mutex.d.ts +0 -9
  169. package/lib/Utils/message-retry-manager.d.ts +0 -88
  170. package/lib/Utils/messages-media.d.ts +0 -135
  171. package/lib/Utils/messages.d.ts +0 -105
  172. package/lib/Utils/noise-handler.d.ts +0 -20
  173. package/lib/Utils/process-message.d.ts +0 -49
  174. package/lib/Utils/signal.d.ts +0 -42
  175. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  176. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  177. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  178. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  179. package/lib/Utils/use-single-file-auth-state.js +0 -80
  180. package/lib/Utils/validate-connection.d.ts +0 -13
  181. package/lib/WABinary/constants.d.ts +0 -30
  182. package/lib/WABinary/decode.d.ts +0 -9
  183. package/lib/WABinary/encode.d.ts +0 -3
  184. package/lib/WABinary/generic-utils.d.ts +0 -28
  185. package/lib/WABinary/index.d.ts +0 -5
  186. package/lib/WABinary/jid-utils.d.ts +0 -58
  187. package/lib/WABinary/types.d.ts +0 -22
  188. package/lib/WAM/BinaryInfo.d.ts +0 -16
  189. package/lib/WAM/constants.d.ts +0 -47
  190. package/lib/WAM/encode.d.ts +0 -3
  191. package/lib/WAM/index.d.ts +0 -3
  192. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  193. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  194. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  195. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  196. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  197. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  198. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  199. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  200. package/lib/WAUSync/USyncUser.d.ts +0 -12
  201. package/lib/WAUSync/index.d.ts +0 -3
  202. package/lib/index.d.ts +0 -13
@@ -1,39 +1,64 @@
1
1
  "use strict"
2
2
 
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
3
  Object.defineProperty(exports, "__esModule", { value: true })
8
4
 
9
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"))
10
- const boom_1 = require("@hapi/boom")
11
- const WAProto_1 = require("../../WAProto")
12
- const Defaults_1 = require("../Defaults")
13
- const Types_1 = require("../Types")
14
- const Utils_1 = require("../Utils")
15
- const make_mutex_1 = require("../Utils/make-mutex")
16
- const WABinary_1 = require("../WABinary")
17
- const WAUSync_1 = require("../WAUSync")
18
- const socket_1 = require("./socket")
5
+ const { default: NodeCache } = require("@cacheable/node-cache")
6
+ const { Boom } = require("@hapi/boom")
7
+ const { proto } = require("../../WAProto")
8
+ const {
9
+ CALL_VIDEO_PREFIX,
10
+ CALL_AUDIO_PREFIX
11
+ } = require("../Defaults/prefix")
12
+ const { DEFAULT_CACHE_TTLS } = require("../Defaults/constants")
13
+ const { PROCESSABLE_HISTORY_TYPES } = require("../Defaults/history")
14
+ const {
15
+ SyncState,
16
+ ALL_WA_PATCH_NAMES
17
+ } = require("../Types")
18
+ const {
19
+ newLTHashState,
20
+ processSyncAction,
21
+ extractSyncdPatches,
22
+ generateProfilePicture,
23
+ decodeSyncdSnapshot,
24
+ decodePatches,
25
+ encodeSyncdPatch,
26
+ chatModificationToAppPatch,
27
+ getHistoryMsg,
28
+ processMessage
29
+ } = require("../Utils")
30
+ const { makeMutex } = require("../Utils/make-mutex")
31
+ const {
32
+ getBinaryNodeChild,
33
+ getBinaryNodeChildren,
34
+ jidDecode,
35
+ jidNormalizedUser,
36
+ reduceBinaryNodeToDictionary,
37
+ S_WHATSAPP_NET
38
+ } = require("../WABinary")
39
+ const {
40
+ USyncUser,
41
+ USyncQuery
42
+ } = require("../WAUSync")
43
+ const { makeSocket } = require("./socket")
19
44
  const MAX_SYNC_ATTEMPTS = 2
20
45
 
21
46
  const makeChatsSocket = (config) => {
22
47
  const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config
23
- const suki = socket_1.makeSocket(config)
48
+ const suki = makeSocket(config)
24
49
  const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, groupFetchAllParticipating } = suki
25
50
 
26
51
  let privacySettings
27
- let syncState = Types_1.SyncState.Connecting
52
+ let syncState = SyncState.Connecting
28
53
 
29
54
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
30
- const processingMutex = make_mutex_1.makeMutex()
55
+ const processingMutex = makeMutex()
31
56
 
32
57
  // Timeout for AwaitingInitialSync State
33
58
  let awaitingSyncTimeout
34
59
 
35
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
36
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
60
+ const placeholderResendCache = config.placeholderResendCache || new NodeCache({
61
+ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY,
37
62
  useClones: false
38
63
  })
39
64
 
@@ -53,14 +78,14 @@ const makeChatsSocket = (config) => {
53
78
  tag: 'iq',
54
79
  attrs: {
55
80
  xmlns: 'privacy',
56
- to: WABinary_1.S_WHATSAPP_NET,
81
+ to: S_WHATSAPP_NET,
57
82
  type: 'get'
58
83
  },
59
84
  content: [
60
85
  { tag: 'privacy', attrs: {} }
61
86
  ]
62
87
  })
63
- privacySettings = WABinary_1.reduceBinaryNodeToDictionary(content?.[0], 'category')
88
+ privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category')
64
89
  }
65
90
  return privacySettings
66
91
  }
@@ -71,7 +96,7 @@ const makeChatsSocket = (config) => {
71
96
  tag: 'iq',
72
97
  attrs: {
73
98
  xmlns: 'privacy',
74
- to: WABinary_1.S_WHATSAPP_NET,
99
+ to: S_WHATSAPP_NET,
75
100
  type: 'set'
76
101
  },
77
102
  content: [{
@@ -124,7 +149,7 @@ const makeChatsSocket = (config) => {
124
149
  tag: 'iq',
125
150
  attrs: {
126
151
  xmlns: 'disappearing_mode',
127
- to: WABinary_1.S_WHATSAPP_NET,
152
+ to: S_WHATSAPP_NET,
128
153
  type: 'set'
129
154
  },
130
155
  content: [{
@@ -141,7 +166,7 @@ const makeChatsSocket = (config) => {
141
166
  tag: 'iq',
142
167
  attrs: {
143
168
  xmlns: 'bot',
144
- to: WABinary_1.S_WHATSAPP_NET,
169
+ to: S_WHATSAPP_NET,
145
170
  type: 'get'
146
171
  },
147
172
  content: [{
@@ -152,13 +177,13 @@ const makeChatsSocket = (config) => {
152
177
  }]
153
178
  })
154
179
 
155
- const botNode = WABinary_1.getBinaryNodeChild(resp, 'bot')
180
+ const botNode = getBinaryNodeChild(resp, 'bot')
156
181
 
157
182
  const botList = []
158
183
 
159
- for(const section of WABinary_1.getBinaryNodeChildren(botNode, 'section')) {
184
+ for(const section of getBinaryNodeChildren(botNode, 'section')) {
160
185
  if(section.attrs.type === 'all') {
161
- for(const bot of WABinary_1.getBinaryNodeChildren(section, 'bot')) {
186
+ for(const bot of getBinaryNodeChildren(section, 'bot')) {
162
187
  botList.push({
163
188
  jid: bot.attrs.jid,
164
189
  personaId: bot.attrs['persona_id']
@@ -171,16 +196,16 @@ const makeChatsSocket = (config) => {
171
196
 
172
197
  const getLidUser = async (jid) => {
173
198
  if (!jid) {
174
- throw new boom_1.Boom('Please input a jid user')
199
+ throw new Boom('Please input a jid user')
175
200
  }
176
201
 
177
- if (!WABinary_1.isJidUser(jid)) {
178
- throw new boom_1.Boom('Invalid JID: Not a user JID!')
202
+ if (!isJidUser(jid)) {
203
+ throw new Boom('Invalid JID: Not a user JID!')
179
204
  }
180
205
 
181
- const targetJid = WABinary_1.jidNormalizedUser(jid)
206
+ const targetJid = jidNormalizedUser(jid)
182
207
 
183
- const usyncQuery = new WAUSync_1.USyncQuery()
208
+ const usyncQuery = new USyncQuery()
184
209
  usyncQuery.protocols.push({
185
210
  name: 'lid',
186
211
  getQueryElement: () => ({
@@ -203,10 +228,10 @@ const makeChatsSocket = (config) => {
203
228
  }
204
229
 
205
230
  const fetchStatus = async (...jids) => {
206
- const usyncQuery = new WAUSync_1.USyncQuery().withStatusProtocol()
231
+ const usyncQuery = new USyncQuery().withStatusProtocol()
207
232
 
208
233
  for (const jid of jids) {
209
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid))
234
+ usyncQuery.withUser(new USyncUser().withId(jid))
210
235
  }
211
236
 
212
237
  const result = await suki.executeUSyncQuery(usyncQuery)
@@ -216,10 +241,10 @@ const makeChatsSocket = (config) => {
216
241
  }
217
242
  }
218
243
  const fetchDisappearingDuration = async (...jids) => {
219
- const usyncQuery = new WAUSync_1.USyncQuery().withDisappearingModeProtocol()
244
+ const usyncQuery = new USyncQuery().withDisappearingModeProtocol()
220
245
 
221
246
  for (const jid of jids) {
222
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid))
247
+ usyncQuery.withUser(new USyncUser().withId(jid))
223
248
  }
224
249
 
225
250
  const result = await suki.executeUSyncQuery(usyncQuery)
@@ -233,20 +258,20 @@ const makeChatsSocket = (config) => {
233
258
  let targetJid
234
259
 
235
260
  if (!jid) {
236
- throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
261
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
237
262
  }
238
263
 
239
- if (WABinary_1.jidNormalizedUser(jid) !== WABinary_1.jidNormalizedUser(authState.creds.me.id)) {
240
- targetJid = WABinary_1.jidNormalizedUser(jid) // in case it is someone other than us
264
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
265
+ targetJid = jidNormalizedUser(jid) // in case it is someone other than us
241
266
  }
242
267
 
243
- const { img } = await Utils_1.generateProfilePicture(content)
268
+ const { img } = await generateProfilePicture(content)
244
269
 
245
270
  await query({
246
271
  tag: 'iq',
247
272
  attrs: {
248
273
  target: targetJid,
249
- to: WABinary_1.S_WHATSAPP_NET,
274
+ to: S_WHATSAPP_NET,
250
275
  type: 'set',
251
276
  xmlns: 'w:profile:picture'
252
277
  },
@@ -265,18 +290,18 @@ const makeChatsSocket = (config) => {
265
290
  let targetJid
266
291
 
267
292
  if (!jid) {
268
- throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
293
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update')
269
294
  }
270
295
 
271
- if (WABinary_1.jidNormalizedUser(jid) !== WABinary_1.jidNormalizedUser(authState.creds.me.id)) {
272
- targetJid = WABinary_1.jidNormalizedUser(jid) // in case it is someone other than us
296
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
297
+ targetJid = jidNormalizedUser(jid) // in case it is someone other than us
273
298
  }
274
299
 
275
300
  await query({
276
301
  tag: 'iq',
277
302
  attrs: {
278
303
  target: targetJid,
279
- to: WABinary_1.S_WHATSAPP_NET,
304
+ to: S_WHATSAPP_NET,
280
305
  type: 'set',
281
306
  xmlns: 'w:profile:picture'
282
307
  }
@@ -288,7 +313,7 @@ const makeChatsSocket = (config) => {
288
313
  await query({
289
314
  tag: 'iq',
290
315
  attrs: {
291
- to: WABinary_1.S_WHATSAPP_NET,
316
+ to: S_WHATSAPP_NET,
292
317
  type: 'set',
293
318
  xmlns: 'status'
294
319
  },
@@ -311,14 +336,14 @@ const makeChatsSocket = (config) => {
311
336
  tag: 'iq',
312
337
  attrs: {
313
338
  xmlns: 'blocklist',
314
- to: WABinary_1.S_WHATSAPP_NET,
339
+ to: S_WHATSAPP_NET,
315
340
  type: 'get'
316
341
  }
317
342
  })
318
343
 
319
- const listNode = WABinary_1.getBinaryNodeChild(result, 'list')
344
+ const listNode = getBinaryNodeChild(result, 'list')
320
345
 
321
- return WABinary_1.getBinaryNodeChildren(listNode, 'item').map((n) => n.attrs.jid)
346
+ return getBinaryNodeChildren(listNode, 'item').map((n) => n.attrs.jid)
322
347
  }
323
348
 
324
349
  const updateBlockStatus = async (jid, action) => {
@@ -326,7 +351,7 @@ const makeChatsSocket = (config) => {
326
351
  tag: 'iq',
327
352
  attrs: {
328
353
  xmlns: 'blocklist',
329
- to: WABinary_1.S_WHATSAPP_NET,
354
+ to: S_WHATSAPP_NET,
330
355
  type: 'set'
331
356
  },
332
357
  content: [
@@ -359,19 +384,19 @@ const makeChatsSocket = (config) => {
359
384
  }]
360
385
  })
361
386
 
362
- const profileNode = WABinary_1.getBinaryNodeChild(results, 'business_profile')
387
+ const profileNode = getBinaryNodeChild(results, 'business_profile')
363
388
 
364
- const profiles = WABinary_1.getBinaryNodeChild(profileNode, 'profile')
389
+ const profiles = getBinaryNodeChild(profileNode, 'profile')
365
390
 
366
391
  if (profiles) {
367
- const address = WABinary_1.getBinaryNodeChild(profiles, 'address')
368
- const description = WABinary_1.getBinaryNodeChild(profiles, 'description')
369
- const website = WABinary_1.getBinaryNodeChild(profiles, 'website')
370
- const email = WABinary_1.getBinaryNodeChild(profiles, 'email')
371
- const category = WABinary_1.getBinaryNodeChild(WABinary_1.getBinaryNodeChild(profiles, 'categories'), 'category')
372
- const businessHours = WABinary_1.getBinaryNodeChild(profiles, 'business_hours')
392
+ const address = getBinaryNodeChild(profiles, 'address')
393
+ const description = getBinaryNodeChild(profiles, 'description')
394
+ const website = getBinaryNodeChild(profiles, 'website')
395
+ const email = getBinaryNodeChild(profiles, 'email')
396
+ const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category')
397
+ const businessHours = getBinaryNodeChild(profiles, 'business_hours')
373
398
  const businessHoursConfig = businessHours
374
- ? WABinary_1.getBinaryNodeChildren(businessHours, 'business_hours_config')
399
+ ? getBinaryNodeChildren(businessHours, 'business_hours_config')
375
400
  : undefined
376
401
  const websiteStr = website?.content?.toString()
377
402
 
@@ -395,7 +420,7 @@ const makeChatsSocket = (config) => {
395
420
  await sendNode({
396
421
  tag: 'iq',
397
422
  attrs: {
398
- to: WABinary_1.S_WHATSAPP_NET,
423
+ to: S_WHATSAPP_NET,
399
424
  type: 'set',
400
425
  xmlns: 'urn:xmpp:whatsapp:dirty',
401
426
  id: generateMessageTag(),
@@ -415,7 +440,7 @@ const makeChatsSocket = (config) => {
415
440
  const newAppStateChunkHandler = (isInitialSync) => {
416
441
  return {
417
442
  onMutation(mutation) {
418
- Utils_1.processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger)
443
+ processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger)
419
444
  }
420
445
  }
421
446
  }
@@ -445,7 +470,7 @@ const makeChatsSocket = (config) => {
445
470
  }
446
471
  }
447
472
  else {
448
- state = Utils_1.newLTHashState()
473
+ state = newLTHashState()
449
474
  }
450
475
  states[name] = state
451
476
  logger.info(`resyncing ${name} from v${state.version}`)
@@ -463,7 +488,7 @@ const makeChatsSocket = (config) => {
463
488
  const result = await query({
464
489
  tag: 'iq',
465
490
  attrs: {
466
- to: WABinary_1.S_WHATSAPP_NET,
491
+ to: S_WHATSAPP_NET,
467
492
  xmlns: 'w:sync:app:state',
468
493
  type: 'set'
469
494
  },
@@ -477,14 +502,14 @@ const makeChatsSocket = (config) => {
477
502
  })
478
503
 
479
504
  // extract from binary node
480
- const decoded = await Utils_1.extractSyncdPatches(result, config?.options)
505
+ const decoded = await extractSyncdPatches(result, config?.options)
481
506
 
482
507
  for (const key in decoded) {
483
508
  const name = key
484
509
  const { patches, hasMorePatches, snapshot } = decoded[name]
485
510
  try {
486
511
  if (snapshot) {
487
- const { state: newState, mutationMap } = await Utils_1.decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot)
512
+ const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot)
488
513
  states[name] = newState
489
514
  Object.assign(globalMutationMap, mutationMap)
490
515
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`)
@@ -493,7 +518,7 @@ const makeChatsSocket = (config) => {
493
518
 
494
519
  // only process if there are syncd patches
495
520
  if (patches.length) {
496
- const { state: newState, mutationMap } = await Utils_1.decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch)
521
+ const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch)
497
522
  await authState.keys.set({ 'app-state-sync-version': { [name]: newState } })
498
523
  logger.info(`synced ${name} to v${newState.version}`)
499
524
  initialVersionMap[name] = newState.version
@@ -562,10 +587,10 @@ const makeChatsSocket = (config) => {
562
587
  }]
563
588
  }, timeoutMs)
564
589
 
565
- const child = WABinary_1.getBinaryNodeChild(result, 'link_create')
590
+ const child = getBinaryNodeChild(result, 'link_create')
566
591
  const token = child?.attrs?.token
567
592
 
568
- return type === 'audio' ? Defaults_1.CALL_AUDIO_PREFIX + token : Defaults_1.CALL_VIDEO_PREFIX + token
593
+ return type === 'audio' ? CALL_AUDIO_PREFIX + token : CALL_VIDEO_PREFIX + token
569
594
  }
570
595
 
571
596
  const sendPresenceUpdate = async (type, toJid) => {
@@ -587,7 +612,7 @@ const makeChatsSocket = (config) => {
587
612
  })
588
613
  }
589
614
  else {
590
- const { server } = WABinary_1.jidDecode(toJid)
615
+ const { server } = jidDecode(toJid)
591
616
 
592
617
  await sendNode({
593
618
  tag: 'chatstate',
@@ -672,7 +697,7 @@ const makeChatsSocket = (config) => {
672
697
  const myAppStateKeyId = authState.creds.myAppStateKeyId
673
698
 
674
699
  if (!myAppStateKeyId) {
675
- throw new boom_1.Boom('App state key not present!', { statusCode: 400 })
700
+ throw new Boom('App state key not present!', { statusCode: 400 })
676
701
  }
677
702
 
678
703
  let initial
@@ -683,14 +708,14 @@ const makeChatsSocket = (config) => {
683
708
  logger.debug({ patch: patchCreate }, 'applying app patch')
684
709
  await resyncAppState([name], false)
685
710
  const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name])
686
- initial = currentSyncVersion || Utils_1.newLTHashState()
687
- encodeResult = await Utils_1.encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey)
711
+ initial = currentSyncVersion || newLTHashState()
712
+ encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey)
688
713
  const { patch, state } = encodeResult
689
714
 
690
715
  const node = {
691
716
  tag: 'iq',
692
717
  attrs: {
693
- to: WABinary_1.S_WHATSAPP_NET,
718
+ to: S_WHATSAPP_NET,
694
719
  type: 'set',
695
720
  xmlns: 'w:sync:app:state'
696
721
  },
@@ -710,7 +735,7 @@ const makeChatsSocket = (config) => {
710
735
  {
711
736
  tag: 'patch',
712
737
  attrs: {},
713
- content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
738
+ content: proto.SyncdPatch.encode(patch).finish()
714
739
  }
715
740
  ]
716
741
  }
@@ -725,7 +750,7 @@ const makeChatsSocket = (config) => {
725
750
 
726
751
  if (config.emitOwnEvents) {
727
752
  const { onMutation } = newAppStateChunkHandler(false)
728
- const { mutationMap } = await Utils_1.decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger)
753
+ const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger)
729
754
 
730
755
  for (const key in mutationMap) {
731
756
  onMutation(mutationMap[key])
@@ -738,7 +763,7 @@ const makeChatsSocket = (config) => {
738
763
  const resultNode = await query({
739
764
  tag: 'iq',
740
765
  attrs: {
741
- to: WABinary_1.S_WHATSAPP_NET,
766
+ to: S_WHATSAPP_NET,
742
767
  xmlns: 'w',
743
768
  type: 'get',
744
769
  },
@@ -750,7 +775,7 @@ const makeChatsSocket = (config) => {
750
775
  ]
751
776
  })
752
777
 
753
- const propsNode = WABinary_1.getBinaryNodeChild(resultNode, 'props')
778
+ const propsNode = getBinaryNodeChild(resultNode, 'props')
754
779
  let props = {}
755
780
 
756
781
  if (propsNode) {
@@ -759,7 +784,7 @@ const makeChatsSocket = (config) => {
759
784
  ev.emit('creds.update', authState.creds)
760
785
  }
761
786
 
762
- props = WABinary_1.reduceBinaryNodeToDictionary(propsNode, 'prop')
787
+ props = reduceBinaryNodeToDictionary(propsNode, 'prop')
763
788
  }
764
789
  logger.debug('fetched props')
765
790
  return props
@@ -771,7 +796,7 @@ const makeChatsSocket = (config) => {
771
796
  * requires the last messages till the last message received required for archive & unread
772
797
  */
773
798
  const chatModify = (mod, jid) => {
774
- const patch = Utils_1.chatModificationToAppPatch(mod, jid)
799
+ const patch = chatModificationToAppPatch(mod, jid)
775
800
  return appPatch(patch)
776
801
  }
777
802
 
@@ -920,7 +945,7 @@ const makeChatsSocket = (config) => {
920
945
  ev.emit('messages.upsert', { messages: [msg], type })
921
946
  if (!!msg.pushName) {
922
947
  let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid)
923
- jid = WABinary_1.jidNormalizedUser(jid)
948
+ jid = jidNormalizedUser(jid)
924
949
 
925
950
  if (!msg.key.fromMe) {
926
951
  ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }])
@@ -932,36 +957,36 @@ const makeChatsSocket = (config) => {
932
957
  }
933
958
  }
934
959
 
935
- const historyMsg = Utils_1.getHistoryMsg(msg.message)
960
+ const historyMsg = getHistoryMsg(msg.message)
936
961
  const shouldProcessHistoryMsg = historyMsg
937
962
  ? (shouldSyncHistoryMessage(historyMsg)
938
- && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
963
+ && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
939
964
  : false
940
965
 
941
- if (historyMsg && syncState === Types_1.SyncState.AwaitingInitialSync) {
966
+ if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
942
967
  if (awaitingSyncTimeout) {
943
968
  clearTimeout(awaitingSyncTimeout)
944
969
  awaitingSyncTimeout = undefined
945
970
  }
946
971
 
947
972
  if (shouldProcessHistoryMsg) {
948
- syncState = Types_1.SyncState.Syncing
973
+ syncState = SyncState.Syncing
949
974
  logger.info('Transitioned to Syncing state')
950
975
  // Let doAppStateSync handle the final flush after it`s done
951
976
  } else {
952
- syncState = Types_1.SyncState.Online
977
+ syncState = SyncState.Online
953
978
  logger.info('History sync skipped, transitioning to Online state and flushing buffer')
954
979
  ev.flush()
955
980
  }
956
981
  }
957
982
 
958
983
  const doAppStateSync = async () => {
959
- if (syncState === Types_1.SyncState.Syncing) {
984
+ if (syncState === SyncState.Syncing) {
960
985
  logger.info('Doing app state sync')
961
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true)
986
+ await resyncAppState(ALL_WA_PATCH_NAMES, true)
962
987
 
963
988
  // Sync is complete, go online and flush everything
964
- syncState = Types_1.SyncState.Online
989
+ syncState = SyncState.Online
965
990
  logger.info('App state sync complete, transitioning to Online state and flushing buffer')
966
991
  ev.flush()
967
992
 
@@ -976,7 +1001,7 @@ const makeChatsSocket = (config) => {
976
1001
  await doAppStateSync()
977
1002
  }
978
1003
  })(),
979
- Utils_1.processMessage(msg, {
1004
+ processMessage(msg, {
980
1005
  signalRepository,
981
1006
  shouldProcessHistoryMsg,
982
1007
  placeholderResendCache,
@@ -989,7 +1014,7 @@ const makeChatsSocket = (config) => {
989
1014
  })
990
1015
  ])
991
1016
 
992
- if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === Types_1.SyncState.Syncing) {
1017
+ if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
993
1018
  logger.info('App state sync key arrived, triggering app state sync')
994
1019
  await doAppStateSync()
995
1020
  }
@@ -998,7 +1023,7 @@ const makeChatsSocket = (config) => {
998
1023
  ws.on('CB:presence', handlePresenceUpdate)
999
1024
  ws.on('CB:chatstate', handlePresenceUpdate)
1000
1025
  ws.on('CB:ib,,dirty', async (node) => {
1001
- const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
1026
+ const { attrs } = getBinaryNodeChild(node, 'dirty')
1002
1027
  const type = attrs.type
1003
1028
 
1004
1029
  switch (type) {
@@ -1032,21 +1057,21 @@ const makeChatsSocket = (config) => {
1032
1057
  .catch(error => onUnexpectedError(error, 'presence update requests'))
1033
1058
  }
1034
1059
 
1035
- if (!receivedPendingNotifications || syncState !== Types_1.SyncState.Connecting) {
1060
+ if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
1036
1061
  return
1037
1062
  }
1038
1063
 
1039
- syncState = Types_1.AwaitingInitialSync
1064
+ syncState = SyncState.AwaitingInitialSync
1040
1065
  logger.info('Connection is now AwaitingInitialSync, buffering events')
1041
1066
  ev.buffer()
1042
1067
 
1043
- const willSyncHistory = shouldSyncHistoryMessage(WAProto_1.proto.Message.HistorySyncNotification.fromObject({
1044
- syncType: WAProto_1.proto.HistorySync.HistorySyncType.RECENT
1068
+ const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.fromObject({
1069
+ syncType: proto.HistorySync.HistorySyncType.RECENT
1045
1070
  }))
1046
1071
 
1047
1072
  if (!willSyncHistory) {
1048
1073
  logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.')
1049
- syncState = Types_1.SyncState.Online
1074
+ syncState = SyncState.Online
1050
1075
  setTimeout(() => ev.flush(), 0)
1051
1076
  return
1052
1077
  }
@@ -1058,9 +1083,9 @@ const makeChatsSocket = (config) => {
1058
1083
  }
1059
1084
 
1060
1085
  awaitingSyncTimeout = setTimeout(() => {
1061
- if (syncState === Types_1.SyncState.AwaitingInitialSync) {
1086
+ if (syncState === SyncState.AwaitingInitialSync) {
1062
1087
  logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer')
1063
- syncState = Types_1.SyncState.Online
1088
+ syncState = SyncState.Online
1064
1089
  ev.flush()
1065
1090
  }
1066
1091
  }, 20_000)