@neelegirl/baileys 1.5.5 → 1.5.7
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 +183 -10
- package/WAProto/WAProto.proto +5007 -0
- package/WAProto/index.d.ts +57712 -0
- package/WAProto/index.js +178969 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +68 -0
- package/lib/Defaults/index.js +137 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/WASignalGroup/GroupProtocol.js +1909 -0
- package/lib/Signal/WASignalGroup/ciphertext_message.js +16 -0
- package/lib/Signal/WASignalGroup/generate-proto.sh +1 -0
- package/lib/Signal/WASignalGroup/group.proto +42 -0
- package/lib/Signal/WASignalGroup/group_cipher.js +120 -0
- package/lib/Signal/WASignalGroup/group_session_builder.js +46 -0
- package/lib/Signal/WASignalGroup/index.js +6 -0
- package/lib/Signal/WASignalGroup/keyhelper.js +21 -0
- package/lib/Signal/WASignalGroup/protobufs.js +3 -0
- package/lib/Signal/WASignalGroup/queue_job.js +69 -0
- package/lib/Signal/WASignalGroup/readme.md +6 -0
- package/lib/Signal/WASignalGroup/sender_chain_key.js +50 -0
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/lib/Signal/WASignalGroup/sender_key_message.js +92 -0
- package/lib/Signal/WASignalGroup/sender_key_name.js +70 -0
- package/lib/Signal/WASignalGroup/sender_key_record.js +56 -0
- package/lib/Signal/WASignalGroup/sender_key_state.js +129 -0
- package/lib/Signal/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Signal/libsignal.d.ts +4 -0
- package/lib/Signal/libsignal.js +162 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +22 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +18 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/business.d.ts +187 -0
- package/lib/Socket/business.js +268 -0
- package/lib/Socket/chats.d.ts +98 -0
- package/lib/Socket/chats.js +1113 -0
- package/lib/Socket/communities.d.ts +223 -0
- package/lib/Socket/communities.js +433 -0
- package/lib/Socket/groups.d.ts +131 -0
- package/lib/Socket/groups.js +352 -0
- package/lib/Socket/index.d.ts +191 -0
- package/lib/Socket/index.js +23 -0
- package/lib/Socket/messages-recv.d.ts +177 -0
- package/lib/Socket/messages-recv.js +1764 -0
- package/lib/Socket/messages-send.d.ts +168 -0
- package/lib/Socket/messages-send.js +1303 -0
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +47 -0
- package/lib/Socket/newsletter.d.ts +147 -0
- package/lib/Socket/newsletter.js +286 -0
- package/lib/Socket/registration.d.ts +266 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +45 -0
- package/lib/Socket/socket.js +766 -0
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +83 -0
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +24 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.d.ts +123 -0
- package/lib/Store/make-in-memory-store.js +429 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +86 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +31 -0
- package/lib/Types/Auth.d.ts +120 -0
- package/lib/Types/Auth.js +3 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Call.js +3 -0
- package/lib/Types/Chat.d.ts +138 -0
- package/lib/Types/Chat.js +9 -0
- package/lib/Types/Contact.d.ts +20 -0
- package/lib/Types/Contact.js +3 -0
- package/lib/Types/Events.d.ts +229 -0
- package/lib/Types/Events.js +3 -0
- package/lib/Types/GroupMetadata.d.ts +66 -0
- package/lib/Types/GroupMetadata.js +3 -0
- package/lib/Types/Label.d.ts +48 -0
- package/lib/Types/Label.js +31 -0
- package/lib/Types/LabelAssociation.d.ts +35 -0
- package/lib/Types/LabelAssociation.js +13 -0
- package/lib/Types/Message.d.ts +473 -0
- package/lib/Types/Message.js +13 -0
- package/lib/Types/MexUpdates.d.ts +9 -0
- package/lib/Types/MexUpdates.js +18 -0
- package/lib/Types/Newsletter.d.ts +109 -0
- package/lib/Types/Newsletter.js +40 -0
- package/lib/Types/Product.d.ts +92 -0
- package/lib/Types/Product.js +3 -0
- package/lib/Types/Signal.d.ts +68 -0
- package/lib/Types/Signal.js +3 -0
- package/lib/Types/Socket.d.ts +122 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.d.ts +41 -0
- package/lib/Types/State.js +14 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +3 -0
- package/lib/Types/index.d.ts +79 -0
- package/lib/Types/index.js +48 -0
- package/lib/Utils/auth-utils.d.ts +21 -0
- package/lib/Utils/auth-utils.js +205 -0
- package/lib/Utils/baileys-event-stream.d.ts +18 -0
- package/lib/Utils/baileys-event-stream.js +70 -0
- package/lib/Utils/business.d.ts +29 -0
- package/lib/Utils/business.js +255 -0
- package/lib/Utils/chat-utils.d.ts +82 -0
- package/lib/Utils/chat-utils.js +781 -0
- package/lib/Utils/check-npm-version.d.ts +15 -0
- package/lib/Utils/check-npm-version.js +52 -0
- package/lib/Utils/crypto.d.ts +56 -0
- package/lib/Utils/crypto.js +179 -0
- package/lib/Utils/decode-wa-message.d.ts +41 -0
- package/lib/Utils/decode-wa-message.js +253 -0
- package/lib/Utils/event-buffer.d.ts +39 -0
- package/lib/Utils/event-buffer.js +565 -0
- package/lib/Utils/generics.d.ts +129 -0
- package/lib/Utils/generics.js +618 -0
- package/lib/Utils/history.d.ts +23 -0
- package/lib/Utils/history.js +110 -0
- package/lib/Utils/index.d.ts +19 -0
- package/lib/Utils/index.js +41 -0
- package/lib/Utils/link-preview.d.ts +23 -0
- package/lib/Utils/link-preview.js +120 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +14 -0
- package/lib/Utils/lt-hash.js +58 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +49 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/message-retry-manager.js +177 -0
- package/lib/Utils/messages-media.d.ts +129 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.d.ts +103 -0
- package/lib/Utils/messages.js +1579 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/process-message.d.ts +49 -0
- package/lib/Utils/process-message.js +428 -0
- package/lib/Utils/signal.d.ts +42 -0
- package/lib/Utils/signal.js +166 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +84 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
- package/lib/Utils/use-multi-file-auth-state.js +238 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +80 -0
- package/lib/Utils/validate-connection.d.ts +13 -0
- package/lib/Utils/validate-connection.js +187 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/constants.js +1316 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +288 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +265 -0
- package/lib/WABinary/generic-utils.d.ts +28 -0
- package/lib/WABinary/generic-utils.js +142 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +25 -0
- package/lib/WABinary/jid-utils.d.ts +53 -0
- package/lib/WABinary/jid-utils.js +92 -0
- package/lib/WABinary/types.d.ts +22 -0
- package/lib/WABinary/types.js +3 -0
- package/lib/WAM/BinaryInfo.d.ts +16 -0
- package/lib/WAM/BinaryInfo.js +17 -0
- package/lib/WAM/constants.d.ts +47 -0
- package/lib/WAM/constants.js +15371 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +165 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +23 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +36 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +35 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +46 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +26 -0
- package/lib/WAUSync/USyncQuery.d.ts +31 -0
- package/lib/WAUSync/USyncQuery.js +92 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +23 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +33 -0
- package/package.json +88 -10
- package/index.js +0 -38
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface VersionInfo {
|
|
2
|
+
current: string;
|
|
3
|
+
latest: string;
|
|
4
|
+
hasUpdate: boolean;
|
|
5
|
+
changelog?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Check if a new version is available on NPM
|
|
9
|
+
* @param packageName - The package name to check (e.g., '@neelegirl/baileys')
|
|
10
|
+
* @param currentVersion - The current version installed
|
|
11
|
+
* @returns Promise with version info or null if check fails
|
|
12
|
+
*/
|
|
13
|
+
export declare const checkNpmVersion: (packageName: string, currentVersion: string) => Promise<VersionInfo | null>;
|
|
14
|
+
//# sourceMappingURL=check-npm-version.d.ts.map
|
|
15
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkNpmVersion = void 0;
|
|
4
|
+
const https_1 = require("https");
|
|
5
|
+
/**
|
|
6
|
+
* Check if a new version is available on NPM
|
|
7
|
+
* @param packageName - The package name to check (e.g., '@neelegirl/baileys')
|
|
8
|
+
* @param currentVersion - The current version installed
|
|
9
|
+
* @returns Promise with version info or null if check fails
|
|
10
|
+
*/
|
|
11
|
+
const checkNpmVersion = (packageName, currentVersion) => {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
const url = `https://registry.npmjs.org/${packageName}/latest`;
|
|
14
|
+
https_1.default.get(url, { timeout: 5000 }, (res) => {
|
|
15
|
+
let data = '';
|
|
16
|
+
res.on('data', (chunk) => {
|
|
17
|
+
data += chunk;
|
|
18
|
+
});
|
|
19
|
+
res.on('end', () => {
|
|
20
|
+
try {
|
|
21
|
+
const packageInfo = JSON.parse(data);
|
|
22
|
+
const latestVersion = packageInfo.version;
|
|
23
|
+
if (latestVersion && latestVersion !== currentVersion) {
|
|
24
|
+
resolve({
|
|
25
|
+
current: currentVersion,
|
|
26
|
+
latest: latestVersion,
|
|
27
|
+
hasUpdate: true,
|
|
28
|
+
changelog: packageInfo.description || 'Neue Version verfügbar!'
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
resolve({
|
|
33
|
+
current: currentVersion,
|
|
34
|
+
latest: latestVersion,
|
|
35
|
+
hasUpdate: false
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
resolve(null);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}).on('error', () => {
|
|
44
|
+
resolve(null);
|
|
45
|
+
}).on('timeout', () => {
|
|
46
|
+
resolve(null);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
exports.checkNpmVersion = checkNpmVersion;
|
|
51
|
+
//# sourceMappingURL=check-npm-version.js.map
|
|
52
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { KeyPair } from '../Types'
|
|
2
|
+
|
|
3
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
4
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer
|
|
5
|
+
|
|
6
|
+
export declare const Curve: {
|
|
7
|
+
generateKeyPair: () => KeyPair
|
|
8
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer
|
|
9
|
+
sign: (privateKey: Uint8Array, buf: Uint8Array) => any
|
|
10
|
+
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
|
|
14
|
+
keyPair: KeyPair
|
|
15
|
+
signature: any
|
|
16
|
+
keyId: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* encrypt AES 256 GCM
|
|
21
|
+
* where the tag tag is suffixed to the ciphertext
|
|
22
|
+
* */
|
|
23
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* decrypt AES 256 GCM
|
|
27
|
+
* where the auth tag is suffixed to the ciphertext
|
|
28
|
+
* */
|
|
29
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer
|
|
30
|
+
|
|
31
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer
|
|
32
|
+
|
|
33
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer
|
|
34
|
+
|
|
35
|
+
/** decrypt AES 256 CBC where the IV is prefixed to the buffer */
|
|
36
|
+
export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer
|
|
37
|
+
/** decrypt AES 256 CBC */
|
|
38
|
+
|
|
39
|
+
export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer
|
|
40
|
+
|
|
41
|
+
export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer
|
|
42
|
+
|
|
43
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer
|
|
44
|
+
|
|
45
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer
|
|
46
|
+
|
|
47
|
+
export declare function sha256(buffer: Buffer): Buffer
|
|
48
|
+
|
|
49
|
+
export declare function md5(buffer: Buffer): Buffer
|
|
50
|
+
|
|
51
|
+
export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
|
|
52
|
+
salt?: Buffer
|
|
53
|
+
info?: string
|
|
54
|
+
}): Promise<Buffer>
|
|
55
|
+
|
|
56
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc)
|
|
10
|
+
} : function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k
|
|
12
|
+
o[k2] = m[k]
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
+
} : function(o, v) {
|
|
18
|
+
o["default"] = v
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
var __importStar = (this && this.__importStar) || function(mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod
|
|
23
|
+
var result = {}
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
+
__setModuleDefault(result, mod)
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
|
+
|
|
31
|
+
const crypto_1 = require("crypto")
|
|
32
|
+
const libsignal = __importStar(require("@neelegirl/libsignal"))
|
|
33
|
+
const Defaults_1 = require("../Defaults")
|
|
34
|
+
|
|
35
|
+
const generateSignalPubKey = (pubKey) => (
|
|
36
|
+
pubKey.length === 33 ? pubKey : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey])
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
const Curve = {
|
|
40
|
+
generateKeyPair: () => {
|
|
41
|
+
const { pubKey, privKey } = libsignal.curve.generateKeyPair()
|
|
42
|
+
return {
|
|
43
|
+
private: Buffer.from(privKey),
|
|
44
|
+
public: Buffer.from(pubKey.slice(1))
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
sharedKey: (privateKey, publicKey) => {
|
|
48
|
+
const shared = libsignal.curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey)
|
|
49
|
+
return Buffer.from(shared)
|
|
50
|
+
},
|
|
51
|
+
sign: (privateKey, buf) => libsignal.curve.calculateSignature(privateKey, buf),
|
|
52
|
+
verify: (pubKey, message, signature) => {
|
|
53
|
+
try {
|
|
54
|
+
libsignal.curve.verifySignature(generateSignalPubKey(pubKey), message, signature)
|
|
55
|
+
return true
|
|
56
|
+
} catch {
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const signedKeyPair = (identityKeyPair, keyId) => {
|
|
63
|
+
const preKey = Curve.generateKeyPair()
|
|
64
|
+
const pubKey = generateSignalPubKey(preKey.public)
|
|
65
|
+
const signature = Curve.sign(identityKeyPair.private, pubKey)
|
|
66
|
+
return { keyPair: preKey, signature, keyId }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const GCM_TAG_LENGTH = 128 >> 3
|
|
70
|
+
|
|
71
|
+
function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
72
|
+
const cipher = crypto_1.createCipheriv('aes-256-gcm', key, iv)
|
|
73
|
+
cipher.setAAD(additionalData)
|
|
74
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()])
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
78
|
+
const decipher = crypto_1.createDecipheriv('aes-256-gcm', key, iv)
|
|
79
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH)
|
|
80
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH)
|
|
81
|
+
decipher.setAAD(additionalData)
|
|
82
|
+
decipher.setAuthTag(tag)
|
|
83
|
+
return Buffer.concat([decipher.update(enc), decipher.final()])
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function aesEncryptCTR(plaintext, key, iv) {
|
|
87
|
+
const cipher = crypto_1.createCipheriv('aes-256-ctr', key, iv)
|
|
88
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()])
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function aesDecryptCTR(ciphertext, key, iv) {
|
|
92
|
+
const decipher = crypto_1.createDecipheriv('aes-256-ctr', key, iv)
|
|
93
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()])
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function aesDecrypt(buffer, key) {
|
|
97
|
+
return aesDecryptWithIV(buffer.slice(16), key, buffer.slice(0, 16))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function aesDecryptWithIV(buffer, key, IV) {
|
|
101
|
+
const aes = crypto_1.createDecipheriv('aes-256-cbc', key, IV)
|
|
102
|
+
return Buffer.concat([aes.update(buffer), aes.final()])
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function aesEncrypt(buffer, key) {
|
|
106
|
+
const IV = crypto_1.randomBytes(16)
|
|
107
|
+
const aes = crypto_1.createCipheriv('aes-256-cbc', key, IV)
|
|
108
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()])
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function aesEncrypWithIV(buffer, key, IV) {
|
|
112
|
+
const aes = crypto_1.createCipheriv('aes-256-cbc', key, IV)
|
|
113
|
+
return Buffer.concat([aes.update(buffer), aes.final()])
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function hmacSign(buffer, key, variant = 'sha256') {
|
|
117
|
+
return crypto_1.createHmac(variant, key).update(buffer).digest()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function sha256(buffer) {
|
|
121
|
+
return crypto_1.createHash('sha256').update(buffer).digest()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function md5(buffer) {
|
|
125
|
+
return crypto_1.createHash('md5').update(buffer).digest()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function hkdf(buffer, expandedLength, info) {
|
|
129
|
+
const inputKeyMaterial = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer)
|
|
130
|
+
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0)
|
|
131
|
+
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0)
|
|
132
|
+
|
|
133
|
+
const importedKey = await crypto.subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits'])
|
|
134
|
+
|
|
135
|
+
const derivedBits = await crypto.subtle.deriveBits({
|
|
136
|
+
name: 'HKDF',
|
|
137
|
+
hash: 'SHA-256',
|
|
138
|
+
salt,
|
|
139
|
+
info: infoBytes
|
|
140
|
+
}, importedKey, expandedLength * 8)
|
|
141
|
+
|
|
142
|
+
return Buffer.from(derivedBits)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
146
|
+
const encoder = new TextEncoder()
|
|
147
|
+
const pairingCodeBuffer = encoder.encode(pairingCode)
|
|
148
|
+
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt)
|
|
149
|
+
|
|
150
|
+
const keyMaterial = await crypto.subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits'])
|
|
151
|
+
|
|
152
|
+
const derivedBits = await crypto.subtle.deriveBits({
|
|
153
|
+
name: 'PBKDF2',
|
|
154
|
+
salt: saltBuffer,
|
|
155
|
+
iterations: 2 << 16,
|
|
156
|
+
hash: 'SHA-256'
|
|
157
|
+
}, keyMaterial, 32 * 8)
|
|
158
|
+
|
|
159
|
+
return Buffer.from(derivedBits)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = {
|
|
163
|
+
generateSignalPubKey,
|
|
164
|
+
Curve,
|
|
165
|
+
signedKeyPair,
|
|
166
|
+
aesEncryptGCM,
|
|
167
|
+
aesDecryptGCM,
|
|
168
|
+
aesEncryptCTR,
|
|
169
|
+
aesDecryptCTR,
|
|
170
|
+
aesDecrypt,
|
|
171
|
+
aesDecryptWithIV,
|
|
172
|
+
aesEncrypt,
|
|
173
|
+
aesEncrypWithIV,
|
|
174
|
+
hmacSign,
|
|
175
|
+
sha256,
|
|
176
|
+
md5,
|
|
177
|
+
hkdf,
|
|
178
|
+
derivePairingCodeKey
|
|
179
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { proto } from '../../WAProto'
|
|
2
|
+
import { SignalRepository } from '../Types'
|
|
3
|
+
import { BinaryNode } from '../WABinary'
|
|
4
|
+
import { ILogger } from './logger'
|
|
5
|
+
|
|
6
|
+
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node"
|
|
7
|
+
|
|
8
|
+
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled"
|
|
9
|
+
|
|
10
|
+
export declare const NACK_REASONS: {
|
|
11
|
+
ParsingError: number
|
|
12
|
+
UnrecognizedStanza: number
|
|
13
|
+
UnrecognizedStanzaClass: number
|
|
14
|
+
UnrecognizedStanzaType: number
|
|
15
|
+
InvalidProtobuf: number
|
|
16
|
+
InvalidHostedCompanionStanza: number
|
|
17
|
+
MissingMessageSecret: number
|
|
18
|
+
SignalErrorOldCounter: number
|
|
19
|
+
MessageDeletedOnPeer: number
|
|
20
|
+
UnhandledError: number
|
|
21
|
+
UnsupportedAdminRevoke: number
|
|
22
|
+
UnsupportedLIDGroup: number
|
|
23
|
+
DBOperationFailed: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Decode the received node as a message.
|
|
28
|
+
* @note this will only parse the message, not decrypt it
|
|
29
|
+
*/
|
|
30
|
+
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
31
|
+
fullMessage: proto.IWebMessageInfo
|
|
32
|
+
author: string
|
|
33
|
+
sender: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
|
|
37
|
+
fullMessage: proto.IWebMessageInfo
|
|
38
|
+
category: string
|
|
39
|
+
author: string
|
|
40
|
+
decrypt(): Promise<void>
|
|
41
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const boom_1 = require("@hapi/boom")
|
|
6
|
+
const WAProto_1 = require("../../WAProto")
|
|
7
|
+
const WABinary_1 = require("../WABinary")
|
|
8
|
+
const generics_1 = require("./generics")
|
|
9
|
+
const messages_1 = require("./messages")
|
|
10
|
+
|
|
11
|
+
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
|
|
12
|
+
|
|
13
|
+
const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
|
|
14
|
+
|
|
15
|
+
const NACK_REASONS = {
|
|
16
|
+
ParsingError: 487,
|
|
17
|
+
UnrecognizedStanza: 488,
|
|
18
|
+
UnrecognizedStanzaClass: 489,
|
|
19
|
+
UnrecognizedStanzaType: 490,
|
|
20
|
+
InvalidProtobuf: 491,
|
|
21
|
+
InvalidHostedCompanionStanza: 493,
|
|
22
|
+
MissingMessageSecret: 495,
|
|
23
|
+
SignalErrorOldCounter: 496,
|
|
24
|
+
MessageDeletedOnPeer: 499,
|
|
25
|
+
UnhandledError: 500,
|
|
26
|
+
UnsupportedAdminRevoke: 550,
|
|
27
|
+
UnsupportedLIDGroup: 551,
|
|
28
|
+
DBOperationFailed: 552
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Decode the received node as a message.
|
|
33
|
+
* @note this will only parse the message, not decrypt it
|
|
34
|
+
*/
|
|
35
|
+
function decodeMessageNode(stanza, meId, meLid) {
|
|
36
|
+
let msgType
|
|
37
|
+
let chatId
|
|
38
|
+
let author
|
|
39
|
+
const msgId = stanza.attrs.id
|
|
40
|
+
const from = stanza.attrs.from
|
|
41
|
+
let participant = stanza.attrs.participant
|
|
42
|
+
if (participant && participant.endsWith('@lid') && stanza.attrs.participant_pn) {
|
|
43
|
+
participant = stanza.attrs.participant_pn;
|
|
44
|
+
}
|
|
45
|
+
const recipient = stanza.attrs.recipient
|
|
46
|
+
const isMe = (jid) => WABinary_1.areJidsSameUser(jid, meId)
|
|
47
|
+
const isMeLid = (jid) => WABinary_1.areJidsSameUser(jid, meLid)
|
|
48
|
+
if (WABinary_1.isJidUser(from)) {
|
|
49
|
+
if (recipient) {
|
|
50
|
+
if (!isMe(from)) {
|
|
51
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
|
|
52
|
+
}
|
|
53
|
+
chatId = recipient
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
chatId = from
|
|
57
|
+
}
|
|
58
|
+
msgType = 'chat'
|
|
59
|
+
author = from
|
|
60
|
+
}
|
|
61
|
+
else if (WABinary_1.isLidUser(from)) {
|
|
62
|
+
if (recipient) {
|
|
63
|
+
if (!isMeLid(from)) {
|
|
64
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
|
|
65
|
+
}
|
|
66
|
+
chatId = recipient
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
chatId = from
|
|
70
|
+
}
|
|
71
|
+
msgType = 'chat'
|
|
72
|
+
author = from
|
|
73
|
+
}
|
|
74
|
+
else if (WABinary_1.isJidGroup(from)) {
|
|
75
|
+
if (!participant) {
|
|
76
|
+
throw new boom_1.Boom('No participant in group message')
|
|
77
|
+
}
|
|
78
|
+
msgType = 'group'
|
|
79
|
+
author = participant
|
|
80
|
+
chatId = from
|
|
81
|
+
}
|
|
82
|
+
else if (WABinary_1.isJidBroadcast(from)) {
|
|
83
|
+
if (!participant) {
|
|
84
|
+
throw new boom_1.Boom('No participant in group message')
|
|
85
|
+
}
|
|
86
|
+
const isParticipantMe = isMe(participant)
|
|
87
|
+
if (WABinary_1.isJidStatusBroadcast(from)) {
|
|
88
|
+
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status'
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast'
|
|
92
|
+
}
|
|
93
|
+
chatId = from
|
|
94
|
+
author = participant
|
|
95
|
+
}
|
|
96
|
+
else if (WABinary_1.isJidNewsletter(from)) {
|
|
97
|
+
msgType = 'newsletter'
|
|
98
|
+
chatId = from
|
|
99
|
+
author = from
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new boom_1.Boom('Unknown message type', { data: stanza })
|
|
103
|
+
}
|
|
104
|
+
const senderJid = stanza.attrs.participant || stanza.attrs.from;
|
|
105
|
+
|
|
106
|
+
const fromMe = WABinary_1.isJidNewsletter(stanza.attrs.from)
|
|
107
|
+
? !!stanza.attrs?.is_sender
|
|
108
|
+
: WABinary_1.isLidUser(senderJid)
|
|
109
|
+
? (0, WABinary_1.areJidsSameUser)(senderJid, meLid)
|
|
110
|
+
: (0, WABinary_1.areJidsSameUser)(senderJid, meId);
|
|
111
|
+
|
|
112
|
+
const pushname = stanza?.attrs?.notify
|
|
113
|
+
const key = {
|
|
114
|
+
remoteJid: chatId,
|
|
115
|
+
fromMe,
|
|
116
|
+
id: msgId,
|
|
117
|
+
...(participant !== undefined && { participant: fromMe ? meId : participant }),
|
|
118
|
+
...(stanza.attrs.participant_pn !== undefined && { participant_pn: fromMe ? meId : stanza.attrs.participant_pn }),
|
|
119
|
+
...(stanza.attrs.participant_lid !== undefined && { participant_lid: fromMe ? meLid : stanza.attrs.participant_lid }),
|
|
120
|
+
}
|
|
121
|
+
const fullMessage = {
|
|
122
|
+
key,
|
|
123
|
+
messageTimestamp: +stanza.attrs.t,
|
|
124
|
+
pushName: pushname,
|
|
125
|
+
broadcast: WABinary_1.isJidBroadcast(from),
|
|
126
|
+
newsletter: WABinary_1.isJidNewsletter(from),
|
|
127
|
+
additionalAttributes: stanza.attrs
|
|
128
|
+
}
|
|
129
|
+
if (msgType === 'newsletter') {
|
|
130
|
+
fullMessage.newsletter_server_id = +stanza.attrs?.server_id
|
|
131
|
+
}
|
|
132
|
+
if (key.fromMe) {
|
|
133
|
+
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK
|
|
134
|
+
}
|
|
135
|
+
if (!key.fromMe) {
|
|
136
|
+
fullMessage.platform = messages_1.getDevice(key.id)
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
fullMessage,
|
|
140
|
+
author,
|
|
141
|
+
sender: msgType === 'chat' ? author : chatId
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
146
|
+
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
|
|
147
|
+
return {
|
|
148
|
+
fullMessage,
|
|
149
|
+
category: stanza.attrs.category,
|
|
150
|
+
author,
|
|
151
|
+
async decrypt() {
|
|
152
|
+
let decryptables = 0
|
|
153
|
+
if (Array.isArray(stanza.content)) {
|
|
154
|
+
for (const { tag, attrs, content } of stanza.content) {
|
|
155
|
+
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
156
|
+
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content)
|
|
157
|
+
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details)
|
|
158
|
+
fullMessage.verifiedBizName = details.verifiedName
|
|
159
|
+
}
|
|
160
|
+
if (tag === 'multicast' && content instanceof Uint8Array) {
|
|
161
|
+
fullMessage.multicast = true
|
|
162
|
+
}
|
|
163
|
+
if (tag === 'meta' && content instanceof Uint8Array) {
|
|
164
|
+
fullMessage.metaInfo = {
|
|
165
|
+
targetID: attrs.target_id
|
|
166
|
+
}
|
|
167
|
+
if (attrs.target_sender_jid) {
|
|
168
|
+
fullMessage.metaInfo.targetSender = WABinary_1.jidNormalizedUser(attrs.target_sender_jid)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (tag === 'bot' && content instanceof Uint8Array) {
|
|
172
|
+
if (attrs.edit) {
|
|
173
|
+
fullMessage.botInfo = {
|
|
174
|
+
editType: attrs.edit,
|
|
175
|
+
editTargetID: attrs.edit_target_id,
|
|
176
|
+
editSenderTimestampMS: attrs.sender_timestamp_ms
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
181
|
+
continue
|
|
182
|
+
}
|
|
183
|
+
if (!(content instanceof Uint8Array)) {
|
|
184
|
+
continue
|
|
185
|
+
}
|
|
186
|
+
decryptables += 1
|
|
187
|
+
let msgBuffer
|
|
188
|
+
try {
|
|
189
|
+
const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type
|
|
190
|
+
switch (e2eType) {
|
|
191
|
+
case 'skmsg':
|
|
192
|
+
msgBuffer = await repository.decryptGroupMessage({
|
|
193
|
+
group: sender,
|
|
194
|
+
authorJid: author,
|
|
195
|
+
msg: content
|
|
196
|
+
})
|
|
197
|
+
break
|
|
198
|
+
case 'pkmsg':
|
|
199
|
+
case 'msg':
|
|
200
|
+
const user = WABinary_1.isJidUser(sender) ? sender : author
|
|
201
|
+
msgBuffer = await repository.decryptMessage({
|
|
202
|
+
jid: user,
|
|
203
|
+
type: e2eType,
|
|
204
|
+
ciphertext: content
|
|
205
|
+
})
|
|
206
|
+
break
|
|
207
|
+
case 'plaintext':
|
|
208
|
+
msgBuffer = content
|
|
209
|
+
break
|
|
210
|
+
default:
|
|
211
|
+
throw new Error(`Unknown e2e type: ${e2eType}`)
|
|
212
|
+
}
|
|
213
|
+
let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? generics_1.unpadRandomMax16(msgBuffer) : msgBuffer)
|
|
214
|
+
msg = msg.deviceSentMessage?.message || msg
|
|
215
|
+
if (msg.senderKeyDistributionMessage) {
|
|
216
|
+
//eslint-disable-next-line max-depth
|
|
217
|
+
try {
|
|
218
|
+
await repository.processSenderKeyDistributionMessage({
|
|
219
|
+
authorJid: author,
|
|
220
|
+
item: msg.senderKeyDistributionMessage
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (fullMessage.message) {
|
|
228
|
+
Object.assign(fullMessage.message, msg)
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
fullMessage.message = msg
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
|
|
236
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
|
|
237
|
+
fullMessage.messageStubParameters = [err.message]
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// if nothing was found to decrypt
|
|
242
|
+
if (!decryptables) {
|
|
243
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
|
|
244
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT]
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
module.exports = {
|
|
251
|
+
decodeMessageNode,
|
|
252
|
+
decryptMessageNode
|
|
253
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaileysEventEmitter, BaileysEventMap } from '../Types'
|
|
2
|
+
import { ILogger } from './logger'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A map that contains a list of all events that have been triggered
|
|
6
|
+
*
|
|
7
|
+
* Note, this can contain different type of events
|
|
8
|
+
* this can make processing events extremely efficient -- since everything
|
|
9
|
+
* can be done in a single transaction
|
|
10
|
+
*/
|
|
11
|
+
type BaileysEventData = Partial<BaileysEventMap>
|
|
12
|
+
|
|
13
|
+
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
14
|
+
/** Use to process events in a batch */
|
|
15
|
+
process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void)
|
|
16
|
+
/**
|
|
17
|
+
* starts buffering events, call flush() to release them
|
|
18
|
+
* */
|
|
19
|
+
buffer(): void
|
|
20
|
+
/** buffers all events till the promise completes */
|
|
21
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>)
|
|
22
|
+
/**
|
|
23
|
+
* flushes all buffered events
|
|
24
|
+
* @param force if true, will flush all data regardless of any pending buffers
|
|
25
|
+
* @returns returns true if the flush actually happened, otherwise false
|
|
26
|
+
*/
|
|
27
|
+
flush(force?: boolean): boolean
|
|
28
|
+
/** is there an ongoing buffer */
|
|
29
|
+
isBuffering(): boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The event buffer logically consolidates different events into a single event
|
|
34
|
+
* making the data processing more efficient.
|
|
35
|
+
* @param ev the baileys event emitter
|
|
36
|
+
*/
|
|
37
|
+
export declare const makeEventBuffer: (logger: ILogger) => BaileysBufferableEventEmitter
|
|
38
|
+
|
|
39
|
+
export {}
|