austiin-baileys 1.1.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/LICENSE +26 -0
- package/README.md +2579 -0
- package/WAProto/AICommon/AICommon.js +19396 -0
- package/WAProto/AICommon/AICommon.proto +820 -0
- package/WAProto/Adv/Adv.js +1137 -0
- package/WAProto/Adv/Adv.proto +42 -0
- package/WAProto/BotMetadata/BotMetadata.js +8975 -0
- package/WAProto/BotMetadata/BotMetadata.proto +484 -0
- package/WAProto/Cert/Cert.js +893 -0
- package/WAProto/Cert/Cert.proto +30 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
- package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
- package/WAProto/CompanionReg/CompanionReg.js +2457 -0
- package/WAProto/CompanionReg/CompanionReg.proto +103 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
- package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
- package/WAProto/E2E/E2E.js +78728 -0
- package/WAProto/E2E/E2E.proto +1970 -0
- package/WAProto/Ephemeral/Ephemeral.js +143 -0
- package/WAProto/Ephemeral/Ephemeral.proto +7 -0
- package/WAProto/HistorySync/HistorySync.js +95931 -0
- package/WAProto/HistorySync/HistorySync.proto +229 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
- package/WAProto/MmsRetry/MmsRetry.js +310 -0
- package/WAProto/MmsRetry/MmsRetry.proto +19 -0
- package/WAProto/Protocol/Protocol.js +399 -0
- package/WAProto/Protocol/Protocol.proto +22 -0
- package/WAProto/Reporting/Reporting.js +535 -0
- package/WAProto/Reporting/Reporting.proto +22 -0
- package/WAProto/ServerSync/ServerSync.js +1830 -0
- package/WAProto/ServerSync/ServerSync.proto +70 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
- package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
- package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
- package/WAProto/SyncAction/SyncAction.js +17424 -0
- package/WAProto/SyncAction/SyncAction.proto +663 -0
- package/WAProto/UserPassword/UserPassword.js +544 -0
- package/WAProto/UserPassword/UserPassword.proto +28 -0
- package/WAProto/VnameCert/VnameCert.js +1466 -0
- package/WAProto/VnameCert/VnameCert.proto +65 -0
- package/WAProto/Wa6/Wa6.js +4601 -0
- package/WAProto/Wa6/Wa6.proto +241 -0
- package/WAProto/Web/Web.js +90819 -0
- package/WAProto/Web/Web.proto +605 -0
- package/WAProto/index.js +30 -0
- package/engine-requirements.js +9 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -0
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +14 -0
- package/lib/Signal/Group/group-session-builder.js +46 -0
- package/lib/Signal/Group/group_cipher.js +104 -0
- package/lib/Signal/Group/index.js +42 -0
- package/lib/Signal/Group/keyhelper.js +21 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +78 -0
- package/lib/Signal/Group/sender-key-name.js +49 -0
- package/lib/Signal/Group/sender-key-record.js +45 -0
- package/lib/Signal/Group/sender-key-state.js +100 -0
- package/lib/Signal/Group/sender-message-key.js +28 -0
- package/lib/Signal/libsignal.js +364 -0
- package/lib/Signal/lid-mapping.js +164 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +31 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.js +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/Client/websocket.js +67 -0
- package/lib/Socket/business.js +291 -0
- package/lib/Socket/chats.js +874 -0
- package/lib/Socket/community.js +454 -0
- package/lib/Socket/groups.js +357 -0
- package/lib/Socket/idk-bruh.js +637 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/messages-recv.js +1488 -0
- package/lib/Socket/messages-send.js +1483 -0
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +169 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.js +898 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +35 -0
- package/lib/Store/make-cache-manager-store.js +77 -0
- package/lib/Store/make-in-memory-store.js +423 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +26 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +4 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/MexUpdates.js +15 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +9 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +59 -0
- package/lib/Utils/auth-utils.js +256 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +233 -0
- package/lib/Utils/chat-utils.js +896 -0
- package/lib/Utils/crypto.js +144 -0
- package/lib/Utils/decode-wa-message.js +305 -0
- package/lib/Utils/event-buffer.js +555 -0
- package/lib/Utils/generics.js +405 -0
- package/lib/Utils/history.js +100 -0
- package/lib/Utils/index.js +49 -0
- package/lib/Utils/link-preview.js +76 -0
- package/lib/Utils/logger.js +4 -0
- package/lib/Utils/lt-hash.js +45 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-retry-manager.js +134 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.js +2016 -0
- package/lib/Utils/noise-handler.js +157 -0
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +814 -0
- package/lib/Utils/signal.js +183 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -0
- package/lib/Utils/validate-connection.js +229 -0
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1308 -0
- package/lib/WABinary/decode.js +233 -0
- package/lib/WABinary/encode.js +212 -0
- package/lib/WABinary/generic-utils.js +124 -0
- package/lib/WABinary/index.js +36 -0
- package/lib/WABinary/jid-utils.js +101 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +12 -0
- package/lib/WAM/constants.js +20491 -0
- package/lib/WAM/encode.js +148 -0
- package/lib/WAM/index.js +34 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +37 -0
- package/lib/WAUSync/USyncQuery.js +92 -0
- package/lib/WAUSync/USyncUser.js +25 -0
- package/lib/WAUSync/index.js +34 -0
- package/lib/index.js +106 -0
- package/package.json +90 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { Mutex: AsyncMutex } = require("async-mutex");
|
|
4
|
+
const makeMutex = () => {
|
|
5
|
+
const mutex = new AsyncMutex();
|
|
6
|
+
return {
|
|
7
|
+
mutex(code) {
|
|
8
|
+
return mutex.runExclusive(code);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const makeKeyedMutex = () => {
|
|
13
|
+
const map = new Map();
|
|
14
|
+
return {
|
|
15
|
+
async mutex(key, task) {
|
|
16
|
+
let entry = map.get(key);
|
|
17
|
+
if (!entry) {
|
|
18
|
+
entry = { mutex: new AsyncMutex(), refCount: 0 };
|
|
19
|
+
map.set(key, entry);
|
|
20
|
+
}
|
|
21
|
+
entry.refCount++;
|
|
22
|
+
try {
|
|
23
|
+
return await entry.mutex.runExclusive(task);
|
|
24
|
+
} finally {
|
|
25
|
+
entry.refCount--;
|
|
26
|
+
if (entry.refCount === 0 && map.get(key) === entry) {
|
|
27
|
+
map.delete(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
module.exports = { makeMutex: makeMutex, makeKeyedMutex: makeKeyedMutex };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { LRUCache: LRUCache } = require("lru-cache");
|
|
4
|
+
const RECENT_MESSAGES_SIZE = 512;
|
|
5
|
+
const MESSAGE_KEY_SEPARATOR = "\0";
|
|
6
|
+
const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1e3;
|
|
7
|
+
const PHONE_REQUEST_DELAY = 3e3;
|
|
8
|
+
class MessageRetryManager {
|
|
9
|
+
constructor(logger, maxMsgRetryCount) {
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
this.recentMessagesMap = new LRUCache({
|
|
12
|
+
max: RECENT_MESSAGES_SIZE,
|
|
13
|
+
ttl: 5 * 60 * 1e3,
|
|
14
|
+
ttlAutopurge: true,
|
|
15
|
+
dispose: (_value, key) => {
|
|
16
|
+
const separatorIndex = key.lastIndexOf(MESSAGE_KEY_SEPARATOR);
|
|
17
|
+
if (separatorIndex > -1) {
|
|
18
|
+
const messageId = key.slice(separatorIndex + MESSAGE_KEY_SEPARATOR.length);
|
|
19
|
+
this.messageKeyIndex.delete(messageId);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
this.messageKeyIndex = new Map();
|
|
24
|
+
this.sessionRecreateHistory = new LRUCache({
|
|
25
|
+
ttl: RECREATE_SESSION_TIMEOUT * 2,
|
|
26
|
+
ttlAutopurge: true,
|
|
27
|
+
});
|
|
28
|
+
this.retryCounters = new LRUCache({
|
|
29
|
+
ttl: 15 * 60 * 1e3,
|
|
30
|
+
ttlAutopurge: true,
|
|
31
|
+
updateAgeOnGet: true,
|
|
32
|
+
});
|
|
33
|
+
this.pendingPhoneRequests = {};
|
|
34
|
+
this.maxMsgRetryCount = 5;
|
|
35
|
+
this.statistics = {
|
|
36
|
+
totalRetries: 0,
|
|
37
|
+
successfulRetries: 0,
|
|
38
|
+
failedRetries: 0,
|
|
39
|
+
mediaRetries: 0,
|
|
40
|
+
sessionRecreations: 0,
|
|
41
|
+
phoneRequests: 0,
|
|
42
|
+
};
|
|
43
|
+
this.maxMsgRetryCount = maxMsgRetryCount;
|
|
44
|
+
}
|
|
45
|
+
addRecentMessage(to, id, message) {
|
|
46
|
+
const key = { to: to, id: id };
|
|
47
|
+
const keyStr = this.keyToString(key);
|
|
48
|
+
this.recentMessagesMap.set(keyStr, {
|
|
49
|
+
message: message,
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
});
|
|
52
|
+
this.messageKeyIndex.set(id, keyStr);
|
|
53
|
+
this.logger.debug(`Added message to retry cache: ${to}/${id}`);
|
|
54
|
+
}
|
|
55
|
+
getRecentMessage(to, id) {
|
|
56
|
+
const key = { to: to, id: id };
|
|
57
|
+
const keyStr = this.keyToString(key);
|
|
58
|
+
return this.recentMessagesMap.get(keyStr);
|
|
59
|
+
}
|
|
60
|
+
shouldRecreateSession(jid, retryCount, hasSession) {
|
|
61
|
+
if (!hasSession) {
|
|
62
|
+
this.sessionRecreateHistory.set(jid, Date.now());
|
|
63
|
+
this.statistics.sessionRecreations++;
|
|
64
|
+
return {
|
|
65
|
+
reason: "we don't have a Signal session with them",
|
|
66
|
+
recreate: true,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (retryCount < 2) {
|
|
70
|
+
return { reason: "", recreate: false };
|
|
71
|
+
}
|
|
72
|
+
const now = Date.now();
|
|
73
|
+
const prevTime = this.sessionRecreateHistory.get(jid);
|
|
74
|
+
if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
|
|
75
|
+
this.sessionRecreateHistory.set(jid, now);
|
|
76
|
+
this.statistics.sessionRecreations++;
|
|
77
|
+
return {
|
|
78
|
+
reason: "retry count > 1 and over an hour since last recreation",
|
|
79
|
+
recreate: true,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return { reason: "", recreate: false };
|
|
83
|
+
}
|
|
84
|
+
incrementRetryCount(messageId) {
|
|
85
|
+
this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
|
|
86
|
+
this.statistics.totalRetries++;
|
|
87
|
+
return this.retryCounters.get(messageId);
|
|
88
|
+
}
|
|
89
|
+
getRetryCount(messageId) {
|
|
90
|
+
return this.retryCounters.get(messageId) || 0;
|
|
91
|
+
}
|
|
92
|
+
hasExceededMaxRetries(messageId) {
|
|
93
|
+
return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
|
|
94
|
+
}
|
|
95
|
+
markRetrySuccess(messageId) {
|
|
96
|
+
this.statistics.successfulRetries++;
|
|
97
|
+
this.retryCounters.delete(messageId);
|
|
98
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
99
|
+
this.removeRecentMessage(messageId);
|
|
100
|
+
}
|
|
101
|
+
markRetryFailed(messageId) {
|
|
102
|
+
this.statistics.failedRetries++;
|
|
103
|
+
this.retryCounters.delete(messageId);
|
|
104
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
105
|
+
this.removeRecentMessage(messageId);
|
|
106
|
+
}
|
|
107
|
+
schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
|
|
108
|
+
this.cancelPendingPhoneRequest(messageId);
|
|
109
|
+
this.pendingPhoneRequests[messageId] = setTimeout(() => {
|
|
110
|
+
delete this.pendingPhoneRequests[messageId];
|
|
111
|
+
this.statistics.phoneRequests++;
|
|
112
|
+
callback();
|
|
113
|
+
}, delay);
|
|
114
|
+
this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
|
|
115
|
+
}
|
|
116
|
+
cancelPendingPhoneRequest(messageId) {
|
|
117
|
+
const timeout = this.pendingPhoneRequests[messageId];
|
|
118
|
+
if (timeout) {
|
|
119
|
+
clearTimeout(timeout);
|
|
120
|
+
delete this.pendingPhoneRequests[messageId];
|
|
121
|
+
this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
keyToString(key) {
|
|
125
|
+
return `${key.to}${MESSAGE_KEY_SEPARATOR}${key.id}`;
|
|
126
|
+
}
|
|
127
|
+
removeRecentMessage(messageId) {
|
|
128
|
+
const keyStr = this.messageKeyIndex.get(messageId);
|
|
129
|
+
if (!keyStr) return;
|
|
130
|
+
this.recentMessagesMap.delete(keyStr);
|
|
131
|
+
this.messageKeyIndex.delete(messageId);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
module.exports = { MessageRetryManager: MessageRetryManager };
|