@vinzsocket/baileys 2.8.10 → 2.8.30
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/lib/Defaults/index.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +4 -2
package/lib/Utils/signal.js
CHANGED
|
@@ -3,148 +3,210 @@ import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getB
|
|
|
3
3
|
import { Curve, generateSignalPubKey } from './crypto.js';
|
|
4
4
|
import { encodeBigEndian } from './generics.js';
|
|
5
5
|
function chunk(array, size) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const chunks = [];
|
|
7
|
+
for (let i = 0; i < array.length; i += size) {
|
|
8
|
+
chunks.push(array.slice(i, i + size));
|
|
9
|
+
}
|
|
10
|
+
return chunks;
|
|
11
11
|
}
|
|
12
12
|
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
return {
|
|
14
|
+
identifier: {
|
|
15
|
+
name: wid,
|
|
16
|
+
deviceId: 0
|
|
17
|
+
},
|
|
18
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
|
-
export const getPreKeys = async ({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
export const getPreKeys = async ({
|
|
22
|
+
get
|
|
23
|
+
}, min, limit) => {
|
|
24
|
+
const idList = [];
|
|
25
|
+
for (let id = min; id < limit; id++) {
|
|
26
|
+
idList.push(id.toString());
|
|
27
|
+
}
|
|
28
|
+
return get('pre-key', idList);
|
|
24
29
|
};
|
|
25
30
|
export const generateOrGetPreKeys = (creds, range) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
31
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
32
|
+
const remaining = range - avaliable;
|
|
33
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
34
|
+
const newPreKeys = {};
|
|
35
|
+
if (remaining > 0) {
|
|
36
|
+
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
37
|
+
newPreKeys[i] = Curve.generateKeyPair();
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
newPreKeys,
|
|
42
|
+
lastPreKeyId,
|
|
43
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
44
|
+
};
|
|
40
45
|
};
|
|
41
|
-
export const xmppSignedPreKey =
|
|
42
|
-
|
|
46
|
+
export const xmppSignedPreKey = key => ({
|
|
47
|
+
tag: 'skey',
|
|
48
|
+
attrs: {},
|
|
49
|
+
content: [{
|
|
50
|
+
tag: 'id',
|
|
51
|
+
attrs: {},
|
|
52
|
+
content: encodeBigEndian(key.keyId, 3)
|
|
53
|
+
}, {
|
|
54
|
+
tag: 'value',
|
|
43
55
|
attrs: {},
|
|
44
|
-
content:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
content: key.keyPair.public
|
|
57
|
+
}, {
|
|
58
|
+
tag: 'signature',
|
|
59
|
+
attrs: {},
|
|
60
|
+
content: key.signature
|
|
61
|
+
}]
|
|
49
62
|
});
|
|
50
63
|
export const xmppPreKey = (pair, id) => ({
|
|
51
|
-
|
|
64
|
+
tag: 'key',
|
|
65
|
+
attrs: {},
|
|
66
|
+
content: [{
|
|
67
|
+
tag: 'id',
|
|
68
|
+
attrs: {},
|
|
69
|
+
content: encodeBigEndian(id, 3)
|
|
70
|
+
}, {
|
|
71
|
+
tag: 'value',
|
|
52
72
|
attrs: {},
|
|
53
|
-
content:
|
|
54
|
-
|
|
55
|
-
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
|
-
]
|
|
73
|
+
content: pair.public
|
|
74
|
+
}]
|
|
57
75
|
});
|
|
58
76
|
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
const extractKey = key => key ? {
|
|
78
|
+
keyId: getBinaryNodeChildUInt(key, 'id', 3),
|
|
79
|
+
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
|
|
80
|
+
signature: getBinaryNodeChildBuffer(key, 'signature')
|
|
81
|
+
} : undefined;
|
|
82
|
+
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
|
|
83
|
+
for (const node of nodes) {
|
|
84
|
+
assertNodeErrorFree(node);
|
|
85
|
+
}
|
|
86
|
+
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
87
|
+
// So Promise.all doesn't really help here,
|
|
88
|
+
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
89
|
+
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
90
|
+
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
91
|
+
const chunkSize = 100;
|
|
92
|
+
const chunks = chunk(nodes, chunkSize);
|
|
93
|
+
for (const nodesChunk of chunks) {
|
|
94
|
+
await Promise.all(nodesChunk.map(async node => {
|
|
95
|
+
const signedKey = getBinaryNodeChild(node, 'skey');
|
|
96
|
+
const key = getBinaryNodeChild(node, 'key');
|
|
97
|
+
const identity = getBinaryNodeChildBuffer(node, 'identity');
|
|
98
|
+
const jid = node.attrs.jid;
|
|
99
|
+
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
|
|
100
|
+
await repository.injectE2ESession({
|
|
101
|
+
jid,
|
|
102
|
+
session: {
|
|
103
|
+
registrationId: registrationId,
|
|
104
|
+
identityKey: generateSignalPubKey(identity),
|
|
105
|
+
signedPreKey: extractKey(signedKey),
|
|
106
|
+
preKey: extractKey(key)
|
|
64
107
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
assertNodeErrorFree(node);
|
|
69
|
-
}
|
|
70
|
-
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
71
|
-
// So Promise.all doesn't really help here,
|
|
72
|
-
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
73
|
-
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
74
|
-
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
75
|
-
const chunkSize = 100;
|
|
76
|
-
const chunks = chunk(nodes, chunkSize);
|
|
77
|
-
for (const nodesChunk of chunks) {
|
|
78
|
-
await Promise.all(nodesChunk.map(async (node) => {
|
|
79
|
-
const signedKey = getBinaryNodeChild(node, 'skey');
|
|
80
|
-
const key = getBinaryNodeChild(node, 'key');
|
|
81
|
-
const identity = getBinaryNodeChildBuffer(node, 'identity');
|
|
82
|
-
const jid = node.attrs.jid;
|
|
83
|
-
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
|
|
84
|
-
await repository.injectE2ESession({
|
|
85
|
-
jid,
|
|
86
|
-
session: {
|
|
87
|
-
registrationId: registrationId,
|
|
88
|
-
identityKey: generateSignalPubKey(identity),
|
|
89
|
-
signedPreKey: extractKey(signedKey),
|
|
90
|
-
preKey: extractKey(key)
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
108
|
+
});
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
95
111
|
};
|
|
96
112
|
export const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
const {
|
|
114
|
+
user: myUser,
|
|
115
|
+
device: myDevice
|
|
116
|
+
} = jidDecode(myJid);
|
|
117
|
+
const extracted = [];
|
|
118
|
+
for (const userResult of result) {
|
|
119
|
+
const {
|
|
120
|
+
devices,
|
|
121
|
+
id
|
|
122
|
+
} = userResult;
|
|
123
|
+
const {
|
|
124
|
+
user
|
|
125
|
+
} = jidDecode(id);
|
|
126
|
+
const deviceList = devices?.deviceList;
|
|
127
|
+
if (Array.isArray(deviceList)) {
|
|
128
|
+
for (const {
|
|
129
|
+
id: device,
|
|
130
|
+
keyIndex
|
|
131
|
+
} of deviceList) {
|
|
132
|
+
if ((!excludeZeroDevices || device !== 0) && (
|
|
133
|
+
// if zero devices are not-excluded, or device is non zero
|
|
134
|
+
myUser !== user || myDevice !== device) && (
|
|
135
|
+
// either different user or if me user, not this device
|
|
136
|
+
device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
137
|
+
) {
|
|
138
|
+
extracted.push({
|
|
139
|
+
user,
|
|
140
|
+
device
|
|
141
|
+
});
|
|
112
142
|
}
|
|
143
|
+
}
|
|
113
144
|
}
|
|
114
|
-
|
|
145
|
+
}
|
|
146
|
+
return extracted;
|
|
115
147
|
};
|
|
116
148
|
/**
|
|
117
149
|
* get the next N keys for upload or processing
|
|
118
150
|
* @param count number of pre-keys to get or generate
|
|
119
151
|
*/
|
|
120
|
-
export const getNextPreKeys = async ({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
152
|
+
export const getNextPreKeys = async ({
|
|
153
|
+
creds,
|
|
154
|
+
keys
|
|
155
|
+
}, count) => {
|
|
156
|
+
const {
|
|
157
|
+
newPreKeys,
|
|
158
|
+
lastPreKeyId,
|
|
159
|
+
preKeysRange
|
|
160
|
+
} = generateOrGetPreKeys(creds, count);
|
|
161
|
+
const update = {
|
|
162
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
163
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
164
|
+
};
|
|
165
|
+
await keys.set({
|
|
166
|
+
'pre-key': newPreKeys
|
|
167
|
+
});
|
|
168
|
+
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
169
|
+
return {
|
|
170
|
+
update,
|
|
171
|
+
preKeys
|
|
172
|
+
};
|
|
129
173
|
};
|
|
130
174
|
export const getNextPreKeysNode = async (state, count) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
175
|
+
const {
|
|
176
|
+
creds
|
|
177
|
+
} = state;
|
|
178
|
+
const {
|
|
179
|
+
update,
|
|
180
|
+
preKeys
|
|
181
|
+
} = await getNextPreKeys(state, count);
|
|
182
|
+
const node = {
|
|
183
|
+
tag: 'iq',
|
|
184
|
+
attrs: {
|
|
185
|
+
xmlns: 'encrypt',
|
|
186
|
+
type: 'set',
|
|
187
|
+
to: S_WHATSAPP_NET
|
|
188
|
+
},
|
|
189
|
+
content: [{
|
|
190
|
+
tag: 'registration',
|
|
191
|
+
attrs: {},
|
|
192
|
+
content: encodeBigEndian(creds.registrationId)
|
|
193
|
+
}, {
|
|
194
|
+
tag: 'type',
|
|
195
|
+
attrs: {},
|
|
196
|
+
content: KEY_BUNDLE_TYPE
|
|
197
|
+
}, {
|
|
198
|
+
tag: 'identity',
|
|
199
|
+
attrs: {},
|
|
200
|
+
content: creds.signedIdentityKey.public
|
|
201
|
+
}, {
|
|
202
|
+
tag: 'list',
|
|
203
|
+
attrs: {},
|
|
204
|
+
content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k))
|
|
205
|
+
}, xmppSignedPreKey(creds.signedPreKey)]
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
update,
|
|
209
|
+
node
|
|
210
|
+
};
|
|
149
211
|
};
|
|
150
212
|
//# sourceMappingURL=signal.js.map
|
|
@@ -10,13 +10,13 @@ import { BufferJSON } from './generics.js';
|
|
|
10
10
|
// Use a Map to store mutexes for each file path
|
|
11
11
|
const fileLocks = new Map();
|
|
12
12
|
// Get or create a mutex for a specific file path
|
|
13
|
-
const getFileLock =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const getFileLock = path => {
|
|
14
|
+
let mutex = fileLocks.get(path);
|
|
15
|
+
if (!mutex) {
|
|
16
|
+
mutex = new Mutex();
|
|
17
|
+
fileLocks.set(path, mutex);
|
|
18
|
+
}
|
|
19
|
+
return mutex;
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* stores the full authentication state in a single folder.
|
|
@@ -25,97 +25,93 @@ const getFileLock = (path) => {
|
|
|
25
25
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
26
26
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
27
27
|
* */
|
|
28
|
-
export const useMultiFileAuthState = async
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
export const useMultiFileAuthState = async folder => {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
const writeData = async (data, file) => {
|
|
31
|
+
const filePath = join(folder, fixFileName(file));
|
|
32
|
+
const mutex = getFileLock(filePath);
|
|
33
|
+
return mutex.acquire().then(async release => {
|
|
34
|
+
try {
|
|
35
|
+
await writeFile(filePath, JSON.stringify(data, BufferJSON.replacer));
|
|
36
|
+
} finally {
|
|
37
|
+
release();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const readData = async file => {
|
|
42
|
+
try {
|
|
43
|
+
const filePath = join(folder, fixFileName(file));
|
|
44
|
+
const mutex = getFileLock(filePath);
|
|
45
|
+
return await mutex.acquire().then(async release => {
|
|
43
46
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
release();
|
|
53
|
-
}
|
|
54
|
-
});
|
|
47
|
+
const data = await readFile(filePath, {
|
|
48
|
+
encoding: 'utf-8'
|
|
49
|
+
});
|
|
50
|
+
return JSON.parse(data, BufferJSON.reviver);
|
|
51
|
+
} finally {
|
|
52
|
+
release();
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
54
|
+
});
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const removeData = async file => {
|
|
60
|
+
try {
|
|
61
|
+
const filePath = join(folder, fixFileName(file));
|
|
62
|
+
const mutex = getFileLock(filePath);
|
|
63
|
+
return mutex.acquire().then(async release => {
|
|
61
64
|
try {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
await unlink(filePath);
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
release();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
65
|
+
await unlink(filePath);
|
|
66
|
+
} catch {} finally {
|
|
67
|
+
release();
|
|
74
68
|
}
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
await mkdir(folder, { recursive: true });
|
|
69
|
+
});
|
|
70
|
+
} catch {}
|
|
71
|
+
};
|
|
72
|
+
const folderInfo = await stat(folder).catch(() => {});
|
|
73
|
+
if (folderInfo) {
|
|
74
|
+
if (!folderInfo.isDirectory()) {
|
|
75
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
85
76
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
set: async (data) => {
|
|
104
|
-
const tasks = [];
|
|
105
|
-
for (const category in data) {
|
|
106
|
-
for (const id in data[category]) {
|
|
107
|
-
const value = data[category][id];
|
|
108
|
-
const file = `${category}-${id}.json`;
|
|
109
|
-
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
await Promise.all(tasks);
|
|
113
|
-
}
|
|
77
|
+
} else {
|
|
78
|
+
await mkdir(folder, {
|
|
79
|
+
recursive: true
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const fixFileName = file => file?.replace(/\//g, '__')?.replace(/:/g, '-');
|
|
83
|
+
const creds = (await readData('creds.json')) || initAuthCreds();
|
|
84
|
+
return {
|
|
85
|
+
state: {
|
|
86
|
+
creds,
|
|
87
|
+
keys: {
|
|
88
|
+
get: async (type, ids) => {
|
|
89
|
+
const data = {};
|
|
90
|
+
await Promise.all(ids.map(async id => {
|
|
91
|
+
let value = await readData(`${type}-${id}.json`);
|
|
92
|
+
if (type === 'app-state-sync-key' && value) {
|
|
93
|
+
value = proto.Message.AppStateSyncKeyData.create(value);
|
|
114
94
|
}
|
|
95
|
+
data[id] = value;
|
|
96
|
+
}));
|
|
97
|
+
return data;
|
|
115
98
|
},
|
|
116
|
-
|
|
117
|
-
|
|
99
|
+
set: async data => {
|
|
100
|
+
const tasks = [];
|
|
101
|
+
for (const category in data) {
|
|
102
|
+
for (const id in data[category]) {
|
|
103
|
+
const value = data[category][id];
|
|
104
|
+
const file = `${category}-${id}.json`;
|
|
105
|
+
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
await Promise.all(tasks);
|
|
118
109
|
}
|
|
119
|
-
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
saveCreds: async () => {
|
|
113
|
+
return writeData(creds, 'creds.json');
|
|
114
|
+
}
|
|
115
|
+
};
|
|
120
116
|
};
|
|
121
117
|
//# sourceMappingURL=use-multi-file-auth-state.js.map
|