@hbmodsofc/baileys 1.7.8 → 2.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/index.js +157084 -24729
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +8 -12
- package/lib/Defaults/index.js +124 -90
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/group_cipher.d.ts +1 -0
- package/lib/Signal/Group/group_cipher.js +39 -28
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
- package/lib/Signal/Group/sender-chain-key.js +2 -9
- package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
- package/lib/Signal/Group/sender-key-message.js +3 -3
- package/lib/Signal/Group/sender-key-state.d.ts +4 -4
- package/lib/Signal/Group/sender-key-state.js +16 -47
- package/lib/Signal/libsignal.d.ts +3 -7
- package/lib/Signal/libsignal.js +39 -224
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +16 -10
- package/lib/Socket/business.d.ts +78 -94
- package/lib/Socket/business.js +11 -130
- package/lib/Socket/chats.d.ts +233 -63
- package/lib/Socket/chats.js +184 -234
- package/lib/Socket/groups.d.ts +41 -62
- package/lib/Socket/groups.js +64 -76
- package/lib/Socket/hbmods.d.ts +253 -0
- package/lib/Socket/hbmods.js +1 -0
- package/lib/Socket/index.d.ts +83 -129
- package/lib/Socket/index.js +6 -13
- package/lib/Socket/messages-recv.d.ts +48 -59
- package/lib/Socket/messages-recv.js +371 -516
- package/lib/Socket/messages-send.d.ts +67 -86
- package/lib/Socket/messages-send.js +1 -1091
- package/lib/Socket/newsletter.d.ts +64 -76
- package/lib/Socket/newsletter.js +1 -184
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +13 -19
- package/lib/Socket/socket.js +1 -805
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Types/Auth.d.ts +10 -4
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +9 -29
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +14 -55
- package/lib/Types/GroupMetadata.d.ts +5 -15
- 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 +49 -75
- package/lib/Types/Message.js +7 -10
- package/lib/Types/Newsletter.d.ts +98 -129
- package/lib/Types/Newsletter.js +38 -33
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +1 -29
- package/lib/Types/Socket.d.ts +22 -48
- package/lib/Types/State.d.ts +2 -13
- package/lib/Types/State.js +0 -12
- package/lib/Types/USync.d.ts +1 -1
- package/lib/Types/index.d.ts +3 -10
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +102 -378
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.d.ts +2 -2
- package/lib/Utils/business.js +13 -19
- package/lib/Utils/chat-utils.d.ts +22 -21
- package/lib/Utils/chat-utils.js +154 -201
- package/lib/Utils/crypto.d.ts +19 -18
- package/lib/Utils/crypto.js +37 -78
- package/lib/Utils/decode-wa-message.d.ts +7 -34
- package/lib/Utils/decode-wa-message.js +66 -138
- package/lib/Utils/event-buffer.d.ts +8 -6
- package/lib/Utils/event-buffer.js +43 -81
- package/lib/Utils/generics.d.ts +27 -27
- package/lib/Utils/generics.js +133 -128
- package/lib/Utils/history.d.ts +5 -9
- package/lib/Utils/history.js +23 -17
- package/lib/Utils/index.d.ts +0 -2
- package/lib/Utils/index.js +0 -2
- package/lib/Utils/link-preview.d.ts +4 -4
- package/lib/Utils/link-preview.js +12 -40
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/lt-hash.d.ts +8 -8
- package/lib/Utils/lt-hash.js +24 -23
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +2 -3
- package/lib/Utils/messages-media.d.ts +41 -37
- package/lib/Utils/messages-media.js +368 -252
- package/lib/Utils/messages.d.ts +15 -13
- package/lib/Utils/messages.js +261 -274
- package/lib/Utils/noise-handler.d.ts +15 -13
- package/lib/Utils/noise-handler.js +26 -20
- package/lib/Utils/process-message.d.ts +8 -9
- package/lib/Utils/process-message.js +93 -157
- package/lib/Utils/signal.d.ts +5 -6
- package/lib/Utils/signal.js +29 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.js +7 -12
- package/lib/Utils/validate-connection.d.ts +6 -5
- package/lib/Utils/validate-connection.js +97 -39
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +14 -28
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +7 -4
- package/lib/WABinary/generic-utils.js +125 -40
- package/lib/WABinary/jid-utils.d.ts +8 -13
- package/lib/WABinary/jid-utils.js +16 -27
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/constants.js +2359 -2252
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.js +11 -8
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
- package/lib/WAUSync/USyncQuery.d.ts +2 -2
- package/lib/WAUSync/USyncQuery.js +15 -19
- package/lib/WAUSync/USyncUser.d.ts +5 -5
- package/lib/WAUSync/index.d.ts +1 -1
- package/lib/WAUSync/index.js +1 -1
- package/package.json +102 -104
- package/lib/Signal/lid-mapping.d.ts +0 -26
- package/lib/Signal/lid-mapping.js +0 -146
- package/lib/Socket/communities.d.ts +0 -232
- package/lib/Socket/communities.js +0 -402
- package/lib/Socket/mex.d.ts +0 -2
- package/lib/Socket/mex.js +0 -45
- package/lib/Types/Bussines.d.ts +0 -24
- package/lib/Types/Bussines.js +0 -2
- package/lib/Utils/lidToJid-test.d.ts +0 -11
- package/lib/Utils/lidToJid-test.js +0 -27
- package/lib/Utils/message-retry-manager.d.ts +0 -81
- package/lib/Utils/message-retry-manager.js +0 -152
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
package/lib/Utils/crypto.d.ts
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { KeyPair } from '../Types';
|
|
2
3
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
3
|
-
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array
|
|
4
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
|
|
4
5
|
export declare const Curve: {
|
|
5
6
|
generateKeyPair: () => KeyPair;
|
|
6
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer
|
|
7
|
-
sign: (privateKey: Uint8Array, buf: Uint8Array) =>
|
|
7
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer;
|
|
8
|
+
sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
|
|
8
9
|
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
|
9
10
|
};
|
|
10
11
|
export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
|
|
11
12
|
keyPair: KeyPair;
|
|
12
|
-
signature:
|
|
13
|
+
signature: any;
|
|
13
14
|
keyId: number;
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
17
|
* encrypt AES 256 GCM;
|
|
17
18
|
* where the tag tag is suffixed to the ciphertext
|
|
18
19
|
* */
|
|
19
|
-
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer
|
|
20
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
|
20
21
|
/**
|
|
21
22
|
* decrypt AES 256 GCM;
|
|
22
23
|
* where the auth tag is suffixed to the ciphertext
|
|
23
24
|
* */
|
|
24
|
-
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer
|
|
25
|
-
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer
|
|
26
|
-
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer
|
|
25
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer;
|
|
26
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
|
27
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer;
|
|
27
28
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
28
|
-
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer
|
|
29
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer;
|
|
29
30
|
/** decrypt AES 256 CBC */
|
|
30
|
-
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer
|
|
31
|
-
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer
|
|
32
|
-
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer
|
|
33
|
-
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer
|
|
34
|
-
export declare function sha256(buffer: Buffer): Buffer
|
|
35
|
-
export declare function md5(buffer: Buffer): Buffer
|
|
31
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
|
|
32
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer;
|
|
33
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer;
|
|
34
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer;
|
|
35
|
+
export declare function sha256(buffer: Buffer): Buffer;
|
|
36
|
+
export declare function md5(buffer: Buffer): Buffer;
|
|
36
37
|
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
|
37
38
|
salt?: Buffer;
|
|
38
39
|
info?: string;
|
|
39
|
-
}):
|
|
40
|
-
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer):
|
|
40
|
+
}): Buffer;
|
|
41
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -15,49 +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) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
|
|
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
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
35
28
|
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;
|
|
29
|
+
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
30
|
const crypto_1 = require("crypto");
|
|
51
|
-
const
|
|
31
|
+
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
32
|
+
const libsignal = __importStar(require("libsignal"));
|
|
52
33
|
const Defaults_1 = require("../Defaults");
|
|
53
|
-
// insure browser & node compatibility
|
|
54
|
-
const { subtle } = globalThis.crypto;
|
|
55
34
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
56
|
-
const generateSignalPubKey = (pubKey) => pubKey.length === 33
|
|
35
|
+
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
36
|
+
? pubKey
|
|
37
|
+
: Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey]));
|
|
57
38
|
exports.generateSignalPubKey = generateSignalPubKey;
|
|
58
39
|
exports.Curve = {
|
|
59
40
|
generateKeyPair: () => {
|
|
60
|
-
const { pubKey, privKey } = curve.generateKeyPair();
|
|
41
|
+
const { pubKey, privKey } = libsignal.curve.generateKeyPair();
|
|
61
42
|
return {
|
|
62
43
|
private: Buffer.from(privKey),
|
|
63
44
|
// remove version byte
|
|
@@ -65,13 +46,13 @@ exports.Curve = {
|
|
|
65
46
|
};
|
|
66
47
|
},
|
|
67
48
|
sharedKey: (privateKey, publicKey) => {
|
|
68
|
-
const shared = curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
|
|
49
|
+
const shared = libsignal.curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
|
|
69
50
|
return Buffer.from(shared);
|
|
70
51
|
},
|
|
71
|
-
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
52
|
+
sign: (privateKey, buf) => (libsignal.curve.calculateSignature(privateKey, buf)),
|
|
72
53
|
verify: (pubKey, message, signature) => {
|
|
73
54
|
try {
|
|
74
|
-
curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
|
|
55
|
+
libsignal.curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
|
|
75
56
|
return true;
|
|
76
57
|
}
|
|
77
58
|
catch (error) {
|
|
@@ -96,6 +77,7 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
96
77
|
cipher.setAAD(additionalData);
|
|
97
78
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
98
79
|
}
|
|
80
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
99
81
|
/**
|
|
100
82
|
* decrypt AES 256 GCM;
|
|
101
83
|
* where the auth tag is suffixed to the ciphertext
|
|
@@ -110,83 +92,60 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
110
92
|
decipher.setAuthTag(tag);
|
|
111
93
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
112
94
|
}
|
|
95
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
113
96
|
function aesEncryptCTR(plaintext, key, iv) {
|
|
114
97
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
115
98
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
116
99
|
}
|
|
100
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
117
101
|
function aesDecryptCTR(ciphertext, key, iv) {
|
|
118
102
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
119
103
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
120
104
|
}
|
|
105
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
121
106
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
122
107
|
function aesDecrypt(buffer, key) {
|
|
123
108
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
124
109
|
}
|
|
110
|
+
exports.aesDecrypt = aesDecrypt;
|
|
125
111
|
/** decrypt AES 256 CBC */
|
|
126
112
|
function aesDecryptWithIV(buffer, key, IV) {
|
|
127
113
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
128
114
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
129
115
|
}
|
|
116
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
130
117
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
131
118
|
function aesEncrypt(buffer, key) {
|
|
132
119
|
const IV = (0, crypto_1.randomBytes)(16);
|
|
133
120
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
134
121
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
135
122
|
}
|
|
123
|
+
exports.aesEncrypt = aesEncrypt;
|
|
136
124
|
// encrypt AES 256 CBC with a given IV
|
|
137
125
|
function aesEncrypWithIV(buffer, key, IV) {
|
|
138
126
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
139
127
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
140
128
|
}
|
|
129
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
141
130
|
// sign HMAC using SHA 256
|
|
142
131
|
function hmacSign(buffer, key, variant = 'sha256') {
|
|
143
132
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
144
133
|
}
|
|
134
|
+
exports.hmacSign = hmacSign;
|
|
145
135
|
function sha256(buffer) {
|
|
146
136
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
147
137
|
}
|
|
138
|
+
exports.sha256 = sha256;
|
|
148
139
|
function md5(buffer) {
|
|
149
140
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
150
141
|
}
|
|
142
|
+
exports.md5 = md5;
|
|
151
143
|
// HKDF key expansion
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// Cloning via new Uint8Array(...) guarantees the generic parameter is ArrayBuffer which satisfies WebCrypto types.
|
|
155
|
-
const inputKeyMaterial = new Uint8Array(buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer));
|
|
156
|
-
// Set default values if not provided
|
|
157
|
-
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
158
|
-
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0);
|
|
159
|
-
// Import the input key material (cast to BufferSource to appease TS DOM typings)
|
|
160
|
-
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, [
|
|
161
|
-
'deriveBits'
|
|
162
|
-
]);
|
|
163
|
-
// Derive bits using HKDF
|
|
164
|
-
const derivedBits = await subtle.deriveBits({
|
|
165
|
-
name: 'HKDF',
|
|
166
|
-
hash: 'SHA-256',
|
|
167
|
-
salt: salt,
|
|
168
|
-
info: infoBytes
|
|
169
|
-
}, importedKey, expandedLength * 8 // Convert bytes to bits
|
|
170
|
-
);
|
|
171
|
-
return Buffer.from(derivedBits);
|
|
144
|
+
function hkdf(buffer, expandedLength, info) {
|
|
145
|
+
return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
|
|
172
146
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
177
|
-
const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
|
|
178
|
-
// Import the pairing code as key material
|
|
179
|
-
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
|
|
180
|
-
'deriveBits'
|
|
181
|
-
]);
|
|
182
|
-
// Derive bits using PBKDF2 with the same parameters
|
|
183
|
-
// 2 << 16 = 131,072 iterations
|
|
184
|
-
const derivedBits = await subtle.deriveBits({
|
|
185
|
-
name: 'PBKDF2',
|
|
186
|
-
salt: saltBuffer,
|
|
187
|
-
iterations: 2 << 16,
|
|
188
|
-
hash: 'SHA-256'
|
|
189
|
-
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
190
|
-
);
|
|
191
|
-
return Buffer.from(derivedBits);
|
|
147
|
+
exports.hkdf = hkdf;
|
|
148
|
+
function derivePairingCodeKey(pairingCode, salt) {
|
|
149
|
+
return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
|
|
192
150
|
}
|
|
151
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
@@ -1,45 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
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 DECRYPTION_RETRY_CONFIG: {
|
|
8
|
-
maxRetries: number;
|
|
9
|
-
baseDelayMs: number;
|
|
10
|
-
sessionRecordErrors: string[];
|
|
11
|
-
};
|
|
12
|
-
export declare const NACK_REASONS: {
|
|
13
|
-
ParsingError: number;
|
|
14
|
-
UnrecognizedStanza: number;
|
|
15
|
-
UnrecognizedStanzaClass: number;
|
|
16
|
-
UnrecognizedStanzaType: number;
|
|
17
|
-
InvalidProtobuf: number;
|
|
18
|
-
InvalidHostedCompanionStanza: number;
|
|
19
|
-
MissingMessageSecret: number;
|
|
20
|
-
SignalErrorOldCounter: number;
|
|
21
|
-
MessageDeletedOnPeer: number;
|
|
22
|
-
UnhandledError: number;
|
|
23
|
-
UnsupportedAdminRevoke: number;
|
|
24
|
-
UnsupportedLIDGroup: number;
|
|
25
|
-
DBOperationFailed: number;
|
|
26
|
-
};
|
|
27
|
-
export declare const extractAddressingContext: (stanza: BinaryNode) => {
|
|
28
|
-
addressingMode: string;
|
|
29
|
-
senderAlt: string;
|
|
30
|
-
recipientAlt: string;
|
|
31
|
-
};
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { SignalRepository } from '../Types';
|
|
4
|
+
import { BinaryNode } from '../WABinary';
|
|
32
5
|
/**
|
|
33
6
|
* Decode the received node as a message.
|
|
34
7
|
* @note this will only parse the message, not decrypt it
|
|
35
8
|
*/
|
|
36
9
|
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
37
|
-
fullMessage:
|
|
10
|
+
fullMessage: proto.IWebMessageInfo;
|
|
38
11
|
author: string;
|
|
39
12
|
sender: string;
|
|
40
13
|
};
|
|
41
|
-
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository:
|
|
42
|
-
fullMessage:
|
|
14
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
|
|
15
|
+
fullMessage: proto.IWebMessageInfo;
|
|
43
16
|
category: string;
|
|
44
17
|
author: string;
|
|
45
18
|
decrypt(): Promise<void>;
|
|
@@ -1,87 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decryptMessageNode = exports.
|
|
4
|
-
exports.decodeMessageNode = decodeMessageNode;
|
|
3
|
+
exports.decryptMessageNode = exports.decodeMessageNode = void 0;
|
|
5
4
|
const boom_1 = require("@hapi/boom");
|
|
6
|
-
const
|
|
5
|
+
const WAProto_1 = require("../../WAProto");
|
|
7
6
|
const WABinary_1 = require("../WABinary");
|
|
8
7
|
const generics_1 = require("./generics");
|
|
9
|
-
const
|
|
10
|
-
if (!sender.includes('@s.whatsapp.net')) {
|
|
11
|
-
return sender;
|
|
12
|
-
}
|
|
13
|
-
return (await repository.lidMapping.getLIDForPN(sender));
|
|
14
|
-
};
|
|
15
|
-
const storeMappingFromEnvelope = async (stanza, sender, decryptionJid, repository, logger) => {
|
|
16
|
-
const { senderAlt } = (0, exports.extractAddressingContext)(stanza);
|
|
17
|
-
if (senderAlt && (0, WABinary_1.isLidUser)(senderAlt) && (0, WABinary_1.isPnUser)(sender) && decryptionJid === sender) {
|
|
18
|
-
try {
|
|
19
|
-
await repository.lidMapping.storeLIDPNMappings([{ lid: senderAlt, pn: sender }]);
|
|
20
|
-
logger.debug({ sender, senderAlt }, 'Stored LID mapping from envelope');
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
logger.warn({ sender, senderAlt, error }, 'Failed to store LID mapping');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
28
|
-
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
29
|
-
// Retry configuration for failed decryption
|
|
30
|
-
exports.DECRYPTION_RETRY_CONFIG = {
|
|
31
|
-
maxRetries: 3,
|
|
32
|
-
baseDelayMs: 100,
|
|
33
|
-
sessionRecordErrors: ['No session record', 'SessionError: No session record']
|
|
34
|
-
};
|
|
35
|
-
exports.NACK_REASONS = {
|
|
36
|
-
ParsingError: 487,
|
|
37
|
-
UnrecognizedStanza: 488,
|
|
38
|
-
UnrecognizedStanzaClass: 489,
|
|
39
|
-
UnrecognizedStanzaType: 490,
|
|
40
|
-
InvalidProtobuf: 491,
|
|
41
|
-
InvalidHostedCompanionStanza: 493,
|
|
42
|
-
MissingMessageSecret: 495,
|
|
43
|
-
SignalErrorOldCounter: 496,
|
|
44
|
-
MessageDeletedOnPeer: 499,
|
|
45
|
-
UnhandledError: 500,
|
|
46
|
-
UnsupportedAdminRevoke: 550,
|
|
47
|
-
UnsupportedLIDGroup: 551,
|
|
48
|
-
DBOperationFailed: 552
|
|
49
|
-
};
|
|
50
|
-
const extractAddressingContext = (stanza) => {
|
|
51
|
-
let senderAlt;
|
|
52
|
-
let recipientAlt;
|
|
53
|
-
const sender = stanza.attrs.participant || stanza.attrs.from;
|
|
54
|
-
const addressingMode = stanza.attrs.addressing_mode || (sender?.endsWith('lid') ? 'lid' : 'pn');
|
|
55
|
-
if (addressingMode === 'lid') {
|
|
56
|
-
// Message is LID-addressed: sender is LID, extract corresponding PN
|
|
57
|
-
// without device data
|
|
58
|
-
senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn;
|
|
59
|
-
recipientAlt = stanza.attrs.recipient_pn;
|
|
60
|
-
// with device data
|
|
61
|
-
if (sender && senderAlt)
|
|
62
|
-
senderAlt = (0, WABinary_1.transferDevice)(sender, senderAlt);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
// Message is PN-addressed: sender is PN, extract corresponding LID
|
|
66
|
-
// without device data
|
|
67
|
-
senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
|
|
68
|
-
recipientAlt = stanza.attrs.recipient_lid;
|
|
69
|
-
//with device data
|
|
70
|
-
if (sender && senderAlt)
|
|
71
|
-
senderAlt = (0, WABinary_1.transferDevice)(sender, senderAlt);
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
addressingMode,
|
|
75
|
-
senderAlt,
|
|
76
|
-
recipientAlt
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
exports.extractAddressingContext = extractAddressingContext;
|
|
8
|
+
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
80
9
|
/**
|
|
81
10
|
* Decode the received node as a message.
|
|
82
11
|
* @note this will only parse the message, not decrypt it
|
|
83
12
|
*/
|
|
84
13
|
function decodeMessageNode(stanza, meId, meLid) {
|
|
14
|
+
var _a, _b;
|
|
85
15
|
let msgType;
|
|
86
16
|
let chatId;
|
|
87
17
|
let author;
|
|
@@ -89,12 +19,24 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
89
19
|
const from = stanza.attrs.from;
|
|
90
20
|
const participant = stanza.attrs.participant;
|
|
91
21
|
const recipient = stanza.attrs.recipient;
|
|
92
|
-
const addressingContext = (0, exports.extractAddressingContext)(stanza);
|
|
93
22
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
94
23
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
95
|
-
if ((0, WABinary_1.
|
|
96
|
-
if (recipient
|
|
97
|
-
if (!isMe(from)
|
|
24
|
+
if ((0, WABinary_1.isJidUser)(from)) {
|
|
25
|
+
if (recipient) {
|
|
26
|
+
if (!isMe(from)) {
|
|
27
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
28
|
+
}
|
|
29
|
+
chatId = recipient;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
chatId = from;
|
|
33
|
+
}
|
|
34
|
+
msgType = 'chat';
|
|
35
|
+
author = from;
|
|
36
|
+
}
|
|
37
|
+
else if ((0, WABinary_1.isLidUser)(from)) {
|
|
38
|
+
if (recipient) {
|
|
39
|
+
if (!isMeLid(from)) {
|
|
98
40
|
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
99
41
|
}
|
|
100
42
|
chatId = recipient;
|
|
@@ -127,24 +69,21 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
127
69
|
chatId = from;
|
|
128
70
|
author = participant;
|
|
129
71
|
}
|
|
130
|
-
else if ((0, WABinary_1.
|
|
72
|
+
else if ((0, WABinary_1.isJidNewsLetter)(from)) {
|
|
131
73
|
msgType = 'newsletter';
|
|
132
|
-
chatId = from;
|
|
133
74
|
author = from;
|
|
75
|
+
chatId = from;
|
|
134
76
|
}
|
|
135
77
|
else {
|
|
136
78
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
137
79
|
}
|
|
138
|
-
const fromMe = ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(
|
|
139
|
-
const pushname = stanza
|
|
80
|
+
const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
81
|
+
const pushname = stanza.attrs.notify;
|
|
140
82
|
const key = {
|
|
141
83
|
remoteJid: chatId,
|
|
142
|
-
remoteJidAlt: !(0, WABinary_1.isJidGroup)(chatId) ? addressingContext.senderAlt : undefined,
|
|
143
84
|
fromMe,
|
|
144
85
|
id: msgId,
|
|
145
|
-
participant
|
|
146
|
-
participantAlt: (0, WABinary_1.isJidGroup)(chatId) ? addressingContext.senderAlt : undefined,
|
|
147
|
-
...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
|
|
86
|
+
participant
|
|
148
87
|
};
|
|
149
88
|
const fullMessage = {
|
|
150
89
|
key,
|
|
@@ -152,8 +91,11 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
152
91
|
pushName: pushname,
|
|
153
92
|
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
|
154
93
|
};
|
|
94
|
+
if (msgType === 'newsletter') {
|
|
95
|
+
fullMessage.newsletterServerId = +((_b = stanza.attrs) === null || _b === void 0 ? void 0 : _b.server_id);
|
|
96
|
+
}
|
|
155
97
|
if (key.fromMe) {
|
|
156
|
-
fullMessage.status =
|
|
98
|
+
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
|
157
99
|
}
|
|
158
100
|
return {
|
|
159
101
|
fullMessage,
|
|
@@ -161,6 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
161
103
|
sender: msgType === 'chat' ? author : chatId
|
|
162
104
|
};
|
|
163
105
|
}
|
|
106
|
+
exports.decodeMessageNode = decodeMessageNode;
|
|
164
107
|
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
165
108
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
166
109
|
return {
|
|
@@ -168,18 +111,36 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
168
111
|
category: stanza.attrs.category,
|
|
169
112
|
author,
|
|
170
113
|
async decrypt() {
|
|
114
|
+
var _a;
|
|
171
115
|
let decryptables = 0;
|
|
172
|
-
|
|
116
|
+
async function processSenderKeyDistribution(msg) {
|
|
117
|
+
if (msg.senderKeyDistributionMessage) {
|
|
118
|
+
try {
|
|
119
|
+
await repository.processSenderKeyDistributionMessage({
|
|
120
|
+
authorJid: author,
|
|
121
|
+
item: msg.senderKeyDistributionMessage
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
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
|
+
fullMessage.message = msg;
|
|
134
|
+
decryptables += 1;
|
|
135
|
+
}
|
|
136
|
+
else if (Array.isArray(stanza.content)) {
|
|
173
137
|
for (const { tag, attrs, content } of stanza.content) {
|
|
174
138
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
175
|
-
const cert =
|
|
176
|
-
const details =
|
|
139
|
+
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
|
140
|
+
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
177
141
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
178
142
|
}
|
|
179
|
-
if (tag
|
|
180
|
-
fullMessage.key.isViewOnce = true; // TODO: remove from here and add a STUB TYPE
|
|
181
|
-
}
|
|
182
|
-
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
143
|
+
if (tag !== 'enc') {
|
|
183
144
|
continue;
|
|
184
145
|
}
|
|
185
146
|
if (!(content instanceof Uint8Array)) {
|
|
@@ -187,13 +148,8 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
187
148
|
}
|
|
188
149
|
decryptables += 1;
|
|
189
150
|
let msgBuffer;
|
|
190
|
-
const user = (0, WABinary_1.isPnUser)(sender) ? sender : author; // TODO: flaky logic
|
|
191
|
-
const decryptionJid = await getDecryptionJid(user, repository);
|
|
192
|
-
if (tag !== 'plaintext') {
|
|
193
|
-
await storeMappingFromEnvelope(stanza, user, decryptionJid, repository, logger);
|
|
194
|
-
}
|
|
195
151
|
try {
|
|
196
|
-
const e2eType =
|
|
152
|
+
const e2eType = attrs.type;
|
|
197
153
|
switch (e2eType) {
|
|
198
154
|
case 'skmsg':
|
|
199
155
|
msgBuffer = await repository.decryptGroupMessage({
|
|
@@ -204,32 +160,19 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
204
160
|
break;
|
|
205
161
|
case 'pkmsg':
|
|
206
162
|
case 'msg':
|
|
163
|
+
const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
|
|
207
164
|
msgBuffer = await repository.decryptMessage({
|
|
208
|
-
jid:
|
|
165
|
+
jid: user,
|
|
209
166
|
type: e2eType,
|
|
210
167
|
ciphertext: content
|
|
211
168
|
});
|
|
212
169
|
break;
|
|
213
|
-
case 'plaintext':
|
|
214
|
-
msgBuffer = content;
|
|
215
|
-
break;
|
|
216
170
|
default:
|
|
217
171
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
218
172
|
}
|
|
219
|
-
let msg =
|
|
220
|
-
msg = msg.deviceSentMessage
|
|
221
|
-
|
|
222
|
-
//eslint-disable-next-line max-depth
|
|
223
|
-
try {
|
|
224
|
-
await repository.processSenderKeyDistributionMessage({
|
|
225
|
-
authorJid: author,
|
|
226
|
-
item: msg.senderKeyDistributionMessage
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
catch (err) {
|
|
230
|
-
logger.error({ key: fullMessage.key, err }, 'failed to process sender key distribution message');
|
|
231
|
-
}
|
|
232
|
-
}
|
|
173
|
+
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
|
174
|
+
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
175
|
+
await processSenderKeyDistribution(msg);
|
|
233
176
|
if (fullMessage.message) {
|
|
234
177
|
Object.assign(fullMessage.message, msg);
|
|
235
178
|
}
|
|
@@ -238,33 +181,18 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
238
181
|
}
|
|
239
182
|
}
|
|
240
183
|
catch (err) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
|
|
245
|
-
sender,
|
|
246
|
-
author,
|
|
247
|
-
isSessionRecordError: isSessionRecordError(err)
|
|
248
|
-
};
|
|
249
|
-
logger.error(errorContext, 'failed to decrypt message');
|
|
250
|
-
fullMessage.messageStubType = index_js_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
251
|
-
fullMessage.messageStubParameters = [err.message.toString()];
|
|
184
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
185
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
186
|
+
fullMessage.messageStubParameters = [err.message];
|
|
252
187
|
}
|
|
253
188
|
}
|
|
254
189
|
}
|
|
255
190
|
// if nothing was found to decrypt
|
|
256
191
|
if (!decryptables) {
|
|
257
|
-
fullMessage.messageStubType =
|
|
258
|
-
fullMessage.messageStubParameters = [
|
|
192
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
193
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
|
|
259
194
|
}
|
|
260
195
|
}
|
|
261
196
|
};
|
|
262
197
|
};
|
|
263
198
|
exports.decryptMessageNode = decryptMessageNode;
|
|
264
|
-
/**
|
|
265
|
-
* Utility function to check if an error is related to missing session record
|
|
266
|
-
*/
|
|
267
|
-
function isSessionRecordError(error) {
|
|
268
|
-
const errorMessage = error?.message || error?.toString() || '';
|
|
269
|
-
return exports.DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern));
|
|
270
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
3
3
|
/**
|
|
4
4
|
* A map that contains a list of all events that have been triggered
|
|
5
5
|
*
|
|
@@ -10,24 +10,26 @@ import type { ILogger } from './logger';
|
|
|
10
10
|
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
11
|
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
12
|
/** Use to process events in a batch */
|
|
13
|
-
process(handler: (events: BaileysEventData) => void | Promise<void>): () => void;
|
|
13
|
+
process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
|
|
14
14
|
/**
|
|
15
15
|
* starts buffering events, call flush() to release them
|
|
16
16
|
* */
|
|
17
17
|
buffer(): void;
|
|
18
18
|
/** buffers all events till the promise completes */
|
|
19
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T
|
|
19
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
20
20
|
/**
|
|
21
21
|
* flushes all buffered events
|
|
22
|
+
* @param force if true, will flush all data regardless of any pending buffers
|
|
22
23
|
* @returns returns true if the flush actually happened, otherwise false
|
|
23
24
|
*/
|
|
24
|
-
flush(): boolean;
|
|
25
|
+
flush(force?: boolean): boolean;
|
|
25
26
|
/** is there an ongoing buffer */
|
|
26
27
|
isBuffering(): boolean;
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* The event buffer logically consolidates different events into a single event
|
|
30
31
|
* making the data processing more efficient.
|
|
32
|
+
* @param ev the baileys event emitter
|
|
31
33
|
*/
|
|
32
|
-
export declare const makeEventBuffer: (logger:
|
|
34
|
+
export declare const makeEventBuffer: (logger: Logger) => BaileysBufferableEventEmitter;
|
|
33
35
|
export {};
|