kage-baileys 25.0.6 → 25.0.7
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/Socket/index.js
CHANGED
|
@@ -5,9 +5,11 @@ const Defaults_1 = require("../Defaults");
|
|
|
5
5
|
const business_1 = require("./communities");
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* makeWASocket – versión 25.0.
|
|
8
|
+
* makeWASocket – versión 25.0.6-fixed
|
|
9
9
|
* - Sin wrappers __kageModule corruptos
|
|
10
10
|
* - MessageBuilder sin tocar objetos no extensibles (bound functions)
|
|
11
|
+
* - Protección reforzada contra "Cannot add property MessageBuilder, object is not extensible"
|
|
12
|
+
* (inspirado en el parche de Chiaki baileys-compat)
|
|
11
13
|
*/
|
|
12
14
|
const makeWASocket = (config = {}) => {
|
|
13
15
|
try {
|
|
@@ -25,7 +27,32 @@ const makeWASocket = (config = {}) => {
|
|
|
25
27
|
finalConfig.shouldSyncHistoryMessage = () => !!finalConfig.syncFullHistory;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
// Protección temporal contra asignaciones a MessageBuilder en funciones no extensibles
|
|
31
|
+
const origDefineProperty = Object.defineProperty;
|
|
32
|
+
let definePatched = false;
|
|
33
|
+
try {
|
|
34
|
+
Object.defineProperty = function (obj, prop, desc) {
|
|
35
|
+
try {
|
|
36
|
+
if (prop === 'MessageBuilder' && typeof obj === 'function' && !Object.isExtensible(obj)) {
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
return origDefineProperty(obj, prop, desc);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (prop === 'MessageBuilder') return obj;
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
definePatched = true;
|
|
46
|
+
} catch (_) {}
|
|
47
|
+
|
|
48
|
+
let socket;
|
|
49
|
+
try {
|
|
50
|
+
socket = (0, business_1.makeCommunitiesSocket)(finalConfig);
|
|
51
|
+
} finally {
|
|
52
|
+
if (definePatched) {
|
|
53
|
+
Object.defineProperty = origDefineProperty;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
29
56
|
|
|
30
57
|
try { require('../Extensions').installExtensions(socket, finalConfig); } catch (_) {}
|
|
31
58
|
try { require('../Utils/interactive-compat').installKageInteractiveTools(socket); } catch (_) {}
|
|
@@ -50,15 +77,49 @@ const makeWASocket = (config = {}) => {
|
|
|
50
77
|
};
|
|
51
78
|
|
|
52
79
|
// Objeto extensible que también es invocable
|
|
80
|
+
// Usamos Object.create(Function.prototype) + assign para máxima compatibilidad
|
|
53
81
|
const mb = Object.assign(builderFn, {
|
|
54
82
|
MessageBuilder, // clase disponible sin romper extensibility
|
|
55
|
-
create: () => new MessageBuilder(socket)
|
|
83
|
+
create: () => new MessageBuilder(socket),
|
|
84
|
+
VERSION: '4.8-fixed'
|
|
56
85
|
});
|
|
57
86
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
87
|
+
// Asignación segura
|
|
88
|
+
try {
|
|
89
|
+
socket.messageBuilder = mb;
|
|
90
|
+
} catch (_) {
|
|
91
|
+
try {
|
|
92
|
+
Object.defineProperty(socket, 'messageBuilder', {
|
|
93
|
+
value: mb,
|
|
94
|
+
writable: true,
|
|
95
|
+
configurable: true,
|
|
96
|
+
enumerable: true
|
|
97
|
+
});
|
|
98
|
+
} catch (_) {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
socket.createMessageBuilder = () => new MessageBuilder(socket);
|
|
103
|
+
} catch (_) {}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
socket.MessageBuilder = MessageBuilder;
|
|
107
|
+
} catch (_) {
|
|
108
|
+
try {
|
|
109
|
+
Object.defineProperty(socket, 'MessageBuilder', {
|
|
110
|
+
value: MessageBuilder,
|
|
111
|
+
writable: true,
|
|
112
|
+
configurable: true,
|
|
113
|
+
enumerable: true
|
|
114
|
+
});
|
|
115
|
+
} catch (_) {}
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
// Silenciar errores de MessageBuilder para no romper el socket
|
|
119
|
+
if (config && config.logger) {
|
|
120
|
+
try { config.logger.warn?.({ err: e }, 'MessageBuilder attach failed (non-fatal)'); } catch (_) {}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
62
123
|
|
|
63
124
|
try {
|
|
64
125
|
return require('../Utils/automation-tools').installKageTools(socket, config.kageTools || {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kage-baileys",
|
|
3
|
-
"version": "25.0.
|
|
3
|
+
"version": "25.0.7",
|
|
4
4
|
"description": "Kage Baileys completo — API WhatsApp Web con MessageBuilder extendido, Native Flows, review_and_pay, módulos proto, miniaturas base64/Buffer, rich UI, VoIP, canales, comunidades y más.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kage-baileys",
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { X509Certificate, verify as cryptoVerify } from 'crypto'
|
|
2
|
-
|
|
3
|
-
export const BOT_SIGNATURE_VERSION = '1'
|
|
4
|
-
export const BOT_SIGNATURE_USE_CASE_WA_BOT_MSG = 1
|
|
5
|
-
export const BOT_SIGNATURE_ROOT_VERSION = '2025-10'
|
|
6
|
-
|
|
7
|
-
export const BOT_SIGNATURE_ROOT_CERTIFICATE = `-----BEGIN CERTIFICATE-----
|
|
8
|
-
MIIC7TCCApOgAwIBAgIUAtu5QuxmVhfGT8LPkjfm40mSl0AwCgYIKoZIzj0EAwIw
|
|
9
|
-
dzEgMB4GA1UEAwwXTWV0YSBXQSBGZWF0dXJlIFJvb3QgQ0ExCzAJBgNVBAYTAlVT
|
|
10
|
-
MRMwEQYDVQQIDApDYWxpZm9ybmlhMRMwEQYDVQQHDApNZW5sbyBQYXJrMRwwGgYD
|
|
11
|
-
VQQKDBNNZXRhIFBsYXRmb3JtcyBJbmMuMCAXDTI1MDkwNDE3MzEyNFoYDzIwNjUw
|
|
12
|
-
OTA0MTczMTI0WjB3MSAwHgYDVQQDDBdNZXRhIFdBIEZlYXR1cmUgUm9vdCBDQTEL
|
|
13
|
-
MAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExEzARBgNVBAcMCk1lbmxv
|
|
14
|
-
IFBhcmsxHDAaBgNVBAoME01ldGEgUGxhdGZvcm1zIEluYy4wWTATBgcqhkjOPQIB
|
|
15
|
-
BggqhkjOPQMBBwNCAAT60blw90ebreMkw8+Wpcs0ETAkr1VQjoZoyi7PSSQbsoiP
|
|
16
|
-
qYRnzfRrR+xiahaXbYU83qXiTHjVUiOU9wDxI83qo4H6MIH3MA8GA1UdEwEB/wQF
|
|
17
|
-
MAMBAf8wHQYDVR0OBBYEFNO7KMTVSYUxkL6VS3LyWJw7m76zMIG0BgNVHSMEgaww
|
|
18
|
-
gamAFNO7KMTVSYUxkL6VS3LyWJw7m76zoXukeTB3MSAwHgYDVQQDDBdNZXRhIFdB
|
|
19
|
-
IEZlYXR1cmUgUm9vdCBDQTELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3Ju
|
|
20
|
-
aWExEzARBgNVBAcMCk1lbmxvIFBhcmsxHDAaBgNVBAoME01ldGEgUGxhdGZvcm1z
|
|
21
|
-
IEluYy6CFALbuULsZlYXxk/Cz5I35uNJkpdAMA4GA1UdDwEB/wQEAwIBhjAKBggq
|
|
22
|
-
hkjOPQQDAgNIADBFAiAINhjk9DbP416vx/WjqdUfexgic08aQsxnpDDsNE5M0gIh
|
|
23
|
-
ANorq7KwCQVMtS2or5uKJAQsx1FxCHyDafq2GCk9t0AN
|
|
24
|
-
-----END CERTIFICATE-----`
|
|
25
|
-
|
|
26
|
-
let rootCertificate = null
|
|
27
|
-
|
|
28
|
-
export const loadBotSignatureRoot = () => {
|
|
29
|
-
if (!rootCertificate) {
|
|
30
|
-
rootCertificate = new X509Certificate(BOT_SIGNATURE_ROOT_CERTIFICATE)
|
|
31
|
-
}
|
|
32
|
-
return rootCertificate
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const constructSignaturePayload = ({ botFbid, messageDigest, version = BOT_SIGNATURE_VERSION }) =>
|
|
36
|
-
Buffer.concat([Buffer.from(version, 'utf8'), Buffer.from(String(botFbid), 'utf8'), Buffer.from(messageDigest)])
|
|
37
|
-
|
|
38
|
-
export const isParsableCertificateChain = (chain) => {
|
|
39
|
-
if (!Array.isArray(chain) || !chain.length) {
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
for (const entry of chain) {
|
|
44
|
-
new X509Certificate(Buffer.from(entry))
|
|
45
|
-
}
|
|
46
|
-
return true
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const failed = reason => ({ status: 'failed', reason })
|
|
54
|
-
|
|
55
|
-
const validAt = (certificate, at) => {
|
|
56
|
-
const from = Date.parse(certificate.validFrom)
|
|
57
|
-
const to = Date.parse(certificate.validTo)
|
|
58
|
-
return Number.isFinite(from) && Number.isFinite(to) && at >= from && at <= to
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const verifyBotSignature = ({ botJid, unifiedResponseBytes, proof, at = Date.now(), root = loadBotSignatureRoot() } = {}) => {
|
|
62
|
-
if (!proof) {
|
|
63
|
-
return failed('no WA_BOT_MSG proof')
|
|
64
|
-
}
|
|
65
|
-
if (Number(proof.version) !== 1) {
|
|
66
|
-
return failed(`unsupported signature version ${proof.version}`)
|
|
67
|
-
}
|
|
68
|
-
if (!proof.signature?.length) {
|
|
69
|
-
return failed('proof carries no signature')
|
|
70
|
-
}
|
|
71
|
-
if (!proof.certificateChain?.length) {
|
|
72
|
-
return failed('empty certificate chain')
|
|
73
|
-
}
|
|
74
|
-
if (!unifiedResponseBytes?.length) {
|
|
75
|
-
return failed('no unified response bytes to verify')
|
|
76
|
-
}
|
|
77
|
-
const botFbid = String(botJid ?? '').split('@')[0]
|
|
78
|
-
if (!botFbid) {
|
|
79
|
-
return failed('no bot jid, the fbid is part of the signed payload')
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let chain
|
|
83
|
-
try {
|
|
84
|
-
chain = proof.certificateChain.map(entry => new X509Certificate(Buffer.from(entry)))
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
return failed(`certificate did not parse: ${error.message}`)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const [leaf] = chain
|
|
91
|
-
if (!validAt(leaf, at)) {
|
|
92
|
-
return failed('leaf certificate is outside its validity window')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const full = [...chain, root]
|
|
96
|
-
for (let index = 0; index < full.length - 1; index += 1) {
|
|
97
|
-
const issuer = full[index + 1]
|
|
98
|
-
if (!validAt(issuer, at)) {
|
|
99
|
-
return failed(`issuer at position ${index + 1} is outside its validity window`)
|
|
100
|
-
}
|
|
101
|
-
let ok = false
|
|
102
|
-
try {
|
|
103
|
-
ok = full[index].verify(issuer.publicKey)
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
return failed(`chain verification threw at position ${index}: ${error.message}`)
|
|
107
|
-
}
|
|
108
|
-
if (!ok) {
|
|
109
|
-
return failed(`chain broken at position ${index}`)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const payload = constructSignaturePayload({ botFbid, messageDigest: unifiedResponseBytes })
|
|
114
|
-
let ok = false
|
|
115
|
-
try {
|
|
116
|
-
ok = cryptoVerify(null, payload, leaf.publicKey, Buffer.from(proof.signature))
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
return failed(`signature verification threw: ${error.message}`)
|
|
120
|
-
}
|
|
121
|
-
return ok ? { status: 'passed' } : failed('signature does not match the unified response bytes')
|
|
122
|
-
}
|