@vanzxy/baileys 1.4.1 → 1.4.2
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.
Potentially problematic release.
This version of @vanzxy/baileys might be problematic. Click here for more details.
- package/cjs/WAProto/index.js +106053 -0
- package/cjs/lib/Defaults/index.js +168 -0
- package/cjs/lib/Signal/Group/ciphertext-message.js +16 -0
- package/cjs/lib/Signal/Group/group-session-builder.js +67 -0
- package/cjs/lib/Signal/Group/group_cipher.js +86 -0
- package/cjs/lib/Signal/Group/index.js +58 -0
- package/cjs/lib/Signal/Group/keyhelper.js +56 -0
- package/cjs/lib/Signal/Group/sender-chain-key.js +30 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.js +67 -0
- package/cjs/lib/Signal/Group/sender-key-message.js +70 -0
- package/cjs/lib/Signal/Group/sender-key-name.js +52 -0
- package/cjs/lib/Signal/Group/sender-key-record.js +45 -0
- package/cjs/lib/Signal/Group/sender-key-state.js +88 -0
- package/cjs/lib/Signal/Group/sender-message-key.js +30 -0
- package/cjs/lib/Signal/libsignal.js +467 -0
- package/cjs/lib/Signal/lid-mapping.js +281 -0
- package/cjs/lib/Socket/Client/index.js +19 -0
- package/cjs/lib/Socket/Client/types.js +15 -0
- package/cjs/lib/Socket/Client/websocket.js +61 -0
- package/cjs/lib/Socket/business.js +384 -0
- package/cjs/lib/Socket/chats.js +1257 -0
- package/cjs/lib/Socket/communities.js +442 -0
- package/cjs/lib/Socket/dugong.js +753 -0
- package/cjs/lib/Socket/groups.js +360 -0
- package/cjs/lib/Socket/index.js +19 -0
- package/cjs/lib/Socket/messages-recv.js +1790 -0
- package/cjs/lib/Socket/messages-send.js +1390 -0
- package/cjs/lib/Socket/mex.js +46 -0
- package/cjs/lib/Socket/newsletter.js +340 -0
- package/cjs/lib/Socket/socket.js +1007 -0
- package/cjs/lib/Store/index.js +20 -0
- package/cjs/lib/Store/make-in-memory-store.js +438 -0
- package/cjs/lib/Store/make-ordered-dictionary.js +82 -0
- package/cjs/lib/Store/object-repository.js +28 -0
- package/cjs/lib/Types/Auth.js +3 -0
- package/cjs/lib/Types/Bussines.js +3 -0
- package/cjs/lib/Types/Call.js +3 -0
- package/cjs/lib/Types/Chat.js +11 -0
- package/cjs/lib/Types/Contact.js +3 -0
- package/cjs/lib/Types/Events.js +4 -0
- package/cjs/lib/Types/GroupMetadata.js +3 -0
- package/cjs/lib/Types/Label.js +26 -0
- package/cjs/lib/Types/LabelAssociation.js +8 -0
- package/cjs/lib/Types/Message.js +19 -0
- package/cjs/lib/Types/Mex.js +40 -0
- package/cjs/lib/Types/Product.js +3 -0
- package/cjs/lib/Types/RichType.js +24 -0
- package/cjs/lib/Types/Signal.js +4 -0
- package/cjs/lib/Types/Socket.js +4 -0
- package/cjs/lib/Types/State.js +54 -0
- package/cjs/lib/Types/USync.js +4 -0
- package/cjs/lib/Types/index.js +42 -0
- package/cjs/lib/Utils/MessageBuilder.js +2164 -0
- package/cjs/lib/Utils/auth-utils.js +312 -0
- package/cjs/lib/Utils/browser-utils.js +32 -0
- package/cjs/lib/Utils/business.js +245 -0
- package/cjs/lib/Utils/chat-utils.js +937 -0
- package/cjs/lib/Utils/companion-reg-client-utils.js +45 -0
- package/cjs/lib/Utils/crypto.js +196 -0
- package/cjs/lib/Utils/decode-wa-message.js +324 -0
- package/cjs/lib/Utils/event-buffer.js +643 -0
- package/cjs/lib/Utils/generics.js +429 -0
- package/cjs/lib/Utils/history.js +151 -0
- package/cjs/lib/Utils/identity-change-handler.js +56 -0
- package/cjs/lib/Utils/index.js +42 -0
- package/cjs/lib/Utils/link-preview.js +122 -0
- package/cjs/lib/Utils/logger.js +8 -0
- package/cjs/lib/Utils/lt-hash.js +62 -0
- package/cjs/lib/Utils/make-mutex.js +38 -0
- package/cjs/lib/Utils/message-retry-manager.js +267 -0
- package/cjs/lib/Utils/messages-media.js +933 -0
- package/cjs/lib/Utils/messages.js +2175 -0
- package/cjs/lib/Utils/noise-handler.js +205 -0
- package/cjs/lib/Utils/offline-node-processor.js +43 -0
- package/cjs/lib/Utils/pre-key-manager.js +113 -0
- package/cjs/lib/Utils/process-message.js +772 -0
- package/cjs/lib/Utils/reporting-utils.js +263 -0
- package/cjs/lib/Utils/rich-message-utils.js +439 -0
- package/cjs/lib/Utils/signal.js +214 -0
- package/cjs/lib/Utils/stanza-ack.js +41 -0
- package/cjs/lib/Utils/sync-action-utils.js +54 -0
- package/cjs/lib/Utils/tc-token-utils.js +174 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/cjs/lib/Utils/use-single-file-auth-state.js +121 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.js +182 -0
- package/cjs/lib/Utils/validate-connection.js +210 -0
- package/cjs/lib/WABinary/constants.js +1470 -0
- package/cjs/lib/WABinary/decode.js +301 -0
- package/cjs/lib/WABinary/encode.js +257 -0
- package/cjs/lib/WABinary/generic-utils.js +274 -0
- package/cjs/lib/WABinary/index.js +22 -0
- package/cjs/lib/WABinary/jid-utils.js +114 -0
- package/cjs/lib/WABinary/types.js +37 -0
- package/cjs/lib/WAM/BinaryInfo.js +14 -0
- package/cjs/lib/WAM/constants.js +22856 -0
- package/cjs/lib/WAM/encode.js +154 -0
- package/cjs/lib/WAM/index.js +20 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +56 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +67 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +29 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +55 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +33 -0
- package/cjs/lib/WAUSync/Protocols/index.js +24 -0
- package/cjs/lib/WAUSync/USyncQuery.js +126 -0
- package/cjs/lib/WAUSync/USyncUser.js +35 -0
- package/cjs/lib/WAUSync/index.js +20 -0
- package/cjs/lib/index.js +34 -0
- package/cjs/package.json +1 -0
- package/package.json +16 -5
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useSingleFileAuthState = void 0;
|
|
7
|
+
const promises_1 = require("fs/promises");
|
|
8
|
+
const index_js_1 = require("../Defaults/index.js");
|
|
9
|
+
const index_js_2 = require("../../WAProto/index.js");
|
|
10
|
+
const auth_utils_js_1 = require("./auth-utils.js");
|
|
11
|
+
const generics_js_1 = require("./generics.js");
|
|
12
|
+
const lru_cache_1 = require("lru-cache");
|
|
13
|
+
const async_mutex_1 = require("async-mutex");
|
|
14
|
+
const logger_js_1 = __importDefault(require("./logger.js"));
|
|
15
|
+
// Lia@Changes 25-03-26 --- Add useSingleFileAuthState with integrated cache
|
|
16
|
+
const FLUSH_TIMEOUT_MS = 3000;
|
|
17
|
+
// Lia@Changes 22-04-26 --- Enhanced useSingleFileAuthState with LRUCache
|
|
18
|
+
const useSingleFileAuthState = async (fileName) => {
|
|
19
|
+
const cache = new lru_cache_1.LRUCache({
|
|
20
|
+
max: 20000,
|
|
21
|
+
ttl: 1000 * index_js_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
22
|
+
updateAgeOnGet: false,
|
|
23
|
+
updateAgeOnHas: false,
|
|
24
|
+
ttlAutopurge: true
|
|
25
|
+
});
|
|
26
|
+
// Lia@Changes 26-04-26 --- Add mutex for prevent race condition
|
|
27
|
+
const mutex = new async_mutex_1.Mutex();
|
|
28
|
+
let fileData = {};
|
|
29
|
+
let isLoaded = false;
|
|
30
|
+
let flushTimeout = null;
|
|
31
|
+
const loadKey = async () => {
|
|
32
|
+
return await mutex.runExclusive(async () => {
|
|
33
|
+
if (isLoaded)
|
|
34
|
+
return;
|
|
35
|
+
try {
|
|
36
|
+
const data = JSON.parse(await (0, promises_1.readFile)(fileName, 'utf-8'), generics_js_1.BufferJSON.reviver);
|
|
37
|
+
fileData = data || {};
|
|
38
|
+
for (const [keyName, value] of Object.entries(fileData)) {
|
|
39
|
+
cache.set(keyName, value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
fileData = {};
|
|
44
|
+
}
|
|
45
|
+
isLoaded = true;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const flushKey = () => {
|
|
49
|
+
if (flushTimeout)
|
|
50
|
+
return;
|
|
51
|
+
flushTimeout = setTimeout(async () => {
|
|
52
|
+
flushTimeout = null;
|
|
53
|
+
await mutex.runExclusive(async () => {
|
|
54
|
+
try {
|
|
55
|
+
const tempFile = fileName + '.temp';
|
|
56
|
+
await (0, promises_1.writeFile)(tempFile, JSON.stringify(fileData, generics_js_1.BufferJSON.replacer));
|
|
57
|
+
await (0, promises_1.rename)(tempFile, fileName);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
// Vanz@Fix (bug 58): was silently swallowed — auth session could fail
|
|
61
|
+
// to persist (disk full, permission error, etc.) with zero trace.
|
|
62
|
+
logger_js_1.default.error({ err, fileName }, 'failed to flush auth state to disk');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}, FLUSH_TIMEOUT_MS);
|
|
66
|
+
};
|
|
67
|
+
const writeKey = (keyName, value) => {
|
|
68
|
+
cache.set(keyName, value);
|
|
69
|
+
fileData[keyName] = value;
|
|
70
|
+
flushKey();
|
|
71
|
+
};
|
|
72
|
+
const removeKey = (keyName) => {
|
|
73
|
+
cache.delete(keyName);
|
|
74
|
+
delete fileData[keyName];
|
|
75
|
+
flushKey();
|
|
76
|
+
};
|
|
77
|
+
const fileInfo = await (0, promises_1.stat)(fileName).catch(() => null);
|
|
78
|
+
if (!fileInfo) {
|
|
79
|
+
await (0, promises_1.writeFile)(fileName, '{}');
|
|
80
|
+
}
|
|
81
|
+
else if (!fileInfo.isFile()) {
|
|
82
|
+
throw new Error(`found something that is not a file at ${fileName}, either delete it or specify a different location`);
|
|
83
|
+
}
|
|
84
|
+
await loadKey();
|
|
85
|
+
const creds = fileData['creds'] || (0, auth_utils_js_1.initAuthCreds)();
|
|
86
|
+
return {
|
|
87
|
+
state: {
|
|
88
|
+
creds,
|
|
89
|
+
keys: {
|
|
90
|
+
get: (type, ids) => {
|
|
91
|
+
const data = {};
|
|
92
|
+
for (const id of ids) {
|
|
93
|
+
const keyName = type + id;
|
|
94
|
+
let value = cache.get(keyName);
|
|
95
|
+
if (value === undefined && fileData[keyName] !== undefined) {
|
|
96
|
+
value = fileData[keyName];
|
|
97
|
+
cache.set(keyName, value);
|
|
98
|
+
}
|
|
99
|
+
if (type === 'app-state-sync-key' && value) {
|
|
100
|
+
value = index_js_2.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
101
|
+
}
|
|
102
|
+
data[id] = value;
|
|
103
|
+
}
|
|
104
|
+
return data;
|
|
105
|
+
},
|
|
106
|
+
set: (data) => {
|
|
107
|
+
for (const category in data) {
|
|
108
|
+
for (const id in data[category]) {
|
|
109
|
+
const keyName = category + id;
|
|
110
|
+
const value = data[category][id];
|
|
111
|
+
value ? writeKey(keyName, value) : removeKey(keyName);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
saveCreds: () => writeKey('creds', creds)
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
exports.useSingleFileAuthState = useSingleFileAuthState;
|
|
121
|
+
//# sourceMappingURL=use-single-file-auth-state.js.map
|
|
@@ -0,0 +1,182 @@
|
|
|
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 promises_1 = require("fs/promises");
|
|
38
|
+
const path_1 = require("path");
|
|
39
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
40
|
+
const auth_utils_js_1 = require("./auth-utils.js");
|
|
41
|
+
const generics_js_1 = require("./generics.js");
|
|
42
|
+
async function loadBetterSqlite3() {
|
|
43
|
+
try {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
const mod = (await Promise.resolve().then(() => __importStar(require('better-sqlite3'))));
|
|
46
|
+
return mod.default ?? mod;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
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`).');
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
helpful.cause = err;
|
|
52
|
+
throw helpful;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const CREDS_ROW_KEY = '__creds__';
|
|
56
|
+
const CREATE_SCHEMA_SQL = `
|
|
57
|
+
CREATE TABLE IF NOT EXISTS creds (
|
|
58
|
+
key TEXT PRIMARY KEY,
|
|
59
|
+
value TEXT NOT NULL
|
|
60
|
+
);
|
|
61
|
+
CREATE TABLE IF NOT EXISTS signal_keys (
|
|
62
|
+
type TEXT NOT NULL,
|
|
63
|
+
id TEXT NOT NULL,
|
|
64
|
+
value TEXT NOT NULL,
|
|
65
|
+
PRIMARY KEY (type, id)
|
|
66
|
+
);
|
|
67
|
+
CREATE INDEX IF NOT EXISTS signal_keys_type_idx ON signal_keys(type);
|
|
68
|
+
`;
|
|
69
|
+
async function useSqliteAuthState(opts) {
|
|
70
|
+
let db;
|
|
71
|
+
if (opts.database) {
|
|
72
|
+
db = opts.database;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const Database = await loadBetterSqlite3();
|
|
76
|
+
db = new Database(opts.dbPath);
|
|
77
|
+
}
|
|
78
|
+
// WAL mode allows concurrent reads alongside a single writer; matches
|
|
79
|
+
// what SQLite recommends for read-heavy workloads with sporadic writes.
|
|
80
|
+
db.pragma('journal_mode = WAL');
|
|
81
|
+
db.pragma('synchronous = NORMAL');
|
|
82
|
+
db.exec(CREATE_SCHEMA_SQL);
|
|
83
|
+
// Vanz@Fix (bug 8): periodic WAL checkpoint + cleanup old signal keys to prevent DB bloat.
|
|
84
|
+
// Runs every 30 minutes. WAL checkpoint reclaims WAL file space; key cleanup removes stale session entries.
|
|
85
|
+
const _walCleanupInterval = setInterval(() => {
|
|
86
|
+
try {
|
|
87
|
+
db.pragma('wal_checkpoint(PASSIVE)');
|
|
88
|
+
// Remove signal keys older than 30 days (pre-keys, session keys that have expired)
|
|
89
|
+
// Only removes types that are safe to prune (not creds or app-state-sync-key)
|
|
90
|
+
const pruneTypes = ['pre-key', 'session'];
|
|
91
|
+
for (const type of pruneTypes) {
|
|
92
|
+
try {
|
|
93
|
+
// Keep last 500 per type to avoid breaking active sessions
|
|
94
|
+
db.prepare(`
|
|
95
|
+
DELETE FROM signal_keys WHERE type = ? AND id NOT IN (
|
|
96
|
+
SELECT id FROM signal_keys WHERE type = ? ORDER BY rowid DESC LIMIT 500
|
|
97
|
+
)
|
|
98
|
+
`).run(type, type);
|
|
99
|
+
}
|
|
100
|
+
catch { /* ignore per-type errors */ }
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch { /* ignore checkpoint errors — non-fatal */ }
|
|
104
|
+
}, 30 * 60 * 1000);
|
|
105
|
+
// Allow Node process to exit even if interval is still running
|
|
106
|
+
if (_walCleanupInterval.unref)
|
|
107
|
+
_walCleanupInterval.unref();
|
|
108
|
+
const stmts = {
|
|
109
|
+
credsSelect: db.prepare('SELECT value FROM creds WHERE key = ?'),
|
|
110
|
+
credsUpsert: db.prepare('INSERT INTO creds (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'),
|
|
111
|
+
keySelect: db.prepare('SELECT value FROM signal_keys WHERE type = ? AND id = ?'),
|
|
112
|
+
keyUpsert: db.prepare('INSERT INTO signal_keys (type, id, value) VALUES (?, ?, ?) ON CONFLICT(type, id) DO UPDATE SET value = excluded.value'),
|
|
113
|
+
keyDelete: db.prepare('DELETE FROM signal_keys WHERE type = ? AND id = ?'),
|
|
114
|
+
keyListIds: db.prepare('SELECT id FROM signal_keys WHERE type = ?'),
|
|
115
|
+
keyList: db.prepare('SELECT id, value FROM signal_keys WHERE type = ?'),
|
|
116
|
+
clearKeys: db.prepare('DELETE FROM signal_keys')
|
|
117
|
+
};
|
|
118
|
+
const loadCreds = () => {
|
|
119
|
+
const row = stmts.credsSelect.get(CREDS_ROW_KEY);
|
|
120
|
+
if (!row)
|
|
121
|
+
return (0, auth_utils_js_1.initAuthCreds)();
|
|
122
|
+
return JSON.parse(row.value, generics_js_1.BufferJSON.reviver);
|
|
123
|
+
};
|
|
124
|
+
const persistCreds = (creds) => {
|
|
125
|
+
stmts.credsUpsert.run(CREDS_ROW_KEY, JSON.stringify(creds, generics_js_1.BufferJSON.replacer));
|
|
126
|
+
};
|
|
127
|
+
const creds = loadCreds();
|
|
128
|
+
return {
|
|
129
|
+
state: {
|
|
130
|
+
creds,
|
|
131
|
+
keys: {
|
|
132
|
+
get: async (type, ids) => {
|
|
133
|
+
const data = {};
|
|
134
|
+
for (const id of ids) {
|
|
135
|
+
const row = stmts.keySelect.get(type, id);
|
|
136
|
+
if (row) {
|
|
137
|
+
let value = JSON.parse(row.value, generics_js_1.BufferJSON.reviver);
|
|
138
|
+
if (type === 'app-state-sync-key' && value) {
|
|
139
|
+
value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
140
|
+
}
|
|
141
|
+
data[id] = value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return data;
|
|
145
|
+
},
|
|
146
|
+
set: async (data) => {
|
|
147
|
+
const writeTx = db.transaction(() => {
|
|
148
|
+
for (const category in data) {
|
|
149
|
+
for (const id in data[category]) {
|
|
150
|
+
const value = data[category][id];
|
|
151
|
+
if (value) {
|
|
152
|
+
const stringified = JSON.stringify(value, generics_js_1.BufferJSON.replacer);
|
|
153
|
+
stmts.keyUpsert.run(category, id, stringified);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
stmts.keyDelete.run(category, id);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
writeTx();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
saveCreds: async () => {
|
|
166
|
+
persistCreds(creds);
|
|
167
|
+
},
|
|
168
|
+
// Vanz@Fix: release the WAL cleanup interval and (if we opened it ourselves)
|
|
169
|
+
// the underlying db handle. Without this, every useSqliteAuthState() call
|
|
170
|
+
// (e.g. re-pairing / rotating sessions) leaked a timer + open sqlite fd forever.
|
|
171
|
+
close: async () => {
|
|
172
|
+
clearInterval(_walCleanupInterval);
|
|
173
|
+
if (!opts.database) {
|
|
174
|
+
try {
|
|
175
|
+
db.close();
|
|
176
|
+
}
|
|
177
|
+
catch { /* already closed */ }
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=use-sqlite-auth-state.js.map
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
7
|
+
const index_js_2 = require("../Defaults/index.js");
|
|
8
|
+
const index_js_3 = require("../WABinary/index.js");
|
|
9
|
+
const crypto_js_1 = require("./crypto.js");
|
|
10
|
+
const generics_js_1 = require("./generics.js");
|
|
11
|
+
const signal_js_1 = require("./signal.js");
|
|
12
|
+
const getUserAgent = (config) => {
|
|
13
|
+
return {
|
|
14
|
+
appVersion: {
|
|
15
|
+
primary: config.version[0],
|
|
16
|
+
secondary: config.version[1],
|
|
17
|
+
tertiary: config.version[2]
|
|
18
|
+
},
|
|
19
|
+
platform: index_js_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
20
|
+
releaseChannel: index_js_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
21
|
+
osVersion: '0.1',
|
|
22
|
+
device: 'Desktop',
|
|
23
|
+
osBuildNumber: '0.1',
|
|
24
|
+
localeLanguageIso6391: 'en',
|
|
25
|
+
mnc: '000',
|
|
26
|
+
mcc: '000',
|
|
27
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const PLATFORM_MAP = {
|
|
31
|
+
'Mac OS': index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
32
|
+
Windows: index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
33
|
+
};
|
|
34
|
+
const getWebInfo = (config) => {
|
|
35
|
+
let webSubPlatform = index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
36
|
+
if (config.syncFullHistory &&
|
|
37
|
+
PLATFORM_MAP[config.browser[0]] &&
|
|
38
|
+
config.browser[1] === 'Desktop') {
|
|
39
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
40
|
+
}
|
|
41
|
+
return { webSubPlatform };
|
|
42
|
+
};
|
|
43
|
+
const getClientPayload = (config) => {
|
|
44
|
+
const payload = {
|
|
45
|
+
connectType: index_js_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
46
|
+
connectReason: index_js_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
47
|
+
userAgent: getUserAgent(config)
|
|
48
|
+
};
|
|
49
|
+
payload.webInfo = getWebInfo(config);
|
|
50
|
+
if (config.pushName) {
|
|
51
|
+
payload.pushName = config.pushName;
|
|
52
|
+
}
|
|
53
|
+
return payload;
|
|
54
|
+
};
|
|
55
|
+
const generateLoginNode = (userJid, config) => {
|
|
56
|
+
const { user, device } = (0, index_js_3.jidDecode)(userJid);
|
|
57
|
+
const payload = {
|
|
58
|
+
...getClientPayload(config),
|
|
59
|
+
passive: true,
|
|
60
|
+
pull: true,
|
|
61
|
+
username: +user,
|
|
62
|
+
device: device,
|
|
63
|
+
// Vanz@Fix (bug 49): was hardcoded false — now reads from config.lidDbMigrated (default false until investigated)
|
|
64
|
+
lidDbMigrated: config.lidDbMigrated ?? false
|
|
65
|
+
};
|
|
66
|
+
return index_js_1.proto.ClientPayload.fromObject(payload);
|
|
67
|
+
};
|
|
68
|
+
exports.generateLoginNode = generateLoginNode;
|
|
69
|
+
const getPlatformType = (platform) => {
|
|
70
|
+
const platformType = platform.toUpperCase();
|
|
71
|
+
return (index_js_1.proto.DeviceProps.PlatformType[platformType] ||
|
|
72
|
+
index_js_1.proto.DeviceProps.PlatformType.CHROME);
|
|
73
|
+
};
|
|
74
|
+
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
75
|
+
// the app version needs to be md5 hashed
|
|
76
|
+
// and passed in
|
|
77
|
+
const appVersionBuf = (0, crypto_1.createHash)('md5')
|
|
78
|
+
.update(config.version.join('.')) // join as string
|
|
79
|
+
.digest();
|
|
80
|
+
const companion = {
|
|
81
|
+
os: config.browser[0],
|
|
82
|
+
platformType: getPlatformType(config.browser[1]),
|
|
83
|
+
requireFullSync: config.syncFullHistory,
|
|
84
|
+
historySyncConfig: {
|
|
85
|
+
storageQuotaMb: 10240,
|
|
86
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
87
|
+
recentSyncDaysLimit: undefined,
|
|
88
|
+
supportCallLogHistory: false,
|
|
89
|
+
supportBotUserAgentChatHistory: true,
|
|
90
|
+
supportCagReactionsAndPolls: true,
|
|
91
|
+
supportBizHostedMsg: true,
|
|
92
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
93
|
+
supportHostedGroupMsg: true,
|
|
94
|
+
supportFbidBotChatHistory: true,
|
|
95
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
96
|
+
supportMessageAssociation: true,
|
|
97
|
+
supportGroupHistory: false,
|
|
98
|
+
onDemandReady: undefined,
|
|
99
|
+
supportGuestChat: undefined
|
|
100
|
+
},
|
|
101
|
+
version: {
|
|
102
|
+
primary: 10,
|
|
103
|
+
secondary: 15,
|
|
104
|
+
tertiary: 7
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const companionProto = index_js_1.proto.DeviceProps.encode(companion).finish();
|
|
108
|
+
const registerPayload = {
|
|
109
|
+
...getClientPayload(config),
|
|
110
|
+
passive: false,
|
|
111
|
+
pull: false,
|
|
112
|
+
devicePairingData: {
|
|
113
|
+
buildHash: appVersionBuf,
|
|
114
|
+
deviceProps: companionProto,
|
|
115
|
+
eRegid: (0, generics_js_1.encodeBigEndian)(registrationId),
|
|
116
|
+
eKeytype: index_js_2.KEY_BUNDLE_TYPE,
|
|
117
|
+
eIdent: signedIdentityKey.public,
|
|
118
|
+
eSkeyId: (0, generics_js_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
119
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
120
|
+
eSkeySig: signedPreKey.signature
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return index_js_1.proto.ClientPayload.fromObject(registerPayload);
|
|
124
|
+
};
|
|
125
|
+
exports.generateRegistrationNode = generateRegistrationNode;
|
|
126
|
+
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
127
|
+
const msgId = stanza.attrs.id;
|
|
128
|
+
const pairSuccessNode = (0, index_js_3.getBinaryNodeChild)(stanza, 'pair-success');
|
|
129
|
+
const deviceIdentityNode = (0, index_js_3.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
|
|
130
|
+
const platformNode = (0, index_js_3.getBinaryNodeChild)(pairSuccessNode, 'platform');
|
|
131
|
+
const deviceNode = (0, index_js_3.getBinaryNodeChild)(pairSuccessNode, 'device');
|
|
132
|
+
const businessNode = (0, index_js_3.getBinaryNodeChild)(pairSuccessNode, 'biz');
|
|
133
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
134
|
+
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
135
|
+
}
|
|
136
|
+
const bizName = businessNode?.attrs.name;
|
|
137
|
+
const jid = deviceNode.attrs.jid;
|
|
138
|
+
const lid = deviceNode.attrs.lid;
|
|
139
|
+
const { details, hmac, accountType } = index_js_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
140
|
+
let hmacPrefix = Buffer.from([]);
|
|
141
|
+
if (accountType !== undefined && accountType === index_js_1.proto.ADVEncryptionType.HOSTED) {
|
|
142
|
+
hmacPrefix = index_js_2.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
|
|
143
|
+
}
|
|
144
|
+
const advSign = (0, crypto_js_1.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
145
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
146
|
+
throw new boom_1.Boom('Invalid account signature');
|
|
147
|
+
}
|
|
148
|
+
const account = index_js_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
149
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
150
|
+
const deviceIdentity = index_js_1.proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
151
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === index_js_1.proto.ADVEncryptionType.HOSTED
|
|
152
|
+
? index_js_2.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
153
|
+
: index_js_2.WA_ADV_ACCOUNT_SIG_PREFIX;
|
|
154
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
155
|
+
if (!crypto_js_1.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
156
|
+
throw new boom_1.Boom('Failed to verify account signature');
|
|
157
|
+
}
|
|
158
|
+
const deviceMsg = Buffer.concat([
|
|
159
|
+
index_js_2.WA_ADV_DEVICE_SIG_PREFIX,
|
|
160
|
+
deviceDetails,
|
|
161
|
+
signedIdentityKey.public,
|
|
162
|
+
accountSignatureKey
|
|
163
|
+
]);
|
|
164
|
+
account.deviceSignature = crypto_js_1.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
165
|
+
const identity = (0, signal_js_1.createSignalIdentity)(lid, accountSignatureKey);
|
|
166
|
+
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
167
|
+
const reply = {
|
|
168
|
+
tag: 'iq',
|
|
169
|
+
attrs: {
|
|
170
|
+
to: index_js_3.S_WHATSAPP_NET,
|
|
171
|
+
type: 'result',
|
|
172
|
+
id: msgId
|
|
173
|
+
},
|
|
174
|
+
content: [
|
|
175
|
+
{
|
|
176
|
+
tag: 'pair-device-sign',
|
|
177
|
+
attrs: {},
|
|
178
|
+
content: [
|
|
179
|
+
{
|
|
180
|
+
tag: 'device-identity',
|
|
181
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
182
|
+
content: accountEnc
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
};
|
|
188
|
+
const authUpdate = {
|
|
189
|
+
account,
|
|
190
|
+
me: { id: jid, name: bizName, lid },
|
|
191
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
192
|
+
platform: platformNode?.attrs.name
|
|
193
|
+
};
|
|
194
|
+
return {
|
|
195
|
+
creds: authUpdate,
|
|
196
|
+
reply
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
200
|
+
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
201
|
+
account = { ...account };
|
|
202
|
+
// set to null if we are not to include the signature key
|
|
203
|
+
// or if we are including the signature key but it is empty
|
|
204
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
205
|
+
account.accountSignatureKey = null;
|
|
206
|
+
}
|
|
207
|
+
return index_js_1.proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
208
|
+
};
|
|
209
|
+
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
210
|
+
//# sourceMappingURL=validate-connection.js.map
|