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.
Files changed (131) hide show
  1. package/README.md +1880 -36
  2. package/WAProto/index.d.ts +50383 -0
  3. package/WAProto/index.js +37203 -11791
  4. package/WASignalGroup/GroupProtocol.js +1697 -0
  5. package/WASignalGroup/ciphertext_message.js +16 -0
  6. package/WASignalGroup/group_cipher.js +120 -0
  7. package/WASignalGroup/group_session_builder.js +46 -0
  8. package/WASignalGroup/index.js +5 -0
  9. package/WASignalGroup/keyhelper.js +21 -0
  10. package/WASignalGroup/protobufs.js +3 -0
  11. package/WASignalGroup/queue_job.js +69 -0
  12. package/WASignalGroup/sender_chain_key.js +50 -0
  13. package/WASignalGroup/sender_key_distribution_message.js +78 -0
  14. package/WASignalGroup/sender_key_message.js +92 -0
  15. package/WASignalGroup/sender_key_name.js +70 -0
  16. package/WASignalGroup/sender_key_record.js +56 -0
  17. package/WASignalGroup/sender_key_state.js +129 -0
  18. package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -6
  19. package/lib/Defaults/baileys-version.json +1 -1
  20. package/lib/Defaults/index.js +79 -101
  21. package/lib/Signal/libsignal.js +29 -51
  22. package/lib/Socket/Client/web-socket-client.js +0 -2
  23. package/lib/Socket/business.d.ts +42 -43
  24. package/lib/Socket/chats.d.ts +9 -8
  25. package/lib/Socket/chats.js +107 -21
  26. package/lib/Socket/groups.d.ts +7 -7
  27. package/lib/Socket/groups.js +24 -25
  28. package/lib/Socket/index.d.ts +51 -52
  29. package/lib/Socket/messages-recv.d.ts +34 -37
  30. package/lib/Socket/messages-recv.js +37 -175
  31. package/lib/Socket/messages-send.d.ts +16 -10
  32. package/lib/Socket/messages-send.js +540 -346
  33. package/lib/Socket/newsletter.d.ts +26 -28
  34. package/lib/Socket/newsletter.js +4 -4
  35. package/lib/Socket/registration.d.ts +49 -52
  36. package/lib/Socket/registration.js +7 -7
  37. package/lib/Socket/socket.d.ts +1 -0
  38. package/lib/Socket/socket.js +36 -23
  39. package/lib/Socket/usync.d.ts +11 -10
  40. package/lib/Store/make-cache-manager-store.d.ts +2 -1
  41. package/lib/Store/make-in-memory-store.d.ts +2 -2
  42. package/lib/Store/make-in-memory-store.js +5 -1
  43. package/lib/Store/make-ordered-dictionary.js +2 -2
  44. package/lib/Types/Auth.d.ts +0 -1
  45. package/lib/Types/Call.d.ts +1 -1
  46. package/lib/Types/Chat.d.ts +12 -7
  47. package/lib/Types/Events.d.ts +17 -2
  48. package/lib/Types/GroupMetadata.d.ts +3 -2
  49. package/lib/Types/Label.d.ts +11 -0
  50. package/lib/Types/Label.js +1 -1
  51. package/lib/Types/LabelAssociation.js +1 -1
  52. package/lib/Types/Message.d.ts +170 -10
  53. package/lib/Types/Newsletter.js +3 -3
  54. package/lib/Types/Socket.d.ts +7 -2
  55. package/lib/Types/index.d.ts +9 -0
  56. package/lib/Types/index.js +1 -1
  57. package/lib/Utils/auth-utils.js +35 -14
  58. package/lib/Utils/business.d.ts +1 -1
  59. package/lib/Utils/business.js +2 -2
  60. package/lib/Utils/chat-utils.d.ts +11 -12
  61. package/lib/Utils/chat-utils.js +52 -36
  62. package/lib/Utils/crypto.d.ts +15 -16
  63. package/lib/Utils/crypto.js +74 -26
  64. package/lib/Utils/decode-wa-message.d.ts +17 -0
  65. package/lib/Utils/decode-wa-message.js +53 -17
  66. package/lib/Utils/event-buffer.js +10 -7
  67. package/lib/Utils/generics.d.ts +13 -17
  68. package/lib/Utils/generics.js +26 -15
  69. package/lib/Utils/history.d.ts +6 -2
  70. package/lib/Utils/history.js +4 -6
  71. package/lib/Utils/logger.d.ts +1 -3
  72. package/lib/Utils/lt-hash.js +12 -12
  73. package/lib/Utils/make-mutex.d.ts +2 -2
  74. package/lib/Utils/messages-media.d.ts +25 -28
  75. package/lib/Utils/messages-media.js +47 -57
  76. package/lib/Utils/messages.js +461 -44
  77. package/lib/Utils/noise-handler.d.ts +4 -5
  78. package/lib/Utils/noise-handler.js +19 -14
  79. package/lib/Utils/process-message.d.ts +5 -5
  80. package/lib/Utils/process-message.js +75 -23
  81. package/lib/Utils/signal.d.ts +2 -1
  82. package/lib/Utils/signal.js +43 -35
  83. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -1
  84. package/lib/Utils/use-multi-file-auth-state.js +251 -36
  85. package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
  86. package/lib/Utils/use-single-file-auth-state.js +75 -0
  87. package/lib/Utils/validate-connection.d.ts +1 -1
  88. package/lib/Utils/validate-connection.js +1 -1
  89. package/lib/WABinary/decode.d.ts +1 -2
  90. package/lib/WABinary/decode.js +23 -11
  91. package/lib/WABinary/encode.d.ts +1 -2
  92. package/lib/WABinary/encode.js +46 -22
  93. package/lib/WABinary/generic-utils.d.ts +2 -4
  94. package/lib/WABinary/generic-utils.js +2 -10
  95. package/lib/WABinary/jid-utils.d.ts +1 -1
  96. package/lib/WAM/BinaryInfo.d.ts +2 -11
  97. package/lib/WAM/encode.d.ts +1 -2
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  99. package/lib/WAUSync/USyncUser.d.ts +0 -2
  100. package/lib/index.js +0 -6
  101. package/package.json +96 -104
  102. package/engine-requirements.js +0 -10
  103. package/lib/Defaults/phonenumber-mcc.json +0 -223
  104. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  105. package/lib/Signal/Group/ciphertext-message.js +0 -15
  106. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  107. package/lib/Signal/Group/group-session-builder.js +0 -64
  108. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  109. package/lib/Signal/Group/group_cipher.js +0 -96
  110. package/lib/Signal/Group/index.d.ts +0 -11
  111. package/lib/Signal/Group/index.js +0 -57
  112. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  113. package/lib/Signal/Group/keyhelper.js +0 -55
  114. package/lib/Signal/Group/queue-job.d.ts +0 -1
  115. package/lib/Signal/Group/queue-job.js +0 -57
  116. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  117. package/lib/Signal/Group/sender-chain-key.js +0 -34
  118. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  119. package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
  120. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  121. package/lib/Signal/Group/sender-key-message.js +0 -69
  122. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  123. package/lib/Signal/Group/sender-key-name.js +0 -51
  124. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  125. package/lib/Signal/Group/sender-key-record.js +0 -53
  126. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  127. package/lib/Signal/Group/sender-key-state.js +0 -99
  128. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  129. package/lib/Socket/dugong.d.ts +0 -175
  130. package/lib/Socket/dugong.js +0 -342
  131. package/lib/index.d.ts +0 -12
@@ -1,11 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decryptMessageNode = exports.decodeMessageNode = void 0;
3
+ exports.decryptMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
4
+ exports.decodeMessageNode = decodeMessageNode;
4
5
  const boom_1 = require("@hapi/boom");
5
6
  const WAProto_1 = require("../../WAProto");
6
7
  const WABinary_1 = require("../WABinary");
7
8
  const generics_1 = require("./generics");
8
- const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
9
+ exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
10
+ exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
11
+ exports.NACK_REASONS = {
12
+ ParsingError: 487,
13
+ UnrecognizedStanza: 488,
14
+ UnrecognizedStanzaClass: 489,
15
+ UnrecognizedStanzaType: 490,
16
+ InvalidProtobuf: 491,
17
+ InvalidHostedCompanionStanza: 493,
18
+ MissingMessageSecret: 495,
19
+ SignalErrorOldCounter: 496,
20
+ MessageDeletedOnPeer: 499,
21
+ UnhandledError: 500,
22
+ UnsupportedAdminRevoke: 550,
23
+ UnsupportedLIDGroup: 551,
24
+ DBOperationFailed: 552
25
+ };
9
26
  /**
10
27
  * Decode the received node as a message.
11
28
  * @note this will only parse the message, not decrypt it
@@ -77,13 +94,21 @@ function decodeMessageNode(stanza, meId, meLid) {
77
94
  else {
78
95
  throw new boom_1.Boom('Unknown message type', { data: stanza });
79
96
  }
80
- const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
97
+ const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(participant || from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
81
98
  const pushname = stanza.attrs.notify;
82
99
  const key = {
83
100
  remoteJid: chatId,
84
101
  fromMe,
85
102
  id: msgId,
86
- participant
103
+ ...(stanza.attrs.participant_pn ?? participant) !== undefined && {
104
+ participant: fromMe ? meId : stanza.attrs.participant_pn ?? participant
105
+ },
106
+ ...(stanza.attrs.participant_pn ?? participant) !== undefined && {
107
+ participant_pn: fromMe ? meId : stanza.attrs.participant_pn ?? participant
108
+ },
109
+ ...(stanza.attrs.participant_lid ?? participant) !== undefined && {
110
+ participant_lid: fromMe ? meLid : stanza.attrs.participant_lid ?? participant
111
+ }
87
112
  };
88
113
  const fullMessage = {
89
114
  key,
@@ -103,7 +128,6 @@ function decodeMessageNode(stanza, meId, meLid) {
103
128
  sender: msgType === 'chat' ? author : chatId
104
129
  };
105
130
  }
106
- exports.decodeMessageNode = decodeMessageNode;
107
131
  const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
108
132
  const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
109
133
  return {
@@ -113,8 +137,11 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
113
137
  async decrypt() {
114
138
  var _a;
115
139
  let decryptables = 0;
116
- async function processSenderKeyDistribution(msg) {
140
+ if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
141
+ const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
142
+ const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
117
143
  if (msg.senderKeyDistributionMessage) {
144
+ //eslint-disable-next-line max-depth
118
145
  try {
119
146
  await repository.processSenderKeyDistributionMessage({
120
147
  authorJid: author,
@@ -122,14 +149,9 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
122
149
  });
123
150
  }
124
151
  catch (err) {
125
- logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
152
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
126
153
  }
127
154
  }
128
- }
129
- if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
130
- const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
131
- const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
132
- await processSenderKeyDistribution(msg);
133
155
  fullMessage.message = msg;
134
156
  decryptables += 1;
135
157
  }
@@ -140,7 +162,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
140
162
  const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
141
163
  fullMessage.verifiedBizName = details.verifiedName;
142
164
  }
143
- if (tag !== 'enc') {
165
+ if (tag !== 'enc' && tag !== 'plaintext') {
144
166
  continue;
145
167
  }
146
168
  if (!(content instanceof Uint8Array)) {
@@ -149,7 +171,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
149
171
  decryptables += 1;
150
172
  let msgBuffer;
151
173
  try {
152
- const e2eType = attrs.type;
174
+ const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
153
175
  switch (e2eType) {
154
176
  case 'skmsg':
155
177
  msgBuffer = await repository.decryptGroupMessage({
@@ -167,12 +189,26 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
167
189
  ciphertext: content
168
190
  });
169
191
  break;
192
+ case 'plaintext':
193
+ msgBuffer = content;
194
+ break;
170
195
  default:
171
196
  throw new Error(`Unknown e2e type: ${e2eType}`);
172
197
  }
173
- let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
198
+ let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
174
199
  msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
175
- await processSenderKeyDistribution(msg);
200
+ if (msg.senderKeyDistributionMessage) {
201
+ //eslint-disable-next-line max-depth
202
+ try {
203
+ await repository.processSenderKeyDistributionMessage({
204
+ authorJid: author,
205
+ item: msg.senderKeyDistributionMessage
206
+ });
207
+ }
208
+ catch (err) {
209
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
210
+ }
211
+ }
176
212
  if (fullMessage.message) {
177
213
  Object.assign(fullMessage.message, msg);
178
214
  }
@@ -190,7 +226,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
190
226
  // if nothing was found to decrypt
191
227
  if (!decryptables) {
192
228
  fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
193
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
229
+ fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
194
230
  }
195
231
  }
196
232
  };
@@ -176,6 +176,9 @@ function append(data, historyCache, event, eventData, logger) {
176
176
  }
177
177
  }
178
178
  data.historySets.empty = false;
179
+ data.historySets.syncType = eventData.syncType;
180
+ data.historySets.progress = eventData.progress;
181
+ data.historySets.peerDataRequestSessionId = eventData.peerDataRequestSessionId;
179
182
  data.historySets.isLatest = eventData.isLatest || data.historySets.isLatest;
180
183
  break;
181
184
  case 'chats.upsert':
@@ -442,7 +445,10 @@ function consolidateEvents(data) {
442
445
  chats: Object.values(data.historySets.chats),
443
446
  messages: Object.values(data.historySets.messages),
444
447
  contacts: Object.values(data.historySets.contacts),
445
- isLatest: data.historySets.isLatest
448
+ syncType: data.historySets.syncType,
449
+ progress: data.historySets.progress,
450
+ isLatest: data.historySets.isLatest,
451
+ peerDataRequestSessionId: data.historySets.peerDataRequestSessionId
446
452
  };
447
453
  }
448
454
  const chatUpsertList = Object.values(data.chatUpserts);
@@ -496,12 +502,9 @@ function consolidateEvents(data) {
496
502
  return map;
497
503
  }
498
504
  function concatChats(a, b) {
499
- if (b.unreadCount === null) {
500
- // neutralize unread counter
501
- if (a.unreadCount < 0) {
502
- a.unreadCount = undefined;
503
- b.unreadCount = undefined;
504
- }
505
+ if (b.unreadCount === null && a.unreadCount < 0) {
506
+ a.unreadCount = undefined;
507
+ b.unreadCount = undefined;
505
508
  }
506
509
  if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
507
510
  b = { ...b };
@@ -1,24 +1,20 @@
1
- /// <reference types="node" />
2
1
  import { AxiosRequestConfig } from 'axios';
3
2
  import { Logger } from 'pino';
4
3
  import { proto } from '../../WAProto';
5
- import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
4
+ import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
6
5
  import { BinaryNode } from '../WABinary';
7
- export declare const Browsers: {
8
- ubuntu: (browser: any) => [string, string, string];
9
- macOS: (browser: any) => [string, string, string];
10
- baileys: (browser: any) => [string, string, string];
11
- windows: (browser: any) => [string, string, string];
12
- /** The appropriate browser based on your OS & release */
13
- appropriate: (browser: any) => [string, string, string];
14
- };
6
+ export declare const Browsers: BrowsersMap;
15
7
  export declare const getPlatformId: (browser: string) => any;
8
+ export declare const BufferJSON: {
9
+ replacer: (k: any, value: any) => any;
10
+ reviver: (_: any, value: any) => any;
11
+ };
16
12
  export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
17
- export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
18
- export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
19
- export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
13
+ export declare const writeRandomPadMax16: (msg: Uint8Array) => any;
14
+ export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array<any>;
15
+ export declare const encodeWAMessage: (message: proto.IMessage) => any;
20
16
  export declare const generateRegistrationId: () => number;
21
- export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
17
+ export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array<ArrayBuffer>;
22
18
  export declare const toNumber: (t: Long | number | null | undefined) => number;
23
19
  /** unix timestamp of a date in seconds */
24
20
  export declare const unixTimestampSeconds: (date?: Date) => number;
@@ -38,14 +34,14 @@ export declare function promiseTimeout<T>(ms: number | undefined, promise: (reso
38
34
  export declare const generateMessageIDV2: (userId?: string) => string;
39
35
  export declare const generateMessageID: () => string;
40
36
  export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
41
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
37
+ export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
42
38
  export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
43
39
  /**
44
40
  * utility that fetches latest baileys version from the master branch.
45
41
  * Use to ensure your WA connection is always on the latest version
46
42
  */
47
43
  export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
48
- version: WAVersion;
44
+ version: any;
49
45
  isLatest: boolean;
50
46
  error?: undefined;
51
47
  } | {
@@ -87,6 +83,6 @@ export declare const getCodeFromWSError: (error: Error) => number;
87
83
  * Is the given platform WA business
88
84
  * @param platform AuthenticationCreds.platform
89
85
  */
90
- export declare const isWABusinessPlatform: (platform: string) => boolean;
86
+ export declare const isWABusinessPlatform: (platform: string) => platform is "smbi" | "smba";
91
87
  export declare function trimUndefined(obj: any): any;
92
88
  export declare function bytesToCrockford(buffer: Buffer): string;
@@ -1,9 +1,13 @@
1
- "use strict";
1
+ "use strict";
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.bytesToCrockford = exports.trimUndefined = exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.bindWaitForEvent = exports.generateMessageID = exports.generateMessageIDV2 = exports.promiseTimeout = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.Browsers = void 0;
6
+ exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.printQRIfNecessaryListener = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
7
+ exports.promiseTimeout = promiseTimeout;
8
+ exports.bindWaitForEvent = bindWaitForEvent;
9
+ exports.trimUndefined = trimUndefined;
10
+ exports.bytesToCrockford = bytesToCrockford;
7
11
  const boom_1 = require("@hapi/boom");
8
12
  const axios_1 = __importDefault(require("axios"));
9
13
  const crypto_1 = require("crypto");
@@ -12,6 +16,13 @@ const WAProto_1 = require("../../WAProto");
12
16
  const baileys_version_json_1 = require("../Defaults/baileys-version.json");
13
17
  const Types_1 = require("../Types");
14
18
  const WABinary_1 = require("../WABinary");
19
+ const COMPANION_PLATFORM_MAP = {
20
+ 'Chrome': '49',
21
+ 'Edge': '50',
22
+ 'Firefox': '51',
23
+ 'Opera': '53',
24
+ 'Safari': '54'
25
+ };
15
26
  const PLATFORM_MAP = {
16
27
  'aix': 'AIX',
17
28
  'darwin': 'Mac OS',
@@ -26,12 +37,14 @@ exports.Browsers = {
26
37
  macOS: (browser) => ['Mac OS', browser, '14.4.1'],
27
38
  baileys: (browser) => ['Baileys', browser, '6.5.0'],
28
39
  windows: (browser) => ['Windows', browser, '10.0.22631'],
40
+ iOS: (browser) => ['iOS', browser, '18.2'],
41
+ linux: (browser) => ['Linux', browser, '6.12.6'],
42
+ /** The appropriate browser based on your OS & release */
29
43
  appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
30
44
  };
31
-
32
45
  const getPlatformId = (browser) => {
33
46
  const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
34
- return platformType ? platformType.toString() : '1'; //chrome
47
+ return platformType ? platformType.toString().charCodeAt(0).toString() : '49'; //chrome
35
48
  };
36
49
  exports.getPlatformId = getPlatformId;
37
50
  exports.BufferJSON = {
@@ -88,7 +101,7 @@ const encodeBigEndian = (e, t = 4) => {
88
101
  return a;
89
102
  };
90
103
  exports.encodeBigEndian = encodeBigEndian;
91
- const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
104
+ const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0);
92
105
  exports.toNumber = toNumber;
93
106
  /** unix timestamp of a date in seconds */
94
107
  const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
@@ -154,7 +167,6 @@ async function promiseTimeout(ms, promise) {
154
167
  .finally(cancel);
155
168
  return p;
156
169
  }
157
- exports.promiseTimeout = promiseTimeout;
158
170
  const generateMessageIDV2 = (userId) => {
159
171
  const data = Buffer.alloc(8 + 20 + 16);
160
172
  data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
@@ -168,11 +180,11 @@ const generateMessageIDV2 = (userId) => {
168
180
  const random = (0, crypto_1.randomBytes)(16);
169
181
  random.copy(data, 28);
170
182
  const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
171
- return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18);
183
+ return hash.toString('hex').toUpperCase().substring(0, 32);
172
184
  };
173
185
  exports.generateMessageIDV2 = generateMessageIDV2;
174
186
  // generate a random ID to attach to a message
175
- const generateMessageID = () => 'SH3NN-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
187
+ const generateMessageID = () => (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase();
176
188
  exports.generateMessageID = generateMessageID;
177
189
  function bindWaitForEvent(ev, event) {
178
190
  return async (check, timeoutMs) => {
@@ -199,7 +211,6 @@ function bindWaitForEvent(ev, event) {
199
211
  }));
200
212
  };
201
213
  }
202
- exports.bindWaitForEvent = bindWaitForEvent;
203
214
  const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
204
215
  exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
205
216
  const printQRIfNecessaryListener = (ev, logger) => {
@@ -220,7 +231,7 @@ exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
220
231
  * Use to ensure your WA connection is always on the latest version
221
232
  */
222
233
  const fetchLatestBaileysVersion = async (options = {}) => {
223
- const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
234
+ const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
224
235
  try {
225
236
  const result = await axios_1.default.get(URL, {
226
237
  ...options,
@@ -272,6 +283,7 @@ const generateMdTagPrefix = () => {
272
283
  };
273
284
  exports.generateMdTagPrefix = generateMdTagPrefix;
274
285
  const STATUS_MAP = {
286
+ 'sender': WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
275
287
  'played': WAProto_1.proto.WebMessageInfo.Status.PLAYED,
276
288
  'read': WAProto_1.proto.WebMessageInfo.Status.READ,
277
289
  'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
@@ -320,7 +332,8 @@ const getCallStatusFromNode = ({ tag, attrs }) => {
320
332
  status = 'timeout';
321
333
  }
322
334
  else {
323
- status = 'reject';
335
+ //fired when accepted/rejected/timeout/caller hangs up
336
+ status = 'terminate';
324
337
  }
325
338
  break;
326
339
  case 'reject':
@@ -369,14 +382,13 @@ function trimUndefined(obj) {
369
382
  }
370
383
  return obj;
371
384
  }
372
- exports.trimUndefined = trimUndefined;
373
385
  const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
374
386
  function bytesToCrockford(buffer) {
375
387
  let value = 0;
376
388
  let bitCount = 0;
377
389
  const crockford = [];
378
- for (let i = 0; i < buffer.length; i++) {
379
- value = (value << 8) | (buffer[i] & 0xff);
390
+ for (const element of buffer) {
391
+ value = (value << 8) | (element & 0xff);
380
392
  bitCount += 8;
381
393
  while (bitCount >= 5) {
382
394
  crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
@@ -388,4 +400,3 @@ function bytesToCrockford(buffer) {
388
400
  }
389
401
  return crockford.join('');
390
402
  }
391
- exports.bytesToCrockford = bytesToCrockford;
@@ -1,15 +1,19 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { proto } from '../../WAProto';
3
3
  import { Chat, Contact } from '../Types';
4
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
4
+ export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
5
5
  export declare const processHistoryMessage: (item: proto.IHistorySync) => {
6
6
  chats: Chat[];
7
7
  contacts: Contact[];
8
8
  messages: proto.IWebMessageInfo[];
9
+ syncType: proto.HistorySync.HistorySyncType;
10
+ progress: number | null | undefined;
9
11
  };
10
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
12
+ export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
11
13
  chats: Chat[];
12
14
  contacts: Contact[];
13
15
  messages: proto.IWebMessageInfo[];
16
+ syncType: proto.HistorySync.HistorySyncType;
17
+ progress: number | null | undefined;
14
18
  }>;
15
19
  export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
@@ -32,13 +32,9 @@ const processHistoryMessage = (item) => {
32
32
  case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
33
33
  case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
34
34
  case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
35
+ case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
35
36
  for (const chat of item.conversations) {
36
- contacts.push({
37
- id: chat.id,
38
- name: chat.name || undefined,
39
- lid: chat.lidJid || undefined,
40
- jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
41
- });
37
+ contacts.push({ id: chat.id, name: chat.name || undefined });
42
38
  const msgs = chat.messages || [];
43
39
  delete chat.messages;
44
40
  delete chat.archived;
@@ -79,6 +75,8 @@ const processHistoryMessage = (item) => {
79
75
  chats,
80
76
  contacts,
81
77
  messages,
78
+ syncType: item.syncType,
79
+ progress: item.progress
82
80
  };
83
81
  };
84
82
  exports.processHistoryMessage = processHistoryMessage;
@@ -1,4 +1,2 @@
1
- declare const _default: import("pino").Logger<{
2
- timestamp: () => string;
3
- }>;
1
+ declare const _default: any;
4
2
  export default _default;
@@ -12,33 +12,33 @@ class d {
12
12
  constructor(e) {
13
13
  this.salt = e;
14
14
  }
15
- add(e, t) {
15
+ async add(e, t) {
16
16
  var r = this;
17
17
  for (const item of t) {
18
- e = r._addSingle(e, item);
18
+ e = await r._addSingle(e, item);
19
19
  }
20
20
  return e;
21
21
  }
22
- subtract(e, t) {
22
+ async subtract(e, t) {
23
23
  var r = this;
24
24
  for (const item of t) {
25
- e = r._subtractSingle(e, item);
25
+ e = await r._subtractSingle(e, item);
26
26
  }
27
27
  return e;
28
28
  }
29
- subtractThenAdd(e, t, r) {
29
+ async subtractThenAdd(e, t, r) {
30
30
  var n = this;
31
- return n.add(n.subtract(e, r), t);
31
+ return n.add(await n.subtract(e, r), t);
32
32
  }
33
- _addSingle(e, t) {
33
+ async _addSingle(e, t) {
34
34
  var r = this;
35
- const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
36
- return r.performPointwiseWithOverflow(e, n, ((e, t) => e + t));
35
+ const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
36
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t));
37
37
  }
38
- _subtractSingle(e, t) {
38
+ async _subtractSingle(e, t) {
39
39
  var r = this;
40
- const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
41
- return r.performPointwiseWithOverflow(e, n, ((e, t) => e - t));
40
+ const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
41
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t));
42
42
  }
43
43
  performPointwiseWithOverflow(e, t, r) {
44
44
  const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
@@ -1,7 +1,7 @@
1
1
  export declare const makeMutex: () => {
2
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
2
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
3
3
  };
4
4
  export type Mutex = ReturnType<typeof makeMutex>;
5
5
  export declare const makeKeyedMutex: () => {
6
- mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
6
+ mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
7
7
  };
@@ -1,10 +1,7 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
1
  import { Boom } from '@hapi/boom';
5
2
  import { AxiosRequestConfig } from 'axios';
6
3
  import type { Logger } from 'pino';
7
- import { Readable, Transform } from 'stream';
4
+ import { Readable } from 'stream';
8
5
  import { URL } from 'url';
9
6
  import { proto } from '../../WAProto';
10
7
  import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
@@ -13,10 +10,10 @@ export declare const hkdfInfoKey: (type: MediaType) => string;
13
10
  /** generates all the keys required to encrypt/decrypt & sign a media message */
14
11
  export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
15
12
  export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
16
- buffer: Buffer;
13
+ buffer: any;
17
14
  original: {
18
- width: number | undefined;
19
- height: number | undefined;
15
+ width: any;
16
+ height: any;
20
17
  };
21
18
  }>;
22
19
  export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
@@ -24,25 +21,25 @@ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Pro
24
21
  img: Buffer;
25
22
  }>;
26
23
  /** gets the SHA256 of the given media message */
27
- export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
28
- export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
24
+ export declare const mediaMessageSHA256B64: (message: WAMessageContent) => any;
25
+ export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<any>;
29
26
  /**
30
27
  referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
31
28
  */
32
- export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
33
- export declare const toReadable: (buffer: Buffer) => Readable;
34
- export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
29
+ export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array<ArrayBuffer> | undefined>;
30
+ export declare const toReadable: (buffer: Buffer) => any;
31
+ export declare const toBuffer: (stream: Readable) => Promise<any>;
35
32
  export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
36
- readonly stream: Readable;
33
+ readonly stream: any;
37
34
  readonly type: "buffer";
38
35
  } | {
39
- readonly stream: Readable;
36
+ readonly stream: any;
40
37
  readonly type: "readable";
41
38
  } | {
42
39
  readonly stream: Readable;
43
40
  readonly type: "remote";
44
41
  } | {
45
- readonly stream: import("fs").ReadStream;
42
+ readonly stream: any;
46
43
  readonly type: "file";
47
44
  }>;
48
45
  /** generates a thumbnail for a given media, if required */
@@ -65,20 +62,20 @@ type EncryptedStreamOptions = {
65
62
  };
66
63
  export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
67
64
  mediaKey: undefined;
68
- encWriteStream: Buffer;
69
- fileLength: number;
70
- fileSha256: Buffer;
65
+ encWriteStream: any;
66
+ fileLength: any;
67
+ fileSha256: any;
71
68
  fileEncSha256: undefined;
72
69
  bodyPath: string | undefined;
73
70
  didSaveToTmpPath: boolean;
74
71
  }>;
75
72
  export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
76
- mediaKey: Buffer;
77
- encWriteStream: Readable;
73
+ mediaKey: any;
74
+ encWriteStream: any;
78
75
  bodyPath: string | undefined;
79
- mac: Buffer;
80
- fileEncSha256: Buffer;
81
- fileSha256: Buffer;
76
+ mac: any;
77
+ fileEncSha256: any;
78
+ fileSha256: any;
82
79
  fileLength: number;
83
80
  didSaveToTmpPath: boolean;
84
81
  }>;
@@ -88,12 +85,12 @@ export type MediaDownloadOptions = {
88
85
  options?: AxiosRequestConfig<any>;
89
86
  };
90
87
  export declare const getUrlFromDirectPath: (directPath: string) => string;
91
- export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
88
+ export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<any>;
92
89
  /**
93
90
  * Decrypts and downloads an AES256-CBC encrypted file given the keys.
94
91
  * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
95
92
  * */
96
- export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
93
+ export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<any>;
97
94
  export declare function extensionForMediaMessage(message: WAMessageContent): string;
98
95
  export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
99
96
  /**
@@ -101,12 +98,12 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
101
98
  */
102
99
  export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
103
100
  export declare const decodeMediaRetryNode: (node: BinaryNode) => {
104
- key: proto.IMessageKey;
101
+ key: import("../Types").WAMessageKey;
105
102
  media?: {
106
103
  ciphertext: Uint8Array;
107
104
  iv: Uint8Array;
108
- } | undefined;
109
- error?: Boom<any> | undefined;
105
+ };
106
+ error?: Boom;
110
107
  };
111
108
  export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
112
109
  ciphertext: Uint8Array;