sanka-baileyss 2.3.2 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/WAProto/BotMetadata/BotMetadata.d.ts +594 -1
  2. package/WAProto/BotMetadata/BotMetadata.js +1910 -148
  3. package/WAProto/BotMetadata/BotMetadata.proto +36 -0
  4. package/WAProto/E2E/E2E.d.ts +570 -6
  5. package/WAProto/E2E/E2E.js +1591 -26
  6. package/WAProto/E2E/E2E.proto +10 -1
  7. package/WAProto/HistorySync/HistorySync.d.ts +806 -6
  8. package/WAProto/HistorySync/HistorySync.js +2193 -29
  9. package/WAProto/HistorySync/HistorySync.proto +2 -1
  10. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +570 -6
  11. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1591 -26
  12. package/WAProto/StatusAttributions/StatusAttributions.d.ts +2 -1
  13. package/WAProto/StatusAttributions/StatusAttributions.js +7 -0
  14. package/WAProto/StatusAttributions/StatusAttributions.proto +1 -0
  15. package/WAProto/SyncAction/SyncAction.d.ts +230 -0
  16. package/WAProto/SyncAction/SyncAction.js +578 -2
  17. package/WAProto/SyncAction/SyncAction.proto +13 -1
  18. package/WAProto/Web/Web.d.ts +570 -6
  19. package/WAProto/Web/Web.js +1591 -26
  20. package/lib/Defaults/baileys-version.json +2 -2
  21. package/lib/Defaults/index.d.ts +42 -25
  22. package/lib/Defaults/index.js +6 -2
  23. package/lib/Signal/Group/sender-key-record.js +23 -28
  24. package/lib/Signal/libsignal.d.ts +1 -0
  25. package/lib/Socket/Client/index.js +13 -9
  26. package/lib/Socket/Client/types.d.ts +11 -10
  27. package/lib/Socket/Client/types.js +11 -7
  28. package/lib/Socket/Client/websocket.d.ts +9 -8
  29. package/lib/Socket/Client/websocket.js +52 -47
  30. package/lib/Socket/business.d.ts +185 -182
  31. package/lib/Socket/business.js +258 -249
  32. package/lib/Socket/chats.d.ts +90 -87
  33. package/lib/Socket/chats.js +1095 -888
  34. package/lib/Socket/community.d.ts +131 -0
  35. package/lib/Socket/community.js +369 -0
  36. package/lib/Socket/groups.d.ts +50 -41
  37. package/lib/Socket/groups.js +10 -3
  38. package/lib/Socket/index.d.ts +5 -1
  39. package/lib/Socket/index.js +19 -5
  40. package/lib/Socket/messages-recv.d.ts +6 -2
  41. package/lib/Socket/messages-recv.js +31 -8
  42. package/lib/Socket/messages-send.d.ts +5 -1
  43. package/lib/Socket/messages-send.js +1293 -1351
  44. package/lib/Socket/newsletter.d.ts +142 -135
  45. package/lib/Socket/newsletter.js +274 -230
  46. package/lib/Socket/socket.d.ts +37 -35
  47. package/lib/Socket/usync.d.ts +31 -30
  48. package/lib/Socket/usync.js +74 -62
  49. package/lib/Types/Auth.d.ts +89 -72
  50. package/lib/Types/Auth.js +1 -0
  51. package/lib/Types/Call.d.ts +11 -10
  52. package/lib/Types/Call.js +1 -0
  53. package/lib/Types/Chat.d.ts +85 -62
  54. package/lib/Types/Chat.js +4 -1
  55. package/lib/Types/Contact.js +1 -0
  56. package/lib/Types/Events.d.ts +209 -191
  57. package/lib/Types/Events.js +1 -0
  58. package/lib/Types/GroupMetadata.d.ts +12 -27
  59. package/lib/Types/GroupMetadata.js +1 -0
  60. package/lib/Types/Label.d.ts +41 -39
  61. package/lib/Types/Label.js +24 -21
  62. package/lib/Types/LabelAssociation.d.ts +18 -12
  63. package/lib/Types/LabelAssociation.js +6 -3
  64. package/lib/Types/Message.d.ts +3 -2
  65. package/lib/Types/Message.js +7 -3
  66. package/lib/Types/MexUpdates.d.ts +9 -0
  67. package/lib/Types/MexUpdates.js +18 -0
  68. package/lib/Types/Newsletter.d.ts +84 -67
  69. package/lib/Types/Newsletter.js +30 -23
  70. package/lib/Types/Product.d.ts +70 -56
  71. package/lib/Types/Product.js +1 -0
  72. package/lib/Types/Signal.d.ts +46 -35
  73. package/lib/Types/Signal.js +1 -0
  74. package/lib/Types/Socket.d.ts +105 -101
  75. package/lib/Types/Socket.js +1 -0
  76. package/lib/Types/State.d.ts +37 -23
  77. package/lib/Types/State.js +13 -1
  78. package/lib/Types/USync.d.ts +21 -20
  79. package/lib/Types/USync.js +1 -0
  80. package/lib/Types/index.d.ts +51 -42
  81. package/lib/Types/index.js +25 -19
  82. package/lib/Utils/auth-utils.d.ts +14 -11
  83. package/lib/Utils/auth-utils.js +189 -182
  84. package/lib/Utils/baileys-event-stream.d.ts +12 -10
  85. package/lib/Utils/baileys-event-stream.js +52 -46
  86. package/lib/Utils/business.d.ts +15 -8
  87. package/lib/Utils/business.js +229 -217
  88. package/lib/Utils/chat-utils.d.ts +22 -12
  89. package/lib/Utils/chat-utils.js +57 -27
  90. package/lib/Utils/crypto.d.ts +31 -15
  91. package/lib/Utils/crypto.js +136 -107
  92. package/lib/Utils/decode-wa-message.d.ts +34 -245
  93. package/lib/Utils/decode-wa-message.js +205 -217
  94. package/lib/Utils/event-buffer.d.ts +30 -26
  95. package/lib/Utils/event-buffer.js +519 -515
  96. package/lib/Utils/history.d.ts +2 -8
  97. package/lib/Utils/index.js +13 -9
  98. package/lib/Utils/link-preview.d.ts +16 -14
  99. package/lib/Utils/link-preview.js +100 -92
  100. package/lib/Utils/logger.d.ts +9 -7
  101. package/lib/Utils/logger.js +1 -1
  102. package/lib/Utils/lt-hash.d.ts +10 -8
  103. package/lib/Utils/lt-hash.js +49 -44
  104. package/lib/Utils/make-mutex.d.ts +4 -2
  105. package/lib/Utils/make-mutex.js +43 -39
  106. package/lib/Utils/messages-media.d.ts +75 -50
  107. package/lib/Utils/messages.d.ts +60 -35
  108. package/lib/Utils/messages.js +87 -8
  109. package/lib/Utils/noise-handler.d.ts +13 -12
  110. package/lib/Utils/noise-handler.js +143 -138
  111. package/lib/Utils/process-message.d.ts +32 -24
  112. package/lib/Utils/process-message.js +387 -367
  113. package/lib/Utils/signal.d.ts +24 -15
  114. package/lib/Utils/signal.js +143 -131
  115. package/lib/Utils/use-mongo-file-auth-state.d.ts +3 -2
  116. package/lib/Utils/use-mongo-file-auth-state.js +72 -63
  117. package/lib/Utils/use-multi-file-auth-state.d.ts +9 -8
  118. package/lib/Utils/use-multi-file-auth-state.js +110 -102
  119. package/lib/Utils/use-single-file-auth-state.d.ts +8 -7
  120. package/lib/Utils/use-single-file-auth-state.js +66 -61
  121. package/lib/Utils/validate-connection.d.ts +5 -2
  122. package/lib/Utils/validate-connection.js +7 -6
  123. package/lib/WABinary/constants.d.ts +24 -21
  124. package/lib/WABinary/constants.js +1302 -31
  125. package/lib/WABinary/decode.d.ts +4 -1
  126. package/lib/WABinary/decode.js +267 -234
  127. package/lib/WABinary/encode.d.ts +1 -0
  128. package/lib/WABinary/encode.js +248 -226
  129. package/lib/WABinary/generic-utils.d.ts +13 -1
  130. package/lib/WABinary/generic-utils.js +113 -96
  131. package/lib/WABinary/index.js +13 -9
  132. package/lib/WABinary/jid-utils.d.ts +23 -4
  133. package/lib/WABinary/jid-utils.js +58 -39
  134. package/lib/WABinary/types.d.ts +15 -11
  135. package/lib/WABinary/types.js +1 -0
  136. package/lib/WAM/BinaryInfo.d.ts +14 -14
  137. package/lib/WAM/BinaryInfo.js +11 -8
  138. package/lib/WAM/constants.d.ts +34 -26
  139. package/lib/WAM/constants.js +15358 -15349
  140. package/lib/WAM/encode.d.ts +1 -0
  141. package/lib/WAM/encode.js +153 -144
  142. package/lib/WAM/index.js +13 -9
  143. package/lib/index.js +11 -11
  144. package/package.json +1 -66
  145. package/WASignalGroup/GroupProtocol.js +0 -1771
  146. package/WASignalGroup/ciphertext_message.js +0 -10
  147. package/WASignalGroup/group_cipher.js +0 -103
  148. package/WASignalGroup/group_session_builder.js +0 -39
  149. package/WASignalGroup/index.js +0 -5
  150. package/WASignalGroup/keyhelper.js +0 -17
  151. package/WASignalGroup/protobufs.js +0 -2
  152. package/WASignalGroup/queue_job.js +0 -64
  153. package/WASignalGroup/sender_chain_key.js +0 -38
  154. package/WASignalGroup/sender_key_distribution_message.js +0 -68
  155. package/WASignalGroup/sender_key_message.js +0 -79
  156. package/WASignalGroup/sender_key_name.js +0 -59
  157. package/WASignalGroup/sender_key_record.js +0 -47
  158. package/WASignalGroup/sender_key_state.js +0 -110
  159. package/WASignalGroup/sender_message_key.js +0 -30
@@ -6,10 +6,7 @@ export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotificati
6
6
 
7
7
  export declare const processHistoryMessage: (item: proto.IHistorySync) => {
8
8
  chats: Chat[]
9
- contacts: Array<Contact & {
10
- lid?: string
11
- jid?: string
12
- }>
9
+ contacts: Contact[]
13
10
  messages: proto.IWebMessageInfo[]
14
11
  syncType: proto.HistorySync.HistorySyncType
15
12
  progress: number | null | undefined
@@ -17,10 +14,7 @@ export declare const processHistoryMessage: (item: proto.IHistorySync) => {
17
14
 
18
15
  export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
19
16
  chats: Chat[]
20
- contacts: Array<Contact & {
21
- lid?: string
22
- jid?: string
23
- }>
17
+ contacts: Contact[]
24
18
  messages: proto.IWebMessageInfo[]
25
19
  syncType: proto.HistorySync.HistorySyncType
26
20
  progress: number | null | undefined
@@ -1,19 +1,23 @@
1
1
  "use strict"
2
+
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k
4
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k] } }
7
- }
8
- Object.defineProperty(o, k2, desc)
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
9
10
  }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k
11
- o[k2] = m[k]
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
12
13
  }))
14
+
13
15
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
15
17
  }
18
+
16
19
  Object.defineProperty(exports, "__esModule", { value: true })
20
+
17
21
  __exportStar(require("./generics"), exports)
18
22
  __exportStar(require("./decode-wa-message"), exports)
19
23
  __exportStar(require("./messages"), exports)
@@ -1,21 +1,23 @@
1
1
  import { AxiosRequestConfig } from 'axios'
2
2
  import { WAMediaUploadFunction, WAUrlInfo } from '../Types'
3
3
  import { ILogger } from './logger'
4
+
4
5
  export type URLGenerationOptions = {
5
- thumbnailWidth: number
6
- fetchOpts: {
7
- /** Timeout in ms */
8
- timeout: number
9
- proxyUrl?: string
10
- headers?: AxiosRequestConfig<{}>['headers']
11
- }
12
- uploadImage?: WAMediaUploadFunction
13
- logger?: ILogger
6
+ thumbnailWidth: number
7
+ fetchOpts: {
8
+ /** Timeout in ms */
9
+ timeout: number
10
+ proxyUrl?: string
11
+ headers?: AxiosRequestConfig<{}>['headers']
12
+ }
13
+ uploadImage?: WAMediaUploadFunction
14
+ logger?: ILogger
14
15
  }
16
+
15
17
  /**
16
- * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
17
- * Return undefined if the fetch failed or no URL was found
18
- * @param text first matched URL in text
19
- * @returns the URL info required to generate link preview
20
- */
18
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
19
+ * Return undefined if the fetch failed or no URL was found
20
+ * @param text first matched URL in text
21
+ * @returns the URL info required to generate link preview
22
+ */
21
23
  export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>
@@ -1,112 +1,120 @@
1
1
  "use strict"
2
+
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k
4
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k] } }
7
- }
8
- Object.defineProperty(o, k2, desc)
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
9
10
  }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k
11
- o[k2] = m[k]
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
12
13
  }))
14
+
13
15
  var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v })
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v })
15
17
  }) : function(o, v) {
16
- o["default"] = v
18
+ o["default"] = v
17
19
  })
20
+
18
21
  var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod
20
- var result = {}
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
22
- __setModuleDefault(result, mod)
23
- return result
22
+ if (mod && mod.__esModule) return mod
23
+ var result = {}
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
25
+ __setModuleDefault(result, mod)
26
+ return result
24
27
  }
28
+
25
29
  Object.defineProperty(exports, "__esModule", { value: true })
30
+
26
31
  const messages_1 = require("./messages")
27
32
  const messages_media_1 = require("./messages-media")
28
33
  const THUMBNAIL_WIDTH_PX = 192
34
+
29
35
  /** Fetches an image and generates a thumbnail for it */
30
36
  const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
31
- const stream = await messages_media_1.getHttpStream(url, fetchOpts)
32
- const result = await messages_media_1.extractImageThumb(stream, thumbnailWidth)
33
- return result
37
+ const stream = await messages_media_1.getHttpStream(url, fetchOpts)
38
+ const result = await messages_media_1.extractImageThumb(stream, thumbnailWidth)
39
+ return result
34
40
  }
41
+
35
42
  /**
36
- * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
37
- * Return undefined if the fetch failed or no URL was found
38
- * @param text first matched URL in text
39
- * @returns the URL info required to generate link preview
40
- */
43
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
44
+ * Return undefined if the fetch failed or no URL was found
45
+ * @param text first matched URL in text
46
+ * @returns the URL info required to generate link preview
47
+ */
41
48
  const getUrlInfo = async (text, opts = { thumbnailWidth: THUMBNAIL_WIDTH_PX, fetchOpts: { timeout: 3000 }}) => {
42
- try {
43
- const retries = 0
44
- const maxRetry = 5
45
- const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')))
46
- let previewLink = text
47
- if (!text.startsWith('https://') && !text.startsWith('http://')) {
48
- previewLink = 'https://' + previewLink
49
- }
50
- const info = await getLinkPreview(previewLink, {
51
- ...opts.fetchOpts,
52
- followRedirects: 'follow',
53
- handleRedirects: (baseURL, forwardedURL) => {
54
- const urlObj = new URL(baseURL)
55
- const forwardedURLObj = new URL(forwardedURL)
56
- if (retries >= maxRetry) {
57
- return false
58
- }
59
- if (forwardedURLObj.hostname === urlObj.hostname
60
- || forwardedURLObj.hostname === 'www.' + urlObj.hostname
61
- || 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
62
- retries + 1
63
- return true
64
- }
65
- else {
66
- return false
67
- }
68
- },
69
- headers: opts.fetchOpts
70
- })
71
- if (info && 'title' in info && info.title) {
72
- const [image] = info.images
73
- const urlInfo = {
74
- 'canonical-url': info.url,
75
- 'matched-text': text,
76
- title: info.title,
77
- description: info.description,
78
- originalThumbnailUrl: image
79
- }
80
- if (opts.uploadImage) {
81
- const { imageMessage } = await messages_1.prepareWAMessageMedia({ image: { url: image } }, {
82
- upload: opts.uploadImage,
83
- mediaTypeOverride: 'thumbnail-link',
84
- options: opts.fetchOpts
85
- })
86
- urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
87
- ? Buffer.from(imageMessage.jpegThumbnail)
88
- : undefined
89
- urlInfo.highQualityThumbnail = imageMessage || undefined
90
- }
91
- else {
92
- try {
93
- urlInfo.jpegThumbnail = image
94
- ? (await getCompressedJpegThumbnail(image, opts)).buffer
95
- : undefined
96
- }
97
- catch (error) {
98
- opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
99
- }
100
- }
101
- return urlInfo
102
- }
103
- }
104
- catch (error) {
105
- if (!error.message.includes('receive a valid')) {
106
- throw error
107
- }
108
- }
109
- }
49
+ try {
50
+ const retries = 0
51
+ const maxRetry = 5
52
+ const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')))
53
+ let previewLink = text
54
+ if (!text.startsWith('https://') && !text.startsWith('http://')) {
55
+ previewLink = 'https://' + previewLink
56
+ }
57
+ const info = await getLinkPreview(previewLink, {
58
+ ...opts.fetchOpts,
59
+ followRedirects: 'follow',
60
+ handleRedirects: (baseURL, forwardedURL) => {
61
+ const urlObj = new URL(baseURL)
62
+ const forwardedURLObj = new URL(forwardedURL)
63
+ if (retries >= maxRetry) {
64
+ return false
65
+ }
66
+ if (forwardedURLObj.hostname === urlObj.hostname
67
+ || forwardedURLObj.hostname === 'www.' + urlObj.hostname
68
+ || 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
69
+ retries + 1
70
+ return true
71
+ }
72
+ else {
73
+ return false
74
+ }
75
+ },
76
+ headers: opts.fetchOpts
77
+ })
78
+ if (info && 'title' in info && info.title) {
79
+ const [image] = info.images
80
+ const urlInfo = {
81
+ 'canonical-url': info.url,
82
+ 'matched-text': text,
83
+ title: info.title,
84
+ description: info.description,
85
+ originalThumbnailUrl: image
86
+ }
87
+ if (opts.uploadImage) {
88
+ const { imageMessage } = await messages_1.prepareWAMessageMedia({ image: { url: image } }, {
89
+ upload: opts.uploadImage,
90
+ mediaTypeOverride: 'thumbnail-link',
91
+ options: opts.fetchOpts
92
+ })
93
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail
94
+ ? Buffer.from(imageMessage.jpegThumbnail)
95
+ : undefined
96
+ urlInfo.highQualityThumbnail = imageMessage || undefined
97
+ }
98
+ else {
99
+ try {
100
+ urlInfo.jpegThumbnail = image
101
+ ? (await getCompressedJpegThumbnail(image, opts)).buffer
102
+ : undefined
103
+ }
104
+ catch (error) {
105
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
106
+ }
107
+ }
108
+ return urlInfo
109
+ }
110
+ }
111
+ catch (error) {
112
+ if (!error.message.includes('receive a valid')) {
113
+ throw error
114
+ }
115
+ }
116
+ }
117
+
110
118
  module.exports = {
111
- getUrlInfo
119
+ getUrlInfo
112
120
  }
@@ -1,11 +1,13 @@
1
1
  export interface ILogger {
2
- level: string
3
- child(obj: Record<string, unknown>): ILogger
4
- trace(obj: unknown, msg?: string): any
5
- debug(obj: unknown, msg?: string): any
6
- info(obj: unknown, msg?: string): any
7
- warn(obj: unknown, msg?: string): any
8
- error(obj: unknown, msg?: string): any
2
+ level: string
3
+ child(obj: Record<string, unknown>): ILogger
4
+ trace(obj: unknown, msg?: string): any
5
+ debug(obj: unknown, msg?: string): any
6
+ info(obj: unknown, msg?: string): any
7
+ warn(obj: unknown, msg?: string): any
8
+ error(obj: unknown, msg?: string): any
9
9
  }
10
+
10
11
  declare const _default: import("pino").Logger<never, boolean>
12
+
11
13
  export default _default
@@ -1,6 +1,6 @@
1
1
  "use strict"
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod }
3
+ return (mod && mod.__esModule) ? mod : { "default": mod }
4
4
  }
5
5
  Object.defineProperty(exports, "__esModule", { value: true })
6
6
  const pino_1 = __importDefault(require("pino"))
@@ -1,12 +1,14 @@
1
1
  declare class d {
2
- salt: string
3
- constructor(e: string)
4
- add(e: any, t: any): any
5
- subtract(e: any, t: any): any
6
- subtractThenAdd(e: any, t: any, r: any): any
7
- _addSingle(e: any, t: any): Promise<ArrayBuffer>
8
- _subtractSingle(e: any, t: any): Promise<ArrayBuffer>
9
- performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer
2
+ salt: string
3
+ constructor(e: string)
4
+ add(e: any, t: any): any
5
+ subtract(e: any, t: any): any
6
+ subtractThenAdd(e: any, t: any, r: any): any
7
+ _addSingle(e: any, t: any): Promise<ArrayBuffer>
8
+ _subtractSingle(e: any, t: any): Promise<ArrayBuffer>
9
+ performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer
10
10
  }
11
+
11
12
  export declare const LT_HASH_ANTI_TAMPERING: d
13
+
12
14
  export {}
@@ -1,53 +1,58 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
+
3
5
  const crypto_1 = require("./crypto")
6
+
4
7
  /**
5
- * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
6
- * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
7
- * if the same series of mutations was made sequentially.
8
- */
8
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
9
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
10
+ * if the same series of mutations was made sequentially.
11
+ */
9
12
  const o = 128
10
13
  class d {
11
- constructor(e) {
12
- this.salt = e
13
- }
14
- add(e, t) {
15
- var r = this
16
- for (const item of t) {
17
- e = r._addSingle(e, item)
18
- }
19
- return e
20
- }
21
- subtract(e, t) {
22
- var r = this
23
- for (const item of t) {
24
- e = r._subtractSingle(e, item)
25
- }
26
- return e
27
- }
28
- subtractThenAdd(e, t, r) {
29
- var n = this
30
- return n.add(n.subtract(e, r), t)
31
- }
32
- async _addSingle(e, t) {
33
- var r = this
34
- const n = new Uint8Array(await crypto_1.hkdf(Buffer.from(t), o, { info: r.salt })).buffer
35
- return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t))
36
- }
37
- async _subtractSingle(e, t) {
38
- var r = this
39
- const n = new Uint8Array(await crypto_1.hkdf(Buffer.from(t), o, { info: r.salt })).buffer
40
- return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t))
41
- }
42
- performPointwiseWithOverflow(e, t, r) {
43
- const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a)
44
- for (let e = 0; e < n.byteLength; e += 2) {
45
- s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0)
46
- }
47
- return a
48
- }
49
- }
14
+ constructor(e) {
15
+ this.salt = e
16
+ }
17
+ add(e, t) {
18
+ var r = this
19
+ for (const item of t) {
20
+ e = r._addSingle(e, item)
21
+ }
22
+ return e
23
+ }
24
+ subtract(e, t) {
25
+ var r = this
26
+ for (const item of t) {
27
+ e = r._subtractSingle(e, item)
28
+ }
29
+ return e
30
+ }
31
+ subtractThenAdd(e, t, r) {
32
+ var n = this
33
+ return n.add(n.subtract(e, r), t)
34
+ }
35
+ async _addSingle(e, t) {
36
+ var r = this
37
+ const n = new Uint8Array(await crypto_1.hkdf(Buffer.from(t), o, { info: r.salt })).buffer
38
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t))
39
+ }
40
+ async _subtractSingle(e, t) {
41
+ var r = this
42
+ const n = new Uint8Array(await crypto_1.hkdf(Buffer.from(t), o, { info: r.salt })).buffer
43
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t))
44
+ }
45
+ performPointwiseWithOverflow(e, t, r) {
46
+ const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a)
47
+ for (let e = 0; e < n.byteLength; e += 2) {
48
+ s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0)
49
+ }
50
+ return a
51
+ }
52
+ }
53
+
50
54
  const LT_HASH_ANTI_TAMPERING = new d('WhatsApp Patch Integrity')
55
+
51
56
  module.exports = {
52
- LT_HASH_ANTI_TAMPERING
57
+ LT_HASH_ANTI_TAMPERING
53
58
  }
@@ -1,7 +1,9 @@
1
1
  export declare const makeMutex: () => {
2
- mutex<T>(code: () => T | Promise<T>): Promise<T>
2
+ mutex<T>(code: () => T | Promise<T>): Promise<T>
3
3
  }
4
+
4
5
  export type Mutex = ReturnType<typeof makeMutex>
6
+
5
7
  export declare const makeKeyedMutex: () => {
6
- mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>
8
+ mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>
7
9
  }
@@ -1,45 +1,49 @@
1
1
  "use strict"
2
+
2
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
+
3
5
  const makeMutex = () => {
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
- let task = Promise.resolve()
6
- let taskTimeout
7
- return {
8
- mutex(code) {
9
- task = (async () => {
10
- // wait for the previous task to complete
11
- // if there is an error, we swallow so as to not block the queue
12
- try {
13
- await task
14
- }
15
- catch (_a) { }
16
- try {
17
- // execute the current task
18
- const result = await code()
19
- return result
20
- }
21
- finally {
22
- clearTimeout(taskTimeout)
23
- }
24
- })()
25
- // we replace the existing task, appending the new piece of execution to it
26
- // so the next task will have to wait for this one to finish
27
- return task
28
- },
29
- }
30
- }
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ let task = Promise.resolve()
8
+ let taskTimeout
9
+ return {
10
+ mutex(code) {
11
+ task = (async () => {
12
+ // wait for the previous task to complete
13
+ // if there is an error, we swallow so as to not block the queue
14
+ try {
15
+ await task
16
+ }
17
+ catch (_a) { }
18
+ try {
19
+ // execute the current task
20
+ const result = await code()
21
+ return result
22
+ }
23
+ finally {
24
+ clearTimeout(taskTimeout)
25
+ }
26
+ })()
27
+ // we replace the existing task, appending the new piece of execution to it
28
+ // so the next task will have to wait for this one to finish
29
+ return task
30
+ },
31
+ }
32
+ }
33
+
31
34
  const makeKeyedMutex = () => {
32
- const map = {}
33
- return {
34
- mutex(key, task) {
35
- if (!map[key]) {
36
- map[key] = makeMutex()
37
- }
38
- return map[key].mutex(task)
39
- }
40
- }
41
- }
35
+ const map = {}
36
+ return {
37
+ mutex(key, task) {
38
+ if (!map[key]) {
39
+ map[key] = makeMutex()
40
+ }
41
+ return map[key].mutex(task)
42
+ }
43
+ }
44
+ }
45
+
42
46
  module.exports = {
43
- makeMutex,
44
- makeKeyedMutex
47
+ makeMutex,
48
+ makeKeyedMutex
45
49
  }