@neelegirl/baileys 1.4.3

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 (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -0
  3. package/WAProto/GenerateStatics.sh +4 -0
  4. package/WAProto/WAProto.proto +4451 -0
  5. package/WAProto/index.d.ts +51459 -0
  6. package/WAProto/index.js +158781 -0
  7. package/WASignalGroup/GroupProtocol.js +1697 -0
  8. package/WASignalGroup/ciphertext_message.js +16 -0
  9. package/WASignalGroup/group_cipher.js +120 -0
  10. package/WASignalGroup/group_session_builder.js +46 -0
  11. package/WASignalGroup/index.js +5 -0
  12. package/WASignalGroup/keyhelper.js +21 -0
  13. package/WASignalGroup/protobufs.js +3 -0
  14. package/WASignalGroup/queue_job.js +69 -0
  15. package/WASignalGroup/sender_chain_key.js +50 -0
  16. package/WASignalGroup/sender_key_distribution_message.js +78 -0
  17. package/WASignalGroup/sender_key_message.js +92 -0
  18. package/WASignalGroup/sender_key_name.js +70 -0
  19. package/WASignalGroup/sender_key_record.js +56 -0
  20. package/WASignalGroup/sender_key_state.js +129 -0
  21. package/WASignalGroup/sender_message_key.js +39 -0
  22. package/package.json +88 -0
  23. package/src/Defaults/baileys-version.json +3 -0
  24. package/src/Defaults/index.d.ts +68 -0
  25. package/src/Defaults/index.js +131 -0
  26. package/src/Defaults/phonenumber-mcc.json +223 -0
  27. package/src/Signal/libsignal.d.ts +4 -0
  28. package/src/Signal/libsignal.js +162 -0
  29. package/src/Socket/Client/index.d.ts +2 -0
  30. package/src/Socket/Client/index.js +22 -0
  31. package/src/Socket/Client/types.d.ts +16 -0
  32. package/src/Socket/Client/types.js +18 -0
  33. package/src/Socket/Client/websocket.d.ts +13 -0
  34. package/src/Socket/Client/websocket.js +62 -0
  35. package/src/Socket/business.d.ts +182 -0
  36. package/src/Socket/business.js +268 -0
  37. package/src/Socket/chats.d.ts +96 -0
  38. package/src/Socket/chats.js +1278 -0
  39. package/src/Socket/groups.d.ts +130 -0
  40. package/src/Socket/groups.js +337 -0
  41. package/src/Socket/index.d.ts +185 -0
  42. package/src/Socket/index.js +14 -0
  43. package/src/Socket/messages-recv.d.ts +171 -0
  44. package/src/Socket/messages-recv.js +1182 -0
  45. package/src/Socket/messages-send.d.ts +162 -0
  46. package/src/Socket/messages-send.js +1086 -0
  47. package/src/Socket/newsletter.d.ts +142 -0
  48. package/src/Socket/newsletter.js +256 -0
  49. package/src/Socket/socket.d.ts +45 -0
  50. package/src/Socket/socket.js +749 -0
  51. package/src/Socket/usync.d.ts +37 -0
  52. package/src/Socket/usync.js +83 -0
  53. package/src/Store/index.d.ts +4 -0
  54. package/src/Store/index.js +24 -0
  55. package/src/Store/make-cache-manager-store.d.ts +14 -0
  56. package/src/Store/make-cache-manager-store.js +90 -0
  57. package/src/Store/make-in-memory-store.d.ts +123 -0
  58. package/src/Store/make-in-memory-store.js +429 -0
  59. package/src/Store/make-ordered-dictionary.d.ts +12 -0
  60. package/src/Store/make-ordered-dictionary.js +86 -0
  61. package/src/Store/object-repository.d.ts +10 -0
  62. package/src/Store/object-repository.js +31 -0
  63. package/src/Types/Auth.d.ts +120 -0
  64. package/src/Types/Auth.js +3 -0
  65. package/src/Types/Call.d.ts +14 -0
  66. package/src/Types/Call.js +3 -0
  67. package/src/Types/Chat.d.ts +134 -0
  68. package/src/Types/Chat.js +9 -0
  69. package/src/Types/Contact.d.ts +25 -0
  70. package/src/Types/Contact.js +3 -0
  71. package/src/Types/Events.d.ts +212 -0
  72. package/src/Types/Events.js +3 -0
  73. package/src/Types/GroupMetadata.d.ts +64 -0
  74. package/src/Types/GroupMetadata.js +3 -0
  75. package/src/Types/Label.d.ts +48 -0
  76. package/src/Types/Label.js +31 -0
  77. package/src/Types/LabelAssociation.d.ts +35 -0
  78. package/src/Types/LabelAssociation.js +13 -0
  79. package/src/Types/Message.d.ts +459 -0
  80. package/src/Types/Message.js +13 -0
  81. package/src/Types/Newsletter.d.ts +107 -0
  82. package/src/Types/Newsletter.js +38 -0
  83. package/src/Types/Product.d.ts +92 -0
  84. package/src/Types/Product.js +3 -0
  85. package/src/Types/Signal.d.ts +68 -0
  86. package/src/Types/Signal.js +3 -0
  87. package/src/Types/Socket.d.ts +120 -0
  88. package/src/Types/Socket.js +3 -0
  89. package/src/Types/State.d.ts +29 -0
  90. package/src/Types/State.js +3 -0
  91. package/src/Types/USync.d.ts +26 -0
  92. package/src/Types/USync.js +3 -0
  93. package/src/Types/index.d.ts +78 -0
  94. package/src/Types/index.js +47 -0
  95. package/src/Utils/auth-utils.d.ts +21 -0
  96. package/src/Utils/auth-utils.js +205 -0
  97. package/src/Utils/baileys-event-stream.d.ts +18 -0
  98. package/src/Utils/baileys-event-stream.js +70 -0
  99. package/src/Utils/business.d.ts +29 -0
  100. package/src/Utils/business.js +247 -0
  101. package/src/Utils/chat-utils.d.ts +82 -0
  102. package/src/Utils/chat-utils.js +774 -0
  103. package/src/Utils/crypto.d.ts +56 -0
  104. package/src/Utils/crypto.js +179 -0
  105. package/src/Utils/decode-wa-message.d.ts +41 -0
  106. package/src/Utils/decode-wa-message.js +236 -0
  107. package/src/Utils/event-buffer.d.ts +39 -0
  108. package/src/Utils/event-buffer.js +548 -0
  109. package/src/Utils/generics.d.ts +129 -0
  110. package/src/Utils/generics.js +584 -0
  111. package/src/Utils/history.d.ts +23 -0
  112. package/src/Utils/history.js +100 -0
  113. package/src/Utils/index.d.ts +19 -0
  114. package/src/Utils/index.js +39 -0
  115. package/src/Utils/link-preview.d.ts +23 -0
  116. package/src/Utils/link-preview.js +120 -0
  117. package/src/Utils/logger.d.ts +13 -0
  118. package/src/Utils/logger.js +7 -0
  119. package/src/Utils/lt-hash.d.ts +14 -0
  120. package/src/Utils/lt-hash.js +58 -0
  121. package/src/Utils/make-mutex.d.ts +9 -0
  122. package/src/Utils/make-mutex.js +49 -0
  123. package/src/Utils/messages-media.d.ts +129 -0
  124. package/src/Utils/messages-media.js +782 -0
  125. package/src/Utils/messages.d.ts +103 -0
  126. package/src/Utils/messages.js +1536 -0
  127. package/src/Utils/noise-handler.d.ts +20 -0
  128. package/src/Utils/noise-handler.js +155 -0
  129. package/src/Utils/process-message.d.ts +49 -0
  130. package/src/Utils/process-message.js +387 -0
  131. package/src/Utils/signal.d.ts +42 -0
  132. package/src/Utils/signal.js +166 -0
  133. package/src/Utils/use-mongo-file-auth-state.d.ts +6 -0
  134. package/src/Utils/use-mongo-file-auth-state.js +84 -0
  135. package/src/Utils/use-multi-file-auth-state.d.ts +13 -0
  136. package/src/Utils/use-multi-file-auth-state.js +131 -0
  137. package/src/Utils/use-single-file-auth-state.d.ts +13 -0
  138. package/src/Utils/use-single-file-auth-state.js +80 -0
  139. package/src/Utils/validate-connection.d.ts +13 -0
  140. package/src/Utils/validate-connection.js +186 -0
  141. package/src/WABinary/constants.d.ts +30 -0
  142. package/src/WABinary/constants.js +53 -0
  143. package/src/WABinary/decode.d.ts +9 -0
  144. package/src/WABinary/decode.js +288 -0
  145. package/src/WABinary/encode.d.ts +3 -0
  146. package/src/WABinary/encode.js +256 -0
  147. package/src/WABinary/generic-utils.d.ts +28 -0
  148. package/src/WABinary/generic-utils.js +149 -0
  149. package/src/WABinary/index.d.ts +5 -0
  150. package/src/WABinary/index.js +25 -0
  151. package/src/WABinary/jid-utils.d.ts +53 -0
  152. package/src/WABinary/jid-utils.js +92 -0
  153. package/src/WABinary/types.d.ts +22 -0
  154. package/src/WABinary/types.js +3 -0
  155. package/src/WAM/BinaryInfo.d.ts +16 -0
  156. package/src/WAM/BinaryInfo.js +17 -0
  157. package/src/WAM/constants.d.ts +47 -0
  158. package/src/WAM/constants.js +15371 -0
  159. package/src/WAM/encode.d.ts +3 -0
  160. package/src/WAM/encode.js +165 -0
  161. package/src/WAM/index.d.ts +3 -0
  162. package/src/WAM/index.js +23 -0
  163. package/src/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
  164. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
  165. package/src/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  166. package/src/WAUSync/Protocols/USyncContactProtocol.js +36 -0
  167. package/src/WAUSync/Protocols/USyncDeviceProtocol.d.ts +26 -0
  168. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
  169. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +14 -0
  170. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +35 -0
  171. package/src/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
  172. package/src/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  173. package/src/WAUSync/Protocols/USyncStatusProtocol.d.ts +14 -0
  174. package/src/WAUSync/Protocols/USyncStatusProtocol.js +46 -0
  175. package/src/WAUSync/Protocols/index.d.ts +6 -0
  176. package/src/WAUSync/Protocols/index.js +26 -0
  177. package/src/WAUSync/USyncQuery.d.ts +31 -0
  178. package/src/WAUSync/USyncQuery.js +92 -0
  179. package/src/WAUSync/USyncUser.d.ts +12 -0
  180. package/src/WAUSync/USyncUser.js +30 -0
  181. package/src/WAUSync/index.d.ts +3 -0
  182. package/src/WAUSync/index.js +23 -0
  183. package/src/index.d.ts +13 -0
  184. package/src/index.js +33 -0
@@ -0,0 +1,68 @@
1
+ import { proto } from '../../WAProto'
2
+
3
+ type DecryptGroupSignalOpts = {
4
+ group: string
5
+ authorJid: string
6
+ msg: Uint8Array
7
+ }
8
+
9
+ type ProcessSenderKeyDistributionMessageOpts = {
10
+ item: proto.Message.ISenderKeyDistributionMessage
11
+ authorJid: string
12
+ }
13
+
14
+ type DecryptSignalProtoOpts = {
15
+ jid: string
16
+ type: 'pkmsg' | 'msg'
17
+ ciphertext: Uint8Array
18
+ }
19
+
20
+ type EncryptMessageOpts = {
21
+ jid: string
22
+ data: Uint8Array
23
+ }
24
+
25
+ type EncryptGroupMessageOpts = {
26
+ group: string
27
+ data: Uint8Array
28
+ meId: string
29
+ }
30
+
31
+ type PreKey = {
32
+ keyId: number
33
+ publicKey: Uint8Array
34
+ }
35
+
36
+ type SignedPreKey = PreKey & {
37
+ signature: Uint8Array
38
+ }
39
+
40
+ type E2ESession = {
41
+ registrationId: number
42
+ identityKey: Uint8Array
43
+ signedPreKey: SignedPreKey
44
+ preKey: PreKey
45
+ }
46
+
47
+ type E2ESessionOpts = {
48
+ jid: string
49
+ session: E2ESession
50
+ }
51
+
52
+ export type SignalRepository = {
53
+ decryptGroupMessage(opts: DecryptGroupSignalOpts): Promise<Uint8Array>
54
+ processSenderKeyDistributionMessage(opts: ProcessSenderKeyDistributionMessageOpts): Promise<void>
55
+ decryptMessage(opts: DecryptSignalProtoOpts): Promise<Uint8Array>
56
+ encryptMessage(opts: EncryptMessageOpts): Promise<{
57
+ type: 'pkmsg' | 'msg'
58
+ ciphertext: Uint8Array
59
+ }>
60
+ encryptGroupMessage(opts: EncryptGroupMessageOpts): Promise<{
61
+ senderKeyDistributionMessage: Uint8Array
62
+ ciphertext: Uint8Array
63
+ }>
64
+ injectE2ESession(opts: E2ESessionOpts): Promise<void>
65
+ jidToSignalProtocolAddress(jid: string): string
66
+ }
67
+
68
+ export {}
@@ -0,0 +1,3 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,120 @@
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
+
11
+ export type WAVersion = [number, number, number]
12
+
13
+ export type WABrowserDescription = [string, string, string]
14
+
15
+ export type CacheStore = {
16
+ /** get a cached key and change the stats */
17
+ get<T>(key: string): T | undefined
18
+ /** set a key in the cache */
19
+ set<T>(key: string, value: T): void
20
+ /** delete a key from the cache */
21
+ del(key: string): void
22
+ /** flush all data */
23
+ flushAll(): void
24
+ }
25
+
26
+ export type SocketConfig = {
27
+ /** the WS url to connect to WA */
28
+ waWebSocketUrl: string | URL
29
+ /** Fails the connection if the socket times out in this interval */
30
+ connectTimeoutMs: number
31
+ /** Default timeout for queries, undefined for no timeout */
32
+ defaultQueryTimeoutMs: number | undefined
33
+ /** ping-pong interval for WS connection */
34
+ keepAliveIntervalMs: number
35
+ /** should baileys use the mobile api instead of the multi device api
36
+ * @deprecated This feature has been removed
37
+ */
38
+ mobile?: boolean
39
+ /** proxy agent */
40
+ agent?: Agent
41
+ /** logger */
42
+ logger: ILogger
43
+ /** version to connect with */
44
+ version: WAVersion
45
+ /** override browser config */
46
+ browser: WABrowserDescription
47
+ /** agent used for fetch requests -- uploading/downloading media */
48
+ fetchAgent?: Agent
49
+ /** should the QR be printed in the terminal */
50
+ printQRInTerminal: boolean
51
+ /** should events be emitted for actions done by this socket connection */
52
+ emitOwnEvents: boolean
53
+ /** custom upload hosts to upload media to */
54
+ customUploadHosts: MediaConnInfo['hosts']
55
+ /** time to wait between sending new retry requests */
56
+ retryRequestDelayMs: number
57
+ /** max retry count */
58
+ maxMsgRetryCount: number
59
+ /** time to wait for the generation of the next QR in ms */
60
+ qrTimeout?: number
61
+ /** provide an auth state object to maintain the auth state */
62
+ auth: AuthenticationState
63
+ /** manage history processing with this control by default will sync up everything */
64
+ shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => boolean
65
+ /** transaction capability options for SignalKeyStore */
66
+ transactionOpts: TransactionCapabilityOptions
67
+ /** marks the client as online whenever the socket successfully connects */
68
+ markOnlineOnConnect: boolean
69
+ /** alphanumeric country code (USA -> US) for the number used */
70
+ countryCode: string
71
+ /** provide a cache to store media, so does not have to be re-uploaded */
72
+ mediaCache?: CacheStore
73
+ /**
74
+ * map to store the retry counts for failed messages
75
+ * used to determine whether to retry a message or not */
76
+ msgRetryCounterCache?: CacheStore
77
+ /** provide a cache to store a user's device list */
78
+ userDevicesCache?: CacheStore
79
+ /** cache to store call offers */
80
+ callOfferCache?: CacheStore
81
+ /** cache to track placeholder resends */
82
+ placeholderResendCache?: CacheStore
83
+ /** width for link preview images */
84
+ linkPreviewImageThumbnailWidth: number
85
+ /** Should Baileys ask the phone for full history, will be received async */
86
+ syncFullHistory: boolean
87
+ /** Should baileys fire init queries automatically, default true */
88
+ fireInitQueries: boolean
89
+ /**
90
+ * generate a high quality link preview,
91
+ * entails uploading the jpegThumbnail to WA
92
+ * */
93
+ generateHighQualityLinkPreview: boolean
94
+ /**
95
+ * Returns if a jid should be ignored,
96
+ * no event for that jid will be triggered.
97
+ * Messages from that jid will also not be decrypted
98
+ * */
99
+ shouldIgnoreJid: (jid: string) => boolean | undefined
100
+ /**
101
+ * Optionally patch the message before sending out
102
+ * */
103
+ patchMessageBeforeSending: (msg: proto.IMessage, recipientJids: string[]) => Promise<proto.IMessage> | proto.IMessage
104
+ /** verify app state MACs */
105
+ appStateMacVerification: {
106
+ patch: boolean
107
+ snapshot: boolean
108
+ }
109
+ /** options for axios */
110
+ options: AxiosRequestConfig<{}>
111
+ /**
112
+ * fetch a message from your store
113
+ * implement this so that messages failed to send
114
+ * (solves the "this message can take a while" issue) can be retried
115
+ * */
116
+ getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>
117
+ /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
118
+ cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>
119
+ makeSignalRepository: (auth: SignalAuthState) => SignalRepository
120
+ }
@@ -0,0 +1,3 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,29 @@
1
+ import { Contact } from './Contact'
2
+
3
+ export type WAConnectionState = 'open' | 'connecting' | 'close'
4
+
5
+ export type ConnectionState = {
6
+ /** connection is now open, connecting or closed */
7
+ connection: WAConnectionState
8
+ /** the error that caused the connection to close */
9
+ lastDisconnect?: {
10
+ error: Error | undefined
11
+ date: Date
12
+ }
13
+ /** is this a new login */
14
+ isNewLogin?: boolean
15
+ /** the current QR code */
16
+ qr?: string
17
+ /** has the device received all pending notifications while it was offline */
18
+ receivedPendingNotifications?: boolean
19
+ /** legacy connection options */
20
+ legacy?: {
21
+ phoneConnected: boolean
22
+ user?: Contact
23
+ }
24
+ /**
25
+ * if the client is shown as an active, online client.
26
+ * If this is false, the primary phone and other devices will receive notifs
27
+ * */
28
+ isOnline?: boolean
29
+ }
@@ -0,0 +1,3 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,26 @@
1
+ import { BinaryNode } from '../WABinary'
2
+ import { USyncUser } from '../WAUSync'
3
+
4
+ /**
5
+ * Defines the interface for a USyncQuery protocol
6
+ */
7
+ export interface USyncQueryProtocol {
8
+ /**
9
+ * The name of the protocol
10
+ */
11
+ name: string
12
+ /**
13
+ * Defines what goes inside the query part of a USyncQuery
14
+ */
15
+ getQueryElement: () => BinaryNode
16
+ /**
17
+ * Defines what goes inside the user part of a USyncQuery
18
+ */
19
+ getUserElement: (user: USyncUser) => BinaryNode | null
20
+ /**
21
+ * Parse the result of the query
22
+ * @param data Data from the result
23
+ * @returns Whatever the protocol is supposed to return
24
+ */
25
+ parser: (data: BinaryNode) => unknown
26
+ }
@@ -0,0 +1,3 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
@@ -0,0 +1,78 @@
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
+
14
+ import { AuthenticationState } from './Auth'
15
+ import { SocketConfig } from './Socket'
16
+
17
+ export type UserFacingSocketConfig = Partial<SocketConfig> & {
18
+ auth: AuthenticationState
19
+ }
20
+
21
+ export type BrowsersMap = {
22
+ ubuntu(browser: string): [string, string, string]
23
+ macOS(browser: string): [string, string, string]
24
+ windows(browser: string): [string, string, string]
25
+ linux(browser: string): [string, string, string]
26
+ android(browser: string): [string, string, string]
27
+ iOS(browser: string): [string, string, string]
28
+ baileys(browser: string): [string, string, string]
29
+ kaiOS(browser: string): [string, string, string]
30
+ chromeOS(browser: string): [string, string, string]
31
+ appropriate(browser: string): [string, string, string]
32
+ custom(platform: string, browser: string, version: string): [string, string, string]
33
+ }
34
+
35
+ export declare const enum DisconnectReason {
36
+ connectionClosed = 428,
37
+ connectionLost = 408,
38
+ connectionReplaced = 440,
39
+ timedOut = 408,
40
+ loggedOut = 401,
41
+ badSession = 500,
42
+ restartRequired = 515,
43
+ multideviceMismatch = 411,
44
+ forbidden = 403,
45
+ unavailableService = 503
46
+ }
47
+
48
+ export type WAInitResponse = {
49
+ ref: string
50
+ ttl: number
51
+ status: 200
52
+ }
53
+
54
+ export type WABusinessHoursConfig = {
55
+ day_of_week: string
56
+ mode: string
57
+ open_time?: number
58
+ close_time?: number
59
+ }
60
+
61
+ export type WABusinessProfile = {
62
+ description: string
63
+ email: string | undefined
64
+ business_hours: {
65
+ timezone?: string
66
+ config?: WABusinessHoursConfig[]
67
+ business_config?: WABusinessHoursConfig[]
68
+ }
69
+ website: string[]
70
+ category?: string
71
+ wid?: string
72
+ address?: string
73
+ }
74
+
75
+ export type CurveKeyPair = {
76
+ private: Uint8Array
77
+ public: Uint8Array
78
+ }
@@ -0,0 +1,47 @@
1
+ "use strict"
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
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)
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ }
18
+
19
+ Object.defineProperty(exports, "__esModule", { value: true })
20
+
21
+ exports.DisconnectReason = void 0;
22
+ __exportStar(require("./Auth"), exports)
23
+ __exportStar(require("./GroupMetadata"), exports)
24
+ __exportStar(require("./Chat"), exports)
25
+ __exportStar(require("./Contact"), exports)
26
+ __exportStar(require("./State"), exports)
27
+ __exportStar(require("./Message"), exports)
28
+ __exportStar(require("./Newsletter"), exports)
29
+ __exportStar(require("./Socket"), exports)
30
+ __exportStar(require("./Events"), exports)
31
+ __exportStar(require("./Product"), exports)
32
+ __exportStar(require("./Call"), exports)
33
+ __exportStar(require("./Signal"), exports)
34
+
35
+ const DisconnectReason = {
36
+ connectionClosed: 428,
37
+ connectionLost: 408,
38
+ connectionReplaced: 440,
39
+ timedOut: 408,
40
+ loggedOut: 401,
41
+ badSession: 500,
42
+ restartRequired: 515,
43
+ multideviceMismatch: 411,
44
+ forbidden: 403,
45
+ unavailableService: 503
46
+ }
47
+ exports.DisconnectReason = DisconnectReason
@@ -0,0 +1,21 @@
1
+ import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types'
2
+ import { ILogger } from './logger'
3
+
4
+ /**
5
+ * Adds caching capability to a SignalKeyStore
6
+ * @param store the store to add caching to
7
+ * @param logger to log trace events
8
+ * @param _cache cache store to use
9
+ */
10
+ export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger?: ILogger, _cache?: CacheStore): SignalKeyStore
11
+
12
+ /**
13
+ * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
14
+ * this allows batch read & write operations & improves the performance of the lib
15
+ * @param state the key store to apply this capability to
16
+ * @param logger logger to log events
17
+ * @returns SignalKeyStore with transaction capability
18
+ */
19
+ export declare const addTransactionCapability: (state: SignalKeyStore, logger?: ILogger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction
20
+
21
+ export declare const initAuthCreds: () => AuthenticationCreds
@@ -0,0 +1,205 @@
1
+ "use strict"
2
+
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod }
5
+ }
6
+
7
+ Object.defineProperty(exports, "__esModule", { value: true })
8
+
9
+ const crypto_1 = require("crypto")
10
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"))
11
+ const Defaults_1 = require("../Defaults")
12
+ const crypto_2 = require("./crypto")
13
+ const generics_1 = require("./generics")
14
+
15
+ /**
16
+ * Adds caching capability to a SignalKeyStore
17
+ * @param store the store to add caching to
18
+ * @param logger to log trace events
19
+ * @param _cache cache store to use
20
+ */
21
+ function makeCacheableSignalKeyStore(store, logger, _cache) {
22
+ const cache = _cache || new node_cache_1.default({
23
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
24
+ useClones: false,
25
+ deleteOnExpire: true,
26
+ })
27
+ function getUniqueId(type, id) {
28
+ return `${type}.${id}`
29
+ }
30
+ return {
31
+ async get(type, ids) {
32
+ const data = {}
33
+ const idsToFetch = []
34
+ for (const id of ids) {
35
+ const item = cache.get(getUniqueId(type, id))
36
+ if (typeof item !== 'undefined') {
37
+ data[id] = item
38
+ }
39
+ else {
40
+ idsToFetch.push(id)
41
+ }
42
+ }
43
+ if (idsToFetch.length) {
44
+ logger.trace({ items: idsToFetch.length }, 'loading from store')
45
+ const fetched = await store.get(type, idsToFetch)
46
+ for (const id of idsToFetch) {
47
+ const item = fetched[id]
48
+ if (item) {
49
+ data[id] = item
50
+ cache.set(getUniqueId(type, id), item)
51
+ }
52
+ }
53
+ }
54
+ return data
55
+ },
56
+ async set(data) {
57
+ let keys = 0
58
+ for (const type in data) {
59
+ for (const id in data[type]) {
60
+ cache.set(getUniqueId(type, id), data[type][id])
61
+ keys += 1
62
+ }
63
+ }
64
+ logger.trace({ keys }, 'updated cache')
65
+ await store.set(data)
66
+ },
67
+ async clear() {
68
+ cache.flushAll()
69
+ await store.clear?.call(store)
70
+ }
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
76
+ * this allows batch read & write operations & improves the performance of the lib
77
+ * @param state the key store to apply this capability to
78
+ * @param logger logger to log events
79
+ * @returns SignalKeyStore with transaction capability
80
+ */
81
+ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
82
+ // number of queries made to the DB during the transaction
83
+ // only there for logging purposes
84
+ let dbQueriesInTransaction = 0
85
+ let transactionCache = {}
86
+ let mutations = {}
87
+ let transactionsInProgress = 0
88
+ return {
89
+ get: async (type, ids) => {
90
+ if (isInTransaction()) {
91
+ const dict = transactionCache[type]
92
+ const idsRequiringFetch = dict
93
+ ? ids.filter(item => typeof dict[item] === 'undefined')
94
+ : ids
95
+ // only fetch if there are any items to fetch
96
+ if (idsRequiringFetch.length) {
97
+ dbQueriesInTransaction += 1
98
+ const result = await state.get(type, idsRequiringFetch)
99
+ transactionCache[type] || (transactionCache[type] = {})
100
+ Object.assign(transactionCache[type], result)
101
+ }
102
+ return ids.reduce((dict, id) => {
103
+ const value = transactionCache[type]?.[id]
104
+ if (value) {
105
+ dict[id] = value
106
+ }
107
+ return dict
108
+ }, {})
109
+ }
110
+ else {
111
+ return state.get(type, ids)
112
+ }
113
+ },
114
+ set: data => {
115
+ if (isInTransaction()) {
116
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction')
117
+ for (const key in data) {
118
+ transactionCache[key] = transactionCache[key] || {}
119
+ Object.assign(transactionCache[key], data[key])
120
+ mutations[key] = mutations[key] || {}
121
+ Object.assign(mutations[key], data[key])
122
+ }
123
+ }
124
+ else {
125
+ return state.set(data)
126
+ }
127
+ },
128
+ isInTransaction,
129
+ async transaction(work) {
130
+ let result
131
+ transactionsInProgress += 1
132
+ if (transactionsInProgress === 1) {
133
+ logger.trace('entering transaction')
134
+ }
135
+ try {
136
+ result = await work()
137
+ // commit if this is the outermost transaction
138
+ if (transactionsInProgress === 1) {
139
+ if (Object.keys(mutations).length) {
140
+ logger.trace('committing transaction')
141
+ // retry mechanism to ensure we've some recovery
142
+ // in case a transaction fails in the first attempt
143
+ let tries = maxCommitRetries
144
+ while (tries) {
145
+ tries -= 1
146
+ try {
147
+ await state.set(mutations)
148
+ logger.trace({ dbQueriesInTransaction }, 'committed transaction')
149
+ break
150
+ }
151
+ catch (error) {
152
+ logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`)
153
+ await generics_1.delay(delayBetweenTriesMs)
154
+ }
155
+ }
156
+ }
157
+ else {
158
+ logger.trace('no mutations in transaction')
159
+ }
160
+ }
161
+ }
162
+ finally {
163
+ transactionsInProgress -= 1
164
+ if (transactionsInProgress === 0) {
165
+ transactionCache = {}
166
+ mutations = {}
167
+ dbQueriesInTransaction = 0
168
+ }
169
+ }
170
+ return result
171
+ }
172
+ }
173
+ function isInTransaction() {
174
+ return transactionsInProgress > 0
175
+ }
176
+ }
177
+
178
+ const initAuthCreds = () => {
179
+ const identityKey = crypto_2.Curve.generateKeyPair()
180
+ return {
181
+ noiseKey: crypto_2.Curve.generateKeyPair(),
182
+ pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
183
+ signedIdentityKey: identityKey,
184
+ signedPreKey: crypto_2.signedKeyPair(identityKey, 1),
185
+ registrationId: generics_1.generateRegistrationId(),
186
+ advSecretKey: crypto_1.randomBytes(32).toString('base64'),
187
+ processedHistoryMessages: [],
188
+ nextPreKeyId: 1,
189
+ firstUnuploadedPreKeyId: 1,
190
+ accountSyncCounter: 0,
191
+ accountSettings: {
192
+ unarchiveChats: false
193
+ },
194
+ registered: false,
195
+ pairingCode: undefined,
196
+ lastPropHash: undefined,
197
+ routingInfo: undefined
198
+ }
199
+ }
200
+
201
+ module.exports = {
202
+ makeCacheableSignalKeyStore,
203
+ addTransactionCapability,
204
+ initAuthCreds
205
+ }
@@ -0,0 +1,18 @@
1
+ import type { BaileysEventEmitter } from '../Types'
2
+
3
+ /**
4
+ * Captures events from a baileys event emitter & stores them in a file
5
+ * @param ev The event emitter to read events from
6
+ * @param filename File to save to
7
+ */
8
+ export declare const captureEventStream: (ev: BaileysEventEmitter, filename: string) => void
9
+
10
+ /**
11
+ * Read event file and emit events from there
12
+ * @param filename filename containing event data
13
+ * @param delayIntervalMs delay between each event emit
14
+ */
15
+ export declare const readAndEmitEventStream: (filename: string, delayIntervalMs?: number) => {
16
+ ev: BaileysEventEmitter
17
+ task: Promise<void>
18
+ }