gifted-baileys 1.5.5 → 1.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/README.md +6 -1642
  2. package/WAProto/WAProto.proto +969 -88
  3. package/WAProto/index.d.ts +13199 -1260
  4. package/WAProto/index.js +124901 -74525
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +284 -0
  7. package/{src → lib}/Defaults/index.js +7 -14
  8. package/lib/Signal/libsignal.d.ts +3 -0
  9. package/lib/Signal/libsignal.js +161 -0
  10. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  11. package/lib/Socket/Client/index.d.ts +2 -0
  12. package/{src → lib}/Socket/Client/index.js +2 -3
  13. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  15. package/lib/Socket/Client/types.d.ts +17 -0
  16. package/lib/Socket/Client/types.js +13 -0
  17. package/lib/Socket/Client/websocket.d.ts +12 -0
  18. package/lib/Socket/Client/websocket.js +62 -0
  19. package/lib/Socket/business.d.ts +170 -0
  20. package/{src → lib}/Socket/business.js +28 -33
  21. package/lib/Socket/chats.d.ts +81 -0
  22. package/{src → lib}/Socket/chats.js +174 -176
  23. package/lib/Socket/groups.d.ts +115 -0
  24. package/{src → lib}/Socket/groups.js +80 -68
  25. package/lib/Socket/index.d.ts +172 -0
  26. package/{src → lib}/Socket/index.js +4 -1
  27. package/lib/Socket/messages-recv.d.ts +158 -0
  28. package/{src → lib}/Socket/messages-recv.js +378 -211
  29. package/lib/Socket/messages-send.d.ts +155 -0
  30. package/{src → lib}/Socket/messages-send.js +452 -177
  31. package/lib/Socket/newsletter.d.ts +132 -0
  32. package/{src → lib}/Socket/newsletter.js +107 -98
  33. package/lib/Socket/registration.d.ts +264 -0
  34. package/{src → lib}/Socket/registration.js +56 -48
  35. package/lib/Socket/socket.d.ts +44 -0
  36. package/{src → lib}/Socket/socket.js +77 -77
  37. package/lib/Socket/usync.d.ts +37 -0
  38. package/lib/Socket/usync.js +70 -0
  39. package/lib/Store/index.d.ts +3 -0
  40. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  41. package/{src → lib}/Store/make-cache-manager-store.js +25 -34
  42. package/lib/Store/make-in-memory-store.d.ts +118 -0
  43. package/{src → lib}/Store/make-in-memory-store.js +36 -32
  44. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  45. package/lib/Store/object-repository.d.ts +10 -0
  46. package/{src → lib}/Store/object-repository.js +1 -1
  47. package/lib/Types/Auth.d.ts +109 -0
  48. package/lib/Types/Call.d.ts +13 -0
  49. package/lib/Types/Chat.d.ts +107 -0
  50. package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
  51. package/lib/Types/Events.d.ts +172 -0
  52. package/lib/Types/GroupMetadata.d.ts +56 -0
  53. package/lib/Types/Label.d.ts +46 -0
  54. package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
  55. package/lib/Types/Message.d.ts +433 -0
  56. package/lib/Types/Newsletter.d.ts +92 -0
  57. package/lib/Types/Product.d.ts +78 -0
  58. package/lib/Types/Signal.d.ts +57 -0
  59. package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
  60. package/lib/Types/State.d.ts +27 -0
  61. package/lib/Types/USync.d.ts +25 -0
  62. package/lib/Types/index.d.ts +66 -0
  63. package/lib/Utils/auth-utils.d.ts +18 -0
  64. package/{src → lib}/Utils/auth-utils.js +73 -90
  65. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  66. package/lib/Utils/baileys-event-stream.js +63 -0
  67. package/lib/Utils/business.d.ts +22 -0
  68. package/{src → lib}/Utils/business.js +15 -43
  69. package/lib/Utils/chat-utils.d.ts +70 -0
  70. package/{src → lib}/Utils/chat-utils.js +87 -94
  71. package/lib/Utils/crypto.d.ts +40 -0
  72. package/{src → lib}/Utils/crypto.js +4 -2
  73. package/lib/Utils/decode-wa-message.d.ts +36 -0
  74. package/lib/Utils/decode-wa-message.js +226 -0
  75. package/lib/Utils/event-buffer.d.ts +35 -0
  76. package/{src → lib}/Utils/event-buffer.js +4 -13
  77. package/lib/Utils/generics.d.ts +88 -0
  78. package/{src → lib}/Utils/generics.js +67 -86
  79. package/lib/Utils/history.d.ts +19 -0
  80. package/{src → lib}/Utils/history.js +13 -39
  81. package/lib/Utils/index.d.ts +17 -0
  82. package/lib/Utils/link-preview.d.ts +21 -0
  83. package/{src → lib}/Utils/link-preview.js +17 -54
  84. package/lib/Utils/logger.d.ts +2 -0
  85. package/lib/Utils/lt-hash.d.ts +12 -0
  86. package/lib/Utils/make-mutex.d.ts +7 -0
  87. package/{src → lib}/Utils/make-mutex.js +4 -13
  88. package/lib/Utils/messages-media.d.ts +113 -0
  89. package/{src → lib}/Utils/messages-media.js +193 -255
  90. package/lib/Utils/messages.d.ts +77 -0
  91. package/{src → lib}/Utils/messages.js +588 -118
  92. package/lib/Utils/noise-handler.d.ts +20 -0
  93. package/lib/Utils/process-message.d.ts +41 -0
  94. package/{src → lib}/Utils/process-message.js +27 -30
  95. package/lib/Utils/signal.d.ts +33 -0
  96. package/{src → lib}/Utils/signal.js +25 -42
  97. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  98. package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
  99. package/lib/Utils/validate-connection.d.ts +11 -0
  100. package/{src → lib}/Utils/validate-connection.js +40 -9
  101. package/lib/WABinary/constants.d.ts +27 -0
  102. package/lib/WABinary/decode.d.ts +6 -0
  103. package/lib/WABinary/encode.d.ts +2 -0
  104. package/{src → lib}/WABinary/encode.js +16 -10
  105. package/lib/WABinary/generic-utils.d.ts +14 -0
  106. package/lib/WABinary/index.d.ts +5 -0
  107. package/lib/WABinary/jid-utils.d.ts +31 -0
  108. package/lib/WABinary/types.d.ts +18 -0
  109. package/lib/WABinary/types.js +2 -0
  110. package/lib/WAM/BinaryInfo.d.ts +8 -0
  111. package/lib/WAM/constants.d.ts +38 -0
  112. package/lib/WAM/encode.d.ts +2 -0
  113. package/lib/WAM/index.d.ts +3 -0
  114. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  115. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  116. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  117. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  118. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  119. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  120. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  121. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  122. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  123. package/lib/WAUSync/Protocols/index.js +20 -0
  124. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  125. package/lib/WAUSync/USyncQuery.js +79 -0
  126. package/lib/WAUSync/USyncUser.d.ts +10 -0
  127. package/lib/WAUSync/USyncUser.js +22 -0
  128. package/lib/WAUSync/index.d.ts +3 -0
  129. package/lib/WAUSync/index.js +19 -0
  130. package/{src → lib}/index.js +1 -0
  131. package/package.json +26 -8
  132. package/LICENSE +0 -21
  133. package/src/Defaults/baileys-version.json +0 -3
  134. package/src/Defaults/index.ts +0 -131
  135. package/src/Signal/libsignal.js +0 -180
  136. package/src/Signal/libsignal.ts +0 -141
  137. package/src/Socket/Client/abstract-socket-client.ts +0 -19
  138. package/src/Socket/Client/index.ts +0 -3
  139. package/src/Socket/Client/mobile-socket-client.js +0 -78
  140. package/src/Socket/Client/mobile-socket-client.ts +0 -66
  141. package/src/Socket/Client/web-socket-client.js +0 -75
  142. package/src/Socket/Client/web-socket-client.ts +0 -57
  143. package/src/Socket/business.ts +0 -281
  144. package/src/Socket/chats.ts +0 -1030
  145. package/src/Socket/groups.ts +0 -356
  146. package/src/Socket/index.ts +0 -13
  147. package/src/Socket/messages-recv.ts +0 -985
  148. package/src/Socket/messages-send.ts +0 -871
  149. package/src/Socket/newsletter.ts +0 -282
  150. package/src/Socket/registration.ts +0 -250
  151. package/src/Socket/socket.ts +0 -777
  152. package/src/Store/index.ts +0 -3
  153. package/src/Store/make-cache-manager-store.ts +0 -100
  154. package/src/Store/make-in-memory-store.ts +0 -475
  155. package/src/Store/make-ordered-dictionary.ts +0 -86
  156. package/src/Store/object-repository.ts +0 -32
  157. package/src/Tests/test.app-state-sync.js +0 -204
  158. package/src/Tests/test.app-state-sync.ts +0 -207
  159. package/src/Tests/test.event-buffer.js +0 -270
  160. package/src/Tests/test.event-buffer.ts +0 -319
  161. package/src/Tests/test.key-store.js +0 -76
  162. package/src/Tests/test.key-store.ts +0 -92
  163. package/src/Tests/test.libsignal.js +0 -141
  164. package/src/Tests/test.libsignal.ts +0 -186
  165. package/src/Tests/test.media-download.js +0 -93
  166. package/src/Tests/test.media-download.ts +0 -76
  167. package/src/Tests/test.messages.js +0 -33
  168. package/src/Tests/test.messages.ts +0 -37
  169. package/src/Tests/utils.js +0 -34
  170. package/src/Tests/utils.ts +0 -36
  171. package/src/Types/Auth.ts +0 -113
  172. package/src/Types/Call.ts +0 -15
  173. package/src/Types/Chat.ts +0 -106
  174. package/src/Types/Events.ts +0 -93
  175. package/src/Types/GroupMetadata.ts +0 -53
  176. package/src/Types/Label.ts +0 -36
  177. package/src/Types/Message.ts +0 -288
  178. package/src/Types/Newsletter.ts +0 -98
  179. package/src/Types/Product.ts +0 -85
  180. package/src/Types/Signal.ts +0 -68
  181. package/src/Types/State.ts +0 -29
  182. package/src/Types/index.ts +0 -59
  183. package/src/Utils/auth-utils.ts +0 -222
  184. package/src/Utils/baileys-event-stream.js +0 -92
  185. package/src/Utils/baileys-event-stream.ts +0 -66
  186. package/src/Utils/business.ts +0 -275
  187. package/src/Utils/chat-utils.ts +0 -860
  188. package/src/Utils/crypto.ts +0 -131
  189. package/src/Utils/decode-wa-message.js +0 -211
  190. package/src/Utils/decode-wa-message.ts +0 -228
  191. package/src/Utils/event-buffer.ts +0 -613
  192. package/src/Utils/generics.ts +0 -434
  193. package/src/Utils/history.ts +0 -112
  194. package/src/Utils/index.ts +0 -17
  195. package/src/Utils/link-preview.ts +0 -122
  196. package/src/Utils/logger.ts +0 -3
  197. package/src/Utils/lt-hash.ts +0 -61
  198. package/src/Utils/make-mutex.ts +0 -44
  199. package/src/Utils/messages-media.ts +0 -847
  200. package/src/Utils/messages.ts +0 -956
  201. package/src/Utils/noise-handler.ts +0 -197
  202. package/src/Utils/process-message.ts +0 -414
  203. package/src/Utils/signal.ts +0 -177
  204. package/src/Utils/use-multi-file-auth-state.ts +0 -90
  205. package/src/Utils/validate-connection.ts +0 -238
  206. package/src/WABinary/constants.ts +0 -42
  207. package/src/WABinary/decode.ts +0 -265
  208. package/src/WABinary/encode.ts +0 -236
  209. package/src/WABinary/generic-utils.ts +0 -121
  210. package/src/WABinary/index.ts +0 -5
  211. package/src/WABinary/jid-utils.ts +0 -68
  212. package/src/WABinary/types.ts +0 -17
  213. package/src/WAM/BinaryInfo.ts +0 -12
  214. package/src/WAM/constants.ts +0 -15382
  215. package/src/WAM/encode.ts +0 -174
  216. package/src/WAM/index.ts +0 -3
  217. package/src/gifted +0 -1
  218. package/src/index.ts +0 -13
  219. /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
  220. /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
  221. /package/{src → lib}/Store/index.js +0 -0
  222. /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
  223. /package/{src → lib}/Types/Auth.js +0 -0
  224. /package/{src → lib}/Types/Call.js +0 -0
  225. /package/{src → lib}/Types/Chat.js +0 -0
  226. /package/{src → lib}/Types/Contact.js +0 -0
  227. /package/{src → lib}/Types/Events.js +0 -0
  228. /package/{src → lib}/Types/GroupMetadata.js +0 -0
  229. /package/{src → lib}/Types/Label.js +0 -0
  230. /package/{src → lib}/Types/LabelAssociation.js +0 -0
  231. /package/{src → lib}/Types/Message.js +0 -0
  232. /package/{src → lib}/Types/Newsletter.js +0 -0
  233. /package/{src → lib}/Types/Product.js +0 -0
  234. /package/{src → lib}/Types/Signal.js +0 -0
  235. /package/{src → lib}/Types/Socket.js +0 -0
  236. /package/{src → lib}/Types/State.js +0 -0
  237. /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
  238. /package/{src → lib}/Types/index.js +0 -0
  239. /package/{src → lib}/Utils/index.js +0 -0
  240. /package/{src → lib}/Utils/logger.js +0 -0
  241. /package/{src → lib}/Utils/lt-hash.js +0 -0
  242. /package/{src → lib}/Utils/noise-handler.js +0 -0
  243. /package/{src → lib}/WABinary/constants.js +0 -0
  244. /package/{src → lib}/WABinary/decode.js +0 -0
  245. /package/{src → lib}/WABinary/generic-utils.js +0 -0
  246. /package/{src → lib}/WABinary/index.js +0 -0
  247. /package/{src → lib}/WABinary/jid-utils.js +0 -0
  248. /package/{src → lib}/WAM/BinaryInfo.js +0 -0
  249. /package/{src → lib}/WAM/constants.js +0 -0
  250. /package/{src → lib}/WAM/encode.js +0 -0
  251. /package/{src → lib}/WAM/index.js +0 -0
@@ -27,4 +27,5 @@ __exportStar(require("./Store"), exports);
27
27
  __exportStar(require("./Defaults"), exports);
28
28
  __exportStar(require("./WABinary"), exports);
29
29
  __exportStar(require("./WAM"), exports);
30
+ __exportStar(require("./WAUSync"), exports);
30
31
  exports.default = Socket_1.default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gifted-baileys",
3
- "version": "1.5.5",
4
- "description": "Typescript/Javascript WhatsApp Web API",
3
+ "version": "1.5.7",
4
+ "description": "Typescript/Javascript WhatsApp Web API",
5
5
  "keywords": [
6
6
  "whatsapp",
7
7
  "js-whatsapp",
@@ -20,22 +20,40 @@
20
20
  },
21
21
  "license": "MIT",
22
22
  "author": "GiftedTech",
23
- "main": "src/index.js",
24
- "types": "src/index.d.ts",
23
+ "main": "lib/index.js",
24
+ "types": "lib/index.d.ts",
25
25
  "files": [
26
- "src/*",
26
+ "lib/*",
27
27
  "WAProto/*",
28
28
  "WASignalGroup/*.js"
29
29
  ],
30
+ "scripts": {
31
+ "build:all": "tsc && typedoc",
32
+ "build:docs": "typedoc",
33
+ "build:tsc": "tsc",
34
+ "changelog:last": "conventional-changelog -p angular -r 2",
35
+ "changelog:preview": "conventional-changelog -p angular -u",
36
+ "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
37
+ "example": "node --inspect -r ts-node/register Example/example.ts",
38
+ "example:mobile": "node --inspect -r ts-node/register Example/example.ts --mobile",
39
+ "gen:protobuf": "sh WAProto/GenerateStatics.sh",
40
+ "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
41
+ "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
42
+ "prepack": "tsc",
43
+ "prepare": "tsc",
44
+ "release": "release-it",
45
+ "test": "jest"
46
+ },
30
47
  "dependencies": {
31
48
  "@adiwajshing/keyed-db": "^0.2.4",
32
49
  "@hapi/boom": "^9.1.3",
50
+ "async-lock": "^1.4.1",
33
51
  "audio-decode": "^2.1.3",
34
52
  "axios": "^1.3.3",
35
53
  "cache-manager": "4.0.1",
36
54
  "futoin-hkdf": "^1.5.1",
37
55
  "libphonenumber-js": "^1.10.20",
38
- "libsignal": "github:adiwajshing/libsignal-node",
56
+ "libsignal": "github:WhiskeySockets/libsignal-node",
39
57
  "music-metadata": "^7.12.3",
40
58
  "node-cache": "^5.1.2",
41
59
  "pino": "^7.0.0",
@@ -44,7 +62,7 @@
44
62
  "ws": "^8.13.0"
45
63
  },
46
64
  "devDependencies": {
47
- "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
65
+ "@adiwajshing/eslint-config": "github:whiskeysockets/eslint-config",
48
66
  "@types/got": "^9.6.11",
49
67
  "@types/jest": "^27.5.1",
50
68
  "@types/node": "^16.0.0",
@@ -53,7 +71,7 @@
53
71
  "conventional-changelog-cli": "^2.2.2",
54
72
  "eslint": "^8.0.0",
55
73
  "jest": "^27.0.6",
56
- "jimp": "^0.22.12",
74
+ "jimp": "^0.16.1",
57
75
  "link-preview-js": "^3.0.0",
58
76
  "open": "^8.4.2",
59
77
  "qrcode-terminal": "^0.12.0",
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 GIFTED TECH
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,3 +0,0 @@
1
- {
2
- "version": [2, 2413, 1]
3
- }
@@ -1,131 +0,0 @@
1
- import { createHash } from 'crypto'
2
- import { proto } from '../../WAProto'
3
- import { makeLibSignalRepository } from '../Signal/libsignal'
4
- import type { AuthenticationState, MediaType, SocketConfig, WAVersion } from '../Types'
5
- import { Browsers } from '../Utils'
6
- import logger from '../Utils/logger'
7
- import { version } from './baileys-version.json'
8
- import phoneNumberMCC from './phonenumber-mcc.json'
9
-
10
- export const UNAUTHORIZED_CODES = [401, 403, 419]
11
-
12
- export const PHONENUMBER_MCC = phoneNumberMCC
13
-
14
- export const DEFAULT_ORIGIN = 'https://web.whatsapp.com'
15
- export const MOBILE_ENDPOINT = 'g.whatsapp.net'
16
- export const MOBILE_PORT = 443
17
- export const DEF_CALLBACK_PREFIX = 'CB:'
18
- export const DEF_TAG_PREFIX = 'TAG:'
19
- export const PHONE_CONNECTION_CB = 'CB:Pong'
20
-
21
- export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
22
-
23
- const WA_VERSION = '2.24.6.77'
24
-
25
- const WA_VERSION_HASH = createHash('md5').update(WA_VERSION).digest('hex')
26
- export const MOBILE_TOKEN = Buffer.from('0a1mLfGUIBVrMKF1RdvLI5lkRBvof6vn0fD2QRSM' + WA_VERSION_HASH)
27
- export const MOBILE_REGISTRATION_ENDPOINT = 'https://v.whatsapp.net/v2'
28
- export const MOBILE_USERAGENT = `WhatsApp/${WA_VERSION} iOS/15.3.1 Device/Apple-iPhone_7`
29
- export const REGISTRATION_PUBLIC_KEY = Buffer.from([
30
- 5, 142, 140, 15, 116, 195, 235, 197, 215, 166, 134, 92, 108, 60, 132, 56, 86, 176, 97, 33, 204, 232, 234, 119, 77,
31
- 34, 251, 111, 18, 37, 18, 48, 45,
32
- ])
33
- export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
34
- export const DICT_VERSION = 2
35
- export const KEY_BUNDLE_TYPE = Buffer.from([5])
36
- export const NOISE_WA_HEADER = Buffer.from(
37
- [ 87, 65, 6, DICT_VERSION ]
38
- ) // last is "DICT_VERSION"
39
- export const PROTOCOL_VERSION = [5, 2]
40
- export const MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(PROTOCOL_VERSION)])
41
- /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
42
- export const URL_REGEX = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/
43
-
44
- export const WA_CERT_DETAILS = {
45
- SERIAL: 0,
46
- }
47
-
48
- export const PROCESSABLE_HISTORY_TYPES = [
49
- proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
50
- proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
51
- proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
52
- proto.Message.HistorySyncNotification.HistorySyncType.FULL
53
- ]
54
-
55
- export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
56
- version: version as WAVersion,
57
- browser: Browsers.ubuntu('Chrome'),
58
- waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
59
- connectTimeoutMs: 20_000,
60
- keepAliveIntervalMs: 30_000,
61
- logger: logger.child({ class: 'baileys' }),
62
- printQRInTerminal: false,
63
- emitOwnEvents: true,
64
- defaultQueryTimeoutMs: 60_000,
65
- customUploadHosts: [],
66
- retryRequestDelayMs: 250,
67
- maxMsgRetryCount: 5,
68
- fireInitQueries: true,
69
- auth: undefined as unknown as AuthenticationState,
70
- markOnlineOnConnect: true,
71
- syncFullHistory: false,
72
- patchMessageBeforeSending: msg => msg,
73
- shouldSyncHistoryMessage: () => true,
74
- shouldIgnoreJid: () => false,
75
- linkPreviewImageThumbnailWidth: 192,
76
- transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
77
- generateHighQualityLinkPreview: false,
78
- options: { },
79
- appStateMacVerification: {
80
- patch: false,
81
- snapshot: false,
82
- },
83
- getMessage: async() => undefined,
84
- makeSignalRepository: makeLibSignalRepository
85
- }
86
-
87
- export const MEDIA_PATH_MAP: { [T in MediaType]?: string } = {
88
- image: '/mms/image',
89
- video: '/mms/video',
90
- document: '/mms/document',
91
- audio: '/mms/audio',
92
- sticker: '/mms/image',
93
- 'thumbnail-link': '/mms/image',
94
- 'product-catalog-image': '/product/image',
95
- 'md-app-state': '',
96
- 'md-msg-hist': '/mms/md-app-state',
97
- }
98
-
99
- export const MEDIA_HKDF_KEY_MAPPING = {
100
- 'audio': 'Audio',
101
- 'document': 'Document',
102
- 'gif': 'Video',
103
- 'image': 'Image',
104
- 'ppic': '',
105
- 'product': 'Image',
106
- 'ptt': 'Audio',
107
- 'sticker': 'Image',
108
- 'video': 'Video',
109
- 'thumbnail-document': 'Document Thumbnail',
110
- 'thumbnail-image': 'Image Thumbnail',
111
- 'thumbnail-video': 'Video Thumbnail',
112
- 'thumbnail-link': 'Link Thumbnail',
113
- 'md-msg-hist': 'History',
114
- 'md-app-state': 'App State',
115
- 'product-catalog-image': '',
116
- 'payment-bg-image': 'Payment Background',
117
- 'ptv': 'Video'
118
- }
119
-
120
- export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP) as MediaType[]
121
-
122
- export const MIN_PREKEY_COUNT = 5
123
-
124
- export const INITIAL_PREKEY_COUNT = 30
125
-
126
- export const DEFAULT_CACHE_TTLS = {
127
- SIGNAL_STORE: 5 * 60, // 5 minutes
128
- MSG_RETRY: 60 * 60, // 1 hour
129
- CALL_OFFER: 5 * 60, // 5 minutes
130
- USER_DEVICES: 5 * 60, // 5 minutes
131
- }
@@ -1,180 +0,0 @@
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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.makeLibSignalRepository = makeLibSignalRepository;
46
- const libsignal = __importStar(require("libsignal"));
47
- const WASignalGroup_1 = require("../../WASignalGroup");
48
- const Utils_1 = require("../Utils");
49
- const WABinary_1 = require("../WABinary");
50
- function makeLibSignalRepository(auth) {
51
- const storage = signalStorage(auth);
52
- return {
53
- decryptGroupMessage({ group, authorJid, msg }) {
54
- const senderName = jidToSignalSenderKeyName(group, authorJid);
55
- const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
56
- return cipher.decrypt(msg);
57
- },
58
- processSenderKeyDistributionMessage(_a) {
59
- return __awaiter(this, arguments, void 0, function* ({ item, authorJid }) {
60
- const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
61
- const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
62
- const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
63
- const { [senderName]: senderKey } = yield auth.keys.get('sender-key', [senderName]);
64
- if (!senderKey) {
65
- yield storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
66
- }
67
- yield builder.process(senderName, senderMsg);
68
- });
69
- },
70
- decryptMessage(_a) {
71
- return __awaiter(this, arguments, void 0, function* ({ jid, type, ciphertext }) {
72
- const addr = jidToSignalProtocolAddress(jid);
73
- const session = new libsignal.SessionCipher(storage, addr);
74
- let result;
75
- switch (type) {
76
- case 'pkmsg':
77
- result = yield session.decryptPreKeyWhisperMessage(ciphertext);
78
- break;
79
- case 'msg':
80
- result = yield session.decryptWhisperMessage(ciphertext);
81
- break;
82
- }
83
- return result;
84
- });
85
- },
86
- encryptMessage(_a) {
87
- return __awaiter(this, arguments, void 0, function* ({ jid, data }) {
88
- const addr = jidToSignalProtocolAddress(jid);
89
- const cipher = new libsignal.SessionCipher(storage, addr);
90
- const { type: sigType, body } = yield cipher.encrypt(data);
91
- const type = sigType === 3 ? 'pkmsg' : 'msg';
92
- return { type, ciphertext: Buffer.from(body, 'binary') };
93
- });
94
- },
95
- encryptGroupMessage(_a) {
96
- return __awaiter(this, arguments, void 0, function* ({ group, meId, data }) {
97
- const senderName = jidToSignalSenderKeyName(group, meId);
98
- const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
99
- const { [senderName]: senderKey } = yield auth.keys.get('sender-key', [senderName]);
100
- if (!senderKey) {
101
- yield storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
102
- }
103
- const senderKeyDistributionMessage = yield builder.create(senderName);
104
- const session = new WASignalGroup_1.GroupCipher(storage, senderName);
105
- const ciphertext = yield session.encrypt(data);
106
- return {
107
- ciphertext,
108
- senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
109
- };
110
- });
111
- },
112
- injectE2ESession(_a) {
113
- return __awaiter(this, arguments, void 0, function* ({ jid, session }) {
114
- const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
115
- yield cipher.initOutgoing(session);
116
- });
117
- },
118
- jidToSignalProtocolAddress(jid) {
119
- return jidToSignalProtocolAddress(jid).toString();
120
- },
121
- };
122
- }
123
- const jidToSignalProtocolAddress = (jid) => {
124
- const { user, device } = (0, WABinary_1.jidDecode)(jid);
125
- return new libsignal.ProtocolAddress(user, device || 0);
126
- };
127
- const jidToSignalSenderKeyName = (group, user) => {
128
- return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
129
- };
130
- function signalStorage({ creds, keys }) {
131
- return {
132
- loadSession: (id) => __awaiter(this, void 0, void 0, function* () {
133
- const { [id]: sess } = yield keys.get('session', [id]);
134
- if (sess) {
135
- return libsignal.SessionRecord.deserialize(sess);
136
- }
137
- }),
138
- storeSession: (id, session) => __awaiter(this, void 0, void 0, function* () {
139
- yield keys.set({ 'session': { [id]: session.serialize() } });
140
- }),
141
- isTrustedIdentity: () => {
142
- return true;
143
- },
144
- loadPreKey: (id) => __awaiter(this, void 0, void 0, function* () {
145
- const keyId = id.toString();
146
- const { [keyId]: key } = yield keys.get('pre-key', [keyId]);
147
- if (key) {
148
- return {
149
- privKey: Buffer.from(key.private),
150
- pubKey: Buffer.from(key.public)
151
- };
152
- }
153
- }),
154
- removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
155
- loadSignedPreKey: () => {
156
- const key = creds.signedPreKey;
157
- return {
158
- privKey: Buffer.from(key.keyPair.private),
159
- pubKey: Buffer.from(key.keyPair.public)
160
- };
161
- },
162
- loadSenderKey: (keyId) => __awaiter(this, void 0, void 0, function* () {
163
- const { [keyId]: key } = yield keys.get('sender-key', [keyId]);
164
- if (key) {
165
- return new WASignalGroup_1.SenderKeyRecord(key);
166
- }
167
- }),
168
- storeSenderKey: (keyId, key) => __awaiter(this, void 0, void 0, function* () {
169
- yield keys.set({ 'sender-key': { [keyId]: key.serialize() } });
170
- }),
171
- getOurRegistrationId: () => (creds.registrationId),
172
- getOurIdentity: () => {
173
- const { signedIdentityKey } = creds;
174
- return {
175
- privKey: Buffer.from(signedIdentityKey.private),
176
- pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
177
- };
178
- }
179
- };
180
- }
@@ -1,141 +0,0 @@
1
- import * as libsignal from 'libsignal'
2
- import { GroupCipher, GroupSessionBuilder, SenderKeyDistributionMessage, SenderKeyName, SenderKeyRecord } from '../../WASignalGroup'
3
- import { SignalAuthState } from '../Types'
4
- import { SignalRepository } from '../Types/Signal'
5
- import { generateSignalPubKey } from '../Utils'
6
- import { jidDecode } from '../WABinary'
7
-
8
- export function makeLibSignalRepository(auth: SignalAuthState): SignalRepository {
9
- const storage = signalStorage(auth)
10
- return {
11
- decryptGroupMessage({ group, authorJid, msg }) {
12
- const senderName = jidToSignalSenderKeyName(group, authorJid)
13
- const cipher = new GroupCipher(storage, senderName)
14
-
15
- return cipher.decrypt(msg)
16
- },
17
- async processSenderKeyDistributionMessage({ item, authorJid }) {
18
- const builder = new GroupSessionBuilder(storage)
19
- const senderName = jidToSignalSenderKeyName(item.groupId!, authorJid)
20
-
21
- const senderMsg = new SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage)
22
- const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
23
- if(!senderKey) {
24
- await storage.storeSenderKey(senderName, new SenderKeyRecord())
25
- }
26
-
27
- await builder.process(senderName, senderMsg)
28
- },
29
- async decryptMessage({ jid, type, ciphertext }) {
30
- const addr = jidToSignalProtocolAddress(jid)
31
- const session = new libsignal.SessionCipher(storage, addr)
32
- let result: Buffer
33
- switch (type) {
34
- case 'pkmsg':
35
- result = await session.decryptPreKeyWhisperMessage(ciphertext)
36
- break
37
- case 'msg':
38
- result = await session.decryptWhisperMessage(ciphertext)
39
- break
40
- }
41
-
42
- return result
43
- },
44
- async encryptMessage({ jid, data }) {
45
- const addr = jidToSignalProtocolAddress(jid)
46
- const cipher = new libsignal.SessionCipher(storage, addr)
47
-
48
- const { type: sigType, body } = await cipher.encrypt(data)
49
- const type = sigType === 3 ? 'pkmsg' : 'msg'
50
- return { type, ciphertext: Buffer.from(body, 'binary') }
51
- },
52
- async encryptGroupMessage({ group, meId, data }) {
53
- const senderName = jidToSignalSenderKeyName(group, meId)
54
- const builder = new GroupSessionBuilder(storage)
55
-
56
- const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
57
- if(!senderKey) {
58
- await storage.storeSenderKey(senderName, new SenderKeyRecord())
59
- }
60
-
61
- const senderKeyDistributionMessage = await builder.create(senderName)
62
- const session = new GroupCipher(storage, senderName)
63
- const ciphertext = await session.encrypt(data)
64
-
65
- return {
66
- ciphertext,
67
- senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
68
- }
69
- },
70
- async injectE2ESession({ jid, session }) {
71
- const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid))
72
- await cipher.initOutgoing(session)
73
- },
74
- jidToSignalProtocolAddress(jid) {
75
- return jidToSignalProtocolAddress(jid).toString()
76
- },
77
- }
78
- }
79
-
80
- const jidToSignalProtocolAddress = (jid: string) => {
81
- const { user, device } = jidDecode(jid)!
82
- return new libsignal.ProtocolAddress(user, device || 0)
83
- }
84
-
85
- const jidToSignalSenderKeyName = (group: string, user: string): string => {
86
- return new SenderKeyName(group, jidToSignalProtocolAddress(user)).toString()
87
- }
88
-
89
- function signalStorage({ creds, keys }: SignalAuthState) {
90
- return {
91
- loadSession: async(id: string) => {
92
- const { [id]: sess } = await keys.get('session', [id])
93
- if(sess) {
94
- return libsignal.SessionRecord.deserialize(sess)
95
- }
96
- },
97
- storeSession: async(id, session) => {
98
- await keys.set({ 'session': { [id]: session.serialize() } })
99
- },
100
- isTrustedIdentity: () => {
101
- return true
102
- },
103
- loadPreKey: async(id: number | string) => {
104
- const keyId = id.toString()
105
- const { [keyId]: key } = await keys.get('pre-key', [keyId])
106
- if(key) {
107
- return {
108
- privKey: Buffer.from(key.private),
109
- pubKey: Buffer.from(key.public)
110
- }
111
- }
112
- },
113
- removePreKey: (id: number) => keys.set({ 'pre-key': { [id]: null } }),
114
- loadSignedPreKey: () => {
115
- const key = creds.signedPreKey
116
- return {
117
- privKey: Buffer.from(key.keyPair.private),
118
- pubKey: Buffer.from(key.keyPair.public)
119
- }
120
- },
121
- loadSenderKey: async(keyId: string) => {
122
- const { [keyId]: key } = await keys.get('sender-key', [keyId])
123
- if(key) {
124
- return new SenderKeyRecord(key)
125
- }
126
- },
127
- storeSenderKey: async(keyId, key) => {
128
- await keys.set({ 'sender-key': { [keyId]: key.serialize() } })
129
- },
130
- getOurRegistrationId: () => (
131
- creds.registrationId
132
- ),
133
- getOurIdentity: () => {
134
- const { signedIdentityKey } = creds
135
- return {
136
- privKey: Buffer.from(signedIdentityKey.private),
137
- pubKey: generateSignalPubKey(signedIdentityKey.public),
138
- }
139
- }
140
- }
141
- }
@@ -1,19 +0,0 @@
1
- import { EventEmitter } from 'events'
2
- import { URL } from 'url'
3
- import { SocketConfig } from '../../Types'
4
-
5
- export abstract class AbstractSocketClient extends EventEmitter {
6
- abstract get isOpen(): boolean
7
- abstract get isClosed(): boolean
8
- abstract get isClosing(): boolean
9
- abstract get isConnecting(): boolean
10
-
11
- constructor(public url: URL, public config: SocketConfig) {
12
- super()
13
- this.setMaxListeners(0)
14
- }
15
-
16
- abstract connect(): Promise<void>
17
- abstract close(): Promise<void>
18
- abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
19
- }
@@ -1,3 +0,0 @@
1
- export * from './abstract-socket-client'
2
- export * from './mobile-socket-client'
3
- export * from './web-socket-client'
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MobileSocketClient = void 0;
13
- const net_1 = require("net");
14
- const abstract_socket_client_1 = require("./abstract-socket-client");
15
- class MobileSocketClient extends abstract_socket_client_1.AbstractSocketClient {
16
- constructor() {
17
- super(...arguments);
18
- this.socket = null;
19
- }
20
- get isOpen() {
21
- var _a;
22
- return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'open';
23
- }
24
- get isClosed() {
25
- var _a;
26
- return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
27
- }
28
- get isClosing() {
29
- var _a;
30
- return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
31
- }
32
- get isConnecting() {
33
- var _a;
34
- return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'opening';
35
- }
36
- connect() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- var _a;
39
- if (this.socket) {
40
- return;
41
- }
42
- if (this.config.agent) {
43
- throw new Error('There are not support for proxy agent for mobile connection');
44
- }
45
- else {
46
- this.socket = (0, net_1.connect)({
47
- host: this.url.hostname,
48
- port: Number(this.url.port) || 443
49
- });
50
- }
51
- this.socket.setMaxListeners(0);
52
- const events = ['close', 'connect', 'data', 'drain', 'end', 'error', 'lookup', 'ready', 'timeout'];
53
- for (const event of events) {
54
- (_a = this.socket) === null || _a === void 0 ? void 0 : _a.on(event, (...args) => this.emit(event, ...args));
55
- }
56
- this.socket.on('data', (...args) => this.emit('message', ...args));
57
- this.socket.on('ready', (...args) => this.emit('open', ...args));
58
- });
59
- }
60
- close() {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- if (!this.socket) {
63
- return;
64
- }
65
- return new Promise(resolve => {
66
- this.socket.end(resolve);
67
- this.socket = null;
68
- });
69
- });
70
- }
71
- send(str, cb) {
72
- if (this.socket === null) {
73
- return false;
74
- }
75
- return this.socket.write(str, undefined, cb);
76
- }
77
- }
78
- exports.MobileSocketClient = MobileSocketClient;