kage-baileys 3.0.6 → 3.2.4
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/Example/connection.cjs +4 -0
- package/README.MD +4726 -48
- package/README.md +5941 -0
- package/WAProto/WAProto.proto +3395 -415
- package/WAProto/compat.cjs +12 -0
- package/WAProto/index.d.ts +47104 -19888
- package/WAProto/index.js +131979 -57361
- package/lib/Addon/http-error.js +43 -0
- package/lib/Addon/index.js +32 -0
- package/lib/Addon/keyed-db.js +250 -0
- package/lib/Addon/link-preview.js +82 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +110 -0
- package/lib/Defaults/constants.js +156 -0
- package/lib/Defaults/history.js +46 -0
- package/lib/Defaults/index.js +230 -0
- package/lib/Defaults/media.js +104 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +44 -0
- package/lib/Extensions/business-advanced.js +382 -0
- package/lib/Extensions/business.js +159 -0
- package/lib/Extensions/chats-advanced.js +1106 -0
- package/lib/Extensions/chats.js +349 -0
- package/lib/Extensions/communities-advanced.js +430 -0
- package/lib/Extensions/community.js +94 -0
- package/lib/Extensions/groups-advanced.js +343 -0
- package/lib/Extensions/index.js +30 -0
- package/lib/Extensions/messages-recv-advanced.js +1690 -0
- package/lib/Extensions/messages-send-advanced.js +622 -0
- package/lib/Extensions/messages-send.js +1380 -0
- package/lib/Extensions/newsletter-advanced.js +228 -0
- package/lib/Extensions/newsletter.js +72 -0
- package/lib/Extensions/socket.js +389 -0
- package/lib/Modded/message_builder.js +2084 -4
- package/lib/Signal/Group/ciphertext-message.js +54 -0
- package/lib/Signal/Group/group-session-builder.js +124 -0
- package/lib/Signal/Group/group_cipher.js +216 -0
- package/lib/Signal/Group/index.js +124 -0
- package/lib/Signal/Group/keyhelper.js +108 -0
- package/lib/Signal/Group/sender-chain-key.js +83 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
- package/lib/Signal/Group/sender-key-message.js +166 -0
- package/lib/Signal/Group/sender-key-name.js +130 -0
- package/lib/Signal/Group/sender-key-record.js +113 -0
- package/lib/Signal/Group/sender-key-state.js +208 -0
- package/lib/Signal/Group/sender-message-key.js +82 -0
- package/lib/Signal/libsignal.js +935 -0
- package/lib/Signal/lid-mapping.js +545 -1
- package/lib/Socket/Client/index.js +60 -0
- package/lib/Socket/Client/types.js +51 -0
- package/lib/Socket/Client/websocket.js +152 -0
- package/lib/Socket/business.js +831 -0
- package/lib/Socket/chats.js +2535 -49
- package/lib/Socket/communities.js +450 -1
- package/lib/Socket/community.js +1022 -0
- package/lib/Socket/dugong.js +1 -1
- package/lib/Socket/groups.js +747 -0
- package/lib/Socket/index.js +60 -2
- package/lib/Socket/messages-recv.js +3450 -5
- package/lib/Socket/messages-send.js +3123 -0
- package/lib/Socket/mex.js +126 -1
- package/lib/Socket/newsletter.js +465 -0
- package/lib/Socket/socket.js +2217 -1
- package/lib/Store/index.js +79 -0
- package/lib/Store/make-cache-manager-store.js +186 -0
- package/lib/Store/make-in-memory-store.js +878 -0
- package/lib/Store/make-ordered-dictionary.js +187 -0
- package/lib/Store/object-repository.js +78 -0
- package/lib/Types/Auth.js +25 -0
- package/lib/Types/Bussines.js +25 -1
- package/lib/Types/Call.js +25 -0
- package/lib/Types/Chat.js +39 -0
- package/lib/Types/Contact.js +25 -0
- package/lib/Types/Events.js +25 -0
- package/lib/Types/GroupMetadata.js +25 -0
- package/lib/Types/Label.js +76 -0
- package/lib/Types/LabelAssociation.js +40 -0
- package/lib/Types/Message.js +57 -0
- package/lib/Types/Mex.js +56 -1
- package/lib/Types/MexUpdates.js +46 -0
- package/lib/Types/Newsletter.js +56 -0
- package/lib/Types/Product.js +25 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.js +25 -0
- package/lib/Types/Socket.js +25 -0
- package/lib/Types/State.js +92 -0
- package/lib/Types/USync.js +25 -0
- package/lib/Types/index.js +133 -0
- package/lib/Utils/auth-utils.js +703 -0
- package/lib/Utils/automation-tools.js +51 -16
- package/lib/Utils/baileys-event-stream.js +146 -0
- package/lib/Utils/browser-utils.js +95 -0
- package/lib/Utils/business.js +525 -0
- package/lib/Utils/chat-utils.js +1861 -0
- package/lib/Utils/companion-reg-client-utils.js +55 -1
- package/lib/Utils/crypto.js +355 -0
- package/lib/Utils/decode-wa-message.js +709 -0
- package/lib/Utils/event-buffer.js +1323 -8
- package/lib/Utils/generics.js +945 -1
- package/lib/Utils/history.js +266 -0
- package/lib/Utils/identity-change-handler.js +62 -1
- package/lib/Utils/index.js +114 -0
- package/lib/Utils/link-preview.js +179 -0
- package/lib/Utils/logger.js +42 -0
- package/lib/Utils/lt-hash.js +73 -0
- package/lib/Utils/make-mutex.js +104 -0
- package/lib/Utils/message-inspector.js +110 -0
- package/lib/Utils/message-retry-manager.js +507 -2
- package/lib/Utils/messages-media.js +1931 -1
- package/lib/Utils/messages.js +3748 -0
- package/lib/Utils/noise-handler.js +423 -0
- package/lib/Utils/offline-node-processor.js +53 -1
- package/lib/Utils/pre-key-manager.js +255 -1
- package/lib/Utils/process-message.js +1592 -0
- package/lib/Utils/reporting-utils.js +272 -1
- package/lib/Utils/rich-message-utils.js +377 -0
- package/lib/Utils/rich-messages.js +1 -1
- package/lib/Utils/signal.js +437 -0
- package/lib/Utils/stanza-ack.js +51 -1
- package/lib/Utils/status-refresh.js +37 -0
- package/lib/Utils/status-tools.js +4 -2
- package/lib/Utils/sync-action-utils.js +63 -1
- package/lib/Utils/tc-token-utils.js +185 -1
- package/lib/Utils/terminal-banner.js +31 -0
- package/lib/Utils/use-multi-file-auth-state.js +271 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +142 -0
- package/lib/Utils/validate-connection.js +497 -1
- package/lib/Utils/view-once-compat.js +13 -5
- package/lib/VoIP/audio-feeder.js +150 -0
- package/lib/VoIP/index.js +289 -0
- package/lib/VoIP/relay-transport.js +608 -0
- package/lib/VoIP/signaling.js +583 -0
- package/lib/VoIP/types.js +30 -0
- package/lib/VoIP/wasm-engine.js +1261 -2
- package/lib/VoIP/worker-bootstrap.js +1090 -2
- package/lib/WABinary/constants.js +2805 -0
- package/lib/WABinary/decode.js +649 -2
- package/lib/WABinary/encode.js +564 -2
- package/lib/WABinary/generic-utils.js +401 -0
- package/lib/WABinary/index.js +82 -0
- package/lib/WABinary/jid-utils.js +290 -0
- package/lib/WABinary/types.js +25 -0
- package/lib/WAM/BinaryInfo.js +50 -0
- package/lib/WAM/constants.js +45747 -0
- package/lib/WAM/encode.js +393 -0
- package/lib/WAM/index.js +78 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
- package/lib/WAUSync/Protocols/index.js +83 -0
- package/lib/WAUSync/USyncQuery.js +241 -2
- package/lib/WAUSync/USyncUser.js +86 -0
- package/lib/WAUSync/index.js +78 -0
- package/lib/assets/wasm/loader.js +1875 -1
- package/lib/assets/wasm/worker-modules.js +11047 -1
- package/lib/index.d.ts +126 -0
- package/lib/index.js +53 -21
- package/lib/index.mjs +437 -0
- package/licenses/upstream-MIT.txt +22 -0
- package/maintenance/api-coverage.json +1642 -0
- package/maintenance/archivos-sha256.json +207 -0
- package/maintenance/consumer-validation.log +3 -0
- package/maintenance/dependency-audit.json +4 -4
- package/maintenance/extension-inventory.json +57 -0
- package/maintenance/protocol-update.json +1101 -0
- package/maintenance/protocol-wire-audit.json +4 -0
- package/maintenance/reference-socket-surface.json +209 -0
- package/maintenance/resumen-validacion.json +50 -0
- package/maintenance/validation.log +2725 -0
- package/maintenance/verification.json +566 -0
- package/package.json +107 -9
- package/scripts/check-imports.cjs +10 -0
- package/scripts/check-package.cjs +40 -0
- package/scripts/check-syntax.cjs +1 -1
- package/scripts/generate-protobuf.cjs +6 -1
- package/scripts/generate-public-types.cjs +9 -0
- package/scripts/kage-base64-fix.cjs +45 -0
- package/scripts/maintenance.cjs +10 -0
- package/test/advanced.test.cjs +24 -0
- package/test/base64-fix.test.cjs +49 -0
- package/test/maintenance.test.cjs +1 -1
- package/test/npm-publication.test.cjs +141 -0
- package/test/recepcion-reparada.test.cjs +98 -0
- package/test/resilience-binary.test.cjs +69 -0
- package/test/resilience-transport.test.cjs +34 -0
- package/test/types.test.ts +5 -0
- package/test/upgrade.test.cjs +104 -0
- package/tsconfig.json +20 -0
- package/WAProto/p.html +0 -1
- package/lib/KageExtra/Modded/message_builder.js +0 -2330
- package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
- package/lib/KageExtra/VoIP/index.js +0 -282
- package/lib/KageExtra/VoIP/relay-transport.js +0 -559
- package/lib/KageExtra/VoIP/signaling.js +0 -603
- package/lib/KageExtra/VoIP/types.js +0 -17
- package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
- package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
- package/lib/KageExtra/assets/wasm/loader.js +0 -5
- package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
- package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
- package/lib/KageExtra/index.js +0 -3
- package/lib/KageExtra/package.json +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- package/maintenance/revision-full-check.txt +0 -1097
- package/maintenance/revision-library-tests.tap +0 -1088
- package/maintenance/revision-protobuf.txt +0 -5
- package/maintenance/revision-syntax.txt +0 -5
- package/maintenance/schema-coverage.json +0 -23
- package/maintenance/schema-merge.json +0 -30
- package/maintenance/validation-node20.txt +0 -191
- package/maintenance/validation-node22.txt +0 -237
package/lib/WABinary/decode.js
CHANGED
|
@@ -38,10 +38,14 @@ const util_1 = require("util");
|
|
|
38
38
|
const zlib_1 = require("zlib");
|
|
39
39
|
const constants = __importStar(require("./constants"));
|
|
40
40
|
const jid_utils_1 = require("./jid-utils");
|
|
41
|
+
const MAX_BINARY_BYTES = 32 * 1024 * 1024;
|
|
42
|
+
const MAX_BINARY_DEPTH = 64;
|
|
43
|
+
const MAX_BINARY_NODES = 100000;
|
|
41
44
|
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
42
45
|
const decompressingIfRequired = async (buffer) => {
|
|
46
|
+
if (!Buffer.isBuffer(buffer) || !buffer.length || buffer.length > MAX_BINARY_BYTES) throw new Error('BINARY_SIZE_LIMIT');
|
|
43
47
|
if (2 & buffer.readUInt8()) {
|
|
44
|
-
buffer = await inflatePromise(buffer.
|
|
48
|
+
buffer = await inflatePromise(buffer.subarray(1), { maxOutputLength: MAX_BINARY_BYTES });
|
|
45
49
|
}
|
|
46
50
|
else { // nodes with no compression have a 0x00 prefix, we remove that
|
|
47
51
|
buffer = buffer.slice(1);
|
|
@@ -49,6 +53,608 @@ const decompressingIfRequired = async (buffer) => {
|
|
|
49
53
|
return buffer;
|
|
50
54
|
};
|
|
51
55
|
exports.decompressingIfRequired = decompressingIfRequired;
|
|
56
|
+
const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }, depth = 0) => {
|
|
57
|
+
if (!Buffer.isBuffer(buffer) || buffer.length > MAX_BINARY_BYTES) throw new Error('BINARY_SIZE_LIMIT');
|
|
58
|
+
if (!Number.isSafeInteger(indexRef.index) || indexRef.index < 0) throw new Error('BINARY_INVALID_INDEX');
|
|
59
|
+
if (depth > MAX_BINARY_DEPTH || (indexRef.nodes = (indexRef.nodes || 0) + 1) > MAX_BINARY_NODES) throw new Error('BINARY_COMPLEXITY_LIMIT');
|
|
60
|
+
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
|
|
61
|
+
const checkEOS = (length) => {
|
|
62
|
+
if (!Number.isSafeInteger(length) || length < 0 || indexRef.index + length > buffer.length) {
|
|
63
|
+
throw new Error('end of stream');
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const next = () => {
|
|
67
|
+
const value = buffer[indexRef.index];
|
|
68
|
+
indexRef.index += 1;
|
|
69
|
+
return value;
|
|
70
|
+
};
|
|
71
|
+
const readByte = () => {
|
|
72
|
+
checkEOS(1);
|
|
73
|
+
return next();
|
|
74
|
+
};
|
|
75
|
+
const readBytes = (n) => {
|
|
76
|
+
checkEOS(n);
|
|
77
|
+
const value = buffer.slice(indexRef.index, indexRef.index + n);
|
|
78
|
+
indexRef.index += n;
|
|
79
|
+
return value;
|
|
80
|
+
};
|
|
81
|
+
const readStringFromChars = (length) => {
|
|
82
|
+
return readBytes(length).toString('utf-8');
|
|
83
|
+
};
|
|
84
|
+
const readInt = (n, littleEndian = false) => {
|
|
85
|
+
checkEOS(n);
|
|
86
|
+
let val = 0;
|
|
87
|
+
for (let i = 0; i < n; i++) {
|
|
88
|
+
const shift = littleEndian ? i : n - 1 - i;
|
|
89
|
+
val |= next() << (shift * 8);
|
|
90
|
+
}
|
|
91
|
+
return n === 4 ? val >>> 0 : val;
|
|
92
|
+
};
|
|
93
|
+
const readInt20 = () => {
|
|
94
|
+
checkEOS(3);
|
|
95
|
+
return ((next() & 15) << 16) + (next() << 8) + next();
|
|
96
|
+
};
|
|
97
|
+
const unpackHex = (value) => {
|
|
98
|
+
if (value >= 0 && value < 16) {
|
|
99
|
+
return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10;
|
|
100
|
+
}
|
|
101
|
+
throw new Error('invalid hex: ' + value);
|
|
102
|
+
};
|
|
103
|
+
const unpackNibble = (value) => {
|
|
104
|
+
if (value >= 0 && value <= 9) {
|
|
105
|
+
return '0'.charCodeAt(0) + value;
|
|
106
|
+
}
|
|
107
|
+
switch (value) {
|
|
108
|
+
case 10:
|
|
109
|
+
return '-'.charCodeAt(0);
|
|
110
|
+
case 11:
|
|
111
|
+
return '.'.charCodeAt(0);
|
|
112
|
+
case 15:
|
|
113
|
+
return '\0'.charCodeAt(0);
|
|
114
|
+
default:
|
|
115
|
+
throw new Error('invalid nibble: ' + value);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const unpackByte = (tag, value) => {
|
|
119
|
+
if (tag === TAGS.NIBBLE_8) {
|
|
120
|
+
return unpackNibble(value);
|
|
121
|
+
}
|
|
122
|
+
else if (tag === TAGS.HEX_8) {
|
|
123
|
+
return unpackHex(value);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
throw new Error('unknown tag: ' + tag);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const readPacked8 = (tag) => {
|
|
130
|
+
const startByte = readByte();
|
|
131
|
+
let value = '';
|
|
132
|
+
for (let i = 0; i < (startByte & 127); i++) {
|
|
133
|
+
const curByte = readByte();
|
|
134
|
+
value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4));
|
|
135
|
+
value += String.fromCharCode(unpackByte(tag, curByte & 0x0f));
|
|
136
|
+
}
|
|
137
|
+
if (startByte >> 7 !== 0) {
|
|
138
|
+
value = value.slice(0, -1);
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
};
|
|
142
|
+
const isListTag = (tag) => {
|
|
143
|
+
return tag === TAGS.LIST_EMPTY || tag === TAGS.LIST_8 || tag === TAGS.LIST_16;
|
|
144
|
+
};
|
|
145
|
+
const readListSize = (tag) => {
|
|
146
|
+
switch (tag) {
|
|
147
|
+
case TAGS.LIST_EMPTY:
|
|
148
|
+
return 0;
|
|
149
|
+
case TAGS.LIST_8:
|
|
150
|
+
return readByte();
|
|
151
|
+
case TAGS.LIST_16:
|
|
152
|
+
return readInt(2);
|
|
153
|
+
default:
|
|
154
|
+
throw new Error('invalid tag for list size: ' + tag);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const readJidPair = () => {
|
|
158
|
+
const i = readString(readByte());
|
|
159
|
+
const j = readString(readByte());
|
|
160
|
+
if (j) {
|
|
161
|
+
return (i || '') + '@' + j;
|
|
162
|
+
}
|
|
163
|
+
throw new Error('invalid jid pair: ' + i + ', ' + j);
|
|
164
|
+
};
|
|
165
|
+
const readAdJid = () => {
|
|
166
|
+
const rawDomainType = readByte();
|
|
167
|
+
const domainType = Number(rawDomainType);
|
|
168
|
+
const device = readByte();
|
|
169
|
+
const user = readString(readByte());
|
|
170
|
+
return (0, jid_utils_1.jidEncode)(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
|
|
171
|
+
};
|
|
172
|
+
let stringDepth = 0;
|
|
173
|
+
const readString = (tag) => {
|
|
174
|
+
if (++stringDepth > MAX_BINARY_DEPTH) throw new Error('BINARY_STRING_DEPTH_LIMIT');
|
|
175
|
+
try {
|
|
176
|
+
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
177
|
+
return SINGLE_BYTE_TOKENS[tag] || '';
|
|
178
|
+
}
|
|
179
|
+
switch (tag) {
|
|
180
|
+
case TAGS.DICTIONARY_0:
|
|
181
|
+
case TAGS.DICTIONARY_1:
|
|
182
|
+
case TAGS.DICTIONARY_2:
|
|
183
|
+
case TAGS.DICTIONARY_3:
|
|
184
|
+
return getTokenDouble(tag - TAGS.DICTIONARY_0, readByte());
|
|
185
|
+
case TAGS.LIST_EMPTY:
|
|
186
|
+
return '';
|
|
187
|
+
case TAGS.BINARY_8:
|
|
188
|
+
return readStringFromChars(readByte());
|
|
189
|
+
case TAGS.BINARY_20:
|
|
190
|
+
return readStringFromChars(readInt20());
|
|
191
|
+
case TAGS.BINARY_32:
|
|
192
|
+
return readStringFromChars(readInt(4));
|
|
193
|
+
case TAGS.JID_PAIR:
|
|
194
|
+
return readJidPair();
|
|
195
|
+
case TAGS.AD_JID:
|
|
196
|
+
return readAdJid();
|
|
197
|
+
case TAGS.HEX_8:
|
|
198
|
+
case TAGS.NIBBLE_8:
|
|
199
|
+
return readPacked8(tag);
|
|
200
|
+
default:
|
|
201
|
+
throw new Error('invalid string with tag: ' + tag);
|
|
202
|
+
}
|
|
203
|
+
} finally { stringDepth--; }
|
|
204
|
+
};
|
|
205
|
+
const readList = (tag) => {
|
|
206
|
+
const items = [];
|
|
207
|
+
const size = readListSize(tag);
|
|
208
|
+
for (let i = 0; i < size; i++) {
|
|
209
|
+
items.push((0, exports.decodeDecompressedBinaryNode)(buffer, opts, indexRef, depth + 1));
|
|
210
|
+
}
|
|
211
|
+
return items;
|
|
212
|
+
};
|
|
213
|
+
const getTokenDouble = (index1, index2) => {
|
|
214
|
+
const dict = DOUBLE_BYTE_TOKENS[index1];
|
|
215
|
+
if (!dict) {
|
|
216
|
+
throw new Error(`Invalid double token dict (${index1})`);
|
|
217
|
+
}
|
|
218
|
+
const value = dict[index2];
|
|
219
|
+
if (typeof value === 'undefined') {
|
|
220
|
+
throw new Error(`Invalid double token (${index2})`);
|
|
221
|
+
}
|
|
222
|
+
return value;
|
|
223
|
+
};
|
|
224
|
+
const listSize = readListSize(readByte());
|
|
225
|
+
const header = readString(readByte());
|
|
226
|
+
if (!listSize || !header.length) {
|
|
227
|
+
throw new Error('invalid node');
|
|
228
|
+
}
|
|
229
|
+
const attrs = {};
|
|
230
|
+
let data;
|
|
231
|
+
if (listSize === 0 || !header) {
|
|
232
|
+
throw new Error('invalid node');
|
|
233
|
+
}
|
|
234
|
+
// read the attributes in
|
|
235
|
+
const attributesLength = (listSize - 1) >> 1;
|
|
236
|
+
for (let i = 0; i < attributesLength; i++) {
|
|
237
|
+
const key = readString(readByte());
|
|
238
|
+
const value = readString(readByte());
|
|
239
|
+
Object.defineProperty(attrs, key, { value, enumerable: true, configurable: true, writable: true });
|
|
240
|
+
}
|
|
241
|
+
if (listSize % 2 === 0) {
|
|
242
|
+
const tag = readByte();
|
|
243
|
+
if (isListTag(tag)) {
|
|
244
|
+
data = readList(tag);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
let decoded;
|
|
248
|
+
switch (tag) {
|
|
249
|
+
case TAGS.BINARY_8:
|
|
250
|
+
decoded = readBytes(readByte());
|
|
251
|
+
break;
|
|
252
|
+
case TAGS.BINARY_20:
|
|
253
|
+
decoded = readBytes(readInt20());
|
|
254
|
+
break;
|
|
255
|
+
case TAGS.BINARY_32:
|
|
256
|
+
decoded = readBytes(readInt(4));
|
|
257
|
+
break;
|
|
258
|
+
default:
|
|
259
|
+
decoded = readString(tag);
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
data = decoded;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
tag: header,
|
|
267
|
+
attrs,
|
|
268
|
+
content: data
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
|
|
272
|
+
const decodeBinaryNode = async (buff) => {
|
|
273
|
+
const decompBuff = await (0, exports.decompressingIfRequired)(buff);
|
|
274
|
+
return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
|
|
275
|
+
};
|
|
276
|
+
exports.decodeBinaryNode = decodeBinaryNode;
|
|
277
|
+
|
|
278
|
+
// Kage: compatibilidad de API.
|
|
279
|
+
const __kageModule82 = (() => {
|
|
280
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
281
|
+
"use strict"
|
|
282
|
+
|
|
283
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
284
|
+
|
|
285
|
+
const { promisify } = require("util")
|
|
286
|
+
const { inflate } = require("zlib")
|
|
287
|
+
const {
|
|
288
|
+
jidEncode,
|
|
289
|
+
WAJIDDomains
|
|
290
|
+
} = require("./jid-utils")
|
|
291
|
+
const constants = require("./constants")
|
|
292
|
+
const inflatePromise = promisify(inflate)
|
|
293
|
+
|
|
294
|
+
const decompressingIfRequired = async (buffer) => {
|
|
295
|
+
if (2 & buffer.readUInt8()) {
|
|
296
|
+
buffer = await inflatePromise(buffer.slice(1))
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
else {
|
|
300
|
+
// nodes with no compression have a 0x00 prefix, we remove that
|
|
301
|
+
buffer = buffer.slice(1)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return buffer
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
308
|
+
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts
|
|
309
|
+
const checkEOS = (length) => {
|
|
310
|
+
if (indexRef.index + length > buffer.length) {
|
|
311
|
+
throw new Error('end of stream')
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const next = () => {
|
|
316
|
+
const value = buffer[indexRef.index]
|
|
317
|
+
|
|
318
|
+
indexRef.index += 1
|
|
319
|
+
|
|
320
|
+
return value
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const readByte = () => {
|
|
324
|
+
checkEOS(1)
|
|
325
|
+
return next()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const readBytes = (n) => {
|
|
329
|
+
checkEOS(n)
|
|
330
|
+
|
|
331
|
+
const value = buffer.slice(indexRef.index, indexRef.index + n)
|
|
332
|
+
|
|
333
|
+
indexRef.index += n
|
|
334
|
+
|
|
335
|
+
return value
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const readStringFromChars = (length) => {
|
|
339
|
+
return readBytes(length).toString('utf-8')
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const readInt = (n, littleEndian = false) => {
|
|
343
|
+
checkEOS(n)
|
|
344
|
+
|
|
345
|
+
let val = 0
|
|
346
|
+
|
|
347
|
+
for (let i = 0; i < n; i++) {
|
|
348
|
+
const shift = littleEndian ? i : n - 1 - i
|
|
349
|
+
val |= next() << (shift * 8)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return val
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const readInt20 = () => {
|
|
356
|
+
checkEOS(3)
|
|
357
|
+
return ((next() & 15) << 16) + (next() << 8) + next()
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const unpackHex = (value) => {
|
|
361
|
+
if (value >= 0 && value < 16) {
|
|
362
|
+
return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
throw new Error('invalid hex: ' + value)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const unpackNibble = (value) => {
|
|
369
|
+
if (value >= 0 && value <= 9) {
|
|
370
|
+
return '0'.charCodeAt(0) + value
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
switch (value) {
|
|
374
|
+
case 10:
|
|
375
|
+
return '-'.charCodeAt(0)
|
|
376
|
+
case 11:
|
|
377
|
+
return '.'.charCodeAt(0)
|
|
378
|
+
case 15:
|
|
379
|
+
return '\0'.charCodeAt(0)
|
|
380
|
+
default:
|
|
381
|
+
throw new Error('invalid nibble: ' + value)
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const unpackByte = (tag, value) => {
|
|
386
|
+
if (tag === TAGS.NIBBLE_8) {
|
|
387
|
+
return unpackNibble(value)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
else if (tag === TAGS.HEX_8) {
|
|
391
|
+
return unpackHex(value)
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
else {
|
|
395
|
+
throw new Error('unknown tag: ' + tag)
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const readPacked8 = (tag) => {
|
|
400
|
+
const startByte = readByte()
|
|
401
|
+
|
|
402
|
+
let value = ''
|
|
403
|
+
|
|
404
|
+
for (let i = 0; i < (startByte & 127); i++) {
|
|
405
|
+
const curByte = readByte()
|
|
406
|
+
|
|
407
|
+
value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4))
|
|
408
|
+
value += String.fromCharCode(unpackByte(tag, curByte & 0x0f))
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (startByte >> 7 !== 0) {
|
|
412
|
+
value = value.slice(0, -1)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return value
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const isListTag = (tag) => {
|
|
419
|
+
return tag === TAGS.LIST_EMPTY || tag === TAGS.LIST_8 || tag === TAGS.LIST_16
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const readListSize = (tag) => {
|
|
423
|
+
switch (tag) {
|
|
424
|
+
case TAGS.LIST_EMPTY:
|
|
425
|
+
return 0
|
|
426
|
+
case TAGS.LIST_8:
|
|
427
|
+
return readByte()
|
|
428
|
+
case TAGS.LIST_16:
|
|
429
|
+
return readInt(2)
|
|
430
|
+
default:
|
|
431
|
+
throw new Error('invalid tag for list size: ' + tag)
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const readJidPair = () => {
|
|
436
|
+
const i = readString(readByte())
|
|
437
|
+
const j = readString(readByte())
|
|
438
|
+
|
|
439
|
+
if (j) {
|
|
440
|
+
return (i || '') + '@' + j
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
throw new Error('invalid jid pair: ' + i + ', ' + j)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const readAdJid = () => {
|
|
447
|
+
const rawDomainType = readByte()
|
|
448
|
+
const domainType = Number(rawDomainType)
|
|
449
|
+
const device = readByte()
|
|
450
|
+
const user = readString(readByte())
|
|
451
|
+
|
|
452
|
+
let server = 's.whatsapp.net' // default whatsapp server
|
|
453
|
+
|
|
454
|
+
if (domainType === WAJIDDomains.LID) {
|
|
455
|
+
server = 'lid'
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
else if (domainType === WAJIDDomains.HOSTED) {
|
|
459
|
+
server = 'hosted'
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
else if (domainType === WAJIDDomains.HOSTED_LID) {
|
|
463
|
+
server = 'hosted.lid'
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return jidEncode(user, server, device)
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const readString = (tag) => {
|
|
470
|
+
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
471
|
+
return SINGLE_BYTE_TOKENS[tag] || ''
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
switch (tag) {
|
|
475
|
+
case TAGS.DICTIONARY_0:
|
|
476
|
+
case TAGS.DICTIONARY_1:
|
|
477
|
+
case TAGS.DICTIONARY_2:
|
|
478
|
+
case TAGS.DICTIONARY_3:
|
|
479
|
+
return getTokenDouble(tag - TAGS.DICTIONARY_0, readByte())
|
|
480
|
+
case TAGS.LIST_EMPTY:
|
|
481
|
+
return ''
|
|
482
|
+
case TAGS.BINARY_8:
|
|
483
|
+
return readStringFromChars(readByte())
|
|
484
|
+
case TAGS.BINARY_20:
|
|
485
|
+
return readStringFromChars(readInt20())
|
|
486
|
+
case TAGS.BINARY_32:
|
|
487
|
+
return readStringFromChars(readInt(4))
|
|
488
|
+
case TAGS.JID_PAIR:
|
|
489
|
+
return readJidPair()
|
|
490
|
+
case TAGS.AD_JID:
|
|
491
|
+
return readAdJid()
|
|
492
|
+
case TAGS.HEX_8:
|
|
493
|
+
case TAGS.NIBBLE_8:
|
|
494
|
+
return readPacked8(tag)
|
|
495
|
+
default:
|
|
496
|
+
throw new Error('invalid string with tag: ' + tag)
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const readList = (tag) => {
|
|
501
|
+
const items = []
|
|
502
|
+
const size = readListSize(tag)
|
|
503
|
+
|
|
504
|
+
for (let i = 0; i < size; i++) {
|
|
505
|
+
items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef))
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return items
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const getTokenDouble = (index1, index2) => {
|
|
512
|
+
const dict = DOUBLE_BYTE_TOKENS[index1]
|
|
513
|
+
|
|
514
|
+
if (!dict) {
|
|
515
|
+
throw new Error(`Invalid double token dict (${index1})`)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const value = dict[index2]
|
|
519
|
+
|
|
520
|
+
if (typeof value === 'undefined') {
|
|
521
|
+
throw new Error(`Invalid double token (${index2})`)
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return value
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const listSize = readListSize(readByte())
|
|
528
|
+
const header = readString(readByte())
|
|
529
|
+
|
|
530
|
+
if (!listSize || !header.length) {
|
|
531
|
+
throw new Error('invalid node')
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const attrs = {}
|
|
535
|
+
|
|
536
|
+
let data
|
|
537
|
+
|
|
538
|
+
if (listSize === 0 || !header) {
|
|
539
|
+
throw new Error('invalid node')
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// read the attributes in
|
|
543
|
+
const attributesLength = (listSize - 1) >> 1
|
|
544
|
+
|
|
545
|
+
for (let i = 0; i < attributesLength; i++) {
|
|
546
|
+
const key = readString(readByte())
|
|
547
|
+
const value = readString(readByte())
|
|
548
|
+
attrs[key] = value
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (listSize % 2 === 0) {
|
|
552
|
+
const tag = readByte()
|
|
553
|
+
|
|
554
|
+
if (isListTag(tag)) {
|
|
555
|
+
data = readList(tag)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
else {
|
|
559
|
+
let decoded
|
|
560
|
+
|
|
561
|
+
switch (tag) {
|
|
562
|
+
case TAGS.BINARY_8:
|
|
563
|
+
decoded = readBytes(readByte())
|
|
564
|
+
break
|
|
565
|
+
case TAGS.BINARY_20:
|
|
566
|
+
decoded = readBytes(readInt20())
|
|
567
|
+
break
|
|
568
|
+
case TAGS.BINARY_32:
|
|
569
|
+
decoded = readBytes(readInt(4))
|
|
570
|
+
break
|
|
571
|
+
default:
|
|
572
|
+
decoded = readString(tag)
|
|
573
|
+
break
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
data = decoded
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return {
|
|
581
|
+
tag: header,
|
|
582
|
+
attrs,
|
|
583
|
+
content: data
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const decodeBinaryNode = async (buff) => {
|
|
588
|
+
const decompBuff = await decompressingIfRequired(buff)
|
|
589
|
+
return decodeDecompressedBinaryNode(decompBuff, constants)
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
module.exports = {
|
|
593
|
+
decompressingIfRequired,
|
|
594
|
+
decodeDecompressedBinaryNode,
|
|
595
|
+
decodeBinaryNode
|
|
596
|
+
}
|
|
597
|
+
return module.exports;
|
|
598
|
+
})();
|
|
599
|
+
for (const key of Object.keys(__kageModule82)) {
|
|
600
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule82[key]});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// Kage: funciones avanzadas.
|
|
604
|
+
const __kageModule191 = (() => {
|
|
605
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
606
|
+
"use strict";
|
|
607
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
608
|
+
if (k2 === undefined) k2 = k;
|
|
609
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
610
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
611
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
612
|
+
}
|
|
613
|
+
Object.defineProperty(o, k2, desc);
|
|
614
|
+
}) : (function(o, m, k, k2) {
|
|
615
|
+
if (k2 === undefined) k2 = k;
|
|
616
|
+
o[k2] = m[k];
|
|
617
|
+
}));
|
|
618
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
619
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
620
|
+
}) : function(o, v) {
|
|
621
|
+
o["default"] = v;
|
|
622
|
+
});
|
|
623
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
624
|
+
var ownKeys = function(o) {
|
|
625
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
626
|
+
var ar = [];
|
|
627
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
628
|
+
return ar;
|
|
629
|
+
};
|
|
630
|
+
return ownKeys(o);
|
|
631
|
+
};
|
|
632
|
+
return function (mod) {
|
|
633
|
+
if (mod && mod.__esModule) return mod;
|
|
634
|
+
var result = {};
|
|
635
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
636
|
+
__setModuleDefault(result, mod);
|
|
637
|
+
return result;
|
|
638
|
+
};
|
|
639
|
+
})();
|
|
640
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
641
|
+
exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
|
|
642
|
+
const node_util_1 = require("node:util");
|
|
643
|
+
const node_zlib_1 = require("node:zlib");
|
|
644
|
+
const constants = __importStar(require("./constants.js"));
|
|
645
|
+
const jid_utils_js_1 = require("./jid-utils.js");
|
|
646
|
+
const inflatePromise = (0, node_util_1.promisify)(node_zlib_1.inflate);
|
|
647
|
+
const decompressingIfRequired = async (buffer) => {
|
|
648
|
+
if (2 & buffer.readUInt8()) {
|
|
649
|
+
buffer = await inflatePromise(buffer.slice(1));
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
// nodes with no compression have a 0x00 prefix, we remove that
|
|
653
|
+
buffer = buffer.slice(1);
|
|
654
|
+
}
|
|
655
|
+
return buffer;
|
|
656
|
+
};
|
|
657
|
+
exports.decompressingIfRequired = decompressingIfRequired;
|
|
52
658
|
const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
53
659
|
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
|
|
54
660
|
const checkEOS = (length) => {
|
|
@@ -160,7 +766,37 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
160
766
|
const domainType = Number(rawDomainType);
|
|
161
767
|
const device = readByte();
|
|
162
768
|
const user = readString(readByte());
|
|
163
|
-
|
|
769
|
+
let server = 's.whatsapp.net'; // default whatsapp server
|
|
770
|
+
if (domainType === jid_utils_js_1.WAJIDDomains.LID) {
|
|
771
|
+
server = 'lid';
|
|
772
|
+
}
|
|
773
|
+
else if (domainType === jid_utils_js_1.WAJIDDomains.HOSTED) {
|
|
774
|
+
server = 'hosted';
|
|
775
|
+
}
|
|
776
|
+
else if (domainType === jid_utils_js_1.WAJIDDomains.HOSTED_LID) {
|
|
777
|
+
server = 'hosted.lid';
|
|
778
|
+
}
|
|
779
|
+
return (0, jid_utils_js_1.jidEncode)(user, server, device);
|
|
780
|
+
};
|
|
781
|
+
const readFbJid = () => {
|
|
782
|
+
const user = readString(readByte());
|
|
783
|
+
const device = readInt(2);
|
|
784
|
+
const server = readString(readByte());
|
|
785
|
+
return `${user}:${device}@${server}`;
|
|
786
|
+
};
|
|
787
|
+
const readInteropJid = () => {
|
|
788
|
+
const user = readString(readByte());
|
|
789
|
+
const device = readInt(2);
|
|
790
|
+
const integrator = readInt(2);
|
|
791
|
+
let server = 'interop';
|
|
792
|
+
const beforeServer = indexRef.index;
|
|
793
|
+
try {
|
|
794
|
+
server = readString(readByte());
|
|
795
|
+
}
|
|
796
|
+
catch (err) {
|
|
797
|
+
indexRef.index = beforeServer;
|
|
798
|
+
}
|
|
799
|
+
return `${integrator}-${user}:${device}@${server}`;
|
|
164
800
|
};
|
|
165
801
|
const readString = (tag) => {
|
|
166
802
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
@@ -182,6 +818,10 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
182
818
|
return readStringFromChars(readInt(4));
|
|
183
819
|
case TAGS.JID_PAIR:
|
|
184
820
|
return readJidPair();
|
|
821
|
+
case TAGS.FB_JID:
|
|
822
|
+
return readFbJid();
|
|
823
|
+
case TAGS.INTEROP_JID:
|
|
824
|
+
return readInteropJid();
|
|
185
825
|
case TAGS.AD_JID:
|
|
186
826
|
return readAdJid();
|
|
187
827
|
case TAGS.HEX_8:
|
|
@@ -263,3 +903,10 @@ const decodeBinaryNode = async (buff) => {
|
|
|
263
903
|
return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
|
|
264
904
|
};
|
|
265
905
|
exports.decodeBinaryNode = decodeBinaryNode;
|
|
906
|
+
|
|
907
|
+
return module.exports;
|
|
908
|
+
})();
|
|
909
|
+
for (const key of Object.keys(__kageModule191)) {
|
|
910
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule191[key]});
|
|
911
|
+
}
|
|
912
|
+
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule191, configurable:true});
|