violetics 7.0.0-alpha → 7.0.2-alpha
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 +3 -2
- package/README.md +1001 -232
- package/WAProto/index.js +75379 -142631
- package/engine-requirements.js +11 -8
- package/lib/Defaults/index.js +132 -144
- package/lib/Signal/Group/ciphertext-message.js +2 -6
- package/lib/Signal/Group/group-session-builder.js +7 -42
- package/lib/Signal/Group/group_cipher.js +37 -52
- package/lib/Signal/Group/index.js +11 -57
- package/lib/Signal/Group/keyhelper.js +7 -45
- package/lib/Signal/Group/sender-chain-key.js +7 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -12
- package/lib/Signal/Group/sender-key-message.js +9 -13
- package/lib/Signal/Group/sender-key-name.js +2 -6
- package/lib/Signal/Group/sender-key-record.js +9 -22
- package/lib/Signal/Group/sender-key-state.js +27 -43
- package/lib/Signal/Group/sender-message-key.js +4 -8
- package/lib/Signal/libsignal.js +319 -94
- package/lib/Signal/lid-mapping.js +224 -139
- package/lib/Socket/Client/index.js +2 -19
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.js +162 -44
- package/lib/Socket/chats.js +477 -442
- package/lib/Socket/communities.js +430 -0
- package/lib/Socket/groups.js +110 -99
- package/lib/Socket/index.js +10 -10
- package/lib/Socket/messages-recv.js +878 -552
- package/lib/Socket/messages-send.js +859 -428
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +195 -390
- package/lib/Socket/socket.js +463 -289
- package/lib/Store/index.js +3 -10
- package/lib/Store/make-in-memory-store.js +73 -79
- package/lib/Store/make-ordered-dictionary.js +4 -7
- package/lib/Store/object-repository.js +2 -6
- package/lib/Types/Auth.js +1 -2
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.js +1 -2
- package/lib/Types/Chat.js +7 -4
- package/lib/Types/Contact.js +1 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +1 -2
- package/lib/Types/Label.js +2 -5
- package/lib/Types/LabelAssociation.js +2 -5
- package/lib/Types/Message.js +17 -9
- package/lib/Types/Newsletter.js +33 -38
- package/lib/Types/Product.js +1 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -2
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +14 -31
- package/lib/Utils/auth-utils.js +228 -145
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +66 -70
- package/lib/Utils/chat-utils.js +331 -249
- package/lib/Utils/crypto.js +57 -91
- package/lib/Utils/decode-wa-message.js +168 -84
- package/lib/Utils/event-buffer.js +138 -80
- package/lib/Utils/generics.js +180 -297
- package/lib/Utils/history.js +83 -49
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -23
- package/lib/Utils/logger.js +2 -7
- package/lib/Utils/lt-hash.js +2 -46
- package/lib/Utils/make-mutex.js +24 -35
- package/lib/Utils/message-retry-manager.js +224 -0
- package/lib/Utils/messages-media.js +501 -496
- package/lib/Utils/messages.js +1428 -362
- package/lib/Utils/noise-handler.js +145 -100
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.js +356 -150
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/signal.js +78 -73
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.js +17 -0
- package/lib/Utils/use-multi-file-auth-state.js +32 -34
- package/lib/Utils/validate-connection.js +91 -107
- package/lib/WABinary/constants.js +1300 -1304
- package/lib/WABinary/decode.js +26 -48
- package/lib/WABinary/encode.js +109 -155
- package/lib/WABinary/generic-utils.js +161 -149
- package/lib/WABinary/index.js +5 -21
- package/lib/WABinary/jid-utils.js +73 -40
- package/lib/WABinary/types.js +1 -2
- package/lib/WAM/BinaryInfo.js +2 -6
- package/lib/WAM/constants.js +19070 -11568
- package/lib/WAM/encode.js +17 -23
- package/lib/WAM/index.js +3 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -15
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -14
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -23
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -9
- package/lib/WAUSync/Protocols/index.js +4 -20
- package/lib/WAUSync/USyncQuery.js +40 -36
- package/lib/WAUSync/USyncUser.js +2 -6
- package/lib/WAUSync/index.js +3 -19
- package/lib/index.js +11 -44
- package/package.json +75 -108
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -111
- package/lib/Socket/groupStatus.js +0 -637
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Utils/baileys-event-stream.js +0 -63
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,189 +1,278 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const Defaults_1 = require("../Defaults");
|
|
11
|
-
const crypto_2 = require("./crypto");
|
|
12
|
-
const generics_1 = require("./generics");
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
|
+
import { Mutex } from 'async-mutex';
|
|
4
|
+
import { randomBytes } from 'crypto';
|
|
5
|
+
import PQueue from 'p-queue';
|
|
6
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
7
|
+
import { Curve, signedKeyPair } from './crypto.js';
|
|
8
|
+
import { delay, generateRegistrationId } from './generics.js';
|
|
9
|
+
import { PreKeyManager } from './pre-key-manager.js';
|
|
13
10
|
/**
|
|
14
11
|
* Adds caching capability to a SignalKeyStore
|
|
15
12
|
* @param store the store to add caching to
|
|
16
13
|
* @param logger to log trace events
|
|
17
14
|
* @param _cache cache store to use
|
|
18
15
|
*/
|
|
19
|
-
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
20
|
-
const cache = _cache ||
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
17
|
+
const cache = _cache ||
|
|
18
|
+
new NodeCache({
|
|
19
|
+
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
20
|
+
useClones: false,
|
|
21
|
+
deleteOnExpire: true
|
|
22
|
+
});
|
|
23
|
+
// Mutex for protecting cache operations
|
|
24
|
+
const cacheMutex = new Mutex();
|
|
25
25
|
function getUniqueId(type, id) {
|
|
26
26
|
return `${type}.${id}`;
|
|
27
27
|
}
|
|
28
28
|
return {
|
|
29
29
|
async get(type, ids) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
idsToFetch.push(id);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (idsToFetch.length) {
|
|
42
|
-
logger.trace({ items: idsToFetch.length }, 'loading from store');
|
|
43
|
-
const fetched = await store.get(type, idsToFetch);
|
|
44
|
-
for (const id of idsToFetch) {
|
|
45
|
-
const item = fetched[id];
|
|
46
|
-
if (item) {
|
|
30
|
+
return cacheMutex.runExclusive(async () => {
|
|
31
|
+
const data = {};
|
|
32
|
+
const idsToFetch = [];
|
|
33
|
+
for (const id of ids) {
|
|
34
|
+
const item = (await cache.get(getUniqueId(type, id)));
|
|
35
|
+
if (typeof item !== 'undefined') {
|
|
47
36
|
data[id] = item;
|
|
48
|
-
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
idsToFetch.push(id);
|
|
49
40
|
}
|
|
50
41
|
}
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
if (idsToFetch.length) {
|
|
43
|
+
logger?.trace({ items: idsToFetch.length }, 'loading from store');
|
|
44
|
+
const fetched = await store.get(type, idsToFetch);
|
|
45
|
+
for (const id of idsToFetch) {
|
|
46
|
+
const item = fetched[id];
|
|
47
|
+
if (item) {
|
|
48
|
+
data[id] = item;
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
50
|
+
await cache.set(getUniqueId(type, id), item);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return data;
|
|
55
|
+
});
|
|
53
56
|
},
|
|
54
57
|
async set(data) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
for (const
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
return cacheMutex.runExclusive(async () => {
|
|
59
|
+
let keys = 0;
|
|
60
|
+
for (const type in data) {
|
|
61
|
+
for (const id in data[type]) {
|
|
62
|
+
await cache.set(getUniqueId(type, id), data[type][id]);
|
|
63
|
+
keys += 1;
|
|
64
|
+
}
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
logger?.trace({ keys }, 'updated cache');
|
|
67
|
+
await store.set(data);
|
|
68
|
+
});
|
|
64
69
|
},
|
|
65
70
|
async clear() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
|
|
71
|
+
await cache.flushAll();
|
|
72
|
+
await store.clear?.();
|
|
69
73
|
}
|
|
70
74
|
};
|
|
71
75
|
}
|
|
72
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
73
76
|
/**
|
|
74
|
-
* Adds DB
|
|
75
|
-
*
|
|
77
|
+
* Adds DB-like transaction capability to the SignalKeyStore
|
|
78
|
+
* Uses AsyncLocalStorage for automatic context management
|
|
76
79
|
* @param state the key store to apply this capability to
|
|
77
80
|
* @param logger logger to log events
|
|
78
81
|
* @returns SignalKeyStore with transaction capability
|
|
79
82
|
*/
|
|
80
|
-
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
84
|
+
const txStorage = new AsyncLocalStorage();
|
|
85
|
+
// Queues for concurrency control (keyed by signal data type - bounded set)
|
|
86
|
+
const keyQueues = new Map();
|
|
87
|
+
// Transaction mutexes with reference counting for cleanup
|
|
88
|
+
const txMutexes = new Map();
|
|
89
|
+
const txMutexRefCounts = new Map();
|
|
90
|
+
// Pre-key manager for specialized operations
|
|
91
|
+
const preKeyManager = new PreKeyManager(state, logger);
|
|
92
|
+
/**
|
|
93
|
+
* Get or create a queue for a specific key type
|
|
94
|
+
*/
|
|
95
|
+
function getQueue(key) {
|
|
96
|
+
if (!keyQueues.has(key)) {
|
|
97
|
+
keyQueues.set(key, new PQueue({ concurrency: 1 }));
|
|
98
|
+
}
|
|
99
|
+
return keyQueues.get(key);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get or create a transaction mutex
|
|
103
|
+
*/
|
|
104
|
+
function getTxMutex(key) {
|
|
105
|
+
if (!txMutexes.has(key)) {
|
|
106
|
+
txMutexes.set(key, new Mutex());
|
|
107
|
+
txMutexRefCounts.set(key, 0);
|
|
108
|
+
}
|
|
109
|
+
return txMutexes.get(key);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Acquire a reference to a transaction mutex
|
|
113
|
+
*/
|
|
114
|
+
function acquireTxMutexRef(key) {
|
|
115
|
+
const count = txMutexRefCounts.get(key) ?? 0;
|
|
116
|
+
txMutexRefCounts.set(key, count + 1);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Release a reference to a transaction mutex and cleanup if no longer needed
|
|
120
|
+
*/
|
|
121
|
+
function releaseTxMutexRef(key) {
|
|
122
|
+
const count = (txMutexRefCounts.get(key) ?? 1) - 1;
|
|
123
|
+
txMutexRefCounts.set(key, count);
|
|
124
|
+
// Cleanup if no more references and mutex is not locked
|
|
125
|
+
if (count <= 0) {
|
|
126
|
+
const mutex = txMutexes.get(key);
|
|
127
|
+
if (mutex && !mutex.isLocked()) {
|
|
128
|
+
txMutexes.delete(key);
|
|
129
|
+
txMutexRefCounts.delete(key);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Check if currently in a transaction
|
|
135
|
+
*/
|
|
136
|
+
function isInTransaction() {
|
|
137
|
+
return !!txStorage.getStore();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Commit transaction with retries
|
|
141
|
+
*/
|
|
142
|
+
async function commitWithRetry(mutations) {
|
|
143
|
+
if (Object.keys(mutations).length === 0) {
|
|
144
|
+
logger.trace('no mutations in transaction');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
logger.trace('committing transaction');
|
|
148
|
+
for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
|
|
149
|
+
try {
|
|
150
|
+
await state.set(mutations);
|
|
151
|
+
logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
const retriesLeft = maxCommitRetries - attempt - 1;
|
|
156
|
+
logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
|
|
157
|
+
if (retriesLeft === 0) {
|
|
158
|
+
throw error;
|
|
100
159
|
}
|
|
101
|
-
|
|
102
|
-
var _a;
|
|
103
|
-
const value = (_a = transactionCache[type]) === null || _a === void 0 ? void 0 : _a[id];
|
|
104
|
-
if (value) {
|
|
105
|
-
dict[id] = value;
|
|
106
|
-
}
|
|
107
|
-
return dict;
|
|
108
|
-
}, {});
|
|
160
|
+
await delay(delayBetweenTriesMs);
|
|
109
161
|
}
|
|
110
|
-
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
get: async (type, ids) => {
|
|
166
|
+
const ctx = txStorage.getStore();
|
|
167
|
+
if (!ctx) {
|
|
168
|
+
// No transaction - direct read without exclusive lock for concurrency
|
|
111
169
|
return state.get(type, ids);
|
|
112
170
|
}
|
|
171
|
+
// In transaction - check cache first
|
|
172
|
+
const cached = ctx.cache[type] || {};
|
|
173
|
+
const missing = ids.filter(id => !(id in cached));
|
|
174
|
+
if (missing.length > 0) {
|
|
175
|
+
ctx.dbQueries++;
|
|
176
|
+
logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
|
|
177
|
+
const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
|
|
178
|
+
// Update cache
|
|
179
|
+
ctx.cache[type] = ctx.cache[type] || {};
|
|
180
|
+
Object.assign(ctx.cache[type], fetched);
|
|
181
|
+
}
|
|
182
|
+
// Return requested ids from cache
|
|
183
|
+
const result = {};
|
|
184
|
+
for (const id of ids) {
|
|
185
|
+
const value = ctx.cache[type]?.[id];
|
|
186
|
+
if (value !== undefined && value !== null) {
|
|
187
|
+
result[id] = value;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
113
191
|
},
|
|
114
|
-
set: data => {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
192
|
+
set: async (data) => {
|
|
193
|
+
const ctx = txStorage.getStore();
|
|
194
|
+
if (!ctx) {
|
|
195
|
+
// No transaction - direct write with queue protection
|
|
196
|
+
const types = Object.keys(data);
|
|
197
|
+
// Process pre-keys with validation
|
|
198
|
+
for (const type_ of types) {
|
|
199
|
+
const type = type_;
|
|
200
|
+
if (type === 'pre-key') {
|
|
201
|
+
await preKeyManager.validateDeletions(data, type);
|
|
202
|
+
}
|
|
122
203
|
}
|
|
204
|
+
// Write all data in parallel
|
|
205
|
+
await Promise.all(types.map(type => getQueue(type).add(async () => {
|
|
206
|
+
const typeData = { [type]: data[type] };
|
|
207
|
+
await state.set(typeData);
|
|
208
|
+
})));
|
|
209
|
+
return;
|
|
123
210
|
}
|
|
124
|
-
|
|
125
|
-
|
|
211
|
+
// In transaction - update cache and mutations
|
|
212
|
+
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
213
|
+
for (const key_ in data) {
|
|
214
|
+
const key = key_;
|
|
215
|
+
// Ensure structures exist
|
|
216
|
+
ctx.cache[key] = ctx.cache[key] || {};
|
|
217
|
+
ctx.mutations[key] = ctx.mutations[key] || {};
|
|
218
|
+
// Special handling for pre-keys
|
|
219
|
+
if (key === 'pre-key') {
|
|
220
|
+
await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// Normal key types
|
|
224
|
+
Object.assign(ctx.cache[key], data[key]);
|
|
225
|
+
Object.assign(ctx.mutations[key], data[key]);
|
|
226
|
+
}
|
|
126
227
|
}
|
|
127
228
|
},
|
|
128
229
|
isInTransaction,
|
|
129
|
-
async
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (
|
|
133
|
-
logger.trace('
|
|
230
|
+
transaction: async (work, key) => {
|
|
231
|
+
const existing = txStorage.getStore();
|
|
232
|
+
// Nested transaction - reuse existing context
|
|
233
|
+
if (existing) {
|
|
234
|
+
logger.trace('reusing existing transaction context');
|
|
235
|
+
return work();
|
|
134
236
|
}
|
|
237
|
+
// New transaction - acquire mutex and create context
|
|
238
|
+
const mutex = getTxMutex(key);
|
|
239
|
+
acquireTxMutexRef(key);
|
|
135
240
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
|
|
153
|
-
await (0, generics_1.delay)(delayBetweenTriesMs);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
241
|
+
return await mutex.runExclusive(async () => {
|
|
242
|
+
const ctx = {
|
|
243
|
+
cache: {},
|
|
244
|
+
mutations: {},
|
|
245
|
+
dbQueries: 0
|
|
246
|
+
};
|
|
247
|
+
logger.trace('entering transaction');
|
|
248
|
+
try {
|
|
249
|
+
const result = await txStorage.run(ctx, work);
|
|
250
|
+
// Commit mutations
|
|
251
|
+
await commitWithRetry(ctx.mutations);
|
|
252
|
+
logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
|
|
253
|
+
return result;
|
|
156
254
|
}
|
|
157
|
-
|
|
158
|
-
logger.
|
|
255
|
+
catch (error) {
|
|
256
|
+
logger.error({ error }, 'transaction failed, rolling back');
|
|
257
|
+
throw error;
|
|
159
258
|
}
|
|
160
|
-
}
|
|
259
|
+
});
|
|
161
260
|
}
|
|
162
261
|
finally {
|
|
163
|
-
|
|
164
|
-
if (transactionsInProgress === 0) {
|
|
165
|
-
transactionCache = {};
|
|
166
|
-
mutations = {};
|
|
167
|
-
dbQueriesInTransaction = 0;
|
|
168
|
-
}
|
|
262
|
+
releaseTxMutexRef(key);
|
|
169
263
|
}
|
|
170
|
-
return result;
|
|
171
264
|
}
|
|
172
265
|
};
|
|
173
|
-
function isInTransaction() {
|
|
174
|
-
return transactionsInProgress > 0;
|
|
175
|
-
}
|
|
176
266
|
};
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
const identityKey = crypto_2.Curve.generateKeyPair();
|
|
267
|
+
export const initAuthCreds = () => {
|
|
268
|
+
const identityKey = Curve.generateKeyPair();
|
|
180
269
|
return {
|
|
181
|
-
noiseKey:
|
|
182
|
-
pairingEphemeralKeyPair:
|
|
270
|
+
noiseKey: Curve.generateKeyPair(),
|
|
271
|
+
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
183
272
|
signedIdentityKey: identityKey,
|
|
184
|
-
signedPreKey:
|
|
185
|
-
registrationId:
|
|
186
|
-
advSecretKey:
|
|
273
|
+
signedPreKey: signedKeyPair(identityKey, 1),
|
|
274
|
+
registrationId: generateRegistrationId(),
|
|
275
|
+
advSecretKey: randomBytes(32).toString('base64'),
|
|
187
276
|
processedHistoryMessages: [],
|
|
188
277
|
nextPreKeyId: 1,
|
|
189
278
|
firstUnuploadedPreKeyId: 1,
|
|
@@ -191,16 +280,10 @@ const initAuthCreds = () => {
|
|
|
191
280
|
accountSettings: {
|
|
192
281
|
unarchiveChats: false
|
|
193
282
|
},
|
|
194
|
-
// mobile creds
|
|
195
|
-
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
196
|
-
phoneId: (0, uuid_1.v4)(),
|
|
197
|
-
identityId: (0, crypto_1.randomBytes)(20),
|
|
198
283
|
registered: false,
|
|
199
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
-
registration: {},
|
|
201
284
|
pairingCode: undefined,
|
|
202
285
|
lastPropHash: undefined,
|
|
203
286
|
routingInfo: undefined,
|
|
287
|
+
additionalData: undefined
|
|
204
288
|
};
|
|
205
|
-
};
|
|
206
|
-
exports.initAuthCreds = initAuthCreds;
|
|
289
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { platform, release } from 'node:os';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
const PLATFORM_MAP = {
|
|
4
|
+
aix: 'AIX',
|
|
5
|
+
darwin: 'Mac OS',
|
|
6
|
+
win32: 'Windows',
|
|
7
|
+
android: 'Android',
|
|
8
|
+
freebsd: 'FreeBSD',
|
|
9
|
+
openbsd: 'OpenBSD',
|
|
10
|
+
sunos: 'Solaris',
|
|
11
|
+
linux: undefined,
|
|
12
|
+
haiku: undefined,
|
|
13
|
+
cygwin: undefined,
|
|
14
|
+
netbsd: undefined
|
|
15
|
+
};
|
|
16
|
+
export const Browsers = {
|
|
17
|
+
ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
|
|
18
|
+
macOS: browser => ['Mac OS', browser, '14.4.1'],
|
|
19
|
+
baileys: browser => ['Baileys', browser, '6.5.0'],
|
|
20
|
+
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
21
|
+
android: browser => [browser, 'Android', ''],
|
|
22
|
+
/** The appropriate browser based on your OS & release */
|
|
23
|
+
appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
|
|
24
|
+
};
|
|
25
|
+
export const getPlatformId = (browser) => {
|
|
26
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
27
|
+
return platformType ? platformType.toString() : '1'; //chrome
|
|
28
|
+
};
|