gifted-baileys 1.5.4 → 1.5.5

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 (250) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/WAProto.proto +88 -969
  3. package/WAProto/index.d.ts +1256 -13195
  4. package/WAProto/index.js +74730 -125106
  5. package/package.json +9 -27
  6. package/src/Defaults/baileys-version.json +3 -0
  7. package/{lib → src}/Defaults/index.js +14 -7
  8. package/src/Defaults/index.ts +131 -0
  9. package/src/Signal/libsignal.js +180 -0
  10. package/src/Signal/libsignal.ts +141 -0
  11. package/src/Socket/Client/abstract-socket-client.ts +19 -0
  12. package/{lib → src}/Socket/Client/index.js +3 -2
  13. package/src/Socket/Client/index.ts +3 -0
  14. package/src/Socket/Client/mobile-socket-client.js +78 -0
  15. package/src/Socket/Client/mobile-socket-client.ts +66 -0
  16. package/src/Socket/Client/web-socket-client.js +75 -0
  17. package/src/Socket/Client/web-socket-client.ts +57 -0
  18. package/{lib → src}/Socket/business.js +33 -28
  19. package/src/Socket/business.ts +281 -0
  20. package/{lib → src}/Socket/chats.js +176 -174
  21. package/src/Socket/chats.ts +1030 -0
  22. package/{lib → src}/Socket/groups.js +68 -80
  23. package/src/Socket/groups.ts +356 -0
  24. package/{lib → src}/Socket/index.js +1 -4
  25. package/src/Socket/index.ts +13 -0
  26. package/{lib → src}/Socket/messages-recv.js +211 -378
  27. package/src/Socket/messages-recv.ts +985 -0
  28. package/{lib → src}/Socket/messages-send.js +177 -452
  29. package/src/Socket/messages-send.ts +871 -0
  30. package/{lib → src}/Socket/newsletter.js +98 -107
  31. package/src/Socket/newsletter.ts +282 -0
  32. package/{lib → src}/Socket/registration.js +48 -56
  33. package/src/Socket/registration.ts +250 -0
  34. package/{lib → src}/Socket/socket.js +77 -77
  35. package/src/Socket/socket.ts +777 -0
  36. package/src/Store/index.ts +3 -0
  37. package/{lib → src}/Store/make-cache-manager-store.js +34 -25
  38. package/src/Store/make-cache-manager-store.ts +100 -0
  39. package/{lib → src}/Store/make-in-memory-store.js +32 -36
  40. package/src/Store/make-in-memory-store.ts +475 -0
  41. package/src/Store/make-ordered-dictionary.ts +86 -0
  42. package/{lib → src}/Store/object-repository.js +1 -1
  43. package/src/Store/object-repository.ts +32 -0
  44. package/src/Tests/test.app-state-sync.js +204 -0
  45. package/src/Tests/test.app-state-sync.ts +207 -0
  46. package/src/Tests/test.event-buffer.js +270 -0
  47. package/src/Tests/test.event-buffer.ts +319 -0
  48. package/src/Tests/test.key-store.js +76 -0
  49. package/src/Tests/test.key-store.ts +92 -0
  50. package/src/Tests/test.libsignal.js +141 -0
  51. package/src/Tests/test.libsignal.ts +186 -0
  52. package/src/Tests/test.media-download.js +93 -0
  53. package/src/Tests/test.media-download.ts +76 -0
  54. package/src/Tests/test.messages.js +33 -0
  55. package/src/Tests/test.messages.ts +37 -0
  56. package/src/Tests/utils.js +34 -0
  57. package/src/Tests/utils.ts +36 -0
  58. package/src/Types/Auth.ts +113 -0
  59. package/src/Types/Call.ts +15 -0
  60. package/src/Types/Chat.ts +106 -0
  61. package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
  62. package/src/Types/Events.ts +93 -0
  63. package/src/Types/GroupMetadata.ts +53 -0
  64. package/src/Types/Label.ts +36 -0
  65. package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
  66. package/src/Types/Message.ts +288 -0
  67. package/src/Types/Newsletter.ts +98 -0
  68. package/src/Types/Product.ts +85 -0
  69. package/src/Types/Signal.ts +68 -0
  70. package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -61
  71. package/src/Types/State.ts +29 -0
  72. package/src/Types/index.ts +59 -0
  73. package/{lib → src}/Utils/auth-utils.js +90 -73
  74. package/src/Utils/auth-utils.ts +222 -0
  75. package/src/Utils/baileys-event-stream.js +92 -0
  76. package/src/Utils/baileys-event-stream.ts +66 -0
  77. package/{lib → src}/Utils/business.js +43 -15
  78. package/src/Utils/business.ts +275 -0
  79. package/{lib → src}/Utils/chat-utils.js +94 -87
  80. package/src/Utils/chat-utils.ts +860 -0
  81. package/{lib → src}/Utils/crypto.js +2 -4
  82. package/src/Utils/crypto.ts +131 -0
  83. package/src/Utils/decode-wa-message.js +211 -0
  84. package/src/Utils/decode-wa-message.ts +228 -0
  85. package/{lib → src}/Utils/event-buffer.js +13 -4
  86. package/src/Utils/event-buffer.ts +613 -0
  87. package/{lib → src}/Utils/generics.js +86 -67
  88. package/src/Utils/generics.ts +434 -0
  89. package/{lib → src}/Utils/history.js +39 -13
  90. package/src/Utils/history.ts +112 -0
  91. package/src/Utils/index.ts +17 -0
  92. package/{lib → src}/Utils/link-preview.js +54 -17
  93. package/src/Utils/link-preview.ts +122 -0
  94. package/src/Utils/logger.ts +3 -0
  95. package/src/Utils/lt-hash.ts +61 -0
  96. package/{lib → src}/Utils/make-mutex.js +13 -4
  97. package/src/Utils/make-mutex.ts +44 -0
  98. package/{lib → src}/Utils/messages-media.js +255 -193
  99. package/src/Utils/messages-media.ts +847 -0
  100. package/{lib → src}/Utils/messages.js +118 -588
  101. package/src/Utils/messages.ts +956 -0
  102. package/src/Utils/noise-handler.ts +197 -0
  103. package/{lib → src}/Utils/process-message.js +30 -27
  104. package/src/Utils/process-message.ts +414 -0
  105. package/{lib → src}/Utils/signal.js +42 -25
  106. package/src/Utils/signal.ts +177 -0
  107. package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -27
  108. package/src/Utils/use-multi-file-auth-state.ts +90 -0
  109. package/{lib → src}/Utils/validate-connection.js +9 -40
  110. package/src/Utils/validate-connection.ts +238 -0
  111. package/src/WABinary/constants.ts +42 -0
  112. package/src/WABinary/decode.ts +265 -0
  113. package/{lib → src}/WABinary/encode.js +10 -16
  114. package/src/WABinary/encode.ts +236 -0
  115. package/src/WABinary/generic-utils.ts +121 -0
  116. package/src/WABinary/index.ts +5 -0
  117. package/src/WABinary/jid-utils.ts +68 -0
  118. package/src/WABinary/types.ts +17 -0
  119. package/src/WAM/BinaryInfo.ts +12 -0
  120. package/src/WAM/constants.ts +15382 -0
  121. package/src/WAM/encode.ts +174 -0
  122. package/src/WAM/index.ts +3 -0
  123. package/{lib → src}/index.js +0 -1
  124. package/src/index.ts +13 -0
  125. package/lib/Defaults/baileys-version.json +0 -3
  126. package/lib/Defaults/index.d.ts +0 -284
  127. package/lib/Signal/libsignal.d.ts +0 -3
  128. package/lib/Signal/libsignal.js +0 -161
  129. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  130. package/lib/Socket/Client/index.d.ts +0 -2
  131. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  132. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  133. package/lib/Socket/Client/types.d.ts +0 -17
  134. package/lib/Socket/Client/types.js +0 -13
  135. package/lib/Socket/Client/websocket.d.ts +0 -12
  136. package/lib/Socket/Client/websocket.js +0 -62
  137. package/lib/Socket/business.d.ts +0 -170
  138. package/lib/Socket/chats.d.ts +0 -81
  139. package/lib/Socket/groups.d.ts +0 -115
  140. package/lib/Socket/index.d.ts +0 -172
  141. package/lib/Socket/messages-recv.d.ts +0 -158
  142. package/lib/Socket/messages-send.d.ts +0 -155
  143. package/lib/Socket/newsletter.d.ts +0 -132
  144. package/lib/Socket/registration.d.ts +0 -264
  145. package/lib/Socket/socket.d.ts +0 -44
  146. package/lib/Socket/usync.d.ts +0 -37
  147. package/lib/Socket/usync.js +0 -70
  148. package/lib/Store/index.d.ts +0 -3
  149. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  150. package/lib/Store/make-in-memory-store.d.ts +0 -118
  151. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  152. package/lib/Store/object-repository.d.ts +0 -10
  153. package/lib/Types/Auth.d.ts +0 -109
  154. package/lib/Types/Call.d.ts +0 -13
  155. package/lib/Types/Chat.d.ts +0 -107
  156. package/lib/Types/Events.d.ts +0 -172
  157. package/lib/Types/GroupMetadata.d.ts +0 -56
  158. package/lib/Types/Label.d.ts +0 -46
  159. package/lib/Types/Message.d.ts +0 -433
  160. package/lib/Types/Newsletter.d.ts +0 -92
  161. package/lib/Types/Product.d.ts +0 -78
  162. package/lib/Types/Signal.d.ts +0 -57
  163. package/lib/Types/State.d.ts +0 -27
  164. package/lib/Types/USync.d.ts +0 -25
  165. package/lib/Types/USync.js +0 -2
  166. package/lib/Types/index.d.ts +0 -66
  167. package/lib/Utils/auth-utils.d.ts +0 -18
  168. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  169. package/lib/Utils/baileys-event-stream.js +0 -63
  170. package/lib/Utils/business.d.ts +0 -22
  171. package/lib/Utils/chat-utils.d.ts +0 -70
  172. package/lib/Utils/crypto.d.ts +0 -40
  173. package/lib/Utils/decode-wa-message.d.ts +0 -36
  174. package/lib/Utils/decode-wa-message.js +0 -226
  175. package/lib/Utils/event-buffer.d.ts +0 -35
  176. package/lib/Utils/generics.d.ts +0 -88
  177. package/lib/Utils/history.d.ts +0 -19
  178. package/lib/Utils/index.d.ts +0 -17
  179. package/lib/Utils/link-preview.d.ts +0 -21
  180. package/lib/Utils/logger.d.ts +0 -2
  181. package/lib/Utils/lt-hash.d.ts +0 -12
  182. package/lib/Utils/make-mutex.d.ts +0 -7
  183. package/lib/Utils/messages-media.d.ts +0 -113
  184. package/lib/Utils/messages.d.ts +0 -77
  185. package/lib/Utils/noise-handler.d.ts +0 -20
  186. package/lib/Utils/process-message.d.ts +0 -41
  187. package/lib/Utils/signal.d.ts +0 -33
  188. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  189. package/lib/Utils/validate-connection.d.ts +0 -11
  190. package/lib/WABinary/constants.d.ts +0 -27
  191. package/lib/WABinary/decode.d.ts +0 -6
  192. package/lib/WABinary/encode.d.ts +0 -2
  193. package/lib/WABinary/generic-utils.d.ts +0 -14
  194. package/lib/WABinary/index.d.ts +0 -5
  195. package/lib/WABinary/jid-utils.d.ts +0 -31
  196. package/lib/WABinary/types.d.ts +0 -18
  197. package/lib/WAM/BinaryInfo.d.ts +0 -8
  198. package/lib/WAM/constants.d.ts +0 -38
  199. package/lib/WAM/encode.d.ts +0 -2
  200. package/lib/WAM/index.d.ts +0 -3
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  202. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  203. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  204. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  205. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  206. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  207. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  208. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  209. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  210. package/lib/WAUSync/Protocols/index.js +0 -20
  211. package/lib/WAUSync/USyncQuery.d.ts +0 -26
  212. package/lib/WAUSync/USyncQuery.js +0 -79
  213. package/lib/WAUSync/USyncUser.d.ts +0 -10
  214. package/lib/WAUSync/USyncUser.js +0 -22
  215. package/lib/WAUSync/index.d.ts +0 -3
  216. package/lib/WAUSync/index.js +0 -19
  217. /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
  218. /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
  219. /package/{lib → src}/Store/index.js +0 -0
  220. /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
  221. /package/{lib → src}/Types/Auth.js +0 -0
  222. /package/{lib → src}/Types/Call.js +0 -0
  223. /package/{lib → src}/Types/Chat.js +0 -0
  224. /package/{lib → src}/Types/Contact.js +0 -0
  225. /package/{lib → src}/Types/Events.js +0 -0
  226. /package/{lib → src}/Types/GroupMetadata.js +0 -0
  227. /package/{lib → src}/Types/Label.js +0 -0
  228. /package/{lib → src}/Types/LabelAssociation.js +0 -0
  229. /package/{lib → src}/Types/Message.js +0 -0
  230. /package/{lib → src}/Types/Newsletter.js +0 -0
  231. /package/{lib → src}/Types/Product.js +0 -0
  232. /package/{lib → src}/Types/Signal.js +0 -0
  233. /package/{lib → src}/Types/Socket.js +0 -0
  234. /package/{lib → src}/Types/State.js +0 -0
  235. /package/{lib → src}/Types/index.js +0 -0
  236. /package/{lib → src}/Utils/index.js +0 -0
  237. /package/{lib → src}/Utils/logger.js +0 -0
  238. /package/{lib → src}/Utils/lt-hash.js +0 -0
  239. /package/{lib → src}/Utils/noise-handler.js +0 -0
  240. /package/{lib → src}/WABinary/constants.js +0 -0
  241. /package/{lib → src}/WABinary/decode.js +0 -0
  242. /package/{lib → src}/WABinary/generic-utils.js +0 -0
  243. /package/{lib → src}/WABinary/index.js +0 -0
  244. /package/{lib → src}/WABinary/jid-utils.js +0 -0
  245. /package/{lib → src}/WABinary/types.js +0 -0
  246. /package/{lib → src}/WAM/BinaryInfo.js +0 -0
  247. /package/{lib → src}/WAM/constants.js +0 -0
  248. /package/{lib → src}/WAM/encode.js +0 -0
  249. /package/{lib → src}/WAM/index.js +0 -0
  250. /package/{lib → src}/gifted +0 -0
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.makeSocket = void 0;
4
13
  const boom_1 = require("@hapi/boom");
@@ -54,21 +63,21 @@ const makeSocket = (config) => {
54
63
  const generateMessageTag = () => `${uqTagId}${epoch++}`;
55
64
  const sendPromise = (0, util_1.promisify)(ws.send);
56
65
  /** send a raw buffer */
57
- const sendRawMessage = async (data) => {
66
+ const sendRawMessage = (data) => __awaiter(void 0, void 0, void 0, function* () {
58
67
  if (!ws.isOpen) {
59
68
  throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
60
69
  }
61
70
  const bytes = noise.encodeFrame(data);
62
- await (0, Utils_1.promiseTimeout)(connectTimeoutMs, async (resolve, reject) => {
71
+ yield (0, Utils_1.promiseTimeout)(connectTimeoutMs, (resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
63
72
  try {
64
- await sendPromise.call(ws, bytes);
73
+ yield sendPromise.call(ws, bytes);
65
74
  resolve();
66
75
  }
67
76
  catch (error) {
68
77
  reject(error);
69
78
  }
70
- });
71
- };
79
+ }));
80
+ });
72
81
  /** send a binary node */
73
82
  const sendNode = (frame) => {
74
83
  if (logger.level === 'trace') {
@@ -82,7 +91,7 @@ const makeSocket = (config) => {
82
91
  logger.error({ err }, `unexpected error in '${msg}'`);
83
92
  };
84
93
  /** await the next incoming message */
85
- const awaitNextMessage = async (sendMsg) => {
94
+ const awaitNextMessage = (sendMsg) => __awaiter(void 0, void 0, void 0, function* () {
86
95
  if (!ws.isOpen) {
87
96
  throw new boom_1.Boom('Connection Closed', {
88
97
  statusCode: Types_1.DisconnectReason.connectionClosed
@@ -106,17 +115,17 @@ const makeSocket = (config) => {
106
115
  sendRawMessage(sendMsg).catch(onClose);
107
116
  }
108
117
  return result;
109
- };
118
+ });
110
119
  /**
111
120
  * Wait for a message with a certain tag to be received
112
121
  * @param msgId the message tag to await
113
122
  * @param timeoutMs timeout after which the promise will reject
114
123
  */
115
- const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
124
+ const waitForMessage = (msgId_1, ...args_1) => __awaiter(void 0, [msgId_1, ...args_1], void 0, function* (msgId, timeoutMs = defaultQueryTimeoutMs) {
116
125
  let onRecv;
117
126
  let onErr;
118
127
  try {
119
- return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
128
+ return yield (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
120
129
  onRecv = resolve;
121
130
  onErr = err => {
122
131
  reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
@@ -131,30 +140,30 @@ const makeSocket = (config) => {
131
140
  ws.off('close', onErr); // if the socket closes, you'll never receive the message
132
141
  ws.off('error', onErr);
133
142
  }
134
- };
143
+ });
135
144
  /** send a query, and wait for its response. auto-generates message ID if not provided */
136
- const query = async (node, timeoutMs) => {
145
+ const query = (node, timeoutMs) => __awaiter(void 0, void 0, void 0, function* () {
137
146
  if (!node.attrs.id) {
138
147
  node.attrs.id = generateMessageTag();
139
148
  }
140
149
  const msgId = node.attrs.id;
141
150
  const wait = waitForMessage(msgId, timeoutMs);
142
- await sendNode(node);
143
- const result = await wait;
151
+ yield sendNode(node);
152
+ const result = yield wait;
144
153
  if ('tag' in result) {
145
154
  (0, WABinary_1.assertNodeErrorFree)(result);
146
155
  }
147
156
  return result;
148
- };
157
+ });
149
158
  /** connection handshake */
150
- const validateConnection = async () => {
159
+ const validateConnection = () => __awaiter(void 0, void 0, void 0, function* () {
151
160
  let helloMsg = {
152
161
  clientHello: { ephemeral: ephemeralKeyPair.public }
153
162
  };
154
163
  helloMsg = WAProto_1.proto.HandshakeMessage.fromObject(helloMsg);
155
164
  logger.info({ browser, helloMsg }, 'connected to WA');
156
165
  const init = WAProto_1.proto.HandshakeMessage.encode(helloMsg).finish();
157
- const result = await awaitNextMessage(init);
166
+ const result = yield awaitNextMessage(init);
158
167
  const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
159
168
  logger.trace({ handshake }, 'handshake recv from WA');
160
169
  const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
@@ -171,7 +180,7 @@ const makeSocket = (config) => {
171
180
  logger.info({ node }, 'logging in...');
172
181
  }
173
182
  const payloadEnc = noise.encrypt(WAProto_1.proto.ClientPayload.encode(node).finish());
174
- await sendRawMessage(WAProto_1.proto.HandshakeMessage.encode({
183
+ yield sendRawMessage(WAProto_1.proto.HandshakeMessage.encode({
175
184
  clientFinish: {
176
185
  static: keyEnc,
177
186
  payload: payloadEnc,
@@ -179,9 +188,9 @@ const makeSocket = (config) => {
179
188
  }).finish());
180
189
  noise.finishInit();
181
190
  startKeepAliveRequest();
182
- };
183
- const getAvailablePreKeysOnServer = async () => {
184
- const result = await query({
191
+ });
192
+ const getAvailablePreKeysOnServer = () => __awaiter(void 0, void 0, void 0, function* () {
193
+ const result = yield query({
185
194
  tag: 'iq',
186
195
  attrs: {
187
196
  id: generateMessageTag(),
@@ -195,24 +204,24 @@ const makeSocket = (config) => {
195
204
  });
196
205
  const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
197
206
  return +countChild.attrs.value;
198
- };
207
+ });
199
208
  /** generates and uploads a set of pre-keys to the server */
200
- const uploadPreKeys = async (count = Defaults_1.INITIAL_PREKEY_COUNT) => {
201
- await keys.transaction(async () => {
209
+ const uploadPreKeys = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (count = Defaults_1.INITIAL_PREKEY_COUNT) {
210
+ yield keys.transaction(() => __awaiter(void 0, void 0, void 0, function* () {
202
211
  logger.info({ count }, 'uploading pre-keys');
203
- const { update, node } = await (0, Utils_1.getNextPreKeysNode)({ creds, keys }, count);
204
- await query(node);
212
+ const { update, node } = yield (0, Utils_1.getNextPreKeysNode)({ creds, keys }, count);
213
+ yield query(node);
205
214
  ev.emit('creds.update', update);
206
215
  logger.info({ count }, 'uploaded pre-keys');
207
- });
208
- };
209
- const uploadPreKeysToServerIfRequired = async () => {
210
- const preKeyCount = await getAvailablePreKeysOnServer();
216
+ }));
217
+ });
218
+ const uploadPreKeysToServerIfRequired = () => __awaiter(void 0, void 0, void 0, function* () {
219
+ const preKeyCount = yield getAvailablePreKeysOnServer();
211
220
  logger.info(`${preKeyCount} pre-keys found on server`);
212
221
  if (preKeyCount <= Defaults_1.MIN_PREKEY_COUNT) {
213
- await uploadPreKeys();
222
+ yield uploadPreKeys();
214
223
  }
215
- };
224
+ });
216
225
  const onMessageReceived = (data) => {
217
226
  noise.decodeFrame(data, frame => {
218
227
  var _a;
@@ -273,7 +282,7 @@ const makeSocket = (config) => {
273
282
  });
274
283
  ev.removeAllListeners('connection.update');
275
284
  };
276
- const waitForSocketOpen = async () => {
285
+ const waitForSocketOpen = () => __awaiter(void 0, void 0, void 0, function* () {
277
286
  if (ws.isOpen) {
278
287
  return;
279
288
  }
@@ -282,7 +291,7 @@ const makeSocket = (config) => {
282
291
  }
283
292
  let onOpen;
284
293
  let onClose;
285
- await new Promise((resolve, reject) => {
294
+ yield new Promise((resolve, reject) => {
286
295
  onOpen = () => resolve(undefined);
287
296
  onClose = mapWebSocketError(reject);
288
297
  ws.on('open', onOpen);
@@ -294,7 +303,7 @@ const makeSocket = (config) => {
294
303
  ws.off('close', onClose);
295
304
  ws.off('error', onClose);
296
305
  });
297
- };
306
+ });
298
307
  const startKeepAliveRequest = () => (keepAliveReq = setInterval(() => {
299
308
  if (!lastDateRecv) {
300
309
  lastDateRecv = new Date();
@@ -340,11 +349,11 @@ const makeSocket = (config) => {
340
349
  ]
341
350
  }));
342
351
  /** logout & invalidate connection */
343
- const logout = async (msg) => {
352
+ const logout = (msg) => __awaiter(void 0, void 0, void 0, function* () {
344
353
  var _a;
345
354
  const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
346
355
  if (jid) {
347
- await sendNode({
356
+ yield sendNode({
348
357
  tag: 'iq',
349
358
  attrs: {
350
359
  to: WABinary_1.S_WHATSAPP_NET,
@@ -364,19 +373,15 @@ const makeSocket = (config) => {
364
373
  });
365
374
  }
366
375
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
367
- };
368
- const requestPairingCode = async (phoneNumber, pairKey = "FIZZBAIL") => {
369
- if (pairKey) {
370
- authState.creds.pairingCode = pairKey.toUpperCase()
371
- } else {
372
- authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
373
- }
376
+ });
377
+ const requestPairingCode = (phoneNumber) => __awaiter(void 0, void 0, void 0, function* () {
378
+ authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
374
379
  authState.creds.me = {
375
380
  id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
376
381
  name: '~'
377
382
  };
378
383
  ev.emit('creds.update', authState.creds);
379
- await sendNode({
384
+ yield sendNode({
380
385
  tag: 'iq',
381
386
  attrs: {
382
387
  to: WABinary_1.S_WHATSAPP_NET,
@@ -397,7 +402,7 @@ const makeSocket = (config) => {
397
402
  {
398
403
  tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
399
404
  attrs: {},
400
- content: await generatePairingKey()
405
+ content: yield generatePairingKey()
401
406
  },
402
407
  {
403
408
  tag: 'companion_server_auth_key_pub',
@@ -407,7 +412,7 @@ const makeSocket = (config) => {
407
412
  {
408
413
  tag: 'companion_platform_id',
409
414
  attrs: {},
410
- content: (0, Utils_1.getPlatformId)(browser[1])
415
+ content: '49' // Chrome
411
416
  },
412
417
  {
413
418
  tag: 'companion_platform_display',
@@ -424,13 +429,15 @@ const makeSocket = (config) => {
424
429
  ]
425
430
  });
426
431
  return authState.creds.pairingCode;
427
- };
428
- async function generatePairingKey() {
429
- const salt = (0, crypto_1.randomBytes)(32);
430
- const randomIv = (0, crypto_1.randomBytes)(16);
431
- const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
432
- const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
433
- return Buffer.concat([salt, randomIv, ciphered]);
432
+ });
433
+ function generatePairingKey() {
434
+ return __awaiter(this, void 0, void 0, function* () {
435
+ const salt = (0, crypto_1.randomBytes)(32);
436
+ const randomIv = (0, crypto_1.randomBytes)(16);
437
+ const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
438
+ const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
439
+ return Buffer.concat([salt, randomIv, ciphered]);
440
+ });
434
441
  }
435
442
  const sendWAMBuffer = (wamBuffer) => {
436
443
  return query({
@@ -450,21 +457,21 @@ const makeSocket = (config) => {
450
457
  });
451
458
  };
452
459
  ws.on('message', onMessageReceived);
453
- ws.on('open', async () => {
460
+ ws.on('open', () => __awaiter(void 0, void 0, void 0, function* () {
454
461
  try {
455
- await validateConnection();
462
+ yield validateConnection();
456
463
  }
457
464
  catch (err) {
458
465
  logger.error({ err }, 'error in validating connection');
459
466
  end(err);
460
467
  }
461
- });
468
+ }));
462
469
  ws.on('error', mapWebSocketError(end));
463
470
  ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
464
471
  // the server terminated the connection
465
472
  ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
466
473
  // QR gen
467
- ws.on('CB:iq,type:set,pair-device', async (stanza) => {
474
+ ws.on('CB:iq,type:set,pair-device', (stanza) => __awaiter(void 0, void 0, void 0, function* () {
468
475
  const iq = {
469
476
  tag: 'iq',
470
477
  attrs: {
@@ -473,7 +480,7 @@ const makeSocket = (config) => {
473
480
  id: stanza.attrs.id,
474
481
  }
475
482
  };
476
- await sendNode(iq);
483
+ yield sendNode(iq);
477
484
  const pairDeviceNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-device');
478
485
  const refNodes = (0, WABinary_1.getBinaryNodeChildren)(pairDeviceNode, 'ref');
479
486
  const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
@@ -496,38 +503,32 @@ const makeSocket = (config) => {
496
503
  qrMs = qrTimeout || 20000; // shorter subsequent qrs
497
504
  };
498
505
  genPairQR();
499
- });
506
+ }));
500
507
  // device paired for the first time
501
508
  // if device pairs successfully, the server asks to restart the connection
502
- ws.on('CB:iq,,pair-success', async (stanza) => {
509
+ ws.on('CB:iq,,pair-success', (stanza) => __awaiter(void 0, void 0, void 0, function* () {
503
510
  logger.debug('pair success recv');
504
511
  try {
505
512
  const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
506
513
  logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
507
514
  ev.emit('creds.update', updatedCreds);
508
515
  ev.emit('connection.update', { isNewLogin: true, qr: undefined });
509
- await sendNode(reply);
516
+ yield sendNode(reply);
510
517
  }
511
518
  catch (error) {
512
519
  logger.info({ trace: error.stack }, 'error in pairing');
513
520
  end(error);
514
521
  }
515
- });
522
+ }));
516
523
  // login complete
517
- ws.on('CB:success', async (node) => {
518
- try {
519
- await uploadPreKeysToServerIfRequired();
520
- await sendPassiveIq('active');
521
- logger.info('opened connection to WA');
522
- clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
523
- ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
524
- ev.emit('connection.update', { connection: 'open' });
525
- }
526
- catch (err) {
527
- logger.error({ err }, 'error opening connection');
528
- end(err);
529
- }
530
- });
524
+ ws.on('CB:success', (node) => __awaiter(void 0, void 0, void 0, function* () {
525
+ yield uploadPreKeysToServerIfRequired();
526
+ yield sendPassiveIq('active');
527
+ logger.info('opened connection to WA');
528
+ clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
529
+ ev.emit('creds.update', { me: Object.assign(Object.assign({}, authState.creds.me), { lid: node.attrs.lid }) });
530
+ ev.emit('connection.update', { connection: 'open' });
531
+ }));
531
532
  ws.on('CB:stream:error', (node) => {
532
533
  logger.error({ node }, 'stream errored out');
533
534
  const { reason, statusCode } = (0, Utils_1.getErrorCodeFromStreamError)(node);
@@ -546,7 +547,6 @@ const makeSocket = (config) => {
546
547
  const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
547
548
  if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
548
549
  authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
549
- ev.emit('creds.update', authState.creds);
550
550
  }
551
551
  });
552
552
  let didStartBuffer = false;