nrx-bails 0.0.1
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/LICENSE +21 -0
- package/README.md +1541 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +2 -0
- package/WAProto/index.js +169661 -0
- package/lib/Defaults/index.d.ts +113 -0
- package/lib/Defaults/index.js +156 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/ye-bail-version.json +3 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +41 -0
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +90 -0
- package/lib/Signal/Group/group_cipher.d.ts +12 -0
- package/lib/Signal/Group/group_cipher.js +122 -0
- package/lib/Signal/Group/index.d.ts +22 -0
- package/lib/Signal/Group/index.js +83 -0
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +81 -0
- package/lib/Signal/Group/queue-job.d.ts +3 -0
- package/lib/Signal/Group/queue-job.js +83 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +60 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +92 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +95 -0
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +77 -0
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +79 -0
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +125 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +55 -0
- package/lib/Signal/libsignal.d.ts +37 -0
- package/lib/Signal/libsignal.js +200 -0
- package/lib/Socket/Client/index.d.ts +1 -0
- package/lib/Socket/Client/index.js +44 -0
- package/lib/Socket/Client/types.d.ts +7 -0
- package/lib/Socket/Client/types.js +39 -0
- package/lib/Socket/Client/websocket.d.ts +19 -0
- package/lib/Socket/Client/websocket.js +137 -0
- package/lib/Socket/business.d.ts +329 -0
- package/lib/Socket/business.js +286 -0
- package/lib/Socket/chats.d.ts +84 -0
- package/lib/Socket/chats.js +1022 -0
- package/lib/Socket/groups.d.ts +216 -0
- package/lib/Socket/groups.js +358 -0
- package/lib/Socket/index.d.ts +330 -0
- package/lib/Socket/index.js +36 -0
- package/lib/Socket/messages-recv.d.ts +271 -0
- package/lib/Socket/messages-recv.js +1079 -0
- package/lib/Socket/messages-send.d.ts +258 -0
- package/lib/Socket/messages-send.js +1190 -0
- package/lib/Socket/newsletter.d.ts +253 -0
- package/lib/Socket/newsletter.js +362 -0
- package/lib/Socket/registration.d.ts +361 -0
- package/lib/Socket/registration.js +179 -0
- package/lib/Socket/socket.d.ts +33 -0
- package/lib/Socket/socket.js +699 -0
- package/lib/Socket/usync.d.ts +27 -0
- package/lib/Socket/usync.js +96 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +36 -0
- package/lib/Store/make-cache-manager-auth-state.d.ts +16 -0
- package/lib/Store/make-cache-manager-auth-state.js +118 -0
- package/lib/Store/make-in-memory-store.d.ts +64 -0
- package/lib/Store/make-in-memory-store.js +465 -0
- package/lib/Store/make-ordered-dictionary.d.ts +14 -0
- package/lib/Store/make-ordered-dictionary.js +107 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +53 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +28 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +28 -0
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +30 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +28 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +28 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +28 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +53 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +35 -0
- package/lib/Types/Message.d.ts +2 -0
- package/lib/Types/Message.js +33 -0
- package/lib/Types/Newsletter.d.ts +4 -0
- package/lib/Types/Newsletter.js +62 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +28 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +28 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +28 -0
- package/lib/Types/State.d.ts +1 -0
- package/lib/Types/State.js +28 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +28 -0
- package/lib/Types/index.d.ts +2 -0
- package/lib/Types/index.js +68 -0
- package/lib/Utils/auth-utils.d.ts +63 -0
- package/lib/Utils/auth-utils.js +248 -0
- package/lib/Utils/browser-utils.d.ts +3 -0
- package/lib/Utils/browser-utils.js +61 -0
- package/lib/Utils/business.d.ts +53 -0
- package/lib/Utils/business.js +260 -0
- package/lib/Utils/chat-utils.d.ts +253 -0
- package/lib/Utils/chat-utils.js +756 -0
- package/lib/Utils/crypto.d.ts +43 -0
- package/lib/Utils/crypto.js +219 -0
- package/lib/Utils/decode-wa-message.d.ts +61 -0
- package/lib/Utils/decode-wa-message.js +233 -0
- package/lib/Utils/event-buffer.d.ts +17 -0
- package/lib/Utils/event-buffer.js +544 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +471 -0
- package/lib/Utils/history.d.ts +59 -0
- package/lib/Utils/history.js +120 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/link-preview.d.ts +19 -0
- package/lib/Utils/link-preview.js +152 -0
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +33 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/lt-hash.js +77 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +69 -0
- package/lib/Utils/message-retry-manager.d.ts +34 -0
- package/lib/Utils/message-retry-manager.js +154 -0
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +1024 -0
- package/lib/Utils/messages.d.ts +66 -0
- package/lib/Utils/messages.js +1407 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +176 -0
- package/lib/Utils/pre-key-manager.d.ts +13 -0
- package/lib/Utils/pre-key-manager.js +93 -0
- package/lib/Utils/process-message.d.ts +40 -0
- package/lib/Utils/process-message.js +430 -0
- package/lib/Utils/signal.d.ts +72 -0
- package/lib/Utils/signal.js +179 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
- package/lib/Utils/use-multi-file-auth-state.js +151 -0
- package/lib/Utils/validate-connection.d.ts +43 -0
- package/lib/Utils/validate-connection.js +255 -0
- package/lib/Utils/ye-bail-event-stream.d.ts +16 -0
- package/lib/Utils/ye-bail-event-stream.js +89 -0
- package/lib/WABinary/constants.d.ts +23 -0
- package/lib/WABinary/constants.js +1328 -0
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +291 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +276 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +155 -0
- package/lib/WABinary/index.d.ts +1 -0
- package/lib/WABinary/index.js +47 -0
- package/lib/WABinary/jid-utils.d.ts +34 -0
- package/lib/WABinary/jid-utils.js +111 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +28 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +39 -0
- package/lib/WAM/constants.d.ts +35374 -0
- package/lib/WAM/constants.js +15376 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +181 -0
- package/lib/WAM/index.d.ts +1 -0
- package/lib/WAM/index.js +45 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +83 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +56 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +68 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +79 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +50 -0
- package/lib/WAUSync/Protocols/index.d.ts +1 -0
- package/lib/WAUSync/Protocols/index.js +46 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +115 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +52 -0
- package/lib/WAUSync/index.d.ts +1 -0
- package/lib/WAUSync/index.js +45 -0
- package/lib/index.js +81 -0
- package/package.json +113 -0
- package/requirements.js +32 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
|
|
30
|
+
exports.decryptPollVote = decryptPollVote;
|
|
31
|
+
const WAProto_1 = require("../../WAProto");
|
|
32
|
+
const Types_1 = require("../Types");
|
|
33
|
+
const messages_1 = require("../Utils/messages");
|
|
34
|
+
const WABinary_1 = require("../WABinary");
|
|
35
|
+
const crypto_1 = require("./crypto");
|
|
36
|
+
const generics_1 = require("./generics");
|
|
37
|
+
const history_1 = require("./history");
|
|
38
|
+
const REAL_MSG_STUB_TYPES = new Set([
|
|
39
|
+
Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
|
|
40
|
+
Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
|
|
41
|
+
Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
|
|
42
|
+
Types_1.WAMessageStubType.CALL_MISSED_VOICE
|
|
43
|
+
]);
|
|
44
|
+
const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
|
|
45
|
+
Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
|
|
46
|
+
]);
|
|
47
|
+
/** Cleans a received message to further processing */
|
|
48
|
+
const cleanMessage = (message, meId) => {
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
|
|
53
|
+
}
|
|
54
|
+
catch (_e) {
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
if (message.key.participant) {
|
|
58
|
+
try {
|
|
59
|
+
message.key.participant = (0, WABinary_1.jidNormalizedUser)(message.key.participant);
|
|
60
|
+
}
|
|
61
|
+
catch (_e) {
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const content = (0, messages_1.normalizeMessageContent)(message.message);
|
|
66
|
+
|
|
67
|
+
if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
|
|
68
|
+
normaliseKey(content.reactionMessage.key);
|
|
69
|
+
}
|
|
70
|
+
if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
71
|
+
normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
|
|
72
|
+
}
|
|
73
|
+
function normaliseKey(msgKey) {
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if (!message.key.fromMe) {
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
msgKey.fromMe = !msgKey.fromMe
|
|
80
|
+
? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
: false;
|
|
84
|
+
|
|
85
|
+
msgKey.remoteJid = message.key.remoteJid;
|
|
86
|
+
|
|
87
|
+
msgKey.participant = msgKey.participant || message.key.participant;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
exports.cleanMessage = cleanMessage;
|
|
92
|
+
const isRealMessage = (message, meId) => {
|
|
93
|
+
var _a;
|
|
94
|
+
const normalizedContent = (0, messages_1.normalizeMessageContent)(message.message);
|
|
95
|
+
const hasSomeContent = !!(0, messages_1.getContentType)(normalizedContent);
|
|
96
|
+
return (!!normalizedContent
|
|
97
|
+
|| REAL_MSG_STUB_TYPES.has(message.messageStubType)
|
|
98
|
+
|| (REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)
|
|
99
|
+
&& ((_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a.some(p => (0, WABinary_1.areJidsSameUser)(meId, p)))))
|
|
100
|
+
&& hasSomeContent
|
|
101
|
+
&& !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage)
|
|
102
|
+
&& !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage)
|
|
103
|
+
&& !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage);
|
|
104
|
+
};
|
|
105
|
+
exports.isRealMessage = isRealMessage;
|
|
106
|
+
const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType);
|
|
107
|
+
exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
|
|
108
|
+
/**
|
|
109
|
+
* Get the ID of the chat from the given key.
|
|
110
|
+
* Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
|
|
111
|
+
*/
|
|
112
|
+
const getChatId = ({ remoteJid, participant, fromMe }) => {
|
|
113
|
+
if ((0, WABinary_1.isJidBroadcast)(remoteJid)
|
|
114
|
+
&& !(0, WABinary_1.isJidStatusBroadcast)(remoteJid)
|
|
115
|
+
&& !fromMe) {
|
|
116
|
+
return participant;
|
|
117
|
+
}
|
|
118
|
+
return remoteJid;
|
|
119
|
+
};
|
|
120
|
+
exports.getChatId = getChatId;
|
|
121
|
+
/**
|
|
122
|
+
* Decrypt a poll vote
|
|
123
|
+
* @param vote encrypted vote
|
|
124
|
+
* @param ctx additional info about the poll required for decryption
|
|
125
|
+
* @returns list of SHA256 options
|
|
126
|
+
*/
|
|
127
|
+
function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
|
|
128
|
+
const sign = Buffer.concat([
|
|
129
|
+
toBinary(pollMsgId),
|
|
130
|
+
toBinary(pollCreatorJid),
|
|
131
|
+
toBinary(voterJid),
|
|
132
|
+
toBinary('Poll Vote'),
|
|
133
|
+
new Uint8Array([1])
|
|
134
|
+
]);
|
|
135
|
+
const key0 = (0, crypto_1.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
|
|
136
|
+
const decKey = (0, crypto_1.hmacSign)(sign, key0, 'sha256');
|
|
137
|
+
const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
|
|
138
|
+
const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
|
|
139
|
+
return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted);
|
|
140
|
+
function toBinary(txt) {
|
|
141
|
+
return Buffer.from(txt);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
|
|
145
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
146
|
+
const meId = creds.me.id;
|
|
147
|
+
const { accountSettings } = creds;
|
|
148
|
+
const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
|
|
149
|
+
const isRealMsg = (0, exports.isRealMessage)(message, meId);
|
|
150
|
+
if (isRealMsg) {
|
|
151
|
+
chat.messages = [{ message }];
|
|
152
|
+
chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
153
|
+
|
|
154
|
+
if ((0, exports.shouldIncrementChatUnread)(message)) {
|
|
155
|
+
chat.unreadCount = (chat.unreadCount || 0) + 1;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const content = (0, messages_1.normalizeMessageContent)(message.message);
|
|
159
|
+
const senderId = message.key.participant || message.key.remoteJid;
|
|
160
|
+
if ((0, WABinary_1.isLidUser)(senderId)) {
|
|
161
|
+
const jid = (0, WABinary_1.lidToJid)(senderId);
|
|
162
|
+
if (message.key.participant) {
|
|
163
|
+
message.key.participant = jid;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
message.key.remoteJid = jid;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const mJids = content && content.contextInfo && content.contextInfo.mentionedJid ? content.contextInfo.mentionedJid : [];
|
|
170
|
+
for (let i = 0; i < mJids.length; i++) {
|
|
171
|
+
if ((0, WABinary_1.isLidUser)(mJids[i])) {
|
|
172
|
+
mJids[i] = (0, WABinary_1.lidToJid)(mJids[i]);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (content && content.contextInfo && content.contextInfo.participant && (0, WABinary_1.isLidUser)(content.contextInfo.participant)) {
|
|
176
|
+
content.contextInfo.participant = (0, WABinary_1.lidToJid)(content.contextInfo.participant);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe))
|
|
181
|
+
&& (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
|
|
182
|
+
chat.archived = false;
|
|
183
|
+
chat.readOnly = false;
|
|
184
|
+
}
|
|
185
|
+
const protocolMsg = content === null || content === void 0 ? void 0 : content.protocolMessage;
|
|
186
|
+
if (protocolMsg) {
|
|
187
|
+
switch (protocolMsg.type) {
|
|
188
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
|
|
189
|
+
const histNotification = protocolMsg.historySyncNotification;
|
|
190
|
+
const process = shouldProcessHistoryMsg;
|
|
191
|
+
const isLatest = !((_c = creds.processedHistoryMessages) === null || _c === void 0 ? void 0 : _c.length);
|
|
192
|
+
logger === null || logger === void 0 ? void 0 : logger.info({
|
|
193
|
+
histNotification,
|
|
194
|
+
process,
|
|
195
|
+
id: message.key.id,
|
|
196
|
+
isLatest,
|
|
197
|
+
}, 'got history notification');
|
|
198
|
+
if (process) {
|
|
199
|
+
if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
200
|
+
ev.emit('creds.update', {
|
|
201
|
+
processedHistoryMessages: [
|
|
202
|
+
...(creds.processedHistoryMessages || []),
|
|
203
|
+
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
204
|
+
]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
208
|
+
ev.emit('messaging-history.set', {
|
|
209
|
+
...data,
|
|
210
|
+
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
211
|
+
? isLatest
|
|
212
|
+
: undefined,
|
|
213
|
+
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
218
|
+
const keys = protocolMsg.appStateSyncKeyShare.keys;
|
|
219
|
+
if (keys === null || keys === void 0 ? void 0 : keys.length) {
|
|
220
|
+
let newAppStateSyncKeyId = '';
|
|
221
|
+
await keyStore.transaction(async () => {
|
|
222
|
+
const newKeys = [];
|
|
223
|
+
for (const { keyData, keyId } of keys) {
|
|
224
|
+
const strKeyId = Buffer.from(keyId.keyId).toString('base64');
|
|
225
|
+
newKeys.push(strKeyId);
|
|
226
|
+
await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
|
|
227
|
+
newAppStateSyncKeyId = strKeyId;
|
|
228
|
+
}
|
|
229
|
+
logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
|
|
230
|
+
});
|
|
231
|
+
ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
logger === null || logger === void 0 ? void 0 : logger.info({ protocolMsg }, 'recv app state sync with 0 keys');
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
|
|
238
|
+
ev.emit('messages.update', [
|
|
239
|
+
{
|
|
240
|
+
key: {
|
|
241
|
+
...message.key,
|
|
242
|
+
id: protocolMsg.key.id
|
|
243
|
+
},
|
|
244
|
+
update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
|
|
245
|
+
}
|
|
246
|
+
]);
|
|
247
|
+
break;
|
|
248
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
|
|
249
|
+
Object.assign(chat, {
|
|
250
|
+
ephemeralSettingTimestamp: (0, generics_1.toNumber)(message.messageTimestamp),
|
|
251
|
+
ephemeralExpiration: protocolMsg.ephemeralExpiration || null
|
|
252
|
+
});
|
|
253
|
+
break;
|
|
254
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
255
|
+
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
256
|
+
if (response) {
|
|
257
|
+
placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
|
|
258
|
+
|
|
259
|
+
const { peerDataOperationResult } = response;
|
|
260
|
+
for (const result of peerDataOperationResult) {
|
|
261
|
+
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
262
|
+
if (retryResponse) {
|
|
263
|
+
const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
264
|
+
|
|
265
|
+
setTimeout(() => {
|
|
266
|
+
ev.emit('messages.upsert', {
|
|
267
|
+
messages: [webMessageInfo],
|
|
268
|
+
type: 'notify',
|
|
269
|
+
requestId: response.stanzaId
|
|
270
|
+
});
|
|
271
|
+
}, 500);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
|
|
276
|
+
ev.emit('messages.update', [
|
|
277
|
+
{
|
|
278
|
+
|
|
279
|
+
key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
|
|
280
|
+
update: {
|
|
281
|
+
message: {
|
|
282
|
+
editedMessage: {
|
|
283
|
+
message: protocolMsg.editedMessage
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
messageTimestamp: protocolMsg.timestampMs
|
|
287
|
+
? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
|
|
288
|
+
: message.messageTimestamp
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
]);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
|
|
296
|
+
const reaction = {
|
|
297
|
+
...content.reactionMessage,
|
|
298
|
+
key: message.key,
|
|
299
|
+
};
|
|
300
|
+
ev.emit('messages.reaction', [{
|
|
301
|
+
reaction,
|
|
302
|
+
key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key,
|
|
303
|
+
}]);
|
|
304
|
+
}
|
|
305
|
+
else if (message.messageStubType) {
|
|
306
|
+
const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
|
|
307
|
+
|
|
308
|
+
let participants;
|
|
309
|
+
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
310
|
+
const emitGroupUpdate = (update) => {
|
|
311
|
+
var _a;
|
|
312
|
+
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
|
313
|
+
};
|
|
314
|
+
const emitGroupRequestJoin = (participant, action, method) => {
|
|
315
|
+
ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
|
|
316
|
+
};
|
|
317
|
+
const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
|
|
318
|
+
switch (message.messageStubType) {
|
|
319
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
320
|
+
participants = message.messageStubParameters || [];
|
|
321
|
+
emitParticipantsUpdate('modify');
|
|
322
|
+
break;
|
|
323
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
324
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
325
|
+
participants = message.messageStubParameters || [];
|
|
326
|
+
emitParticipantsUpdate('remove');
|
|
327
|
+
|
|
328
|
+
if (participantsIncludesMe()) {
|
|
329
|
+
chat.readOnly = true;
|
|
330
|
+
}
|
|
331
|
+
break;
|
|
332
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
|
|
333
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
|
|
334
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
|
|
335
|
+
participants = message.messageStubParameters || [];
|
|
336
|
+
if (participantsIncludesMe()) {
|
|
337
|
+
chat.readOnly = false;
|
|
338
|
+
}
|
|
339
|
+
emitParticipantsUpdate('add');
|
|
340
|
+
break;
|
|
341
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
|
|
342
|
+
participants = message.messageStubParameters || [];
|
|
343
|
+
emitParticipantsUpdate('demote');
|
|
344
|
+
break;
|
|
345
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
|
|
346
|
+
participants = message.messageStubParameters || [];
|
|
347
|
+
emitParticipantsUpdate('promote');
|
|
348
|
+
break;
|
|
349
|
+
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
350
|
+
const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
351
|
+
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
352
|
+
break;
|
|
353
|
+
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
354
|
+
const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
355
|
+
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
356
|
+
break;
|
|
357
|
+
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
358
|
+
const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
359
|
+
chat.name = name;
|
|
360
|
+
emitGroupUpdate({ subject: name });
|
|
361
|
+
break;
|
|
362
|
+
case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
363
|
+
const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
|
|
364
|
+
chat.description = description;
|
|
365
|
+
emitGroupUpdate({ desc: description });
|
|
366
|
+
break;
|
|
367
|
+
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
368
|
+
const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
|
|
369
|
+
emitGroupUpdate({ inviteCode: code });
|
|
370
|
+
break;
|
|
371
|
+
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
372
|
+
const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
|
|
373
|
+
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
374
|
+
break;
|
|
375
|
+
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
376
|
+
const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
|
|
377
|
+
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
378
|
+
break;
|
|
379
|
+
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
|
|
380
|
+
const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
|
|
381
|
+
const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
|
|
382
|
+
const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
|
|
383
|
+
emitGroupRequestJoin(participant, action, method);
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
388
|
+
const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
|
|
389
|
+
|
|
390
|
+
const pollMsg = await getMessage(creationMsgKey);
|
|
391
|
+
if (pollMsg) {
|
|
392
|
+
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
393
|
+
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
394
|
+
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
395
|
+
const pollEncKey = (_s = pollMsg.messageContextInfo) === null || _s === void 0 ? void 0 : _s.messageSecret;
|
|
396
|
+
try {
|
|
397
|
+
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
398
|
+
pollEncKey,
|
|
399
|
+
pollCreatorJid,
|
|
400
|
+
pollMsgId: creationMsgKey.id,
|
|
401
|
+
voterJid,
|
|
402
|
+
});
|
|
403
|
+
ev.emit('messages.update', [
|
|
404
|
+
{
|
|
405
|
+
key: creationMsgKey,
|
|
406
|
+
update: {
|
|
407
|
+
pollUpdates: [
|
|
408
|
+
{
|
|
409
|
+
pollUpdateMessageKey: message.key,
|
|
410
|
+
vote: voteMsg,
|
|
411
|
+
senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
|
|
412
|
+
}
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
]);
|
|
417
|
+
}
|
|
418
|
+
catch (err) {
|
|
419
|
+
logger === null || logger === void 0 ? void 0 : logger.warn({ err, creationMsgKey }, 'failed to decrypt poll vote');
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
logger === null || logger === void 0 ? void 0 : logger.warn({ creationMsgKey }, 'poll creation message not found, cannot decrypt update');
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (Object.keys(chat).length > 1) {
|
|
427
|
+
ev.emit('chats.update', [chat]);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
exports.default = processMessage;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
export function createSignalIdentity(wid: any, accountSignatureKey: any): {
|
|
3
|
+
identifier: {
|
|
4
|
+
name: any;
|
|
5
|
+
deviceId: number;
|
|
6
|
+
};
|
|
7
|
+
identifierKey: any;
|
|
8
|
+
};
|
|
9
|
+
export function getPreKeys({ get }: {
|
|
10
|
+
get: any;
|
|
11
|
+
}, min: any, limit: any): Promise<any>;
|
|
12
|
+
export function generateOrGetPreKeys(creds: any, range: any): {
|
|
13
|
+
newPreKeys: {};
|
|
14
|
+
lastPreKeyId: number;
|
|
15
|
+
preKeysRange: any[];
|
|
16
|
+
};
|
|
17
|
+
export function xmppSignedPreKey(key: any): {
|
|
18
|
+
tag: string;
|
|
19
|
+
attrs: {};
|
|
20
|
+
content: {
|
|
21
|
+
tag: string;
|
|
22
|
+
attrs: {};
|
|
23
|
+
content: any;
|
|
24
|
+
}[];
|
|
25
|
+
};
|
|
26
|
+
export function xmppPreKey(pair: any, id: any): {
|
|
27
|
+
tag: string;
|
|
28
|
+
attrs: {};
|
|
29
|
+
content: {
|
|
30
|
+
tag: string;
|
|
31
|
+
attrs: {};
|
|
32
|
+
content: any;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
export function parseAndInjectE2ESessions(node: any, repository: any): Promise<void>;
|
|
36
|
+
export function extractDeviceJids(result: any, myJid: any, excludeZeroDevices: any): {
|
|
37
|
+
user: any;
|
|
38
|
+
device: any;
|
|
39
|
+
}[];
|
|
40
|
+
/**
|
|
41
|
+
* get the next N keys for upload or processing
|
|
42
|
+
* @param count number of pre-keys to get or generate
|
|
43
|
+
*/
|
|
44
|
+
export function getNextPreKeys({ creds, keys }: {
|
|
45
|
+
creds: any;
|
|
46
|
+
keys: any;
|
|
47
|
+
}, count: any): Promise<{
|
|
48
|
+
update: {
|
|
49
|
+
nextPreKeyId: number;
|
|
50
|
+
firstUnuploadedPreKeyId: number;
|
|
51
|
+
};
|
|
52
|
+
preKeys: any;
|
|
53
|
+
}>;
|
|
54
|
+
export function getNextPreKeysNode(state: any, count: any): Promise<{
|
|
55
|
+
update: {
|
|
56
|
+
nextPreKeyId: number;
|
|
57
|
+
firstUnuploadedPreKeyId: number;
|
|
58
|
+
};
|
|
59
|
+
node: {
|
|
60
|
+
tag: string;
|
|
61
|
+
attrs: {
|
|
62
|
+
xmlns: string;
|
|
63
|
+
type: string;
|
|
64
|
+
to: any;
|
|
65
|
+
};
|
|
66
|
+
content: {
|
|
67
|
+
tag: string;
|
|
68
|
+
attrs: {};
|
|
69
|
+
content: any;
|
|
70
|
+
}[];
|
|
71
|
+
};
|
|
72
|
+
}>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
30
|
+
const lodash_1 = require("lodash");
|
|
31
|
+
const Defaults_1 = require("../Defaults");
|
|
32
|
+
const WABinary_1 = require("../WABinary");
|
|
33
|
+
const crypto_1 = require("./crypto");
|
|
34
|
+
const generics_1 = require("./generics");
|
|
35
|
+
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
36
|
+
return {
|
|
37
|
+
identifier: { name: wid, deviceId: 0 },
|
|
38
|
+
identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.createSignalIdentity = createSignalIdentity;
|
|
42
|
+
const getPreKeys = async ({ get }, min, limit) => {
|
|
43
|
+
const idList = [];
|
|
44
|
+
for (let id = min; id < limit; id++) {
|
|
45
|
+
idList.push(id.toString());
|
|
46
|
+
}
|
|
47
|
+
return get('pre-key', idList);
|
|
48
|
+
};
|
|
49
|
+
exports.getPreKeys = getPreKeys;
|
|
50
|
+
const generateOrGetPreKeys = (creds, range) => {
|
|
51
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
52
|
+
const remaining = range - avaliable;
|
|
53
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
54
|
+
const newPreKeys = {};
|
|
55
|
+
if (remaining > 0) {
|
|
56
|
+
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
57
|
+
newPreKeys[i] = crypto_1.Curve.generateKeyPair();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
newPreKeys,
|
|
62
|
+
lastPreKeyId,
|
|
63
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range],
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
67
|
+
const xmppSignedPreKey = (key) => ({
|
|
68
|
+
tag: 'skey',
|
|
69
|
+
attrs: {},
|
|
70
|
+
content: [
|
|
71
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
|
|
72
|
+
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
73
|
+
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
exports.xmppSignedPreKey = xmppSignedPreKey;
|
|
77
|
+
const xmppPreKey = (pair, id) => ({
|
|
78
|
+
tag: 'key',
|
|
79
|
+
attrs: {},
|
|
80
|
+
content: [
|
|
81
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
|
|
82
|
+
{ tag: 'value', attrs: {}, content: pair.public }
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
exports.xmppPreKey = xmppPreKey;
|
|
86
|
+
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
87
|
+
const extractKey = (key) => (key ? ({
|
|
88
|
+
keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
|
|
89
|
+
publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
|
|
90
|
+
signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature'),
|
|
91
|
+
}) : undefined);
|
|
92
|
+
const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
|
|
93
|
+
for (const node of nodes) {
|
|
94
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
const chunkSize = 100;
|
|
102
|
+
const chunks = (0, lodash_1.chunk)(nodes, chunkSize);
|
|
103
|
+
for (const nodesChunk of chunks) {
|
|
104
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
105
|
+
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
106
|
+
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
107
|
+
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
108
|
+
const jid = node.attrs.jid;
|
|
109
|
+
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
110
|
+
await repository.injectE2ESession({
|
|
111
|
+
jid,
|
|
112
|
+
session: {
|
|
113
|
+
registrationId: registrationId,
|
|
114
|
+
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
115
|
+
signedPreKey: extractKey(signedKey),
|
|
116
|
+
preKey: extractKey(key)
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
123
|
+
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
124
|
+
const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
|
|
125
|
+
const extracted = [];
|
|
126
|
+
for (const userResult of result) {
|
|
127
|
+
const { devices, id } = userResult;
|
|
128
|
+
const { user } = (0, WABinary_1.jidDecode)(id);
|
|
129
|
+
const deviceList = devices === null || devices === void 0 ? void 0 : devices.deviceList;
|
|
130
|
+
if (Array.isArray(deviceList)) {
|
|
131
|
+
for (const { id: device, keyIndex } of deviceList) {
|
|
132
|
+
if ((!excludeZeroDevices || device !== 0) &&
|
|
133
|
+
(myUser !== user || myDevice !== device) &&
|
|
134
|
+
(device === 0 || !!keyIndex)
|
|
135
|
+
) {
|
|
136
|
+
extracted.push({ user, device });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return extracted;
|
|
142
|
+
};
|
|
143
|
+
exports.extractDeviceJids = extractDeviceJids;
|
|
144
|
+
/**
|
|
145
|
+
* get the next N keys for upload or processing
|
|
146
|
+
* @param count number of pre-keys to get or generate
|
|
147
|
+
*/
|
|
148
|
+
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
149
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
150
|
+
const update = {
|
|
151
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
152
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
153
|
+
};
|
|
154
|
+
await keys.set({ 'pre-key': newPreKeys });
|
|
155
|
+
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
156
|
+
return { update, preKeys };
|
|
157
|
+
};
|
|
158
|
+
exports.getNextPreKeys = getNextPreKeys;
|
|
159
|
+
const getNextPreKeysNode = async (state, count) => {
|
|
160
|
+
const { creds } = state;
|
|
161
|
+
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
162
|
+
const node = {
|
|
163
|
+
tag: 'iq',
|
|
164
|
+
attrs: {
|
|
165
|
+
xmlns: 'encrypt',
|
|
166
|
+
type: 'set',
|
|
167
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
168
|
+
},
|
|
169
|
+
content: [
|
|
170
|
+
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
171
|
+
{ tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
|
|
172
|
+
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
173
|
+
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
|
|
174
|
+
(0, exports.xmppSignedPreKey)(creds.signedPreKey)
|
|
175
|
+
]
|
|
176
|
+
};
|
|
177
|
+
return { update, node };
|
|
178
|
+
};
|
|
179
|
+
exports.getNextPreKeysNode = getNextPreKeysNode;
|