sanka-baileyss 1.4.8

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 (252) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2520 -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/Cert/Cert.d.ts +497 -0
  7. package/WAProto/Cert/Cert.js +1503 -0
  8. package/WAProto/Cert/Cert.proto +28 -0
  9. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +391 -0
  10. package/WAProto/ChatLockSettings/ChatLockSettings.js +1155 -0
  11. package/WAProto/ChatLockSettings/ChatLockSettings.proto +7 -0
  12. package/WAProto/CompanionReg/CompanionReg.d.ts +1049 -0
  13. package/WAProto/CompanionReg/CompanionReg.js +3496 -0
  14. package/WAProto/CompanionReg/CompanionReg.proto +88 -0
  15. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +187 -0
  16. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +520 -0
  17. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +14 -0
  18. package/WAProto/E2E/E2E.d.ts +27989 -0
  19. package/WAProto/E2E/E2E.js +97013 -0
  20. package/WAProto/E2E/E2E.proto +2256 -0
  21. package/WAProto/Ephemeral/Ephemeral.d.ts +95 -0
  22. package/WAProto/Ephemeral/Ephemeral.js +269 -0
  23. package/WAProto/Ephemeral/Ephemeral.proto +6 -0
  24. package/WAProto/HistorySync/HistorySync.d.ts +40300 -0
  25. package/WAProto/HistorySync/HistorySync.js +141555 -0
  26. package/WAProto/HistorySync/HistorySync.proto +207 -0
  27. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +189 -0
  28. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +585 -0
  29. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +11 -0
  30. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +461 -0
  31. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +1559 -0
  32. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +37 -0
  33. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +28866 -0
  34. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +100307 -0
  35. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +76 -0
  36. package/WAProto/MmsRetry/MmsRetry.d.ts +200 -0
  37. package/WAProto/MmsRetry/MmsRetry.js +586 -0
  38. package/WAProto/MmsRetry/MmsRetry.proto +17 -0
  39. package/WAProto/Protocol/Protocol.d.ts +218 -0
  40. package/WAProto/Protocol/Protocol.js +701 -0
  41. package/WAProto/Protocol/Protocol.proto +20 -0
  42. package/WAProto/Reporting/Reporting.d.ts +301 -0
  43. package/WAProto/Reporting/Reporting.js +989 -0
  44. package/WAProto/Reporting/Reporting.proto +19 -0
  45. package/WAProto/ServerSync/ServerSync.d.ts +1050 -0
  46. package/WAProto/ServerSync/ServerSync.js +3176 -0
  47. package/WAProto/ServerSync/ServerSync.proto +59 -0
  48. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +1507 -0
  49. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +4756 -0
  50. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +88 -0
  51. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +617 -0
  52. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1940 -0
  53. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +38 -0
  54. package/WAProto/StatusAttributions/StatusAttributions.d.ts +544 -0
  55. package/WAProto/StatusAttributions/StatusAttributions.js +1769 -0
  56. package/WAProto/StatusAttributions/StatusAttributions.proto +53 -0
  57. package/WAProto/SyncAction/SyncAction.d.ts +7227 -0
  58. package/WAProto/SyncAction/SyncAction.js +22271 -0
  59. package/WAProto/SyncAction/SyncAction.proto +423 -0
  60. package/WAProto/UserPassword/UserPassword.d.ts +298 -0
  61. package/WAProto/UserPassword/UserPassword.js +898 -0
  62. package/WAProto/UserPassword/UserPassword.proto +27 -0
  63. package/WAProto/VnameCert/VnameCert.d.ts +658 -0
  64. package/WAProto/VnameCert/VnameCert.js +2225 -0
  65. package/WAProto/VnameCert/VnameCert.proto +60 -0
  66. package/WAProto/Wa6/Wa6.d.ts +1613 -0
  67. package/WAProto/Wa6/Wa6.js +6299 -0
  68. package/WAProto/Wa6/Wa6.proto +229 -0
  69. package/WAProto/Web/Web.d.ts +31290 -0
  70. package/WAProto/Web/Web.js +111977 -0
  71. package/WAProto/Web/Web.proto +545 -0
  72. package/WAProto/index.d.ts +49 -0
  73. package/WAProto/index.js +28 -0
  74. package/WASignalGroup/GroupProtocol.js +1771 -0
  75. package/WASignalGroup/ciphertext_message.js +10 -0
  76. package/WASignalGroup/group_cipher.js +103 -0
  77. package/WASignalGroup/group_session_builder.js +39 -0
  78. package/WASignalGroup/index.js +5 -0
  79. package/WASignalGroup/keyhelper.js +17 -0
  80. package/WASignalGroup/protobufs.js +2 -0
  81. package/WASignalGroup/queue_job.js +64 -0
  82. package/WASignalGroup/sender_chain_key.js +38 -0
  83. package/WASignalGroup/sender_key_distribution_message.js +68 -0
  84. package/WASignalGroup/sender_key_message.js +79 -0
  85. package/WASignalGroup/sender_key_name.js +59 -0
  86. package/WASignalGroup/sender_key_record.js +47 -0
  87. package/WASignalGroup/sender_key_state.js +110 -0
  88. package/WASignalGroup/sender_message_key.js +30 -0
  89. package/check-node-version.js +10 -0
  90. package/lib/Defaults/baileys-version.json +3 -0
  91. package/lib/Defaults/index.d.ts +51 -0
  92. package/lib/Defaults/index.js +108 -0
  93. package/lib/Defaults/phonenumber-mcc.json +223 -0
  94. package/lib/Signal/libsignal.d.ts +3 -0
  95. package/lib/Signal/libsignal.js +153 -0
  96. package/lib/Socket/Client/index.d.ts +2 -0
  97. package/lib/Socket/Client/index.js +18 -0
  98. package/lib/Socket/Client/types.d.ts +15 -0
  99. package/lib/Socket/Client/types.js +14 -0
  100. package/lib/Socket/Client/websocket.d.ts +12 -0
  101. package/lib/Socket/Client/websocket.js +57 -0
  102. package/lib/Socket/business.d.ts +181 -0
  103. package/lib/Socket/business.js +259 -0
  104. package/lib/Socket/chats.d.ts +95 -0
  105. package/lib/Socket/chats.js +906 -0
  106. package/lib/Socket/groups.d.ts +128 -0
  107. package/lib/Socket/groups.js +307 -0
  108. package/lib/Socket/index.d.ts +183 -0
  109. package/lib/Socket/index.js +10 -0
  110. package/lib/Socket/messages-recv.d.ts +170 -0
  111. package/lib/Socket/messages-recv.js +1072 -0
  112. package/lib/Socket/messages-send.d.ts +161 -0
  113. package/lib/Socket/messages-send.js +984 -0
  114. package/lib/Socket/newsletter.d.ts +140 -0
  115. package/lib/Socket/newsletter.js +242 -0
  116. package/lib/Socket/socket.d.ts +43 -0
  117. package/lib/Socket/socket.js +651 -0
  118. package/lib/Socket/usync.d.ts +36 -0
  119. package/lib/Socket/usync.js +71 -0
  120. package/lib/Store/index.d.ts +4 -0
  121. package/lib/Store/index.js +20 -0
  122. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  123. package/lib/Store/make-cache-manager-store.js +85 -0
  124. package/lib/Store/make-in-memory-store.d.ts +117 -0
  125. package/lib/Store/make-in-memory-store.js +420 -0
  126. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  127. package/lib/Store/make-ordered-dictionary.js +83 -0
  128. package/lib/Store/object-repository.d.ts +10 -0
  129. package/lib/Store/object-repository.js +28 -0
  130. package/lib/Types/Auth.d.ts +103 -0
  131. package/lib/Types/Auth.js +2 -0
  132. package/lib/Types/Call.d.ts +13 -0
  133. package/lib/Types/Call.js +2 -0
  134. package/lib/Types/Chat.d.ts +115 -0
  135. package/lib/Types/Chat.js +6 -0
  136. package/lib/Types/Contact.d.ts +24 -0
  137. package/lib/Types/Contact.js +2 -0
  138. package/lib/Types/Events.d.ts +208 -0
  139. package/lib/Types/Events.js +2 -0
  140. package/lib/Types/GroupMetadata.d.ts +58 -0
  141. package/lib/Types/GroupMetadata.js +2 -0
  142. package/lib/Types/Label.d.ts +46 -0
  143. package/lib/Types/Label.js +28 -0
  144. package/lib/Types/LabelAssociation.d.ts +29 -0
  145. package/lib/Types/LabelAssociation.js +10 -0
  146. package/lib/Types/Message.d.ts +391 -0
  147. package/lib/Types/Message.js +9 -0
  148. package/lib/Types/Newsletter.d.ts +92 -0
  149. package/lib/Types/Newsletter.js +33 -0
  150. package/lib/Types/Product.d.ts +78 -0
  151. package/lib/Types/Product.js +2 -0
  152. package/lib/Types/Signal.d.ts +57 -0
  153. package/lib/Types/Signal.js +2 -0
  154. package/lib/Types/Socket.d.ts +116 -0
  155. package/lib/Types/Socket.js +2 -0
  156. package/lib/Types/State.d.ts +27 -0
  157. package/lib/Types/State.js +2 -0
  158. package/lib/Types/USync.d.ts +25 -0
  159. package/lib/Types/USync.js +2 -0
  160. package/lib/Types/index.d.ts +70 -0
  161. package/lib/Types/index.js +42 -0
  162. package/lib/Utils/auth-utils.d.ts +18 -0
  163. package/lib/Utils/auth-utils.js +198 -0
  164. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  165. package/lib/Utils/baileys-event-stream.js +64 -0
  166. package/lib/Utils/business.d.ts +22 -0
  167. package/lib/Utils/business.js +239 -0
  168. package/lib/Utils/chat-utils.d.ts +70 -0
  169. package/lib/Utils/chat-utils.js +754 -0
  170. package/lib/Utils/crypto.d.ts +40 -0
  171. package/lib/Utils/crypto.js +150 -0
  172. package/lib/Utils/decode-wa-message.d.ts +36 -0
  173. package/lib/Utils/decode-wa-message.js +228 -0
  174. package/lib/Utils/event-buffer.d.ts +35 -0
  175. package/lib/Utils/event-buffer.js +539 -0
  176. package/lib/Utils/generics.d.ts +96 -0
  177. package/lib/Utils/generics.js +553 -0
  178. package/lib/Utils/history.d.ts +19 -0
  179. package/lib/Utils/history.js +93 -0
  180. package/lib/Utils/index.d.ts +19 -0
  181. package/lib/Utils/index.js +35 -0
  182. package/lib/Utils/link-preview.d.ts +21 -0
  183. package/lib/Utils/link-preview.js +112 -0
  184. package/lib/Utils/logger.d.ts +11 -0
  185. package/lib/Utils/logger.js +7 -0
  186. package/lib/Utils/lt-hash.d.ts +12 -0
  187. package/lib/Utils/lt-hash.js +53 -0
  188. package/lib/Utils/make-mutex.d.ts +7 -0
  189. package/lib/Utils/make-mutex.js +45 -0
  190. package/lib/Utils/messages-media.d.ts +104 -0
  191. package/lib/Utils/messages-media.js +751 -0
  192. package/lib/Utils/messages.d.ts +80 -0
  193. package/lib/Utils/messages.js +1371 -0
  194. package/lib/Utils/noise-handler.d.ts +19 -0
  195. package/lib/Utils/noise-handler.js +150 -0
  196. package/lib/Utils/process-message.d.ts +41 -0
  197. package/lib/Utils/process-message.js +378 -0
  198. package/lib/Utils/signal.d.ts +33 -0
  199. package/lib/Utils/signal.js +154 -0
  200. package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -0
  201. package/lib/Utils/use-mongo-file-auth-state.js +75 -0
  202. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  203. package/lib/Utils/use-multi-file-auth-state.js +123 -0
  204. package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
  205. package/lib/Utils/use-single-file-auth-state.js +75 -0
  206. package/lib/Utils/validate-connection.d.ts +10 -0
  207. package/lib/Utils/validate-connection.js +174 -0
  208. package/lib/WABinary/constants.d.ts +27 -0
  209. package/lib/WABinary/constants.js +45 -0
  210. package/lib/WABinary/decode.d.ts +6 -0
  211. package/lib/WABinary/decode.js +255 -0
  212. package/lib/WABinary/encode.d.ts +2 -0
  213. package/lib/WABinary/encode.js +243 -0
  214. package/lib/WABinary/generic-utils.d.ts +16 -0
  215. package/lib/WABinary/generic-utils.js +125 -0
  216. package/lib/WABinary/index.d.ts +5 -0
  217. package/lib/WABinary/index.js +21 -0
  218. package/lib/WABinary/jid-utils.d.ts +34 -0
  219. package/lib/WABinary/jid-utils.js +73 -0
  220. package/lib/WABinary/types.d.ts +18 -0
  221. package/lib/WABinary/types.js +2 -0
  222. package/lib/WAM/BinaryInfo.d.ts +16 -0
  223. package/lib/WAM/BinaryInfo.js +14 -0
  224. package/lib/WAM/constants.d.ts +39 -0
  225. package/lib/WAM/constants.js +15362 -0
  226. package/lib/WAM/encode.d.ts +2 -0
  227. package/lib/WAM/encode.js +156 -0
  228. package/lib/WAM/index.d.ts +3 -0
  229. package/lib/WAM/index.js +19 -0
  230. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +25 -0
  231. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +60 -0
  232. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  233. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  234. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  235. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  236. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  237. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  238. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +8 -0
  239. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +26 -0
  240. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  241. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  242. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  243. package/lib/WAUSync/Protocols/index.js +22 -0
  244. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  245. package/lib/WAUSync/USyncQuery.js +88 -0
  246. package/lib/WAUSync/USyncUser.d.ts +12 -0
  247. package/lib/WAUSync/USyncUser.js +27 -0
  248. package/lib/WAUSync/index.d.ts +3 -0
  249. package/lib/WAUSync/index.js +19 -0
  250. package/lib/index.d.ts +13 -0
  251. package/lib/index.js +9 -0
  252. package/package.json +66 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": [2, 3000, 1023380135]
3
+ }
@@ -0,0 +1,51 @@
1
+ import { proto } from '../../WAProto'
2
+ import type { MediaType, SocketConfig } from '../Types'
3
+ export declare const UNAUTHORIZED_CODES: number[]
4
+ export declare const PHONENUMBER_MCC: Record<string, number>
5
+ export declare const DEFAULT_ORIGIN: "https://web.whatsapp.com"
6
+ export declare const DEF_CALLBACK_PREFIX: "CB:"
7
+ export declare const DEF_TAG_PREFIX: "TAG:"
8
+ export declare const PHONE_CONNECTION_CB: "CB:Pong"
9
+ export declare const WA_DEFAULT_EPHEMERAL: number
10
+ export declare const NOISE_MODE: "Noise_XX_25519_AESGCM_SHA256\0\0\0\0"
11
+ export declare const DICT_VERSION: 2
12
+ export declare const KEY_BUNDLE_TYPE: Buffer
13
+ export declare const NOISE_WA_HEADER: Buffer
14
+ export declare const URL_REGEX: RegExp
15
+ export declare const WA_CERT_DETAILS: {
16
+ SERIAL: number
17
+ }
18
+ export declare const PROCESSABLE_HISTORY_TYPES: proto.Message.HistorySyncNotification.HistorySyncType[]
19
+ export declare const DEFAULT_CONNECTION_CONFIG: SocketConfig
20
+ export declare const MEDIA_PATH_MAP: {
21
+ [T in MediaType]?: string
22
+ }
23
+ export declare const MEDIA_HKDF_KEY_MAPPING: {
24
+ 'audio': string
25
+ 'document': string
26
+ 'gif': string
27
+ 'image': string
28
+ 'ppic': string
29
+ 'product': string
30
+ 'ptt': string
31
+ 'sticker': string
32
+ 'video': string
33
+ 'thumbnail-document': string
34
+ 'thumbnail-image': string
35
+ 'thumbnail-video': string
36
+ 'thumbnail-link': string
37
+ 'md-msg-hist': string
38
+ 'md-app-state': string
39
+ 'product-catalog-image': string
40
+ 'payment-bg-image': string
41
+ 'ptv': string
42
+ }
43
+ export declare const MEDIA_KEYS: (keyof typeof MEDIA_HKDF_KEY_MAPPING)[]
44
+ export declare const MIN_PREKEY_COUNT: 5
45
+ export declare const INITIAL_PREKEY_COUNT: 30
46
+ export declare const DEFAULT_CACHE_TTLS: {
47
+ SIGNAL_STORE: number
48
+ MSG_RETRY: number
49
+ CALL_OFFER: number
50
+ USER_DEVICES: number
51
+ }
@@ -0,0 +1,108 @@
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
+ exports.DEFAULT_CACHE_TTLS = exports.INITIAL_PREKEY_COUNT = exports.MIN_PREKEY_COUNT = exports.MEDIA_KEYS = exports.MEDIA_HKDF_KEY_MAPPING = exports.MEDIA_PATH_MAP = exports.DEFAULT_CONNECTION_CONFIG = exports.PROCESSABLE_HISTORY_TYPES = exports.WA_CERT_DETAILS = exports.URL_REGEX = exports.NOISE_WA_HEADER = exports.KEY_BUNDLE_TYPE = exports.DICT_VERSION = exports.NOISE_MODE = exports.WA_DEFAULT_EPHEMERAL = exports.PHONE_CONNECTION_CB = exports.DEF_TAG_PREFIX = exports.DEF_CALLBACK_PREFIX = exports.DEFAULT_ORIGIN = exports.UNAUTHORIZED_CODES = null
7
+ const WAProto_1 = require("../../WAProto");
8
+ const libsignal_1 = require("../Signal/libsignal");
9
+ const Utils_1 = require("../Utils");
10
+ const logger_1 = __importDefault(require("../Utils/logger"));
11
+ const baileys_version_json_1 = require("./baileys-version.json");
12
+ const phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"))
13
+ exports.UNAUTHORIZED_CODES = [401, 403, 419]
14
+ exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default
15
+ exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com'
16
+ exports.DEF_CALLBACK_PREFIX = 'CB:'
17
+ exports.DEF_TAG_PREFIX = 'TAG:'
18
+ exports.PHONE_CONNECTION_CB = 'CB:Pong'
19
+ exports.WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
20
+ exports.NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
21
+ exports.DICT_VERSION = 2
22
+ exports.KEY_BUNDLE_TYPE = Buffer.from([5])
23
+ exports.NOISE_WA_HEADER = Buffer.from([87, 65, 6, exports.DICT_VERSION]) // last is "DICT_VERSION"
24
+ /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
25
+ exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g
26
+ exports.WA_CERT_DETAILS = {
27
+ SERIAL: 0,
28
+ }
29
+ exports.PROCESSABLE_HISTORY_TYPES = [
30
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
31
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
32
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
33
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
34
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
35
+ ]
36
+ exports.DEFAULT_CONNECTION_CONFIG = {
37
+ version: baileys_version_json_1.version,
38
+ browser: Utils_1.Browsers.ubuntu('Chrome'),
39
+ waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
40
+ connectTimeoutMs: 20000,
41
+ keepAliveIntervalMs: 30000,
42
+ logger: logger_1.default.child({ class: 'baileys' }),
43
+ printQRInTerminal: false,
44
+ emitOwnEvents: true,
45
+ defaultQueryTimeoutMs: 60000,
46
+ customUploadHosts: [],
47
+ retryRequestDelayMs: 250,
48
+ maxMsgRetryCount: 5,
49
+ fireInitQueries: true,
50
+ auth: undefined,
51
+ markOnlineOnConnect: true,
52
+ syncFullHistory: false,
53
+ patchMessageBeforeSending: msg => msg,
54
+ shouldSyncHistoryMessage: () => true,
55
+ shouldIgnoreJid: () => false,
56
+ linkPreviewImageThumbnailWidth: 192,
57
+ transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
58
+ generateHighQualityLinkPreview: false,
59
+ options: {},
60
+ appStateMacVerification: {
61
+ patch: false,
62
+ snapshot: false,
63
+ },
64
+ countryCode: 'US',
65
+ getMessage: async () => undefined,
66
+ cachedGroupMetadata: async () => undefined,
67
+ makeSignalRepository: libsignal_1.makeLibSignalRepository
68
+ }
69
+ exports.MEDIA_PATH_MAP = {
70
+ image: '/mms/image',
71
+ video: '/mms/video',
72
+ document: '/mms/document',
73
+ audio: '/mms/audio',
74
+ sticker: '/mms/image',
75
+ 'thumbnail-link': '/mms/image',
76
+ 'product-catalog-image': '/product/image',
77
+ 'md-app-state': '',
78
+ 'md-msg-hist': '/mms/md-app-state',
79
+ }
80
+ exports.MEDIA_HKDF_KEY_MAPPING = {
81
+ 'audio': 'Audio',
82
+ 'document': 'Document',
83
+ 'gif': 'Video',
84
+ 'image': 'Image',
85
+ 'ppic': '',
86
+ 'product': 'Image',
87
+ 'ptt': 'Audio',
88
+ 'sticker': 'Image',
89
+ 'video': 'Video',
90
+ 'thumbnail-document': 'Document Thumbnail',
91
+ 'thumbnail-image': 'Image Thumbnail',
92
+ 'thumbnail-video': 'Video Thumbnail',
93
+ 'thumbnail-link': 'Link Thumbnail',
94
+ 'md-msg-hist': 'History',
95
+ 'md-app-state': 'App State',
96
+ 'product-catalog-image': '',
97
+ 'payment-bg-image': 'Payment Background',
98
+ 'ptv': 'Video'
99
+ }
100
+ exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP)
101
+ exports.MIN_PREKEY_COUNT = 5
102
+ exports.INITIAL_PREKEY_COUNT = 30
103
+ exports.DEFAULT_CACHE_TTLS = {
104
+ SIGNAL_STORE: 5 * 60,
105
+ MSG_RETRY: 60 * 60,
106
+ CALL_OFFER: 5 * 60,
107
+ USER_DEVICES: 5 * 60, // 5 minutes
108
+ }
@@ -0,0 +1,223 @@
1
+ {
2
+ "93": 412,
3
+ "355": 276,
4
+ "213": 603,
5
+ "1-684": 544,
6
+ "376": 213,
7
+ "244": 631,
8
+ "1-264": 365,
9
+ "1-268": 344,
10
+ "54": 722,
11
+ "374": 283,
12
+ "297": 363,
13
+ "61": 505,
14
+ "43": 232,
15
+ "994": 400,
16
+ "1-242": 364,
17
+ "973": 426,
18
+ "880": 470,
19
+ "1-246": 342,
20
+ "375": 257,
21
+ "32": 206,
22
+ "501": 702,
23
+ "229": 616,
24
+ "1-441": 350,
25
+ "975": 402,
26
+ "591": 736,
27
+ "387": 218,
28
+ "267": 652,
29
+ "55": 724,
30
+ "1-284": 348,
31
+ "673": 528,
32
+ "359": 284,
33
+ "226": 613,
34
+ "257": 642,
35
+ "855": 456,
36
+ "237": 624,
37
+ "238": 625,
38
+ "1-345": 346,
39
+ "236": 623,
40
+ "235": 622,
41
+ "56": 730,
42
+ "86": 454,
43
+ "57": 732,
44
+ "269": 654,
45
+ "682": 548,
46
+ "506": 712,
47
+ "385": 219,
48
+ "53": 368,
49
+ "357": 280,
50
+ "420": 230,
51
+ "243": 630,
52
+ "45": 238,
53
+ "253": 638,
54
+ "1-767": 366,
55
+ "1-809": 370,
56
+ "1-849": 370,
57
+ "1-829": 370,
58
+ "593": 740,
59
+ "20": 602,
60
+ "503": 706,
61
+ "240": 627,
62
+ "291": 657,
63
+ "372": 248,
64
+ "251": 636,
65
+ "500": 750,
66
+ "298": 288,
67
+ "679": 542,
68
+ "358": 244,
69
+ "33": 208,
70
+ "689": 547,
71
+ "241": 628,
72
+ "220": 607,
73
+ "995": 282,
74
+ "49": 262,
75
+ "233": 620,
76
+ "350": 266,
77
+ "30": 202,
78
+ "299": 290,
79
+ "1-473": 352,
80
+ "1-671": 535,
81
+ "502": 704,
82
+ "224": 537,
83
+ "592": 738,
84
+ "509": 372,
85
+ "504": 708,
86
+ "852": 454,
87
+ "36": 216,
88
+ "354": 274,
89
+ "91": 404,
90
+ "62": 510,
91
+ "98": 432,
92
+ "964": 418,
93
+ "353": 234,
94
+ "972": 425,
95
+ "39": 222,
96
+ "225": 612,
97
+ "1-876": 338,
98
+ "81": 440,
99
+ "962": 416,
100
+ "254": 639,
101
+ "686": 545,
102
+ "383": 221,
103
+ "965": 419,
104
+ "371": 247,
105
+ "961": 415,
106
+ "266": 651,
107
+ "231": 618,
108
+ "218": 606,
109
+ "423": 295,
110
+ "370": 246,
111
+ "352": 270,
112
+ "389": 294,
113
+ "261": 646,
114
+ "265": 650,
115
+ "60": 502,
116
+ "960": 472,
117
+ "223": 610,
118
+ "356": 278,
119
+ "692": 551,
120
+ "222": 609,
121
+ "230": 617,
122
+ "52": 334,
123
+ "691": 550,
124
+ "373": 259,
125
+ "377": 212,
126
+ "976": 428,
127
+ "382": 297,
128
+ "1-664": 354,
129
+ "212": 604,
130
+ "258": 643,
131
+ "95": 414,
132
+ "264": 649,
133
+ "674": 536,
134
+ "977": 429,
135
+ "31": 204,
136
+ "687": 546,
137
+ "64": 530,
138
+ "505": 710,
139
+ "227": 614,
140
+ "234": 621,
141
+ "683": 555,
142
+ "1-670": 534,
143
+ "47": 242,
144
+ "968": 226,
145
+ "92": 410,
146
+ "680": 552,
147
+ "970": 423,
148
+ "507": 714,
149
+ "675": 537,
150
+ "595": 744,
151
+ "51": 716,
152
+ "63": 515,
153
+ "48": 260,
154
+ "351": 268,
155
+ "1-787, 1-939": 330,
156
+ "974": 427,
157
+ "242": 630,
158
+ "40": 226,
159
+ "7": 250,
160
+ "250": 635,
161
+ "290": 658,
162
+ "1-869": 356,
163
+ "1-758": 358,
164
+ "508": 308,
165
+ "1-784": 360,
166
+ "685": 544,
167
+ "378": 292,
168
+ "239": 626,
169
+ "966": 420,
170
+ "221": 608,
171
+ "381": 220,
172
+ "248": 633,
173
+ "232": 619,
174
+ "65": 525,
175
+ "386": 293,
176
+ "677": 540,
177
+ "27": 655,
178
+ "211": 659,
179
+ "34": 214,
180
+ "94": 413,
181
+ "249": 634,
182
+ "597": 746,
183
+ "268": 653,
184
+ "46": 240,
185
+ "41": 228,
186
+ "963": 417,
187
+ "886": 466,
188
+ "992": 436,
189
+ "255": 640,
190
+ "66": 520,
191
+ "228": 615,
192
+ "690": 554,
193
+ "676": 539,
194
+ "1-868": 374,
195
+ "216": 605,
196
+ "90": 286,
197
+ "993": 438,
198
+ "1-649": 376,
199
+ "688": 553,
200
+ "1-340": 332,
201
+ "256": 641,
202
+ "380": 255,
203
+ "971": 424,
204
+ "44": 234,
205
+ "1": 310,
206
+ "598": 748,
207
+ "998": 434,
208
+ "678": 541,
209
+ "379": 225,
210
+ "58": 734,
211
+ "681": 543,
212
+ "967": 421,
213
+ "260": 645,
214
+ "263": 648,
215
+ "670": 514,
216
+ "245": 632,
217
+ "856": 457,
218
+ "599": 362,
219
+ "850": 467,
220
+ "262": 647,
221
+ "82": 450,
222
+ "84": 452
223
+ }
@@ -0,0 +1,3 @@
1
+ import { SignalAuthState } from '../Types'
2
+ import { SignalRepository } from '../Types/Signal'
3
+ export declare function makeLibSignalRepository(auth: SignalAuthState): SignalRepository
@@ -0,0 +1,153 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v })
15
+ }) : function(o, v) {
16
+ o["default"] = v
17
+ })
18
+ 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
24
+ }
25
+ Object.defineProperty(exports, "__esModule", { value: true })
26
+ const libsignal = __importStar(require("libsignal"))
27
+ const WASignalGroup_1 = require("../../WASignalGroup")
28
+ const Utils_1 = require("../Utils")
29
+ const WABinary_1 = require("../WABinary")
30
+ function makeLibSignalRepository(auth) {
31
+ const storage = signalStorage(auth)
32
+ return {
33
+ decryptGroupMessage({ group, authorJid, msg }) {
34
+ const senderName = jidToSignalSenderKeyName(group, authorJid)
35
+ const cipher = new WASignalGroup_1.GroupCipher(storage, senderName)
36
+ return cipher.decrypt(msg)
37
+ },
38
+ async processSenderKeyDistributionMessage({ item, authorJid }) {
39
+ const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
40
+ const senderName = jidToSignalSenderKeyName(item.groupId, authorJid)
41
+ const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage)
42
+ const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
43
+ if (!senderKey) {
44
+ await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
45
+ }
46
+ await builder.process(senderName, senderMsg)
47
+ },
48
+ async decryptMessage({ jid, type, ciphertext }) {
49
+ const addr = jidToSignalProtocolAddress(jid)
50
+ const session = new libsignal.SessionCipher(storage, addr)
51
+ let result
52
+ switch (type) {
53
+ case 'pkmsg':
54
+ result = await session.decryptPreKeyWhisperMessage(ciphertext)
55
+ break
56
+ case 'msg':
57
+ result = await session.decryptWhisperMessage(ciphertext)
58
+ break
59
+ }
60
+ return result
61
+ },
62
+ async encryptMessage({ jid, data }) {
63
+ const addr = jidToSignalProtocolAddress(jid)
64
+ const cipher = new libsignal.SessionCipher(storage, addr)
65
+ const { type: sigType, body } = await cipher.encrypt(data)
66
+ const type = sigType === 3 ? 'pkmsg' : 'msg'
67
+ return { type, ciphertext: Buffer.from(body, 'binary') }
68
+ },
69
+ async encryptGroupMessage({ group, meId, data }) {
70
+ const senderName = jidToSignalSenderKeyName(group, meId)
71
+ const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
72
+ const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
73
+ if (!senderKey) {
74
+ await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
75
+ }
76
+ const senderKeyDistributionMessage = await builder.create(senderName)
77
+ const session = new WASignalGroup_1.GroupCipher(storage, senderName)
78
+ const ciphertext = await session.encrypt(data)
79
+ return {
80
+ ciphertext,
81
+ senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
82
+ }
83
+ },
84
+ async injectE2ESession({ jid, session }) {
85
+ const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid))
86
+ await cipher.initOutgoing(session)
87
+ },
88
+ jidToSignalProtocolAddress(jid) {
89
+ return jidToSignalProtocolAddress(jid).toString()
90
+ },
91
+ }
92
+ }
93
+ const jidToSignalProtocolAddress = (jid) => {
94
+ const { user, device } = WABinary_1.jidDecode(jid)
95
+ return new libsignal.ProtocolAddress(user, device || 0)
96
+ }
97
+ const jidToSignalSenderKeyName = (group, user) => {
98
+ return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString()
99
+ }
100
+ function signalStorage({ creds, keys }) {
101
+ return {
102
+ loadSession: async (id) => {
103
+ const { [id]: sess } = await keys.get('session', [id])
104
+ if (sess) {
105
+ return libsignal.SessionRecord.deserialize(sess)
106
+ }
107
+ },
108
+ storeSession: async (id, session) => {
109
+ await keys.set({ 'session': { [id]: session.serialize() } })
110
+ },
111
+ isTrustedIdentity: () => {
112
+ return true
113
+ },
114
+ loadPreKey: async (id) => {
115
+ const keyId = id.toString()
116
+ const { [keyId]: key } = await keys.get('pre-key', [keyId])
117
+ if (key) {
118
+ return {
119
+ privKey: Buffer.from(key.private),
120
+ pubKey: Buffer.from(key.public)
121
+ }
122
+ }
123
+ },
124
+ removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
125
+ loadSignedPreKey: () => {
126
+ const key = creds.signedPreKey
127
+ return {
128
+ privKey: Buffer.from(key.keyPair.private),
129
+ pubKey: Buffer.from(key.keyPair.public)
130
+ }
131
+ },
132
+ loadSenderKey: async (keyId) => {
133
+ const { [keyId]: key } = await keys.get('sender-key', [keyId])
134
+ if (key) {
135
+ return new WASignalGroup_1.SenderKeyRecord(key)
136
+ }
137
+ },
138
+ storeSenderKey: async (keyId, key) => {
139
+ await keys.set({ 'sender-key': { [keyId]: key.serialize() } })
140
+ },
141
+ getOurRegistrationId: () => (creds.registrationId),
142
+ getOurIdentity: () => {
143
+ const { signedIdentityKey } = creds
144
+ return {
145
+ privKey: Buffer.from(signedIdentityKey.private),
146
+ pubKey: Utils_1.generateSignalPubKey(signedIdentityKey.public),
147
+ }
148
+ }
149
+ }
150
+ }
151
+ module.exports = {
152
+ makeLibSignalRepository
153
+ }
@@ -0,0 +1,2 @@
1
+ export * from './types'
2
+ export * from './websocket'
@@ -0,0 +1,18 @@
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
+ __exportStar(require("./types"), exports)
18
+ __exportStar(require("./websocket"), exports)
@@ -0,0 +1,15 @@
1
+ import { EventEmitter } from 'events'
2
+ import { URL } from 'url'
3
+ import { SocketConfig } from '../../Types'
4
+ export declare abstract class AbstractSocketClient extends EventEmitter {
5
+ url: URL
6
+ config: SocketConfig
7
+ abstract get isOpen(): boolean
8
+ abstract get isClosed(): boolean
9
+ abstract get isClosing(): boolean
10
+ abstract get isConnecting(): boolean
11
+ constructor(url: URL, config: SocketConfig)
12
+ abstract connect(): Promise<void>
13
+ abstract close(): Promise<void>
14
+ abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean
15
+ }
@@ -0,0 +1,14 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const events_1 = require("events")
4
+ class AbstractSocketClient extends events_1.EventEmitter {
5
+ constructor(url, config) {
6
+ super()
7
+ this.url = url
8
+ this.config = config
9
+ this.setMaxListeners(0)
10
+ }
11
+ }
12
+ module.exports = {
13
+ AbstractSocketClient
14
+ }
@@ -0,0 +1,12 @@
1
+ import WebSocket from 'ws'
2
+ import { AbstractSocketClient } from './types'
3
+ export declare class WebSocketClient extends AbstractSocketClient {
4
+ protected socket: WebSocket | null
5
+ get isOpen(): boolean
6
+ get isClosed(): boolean
7
+ get isClosing(): boolean
8
+ get isConnecting(): boolean
9
+ connect(): Promise<void>
10
+ close(): Promise<void>
11
+ send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean
12
+ }
@@ -0,0 +1,57 @@
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 ws_1 = __importDefault(require("ws"))
7
+ const Defaults_1 = require("../../Defaults")
8
+ const types_1 = require("./types")
9
+ class WebSocketClient extends types_1.AbstractSocketClient {
10
+ constructor() {
11
+ super(...arguments)
12
+ this.socket = null
13
+ }
14
+ get isOpen() {
15
+ return this.socket?.readyState === ws_1.default.OPEN
16
+ }
17
+ get isClosed() {
18
+ return this.socket?.readyState === ws_1.default.CLOSED
19
+ }
20
+ get isClosing() {
21
+ this.socket?.readyState === ws_1.default.CLOSING
22
+ }
23
+ get isConnecting() {
24
+ this.socket?.readyState === ws_1.default.CONNECTING
25
+ }
26
+ async connect() {
27
+ if (this.socket) {
28
+ return
29
+ }
30
+ this.socket = new ws_1.default(this.url, {
31
+ origin: Defaults_1.DEFAULT_ORIGIN,
32
+ headers: this.config.options?.headers,
33
+ handshakeTimeout: this.config.connectTimeoutMs,
34
+ timeout: this.config.connectTimeoutMs,
35
+ agent: this.config.agent,
36
+ })
37
+ this.socket.setMaxListeners(0)
38
+ const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response']
39
+ for (const event of events) {
40
+ this.socket?.on(event, (...args) => this.emit(event, ...args))
41
+ }
42
+ }
43
+ async close() {
44
+ if (!this.socket) {
45
+ return
46
+ }
47
+ this.socket.close()
48
+ this.socket = null
49
+ }
50
+ send(str, cb) {
51
+ this.socket?.send(str, cb)
52
+ return Boolean(this.socket)
53
+ }
54
+ }
55
+ module.exports = {
56
+ WebSocketClient
57
+ }