@nexustechpro/baileys 2.0.2 → 2.0.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 +1 -1
- package/README.md +924 -1299
- package/lib/Defaults/baileys-version.json +6 -2
- package/lib/Defaults/index.js +172 -172
- package/lib/Signal/libsignal.js +380 -292
- package/lib/Signal/lid-mapping.js +264 -171
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.js +10 -10
- package/lib/Socket/Client/websocket.js +45 -310
- package/lib/Socket/business.js +375 -375
- package/lib/Socket/chats.js +909 -963
- package/lib/Socket/communities.js +430 -430
- package/lib/Socket/groups.js +342 -342
- package/lib/Socket/index.js +22 -22
- package/lib/Socket/messages-recv.js +777 -743
- package/lib/Socket/messages-send.js +295 -305
- package/lib/Socket/mex.js +50 -50
- package/lib/Socket/newsletter.js +148 -148
- package/lib/Socket/nexus-handler.js +75 -261
- package/lib/Socket/socket.js +709 -1201
- package/lib/Store/index.js +5 -5
- package/lib/Store/make-cache-manager-store.js +81 -81
- package/lib/Store/make-in-memory-store.js +416 -416
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- package/lib/Types/Auth.js +1 -1
- package/lib/Types/Bussines.js +1 -1
- package/lib/Types/Call.js +1 -1
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Contact.js +1 -1
- package/lib/Types/Events.js +1 -1
- package/lib/Types/GroupMetadata.js +1 -1
- package/lib/Types/Label.js +24 -24
- package/lib/Types/LabelAssociation.js +6 -6
- package/lib/Types/Message.js +10 -10
- package/lib/Types/Newsletter.js +28 -28
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -12
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +25 -25
- package/lib/Utils/auth-utils.js +264 -256
- package/lib/Utils/baileys-event-stream.js +55 -55
- package/lib/Utils/browser-utils.js +27 -27
- package/lib/Utils/business.js +228 -230
- package/lib/Utils/chat-utils.js +694 -764
- package/lib/Utils/crypto.js +109 -135
- package/lib/Utils/decode-wa-message.js +310 -314
- package/lib/Utils/event-buffer.js +547 -547
- package/lib/Utils/generics.js +297 -297
- package/lib/Utils/history.js +91 -83
- package/lib/Utils/index.js +21 -20
- package/lib/Utils/key-store.js +17 -0
- package/lib/Utils/link-preview.js +97 -98
- package/lib/Utils/logger.js +2 -2
- package/lib/Utils/lt-hash.js +47 -47
- package/lib/Utils/make-mutex.js +39 -39
- package/lib/Utils/message-retry-manager.js +148 -148
- package/lib/Utils/messages-media.js +534 -534
- package/lib/Utils/messages.js +705 -705
- package/lib/Utils/noise-handler.js +255 -255
- package/lib/Utils/pre-key-manager.js +105 -105
- package/lib/Utils/process-message.js +412 -412
- package/lib/Utils/signal.js +160 -158
- package/lib/Utils/use-multi-file-auth-state.js +120 -120
- package/lib/Utils/validate-connection.js +194 -194
- package/lib/WABinary/constants.js +1300 -1300
- package/lib/WABinary/decode.js +237 -237
- package/lib/WABinary/encode.js +232 -232
- package/lib/WABinary/generic-utils.js +252 -211
- package/lib/WABinary/index.js +5 -5
- package/lib/WABinary/jid-utils.js +279 -95
- package/lib/WABinary/types.js +1 -1
- package/lib/WAM/BinaryInfo.js +9 -9
- package/lib/WAM/constants.js +22852 -22852
- package/lib/WAM/encode.js +149 -149
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
- package/lib/WAUSync/Protocols/index.js +4 -4
- package/lib/WAUSync/USyncQuery.js +93 -93
- package/lib/WAUSync/USyncUser.js +22 -22
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +171 -144
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -100
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-message-key.js +0 -26
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,136 +1,110 @@
|
|
|
1
|
-
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from 'crypto'
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
export function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
export function sha256(buffer) {
|
|
111
|
-
return createHash('sha256').update(buffer).digest();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function derivePairingCodeKey(pairingCode, salt) {
|
|
115
|
-
// Convert inputs to formats Web Crypto API can work with
|
|
116
|
-
const encoder = new TextEncoder();
|
|
117
|
-
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
118
|
-
const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
|
|
119
|
-
|
|
120
|
-
// Import the pairing code as key material
|
|
121
|
-
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
|
|
122
|
-
'deriveBits'
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
// Derive bits using PBKDF2 with the same parameters
|
|
126
|
-
// 2 << 16 = 131,072 iterations
|
|
127
|
-
const derivedBits = await subtle.deriveBits({
|
|
128
|
-
name: 'PBKDF2',
|
|
129
|
-
salt: saltBuffer,
|
|
130
|
-
iterations: 2 << 16,
|
|
131
|
-
hash: 'SHA-256'
|
|
132
|
-
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
return Buffer.from(derivedBits);
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from 'crypto'
|
|
2
|
+
import {
|
|
3
|
+
calculateAgreement,
|
|
4
|
+
calculateSignature,
|
|
5
|
+
verifySignature as rustVerifySignature,
|
|
6
|
+
generateKeyPair as rustGenerateKeyPair,
|
|
7
|
+
hkdf,
|
|
8
|
+
md5
|
|
9
|
+
} from 'whatsapp-rust-bridge'
|
|
10
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js'
|
|
11
|
+
|
|
12
|
+
export { hkdf, md5 }
|
|
13
|
+
|
|
14
|
+
export const generateSignalPubKey = (pubKey) =>
|
|
15
|
+
pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey])
|
|
16
|
+
|
|
17
|
+
export const Curve = {
|
|
18
|
+
generateKeyPair: () => {
|
|
19
|
+
const { pubKey, privKey } = rustGenerateKeyPair()
|
|
20
|
+
return {
|
|
21
|
+
private: Buffer.from(privKey),
|
|
22
|
+
public: Buffer.from(pubKey.slice(1)) // remove version byte
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
sharedKey: (privateKey, publicKey) => {
|
|
26
|
+
const shared = calculateAgreement(generateSignalPubKey(publicKey), privateKey)
|
|
27
|
+
return Buffer.from(shared)
|
|
28
|
+
},
|
|
29
|
+
sign: (privateKey, buf) => calculateSignature(privateKey, buf),
|
|
30
|
+
verify: (pubKey, message, signature) => {
|
|
31
|
+
try {
|
|
32
|
+
return rustVerifySignature(generateSignalPubKey(pubKey), message, signature)
|
|
33
|
+
} catch {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const signedKeyPair = (identityKeyPair, keyId) => {
|
|
40
|
+
const preKey = Curve.generateKeyPair()
|
|
41
|
+
const pubKey = generateSignalPubKey(preKey.public)
|
|
42
|
+
const signature = Curve.sign(identityKeyPair.private, pubKey)
|
|
43
|
+
return { keyPair: preKey, signature, keyId }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const GCM_TAG_LENGTH = 128 >> 3
|
|
47
|
+
|
|
48
|
+
export function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
49
|
+
const cipher = createCipheriv('aes-256-gcm', key, iv)
|
|
50
|
+
cipher.setAAD(additionalData)
|
|
51
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()])
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
55
|
+
const decipher = createDecipheriv('aes-256-gcm', key, iv)
|
|
56
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH)
|
|
57
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH)
|
|
58
|
+
decipher.setAAD(additionalData)
|
|
59
|
+
decipher.setAuthTag(tag)
|
|
60
|
+
return Buffer.concat([decipher.update(enc), decipher.final()])
|
|
61
|
+
}
|
|
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
|
+
|
|
68
|
+
export function aesDecryptCTR(ciphertext, key, iv) {
|
|
69
|
+
const decipher = createDecipheriv('aes-256-ctr', key, iv)
|
|
70
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()])
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function aesDecrypt(buffer, key) {
|
|
74
|
+
return aesDecryptWithIV(buffer.subarray(16), key, buffer.subarray(0, 16))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function aesDecryptWithIV(buffer, key, IV) {
|
|
78
|
+
const aes = createDecipheriv('aes-256-cbc', key, IV)
|
|
79
|
+
return Buffer.concat([aes.update(buffer), aes.final()])
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function aesEncrypt(buffer, key) {
|
|
83
|
+
const IV = randomBytes(16)
|
|
84
|
+
const aes = createCipheriv('aes-256-cbc', key, IV)
|
|
85
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()])
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function aesEncrypWithIV(buffer, key, IV) {
|
|
89
|
+
const aes = createCipheriv('aes-256-cbc', key, IV)
|
|
90
|
+
return Buffer.concat([aes.update(buffer), aes.final()])
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function hmacSign(buffer, key, variant = 'sha256') {
|
|
94
|
+
return createHmac(variant, key).update(buffer).digest()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function sha256(buffer) {
|
|
98
|
+
return createHash('sha256').update(buffer).digest()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function derivePairingCodeKey(pairingCode, salt) {
|
|
102
|
+
const { subtle } = globalThis.crypto
|
|
103
|
+
const encoder = new TextEncoder()
|
|
104
|
+
const keyMaterial = await subtle.importKey('raw', encoder.encode(pairingCode), { name: 'PBKDF2' }, false, ['deriveBits'])
|
|
105
|
+
const derivedBits = await subtle.deriveBits(
|
|
106
|
+
{ name: 'PBKDF2', salt: new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt)), iterations: 2 << 16, hash: 'SHA-256' },
|
|
107
|
+
keyMaterial, 256
|
|
108
|
+
)
|
|
109
|
+
return Buffer.from(derivedBits)
|
|
136
110
|
}
|