ai-md-baileys 2.9.9 → 3.1.2
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/dist/cjs/lib/Utils/crypto.js +34 -25
- package/dist/esm/lib/Utils/crypto.js +32 -23
- package/package.json +2 -3
|
@@ -38,38 +38,36 @@ __export(crypto_exports, {
|
|
|
38
38
|
aesEncryptGCM: () => aesEncryptGCM,
|
|
39
39
|
derivePairingCodeKey: () => derivePairingCodeKey,
|
|
40
40
|
generateSignalPubKey: () => generateSignalPubKey,
|
|
41
|
-
hkdf: () =>
|
|
41
|
+
hkdf: () => hkdf,
|
|
42
42
|
hmacSign: () => hmacSign,
|
|
43
|
-
md5: () =>
|
|
43
|
+
md5: () => md5,
|
|
44
44
|
sha256: () => sha256,
|
|
45
45
|
signedKeyPair: () => signedKeyPair
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(crypto_exports);
|
|
48
48
|
var import_crypto = require("crypto");
|
|
49
|
-
var
|
|
49
|
+
var libsignal = __toESM(require("libsignal"));
|
|
50
50
|
var import_Defaults = require("../Defaults/index.js");
|
|
51
|
-
var import_whatsapp_rust_bridge = require("whatsapp-rust-bridge");
|
|
52
51
|
const { subtle } = globalThis.crypto;
|
|
53
52
|
const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([import_Defaults.KEY_BUNDLE_TYPE, pubKey]);
|
|
54
53
|
const Curve = {
|
|
55
54
|
generateKeyPair: () => {
|
|
56
|
-
const { pubKey, privKey } = curve.generateKeyPair();
|
|
55
|
+
const { pubKey, privKey } = libsignal.curve.generateKeyPair();
|
|
57
56
|
return {
|
|
58
57
|
private: Buffer.from(privKey),
|
|
59
|
-
// remove version byte
|
|
60
58
|
public: Buffer.from(pubKey.slice(1))
|
|
61
59
|
};
|
|
62
60
|
},
|
|
63
61
|
sharedKey: (privateKey, publicKey) => {
|
|
64
|
-
const shared = curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
62
|
+
const shared = libsignal.curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
65
63
|
return Buffer.from(shared);
|
|
66
64
|
},
|
|
67
|
-
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
65
|
+
sign: (privateKey, buf) => libsignal.curve.calculateSignature(privateKey, buf),
|
|
68
66
|
verify: (pubKey, message, signature) => {
|
|
69
67
|
try {
|
|
70
|
-
curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
68
|
+
libsignal.curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
71
69
|
return true;
|
|
72
|
-
} catch
|
|
70
|
+
} catch {
|
|
73
71
|
return false;
|
|
74
72
|
}
|
|
75
73
|
}
|
|
@@ -124,24 +122,35 @@ function hmacSign(buffer, key, variant = "sha256") {
|
|
|
124
122
|
function sha256(buffer) {
|
|
125
123
|
return (0, import_crypto.createHash)("sha256").update(buffer).digest();
|
|
126
124
|
}
|
|
125
|
+
function md5(buffer) {
|
|
126
|
+
return (0, import_crypto.createHash)("md5").update(buffer).digest();
|
|
127
|
+
}
|
|
128
|
+
function hkdf(ikm, length, { salt = Buffer.alloc(32, 0), info = "" } = {}) {
|
|
129
|
+
const mac = (0, import_crypto.createHmac)("sha256", salt);
|
|
130
|
+
mac.update(ikm);
|
|
131
|
+
const prk = mac.digest();
|
|
132
|
+
const N = Math.ceil(length / 32);
|
|
133
|
+
const okm = Buffer.alloc(length);
|
|
134
|
+
let T = Buffer.alloc(0);
|
|
135
|
+
for (let i = 1; i <= N; i++) {
|
|
136
|
+
const hmac = (0, import_crypto.createHmac)("sha256", prk);
|
|
137
|
+
hmac.update(Buffer.concat([T, Buffer.from(info), Buffer.from([i])]));
|
|
138
|
+
T = hmac.digest();
|
|
139
|
+
T.copy(okm, (i - 1) * 32);
|
|
140
|
+
}
|
|
141
|
+
return okm;
|
|
142
|
+
}
|
|
127
143
|
async function derivePairingCodeKey(pairingCode, salt) {
|
|
128
144
|
const encoder = new TextEncoder();
|
|
129
145
|
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
130
|
-
const saltBuffer =
|
|
131
|
-
const keyMaterial = await subtle.importKey("raw", pairingCodeBuffer, { name: "PBKDF2" }, false, [
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
iterations: 2 << 16,
|
|
139
|
-
hash: "SHA-256"
|
|
140
|
-
},
|
|
141
|
-
keyMaterial,
|
|
142
|
-
32 * 8
|
|
143
|
-
// 32 bytes * 8 = 256 bits
|
|
144
|
-
);
|
|
146
|
+
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
147
|
+
const keyMaterial = await subtle.importKey("raw", pairingCodeBuffer, { name: "PBKDF2" }, false, ["deriveBits"]);
|
|
148
|
+
const derivedBits = await subtle.deriveBits({
|
|
149
|
+
name: "PBKDF2",
|
|
150
|
+
salt: saltBuffer,
|
|
151
|
+
iterations: 2 << 16,
|
|
152
|
+
hash: "SHA-256"
|
|
153
|
+
}, keyMaterial, 32 * 8);
|
|
145
154
|
return Buffer.from(derivedBits);
|
|
146
155
|
}
|
|
147
156
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from "crypto";
|
|
2
|
-
import * as
|
|
2
|
+
import * as libsignal from "libsignal";
|
|
3
3
|
import { KEY_BUNDLE_TYPE } from "../Defaults/index.js";
|
|
4
|
-
import { md5, hkdf } from "whatsapp-rust-bridge";
|
|
5
4
|
const { subtle } = globalThis.crypto;
|
|
6
5
|
const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
|
|
7
6
|
const Curve = {
|
|
8
7
|
generateKeyPair: () => {
|
|
9
|
-
const { pubKey, privKey } = curve.generateKeyPair();
|
|
8
|
+
const { pubKey, privKey } = libsignal.curve.generateKeyPair();
|
|
10
9
|
return {
|
|
11
10
|
private: Buffer.from(privKey),
|
|
12
|
-
// remove version byte
|
|
13
11
|
public: Buffer.from(pubKey.slice(1))
|
|
14
12
|
};
|
|
15
13
|
},
|
|
16
14
|
sharedKey: (privateKey, publicKey) => {
|
|
17
|
-
const shared = curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
15
|
+
const shared = libsignal.curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
18
16
|
return Buffer.from(shared);
|
|
19
17
|
},
|
|
20
|
-
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
18
|
+
sign: (privateKey, buf) => libsignal.curve.calculateSignature(privateKey, buf),
|
|
21
19
|
verify: (pubKey, message, signature) => {
|
|
22
20
|
try {
|
|
23
|
-
curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
21
|
+
libsignal.curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
24
22
|
return true;
|
|
25
|
-
} catch
|
|
23
|
+
} catch {
|
|
26
24
|
return false;
|
|
27
25
|
}
|
|
28
26
|
}
|
|
@@ -77,24 +75,35 @@ function hmacSign(buffer, key, variant = "sha256") {
|
|
|
77
75
|
function sha256(buffer) {
|
|
78
76
|
return createHash("sha256").update(buffer).digest();
|
|
79
77
|
}
|
|
78
|
+
function md5(buffer) {
|
|
79
|
+
return createHash("md5").update(buffer).digest();
|
|
80
|
+
}
|
|
81
|
+
function hkdf(ikm, length, { salt = Buffer.alloc(32, 0), info = "" } = {}) {
|
|
82
|
+
const mac = createHmac("sha256", salt);
|
|
83
|
+
mac.update(ikm);
|
|
84
|
+
const prk = mac.digest();
|
|
85
|
+
const N = Math.ceil(length / 32);
|
|
86
|
+
const okm = Buffer.alloc(length);
|
|
87
|
+
let T = Buffer.alloc(0);
|
|
88
|
+
for (let i = 1; i <= N; i++) {
|
|
89
|
+
const hmac = createHmac("sha256", prk);
|
|
90
|
+
hmac.update(Buffer.concat([T, Buffer.from(info), Buffer.from([i])]));
|
|
91
|
+
T = hmac.digest();
|
|
92
|
+
T.copy(okm, (i - 1) * 32);
|
|
93
|
+
}
|
|
94
|
+
return okm;
|
|
95
|
+
}
|
|
80
96
|
async function derivePairingCodeKey(pairingCode, salt) {
|
|
81
97
|
const encoder = new TextEncoder();
|
|
82
98
|
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
83
|
-
const saltBuffer =
|
|
84
|
-
const keyMaterial = await subtle.importKey("raw", pairingCodeBuffer, { name: "PBKDF2" }, false, [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
iterations: 2 << 16,
|
|
92
|
-
hash: "SHA-256"
|
|
93
|
-
},
|
|
94
|
-
keyMaterial,
|
|
95
|
-
32 * 8
|
|
96
|
-
// 32 bytes * 8 = 256 bits
|
|
97
|
-
);
|
|
99
|
+
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
100
|
+
const keyMaterial = await subtle.importKey("raw", pairingCodeBuffer, { name: "PBKDF2" }, false, ["deriveBits"]);
|
|
101
|
+
const derivedBits = await subtle.deriveBits({
|
|
102
|
+
name: "PBKDF2",
|
|
103
|
+
salt: saltBuffer,
|
|
104
|
+
iterations: 2 << 16,
|
|
105
|
+
hash: "SHA-256"
|
|
106
|
+
}, keyMaterial, 32 * 8);
|
|
98
107
|
return Buffer.from(derivedBits);
|
|
99
108
|
}
|
|
100
109
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-md-baileys",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Enhanced Baileys fork with newsletter support, album messages, interactive buttons, rich responses, and communities API",
|
|
5
5
|
"main": "./dist/cjs/lib/index.js",
|
|
6
6
|
"module": "./dist/esm/lib/index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"interactive-messages",
|
|
48
48
|
"album",
|
|
49
49
|
"communities",
|
|
50
|
-
"
|
|
50
|
+
"ai-md-wa-bot"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"p-queue": "^9.1.0",
|
|
65
65
|
"pino": "^9.6",
|
|
66
66
|
"protobufjs": "^7.5.4",
|
|
67
|
-
"whatsapp-rust-bridge": "0.5.3",
|
|
68
67
|
"ws": "^8.19.0"
|
|
69
68
|
},
|
|
70
69
|
"optionalDependencies": {
|