@jkt48connect-corp/baileys 7.2.7 → 7.2.8
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.d.ts +13199 -1260
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +7 -8
- 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/Client/abstract-socket-client.d.ts +0 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -1
- package/lib/Socket/business.d.ts +40 -40
- package/lib/Socket/chats.d.ts +13 -14
- package/lib/Socket/groups.d.ts +20 -21
- package/lib/Socket/groups.js +1 -1
- package/lib/Socket/index.d.ts +49 -49
- package/lib/Socket/messages-recv.d.ts +39 -39
- package/lib/Socket/messages-recv.js +310 -151
- package/lib/Socket/messages-send.d.ts +33 -31
- package/lib/Socket/messages-send.js +269 -36
- package/lib/Socket/newsletter.d.ts +24 -25
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/registration.d.ts +49 -52
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +6 -7
- package/lib/Socket/socket.js +7 -3
- package/lib/Store/make-cache-manager-store.d.ts +1 -0
- package/lib/Store/make-in-memory-store.d.ts +3 -4
- package/lib/Store/make-in-memory-store.js +13 -11
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +0 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +12 -7
- package/lib/Types/Events.d.ts +17 -2
- package/lib/Types/GroupMetadata.d.ts +3 -1
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +164 -13
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/Socket.d.ts +7 -2
- package/lib/Types/index.d.ts +9 -0
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +3 -3
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +11 -12
- package/lib/Utils/chat-utils.js +41 -20
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +35 -23
- package/lib/Utils/decode-wa-message.d.ts +17 -0
- package/lib/Utils/decode-wa-message.js +43 -15
- package/lib/Utils/generics.d.ts +10 -19
- package/lib/Utils/generics.js +32 -16
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/index.d.ts +0 -1
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/logger.d.ts +1 -3
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +25 -28
- package/lib/Utils/messages-media.js +38 -47
- package/lib/Utils/messages.d.ts +5 -8
- package/lib/Utils/messages.js +430 -12
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +17 -3
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +12 -23
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +17 -7
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +33 -17
- package/lib/WABinary/generic-utils.d.ts +2 -3
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +4 -1
- package/package.json +15 -10
- package/lib/Socket/community.d.ts +0 -219
- package/lib/Socket/community.js +0 -354
- 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/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.d.ts
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
/// <reference types="node" />
|
2
1
|
import { KeyPair } from '../Types';
|
3
2
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
4
|
-
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) =>
|
3
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => any;
|
5
4
|
export declare const Curve: {
|
6
5
|
generateKeyPair: () => KeyPair;
|
7
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) =>
|
6
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => any;
|
8
7
|
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
9
8
|
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
10
9
|
};
|
@@ -17,25 +16,25 @@ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) =>
|
|
17
16
|
* encrypt AES 256 GCM;
|
18
17
|
* where the tag tag is suffixed to the ciphertext
|
19
18
|
* */
|
20
|
-
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
19
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
|
21
20
|
/**
|
22
21
|
* decrypt AES 256 GCM;
|
23
22
|
* where the auth tag is suffixed to the ciphertext
|
24
23
|
* */
|
25
|
-
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array):
|
26
|
-
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array):
|
27
|
-
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array):
|
24
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
|
25
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
|
26
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
|
28
27
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
29
|
-
export declare function aesDecrypt(buffer: Buffer, key: Buffer):
|
28
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): any;
|
30
29
|
/** decrypt AES 256 CBC */
|
31
|
-
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer):
|
32
|
-
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer):
|
33
|
-
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer):
|
34
|
-
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'):
|
35
|
-
export declare function sha256(buffer: Buffer):
|
36
|
-
export declare function md5(buffer: Buffer):
|
30
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
|
31
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): any;
|
32
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
|
33
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): any;
|
34
|
+
export declare function sha256(buffer: Buffer): any;
|
35
|
+
export declare function md5(buffer: Buffer): any;
|
37
36
|
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
38
37
|
salt?: Buffer;
|
39
38
|
info?: string;
|
40
|
-
}):
|
41
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer):
|
39
|
+
}): any;
|
40
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<any>;
|
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;
|
@@ -2,6 +2,23 @@ import { Logger } from 'pino';
|
|
2
2
|
import { proto } from '../../WAProto';
|
3
3
|
import { SignalRepository } from '../Types';
|
4
4
|
import { BinaryNode } from '../WABinary';
|
5
|
+
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
6
|
+
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
7
|
+
export declare const NACK_REASONS: {
|
8
|
+
ParsingError: number;
|
9
|
+
UnrecognizedStanza: number;
|
10
|
+
UnrecognizedStanzaClass: number;
|
11
|
+
UnrecognizedStanzaType: number;
|
12
|
+
InvalidProtobuf: number;
|
13
|
+
InvalidHostedCompanionStanza: number;
|
14
|
+
MissingMessageSecret: number;
|
15
|
+
SignalErrorOldCounter: number;
|
16
|
+
MessageDeletedOnPeer: number;
|
17
|
+
UnhandledError: number;
|
18
|
+
UnsupportedAdminRevoke: number;
|
19
|
+
UnsupportedLIDGroup: number;
|
20
|
+
DBOperationFailed: number;
|
21
|
+
};
|
5
22
|
/**
|
6
23
|
* Decode the received node as a message.
|
7
24
|
* @note this will only parse the message, not decrypt it
|
@@ -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.d.ts
CHANGED
@@ -1,29 +1,20 @@
|
|
1
|
-
/// <reference types="node" />
|
2
1
|
import { AxiosRequestConfig } from 'axios';
|
3
2
|
import { Logger } from 'pino';
|
4
3
|
import { proto } from '../../WAProto';
|
5
|
-
import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
|
4
|
+
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
|
6
5
|
import { BinaryNode } from '../WABinary';
|
7
|
-
export declare const Browsers:
|
8
|
-
|
9
|
-
macOS: (browser: any) => [string, string, string];
|
10
|
-
baileys: (browser: any) => [string, string, string];
|
11
|
-
windows: (browser: any) => [string, string, string];
|
12
|
-
iOS: (browser: any) => [string, string, string];
|
13
|
-
linux: (browser: any) => [string, string, string];
|
14
|
-
/** The appropriate browser based on your OS & release */
|
15
|
-
appropriate: (browser: any) => [string, string, string];
|
16
|
-
};
|
6
|
+
export declare const Browsers: BrowsersMap;
|
7
|
+
export declare const getPlatformId: (browser: string) => any;
|
17
8
|
export declare const BufferJSON: {
|
18
9
|
replacer: (k: any, value: any) => any;
|
19
10
|
reviver: (_: any, value: any) => any;
|
20
11
|
};
|
21
12
|
export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
|
22
|
-
export declare const writeRandomPadMax16: (msg: Uint8Array) =>
|
23
|
-
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array
|
24
|
-
export declare const encodeWAMessage: (message: proto.IMessage) =>
|
13
|
+
export declare const writeRandomPadMax16: (msg: Uint8Array) => any;
|
14
|
+
export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array<any>;
|
15
|
+
export declare const encodeWAMessage: (message: proto.IMessage) => any;
|
25
16
|
export declare const generateRegistrationId: () => number;
|
26
|
-
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array
|
17
|
+
export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array<ArrayBuffer>;
|
27
18
|
export declare const toNumber: (t: Long | number | null | undefined) => number;
|
28
19
|
/** unix timestamp of a date in seconds */
|
29
20
|
export declare const unixTimestampSeconds: (date?: Date) => number;
|
@@ -43,14 +34,14 @@ export declare function promiseTimeout<T>(ms: number | undefined, promise: (reso
|
|
43
34
|
export declare const generateMessageIDV2: (userId?: string) => string;
|
44
35
|
export declare const generateMessageID: () => string;
|
45
36
|
export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
46
|
-
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<
|
37
|
+
export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
47
38
|
export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
|
48
39
|
/**
|
49
40
|
* utility that fetches latest baileys version from the master branch.
|
50
41
|
* Use to ensure your WA connection is always on the latest version
|
51
42
|
*/
|
52
43
|
export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
|
53
|
-
version:
|
44
|
+
version: any;
|
54
45
|
isLatest: boolean;
|
55
46
|
error?: undefined;
|
56
47
|
} | {
|
@@ -92,6 +83,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
|
|
92
83
|
* Is the given platform WA business
|
93
84
|
* @param platform AuthenticationCreds.platform
|
94
85
|
*/
|
95
|
-
export declare const isWABusinessPlatform: (platform: string) =>
|
86
|
+
export declare const isWABusinessPlatform: (platform: string) => platform is "smbi" | "smba";
|
96
87
|
export declare function trimUndefined(obj: any): any;
|
97
88
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
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.d.ts
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
2
2
|
import { proto } from '../../WAProto';
|
3
3
|
import { Chat, Contact } from '../Types';
|
4
|
-
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
4
|
+
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
6
6
|
chats: Chat[];
|
7
7
|
contacts: Contact[];
|
8
8
|
messages: proto.IWebMessageInfo[];
|
9
|
+
syncType: proto.HistorySync.HistorySyncType;
|
10
|
+
progress: number | null | undefined;
|
9
11
|
};
|
10
|
-
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<
|
12
|
+
export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
|
11
13
|
chats: Chat[];
|
12
14
|
contacts: Contact[];
|
13
15
|
messages: proto.IWebMessageInfo[];
|
16
|
+
syncType: proto.HistorySync.HistorySyncType;
|
17
|
+
progress: number | null | undefined;
|
14
18
|
}>;
|
15
19
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
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.d.ts
CHANGED
@@ -12,7 +12,6 @@ export * from './lt-hash';
|
|
12
12
|
export * from './auth-utils';
|
13
13
|
export * from './baileys-event-stream';
|
14
14
|
export * from './use-multi-file-auth-state';
|
15
|
-
export * from './use-single-file-auth-statev2';
|
16
15
|
export * from './link-preview';
|
17
16
|
export * from './event-buffer';
|
18
17
|
export * from './process-message';
|
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);
|
package/lib/Utils/logger.d.ts
CHANGED