kage-baileys 25.0.5 → 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.
@@ -5,10 +5,11 @@ const Defaults_1 = require("../Defaults");
5
5
  const business_1 = require("./communities");
6
6
 
7
7
  /**
8
- * Clean makeWASocket – fixed:
9
- * - Removed corrupted __kageModule wrappers
10
- * - Fixed "Cannot add property MessageBuilder, object is not extensible"
11
- * (bound functions are not extensible; we no longer try to attach .MessageBuilder to them)
8
+ * makeWASocket – versión 25.0.6-fixed
9
+ * - Sin wrappers __kageModule corruptos
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)
12
13
  */
13
14
  const makeWASocket = (config = {}) => {
14
15
  try {
@@ -22,51 +23,104 @@ const makeWASocket = (config = {}) => {
22
23
  ...config
23
24
  };
24
25
 
25
- // Default history sync behaviour if not provided
26
26
  if (config.shouldSyncHistoryMessage === undefined) {
27
27
  finalConfig.shouldSyncHistoryMessage = () => !!finalConfig.syncFullHistory;
28
28
  }
29
29
 
30
- const socket = (0, business_1.makeCommunitiesSocket)(finalConfig);
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 (_) {}
31
47
 
32
- // Install Kage extensions safely
48
+ let socket;
33
49
  try {
34
- require('../Extensions').installExtensions(socket, finalConfig);
35
- } catch (e) {
36
- // non-fatal
50
+ socket = (0, business_1.makeCommunitiesSocket)(finalConfig);
51
+ } finally {
52
+ if (definePatched) {
53
+ Object.defineProperty = origDefineProperty;
54
+ }
37
55
  }
38
56
 
39
- try {
40
- require('../Utils/interactive-compat').installKageInteractiveTools(socket);
41
- } catch (_) {}
57
+ try { require('../Extensions').installExtensions(socket, finalConfig); } catch (_) {}
58
+ try { require('../Utils/interactive-compat').installKageInteractiveTools(socket); } catch (_) {}
59
+ try { require('../Utils/profile-tools').installProfileTools(socket, config); } catch (_) {}
42
60
 
61
+ // ---- MessageBuilder (seguro) ----
62
+ // Nunca hacemos: boundFn.MessageBuilder = ... (bound functions no son extensibles)
43
63
  try {
44
- require('../Utils/profile-tools').installProfileTools(socket, config);
45
- } catch (_) {}
64
+ const { MessageBuilder } = require('../Utils/message-builder');
65
+ let moddedFn = null;
66
+ try {
67
+ const mod = require('../Modded/message_builder');
68
+ moddedFn = typeof mod === 'function' ? mod : (mod && mod.default);
69
+ } catch (_) {}
70
+
71
+ // Función usable: messageBuilder(...)
72
+ const builderFn = function (...args) {
73
+ if (typeof moddedFn === 'function') {
74
+ try { return moddedFn.apply(socket, args); } catch (_) {}
75
+ }
76
+ return new MessageBuilder(socket, ...args);
77
+ };
78
+
79
+ // Objeto extensible que también es invocable
80
+ // Usamos Object.create(Function.prototype) + assign para máxima compatibilidad
81
+ const mb = Object.assign(builderFn, {
82
+ MessageBuilder, // clase disponible sin romper extensibility
83
+ create: () => new MessageBuilder(socket),
84
+ VERSION: '4.8-fixed'
85
+ });
86
+
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
+ }
46
100
 
47
- // MessageBuilder helpers – do NOT try to add properties to a bound function
48
- try {
49
- const modded = require('../Modded/message_builder');
50
- // Prefer a plain function reference; if it's already bound, just assign it
51
- socket.messageBuilder = typeof modded === 'function' ? modded.bind(socket) : modded;
52
- } catch (_) {
53
- // fallback
54
101
  try {
55
- const { MessageBuilder } = require('../Utils/message-builder');
56
- socket.messageBuilder = function (...args) {
57
- return new MessageBuilder(socket, ...args);
58
- };
102
+ socket.createMessageBuilder = () => new MessageBuilder(socket);
59
103
  } catch (_) {}
60
- }
61
104
 
62
- try {
63
- const { MessageBuilder } = require('../Utils/message-builder');
64
- socket.createMessageBuilder = () => new MessageBuilder(socket);
65
- // Expose the class itself on the socket (safe)
66
- socket.MessageBuilder = MessageBuilder;
67
- } catch (_) {}
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
+ }
68
123
 
69
- // Final Kage tools
70
124
  try {
71
125
  return require('../Utils/automation-tools').installKageTools(socket, config.kageTools || {});
72
126
  } catch (_) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kage-baileys",
3
- "version": "25.0.5",
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_CERTI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uKJAQsx1FxCHyDafq2GCk9t0AN
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
- }