@codexverified/baileys 2.7.5
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 +21 -0
- package/README.md +233 -0
- package/WAProto/V +1 -0
- package/WAProto/WAProto.proto +8051 -0
- package/WAProto/index.js +289292 -0
- package/engine-requirements.js +13 -0
- package/lib/Defaults/index.js +158 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.js +428 -0
- package/lib/Signal/lid-mapping.js +280 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/aigroups.js +315 -0
- package/lib/Socket/business.js +407 -0
- package/lib/Socket/chats.js +1831 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/graphql.js +899 -0
- package/lib/Socket/groups.js +549 -0
- package/lib/Socket/index.js +79 -0
- package/lib/Socket/interactive-handler.js +600 -0
- package/lib/Socket/interop.js +563 -0
- package/lib/Socket/managed-account.js +208 -0
- package/lib/Socket/messages-recv.js +2144 -0
- package/lib/Socket/messages-send.js +2030 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +226 -0
- package/lib/Socket/privacy.js +446 -0
- package/lib/Socket/registration.js +428 -0
- package/lib/Socket/socket.js +1017 -0
- package/lib/Socket/username.js +229 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-cache-manager-store.js +89 -0
- package/lib/Store/make-in-memory-store.js +420 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.js +39 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +48 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.js +301 -0
- package/lib/Utils/bot-planning-replay.js +169 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.js +885 -0
- package/lib/Utils/companion-reg-client-utils.js +32 -0
- package/lib/Utils/consumer-application.js +102 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.js +484 -0
- package/lib/Utils/event-buffer.js +589 -0
- package/lib/Utils/generics.js +388 -0
- package/lib/Utils/group-history.js +56 -0
- package/lib/Utils/history.js +130 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.js +34 -0
- package/lib/Utils/jid-display-normalization.js +209 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-composer.js +467 -0
- package/lib/Utils/message-inspect.js +67 -0
- package/lib/Utils/message-retry-manager.js +241 -0
- package/lib/Utils/messages-media.js +1006 -0
- package/lib/Utils/messages.js +1851 -0
- package/lib/Utils/meta-ai-msmsg.js +130 -0
- package/lib/Utils/meta-compositing.js +194 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.js +527 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.js +439 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.js +120 -0
- package/lib/Utils/use-single-file-auth-state.js +96 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.js +206 -0
- package/lib/Utils/voip-rekey.js +20 -0
- package/lib/Utils/welcome-flow.js +217 -0
- package/lib/WABinary/constants.js +1463 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.js +227 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +96 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.js +201 -0
- package/lib/WAUSync/USyncUser.js +54 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/antiban.cjs +4726 -0
- package/lib/index.d.ts +286 -0
- package/lib/index.js +18 -0
- package/package.json +121 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const CompanionWebClientType = {
|
|
2
|
+
UNKNOWN: 0,
|
|
3
|
+
CHROME: 1,
|
|
4
|
+
EDGE: 2,
|
|
5
|
+
FIREFOX: 3,
|
|
6
|
+
IE: 4,
|
|
7
|
+
OPERA: 5,
|
|
8
|
+
SAFARI: 6,
|
|
9
|
+
ELECTRON: 7,
|
|
10
|
+
UWP: 8,
|
|
11
|
+
OTHER_WEB_CLIENT: 9
|
|
12
|
+
};
|
|
13
|
+
const BROWSER_TO_COMPANION_WEB_CLIENT = {
|
|
14
|
+
Chrome: CompanionWebClientType.CHROME,
|
|
15
|
+
Edge: CompanionWebClientType.EDGE,
|
|
16
|
+
Firefox: CompanionWebClientType.FIREFOX,
|
|
17
|
+
IE: CompanionWebClientType.IE,
|
|
18
|
+
Opera: CompanionWebClientType.OPERA,
|
|
19
|
+
Safari: CompanionWebClientType.SAFARI
|
|
20
|
+
};
|
|
21
|
+
export const getCompanionWebClientType = ([os, browserName]) => {
|
|
22
|
+
if (browserName === 'Desktop') {
|
|
23
|
+
return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
|
|
24
|
+
}
|
|
25
|
+
return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
|
|
26
|
+
};
|
|
27
|
+
export const getCompanionPlatformId = (browser) => {
|
|
28
|
+
return getCompanionWebClientType(browser).toString();
|
|
29
|
+
};
|
|
30
|
+
export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
|
|
31
|
+
return [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',');
|
|
32
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
|
|
3
|
+
export const decodeConsumerApplication = (buffer) => {
|
|
4
|
+
if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
|
|
5
|
+
throw new TypeError('decodeConsumerApplication: buffer must be Buffer or Uint8Array');
|
|
6
|
+
}
|
|
7
|
+
return proto.ConsumerApplication.decode(buffer);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const textOf = mt => (mt && typeof mt.text === 'string' ? mt.text : undefined);
|
|
11
|
+
|
|
12
|
+
const mapContent = (content) => {
|
|
13
|
+
if (!content) return null;
|
|
14
|
+
switch (content.content) {
|
|
15
|
+
case 'messageText':
|
|
16
|
+
return { conversation: textOf(content.messageText) ?? '' };
|
|
17
|
+
case 'extendedTextMessage': {
|
|
18
|
+
const e = content.extendedTextMessage;
|
|
19
|
+
return {
|
|
20
|
+
extendedTextMessage: {
|
|
21
|
+
text: textOf(e.text),
|
|
22
|
+
matchedText: e.matchedText,
|
|
23
|
+
canonicalUrl: e.canonicalUrl,
|
|
24
|
+
description: e.description,
|
|
25
|
+
title: e.title
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
case 'imageMessage':
|
|
30
|
+
return {
|
|
31
|
+
imageMessage: { mediaPayload: content.imageMessage.image, caption: textOf(content.imageMessage.caption) }
|
|
32
|
+
};
|
|
33
|
+
case 'videoMessage':
|
|
34
|
+
return {
|
|
35
|
+
videoMessage: { mediaPayload: content.videoMessage.video, caption: textOf(content.videoMessage.caption) }
|
|
36
|
+
};
|
|
37
|
+
case 'audioMessage':
|
|
38
|
+
return { audioMessage: { mediaPayload: content.audioMessage.audio, ptt: content.audioMessage.ptt } };
|
|
39
|
+
case 'documentMessage':
|
|
40
|
+
return {
|
|
41
|
+
documentMessage: { mediaPayload: content.documentMessage.document, fileName: content.documentMessage.fileName }
|
|
42
|
+
};
|
|
43
|
+
case 'stickerMessage':
|
|
44
|
+
return { stickerMessage: { mediaPayload: content.stickerMessage.sticker } };
|
|
45
|
+
case 'contactMessage':
|
|
46
|
+
return { contactMessage: { mediaPayload: content.contactMessage.contact } };
|
|
47
|
+
case 'contactsArrayMessage':
|
|
48
|
+
return {
|
|
49
|
+
contactsArrayMessage: {
|
|
50
|
+
displayName: content.contactsArrayMessage.displayName,
|
|
51
|
+
contacts: content.contactsArrayMessage.contacts || []
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
case 'locationMessage': {
|
|
55
|
+
const loc = content.locationMessage.location || {};
|
|
56
|
+
return {
|
|
57
|
+
locationMessage: {
|
|
58
|
+
degreesLatitude: loc.degreesLatitude,
|
|
59
|
+
degreesLongitude: loc.degreesLongitude,
|
|
60
|
+
name: loc.name
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
case 'liveLocationMessage': {
|
|
65
|
+
const loc = content.liveLocationMessage.location || {};
|
|
66
|
+
return {
|
|
67
|
+
liveLocationMessage: {
|
|
68
|
+
degreesLatitude: loc.degreesLatitude,
|
|
69
|
+
degreesLongitude: loc.degreesLongitude,
|
|
70
|
+
caption: textOf(content.liveLocationMessage.caption)
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
case 'reactionMessage':
|
|
75
|
+
return { reactionMessage: content.reactionMessage };
|
|
76
|
+
default:
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const consumerApplicationToMessage = (app) => {
|
|
82
|
+
const payload = app?.payload;
|
|
83
|
+
if (!payload) return null;
|
|
84
|
+
switch (payload.payload) {
|
|
85
|
+
case 'content':
|
|
86
|
+
return mapContent(payload.content);
|
|
87
|
+
case 'applicationData': {
|
|
88
|
+
const ad = payload.applicationData;
|
|
89
|
+
if (ad?.applicationContent === 'revoke' && ad.revoke?.key) {
|
|
90
|
+
return {
|
|
91
|
+
protocolMessage: {
|
|
92
|
+
key: ad.revoke.key,
|
|
93
|
+
type: proto.Message.ProtocolMessage.Type.REVOKE
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
const { subtle } = globalThis.crypto;
|
|
7
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
8
|
+
export const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
|
|
9
|
+
export const Curve = {
|
|
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
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export const signedKeyPair = (identityKeyPair, keyId) => {
|
|
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 };
|
|
38
|
+
};
|
|
39
|
+
const GCM_TAG_LENGTH = 128 >> 3;
|
|
40
|
+
/**
|
|
41
|
+
* encrypt AES 256 GCM;
|
|
42
|
+
* where the tag tag is suffixed to the ciphertext
|
|
43
|
+
* */
|
|
44
|
+
export function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
45
|
+
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
46
|
+
cipher.setAAD(additionalData);
|
|
47
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* decrypt AES 256 GCM;
|
|
51
|
+
* where the auth tag is suffixed to the ciphertext
|
|
52
|
+
* */
|
|
53
|
+
export function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
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()]);
|
|
62
|
+
}
|
|
63
|
+
export function aesEncryptCTR(plaintext, key, iv) {
|
|
64
|
+
const cipher = createCipheriv('aes-256-ctr', key, iv);
|
|
65
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
66
|
+
}
|
|
67
|
+
export function aesDecryptCTR(ciphertext, key, iv) {
|
|
68
|
+
const decipher = createDecipheriv('aes-256-ctr', key, iv);
|
|
69
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
70
|
+
}
|
|
71
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
72
|
+
export function aesDecrypt(buffer, key) {
|
|
73
|
+
return aesDecryptWithIV(buffer.subarray(16), key, buffer.subarray(0, 16));
|
|
74
|
+
}
|
|
75
|
+
/** decrypt AES 256 CBC */
|
|
76
|
+
export function aesDecryptWithIV(buffer, key, IV) {
|
|
77
|
+
const aes = createDecipheriv('aes-256-cbc', key, IV);
|
|
78
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
79
|
+
}
|
|
80
|
+
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
81
|
+
export function aesEncrypt(buffer, key) {
|
|
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
|
|
85
|
+
}
|
|
86
|
+
// encrypt AES 256 CBC with a given IV
|
|
87
|
+
export function aesEncrypWithIV(buffer, key, IV) {
|
|
88
|
+
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
89
|
+
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
90
|
+
}
|
|
91
|
+
// sign HMAC using SHA 256
|
|
92
|
+
export function hmacSign(buffer, key, variant = 'sha256') {
|
|
93
|
+
return createHmac(variant, key).update(buffer).digest();
|
|
94
|
+
}
|
|
95
|
+
export function sha256(buffer) {
|
|
96
|
+
return createHash('sha256').update(buffer).digest();
|
|
97
|
+
}
|
|
98
|
+
export async function derivePairingCodeKey(pairingCode, salt) {
|
|
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);
|
|
117
|
+
}
|