@baileys-md/baileys 11.0.3 → 11.1.0
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/LICENSE +1 -1
- package/README.md +1 -1
- package/WAProto/index.js +4182 -13516
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +71 -52
- package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
- package/lib/Signal/libsignal.js +61 -41
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.js +42 -37
- package/lib/Socket/chats.js +187 -194
- package/lib/Socket/groups.js +90 -87
- package/lib/Socket/index.js +8 -7
- package/lib/Socket/messages-recv.js +335 -360
- package/lib/Socket/messages-send.js +279 -156
- package/lib/Socket/newsletter.js +213 -144
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +161 -128
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
- package/lib/Store/make-mongo-store.js +567 -0
- package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
- package/lib/{Utils → Store}/object-repository.js +4 -1
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +17 -30
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +47 -31
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +195 -200
- package/lib/Utils/crypto.js +85 -70
- package/lib/Utils/decode-wa-message.js +51 -46
- package/lib/Utils/event-buffer.js +46 -36
- package/lib/Utils/generics.js +188 -116
- package/lib/Utils/history.js +46 -37
- package/lib/Utils/index.js +33 -19
- package/lib/Utils/link-preview.js +55 -14
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.js +368 -239
- package/lib/Utils/messages.js +510 -278
- package/lib/Utils/noise-handler.js +31 -22
- package/lib/Utils/process-message.js +148 -144
- package/lib/Utils/signal.js +64 -71
- package/lib/Utils/use-multi-file-auth-state.js +32 -14
- package/lib/Utils/validate-connection.js +115 -72
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.js +52 -15
- package/lib/WABinary/encode.js +48 -14
- package/lib/WABinary/generic-utils.js +39 -31
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +40 -23
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +2366 -2257
- package/lib/WAM/encode.js +21 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.js +32 -34
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +33 -11
- package/package.json +61 -21
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -4633
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/baileys-version.js +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -94
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -19
- package/lib/Signal/Group/queue-job.js +0 -54
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -67
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -50
- package/lib/Signal/Group/sender-key-state.js +0 -96
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/mex.js +0 -42
package/lib/Socket/usync.js
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeUSyncSocket = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const socket_1 = require("./socket");
|
|
7
|
+
const makeUSyncSocket = (config) => {
|
|
8
|
+
const sock = (0, socket_1.makeSocket)(config);
|
|
9
|
+
const { generateMessageTag, query, } = sock;
|
|
8
10
|
const executeUSyncQuery = async (usyncQuery) => {
|
|
9
11
|
if (usyncQuery.protocols.length === 0) {
|
|
10
|
-
throw new Boom('USyncQuery must have at least one protocol');
|
|
12
|
+
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
|
11
13
|
}
|
|
12
14
|
// todo: validate users, throw WARNING on no valid users
|
|
13
15
|
// variable below has only validated users
|
|
14
16
|
const validUsers = usyncQuery.users;
|
|
15
|
-
const userNodes = validUsers.map(user => {
|
|
17
|
+
const userNodes = validUsers.map((user) => {
|
|
16
18
|
return {
|
|
17
19
|
tag: 'user',
|
|
18
20
|
attrs: {
|
|
19
|
-
jid: !user.phone ? user.id : undefined
|
|
21
|
+
jid: !user.phone ? user.id : undefined,
|
|
20
22
|
},
|
|
21
|
-
content: usyncQuery.protocols
|
|
23
|
+
content: usyncQuery.protocols
|
|
24
|
+
.map((a) => a.getUserElement(user))
|
|
25
|
+
.filter(a => a !== null)
|
|
22
26
|
};
|
|
23
27
|
});
|
|
24
28
|
const listNode = {
|
|
@@ -29,14 +33,14 @@ export const makeUSyncSocket = (config) => {
|
|
|
29
33
|
const queryNode = {
|
|
30
34
|
tag: 'query',
|
|
31
35
|
attrs: {},
|
|
32
|
-
content: usyncQuery.protocols.map(a => a.getQueryElement())
|
|
36
|
+
content: usyncQuery.protocols.map((a) => a.getQueryElement())
|
|
33
37
|
};
|
|
34
38
|
const iq = {
|
|
35
39
|
tag: 'iq',
|
|
36
40
|
attrs: {
|
|
37
|
-
to: S_WHATSAPP_NET,
|
|
41
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
38
42
|
type: 'get',
|
|
39
|
-
xmlns: 'usync'
|
|
43
|
+
xmlns: 'usync',
|
|
40
44
|
},
|
|
41
45
|
content: [
|
|
42
46
|
{
|
|
@@ -46,18 +50,21 @@ export const makeUSyncSocket = (config) => {
|
|
|
46
50
|
mode: usyncQuery.mode,
|
|
47
51
|
sid: generateMessageTag(),
|
|
48
52
|
last: 'true',
|
|
49
|
-
index: '0'
|
|
53
|
+
index: '0',
|
|
50
54
|
},
|
|
51
|
-
content: [
|
|
55
|
+
content: [
|
|
56
|
+
queryNode,
|
|
57
|
+
listNode
|
|
58
|
+
]
|
|
52
59
|
}
|
|
53
|
-
]
|
|
60
|
+
],
|
|
54
61
|
};
|
|
55
62
|
const result = await query(iq);
|
|
56
63
|
return usyncQuery.parseUSyncQueryResult(result);
|
|
57
64
|
};
|
|
58
65
|
return {
|
|
59
66
|
...sock,
|
|
60
|
-
executeUSyncQuery
|
|
67
|
+
executeUSyncQuery,
|
|
61
68
|
};
|
|
62
69
|
};
|
|
63
|
-
|
|
70
|
+
exports.makeUSyncSocket = makeUSyncSocket;
|
|
@@ -0,0 +1,8 @@
|
|
|
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.makeInMemoryStore = void 0;
|
|
7
|
+
const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
|
|
8
|
+
exports.makeInMemoryStore = make_in_memory_store_1.default;
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
const cache_manager_1 = require("cache-manager");
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const Utils_1 = require("../Utils");
|
|
9
|
+
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
10
|
+
const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
11
|
+
const defaultKey = (file) => `${sessionKey}:${file}`;
|
|
12
|
+
const databaseConn = await (0, cache_manager_1.caching)(store);
|
|
13
|
+
const writeData = async (file, data) => {
|
|
14
|
+
let ttl = undefined;
|
|
15
|
+
if (file === 'creds') {
|
|
16
|
+
ttl = 63115200; // 2 years
|
|
17
|
+
}
|
|
18
|
+
await databaseConn.set(defaultKey(file), JSON.stringify(data, Utils_1.BufferJSON.replacer), ttl);
|
|
19
|
+
};
|
|
20
|
+
const readData = async (file) => {
|
|
21
|
+
try {
|
|
22
|
+
const data = await databaseConn.get(defaultKey(file));
|
|
23
|
+
if (data) {
|
|
24
|
+
return JSON.parse(data, Utils_1.BufferJSON.reviver);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
logger_1.default.error(error);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const removeData = async (file) => {
|
|
34
|
+
try {
|
|
35
|
+
return await databaseConn.del(defaultKey(file));
|
|
36
|
+
}
|
|
37
|
+
catch (_a) {
|
|
38
|
+
logger_1.default.error(`Error removing ${file} from session ${sessionKey}`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const clearState = async () => {
|
|
42
|
+
try {
|
|
43
|
+
const result = await databaseConn.store.keys(`${sessionKey}*`);
|
|
44
|
+
await Promise.all(result.map(async (key) => await databaseConn.del(key)));
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const creds = (await readData('creds')) || (0, Utils_1.initAuthCreds)();
|
|
50
|
+
return {
|
|
51
|
+
clearState,
|
|
52
|
+
saveCreds: () => writeData('creds', creds),
|
|
53
|
+
state: {
|
|
54
|
+
creds,
|
|
55
|
+
keys: {
|
|
56
|
+
get: async (type, ids) => {
|
|
57
|
+
const data = {};
|
|
58
|
+
await Promise.all(ids.map(async (id) => {
|
|
59
|
+
let value = await readData(`${type}-${id}`);
|
|
60
|
+
if (type === 'app-state-sync-key' && value) {
|
|
61
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
62
|
+
}
|
|
63
|
+
data[id] = value;
|
|
64
|
+
}));
|
|
65
|
+
return data;
|
|
66
|
+
},
|
|
67
|
+
set: async (data) => {
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
const tasks = [];
|
|
70
|
+
for (const category in data) {
|
|
71
|
+
for (const id in data[category]) {
|
|
72
|
+
const value = data[category][id];
|
|
73
|
+
const key = `${category}-${id}`;
|
|
74
|
+
tasks.push(value ? writeData(key, value) : removeData(key));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
await Promise.all(tasks);
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
exports.default = makeCacheManagerAuthState;
|
|
@@ -1,26 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.waLabelAssociationKey = exports.waMessageID = exports.waChatKey = void 0;
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const Defaults_1 = require("../Defaults");
|
|
9
|
+
const LabelAssociation_1 = require("../Types/LabelAssociation");
|
|
10
|
+
const Utils_1 = require("../Utils");
|
|
11
|
+
const WABinary_1 = require("../WABinary");
|
|
12
|
+
const make_ordered_dictionary_1 = __importDefault(require("./make-ordered-dictionary"));
|
|
13
|
+
const object_repository_1 = require("./object-repository");
|
|
14
|
+
const waChatKey = (pin) => ({
|
|
9
15
|
key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
|
|
10
16
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
11
17
|
});
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
exports.waChatKey = waChatKey;
|
|
19
|
+
const waMessageID = (m) => m.key.id || '';
|
|
20
|
+
exports.waMessageID = waMessageID;
|
|
21
|
+
exports.waLabelAssociationKey = {
|
|
14
22
|
key: (la) => (la.type === LabelAssociation_1.LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
|
|
15
23
|
compare: (k1, k2) => k2.localeCompare(k1)
|
|
16
24
|
};
|
|
17
|
-
const makeMessagesDictionary = () => (0, make_ordered_dictionary_1.
|
|
18
|
-
|
|
25
|
+
const makeMessagesDictionary = () => (0, make_ordered_dictionary_1.default)(exports.waMessageID);
|
|
26
|
+
exports.default = (config) => {
|
|
19
27
|
const socket = config.socket;
|
|
20
|
-
const chatKey = config.chatKey || (0, waChatKey)(true);
|
|
21
|
-
const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
|
|
28
|
+
const chatKey = config.chatKey || (0, exports.waChatKey)(true);
|
|
29
|
+
const labelAssociationKey = config.labelAssociationKey || exports.waLabelAssociationKey;
|
|
22
30
|
const logger = config.logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
|
|
23
|
-
const KeyedDB = (
|
|
31
|
+
const KeyedDB = require('@baileys-md/keyed-db').default;
|
|
24
32
|
const chats = new KeyedDB(chatKey, c => c.id);
|
|
25
33
|
const messages = {};
|
|
26
34
|
const contacts = {};
|
|
@@ -404,14 +412,14 @@ export const makeInMemoryStore = async (config) => {
|
|
|
404
412
|
},
|
|
405
413
|
toJSON,
|
|
406
414
|
fromJSON,
|
|
407
|
-
writeToFile:
|
|
415
|
+
writeToFile: (path) => {
|
|
408
416
|
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
409
|
-
const { writeFileSync } =
|
|
417
|
+
const { writeFileSync } = require('fs');
|
|
410
418
|
writeFileSync(path, JSON.stringify(toJSON()));
|
|
411
419
|
},
|
|
412
|
-
readFromFile:
|
|
420
|
+
readFromFile: (path) => {
|
|
413
421
|
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
414
|
-
const { readFileSync, existsSync } =
|
|
422
|
+
const { readFileSync, existsSync } = require('fs');
|
|
415
423
|
if (existsSync(path)) {
|
|
416
424
|
logger.debug({ path }, 'reading from file');
|
|
417
425
|
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|