@pontalabs/baileys 1.0.10 → 1.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/README.md +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +4 -3
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,189 +1,144 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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("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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
createCipheriv: createCipheriv,
|
|
5
|
+
createDecipheriv: createDecipheriv,
|
|
6
|
+
createHash: createHash,
|
|
7
|
+
createHmac: createHmac,
|
|
8
|
+
randomBytes: randomBytes,
|
|
9
|
+
} = require("crypto");
|
|
10
|
+
const { curve: curve } = require("libsignal");
|
|
11
|
+
const { KEY_BUNDLE_TYPE: KEY_BUNDLE_TYPE } = require("../Defaults/constants");
|
|
12
|
+
const generateSignalPubKey = (pubKey) =>
|
|
13
|
+
pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
|
|
39
14
|
const Curve = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
15
|
+
generateKeyPair: () => {
|
|
16
|
+
const { pubKey: pubKey, privKey: privKey } = curve.generateKeyPair();
|
|
17
|
+
return {
|
|
18
|
+
private: Buffer.from(privKey),
|
|
19
|
+
public: Buffer.from(pubKey.slice(1)),
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
sharedKey: (privateKey, publicKey) => {
|
|
23
|
+
const shared = curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
24
|
+
return Buffer.from(shared);
|
|
25
|
+
},
|
|
26
|
+
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
27
|
+
verify: (pubKey, message, signature) => {
|
|
28
|
+
try {
|
|
29
|
+
curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
30
|
+
return true;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
62
36
|
const signedKeyPair = (identityKeyPair, keyId) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const GCM_TAG_LENGTH = 128 >> 3
|
|
70
|
-
|
|
37
|
+
const preKey = Curve.generateKeyPair();
|
|
38
|
+
const pubKey = generateSignalPubKey(preKey.public);
|
|
39
|
+
const signature = Curve.sign(identityKeyPair.private, pubKey);
|
|
40
|
+
return { keyPair: preKey, signature: signature, keyId: keyId };
|
|
41
|
+
};
|
|
42
|
+
const GCM_TAG_LENGTH = 128 >> 3;
|
|
71
43
|
function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
44
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
45
|
+
cipher.setAAD(additionalData);
|
|
46
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
75
47
|
}
|
|
76
|
-
|
|
77
48
|
function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
49
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
50
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
|
|
51
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
52
|
+
if (additionalData) decipher.setAAD(additionalData);
|
|
53
|
+
decipher.setAuthTag(tag);
|
|
54
|
+
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
84
55
|
}
|
|
85
|
-
|
|
86
56
|
function aesEncryptCTR(plaintext, key, iv) {
|
|
87
|
-
|
|
88
|
-
|
|
57
|
+
const cipher = createCipheriv("aes-256-ctr", key, iv);
|
|
58
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
89
59
|
}
|
|
90
|
-
|
|
91
60
|
function aesDecryptCTR(ciphertext, key, iv) {
|
|
92
|
-
|
|
93
|
-
|
|
61
|
+
const decipher = createDecipheriv("aes-256-ctr", key, iv);
|
|
62
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
94
63
|
}
|
|
95
|
-
|
|
96
64
|
function aesDecrypt(buffer, key) {
|
|
97
|
-
|
|
65
|
+
return aesDecryptWithIV(buffer.slice(16), key, buffer.slice(0, 16));
|
|
98
66
|
}
|
|
99
|
-
|
|
100
67
|
function aesDecryptWithIV(buffer, key, IV) {
|
|
101
|
-
|
|
102
|
-
|
|
68
|
+
const aes = createDecipheriv("aes-256-cbc", key, IV);
|
|
69
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
103
70
|
}
|
|
104
|
-
|
|
105
71
|
function aesEncrypt(buffer, key) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
72
|
+
const IV = randomBytes(16);
|
|
73
|
+
const aes = createCipheriv("aes-256-cbc", key, IV);
|
|
74
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()]);
|
|
109
75
|
}
|
|
110
|
-
|
|
111
76
|
function aesEncrypWithIV(buffer, key, IV) {
|
|
112
|
-
|
|
113
|
-
|
|
77
|
+
const aes = createCipheriv("aes-256-cbc", key, IV);
|
|
78
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
114
79
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return crypto_1.createHmac(variant, key).update(buffer).digest()
|
|
80
|
+
function hmacSign(buffer, key, variant = "sha256") {
|
|
81
|
+
return createHmac(variant, key).update(buffer).digest();
|
|
118
82
|
}
|
|
119
|
-
|
|
120
83
|
function sha256(buffer) {
|
|
121
|
-
|
|
84
|
+
return createHash("sha256").update(buffer).digest();
|
|
122
85
|
}
|
|
123
|
-
|
|
124
86
|
function md5(buffer) {
|
|
125
|
-
|
|
87
|
+
return createHash("md5").update(buffer).digest();
|
|
126
88
|
}
|
|
127
|
-
|
|
128
89
|
async function hkdf(buffer, expandedLength, info) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}, importedKey, expandedLength * 8)
|
|
148
|
-
|
|
149
|
-
return Buffer.from(derivedBits)
|
|
90
|
+
const inputKeyMaterial = new Uint8Array(
|
|
91
|
+
buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer)
|
|
92
|
+
);
|
|
93
|
+
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
94
|
+
const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0);
|
|
95
|
+
const importedKey = await crypto.subtle.importKey(
|
|
96
|
+
"raw",
|
|
97
|
+
inputKeyMaterial,
|
|
98
|
+
{ name: "HKDF" },
|
|
99
|
+
false,
|
|
100
|
+
["deriveBits"]
|
|
101
|
+
);
|
|
102
|
+
const derivedBits = await crypto.subtle.deriveBits(
|
|
103
|
+
{ name: "HKDF", hash: "SHA-256", salt: salt, info: infoBytes },
|
|
104
|
+
importedKey,
|
|
105
|
+
expandedLength * 8
|
|
106
|
+
);
|
|
107
|
+
return Buffer.from(derivedBits);
|
|
150
108
|
}
|
|
151
|
-
|
|
152
109
|
async function derivePairingCodeKey(pairingCode, salt) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return Buffer.from(derivedBits)
|
|
110
|
+
const encoder = new TextEncoder();
|
|
111
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
112
|
+
const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
|
|
113
|
+
const keyMaterial = await crypto.subtle.importKey(
|
|
114
|
+
"raw",
|
|
115
|
+
pairingCodeBuffer,
|
|
116
|
+
{ name: "PBKDF2" },
|
|
117
|
+
false,
|
|
118
|
+
["deriveBits"]
|
|
119
|
+
);
|
|
120
|
+
const derivedBits = await crypto.subtle.deriveBits(
|
|
121
|
+
{ name: "PBKDF2", salt: saltBuffer, iterations: 2 << 16, hash: "SHA-256" },
|
|
122
|
+
keyMaterial,
|
|
123
|
+
32 * 8
|
|
124
|
+
);
|
|
125
|
+
return Buffer.from(derivedBits);
|
|
170
126
|
}
|
|
171
|
-
|
|
172
127
|
module.exports = {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
128
|
+
generateSignalPubKey: generateSignalPubKey,
|
|
129
|
+
Curve: Curve,
|
|
130
|
+
signedKeyPair: signedKeyPair,
|
|
131
|
+
aesEncryptGCM: aesEncryptGCM,
|
|
132
|
+
aesDecryptGCM: aesDecryptGCM,
|
|
133
|
+
aesEncryptCTR: aesEncryptCTR,
|
|
134
|
+
aesDecryptCTR: aesDecryptCTR,
|
|
135
|
+
aesDecrypt: aesDecrypt,
|
|
136
|
+
aesDecryptWithIV: aesDecryptWithIV,
|
|
137
|
+
aesEncrypt: aesEncrypt,
|
|
138
|
+
aesEncrypWithIV: aesEncrypWithIV,
|
|
139
|
+
hmacSign: hmacSign,
|
|
140
|
+
sha256: sha256,
|
|
141
|
+
md5: md5,
|
|
142
|
+
hkdf: hkdf,
|
|
143
|
+
derivePairingCodeKey: derivePairingCodeKey,
|
|
144
|
+
};
|