@ubedsockets/baileys 1.6.6 → 1.6.7
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 +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.js +131318 -59331
- package/lib/Defaults/index.js +92 -76
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.js +90 -347
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.js +78 -21
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.js +249 -571
- package/lib/Socket/groups.js +99 -114
- package/lib/Socket/index.js +9 -11
- package/lib/Socket/messages-recv.js +559 -1277
- package/lib/Socket/messages-send.js +669 -674
- package/lib/Socket/newsletter.js +286 -149
- package/lib/Socket/socket.js +235 -548
- 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 -11
- 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 -56
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.js +136 -239
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.js +238 -380
- package/lib/Utils/crypto.js +127 -56
- package/lib/Utils/decode-wa-message.js +63 -173
- package/lib/Utils/event-buffer.js +70 -174
- package/lib/Utils/generics.js +207 -159
- package/lib/Utils/history.js +53 -93
- package/lib/Utils/index.js +33 -22
- package/lib/Utils/link-preview.js +58 -17
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.js +744 -483
- package/lib/Utils/messages.js +621 -411
- package/lib/Utils/noise-handler.js +99 -149
- package/lib/Utils/process-message.js +150 -459
- package/lib/Utils/signal.js +73 -112
- package/lib/Utils/use-multi-file-auth-state.js +27 -23
- package/lib/Utils/validate-connection.js +104 -74
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.js +52 -49
- package/lib/WABinary/encode.js +49 -19
- package/lib/WABinary/generic-utils.js +43 -46
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.js +45 -72
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.js +35 -44
- package/lib/WAUSync/USyncUser.js +5 -10
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +70 -11
- package/package.json +60 -100
- package/engine-requirements.js +0 -10
package/lib/Utils/signal.js
CHANGED
|
@@ -1,113 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextPreKeysNode =
|
|
4
|
+
exports.getNextPreKeys =
|
|
5
|
+
exports.extractDeviceJids =
|
|
6
|
+
exports.parseAndInjectE2ESessions =
|
|
7
|
+
exports.xmppPreKey =
|
|
8
|
+
exports.xmppSignedPreKey =
|
|
9
|
+
exports.generateOrGetPreKeys =
|
|
10
|
+
exports.getPreKeys =
|
|
11
|
+
exports.createSignalIdentity = void 0;
|
|
12
|
+
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
|
+
const Defaults_1 = require("../Defaults");
|
|
15
|
+
const WABinary_1 = require("../WABinary");
|
|
16
|
+
const crypto_1 = require("./crypto");
|
|
17
|
+
const generics_1 = require("./generics");
|
|
18
|
+
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
19
|
return {
|
|
14
20
|
identifier: { name: wid, deviceId: 0 },
|
|
15
|
-
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
21
|
+
identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
|
|
16
22
|
};
|
|
17
23
|
};
|
|
18
|
-
|
|
24
|
+
exports.createSignalIdentity = createSignalIdentity;
|
|
25
|
+
const getPreKeys = async ({ get }, min, limit) => {
|
|
19
26
|
const idList = [];
|
|
20
27
|
for (let id = min; id < limit; id++) {
|
|
21
28
|
idList.push(id.toString());
|
|
22
29
|
}
|
|
23
30
|
return get('pre-key', idList);
|
|
24
31
|
};
|
|
25
|
-
|
|
32
|
+
exports.getPreKeys = getPreKeys;
|
|
33
|
+
const generateOrGetPreKeys = (creds, range) => {
|
|
26
34
|
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
27
35
|
const remaining = range - avaliable;
|
|
28
36
|
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
29
37
|
const newPreKeys = {};
|
|
30
38
|
if (remaining > 0) {
|
|
31
39
|
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
32
|
-
newPreKeys[i] = Curve.generateKeyPair();
|
|
40
|
+
newPreKeys[i] = crypto_1.Curve.generateKeyPair();
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
return {
|
|
36
44
|
newPreKeys,
|
|
37
45
|
lastPreKeyId,
|
|
38
|
-
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
46
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range],
|
|
39
47
|
};
|
|
40
48
|
};
|
|
41
|
-
|
|
49
|
+
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
50
|
+
const xmppSignedPreKey = (key) => ({
|
|
42
51
|
tag: 'skey',
|
|
43
52
|
attrs: {},
|
|
44
53
|
content: [
|
|
45
|
-
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
54
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
|
|
46
55
|
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
56
|
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
57
|
]
|
|
49
58
|
});
|
|
50
|
-
|
|
59
|
+
exports.xmppSignedPreKey = xmppSignedPreKey;
|
|
60
|
+
const xmppPreKey = (pair, id) => ({
|
|
51
61
|
tag: 'key',
|
|
52
62
|
attrs: {},
|
|
53
63
|
content: [
|
|
54
|
-
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
64
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
|
|
55
65
|
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
66
|
]
|
|
57
67
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const identity = getBinaryNodeChildBuffer(keysNode, 'identity');
|
|
67
|
-
const skey = getBinaryNodeChild(keysNode, 'skey');
|
|
68
|
-
if (!identity || identity.length !== 32 || !skey)
|
|
69
|
-
return null;
|
|
70
|
-
const registrationId = getBinaryNodeChildUInt(receipt, 'registration', 4);
|
|
71
|
-
if (!isValidUInt(registrationId))
|
|
72
|
-
return null;
|
|
73
|
-
const signedPubKey = getBinaryNodeChildBuffer(skey, 'value');
|
|
74
|
-
const signedSig = getBinaryNodeChildBuffer(skey, 'signature');
|
|
75
|
-
const signedKeyId = getBinaryNodeChildUInt(skey, 'id', 3);
|
|
76
|
-
if (!signedPubKey || signedPubKey.length !== 32 || !signedSig || !isValidUInt(signedKeyId)) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
const preKeyNode = getBinaryNodeChild(keysNode, 'key');
|
|
80
|
-
let preKey;
|
|
81
|
-
if (preKeyNode) {
|
|
82
|
-
const preKeyPub = getBinaryNodeChildBuffer(preKeyNode, 'value');
|
|
83
|
-
const preKeyId = getBinaryNodeChildUInt(preKeyNode, 'id', 3);
|
|
84
|
-
if (!preKeyPub || preKeyPub.length !== 32 || !isValidUInt(preKeyId)) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
preKey = { keyId: preKeyId, publicKey: generateSignalPubKey(preKeyPub) };
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
registrationId,
|
|
91
|
-
identityKey: generateSignalPubKey(identity),
|
|
92
|
-
signedPreKey: {
|
|
93
|
-
keyId: signedKeyId,
|
|
94
|
-
publicKey: generateSignalPubKey(signedPubKey),
|
|
95
|
-
signature: signedSig
|
|
96
|
-
},
|
|
97
|
-
preKey
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
101
|
-
const extractKey = (key) => key
|
|
102
|
-
? {
|
|
103
|
-
keyId: getBinaryNodeChildUInt(key, 'id', 3),
|
|
104
|
-
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
|
|
105
|
-
signature: getBinaryNodeChildBuffer(key, 'signature')
|
|
106
|
-
}
|
|
107
|
-
: undefined;
|
|
108
|
-
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
|
|
68
|
+
exports.xmppPreKey = xmppPreKey;
|
|
69
|
+
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
70
|
+
const extractKey = (key) => (key ? ({
|
|
71
|
+
keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
|
|
72
|
+
publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
|
|
73
|
+
signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature'),
|
|
74
|
+
}) : undefined);
|
|
75
|
+
const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
|
|
109
76
|
for (const node of nodes) {
|
|
110
|
-
assertNodeErrorFree(node);
|
|
77
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
111
78
|
}
|
|
112
79
|
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
113
80
|
// So Promise.all doesn't really help here,
|
|
@@ -115,87 +82,81 @@ export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
115
82
|
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
116
83
|
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
117
84
|
const chunkSize = 100;
|
|
118
|
-
const chunks = chunk(nodes, chunkSize);
|
|
85
|
+
const chunks = (0, lodash_1.chunk)(nodes, chunkSize);
|
|
119
86
|
for (const nodesChunk of chunks) {
|
|
120
|
-
|
|
121
|
-
const signedKey = getBinaryNodeChild(node, 'skey');
|
|
122
|
-
const key = getBinaryNodeChild(node, 'key');
|
|
123
|
-
const identity = getBinaryNodeChildBuffer(node, 'identity');
|
|
87
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
88
|
+
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
89
|
+
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
90
|
+
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
124
91
|
const jid = node.attrs.jid;
|
|
125
|
-
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
|
|
92
|
+
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
126
93
|
await repository.injectE2ESession({
|
|
127
94
|
jid,
|
|
128
95
|
session: {
|
|
129
96
|
registrationId: registrationId,
|
|
130
|
-
identityKey: generateSignalPubKey(identity),
|
|
97
|
+
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
131
98
|
signedPreKey: extractKey(signedKey),
|
|
132
99
|
preKey: extractKey(key)
|
|
133
100
|
}
|
|
134
101
|
});
|
|
135
|
-
}
|
|
102
|
+
}));
|
|
136
103
|
}
|
|
137
104
|
};
|
|
138
|
-
|
|
139
|
-
|
|
105
|
+
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
106
|
+
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
107
|
+
const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
|
|
140
108
|
const extracted = [];
|
|
141
109
|
for (const userResult of result) {
|
|
142
110
|
const { devices, id } = userResult;
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
) {
|
|
153
|
-
if (isHosted) {
|
|
154
|
-
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
111
|
+
const { user } = (0, WABinary_1.jidDecode)(id);
|
|
112
|
+
const deviceList = devices === null || devices === void 0 ? void 0 : devices.deviceList;
|
|
113
|
+
if (Array.isArray(deviceList)) {
|
|
114
|
+
for (const { id: device, keyIndex } of deviceList) {
|
|
115
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
116
|
+
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
117
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
118
|
+
) {
|
|
119
|
+
extracted.push({ user, device });
|
|
155
120
|
}
|
|
156
|
-
extracted.push({
|
|
157
|
-
user,
|
|
158
|
-
device,
|
|
159
|
-
domainType,
|
|
160
|
-
server: getServerFromDomainType(server, domainType)
|
|
161
|
-
});
|
|
162
121
|
}
|
|
163
122
|
}
|
|
164
123
|
}
|
|
165
124
|
return extracted;
|
|
166
125
|
};
|
|
126
|
+
exports.extractDeviceJids = extractDeviceJids;
|
|
167
127
|
/**
|
|
168
128
|
* get the next N keys for upload or processing
|
|
169
129
|
* @param count number of pre-keys to get or generate
|
|
170
130
|
*/
|
|
171
|
-
|
|
172
|
-
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
131
|
+
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
132
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
173
133
|
const update = {
|
|
174
134
|
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
175
135
|
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
176
136
|
};
|
|
177
137
|
await keys.set({ 'pre-key': newPreKeys });
|
|
178
|
-
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
138
|
+
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
179
139
|
return { update, preKeys };
|
|
180
140
|
};
|
|
181
|
-
|
|
141
|
+
exports.getNextPreKeys = getNextPreKeys;
|
|
142
|
+
const getNextPreKeysNode = async (state, count) => {
|
|
182
143
|
const { creds } = state;
|
|
183
|
-
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
144
|
+
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
184
145
|
const node = {
|
|
185
146
|
tag: 'iq',
|
|
186
147
|
attrs: {
|
|
187
148
|
xmlns: 'encrypt',
|
|
188
149
|
type: 'set',
|
|
189
|
-
to: S_WHATSAPP_NET
|
|
150
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
190
151
|
},
|
|
191
152
|
content: [
|
|
192
|
-
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
193
|
-
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
153
|
+
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
154
|
+
{ tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
|
|
194
155
|
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
195
|
-
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
|
|
196
|
-
xmppSignedPreKey(creds.signedPreKey)
|
|
156
|
+
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
|
|
157
|
+
(0, exports.xmppSignedPreKey)(creds.signedPreKey)
|
|
197
158
|
]
|
|
198
159
|
};
|
|
199
160
|
return { update, node };
|
|
200
161
|
};
|
|
201
|
-
|
|
162
|
+
exports.getNextPreKeysNode = getNextPreKeysNode;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMultiFileAuthState = void 0;
|
|
4
|
+
const async_mutex_1 = require("async-mutex");
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const WAProto_1 = require("../../WAProto");
|
|
8
|
+
const auth_utils_1 = require("./auth-utils");
|
|
9
|
+
const generics_1 = require("./generics");
|
|
7
10
|
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
8
11
|
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
9
12
|
// https://github.com/nodejs/node/issues/26338
|
|
@@ -13,7 +16,7 @@ const fileLocks = new Map();
|
|
|
13
16
|
const getFileLock = (path) => {
|
|
14
17
|
let mutex = fileLocks.get(path);
|
|
15
18
|
if (!mutex) {
|
|
16
|
-
mutex = new Mutex();
|
|
19
|
+
mutex = new async_mutex_1.Mutex();
|
|
17
20
|
fileLocks.set(path, mutex);
|
|
18
21
|
}
|
|
19
22
|
return mutex;
|
|
@@ -25,14 +28,14 @@ const getFileLock = (path) => {
|
|
|
25
28
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
26
29
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
27
30
|
* */
|
|
28
|
-
|
|
31
|
+
const useMultiFileAuthState = async (folder) => {
|
|
29
32
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
33
|
const writeData = async (data, file) => {
|
|
31
|
-
const filePath = join(folder, fixFileName(file));
|
|
34
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
32
35
|
const mutex = getFileLock(filePath);
|
|
33
36
|
return mutex.acquire().then(async (release) => {
|
|
34
37
|
try {
|
|
35
|
-
await writeFile(filePath, JSON.stringify(data, BufferJSON.replacer));
|
|
38
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
36
39
|
}
|
|
37
40
|
finally {
|
|
38
41
|
release();
|
|
@@ -41,12 +44,12 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
41
44
|
};
|
|
42
45
|
const readData = async (file) => {
|
|
43
46
|
try {
|
|
44
|
-
const filePath = join(folder, fixFileName(file));
|
|
47
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
45
48
|
const mutex = getFileLock(filePath);
|
|
46
49
|
return await mutex.acquire().then(async (release) => {
|
|
47
50
|
try {
|
|
48
|
-
const data = await readFile(filePath, { encoding: 'utf-8' });
|
|
49
|
-
return JSON.parse(data, BufferJSON.reviver);
|
|
51
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
52
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
50
53
|
}
|
|
51
54
|
finally {
|
|
52
55
|
release();
|
|
@@ -59,32 +62,33 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
59
62
|
};
|
|
60
63
|
const removeData = async (file) => {
|
|
61
64
|
try {
|
|
62
|
-
const filePath = join(folder, fixFileName(file));
|
|
65
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
63
66
|
const mutex = getFileLock(filePath);
|
|
64
67
|
return mutex.acquire().then(async (release) => {
|
|
65
68
|
try {
|
|
66
|
-
await unlink(filePath);
|
|
69
|
+
await (0, promises_1.unlink)(filePath);
|
|
67
70
|
}
|
|
68
|
-
catch {
|
|
71
|
+
catch (_a) {
|
|
69
72
|
}
|
|
70
73
|
finally {
|
|
71
74
|
release();
|
|
72
75
|
}
|
|
73
76
|
});
|
|
74
77
|
}
|
|
75
|
-
catch {
|
|
78
|
+
catch (_a) {
|
|
79
|
+
}
|
|
76
80
|
};
|
|
77
|
-
const folderInfo = await stat(folder).catch(() => { });
|
|
81
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
78
82
|
if (folderInfo) {
|
|
79
83
|
if (!folderInfo.isDirectory()) {
|
|
80
84
|
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
else {
|
|
84
|
-
await mkdir(folder, { recursive: true });
|
|
88
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
85
89
|
}
|
|
86
|
-
const fixFileName = (file) => file
|
|
87
|
-
const creds =
|
|
90
|
+
const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
|
|
91
|
+
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
88
92
|
return {
|
|
89
93
|
state: {
|
|
90
94
|
creds,
|
|
@@ -94,7 +98,7 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
94
98
|
await Promise.all(ids.map(async (id) => {
|
|
95
99
|
let value = await readData(`${type}-${id}.json`);
|
|
96
100
|
if (type === 'app-state-sync-key' && value) {
|
|
97
|
-
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
101
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
98
102
|
}
|
|
99
103
|
data[id] = value;
|
|
100
104
|
}));
|
|
@@ -118,4 +122,4 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
118
122
|
}
|
|
119
123
|
};
|
|
120
124
|
};
|
|
121
|
-
|
|
125
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|