@hansaka02/baileys 7.3.2 → 7.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.
- package/README.md +247 -203
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +62 -0
- package/lib/Defaults/history.js +17 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +4 -4
- package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -7
- package/lib/Signal/Group/sender-key-state.js +4 -4
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +45 -69
- package/lib/Signal/lid-mapping.js +15 -11
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +16 -14
- package/lib/Socket/business.js +41 -32
- package/lib/Socket/chats.js +123 -98
- package/lib/Socket/community.js +50 -40
- package/lib/Socket/groups.js +59 -47
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +219 -172
- package/lib/Socket/messages-send.js +187 -143
- package/lib/Socket/newsletter.js +61 -47
- package/lib/Socket/socket.js +133 -90
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -5
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +28 -26
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +81 -71
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +319 -311
- package/lib/Utils/event-buffer.js +21 -22
- package/lib/Utils/generics.js +65 -82
- package/lib/Utils/history.js +21 -21
- package/lib/Utils/index.js +27 -13
- package/lib/Utils/link-preview.js +7 -30
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/message-retry-manager.js +4 -4
- package/lib/Utils/messages-media.js +104 -109
- package/lib/Utils/messages.js +203 -171
- package/lib/Utils/noise-handler.js +28 -19
- package/lib/Utils/process-message.js +111 -96
- package/lib/Utils/signal.js +36 -25
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +52 -45
- package/lib/WABinary/decode.js +6 -32
- package/lib/WABinary/encode.js +3 -29
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WAM/encode.js +16 -8
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +17 -10
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +8 -14
- package/WAProto/AICommon/AICommon.d.ts +0 -11702
- package/WAProto/Adv/Adv.d.ts +0 -643
- package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
- package/WAProto/Cert/Cert.d.ts +0 -613
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
- package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
- package/WAProto/E2E/E2E.d.ts +0 -41724
- package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
- package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
- package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
- package/WAProto/Protocol/Protocol.d.ts +0 -270
- package/WAProto/Reporting/Reporting.d.ts +0 -371
- package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
- package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
- package/WAProto/UserPassword/UserPassword.d.ts +0 -363
- package/WAProto/VnameCert/VnameCert.d.ts +0 -821
- package/WAProto/Wa6/Wa6.d.ts +0 -2128
- package/WAProto/Web/Web.d.ts +0 -46383
- package/WAProto/index.d.ts +0 -55
- package/lib/Defaults/index.d.ts +0 -77
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts +0 -19
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -16
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -19
- package/lib/Signal/Group/sender-key-record.d.ts +0 -32
- package/lib/Signal/Group/sender-key-state.d.ts +0 -44
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -187
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/community.d.ts +0 -129
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -80
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/generics.d.ts +0 -117
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/signal.d.ts +0 -42
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -13
|
@@ -1,36 +1,35 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
5
|
+
const { caching } = require("cache-manager")
|
|
6
|
+
const { proto } = require("../../WAProto")
|
|
7
|
+
const {
|
|
8
|
+
BufferJSON,
|
|
9
|
+
initAuthCreds
|
|
10
|
+
} = require("../Utils")
|
|
11
|
+
const { default: logger } = require("../Utils/logger")
|
|
13
12
|
|
|
14
13
|
const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
15
14
|
const defaultKey = (file) => `${sessionKey}:${file}`
|
|
16
|
-
const databaseConn = await
|
|
15
|
+
const databaseConn = await caching(store)
|
|
17
16
|
const writeData = async (file, data) => {
|
|
18
17
|
let ttl = undefined
|
|
19
18
|
if (file === 'creds') {
|
|
20
19
|
ttl = 63115200 // 2 years
|
|
21
20
|
}
|
|
22
|
-
await databaseConn.set(defaultKey(file), JSON.stringify(data,
|
|
21
|
+
await databaseConn.set(defaultKey(file), JSON.stringify(data, BufferJSON.replacer), ttl)
|
|
23
22
|
}
|
|
24
23
|
const readData = async (file) => {
|
|
25
24
|
try {
|
|
26
25
|
const data = await databaseConn.get(defaultKey(file))
|
|
27
26
|
if (data) {
|
|
28
|
-
return JSON.parse(data,
|
|
27
|
+
return JSON.parse(data, BufferJSON.reviver)
|
|
29
28
|
}
|
|
30
29
|
return null
|
|
31
30
|
}
|
|
32
31
|
catch (error) {
|
|
33
|
-
|
|
32
|
+
logger.error(error)
|
|
34
33
|
return null
|
|
35
34
|
}
|
|
36
35
|
}
|
|
@@ -39,7 +38,7 @@ const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
|
39
38
|
return await databaseConn.del(defaultKey(file))
|
|
40
39
|
}
|
|
41
40
|
catch (_a) {
|
|
42
|
-
|
|
41
|
+
logger.error(`Error removing ${file} from session ${sessionKey}`)
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
const clearState = async () => {
|
|
@@ -50,7 +49,7 @@ const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
|
50
49
|
catch (err) {
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
|
-
const creds = (await readData('creds')) ||
|
|
52
|
+
const creds = (await readData('creds')) || initAuthCreds()
|
|
54
53
|
return {
|
|
55
54
|
clearState,
|
|
56
55
|
saveCreds: () => writeData('creds', creds),
|
|
@@ -62,7 +61,7 @@ const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
|
62
61
|
await Promise.all(ids.map(async (id) => {
|
|
63
62
|
let value = await readData(`${type}-${id}`)
|
|
64
63
|
if (type === 'app-state-sync-key' && value) {
|
|
65
|
-
value =
|
|
64
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value)
|
|
66
65
|
}
|
|
67
66
|
data[id] = value
|
|
68
67
|
}))
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const { proto } = require("../../WAProto")
|
|
6
|
+
const { DEFAULT_CONNECTION_CONFIG } = require("../Defaults/connection")
|
|
7
|
+
const { LabelAssociationType } = require("../Types/LabelAssociation")
|
|
8
|
+
const {
|
|
9
|
+
md5,
|
|
10
|
+
toNumber,
|
|
11
|
+
updateMessageWithReceipt,
|
|
12
|
+
updateMessageWithReaction
|
|
13
|
+
} = require("../Utils")
|
|
14
|
+
const {
|
|
15
|
+
jidDecode,
|
|
16
|
+
jidNormalizedUser
|
|
17
|
+
} = require("../WABinary")
|
|
18
|
+
const { makeOrderedDictionary } = require("./make-ordered-dictionary")
|
|
19
|
+
const { ObjectRepository } = require("./object-repository")
|
|
16
20
|
|
|
17
21
|
const waChatKey = (pin) => ({
|
|
18
22
|
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
@@ -22,17 +26,17 @@ const waChatKey = (pin) => ({
|
|
|
22
26
|
const waMessageID = (m) => m.key.id || ''
|
|
23
27
|
|
|
24
28
|
const waLabelAssociationKey = {
|
|
25
|
-
key: (la) => (la.type ===
|
|
29
|
+
key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
26
30
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
const makeMessagesDictionary = () =>
|
|
33
|
+
const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID)
|
|
30
34
|
|
|
31
35
|
const makeInMemoryStore = (config) => {
|
|
32
36
|
const socket = config.socket
|
|
33
37
|
const chatKey = config.chatKey || waChatKey(true)
|
|
34
38
|
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey
|
|
35
|
-
const logger = config.logger ||
|
|
39
|
+
const logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
|
|
36
40
|
const KeyedDB = require('@adiwajshing/keyed-db').default
|
|
37
41
|
const chats = new KeyedDB(chatKey, c => c.id)
|
|
38
42
|
const messages = {}
|
|
@@ -40,7 +44,7 @@ const makeInMemoryStore = (config) => {
|
|
|
40
44
|
const groupMetadata = {}
|
|
41
45
|
const presences = {}
|
|
42
46
|
const state = { connection: 'close' }
|
|
43
|
-
const labels = new
|
|
47
|
+
const labels = new ObjectRepository()
|
|
44
48
|
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key)
|
|
45
49
|
const assertMessageList = (jid) => {
|
|
46
50
|
if (!messages[jid]) {
|
|
@@ -72,7 +76,7 @@ const makeInMemoryStore = (config) => {
|
|
|
72
76
|
Object.assign(state, update)
|
|
73
77
|
})
|
|
74
78
|
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
75
|
-
if (syncType ===
|
|
79
|
+
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
76
80
|
return // FOR NOW,
|
|
77
81
|
//TODO: HANDLE
|
|
78
82
|
}
|
|
@@ -109,8 +113,8 @@ const makeInMemoryStore = (config) => {
|
|
|
109
113
|
}
|
|
110
114
|
else {
|
|
111
115
|
const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
|
|
112
|
-
const { user } =
|
|
113
|
-
return [contactId, (await
|
|
116
|
+
const { user } = jidDecode(contactId)
|
|
117
|
+
return [contactId, (await md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)]
|
|
114
118
|
}))
|
|
115
119
|
contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || ''] // find contact by attrs.hash, when user is not saved as a contact
|
|
116
120
|
}
|
|
@@ -183,14 +187,14 @@ const makeInMemoryStore = (config) => {
|
|
|
183
187
|
case 'append':
|
|
184
188
|
case 'notify':
|
|
185
189
|
for (const msg of newMessages) {
|
|
186
|
-
const jid =
|
|
190
|
+
const jid = jidNormalizedUser(msg.key.remoteJid)
|
|
187
191
|
const list = assertMessageList(jid)
|
|
188
192
|
list.upsert(msg, 'append')
|
|
189
193
|
if (type === 'notify' && !chats.get(jid)) {
|
|
190
194
|
ev.emit('chats.upsert', [
|
|
191
195
|
{
|
|
192
196
|
id: jid,
|
|
193
|
-
conversationTimestamp:
|
|
197
|
+
conversationTimestamp: toNumber(msg.messageTimestamp),
|
|
194
198
|
unreadCount: 1
|
|
195
199
|
}
|
|
196
200
|
])
|
|
@@ -201,7 +205,7 @@ const makeInMemoryStore = (config) => {
|
|
|
201
205
|
})
|
|
202
206
|
ev.on('messages.update', updates => {
|
|
203
207
|
for (const { update, key } of updates) {
|
|
204
|
-
const list = assertMessageList(
|
|
208
|
+
const list = assertMessageList(jidNormalizedUser(key.remoteJid))
|
|
205
209
|
if (update?.status) {
|
|
206
210
|
const listStatus = list.get(key.id)?.status
|
|
207
211
|
if (listStatus && update?.status <= listStatus) {
|
|
@@ -267,7 +271,7 @@ const makeInMemoryStore = (config) => {
|
|
|
267
271
|
const obj = messages[key.remoteJid]
|
|
268
272
|
const msg = obj?.get(key.id)
|
|
269
273
|
if (msg) {
|
|
270
|
-
|
|
274
|
+
updateMessageWithReceipt(msg, receipt)
|
|
271
275
|
}
|
|
272
276
|
}
|
|
273
277
|
})
|
|
@@ -276,7 +280,7 @@ const makeInMemoryStore = (config) => {
|
|
|
276
280
|
const obj = messages[key.remoteJid]
|
|
277
281
|
const msg = obj?.get(key.id)
|
|
278
282
|
if (msg) {
|
|
279
|
-
|
|
283
|
+
updateMessageWithReaction(msg, reaction)
|
|
280
284
|
}
|
|
281
285
|
}
|
|
282
286
|
})
|
|
@@ -296,7 +300,7 @@ const makeInMemoryStore = (config) => {
|
|
|
296
300
|
for (const jid in json.messages) {
|
|
297
301
|
const list = assertMessageList(jid)
|
|
298
302
|
for (const msg of json.messages[jid]) {
|
|
299
|
-
list.upsert(
|
|
303
|
+
list.upsert(proto.WebMessageInfo.fromObject(msg), 'append')
|
|
300
304
|
}
|
|
301
305
|
}
|
|
302
306
|
}
|
package/lib/Types/Message.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const { proto } = require("../../WAProto")
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
8
|
|
|
9
9
|
const WAMessageAddressingMode = {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
PN: 'pn',
|
|
11
|
+
LID: 'lid'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
module.exports = {
|
|
15
15
|
WAMessageAddressingMode,
|
|
16
|
-
WAMessageStubType:
|
|
17
|
-
WAMessageStatus:
|
|
18
|
-
WAProto:
|
|
16
|
+
WAMessageStubType: proto.WebMessageInfo.StubType,
|
|
17
|
+
WAMessageStatus: proto.WebMessageInfo.Status,
|
|
18
|
+
WAProto: proto
|
|
19
19
|
}
|
package/lib/Types/MexUpdates.js
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
5
|
const MexUpdatesOperations = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
OWNER_COMMUNITY: "NotificationCommunityOwnerUpdate",
|
|
7
|
+
GROUP_MEMBER_LINK: "NotificationGroupMemberLinkPropertyUpdate",
|
|
8
|
+
GROUP_LIMIT_SHARING: "NotificationGroupLimitSharingPropertyUpdate"
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
const XWAPathsMexUpdates = {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
GROUP_SHARING_CHANGE: "xwa2_notify_group_on_prop_change",
|
|
13
|
+
COMMUNITY_OWNER_CHANGE: "xwa2_notify_group_on_participants_roles_change"
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
module.exports = {
|
package/lib/Types/State.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
5
|
const SyncState = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
Connecting: 0,
|
|
7
|
+
AwaitingInitialSync: 1,
|
|
8
|
+
Syncing: 2,
|
|
9
|
+
Online: 3
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
module.exports = {
|
package/lib/Types/index.js
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
let desc = Object.getOwnPropertyDescriptor(m, k)
|
|
7
|
+
|
|
6
8
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
Object.defineProperty(o, k2, desc)
|
|
18
|
+
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k
|
|
21
|
+
o[k2] = m[k]
|
|
22
|
+
}
|
|
23
|
+
))
|
|
24
|
+
|
|
25
|
+
const __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) {
|
|
27
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
28
|
+
__createBinding(exports, m, p)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
32
|
|
|
19
|
-
Object.defineProperty(exports, "__esModule", {
|
|
33
|
+
Object.defineProperty(exports, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
})
|
|
20
36
|
|
|
21
|
-
exports.DisconnectReason =
|
|
37
|
+
exports.DisconnectReason = null
|
|
22
38
|
__exportStar(require("./Auth"), exports)
|
|
23
39
|
__exportStar(require("./Bussines"), exports)
|
|
24
40
|
__exportStar(require("./Chat"), exports)
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod }
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
8
4
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
5
|
+
const { randomBytes } = require("crypto")
|
|
6
|
+
const { default: NodeCache } = require("@cacheable/node-cache")
|
|
7
|
+
const { DEFAULT_CACHE_TTLS } = require("../Defaults/constants")
|
|
8
|
+
const { LRUCache } = require("lru-cache")
|
|
9
|
+
const { Mutex }= require("async-mutex")
|
|
10
|
+
const {
|
|
11
|
+
Curve,
|
|
12
|
+
signedKeyPair
|
|
13
|
+
} = require("./crypto")
|
|
14
|
+
const {
|
|
15
|
+
delay,
|
|
16
|
+
generateRegistrationId
|
|
17
|
+
} = require("./generics")
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Adds caching capability to a SignalKeyStore
|
|
@@ -21,14 +23,14 @@ const mutex_1 = require("async-mutex")
|
|
|
21
23
|
* @param _cache cache store to use
|
|
22
24
|
*/
|
|
23
25
|
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
24
|
-
const cache = _cache || new
|
|
25
|
-
stdTTL:
|
|
26
|
+
const cache = _cache || new NodeCache({
|
|
27
|
+
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
26
28
|
useClones: false,
|
|
27
|
-
deleteOnExpire: true
|
|
29
|
+
deleteOnExpire: true
|
|
28
30
|
})
|
|
29
31
|
|
|
30
32
|
// Mutex for protecting cache operations
|
|
31
|
-
const cacheMutex = new
|
|
33
|
+
const cacheMutex = new Mutex()
|
|
32
34
|
|
|
33
35
|
function getUniqueId(type, id) {
|
|
34
36
|
return `${type}.${id}`
|
|
@@ -82,8 +84,8 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
// Module-level specialized mutexes for pre-key operations
|
|
85
|
-
const preKeyMutex = new
|
|
86
|
-
const signedPreKeyMutex = new
|
|
87
|
+
const preKeyMutex = new Mutex()
|
|
88
|
+
const signedPreKeyMutex = new Mutex()
|
|
87
89
|
|
|
88
90
|
/**
|
|
89
91
|
* Get the appropriate mutex for the key type
|
|
@@ -253,7 +255,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
253
255
|
let mutations = {}
|
|
254
256
|
|
|
255
257
|
// LRU Cache to hold mutexes for different key types
|
|
256
|
-
const mutexCache = new
|
|
258
|
+
const mutexCache = new LRUCache({
|
|
257
259
|
ttl: 60 * 60 * 1000, // 1 hour
|
|
258
260
|
ttlAutopurge: true,
|
|
259
261
|
updateAgeOnGet: true
|
|
@@ -277,7 +279,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
277
279
|
function getMutex(key) {
|
|
278
280
|
let mutex = mutexCache.get(key)
|
|
279
281
|
if (!mutex) {
|
|
280
|
-
mutex = new
|
|
282
|
+
mutex = new Mutex()
|
|
281
283
|
mutexCache.set(key, mutex)
|
|
282
284
|
logger.info({ key }, 'created new mutex')
|
|
283
285
|
}
|
|
@@ -312,7 +314,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
312
314
|
catch (error) {
|
|
313
315
|
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`)
|
|
314
316
|
if (tries > 0) {
|
|
315
|
-
await
|
|
317
|
+
await delay(delayBetweenTriesMs)
|
|
316
318
|
}
|
|
317
319
|
}
|
|
318
320
|
}
|
|
@@ -494,14 +496,14 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
|
|
|
494
496
|
}
|
|
495
497
|
|
|
496
498
|
const initAuthCreds = () => {
|
|
497
|
-
const identityKey =
|
|
499
|
+
const identityKey = Curve.generateKeyPair()
|
|
498
500
|
return {
|
|
499
|
-
noiseKey:
|
|
500
|
-
pairingEphemeralKeyPair:
|
|
501
|
+
noiseKey: Curve.generateKeyPair(),
|
|
502
|
+
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
501
503
|
signedIdentityKey: identityKey,
|
|
502
|
-
signedPreKey:
|
|
503
|
-
registrationId:
|
|
504
|
-
advSecretKey:
|
|
504
|
+
signedPreKey: signedKeyPair(identityKey, 1),
|
|
505
|
+
registrationId: generateRegistrationId(),
|
|
506
|
+
advSecretKey: randomBytes(32).toString('base64'),
|
|
505
507
|
processedHistoryMessages: [],
|
|
506
508
|
nextPreKeyId: 1,
|
|
507
509
|
firstUnuploadedPreKeyId: 1,
|
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* @param
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
* @param
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
readAndEmitEventStream
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const Events = require("events")
|
|
6
|
+
const {
|
|
7
|
+
promises,
|
|
8
|
+
createReadStream
|
|
9
|
+
} = require("fs")
|
|
10
|
+
const { writeFile } = require("fs/promises")
|
|
11
|
+
const { createInterface } = require("readline")
|
|
12
|
+
const { delay } = require("./generics")
|
|
13
|
+
const { makeMutex } = require("./make-mutex")
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Captures events from a baileys event emitter & stores them in a file
|
|
17
|
+
* @param ev The event emitter to read events from
|
|
18
|
+
* @param filename File to save to
|
|
19
|
+
*/
|
|
20
|
+
const captureEventStream = (ev, filename) => {
|
|
21
|
+
const oldEmit = ev.emit
|
|
22
|
+
// write mutex so data is appended in order
|
|
23
|
+
const writeMutex = makeMutex()
|
|
24
|
+
// monkey patch eventemitter to capture all events
|
|
25
|
+
ev.emit = function (...args) {
|
|
26
|
+
const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n'
|
|
27
|
+
const result = oldEmit.apply(ev, args)
|
|
28
|
+
writeMutex.mutex(async () => {
|
|
29
|
+
await promises.writeFile(filename, content, { flag: 'a' })
|
|
30
|
+
})
|
|
31
|
+
return result
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Read event file and emit events from there
|
|
37
|
+
* @param filename filename containing event data
|
|
38
|
+
* @param delayIntervalMs delay between each event emit
|
|
39
|
+
*/
|
|
40
|
+
const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
41
|
+
const ev = new Events()
|
|
42
|
+
const fireEvents = async () => {
|
|
43
|
+
// from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
|
|
44
|
+
const fileStream = createReadStream(filename)
|
|
45
|
+
const rl = createInterface({
|
|
46
|
+
input: fileStream,
|
|
47
|
+
crlfDelay: Infinity
|
|
48
|
+
})
|
|
49
|
+
// Note: we use the crlfDelay option to recognize all instances of CR LF
|
|
50
|
+
// ('\r\n') in input.txt as a single line break.
|
|
51
|
+
for await (const line of rl) {
|
|
52
|
+
if (line) {
|
|
53
|
+
const { event, data } = JSON.parse(line)
|
|
54
|
+
ev.emit(event, data)
|
|
55
|
+
delayIntervalMs && await delay(delayIntervalMs)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
fileStream.close()
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
ev,
|
|
62
|
+
task: fireEvents()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = {
|
|
67
|
+
captureEventStream,
|
|
68
|
+
readAndEmitEventStream
|
|
70
69
|
}
|