dcodeindra-baileyspro 2.3.9

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 (286) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2534 -0
  3. package/WAProto/Adv/Adv.d.ts +518 -0
  4. package/WAProto/Adv/Adv.js +1734 -0
  5. package/WAProto/Adv/Adv.proto +36 -0
  6. package/WAProto/BotMetadata/BotMetadata.d.ts +5745 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +16291 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +463 -0
  9. package/WAProto/Cert/Cert.d.ts +497 -0
  10. package/WAProto/Cert/Cert.js +1503 -0
  11. package/WAProto/Cert/Cert.proto +28 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +391 -0
  13. package/WAProto/ChatLockSettings/ChatLockSettings.js +1155 -0
  14. package/WAProto/ChatLockSettings/ChatLockSettings.proto +7 -0
  15. package/WAProto/CompanionReg/CompanionReg.d.ts +1055 -0
  16. package/WAProto/CompanionReg/CompanionReg.js +3532 -0
  17. package/WAProto/CompanionReg/CompanionReg.proto +89 -0
  18. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +187 -0
  19. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +520 -0
  20. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +14 -0
  21. package/WAProto/E2E/E2E.d.ts +28417 -0
  22. package/WAProto/E2E/E2E.js +98438 -0
  23. package/WAProto/E2E/E2E.proto +2289 -0
  24. package/WAProto/Ephemeral/Ephemeral.d.ts +95 -0
  25. package/WAProto/Ephemeral/Ephemeral.js +269 -0
  26. package/WAProto/Ephemeral/Ephemeral.proto +6 -0
  27. package/WAProto/HistorySync/HistorySync.d.ts +40728 -0
  28. package/WAProto/HistorySync/HistorySync.js +142980 -0
  29. package/WAProto/HistorySync/HistorySync.proto +207 -0
  30. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +189 -0
  31. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +585 -0
  32. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +11 -0
  33. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +461 -0
  34. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +1559 -0
  35. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +37 -0
  36. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +29294 -0
  37. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +101732 -0
  38. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +76 -0
  39. package/WAProto/MmsRetry/MmsRetry.d.ts +200 -0
  40. package/WAProto/MmsRetry/MmsRetry.js +586 -0
  41. package/WAProto/MmsRetry/MmsRetry.proto +17 -0
  42. package/WAProto/Protocol/Protocol.d.ts +218 -0
  43. package/WAProto/Protocol/Protocol.js +701 -0
  44. package/WAProto/Protocol/Protocol.proto +20 -0
  45. package/WAProto/Reporting/Reporting.d.ts +301 -0
  46. package/WAProto/Reporting/Reporting.js +989 -0
  47. package/WAProto/Reporting/Reporting.proto +19 -0
  48. package/WAProto/ServerSync/ServerSync.d.ts +1050 -0
  49. package/WAProto/ServerSync/ServerSync.js +3176 -0
  50. package/WAProto/ServerSync/ServerSync.proto +59 -0
  51. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +1507 -0
  52. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +4756 -0
  53. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +88 -0
  54. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +617 -0
  55. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1940 -0
  56. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +38 -0
  57. package/WAProto/StatusAttributions/StatusAttributions.d.ts +636 -0
  58. package/WAProto/StatusAttributions/StatusAttributions.js +2037 -0
  59. package/WAProto/StatusAttributions/StatusAttributions.proto +61 -0
  60. package/WAProto/SyncAction/SyncAction.d.ts +7227 -0
  61. package/WAProto/SyncAction/SyncAction.js +22271 -0
  62. package/WAProto/SyncAction/SyncAction.proto +423 -0
  63. package/WAProto/UserPassword/UserPassword.d.ts +298 -0
  64. package/WAProto/UserPassword/UserPassword.js +898 -0
  65. package/WAProto/UserPassword/UserPassword.proto +27 -0
  66. package/WAProto/VnameCert/VnameCert.d.ts +658 -0
  67. package/WAProto/VnameCert/VnameCert.js +2225 -0
  68. package/WAProto/VnameCert/VnameCert.proto +60 -0
  69. package/WAProto/Wa6/Wa6.d.ts +1613 -0
  70. package/WAProto/Wa6/Wa6.js +6299 -0
  71. package/WAProto/Wa6/Wa6.proto +229 -0
  72. package/WAProto/Web/Web.d.ts +31718 -0
  73. package/WAProto/Web/Web.js +113402 -0
  74. package/WAProto/Web/Web.proto +545 -0
  75. package/WAProto/index.d.ts +49 -0
  76. package/WAProto/index.js +28 -0
  77. package/WASignalGroup/GroupProtocol.js +1771 -0
  78. package/WASignalGroup/ciphertext_message.js +10 -0
  79. package/WASignalGroup/group_cipher.js +103 -0
  80. package/WASignalGroup/group_session_builder.js +39 -0
  81. package/WASignalGroup/index.js +5 -0
  82. package/WASignalGroup/keyhelper.js +17 -0
  83. package/WASignalGroup/protobufs.js +2 -0
  84. package/WASignalGroup/queue_job.js +64 -0
  85. package/WASignalGroup/sender_chain_key.js +38 -0
  86. package/WASignalGroup/sender_key_distribution_message.js +68 -0
  87. package/WASignalGroup/sender_key_message.js +79 -0
  88. package/WASignalGroup/sender_key_name.js +59 -0
  89. package/WASignalGroup/sender_key_record.js +47 -0
  90. package/WASignalGroup/sender_key_state.js +110 -0
  91. package/WASignalGroup/sender_message_key.js +30 -0
  92. package/check-node-version.js +10 -0
  93. package/lib/Defaults/baileys-version.json +3 -0
  94. package/lib/Defaults/index.d.ts +51 -0
  95. package/lib/Defaults/index.js +108 -0
  96. package/lib/Defaults/phonenumber-mcc.json +223 -0
  97. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  98. package/lib/Signal/Group/ciphertext-message.js +19 -0
  99. package/lib/Signal/Group/group-session-builder.d.ts +17 -0
  100. package/lib/Signal/Group/group-session-builder.js +72 -0
  101. package/lib/Signal/Group/group_cipher.d.ts +19 -0
  102. package/lib/Signal/Group/group_cipher.js +99 -0
  103. package/lib/Signal/Group/index.d.ts +11 -0
  104. package/lib/Signal/Group/index.js +61 -0
  105. package/lib/Signal/Group/keyhelper.d.ts +16 -0
  106. package/lib/Signal/Group/keyhelper.js +66 -0
  107. package/lib/Signal/Group/queue-job.d.ts +1 -0
  108. package/lib/Signal/Group/queue-job.js +64 -0
  109. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  110. package/lib/Signal/Group/sender-chain-key.js +39 -0
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  112. package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
  113. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  114. package/lib/Signal/Group/sender-key-message.js +73 -0
  115. package/lib/Signal/Group/sender-key-name.d.ts +19 -0
  116. package/lib/Signal/Group/sender-key-name.js +59 -0
  117. package/lib/Signal/Group/sender-key-record.d.ts +32 -0
  118. package/lib/Signal/Group/sender-key-record.js +53 -0
  119. package/lib/Signal/Group/sender-key-record.ts +77 -0
  120. package/lib/Signal/Group/sender-key-state.d.ts +44 -0
  121. package/lib/Signal/Group/sender-key-state.js +104 -0
  122. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  123. package/lib/Signal/Group/sender-message-key.js +33 -0
  124. package/lib/Signal/libsignal.d.ts +3 -0
  125. package/lib/Signal/libsignal.js +153 -0
  126. package/lib/Socket/Client/index.d.ts +2 -0
  127. package/lib/Socket/Client/index.js +18 -0
  128. package/lib/Socket/Client/types.d.ts +15 -0
  129. package/lib/Socket/Client/types.js +14 -0
  130. package/lib/Socket/Client/websocket.d.ts +12 -0
  131. package/lib/Socket/Client/websocket.js +57 -0
  132. package/lib/Socket/business.d.ts +181 -0
  133. package/lib/Socket/business.js +259 -0
  134. package/lib/Socket/chats.d.ts +95 -0
  135. package/lib/Socket/chats.js +906 -0
  136. package/lib/Socket/community.d.ts +131 -0
  137. package/lib/Socket/community.js +369 -0
  138. package/lib/Socket/groups.d.ts +122 -0
  139. package/lib/Socket/groups.js +360 -0
  140. package/lib/Socket/index.d.ts +183 -0
  141. package/lib/Socket/index.js +10 -0
  142. package/lib/Socket/messages-recv.d.ts +170 -0
  143. package/lib/Socket/messages-recv.js +1074 -0
  144. package/lib/Socket/messages-send.d.ts +161 -0
  145. package/lib/Socket/messages-send.js +982 -0
  146. package/lib/Socket/newsletter.d.ts +140 -0
  147. package/lib/Socket/newsletter.js +242 -0
  148. package/lib/Socket/socket.d.ts +43 -0
  149. package/lib/Socket/socket.js +749 -0
  150. package/lib/Socket/usync.d.ts +36 -0
  151. package/lib/Socket/usync.js +71 -0
  152. package/lib/Store/index.d.ts +4 -0
  153. package/lib/Store/index.js +20 -0
  154. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  155. package/lib/Store/make-cache-manager-store.js +77 -0
  156. package/lib/Store/make-in-memory-store.d.ts +117 -0
  157. package/lib/Store/make-in-memory-store.js +420 -0
  158. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  159. package/lib/Store/make-ordered-dictionary.js +83 -0
  160. package/lib/Store/object-repository.d.ts +10 -0
  161. package/lib/Store/object-repository.js +28 -0
  162. package/lib/Types/Auth.d.ts +103 -0
  163. package/lib/Types/Auth.js +2 -0
  164. package/lib/Types/Call.d.ts +13 -0
  165. package/lib/Types/Call.js +2 -0
  166. package/lib/Types/Chat.d.ts +115 -0
  167. package/lib/Types/Chat.js +6 -0
  168. package/lib/Types/Contact.d.ts +35 -0
  169. package/lib/Types/Contact.js +2 -0
  170. package/lib/Types/Events.d.ts +208 -0
  171. package/lib/Types/Events.js +2 -0
  172. package/lib/Types/GroupMetadata.d.ts +81 -0
  173. package/lib/Types/GroupMetadata.js +2 -0
  174. package/lib/Types/Label.d.ts +46 -0
  175. package/lib/Types/Label.js +28 -0
  176. package/lib/Types/LabelAssociation.d.ts +29 -0
  177. package/lib/Types/LabelAssociation.js +10 -0
  178. package/lib/Types/Message.d.ts +480 -0
  179. package/lib/Types/Message.js +9 -0
  180. package/lib/Types/MexUpdates.d.ts +9 -0
  181. package/lib/Types/MexUpdates.js +18 -0
  182. package/lib/Types/Newsletter.d.ts +92 -0
  183. package/lib/Types/Newsletter.js +33 -0
  184. package/lib/Types/Product.d.ts +78 -0
  185. package/lib/Types/Product.js +2 -0
  186. package/lib/Types/Signal.d.ts +57 -0
  187. package/lib/Types/Signal.js +2 -0
  188. package/lib/Types/Socket.d.ts +116 -0
  189. package/lib/Types/Socket.js +2 -0
  190. package/lib/Types/State.d.ts +27 -0
  191. package/lib/Types/State.js +2 -0
  192. package/lib/Types/USync.d.ts +25 -0
  193. package/lib/Types/USync.js +2 -0
  194. package/lib/Types/index.d.ts +70 -0
  195. package/lib/Types/index.js +42 -0
  196. package/lib/Utils/auth-utils.d.ts +18 -0
  197. package/lib/Utils/auth-utils.js +198 -0
  198. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  199. package/lib/Utils/baileys-event-stream.js +64 -0
  200. package/lib/Utils/business.d.ts +22 -0
  201. package/lib/Utils/business.js +243 -0
  202. package/lib/Utils/chat-utils.d.ts +72 -0
  203. package/lib/Utils/chat-utils.js +762 -0
  204. package/lib/Utils/crypto.d.ts +40 -0
  205. package/lib/Utils/crypto.js +150 -0
  206. package/lib/Utils/decode-wa-message.d.ts +252 -0
  207. package/lib/Utils/decode-wa-message.js +232 -0
  208. package/lib/Utils/event-buffer.d.ts +35 -0
  209. package/lib/Utils/event-buffer.js +539 -0
  210. package/lib/Utils/generics.d.ts +96 -0
  211. package/lib/Utils/generics.js +553 -0
  212. package/lib/Utils/history.d.ts +29 -0
  213. package/lib/Utils/history.js +109 -0
  214. package/lib/Utils/index.d.ts +19 -0
  215. package/lib/Utils/index.js +35 -0
  216. package/lib/Utils/link-preview.d.ts +21 -0
  217. package/lib/Utils/link-preview.js +112 -0
  218. package/lib/Utils/logger.d.ts +11 -0
  219. package/lib/Utils/logger.js +7 -0
  220. package/lib/Utils/lt-hash.d.ts +12 -0
  221. package/lib/Utils/lt-hash.js +53 -0
  222. package/lib/Utils/make-mutex.d.ts +7 -0
  223. package/lib/Utils/make-mutex.js +45 -0
  224. package/lib/Utils/messages-media.d.ts +104 -0
  225. package/lib/Utils/messages-media.js +751 -0
  226. package/lib/Utils/messages.d.ts +80 -0
  227. package/lib/Utils/messages.js +1741 -0
  228. package/lib/Utils/noise-handler.d.ts +19 -0
  229. package/lib/Utils/noise-handler.js +150 -0
  230. package/lib/Utils/process-message.d.ts +41 -0
  231. package/lib/Utils/process-message.js +391 -0
  232. package/lib/Utils/signal.d.ts +33 -0
  233. package/lib/Utils/signal.js +154 -0
  234. package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -0
  235. package/lib/Utils/use-mongo-file-auth-state.js +75 -0
  236. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  237. package/lib/Utils/use-multi-file-auth-state.js +123 -0
  238. package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
  239. package/lib/Utils/use-single-file-auth-state.js +75 -0
  240. package/lib/Utils/validate-connection.d.ts +10 -0
  241. package/lib/Utils/validate-connection.js +174 -0
  242. package/lib/WABinary/constants.d.ts +27 -0
  243. package/lib/WABinary/constants.js +45 -0
  244. package/lib/WABinary/decode.d.ts +6 -0
  245. package/lib/WABinary/decode.js +255 -0
  246. package/lib/WABinary/encode.d.ts +2 -0
  247. package/lib/WABinary/encode.js +243 -0
  248. package/lib/WABinary/generic-utils.d.ts +16 -0
  249. package/lib/WABinary/generic-utils.js +125 -0
  250. package/lib/WABinary/index.d.ts +5 -0
  251. package/lib/WABinary/index.js +21 -0
  252. package/lib/WABinary/jid-utils.d.ts +34 -0
  253. package/lib/WABinary/jid-utils.js +73 -0
  254. package/lib/WABinary/types.d.ts +18 -0
  255. package/lib/WABinary/types.js +2 -0
  256. package/lib/WAM/BinaryInfo.d.ts +16 -0
  257. package/lib/WAM/BinaryInfo.js +14 -0
  258. package/lib/WAM/constants.d.ts +39 -0
  259. package/lib/WAM/constants.js +15362 -0
  260. package/lib/WAM/encode.d.ts +2 -0
  261. package/lib/WAM/encode.js +156 -0
  262. package/lib/WAM/index.d.ts +3 -0
  263. package/lib/WAM/index.js +19 -0
  264. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +25 -0
  265. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +60 -0
  266. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  267. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  268. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  269. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  270. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  271. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  272. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +8 -0
  273. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +26 -0
  274. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  275. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  276. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  277. package/lib/WAUSync/Protocols/index.js +22 -0
  278. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  279. package/lib/WAUSync/USyncQuery.js +88 -0
  280. package/lib/WAUSync/USyncUser.d.ts +12 -0
  281. package/lib/WAUSync/USyncUser.js +27 -0
  282. package/lib/WAUSync/index.d.ts +3 -0
  283. package/lib/WAUSync/index.js +19 -0
  284. package/lib/index.d.ts +13 -0
  285. package/lib/index.js +45 -0
  286. package/package.json +63 -0
@@ -0,0 +1,78 @@
1
+ import { WAMediaUpload } from './Message'
2
+ export type CatalogResult = {
3
+ data: {
4
+ paging: {
5
+ cursors: {
6
+ before: string
7
+ after: string
8
+ }
9
+ }
10
+ data: any[]
11
+ }
12
+ }
13
+ export type ProductCreateResult = {
14
+ data: {
15
+ product: {}
16
+ }
17
+ }
18
+ export type CatalogStatus = {
19
+ status: string
20
+ canAppeal: boolean
21
+ }
22
+ export type CatalogCollection = {
23
+ id: string
24
+ name: string
25
+ products: Product[]
26
+ status: CatalogStatus
27
+ }
28
+ export type ProductAvailability = 'in stock'
29
+ export type ProductBase = {
30
+ name: string
31
+ retailerId?: string
32
+ url?: string
33
+ description: string
34
+ price: number
35
+ currency: string
36
+ isHidden?: boolean
37
+ }
38
+ export type ProductCreate = ProductBase & {
39
+ /** ISO country code for product origin. Set to undefined for no country */
40
+ originCountryCode: string | undefined
41
+ /** images of the product */
42
+ images: WAMediaUpload[]
43
+ }
44
+ export type ProductUpdate = Omit<ProductCreate, 'originCountryCode'>
45
+ export type Product = ProductBase & {
46
+ id: string
47
+ imageUrls: {
48
+ [_: string]: string
49
+ }
50
+ reviewStatus: {
51
+ [_: string]: string
52
+ }
53
+ availability: ProductAvailability
54
+ }
55
+ export type OrderPrice = {
56
+ currency: string
57
+ total: number
58
+ }
59
+ export type OrderProduct = {
60
+ id: string
61
+ imageUrl: string
62
+ name: string
63
+ quantity: number
64
+ currency: string
65
+ price: number
66
+ }
67
+ export type OrderDetails = {
68
+ price: OrderPrice
69
+ products: OrderProduct[]
70
+ }
71
+ export type CatalogCursor = string
72
+ export type GetCatalogOptions = {
73
+ /** cursor to start from */
74
+ cursor?: CatalogCursor
75
+ /** number of products to fetch */
76
+ limit?: number
77
+ jid?: string
78
+ }
@@ -0,0 +1,2 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,57 @@
1
+ import { proto } from '../../WAProto'
2
+ type DecryptGroupSignalOpts = {
3
+ group: string
4
+ authorJid: string
5
+ msg: Uint8Array
6
+ }
7
+ type ProcessSenderKeyDistributionMessageOpts = {
8
+ item: proto.Message.ISenderKeyDistributionMessage
9
+ authorJid: string
10
+ }
11
+ type DecryptSignalProtoOpts = {
12
+ jid: string
13
+ type: 'pkmsg' | 'msg'
14
+ ciphertext: Uint8Array
15
+ }
16
+ type EncryptMessageOpts = {
17
+ jid: string
18
+ data: Uint8Array
19
+ }
20
+ type EncryptGroupMessageOpts = {
21
+ group: string
22
+ data: Uint8Array
23
+ meId: string
24
+ }
25
+ type PreKey = {
26
+ keyId: number
27
+ publicKey: Uint8Array
28
+ }
29
+ type SignedPreKey = PreKey & {
30
+ signature: Uint8Array
31
+ }
32
+ type E2ESession = {
33
+ registrationId: number
34
+ identityKey: Uint8Array
35
+ signedPreKey: SignedPreKey
36
+ preKey: PreKey
37
+ }
38
+ type E2ESessionOpts = {
39
+ jid: string
40
+ session: E2ESession
41
+ }
42
+ export type SignalRepository = {
43
+ decryptGroupMessage(opts: DecryptGroupSignalOpts): Promise<Uint8Array>
44
+ processSenderKeyDistributionMessage(opts: ProcessSenderKeyDistributionMessageOpts): Promise<void>
45
+ decryptMessage(opts: DecryptSignalProtoOpts): Promise<Uint8Array>
46
+ encryptMessage(opts: EncryptMessageOpts): Promise<{
47
+ type: 'pkmsg' | 'msg'
48
+ ciphertext: Uint8Array
49
+ }>
50
+ encryptGroupMessage(opts: EncryptGroupMessageOpts): Promise<{
51
+ senderKeyDistributionMessage: Uint8Array
52
+ ciphertext: Uint8Array
53
+ }>
54
+ injectE2ESession(opts: E2ESessionOpts): Promise<void>
55
+ jidToSignalProtocolAddress(jid: string): string
56
+ }
57
+ export {}
@@ -0,0 +1,2 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,116 @@
1
+ import { AxiosRequestConfig } from 'axios'
2
+ import type { Agent } from 'https'
3
+ import { ILogger } from '../Utils/logger'
4
+ import type { URL } from 'url'
5
+ import { proto } from '../../WAProto'
6
+ import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth'
7
+ import { GroupMetadata } from './GroupMetadata'
8
+ import { MediaConnInfo } from './Message'
9
+ import { SignalRepository } from './Signal'
10
+ export type WAVersion = [number, number, number]
11
+ export type WABrowserDescription = [string, string, string]
12
+ export type CacheStore = {
13
+ /** get a cached key and change the stats */
14
+ get<T>(key: string): T | undefined
15
+ /** set a key in the cache */
16
+ set<T>(key: string, value: T): void
17
+ /** delete a key from the cache */
18
+ del(key: string): void
19
+ /** flush all data */
20
+ flushAll(): void
21
+ }
22
+ export type SocketConfig = {
23
+ /** the WS url to connect to WA */
24
+ waWebSocketUrl: string | URL
25
+ /** Fails the connection if the socket times out in this interval */
26
+ connectTimeoutMs: number
27
+ /** Default timeout for queries, undefined for no timeout */
28
+ defaultQueryTimeoutMs: number | undefined
29
+ /** ping-pong interval for WS connection */
30
+ keepAliveIntervalMs: number
31
+ /** should baileys use the mobile api instead of the multi device api
32
+ * @deprecated This feature has been removed
33
+ */
34
+ mobile?: boolean
35
+ /** proxy agent */
36
+ agent?: Agent
37
+ /** logger */
38
+ logger: ILogger
39
+ /** version to connect with */
40
+ version: WAVersion
41
+ /** override browser config */
42
+ browser: WABrowserDescription
43
+ /** agent used for fetch requests -- uploading/downloading media */
44
+ fetchAgent?: Agent
45
+ /** should the QR be printed in the terminal */
46
+ printQRInTerminal: boolean
47
+ /** should events be emitted for actions done by this socket connection */
48
+ emitOwnEvents: boolean
49
+ /** custom upload hosts to upload media to */
50
+ customUploadHosts: MediaConnInfo['hosts']
51
+ /** time to wait between sending new retry requests */
52
+ retryRequestDelayMs: number
53
+ /** max retry count */
54
+ maxMsgRetryCount: number
55
+ /** time to wait for the generation of the next QR in ms */
56
+ qrTimeout?: number
57
+ /** provide an auth state object to maintain the auth state */
58
+ auth: AuthenticationState
59
+ /** manage history processing with this control by default will sync up everything */
60
+ shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => boolean
61
+ /** transaction capability options for SignalKeyStore */
62
+ transactionOpts: TransactionCapabilityOptions
63
+ /** marks the client as online whenever the socket successfully connects */
64
+ markOnlineOnConnect: boolean
65
+ /** alphanumeric country code (USA -> US) for the number used */
66
+ countryCode: string
67
+ /** provide a cache to store media, so does not have to be re-uploaded */
68
+ mediaCache?: CacheStore
69
+ /**
70
+ * map to store the retry counts for failed messages
71
+ * used to determine whether to retry a message or not */
72
+ msgRetryCounterCache?: CacheStore
73
+ /** provide a cache to store a user's device list */
74
+ userDevicesCache?: CacheStore
75
+ /** cache to store call offers */
76
+ callOfferCache?: CacheStore
77
+ /** cache to track placeholder resends */
78
+ placeholderResendCache?: CacheStore
79
+ /** width for link preview images */
80
+ linkPreviewImageThumbnailWidth: number
81
+ /** Should Baileys ask the phone for full history, will be received async */
82
+ syncFullHistory: boolean
83
+ /** Should baileys fire init queries automatically, default true */
84
+ fireInitQueries: boolean
85
+ /**
86
+ * generate a high quality link preview,
87
+ * entails uploading the jpegThumbnail to WA
88
+ * */
89
+ generateHighQualityLinkPreview: boolean
90
+ /**
91
+ * Returns if a jid should be ignored,
92
+ * no event for that jid will be triggered.
93
+ * Messages from that jid will also not be decrypted
94
+ * */
95
+ shouldIgnoreJid: (jid: string) => boolean | undefined
96
+ /**
97
+ * Optionally patch the message before sending out
98
+ * */
99
+ patchMessageBeforeSending: (msg: proto.IMessage, recipientJids: string[]) => Promise<proto.IMessage> | proto.IMessage
100
+ /** verify app state MACs */
101
+ appStateMacVerification: {
102
+ patch: boolean
103
+ snapshot: boolean
104
+ }
105
+ /** options for axios */
106
+ options: AxiosRequestConfig<{}>
107
+ /**
108
+ * fetch a message from your store
109
+ * implement this so that messages failed to send
110
+ * (solves the "this message can take a while" issue) can be retried
111
+ * */
112
+ getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>
113
+ /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
114
+ cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>
115
+ makeSignalRepository: (auth: SignalAuthState) => SignalRepository
116
+ }
@@ -0,0 +1,2 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,27 @@
1
+ import { Contact } from './Contact'
2
+ export type WAConnectionState = 'open' | 'connecting' | 'close'
3
+ export type ConnectionState = {
4
+ /** connection is now open, connecting or closed */
5
+ connection: WAConnectionState
6
+ /** the error that caused the connection to close */
7
+ lastDisconnect?: {
8
+ error: Error | undefined
9
+ date: Date
10
+ }
11
+ /** is this a new login */
12
+ isNewLogin?: boolean
13
+ /** the current QR code */
14
+ qr?: string
15
+ /** has the device received all pending notifications while it was offline */
16
+ receivedPendingNotifications?: boolean
17
+ /** legacy connection options */
18
+ legacy?: {
19
+ phoneConnected: boolean
20
+ user?: Contact
21
+ }
22
+ /**
23
+ * if the client is shown as an active, online client.
24
+ * If this is false, the primary phone and other devices will receive notifs
25
+ * */
26
+ isOnline?: boolean
27
+ }
@@ -0,0 +1,2 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,25 @@
1
+ import { BinaryNode } from '../WABinary'
2
+ import { USyncUser } from '../WAUSync'
3
+ /**
4
+ * Defines the interface for a USyncQuery protocol
5
+ */
6
+ export interface USyncQueryProtocol {
7
+ /**
8
+ * The name of the protocol
9
+ */
10
+ name: string
11
+ /**
12
+ * Defines what goes inside the query part of a USyncQuery
13
+ */
14
+ getQueryElement: () => BinaryNode
15
+ /**
16
+ * Defines what goes inside the user part of a USyncQuery
17
+ */
18
+ getUserElement: (user: USyncUser) => BinaryNode | null
19
+ /**
20
+ * Parse the result of the query
21
+ * @param data Data from the result
22
+ * @returns Whatever the protocol is supposed to return
23
+ */
24
+ parser: (data: BinaryNode) => unknown
25
+ }
@@ -0,0 +1,2 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,70 @@
1
+ export * from './Auth'
2
+ export * from './GroupMetadata'
3
+ export * from './Chat'
4
+ export * from './Contact'
5
+ export * from './State'
6
+ export * from './Message'
7
+ export * from './Newsletter'
8
+ export * from './Socket'
9
+ export * from './Events'
10
+ export * from './Product'
11
+ export * from './Call'
12
+ export * from './Signal'
13
+ import { AuthenticationState } from './Auth'
14
+ import { SocketConfig } from './Socket'
15
+ export type UserFacingSocketConfig = Partial<SocketConfig> & {
16
+ auth: AuthenticationState
17
+ }
18
+ export type BrowsersMap = {
19
+ ubuntu(browser: string): [string, string, string]
20
+ macOS(browser: string): [string, string, string]
21
+ windows(browser: string): [string, string, string]
22
+ linux(browser: string): [string, string, string]
23
+ android(browser: string): [string, string, string]
24
+ iOS(browser: string): [string, string, string]
25
+ baileys(browser: string): [string, string, string]
26
+ kaiOS(browser: string): [string, string, string]
27
+ chromeOS(browser: string): [string, string, string]
28
+ appropriate(browser: string): [string, string, string]
29
+ custom(platform: string, browser: string, version: string): [string, string, string]
30
+ }
31
+ export declare const enum DisconnectReason {
32
+ connectionClosed = 428,
33
+ connectionLost = 408,
34
+ connectionReplaced = 440,
35
+ timedOut = 408,
36
+ loggedOut = 401,
37
+ badSession = 500,
38
+ restartRequired = 515,
39
+ multideviceMismatch = 411,
40
+ forbidden = 403,
41
+ unavailableService = 503
42
+ }
43
+ export type WAInitResponse = {
44
+ ref: string
45
+ ttl: number
46
+ status: 200
47
+ }
48
+ export type WABusinessHoursConfig = {
49
+ day_of_week: string
50
+ mode: string
51
+ open_time?: number
52
+ close_time?: number
53
+ }
54
+ export type WABusinessProfile = {
55
+ description: string
56
+ email: string | undefined
57
+ business_hours: {
58
+ timezone?: string
59
+ config?: WABusinessHoursConfig[]
60
+ business_config?: WABusinessHoursConfig[]
61
+ }
62
+ website: string[]
63
+ category?: string
64
+ wid?: string
65
+ address?: string
66
+ }
67
+ export type CurveKeyPair = {
68
+ private: Uint8Array
69
+ public: Uint8Array
70
+ }
@@ -0,0 +1,42 @@
1
+ "use strict"
2
+ 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)
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k
11
+ o[k2] = m[k]
12
+ }))
13
+ 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)
15
+ }
16
+ Object.defineProperty(exports, "__esModule", { value: true })
17
+ exports.DisconnectReason = void 0;
18
+ __exportStar(require("./Auth"), exports)
19
+ __exportStar(require("./GroupMetadata"), exports)
20
+ __exportStar(require("./Chat"), exports)
21
+ __exportStar(require("./Contact"), exports)
22
+ __exportStar(require("./State"), exports)
23
+ __exportStar(require("./Message"), exports)
24
+ __exportStar(require("./Newsletter"), exports)
25
+ __exportStar(require("./Socket"), exports)
26
+ __exportStar(require("./Events"), exports)
27
+ __exportStar(require("./Product"), exports)
28
+ __exportStar(require("./Call"), exports)
29
+ __exportStar(require("./Signal"), exports)
30
+ const DisconnectReason = {
31
+ connectionClosed: 428,
32
+ connectionLost: 408,
33
+ connectionReplaced: 440,
34
+ timedOut: 408,
35
+ loggedOut: 401,
36
+ badSession: 500,
37
+ restartRequired: 515,
38
+ multideviceMismatch: 411,
39
+ forbidden: 403,
40
+ unavailableService: 503
41
+ }
42
+ exports.DisconnectReason = DisconnectReason
@@ -0,0 +1,18 @@
1
+ import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types'
2
+ import { ILogger } from './logger'
3
+ /**
4
+ * Adds caching capability to a SignalKeyStore
5
+ * @param store the store to add caching to
6
+ * @param logger to log trace events
7
+ * @param _cache cache store to use
8
+ */
9
+ export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger?: ILogger, _cache?: CacheStore): SignalKeyStore
10
+ /**
11
+ * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
12
+ * this allows batch read & write operations & improves the performance of the lib
13
+ * @param state the key store to apply this capability to
14
+ * @param logger logger to log events
15
+ * @returns SignalKeyStore with transaction capability
16
+ */
17
+ export declare const addTransactionCapability: (state: SignalKeyStore, logger?: ILogger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction
18
+ export declare const initAuthCreds: () => AuthenticationCreds
@@ -0,0 +1,198 @@
1
+ "use strict"
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod }
4
+ }
5
+ Object.defineProperty(exports, "__esModule", { value: true })
6
+ const crypto_1 = require("crypto")
7
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"))
8
+ const Defaults_1 = require("../Defaults")
9
+ const crypto_2 = require("./crypto")
10
+ const generics_1 = require("./generics")
11
+ /**
12
+ * Adds caching capability to a SignalKeyStore
13
+ * @param store the store to add caching to
14
+ * @param logger to log trace events
15
+ * @param _cache cache store to use
16
+ */
17
+ function makeCacheableSignalKeyStore(store, logger, _cache) {
18
+ const cache = _cache || new node_cache_1.default({
19
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
20
+ useClones: false,
21
+ deleteOnExpire: true,
22
+ })
23
+ function getUniqueId(type, id) {
24
+ return `${type}.${id}`
25
+ }
26
+ return {
27
+ async get(type, ids) {
28
+ const data = {}
29
+ const idsToFetch = []
30
+ for (const id of ids) {
31
+ const item = cache.get(getUniqueId(type, id))
32
+ if (typeof item !== 'undefined') {
33
+ data[id] = item
34
+ }
35
+ else {
36
+ idsToFetch.push(id)
37
+ }
38
+ }
39
+ if (idsToFetch.length) {
40
+ logger?.trace({ items: idsToFetch.length }, 'loading from store')
41
+ const fetched = await store.get(type, idsToFetch)
42
+ for (const id of idsToFetch) {
43
+ const item = fetched[id]
44
+ if (item) {
45
+ data[id] = item
46
+ cache.set(getUniqueId(type, id), item)
47
+ }
48
+ }
49
+ }
50
+ return data
51
+ },
52
+ async set(data) {
53
+ let keys = 0
54
+ for (const type in data) {
55
+ for (const id in data[type]) {
56
+ cache.set(getUniqueId(type, id), data[type][id])
57
+ keys += 1
58
+ }
59
+ }
60
+ logger?.trace({ keys }, 'updated cache')
61
+ await store.set(data)
62
+ },
63
+ async clear() {
64
+ cache.flushAll()
65
+ await store.clear?.call(store)
66
+ }
67
+ }
68
+ }
69
+ /**
70
+ * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
71
+ * this allows batch read & write operations & improves the performance of the lib
72
+ * @param state the key store to apply this capability to
73
+ * @param logger logger to log events
74
+ * @returns SignalKeyStore with transaction capability
75
+ */
76
+ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
77
+ // number of queries made to the DB during the transaction
78
+ // only there for logging purposes
79
+ let dbQueriesInTransaction = 0
80
+ let transactionCache = {}
81
+ let mutations = {}
82
+ let transactionsInProgress = 0
83
+ return {
84
+ get: async (type, ids) => {
85
+ if (isInTransaction()) {
86
+ const dict = transactionCache[type]
87
+ const idsRequiringFetch = dict
88
+ ? ids.filter(item => typeof dict[item] === 'undefined')
89
+ : ids
90
+ // only fetch if there are any items to fetch
91
+ if (idsRequiringFetch.length) {
92
+ dbQueriesInTransaction += 1
93
+ const result = await state.get(type, idsRequiringFetch)
94
+ transactionCache[type] || (transactionCache[type] = {})
95
+ Object.assign(transactionCache[type], result)
96
+ }
97
+ return ids.reduce((dict, id) => {
98
+ const value = transactionCache[type]?.[id]
99
+ if (value) {
100
+ dict[id] = value
101
+ }
102
+ return dict
103
+ }, {})
104
+ }
105
+ else {
106
+ return state.get(type, ids)
107
+ }
108
+ },
109
+ set: data => {
110
+ if (isInTransaction()) {
111
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction')
112
+ for (const key in data) {
113
+ transactionCache[key] = transactionCache[key] || {}
114
+ Object.assign(transactionCache[key], data[key])
115
+ mutations[key] = mutations[key] || {}
116
+ Object.assign(mutations[key], data[key])
117
+ }
118
+ }
119
+ else {
120
+ return state.set(data)
121
+ }
122
+ },
123
+ isInTransaction,
124
+ async transaction(work) {
125
+ let result
126
+ transactionsInProgress += 1
127
+ if (transactionsInProgress === 1) {
128
+ logger.trace('entering transaction')
129
+ }
130
+ try {
131
+ result = await work()
132
+ // commit if this is the outermost transaction
133
+ if (transactionsInProgress === 1) {
134
+ if (Object.keys(mutations).length) {
135
+ logger.trace('committing transaction')
136
+ // retry mechanism to ensure we've some recovery
137
+ // in case a transaction fails in the first attempt
138
+ let tries = maxCommitRetries
139
+ while (tries) {
140
+ tries -= 1
141
+ try {
142
+ await state.set(mutations)
143
+ logger.trace({ dbQueriesInTransaction }, 'committed transaction')
144
+ break
145
+ }
146
+ catch (error) {
147
+ logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`)
148
+ await generics_1.delay(delayBetweenTriesMs)
149
+ }
150
+ }
151
+ }
152
+ else {
153
+ logger.trace('no mutations in transaction')
154
+ }
155
+ }
156
+ }
157
+ finally {
158
+ transactionsInProgress -= 1
159
+ if (transactionsInProgress === 0) {
160
+ transactionCache = {}
161
+ mutations = {}
162
+ dbQueriesInTransaction = 0
163
+ }
164
+ }
165
+ return result
166
+ }
167
+ }
168
+ function isInTransaction() {
169
+ return transactionsInProgress > 0
170
+ }
171
+ }
172
+ const initAuthCreds = () => {
173
+ const identityKey = crypto_2.Curve.generateKeyPair()
174
+ return {
175
+ noiseKey: crypto_2.Curve.generateKeyPair(),
176
+ pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
177
+ signedIdentityKey: identityKey,
178
+ signedPreKey: crypto_2.signedKeyPair(identityKey, 1),
179
+ registrationId: generics_1.generateRegistrationId(),
180
+ advSecretKey: crypto_1.randomBytes(32).toString('base64'),
181
+ processedHistoryMessages: [],
182
+ nextPreKeyId: 1,
183
+ firstUnuploadedPreKeyId: 1,
184
+ accountSyncCounter: 0,
185
+ accountSettings: {
186
+ unarchiveChats: false
187
+ },
188
+ registered: false,
189
+ pairingCode: undefined,
190
+ lastPropHash: undefined,
191
+ routingInfo: undefined
192
+ }
193
+ }
194
+ module.exports = {
195
+ makeCacheableSignalKeyStore,
196
+ addTransactionCapability,
197
+ initAuthCreds
198
+ }
@@ -0,0 +1,16 @@
1
+ import type { BaileysEventEmitter } from '../Types'
2
+ /**
3
+ * Captures events from a baileys event emitter & stores them in a file
4
+ * @param ev The event emitter to read events from
5
+ * @param filename File to save to
6
+ */
7
+ export declare const captureEventStream: (ev: BaileysEventEmitter, filename: string) => void
8
+ /**
9
+ * Read event file and emit events from there
10
+ * @param filename filename containing event data
11
+ * @param delayIntervalMs delay between each event emit
12
+ */
13
+ export declare const readAndEmitEventStream: (filename: string, delayIntervalMs?: number) => {
14
+ ev: BaileysEventEmitter
15
+ task: Promise<void>
16
+ }