cuki-bailx 1.2.4 → 1.2.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/LICENSE +21 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.js +56886 -17506
- package/engine-requirements.js +1 -1
- package/lib/Defaults/index.js +98 -108
- package/lib/Defaults/vyzen-baileysx-version.json +3 -0
- package/lib/Signal/libsignal.js +2 -0
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
- package/lib/Socket/chats.js +224 -173
- package/lib/Socket/groups.js +20 -5
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.js +10 -66
- package/lib/Socket/messages-send.js +379 -312
- package/lib/Socket/newsletter.js +54 -40
- package/lib/Socket/socket.js +58 -32
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +27 -15
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.js +3 -17
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.js +6 -13
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/browser-utils.js +35 -0
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.js +36 -35
- package/lib/Utils/crypto.js +71 -29
- package/lib/Utils/decode-wa-message.js +65 -56
- package/lib/Utils/event-buffer.js +13 -9
- package/lib/Utils/generics.js +107 -29
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/index.js +2 -0
- package/lib/Utils/link-preview.js +34 -1
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/message-retry-manager.js +128 -0
- package/lib/Utils/messages-media.js +263 -115
- package/lib/Utils/messages.js +500 -93
- package/lib/Utils/noise-handler.js +18 -23
- package/lib/Utils/process-message.js +108 -25
- package/lib/Utils/signal.js +37 -35
- package/lib/Utils/use-multi-file-auth-state.js +51 -6
- package/lib/Utils/validate-connection.js +90 -66
- package/lib/WABinary/constants.js +1276 -13
- package/lib/WABinary/decode.js +26 -13
- package/lib/WABinary/encode.js +39 -17
- package/lib/WABinary/generic-utils.js +2 -85
- package/lib/WABinary/jid-utils.js +28 -5
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.js +18 -5
- package/package.json +109 -104
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -53
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.d.ts +0 -12
- package/lib/Socket/business.d.ts +0 -171
- package/lib/Socket/chats.d.ts +0 -80
- package/lib/Socket/dugong.d.ts +0 -219
- package/lib/Socket/dugong.js +0 -441
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -173
- package/lib/Socket/messages-recv.d.ts +0 -161
- package/lib/Socket/messages-send.d.ts +0 -149
- package/lib/Socket/newsletter.d.ts +0 -134
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -43
- package/lib/Socket/socket.js.bak +0 -630
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -13
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -110
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -102
- package/lib/Types/Contact.d.ts +0 -19
- package/lib/Types/Events.d.ts +0 -157
- package/lib/Types/GroupMetadata.d.ts +0 -55
- package/lib/Types/Label.d.ts +0 -35
- package/lib/Types/LabelAssociation.d.ts +0 -29
- package/lib/Types/Message.d.ts +0 -273
- package/lib/Types/Newsletter.d.ts +0 -92
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/Socket.d.ts +0 -111
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/index.d.ts +0 -57
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -71
- package/lib/Utils/crypto.d.ts +0 -41
- package/lib/Utils/decode-wa-message.d.ts +0 -19
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -15
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -4
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -116
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -21
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -16
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -17
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -12
- package/lib/index.js.bak +0 -48
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
package/lib/Socket/newsletter.js
CHANGED
|
@@ -5,6 +5,20 @@ const Types_1 = require("../Types");
|
|
|
5
5
|
const Utils_1 = require("../Utils");
|
|
6
6
|
const WABinary_1 = require("../WABinary");
|
|
7
7
|
const groups_1 = require("./groups");
|
|
8
|
+
var QueryIds;
|
|
9
|
+
(function (QueryIds) {
|
|
10
|
+
QueryIds["JOB_MUTATION"] = "7150902998257522";
|
|
11
|
+
QueryIds["METADATA"] = "6620195908089573";
|
|
12
|
+
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
13
|
+
QueryIds["FOLLOW"] = "7871414976211147";
|
|
14
|
+
QueryIds["UNMUTE"] = "7337137176362961";
|
|
15
|
+
QueryIds["MUTE"] = "25151904754424642";
|
|
16
|
+
QueryIds["CREATE"] = "6996806640408138";
|
|
17
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
18
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
19
|
+
QueryIds["DELETE"] = "8316537688363079";
|
|
20
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
|
21
|
+
})(QueryIds || (QueryIds = {}));
|
|
8
22
|
const makeNewsletterSocket = (config) => {
|
|
9
23
|
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
10
24
|
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
@@ -19,7 +33,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
19
33
|
},
|
|
20
34
|
content
|
|
21
35
|
}));
|
|
22
|
-
const newsletterWMexQuery = async (jid,
|
|
36
|
+
const newsletterWMexQuery = async (jid, query_id, content) => (query({
|
|
23
37
|
tag: 'iq',
|
|
24
38
|
attrs: {
|
|
25
39
|
id: generateMessageTag(),
|
|
@@ -30,7 +44,7 @@ const makeNewsletterSocket = (config) => {
|
|
|
30
44
|
content: [
|
|
31
45
|
{
|
|
32
46
|
tag: 'query',
|
|
33
|
-
attrs: {
|
|
47
|
+
attrs: { query_id },
|
|
34
48
|
content: encoder.encode(JSON.stringify({
|
|
35
49
|
variables: {
|
|
36
50
|
'newsletter_id': jid,
|
|
@@ -42,9 +56,8 @@ const makeNewsletterSocket = (config) => {
|
|
|
42
56
|
}));
|
|
43
57
|
const parseFetchedUpdates = async (node, type) => {
|
|
44
58
|
let child;
|
|
45
|
-
if (type === 'messages')
|
|
59
|
+
if (type === 'messages')
|
|
46
60
|
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
47
|
-
}
|
|
48
61
|
else {
|
|
49
62
|
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
50
63
|
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
@@ -77,49 +90,44 @@ const makeNewsletterSocket = (config) => {
|
|
|
77
90
|
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
78
91
|
},
|
|
79
92
|
newsletterReactionMode: async (jid, mode) => {
|
|
80
|
-
await newsletterWMexQuery(jid,
|
|
81
|
-
updates: { settings: {
|
|
93
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
94
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
|
82
95
|
});
|
|
83
96
|
},
|
|
84
97
|
newsletterUpdateDescription: async (jid, description) => {
|
|
85
|
-
await newsletterWMexQuery(jid,
|
|
98
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
86
99
|
updates: { description: description || '', settings: null }
|
|
87
100
|
});
|
|
88
101
|
},
|
|
89
102
|
newsletterUpdateName: async (jid, name) => {
|
|
90
|
-
await newsletterWMexQuery(jid,
|
|
103
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
91
104
|
updates: { name, settings: null }
|
|
92
105
|
});
|
|
93
106
|
},
|
|
94
107
|
newsletterUpdatePicture: async (jid, content) => {
|
|
95
108
|
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
96
|
-
await newsletterWMexQuery(jid,
|
|
109
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
97
110
|
updates: { picture: img.toString('base64'), settings: null }
|
|
98
111
|
});
|
|
99
112
|
},
|
|
100
113
|
newsletterRemovePicture: async (jid) => {
|
|
101
|
-
await newsletterWMexQuery(jid,
|
|
114
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
102
115
|
updates: { picture: '', settings: null }
|
|
103
116
|
});
|
|
104
117
|
},
|
|
105
118
|
newsletterUnfollow: async (jid) => {
|
|
106
|
-
await newsletterWMexQuery(jid,
|
|
119
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
107
120
|
},
|
|
108
121
|
newsletterFollow: async (jid) => {
|
|
109
|
-
await newsletterWMexQuery(jid,
|
|
122
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
110
123
|
},
|
|
111
124
|
newsletterUnmute: async (jid) => {
|
|
112
|
-
await newsletterWMexQuery(jid,
|
|
125
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
113
126
|
},
|
|
114
127
|
newsletterMute: async (jid) => {
|
|
115
|
-
await newsletterWMexQuery(jid,
|
|
116
|
-
},
|
|
117
|
-
newsletterAction: async (jid, type) => {
|
|
118
|
-
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
128
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
119
129
|
},
|
|
120
|
-
newsletterCreate: async (name, description,
|
|
121
|
-
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
122
|
-
/**tos query */
|
|
130
|
+
newsletterCreate: async (name, description, picture) => {
|
|
123
131
|
await query({
|
|
124
132
|
tag: 'iq',
|
|
125
133
|
attrs: {
|
|
@@ -139,50 +147,55 @@ const makeNewsletterSocket = (config) => {
|
|
|
139
147
|
}
|
|
140
148
|
]
|
|
141
149
|
});
|
|
142
|
-
const result = await newsletterWMexQuery(undefined,
|
|
143
|
-
input: {
|
|
150
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
151
|
+
input: {
|
|
152
|
+
name,
|
|
153
|
+
description: description !== null && description !== void 0 ? description : null,
|
|
154
|
+
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
155
|
+
settings: null
|
|
156
|
+
}
|
|
144
157
|
});
|
|
145
158
|
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
146
159
|
},
|
|
147
160
|
newsletterMetadata: async (type, key, role) => {
|
|
148
|
-
const result = await newsletterWMexQuery(undefined,
|
|
161
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
149
162
|
input: {
|
|
150
163
|
key,
|
|
151
164
|
type: type.toUpperCase(),
|
|
152
|
-
|
|
165
|
+
view_role: role || 'GUEST'
|
|
153
166
|
},
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
fetch_viewer_metadata: true,
|
|
168
|
+
fetch_full_image: true,
|
|
169
|
+
fetch_creation_time: true
|
|
157
170
|
});
|
|
158
171
|
return (0, exports.extractNewsletterMetadata)(result);
|
|
159
172
|
},
|
|
160
173
|
newsletterAdminCount: async (jid) => {
|
|
161
174
|
var _a, _b;
|
|
162
|
-
const result = await newsletterWMexQuery(jid,
|
|
175
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
163
176
|
const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
164
177
|
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
165
178
|
},
|
|
166
179
|
/**user is Lid, not Jid */
|
|
167
180
|
newsletterChangeOwner: async (jid, user) => {
|
|
168
|
-
await newsletterWMexQuery(jid,
|
|
169
|
-
|
|
181
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
182
|
+
user_id: user
|
|
170
183
|
});
|
|
171
184
|
},
|
|
172
185
|
/**user is Lid, not Jid */
|
|
173
186
|
newsletterDemote: async (jid, user) => {
|
|
174
|
-
await newsletterWMexQuery(jid,
|
|
175
|
-
|
|
187
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
188
|
+
user_id: user
|
|
176
189
|
});
|
|
177
190
|
},
|
|
178
191
|
newsletterDelete: async (jid) => {
|
|
179
|
-
await newsletterWMexQuery(jid,
|
|
192
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
180
193
|
},
|
|
181
194
|
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
182
|
-
newsletterReactMessage: async (jid,
|
|
195
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
|
183
196
|
await query({
|
|
184
197
|
tag: 'message',
|
|
185
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction',
|
|
198
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
186
199
|
content: [{
|
|
187
200
|
tag: 'reaction',
|
|
188
201
|
attrs: code ? { code } : {}
|
|
@@ -190,10 +203,11 @@ const makeNewsletterSocket = (config) => {
|
|
|
190
203
|
});
|
|
191
204
|
},
|
|
192
205
|
newsletterFetchMessages: async (type, key, count, after) => {
|
|
206
|
+
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
193
207
|
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
194
208
|
{
|
|
195
209
|
tag: 'messages',
|
|
196
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after:
|
|
210
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
197
211
|
}
|
|
198
212
|
]);
|
|
199
213
|
return await parseFetchedUpdates(result, 'messages');
|
|
@@ -211,13 +225,13 @@ const makeNewsletterSocket = (config) => {
|
|
|
211
225
|
};
|
|
212
226
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
213
227
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
214
|
-
var _a, _b, _c, _d
|
|
228
|
+
var _a, _b, _c, _d;
|
|
215
229
|
const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
216
230
|
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
|
217
231
|
const metadata = {
|
|
218
232
|
id: metadataPath.id,
|
|
219
233
|
state: metadataPath.state.type,
|
|
220
|
-
|
|
234
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
221
235
|
name: metadataPath.thread_metadata.name.text,
|
|
222
236
|
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
223
237
|
description: metadataPath.thread_metadata.description.text,
|
|
@@ -226,10 +240,10 @@ const extractNewsletterMetadata = (node, isCreate) => {
|
|
|
226
240
|
handle: metadataPath.thread_metadata.handle,
|
|
227
241
|
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
|
228
242
|
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
|
229
|
-
|
|
243
|
+
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
230
244
|
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
231
245
|
verification: metadataPath.thread_metadata.verification,
|
|
232
|
-
|
|
246
|
+
viewer_metadata: metadataPath.viewer_metadata
|
|
233
247
|
};
|
|
234
248
|
return metadata;
|
|
235
249
|
};
|
package/lib/Socket/socket.js
CHANGED
|
@@ -20,15 +20,14 @@ const Client_1 = require("./Client");
|
|
|
20
20
|
const makeSocket = (config) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
23
|
+
const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
|
+
if (config.mobile || url.protocol === 'tcp:') {
|
|
25
|
+
throw new boom_1.Boom('Mobile API is not supported anymore', { statusCode: Types_1.DisconnectReason.loggedOut });
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
27
|
+
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
29
28
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
30
29
|
}
|
|
31
|
-
const ws =
|
|
30
|
+
const ws = new Client_1.WebSocketClient(url, config);
|
|
32
31
|
ws.connect();
|
|
33
32
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
34
33
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -36,8 +35,7 @@ const makeSocket = (config) => {
|
|
|
36
35
|
/** WA noise protocol wrapper */
|
|
37
36
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
38
37
|
keyPair: ephemeralKeyPair,
|
|
39
|
-
NOISE_HEADER:
|
|
40
|
-
mobile: config.mobile,
|
|
38
|
+
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
41
39
|
logger,
|
|
42
40
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
43
41
|
});
|
|
@@ -80,6 +78,25 @@ const makeSocket = (config) => {
|
|
|
80
78
|
/** log & process any unexpected errors */
|
|
81
79
|
const onUnexpectedError = (err, msg) => {
|
|
82
80
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
81
|
+
const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
|
|
82
|
+
// auto recover from cryptographic desyncs by re-uploading prekeys
|
|
83
|
+
if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
|
|
84
|
+
try {
|
|
85
|
+
uploadPreKeysToServerIfRequired(true)
|
|
86
|
+
.catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
|
|
87
|
+
}
|
|
88
|
+
catch (_e) {
|
|
89
|
+
// ignore
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// gently back off when encountering rate limits (429)
|
|
93
|
+
if (message.includes('429') || message.includes('rate limit')) {
|
|
94
|
+
const wait = Math.min(30000, (config.backoffDelayMs || 5000));
|
|
95
|
+
logger.info({ wait }, 'backing off due to rate limit');
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
// intentionally empty; wait to delay further sends
|
|
98
|
+
}, wait);
|
|
99
|
+
}
|
|
83
100
|
};
|
|
84
101
|
/** await the next incoming message */
|
|
85
102
|
const awaitNextMessage = async (sendMsg) => {
|
|
@@ -116,7 +133,7 @@ const makeSocket = (config) => {
|
|
|
116
133
|
let onRecv;
|
|
117
134
|
let onErr;
|
|
118
135
|
try {
|
|
119
|
-
|
|
136
|
+
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
120
137
|
onRecv = resolve;
|
|
121
138
|
onErr = err => {
|
|
122
139
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -125,6 +142,7 @@ const makeSocket = (config) => {
|
|
|
125
142
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
126
143
|
ws.off('error', onErr);
|
|
127
144
|
});
|
|
145
|
+
return result;
|
|
128
146
|
}
|
|
129
147
|
finally {
|
|
130
148
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
@@ -138,9 +156,10 @@ const makeSocket = (config) => {
|
|
|
138
156
|
node.attrs.id = generateMessageTag();
|
|
139
157
|
}
|
|
140
158
|
const msgId = node.attrs.id;
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
159
|
+
const [result] = await Promise.all([
|
|
160
|
+
waitForMessage(msgId, timeoutMs),
|
|
161
|
+
sendNode(node)
|
|
162
|
+
]);
|
|
144
163
|
if ('tag' in result) {
|
|
145
164
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
146
165
|
}
|
|
@@ -157,12 +176,9 @@ const makeSocket = (config) => {
|
|
|
157
176
|
const result = await awaitNextMessage(init);
|
|
158
177
|
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
159
178
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
160
|
-
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
179
|
+
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
|
|
161
180
|
let node;
|
|
162
|
-
if (
|
|
163
|
-
node = (0, Utils_1.generateMobileNode)(config);
|
|
164
|
-
}
|
|
165
|
-
else if (!creds.me) {
|
|
181
|
+
if (!creds.me) {
|
|
166
182
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
167
183
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
168
184
|
}
|
|
@@ -232,11 +248,11 @@ const makeSocket = (config) => {
|
|
|
232
248
|
const l0 = frame.tag;
|
|
233
249
|
const l1 = frame.attrs || {};
|
|
234
250
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
235
|
-
Object.keys(l1)
|
|
251
|
+
for (const key of Object.keys(l1)) {
|
|
236
252
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
237
253
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
238
254
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
239
|
-
}
|
|
255
|
+
}
|
|
240
256
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
241
257
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
242
258
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -365,11 +381,7 @@ const makeSocket = (config) => {
|
|
|
365
381
|
}
|
|
366
382
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
367
383
|
};
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
/** hey bro, if you delete this text */
|
|
371
|
-
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
372
|
-
const requestPairingCode = async (phoneNumber, pairKey = "HALOCUKI") => {
|
|
384
|
+
const requestPairingCode = async (phoneNumber, pairKey = "HALOCUKI") => {
|
|
373
385
|
if (pairKey) {
|
|
374
386
|
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
375
387
|
}
|
|
@@ -430,11 +442,10 @@ const makeSocket = (config) => {
|
|
|
430
442
|
});
|
|
431
443
|
return authState.creds.pairingCode;
|
|
432
444
|
};
|
|
433
|
-
|
|
434
445
|
async function generatePairingKey() {
|
|
435
446
|
const salt = (0, crypto_1.randomBytes)(32);
|
|
436
447
|
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
437
|
-
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
448
|
+
const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
438
449
|
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
439
450
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
440
451
|
}
|
|
@@ -521,12 +532,18 @@ const makeSocket = (config) => {
|
|
|
521
532
|
});
|
|
522
533
|
// login complete
|
|
523
534
|
ws.on('CB:success', async (node) => {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
535
|
+
try {
|
|
536
|
+
await uploadPreKeysToServerIfRequired();
|
|
537
|
+
await sendPassiveIq('active');
|
|
538
|
+
logger.info('opened connection to WA');
|
|
539
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
540
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
541
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
542
|
+
}
|
|
543
|
+
catch (err) {
|
|
544
|
+
logger.error({ err }, 'error opening connection');
|
|
545
|
+
end(err);
|
|
546
|
+
}
|
|
530
547
|
});
|
|
531
548
|
ws.on('CB:stream:error', (node) => {
|
|
532
549
|
logger.error({ node }, 'stream errored out');
|
|
@@ -541,11 +558,20 @@ const makeSocket = (config) => {
|
|
|
541
558
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
542
559
|
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
543
560
|
});
|
|
561
|
+
ws.on('CB:ib,,offline_preview', (node) => {
|
|
562
|
+
logger.info('offline preview received', JSON.stringify(node));
|
|
563
|
+
sendNode({
|
|
564
|
+
tag: 'ib',
|
|
565
|
+
attrs: {},
|
|
566
|
+
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
|
567
|
+
});
|
|
568
|
+
});
|
|
544
569
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
545
570
|
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
546
571
|
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
547
572
|
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
548
573
|
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
574
|
+
ev.emit('creds.update', authState.creds);
|
|
549
575
|
}
|
|
550
576
|
});
|
|
551
577
|
let didStartBuffer = false;
|
package/lib/Store/index.js
CHANGED
|
@@ -3,8 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const make_cache_manager_store_1 = __importDefault(require("./make-cache-manager-store"));
|
|
8
|
-
exports.makeCacheManagerAuthState = make_cache_manager_store_1.default;
|
|
6
|
+
exports.makeInMemoryStore = void 0;
|
|
9
7
|
const make_in_memory_store_1 = __importDefault(require("./make-in-memory-store"));
|
|
10
8
|
exports.makeInMemoryStore = make_in_memory_store_1.default;
|
|
@@ -65,7 +65,7 @@ exports.default = (config) => {
|
|
|
65
65
|
return Object.keys(contacts);
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
|
-
* binds to a
|
|
68
|
+
* binds to a VyzenBailEventEmitter.
|
|
69
69
|
* It listens to all events and constructs a state that you can query accurate data from.
|
|
70
70
|
* Eg. can use the store to fetch chats, contacts, messages etc.
|
|
71
71
|
* @param ev typically the event emitter from the socket connection
|
|
@@ -74,7 +74,11 @@ exports.default = (config) => {
|
|
|
74
74
|
ev.on('connection.update', update => {
|
|
75
75
|
Object.assign(state, update);
|
|
76
76
|
});
|
|
77
|
-
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
|
|
77
|
+
ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
|
|
78
|
+
if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
79
|
+
return; // FOR NOW,
|
|
80
|
+
//TODO: HANDLE
|
|
81
|
+
}
|
|
78
82
|
if (isLatest) {
|
|
79
83
|
chats.clear();
|
|
80
84
|
for (const id in messages) {
|
|
@@ -187,16 +191,14 @@ exports.default = (config) => {
|
|
|
187
191
|
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
188
192
|
const list = assertMessageList(jid);
|
|
189
193
|
list.upsert(msg, 'append');
|
|
190
|
-
if (type === 'notify') {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
]);
|
|
199
|
-
}
|
|
194
|
+
if (type === 'notify' && !chats.get(jid)) {
|
|
195
|
+
ev.emit('chats.upsert', [
|
|
196
|
+
{
|
|
197
|
+
id: jid,
|
|
198
|
+
conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
|
|
199
|
+
unreadCount: 1
|
|
200
|
+
}
|
|
201
|
+
]);
|
|
200
202
|
}
|
|
201
203
|
}
|
|
202
204
|
break;
|
|
@@ -418,9 +420,19 @@ exports.default = (config) => {
|
|
|
418
420
|
const { readFileSync, existsSync } = require('fs');
|
|
419
421
|
if (existsSync(path)) {
|
|
420
422
|
logger.debug({ path }, 'reading from file');
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
423
|
+
try {
|
|
424
|
+
const jsonStr = readFileSync(path, { encoding: 'utf-8' });
|
|
425
|
+
if (jsonStr.trim().length) {
|
|
426
|
+
const json = JSON.parse(jsonStr);
|
|
427
|
+
fromJSON(json);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
logger.warn({ path }, 'skipping empty json file');
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
catch (err) {
|
|
434
|
+
logger.warn({ path, err }, 'failed to parse json from file');
|
|
435
|
+
}
|
|
424
436
|
}
|
|
425
437
|
}
|
|
426
438
|
};
|
|
@@ -56,9 +56,9 @@ function makeOrderedDictionary(idGetter) {
|
|
|
56
56
|
},
|
|
57
57
|
clear: () => {
|
|
58
58
|
array.splice(0, array.length);
|
|
59
|
-
Object.keys(dict)
|
|
59
|
+
for (const key of Object.keys(dict)) {
|
|
60
60
|
delete dict[key];
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
},
|
|
63
63
|
filter: (contain) => {
|
|
64
64
|
let i = 0;
|
package/lib/Types/Label.js
CHANGED
|
@@ -24,4 +24,4 @@ var LabelColor;
|
|
|
24
24
|
LabelColor[LabelColor["Color18"] = 17] = "Color18";
|
|
25
25
|
LabelColor[LabelColor["Color19"] = 18] = "Color19";
|
|
26
26
|
LabelColor[LabelColor["Color20"] = 19] = "Color20";
|
|
27
|
-
})(LabelColor
|
|
27
|
+
})(LabelColor || (exports.LabelColor = LabelColor = {}));
|
|
@@ -6,4 +6,4 @@ var LabelAssociationType;
|
|
|
6
6
|
(function (LabelAssociationType) {
|
|
7
7
|
LabelAssociationType["Chat"] = "label_jid";
|
|
8
8
|
LabelAssociationType["Message"] = "label_message";
|
|
9
|
-
})(LabelAssociationType
|
|
9
|
+
})(LabelAssociationType || (exports.LabelAssociationType = LabelAssociationType = {}));
|
package/lib/Types/Message.js
CHANGED
|
@@ -3,7 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WAMessageStatus = exports.WAMessageStubType = exports.WAProto = void 0;
|
|
4
4
|
const WAProto_1 = require("../../WAProto");
|
|
5
5
|
Object.defineProperty(exports, "WAProto", { enumerable: true, get: function () { return WAProto_1.proto; } });
|
|
6
|
-
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
7
6
|
exports.WAMessageStubType = WAProto_1.proto.WebMessageInfo.StubType;
|
|
8
|
-
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
9
7
|
exports.WAMessageStatus = WAProto_1.proto.WebMessageInfo.Status;
|
package/lib/Types/Newsletter.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.XWAPaths = exports.MexOperations = void 0;
|
|
4
4
|
var MexOperations;
|
|
5
5
|
(function (MexOperations) {
|
|
6
6
|
MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
|
|
7
7
|
MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
|
|
8
8
|
MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
|
|
9
|
-
})(MexOperations
|
|
9
|
+
})(MexOperations || (exports.MexOperations = MexOperations = {}));
|
|
10
10
|
var XWAPaths;
|
|
11
11
|
(function (XWAPaths) {
|
|
12
12
|
XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
|
|
@@ -15,18 +15,4 @@ var XWAPaths;
|
|
|
15
15
|
XWAPaths["CREATE"] = "xwa2_newsletter_create";
|
|
16
16
|
XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
|
|
17
17
|
XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
|
|
18
|
-
})(XWAPaths
|
|
19
|
-
var QueryIds;
|
|
20
|
-
(function (QueryIds) {
|
|
21
|
-
QueryIds["JOB_MUTATION"] = "7150902998257522";
|
|
22
|
-
QueryIds["METADATA"] = "6620195908089573";
|
|
23
|
-
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
24
|
-
QueryIds["FOLLOW"] = "7871414976211147";
|
|
25
|
-
QueryIds["UNMUTE"] = "7337137176362961";
|
|
26
|
-
QueryIds["MUTE"] = "25151904754424642";
|
|
27
|
-
QueryIds["CREATE"] = "6996806640408138";
|
|
28
|
-
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
29
|
-
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
30
|
-
QueryIds["DELETE"] = "8316537688363079";
|
|
31
|
-
QueryIds["DEMOTE"] = "6551828931592903";
|
|
32
|
-
})(QueryIds = exports.QueryIds || (exports.QueryIds = {}));
|
|
18
|
+
})(XWAPaths || (exports.XWAPaths = XWAPaths = {}));
|
package/lib/Types/index.js
CHANGED
|
@@ -17,11 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.DisconnectReason = void 0;
|
|
18
18
|
__exportStar(require("./Auth"), exports);
|
|
19
19
|
__exportStar(require("./GroupMetadata"), exports);
|
|
20
|
+
__exportStar(require("./Newsletter"), exports);
|
|
20
21
|
__exportStar(require("./Chat"), exports);
|
|
21
22
|
__exportStar(require("./Contact"), exports);
|
|
22
23
|
__exportStar(require("./State"), exports);
|
|
23
24
|
__exportStar(require("./Message"), exports);
|
|
24
|
-
__exportStar(require("./Newsletter"), exports);
|
|
25
25
|
__exportStar(require("./Socket"), exports);
|
|
26
26
|
__exportStar(require("./Events"), exports);
|
|
27
27
|
__exportStar(require("./Product"), exports);
|
|
@@ -39,4 +39,4 @@ var DisconnectReason;
|
|
|
39
39
|
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
|
40
40
|
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
|
41
41
|
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
|
42
|
-
})(DisconnectReason
|
|
42
|
+
})(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
|
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initAuthCreds = exports.addTransactionCapability =
|
|
6
|
+
exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
7
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
7
8
|
const crypto_1 = require("crypto");
|
|
8
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
|
-
const uuid_1 = require("uuid");
|
|
9
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
10
|
const Defaults_1 = require("../Defaults");
|
|
11
11
|
const crypto_2 = require("./crypto");
|
|
12
12
|
const generics_1 = require("./generics");
|
|
@@ -18,7 +18,7 @@ const generics_1 = require("./generics");
|
|
|
18
18
|
*/
|
|
19
19
|
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
20
20
|
const cache = _cache || new node_cache_1.default({
|
|
21
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
21
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
22
22
|
useClones: false,
|
|
23
23
|
deleteOnExpire: true,
|
|
24
24
|
});
|
|
@@ -39,7 +39,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
if (idsToFetch.length) {
|
|
42
|
-
logger.trace({ items: idsToFetch.length }, 'loading from store');
|
|
42
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ items: idsToFetch.length }, 'loading from store');
|
|
43
43
|
const fetched = await store.get(type, idsToFetch);
|
|
44
44
|
for (const id of idsToFetch) {
|
|
45
45
|
const item = fetched[id];
|
|
@@ -59,7 +59,7 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
59
59
|
keys += 1;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
logger.trace({ keys }, 'updated cache');
|
|
62
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ keys }, 'updated cache');
|
|
63
63
|
await store.set(data);
|
|
64
64
|
},
|
|
65
65
|
async clear() {
|
|
@@ -69,7 +69,6 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
73
72
|
/**
|
|
74
73
|
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
|
75
74
|
* this allows batch read & write operations & improves the performance of the lib
|
|
@@ -191,13 +190,7 @@ const initAuthCreds = () => {
|
|
|
191
190
|
accountSettings: {
|
|
192
191
|
unarchiveChats: false
|
|
193
192
|
},
|
|
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
193
|
registered: false,
|
|
199
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
200
|
-
registration: {},
|
|
201
194
|
pairingCode: undefined,
|
|
202
195
|
lastPropHash: undefined,
|
|
203
196
|
routingInfo: undefined,
|