kage-baileys 3.0.6 → 3.2.3
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/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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
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
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.useSqliteAuthState = useSqliteAuthState;
|
|
37
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
38
|
+
const auth_utils_js_1 = require("./auth-utils.js");
|
|
39
|
+
const generics_js_1 = require("./generics.js");
|
|
40
|
+
async function loadBetterSqlite3() {
|
|
41
|
+
try {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
const mod = (await Promise.resolve().then(() => __importStar(require('better-sqlite3'))));
|
|
44
|
+
return mod.default ?? mod;
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
const helpful = new Error('`better-sqlite3` is required for `useSqliteAuthState`. Install it as a peer dependency: `npm install better-sqlite3` (or `yarn add better-sqlite3`).');
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
helpful.cause = err;
|
|
50
|
+
throw helpful;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const CREDS_ROW_KEY = '__creds__';
|
|
54
|
+
const CREATE_SCHEMA_SQL = `
|
|
55
|
+
CREATE TABLE IF NOT EXISTS creds (
|
|
56
|
+
key TEXT PRIMARY KEY,
|
|
57
|
+
value TEXT NOT NULL
|
|
58
|
+
);
|
|
59
|
+
CREATE TABLE IF NOT EXISTS signal_keys (
|
|
60
|
+
type TEXT NOT NULL,
|
|
61
|
+
id TEXT NOT NULL,
|
|
62
|
+
value TEXT NOT NULL,
|
|
63
|
+
PRIMARY KEY (type, id)
|
|
64
|
+
);
|
|
65
|
+
CREATE INDEX IF NOT EXISTS signal_keys_type_idx ON signal_keys(type);
|
|
66
|
+
`;
|
|
67
|
+
async function useSqliteAuthState(opts) {
|
|
68
|
+
let db;
|
|
69
|
+
if (opts.database) {
|
|
70
|
+
db = opts.database;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const Database = await loadBetterSqlite3();
|
|
74
|
+
db = new Database(opts.dbPath);
|
|
75
|
+
}
|
|
76
|
+
// WAL mode allows concurrent reads alongside a single writer; matches
|
|
77
|
+
// what SQLite recommends for read-heavy workloads with sporadic writes.
|
|
78
|
+
db.pragma('journal_mode = WAL');
|
|
79
|
+
db.pragma('synchronous = NORMAL');
|
|
80
|
+
db.exec(CREATE_SCHEMA_SQL);
|
|
81
|
+
const stmts = {
|
|
82
|
+
credsSelect: db.prepare('SELECT value FROM creds WHERE key = ?'),
|
|
83
|
+
credsUpsert: db.prepare('INSERT INTO creds (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'),
|
|
84
|
+
keySelect: db.prepare('SELECT value FROM signal_keys WHERE type = ? AND id = ?'),
|
|
85
|
+
keyUpsert: db.prepare('INSERT INTO signal_keys (type, id, value) VALUES (?, ?, ?) ON CONFLICT(type, id) DO UPDATE SET value = excluded.value'),
|
|
86
|
+
keyDelete: db.prepare('DELETE FROM signal_keys WHERE type = ? AND id = ?'),
|
|
87
|
+
keyListIds: db.prepare('SELECT id FROM signal_keys WHERE type = ?'),
|
|
88
|
+
keyList: db.prepare('SELECT id, value FROM signal_keys WHERE type = ?'),
|
|
89
|
+
clearKeys: db.prepare('DELETE FROM signal_keys')
|
|
90
|
+
};
|
|
91
|
+
const loadCreds = () => {
|
|
92
|
+
const row = stmts.credsSelect.get(CREDS_ROW_KEY);
|
|
93
|
+
if (!row)
|
|
94
|
+
return (0, auth_utils_js_1.initAuthCreds)();
|
|
95
|
+
return JSON.parse(row.value, generics_js_1.BufferJSON.reviver);
|
|
96
|
+
};
|
|
97
|
+
const persistCreds = (creds) => {
|
|
98
|
+
stmts.credsUpsert.run(CREDS_ROW_KEY, JSON.stringify(creds, generics_js_1.BufferJSON.replacer));
|
|
99
|
+
};
|
|
100
|
+
const creds = loadCreds();
|
|
101
|
+
return {
|
|
102
|
+
state: {
|
|
103
|
+
creds,
|
|
104
|
+
keys: {
|
|
105
|
+
get: async (type, ids) => {
|
|
106
|
+
const data = {};
|
|
107
|
+
for (const id of ids) {
|
|
108
|
+
const row = stmts.keySelect.get(type, id);
|
|
109
|
+
if (row) {
|
|
110
|
+
let value = JSON.parse(row.value, generics_js_1.BufferJSON.reviver);
|
|
111
|
+
if (type === 'app-state-sync-key' && value) {
|
|
112
|
+
value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
113
|
+
}
|
|
114
|
+
data[id] = value;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return data;
|
|
118
|
+
},
|
|
119
|
+
set: async (data) => {
|
|
120
|
+
const writeTx = db.transaction(() => {
|
|
121
|
+
for (const category in data) {
|
|
122
|
+
for (const id in data[category]) {
|
|
123
|
+
const value = data[category][id];
|
|
124
|
+
if (value) {
|
|
125
|
+
const stringified = JSON.stringify(value, generics_js_1.BufferJSON.replacer);
|
|
126
|
+
stmts.keyUpsert.run(category, id, stringified);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
stmts.keyDelete.run(category, id);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
writeTx();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
saveCreds: async () => {
|
|
139
|
+
persistCreds(creds);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -226,4 +226,500 @@ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
|
226
226
|
.encode(account)
|
|
227
227
|
.finish();
|
|
228
228
|
};
|
|
229
|
-
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
229
|
+
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
230
|
+
// Kage: compatibilidad de API.
|
|
231
|
+
const __kageModule80 = (() => {
|
|
232
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
233
|
+
"use strict"
|
|
234
|
+
|
|
235
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
236
|
+
|
|
237
|
+
const { Boom } = require("@hapi/boom")
|
|
238
|
+
const { createHash } = require("crypto")
|
|
239
|
+
const { proto } = require("../../WAProto")
|
|
240
|
+
const {
|
|
241
|
+
KEY_BUNDLE_TYPE,
|
|
242
|
+
WA_ADV_ACCOUNT_SIG_PREFIX,
|
|
243
|
+
WA_ADV_DEVICE_SIG_PREFIX,
|
|
244
|
+
WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
245
|
+
} = require("../Defaults/constants")
|
|
246
|
+
const {
|
|
247
|
+
jidDecode,
|
|
248
|
+
getBinaryNodeChild,
|
|
249
|
+
S_WHATSAPP_NET
|
|
250
|
+
} = require("../WABinary")
|
|
251
|
+
const {
|
|
252
|
+
Curve,
|
|
253
|
+
hmacSign
|
|
254
|
+
} = require("./crypto")
|
|
255
|
+
const { encodeBigEndian } = require("./generics")
|
|
256
|
+
const { createSignalIdentity } = require("./signal")
|
|
257
|
+
|
|
258
|
+
const getUserAgent = (config) => {
|
|
259
|
+
return {
|
|
260
|
+
appVersion: {
|
|
261
|
+
primary: config.version[0],
|
|
262
|
+
secondary: config.version[1],
|
|
263
|
+
tertiary: config.version[2],
|
|
264
|
+
},
|
|
265
|
+
platform: /*config.browser[1].toLocaleLowerCase().includes('android')
|
|
266
|
+
? proto.ClientPayload.UserAgent.Platform.ANDROID
|
|
267
|
+
:*/ proto.ClientPayload.UserAgent.Platform.WEB,
|
|
268
|
+
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
269
|
+
osVersion: '0.1',
|
|
270
|
+
device: 'Desktop',
|
|
271
|
+
osBuildNumber: '0.1',
|
|
272
|
+
localeLanguageIso6391: 'en',
|
|
273
|
+
mnc: '000',
|
|
274
|
+
mcc: '000',
|
|
275
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const PLATFORM_MAP = {
|
|
280
|
+
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
281
|
+
'Windows': proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const getWebInfo = (config) => {
|
|
285
|
+
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
|
|
286
|
+
if (config.syncFullHistory &&
|
|
287
|
+
PLATFORM_MAP[config.browser[0]] &&
|
|
288
|
+
config.browser[1] === 'Desktop') {
|
|
289
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]]
|
|
290
|
+
}
|
|
291
|
+
return { webSubPlatform }
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const getClientPayload = (config) => {
|
|
295
|
+
const payload = {
|
|
296
|
+
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
297
|
+
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
298
|
+
userAgent: getUserAgent(config),
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/*if (!config.browser[1].toLocaleLowerCase().includes('android')) {
|
|
302
|
+
payload.webInfo = getWebInfo(config)
|
|
303
|
+
}*/
|
|
304
|
+
payload.webInfo = getWebInfo(config)
|
|
305
|
+
|
|
306
|
+
return payload
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const generateLoginNode = (userJid, config) => {
|
|
310
|
+
const { user, device } = jidDecode(userJid)
|
|
311
|
+
const payload = {
|
|
312
|
+
...getClientPayload(config),
|
|
313
|
+
passive: true,
|
|
314
|
+
pull: true,
|
|
315
|
+
username: +user,
|
|
316
|
+
device: device,
|
|
317
|
+
// TODO: investigate (hard set as false atm)
|
|
318
|
+
lidDbMigrated: false
|
|
319
|
+
}
|
|
320
|
+
return proto.ClientPayload.fromObject(payload)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const getPlatformType = (platform) => {
|
|
324
|
+
const platformType = platform.toUpperCase()
|
|
325
|
+
|
|
326
|
+
/*if (platformType === 'ANDROID') {
|
|
327
|
+
return proto.DeviceProps.PlatformType.ANDROID_PHONE
|
|
328
|
+
}*/
|
|
329
|
+
|
|
330
|
+
return (proto.DeviceProps.PlatformType[platformType] ||
|
|
331
|
+
proto.DeviceProps.PlatformType.CHROME)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
335
|
+
// the app version needs to be md5 hashed
|
|
336
|
+
// and passed in
|
|
337
|
+
const appVersionBuf = createHash('md5')
|
|
338
|
+
.update(config.version.join('.')) // join as string
|
|
339
|
+
.digest()
|
|
340
|
+
|
|
341
|
+
const companion = {
|
|
342
|
+
os: config.browser[0],
|
|
343
|
+
platformType: getPlatformType(config.browser[1]),
|
|
344
|
+
requireFullSync: config.syncFullHistory,
|
|
345
|
+
historySyncConfig: {
|
|
346
|
+
storageQuotaMb: 10240,
|
|
347
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
348
|
+
recentSyncDaysLimit: undefined,
|
|
349
|
+
supportCallLogHistory: false,
|
|
350
|
+
supportBotUserAgentChatHistory: true,
|
|
351
|
+
supportCagReactionsAndPolls: true,
|
|
352
|
+
supportBizHostedMsg: true,
|
|
353
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
354
|
+
supportHostedGroupMsg: true,
|
|
355
|
+
supportFbidBotChatHistory: true,
|
|
356
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
357
|
+
supportMessageAssociation: true,
|
|
358
|
+
supportGroupHistory: false,
|
|
359
|
+
onDemandReady: undefined,
|
|
360
|
+
supportGuestChat: undefined
|
|
361
|
+
},
|
|
362
|
+
version: {
|
|
363
|
+
primary: 10,
|
|
364
|
+
secondary: 15,
|
|
365
|
+
tertiary: 7
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const companionProto = proto.DeviceProps.encode(companion).finish()
|
|
370
|
+
|
|
371
|
+
const registerPayload = {
|
|
372
|
+
...getClientPayload(config),
|
|
373
|
+
passive: false,
|
|
374
|
+
pull: false,
|
|
375
|
+
devicePairingData: {
|
|
376
|
+
buildHash: appVersionBuf,
|
|
377
|
+
deviceProps: companionProto,
|
|
378
|
+
eRegid: encodeBigEndian(registrationId),
|
|
379
|
+
eKeytype: KEY_BUNDLE_TYPE,
|
|
380
|
+
eIdent: signedIdentityKey.public,
|
|
381
|
+
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
382
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
383
|
+
eSkeySig: signedPreKey.signature,
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return proto.ClientPayload.fromObject(registerPayload)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
391
|
+
const msgId = stanza.attrs.id
|
|
392
|
+
const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success')
|
|
393
|
+
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity')
|
|
394
|
+
const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform')
|
|
395
|
+
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device')
|
|
396
|
+
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz')
|
|
397
|
+
|
|
398
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
399
|
+
throw new Boom('Missing device-identity or device in pair success node', { data: stanza })
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const bizName = businessNode?.attrs.name
|
|
403
|
+
const jid = deviceNode.attrs.jid
|
|
404
|
+
const lid = deviceNode.attrs.lid
|
|
405
|
+
const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
|
|
406
|
+
|
|
407
|
+
let hmacPrefix = Buffer.from([])
|
|
408
|
+
|
|
409
|
+
if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
|
|
410
|
+
hmacPrefix = WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
|
|
414
|
+
|
|
415
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
416
|
+
throw new Boom('Invalid account signature')
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const account = proto.ADVSignedDeviceIdentity.decode(details)
|
|
420
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account
|
|
421
|
+
const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails)
|
|
422
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
|
|
423
|
+
? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
424
|
+
: WA_ADV_ACCOUNT_SIG_PREFIX
|
|
425
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public])
|
|
426
|
+
|
|
427
|
+
if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
428
|
+
throw new Boom('Failed to verify account signature')
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const deviceMsg = Buffer.concat([
|
|
432
|
+
WA_ADV_DEVICE_SIG_PREFIX,
|
|
433
|
+
deviceDetails,
|
|
434
|
+
signedIdentityKey.public,
|
|
435
|
+
accountSignatureKey
|
|
436
|
+
])
|
|
437
|
+
|
|
438
|
+
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg)
|
|
439
|
+
|
|
440
|
+
const identity = createSignalIdentity(lid, accountSignatureKey)
|
|
441
|
+
const accountEnc = encodeSignedDeviceIdentity(account, false)
|
|
442
|
+
const reply = {
|
|
443
|
+
tag: 'iq',
|
|
444
|
+
attrs: {
|
|
445
|
+
to: S_WHATSAPP_NET,
|
|
446
|
+
type: 'result',
|
|
447
|
+
id: msgId
|
|
448
|
+
},
|
|
449
|
+
content: [
|
|
450
|
+
{
|
|
451
|
+
tag: 'pair-device-sign',
|
|
452
|
+
attrs: {},
|
|
453
|
+
content: [
|
|
454
|
+
{
|
|
455
|
+
tag: 'device-identity',
|
|
456
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
457
|
+
content: accountEnc
|
|
458
|
+
}
|
|
459
|
+
]
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const authUpdate = {
|
|
465
|
+
account,
|
|
466
|
+
me: { id: jid, name: bizName, lid },
|
|
467
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
468
|
+
platform: platformNode?.attrs.name
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return {
|
|
472
|
+
creds: authUpdate,
|
|
473
|
+
reply
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
478
|
+
account = { ...account }
|
|
479
|
+
// set to null if we are not to include the signature key
|
|
480
|
+
// or if we are including the signature key but it is empty
|
|
481
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
482
|
+
account.accountSignatureKey = null
|
|
483
|
+
}
|
|
484
|
+
return proto.ADVSignedDeviceIdentity.encode(account).finish()
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
module.exports = {
|
|
488
|
+
generateLoginNode,
|
|
489
|
+
generateRegistrationNode,
|
|
490
|
+
configureSuccessfulPairing,
|
|
491
|
+
encodeSignedDeviceIdentity
|
|
492
|
+
}
|
|
493
|
+
return module.exports;
|
|
494
|
+
})();
|
|
495
|
+
for (const key of Object.keys(__kageModule80)) {
|
|
496
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule80[key]});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Kage: funciones avanzadas.
|
|
500
|
+
const __kageModule189 = (() => {
|
|
501
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
502
|
+
"use strict";
|
|
503
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
504
|
+
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
|
|
505
|
+
const node_crypto_1 = require("node:crypto");
|
|
506
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
507
|
+
const index_js_2 = require("../Addon/index.js");
|
|
508
|
+
const index_js_3 = require("../Defaults/index.js");
|
|
509
|
+
const index_js_4 = require("../WABinary/index.js");
|
|
510
|
+
const crypto_js_1 = require("./crypto.js");
|
|
511
|
+
const generics_js_1 = require("./generics.js");
|
|
512
|
+
const signal_js_1 = require("./signal.js");
|
|
513
|
+
const getUserAgent = (config) => {
|
|
514
|
+
return {
|
|
515
|
+
appVersion: {
|
|
516
|
+
primary: config.version[0],
|
|
517
|
+
secondary: config.version[1],
|
|
518
|
+
tertiary: config.version[2]
|
|
519
|
+
},
|
|
520
|
+
platform: config.browser[1].toLocaleLowerCase().includes('android')
|
|
521
|
+
? index_js_1.proto.ClientPayload.UserAgent.Platform.ANDROID
|
|
522
|
+
: index_js_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
523
|
+
releaseChannel: index_js_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
524
|
+
osVersion: '0.1',
|
|
525
|
+
device: 'Desktop',
|
|
526
|
+
osBuildNumber: '0.1',
|
|
527
|
+
localeLanguageIso6391: 'en',
|
|
528
|
+
mnc: '000',
|
|
529
|
+
mcc: '000',
|
|
530
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
531
|
+
};
|
|
532
|
+
};
|
|
533
|
+
const PLATFORM_MAP = {
|
|
534
|
+
'Mac OS': index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
535
|
+
Windows: index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
|
|
536
|
+
};
|
|
537
|
+
const getWebInfo = (config) => {
|
|
538
|
+
let webSubPlatform = index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
539
|
+
if (config.syncFullHistory &&
|
|
540
|
+
PLATFORM_MAP[config.browser[0]] &&
|
|
541
|
+
config.browser[1] === 'Desktop') {
|
|
542
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
543
|
+
}
|
|
544
|
+
return { webSubPlatform };
|
|
545
|
+
};
|
|
546
|
+
const getClientPayload = (config) => {
|
|
547
|
+
const payload = {
|
|
548
|
+
connectType: index_js_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
549
|
+
connectReason: index_js_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
550
|
+
userAgent: getUserAgent(config)
|
|
551
|
+
};
|
|
552
|
+
if (!config.browser[1].toLocaleLowerCase().includes('android')) {
|
|
553
|
+
payload.webInfo = getWebInfo(config);
|
|
554
|
+
}
|
|
555
|
+
if (config.pushName) {
|
|
556
|
+
payload.pushName = config.pushName;
|
|
557
|
+
}
|
|
558
|
+
return payload;
|
|
559
|
+
};
|
|
560
|
+
const generateLoginNode = (userJid, config) => {
|
|
561
|
+
const { user, device } = (0, index_js_4.jidDecode)(userJid);
|
|
562
|
+
const payload = {
|
|
563
|
+
...getClientPayload(config),
|
|
564
|
+
passive: true,
|
|
565
|
+
pull: true,
|
|
566
|
+
username: +user,
|
|
567
|
+
device: device,
|
|
568
|
+
// TODO: investigate (hard set as false atm)
|
|
569
|
+
lidDbMigrated: false
|
|
570
|
+
};
|
|
571
|
+
return index_js_1.proto.ClientPayload.fromObject(payload);
|
|
572
|
+
};
|
|
573
|
+
exports.generateLoginNode = generateLoginNode;
|
|
574
|
+
const getPlatformType = (platform) => {
|
|
575
|
+
const platformType = platform.toUpperCase();
|
|
576
|
+
if (platformType === 'ANDROID') {
|
|
577
|
+
return index_js_1.proto.DeviceProps.PlatformType.ANDROID_PHONE;
|
|
578
|
+
}
|
|
579
|
+
return (index_js_1.proto.DeviceProps.PlatformType[platformType] ||
|
|
580
|
+
index_js_1.proto.DeviceProps.PlatformType.CHROME);
|
|
581
|
+
};
|
|
582
|
+
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
583
|
+
// the app version needs to be md5 hashed
|
|
584
|
+
// and passed in
|
|
585
|
+
const appVersionBuf = (0, node_crypto_1.createHash)('md5')
|
|
586
|
+
.update(config.version.join('.')) // join as string
|
|
587
|
+
.digest();
|
|
588
|
+
const companion = {
|
|
589
|
+
os: config.browser[0],
|
|
590
|
+
platformType: getPlatformType(config.browser[1]),
|
|
591
|
+
requireFullSync: config.syncFullHistory,
|
|
592
|
+
historySyncConfig: {
|
|
593
|
+
storageQuotaMb: 10240,
|
|
594
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
595
|
+
recentSyncDaysLimit: undefined,
|
|
596
|
+
supportCallLogHistory: false,
|
|
597
|
+
supportBotUserAgentChatHistory: true,
|
|
598
|
+
supportCagReactionsAndPolls: true,
|
|
599
|
+
supportBizHostedMsg: true,
|
|
600
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
601
|
+
supportHostedGroupMsg: true,
|
|
602
|
+
supportFbidBotChatHistory: true,
|
|
603
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
604
|
+
supportMessageAssociation: true,
|
|
605
|
+
supportGroupHistory: false,
|
|
606
|
+
onDemandReady: undefined,
|
|
607
|
+
supportGuestChat: undefined
|
|
608
|
+
},
|
|
609
|
+
version: {
|
|
610
|
+
primary: 10,
|
|
611
|
+
secondary: 15,
|
|
612
|
+
tertiary: 7
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
const companionProto = index_js_1.proto.DeviceProps.encode(companion).finish();
|
|
616
|
+
const registerPayload = {
|
|
617
|
+
...getClientPayload(config),
|
|
618
|
+
passive: false,
|
|
619
|
+
pull: false,
|
|
620
|
+
devicePairingData: {
|
|
621
|
+
buildHash: appVersionBuf,
|
|
622
|
+
deviceProps: companionProto,
|
|
623
|
+
eRegid: (0, generics_js_1.encodeBigEndian)(registrationId),
|
|
624
|
+
eKeytype: index_js_3.KEY_BUNDLE_TYPE,
|
|
625
|
+
eIdent: signedIdentityKey.public,
|
|
626
|
+
eSkeyId: (0, generics_js_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
627
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
628
|
+
eSkeySig: signedPreKey.signature
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
return index_js_1.proto.ClientPayload.fromObject(registerPayload);
|
|
632
|
+
};
|
|
633
|
+
exports.generateRegistrationNode = generateRegistrationNode;
|
|
634
|
+
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
635
|
+
const msgId = stanza.attrs.id;
|
|
636
|
+
const pairSuccessNode = (0, index_js_4.getBinaryNodeChild)(stanza, 'pair-success');
|
|
637
|
+
const deviceIdentityNode = (0, index_js_4.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
|
|
638
|
+
const platformNode = (0, index_js_4.getBinaryNodeChild)(pairSuccessNode, 'platform');
|
|
639
|
+
const deviceNode = (0, index_js_4.getBinaryNodeChild)(pairSuccessNode, 'device');
|
|
640
|
+
const businessNode = (0, index_js_4.getBinaryNodeChild)(pairSuccessNode, 'biz');
|
|
641
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
642
|
+
throw new index_js_2.HttpError('Missing device-identity or device in pair success node', { data: stanza });
|
|
643
|
+
}
|
|
644
|
+
const bizName = businessNode?.attrs.name;
|
|
645
|
+
const jid = deviceNode.attrs.jid;
|
|
646
|
+
const lid = deviceNode.attrs.lid;
|
|
647
|
+
const { details, hmac, accountType } = index_js_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
648
|
+
let hmacPrefix = Buffer.from([]);
|
|
649
|
+
if (accountType !== undefined && accountType === index_js_1.proto.ADVEncryptionType.HOSTED) {
|
|
650
|
+
hmacPrefix = index_js_3.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
|
|
651
|
+
}
|
|
652
|
+
const advSign = (0, crypto_js_1.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
653
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
654
|
+
throw new index_js_2.HttpError('Invalid account signature');
|
|
655
|
+
}
|
|
656
|
+
const account = index_js_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
657
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
658
|
+
const deviceIdentity = index_js_1.proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
659
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === index_js_1.proto.ADVEncryptionType.HOSTED
|
|
660
|
+
? index_js_3.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
661
|
+
: index_js_3.WA_ADV_ACCOUNT_SIG_PREFIX;
|
|
662
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
663
|
+
if (!crypto_js_1.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
664
|
+
throw new index_js_2.HttpError('Failed to verify account signature');
|
|
665
|
+
}
|
|
666
|
+
const deviceMsg = Buffer.concat([
|
|
667
|
+
index_js_3.WA_ADV_DEVICE_SIG_PREFIX,
|
|
668
|
+
deviceDetails,
|
|
669
|
+
signedIdentityKey.public,
|
|
670
|
+
accountSignatureKey
|
|
671
|
+
]);
|
|
672
|
+
account.deviceSignature = crypto_js_1.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
673
|
+
const identity = (0, signal_js_1.createSignalIdentity)(lid, accountSignatureKey);
|
|
674
|
+
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
675
|
+
const reply = {
|
|
676
|
+
tag: 'iq',
|
|
677
|
+
attrs: {
|
|
678
|
+
to: index_js_4.S_WHATSAPP_NET,
|
|
679
|
+
type: 'result',
|
|
680
|
+
id: msgId
|
|
681
|
+
},
|
|
682
|
+
content: [
|
|
683
|
+
{
|
|
684
|
+
tag: 'pair-device-sign',
|
|
685
|
+
attrs: {},
|
|
686
|
+
content: [
|
|
687
|
+
{
|
|
688
|
+
tag: 'device-identity',
|
|
689
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
690
|
+
content: accountEnc
|
|
691
|
+
}
|
|
692
|
+
]
|
|
693
|
+
}
|
|
694
|
+
]
|
|
695
|
+
};
|
|
696
|
+
const authUpdate = {
|
|
697
|
+
account,
|
|
698
|
+
me: { id: jid, name: bizName, lid },
|
|
699
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
700
|
+
platform: platformNode?.attrs.name,
|
|
701
|
+
registered: true
|
|
702
|
+
};
|
|
703
|
+
return {
|
|
704
|
+
creds: authUpdate,
|
|
705
|
+
reply
|
|
706
|
+
};
|
|
707
|
+
};
|
|
708
|
+
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
709
|
+
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
710
|
+
account = { ...account };
|
|
711
|
+
// set to null if we are not to include the signature key
|
|
712
|
+
// or if we are including the signature key but it is empty
|
|
713
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
714
|
+
account.accountSignatureKey = null;
|
|
715
|
+
}
|
|
716
|
+
return index_js_1.proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
717
|
+
};
|
|
718
|
+
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
719
|
+
|
|
720
|
+
return module.exports;
|
|
721
|
+
})();
|
|
722
|
+
for (const key of Object.keys(__kageModule189)) {
|
|
723
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule189[key]});
|
|
724
|
+
}
|
|
725
|
+
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule189, configurable:true});
|
|
@@ -7,7 +7,7 @@ function getViewOnceContent(raw) {
|
|
|
7
7
|
let message = raw?.message ?? raw;
|
|
8
8
|
let viewOnce = false;
|
|
9
9
|
for (let i = 0; i < 12 && message && typeof message === 'object'; i++) {
|
|
10
|
-
const wrapper = ['ephemeralMessage', 'documentWithCaptionMessage', 'viewOnceMessage', 'viewOnceMessageV2', 'viewOnceMessageV2Extension'].find(k => message[k]?.message);
|
|
10
|
+
const wrapper = ['deviceSentMessage', 'ephemeralMessage', 'documentWithCaptionMessage', 'viewOnceMessage', 'viewOnceMessageV2', 'viewOnceMessageV2Extension'].find(k => message[k]?.message);
|
|
11
11
|
if (wrapper) { viewOnce ||= wrapper.startsWith('viewOnce'); message = message[wrapper].message; continue; }
|
|
12
12
|
const type = types.find(k => message[k]);
|
|
13
13
|
if (!type) return null;
|
|
@@ -40,12 +40,19 @@ async function resendViewOnceMessage(conn, raw, options = {}) {
|
|
|
40
40
|
if (field === 'document') body.fileName = value.fileName || 'archivo';
|
|
41
41
|
return conn.sendMessage(options.jid || raw.key.remoteJid, body, options.quoted ? { quoted: options.quoted } : {});
|
|
42
42
|
}
|
|
43
|
-
function handleAutoViewOnce(raw, conn, settings = {}, options = {}) {
|
|
43
|
+
async function handleAutoViewOnce(raw, conn, settings = {}, options = {}) {
|
|
44
44
|
const chat = raw?.key?.remoteJid;
|
|
45
|
-
const
|
|
45
|
+
const normalize = jid => String(jid || '').replace(/:\d+@/, '@');
|
|
46
|
+
const aliases = new Set([chat, raw?.key?.remoteJidAlt].filter(Boolean).map(normalize));
|
|
47
|
+
for (const jid of [...aliases]) {
|
|
48
|
+
if (jid.endsWith('@lid')) {
|
|
49
|
+
try { const pn = await conn.signalRepository?.lidMapping?.getPNForLID?.(jid); if (pn) aliases.add(normalize(pn)); } catch {}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const active = () => Array.isArray(settings.autoViewOnceChats) && settings.autoViewOnceChats.some(jid => aliases.has(normalize(jid)));
|
|
46
53
|
// Preserve the explicitly consented archive API for existing library clients.
|
|
47
54
|
if (!active()) return require('./consented-media').handleConsentedAutoViewOnce(raw, conn, settings, options);
|
|
48
|
-
if (!raw?.key?.id || raw.key.fromMe || !/@(s\.whatsapp\.net|lid|g\.us)$/.test(chat || '') || !getViewOnceContent(raw)?.viewOnce) return Promise.resolve(null);
|
|
55
|
+
if (!raw?.key?.id || (raw.key.fromMe && !settings.autoViewOnceOwn) || !/@(s\.whatsapp\.net|lid|g\.us)$/.test(chat || '') || !getViewOnceContent(raw)?.viewOnce) return Promise.resolve(null);
|
|
49
56
|
const timestamp = Number(raw.messageTimestamp?.toNumber?.() ?? raw.messageTimestamp ?? 0) * 1000;
|
|
50
57
|
if (!timestamp || Date.now() - timestamp > 300000 || timestamp > Date.now() + 60000) return Promise.resolve(null);
|
|
51
58
|
let state = queues.get(conn);
|
|
@@ -58,7 +65,8 @@ function handleAutoViewOnce(raw, conn, settings = {}, options = {}) {
|
|
|
58
65
|
state.seen.set(id, now); state.pending++;
|
|
59
66
|
while (state.seen.size > 500) state.seen.delete(state.seen.keys().next().value);
|
|
60
67
|
const task = state.tail.then(() => active() ? resendViewOnceMessage(conn, raw, { ...options, jid: chat, shouldSend: active }) : null);
|
|
61
|
-
|
|
68
|
+
task.then(result => conn.ev?.emit('kage.automation', { kind: 'viewonce', id: raw.key.id, chat, outcome: result ? 'sent' : 'cancelled' }), error => conn.ev?.emit('kage.automation', { kind: 'viewonce', id: raw.key.id, chat, outcome: 'failed', error: String(error.message || error).slice(0,200) })).catch(error => conn.logger?.warn?.({ error: error.message }, 'automation event listener'));
|
|
69
|
+
state.tail = task.catch(() => { state.seen.delete(id); }).finally(() => { state.pending--; });
|
|
62
70
|
return task;
|
|
63
71
|
}
|
|
64
72
|
exports.getViewOnceContent = getViewOnceContent;
|