@baileys-md/baileys 11.2.4 → 12.0.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 +113 -2
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.js +14270 -302
- package/lib/Defaults/index.js +50 -54
- package/lib/Defaults/wileys-version.json +3 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +33 -20
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/chats.js +136 -92
- package/lib/Socket/groups.js +16 -11
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.js +26 -15
- package/lib/Socket/messages-send.js +122 -86
- package/lib/Socket/newsletter.js +23 -21
- package/lib/Socket/socket.js +29 -15
- package/lib/Store/make-in-memory-store.js +23 -15
- package/lib/Utils/auth-utils.js +0 -7
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/chat-utils.js +2 -2
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.js +15 -7
- package/lib/Utils/event-buffer.js +6 -8
- package/lib/Utils/generics.js +38 -16
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/index.js +3 -1
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +212 -57
- package/lib/Utils/messages.js +38 -7
- package/lib/Utils/noise-handler.js +5 -10
- package/lib/Utils/process-message.js +34 -2
- package/lib/Utils/signal.js +26 -16
- package/lib/Utils/validate-connection.js +88 -66
- package/lib/Utils/{baileys-event-stream.js → wileys-event-stream.js} +1 -1
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/jid-utils.js +20 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/index.js +17 -6
- package/package.json +22 -17
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-mongo-store.js +0 -567
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
|
@@ -28,7 +28,7 @@ exports.default = (config) => {
|
|
|
28
28
|
const chatKey = config.chatKey || (0, exports.waChatKey)(true);
|
|
29
29
|
const labelAssociationKey = config.labelAssociationKey || exports.waLabelAssociationKey;
|
|
30
30
|
const logger = config.logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
|
|
31
|
-
const KeyedDB = require('@
|
|
31
|
+
const KeyedDB = require('@adiwajshing/keyed-db').default;
|
|
32
32
|
const chats = new KeyedDB(chatKey, c => c.id);
|
|
33
33
|
const messages = {};
|
|
34
34
|
const contacts = {};
|
|
@@ -65,7 +65,7 @@ exports.default = (config) => {
|
|
|
65
65
|
return Object.keys(contacts);
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
|
-
* binds to a
|
|
68
|
+
* binds to a WileysEventEmitter.
|
|
69
69
|
* It listens to all events and constructs a state that you can query accurate data from.
|
|
70
70
|
* Eg. can use the store to fetch chats, contacts, messages etc.
|
|
71
71
|
* @param ev typically the event emitter from the socket connection
|
|
@@ -191,16 +191,14 @@ exports.default = (config) => {
|
|
|
191
191
|
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
192
192
|
const list = assertMessageList(jid);
|
|
193
193
|
list.upsert(msg, 'append');
|
|
194
|
-
if (type === 'notify') {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
]);
|
|
203
|
-
}
|
|
194
|
+
if (type === 'notify' && !chats.get(jid)) {
|
|
195
|
+
ev.emit('chats.upsert', [
|
|
196
|
+
{
|
|
197
|
+
id: jid,
|
|
198
|
+
conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
|
|
199
|
+
unreadCount: 1
|
|
200
|
+
}
|
|
201
|
+
]);
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
break;
|
|
@@ -422,9 +420,19 @@ exports.default = (config) => {
|
|
|
422
420
|
const { readFileSync, existsSync } = require('fs');
|
|
423
421
|
if (existsSync(path)) {
|
|
424
422
|
logger.debug({ path }, 'reading from file');
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
423
|
+
try {
|
|
424
|
+
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
|
425
|
+
if (jsonStr.trim().length) {
|
|
426
|
+
const json = JSON.parse(jsonStr);
|
|
427
|
+
fromJSON(json);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
logger.warn({ path }, 'skipping empty json file');
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
catch (err) {
|
|
434
|
+
logger.warn({ path, err }, 'failed to parse json from file');
|
|
435
|
+
}
|
|
428
436
|
}
|
|
429
437
|
}
|
|
430
438
|
};
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
|
7
7
|
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
8
8
|
const crypto_1 = require("crypto");
|
|
9
9
|
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
10
|
const Defaults_1 = require("../Defaults");
|
|
12
11
|
const crypto_2 = require("./crypto");
|
|
13
12
|
const generics_1 = require("./generics");
|
|
@@ -191,13 +190,7 @@ const initAuthCreds = () => {
|
|
|
191
190
|
accountSettings: {
|
|
192
191
|
unarchiveChats: false
|
|
193
192
|
},
|
|
194
|
-
// mobile creds
|
|
195
|
-
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
196
|
-
phoneId: (0, uuid_1.v4)(),
|
|
197
|
-
identityId: (0, crypto_1.randomBytes)(20),
|
|
198
193
|
registered: false,
|
|
199
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
-
registration: {},
|
|
201
194
|
pairingCode: undefined,
|
|
202
195
|
lastPropHash: undefined,
|
|
203
196
|
routingInfo: undefined,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPlatformId = exports.Browsers = void 0;
|
|
4
|
+
|
|
5
|
+
const os = require("os");
|
|
6
|
+
const { proto } = require("../../WAProto/index.js");
|
|
7
|
+
|
|
8
|
+
const PLATFORM_MAP = {
|
|
9
|
+
'aix': 'AIX',
|
|
10
|
+
'darwin': 'Mac OS',
|
|
11
|
+
'win32': 'Windows',
|
|
12
|
+
'android': 'Android',
|
|
13
|
+
'freebsd': 'FreeBSD',
|
|
14
|
+
'openbsd': 'OpenBSD',
|
|
15
|
+
'sunos': 'Solaris',
|
|
16
|
+
'linux': undefined, // Default ke Ubuntu untuk Linux
|
|
17
|
+
'haiku': undefined,
|
|
18
|
+
'cygwin': undefined,
|
|
19
|
+
'netbsd': undefined
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Fixed: Browsers sekarang fungsi yang return array [platform, browser, version]
|
|
23
|
+
// Ini kompatibel dengan pemanggilan Browsers('Chrome') di Defaults/index.js
|
|
24
|
+
exports.Browsers = (browser) => {
|
|
25
|
+
const osName = PLATFORM_MAP[os.platform()] || 'Ubuntu'; // Default Ubuntu kalau undefined
|
|
26
|
+
const osRelease = os.release(); // Ambil versi OS real-time
|
|
27
|
+
return [osName, browser, osRelease];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getPlatformId = (browser) => {
|
|
31
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
32
|
+
return platformType ? platformType.toString() : '1'; // Default Chrome
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.getPlatformId = getPlatformId;
|
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.processSyncAction = exports.chatModificationToAppPatch = exports.decodePatches = exports.decodeSyncdSnapshot = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.extractSyncdPatches = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.encodeSyncdPatch = exports.newLTHashState = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const WAProto_1 = require("../../WAProto");
|
|
6
|
-
const LabelAssociation_1 = require("../Types/LabelAssociation");
|
|
7
6
|
const WABinary_1 = require("../WABinary");
|
|
7
|
+
const LabelAssociation_1 = require("../Types/LabelAssociation");
|
|
8
8
|
const crypto_1 = require("./crypto");
|
|
9
9
|
const generics_1 = require("./generics");
|
|
10
10
|
const lt_hash_1 = require("./lt-hash");
|
|
@@ -639,7 +639,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
|
639
639
|
});
|
|
640
640
|
}
|
|
641
641
|
else if (action === null || action === void 0 ? void 0 : action.contactAction) {
|
|
642
|
-
ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName }]);
|
|
642
|
+
ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName, lid: action.contactAction.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(id) ? id : action.contactAction.pnJid }]);
|
|
643
643
|
}
|
|
644
644
|
else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
|
|
645
645
|
const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -15,22 +15,43 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
})();
|
|
28
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
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;
|
|
30
50
|
const crypto_1 = require("crypto");
|
|
31
|
-
const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
|
|
32
51
|
const libsignal = __importStar(require("libsignal"));
|
|
33
52
|
const Defaults_1 = require("../Defaults");
|
|
53
|
+
// insure browser & node compatibility
|
|
54
|
+
const { subtle } = globalThis.crypto;
|
|
34
55
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
35
56
|
const generateSignalPubKey = (pubKey) => (pubKey.length === 33
|
|
36
57
|
? pubKey
|
|
@@ -77,7 +98,6 @@ function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
77
98
|
cipher.setAAD(additionalData);
|
|
78
99
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
79
100
|
}
|
|
80
|
-
exports.aesEncryptGCM = aesEncryptGCM;
|
|
81
101
|
/**
|
|
82
102
|
* decrypt AES 256 GCM;
|
|
83
103
|
* where the auth tag is suffixed to the ciphertext
|
|
@@ -92,60 +112,82 @@ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
92
112
|
decipher.setAuthTag(tag);
|
|
93
113
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
94
114
|
}
|
|
95
|
-
exports.aesDecryptGCM = aesDecryptGCM;
|
|
96
115
|
function aesEncryptCTR(plaintext, key, iv) {
|
|
97
116
|
const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
|
|
98
117
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
99
118
|
}
|
|
100
|
-
exports.aesEncryptCTR = aesEncryptCTR;
|
|
101
119
|
function aesDecryptCTR(ciphertext, key, iv) {
|
|
102
120
|
const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
|
|
103
121
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
104
122
|
}
|
|
105
|
-
exports.aesDecryptCTR = aesDecryptCTR;
|
|
106
123
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
107
124
|
function aesDecrypt(buffer, key) {
|
|
108
125
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
109
126
|
}
|
|
110
|
-
exports.aesDecrypt = aesDecrypt;
|
|
111
127
|
/** decrypt AES 256 CBC */
|
|
112
128
|
function aesDecryptWithIV(buffer, key, IV) {
|
|
113
129
|
const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
|
|
114
130
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
115
131
|
}
|
|
116
|
-
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
117
132
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
118
133
|
function aesEncrypt(buffer, key) {
|
|
119
134
|
const IV = (0, crypto_1.randomBytes)(16);
|
|
120
135
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
121
136
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
122
137
|
}
|
|
123
|
-
exports.aesEncrypt = aesEncrypt;
|
|
124
138
|
// encrypt AES 256 CBC with a given IV
|
|
125
139
|
function aesEncrypWithIV(buffer, key, IV) {
|
|
126
140
|
const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
|
|
127
141
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
128
142
|
}
|
|
129
|
-
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
130
143
|
// sign HMAC using SHA 256
|
|
131
144
|
function hmacSign(buffer, key, variant = 'sha256') {
|
|
132
145
|
return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
|
|
133
146
|
}
|
|
134
|
-
exports.hmacSign = hmacSign;
|
|
135
147
|
function sha256(buffer) {
|
|
136
148
|
return (0, crypto_1.createHash)('sha256').update(buffer).digest();
|
|
137
149
|
}
|
|
138
|
-
exports.sha256 = sha256;
|
|
139
150
|
function md5(buffer) {
|
|
140
151
|
return (0, crypto_1.createHash)('md5').update(buffer).digest();
|
|
141
152
|
}
|
|
142
|
-
exports.md5 = md5;
|
|
143
153
|
// HKDF key expansion
|
|
144
|
-
function hkdf(buffer, expandedLength, info) {
|
|
145
|
-
|
|
154
|
+
async function hkdf(buffer, expandedLength, info) {
|
|
155
|
+
// Ensure we have a Uint8Array for the key material
|
|
156
|
+
const inputKeyMaterial = buffer instanceof Uint8Array
|
|
157
|
+
? buffer
|
|
158
|
+
: new Uint8Array(buffer);
|
|
159
|
+
// Set default values if not provided
|
|
160
|
+
const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0);
|
|
161
|
+
const infoBytes = info.info
|
|
162
|
+
? new TextEncoder().encode(info.info)
|
|
163
|
+
: new Uint8Array(0);
|
|
164
|
+
// Import the input key material
|
|
165
|
+
const importedKey = await subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits']);
|
|
166
|
+
// Derive bits using HKDF
|
|
167
|
+
const derivedBits = await subtle.deriveBits({
|
|
168
|
+
name: 'HKDF',
|
|
169
|
+
hash: 'SHA-256',
|
|
170
|
+
salt: salt,
|
|
171
|
+
info: infoBytes
|
|
172
|
+
}, importedKey, expandedLength * 8 // Convert bytes to bits
|
|
173
|
+
);
|
|
174
|
+
return Buffer.from(derivedBits);
|
|
146
175
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
176
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
177
|
+
// Convert inputs to formats Web Crypto API can work with
|
|
178
|
+
const encoder = new TextEncoder();
|
|
179
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
180
|
+
const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt);
|
|
181
|
+
// Import the pairing code as key material
|
|
182
|
+
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
183
|
+
// Derive bits using PBKDF2 with the same parameters
|
|
184
|
+
// 2 << 16 = 131,072 iterations
|
|
185
|
+
const derivedBits = await subtle.deriveBits({
|
|
186
|
+
name: 'PBKDF2',
|
|
187
|
+
salt: saltBuffer,
|
|
188
|
+
iterations: 2 << 16,
|
|
189
|
+
hash: 'SHA-256'
|
|
190
|
+
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
191
|
+
);
|
|
192
|
+
return Buffer.from(derivedBits);
|
|
150
193
|
}
|
|
151
|
-
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
@@ -28,18 +28,21 @@ exports.NACK_REASONS = {
|
|
|
28
28
|
* @note this will only parse the message, not decrypt it
|
|
29
29
|
*/
|
|
30
30
|
function decodeMessageNode(stanza, meId, meLid) {
|
|
31
|
-
var _a, _b, _c, _d;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
32
32
|
let msgType;
|
|
33
33
|
let chatId;
|
|
34
34
|
let author;
|
|
35
35
|
const msgId = stanza.attrs.id;
|
|
36
36
|
const from = stanza.attrs.from;
|
|
37
|
+
const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
|
|
38
|
+
const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
|
|
37
39
|
const participant = stanza.attrs.participant;
|
|
40
|
+
const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
|
|
38
41
|
const recipient = stanza.attrs.recipient;
|
|
39
42
|
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
40
43
|
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
41
44
|
if ((0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
|
|
42
|
-
if (recipient && !(0, WABinary_1.
|
|
45
|
+
if (recipient && !(0, WABinary_1.isJidMetaAi)(recipient)) {
|
|
43
46
|
if (!isMe(from) && !isMeLid(from)) {
|
|
44
47
|
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
45
48
|
}
|
|
@@ -81,15 +84,17 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
81
84
|
else {
|
|
82
85
|
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
83
86
|
}
|
|
84
|
-
const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((
|
|
85
|
-
const pushname = (
|
|
87
|
+
const fromMe = (0, WABinary_1.isJidNewsletter)(from) ? !!((_d = stanza.attrs) === null || _d === void 0 ? void 0 : _d.is_sender) || false : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
88
|
+
const pushname = (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.notify;
|
|
86
89
|
const key = {
|
|
87
90
|
remoteJid: chatId,
|
|
88
91
|
fromMe,
|
|
89
92
|
id: msgId,
|
|
93
|
+
senderPn,
|
|
94
|
+
senderLid,
|
|
90
95
|
participant,
|
|
91
|
-
|
|
92
|
-
server_id: (
|
|
96
|
+
participantLid,
|
|
97
|
+
'server_id': (_f = stanza.attrs) === null || _f === void 0 ? void 0 : _f.server_id
|
|
93
98
|
};
|
|
94
99
|
const fullMessage = {
|
|
95
100
|
key,
|
|
@@ -98,7 +103,7 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
98
103
|
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
|
99
104
|
};
|
|
100
105
|
if (msgType === 'newsletter') {
|
|
101
|
-
fullMessage.newsletterServerId = +((
|
|
106
|
+
fullMessage.newsletterServerId = +((_g = stanza.attrs) === null || _g === void 0 ? void 0 : _g.server_id);
|
|
102
107
|
}
|
|
103
108
|
if (key.fromMe) {
|
|
104
109
|
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
|
@@ -125,6 +130,9 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
125
130
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
126
131
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
127
132
|
}
|
|
133
|
+
if (tag === 'unavailable' && attrs.type === 'view_once') {
|
|
134
|
+
fullMessage.key.isViewOnce = true;
|
|
135
|
+
}
|
|
128
136
|
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
129
137
|
continue;
|
|
130
138
|
}
|
|
@@ -27,14 +27,14 @@ const BUFFERABLE_EVENT_SET = new Set(BUFFERABLE_EVENT);
|
|
|
27
27
|
/**
|
|
28
28
|
* The event buffer logically consolidates different events into a single event
|
|
29
29
|
* making the data processing more efficient.
|
|
30
|
-
* @param ev the
|
|
30
|
+
* @param ev the wileys event emitter
|
|
31
31
|
*/
|
|
32
32
|
const makeEventBuffer = (logger) => {
|
|
33
33
|
const ev = new events_1.default();
|
|
34
34
|
const historyCache = new Set();
|
|
35
35
|
let data = makeBufferData();
|
|
36
36
|
let buffersInProgress = 0;
|
|
37
|
-
// take the generic event and fire it as a
|
|
37
|
+
// take the generic event and fire it as a wileys event
|
|
38
38
|
ev.on('event', (map) => {
|
|
39
39
|
for (const event in map) {
|
|
40
40
|
ev.emit(event, map[event]);
|
|
@@ -502,12 +502,10 @@ function consolidateEvents(data) {
|
|
|
502
502
|
return map;
|
|
503
503
|
}
|
|
504
504
|
function concatChats(a, b) {
|
|
505
|
-
if (b.unreadCount === null
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
b.unreadCount = undefined;
|
|
510
|
-
}
|
|
505
|
+
if (b.unreadCount === null && // neutralize unread counter
|
|
506
|
+
a.unreadCount < 0) {
|
|
507
|
+
a.unreadCount = undefined;
|
|
508
|
+
b.unreadCount = undefined;
|
|
511
509
|
}
|
|
512
510
|
if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
|
|
513
511
|
b = { ...b };
|
package/lib/Utils/generics.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
39
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestWileysVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeNewsletterMessage = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
40
40
|
exports.promiseTimeout = promiseTimeout;
|
|
41
41
|
exports.bindWaitForEvent = bindWaitForEvent;
|
|
42
42
|
exports.trimUndefined = trimUndefined;
|
|
@@ -46,7 +46,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
46
46
|
const crypto_1 = require("crypto");
|
|
47
47
|
const os_1 = require("os");
|
|
48
48
|
const WAProto_1 = require("../../WAProto");
|
|
49
|
-
const
|
|
49
|
+
const wileys_version_json_1 = require("../Defaults/wileys-version.json");
|
|
50
50
|
const Types_1 = require("../Types");
|
|
51
51
|
const WABinary_1 = require("../WABinary");
|
|
52
52
|
const COMPANION_PLATFORM_MAP = {
|
|
@@ -213,11 +213,11 @@ const generateMessageIDV2 = (userId) => {
|
|
|
213
213
|
const random = (0, crypto_1.randomBytes)(16);
|
|
214
214
|
random.copy(data, 28);
|
|
215
215
|
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
216
|
-
return '
|
|
216
|
+
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
217
217
|
};
|
|
218
218
|
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
219
219
|
// generate a random ID to attach to a message
|
|
220
|
-
const generateMessageID = () => '
|
|
220
|
+
const generateMessageID = () => '3EB0' + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase();
|
|
221
221
|
exports.generateMessageID = generateMessageID;
|
|
222
222
|
function bindWaitForEvent(ev, event) {
|
|
223
223
|
return async (check, timeoutMs) => {
|
|
@@ -258,31 +258,51 @@ const printQRIfNecessaryListener = (ev, logger) => {
|
|
|
258
258
|
});
|
|
259
259
|
};
|
|
260
260
|
exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
* Use to ensure your WA connection is always on the latest version
|
|
264
|
-
*/
|
|
265
|
-
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
266
|
-
const URL = 'https://raw.githubusercontent.com/ruhend2001/apk-dl/refs/heads/master/version.json';
|
|
261
|
+
|
|
262
|
+
const fetchLatestWileysVersion = async (options = {}) => {
|
|
267
263
|
try {
|
|
268
|
-
const
|
|
264
|
+
const { data } = await axios_1.default.get('https://registry.npmjs.org/wileys', {
|
|
269
265
|
...options,
|
|
270
266
|
responseType: 'json'
|
|
271
267
|
});
|
|
268
|
+
const versionStr = data.version;
|
|
269
|
+
const [major, minor, patch] = versionStr.split('.').map(Number);
|
|
272
270
|
return {
|
|
273
|
-
version:
|
|
271
|
+
version: [major, minor, patch],
|
|
274
272
|
isLatest: true
|
|
275
273
|
};
|
|
274
|
+
} catch (error) {
|
|
275
|
+
return {
|
|
276
|
+
version: wileys_version_json_1.version,
|
|
277
|
+
isLatest: false,
|
|
278
|
+
error
|
|
279
|
+
};
|
|
276
280
|
}
|
|
277
|
-
|
|
281
|
+
};
|
|
282
|
+
exports.fetchLatestWileysVersion = fetchLatestWileysVersion;
|
|
283
|
+
|
|
284
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
285
|
+
try {
|
|
286
|
+
const { data } = await axios_1.default.get('https://registry.npmjs.org/wileys', {
|
|
287
|
+
...options,
|
|
288
|
+
responseType: 'json'
|
|
289
|
+
});
|
|
290
|
+
const versionStr = data.version;
|
|
291
|
+
const [major, minor, patch] = versionStr.split('.').map(Number);
|
|
278
292
|
return {
|
|
279
|
-
version:
|
|
293
|
+
version: [major, minor, patch],
|
|
294
|
+
isLatest: true
|
|
295
|
+
};
|
|
296
|
+
} catch (error) {
|
|
297
|
+
return {
|
|
298
|
+
version: wileys_version_json_1.version,
|
|
280
299
|
isLatest: false,
|
|
281
300
|
error
|
|
282
301
|
};
|
|
283
302
|
}
|
|
284
303
|
};
|
|
285
304
|
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
305
|
+
|
|
286
306
|
/**
|
|
287
307
|
* A utility that fetches the latest web version of whatsapp.
|
|
288
308
|
* Use to ensure your WA connection is always on the latest version
|
|
@@ -297,7 +317,7 @@ const fetchLatestWaWebVersion = async (options) => {
|
|
|
297
317
|
const match = data.match(regex);
|
|
298
318
|
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
299
319
|
return {
|
|
300
|
-
version:
|
|
320
|
+
version: wileys_version_json_1.version,
|
|
301
321
|
isLatest: false,
|
|
302
322
|
error: {
|
|
303
323
|
message: 'Could not find client revision in the fetched content'
|
|
@@ -312,7 +332,7 @@ const fetchLatestWaWebVersion = async (options) => {
|
|
|
312
332
|
}
|
|
313
333
|
catch (error) {
|
|
314
334
|
return {
|
|
315
|
-
version:
|
|
335
|
+
version: wileys_version_json_1.version,
|
|
316
336
|
isLatest: false,
|
|
317
337
|
error
|
|
318
338
|
};
|
|
@@ -443,3 +463,5 @@ function bytesToCrockford(buffer) {
|
|
|
443
463
|
}
|
|
444
464
|
return crockford.join('');
|
|
445
465
|
}
|
|
466
|
+
exports.trimUndefined = trimUndefined;
|
|
467
|
+
exports.bytesToCrockford = bytesToCrockford;
|
package/lib/Utils/history.js
CHANGED
|
@@ -34,7 +34,7 @@ const processHistoryMessage = (item) => {
|
|
|
34
34
|
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
35
|
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
36
36
|
for (const chat of item.conversations) {
|
|
37
|
-
contacts.push({ id: chat.id, name: chat.name || undefined });
|
|
37
|
+
contacts.push({ id: chat.id, name: chat.name || undefined, lid: chat.lidJid || undefined, jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : chat.pnJid });
|
|
38
38
|
const msgs = chat.messages || [];
|
|
39
39
|
delete chat.messages;
|
|
40
40
|
delete chat.archived;
|
package/lib/Utils/index.js
CHANGED
|
@@ -26,8 +26,10 @@ __exportStar(require("./history"), exports);
|
|
|
26
26
|
__exportStar(require("./chat-utils"), exports);
|
|
27
27
|
__exportStar(require("./lt-hash"), exports);
|
|
28
28
|
__exportStar(require("./auth-utils"), exports);
|
|
29
|
-
__exportStar(require("./
|
|
29
|
+
__exportStar(require("./wileys-event-stream"), exports);
|
|
30
30
|
__exportStar(require("./use-multi-file-auth-state"), exports);
|
|
31
31
|
__exportStar(require("./link-preview"), exports);
|
|
32
32
|
__exportStar(require("./event-buffer"), exports);
|
|
33
33
|
__exportStar(require("./process-message"), exports);
|
|
34
|
+
__exportStar(require("./message-retry-manager"), exports);
|
|
35
|
+
__exportStar(require("./browser-utils"), exports);
|