@hansaka02/baileys 7.3.2 → 7.3.6

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 (210) hide show
  1. package/lib/Defaults/baileys-version.json +2 -2
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +74 -0
  4. package/lib/Defaults/history.js +19 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +5 -18
  13. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -16
  16. package/lib/Signal/Group/sender-key-state.js +15 -61
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +237 -177
  19. package/lib/Signal/lid-mapping.js +128 -71
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +25 -16
  22. package/lib/Socket/business.js +46 -33
  23. package/lib/Socket/chats.js +286 -170
  24. package/lib/Socket/community.js +215 -77
  25. package/lib/Socket/groups.js +77 -61
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +629 -457
  28. package/lib/Socket/messages-send.js +645 -656
  29. package/lib/Socket/mex.js +61 -0
  30. package/lib/Socket/newsletter.js +166 -245
  31. package/lib/Socket/socket.js +396 -170
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/Newsletter.js +32 -25
  39. package/lib/Types/State.js +4 -4
  40. package/lib/Types/index.js +28 -12
  41. package/lib/Utils/auth-utils.js +212 -375
  42. package/lib/Utils/baileys-event-stream.js +68 -69
  43. package/lib/Utils/browser-utils.js +43 -0
  44. package/lib/Utils/business.js +63 -53
  45. package/lib/Utils/chat-utils.js +241 -106
  46. package/lib/Utils/crypto.js +25 -45
  47. package/lib/Utils/decode-wa-message.js +361 -311
  48. package/lib/Utils/event-buffer.js +97 -42
  49. package/lib/Utils/generics.js +90 -207
  50. package/lib/Utils/history.js +29 -27
  51. package/lib/Utils/index.js +28 -14
  52. package/lib/Utils/link-preview.js +24 -62
  53. package/lib/Utils/logger.js +5 -5
  54. package/lib/Utils/lt-hash.js +29 -23
  55. package/lib/Utils/make-mutex.js +26 -28
  56. package/lib/Utils/message-retry-manager.js +55 -7
  57. package/lib/Utils/messages-media.js +434 -247
  58. package/lib/Utils/messages.js +963 -917
  59. package/lib/Utils/noise-handler.js +60 -20
  60. package/lib/Utils/pre-key-manager.js +126 -0
  61. package/lib/Utils/process-message.js +216 -141
  62. package/lib/Utils/signal.js +75 -37
  63. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  64. package/lib/Utils/validate-connection.js +96 -66
  65. package/lib/WABinary/constants.js +1268 -1268
  66. package/lib/WABinary/decode.js +62 -34
  67. package/lib/WABinary/encode.js +57 -36
  68. package/lib/WABinary/generic-utils.js +4 -4
  69. package/lib/WABinary/index.js +27 -11
  70. package/lib/WABinary/jid-utils.js +58 -11
  71. package/lib/WAM/constants.js +19064 -11563
  72. package/lib/WAM/encode.js +71 -14
  73. package/lib/WAM/index.js +27 -11
  74. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  75. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  76. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  77. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  78. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  79. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  80. package/lib/WAUSync/Protocols/index.js +27 -11
  81. package/lib/WAUSync/USyncQuery.js +51 -28
  82. package/lib/WAUSync/index.js +27 -11
  83. package/lib/index.js +60 -31
  84. package/package.json +12 -17
  85. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  86. package/WAProto/Adv/Adv.d.ts +0 -643
  87. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  88. package/WAProto/Cert/Cert.d.ts +0 -613
  89. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  90. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  91. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  92. package/WAProto/E2E/E2E.d.ts +0 -41724
  93. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  94. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  95. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  96. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  97. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  98. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  99. package/WAProto/Protocol/Protocol.d.ts +0 -270
  100. package/WAProto/Reporting/Reporting.d.ts +0 -371
  101. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  102. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  103. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  104. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  105. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  106. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  107. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  108. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  109. package/WAProto/Web/Web.d.ts +0 -46383
  110. package/WAProto/index.d.ts +0 -55
  111. package/lib/Defaults/index.d.ts +0 -77
  112. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  113. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  114. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  115. package/lib/Signal/Group/index.d.ts +0 -11
  116. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  117. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  118. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  119. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  120. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  121. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  122. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  123. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  124. package/lib/Signal/libsignal.d.ts +0 -8
  125. package/lib/Signal/lid-mapping.d.ts +0 -28
  126. package/lib/Socket/Client/index.d.ts +0 -2
  127. package/lib/Socket/Client/types.d.ts +0 -16
  128. package/lib/Socket/Client/websocket.d.ts +0 -13
  129. package/lib/Socket/business.d.ts +0 -187
  130. package/lib/Socket/chats.d.ts +0 -97
  131. package/lib/Socket/community.d.ts +0 -129
  132. package/lib/Socket/groups.d.ts +0 -129
  133. package/lib/Socket/index.d.ts +0 -191
  134. package/lib/Socket/messages-recv.d.ts +0 -174
  135. package/lib/Socket/messages-send.d.ts +0 -165
  136. package/lib/Socket/newsletter.d.ts +0 -145
  137. package/lib/Socket/socket.d.ts +0 -45
  138. package/lib/Socket/usync.d.ts +0 -37
  139. package/lib/Socket/usync.js +0 -83
  140. package/lib/Store/index.d.ts +0 -4
  141. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  142. package/lib/Store/make-in-memory-store.d.ts +0 -123
  143. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  144. package/lib/Store/object-repository.d.ts +0 -10
  145. package/lib/Types/Auth.d.ts +0 -121
  146. package/lib/Types/Bussiness.d.ts +0 -28
  147. package/lib/Types/Call.d.ts +0 -14
  148. package/lib/Types/Chat.d.ts +0 -143
  149. package/lib/Types/Contact.d.ts +0 -23
  150. package/lib/Types/Events.d.ts +0 -226
  151. package/lib/Types/GroupMetadata.d.ts +0 -66
  152. package/lib/Types/Label.d.ts +0 -48
  153. package/lib/Types/LabelAssociation.d.ts +0 -35
  154. package/lib/Types/Message.d.ts +0 -484
  155. package/lib/Types/MexUpdates.d.ts +0 -9
  156. package/lib/Types/Newsletter.d.ts +0 -109
  157. package/lib/Types/Product.d.ts +0 -92
  158. package/lib/Types/Signal.d.ts +0 -98
  159. package/lib/Types/Socket.d.ts +0 -141
  160. package/lib/Types/State.d.ts +0 -41
  161. package/lib/Types/USync.d.ts +0 -26
  162. package/lib/Types/index.d.ts +0 -80
  163. package/lib/Utils/auth-utils.d.ts +0 -21
  164. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  165. package/lib/Utils/business.d.ts +0 -29
  166. package/lib/Utils/chat-utils.d.ts +0 -82
  167. package/lib/Utils/crypto.d.ts +0 -56
  168. package/lib/Utils/decode-wa-message.d.ts +0 -53
  169. package/lib/Utils/event-buffer.d.ts +0 -39
  170. package/lib/Utils/generics.d.ts +0 -117
  171. package/lib/Utils/history.d.ts +0 -23
  172. package/lib/Utils/index.d.ts +0 -20
  173. package/lib/Utils/link-preview.d.ts +0 -23
  174. package/lib/Utils/logger.d.ts +0 -13
  175. package/lib/Utils/lt-hash.d.ts +0 -14
  176. package/lib/Utils/make-mutex.d.ts +0 -9
  177. package/lib/Utils/message-retry-manager.d.ts +0 -88
  178. package/lib/Utils/messages-media.d.ts +0 -135
  179. package/lib/Utils/messages.d.ts +0 -105
  180. package/lib/Utils/noise-handler.d.ts +0 -20
  181. package/lib/Utils/process-message.d.ts +0 -49
  182. package/lib/Utils/signal.d.ts +0 -42
  183. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  184. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  185. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  186. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  187. package/lib/Utils/use-single-file-auth-state.js +0 -80
  188. package/lib/Utils/validate-connection.d.ts +0 -13
  189. package/lib/WABinary/constants.d.ts +0 -30
  190. package/lib/WABinary/decode.d.ts +0 -9
  191. package/lib/WABinary/encode.d.ts +0 -3
  192. package/lib/WABinary/generic-utils.d.ts +0 -28
  193. package/lib/WABinary/index.d.ts +0 -5
  194. package/lib/WABinary/jid-utils.d.ts +0 -58
  195. package/lib/WABinary/types.d.ts +0 -22
  196. package/lib/WAM/BinaryInfo.d.ts +0 -16
  197. package/lib/WAM/constants.d.ts +0 -47
  198. package/lib/WAM/encode.d.ts +0 -3
  199. package/lib/WAM/index.d.ts +0 -3
  200. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  204. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  205. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  206. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  207. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  208. package/lib/WAUSync/USyncUser.d.ts +0 -12
  209. package/lib/WAUSync/index.d.ts +0 -3
  210. package/lib/index.d.ts +0 -13
@@ -2,38 +2,72 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const WAProto_1 = require("../../WAProto")
6
- const Types_1 = require("../Types")
7
- const messages_1 = require("../Utils/messages")
8
- const WABinary_1 = require("../WABinary")
9
- const crypto_1 = require("./crypto")
10
- const generics_1 = require("./generics")
11
- const history_1 = require("./history")
5
+ const { proto } = require("../../WAProto")
6
+ const { WAMessageStubType } = require("../Types")
7
+ const {
8
+ getDevice,
9
+ getContentType,
10
+ normalizeMessageContent
11
+ } = require("../Utils")
12
+ const {
13
+ areJidsSameUser,
14
+ isHostedLidUser,
15
+ isHostedPnUser,
16
+ isJidBroadcast,
17
+ isJidStatusBroadcast,
18
+ isLidUser,
19
+ jidDecode,
20
+ jidEncode,
21
+ jidNormalizedUser
22
+ } = require("../WABinary")
23
+ const {
24
+ aesDecryptGCM,
25
+ hmacSign
26
+ } = require("./crypto")
27
+ const {
28
+ getKeyAuthor,
29
+ toNumber
30
+ } = require("./generics")
31
+ const { downloadAndProcessHistorySyncNotification } = require("./history")
12
32
 
13
33
  const REAL_MSG_STUB_TYPES = new Set([
14
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
15
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
16
- Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
17
- Types_1.WAMessageStubType.CALL_MISSED_VOICE
34
+ WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
35
+ WAMessageStubType.CALL_MISSED_GROUP_VOICE,
36
+ WAMessageStubType.CALL_MISSED_VIDEO,
37
+ WAMessageStubType.CALL_MISSED_VOICE
18
38
  ])
19
39
 
20
40
  const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
21
- Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
41
+ WAMessageStubType.GROUP_PARTICIPANT_ADD
22
42
  ])
23
43
 
24
44
  /** Cleans a received message to further processing */
25
- const cleanMessage = (message, meId) => {
45
+ const cleanMessage = (message, meId, meLid) => {
26
46
  // ensure remoteJid and participant doesn't have device or agent in it
27
- message.key.remoteJid = WABinary_1.jidNormalizedUser(message.key.remoteJid)
28
- message.key.participant = message.key.participant ? WABinary_1.jidNormalizedUser(message.key.participant) : undefined
29
- const content = messages_1.normalizeMessageContent(message.message)
47
+ if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
48
+ message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid')
49
+ }
50
+ else {
51
+ message.key.remoteJid = jidNormalizedUser(message.key.remoteJid)
52
+ }
53
+
54
+ if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
55
+ message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid')
56
+ }
57
+ else {
58
+ message.key.participant = jidNormalizedUser(message.key.participant)
59
+ }
60
+ const content = normalizeMessageContent(message.message)
61
+
30
62
  // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
31
63
  if (content?.reactionMessage) {
32
64
  normaliseKey(content.reactionMessage.key)
33
65
  }
66
+
34
67
  if (content?.pollUpdateMessage) {
35
68
  normaliseKey(content.pollUpdateMessage.pollCreationMessageKey)
36
69
  }
70
+
37
71
  function normaliseKey(msgKey) {
38
72
  // if the reaction is from another user
39
73
  // we've to correctly map the key to this user's perspective
@@ -41,11 +75,13 @@ const cleanMessage = (message, meId) => {
41
75
  // if the sender believed the message being reacted to is not from them
42
76
  // we've to correct the key to be from them, or some other participant
43
77
  msgKey.fromMe = !msgKey.fromMe
44
- ? WABinary_1.areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId)
45
- // if the message being reacted to, was from them
46
- // fromMe automatically becomes false
47
- : false
78
+ ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
79
+ areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
80
+ : // if the message being reacted to, was from them
81
+ // fromMe automatically becomes false
82
+ false
48
83
  // set the remoteJid to being the same as the chat the message came from
84
+ // TODO: investigate inconsistencies
49
85
  msgKey.remoteJid = message.key.remoteJid
50
86
  // set participant of the message
51
87
  msgKey.participant = msgKey.participant || message.key.participant
@@ -53,32 +89,28 @@ const cleanMessage = (message, meId) => {
53
89
  }
54
90
  }
55
91
 
56
- const isRealMessage = (message, meId) => {
57
- const normalizedContent = messages_1.normalizeMessageContent(message.message)
58
- const hasSomeContent = !!messages_1.getContentType(normalizedContent)
59
- return (
60
- !!normalizedContent ||
92
+ // TODO: target:audit AUDIT THIS FUNCTION AGAIN
93
+ const isRealMessage = (message) => {
94
+ const normalizedContent = normalizeMessageContent(message.message)
95
+ const hasSomeContent = !!getContentType(normalizedContent)
96
+ return ((!!normalizedContent ||
61
97
  REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
62
- (
63
- REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType) &&
64
- message.messageStubParameters?.some(p => WABinary_1.areJidsSameUser(meId, p))
65
- )
66
- ) &&
67
- hasSomeContent &&
68
- !normalizedContent?.protocolMessage &&
69
- !normalizedContent?.reactionMessage &&
70
- !normalizedContent?.pollUpdateMessage
98
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
99
+ hasSomeContent &&
100
+ !normalizedContent?.protocolMessage &&
101
+ !normalizedContent?.reactionMessage &&
102
+ !normalizedContent?.pollUpdateMessage)
71
103
  }
72
104
 
73
- const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType)
105
+ const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType
74
106
 
75
107
  /**
76
108
  * Get the ID of the chat from the given key.
77
109
  * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
78
110
  */
79
111
  const getChatId = ({ remoteJid, participant, fromMe }) => {
80
- if (WABinary_1.isJidBroadcast(remoteJid)
81
- && !WABinary_1.isJidStatusBroadcast(remoteJid)
112
+ if (isJidBroadcast(remoteJid)
113
+ && !isJidStatusBroadcast(remoteJid)
82
114
  && !fromMe) {
83
115
  return participant
84
116
  }
@@ -99,12 +131,12 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
99
131
  toBinary('Poll Vote'),
100
132
  new Uint8Array([1])
101
133
  ])
102
- const key0 = crypto_1.hmacSign(pollEncKey, new Uint8Array(32), 'sha256')
103
- const decKey = crypto_1.hmacSign(sign, key0, 'sha256')
134
+ const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256')
135
+ const decKey = hmacSign(sign, key0, 'sha256')
104
136
  const aad = toBinary(`${pollMsgId}\u0000${voterJid}`)
105
- const decrypted = crypto_1.aesDecryptGCM(encPayload, decKey, encIv, aad)
137
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad)
106
138
 
107
- return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted)
139
+ return proto.Message.PollVoteMessage.decode(decrypted)
108
140
 
109
141
  function toBinary(txt) {
110
142
  return Buffer.from(txt)
@@ -125,11 +157,11 @@ function decryptEventEdit({ encPayload, encIv }, { eventCreatorJid, eventMsgId,
125
157
  new Uint8Array([1])
126
158
  ])
127
159
 
128
- const key0 = crypto_1.hmacSign(eventEncKey, new Uint8Array(32), 'sha256')
129
- const decKey = crypto_1.hmacSign(sign, key0, 'sha256')
130
- const decrypted = crypto_1.aesDecryptGCM(encPayload, decKey, encIv, null)
160
+ const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256')
161
+ const decKey = hmacSign(sign, key0, 'sha256')
162
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, null)
131
163
 
132
- return WAProto_1.proto.Message.decode(decrypted)
164
+ return proto.Message.decode(decrypted)
133
165
 
134
166
  function toBinary(txt) {
135
167
  return Buffer.from(txt)
@@ -151,12 +183,12 @@ function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsg
151
183
  new Uint8Array([1])
152
184
  ])
153
185
 
154
- const key0 = crypto_1.hmacSign(eventEncKey, new Uint8Array(32), 'sha256')
155
- const decKey = crypto_1.hmacSign(sign, key0, 'sha256')
186
+ const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256')
187
+ const decKey = hmacSign(sign, key0, 'sha256')
156
188
  const aad = toBinary(`${eventMsgId}\u0000${responderJid}`)
157
- const decrypted = crypto_1.aesDecryptGCM(encPayload, decKey, encIv, aad)
189
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad)
158
190
 
159
- return WAProto_1.proto.Message.EventResponseMessage.decode(decrypted)
191
+ return proto.Message.EventResponseMessage.decode(decrypted)
160
192
 
161
193
  function toBinary(txt) {
162
194
  return Buffer.from(txt)
@@ -177,11 +209,11 @@ function decryptComment({ encPayload, encIv }, { commentCreatorJid, commentMsgId
177
209
  new Uint8Array([1])
178
210
  ])
179
211
 
180
- const key0 = crypto_1.hmacSign(commentEncKey, new Uint8Array(32), 'sha256')
181
- const decKey = crypto_1.hmacSign(sign, key0, 'sha256')
182
- const decrypted = crypto_1.aesDecryptGCM(encPayload, decKey, encIv, null)
212
+ const key0 = hmacSign(commentEncKey, new Uint8Array(32), 'sha256')
213
+ const decKey = hmacSign(sign, key0, 'sha256')
214
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, null)
183
215
 
184
- return WAProto_1.proto.Message.decode(decrypted)
216
+ return proto.Message.decode(decrypted)
185
217
 
186
218
  function toBinary(txt) {
187
219
  return Buffer.from(txt)
@@ -202,11 +234,11 @@ function decryptReaction({ encPayload, encIv }, { reactionCreatorJid, reactionMs
202
234
  new Uint8Array([1])
203
235
  ])
204
236
 
205
- const key0 = crypto_1.hmacSign(reactionEncKey, new Uint8Array(32), 'sha256')
206
- const decKey = crypto_1.hmacSign(sign, key0, 'sha256')
207
- const decrypted = crypto_1.aesDecryptGCM(encPayload, decKey, encIv, null)
237
+ const key0 = hmacSign(reactionEncKey, new Uint8Array(32), 'sha256')
238
+ const decKey = hmacSign(sign, key0, 'sha256')
239
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, null)
208
240
 
209
- return WAProto_1.proto.Message.ReactionMessage.decode(decrypted)
241
+ return proto.Message.ReactionMessage.decode(decrypted)
210
242
 
211
243
  function toBinary(txt) {
212
244
  return Buffer.from(txt)
@@ -217,17 +249,17 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
217
249
  const meId = creds.me.id
218
250
  const meLid = creds.me.lid
219
251
  const { accountSettings } = creds
220
- const chat = { id: WABinary_1.jidNormalizedUser(getChatId(message.key)) }
221
- const isRealMsg = isRealMessage(message, meId)
252
+ const chat = { id: jidNormalizedUser(getChatId(message.key)) }
253
+ const isRealMsg = isRealMessage(message)
222
254
  if (isRealMsg) {
223
255
  chat.messages = [{ message }]
224
- chat.conversationTimestamp = generics_1.toNumber(message.messageTimestamp)
256
+ chat.conversationTimestamp = toNumber(message.messageTimestamp)
225
257
  // only increment unread count if not CIPHERTEXT and from another person
226
258
  if (shouldIncrementChatUnread(message)) {
227
259
  chat.unreadCount = (chat.unreadCount || 0) + 1
228
260
  }
229
261
  }
230
- const content = messages_1.normalizeMessageContent(message.message)
262
+ const content = normalizeMessageContent(message.message)
231
263
  // unarchive chat if it's a real message, or someone reacted to our message
232
264
  // and we've the unarchive chats setting on
233
265
  if (isRealMsg || content?.reactionMessage?.key?.fromMe
@@ -238,18 +270,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
238
270
  const protocolMsg = content?.protocolMessage
239
271
  if (protocolMsg) {
240
272
  switch (protocolMsg.type) {
241
- case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
273
+ case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
242
274
  const histNotification = protocolMsg.historySyncNotification
243
275
  const process = shouldProcessHistoryMsg
244
276
  const isLatest = !creds.processedHistoryMessages?.length
277
+
245
278
  logger?.info({
246
279
  histNotification,
247
280
  process,
248
281
  id: message.key.id,
249
- isLatest,
282
+ isLatest
250
283
  }, 'got history notification')
284
+
251
285
  if (process) {
252
- if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
286
+ // TODO: investigate
287
+ if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
253
288
  ev.emit('creds.update', {
254
289
  processedHistoryMessages: [
255
290
  ...(creds.processedHistoryMessages || []),
@@ -257,65 +292,77 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
257
292
  ]
258
293
  })
259
294
  }
260
- const data = await history_1.downloadAndProcessHistorySyncNotification(histNotification, options)
295
+
296
+ const data = await downloadAndProcessHistorySyncNotification(histNotification, options)
261
297
  ev.emit('messaging-history.set', {
262
298
  ...data,
263
- isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
264
- ? isLatest
265
- : undefined,
299
+ isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
266
300
  peerDataRequestSessionId: histNotification.peerDataRequestSessionId
267
301
  })
268
302
  }
269
303
  break
270
- case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
304
+ case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
271
305
  const keys = protocolMsg.appStateSyncKeyShare.keys
306
+
272
307
  if (keys?.length) {
273
308
  let newAppStateSyncKeyId = ''
309
+
274
310
  await keyStore.transaction(async () => {
275
311
  const newKeys = []
312
+
276
313
  for (const { keyData, keyId } of keys) {
277
314
  const strKeyId = Buffer.from(keyId.keyId).toString('base64')
315
+
278
316
  newKeys.push(strKeyId)
317
+
279
318
  await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } })
319
+
280
320
  newAppStateSyncKeyId = strKeyId
281
321
  }
322
+
282
323
  logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys')
283
324
  }, meId)
284
325
  ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId })
285
326
  }
327
+
286
328
  else {
287
329
  logger?.info({ protocolMsg }, 'recv app state sync with 0 keys')
288
330
  }
289
331
  break
290
- case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
332
+ case proto.Message.ProtocolMessage.Type.REVOKE:
291
333
  ev.emit('messages.update', [
292
334
  {
293
335
  key: {
294
336
  ...message.key,
295
337
  id: protocolMsg.key.id
296
338
  },
297
- update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
339
+ update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
298
340
  }
299
341
  ])
300
342
  break
301
- case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
343
+ case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
302
344
  Object.assign(chat, {
303
- ephemeralSettingTimestamp: generics_1.toNumber(message.messageTimestamp),
345
+ ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
304
346
  ephemeralExpiration: protocolMsg.ephemeralExpiration || null
305
347
  })
306
348
  break
307
- case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
349
+ case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
308
350
  const response = protocolMsg.peerDataOperationRequestResponseMessage
351
+
309
352
  if (response) {
310
- await laceholderResendCache?.del(response.stanzaId)
353
+ await placeholderResendCache?.del(response.stanzaId)
354
+
311
355
  // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
312
356
  const { peerDataOperationResult } = response
357
+
313
358
  for (const result of peerDataOperationResult) {
314
359
  const { placeholderMessageResendResponse: retryResponse } = result
360
+
315
361
  //eslint-disable-next-line max-depth
316
362
  if (retryResponse) {
317
- const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes)
363
+ const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes)
318
364
  // wait till another upsert event is available, don't want it to be part of the PDO response message
365
+ // TODO: parse through proper message handling utilities (to add relevant key fields)
319
366
  setTimeout(() => {
320
367
  ev.emit('messages.upsert', {
321
368
  messages: [webMessageInfo],
@@ -327,7 +374,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
327
374
  }
328
375
  }
329
376
  break
330
- case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
377
+ case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
331
378
  ev.emit('messages.update', [
332
379
  {
333
380
  // flip the sender / fromMe properties because they're in the perspective of the sender
@@ -339,15 +386,29 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
339
386
  }
340
387
  },
341
388
  messageTimestamp: protocolMsg.timestampMs
342
- ? Math.floor(generics_1.toNumber(protocolMsg.timestampMs) / 1000)
389
+ ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
343
390
  : message.messageTimestamp
344
391
  }
345
392
  }
346
393
  ])
347
394
  break
348
- case WAProto_1.proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
395
+ case proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
396
+ const labelAssociationMsg = protocolMsg.memberLabel
397
+
398
+ if (labelAssociationMsg?.label) {
399
+ ev.emit('group.member-tag.update', {
400
+ groupId: chat.id,
401
+ label: labelAssociationMsg.label,
402
+ participant: message.key.participant,
403
+ participantAlt: message.key.participantAlt,
404
+ messageTimestamp: Number(message.messageTimestamp)
405
+ })
406
+ }
407
+ break
408
+ case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
349
409
  const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload
350
- const { pnToLidMappings, chatDbMigrationTimestamp } = WAProto_1.proto.LIDMigrationMappingSyncPayload.decode(encodedPayload)
410
+
411
+ const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload)
351
412
 
352
413
  logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp')
353
414
 
@@ -359,11 +420,17 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
359
420
  }
360
421
 
361
422
  await signalRepository.lidMapping.storeLIDPNMappings(pairs)
423
+
424
+ if (pairs.length) {
425
+ for (const { pn, lid } of pairs) {
426
+ await signalRepository.migrateSession(pn, lid)
427
+ }
428
+ }
362
429
  break
363
- case WAProto_1.proto.Message.ProtocolMessage.Type.LIMIT_SHARING:
430
+ case proto.Message.ProtocolMessage.Type.LIMIT_SHARING:
364
431
  ev.emit('limit-sharing.update', {
365
432
  id: message.key.remoteJid,
366
- author: WABinary_1.areJidsSameUser(message.key.remoteJid, protocolMsg.key.remoteJid) ? WABinary_1.jidNormalizedUser(meId) : message.key.remoteJid,
433
+ author: areJidsSameUser(message.key.remoteJid, protocolMsg.key.remoteJid) ? jidNormalizedUser(meId) : message.key.remoteJid,
367
434
  action: `${protocolMsg.limitSharing.sharingLimited ? 'on' : 'off'}`,
368
435
  trigger: protocolMsg.limitSharing.trigger,
369
436
  update_time: protocolMsg.limitSharing.limitSharingSettingTimestamp
@@ -383,94 +450,102 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
383
450
  }
384
451
  else if (message.messageStubType) {
385
452
  const jid = message.key?.remoteJid
386
- //let actor = whatsappID (message.participant)
453
+
387
454
  let participants
388
- const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }))
455
+
456
+ const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
457
+ id: jid,
458
+ author: message.key.participant,
459
+ authorPn: message.key.participantAlt,
460
+ participants,
461
+ action
462
+ })
463
+
389
464
  const emitGroupUpdate = (update) => {
390
- ev.emit('groups.update', [{ id: jid, ...update, author: message.participant ? message.participant : undefined }])
465
+ ev.emit('groups.update', [
466
+ { id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
467
+ ])
391
468
  }
469
+
392
470
  const emitGroupRequestJoin = (participant, action, method) => {
393
- ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method })
471
+ ev.emit('group.join-request', {
472
+ id: jid,
473
+ author: message.key.participant,
474
+ authorPn: message.key.participantAlt,
475
+ participant: participant.lid,
476
+ participantPn: participant.pn,
477
+ action,
478
+ method: method
479
+ })
394
480
  }
395
- const participantsIncludesMe = () => participants.find(jid => WABinary_1.areJidsSameUser(meId, jid))
481
+
482
+ const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)) // ADD SUPPORT FOR LID
396
483
  switch (message.messageStubType) {
397
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
398
- participants = message.messageStubParameters || []
484
+ case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
485
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
399
486
  emitParticipantsUpdate('modify')
400
487
  break
401
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
402
- participants = message.messageStubParameters || [];
403
- emitParticipantsUpdate('leave');
404
- // mark the chat read only if you left the group
405
- if (participantsIncludesMe()) {
406
- chat.readOnly = true;
407
- }
408
- break;
409
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
410
- participants = message.messageStubParameters || []
488
+ case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
489
+ case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
490
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
411
491
  emitParticipantsUpdate('remove')
492
+
412
493
  // mark the chat read only if you left the group
413
494
  if (participantsIncludesMe()) {
414
495
  chat.readOnly = true
415
496
  }
416
497
  break
417
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
418
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
419
- let actionGp = 'invite'
420
- participants = message.messageStubParameters || []
421
- if (participantsIncludesMe()) chat.readOnly = false;
422
- if (message?.key?.participant && !participants.includes(message?.key?.participant)) {
423
- actionGp = 'approval-invite'
424
- }
425
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
426
- participants = message.messageStubParameters || []
498
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD:
499
+ case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
500
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
501
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
502
+
427
503
  if (participantsIncludesMe()) {
428
504
  chat.readOnly = false
429
505
  }
506
+
430
507
  emitParticipantsUpdate('add')
431
508
  break
432
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
433
- case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_DEMOTE:
434
- participants = message.messageStubParameters || []
509
+ case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
510
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
435
511
  emitParticipantsUpdate('demote')
436
512
  break
437
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
438
- case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_PROMOTE:
439
- participants = message.messageStubParameters || []
513
+ case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
514
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || []
440
515
  emitParticipantsUpdate('promote')
441
516
  break
442
- case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
517
+ case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
443
518
  const announceValue = message.messageStubParameters?.[0]
444
519
  emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' })
445
520
  break
446
- case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
521
+ case WAMessageStubType.GROUP_CHANGE_RESTRICT:
447
522
  const restrictValue = message.messageStubParameters?.[0]
448
523
  emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' })
449
524
  break
450
- case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
525
+ case WAMessageStubType.GROUP_CHANGE_SUBJECT:
451
526
  const name = message.messageStubParameters?.[0]
452
527
  chat.name = name
453
528
  emitGroupUpdate({ subject: name })
454
529
  break
455
- case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
530
+ case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
456
531
  const description = message.messageStubParameters?.[0]
457
532
  chat.description = description
458
533
  emitGroupUpdate({ desc: description })
459
534
  break
460
- case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
535
+ case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
461
536
  const code = message.messageStubParameters?.[0]
462
537
  emitGroupUpdate({ inviteCode: code })
463
538
  break
464
- case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
539
+ case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
465
540
  const memberAddValue = message.messageStubParameters?.[0]
466
541
  emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' })
467
542
  break
468
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
543
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
469
544
  const approvalMode = message.messageStubParameters?.[0]
470
545
  emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' })
471
546
  break
472
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
473
- const participant = message.messageStubParameters?.[0]
547
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
548
+ const participant = JSON.parse(message.messageStubParameters?.[0])
474
549
  const action = message.messageStubParameters?.[1]
475
550
  const method = message.messageStubParameters?.[2]
476
551
  emitGroupRequestJoin(participant, action, method)
@@ -485,13 +560,13 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
485
560
  const pollMsg = await getMessage(creationMsgKey)
486
561
  if (pollMsg) {
487
562
  try {
488
- const meLidNormalised = WABinary_1.jidNormalizedUser(meLid)
489
- const getDevice = messages_1.getDevice(creationMsgKey.id)
490
- const pollCreationFromMe = getDevice === 'baileys' ? true : false
563
+ const meLidNormalised = jidNormalizedUser(meLid)
564
+ const deviceType = getDevice(creationMsgKey.id)
565
+ const pollCreationFromMe = deviceType === 'baileys' ? true : false
491
566
  const pollEncKey = pollMsg.messageContextInfo?.messageSecret
492
- const voterJid = generics_1.getKeyAuthor(message.key, meLidNormalised)
567
+ const voterJid = getKeyAuthor(message.key, meLidNormalised)
493
568
 
494
- let pollCreatorJid = generics_1.getKeyAuthor(creationMsgKey, meLidNormalised)
569
+ let pollCreatorJid = getKeyAuthor(creationMsgKey, meLidNormalised)
495
570
 
496
571
  if (pollCreationFromMe) {
497
572
  pollCreatorJid = meLidNormalised
@@ -535,15 +610,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
535
610
  const encEventEdit = content.secretEncryptedMessage
536
611
  const creationMsgKey = encEventEdit.targetMessageKey
537
612
 
538
- if (WAProto_1.proto.Message.SecretEncryptedMessage.SecretEncType[encEventEdit.secretEncType] !== 'EVENT_EDIT') return
613
+ if (proto.Message.SecretEncryptedMessage.SecretEncType[encEventEdit.secretEncType] !== 'EVENT_EDIT') return
539
614
 
540
615
  // we need to fetch the event creation message to get the event enc key
541
616
  const eventMsg = await getMessage(creationMsgKey)
542
617
  if (eventMsg) {
543
618
  try {
544
- const meLidNormalised = WABinary_1.jidNormalizedUser(meLid)
545
- const eventCreatorJid = generics_1.getKeyAuthor(message.key, meLidNormalised)
546
- const responderJid = generics_1.getKeyAuthor(message.key, meLidNormalised)
619
+ const meLidNormalised = jidNormalizedUser(meLid)
620
+ const eventCreatorJid = getKeyAuthor(message.key, meLidNormalised)
621
+ const responderJid = getKeyAuthor(message.key, meLidNormalised)
547
622
  const eventEncKey = eventMsg.messageContextInfo?.messageSecret
548
623
 
549
624
  if (!eventEncKey) {
@@ -555,7 +630,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
555
630
  eventMsgId: creationMsgKey.id,
556
631
  responderJid
557
632
  })
558
- const content = messages_1.normalizeMessageContent(responseMsg)
633
+ const content = normalizeMessageContent(responseMsg)
559
634
  const protocolMsg = content?.protocolMessage
560
635
 
561
636
  ev.emit('messages.update', [
@@ -569,7 +644,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
569
644
  }
570
645
  },
571
646
  messageTimestamp: protocolMsg.timestampMs
572
- ? Math.floor(generics_1.toNumber(protocolMsg.timestampMs) / 1000)
647
+ ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
573
648
  : message.messageTimestamp
574
649
  }
575
650
  }
@@ -592,9 +667,9 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
592
667
  const eventMsg = await getMessage(creationMsgKey)
593
668
  if (eventMsg) {
594
669
  try {
595
- const meLidNormalised = WABinary_1.jidNormalizedUser(meLid)
596
- const eventCreatorJid = generics_1.getKeyAuthor(creationMsgKey, meLidNormalised)
597
- const responderJid = generics_1.getKeyAuthor(message.key, meLidNormalised)
670
+ const meLidNormalised = jidNormalizedUser(meLid)
671
+ const eventCreatorJid = getKeyAuthor(creationMsgKey, meLidNormalised)
672
+ const responderJid = getKeyAuthor(message.key, meLidNormalised)
598
673
  const eventEncKey = eventMsg.messageContextInfo?.messageSecret
599
674
 
600
675
  if (!eventEncKey) {
@@ -635,11 +710,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
635
710
  const encComment = content.encCommentMessage
636
711
  const creationMsgKey = encComment.targetMessageKey
637
712
 
638
- // we need to fetch the message to get the reaction enc key
713
+ // we need to fetch the message to get the comment enc key
639
714
  const commentMsg = await getMessage(creationMsgKey)
640
715
  if (commentMsg) {
641
716
  try {
642
- const meLidNormalised = WABinary_1.jidNormalizedUser(meLid)
717
+ const meLidNormalised = jidNormalizedUser(meLid)
643
718
  const commentCreatorJid = creationMsgKey.participant ? creationMsgKey.participant : message.key?.participant ? message.key.participant : meLidNormalised
644
719
  const commentJid = message.key?.participant ? message.key.participant : creationMsgKey.participant ? creationMsgKey.participant : meLidNormalised
645
720
  const commentEncKey = commentMsg.messageContextInfo?.messageSecret
@@ -679,7 +754,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
679
754
  const reactMsg = await getMessage(creationMsgKey)
680
755
  if (reactMsg) {
681
756
  try {
682
- const meLidNormalised = WABinary_1.jidNormalizedUser(meLid)
757
+ const meLidNormalised = jidNormalizedUser(meLid)
683
758
  const reactionCreatorJid = creationMsgKey.participant ? creationMsgKey.participant : message.key?.participant ? message.key.participant : meLidNormalised
684
759
  const reactionJid = message.key?.participant ? message.key.participant : creationMsgKey.participant ? creationMsgKey.participant : meLidNormalised
685
760
  const reactionEncKey = reactMsg.messageContextInfo?.messageSecret