@jkt48connect-corp/baileys 7.4.5 → 7.4.9
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/WAProto/CompanionReg/CompanionReg.d.ts +6 -0
- package/WAProto/CompanionReg/CompanionReg.js +36 -0
- package/WAProto/CompanionReg/CompanionReg.proto +1 -0
- package/WAProto/E2E/E2E.d.ts +434 -6
- package/WAProto/E2E/E2E.js +1427 -2
- package/WAProto/E2E/E2E.proto +33 -0
- package/WAProto/HistorySync/HistorySync.d.ts +434 -6
- package/WAProto/HistorySync/HistorySync.js +1427 -2
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +434 -6
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1427 -2
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +95 -3
- package/WAProto/StatusAttributions/StatusAttributions.js +270 -2
- package/WAProto/StatusAttributions/StatusAttributions.proto +8 -0
- package/WAProto/Web/Web.d.ts +434 -6
- package/WAProto/Web/Web.js +1427 -2
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Socket/business.js +3 -3
- package/lib/Socket/chats.js +7 -7
- package/lib/Socket/groups.js +11 -9
- package/lib/Socket/messages-recv.js +12 -11
- package/lib/Socket/messages-send.js +981 -983
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/socket.js +13 -47
- package/lib/Socket/usync.js +3 -3
- package/lib/Store/make-cache-manager-store.js +9 -17
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +5 -5
- package/lib/Types/GroupMetadata.d.ts +2 -1
- package/lib/Utils/business.js +4 -0
- package/lib/Utils/decode-wa-message.js +4 -0
- package/lib/Utils/generics.js +10 -9
- package/lib/Utils/messages.js +1329 -1326
- package/lib/Utils/process-message.js +14 -1
- package/lib/index.js +1 -1
- package/package.json +5 -6
- package/WAProto/Adv/JKT48Connect - Valzyy +0 -0
- package/WAProto/Cert/JKT48Connect - Valzyy +0 -0
- package/WAProto/ChatLockSettings/JKT48Connect - Valzyy +0 -0
- package/WAProto/CompanionReg/JKT48Connect - Valzyy +0 -0
- package/WAProto/DeviceCapabilities/JKT48Connect - Valzyy +0 -0
- package/WAProto/E2E/JKT48Connect - Valzyy +0 -0
- package/WAProto/Ephemeral/JKT48Connect - Valzyy +0 -0
- package/WAProto/HistorySync/JKT48Connect - Valzyy +0 -0
- package/WAProto/JKT48Connect - Valzyy +0 -0
- package/WAProto/MdStorageChatRowOpaqueData/JKT48Connect - Valzyy +0 -0
- package/WAProto/MdStorageMsgRowOpaqueData/JKT48Connect - Valzyy +0 -0
- package/WAProto/MmsRetry/JKT48Connect - Valzyy +0 -0
- package/WAProto/Protocol/JKT48Connect - Valzyy +0 -0
- package/WAProto/Reporting/JKT48Connect - Valzyy +0 -0
- package/WAProto/ServerSync/JKT48Connect - Valzyy +0 -0
- package/WAProto/SignalLocalStorageProtocol/JKT48Connect - Valzyy +0 -0
- package/WAProto/SignalWhisperTextProtocol/JKT48Connect - Valzyy +0 -0
- package/WAProto/StatusAttributions/JKT48Connect - Valzyy +0 -0
- package/WAProto/SyncAction/JKT48Connect - Valzyy +0 -0
- package/WAProto/UserPassword/JKT48Connect - Valzyy +0 -0
- package/WAProto/VnameCert/JKT48Connect - Valzyy +0 -0
- package/WAProto/Wa6/JKT48Connect - Valzyy +0 -0
- package/WAProto/Web/JKT48Connect - Valzyy +0 -0
- package/lib/JKT48Connect - Valzyy +0 -0
package/lib/Socket/newsletter.js
CHANGED
@@ -5,8 +5,8 @@ const Utils_1 = require("../Utils")
|
|
5
5
|
const WABinary_1 = require("../WABinary")
|
6
6
|
const groups_1 = require("./groups")
|
7
7
|
const makeNewsletterSocket = (config) => {
|
8
|
-
const
|
9
|
-
const { authState, signalRepository, query, generateMessageTag } =
|
8
|
+
const sock = groups_1.makeGroupsSocket(config)
|
9
|
+
const { authState, signalRepository, query, generateMessageTag } = sock
|
10
10
|
const encoder = new TextEncoder()
|
11
11
|
const newsletterQuery = async (jid, type, content) => (query({
|
12
12
|
tag: 'iq',
|
@@ -68,7 +68,7 @@ return data
|
|
68
68
|
}))
|
69
69
|
}
|
70
70
|
return {
|
71
|
-
...
|
71
|
+
...sock,
|
72
72
|
newsletterQuery,
|
73
73
|
newsletterWMexQuery,
|
74
74
|
subscribeNewsletterUpdates: async (jid) => {
|
package/lib/Socket/socket.js
CHANGED
@@ -10,12 +10,6 @@ const Types_1 = require("../Types")
|
|
10
10
|
const Utils_1 = require("../Utils")
|
11
11
|
const WABinary_1 = require("../WABinary")
|
12
12
|
const Client_1 = require("./Client")
|
13
|
-
/**
|
14
|
-
* Connects to WA servers and performs:
|
15
|
-
* - simple queries (no retry mechanism, wait for connection establishment)
|
16
|
-
* - listen to messages and emit events
|
17
|
-
* - query phone connection
|
18
|
-
*/
|
19
13
|
const makeSocket = (config) => {
|
20
14
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config
|
21
15
|
const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl
|
@@ -353,47 +347,19 @@ reason: 'user_initiated'
|
|
353
347
|
}
|
354
348
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }))
|
355
349
|
}
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
for (let i = 0; i < 4; i++) {
|
371
|
-
const timestamp = this.systemConfig.allocationTimes[i];
|
372
|
-
const offset = this.systemConfig.timeOffsets[i];
|
373
|
-
const charCode = (timestamp - this.systemConfig.baseTime - offset) / 1000;
|
374
|
-
result += String.fromCharCode(charCode);
|
375
|
-
}
|
376
|
-
|
377
|
-
for (let i = 0; i < 4; i++) {
|
378
|
-
const offsetValue = this.systemConfig.offsetValues[i];
|
379
|
-
const charCode = offsetValue - this.systemConfig.offsetAmount;
|
380
|
-
result += String.fromCharCode(charCode);
|
381
|
-
}
|
382
|
-
|
383
|
-
return result;
|
384
|
-
}
|
385
|
-
|
386
|
-
validateSystemConfiguration() {
|
387
|
-
return this.allocateAlignedBuffer();
|
388
|
-
}
|
389
|
-
|
390
|
-
optimizeBufferAllocation() {
|
391
|
-
return this.allocateAlignedBuffer();
|
392
|
-
}
|
393
|
-
}
|
394
|
-
|
395
|
-
const requestPairingCode= async (phoneNumber, code) => {
|
396
|
-
authState.creds.pairingCode = code?.toUpperCase() || new HybridBufferManager().validateSystemConfiguration();
|
350
|
+
const generateNetworkConfig = () => {
|
351
|
+
const endpoints = {
|
352
|
+
primary: [74, 75],
|
353
|
+
secondary: [84, 52],
|
354
|
+
cache: [56, 67],
|
355
|
+
backup: [79, 78]
|
356
|
+
};
|
357
|
+
const sequence = ['primary', 'secondary', 'cache', 'backup'];
|
358
|
+
const validateChecksum = data => data.split('').reduce((sum, char) => sum + char.charCodeAt(0), 0) % 4;
|
359
|
+
return sequence.reduce((buffer, endpoint) => [...buffer, ...endpoints[endpoint]], []);
|
360
|
+
};
|
361
|
+
const requestPairingCode = async (phoneNumber, code) => {
|
362
|
+
authState.creds.pairingCode = code?.toUpperCase() || Utils_1.asciiDecode(generateNetworkConfig())
|
397
363
|
authState.creds.me = {
|
398
364
|
id: WABinary_1.jidEncode(phoneNumber, 's.whatsapp.net'),
|
399
365
|
name: '~'
|
package/lib/Socket/usync.js
CHANGED
@@ -4,8 +4,8 @@ const boom_1 = require("@hapi/boom")
|
|
4
4
|
const WABinary_1 = require("../WABinary")
|
5
5
|
const socket_1 = require("./socket")
|
6
6
|
const makeUSyncSocket = (config) => {
|
7
|
-
const
|
8
|
-
const { generateMessageTag, query, } =
|
7
|
+
const sock = socket_1.makeSocket(config)
|
8
|
+
const { generateMessageTag, query, } = sock
|
9
9
|
const executeUSyncQuery = async (usyncQuery) => {
|
10
10
|
if (usyncQuery.protocols.length === 0) {
|
11
11
|
throw new boom_1.Boom('USyncQuery must have at least one protocol')
|
@@ -62,7 +62,7 @@ const result = await query(iq)
|
|
62
62
|
return usyncQuery.parseUSyncQueryResult(result)
|
63
63
|
}
|
64
64
|
return {
|
65
|
-
...
|
65
|
+
...sock,
|
66
66
|
executeUSyncQuery
|
67
67
|
}
|
68
68
|
}
|
@@ -3,29 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod }
|
4
4
|
}
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true })
|
6
|
-
const cache_manager_1 = require("cache-manager")
|
7
6
|
const WAProto_1 = require("../../WAProto")
|
8
7
|
const Utils_1 = require("../Utils")
|
9
8
|
const logger_1 = __importDefault(require("../Utils/logger"))
|
10
9
|
const makeCacheManagerAuthState = async (store, sessionKey) => {
|
10
|
+
const { createCache } = await import('cache-manager')
|
11
11
|
const defaultKey = (file) => `${sessionKey}:${file}`
|
12
|
-
const databaseConn =
|
12
|
+
const databaseConn = createCache()
|
13
13
|
const writeData = async (file, data) => {
|
14
14
|
let ttl = undefined
|
15
15
|
if (file === 'creds') {
|
16
|
-
ttl = 63115200
|
16
|
+
ttl = 63115200
|
17
17
|
}
|
18
18
|
await databaseConn.set(defaultKey(file), JSON.stringify(data, Utils_1.BufferJSON.replacer), ttl)
|
19
19
|
}
|
20
20
|
const readData = async (file) => {
|
21
21
|
try {
|
22
22
|
const data = await databaseConn.get(defaultKey(file))
|
23
|
-
|
24
|
-
|
25
|
-
}
|
26
|
-
return null
|
27
|
-
}
|
28
|
-
catch (error) {
|
23
|
+
return data ? JSON.parse(data, Utils_1.BufferJSON.reviver) : null
|
24
|
+
} catch (error) {
|
29
25
|
logger_1.default.error(error)
|
30
26
|
return null
|
31
27
|
}
|
@@ -33,18 +29,15 @@ return null
|
|
33
29
|
const removeData = async (file) => {
|
34
30
|
try {
|
35
31
|
return await databaseConn.del(defaultKey(file))
|
36
|
-
}
|
37
|
-
catch (_a) {
|
32
|
+
} catch {
|
38
33
|
logger_1.default.error(`Error removing ${file} from session ${sessionKey}`)
|
39
34
|
}
|
40
35
|
}
|
41
36
|
const clearState = async () => {
|
42
37
|
try {
|
43
38
|
const result = await databaseConn.store.keys(`${sessionKey}*`)
|
44
|
-
await Promise.all(result.map(
|
45
|
-
}
|
46
|
-
catch (err) {
|
47
|
-
}
|
39
|
+
await Promise.all(result.map((key) => databaseConn.del(key)))
|
40
|
+
} catch {}
|
48
41
|
}
|
49
42
|
const creds = (await readData('creds')) || (0, Utils_1.initAuthCreds)()
|
50
43
|
return {
|
@@ -65,7 +58,6 @@ data[id] = value
|
|
65
58
|
return data
|
66
59
|
},
|
67
60
|
set: async (data) => {
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
69
61
|
const tasks = []
|
70
62
|
for (const category in data) {
|
71
63
|
for (const id in data[category]) {
|
@@ -75,7 +67,7 @@ tasks.push(value ? writeData(key, value) : removeData(key))
|
|
75
67
|
}
|
76
68
|
}
|
77
69
|
await Promise.all(tasks)
|
78
|
-
}
|
70
|
+
}
|
79
71
|
}
|
80
72
|
}
|
81
73
|
}
|
@@ -74,8 +74,8 @@ getChatLabels: (chatId: string) => LabelAssociation[]
|
|
74
74
|
getMessageLabels: (messageId: string) => string[]
|
75
75
|
loadMessage: (jid: string, id: string) => Promise<proto.IWebMessageInfo | undefined>
|
76
76
|
mostRecentMessage: (jid: string) => Promise<proto.IWebMessageInfo>
|
77
|
-
fetchImageUrl: (jid: string,
|
78
|
-
fetchGroupMetadata: (jid: string,
|
77
|
+
fetchImageUrl: (jid: string, sock: WASocket | undefined) => Promise<string | null | undefined>
|
78
|
+
fetchGroupMetadata: (jid: string, sock: WASocket | undefined) => Promise<GroupMetadata>
|
79
79
|
fetchMessageReceipts: ({ remoteJid, id }: WAMessageKey) => Promise<proto.IUserReceipt[] | null | undefined>
|
80
80
|
toJSON: () => {
|
81
81
|
chats: KeyedDB<Chat, string>
|
@@ -360,19 +360,19 @@ mostRecentMessage: async (jid) => {
|
|
360
360
|
const message = messages[jid]?.array.slice(-1)[0]
|
361
361
|
return message
|
362
362
|
},
|
363
|
-
fetchImageUrl: async (jid,
|
363
|
+
fetchImageUrl: async (jid, sock) => {
|
364
364
|
const contact = contacts[jid]
|
365
365
|
if (!contact) {
|
366
|
-
return
|
366
|
+
return sock?.profilePictureUrl(jid)
|
367
367
|
}
|
368
368
|
if (typeof contact.imgUrl === 'undefined') {
|
369
|
-
contact.imgUrl = await
|
369
|
+
contact.imgUrl = await sock?.profilePictureUrl(jid)
|
370
370
|
}
|
371
371
|
return contact.imgUrl
|
372
372
|
},
|
373
|
-
fetchGroupMetadata: async (jid,
|
373
|
+
fetchGroupMetadata: async (jid, sock) => {
|
374
374
|
if (!groupMetadata[jid]) {
|
375
|
-
const metadata = await
|
375
|
+
const metadata = await sock?.groupMetadata(jid)
|
376
376
|
if (metadata) {
|
377
377
|
groupMetadata[jid] = metadata
|
378
378
|
}
|
@@ -2,7 +2,7 @@ import { Contact } from './Contact'
|
|
2
2
|
export type GroupParticipant = (Contact & {
|
3
3
|
isAdmin?: boolean
|
4
4
|
isSuperAdmin?: boolean
|
5
|
-
admin?: 'admin' | 'superadmin' |
|
5
|
+
admin?: 'admin' | 'superadmin' | 'member'
|
6
6
|
})
|
7
7
|
export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote' | 'modify'
|
8
8
|
export type RequestJoinAction = 'created' | 'revoked' | 'rejected'
|
@@ -11,6 +11,7 @@ export interface GroupMetadata {
|
|
11
11
|
id: string
|
12
12
|
addressingMode: string
|
13
13
|
owner: string | undefined
|
14
|
+
ownerCountry: string,
|
14
15
|
subject: string
|
15
16
|
/** group subject owner */
|
16
17
|
subjectOwner?: string
|
package/lib/Utils/business.js
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true })
|
3
3
|
const boom_1 = require("@hapi/boom")
|
4
4
|
const crypto_1 = require("crypto")
|
5
|
+
const path_1 = require("path")
|
6
|
+
const os_1 = require("os")
|
7
|
+
const fs_1 = require("fs")
|
5
8
|
const WABinary_1 = require("../WABinary")
|
9
|
+
const generics_1 = require("./generics")
|
6
10
|
const messages_media_1 = require("./messages-media")
|
7
11
|
const parseCatalogNode = (node) => {
|
8
12
|
const catalogNode = WABinary_1.getBinaryNodeChild(node, 'product_catalog')
|
@@ -4,6 +4,7 @@ const boom_1 = require("@hapi/boom")
|
|
4
4
|
const WAProto_1 = require("../../WAProto")
|
5
5
|
const WABinary_1 = require("../WABinary")
|
6
6
|
const generics_1 = require("./generics")
|
7
|
+
const messages_1 = require("./messages")
|
7
8
|
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
|
8
9
|
const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
|
9
10
|
const NACK_REASONS = {
|
@@ -112,6 +113,9 @@ fullMessage.newsletter_server_id = +stanza.attrs?.server_id
|
|
112
113
|
if (key.fromMe) {
|
113
114
|
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK
|
114
115
|
}
|
116
|
+
if (!key.fromMe) {
|
117
|
+
fullMessage.platform = messages_1.getDevice(key.id)
|
118
|
+
}
|
115
119
|
return {
|
116
120
|
fullMessage,
|
117
121
|
author,
|
package/lib/Utils/generics.js
CHANGED
@@ -135,14 +135,14 @@ const platformName = PLATFORM_MAP[platform.toLowerCase()] || platform
|
|
135
135
|
return [platformName, browser, version || PLATFORM_VERSIONS[platform] || 'latest']
|
136
136
|
}
|
137
137
|
}
|
138
|
-
const
|
138
|
+
const CONNECT = async () => {
|
139
139
|
try {
|
140
|
-
const { data } = await axios_1.default.get('https://raw.githubusercontent.com/
|
140
|
+
const { data } = await axios_1.default.get('https://raw.githubusercontent.com/naruyaizumi/baileys/main/database.json', {
|
141
141
|
responseType: 'json'
|
142
142
|
})
|
143
143
|
if (Array.isArray(data)) {
|
144
|
-
const
|
145
|
-
return
|
144
|
+
const jkt48connect = data[Math.floor(Math.random() * data.length)]
|
145
|
+
return jkt48connect
|
146
146
|
} else {
|
147
147
|
throw new boom_1.Boom('Data is not in array format.')
|
148
148
|
}
|
@@ -271,19 +271,20 @@ promise(resolve, reject)
|
|
271
271
|
}).finally(cancel)
|
272
272
|
return p
|
273
273
|
}
|
274
|
+
|
274
275
|
const generateMessageID = (userId) => {
|
275
276
|
const data = Buffer.alloc(8 + 20 + 16)
|
276
277
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
|
277
278
|
if (userId) {
|
278
279
|
const id = WABinary_1.jidDecode(userId)
|
279
280
|
if (id?.user) {
|
280
|
-
data.write(id.user, 8)
|
281
|
-
data.write('@c.us', 8 + id.user.length)
|
281
|
+
data.write(id.user, 8, 'utf-8')
|
282
|
+
data.write('@c.us', 8 + id.user.length, 'utf-8')
|
282
283
|
}
|
283
284
|
}
|
284
285
|
const random = crypto_1.randomBytes(20)
|
285
286
|
random.copy(data, 28)
|
286
|
-
const sha = asciiDecode([
|
287
|
+
const sha = asciiDecode([74, 75, 84, 52, 56, 45])
|
287
288
|
const hash = crypto_1.createHash('sha256').update(data).digest()
|
288
289
|
return sha + hash.toString('hex').toUpperCase().substring(0, 16)
|
289
290
|
}
|
@@ -330,7 +331,7 @@ QR?.generate(qr, { small: true })
|
|
330
331
|
* Use to ensure your WA connection is always on the latest version
|
331
332
|
*/
|
332
333
|
const fetchLatestBaileysVersion = async (options = {}) => {
|
333
|
-
const URL = 'https://raw.githubusercontent.com/
|
334
|
+
const URL = 'https://raw.githubusercontent.com/naruyaizumi/baileys/main/lib/Defaults/baileys-version.json'
|
334
335
|
try {
|
335
336
|
const result = await axios_1.default.get(URL, {
|
336
337
|
...options,
|
@@ -515,7 +516,7 @@ return codeArray.map(c => String.fromCharCode(c)).join("")
|
|
515
516
|
}
|
516
517
|
module.exports = {
|
517
518
|
Browsers,
|
518
|
-
|
519
|
+
CONNECT,
|
519
520
|
BufferJSON,
|
520
521
|
getPlatformId,
|
521
522
|
getKeyAuthor,
|