@rexxhayanasi/elaina-baileys 1.1.8 → 1.1.9
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/lib/Signal/Group/keyhelper.js +32 -20
- package/lib/Utils/messages-media.js +5 -4
- package/lib/Utils/messages.js +4 -9
- package/lib/index.js +0 -1
- package/package.json +2 -3
- package/lib/Auth/index.js +0 -8
- package/lib/Auth/sqlite.js +0 -57
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Signal Group Key Helper
|
|
4
|
+
* Helper functions to generate sender keys and signing keys safely.
|
|
5
|
+
*/
|
|
2
6
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
7
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
8
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
9
|
}) : (function(o, m, k, k2) {
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
|
|
13
14
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
15
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
16
|
}) : function(o, v) {
|
|
16
17
|
o["default"] = v;
|
|
17
18
|
});
|
|
19
|
+
|
|
18
20
|
var __importStar = (this && this.__importStar) || (function () {
|
|
19
21
|
var ownKeys = function(o) {
|
|
20
22
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
@@ -32,45 +34,55 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
34
|
return result;
|
|
33
35
|
};
|
|
34
36
|
})();
|
|
37
|
+
|
|
35
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
39
|
exports.generateSenderKey = generateSenderKey;
|
|
37
40
|
exports.generateSenderKeyId = generateSenderKeyId;
|
|
38
41
|
exports.generateSenderSigningKey = generateSenderSigningKey;
|
|
42
|
+
|
|
39
43
|
const nodeCrypto = __importStar(require("crypto"));
|
|
40
|
-
const curve_1 = require("libsignal/src/curve");
|
|
44
|
+
const curve_1 = require("libsignal/src/curve");
|
|
41
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Generates a random 32-byte Sender Key.
|
|
48
|
+
* @returns {Buffer} The generated key.
|
|
49
|
+
*/
|
|
42
50
|
function generateSenderKey() {
|
|
43
51
|
const key = nodeCrypto.randomBytes(32);
|
|
44
|
-
if (
|
|
45
|
-
throw new Error("Failed to generate valid
|
|
52
|
+
if (key.length !== 32) {
|
|
53
|
+
throw new Error("Failed to generate a valid 32-byte Sender Key");
|
|
46
54
|
}
|
|
47
55
|
return key;
|
|
48
56
|
}
|
|
49
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Generates a random Sender Key ID.
|
|
60
|
+
* @returns {number} The generated Key ID.
|
|
61
|
+
*/
|
|
50
62
|
function generateSenderKeyId() {
|
|
51
63
|
const id = nodeCrypto.randomInt(2147483647);
|
|
52
|
-
if (typeof id !== 'number') {
|
|
53
|
-
throw new Error("Failed to generate
|
|
64
|
+
if (!id || typeof id !== 'number') {
|
|
65
|
+
throw new Error("Failed to generate Sender Key ID");
|
|
54
66
|
}
|
|
55
67
|
return id;
|
|
56
68
|
}
|
|
57
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Generates a Sender Signing Key Pair.
|
|
72
|
+
* Uses libsignal's curve implementation.
|
|
73
|
+
* @param {Object} [key] Optional existing key pair.
|
|
74
|
+
* @returns {Object} The key pair (public/private).
|
|
75
|
+
*/
|
|
58
76
|
function generateSenderSigningKey(key) {
|
|
59
77
|
if (!key) {
|
|
60
78
|
key = (0, curve_1.generateKeyPair)();
|
|
61
79
|
}
|
|
80
|
+
|
|
62
81
|
if (!key || !key.pubKey || !key.privKey) {
|
|
63
|
-
throw new Error("Invalid
|
|
82
|
+
throw new Error("Invalid KeyPair generated from Curve");
|
|
64
83
|
}
|
|
65
|
-
const publicBuf = Buffer.from(key.pubKey);
|
|
66
|
-
const privateBuf = Buffer.from(key.privKey);
|
|
67
|
-
|
|
68
|
-
if (publicBuf.length !== 32 || privateBuf.length !== 32) {
|
|
69
|
-
throw new Error("Invalid signing key length");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
84
|
return {
|
|
73
|
-
public:
|
|
74
|
-
private:
|
|
85
|
+
public: key.pubKey,
|
|
86
|
+
private: key.privKey
|
|
75
87
|
};
|
|
76
88
|
}
|
|
@@ -83,9 +83,8 @@ const getImageProcessingLibrary = async () => {
|
|
|
83
83
|
throw new boom_1.Boom('No image processing library available');
|
|
84
84
|
};
|
|
85
85
|
const hkdfInfoKey = (type) => {
|
|
86
|
-
if (type === 'ptv') return 'WhatsApp Video Keys';
|
|
87
86
|
if (type === 'sticker-pack') return 'WhatsApp Image Keys';
|
|
88
|
-
|
|
87
|
+
if (type === 'ptv') return 'WhatsApp Video Keys';
|
|
89
88
|
const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
|
|
90
89
|
return `WhatsApp ${hkdfInfo} Keys`;
|
|
91
90
|
};
|
|
@@ -727,7 +726,7 @@ function extensionForMediaMessage(message) {
|
|
|
727
726
|
}
|
|
728
727
|
return extension;
|
|
729
728
|
}
|
|
730
|
-
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
729
|
+
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
731
730
|
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
|
732
731
|
var _a, _b;
|
|
733
732
|
let uploadInfo = await refreshMediaConn(false);
|
|
@@ -741,6 +740,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
741
740
|
}
|
|
742
741
|
const reqBody = Buffer.isBuffer(stream) ? stream : Buffer.concat(chunks);
|
|
743
742
|
fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
|
|
743
|
+
|
|
744
744
|
let media = Defaults_1.MEDIA_PATH_MAP[mediaType];
|
|
745
745
|
if (mediaType === 'sticker-pack') {
|
|
746
746
|
media = '/mms/image';
|
|
@@ -748,6 +748,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
748
748
|
if (newsletter) {
|
|
749
749
|
media = media === null || media === void 0 ? void 0 : media.replace('/mms/', '/newsletter/newsletter-');
|
|
750
750
|
}
|
|
751
|
+
|
|
751
752
|
for (const { hostname, maxContentLengthBytes } of hosts) {
|
|
752
753
|
logger.debug(`uploading to "${hostname}"`);
|
|
753
754
|
const auth = encodeURIComponent(uploadInfo.auth);
|
|
@@ -798,7 +799,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
|
|
|
798
799
|
return urls;
|
|
799
800
|
};
|
|
800
801
|
};
|
|
801
|
-
exports.getWAUploadToServer = getWAUploadToServer;
|
|
802
|
+
exports.getWAUploadToServer = getWAUploadToServer;
|
|
802
803
|
const getMediaRetryKey = (mediaKey) => {
|
|
803
804
|
return (0, crypto_1.hkdf)(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
|
|
804
805
|
};
|
package/lib/Utils/messages.js
CHANGED
|
@@ -126,7 +126,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
const isNewsletter = (0, WABinary_1.isJidNewsletter)(options.jid);
|
|
129
|
+
const isNewsletter = options.newsletter || (options.jid && (0, WABinary_1.isJidNewsletter)(options.jid));
|
|
130
130
|
|
|
131
131
|
if (isNewsletter) {
|
|
132
132
|
logger === null || logger === void 0 ? void 0 : logger.debug({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
@@ -142,7 +142,8 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
142
142
|
const { mediaUrl, directPath } = await options.upload(bodyPath, {
|
|
143
143
|
fileEncSha256B64,
|
|
144
144
|
mediaType,
|
|
145
|
-
timeoutMs: options.mediaUploadTimeoutMs
|
|
145
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
146
|
+
newsletter: true
|
|
146
147
|
});
|
|
147
148
|
|
|
148
149
|
if (didSaveToTmpPath && bodyPath) {
|
|
@@ -210,21 +211,16 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
210
211
|
if (!uploadData.width && originalImageDimensions) {
|
|
211
212
|
uploadData.width = originalImageDimensions.width;
|
|
212
213
|
uploadData.height = originalImageDimensions.height;
|
|
213
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('set dimensions');
|
|
214
214
|
}
|
|
215
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('generated thumbnail');
|
|
216
215
|
}
|
|
217
216
|
if (requiresDurationComputation) {
|
|
218
217
|
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(bodyPath);
|
|
219
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
|
|
220
218
|
}
|
|
221
219
|
if (requiresWaveformProcessing) {
|
|
222
220
|
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
|
|
223
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
224
221
|
}
|
|
225
222
|
if (requiresAudioBackground) {
|
|
226
223
|
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
227
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('computed backgroundColor audio status');
|
|
228
224
|
}
|
|
229
225
|
}
|
|
230
226
|
catch (error) {
|
|
@@ -262,19 +258,18 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
262
258
|
})
|
|
263
259
|
});
|
|
264
260
|
|
|
265
|
-
|
|
266
261
|
if (uploadData.ptv) {
|
|
267
262
|
obj.ptvMessage = obj.videoMessage;
|
|
268
263
|
delete obj.videoMessage;
|
|
269
264
|
}
|
|
270
265
|
|
|
271
266
|
if (cacheableKey) {
|
|
272
|
-
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
|
|
273
267
|
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
274
268
|
}
|
|
275
269
|
return obj;
|
|
276
270
|
};
|
|
277
271
|
exports.prepareWAMessageMedia = prepareWAMessageMedia;
|
|
272
|
+
|
|
278
273
|
const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
279
274
|
ephemeralExpiration = ephemeralExpiration || 0;
|
|
280
275
|
const content = {
|
package/lib/index.js
CHANGED
|
@@ -55,6 +55,5 @@ __exportStar(require("./WABinary"), exports);
|
|
|
55
55
|
__exportStar(require("./WAM"), exports);
|
|
56
56
|
__exportStar(require("./WAUSync"), exports);
|
|
57
57
|
__exportStar(require("./Api"), exports);
|
|
58
|
-
__exportStar(require("./Auth"), exports);
|
|
59
58
|
|
|
60
59
|
exports.default = Socket_1.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexxhayanasi/elaina-baileys",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Custom Baileys WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -89,8 +89,7 @@
|
|
|
89
89
|
"jimp": "^0.22.10",
|
|
90
90
|
"link-preview-js": "^3.0.0",
|
|
91
91
|
"qrcode-terminal": "^0.12.0",
|
|
92
|
-
"sharp": "^0.34.1"
|
|
93
|
-
"better-sqlite3": "^12.5.0"
|
|
92
|
+
"sharp": "^0.34.1"
|
|
94
93
|
},
|
|
95
94
|
"peerDependenciesMeta": {
|
|
96
95
|
"jimp": {
|
package/lib/Auth/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useSQLiteAuth = void 0;
|
|
7
|
-
const sqlite_1 = __importDefault(require("./sqlite"));
|
|
8
|
-
exports.useSQLiteAuth = sqlite_1.default;
|
package/lib/Auth/sqlite.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.useSQLiteAuth = void 0;
|
|
5
|
-
|
|
6
|
-
const BetterSqlite = require("better-sqlite3");
|
|
7
|
-
const { BufferJSON } = require("../index");
|
|
8
|
-
const { initAuthCreds } = require("../Utils");
|
|
9
|
-
|
|
10
|
-
const db = new BetterSqlite("./session.db");
|
|
11
|
-
|
|
12
|
-
db.exec(`
|
|
13
|
-
CREATE TABLE IF NOT EXISTS auth (
|
|
14
|
-
id TEXT PRIMARY KEY,
|
|
15
|
-
data TEXT
|
|
16
|
-
)
|
|
17
|
-
`);
|
|
18
|
-
|
|
19
|
-
const useSQLiteAuth = () => {
|
|
20
|
-
const readData = (id) => {
|
|
21
|
-
const row = db.prepare("SELECT data FROM auth WHERE id=?").get(id);
|
|
22
|
-
return row ? JSON.parse(row.data, BufferJSON.reviver) : null;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const writeData = (id, data) => {
|
|
26
|
-
db.prepare("INSERT OR REPLACE INTO auth VALUES (?, ?)")
|
|
27
|
-
.run(id, JSON.stringify(data, BufferJSON.replacer));
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const state = {
|
|
31
|
-
creds: readData("creds") || initAuthCreds(),
|
|
32
|
-
keys: {
|
|
33
|
-
get(type, ids) {
|
|
34
|
-
const data = {};
|
|
35
|
-
for (const id of ids) {
|
|
36
|
-
const value = readData(`${type}-${id}`);
|
|
37
|
-
if (value) data[id] = value;
|
|
38
|
-
}
|
|
39
|
-
return data;
|
|
40
|
-
},
|
|
41
|
-
set(data) {
|
|
42
|
-
for (const type in data) {
|
|
43
|
-
for (const id in data[type]) {
|
|
44
|
-
writeData(`${type}-${id}`, data[type][id]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const saveCreds = () => writeData("creds", state.creds);
|
|
52
|
-
|
|
53
|
-
return { state, saveCreds };
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
exports.useSQLiteAuth = useSQLiteAuth;
|
|
57
|
-
exports.default = useSQLiteAuth;
|