@mrlegendbot/baileys 1.2.4 → 1.2.6
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/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +97691 -2
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.js +92 -89
- package/lib/Menu/index.d.ts +42 -0
- package/lib/Menu/index.js +283 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -9
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +22 -21
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +69 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +10 -9
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +22 -21
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +62 -56
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +40 -38
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +34 -33
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +76 -72
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -22
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +405 -506
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.js +258 -276
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +7 -6
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +49 -48
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.js +369 -349
- package/lib/Socket/chats.d.ts +125 -0
- package/lib/Socket/chats.js +1148 -1172
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.js +413 -473
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.js +331 -387
- package/lib/Socket/index.d.ts +267 -0
- package/lib/Socket/index.js +19 -6
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.js +1719 -1782
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.js +2451 -1504
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +35 -40
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.js +191 -239
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.js +923 -992
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +8 -1
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +2 -1
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +22 -20
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +4 -2
- package/lib/Types/Message.d.ts +320 -0
- package/lib/Types/Message.js +5 -3
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.js +31 -26
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +2 -1
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.js +52 -4
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +11 -10
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.js +277 -240
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +23 -20
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +204 -200
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.js +810 -836
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.js +25 -23
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +86 -70
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.js +284 -277
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.js +595 -592
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +335 -312
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.js +115 -123
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +2 -1
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +73 -74
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +2 -3
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +6 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.js +254 -213
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.js +715 -741
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.js +827 -791
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +187 -215
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +98 -69
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +586 -617
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +234 -553
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.js +170 -217
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.js +35 -27
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +41 -37
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.js +141 -120
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +105 -87
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +188 -190
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1294 -28
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +249 -245
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +206 -201
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +89 -86
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +77 -68
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +8 -7
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22853 -19892
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +132 -121
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.js +88 -79
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +29 -28
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +2 -2
- package/package.json +86 -22
- package/README.upstream.md +0 -1312
- package/WAProto/WAProto.json +0 -1
- package/WAProto/WAProto.proto +0 -6275
- package/WAProto/compiler.js +0 -550
- package/lib/Store/index.js +0 -8
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Store/make-cache-manager-store.js +0 -70
- package/lib/Store/make-in-memory-store.js +0 -417
- package/lib/Store/make-ordered-dictionary.js +0 -69
- package/lib/Store/object-repository.js +0 -27
- package/lib/Utils/use-sqlite-auth-state.js +0 -162
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { mkdir, readdir, readFile } from 'fs/promises';
|
|
2
|
-
import { dirname, join } from 'path';
|
|
3
|
-
import { proto } from '../../WAProto/compiler.js';
|
|
4
|
-
import { initAuthCreds } from './auth-utils.js';
|
|
5
|
-
export const useSqliteAuthState = async (pathOrFolder, options = {}) => {
|
|
6
|
-
const {
|
|
7
|
-
fileName = 'auth.db',
|
|
8
|
-
migrateFromFolder,
|
|
9
|
-
logger
|
|
10
|
-
} = options;
|
|
11
|
-
const dbPath = /\.(db|sqlite|sqlite3)$/i.test(pathOrFolder) ? pathOrFolder : join(pathOrFolder, fileName);
|
|
12
|
-
const bufReplacer = (_, value) => {
|
|
13
|
-
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value?.type === 'Buffer') {
|
|
14
|
-
return {
|
|
15
|
-
type: 'Buffer',
|
|
16
|
-
data: Buffer.from(value?.data || value).toString('base64')
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return value;
|
|
20
|
-
};
|
|
21
|
-
const bufReviver = (_, value) => {
|
|
22
|
-
if (value && typeof value === 'object' && value.type === 'Buffer' && typeof value.data === 'string') {
|
|
23
|
-
return Buffer.from(value.data, 'base64');
|
|
24
|
-
}
|
|
25
|
-
return value;
|
|
26
|
-
};
|
|
27
|
-
const encode = value => {
|
|
28
|
-
if (Buffer.isBuffer(value) || value instanceof Uint8Array) {
|
|
29
|
-
return Buffer.concat([Buffer.from([1]), Buffer.from(value)]);
|
|
30
|
-
}
|
|
31
|
-
return Buffer.concat([Buffer.from([0]), Buffer.from(JSON.stringify(value, bufReplacer), 'utf8')]);
|
|
32
|
-
};
|
|
33
|
-
const decode = blob => {
|
|
34
|
-
if (!blob || blob.length === 0) return null;
|
|
35
|
-
if (blob[0] === 1) return Buffer.from(blob.subarray(1));
|
|
36
|
-
return JSON.parse(Buffer.from(blob.subarray(1)).toString('utf8'), bufReviver);
|
|
37
|
-
};
|
|
38
|
-
const fixName = s => s?.replace(/\//g, '__')?.replace(/:/g, '-');
|
|
39
|
-
const keyOf = (category, id) => fixName(`${category}-${id}`);
|
|
40
|
-
let DatabaseSync;
|
|
41
|
-
try {
|
|
42
|
-
({
|
|
43
|
-
DatabaseSync
|
|
44
|
-
} = await import('node:sqlite'));
|
|
45
|
-
} catch (err) {
|
|
46
|
-
throw new Error("useSqliteAuthState needs the built-in 'node:sqlite' module (Node 22.5+). Upgrade Node, or use useMultiFileAuthState instead.");
|
|
47
|
-
}
|
|
48
|
-
await mkdir(dirname(dbPath), {
|
|
49
|
-
recursive: true
|
|
50
|
-
}).catch(() => {});
|
|
51
|
-
const db = new DatabaseSync(dbPath);
|
|
52
|
-
db.exec('PRAGMA journal_mode = TRUNCATE');
|
|
53
|
-
db.exec('PRAGMA synchronous = NORMAL');
|
|
54
|
-
db.exec('PRAGMA busy_timeout = 5000');
|
|
55
|
-
db.exec('CREATE TABLE IF NOT EXISTS auth_state (k TEXT PRIMARY KEY, v BLOB NOT NULL) WITHOUT ROWID');
|
|
56
|
-
const qGet = db.prepare('SELECT v FROM auth_state WHERE k = ?');
|
|
57
|
-
const qUpsert = db.prepare('INSERT INTO auth_state(k,v) VALUES(?,?) ON CONFLICT(k) DO UPDATE SET v=excluded.v');
|
|
58
|
-
const qDelete = db.prepare('DELETE FROM auth_state WHERE k = ?');
|
|
59
|
-
const runTx = fn => {
|
|
60
|
-
db.exec('BEGIN');
|
|
61
|
-
try {
|
|
62
|
-
const r = fn();
|
|
63
|
-
db.exec('COMMIT');
|
|
64
|
-
return r;
|
|
65
|
-
} catch (err) {
|
|
66
|
-
db.exec('ROLLBACK');
|
|
67
|
-
throw err;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const readRaw = k => {
|
|
71
|
-
const row = qGet.get(k);
|
|
72
|
-
if (!row) return null;
|
|
73
|
-
try {
|
|
74
|
-
return decode(row.v);
|
|
75
|
-
} catch (err) {
|
|
76
|
-
logger?.warn?.({
|
|
77
|
-
k,
|
|
78
|
-
err: err?.message
|
|
79
|
-
}, 'sqlite-auth: failed to decode row, treating as missing');
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const runMigration = async folder => {
|
|
84
|
-
let files;
|
|
85
|
-
try {
|
|
86
|
-
files = await readdir(folder);
|
|
87
|
-
} catch {
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
90
|
-
const rows = [];
|
|
91
|
-
for (const file of files) {
|
|
92
|
-
if (!file.endsWith('.json')) continue;
|
|
93
|
-
let value;
|
|
94
|
-
try {
|
|
95
|
-
value = JSON.parse(await readFile(join(folder, file), 'utf8'), bufReviver);
|
|
96
|
-
} catch {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (value === null || value === undefined) continue;
|
|
100
|
-
rows.push([file.slice(0, -'.json'.length), encode(value)]);
|
|
101
|
-
}
|
|
102
|
-
runTx(() => {
|
|
103
|
-
for (const [k, v] of rows) qUpsert.run(k, v);
|
|
104
|
-
});
|
|
105
|
-
return rows.length;
|
|
106
|
-
};
|
|
107
|
-
const hasCreds = () => !!qGet.get('creds');
|
|
108
|
-
if (migrateFromFolder && !hasCreds()) {
|
|
109
|
-
const n = await runMigration(migrateFromFolder);
|
|
110
|
-
if (n > 0) logger?.info?.({
|
|
111
|
-
count: n,
|
|
112
|
-
from: migrateFromFolder
|
|
113
|
-
}, 'sqlite-auth: migrated legacy auth state');
|
|
114
|
-
}
|
|
115
|
-
let creds = readRaw('creds');
|
|
116
|
-
if (!creds) {
|
|
117
|
-
creds = initAuthCreds();
|
|
118
|
-
qUpsert.run('creds', encode(creds));
|
|
119
|
-
}
|
|
120
|
-
const keys = {
|
|
121
|
-
get: async (type, ids) => {
|
|
122
|
-
const data = {};
|
|
123
|
-
for (const id of ids) {
|
|
124
|
-
let value = readRaw(keyOf(type, id));
|
|
125
|
-
if (type === 'app-state-sync-key' && value) {
|
|
126
|
-
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
127
|
-
}
|
|
128
|
-
if (value !== null && value !== undefined) {
|
|
129
|
-
data[id] = value;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return data;
|
|
133
|
-
},
|
|
134
|
-
set: async data => {
|
|
135
|
-
const ops = [];
|
|
136
|
-
for (const category in data) {
|
|
137
|
-
for (const id in data[category]) {
|
|
138
|
-
ops.push([keyOf(category, id), data[category][id]]);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
runTx(() => {
|
|
142
|
-
for (const [k, value] of ops) {
|
|
143
|
-
if (value === null || value === undefined) qDelete.run(k);else qUpsert.run(k, encode(value));
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
},
|
|
147
|
-
clear: async () => {
|
|
148
|
-
db.prepare("DELETE FROM auth_state WHERE k <> 'creds'").run();
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
return {
|
|
152
|
-
state: {
|
|
153
|
-
creds,
|
|
154
|
-
keys
|
|
155
|
-
},
|
|
156
|
-
saveCreds: async () => {
|
|
157
|
-
qUpsert.run('creds', encode(creds));
|
|
158
|
-
},
|
|
159
|
-
db,
|
|
160
|
-
close: () => db.close()
|
|
161
|
-
};
|
|
162
|
-
};
|