sanka-baileyss 2.3.2 → 2.3.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 (159) hide show
  1. package/WAProto/BotMetadata/BotMetadata.d.ts +594 -1
  2. package/WAProto/BotMetadata/BotMetadata.js +1910 -148
  3. package/WAProto/BotMetadata/BotMetadata.proto +36 -0
  4. package/WAProto/E2E/E2E.d.ts +570 -6
  5. package/WAProto/E2E/E2E.js +1591 -26
  6. package/WAProto/E2E/E2E.proto +10 -1
  7. package/WAProto/HistorySync/HistorySync.d.ts +806 -6
  8. package/WAProto/HistorySync/HistorySync.js +2193 -29
  9. package/WAProto/HistorySync/HistorySync.proto +2 -1
  10. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +570 -6
  11. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1591 -26
  12. package/WAProto/StatusAttributions/StatusAttributions.d.ts +2 -1
  13. package/WAProto/StatusAttributions/StatusAttributions.js +7 -0
  14. package/WAProto/StatusAttributions/StatusAttributions.proto +1 -0
  15. package/WAProto/SyncAction/SyncAction.d.ts +230 -0
  16. package/WAProto/SyncAction/SyncAction.js +578 -2
  17. package/WAProto/SyncAction/SyncAction.proto +13 -1
  18. package/WAProto/Web/Web.d.ts +570 -6
  19. package/WAProto/Web/Web.js +1591 -26
  20. package/lib/Defaults/baileys-version.json +2 -2
  21. package/lib/Defaults/index.d.ts +42 -25
  22. package/lib/Defaults/index.js +6 -2
  23. package/lib/Signal/Group/sender-key-record.js +23 -28
  24. package/lib/Signal/libsignal.d.ts +1 -0
  25. package/lib/Socket/Client/index.js +13 -9
  26. package/lib/Socket/Client/types.d.ts +11 -10
  27. package/lib/Socket/Client/types.js +11 -7
  28. package/lib/Socket/Client/websocket.d.ts +9 -8
  29. package/lib/Socket/Client/websocket.js +52 -47
  30. package/lib/Socket/business.d.ts +185 -182
  31. package/lib/Socket/business.js +258 -249
  32. package/lib/Socket/chats.d.ts +90 -87
  33. package/lib/Socket/chats.js +1095 -888
  34. package/lib/Socket/community.d.ts +131 -0
  35. package/lib/Socket/community.js +369 -0
  36. package/lib/Socket/groups.d.ts +50 -41
  37. package/lib/Socket/groups.js +10 -3
  38. package/lib/Socket/index.d.ts +5 -1
  39. package/lib/Socket/index.js +19 -5
  40. package/lib/Socket/messages-recv.d.ts +6 -2
  41. package/lib/Socket/messages-recv.js +31 -8
  42. package/lib/Socket/messages-send.d.ts +5 -1
  43. package/lib/Socket/messages-send.js +1293 -1351
  44. package/lib/Socket/newsletter.d.ts +142 -135
  45. package/lib/Socket/newsletter.js +274 -230
  46. package/lib/Socket/socket.d.ts +37 -35
  47. package/lib/Socket/usync.d.ts +31 -30
  48. package/lib/Socket/usync.js +74 -62
  49. package/lib/Types/Auth.d.ts +89 -72
  50. package/lib/Types/Auth.js +1 -0
  51. package/lib/Types/Call.d.ts +11 -10
  52. package/lib/Types/Call.js +1 -0
  53. package/lib/Types/Chat.d.ts +85 -62
  54. package/lib/Types/Chat.js +4 -1
  55. package/lib/Types/Contact.js +1 -0
  56. package/lib/Types/Events.d.ts +209 -191
  57. package/lib/Types/Events.js +1 -0
  58. package/lib/Types/GroupMetadata.d.ts +12 -27
  59. package/lib/Types/GroupMetadata.js +1 -0
  60. package/lib/Types/Label.d.ts +41 -39
  61. package/lib/Types/Label.js +24 -21
  62. package/lib/Types/LabelAssociation.d.ts +18 -12
  63. package/lib/Types/LabelAssociation.js +6 -3
  64. package/lib/Types/Message.d.ts +3 -2
  65. package/lib/Types/Message.js +7 -3
  66. package/lib/Types/MexUpdates.d.ts +9 -0
  67. package/lib/Types/MexUpdates.js +18 -0
  68. package/lib/Types/Newsletter.d.ts +84 -67
  69. package/lib/Types/Newsletter.js +30 -23
  70. package/lib/Types/Product.d.ts +70 -56
  71. package/lib/Types/Product.js +1 -0
  72. package/lib/Types/Signal.d.ts +46 -35
  73. package/lib/Types/Signal.js +1 -0
  74. package/lib/Types/Socket.d.ts +105 -101
  75. package/lib/Types/Socket.js +1 -0
  76. package/lib/Types/State.d.ts +37 -23
  77. package/lib/Types/State.js +13 -1
  78. package/lib/Types/USync.d.ts +21 -20
  79. package/lib/Types/USync.js +1 -0
  80. package/lib/Types/index.d.ts +51 -42
  81. package/lib/Types/index.js +25 -19
  82. package/lib/Utils/auth-utils.d.ts +14 -11
  83. package/lib/Utils/auth-utils.js +189 -182
  84. package/lib/Utils/baileys-event-stream.d.ts +12 -10
  85. package/lib/Utils/baileys-event-stream.js +52 -46
  86. package/lib/Utils/business.d.ts +15 -8
  87. package/lib/Utils/business.js +229 -217
  88. package/lib/Utils/chat-utils.d.ts +22 -12
  89. package/lib/Utils/chat-utils.js +57 -27
  90. package/lib/Utils/crypto.d.ts +31 -15
  91. package/lib/Utils/crypto.js +136 -107
  92. package/lib/Utils/decode-wa-message.d.ts +34 -245
  93. package/lib/Utils/decode-wa-message.js +205 -217
  94. package/lib/Utils/event-buffer.d.ts +30 -26
  95. package/lib/Utils/event-buffer.js +519 -515
  96. package/lib/Utils/history.d.ts +2 -8
  97. package/lib/Utils/index.js +13 -9
  98. package/lib/Utils/link-preview.d.ts +16 -14
  99. package/lib/Utils/link-preview.js +100 -92
  100. package/lib/Utils/logger.d.ts +9 -7
  101. package/lib/Utils/logger.js +1 -1
  102. package/lib/Utils/lt-hash.d.ts +10 -8
  103. package/lib/Utils/lt-hash.js +49 -44
  104. package/lib/Utils/make-mutex.d.ts +4 -2
  105. package/lib/Utils/make-mutex.js +43 -39
  106. package/lib/Utils/messages-media.d.ts +75 -50
  107. package/lib/Utils/messages.d.ts +60 -35
  108. package/lib/Utils/messages.js +87 -8
  109. package/lib/Utils/noise-handler.d.ts +13 -12
  110. package/lib/Utils/noise-handler.js +143 -138
  111. package/lib/Utils/process-message.d.ts +32 -24
  112. package/lib/Utils/process-message.js +387 -367
  113. package/lib/Utils/signal.d.ts +24 -15
  114. package/lib/Utils/signal.js +143 -131
  115. package/lib/Utils/use-mongo-file-auth-state.d.ts +3 -2
  116. package/lib/Utils/use-mongo-file-auth-state.js +72 -63
  117. package/lib/Utils/use-multi-file-auth-state.d.ts +9 -8
  118. package/lib/Utils/use-multi-file-auth-state.js +110 -102
  119. package/lib/Utils/use-single-file-auth-state.d.ts +8 -7
  120. package/lib/Utils/use-single-file-auth-state.js +66 -61
  121. package/lib/Utils/validate-connection.d.ts +5 -2
  122. package/lib/Utils/validate-connection.js +7 -6
  123. package/lib/WABinary/constants.d.ts +24 -21
  124. package/lib/WABinary/constants.js +1302 -31
  125. package/lib/WABinary/decode.d.ts +4 -1
  126. package/lib/WABinary/decode.js +267 -234
  127. package/lib/WABinary/encode.d.ts +1 -0
  128. package/lib/WABinary/encode.js +248 -226
  129. package/lib/WABinary/generic-utils.d.ts +13 -1
  130. package/lib/WABinary/generic-utils.js +113 -96
  131. package/lib/WABinary/index.js +13 -9
  132. package/lib/WABinary/jid-utils.d.ts +23 -4
  133. package/lib/WABinary/jid-utils.js +58 -39
  134. package/lib/WABinary/types.d.ts +15 -11
  135. package/lib/WABinary/types.js +1 -0
  136. package/lib/WAM/BinaryInfo.d.ts +14 -14
  137. package/lib/WAM/BinaryInfo.js +11 -8
  138. package/lib/WAM/constants.d.ts +34 -26
  139. package/lib/WAM/constants.js +15358 -15349
  140. package/lib/WAM/encode.d.ts +1 -0
  141. package/lib/WAM/encode.js +153 -144
  142. package/lib/WAM/index.js +13 -9
  143. package/lib/index.js +11 -11
  144. package/package.json +1 -66
  145. package/WASignalGroup/GroupProtocol.js +0 -1771
  146. package/WASignalGroup/ciphertext_message.js +0 -10
  147. package/WASignalGroup/group_cipher.js +0 -103
  148. package/WASignalGroup/group_session_builder.js +0 -39
  149. package/WASignalGroup/index.js +0 -5
  150. package/WASignalGroup/keyhelper.js +0 -17
  151. package/WASignalGroup/protobufs.js +0 -2
  152. package/WASignalGroup/queue_job.js +0 -64
  153. package/WASignalGroup/sender_chain_key.js +0 -38
  154. package/WASignalGroup/sender_key_distribution_message.js +0 -68
  155. package/WASignalGroup/sender_key_message.js +0 -79
  156. package/WASignalGroup/sender_key_name.js +0 -59
  157. package/WASignalGroup/sender_key_record.js +0 -47
  158. package/WASignalGroup/sender_key_state.js +0 -110
  159. package/WASignalGroup/sender_message_key.js +0 -30
@@ -1,232 +1,220 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
+
3
5
  const boom_1 = require("@hapi/boom")
4
6
  const WAProto_1 = require("../../WAProto")
5
7
  const WABinary_1 = require("../WABinary")
6
8
  const generics_1 = require("./generics")
7
9
  const messages_1 = require("./messages")
10
+
8
11
  const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
12
+
9
13
  const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
14
+
10
15
  const NACK_REASONS = {
11
- ParsingError: 487,
12
- UnrecognizedStanza: 488,
13
- UnrecognizedStanzaClass: 489,
14
- UnrecognizedStanzaType: 490,
15
- InvalidProtobuf: 491,
16
- InvalidHostedCompanionStanza: 493,
17
- MissingMessageSecret: 495,
18
- SignalErrorOldCounter: 496,
19
- MessageDeletedOnPeer: 499,
20
- UnhandledError: 500,
21
- UnsupportedAdminRevoke: 550,
22
- UnsupportedLIDGroup: 551,
23
- DBOperationFailed: 552
24
- }
16
+ ParsingError: 487,
17
+ UnrecognizedStanza: 488,
18
+ UnrecognizedStanzaClass: 489,
19
+ UnrecognizedStanzaType: 490,
20
+ InvalidProtobuf: 491,
21
+ InvalidHostedCompanionStanza: 493,
22
+ MissingMessageSecret: 495,
23
+ SignalErrorOldCounter: 496,
24
+ MessageDeletedOnPeer: 499,
25
+ UnhandledError: 500,
26
+ UnsupportedAdminRevoke: 550,
27
+ UnsupportedLIDGroup: 551,
28
+ DBOperationFailed: 552
29
+ }
30
+
25
31
  /**
26
- * Decode the received node as a message.
27
- * @note this will only parse the message, not decrypt it
28
- */
32
+ * Decode the received node as a message.
33
+ * @note this will only parse the message, not decrypt it
34
+ */
29
35
  function decodeMessageNode(stanza, meId, meLid) {
30
- let msgType
31
- let chatId
32
- let author
33
- const msgId = stanza.attrs.id
34
- const from = stanza.attrs.from
35
- const participant = stanza.attrs.participant
36
- const recipient = stanza.attrs.recipient
37
- const isMe = (jid) => WABinary_1.areJidsSameUser(jid, meId)
38
- const isMeLid = (jid) => WABinary_1.areJidsSameUser(jid, meLid)
39
- if (WABinary_1.isJidUser(from)) {
40
- if (recipient) {
41
- if (!isMe(from)) {
42
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
43
- }
44
- chatId = recipient
45
- }
46
- else {
47
- chatId = from
48
- }
49
- msgType = 'chat'
50
- author = from
51
- }
52
- else if (WABinary_1.isLidUser(from)) {
53
- if (recipient) {
54
- if (!isMeLid(from)) {
55
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
56
- }
57
- chatId = recipient
58
- }
59
- else {
60
- chatId = from
61
- }
62
- msgType = 'chat'
63
- author = from
64
- }
65
- else if (WABinary_1.isJidGroup(from)) {
66
- if (!participant) {
67
- throw new boom_1.Boom('No participant in group message')
68
- }
69
- msgType = 'group'
70
- author = participant
71
- chatId = from
72
- }
73
- else if (WABinary_1.isJidBroadcast(from)) {
74
- if (!participant) {
75
- throw new boom_1.Boom('No participant in group message')
76
- }
77
- const isParticipantMe = isMe(participant)
78
- if (WABinary_1.isJidStatusBroadcast(from)) {
79
- msgType = isParticipantMe ? 'direct_peer_status' : 'other_status'
80
- }
81
- else {
82
- msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast'
83
- }
84
- chatId = from
85
- author = participant
86
- }
87
- else if (WABinary_1.isJidNewsletter(from)) {
88
- msgType = 'newsletter'
89
- chatId = from
90
- author = from
91
- }
92
- else {
93
- throw new boom_1.Boom('Unknown message type', { data: stanza })
94
- }
95
- const fromMe = WABinary_1.isJidNewsletter(from) ? !!stanza.attrs?.is_sender : WABinary_1.isLidUser(from) ? isMeLid(stanza.attrs.participant || stanza.attrs.from) : isMe(stanza.attrs.participant || stanza.attrs.from)
96
- const pushname = stanza?.attrs?.notify
97
- const key = {
98
- remoteJid: chatId,
99
- fromMe,
100
- id: msgId,
101
- participant
102
- }
103
- const fullMessage = {
104
- key,
105
- messageTimestamp: +stanza.attrs.t,
106
- pushName: pushname,
107
- broadcast: WABinary_1.isJidBroadcast(from),
108
- newsletter: WABinary_1.isJidNewsletter(from)
109
- }
110
- if (msgType === 'newsletter') {
111
- fullMessage.newsletter_server_id = +stanza.attrs?.server_id
112
- }
113
- if (key.fromMe) {
114
- fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK
115
- }
116
- if (!key.fromMe) {
117
- fullMessage.platform = messages_1.getDevice(key.id)
118
- }
119
- return {
120
- fullMessage,
121
- author,
122
- sender: msgType === 'chat' ? author : chatId
123
- }
124
- }
36
+ let msgType
37
+ let chatId
38
+ let author
39
+ const msgId = stanza.attrs.id
40
+ const from = stanza.attrs.from
41
+ const participant = stanza.attrs.participant
42
+ const recipient = stanza.attrs.recipient
43
+ const isMe = (jid) => WABinary_1.areJidsSameUser(jid, meId)
44
+ const isMeLid = (jid) => WABinary_1.areJidsSameUser(jid, meLid)
45
+ if (WABinary_1.isJidUser(from)) {
46
+ if (recipient) {
47
+ if (!isMe(from)) {
48
+ throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
49
+ }
50
+ chatId = recipient
51
+ }
52
+ else {
53
+ chatId = from
54
+ }
55
+ msgType = 'chat'
56
+ author = from
57
+ }
58
+ else if (WABinary_1.isLidUser(from)) {
59
+ if (recipient) {
60
+ if (!isMeLid(from)) {
61
+ throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
62
+ }
63
+ chatId = recipient
64
+ }
65
+ else {
66
+ chatId = from
67
+ }
68
+ msgType = 'chat'
69
+ author = from
70
+ }
71
+ else if (WABinary_1.isJidGroup(from)) {
72
+ if (!participant) {
73
+ throw new boom_1.Boom('No participant in group message')
74
+ }
75
+ msgType = 'group'
76
+ author = participant
77
+ chatId = from
78
+ }
79
+ else if (WABinary_1.isJidBroadcast(from)) {
80
+ if (!participant) {
81
+ throw new boom_1.Boom('No participant in group message')
82
+ }
83
+ const isParticipantMe = isMe(participant)
84
+ if (WABinary_1.isJidStatusBroadcast(from)) {
85
+ msgType = isParticipantMe ? 'direct_peer_status' : 'other_status'
86
+ }
87
+ else {
88
+ msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast'
89
+ }
90
+ chatId = from
91
+ author = participant
92
+ }
93
+ else if (WABinary_1.isJidNewsletter(from)) {
94
+ msgType = 'newsletter'
95
+ chatId = from
96
+ author = from
97
+ }
98
+ else {
99
+ throw new boom_1.Boom('Unknown message type', { data: stanza })
100
+ }
101
+ const fromMe = WABinary_1.isJidNewsletter(from) ? !!stanza.attrs?.is_sender : WABinary_1.isLidUser(from) ? isMeLid(stanza.attrs.participant || stanza.attrs.from) : isMe(stanza.attrs.participant || stanza.attrs.from)
102
+ const pushname = stanza?.attrs?.notify
103
+ const key = {
104
+ remoteJid: chatId,
105
+ fromMe,
106
+ id: msgId,
107
+ participant
108
+ }
109
+ const fullMessage = {
110
+ key,
111
+ messageTimestamp: +stanza.attrs.t,
112
+ pushName: pushname,
113
+ broadcast: WABinary_1.isJidBroadcast(from),
114
+ newsletter: WABinary_1.isJidNewsletter(from)
115
+ }
116
+ if (msgType === 'newsletter') {
117
+ fullMessage.newsletter_server_id = +stanza.attrs?.server_id
118
+ }
119
+ if (key.fromMe) {
120
+ fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK
121
+ }
122
+ if (!key.fromMe) {
123
+ fullMessage.platform = messages_1.getDevice(key.id)
124
+ }
125
+ return {
126
+ fullMessage,
127
+ author,
128
+ sender: msgType === 'chat' ? author : chatId
129
+ }
130
+ }
131
+
125
132
  const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
126
- const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
127
- return {
128
- fullMessage,
129
- category: stanza.attrs.category,
130
- author,
131
- async decrypt() {
132
- let decryptables = 0
133
- if (Array.isArray(stanza.content)) {
134
- for (const { tag, attrs, content } of stanza.content) {
135
- if (tag === 'verified_name' && content instanceof Uint8Array) {
136
- const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content)
137
- const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details)
138
- fullMessage.verifiedBizName = details.verifiedName
139
- }
140
- if (tag === 'multicast' && content instanceof Uint8Array) {
141
- fullMessage.multicast = true
142
- }
143
- if (tag === 'meta' && content instanceof Uint8Array) {
144
- fullMessage.metaInfo = {
145
- targetID: attrs.target_id
146
- }
147
- if (attrs.target_sender_jid) {
148
- fullMessage.metaInfo.targetSender = WABinary_1.jidNormalizedUser(attrs.target_sender_jid)
149
- }
150
- }
151
- if (tag === 'bot' && content instanceof Uint8Array) {
152
- if (attrs.edit) {
153
- fullMessage.botInfo = {
154
- editType: attrs.edit,
155
- editTargetID: attrs.edit_target_id,
156
- editSenderTimestampMS: attrs.sender_timestamp_ms
157
- }
158
- }
159
- }
160
- if (tag !== 'enc' && tag !== 'plaintext') {
161
- continue
162
- }
163
- if (!(content instanceof Uint8Array)) {
164
- continue
165
- }
166
- decryptables += 1
167
- let msgBuffer
168
- try {
169
- const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type
170
- switch (e2eType) {
171
- case 'skmsg':
172
- msgBuffer = await repository.decryptGroupMessage({
173
- group: sender,
174
- authorJid: author,
175
- msg: content
176
- })
177
- break
178
- case 'pkmsg':
179
- case 'msg':
180
- const user = WABinary_1.isJidUser(sender) ? sender : author
181
- msgBuffer = await repository.decryptMessage({
182
- jid: user,
183
- type: e2eType,
184
- ciphertext: content
185
- })
186
- break
187
- case 'plaintext':
188
- msgBuffer = content
189
- break
190
- default:
191
- throw new Error(`Unknown e2e type: ${e2eType}`)
192
- }
193
- let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? generics_1.unpadRandomMax16(msgBuffer) : msgBuffer)
194
- msg = msg.deviceSentMessage?.message || msg
195
- if (msg.senderKeyDistributionMessage) {
196
- //eslint-disable-next-line max-depth
197
- try {
198
- await repository.processSenderKeyDistributionMessage({
199
- authorJid: author,
200
- item: msg.senderKeyDistributionMessage
201
- })
202
- }
203
- catch (err) {
204
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
205
- }
206
- }
207
- if (fullMessage.message) {
208
- Object.assign(fullMessage.message, msg)
209
- }
210
- else {
211
- fullMessage.message = msg
212
- }
213
- }
214
- catch (err) {
215
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
216
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
217
- fullMessage.messageStubParameters = [err.message]
218
- }
219
- }
220
- }
221
- // if nothing was found to decrypt
222
- if (!decryptables) {
223
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
224
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT]
225
- }
226
- }
227
- }
228
- }
133
+ const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
134
+ return {
135
+ fullMessage,
136
+ category: stanza.attrs.category,
137
+ author,
138
+ async decrypt() {
139
+ let decryptables = 0
140
+ if (Array.isArray(stanza.content)) {
141
+ for (const { tag, attrs, content } of stanza.content) {
142
+ if (tag === 'verified_name' && content instanceof Uint8Array) {
143
+ const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content)
144
+ const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details)
145
+ fullMessage.verifiedBizName = details.verifiedName
146
+ }
147
+ if (tag !== 'enc' && tag !== 'plaintext') {
148
+ continue
149
+ }
150
+ if (!(content instanceof Uint8Array)) {
151
+ continue
152
+ }
153
+ decryptables += 1
154
+ let msgBuffer
155
+ try {
156
+ const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type
157
+ switch (e2eType) {
158
+ case 'skmsg':
159
+ msgBuffer = await repository.decryptGroupMessage({
160
+ group: sender,
161
+ authorJid: author,
162
+ msg: content
163
+ })
164
+ break
165
+ case 'pkmsg':
166
+ case 'msg':
167
+ const user = WABinary_1.isJidUser(sender) ? sender : author
168
+ msgBuffer = await repository.decryptMessage({
169
+ jid: user,
170
+ type: e2eType,
171
+ ciphertext: content
172
+ })
173
+ break
174
+ case 'plaintext':
175
+ msgBuffer = content
176
+ break
177
+ default:
178
+ throw new Error(`Unknown e2e type: ${e2eType}`)
179
+ }
180
+ let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? generics_1.unpadRandomMax16(msgBuffer) : msgBuffer)
181
+ msg = msg.deviceSentMessage?.message || msg
182
+ if (msg.senderKeyDistributionMessage) {
183
+ //eslint-disable-next-line max-depth
184
+ try {
185
+ await repository.processSenderKeyDistributionMessage({
186
+ authorJid: author,
187
+ item: msg.senderKeyDistributionMessage
188
+ })
189
+ }
190
+ catch (err) {
191
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
192
+ }
193
+ }
194
+ if (fullMessage.message) {
195
+ Object.assign(fullMessage.message, msg)
196
+ }
197
+ else {
198
+ fullMessage.message = msg
199
+ }
200
+ }
201
+ catch (err) {
202
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
203
+ fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
204
+ fullMessage.messageStubParameters = [err.message]
205
+ }
206
+ }
207
+ }
208
+ // if nothing was found to decrypt
209
+ if (!decryptables) {
210
+ fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
211
+ fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT]
212
+ }
213
+ }
214
+ }
215
+ }
216
+
229
217
  module.exports = {
230
- decodeMessageNode,
231
- decryptMessageNode
218
+ decodeMessageNode,
219
+ decryptMessageNode
232
220
  }
@@ -1,35 +1,39 @@
1
1
  import { BaileysEventEmitter, BaileysEventMap } from '../Types'
2
2
  import { ILogger } from './logger'
3
+
3
4
  /**
4
- * A map that contains a list of all events that have been triggered
5
- *
6
- * Note, this can contain different type of events
7
- * this can make processing events extremely efficient -- since everything
8
- * can be done in a single transaction
9
- */
5
+ * A map that contains a list of all events that have been triggered
6
+ *
7
+ * Note, this can contain different type of events
8
+ * this can make processing events extremely efficient -- since everything
9
+ * can be done in a single transaction
10
+ */
10
11
  type BaileysEventData = Partial<BaileysEventMap>
12
+
11
13
  type BaileysBufferableEventEmitter = BaileysEventEmitter & {
12
- /** Use to process events in a batch */
13
- process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void)
14
- /**
15
- * starts buffering events, call flush() to release them
16
- * */
17
- buffer(): void
18
- /** buffers all events till the promise completes */
19
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>)
20
- /**
21
- * flushes all buffered events
22
- * @param force if true, will flush all data regardless of any pending buffers
23
- * @returns returns true if the flush actually happened, otherwise false
24
- */
25
- flush(force?: boolean): boolean
26
- /** is there an ongoing buffer */
27
- isBuffering(): boolean
14
+ /** Use to process events in a batch */
15
+ process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void)
16
+ /**
17
+ * starts buffering events, call flush() to release them
18
+ * */
19
+ buffer(): void
20
+ /** buffers all events till the promise completes */
21
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>)
22
+ /**
23
+ * flushes all buffered events
24
+ * @param force if true, will flush all data regardless of any pending buffers
25
+ * @returns returns true if the flush actually happened, otherwise false
26
+ */
27
+ flush(force?: boolean): boolean
28
+ /** is there an ongoing buffer */
29
+ isBuffering(): boolean
28
30
  }
31
+
29
32
  /**
30
- * The event buffer logically consolidates different events into a single event
31
- * making the data processing more efficient.
32
- * @param ev the baileys event emitter
33
- */
33
+ * The event buffer logically consolidates different events into a single event
34
+ * making the data processing more efficient.
35
+ * @param ev the baileys event emitter
36
+ */
34
37
  export declare const makeEventBuffer: (logger: ILogger) => BaileysBufferableEventEmitter
38
+
35
39
  export {}