@badzz88/baileys 8.5.6 → 8.5.8

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 (225) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +28 -1189
  3. package/WAProto/fix-imports.js +79 -69
  4. package/WAProto/index.d.ts +71491 -15254
  5. package/WAProto/index.js +126436 -19814
  6. package/engine-requirements.js +8 -15
  7. package/lib/Defaults/index.js +130 -0
  8. package/{src → lib}/Signal/Group/ciphertext-message.js +2 -5
  9. package/lib/Signal/Group/group-session-builder.js +30 -0
  10. package/{src → lib}/Signal/Group/group_cipher.js +11 -11
  11. package/lib/Signal/Group/index.js +12 -0
  12. package/lib/Signal/Group/keyhelper.js +18 -0
  13. package/{src → lib}/Signal/Group/sender-chain-key.js +6 -9
  14. package/{src → lib}/Signal/Group/sender-key-distribution-message.js +6 -9
  15. package/{src → lib}/Signal/Group/sender-key-message.js +9 -12
  16. package/{src → lib}/Signal/Group/sender-key-name.js +2 -5
  17. package/{src → lib}/Signal/Group/sender-key-record.js +8 -11
  18. package/{src → lib}/Signal/Group/sender-key-state.js +6 -9
  19. package/lib/Signal/Group/sender-message-key.js +26 -0
  20. package/{src → lib}/Signal/libsignal.js +131 -155
  21. package/{src → lib}/Signal/lid-mapping.js +27 -23
  22. package/lib/Socket/Client/index.js +3 -0
  23. package/lib/Socket/Client/types.js +11 -0
  24. package/{src → lib}/Socket/Client/websocket.js +11 -18
  25. package/{src → lib}/Socket/business.js +35 -67
  26. package/{src → lib}/Socket/chats.js +294 -550
  27. package/{src → lib}/Socket/communities.js +82 -114
  28. package/lib/Socket/graphql.js +716 -0
  29. package/lib/Socket/groups.js +374 -0
  30. package/lib/Socket/index.js +18 -0
  31. package/lib/Socket/interop.js +463 -0
  32. package/{src → lib}/Socket/luxu.js +120 -82
  33. package/lib/Socket/messages-recv.js +1916 -0
  34. package/lib/Socket/messages-send.js +1436 -0
  35. package/lib/Socket/mex.js +54 -0
  36. package/lib/Socket/newsletter.js +757 -0
  37. package/lib/Socket/privacy.js +318 -0
  38. package/{src → lib}/Socket/socket.js +356 -244
  39. package/lib/Socket/username.js +236 -0
  40. package/lib/Store/index.js +10 -0
  41. package/{src → lib}/Store/keyed-db.js +11 -21
  42. package/lib/Store/make-cache-manager-store.js +85 -0
  43. package/lib/Store/make-in-memory-store.js +244 -0
  44. package/{src → lib}/Store/make-ordered-dictionary.js +19 -25
  45. package/{src → lib}/Store/object-repository.js +11 -5
  46. package/lib/Types/Auth.js +2 -0
  47. package/lib/Types/Bussines.js +2 -0
  48. package/lib/Types/Call.js +2 -0
  49. package/lib/Types/Chat.js +8 -0
  50. package/lib/Types/Contact.js +2 -0
  51. package/lib/Types/Events.js +2 -0
  52. package/lib/Types/GroupMetadata.js +2 -0
  53. package/lib/Types/Label.js +25 -0
  54. package/lib/Types/LabelAssociation.js +7 -0
  55. package/lib/Types/Message.js +11 -0
  56. package/lib/Types/Mex.js +111 -0
  57. package/lib/Types/Product.js +2 -0
  58. package/lib/Types/Signal.js +2 -0
  59. package/lib/Types/Socket.js +3 -0
  60. package/lib/Types/State.js +56 -0
  61. package/lib/Types/USync.js +2 -0
  62. package/lib/Types/index.js +26 -0
  63. package/{src → lib}/Utils/auth-utils.js +91 -43
  64. package/lib/Utils/browser-utils.js +48 -0
  65. package/lib/Utils/business.js +231 -0
  66. package/lib/Utils/chat-utils.js +872 -0
  67. package/lib/Utils/companion-reg-client-utils.js +35 -0
  68. package/lib/Utils/crypto.js +118 -0
  69. package/lib/Utils/decode-wa-message.js +350 -0
  70. package/{src → lib}/Utils/event-buffer.js +81 -39
  71. package/lib/Utils/generics.js +403 -0
  72. package/lib/Utils/history.js +134 -0
  73. package/{src → lib}/Utils/identity-change-handler.js +9 -11
  74. package/lib/Utils/index.js +23 -0
  75. package/lib/Utils/link-preview.js +85 -0
  76. package/lib/Utils/logger.js +3 -0
  77. package/lib/Utils/lt-hash.js +8 -0
  78. package/{src → lib}/Utils/make-mutex.js +7 -10
  79. package/lib/Utils/message-composer.js +273 -0
  80. package/{src → lib}/Utils/message-retry-manager.js +76 -28
  81. package/lib/Utils/messages-media.js +870 -0
  82. package/lib/Utils/messages.js +1337 -0
  83. package/lib/Utils/noise-handler.js +201 -0
  84. package/{src → lib}/Utils/offline-node-processor.js +10 -4
  85. package/{src → lib}/Utils/pre-key-manager.js +27 -11
  86. package/lib/Utils/process-message.js +630 -0
  87. package/{src → lib}/Utils/reporting-utils.js +12 -15
  88. package/lib/Utils/signal.js +201 -0
  89. package/{src → lib}/Utils/stanza-ack.js +12 -4
  90. package/lib/Utils/sticker.js +110 -0
  91. package/{src → lib}/Utils/sync-action-utils.js +14 -10
  92. package/{src → lib}/Utils/tc-token-utils.js +48 -43
  93. package/{src → lib}/Utils/use-multi-file-auth-state.js +35 -25
  94. package/lib/Utils/validate-connection.js +203 -0
  95. package/{src → lib}/WABinary/constants.js +9 -12
  96. package/{src → lib}/WABinary/decode.js +38 -118
  97. package/{src → lib}/WABinary/encode.js +6 -11
  98. package/lib/WABinary/generic-utils.js +204 -0
  99. package/lib/WABinary/index.js +6 -0
  100. package/lib/WABinary/jid-utils.js +98 -0
  101. package/lib/WABinary/types.js +2 -0
  102. package/{src → lib}/WAM/BinaryInfo.js +2 -5
  103. package/{src → lib}/WAM/constants.js +4 -16635
  104. package/{src → lib}/WAM/encode.js +18 -17
  105. package/lib/WAM/index.js +4 -0
  106. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  107. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  108. package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
  109. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  110. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  111. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
  112. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  113. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  114. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
  115. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  116. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  117. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  118. package/lib/WAUSync/Protocols/index.js +12 -0
  119. package/lib/WAUSync/USyncQuery.js +151 -0
  120. package/lib/WAUSync/USyncUser.js +56 -0
  121. package/lib/WAUSync/index.js +3 -0
  122. package/{src → lib}/index.js +16 -51
  123. package/package.json +129 -99
  124. package/LICENSE +0 -21
  125. package/src/Defaults/index.js +0 -186
  126. package/src/Defaults/phonenumber-mcc.json +0 -223
  127. package/src/Signal/Group/group-session-builder.js +0 -86
  128. package/src/Signal/Group/index.js +0 -140
  129. package/src/Signal/Group/keyhelper.js +0 -77
  130. package/src/Signal/Group/sender-message-key.js +0 -29
  131. package/src/Socket/Client/index.js +0 -31
  132. package/src/Socket/Client/types.js +0 -13
  133. package/src/Socket/aigroups.js +0 -221
  134. package/src/Socket/graphql.js +0 -523
  135. package/src/Socket/groups.js +0 -516
  136. package/src/Socket/index.js +0 -31
  137. package/src/Socket/interactive-handler.js +0 -527
  138. package/src/Socket/interop.js +0 -339
  139. package/src/Socket/managed-account.js +0 -98
  140. package/src/Socket/messages-recv.js +0 -2685
  141. package/src/Socket/messages-send.js +0 -2047
  142. package/src/Socket/mex.js +0 -57
  143. package/src/Socket/newsletter.js +0 -455
  144. package/src/Socket/privacy.js +0 -125
  145. package/src/Socket/registration.js +0 -236
  146. package/src/Socket/text-router.js +0 -65
  147. package/src/Socket/username.js +0 -130
  148. package/src/Store/index.js +0 -33
  149. package/src/Store/make-cache-manager-store.js +0 -84
  150. package/src/Store/make-in-memory-store.js +0 -551
  151. package/src/Types/Auth.js +0 -31
  152. package/src/Types/Bussines.js +0 -2
  153. package/src/Types/Call.js +0 -2
  154. package/src/Types/Chat.js +0 -4
  155. package/src/Types/Contact.js +0 -2
  156. package/src/Types/Events.js +0 -2
  157. package/src/Types/GroupMetadata.js +0 -2
  158. package/src/Types/Label.js +0 -26
  159. package/src/Types/LabelAssociation.js +0 -8
  160. package/src/Types/Message.js +0 -93
  161. package/src/Types/Mex.js +0 -112
  162. package/src/Types/Newsletter.js +0 -109
  163. package/src/Types/Product.js +0 -2
  164. package/src/Types/Signal.js +0 -2
  165. package/src/Types/Socket.js +0 -2
  166. package/src/Types/State.js +0 -62
  167. package/src/Types/USync.js +0 -2
  168. package/src/Types/index.js +0 -56
  169. package/src/Utils/browser-utils.js +0 -112
  170. package/src/Utils/business.js +0 -240
  171. package/src/Utils/chat-utils.js +0 -1230
  172. package/src/Utils/command-loader.d.ts +0 -27
  173. package/src/Utils/command-loader.js +0 -89
  174. package/src/Utils/companion-reg-client-utils.js +0 -40
  175. package/src/Utils/consumer-application.js +0 -105
  176. package/src/Utils/crypto.js +0 -118
  177. package/src/Utils/curve25519-js.js +0 -242
  178. package/src/Utils/decode-wa-message.js +0 -529
  179. package/src/Utils/generics.js +0 -483
  180. package/src/Utils/group-history.js +0 -44
  181. package/src/Utils/history.js +0 -232
  182. package/src/Utils/index.js +0 -58
  183. package/src/Utils/jid-display-normalization.js +0 -195
  184. package/src/Utils/link-preview.js +0 -135
  185. package/src/Utils/logger.js +0 -8
  186. package/src/Utils/lt-hash.js +0 -25
  187. package/src/Utils/message-composer.js +0 -471
  188. package/src/Utils/messages-media.js +0 -843
  189. package/src/Utils/messages.js +0 -2817
  190. package/src/Utils/meta-ai-msmsg.js +0 -222
  191. package/src/Utils/native-bridge.js +0 -68
  192. package/src/Utils/noise-handler.js +0 -169
  193. package/src/Utils/process-message.js +0 -950
  194. package/src/Utils/session-pool.d.ts +0 -14
  195. package/src/Utils/session-pool.js +0 -70
  196. package/src/Utils/signal.js +0 -217
  197. package/src/Utils/sticker.d.ts +0 -13
  198. package/src/Utils/sticker.js +0 -123
  199. package/src/Utils/validate-connection.js +0 -209
  200. package/src/Utils/view-once-cache.d.ts +0 -12
  201. package/src/Utils/view-once-cache.js +0 -63
  202. package/src/Utils/voip-rekey.js +0 -22
  203. package/src/WABinary/generic-utils.js +0 -238
  204. package/src/WABinary/index.js +0 -34
  205. package/src/WABinary/jid-utils.js +0 -351
  206. package/src/WABinary/types.js +0 -2
  207. package/src/WAM/index.js +0 -32
  208. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
  209. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -44
  210. package/src/WAUSync/Protocols/USyncContactProtocol.js +0 -55
  211. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +0 -55
  212. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
  213. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +0 -54
  214. package/src/WAUSync/Protocols/USyncLIDProtocol.js +0 -32
  215. package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -473
  216. package/src/WAUSync/Protocols/USyncPictureProtocol.js +0 -34
  217. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
  218. package/src/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  219. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
  220. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
  221. package/src/WAUSync/Protocols/index.js +0 -40
  222. package/src/WAUSync/USyncQuery.js +0 -126
  223. package/src/WAUSync/USyncUser.js +0 -50
  224. package/src/WAUSync/index.js +0 -32
  225. package/src/antiban.js +0 -4152
@@ -1,551 +0,0 @@
1
- 'use strict';
2
- var __importDefault = (this && this.__importDefault) ||
3
- function (mod) {
4
- return mod && mod.__esModule ? mod : { default: mod };
5
- };
6
- Object.defineProperty(exports, '__esModule', { value: true });
7
- const WAProto_1 = require('../../WAProto');
8
- const Defaults_1 = require('../Defaults');
9
- const LabelAssociation_1 = require('../Types/LabelAssociation');
10
- const Utils_1 = require('../Utils');
11
- const WABinary_1 = require('../WABinary');
12
- const Store_1 = require('./make-ordered-dictionary');
13
- const object_repository_1 = require('./object-repository');
14
- const waChatKey = pin => ({
15
- key: c => (pin ? (c.pinned ? '1' : '0') : '') +
16
- (c.archived ? '0' : '1') +
17
- (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') +
18
- c.id,
19
- compare: (k1, k2) => k2.localeCompare(k1)
20
- });
21
- const waMessageID = m => m.key.id || '';
22
- const waLabelAssociationKey = {
23
- key: la => la.type === LabelAssociation_1.LabelAssociationType.Chat
24
- ? la.chatId + la.labelId
25
- : la.chatId + la.messageId + la.labelId,
26
- compare: (k1, k2) => k2.localeCompare(k1)
27
- };
28
- const makeMessagesDictionary = () => Store_1.makeOrderedDictionary(waMessageID);
29
- const ENCRYPTED_STORE_MARKER = 'xazbails-store-v1';
30
- const deriveStoreKey = secret => {
31
- const { createHash } = require('crypto');
32
- return createHash('sha256').update(String(secret)).digest();
33
- };
34
- const encryptStoreJSON = (jsonStr, secret) => {
35
- const { createCipheriv, randomBytes } = require('crypto');
36
- const key = deriveStoreKey(secret);
37
- const iv = randomBytes(12);
38
- const cipher = createCipheriv('aes-256-gcm', key, iv);
39
- const encrypted = Buffer.concat([cipher.update(jsonStr, 'utf-8'), cipher.final()]);
40
- const authTag = cipher.getAuthTag();
41
- return JSON.stringify({
42
- marker: ENCRYPTED_STORE_MARKER,
43
- iv: iv.toString('base64'),
44
- authTag: authTag.toString('base64'),
45
- data: encrypted.toString('base64')
46
- });
47
- };
48
- const decryptStoreJSON = (fileStr, secret) => {
49
- const parsed = JSON.parse(fileStr);
50
- if (parsed.marker !== ENCRYPTED_STORE_MARKER) {
51
- return fileStr;
52
- }
53
- const { createDecipheriv } = require('crypto');
54
- const key = deriveStoreKey(secret);
55
- const iv = Buffer.from(parsed.iv, 'base64');
56
- const authTag = Buffer.from(parsed.authTag, 'base64');
57
- const decipher = createDecipheriv('aes-256-gcm', key, iv);
58
- decipher.setAuthTag(authTag);
59
- const decrypted = Buffer.concat([decipher.update(Buffer.from(parsed.data, 'base64')), decipher.final()]);
60
- return decrypted.toString('utf-8');
61
- };
62
- const makeInMemoryStore = config => {
63
- const socket = config.socket;
64
- const chatKey = config.chatKey || waChatKey(true);
65
- const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
66
- const logger = config.logger ||
67
- Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({
68
- stream: 'in-mem-store'
69
- });
70
- const KeyedDB = require('@adiwajshing/keyed-db').default;
71
- const chats = new KeyedDB(chatKey, c => c.id);
72
- const messages = {};
73
- const contacts = {};
74
- const groupMetadata = {};
75
- const presences = {};
76
- const state = { connection: 'close' };
77
- const labels = new object_repository_1.ObjectRepository();
78
- const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
79
- const maxMessagesPerChat = config.maxMessagesPerChat;
80
- const trimMessagesIfNeeded = jid => {
81
- if (!maxMessagesPerChat)
82
- return;
83
- const list = messages[jid];
84
- if (!list || list.array.length <= maxMessagesPerChat)
85
- return;
86
- while (list.array.length > maxMessagesPerChat) {
87
- let oldest = list.array[0];
88
- for (const m of list.array) {
89
- if ((m.messageTimestamp || 0) < (oldest.messageTimestamp || 0))
90
- oldest = m;
91
- }
92
- list.remove(oldest);
93
- }
94
- };
95
- const assertMessageList = jid => {
96
- if (!messages[jid]) {
97
- messages[jid] = makeMessagesDictionary();
98
- }
99
- return messages[jid];
100
- };
101
- const contactsUpsert = newContacts => {
102
- const oldContacts = new Set(Object.keys(contacts));
103
- for (const contact of newContacts) {
104
- oldContacts.delete(contact.id);
105
- contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
106
- }
107
- return oldContacts;
108
- };
109
- const labelsUpsert = newLabels => {
110
- for (const label of newLabels) {
111
- labels.upsertById(label.id, label);
112
- }
113
- };
114
- const bind = ev => {
115
- ev.on('connection.update', update => {
116
- Object.assign(state, update);
117
- });
118
- ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
119
- if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
120
- return;
121
- }
122
- if (isLatest) {
123
- chats.clear();
124
- for (const id in messages) {
125
- delete messages[id];
126
- }
127
- }
128
- const chatsAdded = chats.insertIfAbsent(...newChats).length;
129
- logger.debug({ chatsAdded }, 'synced chats');
130
- const oldContacts = contactsUpsert(newContacts);
131
- if (isLatest) {
132
- for (const jid of oldContacts) {
133
- delete contacts[jid];
134
- }
135
- }
136
- logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
137
- for (const msg of newMessages) {
138
- const jid = msg.key.remoteJid;
139
- const list = assertMessageList(jid);
140
- list.upsert(msg, 'prepend');
141
- trimMessagesIfNeeded(jid);
142
- }
143
- logger.debug({ messages: newMessages.length }, 'synced messages');
144
- });
145
- ev.on('contacts.upsert', contacts => {
146
- contactsUpsert(contacts);
147
- });
148
- ev.on('contacts.update', async (updates) => {
149
- for (const update of updates) {
150
- let contact;
151
- if (contacts[update.id]) {
152
- contact = contacts[update.id];
153
- }
154
- else {
155
- const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
156
- const { user } = WABinary_1.jidDecode(contactId);
157
- return [
158
- contactId,
159
- (await Utils_1.md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)
160
- ];
161
- }));
162
- contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || ''];
163
- }
164
- if (contact) {
165
- if (update.imgUrl === 'changed') {
166
- contact.imgUrl = socket ? await socket.profilePictureUrl(contact.id) : undefined;
167
- }
168
- else if (update.imgUrl === 'removed') {
169
- delete contact.imgUrl;
170
- }
171
- }
172
- else {
173
- return logger.debug({ update }, 'got update for non-existant contact');
174
- }
175
- Object.assign(contacts[contact.id], contact);
176
- }
177
- });
178
- ev.on('chats.upsert', newChats => {
179
- chats.upsert(...newChats);
180
- });
181
- ev.on('chats.update', updates => {
182
- for (let update of updates) {
183
- const result = chats.update(update.id, chat => {
184
- if (update.unreadCount > 0) {
185
- update = { ...update };
186
- update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
187
- }
188
- Object.assign(chat, update);
189
- });
190
- if (!result) {
191
- logger.debug({ update }, 'got update for non-existant chat');
192
- }
193
- }
194
- });
195
- ev.on('labels.edit', label => {
196
- if (label.deleted) {
197
- return labels.deleteById(label.id);
198
- }
199
- if (labels.count() < 20) {
200
- return labels.upsertById(label.id, label);
201
- }
202
- logger.error('Labels count exceed');
203
- });
204
- ev.on('labels.association', ({ type, association }) => {
205
- switch (type) {
206
- case 'add':
207
- labelAssociations.upsert(association);
208
- break;
209
- case 'remove':
210
- labelAssociations.delete(association);
211
- break;
212
- default:
213
- logger.error({ type }, 'unknown label association operation type');
214
- }
215
- });
216
- ev.on('presence.update', ({ id, presences: update }) => {
217
- presences[id] = presences[id] || {};
218
- Object.assign(presences[id], update);
219
- });
220
- ev.on('chats.delete', deletions => {
221
- for (const item of deletions) {
222
- if (chats.get(item)) {
223
- chats.deleteById(item);
224
- }
225
- }
226
- });
227
- ev.on('messages.upsert', ({ messages: newMessages, type }) => {
228
- switch (type) {
229
- case 'append':
230
- case 'notify':
231
- for (const msg of newMessages) {
232
- const jid = WABinary_1.jidNormalizedUser(msg.key.remoteJid);
233
- const list = assertMessageList(jid);
234
- list.upsert(msg, 'append');
235
- trimMessagesIfNeeded(jid);
236
- if (type === 'notify' && !chats.get(jid)) {
237
- ev.emit('chats.upsert', [
238
- {
239
- id: jid,
240
- conversationTimestamp: Utils_1.toNumber(msg.messageTimestamp),
241
- unreadCount: 1
242
- }
243
- ]);
244
- }
245
- }
246
- break;
247
- }
248
- });
249
- ev.on('messages.update', updates => {
250
- for (const { update, key } of updates) {
251
- const list = assertMessageList(WABinary_1.jidNormalizedUser(key.remoteJid));
252
- if (update?.status) {
253
- const listStatus = list.get(key.id)?.status;
254
- if (listStatus && update?.status <= listStatus) {
255
- logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
256
- delete update.status;
257
- logger.debug({ update }, 'new update object');
258
- }
259
- }
260
- const result = list.updateAssign(key.id, update);
261
- if (!result) {
262
- logger.debug({ update }, 'got update for non-existent message');
263
- }
264
- }
265
- });
266
- ev.on('messages.delete', item => {
267
- if ('all' in item) {
268
- const list = messages[item.jid];
269
- list?.clear();
270
- }
271
- else {
272
- const jid = item.keys[0].remoteJid;
273
- const list = messages[jid];
274
- if (list) {
275
- const idSet = new Set(item.keys.map(k => k.id));
276
- list.filter(m => !idSet.has(m.key.id));
277
- }
278
- }
279
- });
280
- ev.on('groups.update', updates => {
281
- for (const update of updates) {
282
- const id = update.id;
283
- if (groupMetadata[id]) {
284
- Object.assign(groupMetadata[id], update);
285
- }
286
- else {
287
- logger.debug({ update }, 'got update for non-existant group metadata');
288
- }
289
- }
290
- });
291
- ev.on('group-participants.update', ({ id, participants, action }) => {
292
- const metadata = groupMetadata[id];
293
- if (metadata) {
294
- switch (action) {
295
- case 'add':
296
- metadata.participants.push(...participants.map(id => ({
297
- id,
298
- isAdmin: false,
299
- isSuperAdmin: false
300
- })));
301
- break;
302
- case 'demote':
303
- case 'promote':
304
- for (const participant of metadata.participants) {
305
- if (participants.includes(participant.id)) {
306
- participant.isAdmin = action === 'promote';
307
- }
308
- }
309
- break;
310
- case 'remove':
311
- metadata.participants = metadata.participants.filter(p => !participants.includes(p.id));
312
- break;
313
- }
314
- }
315
- });
316
- ev.on('message-receipt.update', updates => {
317
- for (const { key, receipt } of updates) {
318
- const obj = messages[key.remoteJid];
319
- const msg = obj?.get(key.id);
320
- if (msg) {
321
- Utils_1.updateMessageWithReceipt(msg, receipt);
322
- }
323
- }
324
- });
325
- ev.on('messages.reaction', reactions => {
326
- for (const { key, reaction } of reactions) {
327
- const obj = messages[key.remoteJid];
328
- const msg = obj?.get(key.id);
329
- if (msg) {
330
- Utils_1.updateMessageWithReaction(msg, reaction);
331
- }
332
- }
333
- });
334
- ev.on('settings.update', ({ setting, value }) => {
335
- state.settings = state.settings || {};
336
- state.settings[setting] = value;
337
- });
338
- ev.on('labels.reorder', ({ labelIds }) => {
339
- let order = 0;
340
- for (const id of labelIds) {
341
- const label = labels.findById(id);
342
- if (label) {
343
- labels.upsertById(id, { ...label, order: order++ });
344
- }
345
- order++;
346
- }
347
- });
348
- ev.on('call.scheduled', ({ messageKey, scheduledCall, chatId }) => {
349
- state.scheduledCalls = state.scheduledCalls || {};
350
- state.scheduledCalls[messageKey.id] = { key: messageKey, scheduledCall, chatId };
351
- });
352
- ev.on('call.schedule-cancelled', ({ messageKey, editedCallKey }) => {
353
- if (state.scheduledCalls?.[editedCallKey?.id]) {
354
- delete state.scheduledCalls[editedCallKey.id];
355
- }
356
- });
357
- ev.on('payment.split', ({ messageKey, splitPayment }) => {
358
- const list = assertMessageList(WABinary_1.jidNormalizedUser(messageKey.remoteJid));
359
- const msg = list?.get(messageKey.id);
360
- if (msg) {
361
- msg.splitPayment = splitPayment;
362
- }
363
- });
364
- ev.on('message.comment', ({ commentKey, comment, targetKey }) => {
365
- const list = assertMessageList(WABinary_1.jidNormalizedUser(targetKey.remoteJid));
366
- const msg = list?.get(targetKey.id);
367
- if (msg) {
368
- msg.commentCount = (msg.commentCount || 0) + 1;
369
- }
370
- });
371
- ev.on('poll.add-option', ({ pollKey, addedOption }) => {
372
- const list = assertMessageList(WABinary_1.jidNormalizedUser(pollKey.remoteJid));
373
- const msg = list?.get(pollKey.id);
374
- if (msg?.message) {
375
- const poll = msg.message.pollCreationMessage ||
376
- msg.message.pollCreationMessageV3 ||
377
- msg.message.pollCreationMessageV5 ||
378
- msg.message.pollCreationMessageV6;
379
- if (poll && addedOption) {
380
- poll.options = [...(poll.options || []), addedOption];
381
- }
382
- }
383
- });
384
- ev.on('chats.lock', ({ id, locked }) => {
385
- const result = chats.update(id, chat => {
386
- chat.locked = locked;
387
- });
388
- if (!result)
389
- logger.debug({ id }, 'got chats.lock for non-existent chat');
390
- });
391
- ev.on('messaging-history.status', ({ syncType, status }) => {
392
- state.historySyncStatus = state.historySyncStatus || {};
393
- state.historySyncStatus[syncType] = status;
394
- });
395
- };
396
- const toJSON = () => ({
397
- chats,
398
- contacts,
399
- messages,
400
- labels,
401
- labelAssociations,
402
- groupMetadata,
403
- presences,
404
- state
405
- });
406
- const fromJSON = json => {
407
- chats.upsert(...json.chats);
408
- labelAssociations.upsert(...(json.labelAssociations || []));
409
- contactsUpsert(Object.values(json.contacts));
410
- labelsUpsert(Object.values(json.labels || {}));
411
- for (const jid in json.messages) {
412
- const list = assertMessageList(jid);
413
- for (const msg of json.messages[jid]) {
414
- list.upsert(WAProto_1.proto.WebMessageInfo.fromObject(msg), 'append');
415
- }
416
- trimMessagesIfNeeded(jid);
417
- }
418
- if (json.groupMetadata) {
419
- Object.assign(groupMetadata, json.groupMetadata);
420
- }
421
- if (json.presences) {
422
- Object.assign(presences, json.presences);
423
- }
424
- if (json.state) {
425
- Object.assign(state, json.state);
426
- }
427
- };
428
- return {
429
- chats,
430
- contacts,
431
- messages,
432
- groupMetadata,
433
- state,
434
- presences,
435
- labels,
436
- labelAssociations,
437
- bind,
438
- loadMessages: async (jid, count, cursor) => {
439
- const list = assertMessageList(jid);
440
- const mode = !cursor || 'before' in cursor ? 'before' : 'after';
441
- const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
442
- const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
443
- let messages;
444
- if (list && mode === 'before' && (!cursorKey || cursorValue)) {
445
- if (cursorValue) {
446
- const msgIdx = list.array.findIndex(m => m.key.id === cursorKey?.id);
447
- messages = list.array.slice(0, msgIdx);
448
- }
449
- else {
450
- messages = list.array;
451
- }
452
- const diff = count - messages.length;
453
- if (diff < 0) {
454
- messages = messages.slice(-count);
455
- }
456
- }
457
- else {
458
- messages = [];
459
- }
460
- return messages;
461
- },
462
- getLabels: () => {
463
- return labels;
464
- },
465
- getChatLabels: chatId => {
466
- return labelAssociations.filter(la => la.chatId === chatId).all();
467
- },
468
- getMessageLabels: messageId => {
469
- const associations = labelAssociations.filter(la => la.messageId === messageId).all();
470
- return associations.map(({ labelId }) => labelId);
471
- },
472
- loadMessage: async (jid, id) => messages[jid]?.get(id),
473
- mostRecentMessage: async (jid) => {
474
- const message = messages[jid]?.array.slice(-1)[0];
475
- return message;
476
- },
477
- fetchImageUrl: async (jid, suki) => {
478
- const contact = contacts[jid];
479
- if (!contact) {
480
- return suki?.profilePictureUrl(jid);
481
- }
482
- if (typeof contact.imgUrl === 'undefined') {
483
- contact.imgUrl = await suki?.profilePictureUrl(jid);
484
- }
485
- return contact.imgUrl;
486
- },
487
- fetchGroupMetadata: async (jid, suki) => {
488
- if (!groupMetadata[jid]) {
489
- const metadata = await suki?.groupMetadata(jid);
490
- if (metadata) {
491
- groupMetadata[jid] = metadata;
492
- }
493
- }
494
- return groupMetadata[jid];
495
- },
496
- fetchMessageReceipts: async ({ remoteJid, id }) => {
497
- const list = messages[remoteJid];
498
- const msg = list?.get(id);
499
- return msg?.userReceipt;
500
- },
501
- toJSON,
502
- fromJSON,
503
- writeToFile: path => {
504
- const { writeFileSync } = require('fs');
505
- const jsonStr = JSON.stringify(toJSON());
506
- writeFileSync(path, config.encryptionKey ? encryptStoreJSON(jsonStr, config.encryptionKey) : jsonStr);
507
- },
508
- readFromFile: path => {
509
- const { readFileSync, existsSync } = require('fs');
510
- if (existsSync(path)) {
511
- logger.debug({ path }, 'reading from file');
512
- const fileStr = readFileSync(path, { encoding: 'utf-8' });
513
- const jsonStr = config.encryptionKey ? decryptStoreJSON(fileStr, config.encryptionKey) : fileStr;
514
- const json = JSON.parse(jsonStr);
515
- fromJSON(json);
516
- }
517
- },
518
- startAutoSave: (path, intervalMs = 30000) => {
519
- const timer = setInterval(() => {
520
- try {
521
- const { writeFileSync } = require('fs');
522
- const jsonStr = JSON.stringify(toJSON());
523
- writeFileSync(path, config.encryptionKey ? encryptStoreJSON(jsonStr, config.encryptionKey) : jsonStr);
524
- }
525
- catch (error) {
526
- logger.warn({ error, path }, 'failed to auto-save store');
527
- }
528
- }, intervalMs);
529
- if (timer.unref)
530
- timer.unref();
531
- if (socket && typeof socket.registerSocketEndHandler === 'function') {
532
- socket.registerSocketEndHandler(async () => {
533
- try {
534
- const { writeFileSync } = require('fs');
535
- const jsonStr = JSON.stringify(toJSON());
536
- writeFileSync(path, config.encryptionKey ? encryptStoreJSON(jsonStr, config.encryptionKey) : jsonStr);
537
- logger.debug({ path }, 'final store flush on socket end');
538
- }
539
- catch (error) {
540
- logger.warn({ error, path }, 'failed to flush store on socket end');
541
- }
542
- });
543
- }
544
- return () => clearInterval(timer);
545
- }
546
- };
547
- };
548
- exports.waChatKey = waChatKey;
549
- exports.waMessageID = waMessageID;
550
- exports.waLabelAssociationKey = waLabelAssociationKey;
551
- exports.makeInMemoryStore = makeInMemoryStore;
package/src/Types/Auth.js DELETED
@@ -1,31 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- function createKeyPair(publicKey, privateKey) {
4
- return {
5
- public: publicKey,
6
- private: privateKey
7
- };
8
- }
9
- function createSignedKeyPair(keyPair, signature, keyId, timestampS) {
10
- return {
11
- keyPair,
12
- signature,
13
- keyId,
14
- timestampS
15
- };
16
- }
17
- exports.SignalDataTypeMap = {
18
- 'pre-key': 'KeyPair',
19
- session: 'Uint8Array',
20
- 'sender-key': 'Uint8Array',
21
- 'sender-key-memory': 'object',
22
- 'app-state-sync-key': 'proto.Message.IAppStateSyncKeyData',
23
- 'app-state-sync-version': 'LTHashState',
24
- 'lid-mapping': 'string',
25
- 'device-list': 'Array',
26
- tctoken: 'object'
27
- };
28
- exports.SignalDataSet = undefined;
29
- exports.Awaitable = undefined;
30
- exports.createKeyPair = createKeyPair;
31
- exports.createSignedKeyPair = createSignedKeyPair;
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
package/src/Types/Call.js DELETED
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
package/src/Types/Chat.js DELETED
@@ -1,4 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.ALL_WA_PATCH_NAMES = void 0;
4
- exports.ALL_WA_PATCH_NAMES = ['critical_block', 'critical_unblock_low', 'regular_high', 'regular_low', 'regular'];
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
@@ -1,26 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.LabelColor = void 0;
4
- var LabelColor;
5
- (function (LabelColor) {
6
- LabelColor[(LabelColor['Color1'] = 0)] = 'Color1';
7
- LabelColor[(LabelColor['Color2'] = 1)] = 'Color2';
8
- LabelColor[(LabelColor['Color3'] = 2)] = 'Color3';
9
- LabelColor[(LabelColor['Color4'] = 3)] = 'Color4';
10
- LabelColor[(LabelColor['Color5'] = 4)] = 'Color5';
11
- LabelColor[(LabelColor['Color6'] = 5)] = 'Color6';
12
- LabelColor[(LabelColor['Color7'] = 6)] = 'Color7';
13
- LabelColor[(LabelColor['Color8'] = 7)] = 'Color8';
14
- LabelColor[(LabelColor['Color9'] = 8)] = 'Color9';
15
- LabelColor[(LabelColor['Color10'] = 9)] = 'Color10';
16
- LabelColor[(LabelColor['Color11'] = 10)] = 'Color11';
17
- LabelColor[(LabelColor['Color12'] = 11)] = 'Color12';
18
- LabelColor[(LabelColor['Color13'] = 12)] = 'Color13';
19
- LabelColor[(LabelColor['Color14'] = 13)] = 'Color14';
20
- LabelColor[(LabelColor['Color15'] = 14)] = 'Color15';
21
- LabelColor[(LabelColor['Color16'] = 15)] = 'Color16';
22
- LabelColor[(LabelColor['Color17'] = 16)] = 'Color17';
23
- LabelColor[(LabelColor['Color18'] = 17)] = 'Color18';
24
- LabelColor[(LabelColor['Color19'] = 18)] = 'Color19';
25
- LabelColor[(LabelColor['Color20'] = 19)] = 'Color20';
26
- })(LabelColor || (exports.LabelColor = LabelColor = {}));
@@ -1,8 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.LabelAssociationType = void 0;
4
- var LabelAssociationType;
5
- (function (LabelAssociationType) {
6
- LabelAssociationType['Chat'] = 'label_jid';
7
- LabelAssociationType['Message'] = 'label_message';
8
- })(LabelAssociationType || (exports.LabelAssociationType = LabelAssociationType = {}));