@vinzsocket/baileys 2.8.9 → 2.8.20

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.
Files changed (83) hide show
  1. package/lib/Defaults/index.js +75 -73
  2. package/lib/Signal/Group/ciphertext-message.js +9 -9
  3. package/lib/Signal/Group/group-session-builder.js +21 -21
  4. package/lib/Signal/Group/group_cipher.js +79 -81
  5. package/lib/Signal/Group/index.js +2 -2
  6. package/lib/Signal/Group/keyhelper.js +9 -9
  7. package/lib/Signal/Group/queue-job.js +43 -46
  8. package/lib/Signal/Group/sender-chain-key.js +24 -25
  9. package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
  10. package/lib/Signal/Group/sender-key-message.js +55 -60
  11. package/lib/Signal/Group/sender-key-name.js +38 -39
  12. package/lib/Signal/Group/sender-key-record.js +39 -41
  13. package/lib/Signal/Group/sender-key-state.js +85 -89
  14. package/lib/Signal/Group/sender-message-key.js +22 -22
  15. package/lib/Signal/libsignal.js +387 -292
  16. package/lib/Signal/lid-mapping.js +98 -93
  17. package/lib/Socket/Client/types.js +6 -6
  18. package/lib/Socket/Client/websocket.js +44 -44
  19. package/lib/Socket/business.js +350 -365
  20. package/lib/Socket/chats.js +1019 -914
  21. package/lib/Socket/communities.js +454 -376
  22. package/lib/Socket/groups.js +378 -310
  23. package/lib/Socket/index.js +11 -11
  24. package/lib/Socket/messages-recv.js +1355 -1182
  25. package/lib/Socket/messages-send.js +1224 -1081
  26. package/lib/Socket/mex.js +40 -34
  27. package/lib/Socket/newsletter.js +212 -169
  28. package/lib/Socket/socket.js +896 -757
  29. package/lib/Store/index.js +1 -1
  30. package/lib/Store/make-cache-manager-store.js +75 -79
  31. package/lib/Store/make-in-memory-store.js +450 -389
  32. package/lib/Store/make-ordered-dictionary.js +73 -76
  33. package/lib/Store/object-repository.js +24 -22
  34. package/lib/Types/Chat.js +1 -7
  35. package/lib/Types/Label.js +20 -20
  36. package/lib/Types/LabelAssociation.js +2 -2
  37. package/lib/Types/Message.js +2 -2
  38. package/lib/Types/Newsletter.js +24 -24
  39. package/lib/Types/Socket.js +1 -1
  40. package/lib/Types/State.js +8 -8
  41. package/lib/Types/index.js +10 -10
  42. package/lib/Utils/auth-utils.js +408 -401
  43. package/lib/Utils/baileys-event-stream.js +44 -35
  44. package/lib/Utils/business.js +200 -197
  45. package/lib/Utils/chat-utils.js +775 -708
  46. package/lib/Utils/crypto.js +97 -85
  47. package/lib/Utils/decode-wa-message.js +240 -227
  48. package/lib/Utils/event-buffer.js +547 -518
  49. package/lib/Utils/extended-messages.js +250 -203
  50. package/lib/Utils/generics.js +300 -289
  51. package/lib/Utils/history.js +76 -69
  52. package/lib/Utils/lid-resolver.js +47 -42
  53. package/lib/Utils/link-preview.js +75 -65
  54. package/lib/Utils/logger.js +3 -1
  55. package/lib/Utils/lt-hash.js +38 -34
  56. package/lib/Utils/make-mutex.js +32 -34
  57. package/lib/Utils/mention.js +79 -86
  58. package/lib/Utils/message-retry-manager.js +148 -136
  59. package/lib/Utils/messages-media.js +652 -562
  60. package/lib/Utils/messages.js +753 -707
  61. package/lib/Utils/noise-handler.js +156 -135
  62. package/lib/Utils/process-message.js +404 -341
  63. package/lib/Utils/signal.js +180 -118
  64. package/lib/Utils/use-multi-file-auth-state.js +87 -91
  65. package/lib/Utils/validate-connection.js +167 -142
  66. package/lib/WABinary/constants.js +28 -1293
  67. package/lib/WABinary/decode.js +220 -218
  68. package/lib/WABinary/encode.js +199 -201
  69. package/lib/WABinary/generic-utils.js +80 -77
  70. package/lib/WABinary/jid-utils.js +41 -35
  71. package/lib/WAM/BinaryInfo.js +7 -7
  72. package/lib/WAM/constants.js +1 -15241
  73. package/lib/WAM/encode.js +124 -131
  74. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
  76. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
  77. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
  78. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
  81. package/lib/WAUSync/USyncQuery.js +82 -84
  82. package/lib/WAUSync/USyncUser.js +20 -20
  83. package/package.json +4 -1
@@ -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
- const chunks = [];
7
- for (let i = 0; i < array.length; i += size) {
8
- chunks.push(array.slice(i, i + size));
9
- }
10
- return chunks;
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
- return {
14
- identifier: { name: wid, deviceId: 0 },
15
- identifierKey: generateSignalPubKey(accountSignatureKey)
16
- };
13
+ return {
14
+ identifier: {
15
+ name: wid,
16
+ deviceId: 0
17
+ },
18
+ identifierKey: generateSignalPubKey(accountSignatureKey)
19
+ };
17
20
  };
18
- export const getPreKeys = async ({ get }, min, limit) => {
19
- const idList = [];
20
- for (let id = min; id < limit; id++) {
21
- idList.push(id.toString());
22
- }
23
- return get('pre-key', idList);
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
- const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
27
- const remaining = range - avaliable;
28
- const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
29
- const newPreKeys = {};
30
- if (remaining > 0) {
31
- for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
32
- newPreKeys[i] = Curve.generateKeyPair();
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
- return {
36
- newPreKeys,
37
- lastPreKeyId,
38
- preKeysRange: [creds.firstUnuploadedPreKeyId, range]
39
- };
39
+ }
40
+ return {
41
+ newPreKeys,
42
+ lastPreKeyId,
43
+ preKeysRange: [creds.firstUnuploadedPreKeyId, range]
44
+ };
40
45
  };
41
- export const xmppSignedPreKey = (key) => ({
42
- tag: 'skey',
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
- { tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
46
- { tag: 'value', attrs: {}, content: key.keyPair.public },
47
- { tag: 'signature', attrs: {}, content: key.signature }
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
- tag: 'key',
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
- { tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
55
- { tag: 'value', attrs: {}, content: pair.public }
56
- ]
73
+ content: pair.public
74
+ }]
57
75
  });
58
76
  export const parseAndInjectE2ESessions = async (node, repository) => {
59
- const extractKey = (key) => key
60
- ? {
61
- keyId: getBinaryNodeChildUInt(key, 'id', 3),
62
- publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
63
- signature: getBinaryNodeChildBuffer(key, 'signature')
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
- : undefined;
66
- const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
67
- for (const node of nodes) {
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
- const { user: myUser, device: myDevice } = jidDecode(myJid);
98
- const extracted = [];
99
- for (const userResult of result) {
100
- const { devices, id } = userResult;
101
- const { user } = jidDecode(id);
102
- const deviceList = devices?.deviceList;
103
- if (Array.isArray(deviceList)) {
104
- for (const { id: device, keyIndex } of deviceList) {
105
- if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
106
- (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
107
- (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
108
- ) {
109
- extracted.push({ user, device });
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
- return extracted;
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 ({ creds, keys }, count) => {
121
- const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
122
- const update = {
123
- nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
124
- firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
125
- };
126
- await keys.set({ 'pre-key': newPreKeys });
127
- const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
128
- return { update, preKeys };
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
- const { creds } = state;
132
- const { update, preKeys } = await getNextPreKeys(state, count);
133
- const node = {
134
- tag: 'iq',
135
- attrs: {
136
- xmlns: 'encrypt',
137
- type: 'set',
138
- to: S_WHATSAPP_NET
139
- },
140
- content: [
141
- { tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
142
- { tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
143
- { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
144
- { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
145
- xmppSignedPreKey(creds.signedPreKey)
146
- ]
147
- };
148
- return { update, node };
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 = (path) => {
14
- let mutex = fileLocks.get(path);
15
- if (!mutex) {
16
- mutex = new Mutex();
17
- fileLocks.set(path, mutex);
18
- }
19
- return mutex;
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 (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
- }
37
- finally {
38
- release();
39
- }
40
- });
41
- };
42
- const readData = async (file) => {
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
- const filePath = join(folder, fixFileName(file));
45
- const mutex = getFileLock(filePath);
46
- return await mutex.acquire().then(async (release) => {
47
- try {
48
- const data = await readFile(filePath, { encoding: 'utf-8' });
49
- return JSON.parse(data, BufferJSON.reviver);
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
- catch (error) {
57
- return null;
58
- }
59
- };
60
- const removeData = async (file) => {
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
- const filePath = join(folder, fixFileName(file));
63
- const mutex = getFileLock(filePath);
64
- return mutex.acquire().then(async (release) => {
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
- catch { }
76
- };
77
- const folderInfo = await stat(folder).catch(() => { });
78
- if (folderInfo) {
79
- if (!folderInfo.isDirectory()) {
80
- throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
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
- const fixFileName = (file) => file?.replace(/\//g, '__')?.replace(/:/g, '-');
87
- const creds = (await readData('creds.json')) || initAuthCreds();
88
- return {
89
- state: {
90
- creds,
91
- keys: {
92
- get: async (type, ids) => {
93
- const data = {};
94
- await Promise.all(ids.map(async (id) => {
95
- let value = await readData(`${type}-${id}.json`);
96
- if (type === 'app-state-sync-key' && value) {
97
- value = proto.Message.AppStateSyncKeyData.create(value);
98
- }
99
- data[id] = value;
100
- }));
101
- return data;
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
- saveCreds: async () => {
117
- return writeData(creds, 'creds.json');
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