@vinzsocket/baileys 3.2.14 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1337 -2685
  3. package/WAProto/WAProto.proto +916 -360
  4. package/WAProto/fix-imports.js +18 -22
  5. package/WAProto/index.d.ts +0 -14015
  6. package/WAProto/index.js +80576 -45941
  7. package/lib/Defaults/index.d.ts +14 -15
  8. package/lib/Defaults/index.d.ts.map +1 -1
  9. package/lib/Defaults/index.js +110 -99
  10. package/lib/Defaults/index.js.map +1 -1
  11. package/lib/Modded/message_builder.js +2330 -0
  12. package/lib/Signal/Group/group_cipher.js.map +1 -1
  13. package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
  14. package/lib/Signal/Group/keyhelper.js.map +1 -1
  15. package/lib/Signal/Group/sender-chain-key.js.map +1 -1
  16. package/lib/Signal/Group/sender-key-message.js.map +1 -1
  17. package/lib/Signal/Group/sender-message-key.js.map +1 -1
  18. package/lib/Signal/libsignal.d.ts.map +1 -1
  19. package/lib/Signal/libsignal.js +17 -45
  20. package/lib/Signal/libsignal.js.map +1 -1
  21. package/lib/Signal/lid-mapping.d.ts +0 -4
  22. package/lib/Signal/lid-mapping.d.ts.map +1 -1
  23. package/lib/Signal/lid-mapping.js +0 -6
  24. package/lib/Signal/lid-mapping.js.map +1 -1
  25. package/lib/Socket/business.d.ts +532 -213
  26. package/lib/Socket/business.d.ts.map +1 -1
  27. package/lib/Socket/business.js +401 -358
  28. package/lib/Socket/chats.d.ts +2 -15
  29. package/lib/Socket/chats.d.ts.map +1 -1
  30. package/lib/Socket/chats.js +39 -241
  31. package/lib/Socket/chats.js.map +1 -1
  32. package/lib/Socket/communities.d.ts +641 -269
  33. package/lib/Socket/communities.d.ts.map +1 -1
  34. package/lib/Socket/dugong.d.ts +127 -315
  35. package/lib/Socket/dugong.d.ts.map +1 -0
  36. package/lib/Socket/dugong.js +749 -610
  37. package/lib/Socket/dugong.js.map +1 -0
  38. package/lib/Socket/groups.d.ts +2 -13
  39. package/lib/Socket/groups.d.ts.map +1 -1
  40. package/lib/Socket/groups.js +1 -21
  41. package/lib/Socket/groups.js.map +1 -1
  42. package/lib/Socket/index.d.ts +631 -256
  43. package/lib/Socket/index.d.ts.map +1 -1
  44. package/lib/Socket/index.js +12 -9
  45. package/lib/Socket/index.js.map +1 -1
  46. package/lib/Socket/messages-recv.d.ts +58 -23
  47. package/lib/Socket/messages-recv.d.ts.map +1 -1
  48. package/lib/Socket/messages-recv.js +181 -645
  49. package/lib/Socket/messages-recv.js.map +1 -1
  50. package/lib/Socket/messages-send.d.ts +575 -201
  51. package/lib/Socket/messages-send.d.ts.map +1 -1
  52. package/lib/Socket/messages-send.js +1552 -1185
  53. package/lib/Socket/messages-send.js.map +1 -1
  54. package/lib/Socket/mex.d.ts.map +1 -1
  55. package/lib/Socket/mex.js +8 -2
  56. package/lib/Socket/mex.js.map +1 -1
  57. package/lib/Socket/newsletter.d.ts +18 -11
  58. package/lib/Socket/newsletter.d.ts.map +1 -1
  59. package/lib/Socket/newsletter.js +440 -165
  60. package/lib/Socket/newsletter.js.map +1 -1
  61. package/lib/Socket/socket.d.ts +2 -6
  62. package/lib/Socket/socket.d.ts.map +1 -1
  63. package/lib/Socket/socket.js +25 -56
  64. package/lib/Socket/socket.js.map +1 -1
  65. package/lib/Types/Auth.d.ts +0 -1
  66. package/lib/Types/Auth.d.ts.map +1 -1
  67. package/lib/Types/Bussines.d.ts +34 -22
  68. package/lib/Types/Call.d.ts +1 -1
  69. package/lib/Types/Call.d.ts.map +1 -1
  70. package/lib/Types/Chat.d.ts +0 -1
  71. package/lib/Types/Chat.d.ts.map +1 -1
  72. package/lib/Types/Contact.d.ts +0 -2
  73. package/lib/Types/Contact.d.ts.map +1 -1
  74. package/lib/Types/Events.d.ts +1 -20
  75. package/lib/Types/Events.d.ts.map +1 -1
  76. package/lib/Types/GroupMetadata.d.ts +1 -4
  77. package/lib/Types/GroupMetadata.d.ts.map +1 -1
  78. package/lib/Types/Message.d.ts +348 -294
  79. package/lib/Types/Message.d.ts.map +1 -1
  80. package/lib/Types/Message.js.map +1 -1
  81. package/lib/Types/{Mex.d.ts → Newsletter.d.ts} +5 -11
  82. package/lib/Types/Newsletter.d.ts.map +1 -0
  83. package/lib/Types/{Mex.js → Newsletter.js} +3 -9
  84. package/lib/Types/Newsletter.js.map +1 -0
  85. package/lib/Types/Signal.d.ts +1 -12
  86. package/lib/Types/Signal.d.ts.map +1 -1
  87. package/lib/Types/Socket.d.ts +148 -126
  88. package/lib/Types/Socket.d.ts.map +1 -1
  89. package/lib/Types/State.d.ts +0 -58
  90. package/lib/Types/State.d.ts.map +1 -1
  91. package/lib/Types/State.js +0 -43
  92. package/lib/Types/State.js.map +1 -1
  93. package/lib/Types/index.d.ts +52 -51
  94. package/lib/Types/index.d.ts.map +1 -1
  95. package/lib/Types/index.js +30 -23
  96. package/lib/Types/index.js.map +1 -1
  97. package/lib/Utils/auth-utils.d.ts +0 -5
  98. package/lib/Utils/auth-utils.d.ts.map +1 -1
  99. package/lib/Utils/auth-utils.js +0 -12
  100. package/lib/Utils/auth-utils.js.map +1 -1
  101. package/lib/Utils/chat-utils.d.ts +4 -34
  102. package/lib/Utils/chat-utils.d.ts.map +1 -1
  103. package/lib/Utils/chat-utils.js +20 -80
  104. package/lib/Utils/chat-utils.js.map +1 -1
  105. package/lib/Utils/crypto.d.ts +12 -12
  106. package/lib/Utils/crypto.d.ts.map +1 -1
  107. package/lib/Utils/crypto.js.map +1 -1
  108. package/lib/Utils/decode-wa-message.d.ts +0 -18
  109. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  110. package/lib/Utils/decode-wa-message.js +0 -34
  111. package/lib/Utils/decode-wa-message.js.map +1 -1
  112. package/lib/Utils/event-buffer.d.ts +0 -2
  113. package/lib/Utils/event-buffer.d.ts.map +1 -1
  114. package/lib/Utils/event-buffer.js +1 -49
  115. package/lib/Utils/event-buffer.js.map +1 -1
  116. package/lib/Utils/generics.d.ts +2 -2
  117. package/lib/Utils/generics.d.ts.map +1 -1
  118. package/lib/Utils/generics.js +0 -9
  119. package/lib/Utils/generics.js.map +1 -1
  120. package/lib/Utils/history.d.ts +0 -2
  121. package/lib/Utils/history.d.ts.map +1 -1
  122. package/lib/Utils/history.js +9 -12
  123. package/lib/Utils/history.js.map +1 -1
  124. package/lib/Utils/identity-change-handler.d.ts +0 -7
  125. package/lib/Utils/identity-change-handler.d.ts.map +1 -1
  126. package/lib/Utils/identity-change-handler.js +0 -1
  127. package/lib/Utils/identity-change-handler.js.map +1 -1
  128. package/lib/Utils/index.d.ts +23 -23
  129. package/lib/Utils/index.d.ts.map +1 -1
  130. package/lib/Utils/index.js +2 -3
  131. package/lib/Utils/index.js.map +1 -1
  132. package/lib/Utils/link-preview.js +2 -2
  133. package/lib/Utils/link-preview.js.map +1 -1
  134. package/lib/Utils/logger.d.ts +2 -1
  135. package/lib/Utils/logger.d.ts.map +1 -1
  136. package/lib/Utils/message-retry-manager.d.ts +0 -5
  137. package/lib/Utils/message-retry-manager.d.ts.map +1 -1
  138. package/lib/Utils/message-retry-manager.js +0 -40
  139. package/lib/Utils/message-retry-manager.js.map +1 -1
  140. package/lib/Utils/messages-media.d.ts +13 -16
  141. package/lib/Utils/messages-media.d.ts.map +1 -1
  142. package/lib/Utils/messages-media.js +79 -85
  143. package/lib/Utils/messages-media.js.map +1 -1
  144. package/lib/Utils/messages.d.ts +1 -16
  145. package/lib/Utils/messages.d.ts.map +1 -1
  146. package/lib/Utils/messages.js +1121 -1021
  147. package/lib/Utils/messages.js.map +1 -1
  148. package/lib/Utils/noise-handler.d.ts +1 -1
  149. package/lib/Utils/process-message.d.ts.map +1 -1
  150. package/lib/Utils/process-message.js +1 -103
  151. package/lib/Utils/process-message.js.map +1 -1
  152. package/lib/Utils/rich-messages.d.ts +277 -0
  153. package/lib/Utils/rich-messages.d.ts.map +1 -0
  154. package/lib/Utils/rich-messages.js +1144 -0
  155. package/lib/Utils/rich-messages.js.map +1 -0
  156. package/lib/Utils/signal.d.ts +0 -13
  157. package/lib/Utils/signal.d.ts.map +1 -1
  158. package/lib/Utils/signal.js +0 -42
  159. package/lib/Utils/signal.js.map +1 -1
  160. package/lib/Utils/sticker-pack.d.ts +10 -0
  161. package/lib/Utils/sticker-pack.js +111 -0
  162. package/lib/Utils/sync-action-utils.d.ts.map +1 -1
  163. package/lib/Utils/sync-action-utils.js +0 -1
  164. package/lib/Utils/sync-action-utils.js.map +1 -1
  165. package/lib/Utils/tc-token-utils.d.ts +1 -26
  166. package/lib/Utils/tc-token-utils.d.ts.map +1 -1
  167. package/lib/Utils/tc-token-utils.js +4 -149
  168. package/lib/Utils/tc-token-utils.js.map +1 -1
  169. package/lib/Utils/validate-connection.d.ts.map +1 -1
  170. package/lib/Utils/validate-connection.js +0 -3
  171. package/lib/Utils/validate-connection.js.map +1 -1
  172. package/lib/VoIP/audio-feeder.d.ts +15 -0
  173. package/lib/VoIP/audio-feeder.js +132 -0
  174. package/lib/VoIP/index.js +277 -0
  175. package/lib/VoIP/relay-transport.d.ts +43 -0
  176. package/lib/VoIP/relay-transport.js +559 -0
  177. package/lib/VoIP/signaling.js +594 -0
  178. package/lib/VoIP/types.d.ts +69 -0
  179. package/lib/VoIP/types.js +17 -0
  180. package/lib/VoIP/wasm-engine.d.ts +103 -0
  181. package/lib/VoIP/wasm-engine.js +1214 -0
  182. package/lib/VoIP/worker-bootstrap.js +1042 -0
  183. package/lib/WABinary/decode.d.ts +1 -1
  184. package/lib/WABinary/decode.d.ts.map +1 -1
  185. package/lib/WABinary/generic-utils.d.ts +3 -1
  186. package/lib/WABinary/generic-utils.d.ts.map +1 -1
  187. package/lib/WABinary/generic-utils.js +78 -0
  188. package/lib/WABinary/generic-utils.js.map +1 -1
  189. package/lib/WAM/encode.d.ts +1 -1
  190. package/lib/WAM/encode.d.ts.map +1 -1
  191. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
  192. package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -26
  193. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
  194. package/lib/WAUSync/Protocols/index.d.ts +0 -1
  195. package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
  196. package/lib/WAUSync/Protocols/index.js +0 -1
  197. package/lib/WAUSync/Protocols/index.js.map +1 -1
  198. package/lib/WAUSync/USyncQuery.d.ts +0 -1
  199. package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
  200. package/lib/WAUSync/USyncQuery.js +2 -6
  201. package/lib/WAUSync/USyncQuery.js.map +1 -1
  202. package/lib/WAUSync/USyncUser.d.ts +0 -4
  203. package/lib/WAUSync/USyncUser.d.ts.map +1 -1
  204. package/lib/WAUSync/USyncUser.js +0 -8
  205. package/lib/WAUSync/USyncUser.js.map +1 -1
  206. package/lib/assets/wasm/loader.js +5 -0
  207. package/lib/assets/wasm/whatsapp.wasm +0 -0
  208. package/lib/assets/wasm/worker-modules.js +273 -0
  209. package/lib/index.d.ts +1 -0
  210. package/lib/index.d.ts.map +1 -1
  211. package/lib/index.js +3 -0
  212. package/lib/index.js.map +1 -1
  213. package/package.json +29 -92
  214. package/engine-requirements.js +0 -27
  215. package/lib/Types/Mex.d.ts.map +0 -1
  216. package/lib/Types/Mex.js.map +0 -1
  217. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  218. package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
  219. package/lib/Utils/companion-reg-client-utils.js +0 -35
  220. package/lib/Utils/companion-reg-client-utils.js.map +0 -1
  221. package/lib/Utils/mention.d.ts +0 -14
  222. package/lib/Utils/mention.js +0 -138
  223. package/lib/Utils/story-card.js +0 -107
  224. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  225. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +0 -1
  226. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
  227. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +0 -1
@@ -1,19 +1,11 @@
1
1
  import { Boom } from '@hapi/boom';
2
2
  import { proto } from '../../WAProto/index.js';
3
- import type { BotListInfo, CacheStore, ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAMessage, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types/index.js';
3
+ import type { BotListInfo, ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAMessage, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types/index.js';
4
4
  import type { QuickReplyAction } from '../Types/Bussines.js';
5
5
  import type { LabelActionBody } from '../Types/Label.js';
6
6
  import { type BinaryNode } from '../WABinary/index.js';
7
7
  import { USyncQuery } from '../WAUSync/index.js';
8
8
  export declare const makeChatsSocket: (config: SocketConfig) => {
9
- serverProps: {
10
- /** AB prop 10518: gate tctoken on 1:1 messages. Default true (safe: avoids 463). */
11
- privacyTokenOn1to1: boolean;
12
- /** AB prop 9666: gate tctoken on profile picture IQs. WA Web default: true. */
13
- profilePicPrivacyToken: boolean;
14
- /** AB prop 14303: issue tctokens to LID instead of PN. WA Web default: false. */
15
- lidTrustedTokenIssueToLid: boolean;
16
- };
17
9
  createCallLink: (type: "audio" | "video", event?: {
18
10
  startTime: number;
19
11
  }, timeoutMs?: number) => Promise<string | undefined>;
@@ -65,7 +57,6 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
65
57
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
66
58
  addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
67
59
  removeContact: (jid: string) => Promise<void>;
68
- placeholderResendCache: CacheStore;
69
60
  addLabel: (jid: string, labels: LabelActionBody) => Promise<void>;
70
61
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
71
62
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
@@ -85,7 +76,6 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
85
76
  createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
86
77
  flush(): boolean;
87
78
  isBuffering(): boolean;
88
- destroy(): void;
89
79
  };
90
80
  authState: {
91
81
  creds: import("../Types/index.js").AuthenticationCreds;
@@ -101,9 +91,8 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
101
91
  sendNode: (frame: BinaryNode) => Promise<void>;
102
92
  logout: (msg?: string) => Promise<void>;
103
93
  end: (error: Error | undefined) => Promise<void>;
104
- registerSocketEndHandler: (handler: (error: Error | undefined) => void | Promise<void>) => void;
105
94
  onUnexpectedError: (err: Error | Boom, msg: string) => void;
106
- uploadPreKeys: (count?: number) => Promise<void>;
95
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
107
96
  uploadPreKeysToServerIfRequired: () => Promise<void>;
108
97
  digestKeyBundle: () => Promise<void>;
109
98
  rotateSignedPreKey: () => Promise<void>;
@@ -118,7 +107,5 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
118
107
  jid: string;
119
108
  exists: boolean;
120
109
  }[] | undefined>;
121
- fetchAccountReachoutTimelock: () => Promise<import("../Types/index.js").ReachoutTimelockState>;
122
- fetchNewChatMessageCap: () => Promise<import("../Types/index.js").NewChatMessageCapInfo>;
123
110
  };
124
111
  //# sourceMappingURL=chats.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chats.d.ts","sourceRoot":"","sources":["../../src/Socket/chats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE9C,OAAO,KAAK,EACX,WAAW,EACX,UAAU,EAC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/index.js';
4
- import { DEFAULT_CACHE_TTLS, HISTORY_SYNC_PAUSED_TIMEOUT_MS, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
4
+ import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
5
5
  import { ALL_WA_PATCH_NAMES } from '../Types/index.js';
6
6
  import { SyncState } from '../Types/State.js';
7
- import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, ensureLTHashStateVersion, extractSyncdPatches, generateProfilePicture, getHistoryMsg, isAppStateSyncIrrecoverable, isMissingKeyError, MAX_SYNC_ATTEMPTS, newLTHashState, processSyncAction } from '../Utils/index.js';
7
+ import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
8
8
  import { makeMutex } from '../Utils/make-mutex.js';
9
9
  import processMessage from '../Utils/process-message.js';
10
10
  import { buildTcTokenFromJid } from '../Utils/tc-token-utils.js';
11
- import { getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isLidUser, isPnUser, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
11
+ import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
12
12
  import { USyncQuery, USyncUser } from '../WAUSync/index.js';
13
13
  import { makeSocket } from './socket.js';
14
+ const MAX_SYNC_ATTEMPTS = 2;
14
15
  export const makeChatsSocket = (config) => {
15
16
  const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, getMessage } = config;
16
17
  const sock = makeSocket(config);
17
- const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, sendUnifiedSession, registerSocketEndHandler } = sock;
18
- const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
18
+ const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, sendUnifiedSession } = sock;
19
19
  let privacySettings;
20
- /** Server-assigned AB props for protocol behavior. */
21
- const serverProps = {
22
- /** AB prop 10518: gate tctoken on 1:1 messages. Default true (safe: avoids 463). */
23
- privacyTokenOn1to1: true,
24
- /** AB prop 9666: gate tctoken on profile picture IQs. WA Web default: true. */
25
- profilePicPrivacyToken: true,
26
- /** AB prop 14303: issue tctokens to LID instead of PN. WA Web default: false. */
27
- lidTrustedTokenIssueToLid: false
28
- };
29
20
  let syncState = SyncState.Connecting;
30
21
  /** this mutex ensures that messages are processed in order */
31
22
  const messageMutex = makeMutex();
@@ -37,20 +28,14 @@ export const makeChatsSocket = (config) => {
37
28
  const notificationMutex = makeMutex();
38
29
  // Timeout for AwaitingInitialSync state
39
30
  let awaitingSyncTimeout;
40
- // In-memory history sync completion tracking (resets on reconnection)
41
- const historySyncStatus = {
42
- initialBootstrapComplete: false,
43
- recentSyncComplete: false
44
- };
45
- let historySyncPausedTimeout;
46
- // Collections blocked on missing app state sync keys (mirrors WA Web's "Blocked" state).
47
- // When a key arrives via APP_STATE_SYNC_KEY_SHARE, these are re-synced.
48
- const blockedCollections = new Set();
49
31
  const placeholderResendCache = config.placeholderResendCache ||
50
32
  new NodeCache({
51
33
  stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
52
34
  useClones: false
53
35
  });
36
+ if (!config.placeholderResendCache) {
37
+ config.placeholderResendCache = placeholderResendCache;
38
+ }
54
39
  /** helper function to fetch the given app state sync key */
55
40
  const getAppStateSyncKey = async (keyId) => {
56
41
  const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
@@ -273,42 +258,6 @@ export const makeChatsSocket = (config) => {
273
258
  return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
274
259
  };
275
260
  const updateBlockStatus = async (jid, action) => {
276
- const normalizedJid = jidNormalizedUser(jid);
277
- let lid;
278
- let pn_jid;
279
- if (isLidUser(normalizedJid) || isHostedLidUser(normalizedJid)) {
280
- lid = normalizedJid;
281
- if (action === 'block') {
282
- const pn = await signalRepository.lidMapping.getPNForLID(normalizedJid);
283
- if (!pn) {
284
- throw new Boom(`Unable to resolve PN JID for LID: ${jid}`, { statusCode: 400 });
285
- }
286
- pn_jid = jidNormalizedUser(pn);
287
- }
288
- }
289
- else if (isPnUser(normalizedJid) || isHostedPnUser(normalizedJid)) {
290
- const mapped = await signalRepository.lidMapping.getLIDForPN(normalizedJid);
291
- if (!mapped) {
292
- throw new Boom(`Unable to resolve LID for PN JID: ${jid}`, { statusCode: 400 });
293
- }
294
- lid = mapped;
295
- if (action === 'block') {
296
- pn_jid = jidNormalizedUser(normalizedJid);
297
- }
298
- }
299
- else {
300
- throw new Boom(`Invalid jid: ${jid}`, { statusCode: 400 });
301
- }
302
- const itemAttrs = {
303
- action,
304
- jid: lid
305
- };
306
- if (action === 'block') {
307
- if (!pn_jid) {
308
- throw new Boom(`pn_jid required for block: ${jid}`, { statusCode: 400 });
309
- }
310
- itemAttrs.pn_jid = pn_jid;
311
- }
312
261
  await query({
313
262
  tag: 'iq',
314
263
  attrs: {
@@ -319,7 +268,10 @@ export const makeChatsSocket = (config) => {
319
268
  content: [
320
269
  {
321
270
  tag: 'item',
322
- attrs: itemAttrs
271
+ attrs: {
272
+ action,
273
+ jid
274
+ }
323
275
  }
324
276
  ]
325
277
  });
@@ -418,9 +370,6 @@ export const makeChatsSocket = (config) => {
418
370
  const collectionsToHandle = new Set(collections);
419
371
  // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
420
372
  const attemptsMap = {};
421
- // collections that failed and need a full snapshot on retry
422
- // mirrors WA Web's ErrorFatal -> force snapshot behavior
423
- const forceSnapshotCollections = new Set();
424
373
  // keep executing till all collections are done
425
374
  // sometimes a single patch request will not return all the patches (God knows why)
426
375
  // so we fetch till they're all done (this is determined by the "has_more_patches" flag)
@@ -431,7 +380,6 @@ export const makeChatsSocket = (config) => {
431
380
  const result = await authState.keys.get('app-state-sync-version', [name]);
432
381
  let state = result[name];
433
382
  if (state) {
434
- state = ensureLTHashStateVersion(state);
435
383
  if (typeof initialVersionMap[name] === 'undefined') {
436
384
  initialVersionMap[name] = state.version;
437
385
  }
@@ -440,18 +388,14 @@ export const makeChatsSocket = (config) => {
440
388
  state = newLTHashState();
441
389
  }
442
390
  states[name] = state;
443
- const shouldForceSnapshot = forceSnapshotCollections.has(name);
444
- if (shouldForceSnapshot) {
445
- forceSnapshotCollections.delete(name);
446
- }
447
- logger.info(`resyncing ${name} from v${state.version}${shouldForceSnapshot ? ' (forcing snapshot)' : ''}`);
391
+ logger.info(`resyncing ${name} from v${state.version}`);
448
392
  nodes.push({
449
393
  tag: 'collection',
450
394
  attrs: {
451
395
  name,
452
396
  version: state.version.toString(),
453
- // return snapshot if syncing from scratch or forcing after a failed attempt
454
- return_snapshot: (shouldForceSnapshot || !state.version).toString()
397
+ // return snapshot if being synced from scratch
398
+ return_snapshot: (!state.version).toString()
455
399
  }
456
400
  });
457
401
  }
@@ -477,7 +421,7 @@ export const makeChatsSocket = (config) => {
477
421
  const { patches, hasMorePatches, snapshot } = decoded[name];
478
422
  try {
479
423
  if (snapshot) {
480
- const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getCachedAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot, logger);
424
+ const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getCachedAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
481
425
  states[name] = newState;
482
426
  Object.assign(globalMutationMap, mutationMap);
483
427
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
@@ -500,37 +444,19 @@ export const makeChatsSocket = (config) => {
500
444
  }
501
445
  }
502
446
  catch (error) {
447
+ // if retry attempts overshoot
448
+ // or key not found
449
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
450
+ error.output?.statusCode === 404 ||
451
+ error.name === 'TypeError';
452
+ logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
453
+ await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
454
+ // increment number of retries
503
455
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
504
- const logData = {
505
- name,
506
- attempt: attemptsMap[name],
507
- version: states[name].version,
508
- statusCode: error.output?.statusCode,
509
- errorType: error.name,
510
- error: error.stack
511
- };
512
- if (isMissingKeyError(error) && attemptsMap[name] >= MAX_SYNC_ATTEMPTS) {
513
- // WA Web treats missing keys as "Blocked" — park the collection
514
- // until the key arrives via APP_STATE_SYNC_KEY_SHARE.
515
- logger.warn(logData, `${name} blocked on missing key from v${states[name].version}, parking after ${attemptsMap[name]} attempts`);
516
- blockedCollections.add(name);
456
+ if (isIrrecoverableError) {
457
+ // stop retrying
517
458
  collectionsToHandle.delete(name);
518
459
  }
519
- else if (isMissingKeyError(error)) {
520
- // Retry with a snapshot which may use a different key.
521
- logger.info(logData, `${name} blocked on missing key from v${states[name].version}, retrying with snapshot`);
522
- forceSnapshotCollections.add(name);
523
- }
524
- else if (isAppStateSyncIrrecoverable(error, attemptsMap[name])) {
525
- logger.warn(logData, `failed to sync ${name} from v${states[name].version}, giving up`);
526
- collectionsToHandle.delete(name);
527
- }
528
- else {
529
- logger.info(logData, `failed to sync ${name} from v${states[name].version}, forcing snapshot retry`);
530
- // force a full snapshot on retry to recover from
531
- // corrupted local state (e.g. LTHash MAC mismatch)
532
- forceSnapshotCollections.add(name);
533
- }
534
460
  }
535
461
  }
536
462
  }
@@ -547,22 +473,7 @@ export const makeChatsSocket = (config) => {
547
473
  */
548
474
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
549
475
  const baseContent = [{ tag: 'picture', attrs: { type, query: 'url' } }];
550
- // WA Web only includes tctoken for user JIDs (not groups/newsletters)
551
- // and never for own profile pic (Chat model for self has no tcToken).
552
- // Including tctoken for own JID causes the server to never respond.
553
- const normalizedJid = jidNormalizedUser(jid);
554
- const isUserJid = isPnUser(normalizedJid) || isLidUser(normalizedJid);
555
- const me = authState.creds.me;
556
- const isSelf = me && (normalizedJid === jidNormalizedUser(me.id) || (me.lid && normalizedJid === jidNormalizedUser(me.lid)));
557
- let content = baseContent;
558
- if (serverProps.profilePicPrivacyToken && isUserJid && !isSelf) {
559
- content = await buildTcTokenFromJid({
560
- authState,
561
- jid: normalizedJid,
562
- baseContent,
563
- getLIDForPN
564
- });
565
- }
476
+ const tcTokenContent = await buildTcTokenFromJid({ authState, jid, baseContent });
566
477
  jid = jidNormalizedUser(jid);
567
478
  const result = await query({
568
479
  tag: 'iq',
@@ -572,7 +483,7 @@ export const makeChatsSocket = (config) => {
572
483
  type: 'get',
573
484
  xmlns: 'w:profile:picture'
574
485
  },
575
- content
486
+ content: tcTokenContent
576
487
  }, timeoutMs);
577
488
  const child = getBinaryNodeChild(result, 'picture');
578
489
  return child?.attrs?.url;
@@ -638,12 +549,7 @@ export const makeChatsSocket = (config) => {
638
549
  * @param tcToken token for subscription, use if present
639
550
  */
640
551
  const presenceSubscribe = async (toJid) => {
641
- // Only include tctoken for user JIDs — groups/newsletters don't use tctokens
642
- const normalizedToJid = jidNormalizedUser(toJid);
643
- const isUserJid = isPnUser(normalizedToJid) || isLidUser(normalizedToJid);
644
- const tcTokenContent = isUserJid
645
- ? await buildTcTokenFromJid({ authState, jid: normalizedToJid, getLIDForPN })
646
- : undefined;
552
+ const tcTokenContent = await buildTcTokenFromJid({ authState, jid: toJid });
647
553
  return sendNode({
648
554
  tag: 'presence',
649
555
  attrs: {
@@ -664,8 +570,7 @@ export const makeChatsSocket = (config) => {
664
570
  if (tag === 'presence') {
665
571
  presence = {
666
572
  lastKnownPresence: attrs.type === 'unavailable' ? 'unavailable' : 'available',
667
- lastSeen: attrs.last && attrs.last !== 'deny' ? +attrs.last : undefined,
668
- groupOnlineCount: attrs.count ? +attrs.count : undefined
573
+ lastSeen: attrs.last && attrs.last !== 'deny' ? +attrs.last : undefined
669
574
  };
670
575
  }
671
576
  else if (Array.isArray(content)) {
@@ -699,7 +604,7 @@ export const makeChatsSocket = (config) => {
699
604
  logger.debug({ patch: patchCreate }, 'applying app patch');
700
605
  await resyncAppState([name], false);
701
606
  const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
702
- initial = currentSyncVersion ? ensureLTHashStateVersion(currentSyncVersion) : newLTHashState();
607
+ initial = currentSyncVersion || newLTHashState();
703
608
  encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
704
609
  const { patch, state } = encodeResult;
705
610
  const node = {
@@ -745,21 +650,22 @@ export const makeChatsSocket = (config) => {
745
650
  }
746
651
  }
747
652
  };
748
- /** fetch AB props */
653
+ /** sending non-abt props may fix QR scan fail if server expects */
749
654
  const fetchProps = async () => {
655
+ //TODO: implement both protocol 1 and protocol 2 prop fetching, specially for abKey for WM
750
656
  const resultNode = await query({
751
657
  tag: 'iq',
752
658
  attrs: {
753
659
  to: S_WHATSAPP_NET,
754
- xmlns: 'abt',
660
+ xmlns: 'w',
755
661
  type: 'get'
756
662
  },
757
663
  content: [
758
664
  {
759
665
  tag: 'props',
760
666
  attrs: {
761
- protocol: '1',
762
- ...(authState?.creds?.lastPropHash ? { hash: authState.creds.lastPropHash } : {})
667
+ protocol: '2',
668
+ hash: authState?.creds?.lastPropHash || ''
763
669
  }
764
670
  }
765
671
  ]
@@ -774,20 +680,7 @@ export const makeChatsSocket = (config) => {
774
680
  }
775
681
  props = reduceBinaryNodeToDictionary(propsNode, 'prop');
776
682
  }
777
- // Extract protocol-relevant AB props (only the ones we need)
778
- const privacyTokenProp = props['10518'] ?? props['privacy_token_sending_on_all_1_on_1_messages'];
779
- if (privacyTokenProp !== undefined) {
780
- serverProps.privacyTokenOn1to1 = privacyTokenProp === 'true' || privacyTokenProp === '1';
781
- }
782
- const profilePicProp = props['9666'] ?? props['profile_scraping_privacy_token_in_photo_iq'];
783
- if (profilePicProp !== undefined) {
784
- serverProps.profilePicPrivacyToken = profilePicProp === 'true' || profilePicProp === '1';
785
- }
786
- const lidIssueProp = props['14303'] ?? props['lid_trusted_token_issue_to_lid'];
787
- if (lidIssueProp !== undefined) {
788
- serverProps.lidTrustedTokenIssueToLid = lidIssueProp === 'true' || lidIssueProp === '1';
789
- }
790
- logger.debug({ serverProps }, 'fetched props');
683
+ logger.debug('fetched props');
791
684
  return props;
792
685
  };
793
686
  /**
@@ -927,47 +820,6 @@ export const makeChatsSocket = (config) => {
927
820
  ? shouldSyncHistoryMessage(historyMsg) &&
928
821
  PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
929
822
  : false;
930
- if (historyMsg && shouldProcessHistoryMsg) {
931
- const syncType = historyMsg.syncType;
932
- // INITIAL_BOOTSTRAP — fire immediately, no progress check (same as WA Web K function)
933
- if (syncType === proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP &&
934
- !historySyncStatus.initialBootstrapComplete) {
935
- historySyncStatus.initialBootstrapComplete = true;
936
- ev.emit('messaging-history.status', {
937
- syncType,
938
- status: 'complete',
939
- explicit: true
940
- });
941
- }
942
- // RECENT with progress === 100 — explicit completion
943
- if (syncType === proto.HistorySync.HistorySyncType.RECENT &&
944
- historyMsg.progress === 100 &&
945
- !historySyncStatus.recentSyncComplete) {
946
- historySyncStatus.recentSyncComplete = true;
947
- clearTimeout(historySyncPausedTimeout);
948
- historySyncPausedTimeout = undefined;
949
- ev.emit('messaging-history.status', {
950
- syncType,
951
- status: 'complete',
952
- explicit: true
953
- });
954
- }
955
- // Reset 120s paused timeout on any RECENT chunk (like WA Web's handleChunkProgress)
956
- if (syncType === proto.HistorySync.HistorySyncType.RECENT && !historySyncStatus.recentSyncComplete) {
957
- clearTimeout(historySyncPausedTimeout);
958
- historySyncPausedTimeout = setTimeout(() => {
959
- if (!historySyncStatus.recentSyncComplete) {
960
- historySyncStatus.recentSyncComplete = true;
961
- ev.emit('messaging-history.status', {
962
- syncType: proto.HistorySync.HistorySyncType.RECENT,
963
- status: 'paused',
964
- explicit: false
965
- });
966
- }
967
- historySyncPausedTimeout = undefined;
968
- }, HISTORY_SYNC_PAUSED_TIMEOUT_MS);
969
- }
970
- }
971
823
  // State machine: decide on sync and flush
972
824
  if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
973
825
  if (awaitingSyncTimeout) {
@@ -987,8 +839,6 @@ export const makeChatsSocket = (config) => {
987
839
  }
988
840
  const doAppStateSync = async () => {
989
841
  if (syncState === SyncState.Syncing) {
990
- // All collections will be synced, so clear any blocked ones
991
- blockedCollections.clear();
992
842
  logger.info('Doing app state sync');
993
843
  await resyncAppState(ALL_WA_PATCH_NAMES, true);
994
844
  // Sync is complete, go online and flush everything
@@ -1048,11 +898,6 @@ export const makeChatsSocket = (config) => {
1048
898
  }
1049
899
  });
1050
900
  ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
1051
- if (connection === 'close') {
1052
- blockedCollections.clear();
1053
- clearTimeout(historySyncPausedTimeout);
1054
- historySyncPausedTimeout = undefined;
1055
- }
1056
901
  if (connection === 'open') {
1057
902
  if (fireInitQueries) {
1058
903
  executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
@@ -1062,10 +907,6 @@ export const makeChatsSocket = (config) => {
1062
907
  if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
1063
908
  return;
1064
909
  }
1065
- historySyncStatus.initialBootstrapComplete = false;
1066
- historySyncStatus.recentSyncComplete = false;
1067
- clearTimeout(historySyncPausedTimeout);
1068
- historySyncPausedTimeout = undefined;
1069
910
  syncState = SyncState.AwaitingInitialSync;
1070
911
  logger.info('Connection is now AwaitingInitialSync, buffering events');
1071
912
  ev.buffer();
@@ -1078,49 +919,19 @@ export const makeChatsSocket = (config) => {
1078
919
  setTimeout(() => ev.flush(), 0);
1079
920
  return;
1080
921
  }
1081
- // On reconnection (accountSyncCounter > 0), the server does not push
1082
- // history sync notifications — the device already has its data.
1083
- // Skip the 20s wait and go online immediately.
1084
- if (authState.creds.accountSyncCounter > 0) {
1085
- logger.info('Reconnection with existing sync data, skipping history sync wait. Transitioning to Online.');
1086
- syncState = SyncState.Online;
1087
- setTimeout(() => ev.flush(), 0);
1088
- return;
1089
- }
1090
- logger.info('First connection, awaiting history sync notification with a 20s timeout.');
922
+ logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
1091
923
  if (awaitingSyncTimeout) {
1092
924
  clearTimeout(awaitingSyncTimeout);
1093
925
  }
1094
926
  awaitingSyncTimeout = setTimeout(() => {
1095
927
  if (syncState === SyncState.AwaitingInitialSync) {
928
+ // TODO: investigate
1096
929
  logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
1097
930
  syncState = SyncState.Online;
1098
931
  ev.flush();
1099
- // Increment so subsequent reconnections skip the 20s wait.
1100
- // Late-arriving history is still processed via processMessage
1101
- // regardless of the state machine phase.
1102
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
1103
- ev.emit('creds.update', { accountSyncCounter });
1104
932
  }
1105
933
  }, 20000);
1106
934
  });
1107
- // When an app state sync key arrives (myAppStateKeyId is set) and there are
1108
- // collections blocked on a missing key, trigger a re-sync for just those collections.
1109
- // This mirrors WA Web's Blocked → retry-on-key-arrival behavior.
1110
- ev.on('creds.update', ({ myAppStateKeyId }) => {
1111
- if (!myAppStateKeyId || blockedCollections.size === 0) {
1112
- return;
1113
- }
1114
- // If we're in the middle of a full sync, doAppStateSync handles all collections
1115
- if (syncState === SyncState.Syncing) {
1116
- blockedCollections.clear();
1117
- return;
1118
- }
1119
- const collections = [...blockedCollections];
1120
- blockedCollections.clear();
1121
- logger.info({ collections }, 'app state sync key arrived, re-syncing blocked collections');
1122
- resyncAppState(collections, false).catch(error => onUnexpectedError(error, 'blocked collections resync'));
1123
- });
1124
935
  ev.on('lid-mapping.update', async ({ lid, pn }) => {
1125
936
  try {
1126
937
  await signalRepository.lidMapping.storeLIDPNMappings([{ lid, pn }]);
@@ -1129,20 +940,8 @@ export const makeChatsSocket = (config) => {
1129
940
  logger.warn({ lid, pn, error }, 'Failed to store LID-PN mapping');
1130
941
  }
1131
942
  });
1132
- registerSocketEndHandler(() => {
1133
- if (awaitingSyncTimeout) {
1134
- clearTimeout(awaitingSyncTimeout);
1135
- awaitingSyncTimeout = undefined;
1136
- }
1137
- if (!config.placeholderResendCache && placeholderResendCache.close) {
1138
- placeholderResendCache.close();
1139
- }
1140
- syncState = SyncState.Connecting;
1141
- privacySettings = undefined;
1142
- });
1143
943
  return {
1144
944
  ...sock,
1145
- serverProps,
1146
945
  createCallLink,
1147
946
  getBotListV2,
1148
947
  messageMutex,
@@ -1179,7 +978,6 @@ export const makeChatsSocket = (config) => {
1179
978
  cleanDirtyBits,
1180
979
  addOrEditContact,
1181
980
  removeContact,
1182
- placeholderResendCache,
1183
981
  addLabel,
1184
982
  addChatLabel,
1185
983
  removeChatLabel,