@queenanya/baileys 6.9.2 → 7.0.0
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/README.md +56 -13
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +5 -2
- package/lib/Socket/business.d.ts +46 -8
- package/lib/Socket/business.js +1 -0
- package/lib/Socket/chats.d.ts +10 -2
- package/lib/Socket/chats.js +42 -3
- package/lib/Socket/groups.d.ts +17 -3
- package/lib/Socket/groups.js +12 -1
- package/lib/Socket/index.d.ts +46 -8
- package/lib/Socket/messages-recv.d.ts +45 -9
- package/lib/Socket/messages-recv.js +184 -22
- package/lib/Socket/messages-send.d.ts +40 -6
- package/lib/Socket/messages-send.js +153 -37
- package/lib/Socket/newsletter.d.ts +140 -0
- package/lib/Socket/newsletter.js +249 -0
- package/lib/Socket/registration.d.ts +46 -11
- package/lib/Socket/socket.js +18 -4
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +11 -44
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Chat.d.ts +5 -0
- package/lib/Types/Events.d.ts +40 -2
- package/lib/Types/GroupMetadata.d.ts +3 -1
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Message.d.ts +39 -27
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Socket.d.ts +7 -0
- package/lib/Types/index.d.ts +9 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/auth-utils.js +1 -0
- package/lib/Utils/chat-utils.js +16 -0
- package/lib/Utils/crypto.d.ts +1 -1
- package/lib/Utils/crypto.js +4 -2
- package/lib/Utils/decode-wa-message.d.ts +1 -0
- package/lib/Utils/decode-wa-message.js +50 -22
- package/lib/Utils/generics.d.ts +30 -10
- package/lib/Utils/generics.js +82 -10
- package/lib/Utils/history.d.ts +4 -0
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/logger.d.ts +1 -3
- package/lib/Utils/messages-media.d.ts +10 -1
- package/lib/Utils/messages-media.js +61 -18
- package/lib/Utils/messages.d.ts +2 -1
- package/lib/Utils/messages.js +77 -76
- package/lib/Utils/noise-handler.d.ts +3 -2
- package/lib/Utils/noise-handler.js +18 -5
- package/lib/Utils/process-message.d.ts +3 -2
- package/lib/Utils/process-message.js +53 -21
- package/lib/Utils/signal.js +21 -16
- package/lib/Utils/use-multi-file-auth-state.js +16 -3
- package/lib/WABinary/decode.d.ts +2 -2
- package/lib/WABinary/decode.js +6 -4
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +1 -1
- package/lib/WABinary/jid-utils.d.ts +3 -1
- package/lib/WABinary/jid-utils.js +4 -1
- package/package.json +32 -27
|
@@ -11,7 +11,7 @@ const generateIV = (counter) => {
|
|
|
11
11
|
new DataView(iv).setUint32(8, counter);
|
|
12
12
|
return new Uint8Array(iv);
|
|
13
13
|
};
|
|
14
|
-
const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, }) => {
|
|
14
|
+
const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }) => {
|
|
15
15
|
logger = logger.child({ class: 'ns' });
|
|
16
16
|
const authenticate = (data) => {
|
|
17
17
|
if (!isFinished) {
|
|
@@ -101,10 +101,23 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
101
101
|
if (isFinished) {
|
|
102
102
|
data = encrypt(data);
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
let header;
|
|
105
|
+
if (routingInfo) {
|
|
106
|
+
header = Buffer.alloc(7);
|
|
107
|
+
header.write('ED', 0, 'utf8');
|
|
108
|
+
header.writeUint8(0, 2);
|
|
109
|
+
header.writeUint8(1, 3);
|
|
110
|
+
header.writeUint8(routingInfo.byteLength >> 16, 4);
|
|
111
|
+
header.writeUint16BE(routingInfo.byteLength & 65535, 5);
|
|
112
|
+
header = Buffer.concat([header, routingInfo, NOISE_HEADER]);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
header = Buffer.from(NOISE_HEADER);
|
|
116
|
+
}
|
|
117
|
+
const introSize = sentIntro ? 0 : header.length;
|
|
105
118
|
const frame = Buffer.alloc(introSize + 3 + data.byteLength);
|
|
106
119
|
if (!sentIntro) {
|
|
107
|
-
frame.set(
|
|
120
|
+
frame.set(header);
|
|
108
121
|
sentIntro = true;
|
|
109
122
|
}
|
|
110
123
|
frame.writeUInt8(data.byteLength >> 16, introSize);
|
|
@@ -112,7 +125,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
112
125
|
frame.set(data, introSize + 3);
|
|
113
126
|
return frame;
|
|
114
127
|
},
|
|
115
|
-
decodeFrame: (newData, onFrame) => {
|
|
128
|
+
decodeFrame: async (newData, onFrame) => {
|
|
116
129
|
var _a;
|
|
117
130
|
// the binary protocol uses its own framing mechanism
|
|
118
131
|
// on top of the WS frames
|
|
@@ -130,7 +143,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
130
143
|
inBytes = inBytes.slice(size + 3);
|
|
131
144
|
if (isFinished) {
|
|
132
145
|
const result = decrypt(frame);
|
|
133
|
-
frame = (0, WABinary_1.decodeBinaryNode)(result);
|
|
146
|
+
frame = await (0, WABinary_1.decodeBinaryNode)(result);
|
|
134
147
|
}
|
|
135
148
|
logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
|
|
136
149
|
onFrame(frame);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type { Logger } from 'pino';
|
|
3
3
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
4
|
+
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
5
5
|
type ProcessMessageContext = {
|
|
6
6
|
shouldProcessHistoryMsg: boolean;
|
|
7
|
+
placeholderResendCache?: CacheStore;
|
|
7
8
|
creds: AuthenticationCreds;
|
|
8
9
|
keyStore: SignalKeyStoreWithTransaction;
|
|
9
10
|
ev: BaileysEventEmitter;
|
|
@@ -37,5 +38,5 @@ type PollContext = {
|
|
|
37
38
|
* @returns list of SHA256 options
|
|
38
39
|
*/
|
|
39
40
|
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
|
|
40
|
-
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
41
|
+
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
41
42
|
export default processMessage;
|
|
@@ -102,8 +102,8 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
exports.decryptPollVote = decryptPollVote;
|
|
105
|
-
const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
|
|
106
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
105
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
|
|
106
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
107
107
|
const meId = creds.me.id;
|
|
108
108
|
const { accountSettings } = creds;
|
|
109
109
|
const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
|
|
@@ -137,14 +137,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
137
137
|
isLatest,
|
|
138
138
|
}, 'got history notification');
|
|
139
139
|
if (process) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
141
|
+
ev.emit('creds.update', {
|
|
142
|
+
processedHistoryMessages: [
|
|
143
|
+
...(creds.processedHistoryMessages || []),
|
|
144
|
+
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
}
|
|
146
148
|
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
147
|
-
ev.emit('messaging-history.set', {
|
|
149
|
+
ev.emit('messaging-history.set', {
|
|
150
|
+
...data,
|
|
151
|
+
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
152
|
+
? isLatest
|
|
153
|
+
: undefined
|
|
154
|
+
});
|
|
148
155
|
}
|
|
149
156
|
break;
|
|
150
157
|
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
@@ -187,14 +194,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
187
194
|
case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
188
195
|
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
189
196
|
if (response) {
|
|
197
|
+
placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
|
|
198
|
+
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
|
190
199
|
const { peerDataOperationResult } = response;
|
|
191
200
|
for (const result of peerDataOperationResult) {
|
|
192
201
|
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
193
202
|
if (retryResponse) {
|
|
194
203
|
const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
204
|
+
// wait till another upsert event is available, don't want it to be part of the PDO response message
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
ev.emit('messages.upsert', {
|
|
207
|
+
messages: [webMessageInfo],
|
|
208
|
+
type: 'notify',
|
|
209
|
+
requestId: response.stanzaId
|
|
210
|
+
});
|
|
211
|
+
}, 500);
|
|
198
212
|
}
|
|
199
213
|
}
|
|
200
214
|
}
|
|
@@ -208,11 +222,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
208
222
|
};
|
|
209
223
|
ev.emit('messages.reaction', [{
|
|
210
224
|
reaction,
|
|
211
|
-
key: content.reactionMessage.key,
|
|
225
|
+
key: (_d = content.reactionMessage) === null || _d === void 0 ? void 0 : _d.key,
|
|
212
226
|
}]);
|
|
213
227
|
}
|
|
214
228
|
else if (message.messageStubType) {
|
|
215
|
-
const jid = message.key.remoteJid;
|
|
229
|
+
const jid = (_e = message.key) === null || _e === void 0 ? void 0 : _e.remoteJid;
|
|
216
230
|
//let actor = whatsappID (message.participant)
|
|
217
231
|
let participants;
|
|
218
232
|
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
@@ -220,8 +234,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
220
234
|
var _a;
|
|
221
235
|
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
|
222
236
|
};
|
|
237
|
+
const emitGroupRequestJoin = (participant, action, method) => {
|
|
238
|
+
ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
|
|
239
|
+
};
|
|
223
240
|
const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
|
|
224
241
|
switch (message.messageStubType) {
|
|
242
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
243
|
+
participants = message.messageStubParameters || [];
|
|
244
|
+
emitParticipantsUpdate('modify');
|
|
245
|
+
break;
|
|
225
246
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
226
247
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
227
248
|
participants = message.messageStubParameters || [];
|
|
@@ -249,30 +270,41 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
249
270
|
emitParticipantsUpdate('promote');
|
|
250
271
|
break;
|
|
251
272
|
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
252
|
-
const announceValue = (
|
|
273
|
+
const announceValue = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
|
|
253
274
|
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
254
275
|
break;
|
|
255
276
|
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
256
|
-
const restrictValue = (
|
|
277
|
+
const restrictValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
257
278
|
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
258
279
|
break;
|
|
259
280
|
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
260
|
-
const name = (
|
|
281
|
+
const name = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
261
282
|
chat.name = name;
|
|
262
283
|
emitGroupUpdate({ subject: name });
|
|
263
284
|
break;
|
|
285
|
+
case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
286
|
+
const description = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
287
|
+
chat.description = description;
|
|
288
|
+
emitGroupUpdate({ desc: description });
|
|
289
|
+
break;
|
|
264
290
|
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
265
|
-
const code = (
|
|
291
|
+
const code = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
|
|
266
292
|
emitGroupUpdate({ inviteCode: code });
|
|
267
293
|
break;
|
|
268
294
|
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
269
|
-
const memberAddValue = (
|
|
295
|
+
const memberAddValue = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
|
|
270
296
|
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
271
297
|
break;
|
|
272
298
|
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
273
|
-
const approvalMode = (
|
|
299
|
+
const approvalMode = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
|
|
274
300
|
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
275
301
|
break;
|
|
302
|
+
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
|
|
303
|
+
const participant = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
|
|
304
|
+
const action = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[1];
|
|
305
|
+
const method = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[2];
|
|
306
|
+
emitGroupRequestJoin(participant, action, method);
|
|
307
|
+
break;
|
|
276
308
|
}
|
|
277
309
|
}
|
|
278
310
|
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
@@ -283,7 +315,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
283
315
|
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
284
316
|
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
285
317
|
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
286
|
-
const pollEncKey = (
|
|
318
|
+
const pollEncKey = (_r = pollMsg.messageContextInfo) === null || _r === void 0 ? void 0 : _r.messageSecret;
|
|
287
319
|
try {
|
|
288
320
|
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
289
321
|
pollEncKey,
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
4
5
|
const Defaults_1 = require("../Defaults");
|
|
5
6
|
const WABinary_1 = require("../WABinary");
|
|
6
7
|
const crypto_1 = require("./crypto");
|
|
@@ -66,22 +67,26 @@ const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
66
67
|
for (const node of nodes) {
|
|
67
68
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
jid
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
const chunkSize = 100;
|
|
71
|
+
const chunks = (0, lodash_1.chunk)(nodes, chunkSize);
|
|
72
|
+
for (const nodesChunk of chunks) {
|
|
73
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
74
|
+
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
75
|
+
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
76
|
+
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
77
|
+
const jid = node.attrs.jid;
|
|
78
|
+
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
79
|
+
await repository.injectE2ESession({
|
|
80
|
+
jid,
|
|
81
|
+
session: {
|
|
82
|
+
registrationId: registrationId,
|
|
83
|
+
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
84
|
+
signedPreKey: extractKey(signedKey),
|
|
85
|
+
preKey: extractKey(key)
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
85
90
|
};
|
|
86
91
|
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
87
92
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.useMultiFileAuthState = void 0;
|
|
7
|
+
const async_lock_1 = __importDefault(require("async-lock"));
|
|
4
8
|
const promises_1 = require("fs/promises");
|
|
5
9
|
const path_1 = require("path");
|
|
6
10
|
const WAProto_1 = require("../../WAProto");
|
|
7
11
|
const auth_utils_1 = require("./auth-utils");
|
|
8
12
|
const generics_1 = require("./generics");
|
|
13
|
+
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
14
|
+
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
15
|
+
// https://github.com/nodejs/node/issues/26338
|
|
16
|
+
// Default pending is 1000, set it to infinity
|
|
17
|
+
// https://github.com/rogierschouten/async-lock/issues/63
|
|
18
|
+
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
9
19
|
/**
|
|
10
20
|
* stores the full authentication state in a single folder.
|
|
11
21
|
* Far more efficient than singlefileauthstate
|
|
@@ -15,11 +25,13 @@ const generics_1 = require("./generics");
|
|
|
15
25
|
* */
|
|
16
26
|
const useMultiFileAuthState = async (folder) => {
|
|
17
27
|
const writeData = (data, file) => {
|
|
18
|
-
|
|
28
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
29
|
+
return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
|
|
19
30
|
};
|
|
20
31
|
const readData = async (file) => {
|
|
21
32
|
try {
|
|
22
|
-
const
|
|
33
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
34
|
+
const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
|
|
23
35
|
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
24
36
|
}
|
|
25
37
|
catch (error) {
|
|
@@ -28,7 +40,8 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
28
40
|
};
|
|
29
41
|
const removeData = async (file) => {
|
|
30
42
|
try {
|
|
31
|
-
|
|
43
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
44
|
+
await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
|
|
32
45
|
}
|
|
33
46
|
catch (_a) {
|
|
34
47
|
}
|
package/lib/WABinary/decode.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
|
3
|
-
export declare const decompressingIfRequired: (buffer: Buffer) => Buffer
|
|
3
|
+
export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer>;
|
|
4
4
|
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
|
|
5
5
|
index: number;
|
|
6
6
|
}) => BinaryNode;
|
|
7
|
-
export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode
|
|
7
|
+
export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -24,12 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
|
|
27
|
+
const util_1 = require("util");
|
|
27
28
|
const zlib_1 = require("zlib");
|
|
28
29
|
const constants = __importStar(require("./constants"));
|
|
29
30
|
const jid_utils_1 = require("./jid-utils");
|
|
30
|
-
const
|
|
31
|
+
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
32
|
+
const decompressingIfRequired = async (buffer) => {
|
|
31
33
|
if (2 & buffer.readUInt8()) {
|
|
32
|
-
buffer =
|
|
34
|
+
buffer = await inflatePromise(buffer.slice(1));
|
|
33
35
|
}
|
|
34
36
|
else { // nodes with no compression have a 0x00 prefix, we remove that
|
|
35
37
|
buffer = buffer.slice(1);
|
|
@@ -245,8 +247,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
245
247
|
};
|
|
246
248
|
};
|
|
247
249
|
exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
|
|
248
|
-
const decodeBinaryNode = (buff) => {
|
|
249
|
-
const decompBuff = (0, exports.decompressingIfRequired)(buff);
|
|
250
|
+
const decodeBinaryNode = async (buff) => {
|
|
251
|
+
const decompBuff = await (0, exports.decompressingIfRequired)(buff);
|
|
250
252
|
return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
|
|
251
253
|
};
|
|
252
254
|
exports.decodeBinaryNode = decodeBinaryNode;
|
package/lib/WABinary/encode.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { BinaryNode, BinaryNodeCodingOptions } from './types';
|
|
3
|
-
export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) =>
|
|
2
|
+
export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => number[];
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -223,6 +223,6 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
|
|
|
223
223
|
else {
|
|
224
224
|
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
225
225
|
}
|
|
226
|
-
return
|
|
226
|
+
return buffer;
|
|
227
227
|
};
|
|
228
228
|
exports.encodeBinaryNode = encodeBinaryNode;
|
|
@@ -3,7 +3,7 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
|
|
|
3
3
|
export declare const SERVER_JID = "server@c.us";
|
|
4
4
|
export declare const PSA_WID = "0@c.us";
|
|
5
5
|
export declare const STORIES_JID = "status@broadcast";
|
|
6
|
-
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid';
|
|
6
|
+
export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter';
|
|
7
7
|
export type JidWithDevice = {
|
|
8
8
|
user: string;
|
|
9
9
|
device?: number;
|
|
@@ -26,4 +26,6 @@ export declare const isJidBroadcast: (jid: string | undefined) => boolean | unde
|
|
|
26
26
|
export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
|
|
27
27
|
/** is the jid the status broadcast */
|
|
28
28
|
export declare const isJidStatusBroadcast: (jid: string) => boolean;
|
|
29
|
+
/** is the jid a newsletter */
|
|
30
|
+
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
|
29
31
|
export declare const jidNormalizedUser: (jid: string | undefined) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
3
|
+
exports.jidNormalizedUser = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
4
4
|
exports.S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
5
5
|
exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
6
6
|
exports.SERVER_JID = 'server@c.us';
|
|
@@ -48,6 +48,9 @@ exports.isJidGroup = isJidGroup;
|
|
|
48
48
|
/** is the jid the status broadcast */
|
|
49
49
|
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
50
50
|
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
|
51
|
+
/** is the jid a newsletter */
|
|
52
|
+
const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
|
|
53
|
+
exports.isJidNewsletter = isJidNewsletter;
|
|
51
54
|
const jidNormalizedUser = (jid) => {
|
|
52
55
|
const result = (0, exports.jidDecode)(jid);
|
|
53
56
|
if (!result) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@queenanya/baileys",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -43,41 +43,46 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
46
|
-
"@hapi/boom": "^
|
|
47
|
-
"@queenanya/
|
|
48
|
-
"
|
|
49
|
-
"
|
|
46
|
+
"@hapi/boom": "^10.0.1",
|
|
47
|
+
"@queenanya/invite": "latest",
|
|
48
|
+
"async-lock": "^1.4.1",
|
|
49
|
+
"audio-decode": "^2.2.0",
|
|
50
|
+
"axios": "^1.7.2",
|
|
50
51
|
"cache-manager": "4.0.1",
|
|
51
|
-
"futoin-hkdf": "^1.5.
|
|
52
|
+
"futoin-hkdf": "^1.5.3",
|
|
52
53
|
"json": "^11.0.0",
|
|
53
|
-
"libphonenumber-js": "^1.
|
|
54
|
+
"libphonenumber-js": "^1.11.4",
|
|
54
55
|
"libsignal": "npm:@queenanya/libsignal@latest",
|
|
56
|
+
"lodash": "^4.17.21",
|
|
57
|
+
"megajs": "1.1.7",
|
|
55
58
|
"music-metadata": "^7.12.3",
|
|
56
59
|
"node-cache": "^5.1.2",
|
|
57
|
-
"pino": "^
|
|
58
|
-
"protobufjs": "^7.2
|
|
59
|
-
"
|
|
60
|
-
"
|
|
60
|
+
"pino": "^9.3.0",
|
|
61
|
+
"protobufjs": "^7.3.2",
|
|
62
|
+
"release-it": "^17.6.0",
|
|
63
|
+
"uuid": "^10.0.0",
|
|
64
|
+
"ws": "^8.18.0"
|
|
61
65
|
},
|
|
62
66
|
"devDependencies": {
|
|
63
67
|
"@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
|
|
64
|
-
"@types/got": "^9.6.
|
|
65
|
-
"@types/jest": "^
|
|
66
|
-
"@types/node": "^
|
|
67
|
-
"@types/sharp": "^0.
|
|
68
|
-
"@types/ws": "^8.
|
|
69
|
-
"conventional-changelog-cli": "^
|
|
70
|
-
"eslint": "^
|
|
71
|
-
"jest": "^
|
|
72
|
-
"jimp": "^0.
|
|
68
|
+
"@types/got": "^9.6.12",
|
|
69
|
+
"@types/jest": "^29.5.12",
|
|
70
|
+
"@types/node": "^20.14.10",
|
|
71
|
+
"@types/sharp": "^0.31.1",
|
|
72
|
+
"@types/ws": "^8.5.11",
|
|
73
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
74
|
+
"eslint": "^9.7.0",
|
|
75
|
+
"jest": "^29.7.0",
|
|
76
|
+
"jimp": "^0.22.12",
|
|
73
77
|
"json": "^11.0.0",
|
|
74
|
-
"link-preview-js": "^3.0.
|
|
75
|
-
"
|
|
78
|
+
"link-preview-js": "^3.0.5",
|
|
79
|
+
"megajs": "1.1.7",
|
|
80
|
+
"open": "^10.1.0",
|
|
76
81
|
"qrcode-terminal": "^0.12.0",
|
|
77
|
-
"release-it": "^
|
|
78
|
-
"sharp": "^0.
|
|
79
|
-
"ts-jest": "^
|
|
80
|
-
"ts-node": "^10.
|
|
82
|
+
"release-it": "^17.6.0",
|
|
83
|
+
"sharp": "^0.33.4",
|
|
84
|
+
"ts-jest": "^29.2.2",
|
|
85
|
+
"ts-node": "^10.9.2",
|
|
81
86
|
"typedoc": "^0.24.7",
|
|
82
87
|
"typescript": "^4.6.4"
|
|
83
88
|
},
|
|
@@ -85,7 +90,7 @@
|
|
|
85
90
|
"jimp": "^0.16.1",
|
|
86
91
|
"link-preview-js": "^3.0.0",
|
|
87
92
|
"qrcode-terminal": "^0.12.0",
|
|
88
|
-
"sharp": "^0.32.
|
|
93
|
+
"sharp": "^0.32.6"
|
|
89
94
|
},
|
|
90
95
|
"peerDependenciesMeta": {
|
|
91
96
|
"jimp": {
|