astrabail 1.0.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/WAProto.proto +5479 -0
- package/WAProto/fix-imports.js +73 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +89351 -0
- package/WAProto/p.html +1 -0
- package/engine-requirements.js +7 -0
- package/lib/Defaults/astrabail-version.json +8 -0
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +166 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/update-wa-version.js +75 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +66 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +85 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +29 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +44 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +87 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +478 -0
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +14 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +60 -0
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.js +382 -0
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +1155 -0
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.js +438 -0
- package/lib/Socket/community.js +333 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +470 -0
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.js +13 -0
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.js +1708 -0
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.js +1692 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.js +293 -0
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +947 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.js +20 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +398 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +3 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/MexUpdates.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +43 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +3 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +14 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +3 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/astrabail-event-stream.js +3 -0
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +298 -0
- package/lib/Utils/baileys-event-stream.js +60 -0
- package/lib/Utils/bridge-runtime.d.ts +1 -0
- package/lib/Utils/bridge-runtime.js +14 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +44 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +240 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +825 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +168 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +287 -0
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +580 -0
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +483 -0
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +137 -0
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +54 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +48 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +121 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +10 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +37 -0
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +226 -0
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +887 -0
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +295 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.js +1752 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +204 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +112 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +536 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +95 -0
- package/lib/Utils/rust-bridge-shim.d.ts +22 -0
- package/lib/Utils/rust-bridge-shim.js +70 -0
- package/lib/Utils/serial-task-queue.js +29 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +170 -0
- package/lib/Utils/streamToBuffer.js +17 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +20 -0
- package/lib/Utils/use-mongo-file-auth-state.js +71 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +124 -0
- package/lib/Utils/use-single-file-auth-state.js +73 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +206 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +300 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +256 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +138 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +25 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +115 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +36 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22855 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +153 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +41 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +54 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +32 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +22 -0
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +124 -0
- package/package.json +120 -0
- package/readme.md +1956 -0
|
@@ -0,0 +1,298 @@
|
|
|
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.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
7
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
8
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
9
|
+
const async_hooks_1 = require("async_hooks");
|
|
10
|
+
const async_mutex_1 = require("async-mutex");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
const serial_task_queue_js_1 = __importDefault(require("./serial-task-queue.js"));
|
|
13
|
+
const index_js_1 = require("../Defaults/index.js");
|
|
14
|
+
const crypto_js_1 = require("./crypto.js");
|
|
15
|
+
const generics_js_1 = require("./generics.js");
|
|
16
|
+
const pre_key_manager_js_1 = require("./pre-key-manager.js");
|
|
17
|
+
/**
|
|
18
|
+
* Adds caching capability to a SignalKeyStore
|
|
19
|
+
* @param store the store to add caching to
|
|
20
|
+
* @param logger to log trace events
|
|
21
|
+
* @param _cache cache store to use
|
|
22
|
+
*/
|
|
23
|
+
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
24
|
+
const cache = _cache ||
|
|
25
|
+
new node_cache_1.default({
|
|
26
|
+
stdTTL: index_js_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
27
|
+
useClones: false,
|
|
28
|
+
deleteOnExpire: true
|
|
29
|
+
});
|
|
30
|
+
// Mutex for protecting cache operations
|
|
31
|
+
const cacheMutex = new async_mutex_1.Mutex();
|
|
32
|
+
function getUniqueId(type, id) {
|
|
33
|
+
return `${type}.${id}`;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
async get(type, ids) {
|
|
37
|
+
return cacheMutex.runExclusive(async () => {
|
|
38
|
+
const data = {};
|
|
39
|
+
const idsToFetch = [];
|
|
40
|
+
for (const id of ids) {
|
|
41
|
+
const item = (await cache.get(getUniqueId(type, id)));
|
|
42
|
+
if (typeof item !== 'undefined') {
|
|
43
|
+
data[id] = item;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
idsToFetch.push(id);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (idsToFetch.length) {
|
|
50
|
+
logger?.trace({ items: idsToFetch.length }, 'loading from store');
|
|
51
|
+
const fetched = await store.get(type, idsToFetch);
|
|
52
|
+
for (const id of idsToFetch) {
|
|
53
|
+
const item = fetched[id];
|
|
54
|
+
if (item) {
|
|
55
|
+
data[id] = item;
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
57
|
+
await cache.set(getUniqueId(type, id), item);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return data;
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
async set(data) {
|
|
65
|
+
return cacheMutex.runExclusive(async () => {
|
|
66
|
+
let keys = 0;
|
|
67
|
+
for (const type in data) {
|
|
68
|
+
for (const id in data[type]) {
|
|
69
|
+
await cache.set(getUniqueId(type, id), data[type][id]);
|
|
70
|
+
keys += 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
logger?.trace({ keys }, 'updated cache');
|
|
74
|
+
await store.set(data);
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
async clear() {
|
|
78
|
+
await cache.flushAll();
|
|
79
|
+
await store.clear?.();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Adds DB-like transaction capability to the SignalKeyStore
|
|
85
|
+
* Uses AsyncLocalStorage for automatic context management
|
|
86
|
+
* @param state the key store to apply this capability to
|
|
87
|
+
* @param logger logger to log events
|
|
88
|
+
* @returns SignalKeyStore with transaction capability
|
|
89
|
+
*/
|
|
90
|
+
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
91
|
+
const txStorage = new async_hooks_1.AsyncLocalStorage();
|
|
92
|
+
// Queues for concurrency control (keyed by signal data type - bounded set)
|
|
93
|
+
const keyQueues = new Map();
|
|
94
|
+
// Transaction mutexes with reference counting for cleanup
|
|
95
|
+
const txMutexes = new Map();
|
|
96
|
+
const txMutexRefCounts = new Map();
|
|
97
|
+
// Pre-key manager for specialized operations
|
|
98
|
+
const preKeyManager = new pre_key_manager_js_1.PreKeyManager(state, logger);
|
|
99
|
+
/**
|
|
100
|
+
* Get or create a queue for a specific key type
|
|
101
|
+
*/
|
|
102
|
+
function getQueue(key) {
|
|
103
|
+
if (!keyQueues.has(key)) {
|
|
104
|
+
keyQueues.set(key, new serial_task_queue_js_1.default({ concurrency: 1 }));
|
|
105
|
+
}
|
|
106
|
+
return keyQueues.get(key);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get or create a transaction mutex
|
|
110
|
+
*/
|
|
111
|
+
function getTxMutex(key) {
|
|
112
|
+
if (!txMutexes.has(key)) {
|
|
113
|
+
txMutexes.set(key, new async_mutex_1.Mutex());
|
|
114
|
+
txMutexRefCounts.set(key, 0);
|
|
115
|
+
}
|
|
116
|
+
return txMutexes.get(key);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Acquire a reference to a transaction mutex
|
|
120
|
+
*/
|
|
121
|
+
function acquireTxMutexRef(key) {
|
|
122
|
+
const count = txMutexRefCounts.get(key) ?? 0;
|
|
123
|
+
txMutexRefCounts.set(key, count + 1);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Release a reference to a transaction mutex and cleanup if no longer needed
|
|
127
|
+
*/
|
|
128
|
+
function releaseTxMutexRef(key) {
|
|
129
|
+
const count = (txMutexRefCounts.get(key) ?? 1) - 1;
|
|
130
|
+
txMutexRefCounts.set(key, count);
|
|
131
|
+
// Cleanup if no more references and mutex is not locked
|
|
132
|
+
if (count <= 0) {
|
|
133
|
+
const mutex = txMutexes.get(key);
|
|
134
|
+
if (mutex && !mutex.isLocked()) {
|
|
135
|
+
txMutexes.delete(key);
|
|
136
|
+
txMutexRefCounts.delete(key);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if currently in a transaction
|
|
142
|
+
*/
|
|
143
|
+
function isInTransaction() {
|
|
144
|
+
return !!txStorage.getStore();
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Commit transaction with retries
|
|
148
|
+
*/
|
|
149
|
+
async function commitWithRetry(mutations) {
|
|
150
|
+
if (Object.keys(mutations).length === 0) {
|
|
151
|
+
logger.trace('no mutations in transaction');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
logger.trace('committing transaction');
|
|
155
|
+
for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
|
|
156
|
+
try {
|
|
157
|
+
await state.set(mutations);
|
|
158
|
+
logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
const retriesLeft = maxCommitRetries - attempt - 1;
|
|
163
|
+
logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
|
|
164
|
+
if (retriesLeft === 0) {
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
await (0, generics_js_1.delay)(delayBetweenTriesMs);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
get: async (type, ids) => {
|
|
173
|
+
const ctx = txStorage.getStore();
|
|
174
|
+
if (!ctx) {
|
|
175
|
+
// No transaction - direct read without exclusive lock for concurrency
|
|
176
|
+
return state.get(type, ids);
|
|
177
|
+
}
|
|
178
|
+
// In transaction - check cache first
|
|
179
|
+
const cached = ctx.cache[type] || {};
|
|
180
|
+
const missing = ids.filter(id => !(id in cached));
|
|
181
|
+
if (missing.length > 0) {
|
|
182
|
+
ctx.dbQueries++;
|
|
183
|
+
logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
|
|
184
|
+
const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
|
|
185
|
+
// Update cache
|
|
186
|
+
ctx.cache[type] = ctx.cache[type] || {};
|
|
187
|
+
Object.assign(ctx.cache[type], fetched);
|
|
188
|
+
}
|
|
189
|
+
// Return requested ids from cache
|
|
190
|
+
const result = {};
|
|
191
|
+
for (const id of ids) {
|
|
192
|
+
const value = ctx.cache[type]?.[id];
|
|
193
|
+
if (value !== undefined && value !== null) {
|
|
194
|
+
result[id] = value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
},
|
|
199
|
+
set: async (data) => {
|
|
200
|
+
const ctx = txStorage.getStore();
|
|
201
|
+
if (!ctx) {
|
|
202
|
+
// No transaction - direct write with queue protection
|
|
203
|
+
const types = Object.keys(data);
|
|
204
|
+
// Process pre-keys with validation
|
|
205
|
+
for (const type_ of types) {
|
|
206
|
+
const type = type_;
|
|
207
|
+
if (type === 'pre-key') {
|
|
208
|
+
await preKeyManager.validateDeletions(data, type);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Write all data in parallel
|
|
212
|
+
await Promise.all(types.map(type => getQueue(type).add(async () => {
|
|
213
|
+
const typeData = { [type]: data[type] };
|
|
214
|
+
await state.set(typeData);
|
|
215
|
+
})));
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
// In transaction - update cache and mutations
|
|
219
|
+
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
220
|
+
for (const key_ in data) {
|
|
221
|
+
const key = key_;
|
|
222
|
+
// Ensure structures exist
|
|
223
|
+
ctx.cache[key] = ctx.cache[key] || {};
|
|
224
|
+
ctx.mutations[key] = ctx.mutations[key] || {};
|
|
225
|
+
// Special handling for pre-keys
|
|
226
|
+
if (key === 'pre-key') {
|
|
227
|
+
await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
// Normal key types
|
|
231
|
+
Object.assign(ctx.cache[key], data[key]);
|
|
232
|
+
Object.assign(ctx.mutations[key], data[key]);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
isInTransaction,
|
|
237
|
+
transaction: async (work, key) => {
|
|
238
|
+
const existing = txStorage.getStore();
|
|
239
|
+
// Nested transaction - reuse existing context
|
|
240
|
+
if (existing) {
|
|
241
|
+
logger.trace('reusing existing transaction context');
|
|
242
|
+
return work();
|
|
243
|
+
}
|
|
244
|
+
// New transaction - acquire mutex and create context
|
|
245
|
+
const mutex = getTxMutex(key);
|
|
246
|
+
acquireTxMutexRef(key);
|
|
247
|
+
try {
|
|
248
|
+
return await mutex.runExclusive(async () => {
|
|
249
|
+
const ctx = {
|
|
250
|
+
cache: {},
|
|
251
|
+
mutations: {},
|
|
252
|
+
dbQueries: 0
|
|
253
|
+
};
|
|
254
|
+
logger.trace('entering transaction');
|
|
255
|
+
try {
|
|
256
|
+
const result = await txStorage.run(ctx, work);
|
|
257
|
+
// Commit mutations
|
|
258
|
+
await commitWithRetry(ctx.mutations);
|
|
259
|
+
logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
logger.error({ error }, 'transaction failed, rolling back');
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
finally {
|
|
269
|
+
releaseTxMutexRef(key);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
exports.addTransactionCapability = addTransactionCapability;
|
|
275
|
+
const initAuthCreds = () => {
|
|
276
|
+
const identityKey = crypto_js_1.Curve.generateKeyPair();
|
|
277
|
+
return {
|
|
278
|
+
noiseKey: crypto_js_1.Curve.generateKeyPair(),
|
|
279
|
+
pairingEphemeralKeyPair: crypto_js_1.Curve.generateKeyPair(),
|
|
280
|
+
signedIdentityKey: identityKey,
|
|
281
|
+
signedPreKey: (0, crypto_js_1.signedKeyPair)(identityKey, 1),
|
|
282
|
+
registrationId: (0, generics_js_1.generateRegistrationId)(),
|
|
283
|
+
advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
|
|
284
|
+
processedHistoryMessages: [],
|
|
285
|
+
nextPreKeyId: 1,
|
|
286
|
+
firstUnuploadedPreKeyId: 1,
|
|
287
|
+
accountSyncCounter: 0,
|
|
288
|
+
accountSettings: {
|
|
289
|
+
unarchiveChats: false
|
|
290
|
+
},
|
|
291
|
+
registered: false,
|
|
292
|
+
pairingCode: undefined,
|
|
293
|
+
lastPropHash: undefined,
|
|
294
|
+
routingInfo: undefined,
|
|
295
|
+
additionalData: undefined
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
exports.initAuthCreds = initAuthCreds;
|
|
@@ -0,0 +1,60 @@
|
|
|
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.readAndEmitEventStream = exports.captureEventStream = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const promises_1 = require("fs/promises");
|
|
10
|
+
const readline_1 = require("readline");
|
|
11
|
+
const generics_js_1 = require("./generics.js");
|
|
12
|
+
const make_mutex_js_1 = require("./make-mutex.js");
|
|
13
|
+
/**
|
|
14
|
+
* Captures events from a baileys event emitter & stores them in a file
|
|
15
|
+
* @param ev The event emitter to read events from
|
|
16
|
+
* @param filename File to save to
|
|
17
|
+
*/
|
|
18
|
+
const captureEventStream = (ev, filename) => {
|
|
19
|
+
const oldEmit = ev.emit;
|
|
20
|
+
// write mutex so data is appended in order
|
|
21
|
+
const writeMutex = (0, make_mutex_js_1.makeMutex)();
|
|
22
|
+
// monkey patch eventemitter to capture all events
|
|
23
|
+
ev.emit = function (...args) {
|
|
24
|
+
const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
|
|
25
|
+
const result = oldEmit.apply(ev, args);
|
|
26
|
+
writeMutex.mutex(async () => {
|
|
27
|
+
await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.captureEventStream = captureEventStream;
|
|
33
|
+
/**
|
|
34
|
+
* Read event file and emit events from there
|
|
35
|
+
* @param filename filename containing event data
|
|
36
|
+
* @param delayIntervalMs delay between each event emit
|
|
37
|
+
*/
|
|
38
|
+
const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
|
|
39
|
+
const ev = new events_1.default();
|
|
40
|
+
const fireEvents = async () => {
|
|
41
|
+
const fileStream = (0, fs_1.createReadStream)(filename);
|
|
42
|
+
const rl = (0, readline_1.createInterface)({
|
|
43
|
+
input: fileStream,
|
|
44
|
+
crlfDelay: Infinity
|
|
45
|
+
});
|
|
46
|
+
for await (const line of rl) {
|
|
47
|
+
if (line) {
|
|
48
|
+
const { event, data } = JSON.parse(line);
|
|
49
|
+
ev.emit(event, data);
|
|
50
|
+
delayIntervalMs && await (0, generics_js_1.delay)(delayIntervalMs);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
fileStream.close();
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
ev,
|
|
57
|
+
task: fireEvents()
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.readAndEmitEventStream = readAndEmitEventStream;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { md5, hkdf, expandAppStateKeys, LTHashAntiTampering } from './rust-bridge-shim.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LTHashAntiTampering = exports.expandAppStateKeys = exports.hkdf = exports.md5 = void 0;
|
|
4
|
+
let runtime;
|
|
5
|
+
try {
|
|
6
|
+
runtime = require("whatsapp-rust-bridge");
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
runtime = require("./rust-bridge-shim.js");
|
|
10
|
+
}
|
|
11
|
+
exports.md5 = runtime.md5;
|
|
12
|
+
exports.hkdf = runtime.hkdf;
|
|
13
|
+
exports.expandAppStateKeys = runtime.expandAppStateKeys;
|
|
14
|
+
exports.LTHashAntiTampering = runtime.LTHashAntiTampering;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPlatformId = exports.Browsers = exports.PLATFORM_VERSIONS = exports.PLATFORM_MAP = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const index_js_1 = require("../../WAProto/index.js");
|
|
6
|
+
exports.PLATFORM_MAP = {
|
|
7
|
+
'aix': 'AIX', 'darwin': 'Mac OS', 'win32': 'Windows', 'android': 'Android',
|
|
8
|
+
'freebsd': 'FreeBSD', 'openbsd': 'OpenBSD', 'sunos': 'Solaris', 'linux': 'Linux',
|
|
9
|
+
'ubuntu': 'Ubuntu', 'ios': 'iOS', 'baileys': 'Baileys', 'chromeos': 'Chrome OS',
|
|
10
|
+
'tizen': 'Tizen', 'watchos': 'watchOS', 'wearos': 'Wear OS', 'harmonyos': 'HarmonyOS',
|
|
11
|
+
'kaios': 'KaiOS', 'smarttv': 'Smart TV', 'raspberrypi': 'Raspberry Pi OS',
|
|
12
|
+
'symbian': 'Symbian', 'blackberry': 'Blackberry OS', 'windowsphone': 'Windows Phone'
|
|
13
|
+
};
|
|
14
|
+
exports.PLATFORM_VERSIONS = {
|
|
15
|
+
'ubuntu': '22.04.4', 'darwin': '18.5', 'win32': '10.0.22631', 'android': '14.0.0',
|
|
16
|
+
'freebsd': '13.2', 'openbsd': '7.3', 'sunos': '11', 'linux': '6.5', 'ios': '18.2',
|
|
17
|
+
'baileys': '6.5.0', 'chromeos': '117.0.5938.132', 'tizen': '6.5', 'watchos': '10.1',
|
|
18
|
+
'wearos': '4.1', 'harmonyos': '4.0.0', 'kaios': '3.1', 'smarttv': '23.3.1',
|
|
19
|
+
'raspberrypi': '11 (Bullseye)', 'symbian': '3', 'blackberry': '10.3.3', 'windowsphone': '8.1'
|
|
20
|
+
};
|
|
21
|
+
exports.Browsers = {
|
|
22
|
+
ubuntu: (browser) => [exports.PLATFORM_MAP['ubuntu'], browser, exports.PLATFORM_VERSIONS['ubuntu']],
|
|
23
|
+
macOS: (browser) => [exports.PLATFORM_MAP['darwin'], browser, exports.PLATFORM_VERSIONS['darwin']],
|
|
24
|
+
windows: (browser) => [exports.PLATFORM_MAP['win32'], browser, exports.PLATFORM_VERSIONS['win32']],
|
|
25
|
+
linux: (browser) => [exports.PLATFORM_MAP['linux'], browser, exports.PLATFORM_VERSIONS['linux']],
|
|
26
|
+
solaris: (browser) => [exports.PLATFORM_MAP['sunos'], browser, exports.PLATFORM_VERSIONS['sunos']],
|
|
27
|
+
baileys: (browser) => [exports.PLATFORM_MAP['baileys'], browser, exports.PLATFORM_VERSIONS['baileys']],
|
|
28
|
+
android: (browser) => [exports.PLATFORM_MAP['android'], browser, exports.PLATFORM_VERSIONS['android']],
|
|
29
|
+
iOS: (browser) => [exports.PLATFORM_MAP['ios'], browser, exports.PLATFORM_VERSIONS['ios']],
|
|
30
|
+
kaiOS: (browser) => [exports.PLATFORM_MAP['kaios'], browser, exports.PLATFORM_VERSIONS['kaios']],
|
|
31
|
+
chromeOS: (browser) => [exports.PLATFORM_MAP['chromeos'], browser, exports.PLATFORM_VERSIONS['chromeos']],
|
|
32
|
+
appropriate: (browser) => {
|
|
33
|
+
const p = (0, os_1.platform)();
|
|
34
|
+
return [exports.PLATFORM_MAP[p] || 'Unknown OS', browser, exports.PLATFORM_VERSIONS[p] || 'latest'];
|
|
35
|
+
},
|
|
36
|
+
custom: (p, browser, version) => {
|
|
37
|
+
return [exports.PLATFORM_MAP[p.toLowerCase()] || p, browser, version || exports.PLATFORM_VERSIONS[p] || 'latest'];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const getPlatformId = (browser) => {
|
|
41
|
+
const platformType = index_js_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
42
|
+
return platformType ? platformType.toString() : '1';
|
|
43
|
+
};
|
|
44
|
+
exports.getPlatformId = getPlatformId;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types/index.js';
|
|
2
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
3
|
+
export declare const parseCatalogNode: (node: BinaryNode) => {
|
|
4
|
+
products: Product[];
|
|
5
|
+
nextPageCursor: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare const parseCollectionsNode: (node: BinaryNode) => {
|
|
8
|
+
collections: CatalogCollection[];
|
|
9
|
+
};
|
|
10
|
+
export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails;
|
|
11
|
+
export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode;
|
|
12
|
+
export declare const parseProductNode: (productNode: BinaryNode) => Product;
|
|
13
|
+
/**
|
|
14
|
+
* Uploads images not already uploaded to WA's servers
|
|
15
|
+
*/
|
|
16
|
+
export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Uploads images not already uploaded to WA's servers
|
|
19
|
+
*/
|
|
20
|
+
export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
|
|
21
|
+
url: string;
|
|
22
|
+
}[]>;
|
|
23
|
+
//# sourceMappingURL=business.d.ts.map
|