@sanzoffc/baileys 3.0.1 → 3.0.3
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/WAProto/WAProto.proto +769 -233
- package/WAProto/index.js +65801 -141371
- package/lib/Defaults/index.js +117 -114
- package/lib/Defaults/index.js.bak +123 -0
- package/lib/KeyDB/BinarySearch.js +20 -0
- package/lib/KeyDB/KeyedDB.js +167 -0
- package/lib/KeyDB/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -14
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +75 -87
- package/lib/Signal/Group/index.js +13 -57
- package/lib/Signal/Group/keyhelper.js +17 -52
- package/lib/Signal/Group/sender-chain-key.js +27 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -63
- package/lib/Signal/Group/sender-key-message.js +65 -66
- package/lib/Signal/Group/sender-key-name.js +45 -44
- package/lib/Signal/Group/sender-key-record.js +39 -49
- package/lib/Signal/Group/sender-key-state.js +80 -93
- package/lib/Signal/Group/sender-message-key.js +27 -28
- package/lib/Signal/libsignal.js +313 -163
- package/lib/Signal/lid-mapping.js +155 -0
- package/lib/Socket/Client/index.js +4 -18
- package/lib/Socket/Client/types.js +12 -12
- package/lib/Socket/Client/websocket.js +51 -71
- package/lib/Socket/Client/websocket.js.bak +53 -0
- package/lib/Socket/business.js +359 -242
- package/lib/Socket/chats.js +858 -945
- package/lib/Socket/communities.js +413 -0
- package/lib/Socket/groups.js +304 -324
- package/lib/Socket/index.js +15 -9
- package/lib/Socket/messages-recv.js +1105 -1046
- package/lib/Socket/messages-send.js +615 -389
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.js +224 -227
- package/lib/Socket/socket.js +795 -621
- package/lib/Store/index.js +6 -8
- package/lib/Store/make-cache-manager-store.js +75 -0
- package/lib/Store/make-in-memory-store.js +286 -435
- package/lib/Store/make-ordered-dictionary.js +77 -79
- package/lib/Store/object-repository.js +24 -26
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +9 -4
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +24 -26
- package/lib/Types/LabelAssociation.js +6 -8
- package/lib/Types/Message.js +12 -7
- package/lib/Types/Newsletter.js +32 -17
- package/lib/Types/Newsletter.js.bak +33 -0
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -2
- package/lib/Types/State.js +11 -2
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +27 -41
- package/lib/Utils/auth-utils.js +211 -191
- package/lib/Utils/baileys-event-stream.js +44 -0
- package/lib/Utils/browser-utils.js +21 -31
- package/lib/Utils/business.js +213 -214
- package/lib/Utils/chat-utils.js +711 -689
- package/lib/Utils/crypto.js +112 -175
- package/lib/Utils/decode-wa-message.js +254 -194
- package/lib/Utils/event-buffer.js +510 -500
- package/lib/Utils/generics.js +318 -430
- package/lib/Utils/history.js +83 -90
- package/lib/Utils/index.js +21 -35
- package/lib/Utils/link-preview.js +71 -116
- package/lib/Utils/logger.js +5 -7
- package/lib/Utils/lt-hash.js +40 -46
- package/lib/Utils/make-mutex.js +34 -41
- package/lib/Utils/message-retry-manager.js +33 -48
- package/lib/Utils/messages-media.js +573 -825
- package/lib/Utils/messages.js +349 -489
- package/lib/Utils/noise-handler.js +138 -144
- package/lib/Utils/pre-key-manager.js +85 -0
- package/lib/Utils/process-message.js +321 -384
- package/lib/Utils/signal.js +147 -139
- package/lib/Utils/use-multi-file-auth-state.js +95 -109
- package/lib/Utils/validate-connection.js +183 -212
- package/lib/WABinary/constants.js +1298 -1298
- package/lib/WABinary/decode.js +231 -256
- package/lib/WABinary/encode.js +207 -239
- package/lib/WABinary/generic-utils.js +119 -40
- package/lib/WABinary/index.js +7 -21
- package/lib/WABinary/jid-utils.js +87 -79
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.js +10 -12
- package/lib/WAM/constants.js +22851 -15348
- package/lib/WAM/encode.js +135 -136
- package/lib/WAM/index.js +5 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.js +86 -85
- package/lib/WAUSync/USyncUser.js +23 -25
- package/lib/WAUSync/index.js +5 -19
- package/lib/index.js +18 -49
- package/package.json +65 -78
- package/README.MD +0 -1295
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/p.html +0 -1
- package/engine-requirements.js +0 -10
- package/lib/Defaults/wileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.js +0 -70
- package/lib/Utils/wileys-event-stream.js +0 -63
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,193 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = void 0;
|
|
37
|
-
exports.aesEncryptGCM = aesEncryptGCM;
|
|
38
|
-
exports.aesDecryptGCM = aesDecryptGCM;
|
|
39
|
-
exports.aesEncryptCTR = aesEncryptCTR;
|
|
40
|
-
exports.aesDecryptCTR = aesDecryptCTR;
|
|
41
|
-
exports.aesDecrypt = aesDecrypt;
|
|
42
|
-
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
43
|
-
exports.aesEncrypt = aesEncrypt;
|
|
44
|
-
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
45
|
-
exports.hmacSign = hmacSign;
|
|
46
|
-
exports.sha256 = sha256;
|
|
47
|
-
exports.md5 = md5;
|
|
48
|
-
exports.hkdf = hkdf;
|
|
49
|
-
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
50
|
-
const crypto_1 = require("crypto");
|
|
51
|
-
const libsignal = __importStar(require("libsignal"));
|
|
52
|
-
const Defaults_1 = require("../Defaults");
|
|
53
|
-
// insure browser & node compatibility
|
|
1
|
+
//=======================================================//
|
|
2
|
+
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from "crypto";
|
|
3
|
+
import { KEY_BUNDLE_TYPE } from "../Defaults/index.js";
|
|
4
|
+
import * as curve from "@skycodee/libsignal/src/curve.js";
|
|
5
|
+
//=======================================================//
|
|
54
6
|
const { subtle } = globalThis.crypto;
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
libsignal.curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
7
|
+
export const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
|
|
8
|
+
export const Curve = {
|
|
9
|
+
generateKeyPair: () => {
|
|
10
|
+
const { pubKey, privKey } = curve.generateKeyPair();
|
|
11
|
+
return {
|
|
12
|
+
private: Buffer.from(privKey),
|
|
13
|
+
public: Buffer.from(pubKey.slice(1))
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
sharedKey: (privateKey, publicKey) => {
|
|
17
|
+
const shared = curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
18
|
+
return Buffer.from(shared);
|
|
19
|
+
},
|
|
20
|
+
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
21
|
+
verify: (pubKey, message, signature) => {
|
|
22
|
+
try {
|
|
23
|
+
curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return false;
|
|
82
28
|
}
|
|
29
|
+
}
|
|
83
30
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
31
|
+
//=======================================================//
|
|
32
|
+
export const signedKeyPair = (identityKeyPair, keyId) => {
|
|
33
|
+
const preKey = Curve.generateKeyPair();
|
|
34
|
+
const pubKey = generateSignalPubKey(preKey.public);
|
|
35
|
+
const signature = Curve.sign(identityKeyPair.private, pubKey);
|
|
36
|
+
return { keyPair: preKey, signature, keyId };
|
|
89
37
|
};
|
|
90
|
-
|
|
38
|
+
//=======================================================//
|
|
91
39
|
const GCM_TAG_LENGTH = 128 >> 3;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
97
|
-
const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', key, iv);
|
|
98
|
-
cipher.setAAD(additionalData);
|
|
99
|
-
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
40
|
+
export function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
41
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
42
|
+
cipher.setAAD(additionalData);
|
|
43
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
100
44
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
110
|
-
// set additional data
|
|
111
|
-
decipher.setAAD(additionalData);
|
|
112
|
-
decipher.setAuthTag(tag);
|
|
113
|
-
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
45
|
+
//=======================================================//
|
|
46
|
+
export function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
47
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
48
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
|
|
49
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
50
|
+
decipher.setAAD(additionalData);
|
|
51
|
+
decipher.setAuthTag(tag);
|
|
52
|
+
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
114
53
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
54
|
+
//=======================================================//
|
|
55
|
+
export function aesEncryptCTR(plaintext, key, iv) {
|
|
56
|
+
const cipher = createCipheriv("aes-256-ctr", key, iv);
|
|
57
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
118
58
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
59
|
+
//=======================================================//
|
|
60
|
+
export function aesDecryptCTR(ciphertext, key, iv) {
|
|
61
|
+
const decipher = createDecipheriv("aes-256-ctr", key, iv);
|
|
62
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
122
63
|
}
|
|
123
|
-
|
|
124
|
-
function aesDecrypt(buffer, key) {
|
|
125
|
-
|
|
64
|
+
//=======================================================//
|
|
65
|
+
export function aesDecrypt(buffer, key) {
|
|
66
|
+
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
126
67
|
}
|
|
127
|
-
|
|
128
|
-
function aesDecryptWithIV(buffer, key, IV) {
|
|
129
|
-
|
|
130
|
-
|
|
68
|
+
//=======================================================//
|
|
69
|
+
export function aesDecryptWithIV(buffer, key, IV) {
|
|
70
|
+
const aes = createDecipheriv("aes-256-cbc", key, IV);
|
|
71
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
131
72
|
}
|
|
132
|
-
|
|
133
|
-
function aesEncrypt(buffer, key) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
73
|
+
//=======================================================//
|
|
74
|
+
export function aesEncrypt(buffer, key) {
|
|
75
|
+
const IV = randomBytes(16);
|
|
76
|
+
const aes = createCipheriv("aes-256-cbc", key, IV);
|
|
77
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()]);
|
|
137
78
|
}
|
|
138
|
-
|
|
139
|
-
function aesEncrypWithIV(buffer, key, IV) {
|
|
140
|
-
|
|
141
|
-
|
|
79
|
+
//=======================================================//
|
|
80
|
+
export function aesEncrypWithIV(buffer, key, IV) {
|
|
81
|
+
const aes = createCipheriv("aes-256-cbc", key, IV);
|
|
82
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
142
83
|
}
|
|
143
|
-
|
|
144
|
-
function hmacSign(buffer, key, variant =
|
|
145
|
-
|
|
84
|
+
//=======================================================//
|
|
85
|
+
export function hmacSign(buffer, key, variant = "sha256") {
|
|
86
|
+
return createHmac(variant, key).update(buffer).digest();
|
|
146
87
|
}
|
|
147
|
-
|
|
148
|
-
|
|
88
|
+
//=======================================================//
|
|
89
|
+
export function sha256(buffer) {
|
|
90
|
+
return createHash("sha256").update(buffer).digest();
|
|
149
91
|
}
|
|
150
|
-
|
|
151
|
-
|
|
92
|
+
//=======================================================//
|
|
93
|
+
export function md5(buffer) {
|
|
94
|
+
return createHash("md5").update(buffer).digest();
|
|
152
95
|
}
|
|
153
|
-
|
|
154
|
-
async function hkdf(buffer, expandedLength, info) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
hash: 'SHA-256',
|
|
170
|
-
salt: salt,
|
|
171
|
-
info: infoBytes
|
|
172
|
-
}, importedKey, expandedLength * 8 // Convert bytes to bits
|
|
173
|
-
);
|
|
174
|
-
return Buffer.from(derivedBits);
|
|
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);
|
|
175
112
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return Buffer.from(derivedBits);
|
|
113
|
+
//=======================================================//
|
|
114
|
+
export async function derivePairingCodeKey(pairingCode, salt) {
|
|
115
|
+
const encoder = new TextEncoder();
|
|
116
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
117
|
+
const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
|
|
118
|
+
const keyMaterial = await subtle.importKey("raw", pairingCodeBuffer, { name: "PBKDF2" }, false, [
|
|
119
|
+
"deriveBits"
|
|
120
|
+
]);
|
|
121
|
+
const derivedBits = await subtle.deriveBits({
|
|
122
|
+
name: "PBKDF2",
|
|
123
|
+
salt: saltBuffer,
|
|
124
|
+
iterations: 2 << 16,
|
|
125
|
+
hash: "SHA-256"
|
|
126
|
+
}, keyMaterial, 32 * 8
|
|
127
|
+
);
|
|
128
|
+
return Buffer.from(derivedBits);
|
|
193
129
|
}
|
|
130
|
+
//=======================================================//
|