@hbmodsofc/baileys 2.5.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/LICENSE +1 -1
  2. package/README.MD +220 -1198
  3. package/WAProto/GenerateStatics.sh +4 -0
  4. package/WAProto/WAProto.proto +5619 -0
  5. package/engine-requirements.js +1 -1
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.js +97 -122
  8. package/lib/Defaults/phonenumber_mcc.json +223 -0
  9. package/lib/Socket/Client/index.js +2 -3
  10. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
  11. package/lib/Socket/business.js +8 -2
  12. package/lib/Socket/chats.js +455 -288
  13. package/lib/Socket/communities.js +441 -0
  14. package/lib/Socket/groups.js +38 -23
  15. package/lib/Socket/hbmods.js +374 -406
  16. package/lib/Socket/index.js +43 -11
  17. package/lib/Socket/messages-recv.js +24 -69
  18. package/lib/Socket/messages-send.js +391 -419
  19. package/lib/Socket/newsletter.js +104 -190
  20. package/lib/Socket/socket.js +40 -54
  21. package/lib/Store/index.js +1 -3
  22. package/lib/Store/make-in-memory-store.js +27 -15
  23. package/lib/Store/make-ordered-dictionary.js +2 -2
  24. package/lib/Types/Label.js +1 -1
  25. package/lib/Types/LabelAssociation.js +1 -1
  26. package/lib/Types/Message.js +0 -2
  27. package/lib/Types/Newsletter.js +18 -38
  28. package/lib/Types/index.js +2 -2
  29. package/lib/Utils/async-iterable.js +41 -0
  30. package/lib/Utils/audioToBuffer.js +29 -0
  31. package/lib/Utils/auth-utils.js +6 -13
  32. package/lib/Utils/baileys-event-stream.js +1 -1
  33. package/lib/Utils/browser-utils.js +35 -0
  34. package/lib/Utils/business.js +2 -2
  35. package/lib/Utils/chat-utils.js +36 -35
  36. package/lib/Utils/crypto.js +71 -29
  37. package/lib/Utils/decode-wa-message.js +65 -56
  38. package/lib/Utils/event-buffer.js +13 -9
  39. package/lib/Utils/generics.js +88 -84
  40. package/lib/Utils/history.js +4 -6
  41. package/lib/Utils/index.js +3 -0
  42. package/lib/Utils/link-preview.js +34 -1
  43. package/lib/Utils/lt-hash.js +6 -6
  44. package/lib/Utils/message-retry-manager.js +128 -0
  45. package/lib/Utils/messages-media.js +340 -246
  46. package/lib/Utils/messages.js +329 -192
  47. package/lib/Utils/noise-handler.js +18 -23
  48. package/lib/Utils/process-message.js +108 -25
  49. package/lib/Utils/resolveJid.js +52 -0
  50. package/lib/Utils/signal.js +26 -26
  51. package/lib/Utils/streamToBuffer.js +15 -0
  52. package/lib/Utils/use-multi-file-auth-state.js +3 -0
  53. package/lib/Utils/validate-connection.js +1 -3
  54. package/lib/WABinary/constants.js +1276 -13
  55. package/lib/WABinary/decode.js +26 -13
  56. package/lib/WABinary/encode.js +137 -152
  57. package/lib/WABinary/generic-utils.js +37 -125
  58. package/lib/WABinary/jid-utils.js +28 -5
  59. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  60. package/lib/index.js +2 -1
  61. package/package.json +112 -104
  62. package/lib/Defaults/index.d.ts +0 -53
  63. package/lib/Defaults/phonenumber-mcc.json +0 -223
  64. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  65. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  66. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  67. package/lib/Signal/Group/index.d.ts +0 -11
  68. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  69. package/lib/Signal/Group/queue-job.d.ts +0 -1
  70. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  71. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  72. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  73. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  74. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  75. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  76. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  77. package/lib/Signal/libsignal.d.ts +0 -3
  78. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  79. package/lib/Socket/Client/index.d.ts +0 -3
  80. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  81. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  82. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  83. package/lib/Socket/business.d.ts +0 -171
  84. package/lib/Socket/chats.d.ts +0 -267
  85. package/lib/Socket/groups.d.ts +0 -115
  86. package/lib/Socket/hbmods.d.ts +0 -254
  87. package/lib/Socket/index.d.ts +0 -173
  88. package/lib/Socket/messages-recv.d.ts +0 -161
  89. package/lib/Socket/messages-send.d.ts +0 -149
  90. package/lib/Socket/newsletter.d.ts +0 -134
  91. package/lib/Socket/registration.d.ts +0 -267
  92. package/lib/Socket/registration.js +0 -166
  93. package/lib/Socket/socket.d.ts +0 -43
  94. package/lib/Socket/usync.d.ts +0 -36
  95. package/lib/Store/index.d.ts +0 -3
  96. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  97. package/lib/Store/make-cache-manager-store.js +0 -83
  98. package/lib/Store/make-in-memory-store.d.ts +0 -118
  99. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  100. package/lib/Store/object-repository.d.ts +0 -10
  101. package/lib/Types/Auth.d.ts +0 -110
  102. package/lib/Types/Call.d.ts +0 -13
  103. package/lib/Types/Chat.d.ts +0 -102
  104. package/lib/Types/Contact.d.ts +0 -19
  105. package/lib/Types/Events.d.ts +0 -157
  106. package/lib/Types/GroupMetadata.d.ts +0 -55
  107. package/lib/Types/Label.d.ts +0 -35
  108. package/lib/Types/LabelAssociation.d.ts +0 -29
  109. package/lib/Types/Message.d.ts +0 -273
  110. package/lib/Types/Newsletter.d.ts +0 -103
  111. package/lib/Types/Product.d.ts +0 -78
  112. package/lib/Types/Signal.d.ts +0 -57
  113. package/lib/Types/Socket.d.ts +0 -111
  114. package/lib/Types/State.d.ts +0 -27
  115. package/lib/Types/USync.d.ts +0 -25
  116. package/lib/Types/index.d.ts +0 -57
  117. package/lib/Utils/auth-utils.d.ts +0 -18
  118. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  119. package/lib/Utils/business.d.ts +0 -22
  120. package/lib/Utils/chat-utils.d.ts +0 -71
  121. package/lib/Utils/crypto.d.ts +0 -41
  122. package/lib/Utils/decode-wa-message.d.ts +0 -19
  123. package/lib/Utils/event-buffer.d.ts +0 -35
  124. package/lib/Utils/generics.d.ts +0 -92
  125. package/lib/Utils/generics.js.bak +0 -433
  126. package/lib/Utils/history.d.ts +0 -15
  127. package/lib/Utils/index.d.ts +0 -17
  128. package/lib/Utils/link-preview.d.ts +0 -21
  129. package/lib/Utils/logger.d.ts +0 -4
  130. package/lib/Utils/lt-hash.d.ts +0 -12
  131. package/lib/Utils/make-mutex.d.ts +0 -7
  132. package/lib/Utils/messages-media.d.ts +0 -116
  133. package/lib/Utils/messages.d.ts +0 -77
  134. package/lib/Utils/noise-handler.d.ts +0 -21
  135. package/lib/Utils/process-message.d.ts +0 -41
  136. package/lib/Utils/signal.d.ts +0 -32
  137. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  138. package/lib/Utils/validate-connection.d.ts +0 -11
  139. package/lib/Utils/validate-connection.js.bak +0 -237
  140. package/lib/WABinary/constants.d.ts +0 -30
  141. package/lib/WABinary/decode.d.ts +0 -7
  142. package/lib/WABinary/encode.d.ts +0 -3
  143. package/lib/WABinary/generic-utils.d.ts +0 -17
  144. package/lib/WABinary/index.d.ts +0 -5
  145. package/lib/WABinary/jid-utils.d.ts +0 -31
  146. package/lib/WABinary/types.d.ts +0 -18
  147. package/lib/WAM/BinaryInfo.d.ts +0 -17
  148. package/lib/WAM/constants.d.ts +0 -38
  149. package/lib/WAM/encode.d.ts +0 -3
  150. package/lib/WAM/index.d.ts +0 -3
  151. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  152. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  153. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  154. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  155. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  156. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  157. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  158. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  159. package/lib/WAUSync/USyncUser.d.ts +0 -12
  160. package/lib/WAUSync/index.d.ts +0 -3
  161. package/lib/index.d.ts +0 -12
  162. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -1,42 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decryptMessageNode = exports.decodeMessageNode = void 0;
3
+ exports.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
4
+ exports.decodeMessageNode = decodeMessageNode;
4
5
  const boom_1 = require("@hapi/boom");
5
6
  const WAProto_1 = require("../../WAProto");
6
7
  const WABinary_1 = require("../WABinary");
7
8
  const generics_1 = require("./generics");
8
- const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
9
+ exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
10
+ exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
11
+ exports.NACK_REASONS = {
12
+ ParsingError: 487,
13
+ UnrecognizedStanza: 488,
14
+ UnrecognizedStanzaClass: 489,
15
+ UnrecognizedStanzaType: 490,
16
+ InvalidProtobuf: 491,
17
+ InvalidHostedCompanionStanza: 493,
18
+ MissingMessageSecret: 495,
19
+ SignalErrorOldCounter: 496,
20
+ MessageDeletedOnPeer: 499,
21
+ UnhandledError: 500,
22
+ UnsupportedAdminRevoke: 550,
23
+ UnsupportedLIDGroup: 551,
24
+ DBOperationFailed: 552
25
+ };
9
26
  /**
10
27
  * Decode the received node as a message.
11
28
  * @note this will only parse the message, not decrypt it
12
29
  */
13
30
  function decodeMessageNode(stanza, meId, meLid) {
14
- var _a, _b;
31
+ var _a, _b, _c, _d, _e, _f, _g;
15
32
  let msgType;
16
33
  let chatId;
17
34
  let author;
18
35
  const msgId = stanza.attrs.id;
19
36
  const from = stanza.attrs.from;
37
+ const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
38
+ const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
20
39
  const participant = stanza.attrs.participant;
40
+ const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
21
41
  const recipient = stanza.attrs.recipient;
22
42
  const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
23
43
  const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
24
- if ((0, WABinary_1.isJidUser)(from)) {
25
- if (recipient) {
26
- if (!isMe(from)) {
27
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
28
- }
29
- chatId = recipient;
30
- }
31
- else {
32
- chatId = from;
33
- }
34
- msgType = 'chat';
35
- author = from;
36
- }
37
- else if ((0, WABinary_1.isLidUser)(from)) {
38
- if (recipient) {
39
- if (!isMeLid(from)) {
44
+ if ((0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
45
+ if (recipient && !(0, WABinary_1.isJidMetaAi)(recipient)) {
46
+ if (!isMe(from) && !isMeLid(from)) {
40
47
  throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
41
48
  }
42
49
  chatId = recipient;
@@ -55,6 +62,11 @@ function decodeMessageNode(stanza, meId, meLid) {
55
62
  author = participant;
56
63
  chatId = from;
57
64
  }
65
+ else if ((0, WABinary_1.isJidNewsletter)(from)) {
66
+ msgType = 'newsletter';
67
+ author = from;
68
+ chatId = from;
69
+ }
58
70
  else if ((0, WABinary_1.isJidBroadcast)(from)) {
59
71
  if (!participant) {
60
72
  throw new boom_1.Boom('No participant in group message');
@@ -69,21 +81,20 @@ function decodeMessageNode(stanza, meId, meLid) {
69
81
  chatId = from;
70
82
  author = participant;
71
83
  }
72
- else if ((0, WABinary_1.isJidNewsLetter)(from)) {
73
- msgType = 'newsletter';
74
- author = from;
75
- chatId = from;
76
- }
77
84
  else {
78
85
  throw new boom_1.Boom('Unknown message type', { data: stanza });
79
86
  }
80
- const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
81
- const pushname = stanza.attrs.notify;
87
+ const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.is_sender) || false : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
88
+ const pushname = (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.notify;
82
89
  const key = {
83
90
  remoteJid: chatId,
84
91
  fromMe,
85
92
  id: msgId,
86
- participant
93
+ senderPn,
94
+ senderLid,
95
+ participant,
96
+ participantLid,
97
+ 'server_id': (_f = stanza.attrs) === null || _f === void 0 ? void 0 : _f.server_id
87
98
  };
88
99
  const fullMessage = {
89
100
  key,
@@ -92,7 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
92
103
  broadcast: (0, WABinary_1.isJidBroadcast)(from)
93
104
  };
94
105
  if (msgType === 'newsletter') {
95
- fullMessage.newsletterServerId = +((_b = stanza.attrs) === null || _b === void 0 ? void 0 : _b.server_id);
106
+ fullMessage.newsletterServerId = +((_g = stanza.attrs) === null || _g === void 0 ? void 0 : _g.server_id);
96
107
  }
97
108
  if (key.fromMe) {
98
109
  fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
@@ -103,7 +114,6 @@ function decodeMessageNode(stanza, meId, meLid) {
103
114
  sender: msgType === 'chat' ? author : chatId
104
115
  };
105
116
  }
106
- exports.decodeMessageNode = decodeMessageNode;
107
117
  const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
108
118
  const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
109
119
  return {
@@ -113,34 +123,17 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
113
123
  async decrypt() {
114
124
  var _a;
115
125
  let decryptables = 0;
116
- async function processSenderKeyDistribution(msg) {
117
- if (msg.senderKeyDistributionMessage) {
118
- try {
119
- await repository.processSenderKeyDistributionMessage({
120
- authorJid: author,
121
- item: msg.senderKeyDistributionMessage
122
- });
123
- }
124
- catch (err) {
125
- logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
126
- }
127
- }
128
- }
129
- if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
130
- const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
131
- const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
132
- await processSenderKeyDistribution(msg);
133
- fullMessage.message = msg;
134
- decryptables += 1;
135
- }
136
- else if (Array.isArray(stanza.content)) {
126
+ if (Array.isArray(stanza.content)) {
137
127
  for (const { tag, attrs, content } of stanza.content) {
138
128
  if (tag === 'verified_name' && content instanceof Uint8Array) {
139
129
  const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
140
130
  const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
141
131
  fullMessage.verifiedBizName = details.verifiedName;
142
132
  }
143
- if (tag !== 'enc') {
133
+ if (tag === 'unavailable' && attrs.type === 'view_once') {
134
+ fullMessage.key.isViewOnce = true;
135
+ }
136
+ if (tag !== 'enc' && tag !== 'plaintext') {
144
137
  continue;
145
138
  }
146
139
  if (!(content instanceof Uint8Array)) {
@@ -149,7 +142,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
149
142
  decryptables += 1;
150
143
  let msgBuffer;
151
144
  try {
152
- const e2eType = attrs.type;
145
+ const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
153
146
  switch (e2eType) {
154
147
  case 'skmsg':
155
148
  msgBuffer = await repository.decryptGroupMessage({
@@ -167,12 +160,28 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
167
160
  ciphertext: content
168
161
  });
169
162
  break;
163
+ case 'plaintext':
164
+ msgBuffer = content;
165
+ break;
166
+ case undefined:
167
+ msgBuffer = content;
168
+ break;
170
169
  default:
171
170
  throw new Error(`Unknown e2e type: ${e2eType}`);
172
171
  }
173
- let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
174
- msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
175
- await processSenderKeyDistribution(msg);
172
+ let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
173
+ msg = ((_a = msg === null || msg === void 0 ? void 0 : msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
174
+ if (msg.senderKeyDistributionMessage) {
175
+ try {
176
+ await repository.processSenderKeyDistributionMessage({
177
+ authorJid: author,
178
+ item: msg.senderKeyDistributionMessage
179
+ });
180
+ }
181
+ catch (err) {
182
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
183
+ }
184
+ }
176
185
  if (fullMessage.message) {
177
186
  Object.assign(fullMessage.message, msg);
178
187
  }
@@ -190,7 +199,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
190
199
  // if nothing was found to decrypt
191
200
  if (!decryptables) {
192
201
  fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
193
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
202
+ fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
194
203
  }
195
204
  }
196
205
  };
@@ -27,14 +27,14 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
27
27
  /**
28
28
  * The event buffer logically consolidates different events into a single event
29
29
  * making the data processing more efficient.
30
- * @param ev the baileys event emitter
30
+ * @param ev the RexxHayanasi event emitter
31
31
  */
32
32
  const makeEventBuffer = (logger) => {
33
33
  const ev = new events_1.default();
34
34
  const historyCache = new Set();
35
35
  let data = makeBufferData();
36
36
  let buffersInProgress = 0;
37
- // take the generic event and fire it as a baileys event
37
+ // take the generic event and fire it as a RexxHayanasi event
38
38
  ev.on('event', (map) => {
39
39
  for (const event in map) {
40
40
  ev.emit(event, map[event]);
@@ -176,6 +176,9 @@ function append(data, historyCache, event, eventData, logger) {
176
176
  }
177
177
  }
178
178
  data.historySets.empty = false;
179
+ data.historySets.syncType = eventData.syncType;
180
+ data.historySets.progress = eventData.progress;
181
+ data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
179
182
  data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
180
183
  break;
181
184
  case 'chats.upsert':
@@ -442,7 +445,10 @@ function consolidateEvents(data) {
442
445
  chats: Object.values(data.historySets.chats),
443
446
  messages: Object.values(data.historySets.messages),
444
447
  contacts: Object.values(data.historySets.contacts),
445
- isLatest: data.historySets.isLatest
448
+ syncType: data.historySets.syncType,
449
+ progress: data.historySets.progress,
450
+ isLatest: data.historySets.isLatest,
451
+ peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
446
452
  };
447
453
  }
448
454
  const chatUpsertList = Object.values(data.chatUpserts);
@@ -496,12 +502,10 @@ function consolidateEvents(data) {
496
502
  return map;
497
503
  }
498
504
  function concatChats(a, b) {
499
- if (b.unreadCount === null) {
500
- // neutralize unread counter
501
- if (a.unreadCount < 0) {
502
- a.unreadCount = undefined;
503
- b.unreadCount = undefined;
504
- }
505
+ if (b.unreadCount === null && // neutralize unread counter
506
+ a.unreadCount < 0) {
507
+ a.unreadCount = undefined;
508
+ b.unreadCount = undefined;
505
509
  }
506
510
  if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
507
511
  b = { ...b };
@@ -1,19 +1,61 @@
1
- "use strict";
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
39
+ exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
40
+ exports.promiseTimeout = promiseTimeout;
41
+ exports.bindWaitForEvent = bindWaitForEvent;
42
+ exports.trimUndefined = trimUndefined;
43
+ exports.bytesToCrockford = bytesToCrockford;
7
44
  const boom_1 = require("@hapi/boom");
8
45
  const axios_1 = __importDefault(require("axios"));
9
46
  const crypto_1 = require("crypto");
10
47
  const os_1 = require("os");
11
- const fetch_1 = require("node-fetch")
12
48
  const WAProto_1 = require("../../WAProto");
13
49
  const baileys_version_json_1 = require("../Defaults/baileys-version.json");
14
50
  const Types_1 = require("../Types");
15
51
  const WABinary_1 = require("../WABinary");
16
- const baileysVersion = [2, 3000, 1027934701]
52
+ const COMPANION_PLATFORM_MAP = {
53
+ 'Chrome': '49',
54
+ 'Edge': '50',
55
+ 'Firefox': '51',
56
+ 'Opera': '53',
57
+ 'Safari': '54'
58
+ };
17
59
  const PLATFORM_MAP = {
18
60
  'aix': 'AIX',
19
61
  'darwin': 'Mac OS',
@@ -21,26 +63,19 @@ const PLATFORM_MAP = {
21
63
  'android': 'Android',
22
64
  'freebsd': 'FreeBSD',
23
65
  'openbsd': 'OpenBSD',
24
- 'sunos': 'Solaris',
25
- 'linux': undefined,
26
- 'haiku': undefined,
27
- 'cygwin': undefined,
28
- 'netbsd': undefined
66
+ 'sunos': 'Solaris'
29
67
  };
30
-
31
- const Browsers = {
32
- iOS: (browser) => ["ios", browser, "18.2"],
68
+ exports.Browsers = {
33
69
  ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
34
70
  macOS: (browser) => ['Mac OS', browser, '14.4.1'],
35
71
  baileys: (browser) => ['Baileys', browser, '6.5.0'],
36
- windows: (browser) => ['Windows', browser, '10.0.22631']
72
+ windows: (browser) => ['Windows', browser, '10.0.22631'],
73
+ /** The appropriate browser based on your OS & release */
74
+ appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
37
75
  };
38
-
39
- exports.Browsers = Browsers
40
-
41
76
  const getPlatformId = (browser) => {
42
77
  const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
43
- return platformType ? platformType.toString() : '1'; //chrome
78
+ return platformType ? platformType.toString() : '49'; //chrome
44
79
  };
45
80
  exports.getPlatformId = getPlatformId;
46
81
  exports.BufferJSON = {
@@ -83,6 +118,8 @@ const unpadRandomMax16 = (e) => {
83
118
  exports.unpadRandomMax16 = unpadRandomMax16;
84
119
  const encodeWAMessage = (message) => ((0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish()));
85
120
  exports.encodeWAMessage = encodeWAMessage;
121
+ const encodeNewsletterMessage = (message) => (WAProto_1.proto.Message.encode(message).finish());
122
+ exports.encodeNewsletterMessage = encodeNewsletterMessage;
86
123
  const generateRegistrationId = () => {
87
124
  return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
88
125
  };
@@ -97,7 +134,7 @@ const encodeBigEndian = (e, t = 4) => {
97
134
  return a;
98
135
  };
99
136
  exports.encodeBigEndian = encodeBigEndian;
100
- const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
137
+ const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0);
101
138
  exports.toNumber = toNumber;
102
139
  /** unix timestamp of a date in seconds */
103
140
  const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
@@ -163,7 +200,6 @@ async function promiseTimeout(ms, promise) {
163
200
  .finally(cancel);
164
201
  return p;
165
202
  }
166
- exports.promiseTimeout = promiseTimeout;
167
203
  const generateMessageIDV2 = (userId) => {
168
204
  const data = Buffer.alloc(8 + 20 + 16);
169
205
  data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
@@ -181,7 +217,7 @@ const generateMessageIDV2 = (userId) => {
181
217
  };
182
218
  exports.generateMessageIDV2 = generateMessageIDV2;
183
219
  // generate a random ID to attach to a message
184
- const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
220
+ const generateMessageID = () => '3EB0' + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase();
185
221
  exports.generateMessageID = generateMessageID;
186
222
  function bindWaitForEvent(ev, event) {
187
223
  return async (check, timeoutMs) => {
@@ -195,8 +231,8 @@ function bindWaitForEvent(ev, event) {
195
231
  }
196
232
  };
197
233
  ev.on('connection.update', closeListener);
198
- listener = (update) => {
199
- if (check(update)) {
234
+ listener = async (update) => {
235
+ if (await check(update)) {
200
236
  resolve();
201
237
  }
202
238
  };
@@ -208,14 +244,12 @@ function bindWaitForEvent(ev, event) {
208
244
  }));
209
245
  };
210
246
  }
211
- exports.bindWaitForEvent = bindWaitForEvent;
212
247
  const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
213
248
  exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
214
249
  const printQRIfNecessaryListener = (ev, logger) => {
215
250
  ev.on('connection.update', async ({ qr }) => {
216
251
  if (qr) {
217
- const QR = await import('qrcode-terminal')
218
- .then(m => m.default || m)
252
+ const QR = await Promise.resolve().then(() => __importStar(require('qrcode-terminal'))).then(m => m.default || m)
219
253
  .catch(() => {
220
254
  logger.error('QR code terminal not added as dependency');
221
255
  });
@@ -224,68 +258,40 @@ const printQRIfNecessaryListener = (ev, logger) => {
224
258
  });
225
259
  };
226
260
  exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
227
- /**
228
- * utility that fetches latest baileys version from the master branch.
229
- * Use to ensure your WA connection is always on the latest version
230
- */
231
- const fetchLatestWaWebVersion = async (options = {}) => {
232
- try {
233
- const defaultHeaders = {
234
- 'User-Agent':
235
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
236
- 'Accept': '*/*'
237
- }
238
-
239
- const headers = { ...defaultHeaders, ...options.headers }
240
-
241
- const response = await fetch_1('https://web.whatsapp.com/sw.js', {
242
- method: 'GET',
243
- headers
244
- })
245
261
 
246
- if (!response.ok) {
247
- throw new Error(`Failed to fetch sw.js: ${response.status} ${response.statusText}`)
248
- }
249
262
 
250
- const data = await response.text()
251
- const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
252
- const match = data.match(regex)
253
-
254
- if (!match || !match[1]) {
255
- return {
256
- version: baileysVersion,
257
- isLatest: false,
258
- error: { message: 'Client revision not found' }
259
- }
260
- }
263
+ const fetchLatestBaileysVersion = async (options = {}) => {
264
+ return {
265
+ version: baileys_version_json_1.version,
266
+ isLatest: true
267
+ };
268
+ };
269
+ exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
261
270
 
262
- const clientRevision = match[1]
263
- return {
264
- version: [2, 3000, +clientRevision],
265
- isLatest: true
266
- }
267
- } catch (error) {
268
- return {
269
- version: baileysVersion,
270
- isLatest: false,
271
- error
272
- }
273
- }
274
- }
275
- exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
276
271
  /**
277
- * utility that fetches latest baileys version from the master branch.
272
+ * A utility that fetches the latest web version of whatsapp.
278
273
  * Use to ensure your WA connection is always on the latest version
279
274
  */
280
- const fetchLatestBaileysVersion = async (options = {}) => {
281
- const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
275
+ const fetchLatestWaWebVersion = async (options) => {
282
276
  try {
283
- const result = await axios_1.default.get(URL, {
277
+ const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
284
278
  ...options,
285
279
  responseType: 'json'
286
280
  });
281
+ const regex = /\\?"client_revision\\?":\s*(\d+)/;
282
+ const match = data.match(regex);
283
+ if (!(match === null || match === void 0 ? void 0 : match[1])) {
284
+ return {
285
+ version: baileys_version_json_1.version,
286
+ isLatest: false,
287
+ error: {
288
+ message: 'Could not find client revision in the fetched content'
289
+ }
290
+ };
291
+ }
292
+ const clientRevision = match[1];
287
293
  return {
288
- version: result.data.version,
294
+ version: [2, 3000, +clientRevision],
289
295
  isLatest: true
290
296
  };
291
297
  }
@@ -297,7 +303,7 @@ const fetchLatestBaileysVersion = async (options = {}) => {
297
303
  };
298
304
  }
299
305
  };
300
- exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
306
+ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
301
307
  /** unique message tag prefix for MD clients */
302
308
  const generateMdTagPrefix = () => {
303
309
  const bytes = (0, crypto_1.randomBytes)(4);
@@ -305,6 +311,7 @@ const generateMdTagPrefix = () => {
305
311
  };
306
312
  exports.generateMdTagPrefix = generateMdTagPrefix;
307
313
  const STATUS_MAP = {
314
+ 'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
308
315
  'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
309
316
  'read': WAProto_1.proto.WebMessageInfo.Status.READ,
310
317
  'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
@@ -353,7 +360,8 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
353
360
  status = 'timeout';
354
361
  }
355
362
  else {
356
- status = 'reject';
363
+ // fired when accepted/rejected/timeout/caller hangs up
364
+ status = 'terminate';
357
365
  }
358
366
  break;
359
367
  case 'reject':
@@ -402,7 +410,6 @@ function trimUndefined(obj) {
402
410
  }
403
411
  return obj;
404
412
  }
405
- exports.trimUndefined = trimUndefined;
406
413
  const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
407
414
  function bytesToCrockford(buffer) {
408
415
  let value = 0;
@@ -421,8 +428,5 @@ function bytesToCrockford(buffer) {
421
428
  }
422
429
  return crockford.join('');
423
430
  }
424
- exports.bytesToCrockford = bytesToCrockford;
425
- const encodeNewsletterMessage = (message) => {
426
- return WAProto_1.proto.Message.encode(message).finish()
427
- }
428
- exports.encodeNewsletterMessage = encodeNewsletterMessage;
431
+ exports.trimUndefined = trimUndefined;
432
+ exports.bytesToCrockford = bytesToCrockford;
@@ -32,13 +32,9 @@ const processHistoryMessage = (item) => {
32
32
  case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
33
33
  case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
34
34
  case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
35
+ case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
35
36
  for (const chat of item.conversations) {
36
- contacts.push({
37
- id: chat.id,
38
- name: chat.name || undefined,
39
- lid: chat.lidJid || undefined,
40
- jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
41
- });
37
+ contacts.push({ id: chat.id, name: chat.name || undefined, lid: chat.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : chat.pnJid });
42
38
  const msgs = chat.messages || [];
43
39
  delete chat.messages;
44
40
  delete chat.archived;
@@ -79,6 +75,8 @@ const processHistoryMessage = (item) => {
79
75
  chats,
80
76
  contacts,
81
77
  messages,
78
+ syncType: item.syncType,
79
+ progress: item.progress
82
80
  };
83
81
  };
84
82
  exports.processHistoryMessage = processHistoryMessage;
@@ -31,3 +31,6 @@ __exportStar(require("./use-multi-file-auth-state"), exports);
31
31
  __exportStar(require("./link-preview"), exports);
32
32
  __exportStar(require("./event-buffer"), exports);
33
33
  __exportStar(require("./process-message"), exports);
34
+ __exportStar(require("./message-retry-manager"), exports);
35
+ __exportStar(require("./browser-utils"), exports);
36
+ __exportStar(require("./resolveJid"), exports);
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.getUrlInfo = void 0;
4
37
  const messages_1 = require("./messages");
@@ -25,7 +58,7 @@ const getUrlInfo = async (text, opts = {
25
58
  // retries
26
59
  const retries = 0;
27
60
  const maxRetry = 5;
28
- const { getLinkPreview } = await import('link-preview-js');
61
+ const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')));
29
62
  let previewLink = text;
30
63
  if (!text.startsWith('https://') && !text.startsWith('http://')) {
31
64
  previewLink = 'https://' + previewLink;
@@ -30,15 +30,15 @@ class d {
30
30
  var n = this;
31
31
  return n.add(n.subtract(e, r), t);
32
32
  }
33
- _addSingle(e, t) {
33
+ async _addSingle(e, t) {
34
34
  var r = this;
35
- const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
36
- return r.performPointwiseWithOverflow(e, n, ((e, t) => e + t));
35
+ const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
36
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t));
37
37
  }
38
- _subtractSingle(e, t) {
38
+ async _subtractSingle(e, t) {
39
39
  var r = this;
40
- const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
41
- return r.performPointwiseWithOverflow(e, n, ((e, t) => e - t));
40
+ const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
41
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t));
42
42
  }
43
43
  performPointwiseWithOverflow(e, t, r) {
44
44
  const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);