gifted-baileys 1.5.5 → 1.5.7

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 (251) hide show
  1. package/README.md +6 -1642
  2. package/WAProto/WAProto.proto +969 -88
  3. package/WAProto/index.d.ts +13199 -1260
  4. package/WAProto/index.js +124901 -74525
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +284 -0
  7. package/{src → lib}/Defaults/index.js +7 -14
  8. package/lib/Signal/libsignal.d.ts +3 -0
  9. package/lib/Signal/libsignal.js +161 -0
  10. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  11. package/lib/Socket/Client/index.d.ts +2 -0
  12. package/{src → lib}/Socket/Client/index.js +2 -3
  13. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  15. package/lib/Socket/Client/types.d.ts +17 -0
  16. package/lib/Socket/Client/types.js +13 -0
  17. package/lib/Socket/Client/websocket.d.ts +12 -0
  18. package/lib/Socket/Client/websocket.js +62 -0
  19. package/lib/Socket/business.d.ts +170 -0
  20. package/{src → lib}/Socket/business.js +28 -33
  21. package/lib/Socket/chats.d.ts +81 -0
  22. package/{src → lib}/Socket/chats.js +174 -176
  23. package/lib/Socket/groups.d.ts +115 -0
  24. package/{src → lib}/Socket/groups.js +80 -68
  25. package/lib/Socket/index.d.ts +172 -0
  26. package/{src → lib}/Socket/index.js +4 -1
  27. package/lib/Socket/messages-recv.d.ts +158 -0
  28. package/{src → lib}/Socket/messages-recv.js +378 -211
  29. package/lib/Socket/messages-send.d.ts +155 -0
  30. package/{src → lib}/Socket/messages-send.js +452 -177
  31. package/lib/Socket/newsletter.d.ts +132 -0
  32. package/{src → lib}/Socket/newsletter.js +107 -98
  33. package/lib/Socket/registration.d.ts +264 -0
  34. package/{src → lib}/Socket/registration.js +56 -48
  35. package/lib/Socket/socket.d.ts +44 -0
  36. package/{src → lib}/Socket/socket.js +77 -77
  37. package/lib/Socket/usync.d.ts +37 -0
  38. package/lib/Socket/usync.js +70 -0
  39. package/lib/Store/index.d.ts +3 -0
  40. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  41. package/{src → lib}/Store/make-cache-manager-store.js +25 -34
  42. package/lib/Store/make-in-memory-store.d.ts +118 -0
  43. package/{src → lib}/Store/make-in-memory-store.js +36 -32
  44. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  45. package/lib/Store/object-repository.d.ts +10 -0
  46. package/{src → lib}/Store/object-repository.js +1 -1
  47. package/lib/Types/Auth.d.ts +109 -0
  48. package/lib/Types/Call.d.ts +13 -0
  49. package/lib/Types/Chat.d.ts +107 -0
  50. package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
  51. package/lib/Types/Events.d.ts +172 -0
  52. package/lib/Types/GroupMetadata.d.ts +56 -0
  53. package/lib/Types/Label.d.ts +46 -0
  54. package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
  55. package/lib/Types/Message.d.ts +433 -0
  56. package/lib/Types/Newsletter.d.ts +92 -0
  57. package/lib/Types/Product.d.ts +78 -0
  58. package/lib/Types/Signal.d.ts +57 -0
  59. package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
  60. package/lib/Types/State.d.ts +27 -0
  61. package/lib/Types/USync.d.ts +25 -0
  62. package/lib/Types/index.d.ts +66 -0
  63. package/lib/Utils/auth-utils.d.ts +18 -0
  64. package/{src → lib}/Utils/auth-utils.js +73 -90
  65. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  66. package/lib/Utils/baileys-event-stream.js +63 -0
  67. package/lib/Utils/business.d.ts +22 -0
  68. package/{src → lib}/Utils/business.js +15 -43
  69. package/lib/Utils/chat-utils.d.ts +70 -0
  70. package/{src → lib}/Utils/chat-utils.js +87 -94
  71. package/lib/Utils/crypto.d.ts +40 -0
  72. package/{src → lib}/Utils/crypto.js +4 -2
  73. package/lib/Utils/decode-wa-message.d.ts +36 -0
  74. package/lib/Utils/decode-wa-message.js +226 -0
  75. package/lib/Utils/event-buffer.d.ts +35 -0
  76. package/{src → lib}/Utils/event-buffer.js +4 -13
  77. package/lib/Utils/generics.d.ts +88 -0
  78. package/{src → lib}/Utils/generics.js +67 -86
  79. package/lib/Utils/history.d.ts +19 -0
  80. package/{src → lib}/Utils/history.js +13 -39
  81. package/lib/Utils/index.d.ts +17 -0
  82. package/lib/Utils/link-preview.d.ts +21 -0
  83. package/{src → lib}/Utils/link-preview.js +17 -54
  84. package/lib/Utils/logger.d.ts +2 -0
  85. package/lib/Utils/lt-hash.d.ts +12 -0
  86. package/lib/Utils/make-mutex.d.ts +7 -0
  87. package/{src → lib}/Utils/make-mutex.js +4 -13
  88. package/lib/Utils/messages-media.d.ts +113 -0
  89. package/{src → lib}/Utils/messages-media.js +193 -255
  90. package/lib/Utils/messages.d.ts +77 -0
  91. package/{src → lib}/Utils/messages.js +588 -118
  92. package/lib/Utils/noise-handler.d.ts +20 -0
  93. package/lib/Utils/process-message.d.ts +41 -0
  94. package/{src → lib}/Utils/process-message.js +27 -30
  95. package/lib/Utils/signal.d.ts +33 -0
  96. package/{src → lib}/Utils/signal.js +25 -42
  97. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  98. package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
  99. package/lib/Utils/validate-connection.d.ts +11 -0
  100. package/{src → lib}/Utils/validate-connection.js +40 -9
  101. package/lib/WABinary/constants.d.ts +27 -0
  102. package/lib/WABinary/decode.d.ts +6 -0
  103. package/lib/WABinary/encode.d.ts +2 -0
  104. package/{src → lib}/WABinary/encode.js +16 -10
  105. package/lib/WABinary/generic-utils.d.ts +14 -0
  106. package/lib/WABinary/index.d.ts +5 -0
  107. package/lib/WABinary/jid-utils.d.ts +31 -0
  108. package/lib/WABinary/types.d.ts +18 -0
  109. package/lib/WABinary/types.js +2 -0
  110. package/lib/WAM/BinaryInfo.d.ts +8 -0
  111. package/lib/WAM/constants.d.ts +38 -0
  112. package/lib/WAM/encode.d.ts +2 -0
  113. package/lib/WAM/index.d.ts +3 -0
  114. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  115. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  116. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  117. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  118. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  119. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  120. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  121. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  122. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  123. package/lib/WAUSync/Protocols/index.js +20 -0
  124. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  125. package/lib/WAUSync/USyncQuery.js +79 -0
  126. package/lib/WAUSync/USyncUser.d.ts +10 -0
  127. package/lib/WAUSync/USyncUser.js +22 -0
  128. package/lib/WAUSync/index.d.ts +3 -0
  129. package/lib/WAUSync/index.js +19 -0
  130. package/{src → lib}/index.js +1 -0
  131. package/package.json +26 -8
  132. package/LICENSE +0 -21
  133. package/src/Defaults/baileys-version.json +0 -3
  134. package/src/Defaults/index.ts +0 -131
  135. package/src/Signal/libsignal.js +0 -180
  136. package/src/Signal/libsignal.ts +0 -141
  137. package/src/Socket/Client/abstract-socket-client.ts +0 -19
  138. package/src/Socket/Client/index.ts +0 -3
  139. package/src/Socket/Client/mobile-socket-client.js +0 -78
  140. package/src/Socket/Client/mobile-socket-client.ts +0 -66
  141. package/src/Socket/Client/web-socket-client.js +0 -75
  142. package/src/Socket/Client/web-socket-client.ts +0 -57
  143. package/src/Socket/business.ts +0 -281
  144. package/src/Socket/chats.ts +0 -1030
  145. package/src/Socket/groups.ts +0 -356
  146. package/src/Socket/index.ts +0 -13
  147. package/src/Socket/messages-recv.ts +0 -985
  148. package/src/Socket/messages-send.ts +0 -871
  149. package/src/Socket/newsletter.ts +0 -282
  150. package/src/Socket/registration.ts +0 -250
  151. package/src/Socket/socket.ts +0 -777
  152. package/src/Store/index.ts +0 -3
  153. package/src/Store/make-cache-manager-store.ts +0 -100
  154. package/src/Store/make-in-memory-store.ts +0 -475
  155. package/src/Store/make-ordered-dictionary.ts +0 -86
  156. package/src/Store/object-repository.ts +0 -32
  157. package/src/Tests/test.app-state-sync.js +0 -204
  158. package/src/Tests/test.app-state-sync.ts +0 -207
  159. package/src/Tests/test.event-buffer.js +0 -270
  160. package/src/Tests/test.event-buffer.ts +0 -319
  161. package/src/Tests/test.key-store.js +0 -76
  162. package/src/Tests/test.key-store.ts +0 -92
  163. package/src/Tests/test.libsignal.js +0 -141
  164. package/src/Tests/test.libsignal.ts +0 -186
  165. package/src/Tests/test.media-download.js +0 -93
  166. package/src/Tests/test.media-download.ts +0 -76
  167. package/src/Tests/test.messages.js +0 -33
  168. package/src/Tests/test.messages.ts +0 -37
  169. package/src/Tests/utils.js +0 -34
  170. package/src/Tests/utils.ts +0 -36
  171. package/src/Types/Auth.ts +0 -113
  172. package/src/Types/Call.ts +0 -15
  173. package/src/Types/Chat.ts +0 -106
  174. package/src/Types/Events.ts +0 -93
  175. package/src/Types/GroupMetadata.ts +0 -53
  176. package/src/Types/Label.ts +0 -36
  177. package/src/Types/Message.ts +0 -288
  178. package/src/Types/Newsletter.ts +0 -98
  179. package/src/Types/Product.ts +0 -85
  180. package/src/Types/Signal.ts +0 -68
  181. package/src/Types/State.ts +0 -29
  182. package/src/Types/index.ts +0 -59
  183. package/src/Utils/auth-utils.ts +0 -222
  184. package/src/Utils/baileys-event-stream.js +0 -92
  185. package/src/Utils/baileys-event-stream.ts +0 -66
  186. package/src/Utils/business.ts +0 -275
  187. package/src/Utils/chat-utils.ts +0 -860
  188. package/src/Utils/crypto.ts +0 -131
  189. package/src/Utils/decode-wa-message.js +0 -211
  190. package/src/Utils/decode-wa-message.ts +0 -228
  191. package/src/Utils/event-buffer.ts +0 -613
  192. package/src/Utils/generics.ts +0 -434
  193. package/src/Utils/history.ts +0 -112
  194. package/src/Utils/index.ts +0 -17
  195. package/src/Utils/link-preview.ts +0 -122
  196. package/src/Utils/logger.ts +0 -3
  197. package/src/Utils/lt-hash.ts +0 -61
  198. package/src/Utils/make-mutex.ts +0 -44
  199. package/src/Utils/messages-media.ts +0 -847
  200. package/src/Utils/messages.ts +0 -956
  201. package/src/Utils/noise-handler.ts +0 -197
  202. package/src/Utils/process-message.ts +0 -414
  203. package/src/Utils/signal.ts +0 -177
  204. package/src/Utils/use-multi-file-auth-state.ts +0 -90
  205. package/src/Utils/validate-connection.ts +0 -238
  206. package/src/WABinary/constants.ts +0 -42
  207. package/src/WABinary/decode.ts +0 -265
  208. package/src/WABinary/encode.ts +0 -236
  209. package/src/WABinary/generic-utils.ts +0 -121
  210. package/src/WABinary/index.ts +0 -5
  211. package/src/WABinary/jid-utils.ts +0 -68
  212. package/src/WABinary/types.ts +0 -17
  213. package/src/WAM/BinaryInfo.ts +0 -12
  214. package/src/WAM/constants.ts +0 -15382
  215. package/src/WAM/encode.ts +0 -174
  216. package/src/WAM/index.ts +0 -3
  217. package/src/gifted +0 -1
  218. package/src/index.ts +0 -13
  219. /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
  220. /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
  221. /package/{src → lib}/Store/index.js +0 -0
  222. /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
  223. /package/{src → lib}/Types/Auth.js +0 -0
  224. /package/{src → lib}/Types/Call.js +0 -0
  225. /package/{src → lib}/Types/Chat.js +0 -0
  226. /package/{src → lib}/Types/Contact.js +0 -0
  227. /package/{src → lib}/Types/Events.js +0 -0
  228. /package/{src → lib}/Types/GroupMetadata.js +0 -0
  229. /package/{src → lib}/Types/Label.js +0 -0
  230. /package/{src → lib}/Types/LabelAssociation.js +0 -0
  231. /package/{src → lib}/Types/Message.js +0 -0
  232. /package/{src → lib}/Types/Newsletter.js +0 -0
  233. /package/{src → lib}/Types/Product.js +0 -0
  234. /package/{src → lib}/Types/Signal.js +0 -0
  235. /package/{src → lib}/Types/Socket.js +0 -0
  236. /package/{src → lib}/Types/State.js +0 -0
  237. /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
  238. /package/{src → lib}/Types/index.js +0 -0
  239. /package/{src → lib}/Utils/index.js +0 -0
  240. /package/{src → lib}/Utils/logger.js +0 -0
  241. /package/{src → lib}/Utils/lt-hash.js +0 -0
  242. /package/{src → lib}/Utils/noise-handler.js +0 -0
  243. /package/{src → lib}/WABinary/constants.js +0 -0
  244. /package/{src → lib}/WABinary/decode.js +0 -0
  245. /package/{src → lib}/WABinary/generic-utils.js +0 -0
  246. /package/{src → lib}/WABinary/index.js +0 -0
  247. /package/{src → lib}/WABinary/jid-utils.js +0 -0
  248. /package/{src → lib}/WAM/BinaryInfo.js +0 -0
  249. /package/{src → lib}/WAM/constants.js +0 -0
  250. /package/{src → lib}/WAM/encode.js +0 -0
  251. /package/{src → lib}/WAM/index.js +0 -0
@@ -1,20 +1,4 @@
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
- };
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
2
  Object.defineProperty(exports, "__esModule", { value: true });
19
3
  exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
20
4
  exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
@@ -198,53 +182,41 @@ exports.parseProductNode = parseProductNode;
198
182
  /**
199
183
  * Uploads images not already uploaded to WA's servers
200
184
  */
201
- function uploadingNecessaryImagesOfProduct(product_1, waUploadToServer_1) {
202
- return __awaiter(this, arguments, void 0, function* (product, waUploadToServer, timeoutMs = 30000) {
203
- product = Object.assign(Object.assign({}, product), { images: product.images ? yield (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs) : product.images });
204
- return product;
205
- });
185
+ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
186
+ product = {
187
+ ...product,
188
+ images: product.images ? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs) : product.images
189
+ };
190
+ return product;
206
191
  }
207
192
  /**
208
193
  * Uploads images not already uploaded to WA's servers
209
194
  */
210
- const uploadingNecessaryImages = (images_1, waUploadToServer_1, ...args_1) => __awaiter(void 0, [images_1, waUploadToServer_1, ...args_1], void 0, function* (images, waUploadToServer, timeoutMs = 30000) {
211
- const results = yield Promise.all(images.map((img) => __awaiter(void 0, void 0, void 0, function* () {
212
- var _a, e_1, _b, _c;
195
+ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
196
+ const results = await Promise.all(images.map(async (img) => {
213
197
  if ('url' in img) {
214
198
  const url = img.url.toString();
215
199
  if (url.includes('.whatsapp.net')) {
216
200
  return { url };
217
201
  }
218
202
  }
219
- const { stream } = yield (0, messages_media_1.getStream)(img);
203
+ const { stream } = await (0, messages_media_1.getStream)(img);
220
204
  const hasher = (0, crypto_1.createHash)('sha256');
221
205
  const contentBlocks = [];
222
- try {
223
- for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a; _d = true) {
224
- _c = stream_1_1.value;
225
- _d = false;
226
- const block = _c;
227
- hasher.update(block);
228
- contentBlocks.push(block);
229
- }
230
- }
231
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
232
- finally {
233
- try {
234
- if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
235
- }
236
- finally { if (e_1) throw e_1.error; }
206
+ for await (const block of stream) {
207
+ hasher.update(block);
208
+ contentBlocks.push(block);
237
209
  }
238
210
  const sha = hasher.digest('base64');
239
- const { directPath } = yield waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
211
+ const { directPath } = await waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
240
212
  mediaType: 'product-catalog-image',
241
213
  fileEncSha256B64: sha,
242
214
  timeoutMs
243
215
  });
244
216
  return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
245
- })));
217
+ }));
246
218
  return results;
247
- });
219
+ };
248
220
  exports.uploadingNecessaryImages = uploadingNecessaryImages;
249
221
  const parseImageUrls = (mediaNode) => {
250
222
  const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image');
@@ -0,0 +1,70 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import type { Logger } from 'pino';
3
+ import { proto } from '../../WAProto';
4
+ import { BaileysEventEmitter, ChatModification, ChatMutation, Contact, InitialAppStateSyncOptions, LTHashState, WAPatchCreate, WAPatchName } from '../Types';
5
+ import { BinaryNode } from '../WABinary';
6
+ type FetchAppStateSyncKey = (keyId: string) => Promise<proto.Message.IAppStateSyncKeyData | null | undefined>;
7
+ export type ChatMutationMap = {
8
+ [index: string]: ChatMutation;
9
+ };
10
+ export declare const newLTHashState: () => LTHashState;
11
+ export declare const encodeSyncdPatch: ({ type, index, syncAction, apiVersion, operation }: WAPatchCreate, myAppStateKeyId: string, state: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey) => Promise<{
12
+ patch: proto.ISyncdPatch;
13
+ state: LTHashState;
14
+ }>;
15
+ export declare const decodeSyncdMutations: (msgMutations: (proto.ISyncdMutation | proto.ISyncdRecord)[], initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
16
+ hash: any;
17
+ indexValueMap: {
18
+ [indexMacBase64: string]: {
19
+ valueMac: Uint8Array | Buffer;
20
+ };
21
+ };
22
+ }>;
23
+ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchName, initialState: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, onMutation: (mutation: ChatMutation) => void, validateMacs: boolean) => Promise<{
24
+ hash: any;
25
+ indexValueMap: {
26
+ [indexMacBase64: string]: {
27
+ valueMac: Uint8Array | Buffer;
28
+ };
29
+ };
30
+ }>;
31
+ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
32
+ critical_block: {
33
+ patches: proto.ISyncdPatch[];
34
+ hasMorePatches: boolean;
35
+ snapshot?: proto.ISyncdSnapshot;
36
+ };
37
+ critical_unblock_low: {
38
+ patches: proto.ISyncdPatch[];
39
+ hasMorePatches: boolean;
40
+ snapshot?: proto.ISyncdSnapshot;
41
+ };
42
+ regular_high: {
43
+ patches: proto.ISyncdPatch[];
44
+ hasMorePatches: boolean;
45
+ snapshot?: proto.ISyncdSnapshot;
46
+ };
47
+ regular_low: {
48
+ patches: proto.ISyncdPatch[];
49
+ hasMorePatches: boolean;
50
+ snapshot?: proto.ISyncdSnapshot;
51
+ };
52
+ regular: {
53
+ patches: proto.ISyncdPatch[];
54
+ hasMorePatches: boolean;
55
+ snapshot?: proto.ISyncdSnapshot;
56
+ };
57
+ }>;
58
+ export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<any>;
59
+ export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
60
+ export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
61
+ state: LTHashState;
62
+ mutationMap: ChatMutationMap;
63
+ }>;
64
+ export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
65
+ state: LTHashState;
66
+ mutationMap: ChatMutationMap;
67
+ }>;
68
+ export declare const chatModificationToAppPatch: (mod: ChatModification, jid: string) => WAPatchCreate;
69
+ export declare const processSyncAction: (syncAction: ChatMutation, ev: BaileysEventEmitter, me: Contact, initialSyncOpts?: InitialAppStateSyncOptions, logger?: Logger) => void;
70
+ export {};
@@ -1,20 +1,4 @@
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
- };
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
15
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
2
  Object.defineProperty(exports, "__esModule", { value: true });
19
3
  exports.processSyncAction = exports.chatModificationToAppPatch = exports.decodePatches = exports.decodeSyncdSnapshot = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.extractSyncdPatches = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.encodeSyncdPatch = exports.newLTHashState = void 0;
20
4
  const boom_1 = require("@hapi/boom");
@@ -62,7 +46,7 @@ const to64BitNetworkOrder = (e) => {
62
46
  return buff;
63
47
  };
64
48
  const makeLtHashGenerator = ({ indexValueMap, hash }) => {
65
- indexValueMap = Object.assign({}, indexValueMap);
49
+ indexValueMap = { ...indexValueMap };
66
50
  const addBuffs = [];
67
51
  const subBuffs = [];
68
52
  return {
@@ -115,13 +99,13 @@ const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
115
99
  };
116
100
  const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
117
101
  exports.newLTHashState = newLTHashState;
118
- const encodeSyncdPatch = (_a, myAppStateKeyId_1, state_1, getAppStateSyncKey_1) => __awaiter(void 0, [_a, myAppStateKeyId_1, state_1, getAppStateSyncKey_1], void 0, function* ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) {
119
- const key = !!myAppStateKeyId ? yield getAppStateSyncKey(myAppStateKeyId) : undefined;
102
+ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
103
+ const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
120
104
  if (!key) {
121
105
  throw new boom_1.Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
122
106
  }
123
107
  const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
124
- state = Object.assign(Object.assign({}, state), { indexValueMap: Object.assign({}, state.indexValueMap) });
108
+ state = { ...state, indexValueMap: { ...state.indexValueMap } };
125
109
  const indexBuffer = Buffer.from(JSON.stringify(index));
126
110
  const dataProto = WAProto_1.proto.SyncActionData.fromObject({
127
111
  index: indexBuffer,
@@ -162,9 +146,9 @@ const encodeSyncdPatch = (_a, myAppStateKeyId_1, state_1, getAppStateSyncKey_1)
162
146
  const base64Index = indexMac.toString('base64');
163
147
  state.indexValueMap[base64Index] = { valueMac };
164
148
  return { patch, state };
165
- });
149
+ };
166
150
  exports.encodeSyncdPatch = encodeSyncdPatch;
167
- const decodeSyncdMutations = (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => __awaiter(void 0, void 0, void 0, function* () {
151
+ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
168
152
  const ltGenerator = makeLtHashGenerator(initialState);
169
153
  // indexKey used to HMAC sign record.index.blob
170
154
  // valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
@@ -174,7 +158,7 @@ const decodeSyncdMutations = (msgMutations, initialState, getAppStateSyncKey, on
174
158
  // otherwise, if it's only a record -- it'll be a SET mutation
175
159
  const operation = 'operation' in msgMutation ? msgMutation.operation : WAProto_1.proto.SyncdMutation.SyncdOperation.SET;
176
160
  const record = ('record' in msgMutation && !!msgMutation.record) ? msgMutation.record : msgMutation;
177
- const key = yield getKey(record.keyId.id);
161
+ const key = await getKey(record.keyId.id);
178
162
  const content = Buffer.from(record.value.blob);
179
163
  const encContent = content.slice(0, -32);
180
164
  const ogValueMac = content.slice(-32);
@@ -201,22 +185,20 @@ const decodeSyncdMutations = (msgMutations, initialState, getAppStateSyncKey, on
201
185
  });
202
186
  }
203
187
  return ltGenerator.finish();
204
- function getKey(keyId) {
205
- return __awaiter(this, void 0, void 0, function* () {
206
- const base64Key = Buffer.from(keyId).toString('base64');
207
- const keyEnc = yield getAppStateSyncKey(base64Key);
208
- if (!keyEnc) {
209
- throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 404, data: { msgMutations } });
210
- }
211
- return mutationKeys(keyEnc.keyData);
212
- });
188
+ async function getKey(keyId) {
189
+ const base64Key = Buffer.from(keyId).toString('base64');
190
+ const keyEnc = await getAppStateSyncKey(base64Key);
191
+ if (!keyEnc) {
192
+ throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 404, data: { msgMutations } });
193
+ }
194
+ return mutationKeys(keyEnc.keyData);
213
195
  }
214
- });
196
+ };
215
197
  exports.decodeSyncdMutations = decodeSyncdMutations;
216
- const decodeSyncdPatch = (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => __awaiter(void 0, void 0, void 0, function* () {
198
+ const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
217
199
  if (validateMacs) {
218
200
  const base64Key = Buffer.from(msg.keyId.id).toString('base64');
219
- const mainKeyObj = yield getAppStateSyncKey(base64Key);
201
+ const mainKeyObj = await getAppStateSyncKey(base64Key);
220
202
  if (!mainKeyObj) {
221
203
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
222
204
  }
@@ -227,15 +209,15 @@ const decodeSyncdPatch = (msg, name, initialState, getAppStateSyncKey, onMutatio
227
209
  throw new boom_1.Boom('Invalid patch mac');
228
210
  }
229
211
  }
230
- const result = yield (0, exports.decodeSyncdMutations)(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
212
+ const result = await (0, exports.decodeSyncdMutations)(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
231
213
  return result;
232
- });
214
+ };
233
215
  exports.decodeSyncdPatch = decodeSyncdPatch;
234
- const extractSyncdPatches = (result, options) => __awaiter(void 0, void 0, void 0, function* () {
216
+ const extractSyncdPatches = async (result, options) => {
235
217
  const syncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'sync');
236
218
  const collectionNodes = (0, WABinary_1.getBinaryNodeChildren)(syncNode, 'collection');
237
219
  const final = {};
238
- yield Promise.all(collectionNodes.map((collectionNode) => __awaiter(void 0, void 0, void 0, function* () {
220
+ await Promise.all(collectionNodes.map(async (collectionNode) => {
239
221
  const patchesNode = (0, WABinary_1.getBinaryNodeChild)(collectionNode, 'patches');
240
222
  const patches = (0, WABinary_1.getBinaryNodeChildren)(patchesNode || collectionNode, 'patch');
241
223
  const snapshotNode = (0, WABinary_1.getBinaryNodeChild)(collectionNode, 'snapshot');
@@ -248,7 +230,7 @@ const extractSyncdPatches = (result, options) => __awaiter(void 0, void 0, void
248
230
  snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
249
231
  }
250
232
  const blobRef = WAProto_1.proto.ExternalBlobReference.decode(snapshotNode.content);
251
- const data = yield (0, exports.downloadExternalBlob)(blobRef, options);
233
+ const data = await (0, exports.downloadExternalBlob)(blobRef, options);
252
234
  snapshot = WAProto_1.proto.SyncdSnapshot.decode(data);
253
235
  }
254
236
  for (let { content } of patches) {
@@ -264,45 +246,32 @@ const extractSyncdPatches = (result, options) => __awaiter(void 0, void 0, void
264
246
  }
265
247
  }
266
248
  final[name] = { patches: syncds, hasMorePatches, snapshot };
267
- })));
249
+ }));
268
250
  return final;
269
- });
251
+ };
270
252
  exports.extractSyncdPatches = extractSyncdPatches;
271
- const downloadExternalBlob = (blob, options) => __awaiter(void 0, void 0, void 0, function* () {
272
- var _a, e_1, _b, _c;
273
- const stream = yield (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
253
+ const downloadExternalBlob = async (blob, options) => {
254
+ const stream = await (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
274
255
  const bufferArray = [];
275
- try {
276
- for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a; _d = true) {
277
- _c = stream_1_1.value;
278
- _d = false;
279
- const chunk = _c;
280
- bufferArray.push(chunk);
281
- }
282
- }
283
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
284
- finally {
285
- try {
286
- if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
287
- }
288
- finally { if (e_1) throw e_1.error; }
256
+ for await (const chunk of stream) {
257
+ bufferArray.push(chunk);
289
258
  }
290
259
  return Buffer.concat(bufferArray);
291
- });
260
+ };
292
261
  exports.downloadExternalBlob = downloadExternalBlob;
293
- const downloadExternalPatch = (blob, options) => __awaiter(void 0, void 0, void 0, function* () {
294
- const buffer = yield (0, exports.downloadExternalBlob)(blob, options);
262
+ const downloadExternalPatch = async (blob, options) => {
263
+ const buffer = await (0, exports.downloadExternalBlob)(blob, options);
295
264
  const syncData = WAProto_1.proto.SyncdMutations.decode(buffer);
296
265
  return syncData;
297
- });
266
+ };
298
267
  exports.downloadExternalPatch = downloadExternalPatch;
299
- const decodeSyncdSnapshot = (name_1, snapshot_1, getAppStateSyncKey_1, minimumVersionNumber_1, ...args_1) => __awaiter(void 0, [name_1, snapshot_1, getAppStateSyncKey_1, minimumVersionNumber_1, ...args_1], void 0, function* (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) {
268
+ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
300
269
  const newState = (0, exports.newLTHashState)();
301
270
  newState.version = (0, generics_1.toNumber)(snapshot.version.version);
302
271
  const mutationMap = {};
303
272
  const areMutationsRequired = typeof minimumVersionNumber === 'undefined'
304
273
  || newState.version > minimumVersionNumber;
305
- const { hash, indexValueMap } = yield (0, exports.decodeSyncdMutations)(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
274
+ const { hash, indexValueMap } = await (0, exports.decodeSyncdMutations)(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
306
275
  ? (mutation) => {
307
276
  var _a;
308
277
  const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
@@ -313,7 +282,7 @@ const decodeSyncdSnapshot = (name_1, snapshot_1, getAppStateSyncKey_1, minimumVe
313
282
  newState.indexValueMap = indexValueMap;
314
283
  if (validateMacs) {
315
284
  const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
316
- const keyEnc = yield getAppStateSyncKey(base64Key);
285
+ const keyEnc = await getAppStateSyncKey(base64Key);
317
286
  if (!keyEnc) {
318
287
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
319
288
  }
@@ -327,25 +296,27 @@ const decodeSyncdSnapshot = (name_1, snapshot_1, getAppStateSyncKey_1, minimumVe
327
296
  state: newState,
328
297
  mutationMap
329
298
  };
330
- });
299
+ };
331
300
  exports.decodeSyncdSnapshot = decodeSyncdSnapshot;
332
- const decodePatches = (name_1, syncds_1, initial_1, getAppStateSyncKey_1, options_1, minimumVersionNumber_1, logger_1, ...args_1) => __awaiter(void 0, [name_1, syncds_1, initial_1, getAppStateSyncKey_1, options_1, minimumVersionNumber_1, logger_1, ...args_1], void 0, function* (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) {
301
+ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
333
302
  var _a;
334
- const newState = Object.assign(Object.assign({}, initial), { indexValueMap: Object.assign({}, initial.indexValueMap) });
303
+ const newState = {
304
+ ...initial,
305
+ indexValueMap: { ...initial.indexValueMap }
306
+ };
335
307
  const mutationMap = {};
336
- for (let i = 0; i < syncds.length; i++) {
337
- const syncd = syncds[i];
308
+ for (const syncd of syncds) {
338
309
  const { version, keyId, snapshotMac } = syncd;
339
310
  if (syncd.externalMutations) {
340
311
  logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
341
- const ref = yield (0, exports.downloadExternalPatch)(syncd.externalMutations, options);
312
+ const ref = await (0, exports.downloadExternalPatch)(syncd.externalMutations, options);
342
313
  logger === null || logger === void 0 ? void 0 : logger.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
343
314
  (_a = syncd.mutations) === null || _a === void 0 ? void 0 : _a.push(...ref.mutations);
344
315
  }
345
316
  const patchVersion = (0, generics_1.toNumber)(version.version);
346
317
  newState.version = patchVersion;
347
318
  const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
348
- const decodeResult = yield (0, exports.decodeSyncdPatch)(syncd, name, newState, getAppStateSyncKey, shouldMutate
319
+ const decodeResult = await (0, exports.decodeSyncdPatch)(syncd, name, newState, getAppStateSyncKey, shouldMutate
349
320
  ? mutation => {
350
321
  var _a;
351
322
  const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
@@ -356,7 +327,7 @@ const decodePatches = (name_1, syncds_1, initial_1, getAppStateSyncKey_1, option
356
327
  newState.indexValueMap = decodeResult.indexValueMap;
357
328
  if (validateMacs) {
358
329
  const base64Key = Buffer.from(keyId.id).toString('base64');
359
- const keyEnc = yield getAppStateSyncKey(base64Key);
330
+ const keyEnc = await getAppStateSyncKey(base64Key);
360
331
  if (!keyEnc) {
361
332
  throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
362
333
  }
@@ -370,7 +341,7 @@ const decodePatches = (name_1, syncds_1, initial_1, getAppStateSyncKey_1, option
370
341
  syncd.mutations = [];
371
342
  }
372
343
  return { state: newState, mutationMap };
373
- });
344
+ };
374
345
  exports.decodePatches = decodePatches;
375
346
  const chatModificationToAppPatch = (mod, jid) => {
376
347
  const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
@@ -446,25 +417,31 @@ const chatModificationToAppPatch = (mod, jid) => {
446
417
  operation: OP.SET
447
418
  };
448
419
  }
420
+ else if ('deleteForMe' in mod) {
421
+ const { timestamp, key, deleteMedia } = mod.deleteForMe;
422
+ patch = {
423
+ syncAction: {
424
+ deleteMessageForMeAction: {
425
+ deleteMedia,
426
+ messageTimestamp: timestamp
427
+ }
428
+ },
429
+ index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
430
+ type: 'regular_high',
431
+ apiVersion: 3,
432
+ operation: OP.SET
433
+ };
434
+ }
449
435
  else if ('clear' in mod) {
450
- if (mod.clear === 'all') {
451
- throw new boom_1.Boom('not supported');
452
- }
453
- else {
454
- const key = mod.clear.messages[0];
455
- patch = {
456
- syncAction: {
457
- deleteMessageForMeAction: {
458
- deleteMedia: false,
459
- messageTimestamp: key.timestamp
460
- }
461
- },
462
- index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
463
- type: 'regular_high',
464
- apiVersion: 3,
465
- operation: OP.SET
466
- };
467
- }
436
+ patch = {
437
+ syncAction: {
438
+ clearChatAction: {} // add message range later
439
+ },
440
+ index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
441
+ type: 'regular_high',
442
+ apiVersion: 6,
443
+ operation: OP.SET
444
+ };
468
445
  }
469
446
  else if ('pin' in mod) {
470
447
  patch = {
@@ -519,6 +496,22 @@ const chatModificationToAppPatch = (mod, jid) => {
519
496
  operation: OP.SET,
520
497
  };
521
498
  }
499
+ else if ('addLabel' in mod) {
500
+ patch = {
501
+ syncAction: {
502
+ labelEditAction: {
503
+ name: mod.addLabel.name,
504
+ color: mod.addLabel.color,
505
+ predefinedId: mod.addLabel.predefinedId,
506
+ deleted: mod.addLabel.deleted
507
+ }
508
+ },
509
+ index: ['label_edit', mod.addLabel.id],
510
+ type: 'regular',
511
+ apiVersion: 3,
512
+ operation: OP.SET,
513
+ };
514
+ }
522
515
  else if ('addChatLabel' in mod) {
523
516
  patch = {
524
517
  syncAction: {
@@ -666,7 +659,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
666
659
  else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
667
660
  const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
668
661
  if (name && (me === null || me === void 0 ? void 0 : me.name) !== name) {
669
- ev.emit('creds.update', { me: Object.assign(Object.assign({}, me), { name }) });
662
+ ev.emit('creds.update', { me: { ...me, name } });
670
663
  }
671
664
  }
672
665
  else if (action === null || action === void 0 ? void 0 : action.pinAction) {
@@ -0,0 +1,40 @@
1
+ import { KeyPair } from '../Types';
2
+ /** prefix version byte to the pub keys, required for some curve crypto functions */
3
+ export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => any;
4
+ export declare const Curve: {
5
+ generateKeyPair: () => KeyPair;
6
+ sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => any;
7
+ sign: (privateKey: Uint8Array, buf: Uint8Array) => any;
8
+ verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
9
+ };
10
+ export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
11
+ keyPair: KeyPair;
12
+ signature: any;
13
+ keyId: number;
14
+ };
15
+ /**
16
+ * encrypt AES 256 GCM;
17
+ * where the tag tag is suffixed to the ciphertext
18
+ * */
19
+ export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
20
+ /**
21
+ * decrypt AES 256 GCM;
22
+ * where the auth tag is suffixed to the ciphertext
23
+ * */
24
+ export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): any;
25
+ export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
26
+ export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): any;
27
+ /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
28
+ export declare function aesDecrypt(buffer: Buffer, key: Buffer): any;
29
+ /** decrypt AES 256 CBC */
30
+ export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
31
+ export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): any;
32
+ export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): any;
33
+ export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): any;
34
+ export declare function sha256(buffer: Buffer): any;
35
+ export declare function md5(buffer: Buffer): any;
36
+ export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
37
+ salt?: Buffer;
38
+ info?: string;
39
+ }): any;
40
+ export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<any>;
@@ -53,7 +53,9 @@ exports.derivePairingCodeKey = derivePairingCodeKey;
53
53
  const crypto_1 = require("crypto");
54
54
  const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
55
55
  const libsignal = __importStar(require("libsignal"));
56
+ const util_1 = require("util");
56
57
  const Defaults_1 = require("../Defaults");
58
+ const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
57
59
  /** prefix version byte to the pub keys, required for some curve crypto functions */
58
60
  const generateSignalPubKey = (pubKey) => (pubKey.length === 33
59
61
  ? pubKey
@@ -156,6 +158,6 @@ function md5(buffer) {
156
158
  function hkdf(buffer, expandedLength, info) {
157
159
  return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
158
160
  }
159
- function derivePairingCodeKey(pairingCode, salt) {
160
- return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
161
+ async function derivePairingCodeKey(pairingCode, salt) {
162
+ return await pbkdf2Promise(pairingCode, salt, 2 << 16, 32, 'sha256');
161
163
  }
@@ -0,0 +1,36 @@
1
+ import { Logger } from 'pino';
2
+ import { proto } from '../../WAProto';
3
+ import { SignalRepository } from '../Types';
4
+ import { BinaryNode } from '../WABinary';
5
+ export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
6
+ export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
7
+ export declare const NACK_REASONS: {
8
+ ParsingError: number;
9
+ UnrecognizedStanza: number;
10
+ UnrecognizedStanzaClass: number;
11
+ UnrecognizedStanzaType: number;
12
+ InvalidProtobuf: number;
13
+ InvalidHostedCompanionStanza: number;
14
+ MissingMessageSecret: number;
15
+ SignalErrorOldCounter: number;
16
+ MessageDeletedOnPeer: number;
17
+ UnhandledError: number;
18
+ UnsupportedAdminRevoke: number;
19
+ UnsupportedLIDGroup: number;
20
+ DBOperationFailed: number;
21
+ };
22
+ /**
23
+ * Decode the received node as a message.
24
+ * @note this will only parse the message, not decrypt it
25
+ */
26
+ export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
27
+ fullMessage: proto.IWebMessageInfo;
28
+ author: string;
29
+ sender: string;
30
+ };
31
+ export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: Logger) => {
32
+ fullMessage: proto.IWebMessageInfo;
33
+ category: string;
34
+ author: string;
35
+ decrypt(): Promise<void>;
36
+ };