gifted-baileys 1.5.4 → 1.5.5

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 (250) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/WAProto.proto +88 -969
  3. package/WAProto/index.d.ts +1256 -13195
  4. package/WAProto/index.js +74730 -125106
  5. package/package.json +9 -27
  6. package/src/Defaults/baileys-version.json +3 -0
  7. package/{lib → src}/Defaults/index.js +14 -7
  8. package/src/Defaults/index.ts +131 -0
  9. package/src/Signal/libsignal.js +180 -0
  10. package/src/Signal/libsignal.ts +141 -0
  11. package/src/Socket/Client/abstract-socket-client.ts +19 -0
  12. package/{lib → src}/Socket/Client/index.js +3 -2
  13. package/src/Socket/Client/index.ts +3 -0
  14. package/src/Socket/Client/mobile-socket-client.js +78 -0
  15. package/src/Socket/Client/mobile-socket-client.ts +66 -0
  16. package/src/Socket/Client/web-socket-client.js +75 -0
  17. package/src/Socket/Client/web-socket-client.ts +57 -0
  18. package/{lib → src}/Socket/business.js +33 -28
  19. package/src/Socket/business.ts +281 -0
  20. package/{lib → src}/Socket/chats.js +176 -174
  21. package/src/Socket/chats.ts +1030 -0
  22. package/{lib → src}/Socket/groups.js +68 -80
  23. package/src/Socket/groups.ts +356 -0
  24. package/{lib → src}/Socket/index.js +1 -4
  25. package/src/Socket/index.ts +13 -0
  26. package/{lib → src}/Socket/messages-recv.js +211 -378
  27. package/src/Socket/messages-recv.ts +985 -0
  28. package/{lib → src}/Socket/messages-send.js +177 -452
  29. package/src/Socket/messages-send.ts +871 -0
  30. package/{lib → src}/Socket/newsletter.js +98 -107
  31. package/src/Socket/newsletter.ts +282 -0
  32. package/{lib → src}/Socket/registration.js +48 -56
  33. package/src/Socket/registration.ts +250 -0
  34. package/{lib → src}/Socket/socket.js +77 -77
  35. package/src/Socket/socket.ts +777 -0
  36. package/src/Store/index.ts +3 -0
  37. package/{lib → src}/Store/make-cache-manager-store.js +34 -25
  38. package/src/Store/make-cache-manager-store.ts +100 -0
  39. package/{lib → src}/Store/make-in-memory-store.js +32 -36
  40. package/src/Store/make-in-memory-store.ts +475 -0
  41. package/src/Store/make-ordered-dictionary.ts +86 -0
  42. package/{lib → src}/Store/object-repository.js +1 -1
  43. package/src/Store/object-repository.ts +32 -0
  44. package/src/Tests/test.app-state-sync.js +204 -0
  45. package/src/Tests/test.app-state-sync.ts +207 -0
  46. package/src/Tests/test.event-buffer.js +270 -0
  47. package/src/Tests/test.event-buffer.ts +319 -0
  48. package/src/Tests/test.key-store.js +76 -0
  49. package/src/Tests/test.key-store.ts +92 -0
  50. package/src/Tests/test.libsignal.js +141 -0
  51. package/src/Tests/test.libsignal.ts +186 -0
  52. package/src/Tests/test.media-download.js +93 -0
  53. package/src/Tests/test.media-download.ts +76 -0
  54. package/src/Tests/test.messages.js +33 -0
  55. package/src/Tests/test.messages.ts +37 -0
  56. package/src/Tests/utils.js +34 -0
  57. package/src/Tests/utils.ts +36 -0
  58. package/src/Types/Auth.ts +113 -0
  59. package/src/Types/Call.ts +15 -0
  60. package/src/Types/Chat.ts +106 -0
  61. package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
  62. package/src/Types/Events.ts +93 -0
  63. package/src/Types/GroupMetadata.ts +53 -0
  64. package/src/Types/Label.ts +36 -0
  65. package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
  66. package/src/Types/Message.ts +288 -0
  67. package/src/Types/Newsletter.ts +98 -0
  68. package/src/Types/Product.ts +85 -0
  69. package/src/Types/Signal.ts +68 -0
  70. package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -61
  71. package/src/Types/State.ts +29 -0
  72. package/src/Types/index.ts +59 -0
  73. package/{lib → src}/Utils/auth-utils.js +90 -73
  74. package/src/Utils/auth-utils.ts +222 -0
  75. package/src/Utils/baileys-event-stream.js +92 -0
  76. package/src/Utils/baileys-event-stream.ts +66 -0
  77. package/{lib → src}/Utils/business.js +43 -15
  78. package/src/Utils/business.ts +275 -0
  79. package/{lib → src}/Utils/chat-utils.js +94 -87
  80. package/src/Utils/chat-utils.ts +860 -0
  81. package/{lib → src}/Utils/crypto.js +2 -4
  82. package/src/Utils/crypto.ts +131 -0
  83. package/src/Utils/decode-wa-message.js +211 -0
  84. package/src/Utils/decode-wa-message.ts +228 -0
  85. package/{lib → src}/Utils/event-buffer.js +13 -4
  86. package/src/Utils/event-buffer.ts +613 -0
  87. package/{lib → src}/Utils/generics.js +86 -67
  88. package/src/Utils/generics.ts +434 -0
  89. package/{lib → src}/Utils/history.js +39 -13
  90. package/src/Utils/history.ts +112 -0
  91. package/src/Utils/index.ts +17 -0
  92. package/{lib → src}/Utils/link-preview.js +54 -17
  93. package/src/Utils/link-preview.ts +122 -0
  94. package/src/Utils/logger.ts +3 -0
  95. package/src/Utils/lt-hash.ts +61 -0
  96. package/{lib → src}/Utils/make-mutex.js +13 -4
  97. package/src/Utils/make-mutex.ts +44 -0
  98. package/{lib → src}/Utils/messages-media.js +255 -193
  99. package/src/Utils/messages-media.ts +847 -0
  100. package/{lib → src}/Utils/messages.js +118 -588
  101. package/src/Utils/messages.ts +956 -0
  102. package/src/Utils/noise-handler.ts +197 -0
  103. package/{lib → src}/Utils/process-message.js +30 -27
  104. package/src/Utils/process-message.ts +414 -0
  105. package/{lib → src}/Utils/signal.js +42 -25
  106. package/src/Utils/signal.ts +177 -0
  107. package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -27
  108. package/src/Utils/use-multi-file-auth-state.ts +90 -0
  109. package/{lib → src}/Utils/validate-connection.js +9 -40
  110. package/src/Utils/validate-connection.ts +238 -0
  111. package/src/WABinary/constants.ts +42 -0
  112. package/src/WABinary/decode.ts +265 -0
  113. package/{lib → src}/WABinary/encode.js +10 -16
  114. package/src/WABinary/encode.ts +236 -0
  115. package/src/WABinary/generic-utils.ts +121 -0
  116. package/src/WABinary/index.ts +5 -0
  117. package/src/WABinary/jid-utils.ts +68 -0
  118. package/src/WABinary/types.ts +17 -0
  119. package/src/WAM/BinaryInfo.ts +12 -0
  120. package/src/WAM/constants.ts +15382 -0
  121. package/src/WAM/encode.ts +174 -0
  122. package/src/WAM/index.ts +3 -0
  123. package/{lib → src}/index.js +0 -1
  124. package/src/index.ts +13 -0
  125. package/lib/Defaults/baileys-version.json +0 -3
  126. package/lib/Defaults/index.d.ts +0 -284
  127. package/lib/Signal/libsignal.d.ts +0 -3
  128. package/lib/Signal/libsignal.js +0 -161
  129. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  130. package/lib/Socket/Client/index.d.ts +0 -2
  131. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  132. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  133. package/lib/Socket/Client/types.d.ts +0 -17
  134. package/lib/Socket/Client/types.js +0 -13
  135. package/lib/Socket/Client/websocket.d.ts +0 -12
  136. package/lib/Socket/Client/websocket.js +0 -62
  137. package/lib/Socket/business.d.ts +0 -170
  138. package/lib/Socket/chats.d.ts +0 -81
  139. package/lib/Socket/groups.d.ts +0 -115
  140. package/lib/Socket/index.d.ts +0 -172
  141. package/lib/Socket/messages-recv.d.ts +0 -158
  142. package/lib/Socket/messages-send.d.ts +0 -155
  143. package/lib/Socket/newsletter.d.ts +0 -132
  144. package/lib/Socket/registration.d.ts +0 -264
  145. package/lib/Socket/socket.d.ts +0 -44
  146. package/lib/Socket/usync.d.ts +0 -37
  147. package/lib/Socket/usync.js +0 -70
  148. package/lib/Store/index.d.ts +0 -3
  149. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  150. package/lib/Store/make-in-memory-store.d.ts +0 -118
  151. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  152. package/lib/Store/object-repository.d.ts +0 -10
  153. package/lib/Types/Auth.d.ts +0 -109
  154. package/lib/Types/Call.d.ts +0 -13
  155. package/lib/Types/Chat.d.ts +0 -107
  156. package/lib/Types/Events.d.ts +0 -172
  157. package/lib/Types/GroupMetadata.d.ts +0 -56
  158. package/lib/Types/Label.d.ts +0 -46
  159. package/lib/Types/Message.d.ts +0 -433
  160. package/lib/Types/Newsletter.d.ts +0 -92
  161. package/lib/Types/Product.d.ts +0 -78
  162. package/lib/Types/Signal.d.ts +0 -57
  163. package/lib/Types/State.d.ts +0 -27
  164. package/lib/Types/USync.d.ts +0 -25
  165. package/lib/Types/USync.js +0 -2
  166. package/lib/Types/index.d.ts +0 -66
  167. package/lib/Utils/auth-utils.d.ts +0 -18
  168. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  169. package/lib/Utils/baileys-event-stream.js +0 -63
  170. package/lib/Utils/business.d.ts +0 -22
  171. package/lib/Utils/chat-utils.d.ts +0 -70
  172. package/lib/Utils/crypto.d.ts +0 -40
  173. package/lib/Utils/decode-wa-message.d.ts +0 -36
  174. package/lib/Utils/decode-wa-message.js +0 -226
  175. package/lib/Utils/event-buffer.d.ts +0 -35
  176. package/lib/Utils/generics.d.ts +0 -88
  177. package/lib/Utils/history.d.ts +0 -19
  178. package/lib/Utils/index.d.ts +0 -17
  179. package/lib/Utils/link-preview.d.ts +0 -21
  180. package/lib/Utils/logger.d.ts +0 -2
  181. package/lib/Utils/lt-hash.d.ts +0 -12
  182. package/lib/Utils/make-mutex.d.ts +0 -7
  183. package/lib/Utils/messages-media.d.ts +0 -113
  184. package/lib/Utils/messages.d.ts +0 -77
  185. package/lib/Utils/noise-handler.d.ts +0 -20
  186. package/lib/Utils/process-message.d.ts +0 -41
  187. package/lib/Utils/signal.d.ts +0 -33
  188. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  189. package/lib/Utils/validate-connection.d.ts +0 -11
  190. package/lib/WABinary/constants.d.ts +0 -27
  191. package/lib/WABinary/decode.d.ts +0 -6
  192. package/lib/WABinary/encode.d.ts +0 -2
  193. package/lib/WABinary/generic-utils.d.ts +0 -14
  194. package/lib/WABinary/index.d.ts +0 -5
  195. package/lib/WABinary/jid-utils.d.ts +0 -31
  196. package/lib/WABinary/types.d.ts +0 -18
  197. package/lib/WAM/BinaryInfo.d.ts +0 -8
  198. package/lib/WAM/constants.d.ts +0 -38
  199. package/lib/WAM/encode.d.ts +0 -2
  200. package/lib/WAM/index.d.ts +0 -3
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  202. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  203. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  204. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  205. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  206. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  207. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  208. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  209. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  210. package/lib/WAUSync/Protocols/index.js +0 -20
  211. package/lib/WAUSync/USyncQuery.d.ts +0 -26
  212. package/lib/WAUSync/USyncQuery.js +0 -79
  213. package/lib/WAUSync/USyncUser.d.ts +0 -10
  214. package/lib/WAUSync/USyncUser.js +0 -22
  215. package/lib/WAUSync/index.d.ts +0 -3
  216. package/lib/WAUSync/index.js +0 -19
  217. /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
  218. /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
  219. /package/{lib → src}/Store/index.js +0 -0
  220. /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
  221. /package/{lib → src}/Types/Auth.js +0 -0
  222. /package/{lib → src}/Types/Call.js +0 -0
  223. /package/{lib → src}/Types/Chat.js +0 -0
  224. /package/{lib → src}/Types/Contact.js +0 -0
  225. /package/{lib → src}/Types/Events.js +0 -0
  226. /package/{lib → src}/Types/GroupMetadata.js +0 -0
  227. /package/{lib → src}/Types/Label.js +0 -0
  228. /package/{lib → src}/Types/LabelAssociation.js +0 -0
  229. /package/{lib → src}/Types/Message.js +0 -0
  230. /package/{lib → src}/Types/Newsletter.js +0 -0
  231. /package/{lib → src}/Types/Product.js +0 -0
  232. /package/{lib → src}/Types/Signal.js +0 -0
  233. /package/{lib → src}/Types/Socket.js +0 -0
  234. /package/{lib → src}/Types/State.js +0 -0
  235. /package/{lib → src}/Types/index.js +0 -0
  236. /package/{lib → src}/Utils/index.js +0 -0
  237. /package/{lib → src}/Utils/logger.js +0 -0
  238. /package/{lib → src}/Utils/lt-hash.js +0 -0
  239. /package/{lib → src}/Utils/noise-handler.js +0 -0
  240. /package/{lib → src}/WABinary/constants.js +0 -0
  241. /package/{lib → src}/WABinary/decode.js +0 -0
  242. /package/{lib → src}/WABinary/generic-utils.js +0 -0
  243. /package/{lib → src}/WABinary/index.js +0 -0
  244. /package/{lib → src}/WABinary/jid-utils.js +0 -0
  245. /package/{lib → src}/WABinary/types.js +0 -0
  246. /package/{lib → src}/WAM/BinaryInfo.js +0 -0
  247. /package/{lib → src}/WAM/constants.js +0 -0
  248. /package/{lib → src}/WAM/encode.js +0 -0
  249. /package/{lib → src}/WAM/index.js +0 -0
  250. /package/{lib → src}/gifted +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gifted-baileys",
3
- "version": "1.5.4",
4
- "description": "Typescript/Javascript WhatsApp Web API",
3
+ "version": "1.5.5",
4
+ "description": "Typescript/Javascript WhatsApp Web API",
5
5
  "keywords": [
6
6
  "whatsapp",
7
7
  "js-whatsapp",
@@ -19,41 +19,23 @@
19
19
  "url": "https://baileys.giftedtech.web.id"
20
20
  },
21
21
  "license": "MIT",
22
- "author": "Gifted Tech",
23
- "main": "lib/index.js",
24
- "types": "lib/index.d.ts",
22
+ "author": "GiftedTech",
23
+ "main": "src/index.js",
24
+ "types": "src/index.d.ts",
25
25
  "files": [
26
- "lib/*",
26
+ "src/*",
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
- },
47
30
  "dependencies": {
48
31
  "@adiwajshing/keyed-db": "^0.2.4",
49
32
  "@hapi/boom": "^9.1.3",
50
- "async-lock": "^1.4.1",
51
33
  "audio-decode": "^2.1.3",
52
34
  "axios": "^1.3.3",
53
35
  "cache-manager": "4.0.1",
54
36
  "futoin-hkdf": "^1.5.1",
55
37
  "libphonenumber-js": "^1.10.20",
56
- "libsignal": "github:WhiskeySockets/libsignal-node",
38
+ "libsignal": "github:adiwajshing/libsignal-node",
57
39
  "music-metadata": "^7.12.3",
58
40
  "node-cache": "^5.1.2",
59
41
  "pino": "^7.0.0",
@@ -62,7 +44,7 @@
62
44
  "ws": "^8.13.0"
63
45
  },
64
46
  "devDependencies": {
65
- "@adiwajshing/eslint-config": "github:whiskeysockets/eslint-config",
47
+ "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
66
48
  "@types/got": "^9.6.11",
67
49
  "@types/jest": "^27.5.1",
68
50
  "@types/node": "^16.0.0",
@@ -71,7 +53,7 @@
71
53
  "conventional-changelog-cli": "^2.2.2",
72
54
  "eslint": "^8.0.0",
73
55
  "jest": "^27.0.6",
74
- "jimp": "^0.16.1",
56
+ "jimp": "^0.22.12",
75
57
  "link-preview-js": "^3.0.0",
76
58
  "open": "^8.4.2",
77
59
  "qrcode-terminal": "^0.12.0",
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": [2, 2413, 1]
3
+ }
@@ -1,4 +1,13 @@
1
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -44,8 +53,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
44
53
  WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
45
54
  WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
46
55
  WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
47
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
48
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
56
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL
49
57
  ];
50
58
  exports.DEFAULT_CONNECTION_CONFIG = {
51
59
  version: baileys_version_json_1.version,
@@ -75,8 +83,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
75
83
  patch: false,
76
84
  snapshot: false,
77
85
  },
78
- getMessage: async () => undefined,
79
- cachedGroupMetadata: async () => undefined,
86
+ getMessage: () => __awaiter(void 0, void 0, void 0, function* () { return undefined; }),
80
87
  makeSignalRepository: libsignal_1.makeLibSignalRepository
81
88
  };
82
89
  exports.MEDIA_PATH_MAP = {
@@ -114,8 +121,8 @@ exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
114
121
  exports.MIN_PREKEY_COUNT = 5;
115
122
  exports.INITIAL_PREKEY_COUNT = 30;
116
123
  exports.DEFAULT_CACHE_TTLS = {
117
- SIGNAL_STORE: 5 * 60,
118
- MSG_RETRY: 60 * 60,
119
- CALL_OFFER: 5 * 60,
124
+ SIGNAL_STORE: 5 * 60, // 5 minutes
125
+ MSG_RETRY: 60 * 60, // 1 hour
126
+ CALL_OFFER: 5 * 60, // 5 minutes
120
127
  USER_DEVICES: 5 * 60, // 5 minutes
121
128
  };
@@ -0,0 +1,131 @@
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
+ }
@@ -0,0 +1,180 @@
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
+ }
@@ -0,0 +1,141 @@
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
+ }
@@ -0,0 +1,19 @@
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
+ }
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./websocket"), exports);
17
+ __exportStar(require("./abstract-socket-client"), exports);
18
+ __exportStar(require("./mobile-socket-client"), exports);
19
+ __exportStar(require("./web-socket-client"), exports);
@@ -0,0 +1,3 @@
1
+ export * from './abstract-socket-client'
2
+ export * from './mobile-socket-client'
3
+ export * from './web-socket-client'