@heavstaltech/baileys 2.3.4 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +226 -53
  2. package/WAProto/index.js +14270 -302
  3. package/engine-requirements.js +10 -0
  4. package/lib/Defaults/baileys-version.json +1 -1
  5. package/lib/Defaults/index.js +118 -79
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  8. package/lib/Signal/Group/ciphertext-message.js +15 -0
  9. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  10. package/lib/Signal/Group/group-session-builder.js +64 -0
  11. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  12. package/lib/Signal/Group/group_cipher.js +96 -0
  13. package/lib/Signal/Group/index.d.ts +11 -0
  14. package/lib/Signal/Group/index.js +57 -0
  15. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  16. package/lib/Signal/Group/keyhelper.js +55 -0
  17. package/lib/Signal/Group/queue-job.d.ts +1 -0
  18. package/lib/Signal/Group/queue-job.js +57 -0
  19. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  20. package/lib/Signal/Group/sender-chain-key.js +34 -0
  21. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  22. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  23. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  24. package/lib/Signal/Group/sender-key-message.js +69 -0
  25. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  26. package/lib/Signal/Group/sender-key-name.js +51 -0
  27. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  28. package/lib/Signal/Group/sender-key-record.js +53 -0
  29. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  30. package/lib/Signal/Group/sender-key-state.js +99 -0
  31. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  32. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
  33. package/lib/Signal/libsignal.js +51 -29
  34. package/lib/Socket/business.d.ts +43 -42
  35. package/lib/Socket/chats.d.ts +222 -36
  36. package/lib/Socket/chats.js +186 -153
  37. package/lib/Socket/dugong.d.ts +254 -0
  38. package/lib/Socket/dugong.js +484 -0
  39. package/lib/Socket/groups.d.ts +7 -7
  40. package/lib/Socket/groups.js +37 -35
  41. package/lib/Socket/index.d.ts +52 -51
  42. package/lib/Socket/index.js +1 -0
  43. package/lib/Socket/messages-recv.d.ts +37 -34
  44. package/lib/Socket/messages-recv.js +175 -37
  45. package/lib/Socket/messages-send.d.ts +12 -18
  46. package/lib/Socket/messages-send.js +396 -574
  47. package/lib/Socket/newsletter.d.ts +28 -26
  48. package/lib/Socket/newsletter.js +140 -25
  49. package/lib/Socket/registration.d.ts +52 -49
  50. package/lib/Socket/registration.js +7 -7
  51. package/lib/Socket/socket.d.ts +0 -1
  52. package/lib/Socket/socket.js +47 -198
  53. package/lib/Socket/usync.d.ts +10 -11
  54. package/lib/Store/make-cache-manager-store.d.ts +1 -2
  55. package/lib/Store/make-in-memory-store.d.ts +2 -2
  56. package/lib/Store/make-in-memory-store.js +1 -5
  57. package/lib/Store/make-ordered-dictionary.js +2 -2
  58. package/lib/Types/Auth.d.ts +1 -0
  59. package/lib/Types/Call.d.ts +1 -1
  60. package/lib/Types/Chat.d.ts +7 -12
  61. package/lib/Types/Events.d.ts +2 -17
  62. package/lib/Types/GroupMetadata.d.ts +2 -3
  63. package/lib/Types/Label.d.ts +0 -11
  64. package/lib/Types/Label.js +1 -1
  65. package/lib/Types/LabelAssociation.js +1 -1
  66. package/lib/Types/Message.d.ts +10 -170
  67. package/lib/Types/Newsletter.d.ts +97 -86
  68. package/lib/Types/Newsletter.js +38 -32
  69. package/lib/Types/Socket.d.ts +2 -7
  70. package/lib/Types/index.d.ts +0 -9
  71. package/lib/Types/index.js +1 -1
  72. package/lib/Utils/auth-utils.js +14 -35
  73. package/lib/Utils/business.d.ts +1 -1
  74. package/lib/Utils/business.js +2 -2
  75. package/lib/Utils/chat-utils.d.ts +12 -11
  76. package/lib/Utils/chat-utils.js +36 -52
  77. package/lib/Utils/crypto.d.ts +16 -15
  78. package/lib/Utils/crypto.js +26 -74
  79. package/lib/Utils/decode-wa-message.d.ts +0 -17
  80. package/lib/Utils/decode-wa-message.js +17 -53
  81. package/lib/Utils/event-buffer.js +7 -10
  82. package/lib/Utils/generics.d.ts +17 -13
  83. package/lib/Utils/generics.js +79 -58
  84. package/lib/Utils/history.d.ts +2 -6
  85. package/lib/Utils/history.js +6 -4
  86. package/lib/Utils/logger.d.ts +3 -1
  87. package/lib/Utils/lt-hash.js +12 -12
  88. package/lib/Utils/make-mutex.d.ts +2 -2
  89. package/lib/Utils/messages-media.d.ts +28 -25
  90. package/lib/Utils/messages-media.js +201 -103
  91. package/lib/Utils/messages.js +36 -473
  92. package/lib/Utils/noise-handler.d.ts +5 -4
  93. package/lib/Utils/noise-handler.js +14 -19
  94. package/lib/Utils/process-message.d.ts +5 -5
  95. package/lib/Utils/process-message.js +23 -75
  96. package/lib/Utils/signal.d.ts +1 -2
  97. package/lib/Utils/signal.js +26 -32
  98. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  99. package/lib/Utils/use-multi-file-auth-state.js +66 -242
  100. package/lib/Utils/validate-connection.d.ts +1 -1
  101. package/lib/Utils/validate-connection.js +88 -64
  102. package/lib/WABinary/constants.d.ts +27 -24
  103. package/lib/WABinary/decode.d.ts +2 -1
  104. package/lib/WABinary/decode.js +11 -23
  105. package/lib/WABinary/encode.d.ts +2 -1
  106. package/lib/WABinary/encode.js +147 -134
  107. package/lib/WABinary/generic-utils.d.ts +5 -2
  108. package/lib/WABinary/generic-utils.js +125 -37
  109. package/lib/WABinary/jid-utils.d.ts +1 -1
  110. package/lib/WAM/BinaryInfo.d.ts +11 -2
  111. package/lib/WAM/encode.d.ts +2 -1
  112. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  113. package/lib/WAUSync/USyncUser.d.ts +2 -0
  114. package/lib/index.d.ts +12 -0
  115. package/lib/index.js +12 -0
  116. package/package.json +102 -98
  117. package/WAProto/index.d.ts +0 -50383
  118. package/WASignalGroup/GroupProtocol.js +0 -1697
  119. package/WASignalGroup/ciphertext_message.js +0 -16
  120. package/WASignalGroup/group_cipher.js +0 -120
  121. package/WASignalGroup/group_session_builder.js +0 -46
  122. package/WASignalGroup/index.js +0 -5
  123. package/WASignalGroup/keyhelper.js +0 -21
  124. package/WASignalGroup/protobufs.js +0 -3
  125. package/WASignalGroup/queue_job.js +0 -69
  126. package/WASignalGroup/sender_chain_key.js +0 -50
  127. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  128. package/WASignalGroup/sender_key_message.js +0 -92
  129. package/WASignalGroup/sender_key_name.js +0 -70
  130. package/WASignalGroup/sender_key_record.js +0 -56
  131. package/WASignalGroup/sender_key_state.js +0 -129
  132. package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
  133. package/lib/Utils/use-single-file-auth-state.js +0 -75
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { Logger } from 'pino';
2
3
  import { proto } from '../../WAProto';
3
4
  import { KeyPair } from '../Types';
@@ -9,12 +10,12 @@ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public
9
10
  logger: Logger;
10
11
  routingInfo?: Buffer | undefined;
11
12
  }) => {
12
- encrypt: (plaintext: Uint8Array) => any;
13
- decrypt: (ciphertext: Uint8Array) => any;
13
+ encrypt: (plaintext: Uint8Array) => Buffer;
14
+ decrypt: (ciphertext: Uint8Array) => Buffer;
14
15
  authenticate: (data: Uint8Array) => void;
15
16
  mixIntoKey: (data: Uint8Array) => void;
16
17
  finishInit: () => void;
17
- processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => any;
18
- encodeFrame: (data: Buffer | Uint8Array) => any;
18
+ processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Buffer;
19
+ encodeFrame: (data: Buffer | Uint8Array) => Buffer;
19
20
  decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
20
21
  };
@@ -38,20 +38,20 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
38
38
  authenticate(ciphertext);
39
39
  return result;
40
40
  };
41
- const localHKDF = async (data) => {
42
- const key = await (0, crypto_1.hkdf)(Buffer.from(data), 64, { salt, info: '' });
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 = async (data) => {
46
- const [write, read] = await localHKDF(data);
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 = async () => {
54
- const [write, read] = await localHKDF(new Uint8Array(0));
53
+ const finishInit = () => {
54
+ const [write, read] = localHKDF(new Uint8Array(0));
55
55
  encKey = write;
56
56
  decKey = read;
57
57
  hash = Buffer.from([]);
@@ -77,17 +77,12 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
77
77
  authenticate,
78
78
  mixIntoKey,
79
79
  finishInit,
80
- processHandshake: async ({ serverHello }, noiseKey) => {
80
+ processHandshake: ({ serverHello }, noiseKey) => {
81
81
  authenticate(serverHello.ephemeral);
82
- await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral));
82
+ mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral));
83
83
  const decStaticContent = decrypt(serverHello.static);
84
- await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
84
+ 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
- }/*
91
86
  if (mobile) {
92
87
  WAProto_1.proto.CertChain.NoiseCertificate.decode(certDecoded);
93
88
  }
@@ -97,9 +92,9 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
97
92
  if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
98
93
  throw new boom_1.Boom('certification match failed', { statusCode: 400 });
99
94
  }
100
- }*/
95
+ }
101
96
  const keyEnc = encrypt(noiseKey.public);
102
- await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
97
+ mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
103
98
  return keyEnc;
104
99
  },
105
100
  encodeFrame: (data) => {
@@ -130,7 +125,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
130
125
  frame.set(data, introSize + 3);
131
126
  return frame;
132
127
  },
133
- decodeFrame: async (newData, onFrame) => {
128
+ decodeFrame: (newData, onFrame) => {
134
129
  var _a;
135
130
  // the binary protocol uses its own framing mechanism
136
131
  // on top of the WS frames
@@ -148,7 +143,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
148
143
  inBytes = inBytes.slice(size + 3);
149
144
  if (isFinished) {
150
145
  const result = decrypt(frame);
151
- frame = await (0, WABinary_1.decodeBinaryNode)(result);
146
+ frame = (0, WABinary_1.decodeBinaryNode)(result);
152
147
  }
153
148
  logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
154
149
  onFrame(frame);
@@ -157,4 +152,4 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
157
152
  }
158
153
  };
159
154
  };
160
- exports.makeNoiseHandler = makeNoiseHandler;
155
+ exports.makeNoiseHandler = makeNoiseHandler;
@@ -1,14 +1,14 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
+ import type { Logger } from 'pino';
2
3
  import { proto } from '../../WAProto';
3
- import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction } from '../Types';
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
- logger?: ILogger;
10
+ getMessage: SocketConfig['getMessage'];
11
+ logger?: Logger;
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, placeholderResendCache, ev, creds, keyStore, logger, options }: ProcessMessageContext) => Promise<void>;
40
+ declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
41
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");
@@ -102,14 +101,14 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
102
101
  return Buffer.from(txt);
103
102
  }
104
103
  }
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;
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;
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 }];
113
112
  chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
114
113
  // only increment unread count if not CIPHERTEXT and from another person
115
114
  if ((0, exports.shouldIncrementChatUnread)(message)) {
@@ -138,22 +137,14 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
138
137
  isLatest,
139
138
  }, 'got history notification');
140
139
  if (process) {
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
- }
149
- const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
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
140
+ ev.emit('creds.update', {
141
+ processedHistoryMessages: [
142
+ ...(creds.processedHistoryMessages || []),
143
+ { key: message.key, messageTimestamp: message.messageTimestamp }
144
+ ]
156
145
  });
146
+ const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
147
+ ev.emit('messaging-history.set', { ...data, isLatest });
157
148
  }
158
149
  break;
159
150
  case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
@@ -196,42 +187,17 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
196
187
  case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
197
188
  const response = protocolMsg.peerDataOperationRequestResponseMessage;
198
189
  if (response) {
199
- placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
200
- // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
201
190
  const { peerDataOperationResult } = response;
202
191
  for (const result of peerDataOperationResult) {
203
192
  const { placeholderMessageResendResponse: retryResponse } = result;
204
- //eslint-disable-next-line max-depth
205
193
  if (retryResponse) {
206
194
  const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
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);
195
+ ev.emit('messages.update', [
196
+ { key: webMessageInfo.key, update: { message: webMessageInfo.message } }
197
+ ]);
215
198
  }
216
199
  }
217
200
  }
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
- ]);
235
201
  break;
236
202
  }
237
203
  }
@@ -242,11 +208,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
242
208
  };
243
209
  ev.emit('messages.reaction', [{
244
210
  reaction,
245
- key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key,
211
+ key: content.reactionMessage.key,
246
212
  }]);
247
213
  }
248
214
  else if (message.messageStubType) {
249
- const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
215
+ const jid = message.key.remoteJid;
250
216
  //let actor = whatsappID (message.participant)
251
217
  let participants;
252
218
  const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
@@ -254,15 +220,8 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
254
220
  var _a;
255
221
  ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
256
222
  };
257
- const emitGroupRequestJoin = (participant, action, method) => {
258
- ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
259
- };
260
223
  const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
261
224
  switch (message.messageStubType) {
262
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
263
- participants = message.messageStubParameters || [];
264
- emitParticipantsUpdate('modify');
265
- break;
266
225
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
267
226
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
268
227
  participants = message.messageStubParameters || [];
@@ -290,41 +249,30 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
290
249
  emitParticipantsUpdate('promote');
291
250
  break;
292
251
  case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
293
- const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
252
+ const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
294
253
  emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
295
254
  break;
296
255
  case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
297
- const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
256
+ const restrictValue = (_e = message.messageStubParameters) === null || _e === void 0 ? void 0 : _e[0];
298
257
  emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
299
258
  break;
300
259
  case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
301
- const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
260
+ const name = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
302
261
  chat.name = name;
303
262
  emitGroupUpdate({ subject: name });
304
263
  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;
310
264
  case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
311
- const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
265
+ const code = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
312
266
  emitGroupUpdate({ inviteCode: code });
313
267
  break;
314
268
  case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
315
- const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
269
+ const memberAddValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
316
270
  emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
317
271
  break;
318
272
  case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
319
- const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
273
+ const approvalMode = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
320
274
  emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
321
275
  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;
328
276
  }
329
277
  }
330
278
  else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
@@ -335,7 +283,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
335
283
  const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
336
284
  const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
337
285
  const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
338
- const pollEncKey = (_s = pollMsg.messageContextInfo) === null || _s === void 0 ? void 0 : _s.messageSecret;
286
+ const pollEncKey = (_k = pollMsg.messageContextInfo) === null || _k === void 0 ? void 0 : _k.messageSecret;
339
287
  try {
340
288
  const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
341
289
  pollEncKey,
@@ -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: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
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
@@ -4,14 +4,8 @@ exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids
4
4
  const Defaults_1 = require("../Defaults");
5
5
  const WABinary_1 = require("../WABinary");
6
6
  const crypto_1 = require("./crypto");
7
+ const lodash_1 = require("lodash")
7
8
  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
- }
15
9
  const createSignalIdentity = (wid, accountSignatureKey) => {
16
10
  return {
17
11
  identifier: { name: wid, deviceId: 0 },
@@ -65,61 +59,61 @@ const xmppPreKey = (pair, id) => ({
65
59
  exports.xmppPreKey = xmppPreKey;
66
60
  const parseAndInjectE2ESessions = async (node, repository) => {
67
61
  const extractKey = (key) => (key ? ({
68
- keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
69
- publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
70
- signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature'),
71
- }) : undefined);
72
- const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
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')
73
67
  for (const node of nodes) {
74
- (0, WABinary_1.assertNodeErrorFree)(node);
68
+ WABinary_1.assertNodeErrorFree(node)
75
69
  }
76
70
  // Most of the work in repository.injectE2ESession is CPU intensive, not IO
77
71
  // So Promise.all doesn't really help here,
78
72
  // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
79
73
  // This way we chunk it in smaller parts and between those parts we can yield to the event loop
80
74
  // 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);
75
+ const chunkSize = 100
76
+ const chunks = lodash_1.chunk(nodes, chunkSize)
83
77
  for (const nodesChunk of chunks) {
84
78
  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);
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)
90
84
  await repository.injectE2ESession({
91
85
  jid,
92
86
  session: {
93
87
  registrationId: registrationId,
94
- identityKey: (0, crypto_1.generateSignalPubKey)(identity),
88
+ identityKey: crypto_1.generateSignalPubKey(identity),
95
89
  signedPreKey: extractKey(signedKey),
96
90
  preKey: extractKey(key)
97
91
  }
98
- });
99
- }));
92
+ })
93
+ }))
100
94
  }
101
- };
95
+ }
102
96
  exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
103
97
  const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
104
- const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
105
- const extracted = [];
98
+ const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
99
+ const extracted = []
106
100
  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;
101
+ const { devices, id } = userResult
102
+ const { user } = WABinary_1.jidDecode(id)
103
+ const deviceList = devices?.deviceList
110
104
  if (Array.isArray(deviceList)) {
111
105
  for (const { id: device, keyIndex } of deviceList) {
112
106
  if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
113
107
  (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
114
108
  (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
115
109
  ) {
116
- extracted.push({ user, device });
110
+ extracted.push({ user, device })
117
111
  }
118
112
  }
119
113
  }
120
114
  }
121
- return extracted;
122
- };
115
+ return extracted
116
+ }
123
117
  exports.extractDeviceJids = extractDeviceJids;
124
118
  /**
125
119
  * get the next N keys for upload or processing
@@ -10,3 +10,4 @@ export declare const useMultiFileAuthState: (folder: string) => Promise<{
10
10
  state: AuthenticationState;
11
11
  saveCreds: () => Promise<void>;
12
12
  }>;
13
+