@modzneverdie/baileys 17.1.12 → 17.1.17
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 +364 -0
- package/engine-requirements.js +4 -4
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +6 -4
- package/lib/Defaults/index.js +119 -78
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +5 -54
- package/lib/Socket/business.d.ts +58 -59
- package/lib/Socket/chats.d.ts +230 -45
- package/lib/Socket/chats.js +238 -139
- package/lib/Socket/{setup.ts → dugong.d.ts} +52 -17
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +23 -38
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +399 -415
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +136 -71
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +617 -754
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +14 -26
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +7 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -14
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +2 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +21 -148
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +97 -73
- package/lib/Types/Newsletter.js +38 -18
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -8
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +16 -15
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +6 -22
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -11
- package/lib/Utils/generics.d.ts +20 -17
- package/lib/Utils/generics.js +84 -102
- package/lib/Utils/history.d.ts +0 -4
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +24 -28
- package/lib/Utils/messages-media.js +236 -298
- package/lib/Utils/messages.d.ts +10 -8
- package/lib/Utils/messages.js +60 -304
- package/lib/Utils/noise-handler.d.ts +12 -10
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +25 -89
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -26
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +0 -6
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +76 -20
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +13 -26
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +152 -137
- package/lib/WABinary/generic-utils.d.ts +4 -1
- package/lib/WABinary/generic-utils.js +125 -37
- package/lib/WABinary/jid-utils.d.ts +5 -10
- package/lib/WABinary/jid-utils.js +5 -26
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +2 -6
- package/lib/index.js +6 -20
- package/package.json +105 -107
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/lib/Socket/setup.js +0 -433
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Logger } from 'pino';
|
|
2
3
|
import { proto } from '../../WAProto';
|
|
3
4
|
import { KeyPair } from '../Types';
|
|
4
5
|
import { BinaryNode } from '../WABinary';
|
|
5
|
-
export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
|
|
6
|
+
export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
|
|
6
7
|
keyPair: KeyPair;
|
|
7
8
|
NOISE_HEADER: Uint8Array;
|
|
8
|
-
|
|
9
|
+
mobile: boolean;
|
|
10
|
+
logger: Logger;
|
|
9
11
|
routingInfo?: Buffer | undefined;
|
|
10
12
|
}) => {
|
|
11
|
-
encrypt: (plaintext: Uint8Array) => Buffer
|
|
12
|
-
decrypt: (ciphertext: Uint8Array) => Buffer
|
|
13
|
+
encrypt: (plaintext: Uint8Array) => Buffer;
|
|
14
|
+
decrypt: (ciphertext: Uint8Array) => Buffer;
|
|
13
15
|
authenticate: (data: Uint8Array) => void;
|
|
14
|
-
mixIntoKey: (data: Uint8Array) =>
|
|
15
|
-
finishInit: () =>
|
|
16
|
-
processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) =>
|
|
17
|
-
encodeFrame: (data: Buffer | Uint8Array) => Buffer
|
|
18
|
-
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) =>
|
|
16
|
+
mixIntoKey: (data: Uint8Array) => void;
|
|
17
|
+
finishInit: () => void;
|
|
18
|
+
processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Buffer;
|
|
19
|
+
encodeFrame: (data: Buffer | Uint8Array) => Buffer;
|
|
20
|
+
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
|
|
19
21
|
};
|
|
@@ -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, logger, routingInfo }) => {
|
|
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) {
|
|
@@ -38,20 +38,20 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
38
38
|
authenticate(ciphertext);
|
|
39
39
|
return result;
|
|
40
40
|
};
|
|
41
|
-
const localHKDF =
|
|
42
|
-
const key =
|
|
41
|
+
const localHKDF = (data) => {
|
|
42
|
+
const key = (0, crypto_1.hkdf)(Buffer.from(data), 64, { salt, info: '' });
|
|
43
43
|
return [key.slice(0, 32), key.slice(32)];
|
|
44
44
|
};
|
|
45
|
-
const mixIntoKey =
|
|
46
|
-
const [write, read] =
|
|
45
|
+
const mixIntoKey = (data) => {
|
|
46
|
+
const [write, read] = localHKDF(data);
|
|
47
47
|
salt = write;
|
|
48
48
|
encKey = read;
|
|
49
49
|
decKey = read;
|
|
50
50
|
readCounter = 0;
|
|
51
51
|
writeCounter = 0;
|
|
52
52
|
};
|
|
53
|
-
const finishInit =
|
|
54
|
-
const [write, read] =
|
|
53
|
+
const finishInit = () => {
|
|
54
|
+
const [write, read] = localHKDF(new Uint8Array(0));
|
|
55
55
|
encKey = write;
|
|
56
56
|
decKey = read;
|
|
57
57
|
hash = Buffer.from([]);
|
|
@@ -60,7 +60,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
60
60
|
isFinished = true;
|
|
61
61
|
};
|
|
62
62
|
const data = Buffer.from(Defaults_1.NOISE_MODE);
|
|
63
|
-
let hash = data.byteLength === 32 ? data : (0, crypto_1.sha256)(data);
|
|
63
|
+
let hash = Buffer.from(data.byteLength === 32 ? data : (0, crypto_1.sha256)(data));
|
|
64
64
|
let salt = hash;
|
|
65
65
|
let encKey = hash;
|
|
66
66
|
let decKey = hash;
|
|
@@ -77,19 +77,24 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
77
77
|
authenticate,
|
|
78
78
|
mixIntoKey,
|
|
79
79
|
finishInit,
|
|
80
|
-
processHandshake:
|
|
80
|
+
processHandshake: ({ serverHello }, noiseKey) => {
|
|
81
81
|
authenticate(serverHello.ephemeral);
|
|
82
|
-
|
|
82
|
+
mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral));
|
|
83
83
|
const decStaticContent = decrypt(serverHello.static);
|
|
84
|
-
|
|
84
|
+
mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
|
|
85
85
|
const certDecoded = decrypt(serverHello.payload);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
if (mobile) {
|
|
87
|
+
WAProto_1.proto.CertChain.NoiseCertificate.decode(certDecoded);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded);
|
|
91
|
+
const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
|
|
92
|
+
if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
|
|
93
|
+
throw new boom_1.Boom('certification match failed', { statusCode: 400 });
|
|
94
|
+
}
|
|
90
95
|
}
|
|
91
96
|
const keyEnc = encrypt(noiseKey.public);
|
|
92
|
-
|
|
97
|
+
mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
|
|
93
98
|
return keyEnc;
|
|
94
99
|
},
|
|
95
100
|
encodeFrame: (data) => {
|
|
@@ -120,7 +125,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
120
125
|
frame.set(data, introSize + 3);
|
|
121
126
|
return frame;
|
|
122
127
|
},
|
|
123
|
-
decodeFrame:
|
|
128
|
+
decodeFrame: (newData, onFrame) => {
|
|
124
129
|
var _a;
|
|
125
130
|
// the binary protocol uses its own framing mechanism
|
|
126
131
|
// on top of the WS frames
|
|
@@ -138,7 +143,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
138
143
|
inBytes = inBytes.slice(size + 3);
|
|
139
144
|
if (isFinished) {
|
|
140
145
|
const result = decrypt(frame);
|
|
141
|
-
frame =
|
|
146
|
+
frame = (0, WABinary_1.decodeBinaryNode)(result);
|
|
142
147
|
}
|
|
143
148
|
logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
|
|
144
149
|
onFrame(frame);
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import type { Logger } from 'pino';
|
|
2
3
|
import { proto } from '../../WAProto';
|
|
3
|
-
import { AuthenticationCreds, BaileysEventEmitter,
|
|
4
|
-
import { ILogger } from './logger';
|
|
4
|
+
import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
5
5
|
type ProcessMessageContext = {
|
|
6
6
|
shouldProcessHistoryMsg: boolean;
|
|
7
|
-
placeholderResendCache?: CacheStore;
|
|
8
7
|
creds: AuthenticationCreds;
|
|
9
8
|
keyStore: SignalKeyStoreWithTransaction;
|
|
10
9
|
ev: BaileysEventEmitter;
|
|
11
10
|
getMessage: SocketConfig['getMessage'];
|
|
12
|
-
logger?:
|
|
11
|
+
logger?: Logger;
|
|
13
12
|
options: AxiosRequestConfig<{}>;
|
|
14
13
|
};
|
|
15
14
|
/** Cleans a received message to further processing */
|
|
@@ -38,5 +37,5 @@ type PollContext = {
|
|
|
38
37
|
* @returns list of SHA256 options
|
|
39
38
|
*/
|
|
40
39
|
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
|
|
41
|
-
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg,
|
|
40
|
+
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
42
41
|
export default processMessage;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
|
|
4
|
-
exports.decryptPollVote = decryptPollVote;
|
|
3
|
+
exports.decryptPollVote = exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
|
|
5
4
|
const WAProto_1 = require("../../WAProto");
|
|
6
5
|
const Types_1 = require("../Types");
|
|
7
6
|
const messages_1 = require("../Utils/messages");
|
|
@@ -21,21 +20,8 @@ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
|
|
|
21
20
|
/** Cleans a received message to further processing */
|
|
22
21
|
const cleanMessage = (message, meId) => {
|
|
23
22
|
// ensure remoteJid and participant doesn't have device or agent in it
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
|
|
27
|
-
}
|
|
28
|
-
catch (_e) {
|
|
29
|
-
// if normalization fails, retain original remoteJid
|
|
30
|
-
}
|
|
31
|
-
if (message.key.participant) {
|
|
32
|
-
try {
|
|
33
|
-
message.key.participant = (0, WABinary_1.jidNormalizedUser)(message.key.participant);
|
|
34
|
-
}
|
|
35
|
-
catch (_e) {
|
|
36
|
-
// ignore if can't normalize participant
|
|
37
|
-
}
|
|
38
|
-
}
|
|
23
|
+
message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
|
|
24
|
+
message.key.participant = message.key.participant ? (0, WABinary_1.jidNormalizedUser)(message.key.participant) : undefined;
|
|
39
25
|
const content = (0, messages_1.normalizeMessageContent)(message.message);
|
|
40
26
|
// if the message has a reaction, ensure fromMe & remoteJid are from our perspective
|
|
41
27
|
if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
|
|
@@ -115,14 +101,14 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
115
101
|
return Buffer.from(txt);
|
|
116
102
|
}
|
|
117
103
|
}
|
|
118
|
-
|
|
119
|
-
|
|
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;
|
|
120
107
|
const meId = creds.me.id;
|
|
121
108
|
const { accountSettings } = creds;
|
|
122
109
|
const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
|
|
123
110
|
const isRealMsg = (0, exports.isRealMessage)(message, meId);
|
|
124
111
|
if (isRealMsg) {
|
|
125
|
-
chat.messages = [{ message }];
|
|
126
112
|
chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
127
113
|
// only increment unread count if not CIPHERTEXT and from another person
|
|
128
114
|
if ((0, exports.shouldIncrementChatUnread)(message)) {
|
|
@@ -151,22 +137,14 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
151
137
|
isLatest,
|
|
152
138
|
}, 'got history notification');
|
|
153
139
|
if (process) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
processedHistoryMessages
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
]
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
163
|
-
ev.emit('messaging-history.set', {
|
|
164
|
-
...data,
|
|
165
|
-
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
166
|
-
? isLatest
|
|
167
|
-
: undefined,
|
|
168
|
-
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
140
|
+
ev.emit('creds.update', {
|
|
141
|
+
processedHistoryMessages: [
|
|
142
|
+
...(creds.processedHistoryMessages || []),
|
|
143
|
+
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
144
|
+
]
|
|
169
145
|
});
|
|
146
|
+
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
147
|
+
ev.emit('messaging-history.set', { ...data, isLatest });
|
|
170
148
|
}
|
|
171
149
|
break;
|
|
172
150
|
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
@@ -209,41 +187,17 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
209
187
|
case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
210
188
|
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
211
189
|
if (response) {
|
|
212
|
-
placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
|
|
213
|
-
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
|
214
190
|
const { peerDataOperationResult } = response;
|
|
215
191
|
for (const result of peerDataOperationResult) {
|
|
216
192
|
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
217
193
|
if (retryResponse) {
|
|
218
194
|
const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
messages: [webMessageInfo],
|
|
223
|
-
type: 'notify',
|
|
224
|
-
requestId: response.stanzaId
|
|
225
|
-
});
|
|
226
|
-
}, 500);
|
|
195
|
+
ev.emit('messages.update', [
|
|
196
|
+
{ key: webMessageInfo.key, update: { message: webMessageInfo.message } }
|
|
197
|
+
]);
|
|
227
198
|
}
|
|
228
199
|
}
|
|
229
200
|
}
|
|
230
|
-
case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
|
|
231
|
-
ev.emit('messages.update', [
|
|
232
|
-
{
|
|
233
|
-
// flip the sender / fromMe properties because they're in the perspective of the sender
|
|
234
|
-
key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
|
|
235
|
-
update: {
|
|
236
|
-
message: {
|
|
237
|
-
editedMessage: {
|
|
238
|
-
message: protocolMsg.editedMessage
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
messageTimestamp: protocolMsg.timestampMs
|
|
242
|
-
? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
|
|
243
|
-
: message.messageTimestamp
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
]);
|
|
247
201
|
break;
|
|
248
202
|
}
|
|
249
203
|
}
|
|
@@ -254,11 +208,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
254
208
|
};
|
|
255
209
|
ev.emit('messages.reaction', [{
|
|
256
210
|
reaction,
|
|
257
|
-
key:
|
|
211
|
+
key: content.reactionMessage.key,
|
|
258
212
|
}]);
|
|
259
213
|
}
|
|
260
214
|
else if (message.messageStubType) {
|
|
261
|
-
const jid =
|
|
215
|
+
const jid = message.key.remoteJid;
|
|
262
216
|
//let actor = whatsappID (message.participant)
|
|
263
217
|
let participants;
|
|
264
218
|
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
@@ -266,15 +220,8 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
266
220
|
var _a;
|
|
267
221
|
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
|
268
222
|
};
|
|
269
|
-
const emitGroupRequestJoin = (participant, action, method) => {
|
|
270
|
-
ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
|
|
271
|
-
};
|
|
272
223
|
const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
|
|
273
224
|
switch (message.messageStubType) {
|
|
274
|
-
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
275
|
-
participants = message.messageStubParameters || [];
|
|
276
|
-
emitParticipantsUpdate('modify');
|
|
277
|
-
break;
|
|
278
225
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
279
226
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
280
227
|
participants = message.messageStubParameters || [];
|
|
@@ -302,41 +249,30 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
302
249
|
emitParticipantsUpdate('promote');
|
|
303
250
|
break;
|
|
304
251
|
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
305
|
-
const announceValue = (
|
|
252
|
+
const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
|
|
306
253
|
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
307
254
|
break;
|
|
308
255
|
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
309
|
-
const restrictValue = (
|
|
256
|
+
const restrictValue = (_e = message.messageStubParameters) === null || _e === void 0 ? void 0 : _e[0];
|
|
310
257
|
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
311
258
|
break;
|
|
312
259
|
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
313
|
-
const name = (
|
|
260
|
+
const name = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
|
|
314
261
|
chat.name = name;
|
|
315
262
|
emitGroupUpdate({ subject: name });
|
|
316
263
|
break;
|
|
317
|
-
case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
318
|
-
const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
|
|
319
|
-
chat.description = description;
|
|
320
|
-
emitGroupUpdate({ desc: description });
|
|
321
|
-
break;
|
|
322
264
|
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
323
|
-
const code = (
|
|
265
|
+
const code = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
324
266
|
emitGroupUpdate({ inviteCode: code });
|
|
325
267
|
break;
|
|
326
268
|
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
327
|
-
const memberAddValue = (
|
|
269
|
+
const memberAddValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
328
270
|
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
329
271
|
break;
|
|
330
272
|
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
331
|
-
const approvalMode = (
|
|
273
|
+
const approvalMode = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
332
274
|
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
333
275
|
break;
|
|
334
|
-
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
|
|
335
|
-
const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
|
|
336
|
-
const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
|
|
337
|
-
const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
|
|
338
|
-
emitGroupRequestJoin(participant, action, method);
|
|
339
|
-
break;
|
|
340
276
|
}
|
|
341
277
|
}
|
|
342
278
|
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
@@ -347,7 +283,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
347
283
|
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
348
284
|
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
349
285
|
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
350
|
-
const pollEncKey = (
|
|
286
|
+
const pollEncKey = (_k = pollMsg.messageContextInfo) === null || _k === void 0 ? void 0 : _k.messageSecret;
|
|
351
287
|
try {
|
|
352
288
|
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
353
289
|
pollEncKey,
|
package/lib/Utils/signal.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SignalRepository } from '../Types';
|
|
2
2
|
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
|
|
3
3
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
4
|
-
import { USyncQueryResultList } from '../WAUSync';
|
|
5
4
|
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
6
5
|
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
7
6
|
[id: string]: KeyPair;
|
|
@@ -16,7 +15,7 @@ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: n
|
|
|
16
15
|
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
17
16
|
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
18
17
|
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
|
|
19
|
-
export declare const extractDeviceJids: (result:
|
|
18
|
+
export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
|
|
20
19
|
/**
|
|
21
20
|
* get the next N keys for upload or processing
|
|
22
21
|
* @param count number of pre-keys to get or generate
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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");
|
|
5
4
|
const Defaults_1 = require("../Defaults");
|
|
6
5
|
const WABinary_1 = require("../WABinary");
|
|
7
6
|
const crypto_1 = require("./crypto");
|
|
7
|
+
const lodash_1 = require("lodash")
|
|
8
8
|
const generics_1 = require("./generics");
|
|
9
9
|
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
10
10
|
return {
|
|
@@ -59,61 +59,61 @@ const xmppPreKey = (pair, id) => ({
|
|
|
59
59
|
exports.xmppPreKey = xmppPreKey;
|
|
60
60
|
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
61
61
|
const extractKey = (key) => (key ? ({
|
|
62
|
-
keyId:
|
|
63
|
-
publicKey:
|
|
64
|
-
signature:
|
|
65
|
-
}) : undefined)
|
|
66
|
-
const nodes =
|
|
62
|
+
keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
|
|
63
|
+
publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
|
|
64
|
+
signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
|
|
65
|
+
}) : undefined)
|
|
66
|
+
const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
|
|
67
67
|
for (const node of nodes) {
|
|
68
|
-
|
|
68
|
+
WABinary_1.assertNodeErrorFree(node)
|
|
69
69
|
}
|
|
70
70
|
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
71
71
|
// So Promise.all doesn't really help here,
|
|
72
72
|
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
73
73
|
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
74
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 =
|
|
75
|
+
const chunkSize = 100
|
|
76
|
+
const chunks = lodash_1.chunk(nodes, chunkSize)
|
|
77
77
|
for (const nodesChunk of chunks) {
|
|
78
78
|
await Promise.all(nodesChunk.map(async (node) => {
|
|
79
|
-
const signedKey =
|
|
80
|
-
const key =
|
|
81
|
-
const identity =
|
|
82
|
-
const jid = node.attrs.jid
|
|
83
|
-
const registrationId =
|
|
79
|
+
const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
|
|
80
|
+
const key = WABinary_1.getBinaryNodeChild(node, 'key')
|
|
81
|
+
const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
|
|
82
|
+
const jid = node.attrs.jid
|
|
83
|
+
const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
|
|
84
84
|
await repository.injectE2ESession({
|
|
85
85
|
jid,
|
|
86
86
|
session: {
|
|
87
87
|
registrationId: registrationId,
|
|
88
|
-
identityKey:
|
|
88
|
+
identityKey: crypto_1.generateSignalPubKey(identity),
|
|
89
89
|
signedPreKey: extractKey(signedKey),
|
|
90
90
|
preKey: extractKey(key)
|
|
91
91
|
}
|
|
92
|
-
})
|
|
93
|
-
}))
|
|
92
|
+
})
|
|
93
|
+
}))
|
|
94
94
|
}
|
|
95
|
-
}
|
|
95
|
+
}
|
|
96
96
|
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
97
97
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
98
|
-
const { user: myUser, device: myDevice } =
|
|
99
|
-
const extracted = []
|
|
98
|
+
const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
|
|
99
|
+
const extracted = []
|
|
100
100
|
for (const userResult of result) {
|
|
101
|
-
const { devices, id } = userResult
|
|
102
|
-
const { user } =
|
|
103
|
-
const deviceList = devices
|
|
101
|
+
const { devices, id } = userResult
|
|
102
|
+
const { user } = WABinary_1.jidDecode(id)
|
|
103
|
+
const deviceList = devices?.deviceList
|
|
104
104
|
if (Array.isArray(deviceList)) {
|
|
105
105
|
for (const { id: device, keyIndex } of deviceList) {
|
|
106
106
|
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
107
107
|
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
108
108
|
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
109
109
|
) {
|
|
110
|
-
extracted.push({ user, device })
|
|
110
|
+
extracted.push({ user, device })
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
return extracted
|
|
116
|
-
}
|
|
115
|
+
return extracted
|
|
116
|
+
}
|
|
117
117
|
exports.extractDeviceJids = extractDeviceJids;
|
|
118
118
|
/**
|
|
119
119
|
* get the next N keys for upload or processing
|
|
@@ -7,12 +7,7 @@ const path_1 = require("path");
|
|
|
7
7
|
const WAProto_1 = require("../../WAProto");
|
|
8
8
|
const auth_utils_1 = require("./auth-utils");
|
|
9
9
|
const generics_1 = require("./generics");
|
|
10
|
-
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
11
|
-
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
12
|
-
// https://github.com/nodejs/node/issues/26338
|
|
13
|
-
// Use a Map to store mutexes for each file path
|
|
14
10
|
const fileLocks = new Map();
|
|
15
|
-
// Get or create a mutex for a specific file path
|
|
16
11
|
const getFileLock = (path) => {
|
|
17
12
|
let mutex = fileLocks.get(path);
|
|
18
13
|
if (!mutex) {
|
|
@@ -29,7 +24,6 @@ const getFileLock = (path) => {
|
|
|
29
24
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
30
25
|
* */
|
|
31
26
|
const useMultiFileAuthState = async (folder) => {
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
27
|
const writeData = async (data, file) => {
|
|
34
28
|
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
35
29
|
const mutex = getFileLock(filePath);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { proto } from '../../WAProto';
|
|
2
2
|
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
|
|
3
3
|
import { BinaryNode } from '../WABinary';
|
|
4
|
+
export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
|
|
4
5
|
export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
|
|
5
6
|
export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
|
|
6
|
-
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds,
|
|
7
|
+
export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
|
|
7
8
|
creds: Partial<AuthenticationCreds>;
|
|
8
9
|
reply: BinaryNode;
|
|
9
|
-
};
|
|
10
|
-
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array
|
|
10
|
+
};
|
|
11
|
+
export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
|