@jkt48connect-corp/baileys 7.2.7 → 7.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +838 -94
- package/WAProto/WAProto.proto +969 -88
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +5 -3
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Signal/libsignal.js +18 -9
- package/lib/Socket/groups.js +1 -1
- package/lib/Socket/messages-recv.js +310 -151
- package/lib/Socket/messages-send.js +269 -36
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.js +7 -3
- package/lib/Store/make-in-memory-store.js +13 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +3 -3
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.js +41 -20
- package/lib/Utils/crypto.js +35 -23
- package/lib/Utils/decode-wa-message.js +43 -15
- package/lib/Utils/generics.js +32 -16
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/messages-media.js +38 -47
- package/lib/Utils/messages.js +430 -12
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +17 -3
- package/lib/Utils/validate-connection.js +12 -23
- package/lib/WABinary/decode.js +17 -7
- package/lib/WABinary/encode.js +33 -17
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +4 -1
- package/package.json +15 -10
- package/WAProto/index.d.ts +0 -37016
- package/lib/Defaults/index.d.ts +0 -283
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/business.d.ts +0 -170
- package/lib/Socket/chats.d.ts +0 -80
- package/lib/Socket/community.d.ts +0 -219
- package/lib/Socket/community.js +0 -354
- package/lib/Socket/groups.d.ts +0 -114
- package/lib/Socket/index.d.ts +0 -172
- package/lib/Socket/messages-recv.d.ts +0 -158
- package/lib/Socket/messages-send.d.ts +0 -147
- package/lib/Socket/newsletter.d.ts +0 -133
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -54
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -92
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -97
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -18
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-statev2.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-statev2.js +0 -75
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/index.d.ts +0 -11
package/lib/Utils/chat-utils.js
CHANGED
@@ -305,8 +305,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
|
|
305
305
|
indexValueMap: { ...initial.indexValueMap }
|
306
306
|
};
|
307
307
|
const mutationMap = {};
|
308
|
-
for (
|
309
|
-
const syncd = syncds[i];
|
308
|
+
for (const syncd of syncds) {
|
310
309
|
const { version, keyId, snapshotMac } = syncd;
|
311
310
|
if (syncd.externalMutations) {
|
312
311
|
logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
|
@@ -418,25 +417,31 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
418
417
|
operation: OP.SET
|
419
418
|
};
|
420
419
|
}
|
420
|
+
else if ('deleteForMe' in mod) {
|
421
|
+
const { timestamp, key, deleteMedia } = mod.deleteForMe;
|
422
|
+
patch = {
|
423
|
+
syncAction: {
|
424
|
+
deleteMessageForMeAction: {
|
425
|
+
deleteMedia,
|
426
|
+
messageTimestamp: timestamp
|
427
|
+
}
|
428
|
+
},
|
429
|
+
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
430
|
+
type: 'regular_high',
|
431
|
+
apiVersion: 3,
|
432
|
+
operation: OP.SET
|
433
|
+
};
|
434
|
+
}
|
421
435
|
else if ('clear' in mod) {
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
messageTimestamp: key.timestamp
|
432
|
-
}
|
433
|
-
},
|
434
|
-
index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
|
435
|
-
type: 'regular_high',
|
436
|
-
apiVersion: 3,
|
437
|
-
operation: OP.SET
|
438
|
-
};
|
439
|
-
}
|
436
|
+
patch = {
|
437
|
+
syncAction: {
|
438
|
+
clearChatAction: {} // add message range later
|
439
|
+
},
|
440
|
+
index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
|
441
|
+
type: 'regular_high',
|
442
|
+
apiVersion: 6,
|
443
|
+
operation: OP.SET
|
444
|
+
};
|
440
445
|
}
|
441
446
|
else if ('pin' in mod) {
|
442
447
|
patch = {
|
@@ -491,6 +496,22 @@ const chatModificationToAppPatch = (mod, jid) => {
|
|
491
496
|
operation: OP.SET,
|
492
497
|
};
|
493
498
|
}
|
499
|
+
else if ('addLabel' in mod) {
|
500
|
+
patch = {
|
501
|
+
syncAction: {
|
502
|
+
labelEditAction: {
|
503
|
+
name: mod.addLabel.name,
|
504
|
+
color: mod.addLabel.color,
|
505
|
+
predefinedId: mod.addLabel.predefinedId,
|
506
|
+
deleted: mod.addLabel.deleted
|
507
|
+
}
|
508
|
+
},
|
509
|
+
index: ['label_edit', mod.addLabel.id],
|
510
|
+
type: 'regular',
|
511
|
+
apiVersion: 3,
|
512
|
+
operation: OP.SET,
|
513
|
+
};
|
514
|
+
}
|
494
515
|
else if ('addChatLabel' in mod) {
|
495
516
|
patch = {
|
496
517
|
syncAction: {
|
package/lib/Utils/crypto.js
CHANGED
@@ -15,22 +15,47 @@ 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) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
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
|
+
})();
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
37
|
};
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.
|
39
|
+
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
40
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
41
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
42
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
43
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
44
|
+
exports.aesDecrypt = aesDecrypt;
|
45
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
46
|
+
exports.aesEncrypt = aesEncrypt;
|
47
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
48
|
+
exports.hmacSign = hmacSign;
|
49
|
+
exports.sha256 = sha256;
|
50
|
+
exports.md5 = md5;
|
51
|
+
exports.hkdf = hkdf;
|
52
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
30
53
|
const crypto_1 = require("crypto");
|
31
54
|
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
32
55
|
const libsignal = __importStar(require("libsignal"));
|
56
|
+
const util_1 = require("util");
|
33
57
|
const Defaults_1 = require("../Defaults");
|
58
|
+
const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
|
34
59
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
35
60
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
36
61
|
? pubKey
|
@@ -77,7 +102,6 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
77
102
|
cipher.setAAD(additionalData);
|
78
103
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
79
104
|
}
|
80
|
-
exports.aesEncryptGCM = aesEncryptGCM;
|
81
105
|
/**
|
82
106
|
* decrypt AES 256 GCM;
|
83
107
|
* where the auth tag is suffixed to the ciphertext
|
@@ -92,60 +116,48 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
92
116
|
decipher.setAuthTag(tag);
|
93
117
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
94
118
|
}
|
95
|
-
exports.aesDecryptGCM = aesDecryptGCM;
|
96
119
|
function aesEncryptCTR(plaintext, key, iv) {
|
97
120
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
98
121
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
99
122
|
}
|
100
|
-
exports.aesEncryptCTR = aesEncryptCTR;
|
101
123
|
function aesDecryptCTR(ciphertext, key, iv) {
|
102
124
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
103
125
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
104
126
|
}
|
105
|
-
exports.aesDecryptCTR = aesDecryptCTR;
|
106
127
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
107
128
|
function aesDecrypt(buffer, key) {
|
108
129
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
109
130
|
}
|
110
|
-
exports.aesDecrypt = aesDecrypt;
|
111
131
|
/** decrypt AES 256 CBC */
|
112
132
|
function aesDecryptWithIV(buffer, key, IV) {
|
113
133
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
114
134
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
115
135
|
}
|
116
|
-
exports.aesDecryptWithIV = aesDecryptWithIV;
|
117
136
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
118
137
|
function aesEncrypt(buffer, key) {
|
119
138
|
const IV = (0, crypto_1.randomBytes)(16);
|
120
139
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
121
140
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
122
141
|
}
|
123
|
-
exports.aesEncrypt = aesEncrypt;
|
124
142
|
// encrypt AES 256 CBC with a given IV
|
125
143
|
function aesEncrypWithIV(buffer, key, IV) {
|
126
144
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
127
145
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
128
146
|
}
|
129
|
-
exports.aesEncrypWithIV = aesEncrypWithIV;
|
130
147
|
// sign HMAC using SHA 256
|
131
148
|
function hmacSign(buffer, key, variant = 'sha256') {
|
132
149
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
133
150
|
}
|
134
|
-
exports.hmacSign = hmacSign;
|
135
151
|
function sha256(buffer) {
|
136
152
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
137
153
|
}
|
138
|
-
exports.sha256 = sha256;
|
139
154
|
function md5(buffer) {
|
140
155
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
141
156
|
}
|
142
|
-
exports.md5 = md5;
|
143
157
|
// HKDF key expansion
|
144
158
|
function hkdf(buffer, expandedLength, info) {
|
145
159
|
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
146
160
|
}
|
147
|
-
|
148
|
-
|
149
|
-
return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
|
161
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
162
|
+
return await pbkdf2Promise(pairingCode, salt, 2 << 16, 32, 'sha256');
|
150
163
|
}
|
151
|
-
exports.derivePairingCodeKey = derivePairingCodeKey;
|
@@ -1,11 +1,28 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decryptMessageNode = exports.
|
3
|
+
exports.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
4
|
+
exports.decodeMessageNode = decodeMessageNode;
|
4
5
|
const boom_1 = require("@hapi/boom");
|
5
6
|
const WAProto_1 = require("../../WAProto");
|
6
7
|
const WABinary_1 = require("../WABinary");
|
7
8
|
const generics_1 = require("./generics");
|
8
|
-
|
9
|
+
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
10
|
+
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
11
|
+
exports.NACK_REASONS = {
|
12
|
+
ParsingError: 487,
|
13
|
+
UnrecognizedStanza: 488,
|
14
|
+
UnrecognizedStanzaClass: 489,
|
15
|
+
UnrecognizedStanzaType: 490,
|
16
|
+
InvalidProtobuf: 491,
|
17
|
+
InvalidHostedCompanionStanza: 493,
|
18
|
+
MissingMessageSecret: 495,
|
19
|
+
SignalErrorOldCounter: 496,
|
20
|
+
MessageDeletedOnPeer: 499,
|
21
|
+
UnhandledError: 500,
|
22
|
+
UnsupportedAdminRevoke: 550,
|
23
|
+
UnsupportedLIDGroup: 551,
|
24
|
+
DBOperationFailed: 552
|
25
|
+
};
|
9
26
|
/**
|
10
27
|
* Decode the received node as a message.
|
11
28
|
* @note this will only parse the message, not decrypt it
|
@@ -103,7 +120,6 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
103
120
|
sender: msgType === 'chat' ? author : chatId
|
104
121
|
};
|
105
122
|
}
|
106
|
-
exports.decodeMessageNode = decodeMessageNode;
|
107
123
|
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
108
124
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
109
125
|
return {
|
@@ -113,8 +129,11 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
113
129
|
async decrypt() {
|
114
130
|
var _a;
|
115
131
|
let decryptables = 0;
|
116
|
-
|
132
|
+
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
133
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
134
|
+
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
117
135
|
if (msg.senderKeyDistributionMessage) {
|
136
|
+
//eslint-disable-next-line max-depth
|
118
137
|
try {
|
119
138
|
await repository.processSenderKeyDistributionMessage({
|
120
139
|
authorJid: author,
|
@@ -122,14 +141,9 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
122
141
|
});
|
123
142
|
}
|
124
143
|
catch (err) {
|
125
|
-
logger.error({ key: fullMessage.key, err }, 'failed to
|
144
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
126
145
|
}
|
127
146
|
}
|
128
|
-
}
|
129
|
-
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
130
|
-
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
131
|
-
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
132
|
-
await processSenderKeyDistribution(msg);
|
133
147
|
fullMessage.message = msg;
|
134
148
|
decryptables += 1;
|
135
149
|
}
|
@@ -140,7 +154,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
140
154
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
141
155
|
fullMessage.verifiedBizName = details.verifiedName;
|
142
156
|
}
|
143
|
-
if (tag !== 'enc') {
|
157
|
+
if (tag !== 'enc' && tag !== 'plaintext') {
|
144
158
|
continue;
|
145
159
|
}
|
146
160
|
if (!(content instanceof Uint8Array)) {
|
@@ -149,7 +163,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
149
163
|
decryptables += 1;
|
150
164
|
let msgBuffer;
|
151
165
|
try {
|
152
|
-
const e2eType = attrs.type;
|
166
|
+
const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
|
153
167
|
switch (e2eType) {
|
154
168
|
case 'skmsg':
|
155
169
|
msgBuffer = await repository.decryptGroupMessage({
|
@@ -167,12 +181,26 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
167
181
|
ciphertext: content
|
168
182
|
});
|
169
183
|
break;
|
184
|
+
case 'plaintext':
|
185
|
+
msgBuffer = content;
|
186
|
+
break;
|
170
187
|
default:
|
171
188
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
172
189
|
}
|
173
|
-
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
190
|
+
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
|
174
191
|
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
175
|
-
|
192
|
+
if (msg.senderKeyDistributionMessage) {
|
193
|
+
//eslint-disable-next-line max-depth
|
194
|
+
try {
|
195
|
+
await repository.processSenderKeyDistributionMessage({
|
196
|
+
authorJid: author,
|
197
|
+
item: msg.senderKeyDistributionMessage
|
198
|
+
});
|
199
|
+
}
|
200
|
+
catch (err) {
|
201
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
202
|
+
}
|
203
|
+
}
|
176
204
|
if (fullMessage.message) {
|
177
205
|
Object.assign(fullMessage.message, msg);
|
178
206
|
}
|
@@ -190,7 +218,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
190
218
|
// if nothing was found to decrypt
|
191
219
|
if (!decryptables) {
|
192
220
|
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
193
|
-
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT
|
221
|
+
fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
|
194
222
|
}
|
195
223
|
}
|
196
224
|
};
|
package/lib/Utils/generics.js
CHANGED
@@ -3,7 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
7
|
+
exports.promiseTimeout = promiseTimeout;
|
8
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
9
|
+
exports.trimUndefined = trimUndefined;
|
10
|
+
exports.bytesToCrockford = bytesToCrockford;
|
7
11
|
const boom_1 = require("@hapi/boom");
|
8
12
|
const axios_1 = __importDefault(require("axios"));
|
9
13
|
const crypto_1 = require("crypto");
|
@@ -12,22 +16,37 @@ const WAProto_1 = require("../../WAProto");
|
|
12
16
|
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
13
17
|
const Types_1 = require("../Types");
|
14
18
|
const WABinary_1 = require("../WABinary");
|
19
|
+
const COMPANION_PLATFORM_MAP = {
|
20
|
+
'Chrome': '49',
|
21
|
+
'Edge': '50',
|
22
|
+
'Firefox': '51',
|
23
|
+
'Opera': '53',
|
24
|
+
'Safari': '54'
|
25
|
+
};
|
15
26
|
const PLATFORM_MAP = {
|
16
27
|
'aix': 'AIX',
|
17
28
|
'darwin': 'Mac OS',
|
18
29
|
'win32': 'Windows',
|
19
|
-
'android': 'Android'
|
30
|
+
'android': 'Android',
|
31
|
+
'freebsd': 'FreeBSD',
|
32
|
+
'openbsd': 'OpenBSD',
|
33
|
+
'sunos': 'Solaris'
|
20
34
|
};
|
21
35
|
exports.Browsers = {
|
22
|
-
ubuntu: browser => ['Ubuntu', browser, '
|
23
|
-
macOS: browser => ['Mac OS', browser, '
|
24
|
-
baileys: browser => ['Baileys', browser, '
|
25
|
-
windows: browser => ['Windows', browser, '10.0.
|
26
|
-
iOS: browser => ['iOS', browser, '18.2'],
|
27
|
-
linux: browser => ['Linux', browser, '6.12.6'],
|
36
|
+
ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
|
37
|
+
macOS: (browser) => ['Mac OS', browser, '14.4.1'],
|
38
|
+
baileys: (browser) => ['Baileys', browser, '6.5.0'],
|
39
|
+
windows: (browser) => ['Windows', browser, '10.0.22631'],
|
40
|
+
iOS: (browser) => ['iOS', browser, '18.2'],
|
41
|
+
linux: (browser) => ['Linux', browser, '6.12.6'],
|
28
42
|
/** The appropriate browser based on your OS & release */
|
29
|
-
appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
43
|
+
appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
30
44
|
};
|
45
|
+
const getPlatformId = (browser) => {
|
46
|
+
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
47
|
+
return platformType ? platformType.toString().charCodeAt(0).toString() : '49'; //chrome
|
48
|
+
};
|
49
|
+
exports.getPlatformId = getPlatformId;
|
31
50
|
exports.BufferJSON = {
|
32
51
|
replacer: (k, value) => {
|
33
52
|
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
@@ -148,7 +167,6 @@ async function promiseTimeout(ms, promise) {
|
|
148
167
|
.finally(cancel);
|
149
168
|
return p;
|
150
169
|
}
|
151
|
-
exports.promiseTimeout = promiseTimeout;
|
152
170
|
const generateMessageIDV2 = (userId) => {
|
153
171
|
const data = Buffer.alloc(8 + 20 + 16);
|
154
172
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
@@ -162,11 +180,11 @@ const generateMessageIDV2 = (userId) => {
|
|
162
180
|
const random = (0, crypto_1.randomBytes)(16);
|
163
181
|
random.copy(data, 28);
|
164
182
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
165
|
-
return '
|
183
|
+
return 'FizzxyTheGreat-' + hash.toString('hex').toUpperCase().substring(0, 18);
|
166
184
|
};
|
167
185
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
168
186
|
// generate a random ID to attach to a message
|
169
|
-
const generateMessageID = () => '
|
187
|
+
const generateMessageID = () => 'FizzxyTheGreat-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
|
170
188
|
exports.generateMessageID = generateMessageID;
|
171
189
|
function bindWaitForEvent(ev, event) {
|
172
190
|
return async (check, timeoutMs) => {
|
@@ -193,7 +211,6 @@ function bindWaitForEvent(ev, event) {
|
|
193
211
|
}));
|
194
212
|
};
|
195
213
|
}
|
196
|
-
exports.bindWaitForEvent = bindWaitForEvent;
|
197
214
|
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
198
215
|
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
199
216
|
const printQRIfNecessaryListener = (ev, logger) => {
|
@@ -314,7 +331,8 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
314
331
|
status = 'timeout';
|
315
332
|
}
|
316
333
|
else {
|
317
|
-
|
334
|
+
//fired when accepted/rejected/timeout/caller hangs up
|
335
|
+
status = 'terminate';
|
318
336
|
}
|
319
337
|
break;
|
320
338
|
case 'reject':
|
@@ -363,7 +381,6 @@ function trimUndefined(obj) {
|
|
363
381
|
}
|
364
382
|
return obj;
|
365
383
|
}
|
366
|
-
exports.trimUndefined = trimUndefined;
|
367
384
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
368
385
|
function bytesToCrockford(buffer) {
|
369
386
|
let value = 0;
|
@@ -382,4 +399,3 @@ function bytesToCrockford(buffer) {
|
|
382
399
|
}
|
383
400
|
return crockford.join('');
|
384
401
|
}
|
385
|
-
exports.bytesToCrockford = bytesToCrockford;
|
package/lib/Utils/history.js
CHANGED
@@ -32,6 +32,7 @@ const processHistoryMessage = (item) => {
|
|
32
32
|
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
33
33
|
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
34
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
35
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
35
36
|
for (const chat of item.conversations) {
|
36
37
|
contacts.push({ id: chat.id, name: chat.name || undefined });
|
37
38
|
const msgs = chat.messages || [];
|
@@ -74,6 +75,8 @@ const processHistoryMessage = (item) => {
|
|
74
75
|
chats,
|
75
76
|
contacts,
|
76
77
|
messages,
|
78
|
+
syncType: item.syncType,
|
79
|
+
progress: item.progress
|
77
80
|
};
|
78
81
|
};
|
79
82
|
exports.processHistoryMessage = processHistoryMessage;
|
package/lib/Utils/index.js
CHANGED
@@ -28,7 +28,6 @@ __exportStar(require("./lt-hash"), exports);
|
|
28
28
|
__exportStar(require("./auth-utils"), exports);
|
29
29
|
__exportStar(require("./baileys-event-stream"), exports);
|
30
30
|
__exportStar(require("./use-multi-file-auth-state"), exports);
|
31
|
-
__exportStar(require("./use-single-file-auth-statev2"), exports);
|
32
31
|
__exportStar(require("./link-preview"), exports);
|
33
32
|
__exportStar(require("./event-buffer"), exports);
|
34
33
|
__exportStar(require("./process-message"), exports);
|
@@ -15,15 +15,30 @@ 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) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
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
|
+
})();
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.
|
36
|
+
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.hkdfInfoKey = void 0;
|
37
|
+
exports.getMediaKeys = getMediaKeys;
|
38
|
+
exports.getAudioDuration = getAudioDuration;
|
39
|
+
exports.getAudioWaveform = getAudioWaveform;
|
40
|
+
exports.generateThumbnail = generateThumbnail;
|
41
|
+
exports.extensionForMediaMessage = extensionForMediaMessage;
|
27
42
|
const boom_1 = require("@hapi/boom");
|
28
43
|
const child_process_1 = require("child_process");
|
29
44
|
const Crypto = __importStar(require("crypto"));
|
@@ -81,7 +96,6 @@ function getMediaKeys(buffer, mediaType) {
|
|
81
96
|
macKey: expandedMediaKey.slice(48, 80),
|
82
97
|
};
|
83
98
|
}
|
84
|
-
exports.getMediaKeys = getMediaKeys;
|
85
99
|
/** Extracts video thumb using FFMPEG */
|
86
100
|
const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
|
87
101
|
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
|
@@ -142,42 +156,23 @@ const encodeBase64EncodedStringForUpload = (b64) => (encodeURIComponent(b64
|
|
142
156
|
.replace(/\=+$/, '')));
|
143
157
|
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
144
158
|
const generateProfilePicture = async (mediaUpload) => {
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
else if ('url' in mediaUpload) {
|
151
|
-
bufferOrFilePath = mediaUpload.url.toString();
|
152
|
-
}
|
153
|
-
else {
|
154
|
-
bufferOrFilePath = await (0, exports.toBuffer)(mediaUpload.stream);
|
155
|
-
}
|
156
|
-
const lib = await getImageProcessingLibrary();
|
159
|
+
const bufferOrFilePath = Buffer.isBuffer(mediaUpload)
|
160
|
+
? mediaUpload
|
161
|
+
: typeof mediaUpload === 'object' && 'url' in mediaUpload
|
162
|
+
? mediaUpload.url.toString()
|
163
|
+
: await (0, exports.toBuffer)(mediaUpload.stream);
|
157
164
|
let img;
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp;
|
168
|
-
const jimp = await read(bufferOrFilePath);
|
169
|
-
const min = Math.min(jimp.getWidth(), jimp.getHeight());
|
170
|
-
const cropped = jimp.crop(0, 0, min, min);
|
171
|
-
img = cropped
|
172
|
-
.quality(50)
|
173
|
-
.resize(640, 640, RESIZE_BILINEAR)
|
174
|
-
.getBufferAsync(MIME_JPEG);
|
175
|
-
}
|
176
|
-
else {
|
177
|
-
throw new boom_1.Boom('No image processing library available');
|
178
|
-
}
|
165
|
+
const { read, MIME_JPEG, AUTO } = require('jimp');
|
166
|
+
const jimp = await read(bufferOrFilePath);
|
167
|
+
const min = jimp.getWidth();
|
168
|
+
const max = jimp.getHeight();
|
169
|
+
const cropped = jimp.crop(0, 0, min, max);
|
170
|
+
img = cropped
|
171
|
+
.quality(100)
|
172
|
+
.scaleToFit(720, 720, AUTO)
|
173
|
+
.getBufferAsync(MIME_JPEG);
|
179
174
|
return {
|
180
|
-
img: await img
|
175
|
+
img: await img
|
181
176
|
};
|
182
177
|
};
|
183
178
|
exports.generateProfilePicture = generateProfilePicture;
|
@@ -207,7 +202,6 @@ async function getAudioDuration(buffer) {
|
|
207
202
|
}
|
208
203
|
return metadata.format.duration;
|
209
204
|
}
|
210
|
-
exports.getAudioDuration = getAudioDuration;
|
211
205
|
/**
|
212
206
|
referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
|
213
207
|
*/
|
@@ -249,7 +243,6 @@ async function getAudioWaveform(buffer, logger) {
|
|
249
243
|
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
250
244
|
}
|
251
245
|
}
|
252
|
-
exports.getAudioWaveform = getAudioWaveform;
|
253
246
|
const toReadable = (buffer) => {
|
254
247
|
const readable = new stream_1.Readable({ read: () => { } });
|
255
248
|
readable.push(buffer);
|
@@ -311,7 +304,6 @@ async function generateThumbnail(file, mediaType, options) {
|
|
311
304
|
originalImageDimensions
|
312
305
|
};
|
313
306
|
}
|
314
|
-
exports.generateThumbnail = generateThumbnail;
|
315
307
|
const getHttpStream = async (url, options = {}) => {
|
316
308
|
const { default: axios } = await import('axios');
|
317
309
|
const fetched = await axios.get(url.toString(), { ...options, responseType: 'stream' });
|
@@ -565,7 +557,6 @@ function extensionForMediaMessage(message) {
|
|
565
557
|
}
|
566
558
|
return extension;
|
567
559
|
}
|
568
|
-
exports.extensionForMediaMessage = extensionForMediaMessage;
|
569
560
|
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
570
561
|
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
571
562
|
var _a, _b;
|