angularsockets 1.0.1 → 1.0.2
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 +1880 -36
- package/WAProto/index.d.ts +50383 -0
- package/WAProto/index.js +37203 -11791
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -6
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +79 -101
- package/lib/Signal/libsignal.js +29 -51
- package/lib/Socket/Client/web-socket-client.js +0 -2
- package/lib/Socket/business.d.ts +42 -43
- package/lib/Socket/chats.d.ts +9 -8
- package/lib/Socket/chats.js +107 -21
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +24 -25
- package/lib/Socket/index.d.ts +51 -52
- package/lib/Socket/messages-recv.d.ts +34 -37
- package/lib/Socket/messages-recv.js +37 -175
- package/lib/Socket/messages-send.d.ts +16 -10
- package/lib/Socket/messages-send.js +540 -346
- package/lib/Socket/newsletter.d.ts +26 -28
- package/lib/Socket/newsletter.js +4 -4
- package/lib/Socket/registration.d.ts +49 -52
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +1 -0
- package/lib/Socket/socket.js +36 -23
- package/lib/Socket/usync.d.ts +11 -10
- package/lib/Store/make-cache-manager-store.d.ts +2 -1
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +5 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +0 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +12 -7
- package/lib/Types/Events.d.ts +17 -2
- package/lib/Types/GroupMetadata.d.ts +3 -2
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +170 -10
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/Socket.d.ts +7 -2
- package/lib/Types/index.d.ts +9 -0
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +35 -14
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +11 -12
- package/lib/Utils/chat-utils.js +52 -36
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +74 -26
- package/lib/Utils/decode-wa-message.d.ts +17 -0
- package/lib/Utils/decode-wa-message.js +53 -17
- package/lib/Utils/event-buffer.js +10 -7
- package/lib/Utils/generics.d.ts +13 -17
- package/lib/Utils/generics.js +26 -15
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +4 -6
- package/lib/Utils/logger.d.ts +1 -3
- package/lib/Utils/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +25 -28
- package/lib/Utils/messages-media.js +47 -57
- package/lib/Utils/messages.js +461 -44
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/noise-handler.js +19 -14
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +75 -23
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +43 -35
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +251 -36
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-single-file-auth-state.js +75 -0
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +1 -1
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +23 -11
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +46 -22
- package/lib/WABinary/generic-utils.d.ts +2 -4
- package/lib/WABinary/generic-utils.js +2 -10
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/USyncUser.d.ts +0 -2
- package/lib/index.js +0 -6
- package/package.json +96 -104
- package/engine-requirements.js +0 -10
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts +0 -14
- package/lib/Signal/Group/group-session-builder.js +0 -64
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.js +0 -96
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/index.js +0 -57
- package/lib/Signal/Group/keyhelper.d.ts +0 -10
- package/lib/Signal/Group/keyhelper.js +0 -55
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
- package/lib/Signal/Group/sender-chain-key.js +0 -34
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.d.ts +0 -18
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.d.ts +0 -17
- package/lib/Signal/Group/sender-key-name.js +0 -51
- package/lib/Signal/Group/sender-key-record.d.ts +0 -30
- package/lib/Signal/Group/sender-key-record.js +0 -53
- package/lib/Signal/Group/sender-key-state.d.ts +0 -38
- package/lib/Signal/Group/sender-key-state.js +0 -99
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Socket/dugong.d.ts +0 -175
- package/lib/Socket/dugong.js +0 -342
- package/lib/index.d.ts +0 -12
|
@@ -38,20 +38,20 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
38
38
|
authenticate(ciphertext);
|
|
39
39
|
return result;
|
|
40
40
|
};
|
|
41
|
-
const localHKDF = (data) => {
|
|
42
|
-
const key = (0, crypto_1.hkdf)(Buffer.from(data), 64, { salt, info: '' });
|
|
41
|
+
const localHKDF = async (data) => {
|
|
42
|
+
const key = await (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 = (data) => {
|
|
46
|
-
const [write, read] = localHKDF(data);
|
|
45
|
+
const mixIntoKey = async (data) => {
|
|
46
|
+
const [write, read] = await 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] = localHKDF(new Uint8Array(0));
|
|
53
|
+
const finishInit = async () => {
|
|
54
|
+
const [write, read] = await localHKDF(new Uint8Array(0));
|
|
55
55
|
encKey = write;
|
|
56
56
|
decKey = read;
|
|
57
57
|
hash = Buffer.from([]);
|
|
@@ -77,12 +77,17 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
77
77
|
authenticate,
|
|
78
78
|
mixIntoKey,
|
|
79
79
|
finishInit,
|
|
80
|
-
processHandshake: ({ serverHello }, noiseKey) => {
|
|
80
|
+
processHandshake: async ({ serverHello }, noiseKey) => {
|
|
81
81
|
authenticate(serverHello.ephemeral);
|
|
82
|
-
mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral));
|
|
82
|
+
await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral));
|
|
83
83
|
const decStaticContent = decrypt(serverHello.static);
|
|
84
|
-
mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
|
|
84
|
+
await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
|
|
85
85
|
const certDecoded = decrypt(serverHello.payload);
|
|
86
|
+
const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded);
|
|
87
|
+
const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
|
|
88
|
+
if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
|
|
89
|
+
throw new boom_1.Boom('certification match failed', { statusCode: 400 });
|
|
90
|
+
}/*
|
|
86
91
|
if (mobile) {
|
|
87
92
|
WAProto_1.proto.CertChain.NoiseCertificate.decode(certDecoded);
|
|
88
93
|
}
|
|
@@ -92,9 +97,9 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
92
97
|
if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
|
|
93
98
|
throw new boom_1.Boom('certification match failed', { statusCode: 400 });
|
|
94
99
|
}
|
|
95
|
-
}
|
|
100
|
+
}*/
|
|
96
101
|
const keyEnc = encrypt(noiseKey.public);
|
|
97
|
-
mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
|
|
102
|
+
await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
|
|
98
103
|
return keyEnc;
|
|
99
104
|
},
|
|
100
105
|
encodeFrame: (data) => {
|
|
@@ -125,7 +130,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
125
130
|
frame.set(data, introSize + 3);
|
|
126
131
|
return frame;
|
|
127
132
|
},
|
|
128
|
-
decodeFrame: (newData, onFrame) => {
|
|
133
|
+
decodeFrame: async (newData, onFrame) => {
|
|
129
134
|
var _a;
|
|
130
135
|
// the binary protocol uses its own framing mechanism
|
|
131
136
|
// on top of the WS frames
|
|
@@ -143,7 +148,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
143
148
|
inBytes = inBytes.slice(size + 3);
|
|
144
149
|
if (isFinished) {
|
|
145
150
|
const result = decrypt(frame);
|
|
146
|
-
frame = (0, WABinary_1.decodeBinaryNode)(result);
|
|
151
|
+
frame = await (0, WABinary_1.decodeBinaryNode)(result);
|
|
147
152
|
}
|
|
148
153
|
logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
|
|
149
154
|
onFrame(frame);
|
|
@@ -152,4 +157,4 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
|
|
|
152
157
|
}
|
|
153
158
|
};
|
|
154
159
|
};
|
|
155
|
-
exports.makeNoiseHandler = makeNoiseHandler;
|
|
160
|
+
exports.makeNoiseHandler = makeNoiseHandler;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import type { Logger } from 'pino';
|
|
3
2
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { AuthenticationCreds, BaileysEventEmitter,
|
|
3
|
+
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction } from '../Types';
|
|
4
|
+
import { ILogger } from './logger';
|
|
5
5
|
type ProcessMessageContext = {
|
|
6
6
|
shouldProcessHistoryMsg: boolean;
|
|
7
|
+
placeholderResendCache?: CacheStore;
|
|
7
8
|
creds: AuthenticationCreds;
|
|
8
9
|
keyStore: SignalKeyStoreWithTransaction;
|
|
9
10
|
ev: BaileysEventEmitter;
|
|
10
|
-
|
|
11
|
-
logger?: Logger;
|
|
11
|
+
logger?: ILogger;
|
|
12
12
|
options: AxiosRequestConfig<{}>;
|
|
13
13
|
};
|
|
14
14
|
/** Cleans a received message to further processing */
|
|
@@ -37,5 +37,5 @@ type PollContext = {
|
|
|
37
37
|
* @returns list of SHA256 options
|
|
38
38
|
*/
|
|
39
39
|
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
|
|
40
|
+
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options }: ProcessMessageContext) => Promise<void>;
|
|
41
41
|
export default processMessage;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
|
|
4
|
+
exports.decryptPollVote = decryptPollVote;
|
|
4
5
|
const WAProto_1 = require("../../WAProto");
|
|
5
6
|
const Types_1 = require("../Types");
|
|
6
7
|
const messages_1 = require("../Utils/messages");
|
|
@@ -101,14 +102,14 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
101
102
|
return Buffer.from(txt);
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
105
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options }) => {
|
|
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)) };
|
|
110
110
|
const isRealMsg = (0, exports.isRealMessage)(message, meId);
|
|
111
111
|
if (isRealMsg) {
|
|
112
|
+
chat.messages = [{ message }];
|
|
112
113
|
chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
113
114
|
// only increment unread count if not CIPHERTEXT and from another person
|
|
114
115
|
if ((0, exports.shouldIncrementChatUnread)(message)) {
|
|
@@ -137,14 +138,22 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
137
138
|
isLatest,
|
|
138
139
|
}, 'got history notification');
|
|
139
140
|
if (process) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
142
|
+
ev.emit('creds.update', {
|
|
143
|
+
processedHistoryMessages: [
|
|
144
|
+
...(creds.processedHistoryMessages || []),
|
|
145
|
+
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
146
|
+
]
|
|
147
|
+
});
|
|
148
|
+
}
|
|
146
149
|
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
147
|
-
ev.emit('messaging-history.set', {
|
|
150
|
+
ev.emit('messaging-history.set', {
|
|
151
|
+
...data,
|
|
152
|
+
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
153
|
+
? isLatest
|
|
154
|
+
: undefined,
|
|
155
|
+
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
156
|
+
});
|
|
148
157
|
}
|
|
149
158
|
break;
|
|
150
159
|
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
@@ -187,17 +196,42 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
187
196
|
case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
188
197
|
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
189
198
|
if (response) {
|
|
199
|
+
placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
|
|
200
|
+
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
|
190
201
|
const { peerDataOperationResult } = response;
|
|
191
202
|
for (const result of peerDataOperationResult) {
|
|
192
203
|
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
204
|
+
//eslint-disable-next-line max-depth
|
|
193
205
|
if (retryResponse) {
|
|
194
206
|
const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
207
|
+
// wait till another upsert event is available, don't want it to be part of the PDO response message
|
|
208
|
+
setTimeout(() => {
|
|
209
|
+
ev.emit('messages.upsert', {
|
|
210
|
+
messages: [webMessageInfo],
|
|
211
|
+
type: 'notify',
|
|
212
|
+
requestId: response.stanzaId
|
|
213
|
+
});
|
|
214
|
+
}, 500);
|
|
198
215
|
}
|
|
199
216
|
}
|
|
200
217
|
}
|
|
218
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
|
|
219
|
+
ev.emit('messages.update', [
|
|
220
|
+
{
|
|
221
|
+
// flip the sender / fromMe properties because they're in the perspective of the sender
|
|
222
|
+
key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
|
|
223
|
+
update: {
|
|
224
|
+
message: {
|
|
225
|
+
editedMessage: {
|
|
226
|
+
message: protocolMsg.editedMessage
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
messageTimestamp: protocolMsg.timestampMs
|
|
230
|
+
? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
|
|
231
|
+
: message.messageTimestamp
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
]);
|
|
201
235
|
break;
|
|
202
236
|
}
|
|
203
237
|
}
|
|
@@ -208,11 +242,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
208
242
|
};
|
|
209
243
|
ev.emit('messages.reaction', [{
|
|
210
244
|
reaction,
|
|
211
|
-
key: content.reactionMessage.key,
|
|
245
|
+
key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key,
|
|
212
246
|
}]);
|
|
213
247
|
}
|
|
214
248
|
else if (message.messageStubType) {
|
|
215
|
-
const jid = message.key.remoteJid;
|
|
249
|
+
const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
|
|
216
250
|
//let actor = whatsappID (message.participant)
|
|
217
251
|
let participants;
|
|
218
252
|
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
@@ -220,8 +254,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
220
254
|
var _a;
|
|
221
255
|
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
|
222
256
|
};
|
|
257
|
+
const emitGroupRequestJoin = (participant, action, method) => {
|
|
258
|
+
ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
|
|
259
|
+
};
|
|
223
260
|
const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
|
|
224
261
|
switch (message.messageStubType) {
|
|
262
|
+
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
|
|
263
|
+
participants = message.messageStubParameters || [];
|
|
264
|
+
emitParticipantsUpdate('modify');
|
|
265
|
+
break;
|
|
225
266
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
|
|
226
267
|
case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
|
|
227
268
|
participants = message.messageStubParameters || [];
|
|
@@ -249,30 +290,41 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
249
290
|
emitParticipantsUpdate('promote');
|
|
250
291
|
break;
|
|
251
292
|
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
252
|
-
const announceValue = (
|
|
293
|
+
const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
253
294
|
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
254
295
|
break;
|
|
255
296
|
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
256
|
-
const restrictValue = (
|
|
297
|
+
const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
257
298
|
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
258
299
|
break;
|
|
259
300
|
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
260
|
-
const name = (
|
|
301
|
+
const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
261
302
|
chat.name = name;
|
|
262
303
|
emitGroupUpdate({ subject: name });
|
|
263
304
|
break;
|
|
305
|
+
case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
306
|
+
const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
|
|
307
|
+
chat.description = description;
|
|
308
|
+
emitGroupUpdate({ desc: description });
|
|
309
|
+
break;
|
|
264
310
|
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
265
|
-
const code = (
|
|
311
|
+
const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
|
|
266
312
|
emitGroupUpdate({ inviteCode: code });
|
|
267
313
|
break;
|
|
268
314
|
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
269
|
-
const memberAddValue = (
|
|
315
|
+
const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
|
|
270
316
|
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
271
317
|
break;
|
|
272
318
|
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
273
|
-
const approvalMode = (
|
|
319
|
+
const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
|
|
274
320
|
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
275
321
|
break;
|
|
322
|
+
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
|
|
323
|
+
const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
|
|
324
|
+
const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
|
|
325
|
+
const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
|
|
326
|
+
emitGroupRequestJoin(participant, action, method);
|
|
327
|
+
break;
|
|
276
328
|
}
|
|
277
329
|
}
|
|
278
330
|
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
@@ -283,7 +335,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
283
335
|
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
284
336
|
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
285
337
|
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
286
|
-
const pollEncKey = (
|
|
338
|
+
const pollEncKey = (_s = pollMsg.messageContextInfo) === null || _s === void 0 ? void 0 : _s.messageSecret;
|
|
287
339
|
try {
|
|
288
340
|
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
289
341
|
pollEncKey,
|
package/lib/Utils/signal.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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';
|
|
4
5
|
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
5
6
|
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
6
7
|
[id: string]: KeyPair;
|
|
@@ -15,7 +16,7 @@ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: n
|
|
|
15
16
|
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
16
17
|
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
17
18
|
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
|
|
18
|
-
export declare const extractDeviceJids: (result:
|
|
19
|
+
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
|
|
19
20
|
/**
|
|
20
21
|
* get the next N keys for upload or processing
|
|
21
22
|
* @param count number of pre-keys to get or generate
|
package/lib/Utils/signal.js
CHANGED
|
@@ -5,6 +5,13 @@ const Defaults_1 = require("../Defaults");
|
|
|
5
5
|
const WABinary_1 = require("../WABinary");
|
|
6
6
|
const crypto_1 = require("./crypto");
|
|
7
7
|
const generics_1 = require("./generics");
|
|
8
|
+
function chunk(array, size) {
|
|
9
|
+
const result = [];
|
|
10
|
+
for (let i = 0; i < array.length; i += size) {
|
|
11
|
+
result.push(array.slice(i, i + size));
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
8
15
|
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
9
16
|
return {
|
|
10
17
|
identifier: { name: wid, deviceId: 0 },
|
|
@@ -66,46 +73,47 @@ const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
66
73
|
for (const node of nodes) {
|
|
67
74
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
68
75
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
77
|
+
// So Promise.all doesn't really help here,
|
|
78
|
+
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
79
|
+
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
80
|
+
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
81
|
+
const chunkSize = 100;
|
|
82
|
+
const chunks = chunk(nodes, chunkSize);
|
|
83
|
+
for (const nodesChunk of chunks) {
|
|
84
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
85
|
+
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
86
|
+
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
87
|
+
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
88
|
+
const jid = node.attrs.jid;
|
|
89
|
+
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
90
|
+
await repository.injectE2ESession({
|
|
91
|
+
jid,
|
|
92
|
+
session: {
|
|
93
|
+
registrationId: registrationId,
|
|
94
|
+
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
95
|
+
signedPreKey: extractKey(signedKey),
|
|
96
|
+
preKey: extractKey(key)
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
85
101
|
};
|
|
86
102
|
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
87
103
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
88
|
-
var _a;
|
|
89
104
|
const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
|
|
90
105
|
const extracted = [];
|
|
91
|
-
for (const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
for
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
103
|
-
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
104
|
-
(device === 0 || !!attrs['key-index']) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
105
|
-
) {
|
|
106
|
-
extracted.push({ user, device });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
106
|
+
for (const userResult of result) {
|
|
107
|
+
const { devices, id } = userResult;
|
|
108
|
+
const { user } = (0, WABinary_1.jidDecode)(id);
|
|
109
|
+
const deviceList = devices === null || devices === void 0 ? void 0 : devices.deviceList;
|
|
110
|
+
if (Array.isArray(deviceList)) {
|
|
111
|
+
for (const { id: device, keyIndex } of deviceList) {
|
|
112
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
113
|
+
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
114
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
115
|
+
) {
|
|
116
|
+
extracted.push({ user, device });
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
119
|
}
|