@vinzsocket/baileys 2.8.30 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/WAProto/fix-imports.js +7 -16
  2. package/WAProto/index.js +1 -37306
  3. package/lib/Defaults/index.js +37 -33
  4. package/lib/Signal/Group/ciphertext-message.js +6 -2
  5. package/lib/Signal/Group/group-session-builder.js +12 -7
  6. package/lib/Signal/Group/group_cipher.js +18 -13
  7. package/lib/Signal/Group/index.js +77 -12
  8. package/lib/Signal/Group/keyhelper.js +15 -8
  9. package/lib/Signal/Group/queue-job.js +7 -2
  10. package/lib/Signal/Group/sender-chain-key.js +11 -6
  11. package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
  12. package/lib/Signal/Group/sender-key-message.js +14 -9
  13. package/lib/Signal/Group/sender-key-name.js +6 -2
  14. package/lib/Signal/Group/sender-key-record.js +13 -9
  15. package/lib/Signal/Group/sender-key-state.js +10 -6
  16. package/lib/Signal/Group/sender-message-key.js +9 -4
  17. package/lib/Signal/libsignal.js +34 -28
  18. package/lib/Signal/lid-mapping.js +24 -19
  19. package/lib/Socket/Client/index.js +25 -3
  20. package/lib/Socket/Client/types.js +8 -4
  21. package/lib/Socket/Client/websocket.js +16 -11
  22. package/lib/Socket/business.js +38 -34
  23. package/lib/Socket/chats.js +100 -95
  24. package/lib/Socket/communities.js +55 -49
  25. package/lib/Socket/groups.js +56 -51
  26. package/lib/Socket/index.js +9 -6
  27. package/lib/Socket/messages-recv.js +150 -145
  28. package/lib/Socket/messages-send.js +109 -104
  29. package/lib/Socket/mex.js +12 -8
  30. package/lib/Socket/newsletter.js +27 -23
  31. package/lib/Socket/socket.js +111 -107
  32. package/lib/Store/index.js +47 -4
  33. package/lib/Store/make-cache-manager-store.js +17 -11
  34. package/lib/Store/make-in-memory-store.js +31 -29
  35. package/lib/Store/make-ordered-dictionary.js +7 -2
  36. package/lib/Store/object-repository.js +7 -2
  37. package/lib/Types/Auth.js +3 -2
  38. package/lib/Types/Bussines.js +3 -2
  39. package/lib/Types/Call.js +3 -2
  40. package/lib/Types/Chat.js +5 -2
  41. package/lib/Types/Contact.js +3 -2
  42. package/lib/Types/Events.js +1 -2
  43. package/lib/Types/GroupMetadata.js +3 -2
  44. package/lib/Types/Label.js +6 -3
  45. package/lib/Types/LabelAssociation.js +6 -3
  46. package/lib/Types/Message.js +16 -7
  47. package/lib/Types/Newsletter.js +8 -5
  48. package/lib/Types/Product.js +3 -2
  49. package/lib/Types/Signal.js +1 -2
  50. package/lib/Types/Socket.js +2 -3
  51. package/lib/Types/State.js +7 -4
  52. package/lib/Types/USync.js +1 -2
  53. package/lib/Types/index.js +153 -15
  54. package/lib/Utils/auth-utils.js +32 -25
  55. package/lib/Utils/baileys-event-stream.js +21 -15
  56. package/lib/Utils/business.js +71 -61
  57. package/lib/Utils/chat-utils.js +91 -77
  58. package/lib/Utils/crypto.js +54 -32
  59. package/lib/Utils/decode-wa-message.js +46 -39
  60. package/lib/Utils/event-buffer.js +24 -19
  61. package/lib/Utils/extended-messages.js +14 -9
  62. package/lib/Utils/generics.js +100 -64
  63. package/lib/Utils/history.js +30 -23
  64. package/lib/Utils/index.js +234 -22
  65. package/lib/Utils/lid-resolver.js +12 -5
  66. package/lib/Utils/link-preview.js +11 -7
  67. package/lib/Utils/logger.js +8 -4
  68. package/lib/Utils/lt-hash.js +8 -5
  69. package/lib/Utils/make-mutex.js +8 -3
  70. package/lib/Utils/mention.js +12 -4
  71. package/lib/Utils/message-retry-manager.js +10 -6
  72. package/lib/Utils/messages-media.js +127 -95
  73. package/lib/Utils/messages.js +122 -98
  74. package/lib/Utils/noise-handler.js +25 -21
  75. package/lib/Utils/process-message.js +72 -63
  76. package/lib/Utils/signal.js +45 -33
  77. package/lib/Utils/use-multi-file-auth-state.js +24 -20
  78. package/lib/Utils/validate-connection.js +54 -47
  79. package/lib/WABinary/constants.js +9 -6
  80. package/lib/WABinary/decode.js +17 -10
  81. package/lib/WABinary/encode.js +11 -6
  82. package/lib/WABinary/generic-utils.js +31 -17
  83. package/lib/WABinary/index.js +58 -6
  84. package/lib/WABinary/jid-utils.js +36 -20
  85. package/lib/WABinary/types.js +2 -2
  86. package/lib/WAM/BinaryInfo.js +6 -2
  87. package/lib/WAM/constants.js +1 -1
  88. package/lib/WAM/encode.js +16 -12
  89. package/lib/WAM/index.js +36 -4
  90. package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
  91. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
  92. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
  93. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
  94. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
  95. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
  96. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
  97. package/lib/WAUSync/Protocols/index.js +58 -6
  98. package/lib/WAUSync/USyncQuery.js +21 -17
  99. package/lib/WAUSync/USyncUser.js +6 -2
  100. package/lib/WAUSync/index.js +36 -4
  101. package/lib/index.js +112 -12
  102. package/package.json +8 -6
@@ -1,14 +1,18 @@
1
- import { Boom } from '@hapi/boom';
2
- import { proto } from '../../WAProto/index.js';
3
- import { NOISE_MODE, WA_CERT_DETAILS } from '../Defaults/index.js';
4
- import { decodeBinaryNode } from '../WABinary/index.js';
5
- import { aesDecryptGCM, aesEncryptGCM, Curve, hkdf, sha256 } from './crypto.js';
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.makeNoiseHandler = void 0;
5
+ var _boom = require("@hapi/boom");
6
+ var _index = require("../../WAProto/index.js");
7
+ var _index2 = require("../Defaults/index.js");
8
+ var _index3 = require("../WABinary/index.js");
9
+ var _crypto = require("./crypto.js");
6
10
  const generateIV = counter => {
7
11
  const iv = new ArrayBuffer(12);
8
12
  new DataView(iv).setUint32(8, counter);
9
13
  return new Uint8Array(iv);
10
14
  };
11
- export const makeNoiseHandler = ({
15
+ const makeNoiseHandler = ({
12
16
  keyPair: {
13
17
  private: privateKey,
14
18
  public: publicKey
@@ -22,11 +26,11 @@ export const makeNoiseHandler = ({
22
26
  });
23
27
  const authenticate = data => {
24
28
  if (!isFinished) {
25
- hash = sha256(Buffer.concat([hash, data]));
29
+ hash = (0, _crypto.sha256)(Buffer.concat([hash, data]));
26
30
  }
27
31
  };
28
32
  const encrypt = plaintext => {
29
- const result = aesEncryptGCM(plaintext, encKey, generateIV(writeCounter), hash);
33
+ const result = (0, _crypto.aesEncryptGCM)(plaintext, encKey, generateIV(writeCounter), hash);
30
34
  writeCounter += 1;
31
35
  authenticate(result);
32
36
  return result;
@@ -35,7 +39,7 @@ export const makeNoiseHandler = ({
35
39
  // before the handshake is finished, we use the same counter
36
40
  // after handshake, the counters are different
37
41
  const iv = generateIV(isFinished ? readCounter : writeCounter);
38
- const result = aesDecryptGCM(ciphertext, decKey, iv, hash);
42
+ const result = (0, _crypto.aesDecryptGCM)(ciphertext, decKey, iv, hash);
39
43
  if (isFinished) {
40
44
  readCounter += 1;
41
45
  } else {
@@ -45,7 +49,7 @@ export const makeNoiseHandler = ({
45
49
  return result;
46
50
  };
47
51
  const localHKDF = async data => {
48
- const key = await hkdf(Buffer.from(data), 64, {
52
+ const key = await (0, _crypto.hkdf)(Buffer.from(data), 64, {
49
53
  salt,
50
54
  info: ''
51
55
  });
@@ -68,8 +72,8 @@ export const makeNoiseHandler = ({
68
72
  writeCounter = 0;
69
73
  isFinished = true;
70
74
  };
71
- const data = Buffer.from(NOISE_MODE);
72
- let hash = data.byteLength === 32 ? data : sha256(data);
75
+ const data = Buffer.from(_index2.NOISE_MODE);
76
+ let hash = data.byteLength === 32 ? data : (0, _crypto.sha256)(data);
73
77
  let salt = hash;
74
78
  let encKey = hash;
75
79
  let decKey = hash;
@@ -90,23 +94,23 @@ export const makeNoiseHandler = ({
90
94
  serverHello
91
95
  }, noiseKey) => {
92
96
  authenticate(serverHello.ephemeral);
93
- await mixIntoKey(Curve.sharedKey(privateKey, serverHello.ephemeral));
97
+ await mixIntoKey(_crypto.Curve.sharedKey(privateKey, serverHello.ephemeral));
94
98
  const decStaticContent = decrypt(serverHello.static);
95
- await mixIntoKey(Curve.sharedKey(privateKey, decStaticContent));
99
+ await mixIntoKey(_crypto.Curve.sharedKey(privateKey, decStaticContent));
96
100
  const certDecoded = decrypt(serverHello.payload);
97
101
  const {
98
102
  intermediate: certIntermediate
99
- } = proto.CertChain.decode(certDecoded);
103
+ } = _index.proto.CertChain.decode(certDecoded);
100
104
  const {
101
105
  issuerSerial
102
- } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
103
- if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {
104
- throw new Boom('certification match failed', {
106
+ } = _index.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
107
+ if (issuerSerial !== _index2.WA_CERT_DETAILS.SERIAL) {
108
+ throw new _boom.Boom('certification match failed', {
105
109
  statusCode: 400
106
110
  });
107
111
  }
108
112
  const keyEnc = encrypt(noiseKey.public);
109
- await mixIntoKey(Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
113
+ await mixIntoKey(_crypto.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
110
114
  return keyEnc;
111
115
  },
112
116
  encodeFrame: data => {
@@ -153,7 +157,7 @@ export const makeNoiseHandler = ({
153
157
  inBytes = inBytes.slice(size + 3);
154
158
  if (isFinished) {
155
159
  const result = decrypt(frame);
156
- frame = await decodeBinaryNode(result);
160
+ frame = await (0, _index3.decodeBinaryNode)(result);
157
161
  }
158
162
  logger.trace({
159
163
  msg: frame?.attrs?.id
@@ -164,4 +168,4 @@ export const makeNoiseHandler = ({
164
168
  }
165
169
  };
166
170
  };
167
- //# sourceMappingURL=noise-handler.js.map
171
+ exports.makeNoiseHandler = makeNoiseHandler;
@@ -1,18 +1,24 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import { WAMessageStubType } from '../Types/index.js';
3
- import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
4
- import { areJidsSameUser, isJidBroadcast, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary/index.js';
5
- import { aesDecryptGCM, hmacSign } from './crypto.js';
6
- import { toNumber } from './generics.js';
7
- import { downloadAndProcessHistorySyncNotification } from './history.js';
8
- const REAL_MSG_STUB_TYPES = new Set([WAMessageStubType.CALL_MISSED_GROUP_VIDEO, WAMessageStubType.CALL_MISSED_GROUP_VOICE, WAMessageStubType.CALL_MISSED_VIDEO, WAMessageStubType.CALL_MISSED_VOICE]);
9
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.cleanMessage = void 0;
5
+ exports.decryptPollVote = decryptPollVote;
6
+ exports.shouldIncrementChatUnread = exports.isRealMessage = exports.getChatId = exports.default = void 0;
7
+ var _index = require("../../WAProto/index.js");
8
+ var _index2 = require("../Types/index.js");
9
+ var _messages = require("../Utils/messages.js");
10
+ var _index3 = require("../WABinary/index.js");
11
+ var _crypto = require("./crypto.js");
12
+ var _generics = require("./generics.js");
13
+ var _history = require("./history.js");
14
+ const REAL_MSG_STUB_TYPES = new Set([_index2.WAMessageStubType.CALL_MISSED_GROUP_VIDEO, _index2.WAMessageStubType.CALL_MISSED_GROUP_VOICE, _index2.WAMessageStubType.CALL_MISSED_VIDEO, _index2.WAMessageStubType.CALL_MISSED_VOICE]);
15
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([_index2.WAMessageStubType.GROUP_PARTICIPANT_ADD]);
10
16
  /** Cleans a received message to further processing */
11
- export const cleanMessage = (message, meId) => {
17
+ const cleanMessage = (message, meId) => {
12
18
  // ensure remoteJid and participant doesn't have device or agent in it
13
- message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
14
- message.key.participant = message.key.participant ? jidNormalizedUser(message.key.participant) : undefined;
15
- const content = normalizeMessageContent(message.message);
19
+ message.key.remoteJid = (0, _index3.jidNormalizedUser)(message.key.remoteJid);
20
+ message.key.participant = message.key.participant ? (0, _index3.jidNormalizedUser)(message.key.participant) : undefined;
21
+ const content = (0, _messages.normalizeMessageContent)(message.message);
16
22
  // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
17
23
  if (content?.reactionMessage) {
18
24
  normaliseKey(content.reactionMessage.key);
@@ -26,7 +32,7 @@ export const cleanMessage = (message, meId) => {
26
32
  if (!message.key.fromMe) {
27
33
  // if the sender believed the message being reacted to is not from them
28
34
  // we've to correct the key to be from them, or some other participant
29
- msgKey.fromMe = !msgKey.fromMe ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) :
35
+ msgKey.fromMe = !msgKey.fromMe ? (0, _index3.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId) :
30
36
  // if the message being reacted to, was from them
31
37
  // fromMe automatically becomes false
32
38
  false;
@@ -37,22 +43,25 @@ export const cleanMessage = (message, meId) => {
37
43
  }
38
44
  }
39
45
  };
40
- export const isRealMessage = (message, meId) => {
41
- const normalizedContent = normalizeMessageContent(message.message);
42
- const hasSomeContent = !!getContentType(normalizedContent);
43
- return (!!normalizedContent || REAL_MSG_STUB_TYPES.has(message.messageStubType) || REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType) && message.messageStubParameters?.some(p => areJidsSameUser(meId, p))) && hasSomeContent && !normalizedContent?.protocolMessage && !normalizedContent?.reactionMessage && !normalizedContent?.pollUpdateMessage;
46
+ exports.cleanMessage = cleanMessage;
47
+ const isRealMessage = (message, meId) => {
48
+ const normalizedContent = (0, _messages.normalizeMessageContent)(message.message);
49
+ const hasSomeContent = !!(0, _messages.getContentType)(normalizedContent);
50
+ return (!!normalizedContent || REAL_MSG_STUB_TYPES.has(message.messageStubType) || REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType) && message.messageStubParameters?.some(p => (0, _index3.areJidsSameUser)(meId, p))) && hasSomeContent && !normalizedContent?.protocolMessage && !normalizedContent?.reactionMessage && !normalizedContent?.pollUpdateMessage;
44
51
  };
45
- export const shouldIncrementChatUnread = message => !message.key.fromMe && !message.messageStubType;
52
+ exports.isRealMessage = isRealMessage;
53
+ const shouldIncrementChatUnread = message => !message.key.fromMe && !message.messageStubType;
46
54
  /**
47
55
  * Get the ID of the chat from the given key.
48
56
  * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
49
57
  */
50
- export const getChatId = ({
58
+ exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
59
+ const getChatId = ({
51
60
  remoteJid,
52
61
  participant,
53
62
  fromMe
54
63
  }) => {
55
- if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
64
+ if ((0, _index3.isJidBroadcast)(remoteJid) && !(0, _index3.isJidStatusBroadcast)(remoteJid) && !fromMe) {
56
65
  return participant;
57
66
  }
58
67
  return remoteJid;
@@ -63,7 +72,8 @@ export const getChatId = ({
63
72
  * @param ctx additional info about the poll required for decryption
64
73
  * @returns list of SHA256 options
65
74
  */
66
- export function decryptPollVote({
75
+ exports.getChatId = getChatId;
76
+ function decryptPollVote({
67
77
  encPayload,
68
78
  encIv
69
79
  }, {
@@ -73,11 +83,11 @@ export function decryptPollVote({
73
83
  voterJid
74
84
  }) {
75
85
  const sign = Buffer.concat([toBinary(pollMsgId), toBinary(pollCreatorJid), toBinary(voterJid), toBinary('Poll Vote'), new Uint8Array([1])]);
76
- const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
77
- const decKey = hmacSign(sign, key0, 'sha256');
86
+ const key0 = (0, _crypto.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
87
+ const decKey = (0, _crypto.hmacSign)(sign, key0, 'sha256');
78
88
  const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
79
- const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
80
- return proto.Message.PollVoteMessage.decode(decrypted);
89
+ const decrypted = (0, _crypto.aesDecryptGCM)(encPayload, decKey, encIv, aad);
90
+ return _index.proto.Message.PollVoteMessage.decode(decrypted);
81
91
  function toBinary(txt) {
82
92
  return Buffer.from(txt);
83
93
  }
@@ -97,20 +107,20 @@ const processMessage = async (message, {
97
107
  accountSettings
98
108
  } = creds;
99
109
  const chat = {
100
- id: jidNormalizedUser(getChatId(message.key))
110
+ id: (0, _index3.jidNormalizedUser)(getChatId(message.key))
101
111
  };
102
112
  const isRealMsg = isRealMessage(message, meId);
103
113
  if (isRealMsg) {
104
114
  chat.messages = [{
105
115
  message
106
116
  }];
107
- chat.conversationTimestamp = toNumber(message.messageTimestamp);
117
+ chat.conversationTimestamp = (0, _generics.toNumber)(message.messageTimestamp);
108
118
  // only increment unread count if not CIPHERTEXT and from another person
109
119
  if (shouldIncrementChatUnread(message)) {
110
120
  chat.unreadCount = (chat.unreadCount || 0) + 1;
111
121
  }
112
122
  }
113
- const content = normalizeMessageContent(message.message);
123
+ const content = (0, _messages.normalizeMessageContent)(message.message);
114
124
  // unarchive chat if it's a real message, or someone reacted to our message
115
125
  // and we've the unarchive chats setting on
116
126
  if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
@@ -120,7 +130,7 @@ const processMessage = async (message, {
120
130
  const protocolMsg = content?.protocolMessage;
121
131
  if (protocolMsg) {
122
132
  switch (protocolMsg.type) {
123
- case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
133
+ case _index.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
124
134
  const histNotification = protocolMsg.historySyncNotification;
125
135
  const process = shouldProcessHistoryMsg;
126
136
  const isLatest = !creds.processedHistoryMessages?.length;
@@ -131,7 +141,7 @@ const processMessage = async (message, {
131
141
  isLatest
132
142
  }, 'got history notification');
133
143
  if (process) {
134
- if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
144
+ if (histNotification.syncType !== _index.proto.HistorySync.HistorySyncType.ON_DEMAND) {
135
145
  ev.emit('creds.update', {
136
146
  processedHistoryMessages: [...(creds.processedHistoryMessages || []), {
137
147
  key: message.key,
@@ -139,15 +149,15 @@ const processMessage = async (message, {
139
149
  }]
140
150
  });
141
151
  }
142
- const data = await downloadAndProcessHistorySyncNotification(histNotification, options);
152
+ const data = await (0, _history.downloadAndProcessHistorySyncNotification)(histNotification, options);
143
153
  ev.emit('messaging-history.set', {
144
154
  ...data,
145
- isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
155
+ isLatest: histNotification.syncType !== _index.proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
146
156
  peerDataRequestSessionId: histNotification.peerDataRequestSessionId
147
157
  });
148
158
  }
149
159
  break;
150
- case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
160
+ case _index.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
151
161
  const keys = protocolMsg.appStateSyncKeyShare.keys;
152
162
  if (keys?.length) {
153
163
  let newAppStateSyncKeyId = '';
@@ -180,7 +190,7 @@ const processMessage = async (message, {
180
190
  }, 'recv app state sync with 0 keys');
181
191
  }
182
192
  break;
183
- case proto.Message.ProtocolMessage.Type.REVOKE:
193
+ case _index.proto.Message.ProtocolMessage.Type.REVOKE:
184
194
  ev.emit('messages.update', [{
185
195
  key: {
186
196
  ...message.key,
@@ -188,18 +198,18 @@ const processMessage = async (message, {
188
198
  },
189
199
  update: {
190
200
  message: null,
191
- messageStubType: WAMessageStubType.REVOKE,
201
+ messageStubType: _index2.WAMessageStubType.REVOKE,
192
202
  key: message.key
193
203
  }
194
204
  }]);
195
205
  break;
196
- case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
206
+ case _index.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
197
207
  Object.assign(chat, {
198
- ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
208
+ ephemeralSettingTimestamp: (0, _generics.toNumber)(message.messageTimestamp),
199
209
  ephemeralExpiration: protocolMsg.ephemeralExpiration || null
200
210
  });
201
211
  break;
202
- case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
212
+ case _index.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
203
213
  const response = protocolMsg.peerDataOperationRequestResponseMessage;
204
214
  if (response) {
205
215
  placeholderResendCache?.del(response.stanzaId);
@@ -213,7 +223,7 @@ const processMessage = async (message, {
213
223
  } = result;
214
224
  //eslint-disable-next-line max-depth
215
225
  if (retryResponse) {
216
- const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
226
+ const webMessageInfo = _index.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
217
227
  // wait till another upsert event is available, don't want it to be part of the PDO response message
218
228
  setTimeout(() => {
219
229
  ev.emit('messages.upsert', {
@@ -226,7 +236,7 @@ const processMessage = async (message, {
226
236
  }
227
237
  }
228
238
  break;
229
- case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
239
+ case _index.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
230
240
  ev.emit('messages.update', [{
231
241
  // flip the sender / fromMe properties because they're in the perspective of the sender
232
242
  key: {
@@ -239,17 +249,17 @@ const processMessage = async (message, {
239
249
  message: protocolMsg.editedMessage
240
250
  }
241
251
  },
242
- messageTimestamp: protocolMsg.timestampMs ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000) : message.messageTimestamp
252
+ messageTimestamp: protocolMsg.timestampMs ? Math.floor((0, _generics.toNumber)(protocolMsg.timestampMs) / 1000) : message.messageTimestamp
243
253
  }
244
254
  }]);
245
255
  break;
246
- case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
256
+ case _index.proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
247
257
  const lidMappingStore = signalRepository.getLIDMappingStore();
248
258
  const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
249
259
  const {
250
260
  pnToLidMappings,
251
261
  chatDbMigrationTimestamp
252
- } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
262
+ } = _index.proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
253
263
  logger?.debug({
254
264
  pnToLidMappings,
255
265
  chatDbMigrationTimestamp
@@ -303,14 +313,14 @@ const processMessage = async (message, {
303
313
  method: method
304
314
  });
305
315
  };
306
- const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid));
316
+ const participantsIncludesMe = () => participants.find(jid => (0, _index3.areJidsSameUser)(meId, jid));
307
317
  switch (message.messageStubType) {
308
- case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
318
+ case _index2.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
309
319
  participants = message.messageStubParameters || [];
310
320
  emitParticipantsUpdate('modify');
311
321
  break;
312
- case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
313
- case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
322
+ case _index2.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
323
+ case _index2.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
314
324
  participants = message.messageStubParameters || [];
315
325
  emitParticipantsUpdate('remove');
316
326
  // mark the chat read only if you left the group
@@ -318,68 +328,68 @@ const processMessage = async (message, {
318
328
  chat.readOnly = true;
319
329
  }
320
330
  break;
321
- case WAMessageStubType.GROUP_PARTICIPANT_ADD:
322
- case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
323
- case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
331
+ case _index2.WAMessageStubType.GROUP_PARTICIPANT_ADD:
332
+ case _index2.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
333
+ case _index2.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
324
334
  participants = message.messageStubParameters || [];
325
335
  if (participantsIncludesMe()) {
326
336
  chat.readOnly = false;
327
337
  }
328
338
  emitParticipantsUpdate('add');
329
339
  break;
330
- case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
340
+ case _index2.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
331
341
  participants = message.messageStubParameters || [];
332
342
  emitParticipantsUpdate('demote');
333
343
  break;
334
- case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
344
+ case _index2.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
335
345
  participants = message.messageStubParameters || [];
336
346
  emitParticipantsUpdate('promote');
337
347
  break;
338
- case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
348
+ case _index2.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
339
349
  const announceValue = message.messageStubParameters?.[0];
340
350
  emitGroupUpdate({
341
351
  announce: announceValue === 'true' || announceValue === 'on'
342
352
  });
343
353
  break;
344
- case WAMessageStubType.GROUP_CHANGE_RESTRICT:
354
+ case _index2.WAMessageStubType.GROUP_CHANGE_RESTRICT:
345
355
  const restrictValue = message.messageStubParameters?.[0];
346
356
  emitGroupUpdate({
347
357
  restrict: restrictValue === 'true' || restrictValue === 'on'
348
358
  });
349
359
  break;
350
- case WAMessageStubType.GROUP_CHANGE_SUBJECT:
360
+ case _index2.WAMessageStubType.GROUP_CHANGE_SUBJECT:
351
361
  const name = message.messageStubParameters?.[0];
352
362
  chat.name = name;
353
363
  emitGroupUpdate({
354
364
  subject: name
355
365
  });
356
366
  break;
357
- case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
367
+ case _index2.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
358
368
  const description = message.messageStubParameters?.[0];
359
369
  chat.description = description;
360
370
  emitGroupUpdate({
361
371
  desc: description
362
372
  });
363
373
  break;
364
- case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
374
+ case _index2.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
365
375
  const code = message.messageStubParameters?.[0];
366
376
  emitGroupUpdate({
367
377
  inviteCode: code
368
378
  });
369
379
  break;
370
- case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
380
+ case _index2.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
371
381
  const memberAddValue = message.messageStubParameters?.[0];
372
382
  emitGroupUpdate({
373
383
  memberAddMode: memberAddValue === 'all_member_add'
374
384
  });
375
385
  break;
376
- case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
386
+ case _index2.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
377
387
  const approvalMode = message.messageStubParameters?.[0];
378
388
  emitGroupUpdate({
379
389
  joinApprovalMode: approvalMode === 'on'
380
390
  });
381
391
  break;
382
- case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
392
+ case _index2.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
383
393
  const participant = message.messageStubParameters?.[0];
384
394
  const action = message.messageStubParameters?.[1];
385
395
  const method = message.messageStubParameters?.[2];
@@ -438,5 +448,4 @@ const processMessage = async (message, {
438
448
  ev.emit('chats.update', [chat]);
439
449
  }
440
450
  };
441
- export default processMessage;
442
- //# sourceMappingURL=process-message.js.map
451
+ var _default = exports.default = processMessage;
@@ -1,7 +1,11 @@
1
- import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
2
- import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, jidDecode, S_WHATSAPP_NET } from '../WABinary/index.js';
3
- import { Curve, generateSignalPubKey } from './crypto.js';
4
- import { encodeBigEndian } from './generics.js';
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.xmppSignedPreKey = exports.xmppPreKey = exports.parseAndInjectE2ESessions = exports.getPreKeys = exports.getNextPreKeysNode = exports.getNextPreKeys = exports.generateOrGetPreKeys = exports.extractDeviceJids = exports.createSignalIdentity = void 0;
5
+ var _index = require("../Defaults/index.js");
6
+ var _index2 = require("../WABinary/index.js");
7
+ var _crypto = require("./crypto.js");
8
+ var _generics = require("./generics.js");
5
9
  function chunk(array, size) {
6
10
  const chunks = [];
7
11
  for (let i = 0; i < array.length; i += size) {
@@ -9,16 +13,17 @@ function chunk(array, size) {
9
13
  }
10
14
  return chunks;
11
15
  }
12
- export const createSignalIdentity = (wid, accountSignatureKey) => {
16
+ const createSignalIdentity = (wid, accountSignatureKey) => {
13
17
  return {
14
18
  identifier: {
15
19
  name: wid,
16
20
  deviceId: 0
17
21
  },
18
- identifierKey: generateSignalPubKey(accountSignatureKey)
22
+ identifierKey: (0, _crypto.generateSignalPubKey)(accountSignatureKey)
19
23
  };
20
24
  };
21
- export const getPreKeys = async ({
25
+ exports.createSignalIdentity = createSignalIdentity;
26
+ const getPreKeys = async ({
22
27
  get
23
28
  }, min, limit) => {
24
29
  const idList = [];
@@ -27,14 +32,15 @@ export const getPreKeys = async ({
27
32
  }
28
33
  return get('pre-key', idList);
29
34
  };
30
- export const generateOrGetPreKeys = (creds, range) => {
35
+ exports.getPreKeys = getPreKeys;
36
+ const generateOrGetPreKeys = (creds, range) => {
31
37
  const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
32
38
  const remaining = range - avaliable;
33
39
  const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
34
40
  const newPreKeys = {};
35
41
  if (remaining > 0) {
36
42
  for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
37
- newPreKeys[i] = Curve.generateKeyPair();
43
+ newPreKeys[i] = _crypto.Curve.generateKeyPair();
38
44
  }
39
45
  }
40
46
  return {
@@ -43,13 +49,14 @@ export const generateOrGetPreKeys = (creds, range) => {
43
49
  preKeysRange: [creds.firstUnuploadedPreKeyId, range]
44
50
  };
45
51
  };
46
- export const xmppSignedPreKey = key => ({
52
+ exports.generateOrGetPreKeys = generateOrGetPreKeys;
53
+ const xmppSignedPreKey = key => ({
47
54
  tag: 'skey',
48
55
  attrs: {},
49
56
  content: [{
50
57
  tag: 'id',
51
58
  attrs: {},
52
- content: encodeBigEndian(key.keyId, 3)
59
+ content: (0, _generics.encodeBigEndian)(key.keyId, 3)
53
60
  }, {
54
61
  tag: 'value',
55
62
  attrs: {},
@@ -60,28 +67,30 @@ export const xmppSignedPreKey = key => ({
60
67
  content: key.signature
61
68
  }]
62
69
  });
63
- export const xmppPreKey = (pair, id) => ({
70
+ exports.xmppSignedPreKey = xmppSignedPreKey;
71
+ const xmppPreKey = (pair, id) => ({
64
72
  tag: 'key',
65
73
  attrs: {},
66
74
  content: [{
67
75
  tag: 'id',
68
76
  attrs: {},
69
- content: encodeBigEndian(id, 3)
77
+ content: (0, _generics.encodeBigEndian)(id, 3)
70
78
  }, {
71
79
  tag: 'value',
72
80
  attrs: {},
73
81
  content: pair.public
74
82
  }]
75
83
  });
76
- export const parseAndInjectE2ESessions = async (node, repository) => {
84
+ exports.xmppPreKey = xmppPreKey;
85
+ const parseAndInjectE2ESessions = async (node, repository) => {
77
86
  const extractKey = key => key ? {
78
- keyId: getBinaryNodeChildUInt(key, 'id', 3),
79
- publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
80
- signature: getBinaryNodeChildBuffer(key, 'signature')
87
+ keyId: (0, _index2.getBinaryNodeChildUInt)(key, 'id', 3),
88
+ publicKey: (0, _crypto.generateSignalPubKey)((0, _index2.getBinaryNodeChildBuffer)(key, 'value')),
89
+ signature: (0, _index2.getBinaryNodeChildBuffer)(key, 'signature')
81
90
  } : undefined;
82
- const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
91
+ const nodes = (0, _index2.getBinaryNodeChildren)((0, _index2.getBinaryNodeChild)(node, 'list'), 'user');
83
92
  for (const node of nodes) {
84
- assertNodeErrorFree(node);
93
+ (0, _index2.assertNodeErrorFree)(node);
85
94
  }
86
95
  // Most of the work in repository.injectE2ESession is CPU intensive, not IO
87
96
  // So Promise.all doesn't really help here,
@@ -92,16 +101,16 @@ export const parseAndInjectE2ESessions = async (node, repository) => {
92
101
  const chunks = chunk(nodes, chunkSize);
93
102
  for (const nodesChunk of chunks) {
94
103
  await Promise.all(nodesChunk.map(async node => {
95
- const signedKey = getBinaryNodeChild(node, 'skey');
96
- const key = getBinaryNodeChild(node, 'key');
97
- const identity = getBinaryNodeChildBuffer(node, 'identity');
104
+ const signedKey = (0, _index2.getBinaryNodeChild)(node, 'skey');
105
+ const key = (0, _index2.getBinaryNodeChild)(node, 'key');
106
+ const identity = (0, _index2.getBinaryNodeChildBuffer)(node, 'identity');
98
107
  const jid = node.attrs.jid;
99
- const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
108
+ const registrationId = (0, _index2.getBinaryNodeChildUInt)(node, 'registration', 4);
100
109
  await repository.injectE2ESession({
101
110
  jid,
102
111
  session: {
103
112
  registrationId: registrationId,
104
- identityKey: generateSignalPubKey(identity),
113
+ identityKey: (0, _crypto.generateSignalPubKey)(identity),
105
114
  signedPreKey: extractKey(signedKey),
106
115
  preKey: extractKey(key)
107
116
  }
@@ -109,11 +118,12 @@ export const parseAndInjectE2ESessions = async (node, repository) => {
109
118
  }));
110
119
  }
111
120
  };
112
- export const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
121
+ exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
122
+ const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
113
123
  const {
114
124
  user: myUser,
115
125
  device: myDevice
116
- } = jidDecode(myJid);
126
+ } = (0, _index2.jidDecode)(myJid);
117
127
  const extracted = [];
118
128
  for (const userResult of result) {
119
129
  const {
@@ -122,7 +132,7 @@ export const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
122
132
  } = userResult;
123
133
  const {
124
134
  user
125
- } = jidDecode(id);
135
+ } = (0, _index2.jidDecode)(id);
126
136
  const deviceList = devices?.deviceList;
127
137
  if (Array.isArray(deviceList)) {
128
138
  for (const {
@@ -149,7 +159,8 @@ export const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
149
159
  * get the next N keys for upload or processing
150
160
  * @param count number of pre-keys to get or generate
151
161
  */
152
- export const getNextPreKeys = async ({
162
+ exports.extractDeviceJids = extractDeviceJids;
163
+ const getNextPreKeys = async ({
153
164
  creds,
154
165
  keys
155
166
  }, count) => {
@@ -171,7 +182,8 @@ export const getNextPreKeys = async ({
171
182
  preKeys
172
183
  };
173
184
  };
174
- export const getNextPreKeysNode = async (state, count) => {
185
+ exports.getNextPreKeys = getNextPreKeys;
186
+ const getNextPreKeysNode = async (state, count) => {
175
187
  const {
176
188
  creds
177
189
  } = state;
@@ -184,16 +196,16 @@ export const getNextPreKeysNode = async (state, count) => {
184
196
  attrs: {
185
197
  xmlns: 'encrypt',
186
198
  type: 'set',
187
- to: S_WHATSAPP_NET
199
+ to: _index2.S_WHATSAPP_NET
188
200
  },
189
201
  content: [{
190
202
  tag: 'registration',
191
203
  attrs: {},
192
- content: encodeBigEndian(creds.registrationId)
204
+ content: (0, _generics.encodeBigEndian)(creds.registrationId)
193
205
  }, {
194
206
  tag: 'type',
195
207
  attrs: {},
196
- content: KEY_BUNDLE_TYPE
208
+ content: _index.KEY_BUNDLE_TYPE
197
209
  }, {
198
210
  tag: 'identity',
199
211
  attrs: {},
@@ -209,4 +221,4 @@ export const getNextPreKeysNode = async (state, count) => {
209
221
  node
210
222
  };
211
223
  };
212
- //# sourceMappingURL=signal.js.map
224
+ exports.getNextPreKeysNode = getNextPreKeysNode;