@genuxofficial/baileys 2.0.0 → 3.0.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/LICENSE +1 -1
- package/WAProto/WAProto.proto +4633 -0
- package/engine-requirements.js +1 -1
- package/lib/Defaults/index.d.ts +5 -3
- package/lib/Defaults/index.js +7 -7
- package/lib/Signal/libsignal.js +9 -18
- package/lib/Socket/Client/types.d.ts +2 -0
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +40 -38
- package/lib/Socket/chats.d.ts +17 -20
- package/lib/Socket/chats.js +1 -85
- package/lib/Socket/groups.d.ts +25 -28
- package/lib/Socket/groups.js +9 -10
- package/lib/Socket/index.d.ts +46 -44
- package/lib/Socket/messages-recv.d.ts +37 -36
- package/lib/Socket/messages-recv.js +14 -26
- package/lib/Socket/messages-send.d.ts +35 -33
- package/lib/Socket/messages-send.js +10 -8
- package/lib/Socket/newsletter.d.ts +28 -31
- package/lib/Socket/newsletter.js +21 -17
- package/lib/Socket/socket.d.ts +7 -5
- package/lib/Socket/socket.js +1 -1
- package/lib/Socket/usync.d.ts +11 -9
- package/lib/Socket/usync.js +15 -10
- package/lib/Store/make-in-memory-store.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Chat.d.ts +2 -8
- package/lib/Types/Contact.d.ts +0 -5
- package/lib/Types/GroupMetadata.d.ts +4 -5
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +27 -2
- package/lib/Types/Newsletter.js +2 -2
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +3 -3
- package/lib/Utils/business.js +17 -5
- package/lib/Utils/chat-utils.d.ts +10 -8
- package/lib/Utils/chat-utils.js +0 -27
- package/lib/Utils/crypto.d.ts +16 -14
- package/lib/Utils/crypto.js +22 -34
- package/lib/Utils/decode-wa-message.d.ts +1 -1
- package/lib/Utils/decode-wa-message.js +16 -31
- package/lib/Utils/generics.d.ts +8 -33
- package/lib/Utils/generics.js +12 -98
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +19 -29
- package/lib/Utils/messages-media.js +87 -151
- package/lib/Utils/messages.d.ts +8 -5
- package/lib/Utils/messages.js +20 -28
- package/lib/Utils/noise-handler.d.ts +6 -4
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/WABinary/decode.d.ts +4 -2
- package/lib/WABinary/decode.js +7 -17
- package/lib/WABinary/encode.d.ts +3 -1
- package/lib/WABinary/encode.js +7 -17
- package/lib/WABinary/generic-utils.d.ts +6 -6
- package/lib/WABinary/generic-utils.js +36 -21
- package/lib/WABinary/jid-utils.d.ts +6 -2
- package/lib/WABinary/jid-utils.js +5 -1
- package/lib/WAM/BinaryInfo.d.ts +12 -2
- package/lib/WAM/encode.d.ts +3 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +23 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +13 -17
- package/package.json +59 -53
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
package/lib/Utils/crypto.js
CHANGED
@@ -15,38 +15,15 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return ownKeys(o);
|
26
|
-
};
|
27
|
-
return function (mod) {
|
28
|
-
if (mod && mod.__esModule) return mod;
|
29
|
-
var result = {};
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
-
__setModuleDefault(result, mod);
|
32
|
-
return result;
|
33
|
-
};
|
34
|
-
})();
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
35
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
36
|
-
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
37
|
-
exports.aesEncryptGCM = aesEncryptGCM;
|
38
|
-
exports.aesDecryptGCM = aesDecryptGCM;
|
39
|
-
exports.aesEncryptCTR = aesEncryptCTR;
|
40
|
-
exports.aesDecryptCTR = aesDecryptCTR;
|
41
|
-
exports.aesDecrypt = aesDecrypt;
|
42
|
-
exports.aesDecryptWithIV = aesDecryptWithIV;
|
43
|
-
exports.aesEncrypt = aesEncrypt;
|
44
|
-
exports.aesEncrypWithIV = aesEncrypWithIV;
|
45
|
-
exports.hmacSign = hmacSign;
|
46
|
-
exports.sha256 = sha256;
|
47
|
-
exports.md5 = md5;
|
48
|
-
exports.hkdf = hkdf;
|
49
|
-
exports.derivePairingCodeKey = derivePairingCodeKey;
|
26
|
+
exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exports.hmacSign = exports.aesEncrypWithIV = exports.aesEncrypt = exports.aesDecryptWithIV = exports.aesDecrypt = exports.aesDecryptCTR = exports.aesEncryptCTR = exports.aesDecryptGCM = exports.aesEncryptGCM = exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
50
27
|
const crypto_1 = require("crypto");
|
51
28
|
const libsignal = __importStar(require("libsignal"));
|
52
29
|
const Defaults_1 = require("../Defaults");
|
@@ -98,6 +75,7 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
98
75
|
cipher.setAAD(additionalData);
|
99
76
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
100
77
|
}
|
78
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
101
79
|
/**
|
102
80
|
* decrypt AES 256 GCM;
|
103
81
|
* where the auth tag is suffixed to the ciphertext
|
@@ -112,44 +90,54 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
112
90
|
decipher.setAuthTag(tag);
|
113
91
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
114
92
|
}
|
93
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
115
94
|
function aesEncryptCTR(plaintext, key, iv) {
|
116
95
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
117
96
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
118
97
|
}
|
98
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
119
99
|
function aesDecryptCTR(ciphertext, key, iv) {
|
120
100
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
121
101
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
122
102
|
}
|
103
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
123
104
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
124
105
|
function aesDecrypt(buffer, key) {
|
125
106
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
126
107
|
}
|
108
|
+
exports.aesDecrypt = aesDecrypt;
|
127
109
|
/** decrypt AES 256 CBC */
|
128
110
|
function aesDecryptWithIV(buffer, key, IV) {
|
129
111
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
130
112
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
131
113
|
}
|
114
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
132
115
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
133
116
|
function aesEncrypt(buffer, key) {
|
134
117
|
const IV = (0, crypto_1.randomBytes)(16);
|
135
118
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
136
119
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
137
120
|
}
|
121
|
+
exports.aesEncrypt = aesEncrypt;
|
138
122
|
// encrypt AES 256 CBC with a given IV
|
139
123
|
function aesEncrypWithIV(buffer, key, IV) {
|
140
124
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
141
125
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
142
126
|
}
|
127
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
143
128
|
// sign HMAC using SHA 256
|
144
129
|
function hmacSign(buffer, key, variant = 'sha256') {
|
145
130
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
146
131
|
}
|
132
|
+
exports.hmacSign = hmacSign;
|
147
133
|
function sha256(buffer) {
|
148
134
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
149
135
|
}
|
136
|
+
exports.sha256 = sha256;
|
150
137
|
function md5(buffer) {
|
151
138
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
152
139
|
}
|
140
|
+
exports.md5 = md5;
|
153
141
|
// HKDF key expansion
|
154
142
|
async function hkdf(buffer, expandedLength, info) {
|
155
143
|
// Ensure we have a Uint8Array for the key material
|
@@ -159,9 +147,7 @@ async function hkdf(buffer, expandedLength, info) {
|
|
159
147
|
// Set default values if not provided
|
160
148
|
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
161
149
|
const infoBytes = info.info
|
162
|
-
? (
|
163
|
-
? new TextEncoder().encode(info.info)
|
164
|
-
: new Uint8Array(info.info))
|
150
|
+
? new TextEncoder().encode(info.info)
|
165
151
|
: new Uint8Array(0);
|
166
152
|
// Import the input key material
|
167
153
|
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
@@ -175,6 +161,7 @@ async function hkdf(buffer, expandedLength, info) {
|
|
175
161
|
);
|
176
162
|
return Buffer.from(derivedBits);
|
177
163
|
}
|
164
|
+
exports.hkdf = hkdf;
|
178
165
|
async function derivePairingCodeKey(pairingCode, salt) {
|
179
166
|
// Convert inputs to formats Web Crypto API can work with
|
180
167
|
const encoder = new TextEncoder();
|
@@ -193,3 +180,4 @@ async function derivePairingCodeKey(pairingCode, salt) {
|
|
193
180
|
);
|
194
181
|
return Buffer.from(derivedBits);
|
195
182
|
}
|
183
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
@@ -19,7 +19,6 @@ export declare const NACK_REASONS: {
|
|
19
19
|
UnsupportedLIDGroup: number;
|
20
20
|
DBOperationFailed: number;
|
21
21
|
};
|
22
|
-
type GetMessage = (key: WAMessageKey) => Promise<proto.IMessage | undefined>;
|
23
22
|
/**
|
24
23
|
* Decode the received node as a message.
|
25
24
|
* @note this will only parse the message, not decrypt it
|
@@ -29,6 +28,7 @@ export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLi
|
|
29
28
|
author: string;
|
30
29
|
sender: string;
|
31
30
|
};
|
31
|
+
type GetMessage = (key: WAMessageKey) => Promise<proto.IMessage | undefined>;
|
32
32
|
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger, getMessage: GetMessage) => {
|
33
33
|
fullMessage: proto.IWebMessageInfo;
|
34
34
|
category: string;
|
@@ -1,13 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
4
|
-
exports.decodeMessageNode = decodeMessageNode;
|
6
|
+
exports.decryptMessageNode = exports.decodeMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
5
7
|
const boom_1 = require("@hapi/boom");
|
6
8
|
const WAProto_1 = require("../../WAProto");
|
7
9
|
const WABinary_1 = require("../WABinary");
|
8
10
|
const generics_1 = require("./generics");
|
9
|
-
const crypto_1 = require("
|
10
|
-
const
|
11
|
+
const crypto_1 = require("crypto");
|
12
|
+
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
11
13
|
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
12
14
|
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
13
15
|
const BOT_MESSAGE_CONSTANT = "Bot Message";
|
@@ -32,7 +34,7 @@ const deriveMessageSecret = async (messageSecret) => {
|
|
32
34
|
const secretBuffer = Buffer.isBuffer(messageSecret)
|
33
35
|
? messageSecret
|
34
36
|
: Buffer.from(messageSecret.buffer, messageSecret.byteOffset, messageSecret.length);
|
35
|
-
return await (0,
|
37
|
+
return await (0, futoin_hkdf_1.default)(secretBuffer, KEY_LENGTH, { salt: undefined, info: BOT_MESSAGE_CONSTANT, hash: "SHA-256" });
|
36
38
|
};
|
37
39
|
const buildDecryptionKey = async (messageID, botJID, targetJID, messageSecret) => {
|
38
40
|
const derivedSecret = await deriveMessageSecret(messageSecret);
|
@@ -42,7 +44,7 @@ const buildDecryptionKey = async (messageID, botJID, targetJID, messageSecret) =
|
|
42
44
|
Buffer.from(botJID),
|
43
45
|
Buffer.from("")
|
44
46
|
]);
|
45
|
-
return await (0,
|
47
|
+
return await (0, futoin_hkdf_1.default)(derivedSecret, KEY_LENGTH, { salt: undefined, info: useCaseSecret, hash: "SHA-256" });
|
46
48
|
};
|
47
49
|
const decryptBotMessage = async (encPayload, encIv, messageID, botJID, decryptionKey) => {
|
48
50
|
encPayload = Buffer.isBuffer(encPayload) ? encPayload : Buffer.from(encPayload);
|
@@ -62,7 +64,7 @@ const decryptBotMessage = async (encPayload, encIv, messageID, botJID, decryptio
|
|
62
64
|
Buffer.from(botJID)
|
63
65
|
]);
|
64
66
|
try {
|
65
|
-
const decipher = (0,
|
67
|
+
const decipher = (0, crypto_1.createDecipheriv)("aes-256-gcm", decryptionKey, encIv);
|
66
68
|
decipher.setAAD(aad);
|
67
69
|
decipher.setAuthTag(authTag);
|
68
70
|
const decrypted = Buffer.concat([
|
@@ -115,14 +117,10 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
115
117
|
let msgType;
|
116
118
|
let chatId;
|
117
119
|
let author;
|
118
|
-
let userLid;
|
119
120
|
const msgId = stanza.attrs.id;
|
120
121
|
const from = stanza.attrs.from;
|
121
|
-
const participant = stanza.attrs.participant;
|
122
|
-
const participantLid = stanza.attrs.participant_lid;
|
122
|
+
const participant = stanza.attrs.participant_pn || stanza.attrs.participant;
|
123
123
|
const recipient = stanza.attrs.recipient;
|
124
|
-
const peerRecipientLid = stanza.attrs.peer_recipient_lid;
|
125
|
-
const senderLid = stanza.attrs.sender_lid;
|
126
124
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
127
125
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
128
126
|
if ((0, WABinary_1.isJidMetaAI)(from) || (0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
|
@@ -131,11 +129,9 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
131
129
|
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
132
130
|
}
|
133
131
|
chatId = recipient;
|
134
|
-
userLid = peerRecipientLid;
|
135
132
|
}
|
136
133
|
else {
|
137
134
|
chatId = from;
|
138
|
-
userLid = senderLid;
|
139
135
|
}
|
140
136
|
msgType = 'chat';
|
141
137
|
author = from;
|
@@ -147,7 +143,6 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
147
143
|
msgType = 'group';
|
148
144
|
author = participant;
|
149
145
|
chatId = from;
|
150
|
-
userLid = participantLid;
|
151
146
|
}
|
152
147
|
else if ((0, WABinary_1.isJidNewsletter)(from)) {
|
153
148
|
msgType = 'newsletter';
|
@@ -156,7 +151,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
156
151
|
}
|
157
152
|
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
158
153
|
if (!participant) {
|
159
|
-
throw new boom_1.Boom('No participant in
|
154
|
+
throw new boom_1.Boom('No participant in group message');
|
160
155
|
}
|
161
156
|
const isParticipantMe = isMe(participant);
|
162
157
|
if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
|
@@ -167,13 +162,6 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
167
162
|
}
|
168
163
|
chatId = from;
|
169
164
|
author = participant;
|
170
|
-
userLid = participantLid;
|
171
|
-
}
|
172
|
-
else if ((0, WABinary_1.isJidNewsletter)(from)) {
|
173
|
-
msgType = 'newsletter';
|
174
|
-
author = from;
|
175
|
-
chatId = from;
|
176
|
-
userLid = participantLid;
|
177
165
|
}
|
178
166
|
else {
|
179
167
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
@@ -185,8 +173,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
185
173
|
fromMe,
|
186
174
|
id: msgId,
|
187
175
|
participant,
|
188
|
-
|
189
|
-
'server_id': (_c = stanza.attrs) === null || _c === void 0 ? void 0 : _c.server_id
|
176
|
+
server_id: (_c = stanza.attrs) === null || _c === void 0 ? void 0 : _c.server_id
|
190
177
|
};
|
191
178
|
const fullMessage = {
|
192
179
|
key,
|
@@ -206,6 +193,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
206
193
|
sender: msgType === 'chat' ? author : chatId
|
207
194
|
};
|
208
195
|
}
|
196
|
+
exports.decodeMessageNode = decodeMessageNode;
|
209
197
|
const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage) => {
|
210
198
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
211
199
|
let metaTargetId = null;
|
@@ -272,7 +260,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage)
|
|
272
260
|
ciphertext: content
|
273
261
|
});
|
274
262
|
break;
|
275
|
-
case 'msmsg':
|
263
|
+
case 'msmsg': //Message Secret Message
|
276
264
|
let msgRequestkey = {
|
277
265
|
remoteJid: stanza.attrs.from,
|
278
266
|
id: metaTargetId
|
@@ -282,7 +270,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage)
|
|
282
270
|
if (!messageSecret) {
|
283
271
|
throw new Error('Message secret not found');
|
284
272
|
}
|
285
|
-
//
|
273
|
+
//Only decrypts when it is the complete message
|
286
274
|
if (botType == 'last') {
|
287
275
|
const newkey = {
|
288
276
|
participant: stanza.attrs.from,
|
@@ -302,14 +290,11 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger, getMessage)
|
|
302
290
|
case 'plaintext':
|
303
291
|
msgBuffer = content;
|
304
292
|
break;
|
305
|
-
case undefined:
|
306
|
-
msgBuffer = content;
|
307
|
-
break;
|
308
293
|
default:
|
309
294
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
310
295
|
}
|
311
296
|
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' && !hasMsmsg ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
312
|
-
//
|
297
|
+
//It's necessary to save the messageContextInfo in the store to decrypt messages from bots
|
313
298
|
msg = ((_b = msg.deviceSentMessage) === null || _b === void 0 ? void 0 : _b.message) ? { ...msg.deviceSentMessage.message, messageContextInfo: msg.messageContextInfo } : msg;
|
314
299
|
if (msg.senderKeyDistributionMessage) {
|
315
300
|
try {
|
package/lib/Utils/generics.d.ts
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
1
3
|
import { AxiosRequestConfig } from 'axios';
|
2
4
|
import { ILogger } from './logger';
|
3
5
|
import { proto } from '../../WAProto';
|
4
6
|
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
|
5
7
|
import { BinaryNode } from '../WABinary';
|
6
8
|
export declare const Browsers: BrowsersMap;
|
7
|
-
/** Other Browser Support for Paircode */
|
8
9
|
export declare const getPlatformId: (browser: string) => any;
|
9
10
|
export declare const BufferJSON: {
|
10
11
|
replacer: (k: any, value: any) => any;
|
11
12
|
reviver: (_: any, value: any) => any;
|
12
13
|
};
|
13
14
|
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
14
|
-
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer
|
15
|
-
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array
|
16
|
-
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer
|
17
|
-
export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array
|
15
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
|
16
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
|
17
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
|
18
|
+
export declare const encodeNewsletterMessage: (message: proto.IMessage) => Uint8Array;
|
18
19
|
export declare const generateRegistrationId: () => number;
|
19
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
|
20
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
|
20
21
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
21
22
|
/** unix timestamp of a date in seconds */
|
22
23
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
@@ -51,32 +52,6 @@ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<an
|
|
51
52
|
isLatest: boolean;
|
52
53
|
error: any;
|
53
54
|
}>;
|
54
|
-
/**
|
55
|
-
* utility that fetches latest baileys version from the main branch.
|
56
|
-
* Use to ensure your WA connection is always on the latest version
|
57
|
-
*/
|
58
|
-
export declare const fetchLatestBaileysVersion3: (options?: AxiosRequestConfig<any>) => Promise<{
|
59
|
-
version: number[];
|
60
|
-
isLatest: boolean;
|
61
|
-
error?: undefined;
|
62
|
-
} | {
|
63
|
-
version: WAVersion;
|
64
|
-
isLatest: boolean;
|
65
|
-
error: any;
|
66
|
-
}>;
|
67
|
-
/**
|
68
|
-
* utility that fetches latest baileys version from the master branch.
|
69
|
-
* Use to ensure your WA connection is always on the latest version
|
70
|
-
*/
|
71
|
-
export declare const fetchLatestBaileysVersion2: (options?: AxiosRequestConfig<any>) => Promise<{
|
72
|
-
version: WAVersion;
|
73
|
-
isLatest: boolean;
|
74
|
-
error?: undefined;
|
75
|
-
} | {
|
76
|
-
version: WAVersion;
|
77
|
-
isLatest: boolean;
|
78
|
-
error: any;
|
79
|
-
}>;
|
80
55
|
/**
|
81
56
|
* A utility that fetches the latest web version of whatsapp.
|
82
57
|
* Use to ensure your WA connection is always on the latest version
|
@@ -111,7 +86,7 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
111
86
|
* Is the given platform WA business
|
112
87
|
* @param platform AuthenticationCreds.platform
|
113
88
|
*/
|
114
|
-
export declare const isWABusinessPlatform: (platform: string) =>
|
89
|
+
export declare const isWABusinessPlatform: (platform: string) => boolean;
|
115
90
|
export declare function trimUndefined(obj: {
|
116
91
|
[_: string]: any;
|
117
92
|
}): {
|
package/lib/Utils/generics.js
CHANGED
@@ -1,46 +1,9 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
19
|
-
var ownKeys = function(o) {
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
-
var ar = [];
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
-
return ar;
|
24
|
-
};
|
25
|
-
return ownKeys(o);
|
26
|
-
};
|
27
|
-
return function (mod) {
|
28
|
-
if (mod && mod.__esModule) return mod;
|
29
|
-
var result = {};
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
-
__setModuleDefault(result, mod);
|
32
|
-
return result;
|
33
|
-
};
|
34
|
-
})();
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
37
4
|
};
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.
|
40
|
-
exports.promiseTimeout = promiseTimeout;
|
41
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
42
|
-
exports.trimUndefined = trimUndefined;
|
43
|
-
exports.bytesToCrockford = bytesToCrockford;
|
6
|
+
exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
44
7
|
const boom_1 = require("@hapi/boom");
|
45
8
|
const axios_1 = __importDefault(require("axios"));
|
46
9
|
const crypto_1 = require("crypto");
|
@@ -66,18 +29,16 @@ const PLATFORM_MAP = {
|
|
66
29
|
'sunos': 'Solaris'
|
67
30
|
};
|
68
31
|
exports.Browsers = {
|
69
|
-
ubuntu: (browser) => ['Ubuntu', browser, '
|
32
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
70
33
|
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
71
|
-
baileys: (browser) => ['Baileys', browser, '6.
|
34
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
72
35
|
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
73
|
-
// iOS: (browser) => ['iOS', browser, '18.1'],
|
74
36
|
/** The appropriate browser based on your OS & release */
|
75
37
|
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
76
38
|
};
|
77
|
-
/** Other Browser Support for Paircode */
|
78
39
|
const getPlatformId = (browser) => {
|
79
40
|
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
80
|
-
return platformType ? platformType.toString() : '
|
41
|
+
return platformType ? platformType.toString() : '49'; //chrome
|
81
42
|
};
|
82
43
|
exports.getPlatformId = getPlatformId;
|
83
44
|
exports.BufferJSON = {
|
@@ -202,6 +163,7 @@ async function promiseTimeout(ms, promise) {
|
|
202
163
|
.finally(cancel);
|
203
164
|
return p;
|
204
165
|
}
|
166
|
+
exports.promiseTimeout = promiseTimeout;
|
205
167
|
const generateMessageIDV2 = (userId) => {
|
206
168
|
const data = Buffer.alloc(8 + 20 + 16);
|
207
169
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
@@ -215,11 +177,11 @@ const generateMessageIDV2 = (userId) => {
|
|
215
177
|
const random = (0, crypto_1.randomBytes)(16);
|
216
178
|
random.copy(data, 28);
|
217
179
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
218
|
-
return '
|
180
|
+
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
219
181
|
};
|
220
182
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
221
183
|
// generate a random ID to attach to a message
|
222
|
-
const generateMessageID = () => '
|
184
|
+
const generateMessageID = () => '3EB0' + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase();
|
223
185
|
exports.generateMessageID = generateMessageID;
|
224
186
|
function bindWaitForEvent(ev, event) {
|
225
187
|
return async (check, timeoutMs) => {
|
@@ -246,12 +208,14 @@ function bindWaitForEvent(ev, event) {
|
|
246
208
|
}));
|
247
209
|
};
|
248
210
|
}
|
211
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
249
212
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
250
213
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
251
214
|
const printQRIfNecessaryListener = (ev, logger) => {
|
252
215
|
ev.on('connection.update', async ({ qr }) => {
|
253
216
|
if (qr) {
|
254
|
-
const QR = await
|
217
|
+
const QR = await import('qrcode-terminal')
|
218
|
+
.then(m => m.default || m)
|
255
219
|
.catch(() => {
|
256
220
|
logger.error('QR code terminal not added as dependency');
|
257
221
|
});
|
@@ -285,57 +249,6 @@ const fetchLatestBaileysVersion = async (options = {}) => {
|
|
285
249
|
}
|
286
250
|
};
|
287
251
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
288
|
-
/**
|
289
|
-
* utility that fetches latest baileys version from the main branch.
|
290
|
-
* Use to ensure your WA connection is always on the latest version
|
291
|
-
*/
|
292
|
-
const fetchLatestBaileysVersion3 = async (options = {}) => {
|
293
|
-
try {
|
294
|
-
const result = await axios_1.default.get('https://raw.githubusercontent.com/wppconnect-team/wa-version/main/versions.json', {
|
295
|
-
...options,
|
296
|
-
responseType: 'json'
|
297
|
-
});
|
298
|
-
const version = result.data.versions[result.data.versions.length - 1].version.split('.');
|
299
|
-
const version2 = version[2].replace('-alpha', '');
|
300
|
-
return {
|
301
|
-
version: [+version[0], +version[1], +version2],
|
302
|
-
isLatest: true
|
303
|
-
};
|
304
|
-
}
|
305
|
-
catch (error) {
|
306
|
-
return {
|
307
|
-
version: baileys_version_json_1.version,
|
308
|
-
isLatest: false,
|
309
|
-
error
|
310
|
-
};
|
311
|
-
}
|
312
|
-
};
|
313
|
-
exports.fetchLatestBaileysVersion3 = fetchLatestBaileysVersion3;
|
314
|
-
/**
|
315
|
-
* utility that fetches latest baileys version from the master branch.
|
316
|
-
* Use to ensure your WA connection is always on the latest version
|
317
|
-
*/
|
318
|
-
const fetchLatestBaileysVersion2 = async (options = {}) => {
|
319
|
-
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
|
320
|
-
try {
|
321
|
-
const result = await axios_1.default.get(URL, {
|
322
|
-
...options,
|
323
|
-
responseType: 'json'
|
324
|
-
});
|
325
|
-
return {
|
326
|
-
version: result.data.version,
|
327
|
-
isLatest: true
|
328
|
-
};
|
329
|
-
}
|
330
|
-
catch (error) {
|
331
|
-
return {
|
332
|
-
version: baileys_version_json_1.version,
|
333
|
-
isLatest: false,
|
334
|
-
error
|
335
|
-
};
|
336
|
-
}
|
337
|
-
};
|
338
|
-
exports.fetchLatestBaileysVersion2 = fetchLatestBaileysVersion2;
|
339
252
|
/**
|
340
253
|
* A utility that fetches the latest web version of whatsapp.
|
341
254
|
* Use to ensure your WA connection is always on the latest version
|
@@ -347,7 +260,6 @@ const fetchLatestWaWebVersion = async (options) => {
|
|
347
260
|
responseType: 'json'
|
348
261
|
});
|
349
262
|
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
350
|
-
const regexx = /\\?"server_revision\\?":\s*(\d+)/;
|
351
263
|
const match = data.match(regex);
|
352
264
|
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
353
265
|
return {
|
@@ -479,6 +391,7 @@ function trimUndefined(obj) {
|
|
479
391
|
}
|
480
392
|
return obj;
|
481
393
|
}
|
394
|
+
exports.trimUndefined = trimUndefined;
|
482
395
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
483
396
|
function bytesToCrockford(buffer) {
|
484
397
|
let value = 0;
|
@@ -497,3 +410,4 @@ function bytesToCrockford(buffer) {
|
|
497
410
|
}
|
498
411
|
return crockford.join('');
|
499
412
|
}
|
413
|
+
exports.bytesToCrockford = bytesToCrockford;
|
@@ -1,37 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
19
|
-
var ownKeys = function(o) {
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
-
var ar = [];
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
-
return ar;
|
24
|
-
};
|
25
|
-
return ownKeys(o);
|
26
|
-
};
|
27
|
-
return function (mod) {
|
28
|
-
if (mod && mod.__esModule) return mod;
|
29
|
-
var result = {};
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
-
__setModuleDefault(result, mod);
|
32
|
-
return result;
|
33
|
-
};
|
34
|
-
})();
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
36
3
|
exports.getUrlInfo = void 0;
|
37
4
|
const messages_1 = require("./messages");
|
@@ -58,7 +25,7 @@ const getUrlInfo = async (text, opts = {
|
|
58
25
|
// retries
|
59
26
|
const retries = 0;
|
60
27
|
const maxRetry = 5;
|
61
|
-
const { getLinkPreview } = await
|
28
|
+
const { getLinkPreview } = await import('link-preview-js');
|
62
29
|
let previewLink = text;
|
63
30
|
if (!text.startsWith('https://') && !text.startsWith('http://')) {
|
64
31
|
previewLink = 'https://' + previewLink;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export declare const makeMutex: () => {
|
2
|
-
mutex<T>(code: () =>
|
2
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
3
3
|
};
|
4
4
|
export type Mutex = ReturnType<typeof makeMutex>;
|
5
5
|
export declare const makeKeyedMutex: () => {
|
6
|
-
mutex<T>(key: string, task: () =>
|
6
|
+
mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
|
7
7
|
};
|