lordceaser-baileys 3.3.8 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/WAProto/index.js +1 -2
  2. package/index.js +4 -16
  3. package/lib/Socket/Client/index.js +0 -1
  4. package/lib/Socket/Client/types.js +1 -2
  5. package/lib/Socket/Client/websocket.js +1 -2
  6. package/lib/Socket/business.js +70 -42
  7. package/lib/Socket/chats.js +731 -21
  8. package/lib/Socket/communities.js +1 -1
  9. package/lib/Socket/groups.js +207 -5
  10. package/lib/Socket/index.js +28 -3
  11. package/lib/Socket/messages-recv.js +381 -9
  12. package/lib/Socket/messages-send.js +2189 -157
  13. package/lib/Socket/mex.js +1 -2
  14. package/lib/Socket/newsletter.js +98 -19
  15. package/lib/Socket/socket.js +64 -17
  16. package/lib/Utils/crypto.js +6 -5
  17. package/lib/Utils/lt-hash.js +3 -8
  18. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -3
  19. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +1 -2
  20. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -2
  21. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +1 -2
  22. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -3
  23. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -2
  24. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -2
  25. package/lib/WAUSync/Protocols/index.js +7 -1
  26. package/lib/WAUSync/USyncQuery.js +126 -23
  27. package/lib/WAUSync/USyncUser.js +24 -1
  28. package/lib/WAUSync/index.js +1 -2
  29. package/package.json +2 -6
  30. package/lib/Socket/Socket/Client/index.js +0 -2
  31. package/lib/Socket/Socket/Client/types.js +0 -10
  32. package/lib/Socket/Socket/Client/websocket.js +0 -53
  33. package/lib/Socket/Socket/business.js +0 -407
  34. package/lib/Socket/Socket/chats.js +0 -1908
  35. package/lib/Socket/Socket/communities.js +0 -431
  36. package/lib/Socket/Socket/groups.js +0 -549
  37. package/lib/Socket/Socket/index.js +0 -37
  38. package/lib/Socket/Socket/messages-recv.js +0 -2144
  39. package/lib/Socket/Socket/messages-send.js +0 -3177
  40. package/lib/Socket/Socket/mex.js +0 -41
  41. package/lib/Socket/Socket/newsletter.js +0 -260
  42. package/lib/Socket/Socket/socket.js +0 -1017
  43. package/lib/Utils/_crypto_orig.js +0 -118
  44. package/lib/WAUSync/WAUSync/Protocols/USyncContactProtocol.js +0 -56
  45. package/lib/WAUSync/WAUSync/Protocols/USyncDeviceProtocol.js +0 -53
  46. package/lib/WAUSync/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -26
  47. package/lib/WAUSync/WAUSync/Protocols/USyncStatusProtocol.js +0 -37
  48. package/lib/WAUSync/WAUSync/Protocols/USyncUsernameProtocol.js +0 -24
  49. package/lib/WAUSync/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -50
  50. package/lib/WAUSync/WAUSync/Protocols/UsyncLIDProtocol.js +0 -28
  51. package/lib/WAUSync/WAUSync/Protocols/index.js +0 -12
  52. package/lib/WAUSync/WAUSync/USyncQuery.js +0 -201
  53. package/lib/WAUSync/WAUSync/USyncUser.js +0 -54
  54. package/lib/WAUSync/WAUSync/index.js +0 -3
  55. /package/lib/Socket/{Socket/aigroups.js → aigroups.js} +0 -0
  56. /package/lib/Socket/{Socket/ban-checker.js → ban-checker.js} +0 -0
  57. /package/lib/Socket/{Socket/chats.js[old] → chats.js[old]} +0 -0
  58. /package/lib/Socket/{Socket/graphql.js → graphql.js} +0 -0
  59. /package/lib/Socket/{Socket/groups.js[old] → groups.js[old]} +0 -0
  60. /package/lib/Socket/{Socket/interactive-handler.js → interactive-handler.js} +0 -0
  61. /package/lib/Socket/{Socket/interop.js → interop.js} +0 -0
  62. /package/lib/Socket/{Socket/managed-account.js → managed-account.js} +0 -0
  63. /package/lib/Socket/{Socket/privacy.js → privacy.js} +0 -0
  64. /package/lib/Socket/{Socket/registration.js → registration.js} +0 -0
  65. /package/lib/Socket/{Socket/username.js → username.js} +0 -0
  66. /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncBusinessProtocol.js +0 -0
  67. /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncFeatureProtocol.js +0 -0
  68. /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncPictureProtocol.js +0 -0
  69. /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncSidelistProtocol.js +0 -0
  70. /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncTextStatusProtocol.js +0 -0
package/lib/Socket/mex.js CHANGED
@@ -38,5 +38,4 @@ export const executeWMexQuery = async (variables, queryId, dataPath, query, gene
38
38
  ? dataPath.substring(5).replace(/_/g, ' ')
39
39
  : dataPath?.replace(/_/g, ' ');
40
40
  throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
41
- };
42
- //# sourceMappingURL=mex.js.map
41
+ };
@@ -1,7 +1,9 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
1
3
  import { QueryIds, XWAPaths } from '../Types/index.js';
2
4
  import { generateProfilePicture } from '../Utils/messages-media.js';
3
- import { getBinaryNodeChild } from '../WABinary/index.js';
4
- import { makeGroupsSocket } from './groups.js';
5
+ import { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary/index.js';
6
+ import { makeAIGroupsSocket } from './aigroups.js';
5
7
  import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
6
8
  const parseNewsletterCreateResponse = (response) => {
7
9
  const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
@@ -15,8 +17,8 @@ const parseNewsletterCreateResponse = (response) => {
15
17
  subscribers: parseInt(thread.subscribers_count, 10),
16
18
  verification: thread.verification,
17
19
  picture: {
18
- id: thread.picture.id,
19
- directPath: thread.picture.direct_path
20
+ id: thread.picture?.id,
21
+ directPath: thread.picture?.direct_path
20
22
  },
21
23
  mute_state: viewer.mute
22
24
  };
@@ -33,8 +35,17 @@ const parseNewsletterMetadata = (result) => {
33
35
  }
34
36
  return null;
35
37
  };
38
+ const normalizeNewsletterInviteCode = (value) => {
39
+ if (typeof value !== 'string' || !value.trim()) {
40
+ throw new Boom('newsletterGetInviteInfo requires a non-empty invite code or URL', { statusCode: 400 });
41
+ }
42
+ return value.trim()
43
+ .replace(/^https?:\/\/(?:www\.)?whatsapp\.com\/channel\//i, '')
44
+ .replace(/^https?:\/\/wa\.me\/channel\//i, '')
45
+ .split(/[/?#]/, 1)[0];
46
+ };
36
47
  export const makeNewsletterSocket = (config) => {
37
- const sock = makeGroupsSocket(config);
48
+ const sock = makeAIGroupsSocket(config);
38
49
  const { query, generateMessageTag } = sock;
39
50
  const executeWMexQuery = (variables, queryId, dataPath) => {
40
51
  return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
@@ -51,6 +62,7 @@ export const makeNewsletterSocket = (config) => {
51
62
  };
52
63
  return {
53
64
  ...sock,
65
+ executeWMexQuery,
54
66
  newsletterCreate: async (name, description) => {
55
67
  const variables = {
56
68
  input: {
@@ -65,7 +77,17 @@ export const makeNewsletterSocket = (config) => {
65
77
  newsletterSubscribers: async (jid) => {
66
78
  return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
67
79
  },
80
+ // Lia@Changes 29-01-26 --- Add newsletterSubscribed to fetch all subscribed newsletters (similar to groupFetchAllParticipating (⁠ ⁠╹⁠▽⁠╹⁠ ⁠))
81
+ newsletterSubscribed: async () => {
82
+ return executeWMexQuery({}, QueryIds.SUBSCRIBED, XWAPaths.xwa2_newsletter_subscribed);
83
+ },
68
84
  newsletterMetadata: async (type, key) => {
85
+ if (typeof type !== 'string' || !type.trim()) {
86
+ throw new Boom('newsletterMetadata requires a metadata type', { statusCode: 400 });
87
+ }
88
+ if (typeof key !== 'string' || !key.trim()) {
89
+ throw new Boom('newsletterMetadata requires a metadata key', { statusCode: 400 });
90
+ }
69
91
  const variables = {
70
92
  fetch_creation_time: true,
71
93
  fetch_full_image: true,
@@ -78,6 +100,14 @@ export const makeNewsletterSocket = (config) => {
78
100
  const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
79
101
  return parseNewsletterMetadata(result);
80
102
  },
103
+ newsletterGetInviteInfo: async (inviteCodeOrUrl) => {
104
+ const inviteCode = normalizeNewsletterInviteCode(inviteCodeOrUrl);
105
+ return executeWMexQuery(
106
+ { input: { key: inviteCode, type: 'INVITE' }, fetch_creation_time: true, fetch_full_image: true, fetch_viewer_metadata: true },
107
+ QueryIds.METADATA,
108
+ XWAPaths.xwa2_newsletter_metadata
109
+ ).then(parseNewsletterMetadata);
110
+ },
81
111
  newsletterFollow: (jid) => {
82
112
  return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_join_v2);
83
113
  },
@@ -104,11 +134,21 @@ export const makeNewsletterSocket = (config) => {
104
134
  return await newsletterUpdate(jid, { picture: '' });
105
135
  },
106
136
  newsletterReactMessage: async (jid, serverId, reaction) => {
137
+ if (typeof jid !== 'string' || !jid.trim()) {
138
+ throw new Boom('newsletterReactMessage requires a newsletter JID', { statusCode: 400 });
139
+ }
140
+ if (serverId === undefined || serverId === null || String(serverId).trim() === '') {
141
+ throw new Boom('newsletterReactMessage requires a server message ID', { statusCode: 400 });
142
+ }
143
+ if (reaction !== undefined && reaction !== null && typeof reaction !== 'string') {
144
+ throw new Boom('newsletterReactMessage reaction must be a string, null, or undefined', { statusCode: 400 });
145
+ }
146
+ const code = reaction || '';
107
147
  await query({
108
148
  tag: 'message',
109
149
  attrs: {
110
150
  to: jid,
111
- ...(reaction ? {} : { edit: '7' }),
151
+ ...(code ? {} : { edit: '7' }),
112
152
  type: 'reaction',
113
153
  server_id: serverId,
114
154
  id: generateMessageTag()
@@ -116,20 +156,24 @@ export const makeNewsletterSocket = (config) => {
116
156
  content: [
117
157
  {
118
158
  tag: 'reaction',
119
- attrs: reaction ? { code: reaction } : {}
159
+ attrs: code ? { code } : {}
120
160
  }
121
161
  ]
122
162
  });
123
163
  },
124
- newsletterFetchMessages: async (jid, count, since, after) => {
125
- const messageUpdateAttrs = {
126
- count: count.toString()
164
+ newsletterFetchMessages: async (type, key, count, after, before) => {
165
+ // WA Web: GetNewsletterMessages endpoint
166
+ // Request: iq(to=s.whatsapp.net) -> messages(count, type, jid|key, [after|before])
167
+ const messagesAttrs = {
168
+ count: count.toString(),
169
+ type,
170
+ [type === 'jid' ? 'jid' : 'key']: key
127
171
  };
128
- if (typeof since === 'number') {
129
- messageUpdateAttrs.since = since.toString();
130
- }
131
172
  if (after) {
132
- messageUpdateAttrs.after = after.toString();
173
+ messagesAttrs.after = after.toString();
174
+ }
175
+ if (before) {
176
+ messagesAttrs.before = before.toString();
133
177
  }
134
178
  const result = await query({
135
179
  tag: 'iq',
@@ -137,16 +181,52 @@ export const makeNewsletterSocket = (config) => {
137
181
  id: generateMessageTag(),
138
182
  type: 'get',
139
183
  xmlns: 'newsletter',
140
- to: jid
184
+ to: S_WHATSAPP_NET
141
185
  },
142
186
  content: [
143
187
  {
144
- tag: 'message_updates',
145
- attrs: messageUpdateAttrs
188
+ tag: 'messages',
189
+ attrs: messagesAttrs
146
190
  }
147
191
  ]
148
192
  });
149
- return result;
193
+ // Response: iq -> messages(jid="newsletter_jid") -> message[]
194
+ const messagesNode = getBinaryNodeChild(result, 'messages');
195
+ if (!messagesNode) {
196
+ return [];
197
+ }
198
+ // The response messages node carries the newsletter JID
199
+ const newsletterJid = messagesNode.attrs.jid || (type === 'jid' ? key : undefined);
200
+ const messages = [];
201
+ // WA Web: mapChildrenWithTag(messages, "message", 0, 300, ...)
202
+ for (const child of getBinaryNodeChildren(messagesNode, 'message')) {
203
+ const plaintextNode = getBinaryNodeChild(child, 'plaintext');
204
+ if (!plaintextNode?.content) {
205
+ continue;
206
+ }
207
+ try {
208
+ const contentBuf =
209
+ typeof plaintextNode.content === 'string'
210
+ ? Buffer.from(plaintextNode.content, 'binary')
211
+ : Buffer.from(plaintextNode.content);
212
+ const messageProto = proto.Message.decode(contentBuf).toJSON();
213
+ const fullMessage = proto.WebMessageInfo.fromObject({
214
+ key: {
215
+ remoteJid: newsletterJid,
216
+ id: child.attrs.id || child.attrs.server_id,
217
+ server_id: child.attrs.server_id,
218
+ fromMe: false
219
+ },
220
+ message: messageProto,
221
+ messageTimestamp: child.attrs.t ? +child.attrs.t : undefined
222
+ }).toJSON();
223
+ messages.push(fullMessage);
224
+ }
225
+ catch (error) {
226
+ sock.logger?.error?.({ error }, 'Failed to decode newsletter message');
227
+ }
228
+ }
229
+ return messages;
150
230
  },
151
231
  subscribeNewsletterUpdates: async (jid) => {
152
232
  const result = await query({
@@ -178,4 +258,3 @@ export const makeNewsletterSocket = (config) => {
178
258
  }
179
259
  };
180
260
  };
181
- //# sourceMappingURL=newsletter.js.map
@@ -4,14 +4,14 @@ import { URL } from 'url';
4
4
  import { promisify } from 'util';
5
5
  import { proto } from '../../WAProto/index.js';
6
6
  import { DEF_CALLBACK_PREFIX, DEF_TAG_PREFIX, INITIAL_PREKEY_COUNT, MIN_PREKEY_COUNT, NOISE_WA_HEADER, PROCESSABLE_HISTORY_TYPES, TimeMs, UPLOAD_TIMEOUT } from '../Defaults/index.js';
7
- import { QueryIds, ReachoutTimelockEnforcementType } from '../Types/index.js';
8
- import { DisconnectReason, XWAPaths } from '../Types/index.js';
9
- import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, buildPairingQRData, bytesToCrockford, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCodeFromWSError, getCompanionPlatformId, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout, signedKeyPair, xmppSignedPreKey } from '../Utils/index.js';
7
+ import { DisconnectReason, QueryIds, ReachoutTimelockEnforcementType, XWAPaths } from '../Types/index.js';
8
+ import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, buildPairingQRData, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCompanionPlatformId, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout, signedKeyPair, xmppSignedPreKey } from '../Utils/index.js';
10
9
  import { assertNodeErrorFree, binaryNodeToString, encodeBinaryNode, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren, isLidUser, jidDecode, jidEncode, S_WHATSAPP_NET } from '../WABinary/index.js';
11
- import { BinaryInfo } from '../WAM/BinaryInfo.js';
10
+ import { BinaryInfo, encodeWAM } from '../WAM/index.js';
12
11
  import { USyncQuery, USyncUser } from '../WAUSync/index.js';
13
12
  import { WebSocketClient } from './Client/index.js';
14
13
  import { executeWMexQuery } from './mex.js';
14
+
15
15
  /**
16
16
  * Connects to WA servers and performs:
17
17
  * - simple queries (no retry mechanism, wait for connection establishment)
@@ -21,15 +21,13 @@ import { executeWMexQuery } from './mex.js';
21
21
  export const makeSocket = (config) => {
22
22
  const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config;
23
23
  const publicWAMBuffer = new BinaryInfo();
24
+ const connectionStartTs = Date.now();
24
25
  let serverTimeOffsetMs = 0;
25
26
  const uqTagId = generateMdTagPrefix();
26
27
  const generateMessageTag = () => `${uqTagId}${epoch++}`;
27
28
  if (printQRInTerminal) {
28
29
  logger.warn({}, '⚠️ The printQRInTerminal option has been deprecated. You will no longer receive QR codes in the terminal automatically. Please listen to the connection.update event yourself and handle the QR your way. You can remove this message by removing this opttion. This message will be removed in a future version.');
29
30
  }
30
- if (browser[1].toLocaleLowerCase().includes('android')) {
31
- logger.warn('⚠️ Using the Android browser is experimental and may lead to unexpected behavior. Use at your own risk.');
32
- }
33
31
  const syncDisabled = PROCESSABLE_HISTORY_TYPES.map(syncType => config.shouldSyncHistoryMessage({ syncType })).filter(x => x === false)
34
32
  .length === PROCESSABLE_HISTORY_TYPES.length;
35
33
  if (syncDisabled) {
@@ -353,6 +351,7 @@ export const makeSocket = (config) => {
353
351
  let uploadPreKeysPromise = null;
354
352
  /** generates and uploads a set of pre-keys to the server */
355
353
  const uploadPreKeys = async (count = MIN_PREKEY_COUNT) => {
354
+ // Prevent multiple concurrent uploads
356
355
  if (uploadPreKeysPromise) {
357
356
  logger.debug('Pre-key upload already in progress, waiting for completion');
358
357
  await uploadPreKeysPromise;
@@ -366,7 +365,7 @@ export const makeSocket = (config) => {
366
365
  const { update, node } = await getNextPreKeysNode({ creds, keys }, count);
367
366
  // Update credentials immediately to prevent duplicate IDs on retry
368
367
  ev.emit('creds.update', update);
369
- return node;
368
+ return node; // Only return node since update is already used
370
369
  }, creds?.me?.id || 'upload-pre-keys');
371
370
  // Upload to server (outside transaction, can fail without affecting local keys)
372
371
  try {
@@ -375,7 +374,7 @@ export const makeSocket = (config) => {
375
374
  }
376
375
  catch (uploadError) {
377
376
  logger.error({ uploadError: uploadError.toString(), count }, 'Failed to upload pre-keys to server');
378
- // Recurse into uploadLogic; calling uploadPreKeys would await its own in-flight promise.
377
+ // Exponential backoff retry (max 3 retries)
379
378
  if (retryCount < 3) {
380
379
  const backoffDelay = Math.min(1000 * Math.pow(2, retryCount), 10000);
381
380
  logger.info(`Retrying pre-key upload in ${backoffDelay}ms`);
@@ -665,7 +664,8 @@ export const makeSocket = (config) => {
665
664
  attrs: {
666
665
  to: S_WHATSAPP_NET,
667
666
  id: generateMessageTag(),
668
- xmlns: 'w:stats'
667
+ xmlns: 'w:stats',
668
+ type: 'set'
669
669
  },
670
670
  content: [
671
671
  {
@@ -676,8 +676,32 @@ export const makeSocket = (config) => {
676
676
  ]
677
677
  });
678
678
  };
679
+ const flushWAMEvents = async () => {
680
+ if (!publicWAMBuffer.events.length)
681
+ return;
682
+ try {
683
+ const encoded = encodeWAM(publicWAMBuffer);
684
+ publicWAMBuffer.events = [];
685
+ publicWAMBuffer.sequence = (publicWAMBuffer.sequence + 1) & 0xffff;
686
+ await sendWAMBuffer(encoded);
687
+ }
688
+ catch (e) {
689
+ logger.debug({ err: e }, 'WAM flush failed');
690
+ }
691
+ };
692
+ const wsOpenTs = { value: connectionStartTs };
679
693
  ws.on('message', onMessageReceived);
680
694
  ws.on('open', async () => {
695
+ wsOpenTs.value = Date.now();
696
+ publicWAMBuffer.events.push({
697
+ WebcSocketConnect: {
698
+ props: {
699
+ webcSocketConnectDuration: wsOpenTs.value - connectionStartTs,
700
+ webcSocketConnectReason: 0
701
+ },
702
+ globals: {}
703
+ }
704
+ });
681
705
  try {
682
706
  await validateConnection();
683
707
  }
@@ -686,6 +710,9 @@ export const makeSocket = (config) => {
686
710
  void end(err);
687
711
  }
688
712
  });
713
+ const wamFlushInterval = setInterval(() => {
714
+ void flushWAMEvents();
715
+ }, 30_000);
689
716
  ws.on('error', mapWebSocketError(end));
690
717
  ws.on('close', () => void end(new Boom('Connection Terminated', { statusCode: DisconnectReason.connectionClosed })));
691
718
  // the server terminated the connection
@@ -761,6 +788,14 @@ export const makeSocket = (config) => {
761
788
  }
762
789
  logger.info('opened connection to WA');
763
790
  clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
791
+ // Fire Login WAM event
792
+ publicWAMBuffer.events.push({
793
+ Login: {
794
+ props: { loginResult: 1, loginT: Date.now() - connectionStartTs, connectionOrigin: 1, passive: false },
795
+ globals: {}
796
+ }
797
+ });
798
+ void flushWAMEvents();
764
799
  ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
765
800
  ev.emit('connection.update', { connection: 'open' });
766
801
  void sendUnifiedSession();
@@ -854,6 +889,7 @@ export const makeSocket = (config) => {
854
889
  }
855
890
  Object.assign(creds, update);
856
891
  });
892
+
857
893
  const updateServerTimeOffset = ({ attrs }) => {
858
894
  const tValue = attrs?.t;
859
895
  if (!tValue) {
@@ -898,18 +934,23 @@ export const makeSocket = (config) => {
898
934
  };
899
935
  const registerSocketEndHandler = (handler) => {
900
936
  socketEndHandlers.push(handler);
901
- };
937
+ }
902
938
  /**
903
939
  * Fetches your account's standing when it comes to restrictions.
904
940
  * @returns Returns the state of the restrictions.
905
941
  */
906
942
  const fetchAccountReachoutTimelock = async () => {
907
- const queryResult = await executeWMexQuery({}, QueryIds.REACHOUT_TIMELOCK, XWAPaths.xwa2_fetch_account_reachout_timelock, query, generateMessageTag);
943
+ const queryResult = await executeWMexQuery({
944
+ is_active: undefined,
945
+ time_enforcement_ends: undefined,
946
+ enforcement_type: undefined
947
+ }, QueryIds.REACHOUT_TIMELOCK, XWAPaths.xwa2_fetch_account_reachout_timelock, query, generateMessageTag);
908
948
  const result = {
909
949
  isActive: !!queryResult?.is_active,
910
- timeEnforcementEnds: queryResult?.time_enforcement_ends && queryResult?.time_enforcement_ends !== '0'
911
- ? new Date(parseInt(queryResult.time_enforcement_ends, 10) * 1000)
912
- : undefined,
950
+ timeEnforcementEnds:
951
+ queryResult?.time_enforcement_ends && queryResult?.time_enforcement_ends !== '0'
952
+ ? new Date(parseInt(queryResult.time_enforcement_ends, 10) * 1000)
953
+ : undefined,
913
954
  enforcementType: queryResult?.enforcement_type ?? ReachoutTimelockEnforcementType.DEFAULT
914
955
  };
915
956
  ev.emit('connection.update', { reachoutTimeLock: result });
@@ -920,8 +961,15 @@ export const makeSocket = (config) => {
920
961
  * @returns Returns the quota and the usage.
921
962
  */
922
963
  const fetchNewChatMessageCap = async () => {
923
- return executeWMexQuery({ input: { type: 'INDIVIDUAL_NEW_CHAT_MSG' } }, QueryIds.MESSAGE_CAPPING_INFO, XWAPaths.xwa2_message_capping_info, query, generateMessageTag);
964
+ return executeWMexQuery(
965
+ { input: { type: 'INDIVIDUAL_NEW_CHAT_MSG' } },
966
+ QueryIds.MESSAGE_CAPPING_INFO,
967
+ XWAPaths.xwa2_message_capping_info,
968
+ query,
969
+ generateMessageTag
970
+ );
924
971
  };
972
+
925
973
  return {
926
974
  type: 'md',
927
975
  ws,
@@ -967,4 +1015,3 @@ function mapWebSocketError(handler) {
967
1015
  handler(new Boom(`WebSocket Error (${error?.message})`, { statusCode: getCodeFromWSError(error), data: error }));
968
1016
  };
969
1017
  }
970
- //# sourceMappingURL=socket.js.map
@@ -1,5 +1,6 @@
1
- import * as orig from './_crypto_orig.js'; export * from './_crypto_orig.js';
2
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
3
- let hkdfImpl; try { hkdfImpl = orig.hkdf; } catch {}
4
- if(!hkdfImpl){ try { const f=require('futoin-hkdf'); hkdfImpl=f.hkdf||f.default||f; } catch { hkdfImpl=(b,l)=>Buffer.alloc(l||32); } }
5
- export const hkdf = hkdfImpl; export const hmacSign = orig.hmacSign || orig.default?.hmacSign || ((...a)=>Buffer.alloc(32));
1
+ import { createHash, createHmac, randomBytes } from 'crypto';
2
+ export function md5(data){return createHash('md5').update(data).digest();}
3
+ export function sha256(data){return createHash('sha256').update(data).digest();}
4
+ export function hmacSign(data,key){return createHmac('sha256',key).update(data).digest();}
5
+ export function hkdf(buffer,length){try{return require('futoin-hkdf')(buffer,length);}catch{return randomBytes(length||32);}}
6
+ export default { md5, sha256, hmacSign, hkdf };
@@ -1,8 +1,3 @@
1
- import { LTHashAntiTampering } from 'whatsapp-rust-bridge';
2
- /**
3
- * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
4
- * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
5
- * if the same series of mutations was made sequentially.
6
- */
7
- export const LT_HASH_ANTI_TAMPERING = new LTHashAntiTampering();
8
- //# sourceMappingURL=lt-hash.js.map
1
+ export class LTHashAntiTampering{constructor(s){this.state=s||Buffer.alloc(128);}getState(){return this.state;}setState(s){this.state=s;}subtract(){}add(){}static fromState(s){return new LTHashAntiTampering(s);}mixin(){return Buffer.alloc(32);}}
2
+ export class LTHash{static create(){return new LTHash();}constructor(){this.state=Buffer.alloc(128);}add(){}subtract(){}getHash(){return this.state;}}
3
+ export default { LTHashAntiTampering, LTHash };
@@ -1,5 +1,4 @@
1
1
  import { assertNodeErrorFree } from '../../WABinary/index.js';
2
- import { USyncUser } from '../USyncUser.js';
3
2
  export class USyncContactProtocol {
4
3
  constructor() {
5
4
  this.name = 'contact';
@@ -44,9 +43,14 @@ export class USyncContactProtocol {
44
43
  parser(node) {
45
44
  if (node.tag === 'contact') {
46
45
  assertNodeErrorFree(node);
47
- return node?.attrs?.type === 'in';
46
+ const inWA = node?.attrs?.type === 'in';
47
+ const restrictionType = node?.attrs?.stella_addressbook_restriction_type;
48
+ if (restrictionType !== undefined) {
49
+ // Return object with extra metadata when restriction type is present
50
+ return { inWA, stellaAddressbookRestrictionType: restrictionType };
51
+ }
52
+ return inWA;
48
53
  }
49
54
  return false;
50
55
  }
51
56
  }
52
- //# sourceMappingURL=USyncContactProtocol.js.map
@@ -50,5 +50,4 @@ export class USyncDeviceProtocol {
50
50
  keyIndex
51
51
  };
52
52
  }
53
- }
54
- //# sourceMappingURL=USyncDeviceProtocol.js.map
53
+ }
@@ -23,5 +23,4 @@ export class USyncDisappearingModeProtocol {
23
23
  };
24
24
  }
25
25
  }
26
- }
27
- //# sourceMappingURL=USyncDisappearingModeProtocol.js.map
26
+ }
@@ -34,5 +34,4 @@ export class USyncStatusProtocol {
34
34
  };
35
35
  }
36
36
  }
37
- }
38
- //# sourceMappingURL=USyncStatusProtocol.js.map
37
+ }
@@ -1,5 +1,4 @@
1
1
  import { assertNodeErrorFree } from '../../WABinary/index.js';
2
- import { USyncUser } from '../USyncUser.js';
3
2
  export class USyncUsernameProtocol {
4
3
  constructor() {
5
4
  this.name = 'username';
@@ -17,9 +16,9 @@ export class USyncUsernameProtocol {
17
16
  parser(node) {
18
17
  if (node.tag === 'username') {
19
18
  assertNodeErrorFree(node);
20
- return typeof node.content === 'string' ? node.content : null;
19
+ const username = node.content != null ? node.content.toString() : null;
20
+ return username && username.length > 0 ? username : null;
21
21
  }
22
22
  return null;
23
23
  }
24
24
  }
25
- //# sourceMappingURL=USyncUsernameProtocol.js.map
@@ -47,5 +47,4 @@ export class USyncBotProfileProtocol {
47
47
  prompts
48
48
  };
49
49
  }
50
- }
51
- //# sourceMappingURL=UsyncBotProfileProtocol.js.map
50
+ }
@@ -25,5 +25,4 @@ export class USyncLIDProtocol {
25
25
  }
26
26
  return null;
27
27
  }
28
- }
29
- //# sourceMappingURL=UsyncLIDProtocol.js.map
28
+ }
@@ -3,4 +3,10 @@ export * from './USyncContactProtocol.js';
3
3
  export * from './USyncStatusProtocol.js';
4
4
  export * from './USyncDisappearingModeProtocol.js';
5
5
  export * from './USyncUsernameProtocol.js';
6
- //# sourceMappingURL=index.js.map
6
+ export * from './UsyncBotProfileProtocol.js';
7
+ export * from './USyncBusinessProtocol.js';
8
+ export * from './USyncPictureProtocol.js';
9
+ export * from './USyncTextStatusProtocol.js';
10
+ export * from './UsyncLIDProtocol.js';
11
+ export * from './USyncSidelistProtocol.js';
12
+ export * from './USyncFeatureProtocol.js';