supunmd-bail 2.1.1 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +428 -0
  3. package/WAProto/index.js +130529 -45236
  4. package/engine-requirements.js +1 -1
  5. package/lib/Defaults/baileys-version.json +1 -1
  6. package/lib/Defaults/index.d.ts +9 -18
  7. package/lib/Defaults/index.js +136 -104
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
  10. package/lib/Signal/Group/ciphertext-message.js +5 -2
  11. package/lib/Signal/Group/group-session-builder.d.ts +3 -4
  12. package/lib/Signal/Group/group-session-builder.js +41 -7
  13. package/lib/Signal/Group/group_cipher.d.ts +4 -4
  14. package/lib/Signal/Group/group_cipher.js +51 -37
  15. package/lib/Signal/Group/index.d.ts +11 -12
  16. package/lib/Signal/Group/index.js +57 -12
  17. package/lib/Signal/Group/keyhelper.d.ts +1 -2
  18. package/lib/Signal/Group/keyhelper.js +44 -7
  19. package/lib/Signal/Group/queue-job.d.ts +0 -1
  20. package/lib/Signal/Group/queue-job.js +5 -2
  21. package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
  22. package/lib/Signal/Group/sender-chain-key.js +15 -7
  23. package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
  24. package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
  25. package/lib/Signal/Group/sender-key-message.d.ts +1 -2
  26. package/lib/Signal/Group/sender-key-message.js +12 -9
  27. package/lib/Signal/Group/sender-key-name.d.ts +0 -1
  28. package/lib/Signal/Group/sender-key-name.js +5 -2
  29. package/lib/Signal/Group/sender-key-record.d.ts +2 -3
  30. package/lib/Signal/Group/sender-key-record.js +21 -9
  31. package/lib/Signal/Group/sender-key-state.d.ts +6 -7
  32. package/lib/Signal/Group/sender-key-state.js +42 -27
  33. package/lib/Signal/Group/sender-message-key.d.ts +0 -1
  34. package/lib/Signal/Group/sender-message-key.js +7 -4
  35. package/lib/Signal/libsignal.d.ts +3 -5
  36. package/lib/Signal/libsignal.js +90 -258
  37. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -2
  38. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  39. package/lib/Socket/Client/index.d.ts +3 -3
  40. package/lib/Socket/Client/index.js +19 -3
  41. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  42. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  43. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
  44. package/lib/Socket/Client/web-socket-client.js +62 -0
  45. package/lib/Socket/business.d.ts +108 -125
  46. package/lib/Socket/business.js +43 -159
  47. package/lib/Socket/chats.d.ts +239 -70
  48. package/lib/Socket/chats.js +384 -363
  49. package/lib/Socket/dugong.d.ts +254 -0
  50. package/lib/Socket/dugong.js +484 -0
  51. package/lib/Socket/groups.d.ts +56 -78
  52. package/lib/Socket/groups.js +96 -106
  53. package/lib/Socket/index.d.ts +115 -173
  54. package/lib/Socket/index.js +10 -17
  55. package/lib/Socket/messages-recv.d.ts +79 -91
  56. package/lib/Socket/messages-recv.js +521 -639
  57. package/lib/Socket/messages-send.d.ts +91 -111
  58. package/lib/Socket/messages-send.js +438 -599
  59. package/lib/Socket/newsletter.d.ts +84 -97
  60. package/lib/Socket/newsletter.js +239 -145
  61. package/lib/Socket/registration.d.ts +267 -0
  62. package/lib/Socket/registration.js +166 -0
  63. package/lib/Socket/socket.d.ts +18 -26
  64. package/lib/Socket/socket.js +230 -448
  65. package/lib/Socket/usync.d.ts +16 -17
  66. package/lib/Socket/usync.js +26 -19
  67. package/lib/Store/index.d.ts +3 -0
  68. package/lib/Store/index.js +10 -0
  69. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  70. package/lib/Store/make-cache-manager-store.js +83 -0
  71. package/lib/Store/make-in-memory-store.d.ts +118 -0
  72. package/lib/Store/make-in-memory-store.js +427 -0
  73. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  74. package/lib/Store/make-ordered-dictionary.js +81 -0
  75. package/lib/Store/object-repository.d.ts +10 -0
  76. package/lib/Store/object-repository.js +27 -0
  77. package/lib/Types/Auth.d.ts +12 -13
  78. package/lib/Types/Auth.js +2 -2
  79. package/lib/Types/Call.d.ts +1 -2
  80. package/lib/Types/Call.js +2 -2
  81. package/lib/Types/Chat.d.ts +13 -34
  82. package/lib/Types/Chat.js +4 -8
  83. package/lib/Types/Contact.d.ts +1 -6
  84. package/lib/Types/Contact.js +2 -2
  85. package/lib/Types/Events.d.ts +15 -60
  86. package/lib/Types/Events.js +2 -2
  87. package/lib/Types/GroupMetadata.d.ts +5 -17
  88. package/lib/Types/GroupMetadata.js +2 -2
  89. package/lib/Types/Label.d.ts +0 -12
  90. package/lib/Types/Label.js +5 -3
  91. package/lib/Types/LabelAssociation.d.ts +0 -1
  92. package/lib/Types/LabelAssociation.js +5 -3
  93. package/lib/Types/Message.d.ts +54 -84
  94. package/lib/Types/Message.js +9 -11
  95. package/lib/Types/Newsletter.d.ts +98 -130
  96. package/lib/Types/Newsletter.js +38 -31
  97. package/lib/Types/Product.d.ts +1 -2
  98. package/lib/Types/Product.js +2 -2
  99. package/lib/Types/Signal.d.ts +1 -20
  100. package/lib/Types/Signal.js +2 -2
  101. package/lib/Types/Socket.d.ts +25 -47
  102. package/lib/Types/Socket.js +2 -3
  103. package/lib/Types/State.d.ts +2 -14
  104. package/lib/Types/State.js +2 -13
  105. package/lib/Types/USync.d.ts +2 -3
  106. package/lib/Types/USync.js +2 -2
  107. package/lib/Types/index.d.ts +14 -22
  108. package/lib/Types/index.js +31 -15
  109. package/lib/Utils/auth-utils.d.ts +6 -7
  110. package/lib/Utils/auth-utils.js +148 -199
  111. package/lib/Utils/baileys-event-stream.d.ts +1 -2
  112. package/lib/Utils/baileys-event-stream.js +22 -15
  113. package/lib/Utils/business.d.ts +2 -3
  114. package/lib/Utils/business.js +69 -66
  115. package/lib/Utils/chat-utils.d.ts +22 -21
  116. package/lib/Utils/chat-utils.js +226 -260
  117. package/lib/Utils/crypto.d.ts +19 -19
  118. package/lib/Utils/crypto.js +86 -77
  119. package/lib/Utils/decode-wa-message.d.ts +8 -37
  120. package/lib/Utils/decode-wa-message.js +83 -164
  121. package/lib/Utils/event-buffer.d.ts +8 -7
  122. package/lib/Utils/event-buffer.js +76 -110
  123. package/lib/Utils/generics.d.ts +29 -27
  124. package/lib/Utils/generics.js +210 -168
  125. package/lib/Utils/history.d.ts +8 -12
  126. package/lib/Utils/history.js +46 -34
  127. package/lib/Utils/index.d.ts +17 -20
  128. package/lib/Utils/index.js +33 -20
  129. package/lib/Utils/link-preview.d.ts +5 -5
  130. package/lib/Utils/link-preview.js +22 -14
  131. package/lib/Utils/logger.d.ts +3 -11
  132. package/lib/Utils/logger.js +7 -3
  133. package/lib/Utils/lt-hash.d.ts +8 -9
  134. package/lib/Utils/lt-hash.js +28 -25
  135. package/lib/Utils/make-mutex.d.ts +2 -3
  136. package/lib/Utils/make-mutex.js +10 -7
  137. package/lib/Utils/messages-media.d.ts +44 -42
  138. package/lib/Utils/messages-media.js +475 -319
  139. package/lib/Utils/messages.d.ts +18 -17
  140. package/lib/Utils/messages.js +259 -383
  141. package/lib/Utils/noise-handler.d.ts +15 -14
  142. package/lib/Utils/noise-handler.js +38 -30
  143. package/lib/Utils/process-message.d.ts +13 -14
  144. package/lib/Utils/process-message.js +147 -239
  145. package/lib/Utils/signal.d.ts +5 -7
  146. package/lib/Utils/signal.js +72 -78
  147. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
  148. package/lib/Utils/use-multi-file-auth-state.js +27 -29
  149. package/lib/Utils/validate-connection.d.ts +7 -7
  150. package/lib/Utils/validate-connection.js +106 -72
  151. package/lib/WABinary/constants.d.ts +27 -25
  152. package/lib/WABinary/constants.js +20 -1281
  153. package/lib/WABinary/decode.d.ts +5 -5
  154. package/lib/WABinary/decode.js +42 -28
  155. package/lib/WABinary/encode.d.ts +3 -3
  156. package/lib/WABinary/encode.js +154 -105
  157. package/lib/WABinary/generic-utils.d.ts +7 -5
  158. package/lib/WABinary/generic-utils.js +63 -56
  159. package/lib/WABinary/index.d.ts +5 -6
  160. package/lib/WABinary/index.js +21 -6
  161. package/lib/WABinary/jid-utils.d.ts +8 -25
  162. package/lib/WABinary/jid-utils.js +40 -74
  163. package/lib/WABinary/types.d.ts +1 -2
  164. package/lib/WABinary/types.js +2 -2
  165. package/lib/WAM/BinaryInfo.d.ts +11 -3
  166. package/lib/WAM/BinaryInfo.js +5 -2
  167. package/lib/WAM/constants.d.ts +3 -5
  168. package/lib/WAM/constants.js +11958 -19461
  169. package/lib/WAM/encode.d.ts +3 -3
  170. package/lib/WAM/encode.js +22 -17
  171. package/lib/WAM/index.d.ts +3 -4
  172. package/lib/WAM/index.js +19 -4
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
  175. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
  177. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
  179. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
  181. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
  183. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
  185. package/lib/WAUSync/Protocols/index.d.ts +4 -5
  186. package/lib/WAUSync/Protocols/index.js +20 -5
  187. package/lib/WAUSync/USyncQuery.d.ts +4 -5
  188. package/lib/WAUSync/USyncQuery.js +35 -40
  189. package/lib/WAUSync/USyncUser.d.ts +5 -6
  190. package/lib/WAUSync/USyncUser.js +5 -2
  191. package/lib/WAUSync/index.d.ts +3 -4
  192. package/lib/WAUSync/index.js +19 -4
  193. package/lib/index.d.ts +9 -19
  194. package/lib/index.js +47 -24
  195. package/package.json +109 -99
  196. package/WAProto/GenerateStatics.sh +0 -3
  197. package/WAProto/WAProto.proto +0 -5519
  198. package/WAProto/fix-imports.js +0 -29
  199. package/WAProto/index.d.ts +0 -11969
  200. package/lib/Signal/lid-mapping.d.ts +0 -23
  201. package/lib/Signal/lid-mapping.js +0 -171
  202. package/lib/Socket/Client/types.js +0 -11
  203. package/lib/Socket/Client/websocket.js +0 -50
  204. package/lib/Socket/communities.d.ts +0 -244
  205. package/lib/Socket/communities.js +0 -431
  206. package/lib/Socket/mex.d.ts +0 -3
  207. package/lib/Socket/mex.js +0 -42
  208. package/lib/Types/Bussines.d.ts +0 -25
  209. package/lib/Types/Bussines.js +0 -2
  210. package/lib/Utils/browser-utils.d.ts +0 -4
  211. package/lib/Utils/browser-utils.js +0 -28
  212. package/lib/Utils/message-retry-manager.d.ts +0 -82
  213. package/lib/Utils/message-retry-manager.js +0 -149
  214. package/lib/Utils/pre-key-manager.d.ts +0 -28
  215. package/lib/Utils/pre-key-manager.js +0 -106
  216. /package/lib/{supun → supunmd} +0 -0
@@ -1,38 +1,33 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import { WAMessageStubType } from '../Types/index.js';
3
- import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
4
- import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
5
- import { aesDecryptGCM, hmacSign } from './crypto.js';
6
- import { toNumber } from './generics.js';
7
- import { downloadAndProcessHistorySyncNotification } from './history.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decryptPollVote = exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
4
+ const WAProto_1 = require("../../WAProto");
5
+ const Types_1 = require("../Types");
6
+ const messages_1 = require("../Utils/messages");
7
+ const WABinary_1 = require("../WABinary");
8
+ const crypto_1 = require("./crypto");
9
+ const generics_1 = require("./generics");
10
+ const history_1 = require("./history");
8
11
  const REAL_MSG_STUB_TYPES = new Set([
9
- WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
10
- WAMessageStubType.CALL_MISSED_GROUP_VOICE,
11
- WAMessageStubType.CALL_MISSED_VIDEO,
12
- WAMessageStubType.CALL_MISSED_VOICE
12
+ Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
13
+ Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
14
+ Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
15
+ Types_1.WAMessageStubType.CALL_MISSED_VOICE
16
+ ]);
17
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
18
+ Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
13
19
  ]);
14
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
15
20
  /** Cleans a received message to further processing */
16
- export const cleanMessage = (message, meId, meLid) => {
21
+ const cleanMessage = (message, meId) => {
17
22
  // ensure remoteJid and participant doesn't have device or agent in it
18
- if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
19
- message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
20
- }
21
- else {
22
- message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
23
- }
24
- if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
25
- message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid');
26
- }
27
- else {
28
- message.key.participant = jidNormalizedUser(message.key.participant);
29
- }
30
- const content = normalizeMessageContent(message.message);
23
+ message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
24
+ message.key.participant = message.key.participant ? (0, WABinary_1.jidNormalizedUser)(message.key.participant) : undefined;
25
+ const content = (0, messages_1.normalizeMessageContent)(message.message);
31
26
  // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
32
- if (content?.reactionMessage) {
27
+ if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
33
28
  normaliseKey(content.reactionMessage.key);
34
29
  }
35
- if (content?.pollUpdateMessage) {
30
+ if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
36
31
  normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
37
32
  }
38
33
  function normaliseKey(msgKey) {
@@ -42,49 +37,54 @@ export const cleanMessage = (message, meId, meLid) => {
42
37
  // if the sender believed the message being reacted to is not from them
43
38
  // we've to correct the key to be from them, or some other participant
44
39
  msgKey.fromMe = !msgKey.fromMe
45
- ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
46
- areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
47
- : // if the message being reacted to, was from them
48
- // fromMe automatically becomes false
49
- false;
40
+ ? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
41
+ // if the message being reacted to, was from them
42
+ // fromMe automatically becomes false
43
+ : false;
50
44
  // set the remoteJid to being the same as the chat the message came from
51
- // TODO: investigate inconsistencies
52
45
  msgKey.remoteJid = message.key.remoteJid;
53
46
  // set participant of the message
54
47
  msgKey.participant = msgKey.participant || message.key.participant;
55
48
  }
56
49
  }
57
50
  };
58
- // TODO: target:audit AUDIT THIS FUNCTION AGAIN
59
- export const isRealMessage = (message) => {
60
- const normalizedContent = normalizeMessageContent(message.message);
61
- const hasSomeContent = !!getContentType(normalizedContent);
62
- return ((!!normalizedContent ||
63
- REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
64
- REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
65
- hasSomeContent &&
66
- !normalizedContent?.protocolMessage &&
67
- !normalizedContent?.reactionMessage &&
68
- !normalizedContent?.pollUpdateMessage);
51
+ exports.cleanMessage = cleanMessage;
52
+ const isRealMessage = (message, meId) => {
53
+ var _a;
54
+ const normalizedContent = (0, messages_1.normalizeMessageContent)(message.message);
55
+ const hasSomeContent = !!(0, messages_1.getContentType)(normalizedContent);
56
+ return (!!normalizedContent
57
+ || REAL_MSG_STUB_TYPES.has(message.messageStubType)
58
+ || (REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)
59
+ && ((_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a.some(p => (0, WABinary_1.areJidsSameUser)(meId, p)))))
60
+ && hasSomeContent
61
+ && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage)
62
+ && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage)
63
+ && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage);
69
64
  };
70
- export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
65
+ exports.isRealMessage = isRealMessage;
66
+ const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType);
67
+ exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
71
68
  /**
72
69
  * Get the ID of the chat from the given key.
73
70
  * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
74
71
  */
75
- export const getChatId = ({ remoteJid, participant, fromMe }) => {
76
- if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
72
+ const getChatId = ({ remoteJid, participant, fromMe }) => {
73
+ if ((0, WABinary_1.isJidBroadcast)(remoteJid)
74
+ && !(0, WABinary_1.isJidStatusBroadcast)(remoteJid)
75
+ && !fromMe) {
77
76
  return participant;
78
77
  }
79
78
  return remoteJid;
80
79
  };
80
+ exports.getChatId = getChatId;
81
81
  /**
82
82
  * Decrypt a poll vote
83
83
  * @param vote encrypted vote
84
84
  * @param ctx additional info about the poll required for decryption
85
85
  * @returns list of SHA256 options
86
86
  */
87
- export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
87
+ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
88
88
  const sign = Buffer.concat([
89
89
  toBinary(pollMsgId),
90
90
  toBinary(pollCreatorJid),
@@ -92,69 +92,64 @@ export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsg
92
92
  toBinary('Poll Vote'),
93
93
  new Uint8Array([1])
94
94
  ]);
95
- const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
96
- const decKey = hmacSign(sign, key0, 'sha256');
95
+ const key0 = (0, crypto_1.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
96
+ const decKey = (0, crypto_1.hmacSign)(sign, key0, 'sha256');
97
97
  const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
98
- const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
99
- return proto.Message.PollVoteMessage.decode(decrypted);
98
+ const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
99
+ return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted);
100
100
  function toBinary(txt) {
101
101
  return Buffer.from(txt);
102
102
  }
103
103
  }
104
- const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options }) => {
104
+ exports.decryptPollVote = decryptPollVote;
105
+ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
106
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
105
107
  const meId = creds.me.id;
106
108
  const { accountSettings } = creds;
107
- const chat = { id: jidNormalizedUser(getChatId(message.key)) };
108
- const isRealMsg = isRealMessage(message);
109
+ const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
110
+ const isRealMsg = (0, exports.isRealMessage)(message, meId);
109
111
  if (isRealMsg) {
110
- chat.messages = [{ message }];
111
- chat.conversationTimestamp = toNumber(message.messageTimestamp);
112
+ chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
112
113
  // only increment unread count if not CIPHERTEXT and from another person
113
- if (shouldIncrementChatUnread(message)) {
114
+ if ((0, exports.shouldIncrementChatUnread)(message)) {
114
115
  chat.unreadCount = (chat.unreadCount || 0) + 1;
115
116
  }
116
117
  }
117
- const content = normalizeMessageContent(message.message);
118
+ const content = (0, messages_1.normalizeMessageContent)(message.message);
118
119
  // unarchive chat if it's a real message, or someone reacted to our message
119
120
  // and we've the unarchive chats setting on
120
- if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
121
+ if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe))
122
+ && (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
121
123
  chat.archived = false;
122
124
  chat.readOnly = false;
123
125
  }
124
- const protocolMsg = content?.protocolMessage;
126
+ const protocolMsg = content === null || content === void 0 ? void 0 : content.protocolMessage;
125
127
  if (protocolMsg) {
126
128
  switch (protocolMsg.type) {
127
- case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
129
+ case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
128
130
  const histNotification = protocolMsg.historySyncNotification;
129
131
  const process = shouldProcessHistoryMsg;
130
- const isLatest = !creds.processedHistoryMessages?.length;
131
- logger?.info({
132
+ const isLatest = !((_c = creds.processedHistoryMessages) === null || _c === void 0 ? void 0 : _c.length);
133
+ logger === null || logger === void 0 ? void 0 : logger.info({
132
134
  histNotification,
133
135
  process,
134
136
  id: message.key.id,
135
- isLatest
137
+ isLatest,
136
138
  }, 'got history notification');
137
139
  if (process) {
138
- // TODO: investigate
139
- if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
140
- ev.emit('creds.update', {
141
- processedHistoryMessages: [
142
- ...(creds.processedHistoryMessages || []),
143
- { key: message.key, messageTimestamp: message.messageTimestamp }
144
- ]
145
- });
146
- }
147
- const data = await downloadAndProcessHistorySyncNotification(histNotification, options);
148
- ev.emit('messaging-history.set', {
149
- ...data,
150
- isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
151
- peerDataRequestSessionId: histNotification.peerDataRequestSessionId
140
+ ev.emit('creds.update', {
141
+ processedHistoryMessages: [
142
+ ...(creds.processedHistoryMessages || []),
143
+ { key: message.key, messageTimestamp: message.messageTimestamp }
144
+ ]
152
145
  });
146
+ const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
147
+ ev.emit('messaging-history.set', { ...data, isLatest });
153
148
  }
154
149
  break;
155
- case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
150
+ case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
156
151
  const keys = protocolMsg.appStateSyncKeyShare.keys;
157
- if (keys?.length) {
152
+ if (keys === null || keys === void 0 ? void 0 : keys.length) {
158
153
  let newAppStateSyncKeyId = '';
159
154
  await keyStore.transaction(async () => {
160
155
  const newKeys = [];
@@ -164,220 +159,138 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
164
159
  await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
165
160
  newAppStateSyncKeyId = strKeyId;
166
161
  }
167
- logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
168
- }, meId);
162
+ logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
163
+ });
169
164
  ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
170
165
  }
171
166
  else {
172
- logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
167
+ logger === null || logger === void 0 ? void 0 : logger.info({ protocolMsg }, 'recv app state sync with 0 keys');
173
168
  }
174
169
  break;
175
- case proto.Message.ProtocolMessage.Type.REVOKE:
170
+ case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
176
171
  ev.emit('messages.update', [
177
172
  {
178
173
  key: {
179
174
  ...message.key,
180
175
  id: protocolMsg.key.id
181
176
  },
182
- update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
177
+ update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
183
178
  }
184
179
  ]);
185
180
  break;
186
- case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
181
+ case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
187
182
  Object.assign(chat, {
188
- ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
183
+ ephemeralSettingTimestamp: (0, generics_1.toNumber)(message.messageTimestamp),
189
184
  ephemeralExpiration: protocolMsg.ephemeralExpiration || null
190
185
  });
191
186
  break;
192
- case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
187
+ case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
193
188
  const response = protocolMsg.peerDataOperationRequestResponseMessage;
194
189
  if (response) {
195
- await placeholderResendCache?.del(response.stanzaId);
196
- // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
197
190
  const { peerDataOperationResult } = response;
198
191
  for (const result of peerDataOperationResult) {
199
192
  const { placeholderMessageResendResponse: retryResponse } = result;
200
- //eslint-disable-next-line max-depth
201
193
  if (retryResponse) {
202
- const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
203
- // wait till another upsert event is available, don't want it to be part of the PDO response message
204
- // TODO: parse through proper message handling utilities (to add relevant key fields)
205
- setTimeout(() => {
206
- ev.emit('messages.upsert', {
207
- messages: [webMessageInfo],
208
- type: 'notify',
209
- requestId: response.stanzaId
210
- });
211
- }, 500);
194
+ const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
195
+ ev.emit('messages.update', [
196
+ { key: webMessageInfo.key, update: { message: webMessageInfo.message } }
197
+ ]);
212
198
  }
213
199
  }
214
200
  }
215
201
  break;
216
- case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
217
- ev.emit('messages.update', [
218
- {
219
- // flip the sender / fromMe properties because they're in the perspective of the sender
220
- key: { ...message.key, id: protocolMsg.key?.id },
221
- update: {
222
- message: {
223
- editedMessage: {
224
- message: protocolMsg.editedMessage
225
- }
226
- },
227
- messageTimestamp: protocolMsg.timestampMs
228
- ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
229
- : message.messageTimestamp
230
- }
231
- }
232
- ]);
233
- break;
234
- case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
235
- const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
236
- const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
237
- logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
238
- const pairs = [];
239
- for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
240
- const lid = latestLid || assignedLid;
241
- pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
242
- }
243
- await signalRepository.lidMapping.storeLIDPNMappings(pairs);
244
- if (pairs.length) {
245
- for (const { pn, lid } of pairs) {
246
- await signalRepository.migrateSession(pn, lid);
247
- }
248
- }
249
202
  }
250
203
  }
251
- else if (content?.reactionMessage) {
204
+ else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
252
205
  const reaction = {
253
206
  ...content.reactionMessage,
254
- key: message.key
207
+ key: message.key,
255
208
  };
256
- ev.emit('messages.reaction', [
257
- {
209
+ ev.emit('messages.reaction', [{
258
210
  reaction,
259
- key: content.reactionMessage?.key
260
- }
261
- ]);
211
+ key: content.reactionMessage.key,
212
+ }]);
262
213
  }
263
214
  else if (message.messageStubType) {
264
- const jid = message.key?.remoteJid;
215
+ const jid = message.key.remoteJid;
265
216
  //let actor = whatsappID (message.participant)
266
217
  let participants;
267
- const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
268
- id: jid,
269
- author: message.key.participant,
270
- authorPn: message.key.participantAlt,
271
- participants,
272
- action
273
- });
218
+ const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
274
219
  const emitGroupUpdate = (update) => {
275
- ev.emit('groups.update', [
276
- { id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
277
- ]);
220
+ var _a;
221
+ ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
278
222
  };
279
- const emitGroupRequestJoin = (participant, action, method) => {
280
- ev.emit('group.join-request', {
281
- id: jid,
282
- author: message.key.participant,
283
- authorPn: message.key.participantAlt,
284
- participant: participant.lid,
285
- participantPn: participant.pn,
286
- action,
287
- method: method
288
- });
289
- };
290
- const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
223
+ const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
291
224
  switch (message.messageStubType) {
292
- case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
293
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
294
- emitParticipantsUpdate('modify');
295
- break;
296
- case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
297
- case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
298
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
225
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
226
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
227
+ participants = message.messageStubParameters || [];
299
228
  emitParticipantsUpdate('remove');
300
229
  // mark the chat read only if you left the group
301
230
  if (participantsIncludesMe()) {
302
231
  chat.readOnly = true;
303
232
  }
304
233
  break;
305
- case WAMessageStubType.GROUP_PARTICIPANT_ADD:
306
- case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
307
- case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
308
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
234
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
235
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
236
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
237
+ participants = message.messageStubParameters || [];
309
238
  if (participantsIncludesMe()) {
310
239
  chat.readOnly = false;
311
240
  }
312
241
  emitParticipantsUpdate('add');
313
242
  break;
314
- case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
315
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
243
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
244
+ participants = message.messageStubParameters || [];
316
245
  emitParticipantsUpdate('demote');
317
246
  break;
318
- case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
319
- participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
247
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
248
+ participants = message.messageStubParameters || [];
320
249
  emitParticipantsUpdate('promote');
321
250
  break;
322
- case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
323
- const announceValue = message.messageStubParameters?.[0];
251
+ case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
252
+ const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
324
253
  emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
325
254
  break;
326
- case WAMessageStubType.GROUP_CHANGE_RESTRICT:
327
- const restrictValue = message.messageStubParameters?.[0];
255
+ case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
256
+ const restrictValue = (_e = message.messageStubParameters) === null || _e === void 0 ? void 0 : _e[0];
328
257
  emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
329
258
  break;
330
- case WAMessageStubType.GROUP_CHANGE_SUBJECT:
331
- const name = message.messageStubParameters?.[0];
259
+ case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
260
+ const name = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
332
261
  chat.name = name;
333
262
  emitGroupUpdate({ subject: name });
334
263
  break;
335
- case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
336
- const description = message.messageStubParameters?.[0];
337
- chat.description = description;
338
- emitGroupUpdate({ desc: description });
339
- break;
340
- case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
341
- const code = message.messageStubParameters?.[0];
264
+ case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
265
+ const code = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
342
266
  emitGroupUpdate({ inviteCode: code });
343
267
  break;
344
- case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
345
- const memberAddValue = message.messageStubParameters?.[0];
268
+ case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
269
+ const memberAddValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
346
270
  emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
347
271
  break;
348
- case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
349
- const approvalMode = message.messageStubParameters?.[0];
272
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
273
+ const approvalMode = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
350
274
  emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
351
275
  break;
352
- case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
353
- const participant = JSON.parse(message.messageStubParameters?.[0]);
354
- const action = message.messageStubParameters?.[1];
355
- const method = message.messageStubParameters?.[2];
356
- emitGroupRequestJoin(participant, action, method);
357
- break;
358
276
  }
359
- } /* else if(content?.pollUpdateMessage) {
360
- const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
277
+ }
278
+ else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
279
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
361
280
  // we need to fetch the poll creation message to get the poll enc key
362
- // TODO: make standalone, remove getMessage reference
363
- // TODO: Remove entirely
364
- const pollMsg = await getMessage(creationMsgKey)
365
- if(pollMsg) {
366
- const meIdNormalised = jidNormalizedUser(meId)
367
- const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
368
- const voterJid = getKeyAuthor(message.key, meIdNormalised)
369
- const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
370
-
281
+ const pollMsg = await getMessage(creationMsgKey);
282
+ if (pollMsg) {
283
+ const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
284
+ const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
285
+ const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
286
+ const pollEncKey = (_k = pollMsg.messageContextInfo) === null || _k === void 0 ? void 0 : _k.messageSecret;
371
287
  try {
372
- const voteMsg = decryptPollVote(
373
- content.pollUpdateMessage.vote!,
374
- {
375
- pollEncKey,
376
- pollCreatorJid,
377
- pollMsgId: creationMsgKey.id!,
378
- voterJid,
379
- }
380
- )
288
+ const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
289
+ pollEncKey,
290
+ pollCreatorJid,
291
+ pollMsgId: creationMsgKey.id,
292
+ voterJid,
293
+ });
381
294
  ev.emit('messages.update', [
382
295
  {
383
296
  key: creationMsgKey,
@@ -386,28 +299,23 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
386
299
  {
387
300
  pollUpdateMessageKey: message.key,
388
301
  vote: voteMsg,
389
- senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
302
+ senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
390
303
  }
391
304
  ]
392
305
  }
393
306
  }
394
- ])
395
- } catch(err) {
396
- logger?.warn(
397
- { err, creationMsgKey },
398
- 'failed to decrypt poll vote'
399
- )
307
+ ]);
308
+ }
309
+ catch (err) {
310
+ logger === null || logger === void 0 ? void 0 : logger.warn({ err, creationMsgKey }, 'failed to decrypt poll vote');
400
311
  }
401
- } else {
402
- logger?.warn(
403
- { creationMsgKey },
404
- 'poll creation message not found, cannot decrypt update'
405
- )
406
312
  }
407
- } */
313
+ else {
314
+ logger === null || logger === void 0 ? void 0 : logger.warn({ creationMsgKey }, 'poll creation message not found, cannot decrypt update');
315
+ }
316
+ }
408
317
  if (Object.keys(chat).length > 1) {
409
318
  ev.emit('chats.update', [chat]);
410
319
  }
411
320
  };
412
- export default processMessage;
413
- //# sourceMappingURL=process-message.js.map
321
+ exports.default = processMessage;
@@ -1,7 +1,6 @@
1
- import type { SignalRepositoryWithLIDStore } from '../Types/index.js';
2
- import type { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth.js';
3
- import { type BinaryNode, type FullJid } from '../WABinary/index.js';
4
- import type { USyncQueryResultList } from '../WAUSync/index.js';
1
+ import { SignalRepository } from '../Types';
2
+ import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
3
+ import { BinaryNode, JidWithDevice } from '../WABinary';
5
4
  export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
6
5
  export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
7
6
  [id: string]: KeyPair;
@@ -15,8 +14,8 @@ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: n
15
14
  };
16
15
  export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
17
16
  export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
18
- export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => Promise<void>;
19
- export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, myLid: string, excludeZeroDevices: boolean) => FullJid[];
17
+ export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
18
+ export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
20
19
  /**
21
20
  * get the next N keys for upload or processing
22
21
  * @param count number of pre-keys to get or generate
@@ -31,4 +30,3 @@ export declare const getNextPreKeysNode: (state: AuthenticationState, count: num
31
30
  update: Partial<AuthenticationCreds>;
32
31
  node: BinaryNode;
33
32
  }>;
34
- //# sourceMappingURL=signal.d.ts.map