@nexustechpro/baileys 2.0.5 → 2.1.0
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 +71 -0
- package/WAProto/index.js +22 -18
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +9 -8
- package/lib/Signal/libsignal.js +551 -342
- package/lib/Socket/chats.js +83 -65
- package/lib/Socket/index.js +2 -3
- package/lib/Socket/messages-recv.js +227 -41
- package/lib/Socket/messages-send.js +97 -117
- package/lib/Socket/newsletter.js +87 -36
- package/lib/Socket/nexus-handler.js +326 -89
- package/lib/Socket/registration.js +50 -33
- package/lib/Socket/socket.js +245 -69
- package/lib/Store/make-in-memory-store.js +29 -20
- package/lib/Types/Newsletter.js +37 -29
- package/lib/Types/State.js +43 -0
- package/lib/Utils/auth-utils.js +2 -2
- package/lib/Utils/chat-utils.js +48 -16
- package/lib/Utils/companion-reg-client-utils.js +34 -0
- package/lib/Utils/decode-wa-message.js +39 -22
- package/lib/Utils/generics.js +5 -7
- package/lib/Utils/index.js +4 -0
- package/lib/Utils/key-store.js +1 -1
- package/lib/Utils/link-preview.js +134 -61
- package/lib/Utils/messages-media.js +496 -381
- package/lib/Utils/messages.js +699 -706
- package/lib/Utils/process-message.js +53 -35
- package/lib/Utils/reporting-utils.js +155 -0
- package/lib/Utils/signal.js +134 -104
- package/lib/Utils/sync-action-utils.js +33 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.js +174 -91
- package/lib/WABinary/constants.js +6 -0
- package/lib/WABinary/index.js +1 -0
- package/lib/index.js +2 -3
- package/package.json +13 -9
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import WAProto from '../../WAProto/index.js';
|
|
2
2
|
import * as Defaults from '../Defaults/index.js';
|
|
3
3
|
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import * as Utils_1 from '../Utils/index.js';
|
|
5
|
+
import * as WABinary_1 from '../WABinary/index.js';
|
|
6
6
|
import { makeOrderedDictionary } from './make-ordered-dictionary.js';
|
|
7
7
|
import { ObjectRepository } from './object-repository.js';
|
|
8
8
|
|
|
9
9
|
const waChatKey = (pin) => ({
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
11
|
+
compare: (k1, k2) => k2.localeCompare(k1)
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
const waMessageID = (m) => m.key.id || '';
|
|
15
15
|
|
|
16
16
|
const waLabelAssociationKey = {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
18
|
+
compare: (k1, k2) => k2.localeCompare(k1)
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
|
|
@@ -24,7 +24,7 @@ const makeInMemoryStore = (config) => {
|
|
|
24
24
|
const socket = config.socket
|
|
25
25
|
const chatKey = config.chatKey || waChatKey(true)
|
|
26
26
|
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey
|
|
27
|
-
const logger = config.logger ||
|
|
27
|
+
const logger = config.logger || Defaults.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
|
|
28
28
|
const KeyedDB = require('@adiwajshing/keyed-db').default
|
|
29
29
|
const chats = new KeyedDB(chatKey, c => c.id)
|
|
30
30
|
const messages = {}
|
|
@@ -32,7 +32,7 @@ const makeInMemoryStore = (config) => {
|
|
|
32
32
|
const groupMetadata = {}
|
|
33
33
|
const presences = {}
|
|
34
34
|
const state = { connection: 'close' }
|
|
35
|
-
const labels = new
|
|
35
|
+
const labels = new ObjectRepository()
|
|
36
36
|
const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key)
|
|
37
37
|
const assertMessageList = (jid) => {
|
|
38
38
|
if (!messages[jid]) {
|
|
@@ -64,7 +64,7 @@ const makeInMemoryStore = (config) => {
|
|
|
64
64
|
Object.assign(state, update)
|
|
65
65
|
})
|
|
66
66
|
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
67
|
-
if (syncType ===
|
|
67
|
+
if (syncType === WAProto.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
68
68
|
return // FOR NOW,
|
|
69
69
|
//TODO: HANDLE
|
|
70
70
|
}
|
|
@@ -102,21 +102,30 @@ const makeInMemoryStore = (config) => {
|
|
|
102
102
|
else {
|
|
103
103
|
const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
|
|
104
104
|
const { user } = WABinary_1.jidDecode(contactId)
|
|
105
|
-
return [contactId, (
|
|
105
|
+
return [contactId, (Utils_1.md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)]
|
|
106
106
|
}))
|
|
107
107
|
contact = contacts[contactHashes.find(([, b]) => b === update.id?.[0]) || ''] // find contact by attrs.hash, when user is not saved as a contact
|
|
108
108
|
}
|
|
109
|
-
if (contact) {
|
|
110
|
-
if
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
if (!contact) {
|
|
110
|
+
// Create new contact entry if the update has meaningful data
|
|
111
|
+
if (update.notify || update.verifiedName || update.name) {
|
|
112
|
+
contacts[update.id] = { id: update.id }
|
|
113
|
+
contact = contacts[update.id]
|
|
114
|
+
} else {
|
|
115
|
+
logger.debug({ update }, 'got update for non-existant contact')
|
|
116
|
+
continue
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
if (update.imgUrl === 'changed') {
|
|
120
|
+
contact.imgUrl = socket ? await socket.profilePictureUrl(contact.id) : undefined
|
|
121
|
+
}
|
|
122
|
+
else if (update.imgUrl === 'removed') {
|
|
123
|
+
delete contact.imgUrl
|
|
119
124
|
}
|
|
125
|
+
// Persist pushName, verifiedName, and name from the update
|
|
126
|
+
if (update.notify) contact.notify = update.notify
|
|
127
|
+
if (update.verifiedName) contact.verifiedName = update.verifiedName
|
|
128
|
+
if (update.name) contact.name = update.name
|
|
120
129
|
Object.assign(contacts[contact.id], contact)
|
|
121
130
|
}
|
|
122
131
|
})
|
|
@@ -288,7 +297,7 @@ const makeInMemoryStore = (config) => {
|
|
|
288
297
|
for (const jid in json.messages) {
|
|
289
298
|
const list = assertMessageList(jid)
|
|
290
299
|
for (const msg of json.messages[jid]) {
|
|
291
|
-
list.upsert(
|
|
300
|
+
list.upsert(WAProto.proto.WebMessageInfo.fromObject(msg), 'append')
|
|
292
301
|
}
|
|
293
302
|
}
|
|
294
303
|
}
|
|
@@ -355,7 +364,7 @@ const makeInMemoryStore = (config) => {
|
|
|
355
364
|
.all()
|
|
356
365
|
return associations.map(({ labelId }) => labelId)
|
|
357
366
|
},
|
|
358
|
-
loadMessage: async (jid, id) => messages[jid]?.get(id),
|
|
367
|
+
loadMessage: async (jid, id) => messages[jid]?.get(id),
|
|
359
368
|
mostRecentMessage: async (jid) => {
|
|
360
369
|
const message = messages[jid]?.array.slice(-1)[0]
|
|
361
370
|
return message
|
package/lib/Types/Newsletter.js
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
export var XWAPaths;
|
|
2
|
+
(function (XWAPaths) {
|
|
3
|
+
XWAPaths["xwa2_newsletter_create"] = "xwa2_newsletter_create";
|
|
4
|
+
XWAPaths["xwa2_newsletter_subscribers"] = "xwa2_newsletter_subscribers";
|
|
5
|
+
XWAPaths["xwa2_newsletter_view"] = "xwa2_newsletter_view";
|
|
6
|
+
XWAPaths["xwa2_newsletter_metadata"] = "xwa2_newsletter";
|
|
7
|
+
XWAPaths["xwa2_newsletter_admin_count"] = "xwa2_newsletter_admin";
|
|
8
|
+
XWAPaths["xwa2_newsletter_mute_v2"] = "xwa2_newsletter_mute_v2";
|
|
9
|
+
XWAPaths["xwa2_newsletter_unmute_v2"] = "xwa2_newsletter_unmute_v2";
|
|
10
|
+
XWAPaths["xwa2_newsletter_follow"] = "xwa2_newsletter_follow";
|
|
11
|
+
XWAPaths["xwa2_newsletter_unfollow"] = "xwa2_newsletter_unfollow";
|
|
12
|
+
XWAPaths["xwa2_newsletter_join_v2"] = "xwa2_newsletter_join_v2";
|
|
13
|
+
XWAPaths["xwa2_newsletter_leave_v2"] = "xwa2_newsletter_leave_v2";
|
|
14
|
+
XWAPaths["xwa2_newsletter_change_owner"] = "xwa2_newsletter_change_owner";
|
|
15
|
+
XWAPaths["xwa2_newsletter_demote"] = "xwa2_newsletter_demote";
|
|
16
|
+
XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
|
|
17
|
+
XWAPaths["xwa2_fetch_account_reachout_timelock"] = "xwa2_fetch_account_reachout_timelock";
|
|
18
|
+
XWAPaths["xwa2_message_capping_info"] = "xwa2_message_capping_info";
|
|
19
|
+
})(XWAPaths || (XWAPaths = {}));
|
|
20
|
+
export var QueryIds;
|
|
21
|
+
(function (QueryIds) {
|
|
22
|
+
QueryIds["CREATE"] = "8823471724422422";
|
|
23
|
+
QueryIds["UPDATE_METADATA"] = "24250201037901610";
|
|
24
|
+
QueryIds["METADATA"] = "6563316087068696";
|
|
25
|
+
QueryIds["SUBSCRIBERS"] = "9783111038412085";
|
|
26
|
+
QueryIds["FOLLOW"] = "24404358912487870";
|
|
27
|
+
QueryIds["UNFOLLOW"] = "9767147403369991";
|
|
28
|
+
QueryIds["MUTE"] = "29766401636284406";
|
|
29
|
+
QueryIds["UNMUTE"] = "9864994326891137";
|
|
30
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
31
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
32
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
|
33
|
+
QueryIds["DELETE"] = "30062808666639665";
|
|
34
|
+
QueryIds["REACHOUT_TIMELOCK"] = "23983697327930364";
|
|
35
|
+
QueryIds["MESSAGE_CAPPING_INFO"] = "24503548349331633";
|
|
36
|
+
})(QueryIds || (QueryIds = {}));
|
|
37
|
+
//# sourceMappingURL=Mex.js.map
|
package/lib/Types/State.js
CHANGED
|
@@ -10,4 +10,47 @@ export var SyncState;
|
|
|
10
10
|
/** Initial sync is complete, or was skipped. The socket is fully operational and events are processed in real-time. */
|
|
11
11
|
SyncState[SyncState["Online"] = 3] = "Online";
|
|
12
12
|
})(SyncState || (SyncState = {}));
|
|
13
|
+
export var ReachoutTimelockEnforcementType;
|
|
14
|
+
(function (ReachoutTimelockEnforcementType) {
|
|
15
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ALCOHOL"] = "BIZ_COMMERCE_VIOLATION_ALCOHOL";
|
|
16
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ADULT"] = "BIZ_COMMERCE_VIOLATION_ADULT";
|
|
17
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ANIMALS"] = "BIZ_COMMERCE_VIOLATION_ANIMALS";
|
|
18
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS"] = "BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS";
|
|
19
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DATING"] = "BIZ_COMMERCE_VIOLATION_DATING";
|
|
20
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS"] = "BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS";
|
|
21
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DRUGS"] = "BIZ_COMMERCE_VIOLATION_DRUGS";
|
|
22
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC"] = "BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC";
|
|
23
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_GAMBLING"] = "BIZ_COMMERCE_VIOLATION_GAMBLING";
|
|
24
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_HEALTHCARE"] = "BIZ_COMMERCE_VIOLATION_HEALTHCARE";
|
|
25
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY"] = "BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY";
|
|
26
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_SUPPLEMENTS"] = "BIZ_COMMERCE_VIOLATION_SUPPLEMENTS";
|
|
27
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_TOBACCO"] = "BIZ_COMMERCE_VIOLATION_TOBACCO";
|
|
28
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT"] = "BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT";
|
|
29
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_WEAPONS"] = "BIZ_COMMERCE_VIOLATION_WEAPONS";
|
|
30
|
+
ReachoutTimelockEnforcementType["BIZ_QUALITY"] = "BIZ_QUALITY";
|
|
31
|
+
/** This means there is no restriction */
|
|
32
|
+
ReachoutTimelockEnforcementType["DEFAULT"] = "DEFAULT";
|
|
33
|
+
ReachoutTimelockEnforcementType["WEB_COMPANION_ONLY"] = "WEB_COMPANION_ONLY";
|
|
34
|
+
})(ReachoutTimelockEnforcementType || (ReachoutTimelockEnforcementType = {}));
|
|
35
|
+
export var NewChatMessageCappingStatusType;
|
|
36
|
+
(function (NewChatMessageCappingStatusType) {
|
|
37
|
+
NewChatMessageCappingStatusType["NONE"] = "NONE";
|
|
38
|
+
NewChatMessageCappingStatusType["FIRST_WARNING"] = "FIRST_WARNING";
|
|
39
|
+
NewChatMessageCappingStatusType["SECOND_WARNING"] = "SECOND_WARNING";
|
|
40
|
+
NewChatMessageCappingStatusType["CAPPED"] = "CAPPED";
|
|
41
|
+
})(NewChatMessageCappingStatusType || (NewChatMessageCappingStatusType = {}));
|
|
42
|
+
export var NewChatMessageCappingMVStatusType;
|
|
43
|
+
(function (NewChatMessageCappingMVStatusType) {
|
|
44
|
+
NewChatMessageCappingMVStatusType["NOT_ELIGIBLE"] = "NOT_ELIGIBLE";
|
|
45
|
+
NewChatMessageCappingMVStatusType["NOT_ACTIVE"] = "NOT_ACTIVE";
|
|
46
|
+
NewChatMessageCappingMVStatusType["ACTIVE"] = "ACTIVE";
|
|
47
|
+
NewChatMessageCappingMVStatusType["ACTIVE_UPGRADE_AVAILABLE"] = "ACTIVE_UPGRADE_AVAILABLE";
|
|
48
|
+
})(NewChatMessageCappingMVStatusType || (NewChatMessageCappingMVStatusType = {}));
|
|
49
|
+
export var NewChatMessageCappingOTEStatusType;
|
|
50
|
+
(function (NewChatMessageCappingOTEStatusType) {
|
|
51
|
+
NewChatMessageCappingOTEStatusType["NOT_ELIGIBLE"] = "NOT_ELIGIBLE";
|
|
52
|
+
NewChatMessageCappingOTEStatusType["ELIGIBLE"] = "ELIGIBLE";
|
|
53
|
+
NewChatMessageCappingOTEStatusType["ACTIVE_IN_CURRENT_CYCLE"] = "ACTIVE_IN_CURRENT_CYCLE";
|
|
54
|
+
NewChatMessageCappingOTEStatusType["EXHAUSTED"] = "EXHAUSTED";
|
|
55
|
+
})(NewChatMessageCappingOTEStatusType || (NewChatMessageCappingOTEStatusType = {}));
|
|
13
56
|
//# sourceMappingURL=State.js.map
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -128,7 +128,7 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
128
128
|
}
|
|
129
129
|
catch (error) {
|
|
130
130
|
const msg = error?.message || (typeof error === 'string' ? error : '') || ''
|
|
131
|
-
const isExpected = msg.includes('InvalidPreKeyId') || msg.includes('SessionNotFound') || msg.includes('InvalidMessage') || msg.includes('no sender key state') || msg.includes('old counter') || msg.includes('DuplicatedMessage') || msg.includes('Connection Closed')
|
|
131
|
+
const isExpected = msg.includes('InvalidPreKeyId') || msg.includes('SessionNotFound') || msg.includes('InvalidMessage') || msg.includes('no sender key state') || msg.includes('memory access out of bounds') || msg.includes('old counter') || msg.includes('DuplicatedMessage') || msg.includes('BadMac') || msg.includes('Connection Closed')
|
|
132
132
|
if (isExpected) { logger?.debug?.({ error: msg }, 'transaction skipped — expected decrypt error, message dropped silently'); return undefined } // skip, no retry
|
|
133
133
|
logger?.error?.({ error: msg || error }, 'transaction failed, rolling back')
|
|
134
134
|
throw error
|
|
@@ -225,7 +225,7 @@ export const addTransactionCapability = (state, logger, { maxCommitRetries, dela
|
|
|
225
225
|
}
|
|
226
226
|
catch (error) {
|
|
227
227
|
const msg = error?.message || (typeof error === 'string' ? error : '') || ''
|
|
228
|
-
const isExpected = msg.includes('InvalidPreKeyId') || msg.includes('SessionNotFound') || msg.includes('InvalidMessage') || msg.includes('no sender key state') || msg.includes('old counter')
|
|
228
|
+
const isExpected = msg.includes('InvalidPreKeyId') || msg.includes('SessionNotFound') || msg.includes('InvalidMessage') || msg.includes('no sender key state') || msg.includes('memory access out of bounds') || msg.includes('old counter') || msg.includes('DuplicatedMessage') || msg.includes('BadMac')
|
|
229
229
|
; (isExpected ? logger?.debug?.bind(logger) : logger?.error?.bind(logger))?.({ error: msg || error }, 'transaction failed, rolling back')
|
|
230
230
|
throw error
|
|
231
231
|
}
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { proto } from '../../WAProto/index.js';
|
|
3
3
|
import { LabelAssociationType } from '../Types/LabelAssociation.js';
|
|
4
|
+
import { processContactAction, emitSyncActionResults } from './sync-action-utils.js'
|
|
4
5
|
import { getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidNormalizedUser, isJidUser } from '../WABinary/index.js';
|
|
5
6
|
import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto.js';
|
|
6
7
|
import { toNumber } from './generics.js';
|
|
@@ -155,6 +156,7 @@ export const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, op
|
|
|
155
156
|
|
|
156
157
|
export const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs, logger) => {
|
|
157
158
|
const ltGenerator = makeLtHashGenerator(initialState);
|
|
159
|
+
const derivedKeyCache = new Map()
|
|
158
160
|
let skippedMutations = 0;
|
|
159
161
|
for (const msgMutation of msgMutations) {
|
|
160
162
|
const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
|
|
@@ -201,15 +203,14 @@ export const decodeSyncdMutations = async (msgMutations, initialState, getAppSta
|
|
|
201
203
|
return await ltGenerator.finish();
|
|
202
204
|
|
|
203
205
|
async function getKey(keyId) {
|
|
204
|
-
const base64Key = Buffer.from(keyId).toString('base64')
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return mutationKeys(keyEnc.keyData);
|
|
206
|
+
const base64Key = Buffer.from(keyId).toString('base64')
|
|
207
|
+
const cached = derivedKeyCache.get(base64Key)
|
|
208
|
+
if (cached) return cached
|
|
209
|
+
const keyEnc = await getAppStateSyncKey(base64Key)
|
|
210
|
+
if (!keyEnc) throw new Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 404, data: { isMissingKey: true, msgMutations } })
|
|
211
|
+
const keys = await mutationKeys(keyEnc.keyData)
|
|
212
|
+
derivedKeyCache.set(base64Key, keys)
|
|
213
|
+
return keys
|
|
213
214
|
}
|
|
214
215
|
};
|
|
215
216
|
|
|
@@ -609,13 +610,8 @@ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) =
|
|
|
609
610
|
});
|
|
610
611
|
}
|
|
611
612
|
else if (action?.contactAction) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
name: action.contactAction.fullName,
|
|
615
|
-
lid: action.contactAction.lidJid || undefined,
|
|
616
|
-
phoneNumber: action.contactAction.pnJid || undefined,
|
|
617
|
-
jid: isJidUser(id) ? id : undefined
|
|
618
|
-
}]);
|
|
613
|
+
const results = processContactAction(action.contactAction, id, logger)
|
|
614
|
+
emitSyncActionResults(ev, results)
|
|
619
615
|
}
|
|
620
616
|
else if (action?.pushNameSetting) {
|
|
621
617
|
const name = action?.pushNameSetting?.name;
|
|
@@ -671,6 +667,42 @@ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) =
|
|
|
671
667
|
: { type: LabelAssociationType.Message, chatId: syncAction.index[2], messageId: syncAction.index[3], labelId: syncAction.index[1] }
|
|
672
668
|
});
|
|
673
669
|
}
|
|
670
|
+
else if (action?.localeSetting?.locale) {
|
|
671
|
+
ev.emit('settings.update', { setting: 'locale', value: action.localeSetting.locale })
|
|
672
|
+
}
|
|
673
|
+
else if (action?.timeFormatAction) {
|
|
674
|
+
ev.emit('settings.update', { setting: 'timeFormat', value: action.timeFormatAction })
|
|
675
|
+
}
|
|
676
|
+
else if (action?.pnForLidChatAction) {
|
|
677
|
+
if (action.pnForLidChatAction.pnJid) ev.emit('lid-mapping.update', { lid: id, pn: action.pnForLidChatAction.pnJid })
|
|
678
|
+
}
|
|
679
|
+
else if (action?.privacySettingRelayAllCalls) {
|
|
680
|
+
ev.emit('settings.update', { setting: 'privacySettingRelayAllCalls', value: action.privacySettingRelayAllCalls })
|
|
681
|
+
}
|
|
682
|
+
else if (action?.statusPrivacy) {
|
|
683
|
+
ev.emit('settings.update', { setting: 'statusPrivacy', value: action.statusPrivacy })
|
|
684
|
+
}
|
|
685
|
+
else if (action?.lockChatAction) {
|
|
686
|
+
ev.emit('chats.lock', { id, locked: !!action.lockChatAction.locked })
|
|
687
|
+
}
|
|
688
|
+
else if (action?.privacySettingDisableLinkPreviewsAction) {
|
|
689
|
+
ev.emit('settings.update', { setting: 'disableLinkPreviews', value: action.privacySettingDisableLinkPreviewsAction })
|
|
690
|
+
}
|
|
691
|
+
else if (action?.notificationActivitySettingAction?.notificationActivitySetting) {
|
|
692
|
+
ev.emit('settings.update', { setting: 'notificationActivitySetting', value: action.notificationActivitySettingAction.notificationActivitySetting })
|
|
693
|
+
}
|
|
694
|
+
else if (action?.lidContactAction) {
|
|
695
|
+
ev.emit('contacts.upsert', [{
|
|
696
|
+
id,
|
|
697
|
+
name: action.lidContactAction.fullName || action.lidContactAction.firstName || action.lidContactAction.username || undefined,
|
|
698
|
+
username: action.lidContactAction.username || undefined,
|
|
699
|
+
lid: id,
|
|
700
|
+
phoneNumber: undefined
|
|
701
|
+
}])
|
|
702
|
+
}
|
|
703
|
+
else if (action?.privacySettingChannelsPersonalisedRecommendationAction) {
|
|
704
|
+
ev.emit('settings.update', { setting: 'channelsPersonalisedRecommendation', value: action.privacySettingChannelsPersonalisedRecommendationAction })
|
|
705
|
+
}
|
|
674
706
|
else {
|
|
675
707
|
logger?.debug({ syncAction, id }, 'unprocessable update');
|
|
676
708
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export var CompanionWebClientType;
|
|
2
|
+
(function (CompanionWebClientType) {
|
|
3
|
+
CompanionWebClientType[CompanionWebClientType["UNKNOWN"] = 0] = "UNKNOWN";
|
|
4
|
+
CompanionWebClientType[CompanionWebClientType["CHROME"] = 1] = "CHROME";
|
|
5
|
+
CompanionWebClientType[CompanionWebClientType["EDGE"] = 2] = "EDGE";
|
|
6
|
+
CompanionWebClientType[CompanionWebClientType["FIREFOX"] = 3] = "FIREFOX";
|
|
7
|
+
CompanionWebClientType[CompanionWebClientType["IE"] = 4] = "IE";
|
|
8
|
+
CompanionWebClientType[CompanionWebClientType["OPERA"] = 5] = "OPERA";
|
|
9
|
+
CompanionWebClientType[CompanionWebClientType["SAFARI"] = 6] = "SAFARI";
|
|
10
|
+
CompanionWebClientType[CompanionWebClientType["ELECTRON"] = 7] = "ELECTRON";
|
|
11
|
+
CompanionWebClientType[CompanionWebClientType["UWP"] = 8] = "UWP";
|
|
12
|
+
CompanionWebClientType[CompanionWebClientType["OTHER_WEB_CLIENT"] = 9] = "OTHER_WEB_CLIENT";
|
|
13
|
+
})(CompanionWebClientType || (CompanionWebClientType = {}));
|
|
14
|
+
const BROWSER_TO_COMPANION_WEB_CLIENT = {
|
|
15
|
+
Chrome: CompanionWebClientType.CHROME,
|
|
16
|
+
Edge: CompanionWebClientType.EDGE,
|
|
17
|
+
Firefox: CompanionWebClientType.FIREFOX,
|
|
18
|
+
IE: CompanionWebClientType.IE,
|
|
19
|
+
Opera: CompanionWebClientType.OPERA,
|
|
20
|
+
Safari: CompanionWebClientType.SAFARI
|
|
21
|
+
};
|
|
22
|
+
export const getCompanionWebClientType = ([os, browserName]) => {
|
|
23
|
+
if (browserName === 'Desktop') {
|
|
24
|
+
return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
|
|
25
|
+
}
|
|
26
|
+
return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
|
|
27
|
+
};
|
|
28
|
+
export const getCompanionPlatformId = (browser) => {
|
|
29
|
+
return getCompanionWebClientType(browser).toString();
|
|
30
|
+
};
|
|
31
|
+
export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
|
|
32
|
+
return ('https://wa.me/settings/linked_devices#' +
|
|
33
|
+
[ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(','));
|
|
34
|
+
};
|
|
@@ -55,6 +55,7 @@ const storeMappingFromEnvelope = async (stanza, sender, repository, decryptionJi
|
|
|
55
55
|
}
|
|
56
56
|
export const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node"
|
|
57
57
|
export const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled"
|
|
58
|
+
export const ACCOUNT_RESTRICTED_TEXT = 'Your account has been restricted';
|
|
58
59
|
// Retry configuration for failed decryption
|
|
59
60
|
export const DECRYPTION_RETRY_CONFIG = {
|
|
60
61
|
maxRetries: 3,
|
|
@@ -102,6 +103,21 @@ export const extractAddressingContext = (stanza) => {
|
|
|
102
103
|
recipientAlt,
|
|
103
104
|
}
|
|
104
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Server-side error codes returned in ack stanzas (server → client) that we
|
|
108
|
+
* currently have dedicated handlers for. Extend as more handlers are added.
|
|
109
|
+
* Distinct from the client-side NackReason enum (WAWebCreateNackFromStanza).
|
|
110
|
+
*/
|
|
111
|
+
export const SERVER_ERROR_CODES = {
|
|
112
|
+
/**
|
|
113
|
+
* 1:1 message missing privacy token (tctoken). Usually means the account is
|
|
114
|
+
* restricted: WhatsApp blocks starting new chats but preserves existing ones,
|
|
115
|
+
* since established chats already carry a tctoken.
|
|
116
|
+
*/
|
|
117
|
+
MessageAccountRestriction: '463',
|
|
118
|
+
/** Stanza validation failure (SMAX_INVALID) — likely stale device session */
|
|
119
|
+
SmaxInvalid: '479'
|
|
120
|
+
};
|
|
105
121
|
/**
|
|
106
122
|
* Decode the received node as a message.
|
|
107
123
|
* @note this will only parse the message, not decrypt it
|
|
@@ -119,13 +135,13 @@ export function decodeMessageNode(stanza, meId, meLid) {
|
|
|
119
135
|
const isMe = (jid) => areJidsSameUser(jid, meId)
|
|
120
136
|
const isMeLid = (jid) => areJidsSameUser(jid, meLid)
|
|
121
137
|
if (isPnUser(from) || isLidUser(from) || isHostedLidUser(from) || isHostedPnUser(from)) {
|
|
138
|
+
if (isMe(from) || isMeLid(from)) {
|
|
139
|
+
fromMe = true
|
|
140
|
+
}
|
|
122
141
|
if (recipient && !isJidMetaAI(recipient)) {
|
|
123
|
-
if (!
|
|
142
|
+
if (!fromMe) {
|
|
124
143
|
throw new Boom("receipient present, but msg not from me", { data: stanza })
|
|
125
144
|
}
|
|
126
|
-
if (isMe(from) || isMeLid(from)) {
|
|
127
|
-
fromMe = true
|
|
128
|
-
}
|
|
129
145
|
chatId = recipient
|
|
130
146
|
} else {
|
|
131
147
|
chatId = from
|
|
@@ -230,30 +246,31 @@ export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
230
246
|
const e2eType = tag === "plaintext" ? "plaintext" : attrs.type
|
|
231
247
|
switch (e2eType) {
|
|
232
248
|
case "skmsg":
|
|
233
|
-
msgBuffer = await repository.decryptGroupMessage({
|
|
234
|
-
group: sender,
|
|
235
|
-
authorJid: author,
|
|
236
|
-
msg: content,
|
|
237
|
-
})
|
|
238
|
-
break
|
|
239
|
-
case "pkmsg":
|
|
240
|
-
case "msg":
|
|
241
249
|
try {
|
|
242
|
-
msgBuffer = await repository.
|
|
250
|
+
msgBuffer = await repository.decryptGroupMessage({
|
|
251
|
+
group: sender,
|
|
252
|
+
authorJid: author,
|
|
253
|
+
msg: content,
|
|
254
|
+
})
|
|
243
255
|
} catch (decryptErr) {
|
|
244
256
|
const errMsg = decryptErr?.message || decryptErr?.toString() || ''
|
|
245
|
-
if (errMsg.includes('
|
|
246
|
-
|
|
257
|
+
if (errMsg.includes('memory access out of bounds')) {
|
|
258
|
+
console.error('[Signal] Stale sender key — group:', sender, 'author:', author, 'err:', errMsg)
|
|
247
259
|
try {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
} catch {
|
|
260
|
+
await repository.deleteSenderKey(sender, author)
|
|
261
|
+
console.error('[Signal] Sender key deleted successfully')
|
|
262
|
+
} catch (e) {
|
|
263
|
+
console.error('[Signal] Failed to delete sender key:', e)
|
|
264
|
+
}
|
|
251
265
|
}
|
|
252
|
-
|
|
253
|
-
cleanError.stack = decryptErr?.stack
|
|
254
|
-
throw cleanError
|
|
266
|
+
throw decryptErr
|
|
255
267
|
}
|
|
256
268
|
break
|
|
269
|
+
case "pkmsg":
|
|
270
|
+
case "msg":
|
|
271
|
+
msgBuffer = await repository.decryptMessage({ jid: decryptionJid, type: e2eType, ciphertext: content })
|
|
272
|
+
if (msgBuffer === null) return // DuplicatedMessage — libsignal already handled it silently
|
|
273
|
+
break
|
|
257
274
|
case "plaintext":
|
|
258
275
|
msgBuffer = content
|
|
259
276
|
break
|
|
@@ -292,7 +309,7 @@ export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
292
309
|
} catch (err) {
|
|
293
310
|
const errorMessage = err?.message || err?.toString() || ""
|
|
294
311
|
const errStr = err?.message || (typeof err === "string" ? err : "") || ""
|
|
295
|
-
const isExpectedDecryptErr = errStr.includes("InvalidPreKeyId") || errStr.includes("SessionNotFound") || errStr.includes("InvalidMessage") || errStr.includes("no sender key state") || errStr.includes("old counter")
|
|
312
|
+
const isExpectedDecryptErr = errStr.includes("InvalidPreKeyId") || errStr.includes("SessionNotFound") || errStr.includes("InvalidMessage") || errStr.includes("no sender key state") || errStr.includes("memory access out of bounds") || errStr.includes("old counter") || errStr.includes("DuplicatedMessage") || errStr.includes("BadMac")
|
|
296
313
|
; (isExpectedDecryptErr ? logger?.debug?.bind(logger) : logger?.error?.bind(logger))?.({ key: fullMessage.key, err, errorMessage, messageType: tag === "plaintext" ? "plaintext" : attrs.type, sender, author }, "failed to decrypt message")
|
|
297
314
|
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT
|
|
298
315
|
fullMessage.messageStubParameters = [errorMessage]
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom'
|
|
2
2
|
import { createHash, randomBytes } from 'crypto'
|
|
3
3
|
import { proto } from '../../WAProto/index.js'
|
|
4
|
-
const baileysVersion = [2, 3000,
|
|
4
|
+
const baileysVersion = [2, 3000, 1040069233]
|
|
5
5
|
import { DisconnectReason } from '../Types/index.js'
|
|
6
6
|
import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js'
|
|
7
7
|
import { sha256 } from './crypto.js'
|
|
@@ -149,10 +149,10 @@ export const generateMessageIDV2 = (userId) => {
|
|
|
149
149
|
const random = randomBytes(16)
|
|
150
150
|
random.copy(data, 28)
|
|
151
151
|
const hash = createHash('sha256').update(data).digest()
|
|
152
|
-
return '
|
|
152
|
+
return 'NEXUSTECHPRO' + hash.toString('hex').toUpperCase().substring(0, 18)
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
export const generateMessageID = () => '
|
|
155
|
+
export const generateMessageID = () => 'NEXUSTECHPRO' + randomBytes(18).toString('hex').toUpperCase()
|
|
156
156
|
|
|
157
157
|
export function bindWaitForEvent(ev, event) {
|
|
158
158
|
return async (check, timeoutMs) => {
|
|
@@ -177,14 +177,12 @@ export function bindWaitForEvent(ev, event) {
|
|
|
177
177
|
export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update')
|
|
178
178
|
|
|
179
179
|
export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
180
|
-
const URL = 'https://raw.githubusercontent.com/
|
|
180
|
+
const URL = 'https://raw.githubusercontent.com/nexustechpro2/baileys/master/lib/Defaults/index.js'
|
|
181
181
|
try {
|
|
182
182
|
const response = await fetch(URL, { dispatcher: options.dispatcher, method: 'GET', headers: options.headers })
|
|
183
183
|
if (!response.ok) throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status })
|
|
184
184
|
const text = await response.text()
|
|
185
|
-
const
|
|
186
|
-
const versionLine = lines[6]
|
|
187
|
-
const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/)
|
|
185
|
+
const versionMatch = text.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/)
|
|
188
186
|
if (versionMatch) {
|
|
189
187
|
const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])]
|
|
190
188
|
return { version, isLatest: true }
|
package/lib/Utils/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './messages-media.js';
|
|
|
5
5
|
export * from './validate-connection.js';
|
|
6
6
|
export * from './crypto.js';
|
|
7
7
|
export * from './signal.js';
|
|
8
|
+
export * from './make-mutex.js';
|
|
8
9
|
export * from './noise-handler.js';
|
|
9
10
|
export * from './history.js';
|
|
10
11
|
export * from './chat-utils.js';
|
|
@@ -19,4 +20,7 @@ export * from './message-retry-manager.js';
|
|
|
19
20
|
export * from './browser-utils.js';
|
|
20
21
|
export * from './identity-chnage-handler.js';
|
|
21
22
|
export * from './key-store.js';
|
|
23
|
+
export * from './reporting-utils.js';
|
|
24
|
+
export * from './companion-reg-client-utils.js';
|
|
25
|
+
export * from './tc-token-utils.js';
|
|
22
26
|
//# sourceMappingURL=index.js.map
|
package/lib/Utils/key-store.js
CHANGED
|
@@ -8,7 +8,7 @@ export const migrateIndexKey = async (keys, type) => {
|
|
|
8
8
|
const oldKey = '_index'
|
|
9
9
|
const newKey = 'index'
|
|
10
10
|
const oldData = await keys.get(type, [oldKey])
|
|
11
|
-
if (oldData?.[oldKey] && typeof oldData[oldKey] === 'object') { // only migrate if old blob actually exists and has data
|
|
11
|
+
if (oldData?.[oldKey] !== null && oldData?.[oldKey] !== undefined && typeof oldData[oldKey] === 'object') { // only migrate if old blob actually exists and has data
|
|
12
12
|
await keys.set({ [type]: { [newKey]: oldData[oldKey], [oldKey]: null } })
|
|
13
13
|
return oldData[oldKey]
|
|
14
14
|
}
|