@rizzxdc/baileys 8.0.10 → 8.1.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 +4 -2
- package/README.md +107 -245
- package/WAProto/index.d.ts +15795 -0
- package/WAProto/index.js +25587 -4867
- package/lib/Defaults/index.d.ts +147 -0
- package/lib/Defaults/index.js +134 -104
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -11
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +5 -8
- package/lib/Signal/Group/group_cipher.d.ts +11 -0
- package/lib/Signal/Group/group_cipher.js +72 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +11 -13
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +11 -14
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +23 -26
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +61 -64
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +39 -44
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +35 -38
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +76 -79
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -26
- package/lib/Signal/libsignal.d.ts +55 -0
- package/lib/Signal/libsignal.js +414 -308
- package/lib/Signal/lid-mapping.d.ts +21 -0
- package/lib/Signal/lid-mapping.js +270 -149
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -4
- package/lib/Socket/Client/types.d.ts +6 -0
- package/lib/Socket/Client/types.js +8 -11
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +51 -50
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +357 -355
- package/lib/Socket/chats.d.ts +137 -0
- package/lib/Socket/chats.js +1195 -867
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +416 -398
- package/lib/Socket/dugong.js +8 -1
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +336 -301
- package/lib/Socket/index.d.ts +530 -0
- package/lib/Socket/index.js +8 -13
- package/lib/Socket/messages-recv.d.ts +334 -0
- package/lib/Socket/messages-recv.js +1729 -1121
- package/lib/Socket/messages-send.d.ts +330 -0
- package/lib/Socket/messages-send.js +684 -462
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +36 -40
- package/lib/Socket/newsletter.d.ts +284 -0
- package/lib/Socket/newsletter.js +247 -237
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +968 -790
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -6
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +414 -284
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +75 -76
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +21 -23
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.js +0 -2
- package/lib/Types/Bussines.d.ts +2 -0
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.d.ts +2 -0
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +5 -7
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.js +1 -3
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.d.ts +3 -0
- package/lib/Types/Label.js +21 -22
- package/lib/Types/LabelAssociation.d.ts +3 -0
- package/lib/Types/LabelAssociation.js +3 -4
- package/lib/Types/Message.d.ts +12 -0
- package/lib/Types/Message.js +11 -6
- package/lib/Types/Mex.d.ts +3 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +2 -0
- package/lib/Types/Product.js +0 -2
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +2 -0
- package/lib/Types/Signal.js +1 -3
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/Socket.js +1 -4
- package/lib/Types/State.d.ts +6 -0
- package/lib/Types/State.js +52 -8
- package/lib/Types/USync.d.ts +2 -0
- package/lib/Types/USync.js +1 -3
- package/lib/Types/index.d.ts +14 -0
- package/lib/Types/index.js +22 -25
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +285 -203
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +21 -19
- package/lib/Utils/business.d.ts +50 -0
- package/lib/Utils/business.js +206 -209
- package/lib/Utils/chat-utils.d.ts +409 -0
- package/lib/Utils/chat-utils.js +825 -706
- package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +88 -101
- package/lib/Utils/decode-wa-message.d.ts +84 -0
- package/lib/Utils/decode-wa-message.js +287 -238
- package/lib/Utils/event-buffer.d.ts +13 -0
- package/lib/Utils/event-buffer.js +602 -509
- package/lib/Utils/generics.d.ts +64 -0
- package/lib/Utils/generics.js +334 -295
- package/lib/Utils/history.d.ts +76 -0
- package/lib/Utils/history.js +125 -79
- package/lib/Utils/identity-change-handler.d.ts +14 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.js +25 -21
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -70
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +1 -4
- package/lib/Utils/lt-hash.d.ts +7 -0
- package/lib/Utils/lt-hash.js +7 -45
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +27 -31
- package/lib/Utils/message-retry-manager.d.ts +80 -0
- package/lib/Utils/message-retry-manager.js +165 -14
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +768 -572
- package/lib/Utils/messages.d.ts +46 -0
- package/lib/Utils/messages.js +1082 -130
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +191 -135
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.d.ts +26 -0
- package/lib/Utils/pre-key-manager.js +96 -76
- package/lib/Utils/process-message.d.ts +84 -0
- package/lib/Utils/process-message.js +718 -311
- package/lib/Utils/reporting-utils.d.ts +13 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.js +257 -0
- package/lib/Utils/signal.d.ts +83 -0
- package/lib/Utils/signal.js +174 -135
- package/lib/Utils/stanza-ack.d.ts +17 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +3 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +30 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -95
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +182 -180
- package/lib/WABinary/constants.d.ts +62 -0
- package/lib/WABinary/constants.js +1455 -1292
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +249 -228
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +207 -206
- package/lib/WABinary/generic-utils.d.ts +77 -0
- package/lib/WABinary/generic-utils.js +135 -99
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +5 -7
- package/lib/WABinary/jid-utils.d.ts +29 -0
- package/lib/WABinary/jid-utils.js +80 -78
- package/lib/WABinary/types.d.ts +2 -0
- package/lib/WABinary/types.js +1 -3
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +7 -9
- package/lib/WAM/constants.d.ts +34927 -0
- package/lib/WAM/constants.js +22847 -22848
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +129 -134
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +5 -6
- package/lib/WAUSync/USyncQuery.d.ts +21 -0
- package/lib/WAUSync/USyncQuery.js +92 -85
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +28 -22
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -5
- package/lib/index.d.ts +12 -0
- package/lib/index.js +31 -19
- package/package.json +12 -6
- package/lib/Types/Newsletter.js +0 -33
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const CompanionWebClientType: any;
|
|
2
|
+
export function getCompanionWebClientType([os, browserName]: [any, any]): any;
|
|
3
|
+
export function getCompanionPlatformId(browser: any): any;
|
|
4
|
+
export function buildPairingQRData(ref: any, noiseKeyB64: any, identityKeyB64: any, advB64: any, browser: any): string;
|
|
5
|
+
//# sourceMappingURL=companion-reg-client-utils.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export var CompanionWebClientType;
|
|
2
|
+
(function (CompanionWebClientType) {
|
|
3
|
+
CompanionWebClientType[CompanionWebClientType["UNKNOWN"] = 0] = "UNKNOWN";
|
|
4
|
+
CompanionWebClientType[CompanionWebClientType["CHROME"] = 1] = "CHROME";
|
|
5
|
+
CompanionWebClientType[CompanionWebClientType["EDGE"] = 2] = "EDGE";
|
|
6
|
+
CompanionWebClientType[CompanionWebClientType["FIREFOX"] = 3] = "FIREFOX";
|
|
7
|
+
CompanionWebClientType[CompanionWebClientType["IE"] = 4] = "IE";
|
|
8
|
+
CompanionWebClientType[CompanionWebClientType["OPERA"] = 5] = "OPERA";
|
|
9
|
+
CompanionWebClientType[CompanionWebClientType["SAFARI"] = 6] = "SAFARI";
|
|
10
|
+
CompanionWebClientType[CompanionWebClientType["ELECTRON"] = 7] = "ELECTRON";
|
|
11
|
+
CompanionWebClientType[CompanionWebClientType["UWP"] = 8] = "UWP";
|
|
12
|
+
CompanionWebClientType[CompanionWebClientType["OTHER_WEB_CLIENT"] = 9] = "OTHER_WEB_CLIENT";
|
|
13
|
+
})(CompanionWebClientType || (CompanionWebClientType = {}));
|
|
14
|
+
const BROWSER_TO_COMPANION_WEB_CLIENT = {
|
|
15
|
+
Chrome: CompanionWebClientType.CHROME,
|
|
16
|
+
Edge: CompanionWebClientType.EDGE,
|
|
17
|
+
Firefox: CompanionWebClientType.FIREFOX,
|
|
18
|
+
IE: CompanionWebClientType.IE,
|
|
19
|
+
Opera: CompanionWebClientType.OPERA,
|
|
20
|
+
Safari: CompanionWebClientType.SAFARI
|
|
21
|
+
};
|
|
22
|
+
export const getCompanionWebClientType = ([os, browserName]) => {
|
|
23
|
+
if (browserName === 'Desktop') {
|
|
24
|
+
return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
|
|
25
|
+
}
|
|
26
|
+
return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
|
|
27
|
+
};
|
|
28
|
+
export const getCompanionPlatformId = (browser) => {
|
|
29
|
+
return getCompanionWebClientType(browser).toString();
|
|
30
|
+
};
|
|
31
|
+
export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
|
|
32
|
+
return 'https://wa.me/settings/linked_devices#' + [
|
|
33
|
+
ref,
|
|
34
|
+
noiseKeyB64,
|
|
35
|
+
identityKeyB64,
|
|
36
|
+
advB64,
|
|
37
|
+
getCompanionPlatformId(browser)
|
|
38
|
+
].join(',');
|
|
39
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* encrypt AES 256 GCM;
|
|
3
|
+
* where the tag tag is suffixed to the ciphertext
|
|
4
|
+
* */
|
|
5
|
+
export function aesEncryptGCM(plaintext: any, key: any, iv: any, additionalData: any): any;
|
|
6
|
+
/**
|
|
7
|
+
* decrypt AES 256 GCM;
|
|
8
|
+
* where the auth tag is suffixed to the ciphertext
|
|
9
|
+
* */
|
|
10
|
+
export function aesDecryptGCM(ciphertext: any, key: any, iv: any, additionalData: any): any;
|
|
11
|
+
export function aesEncryptCTR(plaintext: any, key: any, iv: any): any;
|
|
12
|
+
export function aesDecryptCTR(ciphertext: any, key: any, iv: any): any;
|
|
13
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
14
|
+
export function aesDecrypt(buffer: any, key: any): any;
|
|
15
|
+
/** decrypt AES 256 CBC */
|
|
16
|
+
export function aesDecryptWithIV(buffer: any, key: any, IV: any): any;
|
|
17
|
+
export function aesEncrypt(buffer: any, key: any): any;
|
|
18
|
+
export function aesEncrypWithIV(buffer: any, key: any, IV: any): any;
|
|
19
|
+
export function hmacSign(buffer: any, key: any, variant?: string): any;
|
|
20
|
+
export function sha256(buffer: any): any;
|
|
21
|
+
export function derivePairingCodeKey(pairingCode: any, salt: any): Promise<any>;
|
|
22
|
+
export function generateSignalPubKey(pubKey: any): any;
|
|
23
|
+
export namespace Curve {
|
|
24
|
+
function generateKeyPair(): {
|
|
25
|
+
private: any;
|
|
26
|
+
public: any;
|
|
27
|
+
};
|
|
28
|
+
function sharedKey(privateKey: any, publicKey: any): any;
|
|
29
|
+
function sign(privateKey: any, buf: any): any;
|
|
30
|
+
function verify(pubKey: any, message: any, signature: any): boolean;
|
|
31
|
+
}
|
|
32
|
+
export function signedKeyPair(identityKeyPair: any, keyId: any): {
|
|
33
|
+
keyPair: {
|
|
34
|
+
private: any;
|
|
35
|
+
public: any;
|
|
36
|
+
};
|
|
37
|
+
signature: any;
|
|
38
|
+
keyId: any;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=crypto.d.ts.map
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,130 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { KEY_BUNDLE_TYPE } from
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from 'crypto';
|
|
2
|
+
import * as curve from 'libsignal/src/curve.js';
|
|
3
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
4
|
+
export { md5, hkdf } from 'whatsapp-rust-bridge';
|
|
5
|
+
// insure browser & node compatibility
|
|
6
6
|
const { subtle } = globalThis.crypto;
|
|
7
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
7
8
|
export const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
|
|
8
9
|
export const Curve = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
generateKeyPair: () => {
|
|
11
|
+
const { pubKey, privKey } = curve.generateKeyPair();
|
|
12
|
+
return {
|
|
13
|
+
private: Buffer.from(privKey),
|
|
14
|
+
// remove version byte
|
|
15
|
+
public: Buffer.from(pubKey.slice(1))
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
sharedKey: (privateKey, publicKey) => {
|
|
19
|
+
const shared = curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
20
|
+
return Buffer.from(shared);
|
|
21
|
+
},
|
|
22
|
+
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
23
|
+
verify: (pubKey, message, signature) => {
|
|
24
|
+
try {
|
|
25
|
+
curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
32
|
};
|
|
31
|
-
//=======================================================//
|
|
32
33
|
export const signedKeyPair = (identityKeyPair, keyId) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const preKey = Curve.generateKeyPair();
|
|
35
|
+
const pubKey = generateSignalPubKey(preKey.public);
|
|
36
|
+
const signature = Curve.sign(identityKeyPair.private, pubKey);
|
|
37
|
+
return { keyPair: preKey, signature, keyId };
|
|
37
38
|
};
|
|
38
|
-
//=======================================================//
|
|
39
39
|
const GCM_TAG_LENGTH = 128 >> 3;
|
|
40
|
+
/**
|
|
41
|
+
* encrypt AES 256 GCM;
|
|
42
|
+
* where the tag tag is suffixed to the ciphertext
|
|
43
|
+
* */
|
|
40
44
|
export function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
46
|
+
cipher.setAAD(additionalData);
|
|
47
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
44
48
|
}
|
|
45
|
-
|
|
49
|
+
/**
|
|
50
|
+
* decrypt AES 256 GCM;
|
|
51
|
+
* where the auth tag is suffixed to the ciphertext
|
|
52
|
+
* */
|
|
46
53
|
export function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
const decipher = createDecipheriv('aes-256-gcm', key, iv);
|
|
55
|
+
// decrypt additional adata
|
|
56
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
|
|
57
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
58
|
+
// set additional data
|
|
59
|
+
decipher.setAAD(additionalData);
|
|
60
|
+
decipher.setAuthTag(tag);
|
|
61
|
+
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
53
62
|
}
|
|
54
|
-
//=======================================================//
|
|
55
63
|
export function aesEncryptCTR(plaintext, key, iv) {
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
const cipher = createCipheriv('aes-256-ctr', key, iv);
|
|
65
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
58
66
|
}
|
|
59
|
-
//=======================================================//
|
|
60
67
|
export function aesDecryptCTR(ciphertext, key, iv) {
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
const decipher = createDecipheriv('aes-256-ctr', key, iv);
|
|
69
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
63
70
|
}
|
|
64
|
-
|
|
71
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
65
72
|
export function aesDecrypt(buffer, key) {
|
|
66
|
-
|
|
73
|
+
return aesDecryptWithIV(buffer.subarray(16), key, buffer.subarray(0, 16));
|
|
67
74
|
}
|
|
68
|
-
|
|
75
|
+
/** decrypt AES 256 CBC */
|
|
69
76
|
export function aesDecryptWithIV(buffer, key, IV) {
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
const aes = createDecipheriv('aes-256-cbc', key, IV);
|
|
78
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
72
79
|
}
|
|
73
|
-
|
|
80
|
+
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
74
81
|
export function aesEncrypt(buffer, key) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
const IV = randomBytes(16);
|
|
83
|
+
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
84
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
78
85
|
}
|
|
79
|
-
|
|
86
|
+
// encrypt AES 256 CBC with a given IV
|
|
80
87
|
export function aesEncrypWithIV(buffer, key, IV) {
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
89
|
+
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
83
90
|
}
|
|
84
|
-
|
|
85
|
-
export function hmacSign(buffer, key, variant =
|
|
86
|
-
|
|
91
|
+
// sign HMAC using SHA 256
|
|
92
|
+
export function hmacSign(buffer, key, variant = 'sha256') {
|
|
93
|
+
return createHmac(variant, key).update(buffer).digest();
|
|
87
94
|
}
|
|
88
|
-
//=======================================================//
|
|
89
95
|
export function sha256(buffer) {
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
//=======================================================//
|
|
93
|
-
export function md5(buffer) {
|
|
94
|
-
return createHash("md5").update(buffer).digest();
|
|
95
|
-
}
|
|
96
|
-
//=======================================================//
|
|
97
|
-
export async function hkdf(buffer, expandedLength, info) {
|
|
98
|
-
const inputKeyMaterial = new Uint8Array(buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer));
|
|
99
|
-
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
100
|
-
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0);
|
|
101
|
-
const importedKey = await subtle.importKey("raw", inputKeyMaterial, { name: "HKDF" }, false, [
|
|
102
|
-
"deriveBits"
|
|
103
|
-
]);
|
|
104
|
-
const derivedBits = await subtle.deriveBits({
|
|
105
|
-
name: "HKDF",
|
|
106
|
-
hash: "SHA-256",
|
|
107
|
-
salt: salt,
|
|
108
|
-
info: infoBytes
|
|
109
|
-
}, importedKey, expandedLength * 8
|
|
110
|
-
);
|
|
111
|
-
return Buffer.from(derivedBits);
|
|
96
|
+
return createHash('sha256').update(buffer).digest();
|
|
112
97
|
}
|
|
113
|
-
//=======================================================//
|
|
114
98
|
export async function derivePairingCodeKey(pairingCode, salt) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
99
|
+
// Convert inputs to formats Web Crypto API can work with
|
|
100
|
+
const encoder = new TextEncoder();
|
|
101
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
102
|
+
const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
|
|
103
|
+
// Import the pairing code as key material
|
|
104
|
+
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
|
|
105
|
+
'deriveBits'
|
|
106
|
+
]);
|
|
107
|
+
// Derive bits using PBKDF2 with the same parameters
|
|
108
|
+
// 2 << 16 = 131,072 iterations
|
|
109
|
+
const derivedBits = await subtle.deriveBits({
|
|
110
|
+
name: 'PBKDF2',
|
|
111
|
+
salt: saltBuffer,
|
|
112
|
+
iterations: 2 << 16,
|
|
113
|
+
hash: 'SHA-256'
|
|
114
|
+
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
115
|
+
);
|
|
116
|
+
return Buffer.from(derivedBits);
|
|
129
117
|
}
|
|
130
|
-
//=======================================================//
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode the received node as a message.
|
|
3
|
+
* @note this will only parse the message, not decrypt it
|
|
4
|
+
*/
|
|
5
|
+
export function decodeMessageNode(stanza: any, meId: any, meLid: any): {
|
|
6
|
+
fullMessage: {
|
|
7
|
+
key: {
|
|
8
|
+
server_id?: any;
|
|
9
|
+
remoteJid: any;
|
|
10
|
+
remoteJidAlt: any;
|
|
11
|
+
remoteJidUsername: any;
|
|
12
|
+
fromMe: boolean;
|
|
13
|
+
id: any;
|
|
14
|
+
participant: any;
|
|
15
|
+
participantAlt: any;
|
|
16
|
+
participantUsername: any;
|
|
17
|
+
addressingMode: any;
|
|
18
|
+
};
|
|
19
|
+
category: any;
|
|
20
|
+
messageTimestamp: number;
|
|
21
|
+
pushName: any;
|
|
22
|
+
broadcast: any;
|
|
23
|
+
};
|
|
24
|
+
author: any;
|
|
25
|
+
sender: any;
|
|
26
|
+
};
|
|
27
|
+
export function getDecryptionJid(sender: any, repository: any): Promise<any>;
|
|
28
|
+
export const NO_MESSAGE_FOUND_ERROR_TEXT: "Message absent from node";
|
|
29
|
+
export const MISSING_KEYS_ERROR_TEXT: "Key used already or never filled";
|
|
30
|
+
export const ACCOUNT_RESTRICTED_TEXT: "Your account has been restricted";
|
|
31
|
+
export namespace DECRYPTION_RETRY_CONFIG {
|
|
32
|
+
let maxRetries: number;
|
|
33
|
+
let baseDelayMs: number;
|
|
34
|
+
let sessionRecordErrors: string[];
|
|
35
|
+
}
|
|
36
|
+
export namespace NACK_REASONS {
|
|
37
|
+
let SenderReachoutTimelocked: number;
|
|
38
|
+
let ParsingError: number;
|
|
39
|
+
let UnrecognizedStanza: number;
|
|
40
|
+
let UnrecognizedStanzaClass: number;
|
|
41
|
+
let UnrecognizedStanzaType: number;
|
|
42
|
+
let InvalidProtobuf: number;
|
|
43
|
+
let InvalidHostedCompanionStanza: number;
|
|
44
|
+
let MissingMessageSecret: number;
|
|
45
|
+
let SignalErrorOldCounter: number;
|
|
46
|
+
let MessageDeletedOnPeer: number;
|
|
47
|
+
let UnhandledError: number;
|
|
48
|
+
let UnsupportedAdminRevoke: number;
|
|
49
|
+
let UnsupportedLIDGroup: number;
|
|
50
|
+
let DBOperationFailed: number;
|
|
51
|
+
}
|
|
52
|
+
export namespace SERVER_ERROR_CODES {
|
|
53
|
+
let MessageAccountRestriction: string;
|
|
54
|
+
let SmaxInvalid: string;
|
|
55
|
+
}
|
|
56
|
+
export function extractAddressingContext(stanza: any): {
|
|
57
|
+
addressingMode: any;
|
|
58
|
+
senderAlt: any;
|
|
59
|
+
recipientAlt: any;
|
|
60
|
+
};
|
|
61
|
+
export function decryptMessageNode(stanza: any, meId: any, meLid: any, repository: any, logger: any): {
|
|
62
|
+
fullMessage: {
|
|
63
|
+
key: {
|
|
64
|
+
server_id?: any;
|
|
65
|
+
remoteJid: any;
|
|
66
|
+
remoteJidAlt: any;
|
|
67
|
+
remoteJidUsername: any;
|
|
68
|
+
fromMe: boolean;
|
|
69
|
+
id: any;
|
|
70
|
+
participant: any;
|
|
71
|
+
participantAlt: any;
|
|
72
|
+
participantUsername: any;
|
|
73
|
+
addressingMode: any;
|
|
74
|
+
};
|
|
75
|
+
category: any;
|
|
76
|
+
messageTimestamp: number;
|
|
77
|
+
pushName: any;
|
|
78
|
+
broadcast: any;
|
|
79
|
+
};
|
|
80
|
+
category: any;
|
|
81
|
+
author: any;
|
|
82
|
+
decrypt(): Promise<void>;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=decode-wa-message.d.ts.map
|