@neelegirl/baileys 1.5.6 → 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 (421) hide show
  1. package/README.md +21 -27
  2. package/WAProto/WAProto.proto +665 -291
  3. package/WAProto/index.d.ts +48037 -2294
  4. package/WAProto/index.js +139804 -45203
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +64 -58
  7. package/lib/Defaults/index.js +96 -74
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Signal/WASignalGroup/GroupProtocol.js +1909 -0
  10. package/lib/Signal/WASignalGroup/ciphertext_message.js +16 -0
  11. package/lib/Signal/WASignalGroup/generate-proto.sh +1 -0
  12. package/lib/Signal/WASignalGroup/group.proto +42 -0
  13. package/lib/Signal/WASignalGroup/group_cipher.js +120 -0
  14. package/lib/Signal/WASignalGroup/group_session_builder.js +46 -0
  15. package/lib/Signal/WASignalGroup/index.js +6 -0
  16. package/lib/Signal/WASignalGroup/keyhelper.js +21 -0
  17. package/lib/Signal/WASignalGroup/protobufs.js +3 -0
  18. package/lib/Signal/WASignalGroup/queue_job.js +69 -0
  19. package/lib/Signal/WASignalGroup/readme.md +6 -0
  20. package/lib/Signal/WASignalGroup/sender_chain_key.js +50 -0
  21. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +78 -0
  22. package/lib/Signal/WASignalGroup/sender_key_message.js +92 -0
  23. package/lib/Signal/WASignalGroup/sender_key_name.js +70 -0
  24. package/lib/Signal/WASignalGroup/sender_key_record.js +56 -0
  25. package/lib/Signal/WASignalGroup/sender_key_state.js +129 -0
  26. package/lib/Signal/{Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -3
  27. package/lib/Signal/libsignal.d.ts +4 -5
  28. package/lib/Signal/libsignal.js +112 -292
  29. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  30. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  31. package/lib/Socket/Client/index.d.ts +2 -3
  32. package/lib/Socket/Client/index.js +22 -3
  33. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  34. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  35. package/lib/Socket/Client/types.d.ts +15 -15
  36. package/lib/Socket/Client/types.js +15 -8
  37. package/lib/Socket/Client/websocket.d.ts +12 -12
  38. package/lib/Socket/Client/websocket.js +36 -24
  39. package/lib/Socket/business.d.ts +177 -178
  40. package/lib/Socket/business.js +71 -179
  41. package/lib/Socket/chats.d.ts +93 -93
  42. package/lib/Socket/chats.js +625 -474
  43. package/lib/Socket/communities.d.ts +62 -83
  44. package/lib/Socket/communities.js +414 -412
  45. package/lib/Socket/groups.d.ts +112 -118
  46. package/lib/Socket/groups.js +171 -146
  47. package/lib/Socket/index.d.ts +182 -222
  48. package/lib/Socket/index.js +17 -12
  49. package/lib/Socket/messages-recv.d.ts +169 -165
  50. package/lib/Socket/messages-recv.js +1721 -1185
  51. package/lib/Socket/messages-send.d.ts +160 -161
  52. package/lib/Socket/messages-send.js +992 -642
  53. package/lib/Socket/mex.d.ts +0 -1
  54. package/lib/Socket/mex.js +9 -4
  55. package/lib/Socket/newsletter.d.ts +139 -139
  56. package/lib/Socket/newsletter.js +258 -153
  57. package/lib/Socket/registration.d.ts +266 -0
  58. package/lib/Socket/registration.js +166 -0
  59. package/lib/Socket/socket.d.ts +36 -42
  60. package/lib/Socket/socket.js +525 -623
  61. package/lib/Socket/usync.d.ts +37 -0
  62. package/lib/Socket/usync.js +83 -0
  63. package/lib/Store/index.d.ts +4 -0
  64. package/lib/Store/index.js +24 -0
  65. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  66. package/lib/Store/make-cache-manager-store.js +90 -0
  67. package/lib/Store/make-in-memory-store.d.ts +123 -0
  68. package/lib/Store/make-in-memory-store.js +429 -0
  69. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  70. package/lib/Store/make-ordered-dictionary.js +86 -0
  71. package/lib/Store/object-repository.d.ts +10 -0
  72. package/lib/Store/object-repository.js +31 -0
  73. package/lib/Types/Auth.d.ts +96 -87
  74. package/lib/Types/Auth.js +3 -2
  75. package/lib/Types/Call.d.ts +13 -13
  76. package/lib/Types/Call.js +3 -2
  77. package/lib/Types/Chat.d.ts +94 -79
  78. package/lib/Types/Chat.js +9 -8
  79. package/lib/Types/Contact.d.ts +9 -13
  80. package/lib/Types/Contact.js +3 -2
  81. package/lib/Types/Events.d.ts +179 -152
  82. package/lib/Types/Events.js +3 -2
  83. package/lib/Types/GroupMetadata.d.ts +48 -49
  84. package/lib/Types/GroupMetadata.js +3 -2
  85. package/lib/Types/Label.d.ts +14 -13
  86. package/lib/Types/Label.js +30 -24
  87. package/lib/Types/LabelAssociation.d.ts +20 -15
  88. package/lib/Types/LabelAssociation.js +12 -6
  89. package/lib/Types/Message.d.ts +404 -234
  90. package/lib/Types/Message.js +13 -11
  91. package/lib/Types/MexUpdates.d.ts +9 -0
  92. package/lib/Types/MexUpdates.js +18 -0
  93. package/lib/Types/Newsletter.d.ts +104 -130
  94. package/lib/Types/Newsletter.js +40 -31
  95. package/lib/Types/Product.d.ts +71 -58
  96. package/lib/Types/Product.js +3 -2
  97. package/lib/Types/Signal.d.ts +55 -63
  98. package/lib/Types/Signal.js +3 -2
  99. package/lib/Types/Socket.d.ts +66 -77
  100. package/lib/Types/Socket.js +3 -3
  101. package/lib/Types/State.d.ts +19 -17
  102. package/lib/Types/State.js +14 -13
  103. package/lib/Types/USync.d.ts +8 -8
  104. package/lib/Types/USync.js +3 -2
  105. package/lib/Types/index.d.ts +61 -47
  106. package/lib/Types/index.js +48 -26
  107. package/lib/Utils/auth-utils.d.ts +10 -8
  108. package/lib/Utils/auth-utils.js +154 -206
  109. package/lib/Utils/baileys-event-stream.d.ts +7 -6
  110. package/lib/Utils/baileys-event-stream.js +43 -29
  111. package/lib/Utils/business.d.ts +20 -14
  112. package/lib/Utils/business.js +134 -110
  113. package/lib/Utils/chat-utils.d.ts +69 -57
  114. package/lib/Utils/chat-utils.js +380 -362
  115. package/lib/Utils/check-npm-version.d.ts +15 -0
  116. package/lib/Utils/check-npm-version.js +52 -0
  117. package/lib/Utils/crypto.d.ts +45 -30
  118. package/lib/Utils/crypto.js +178 -141
  119. package/lib/Utils/decode-wa-message.d.ts +35 -42
  120. package/lib/Utils/decode-wa-message.js +150 -176
  121. package/lib/Utils/event-buffer.d.ts +17 -12
  122. package/lib/Utils/event-buffer.js +286 -269
  123. package/lib/Utils/generics.d.ts +99 -60
  124. package/lib/Utils/generics.js +481 -244
  125. package/lib/Utils/history.d.ts +22 -18
  126. package/lib/Utils/history.js +80 -54
  127. package/lib/Utils/index.d.ts +19 -20
  128. package/lib/Utils/index.js +41 -19
  129. package/lib/Utils/link-preview.d.ts +14 -12
  130. package/lib/Utils/link-preview.js +75 -40
  131. package/lib/Utils/logger.d.ts +11 -10
  132. package/lib/Utils/logger.js +7 -3
  133. package/lib/Utils/lt-hash.d.ts +13 -12
  134. package/lib/Utils/lt-hash.js +37 -27
  135. package/lib/Utils/make-mutex.d.ts +7 -6
  136. package/lib/Utils/make-mutex.js +29 -20
  137. package/lib/Utils/message-retry-manager.d.ts +6 -6
  138. package/lib/Utils/message-retry-manager.js +36 -8
  139. package/lib/Utils/messages-media.d.ts +102 -87
  140. package/lib/Utils/messages-media.js +570 -427
  141. package/lib/Utils/messages.d.ts +64 -37
  142. package/lib/Utils/messages.js +1270 -511
  143. package/lib/Utils/noise-handler.d.ts +18 -18
  144. package/lib/Utils/noise-handler.js +109 -101
  145. package/lib/Utils/process-message.d.ts +32 -25
  146. package/lib/Utils/process-message.js +281 -266
  147. package/lib/Utils/signal.d.ts +32 -24
  148. package/lib/Utils/signal.js +105 -98
  149. package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
  150. package/lib/Utils/use-mongo-file-auth-state.js +84 -0
  151. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -5
  152. package/lib/Utils/use-multi-file-auth-state.js +186 -69
  153. package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
  154. package/lib/Utils/use-single-file-auth-state.js +80 -0
  155. package/lib/Utils/validate-connection.d.ts +13 -11
  156. package/lib/Utils/validate-connection.js +116 -124
  157. package/lib/WABinary/constants.d.ts +27 -25
  158. package/lib/WABinary/constants.js +1292 -1277
  159. package/lib/WABinary/decode.d.ts +9 -7
  160. package/lib/WABinary/decode.js +189 -139
  161. package/lib/WABinary/encode.d.ts +3 -3
  162. package/lib/WABinary/encode.js +154 -105
  163. package/lib/WABinary/generic-utils.d.ts +27 -14
  164. package/lib/WABinary/generic-utils.js +102 -62
  165. package/lib/WABinary/index.d.ts +5 -6
  166. package/lib/WABinary/index.js +25 -6
  167. package/lib/WABinary/jid-utils.d.ts +46 -41
  168. package/lib/WABinary/jid-utils.js +80 -84
  169. package/lib/WABinary/types.d.ts +13 -10
  170. package/lib/WABinary/types.js +3 -2
  171. package/lib/WAM/BinaryInfo.d.ts +15 -8
  172. package/lib/WAM/BinaryInfo.js +14 -7
  173. package/lib/WAM/constants.d.ts +37 -30
  174. package/lib/WAM/constants.js +11983 -19465
  175. package/lib/WAM/encode.d.ts +3 -3
  176. package/lib/WAM/encode.js +110 -95
  177. package/lib/WAM/index.d.ts +3 -4
  178. package/lib/WAM/index.js +23 -4
  179. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
  180. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
  181. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  182. package/lib/WAUSync/Protocols/USyncContactProtocol.js +19 -12
  183. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
  184. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
  185. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
  186. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
  187. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
  188. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  189. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
  190. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
  191. package/lib/WAUSync/Protocols/index.d.ts +6 -5
  192. package/lib/WAUSync/Protocols/index.js +26 -5
  193. package/lib/WAUSync/USyncQuery.d.ts +28 -26
  194. package/lib/WAUSync/USyncQuery.js +62 -64
  195. package/lib/WAUSync/USyncUser.d.ts +10 -11
  196. package/lib/WAUSync/USyncUser.js +19 -12
  197. package/lib/WAUSync/index.d.ts +3 -4
  198. package/lib/WAUSync/index.js +23 -4
  199. package/lib/index.d.ts +11 -10
  200. package/lib/index.js +33 -11
  201. package/package.json +43 -48
  202. package/WAProto/GenerateStatics.sh +0 -3
  203. package/WAProto/fix-imports.js +0 -29
  204. package/engine-requirements.js +0 -10
  205. package/lib/Defaults/index.d.ts.map +0 -1
  206. package/lib/Defaults/index.js.map +0 -1
  207. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  208. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  209. package/lib/Signal/Group/ciphertext-message.js +0 -12
  210. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  211. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  212. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  213. package/lib/Signal/Group/group-session-builder.js +0 -30
  214. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  215. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  216. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  217. package/lib/Signal/Group/group_cipher.js +0 -82
  218. package/lib/Signal/Group/group_cipher.js.map +0 -1
  219. package/lib/Signal/Group/index.d.ts +0 -12
  220. package/lib/Signal/Group/index.d.ts.map +0 -1
  221. package/lib/Signal/Group/index.js +0 -12
  222. package/lib/Signal/Group/index.js.map +0 -1
  223. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  224. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  225. package/lib/Signal/Group/keyhelper.js +0 -18
  226. package/lib/Signal/Group/keyhelper.js.map +0 -1
  227. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  228. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  229. package/lib/Signal/Group/sender-chain-key.js +0 -26
  230. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  231. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  232. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  233. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  234. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  235. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  236. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  237. package/lib/Signal/Group/sender-key-message.js +0 -66
  238. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  239. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  240. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  241. package/lib/Signal/Group/sender-key-name.js +0 -48
  242. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  243. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  244. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  245. package/lib/Signal/Group/sender-key-record.js +0 -41
  246. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  247. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  248. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  249. package/lib/Signal/Group/sender-key-state.js +0 -84
  250. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  251. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  252. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  253. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  254. package/lib/Signal/libsignal.d.ts.map +0 -1
  255. package/lib/Signal/libsignal.js.map +0 -1
  256. package/lib/Signal/lid-mapping.d.ts +0 -23
  257. package/lib/Signal/lid-mapping.d.ts.map +0 -1
  258. package/lib/Signal/lid-mapping.js +0 -171
  259. package/lib/Signal/lid-mapping.js.map +0 -1
  260. package/lib/Socket/Client/index.d.ts.map +0 -1
  261. package/lib/Socket/Client/index.js.map +0 -1
  262. package/lib/Socket/Client/types.d.ts.map +0 -1
  263. package/lib/Socket/Client/types.js.map +0 -1
  264. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  265. package/lib/Socket/Client/websocket.js.map +0 -1
  266. package/lib/Socket/business.d.ts.map +0 -1
  267. package/lib/Socket/business.js.map +0 -1
  268. package/lib/Socket/chats.d.ts.map +0 -1
  269. package/lib/Socket/chats.js.map +0 -1
  270. package/lib/Socket/communities.d.ts.map +0 -1
  271. package/lib/Socket/communities.js.map +0 -1
  272. package/lib/Socket/groups.d.ts.map +0 -1
  273. package/lib/Socket/groups.js.map +0 -1
  274. package/lib/Socket/index.d.ts.map +0 -1
  275. package/lib/Socket/index.js.map +0 -1
  276. package/lib/Socket/messages-recv.d.ts.map +0 -1
  277. package/lib/Socket/messages-recv.js.map +0 -1
  278. package/lib/Socket/messages-send.d.ts.map +0 -1
  279. package/lib/Socket/messages-send.js.map +0 -1
  280. package/lib/Socket/mex.d.ts.map +0 -1
  281. package/lib/Socket/mex.js.map +0 -1
  282. package/lib/Socket/newsletter.d.ts.map +0 -1
  283. package/lib/Socket/newsletter.js.map +0 -1
  284. package/lib/Socket/socket.d.ts.map +0 -1
  285. package/lib/Socket/socket.js.map +0 -1
  286. package/lib/Types/Auth.d.ts.map +0 -1
  287. package/lib/Types/Auth.js.map +0 -1
  288. package/lib/Types/Bussines.d.ts +0 -25
  289. package/lib/Types/Bussines.d.ts.map +0 -1
  290. package/lib/Types/Bussines.js +0 -2
  291. package/lib/Types/Bussines.js.map +0 -1
  292. package/lib/Types/Call.d.ts.map +0 -1
  293. package/lib/Types/Call.js.map +0 -1
  294. package/lib/Types/Chat.d.ts.map +0 -1
  295. package/lib/Types/Chat.js.map +0 -1
  296. package/lib/Types/Contact.d.ts.map +0 -1
  297. package/lib/Types/Contact.js.map +0 -1
  298. package/lib/Types/Events.d.ts.map +0 -1
  299. package/lib/Types/Events.js.map +0 -1
  300. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  301. package/lib/Types/GroupMetadata.js.map +0 -1
  302. package/lib/Types/Label.d.ts.map +0 -1
  303. package/lib/Types/Label.js.map +0 -1
  304. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  305. package/lib/Types/LabelAssociation.js.map +0 -1
  306. package/lib/Types/Message.d.ts.map +0 -1
  307. package/lib/Types/Message.js.map +0 -1
  308. package/lib/Types/Newsletter.d.ts.map +0 -1
  309. package/lib/Types/Newsletter.js.map +0 -1
  310. package/lib/Types/Product.d.ts.map +0 -1
  311. package/lib/Types/Product.js.map +0 -1
  312. package/lib/Types/Signal.d.ts.map +0 -1
  313. package/lib/Types/Signal.js.map +0 -1
  314. package/lib/Types/Socket.d.ts.map +0 -1
  315. package/lib/Types/Socket.js.map +0 -1
  316. package/lib/Types/State.d.ts.map +0 -1
  317. package/lib/Types/State.js.map +0 -1
  318. package/lib/Types/USync.d.ts.map +0 -1
  319. package/lib/Types/USync.js.map +0 -1
  320. package/lib/Types/index.d.ts.map +0 -1
  321. package/lib/Types/index.js.map +0 -1
  322. package/lib/Utils/auth-utils.d.ts.map +0 -1
  323. package/lib/Utils/auth-utils.js.map +0 -1
  324. package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
  325. package/lib/Utils/baileys-event-stream.js.map +0 -1
  326. package/lib/Utils/browser-utils.d.ts +0 -4
  327. package/lib/Utils/browser-utils.d.ts.map +0 -1
  328. package/lib/Utils/browser-utils.js +0 -28
  329. package/lib/Utils/browser-utils.js.map +0 -1
  330. package/lib/Utils/business.d.ts.map +0 -1
  331. package/lib/Utils/business.js.map +0 -1
  332. package/lib/Utils/chat-utils.d.ts.map +0 -1
  333. package/lib/Utils/chat-utils.js.map +0 -1
  334. package/lib/Utils/crypto.d.ts.map +0 -1
  335. package/lib/Utils/crypto.js.map +0 -1
  336. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  337. package/lib/Utils/decode-wa-message.js.map +0 -1
  338. package/lib/Utils/event-buffer.d.ts.map +0 -1
  339. package/lib/Utils/event-buffer.js.map +0 -1
  340. package/lib/Utils/generics.d.ts.map +0 -1
  341. package/lib/Utils/generics.js.map +0 -1
  342. package/lib/Utils/history.d.ts.map +0 -1
  343. package/lib/Utils/history.js.map +0 -1
  344. package/lib/Utils/index.d.ts.map +0 -1
  345. package/lib/Utils/index.js.map +0 -1
  346. package/lib/Utils/link-preview.d.ts.map +0 -1
  347. package/lib/Utils/link-preview.js.map +0 -1
  348. package/lib/Utils/logger.d.ts.map +0 -1
  349. package/lib/Utils/logger.js.map +0 -1
  350. package/lib/Utils/lt-hash.d.ts.map +0 -1
  351. package/lib/Utils/lt-hash.js.map +0 -1
  352. package/lib/Utils/make-mutex.d.ts.map +0 -1
  353. package/lib/Utils/make-mutex.js.map +0 -1
  354. package/lib/Utils/message-retry-manager.d.ts.map +0 -1
  355. package/lib/Utils/message-retry-manager.js.map +0 -1
  356. package/lib/Utils/messages-media.d.ts.map +0 -1
  357. package/lib/Utils/messages-media.js.map +0 -1
  358. package/lib/Utils/messages.d.ts.map +0 -1
  359. package/lib/Utils/messages.js.map +0 -1
  360. package/lib/Utils/noise-handler.d.ts.map +0 -1
  361. package/lib/Utils/noise-handler.js.map +0 -1
  362. package/lib/Utils/pre-key-manager.d.ts +0 -28
  363. package/lib/Utils/pre-key-manager.d.ts.map +0 -1
  364. package/lib/Utils/pre-key-manager.js +0 -106
  365. package/lib/Utils/pre-key-manager.js.map +0 -1
  366. package/lib/Utils/process-message.d.ts.map +0 -1
  367. package/lib/Utils/process-message.js.map +0 -1
  368. package/lib/Utils/signal.d.ts.map +0 -1
  369. package/lib/Utils/signal.js.map +0 -1
  370. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  371. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  372. package/lib/Utils/validate-connection.d.ts.map +0 -1
  373. package/lib/Utils/validate-connection.js.map +0 -1
  374. package/lib/WABinary/constants.d.ts.map +0 -1
  375. package/lib/WABinary/constants.js.map +0 -1
  376. package/lib/WABinary/decode.d.ts.map +0 -1
  377. package/lib/WABinary/decode.js.map +0 -1
  378. package/lib/WABinary/encode.d.ts.map +0 -1
  379. package/lib/WABinary/encode.js.map +0 -1
  380. package/lib/WABinary/generic-utils.d.ts.map +0 -1
  381. package/lib/WABinary/generic-utils.js.map +0 -1
  382. package/lib/WABinary/index.d.ts.map +0 -1
  383. package/lib/WABinary/index.js.map +0 -1
  384. package/lib/WABinary/jid-utils.d.ts.map +0 -1
  385. package/lib/WABinary/jid-utils.js.map +0 -1
  386. package/lib/WABinary/types.d.ts.map +0 -1
  387. package/lib/WABinary/types.js.map +0 -1
  388. package/lib/WAM/BinaryInfo.d.ts.map +0 -1
  389. package/lib/WAM/BinaryInfo.js.map +0 -1
  390. package/lib/WAM/constants.d.ts.map +0 -1
  391. package/lib/WAM/constants.js.map +0 -1
  392. package/lib/WAM/encode.d.ts.map +0 -1
  393. package/lib/WAM/encode.js.map +0 -1
  394. package/lib/WAM/index.d.ts.map +0 -1
  395. package/lib/WAM/index.js.map +0 -1
  396. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
  397. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
  398. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
  399. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
  400. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
  401. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
  402. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
  403. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
  404. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  405. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
  406. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  407. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
  408. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  409. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
  410. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
  411. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
  412. package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
  413. package/lib/WAUSync/Protocols/index.js.map +0 -1
  414. package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
  415. package/lib/WAUSync/USyncQuery.js.map +0 -1
  416. package/lib/WAUSync/USyncUser.d.ts.map +0 -1
  417. package/lib/WAUSync/USyncUser.js.map +0 -1
  418. package/lib/WAUSync/index.d.ts.map +0 -1
  419. package/lib/WAUSync/index.js.map +0 -1
  420. package/lib/index.d.ts.map +0 -1
  421. package/lib/index.js.map +0 -1
@@ -0,0 +1,129 @@
1
+ const SenderChainKey = require('./sender_chain_key');
2
+ const SenderMessageKey = require('./sender_message_key');
3
+
4
+ const protobufs = require('./protobufs');
5
+
6
+ class SenderKeyState {
7
+ MAX_MESSAGE_KEYS = 2000;
8
+
9
+ constructor(
10
+ id = null,
11
+ iteration = null,
12
+ chainKey = null,
13
+ signatureKeyPair = null,
14
+ signatureKeyPublic = null,
15
+ signatureKeyPrivate = null,
16
+ senderKeyStateStructure = null
17
+ ) {
18
+ if (senderKeyStateStructure) {
19
+ this.senderKeyStateStructure = senderKeyStateStructure;
20
+ } else {
21
+ if (signatureKeyPair) {
22
+ signatureKeyPublic = signatureKeyPair.public;
23
+ signatureKeyPrivate = signatureKeyPair.private;
24
+ }
25
+
26
+ chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
27
+ this.senderKeyStateStructure = protobufs.SenderKeyStateStructure.create();
28
+ const senderChainKeyStructure = protobufs.SenderChainKey.create();
29
+ senderChainKeyStructure.iteration = iteration;
30
+ senderChainKeyStructure.seed = chainKey;
31
+ this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
32
+
33
+ const signingKeyStructure = protobufs.SenderSigningKey.create();
34
+ signingKeyStructure.public =
35
+ typeof signatureKeyPublic === 'string' ?
36
+ Buffer.from(signatureKeyPublic, 'base64') :
37
+ signatureKeyPublic;
38
+ if (signatureKeyPrivate) {
39
+ signingKeyStructure.private =
40
+ typeof signatureKeyPrivate === 'string' ?
41
+ Buffer.from(signatureKeyPrivate, 'base64') :
42
+ signatureKeyPrivate;
43
+ }
44
+ this.senderKeyStateStructure.senderKeyId = id;
45
+ this.senderChainKey = senderChainKeyStructure;
46
+ this.senderKeyStateStructure.senderSigningKey = signingKeyStructure;
47
+ }
48
+ this.senderKeyStateStructure.senderMessageKeys =
49
+ this.senderKeyStateStructure.senderMessageKeys || [];
50
+ }
51
+
52
+ SenderKeyState(senderKeyStateStructure) {
53
+ this.senderKeyStateStructure = senderKeyStateStructure;
54
+ }
55
+
56
+ getKeyId() {
57
+ return this.senderKeyStateStructure.senderKeyId;
58
+ }
59
+
60
+ getSenderChainKey() {
61
+ return new SenderChainKey(
62
+ this.senderKeyStateStructure.senderChainKey.iteration,
63
+ this.senderKeyStateStructure.senderChainKey.seed
64
+ );
65
+ }
66
+
67
+ setSenderChainKey(chainKey) {
68
+ const senderChainKeyStructure = protobufs.SenderChainKey.create({
69
+ iteration: chainKey.getIteration(),
70
+ seed: chainKey.getSeed(),
71
+ });
72
+ this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
73
+ }
74
+
75
+ getSigningKeyPublic() {
76
+ return typeof this.senderKeyStateStructure.senderSigningKey.public === 'string' ?
77
+ Buffer.from(this.senderKeyStateStructure.senderSigningKey.public, 'base64') :
78
+ this.senderKeyStateStructure.senderSigningKey.public;
79
+ }
80
+
81
+ getSigningKeyPrivate() {
82
+ return typeof this.senderKeyStateStructure.senderSigningKey.private === 'string' ?
83
+ Buffer.from(this.senderKeyStateStructure.senderSigningKey.private, 'base64') :
84
+ this.senderKeyStateStructure.senderSigningKey.private;
85
+ }
86
+
87
+ hasSenderMessageKey(iteration) {
88
+ const list = this.senderKeyStateStructure.senderMessageKeys;
89
+ for (let o = 0; o < list.length; o++) {
90
+ const senderMessageKey = list[o];
91
+ if (senderMessageKey.iteration === iteration) return true;
92
+ }
93
+ return false;
94
+ }
95
+
96
+ addSenderMessageKey(senderMessageKey) {
97
+ const senderMessageKeyStructure = protobufs.SenderKeyStateStructure.create({
98
+ iteration: senderMessageKey.getIteration(),
99
+ seed: senderMessageKey.getSeed(),
100
+ });
101
+ this.senderKeyStateStructure.senderMessageKeys.push(senderMessageKeyStructure);
102
+
103
+ if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
104
+ this.senderKeyStateStructure.senderMessageKeys.shift();
105
+ }
106
+ }
107
+
108
+ removeSenderMessageKey(iteration) {
109
+ let result = null;
110
+
111
+ this.senderKeyStateStructure.senderMessageKeys = this.senderKeyStateStructure.senderMessageKeys.filter(
112
+ senderMessageKey => {
113
+ if (senderMessageKey.iteration === iteration) result = senderMessageKey;
114
+ return senderMessageKey.iteration !== iteration;
115
+ }
116
+ );
117
+
118
+ if (result != null) {
119
+ return new SenderMessageKey(result.iteration, result.seed);
120
+ }
121
+ return null;
122
+ }
123
+
124
+ getStructure() {
125
+ return this.senderKeyStateStructure;
126
+ }
127
+ }
128
+
129
+ module.exports = SenderKeyState;
@@ -1,5 +1,13 @@
1
- import { deriveSecrets } from 'libsignal/src/crypto.js';
2
- export class SenderMessageKey {
1
+ const { deriveSecrets } = require('@neelegirl/libsignal/src/crypto');
2
+ class SenderMessageKey {
3
+ iteration = 0;
4
+
5
+ iv = Buffer.alloc(0);
6
+
7
+ cipherKey = Buffer.alloc(0);
8
+
9
+ seed = Buffer.alloc(0);
10
+
3
11
  constructor(iteration, seed) {
4
12
  const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
5
13
  const keys = new Uint8Array(32);
@@ -7,20 +15,25 @@ export class SenderMessageKey {
7
15
  keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
8
16
  this.iv = Buffer.from(derivative[0].slice(0, 16));
9
17
  this.cipherKey = Buffer.from(keys.buffer);
18
+
10
19
  this.iteration = iteration;
11
20
  this.seed = seed;
12
21
  }
22
+
13
23
  getIteration() {
14
24
  return this.iteration;
15
25
  }
26
+
16
27
  getIv() {
17
28
  return this.iv;
18
29
  }
30
+
19
31
  getCipherKey() {
20
32
  return this.cipherKey;
21
33
  }
34
+
22
35
  getSeed() {
23
36
  return this.seed;
24
37
  }
25
38
  }
26
- //# sourceMappingURL=sender-message-key.js.map
39
+ module.exports = SenderMessageKey;
@@ -1,5 +1,4 @@
1
- import type { LIDMapping, SignalAuthState } from '../Types/index.js';
2
- import type { SignalRepositoryWithLIDStore } from '../Types/Signal.js';
3
- import type { ILogger } from '../Utils/logger.js';
4
- export declare function makeLibSignalRepository(auth: SignalAuthState, logger: ILogger, pnToLIDFunc?: (jids: string[]) => Promise<LIDMapping[] | undefined>): SignalRepositoryWithLIDStore;
5
- //# sourceMappingURL=libsignal.d.ts.map
1
+ import { SignalAuthState } from '../Types'
2
+ import { SignalRepository } from '../Types/Signal'
3
+
4
+ export declare function makeLibSignalRepository(auth: SignalAuthState): SignalRepository
@@ -1,342 +1,162 @@
1
- /* @ts-ignore */
2
- import * as libsignal from 'libsignal';
3
- import { LRUCache } from 'lru-cache';
4
- import { generateSignalPubKey } from '../Utils/index.js';
5
- import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser, jidDecode, transferDevice, WAJIDDomains } from '../WABinary/index.js';
6
- import { SenderKeyName } from './Group/sender-key-name.js';
7
- import { SenderKeyRecord } from './Group/sender-key-record.js';
8
- import { GroupCipher, GroupSessionBuilder, SenderKeyDistributionMessage } from './Group/index.js';
9
- import { LIDMappingStore } from './lid-mapping.js';
10
- export function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
11
- const lidMapping = new LIDMappingStore(auth.keys, logger, pnToLIDFunc);
12
- const storage = signalStorage(auth, lidMapping);
13
- const parsedKeys = auth.keys;
14
- const migratedSessionCache = new LRUCache({
15
- ttl: 7 * 24 * 60 * 60 * 1000, // 7 days
16
- ttlAutopurge: true,
17
- updateAgeOnGet: true
18
- });
19
- const repository = {
1
+ "use strict"
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v })
17
+ }) : function(o, v) {
18
+ o["default"] = v
19
+ })
20
+
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod
23
+ var result = {}
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
25
+ __setModuleDefault(result, mod)
26
+ return result
27
+ }
28
+ Object.defineProperty(exports, "__esModule", { value: true })
29
+
30
+ const libsignal = __importStar(require("@neelegirl/libsignal"))
31
+ const WASignalGroup_1 = require("./WASignalGroup")
32
+ const Utils_1 = require("../Utils")
33
+ const WABinary_1 = require("../WABinary")
34
+
35
+ function makeLibSignalRepository(auth) {
36
+ const storage = signalStorage(auth)
37
+ return {
20
38
  decryptGroupMessage({ group, authorJid, msg }) {
21
- const senderName = jidToSignalSenderKeyName(group, authorJid);
22
- const cipher = new GroupCipher(storage, senderName);
23
- // Use transaction to ensure atomicity
24
- return parsedKeys.transaction(async () => {
25
- return cipher.decrypt(msg);
26
- }, group);
39
+ const senderName = jidToSignalSenderKeyName(group, authorJid)
40
+ const cipher = new WASignalGroup_1.GroupCipher(storage, senderName)
41
+ return cipher.decrypt(msg)
27
42
  },
28
43
  async processSenderKeyDistributionMessage({ item, authorJid }) {
29
- const builder = new GroupSessionBuilder(storage);
30
- if (!item.groupId) {
31
- throw new Error('Group ID is required for sender key distribution message');
32
- }
33
- const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
34
- const senderMsg = new SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
35
- const senderNameStr = senderName.toString();
36
- const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
44
+ const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
45
+ const senderName = jidToSignalSenderKeyName(item.groupId, authorJid)
46
+ const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage)
47
+ const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
37
48
  if (!senderKey) {
38
- await storage.storeSenderKey(senderName, new SenderKeyRecord());
49
+ await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
39
50
  }
40
- return parsedKeys.transaction(async () => {
41
- const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
42
- if (!senderKey) {
43
- await storage.storeSenderKey(senderName, new SenderKeyRecord());
44
- }
45
- await builder.process(senderName, senderMsg);
46
- }, item.groupId);
51
+ await builder.process(senderName, senderMsg)
47
52
  },
48
53
  async decryptMessage({ jid, type, ciphertext }) {
49
- const addr = jidToSignalProtocolAddress(jid);
50
- const session = new libsignal.SessionCipher(storage, addr);
51
- async function doDecrypt() {
52
- let result;
53
- switch (type) {
54
- case 'pkmsg':
55
- result = await session.decryptPreKeyWhisperMessage(ciphertext);
56
- break;
57
- case 'msg':
58
- result = await session.decryptWhisperMessage(ciphertext);
59
- break;
60
- }
61
- return result;
54
+ const addr = jidToSignalProtocolAddress(jid)
55
+ const session = new libsignal.SessionCipher(storage, addr)
56
+ let result
57
+ switch (type) {
58
+ case 'pkmsg':
59
+ result = await session.decryptPreKeyWhisperMessage(ciphertext)
60
+ break
61
+ case 'msg':
62
+ result = await session.decryptWhisperMessage(ciphertext)
63
+ break
62
64
  }
63
- // If it's not a sync message, we need to ensure atomicity
64
- // For regular messages, we use a transaction to ensure atomicity
65
- return parsedKeys.transaction(async () => {
66
- return await doDecrypt();
67
- }, jid);
65
+ return result
68
66
  },
69
67
  async encryptMessage({ jid, data }) {
70
- const addr = jidToSignalProtocolAddress(jid);
71
- const cipher = new libsignal.SessionCipher(storage, addr);
72
- // Use transaction to ensure atomicity
73
- return parsedKeys.transaction(async () => {
74
- const { type: sigType, body } = await cipher.encrypt(data);
75
- const type = sigType === 3 ? 'pkmsg' : 'msg';
76
- return { type, ciphertext: Buffer.from(body, 'binary') };
77
- }, jid);
68
+ const addr = jidToSignalProtocolAddress(jid)
69
+ const cipher = new libsignal.SessionCipher(storage, addr)
70
+ const { type: sigType, body } = await cipher.encrypt(data)
71
+ const type = sigType === 3 ? 'pkmsg' : 'msg'
72
+ return { type, ciphertext: Buffer.from(body, 'binary') }
78
73
  },
79
74
  async encryptGroupMessage({ group, meId, data }) {
80
- const senderName = jidToSignalSenderKeyName(group, meId);
81
- const builder = new GroupSessionBuilder(storage);
82
- const senderNameStr = senderName.toString();
83
- return parsedKeys.transaction(async () => {
84
- const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
85
- if (!senderKey) {
86
- await storage.storeSenderKey(senderName, new SenderKeyRecord());
87
- }
88
- const senderKeyDistributionMessage = await builder.create(senderName);
89
- const session = new GroupCipher(storage, senderName);
90
- const ciphertext = await session.encrypt(data);
91
- return {
92
- ciphertext,
93
- senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
94
- };
95
- }, group);
75
+ const senderName = jidToSignalSenderKeyName(group, meId)
76
+ const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
77
+ const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
78
+ if (!senderKey) {
79
+ await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
80
+ }
81
+ const senderKeyDistributionMessage = await builder.create(senderName)
82
+ const session = new WASignalGroup_1.GroupCipher(storage, senderName)
83
+ const ciphertext = await session.encrypt(data)
84
+ return {
85
+ ciphertext,
86
+ senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
87
+ }
96
88
  },
97
89
  async injectE2ESession({ jid, session }) {
98
- logger.trace({ jid }, 'injecting E2EE session');
99
- const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
100
- return parsedKeys.transaction(async () => {
101
- await cipher.initOutgoing(session);
102
- }, jid);
90
+ const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid))
91
+ await cipher.initOutgoing(session)
103
92
  },
104
93
  jidToSignalProtocolAddress(jid) {
105
- return jidToSignalProtocolAddress(jid).toString();
106
- },
107
- // Optimized direct access to LID mapping store
108
- lidMapping,
109
- async validateSession(jid) {
110
- try {
111
- const addr = jidToSignalProtocolAddress(jid);
112
- const session = await storage.loadSession(addr.toString());
113
- if (!session) {
114
- return { exists: false, reason: 'no session' };
115
- }
116
- if (!session.haveOpenSession()) {
117
- return { exists: false, reason: 'no open session' };
118
- }
119
- return { exists: true };
120
- }
121
- catch (error) {
122
- return { exists: false, reason: 'validation error' };
123
- }
124
- },
125
- async deleteSession(jids) {
126
- if (!jids.length)
127
- return;
128
- // Convert JIDs to signal addresses and prepare for bulk deletion
129
- const sessionUpdates = {};
130
- jids.forEach(jid => {
131
- const addr = jidToSignalProtocolAddress(jid);
132
- sessionUpdates[addr.toString()] = null;
133
- });
134
- // Single transaction for all deletions
135
- return parsedKeys.transaction(async () => {
136
- await auth.keys.set({ session: sessionUpdates });
137
- }, `delete-${jids.length}-sessions`);
94
+ return jidToSignalProtocolAddress(jid).toString()
138
95
  },
139
- async migrateSession(fromJid, toJid) {
140
- // TODO: use usync to handle this entire mess
141
- if (!fromJid || (!isLidUser(toJid) && !isHostedLidUser(toJid)))
142
- return { migrated: 0, skipped: 0, total: 0 };
143
- // Only support PN to LID migration
144
- if (!isPnUser(fromJid) && !isHostedPnUser(fromJid)) {
145
- return { migrated: 0, skipped: 0, total: 1 };
146
- }
147
- const { user } = jidDecode(fromJid);
148
- logger.debug({ fromJid }, 'bulk device migration - loading all user devices');
149
- // Get user's device list from storage
150
- const { [user]: userDevices } = await parsedKeys.get('device-list', [user]);
151
- if (!userDevices) {
152
- return { migrated: 0, skipped: 0, total: 0 };
153
- }
154
- const { device: fromDevice } = jidDecode(fromJid);
155
- const fromDeviceStr = fromDevice?.toString() || '0';
156
- if (!userDevices.includes(fromDeviceStr)) {
157
- userDevices.push(fromDeviceStr);
158
- }
159
- // Filter out cached devices before database fetch
160
- const uncachedDevices = userDevices.filter(device => {
161
- const deviceKey = `${user}.${device}`;
162
- return !migratedSessionCache.has(deviceKey);
163
- });
164
- // Bulk check session existence only for uncached devices
165
- const deviceSessionKeys = uncachedDevices.map(device => `${user}.${device}`);
166
- const existingSessions = await parsedKeys.get('session', deviceSessionKeys);
167
- // Step 3: Convert existing sessions to JIDs (only migrate sessions that exist)
168
- const deviceJids = [];
169
- for (const [sessionKey, sessionData] of Object.entries(existingSessions)) {
170
- if (sessionData) {
171
- // Session exists in storage
172
- const deviceStr = sessionKey.split('.')[1];
173
- if (!deviceStr)
174
- continue;
175
- const deviceNum = parseInt(deviceStr);
176
- let jid = deviceNum === 0 ? `${user}@s.whatsapp.net` : `${user}:${deviceNum}@s.whatsapp.net`;
177
- if (deviceNum === 99) {
178
- jid = `${user}:99@hosted`;
179
- }
180
- deviceJids.push(jid);
181
- }
182
- }
183
- logger.debug({
184
- fromJid,
185
- totalDevices: userDevices.length,
186
- devicesWithSessions: deviceJids.length,
187
- devices: deviceJids
188
- }, 'bulk device migration complete - all user devices processed');
189
- // Single transaction for all migrations
190
- return parsedKeys.transaction(async () => {
191
- const migrationOps = deviceJids.map(jid => {
192
- const lidWithDevice = transferDevice(jid, toJid);
193
- const fromDecoded = jidDecode(jid);
194
- const toDecoded = jidDecode(lidWithDevice);
195
- return {
196
- fromJid: jid,
197
- toJid: lidWithDevice,
198
- pnUser: fromDecoded.user,
199
- lidUser: toDecoded.user,
200
- deviceId: fromDecoded.device || 0,
201
- fromAddr: jidToSignalProtocolAddress(jid),
202
- toAddr: jidToSignalProtocolAddress(lidWithDevice)
203
- };
204
- });
205
- const totalOps = migrationOps.length;
206
- let migratedCount = 0;
207
- // Bulk fetch PN sessions - already exist (verified during device discovery)
208
- const pnAddrStrings = Array.from(new Set(migrationOps.map(op => op.fromAddr.toString())));
209
- const pnSessions = await parsedKeys.get('session', pnAddrStrings);
210
- // Prepare bulk session updates (PN → LID migration + deletion)
211
- const sessionUpdates = {};
212
- for (const op of migrationOps) {
213
- const pnAddrStr = op.fromAddr.toString();
214
- const lidAddrStr = op.toAddr.toString();
215
- const pnSession = pnSessions[pnAddrStr];
216
- if (pnSession) {
217
- // Session exists (guaranteed from device discovery)
218
- const fromSession = libsignal.SessionRecord.deserialize(pnSession);
219
- if (fromSession.haveOpenSession()) {
220
- // Queue for bulk update: copy to LID, delete from PN
221
- sessionUpdates[lidAddrStr] = fromSession.serialize();
222
- sessionUpdates[pnAddrStr] = null;
223
- migratedCount++;
224
- }
225
- }
226
- }
227
- // Single bulk session update for all migrations
228
- if (Object.keys(sessionUpdates).length > 0) {
229
- await parsedKeys.set({ session: sessionUpdates });
230
- logger.debug({ migratedSessions: migratedCount }, 'bulk session migration complete');
231
- // Cache device-level migrations
232
- for (const op of migrationOps) {
233
- if (sessionUpdates[op.toAddr.toString()]) {
234
- const deviceKey = `${op.pnUser}.${op.deviceId}`;
235
- migratedSessionCache.set(deviceKey, true);
236
- }
237
- }
238
- }
239
- const skippedCount = totalOps - migratedCount;
240
- return { migrated: migratedCount, skipped: skippedCount, total: totalOps };
241
- }, `migrate-${deviceJids.length}-sessions-${jidDecode(toJid)?.user}`);
242
- }
243
- };
244
- return repository;
96
+ }
245
97
  }
98
+
246
99
  const jidToSignalProtocolAddress = (jid) => {
247
- const decoded = jidDecode(jid);
248
- const { user, device, server, domainType } = decoded;
249
- if (!user) {
250
- throw new Error(`JID decoded but user is empty: "${jid}" -> user: "${user}", server: "${server}", device: ${device}`);
251
- }
252
- const signalUser = domainType !== WAJIDDomains.WHATSAPP ? `${user}_${domainType}` : user;
253
- const finalDevice = device || 0;
254
- if (device === 99 && decoded.server !== 'hosted' && decoded.server !== 'hosted.lid') {
255
- throw new Error('Unexpected non-hosted device JID with device 99. This ID seems invalid. ID:' + jid);
256
- }
257
- return new libsignal.ProtocolAddress(signalUser, finalDevice);
258
- };
100
+ const { user, device } = WABinary_1.jidDecode(jid)
101
+ return new libsignal.ProtocolAddress(user, device || 0)
102
+ }
103
+
259
104
  const jidToSignalSenderKeyName = (group, user) => {
260
- return new SenderKeyName(group, jidToSignalProtocolAddress(user));
261
- };
262
- function signalStorage({ creds, keys }, lidMapping) {
263
- // Shared function to resolve PN signal address to LID if mapping exists
264
- const resolveLIDSignalAddress = async (id) => {
265
- if (id.includes('.')) {
266
- const [deviceId, device] = id.split('.');
267
- const [user, domainType_] = deviceId.split('_');
268
- const domainType = parseInt(domainType_ || '0');
269
- if (domainType === WAJIDDomains.LID || domainType === WAJIDDomains.HOSTED_LID)
270
- return id;
271
- const pnJid = `${user}${device !== '0' ? `:${device}` : ''}@${domainType === WAJIDDomains.HOSTED ? 'hosted' : 's.whatsapp.net'}`;
272
- const lidForPN = await lidMapping.getLIDForPN(pnJid);
273
- if (lidForPN) {
274
- const lidAddr = jidToSignalProtocolAddress(lidForPN);
275
- return lidAddr.toString();
276
- }
277
- }
278
- return id;
279
- };
105
+ return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString()
106
+ }
107
+
108
+ function signalStorage({ creds, keys }) {
280
109
  return {
281
110
  loadSession: async (id) => {
282
- try {
283
- const wireJid = await resolveLIDSignalAddress(id);
284
- const { [wireJid]: sess } = await keys.get('session', [wireJid]);
285
- if (sess) {
286
- return libsignal.SessionRecord.deserialize(sess);
287
- }
288
- }
289
- catch (e) {
290
- return null;
111
+ const { [id]: sess } = await keys.get('session', [id])
112
+ if (sess) {
113
+ return libsignal.SessionRecord.deserialize(sess)
291
114
  }
292
- return null;
293
115
  },
294
116
  storeSession: async (id, session) => {
295
- const wireJid = await resolveLIDSignalAddress(id);
296
- await keys.set({ session: { [wireJid]: session.serialize() } });
117
+ await keys.set({ 'session': { [id]: session.serialize() } })
297
118
  },
298
119
  isTrustedIdentity: () => {
299
- return true; // todo: implement
120
+ return true
300
121
  },
301
122
  loadPreKey: async (id) => {
302
- const keyId = id.toString();
303
- const { [keyId]: key } = await keys.get('pre-key', [keyId]);
123
+ const keyId = id.toString()
124
+ const { [keyId]: key } = await keys.get('pre-key', [keyId])
304
125
  if (key) {
305
126
  return {
306
127
  privKey: Buffer.from(key.private),
307
128
  pubKey: Buffer.from(key.public)
308
- };
129
+ }
309
130
  }
310
131
  },
311
132
  removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
312
133
  loadSignedPreKey: () => {
313
- const key = creds.signedPreKey;
134
+ const key = creds.signedPreKey
314
135
  return {
315
136
  privKey: Buffer.from(key.keyPair.private),
316
137
  pubKey: Buffer.from(key.keyPair.public)
317
- };
138
+ }
318
139
  },
319
- loadSenderKey: async (senderKeyName) => {
320
- const keyId = senderKeyName.toString();
321
- const { [keyId]: key } = await keys.get('sender-key', [keyId]);
140
+ loadSenderKey: async (keyId) => {
141
+ const { [keyId]: key } = await keys.get('sender-key', [keyId])
322
142
  if (key) {
323
- return SenderKeyRecord.deserialize(key);
143
+ return new WASignalGroup_1.SenderKeyRecord(key)
324
144
  }
325
- return new SenderKeyRecord();
326
145
  },
327
- storeSenderKey: async (senderKeyName, key) => {
328
- const keyId = senderKeyName.toString();
329
- const serialized = JSON.stringify(key.serialize());
330
- await keys.set({ 'sender-key': { [keyId]: Buffer.from(serialized, 'utf-8') } });
146
+ storeSenderKey: async (keyId, key) => {
147
+ await keys.set({ 'sender-key': { [keyId]: key.serialize() } })
331
148
  },
332
- getOurRegistrationId: () => creds.registrationId,
149
+ getOurRegistrationId: () => (creds.registrationId),
333
150
  getOurIdentity: () => {
334
- const { signedIdentityKey } = creds;
151
+ const { signedIdentityKey } = creds
335
152
  return {
336
153
  privKey: Buffer.from(signedIdentityKey.private),
337
- pubKey: Buffer.from(generateSignalPubKey(signedIdentityKey.public))
338
- };
154
+ pubKey: Utils_1.generateSignalPubKey(signedIdentityKey.public),
155
+ }
339
156
  }
340
- };
157
+ }
341
158
  }
342
- //# sourceMappingURL=libsignal.js.map
159
+
160
+ module.exports = {
161
+ makeLibSignalRepository
162
+ }
@@ -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
+ }