@eduh_dev021/baileys 0.0.0-stage → 1.0.0

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 (504) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +495 -2
  3. package/WAProto/index.d.ts +22220 -0
  4. package/WAProto/index.js +5 -0
  5. package/cjs/WAProto/index.d.ts +22220 -0
  6. package/cjs/WAProto/index.js +60125 -0
  7. package/cjs/engine-requirements.js +12 -0
  8. package/cjs/lib/Addon/http-error.d.ts +18 -0
  9. package/cjs/lib/Addon/http-error.js +66 -0
  10. package/cjs/lib/Addon/index.d.ts +3 -0
  11. package/cjs/lib/Addon/index.js +50 -0
  12. package/cjs/lib/Addon/keyed-db.d.ts +14 -0
  13. package/cjs/lib/Addon/keyed-db.js +264 -0
  14. package/cjs/lib/Addon/link-preview.d.ts +15 -0
  15. package/cjs/lib/Addon/link-preview.js +104 -0
  16. package/cjs/lib/Defaults/index.d.ts +184 -0
  17. package/cjs/lib/Defaults/index.js +292 -0
  18. package/cjs/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  19. package/cjs/lib/Signal/Group/ciphertext-message.js +37 -0
  20. package/cjs/lib/Signal/Group/group-cipher.d.ts +10 -0
  21. package/cjs/lib/Signal/Group/group-cipher.js +105 -0
  22. package/cjs/lib/Signal/Group/group-session-builder.d.ts +7 -0
  23. package/cjs/lib/Signal/Group/group-session-builder.js +65 -0
  24. package/cjs/lib/Signal/Group/index.d.ts +11 -0
  25. package/cjs/lib/Signal/Group/index.js +67 -0
  26. package/cjs/lib/Signal/Group/keyhelper.d.ts +6 -0
  27. package/cjs/lib/Signal/Group/keyhelper.js +47 -0
  28. package/cjs/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  29. package/cjs/lib/Signal/Group/sender-chain-key.js +51 -0
  30. package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  31. package/cjs/lib/Signal/Group/sender-key-distribution-message.js +80 -0
  32. package/cjs/lib/Signal/Group/sender-key-message.d.ts +18 -0
  33. package/cjs/lib/Signal/Group/sender-key-message.js +87 -0
  34. package/cjs/lib/Signal/Group/sender-key-name.d.ts +11 -0
  35. package/cjs/lib/Signal/Group/sender-key-name.js +73 -0
  36. package/cjs/lib/Signal/Group/sender-key-record.d.ts +12 -0
  37. package/cjs/lib/Signal/Group/sender-key-record.js +66 -0
  38. package/cjs/lib/Signal/Group/sender-key-state.d.ts +16 -0
  39. package/cjs/lib/Signal/Group/sender-key-state.js +106 -0
  40. package/cjs/lib/Signal/Group/sender-message-key.d.ts +11 -0
  41. package/cjs/lib/Signal/Group/sender-message-key.js +51 -0
  42. package/cjs/lib/Signal/libsignal.d.ts +54 -0
  43. package/cjs/lib/Signal/libsignal.js +421 -0
  44. package/cjs/lib/Signal/lid-mapping.d.ts +20 -0
  45. package/cjs/lib/Signal/lid-mapping.js +292 -0
  46. package/cjs/lib/Socket/Client/index.d.ts +2 -0
  47. package/cjs/lib/Socket/Client/index.js +23 -0
  48. package/cjs/lib/Socket/Client/types.d.ts +5 -0
  49. package/cjs/lib/Socket/Client/types.js +36 -0
  50. package/cjs/lib/Socket/Client/websocket.d.ts +12 -0
  51. package/cjs/lib/Socket/Client/websocket.js +143 -0
  52. package/cjs/lib/Socket/business.d.ts +387 -0
  53. package/cjs/lib/Socket/business.js +402 -0
  54. package/cjs/lib/Socket/chats.d.ts +144 -0
  55. package/cjs/lib/Socket/chats.js +1118 -0
  56. package/cjs/lib/Socket/communities.d.ts +554 -0
  57. package/cjs/lib/Socket/communities.js +456 -0
  58. package/cjs/lib/Socket/groups.d.ts +286 -0
  59. package/cjs/lib/Socket/groups.js +366 -0
  60. package/cjs/lib/Socket/index.d.ts +522 -0
  61. package/cjs/lib/Socket/index.js +32 -0
  62. package/cjs/lib/Socket/messages-recv.d.ts +326 -0
  63. package/cjs/lib/Socket/messages-recv.js +1670 -0
  64. package/cjs/lib/Socket/messages-send.d.ts +321 -0
  65. package/cjs/lib/Socket/messages-send.js +1252 -0
  66. package/cjs/lib/Socket/mex.d.ts +1 -0
  67. package/cjs/lib/Socket/mex.js +65 -0
  68. package/cjs/lib/Socket/newsletter.d.ts +283 -0
  69. package/cjs/lib/Socket/newsletter.js +243 -0
  70. package/cjs/lib/Socket/socket.d.ts +61 -0
  71. package/cjs/lib/Socket/socket.js +908 -0
  72. package/cjs/lib/Store/index.d.ts +3 -0
  73. package/cjs/lib/Store/index.js +25 -0
  74. package/cjs/lib/Store/make-in-memory-store.d.ts +63 -0
  75. package/cjs/lib/Store/make-in-memory-store.js +431 -0
  76. package/cjs/lib/Store/make-ordered-dictionary.d.ts +12 -0
  77. package/cjs/lib/Store/make-ordered-dictionary.js +101 -0
  78. package/cjs/lib/Store/object-repository.d.ts +10 -0
  79. package/cjs/lib/Store/object-repository.js +49 -0
  80. package/cjs/lib/Transport/crypto.d.ts +6 -0
  81. package/cjs/lib/Transport/crypto.js +107 -0
  82. package/cjs/lib/Transport/curve.d.ts +8 -0
  83. package/cjs/lib/Transport/curve.js +94 -0
  84. package/cjs/lib/Transport/index.d.ts +16 -0
  85. package/cjs/lib/Transport/index.js +67 -0
  86. package/cjs/lib/Transport/internals.d.ts +57 -0
  87. package/cjs/lib/Transport/internals.js +203 -0
  88. package/cjs/lib/Transport/session-builder.d.ts +40 -0
  89. package/cjs/lib/Transport/session-builder.js +169 -0
  90. package/cjs/lib/Transport/session-cipher.d.ts +26 -0
  91. package/cjs/lib/Transport/session-cipher.js +328 -0
  92. package/cjs/lib/Transport/session-record.d.ts +55 -0
  93. package/cjs/lib/Transport/session-record.js +289 -0
  94. package/cjs/lib/Types/Auth.d.ts +1 -0
  95. package/cjs/lib/Types/Auth.js +15 -0
  96. package/cjs/lib/Types/Bussines.d.ts +1 -0
  97. package/cjs/lib/Types/Bussines.js +15 -0
  98. package/cjs/lib/Types/Call.d.ts +1 -0
  99. package/cjs/lib/Types/Call.js +15 -0
  100. package/cjs/lib/Types/Chat.d.ts +1 -0
  101. package/cjs/lib/Types/Chat.js +33 -0
  102. package/cjs/lib/Types/Contact.d.ts +1 -0
  103. package/cjs/lib/Types/Contact.js +15 -0
  104. package/cjs/lib/Types/Events.d.ts +1 -0
  105. package/cjs/lib/Types/Events.js +1 -0
  106. package/cjs/lib/Types/GroupMetadata.d.ts +1 -0
  107. package/cjs/lib/Types/GroupMetadata.js +15 -0
  108. package/cjs/lib/Types/Label.d.ts +2 -0
  109. package/cjs/lib/Types/Label.js +49 -0
  110. package/cjs/lib/Types/LabelAssociation.d.ts +2 -0
  111. package/cjs/lib/Types/LabelAssociation.js +31 -0
  112. package/cjs/lib/Types/Message.d.ts +11 -0
  113. package/cjs/lib/Types/Message.js +58 -0
  114. package/cjs/lib/Types/Mex.d.ts +2 -0
  115. package/cjs/lib/Types/Mex.js +66 -0
  116. package/cjs/lib/Types/Product.d.ts +1 -0
  117. package/cjs/lib/Types/Product.js +15 -0
  118. package/cjs/lib/Types/RichType.d.ts +2 -0
  119. package/cjs/lib/Types/RichType.js +50 -0
  120. package/cjs/lib/Types/Signal.d.ts +1 -0
  121. package/cjs/lib/Types/Signal.js +1 -0
  122. package/cjs/lib/Types/Socket.d.ts +1 -0
  123. package/cjs/lib/Types/Socket.js +1 -0
  124. package/cjs/lib/Types/State.d.ts +5 -0
  125. package/cjs/lib/Types/State.js +83 -0
  126. package/cjs/lib/Types/USync.d.ts +1 -0
  127. package/cjs/lib/Types/USync.js +1 -0
  128. package/cjs/lib/Types/index.d.ts +13 -0
  129. package/cjs/lib/Types/index.js +64 -0
  130. package/cjs/lib/Utils/auth-utils.d.ts +58 -0
  131. package/cjs/lib/Utils/auth-utils.js +275 -0
  132. package/cjs/lib/Utils/browser-utils.d.ts +9 -0
  133. package/cjs/lib/Utils/browser-utils.js +56 -0
  134. package/cjs/lib/Utils/business.d.ts +49 -0
  135. package/cjs/lib/Utils/business.js +259 -0
  136. package/cjs/lib/Utils/chat-utils.d.ts +408 -0
  137. package/cjs/lib/Utils/chat-utils.js +821 -0
  138. package/cjs/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  139. package/cjs/lib/Utils/companion-reg-client-utils.js +71 -0
  140. package/cjs/lib/Utils/crypto.d.ts +39 -0
  141. package/cjs/lib/Utils/crypto.js +155 -0
  142. package/cjs/lib/Utils/decode-wa-message.d.ts +83 -0
  143. package/cjs/lib/Utils/decode-wa-message.js +316 -0
  144. package/cjs/lib/Utils/event-buffer.d.ts +12 -0
  145. package/cjs/lib/Utils/event-buffer.js +605 -0
  146. package/cjs/lib/Utils/generics.d.ts +63 -0
  147. package/cjs/lib/Utils/generics.js +440 -0
  148. package/cjs/lib/Utils/history.d.ts +75 -0
  149. package/cjs/lib/Utils/history.js +153 -0
  150. package/cjs/lib/Utils/identity-change-handler.d.ts +13 -0
  151. package/cjs/lib/Utils/identity-change-handler.js +73 -0
  152. package/cjs/lib/Utils/index.d.ts +24 -0
  153. package/cjs/lib/Utils/index.js +67 -0
  154. package/cjs/lib/Utils/link-preview.d.ts +13 -0
  155. package/cjs/lib/Utils/link-preview.js +87 -0
  156. package/cjs/lib/Utils/logger.d.ts +12 -0
  157. package/cjs/lib/Utils/logger.js +40 -0
  158. package/cjs/lib/Utils/lt-hash.d.ts +6 -0
  159. package/cjs/lib/Utils/lt-hash.js +28 -0
  160. package/cjs/lib/Utils/make-mutex.d.ts +6 -0
  161. package/cjs/lib/Utils/make-mutex.js +58 -0
  162. package/cjs/lib/Utils/message-retry-manager.d.ts +79 -0
  163. package/cjs/lib/Utils/message-retry-manager.js +274 -0
  164. package/cjs/lib/Utils/messages-media.d.ts +134 -0
  165. package/cjs/lib/Utils/messages-media.js +799 -0
  166. package/cjs/lib/Utils/messages.d.ts +47 -0
  167. package/cjs/lib/Utils/messages.js +1667 -0
  168. package/cjs/lib/Utils/noise-handler.d.ts +20 -0
  169. package/cjs/lib/Utils/noise-handler.js +223 -0
  170. package/cjs/lib/Utils/offline-node-processor.d.ts +10 -0
  171. package/cjs/lib/Utils/offline-node-processor.js +60 -0
  172. package/cjs/lib/Utils/pre-key-manager.d.ts +25 -0
  173. package/cjs/lib/Utils/pre-key-manager.js +116 -0
  174. package/cjs/lib/Utils/process-message.d.ts +83 -0
  175. package/cjs/lib/Utils/process-message.js +607 -0
  176. package/cjs/lib/Utils/reporting-utils.d.ts +12 -0
  177. package/cjs/lib/Utils/reporting-utils.js +282 -0
  178. package/cjs/lib/Utils/rich-message-utils.d.ts +48 -0
  179. package/cjs/lib/Utils/rich-message-utils.js +381 -0
  180. package/cjs/lib/Utils/signal.d.ts +82 -0
  181. package/cjs/lib/Utils/signal.js +232 -0
  182. package/cjs/lib/Utils/stanza-ack.d.ts +16 -0
  183. package/cjs/lib/Utils/stanza-ack.js +53 -0
  184. package/cjs/lib/Utils/sync-action-utils.d.ts +2 -0
  185. package/cjs/lib/Utils/sync-action-utils.js +68 -0
  186. package/cjs/lib/Utils/tc-token-utils.d.ts +29 -0
  187. package/cjs/lib/Utils/tc-token-utils.js +182 -0
  188. package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  189. package/cjs/lib/Utils/use-multi-file-auth-state.js +135 -0
  190. package/cjs/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  191. package/cjs/lib/Utils/use-single-file-auth-state.js +115 -0
  192. package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  193. package/cjs/lib/Utils/use-sqlite-auth-state.js +140 -0
  194. package/cjs/lib/Utils/validate-connection.d.ts +44 -0
  195. package/cjs/lib/Utils/validate-connection.js +229 -0
  196. package/cjs/lib/WABinary/constants.d.ts +61 -0
  197. package/cjs/lib/WABinary/constants.js +1992 -0
  198. package/cjs/lib/WABinary/decode.d.ts +9 -0
  199. package/cjs/lib/WABinary/decode.js +292 -0
  200. package/cjs/lib/WABinary/encode.d.ts +2 -0
  201. package/cjs/lib/WABinary/encode.js +240 -0
  202. package/cjs/lib/WABinary/generic-utils.d.ts +79 -0
  203. package/cjs/lib/WABinary/generic-utils.js +252 -0
  204. package/cjs/lib/WABinary/index.d.ts +5 -0
  205. package/cjs/lib/WABinary/index.js +29 -0
  206. package/cjs/lib/WABinary/jid-utils.d.ts +28 -0
  207. package/cjs/lib/WABinary/jid-utils.js +151 -0
  208. package/cjs/lib/WABinary/types.d.ts +1 -0
  209. package/cjs/lib/WABinary/types.js +23 -0
  210. package/cjs/lib/WACrypto/appstate-keys.js +39 -0
  211. package/cjs/lib/WACrypto/curves/constants.js +37 -0
  212. package/cjs/lib/WACrypto/hkdf.js +38 -0
  213. package/cjs/lib/WACrypto/index.js +51 -0
  214. package/cjs/lib/WACrypto/lthash.js +59 -0
  215. package/cjs/lib/WACrypto/math/constants.js +53 -0
  216. package/cjs/lib/WACrypto/math/edwards.js +206 -0
  217. package/cjs/lib/WACrypto/math/fe.js +449 -0
  218. package/cjs/lib/WACrypto/math/le.js +44 -0
  219. package/cjs/lib/WACrypto/math/mod.js +36 -0
  220. package/cjs/lib/WACrypto/util/bytes.js +348 -0
  221. package/cjs/lib/WACrypto/x25519.js +157 -0
  222. package/cjs/lib/WACrypto/xeddsa.js +134 -0
  223. package/cjs/lib/WAM/BinaryInfo.d.ts +7 -0
  224. package/cjs/lib/WAM/BinaryInfo.js +35 -0
  225. package/cjs/lib/WAM/constants.d.ts +34926 -0
  226. package/cjs/lib/WAM/constants.js +22890 -0
  227. package/cjs/lib/WAM/encode.d.ts +1 -0
  228. package/cjs/lib/WAM/encode.js +162 -0
  229. package/cjs/lib/WAM/index.d.ts +3 -0
  230. package/cjs/lib/WAM/index.js +25 -0
  231. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  232. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +77 -0
  233. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  234. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +76 -0
  235. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  236. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +52 -0
  237. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  238. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +61 -0
  239. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  240. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +50 -0
  241. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  242. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
  243. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  244. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +53 -0
  245. package/cjs/lib/WAUSync/Protocols/index.d.ts +5 -0
  246. package/cjs/lib/WAUSync/Protocols/index.js +29 -0
  247. package/cjs/lib/WAUSync/USyncQuery.d.ts +20 -0
  248. package/cjs/lib/WAUSync/USyncQuery.js +113 -0
  249. package/cjs/lib/WAUSync/USyncUser.d.ts +16 -0
  250. package/cjs/lib/WAUSync/USyncUser.js +56 -0
  251. package/cjs/lib/WAUSync/index.d.ts +3 -0
  252. package/cjs/lib/WAUSync/index.js +25 -0
  253. package/cjs/lib/index.d.ts +11 -0
  254. package/cjs/lib/index.js +56 -0
  255. package/cjs/package.json +3 -0
  256. package/engine-requirements.js +12 -0
  257. package/lib/Addon/http-error.d.ts +18 -0
  258. package/lib/Addon/http-error.js +40 -0
  259. package/lib/Addon/index.d.ts +3 -0
  260. package/lib/Addon/index.js +4 -0
  261. package/lib/Addon/keyed-db.d.ts +14 -0
  262. package/lib/Addon/keyed-db.js +241 -0
  263. package/lib/Addon/link-preview.d.ts +15 -0
  264. package/lib/Addon/link-preview.js +79 -0
  265. package/lib/Defaults/index.d.ts +184 -0
  266. package/lib/Defaults/index.js +181 -0
  267. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  268. package/lib/Signal/Group/ciphertext-message.js +11 -0
  269. package/lib/Signal/Group/group-cipher.d.ts +10 -0
  270. package/lib/Signal/Group/group-cipher.js +81 -0
  271. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  272. package/lib/Signal/Group/group-session-builder.js +29 -0
  273. package/lib/Signal/Group/index.d.ts +11 -0
  274. package/lib/Signal/Group/index.js +11 -0
  275. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  276. package/lib/Signal/Group/keyhelper.js +17 -0
  277. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  278. package/lib/Signal/Group/sender-chain-key.js +25 -0
  279. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  280. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  281. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  282. package/lib/Signal/Group/sender-key-message.js +65 -0
  283. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  284. package/lib/Signal/Group/sender-key-name.js +47 -0
  285. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  286. package/lib/Signal/Group/sender-key-record.js +40 -0
  287. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  288. package/lib/Signal/Group/sender-key-state.js +83 -0
  289. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  290. package/lib/Signal/Group/sender-message-key.js +25 -0
  291. package/lib/Signal/libsignal.d.ts +54 -0
  292. package/lib/Signal/libsignal.js +426 -0
  293. package/lib/Signal/lid-mapping.d.ts +20 -0
  294. package/lib/Signal/lid-mapping.js +274 -0
  295. package/lib/Socket/Client/index.d.ts +2 -0
  296. package/lib/Socket/Client/index.js +2 -0
  297. package/lib/Socket/Client/types.d.ts +5 -0
  298. package/lib/Socket/Client/types.js +10 -0
  299. package/lib/Socket/Client/websocket.d.ts +12 -0
  300. package/lib/Socket/Client/websocket.js +119 -0
  301. package/lib/Socket/business.d.ts +387 -0
  302. package/lib/Socket/business.js +379 -0
  303. package/lib/Socket/chats.d.ts +144 -0
  304. package/lib/Socket/chats.js +1216 -0
  305. package/lib/Socket/communities.d.ts +554 -0
  306. package/lib/Socket/communities.js +431 -0
  307. package/lib/Socket/groups.d.ts +286 -0
  308. package/lib/Socket/groups.js +347 -0
  309. package/lib/Socket/index.d.ts +522 -0
  310. package/lib/Socket/index.js +11 -0
  311. package/lib/Socket/messages-recv.d.ts +326 -0
  312. package/lib/Socket/messages-recv.js +1822 -0
  313. package/lib/Socket/messages-send.d.ts +321 -0
  314. package/lib/Socket/messages-send.js +1378 -0
  315. package/lib/Socket/mex.d.ts +1 -0
  316. package/lib/Socket/mex.js +41 -0
  317. package/lib/Socket/newsletter.d.ts +283 -0
  318. package/lib/Socket/newsletter.js +225 -0
  319. package/lib/Socket/socket.d.ts +61 -0
  320. package/lib/Socket/socket.js +992 -0
  321. package/lib/Store/index.d.ts +3 -0
  322. package/lib/Store/index.js +3 -0
  323. package/lib/Store/make-in-memory-store.d.ts +63 -0
  324. package/lib/Store/make-in-memory-store.js +419 -0
  325. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  326. package/lib/Store/make-ordered-dictionary.js +78 -0
  327. package/lib/Store/object-repository.d.ts +10 -0
  328. package/lib/Store/object-repository.js +23 -0
  329. package/lib/Transport/crypto.d.ts +6 -0
  330. package/lib/Transport/crypto.js +61 -0
  331. package/lib/Transport/curve.d.ts +8 -0
  332. package/lib/Transport/curve.js +66 -0
  333. package/lib/Transport/index.d.ts +16 -0
  334. package/lib/Transport/index.js +9 -0
  335. package/lib/Transport/internals.d.ts +57 -0
  336. package/lib/Transport/internals.js +155 -0
  337. package/lib/Transport/session-builder.d.ts +40 -0
  338. package/lib/Transport/session-builder.js +143 -0
  339. package/lib/Transport/session-cipher.d.ts +26 -0
  340. package/lib/Transport/session-cipher.js +301 -0
  341. package/lib/Transport/session-record.d.ts +55 -0
  342. package/lib/Transport/session-record.js +272 -0
  343. package/lib/Types/Auth.d.ts +1 -0
  344. package/lib/Types/Auth.js +1 -0
  345. package/lib/Types/Bussines.d.ts +1 -0
  346. package/lib/Types/Bussines.js +1 -0
  347. package/lib/Types/Call.d.ts +1 -0
  348. package/lib/Types/Call.js +1 -0
  349. package/lib/Types/Chat.d.ts +1 -0
  350. package/lib/Types/Chat.js +7 -0
  351. package/lib/Types/Contact.d.ts +1 -0
  352. package/lib/Types/Contact.js +1 -0
  353. package/lib/Types/Events.d.ts +1 -0
  354. package/lib/Types/Events.js +1 -0
  355. package/lib/Types/GroupMetadata.d.ts +1 -0
  356. package/lib/Types/GroupMetadata.js +1 -0
  357. package/lib/Types/Label.d.ts +2 -0
  358. package/lib/Types/Label.js +24 -0
  359. package/lib/Types/LabelAssociation.d.ts +2 -0
  360. package/lib/Types/LabelAssociation.js +6 -0
  361. package/lib/Types/Message.d.ts +11 -0
  362. package/lib/Types/Message.js +17 -0
  363. package/lib/Types/Mex.d.ts +2 -0
  364. package/lib/Types/Mex.js +38 -0
  365. package/lib/Types/Product.d.ts +1 -0
  366. package/lib/Types/Product.js +1 -0
  367. package/lib/Types/RichType.d.ts +2 -0
  368. package/lib/Types/RichType.js +22 -0
  369. package/lib/Types/Signal.d.ts +1 -0
  370. package/lib/Types/Signal.js +1 -0
  371. package/lib/Types/Socket.d.ts +1 -0
  372. package/lib/Types/Socket.js +1 -0
  373. package/lib/Types/State.d.ts +5 -0
  374. package/lib/Types/State.js +54 -0
  375. package/lib/Types/USync.d.ts +1 -0
  376. package/lib/Types/USync.js +1 -0
  377. package/lib/Types/index.d.ts +13 -0
  378. package/lib/Types/index.js +25 -0
  379. package/lib/Utils/auth-utils.d.ts +58 -0
  380. package/lib/Utils/auth-utils.js +316 -0
  381. package/lib/Utils/browser-utils.d.ts +9 -0
  382. package/lib/Utils/browser-utils.js +28 -0
  383. package/lib/Utils/business.d.ts +49 -0
  384. package/lib/Utils/business.js +230 -0
  385. package/lib/Utils/chat-utils.d.ts +408 -0
  386. package/lib/Utils/chat-utils.js +871 -0
  387. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  388. package/lib/Utils/companion-reg-client-utils.js +39 -0
  389. package/lib/Utils/crypto.d.ts +39 -0
  390. package/lib/Utils/crypto.js +117 -0
  391. package/lib/Utils/decode-wa-message.d.ts +83 -0
  392. package/lib/Utils/decode-wa-message.js +316 -0
  393. package/lib/Utils/event-buffer.d.ts +12 -0
  394. package/lib/Utils/event-buffer.js +621 -0
  395. package/lib/Utils/generics.d.ts +63 -0
  396. package/lib/Utils/generics.js +394 -0
  397. package/lib/Utils/history.d.ts +75 -0
  398. package/lib/Utils/history.js +133 -0
  399. package/lib/Utils/identity-change-handler.d.ts +13 -0
  400. package/lib/Utils/identity-change-handler.js +48 -0
  401. package/lib/Utils/index.d.ts +24 -0
  402. package/lib/Utils/index.js +24 -0
  403. package/lib/Utils/link-preview.d.ts +13 -0
  404. package/lib/Utils/link-preview.js +73 -0
  405. package/lib/Utils/logger.d.ts +12 -0
  406. package/lib/Utils/logger.js +12 -0
  407. package/lib/Utils/lt-hash.d.ts +6 -0
  408. package/lib/Utils/lt-hash.js +7 -0
  409. package/lib/Utils/make-mutex.d.ts +6 -0
  410. package/lib/Utils/make-mutex.js +32 -0
  411. package/lib/Utils/message-retry-manager.d.ts +79 -0
  412. package/lib/Utils/message-retry-manager.js +259 -0
  413. package/lib/Utils/messages-media.d.ts +134 -0
  414. package/lib/Utils/messages-media.js +802 -0
  415. package/lib/Utils/messages.d.ts +47 -0
  416. package/lib/Utils/messages.js +1911 -0
  417. package/lib/Utils/noise-handler.d.ts +20 -0
  418. package/lib/Utils/noise-handler.js +200 -0
  419. package/lib/Utils/offline-node-processor.d.ts +10 -0
  420. package/lib/Utils/offline-node-processor.js +40 -0
  421. package/lib/Utils/pre-key-manager.d.ts +25 -0
  422. package/lib/Utils/pre-key-manager.js +105 -0
  423. package/lib/Utils/process-message.d.ts +83 -0
  424. package/lib/Utils/process-message.js +748 -0
  425. package/lib/Utils/reporting-utils.d.ts +12 -0
  426. package/lib/Utils/reporting-utils.js +257 -0
  427. package/lib/Utils/rich-message-utils.d.ts +48 -0
  428. package/lib/Utils/rich-message-utils.js +369 -0
  429. package/lib/Utils/signal.d.ts +82 -0
  430. package/lib/Utils/signal.js +200 -0
  431. package/lib/Utils/stanza-ack.d.ts +16 -0
  432. package/lib/Utils/stanza-ack.js +37 -0
  433. package/lib/Utils/sync-action-utils.d.ts +2 -0
  434. package/lib/Utils/sync-action-utils.js +48 -0
  435. package/lib/Utils/tc-token-utils.d.ts +29 -0
  436. package/lib/Utils/tc-token-utils.js +163 -0
  437. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  438. package/lib/Utils/use-multi-file-auth-state.js +116 -0
  439. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  440. package/lib/Utils/use-single-file-auth-state.js +94 -0
  441. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  442. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  443. package/lib/Utils/validate-connection.d.ts +44 -0
  444. package/lib/Utils/validate-connection.js +210 -0
  445. package/lib/WABinary/constants.d.ts +61 -0
  446. package/lib/WABinary/constants.js +1466 -0
  447. package/lib/WABinary/decode.d.ts +9 -0
  448. package/lib/WABinary/decode.js +261 -0
  449. package/lib/WABinary/encode.d.ts +2 -0
  450. package/lib/WABinary/encode.js +219 -0
  451. package/lib/WABinary/generic-utils.d.ts +79 -0
  452. package/lib/WABinary/generic-utils.js +228 -0
  453. package/lib/WABinary/index.d.ts +5 -0
  454. package/lib/WABinary/index.js +5 -0
  455. package/lib/WABinary/jid-utils.d.ts +28 -0
  456. package/lib/WABinary/jid-utils.js +95 -0
  457. package/lib/WABinary/types.d.ts +1 -0
  458. package/lib/WABinary/types.js +1 -0
  459. package/lib/WACrypto/appstate-keys.js +26 -0
  460. package/lib/WACrypto/curves/constants.js +12 -0
  461. package/lib/WACrypto/hkdf.js +27 -0
  462. package/lib/WACrypto/index.js +20 -0
  463. package/lib/WACrypto/lthash.js +54 -0
  464. package/lib/WACrypto/math/constants.js +24 -0
  465. package/lib/WACrypto/math/edwards.js +194 -0
  466. package/lib/WACrypto/math/fe.js +698 -0
  467. package/lib/WACrypto/math/le.js +23 -0
  468. package/lib/WACrypto/math/mod.js +15 -0
  469. package/lib/WACrypto/util/bytes.js +339 -0
  470. package/lib/WACrypto/x25519.js +145 -0
  471. package/lib/WACrypto/xeddsa.js +92 -0
  472. package/lib/WAM/BinaryInfo.d.ts +7 -0
  473. package/lib/WAM/BinaryInfo.js +9 -0
  474. package/lib/WAM/constants.d.ts +34926 -0
  475. package/lib/WAM/constants.js +22852 -0
  476. package/lib/WAM/encode.d.ts +1 -0
  477. package/lib/WAM/encode.js +149 -0
  478. package/lib/WAM/index.d.ts +3 -0
  479. package/lib/WAM/index.js +3 -0
  480. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  481. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  482. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  483. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  484. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  485. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  486. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  487. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  488. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  489. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  490. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  491. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  492. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  493. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  494. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  495. package/lib/WAUSync/Protocols/index.js +5 -0
  496. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  497. package/lib/WAUSync/USyncQuery.js +97 -0
  498. package/lib/WAUSync/USyncUser.d.ts +16 -0
  499. package/lib/WAUSync/USyncUser.js +30 -0
  500. package/lib/WAUSync/index.d.ts +3 -0
  501. package/lib/WAUSync/index.js +3 -0
  502. package/lib/index.d.ts +11 -0
  503. package/lib/index.js +11 -0
  504. package/package.json +79 -5
@@ -0,0 +1,106 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var sender_key_state_exports = {};
19
+ __export(sender_key_state_exports, {
20
+ SenderKeyState: () => SenderKeyState
21
+ });
22
+ module.exports = __toCommonJS(sender_key_state_exports);
23
+ var import_sender_chain_key = require("./sender-chain-key.js");
24
+ var import_sender_message_key = require("./sender-message-key.js");
25
+ class SenderKeyState {
26
+ constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
27
+ this.MAX_MESSAGE_KEYS = 2e3;
28
+ if (senderKeyStateStructure) {
29
+ this.senderKeyStateStructure = {
30
+ ...senderKeyStateStructure,
31
+ senderMessageKeys: Array.isArray(senderKeyStateStructure.senderMessageKeys) ? senderKeyStateStructure.senderMessageKeys : []
32
+ };
33
+ } else {
34
+ if (signatureKeyPair) {
35
+ signatureKeyPublic = signatureKeyPair.public;
36
+ signatureKeyPrivate = signatureKeyPair.private;
37
+ }
38
+ this.senderKeyStateStructure = {
39
+ senderKeyId: id || 0,
40
+ senderChainKey: {
41
+ iteration: iteration || 0,
42
+ seed: Buffer.from(chainKey || [])
43
+ },
44
+ senderSigningKey: {
45
+ public: Buffer.from(signatureKeyPublic || []),
46
+ private: Buffer.from(signatureKeyPrivate || [])
47
+ },
48
+ senderMessageKeys: []
49
+ };
50
+ }
51
+ }
52
+ getKeyId() {
53
+ return this.senderKeyStateStructure.senderKeyId;
54
+ }
55
+ getSenderChainKey() {
56
+ return new import_sender_chain_key.SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
57
+ }
58
+ setSenderChainKey(chainKey) {
59
+ this.senderKeyStateStructure.senderChainKey = {
60
+ iteration: chainKey.getIteration(),
61
+ seed: chainKey.getSeed()
62
+ };
63
+ }
64
+ getSigningKeyPublic() {
65
+ const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public);
66
+ if (publicKey.length === 32) {
67
+ const fixed = Buffer.alloc(33);
68
+ fixed[0] = 5;
69
+ publicKey.copy(fixed, 1);
70
+ return fixed;
71
+ }
72
+ return publicKey;
73
+ }
74
+ getSigningKeyPrivate() {
75
+ const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
76
+ return Buffer.from(privateKey || []);
77
+ }
78
+ hasSenderMessageKey(iteration) {
79
+ return this.senderKeyStateStructure.senderMessageKeys.some((key) => key.iteration === iteration);
80
+ }
81
+ addSenderMessageKey(senderMessageKey) {
82
+ this.senderKeyStateStructure.senderMessageKeys.push({
83
+ iteration: senderMessageKey.getIteration(),
84
+ seed: senderMessageKey.getSeed()
85
+ });
86
+ if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
87
+ this.senderKeyStateStructure.senderMessageKeys.shift();
88
+ }
89
+ }
90
+ removeSenderMessageKey(iteration) {
91
+ const index = this.senderKeyStateStructure.senderMessageKeys.findIndex((key) => key.iteration === iteration);
92
+ if (index !== -1) {
93
+ const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
94
+ this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
95
+ return new import_sender_message_key.SenderMessageKey(messageKey.iteration, messageKey.seed);
96
+ }
97
+ return null;
98
+ }
99
+ getStructure() {
100
+ return this.senderKeyStateStructure;
101
+ }
102
+ }
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ SenderKeyState
106
+ });
@@ -0,0 +1,11 @@
1
+ export class SenderMessageKey {
2
+ constructor(iteration: any, seed: any);
3
+ iv: any;
4
+ cipherKey: any;
5
+ iteration: any;
6
+ seed: any;
7
+ getIteration(): any;
8
+ getIv(): any;
9
+ getCipherKey(): any;
10
+ getSeed(): any;
11
+ }
@@ -0,0 +1,51 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var sender_message_key_exports = {};
19
+ __export(sender_message_key_exports, {
20
+ SenderMessageKey: () => SenderMessageKey
21
+ });
22
+ module.exports = __toCommonJS(sender_message_key_exports);
23
+ var import_Transport = require("../../Transport/index.js");
24
+ class SenderMessageKey {
25
+ constructor(iteration, seed) {
26
+ const derivative = import_Transport.crypto.deriveSecrets(seed, Buffer.alloc(32), Buffer.from("WhisperGroup"));
27
+ const keys = new Uint8Array(32);
28
+ keys.set(new Uint8Array(derivative[0].slice(16)));
29
+ keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
30
+ this.iv = Buffer.from(derivative[0].slice(0, 16));
31
+ this.cipherKey = Buffer.from(keys.buffer);
32
+ this.iteration = iteration;
33
+ this.seed = seed;
34
+ }
35
+ getIteration() {
36
+ return this.iteration;
37
+ }
38
+ getIv() {
39
+ return this.iv;
40
+ }
41
+ getCipherKey() {
42
+ return this.cipherKey;
43
+ }
44
+ getSeed() {
45
+ return this.seed;
46
+ }
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ SenderMessageKey
51
+ });
@@ -0,0 +1,54 @@
1
+ export function makeLibSignalRepository(auth: any, logger: any, pnToLIDFunc: any): {
2
+ decryptGroupMessage({ group, authorJid, msg }: {
3
+ group: any;
4
+ authorJid: any;
5
+ msg: any;
6
+ }): any;
7
+ processSenderKeyDistributionMessage({ item, authorJid }: {
8
+ item: any;
9
+ authorJid: any;
10
+ }): Promise<any>;
11
+ decryptMessage({ jid, type, ciphertext }: {
12
+ jid: any;
13
+ type: any;
14
+ ciphertext: any;
15
+ }): Promise<any>;
16
+ encryptMessage({ jid, data }: {
17
+ jid: any;
18
+ data: any;
19
+ }): Promise<any>;
20
+ encryptGroupMessage({ group, meId, data }: {
21
+ group: any;
22
+ meId: any;
23
+ data: any;
24
+ }): Promise<any>;
25
+ getSenderKeyDistributionMessage({ group, meId }: {
26
+ group: any;
27
+ meId: any;
28
+ }): Promise<any>;
29
+ hasSenderKey({ group, meId }: {
30
+ group: any;
31
+ meId: any;
32
+ }): Promise<boolean>;
33
+ getSessionInfo(jid: any): Promise<{
34
+ baseKey: Uint8Array<any>;
35
+ registrationId: number;
36
+ } | null>;
37
+ injectE2ESession({ jid, session }: {
38
+ jid: any;
39
+ session: any;
40
+ }): Promise<any>;
41
+ jidToSignalProtocolAddress(jid: any): string;
42
+ lidMapping: LIDMappingStore;
43
+ validateSession(jid: any): Promise<{
44
+ exists: boolean;
45
+ reason: string;
46
+ } | {
47
+ exists: boolean;
48
+ reason?: undefined;
49
+ }>;
50
+ deleteSession(jids: any): Promise<any>;
51
+ close(): void;
52
+ migrateSession(fromJid: any, toJid: any): Promise<any>;
53
+ };
54
+ import { LIDMappingStore } from './lid-mapping.js';
@@ -0,0 +1,421 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var libsignal_exports = {};
19
+ __export(libsignal_exports, {
20
+ makeLibSignalRepository: () => makeLibSignalRepository
21
+ });
22
+ module.exports = __toCommonJS(libsignal_exports);
23
+ var import_WAProto = require("../../WAProto/index.js");
24
+ var import_Addon = require("../Addon/index.js");
25
+ var import_Transport = require("../Transport/index.js");
26
+ var import_Utils = require("../Utils/index.js");
27
+ var import_WABinary = require("../WABinary/index.js");
28
+ var import_sender_key_name = require("./Group/sender-key-name.js");
29
+ var import_sender_key_record = require("./Group/sender-key-record.js");
30
+ var import_Group = require("./Group/index.js");
31
+ var import_lid_mapping = require("./lid-mapping.js");
32
+ function extractIdentityFromPkmsg(ciphertext) {
33
+ try {
34
+ if (!ciphertext || ciphertext.length < 2) {
35
+ return void 0;
36
+ }
37
+ const version = ciphertext[0];
38
+ if ((version & 15) !== 3) {
39
+ return void 0;
40
+ }
41
+ const preKeyProto = import_WAProto.proto.PreKeySignalMessage.decode(ciphertext.slice(1));
42
+ if (preKeyProto.identityKey?.length === 33) {
43
+ return new Uint8Array(preKeyProto.identityKey);
44
+ }
45
+ return void 0;
46
+ } catch {
47
+ return void 0;
48
+ }
49
+ }
50
+ function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
51
+ const lidMapping = new import_lid_mapping.LIDMappingStore(auth.keys, logger, pnToLIDFunc);
52
+ const storage = signalStorage(auth, lidMapping);
53
+ const parsedKeys = auth.keys;
54
+ const migratedSessionCache = (0, import_Addon.createCache)({
55
+ ttl: 3 * 24 * 60 * 60
56
+ // 3 days
57
+ });
58
+ const ensureSenderKeyAndCreateSkdm = async (group, meId) => {
59
+ const senderName = jidToSignalSenderKeyName(group, meId);
60
+ const senderNameStr = senderName.toString();
61
+ const { [senderNameStr]: senderKey } = await auth.keys.get("sender-key", [senderNameStr]);
62
+ if (!senderKey) {
63
+ await storage.storeSenderKey(senderName, new import_sender_key_record.SenderKeyRecord());
64
+ }
65
+ const skdm = await new import_Group.GroupSessionBuilder(storage).create(senderName);
66
+ return { senderName, skdm };
67
+ };
68
+ const repository = {
69
+ decryptGroupMessage({ group, authorJid, msg }) {
70
+ const senderName = jidToSignalSenderKeyName(group, authorJid);
71
+ const cipher = new import_Group.GroupCipher(storage, senderName);
72
+ return parsedKeys.transaction(async () => {
73
+ return cipher.decrypt(msg);
74
+ }, group);
75
+ },
76
+ async processSenderKeyDistributionMessage({ item, authorJid }) {
77
+ const builder = new import_Group.GroupSessionBuilder(storage);
78
+ if (!item.groupId) {
79
+ throw new Error("Group ID is required for sender key distribution message");
80
+ }
81
+ const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
82
+ const senderMsg = new import_Group.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
83
+ const senderNameStr = senderName.toString();
84
+ const { [senderNameStr]: senderKey } = await auth.keys.get("sender-key", [senderNameStr]);
85
+ if (!senderKey) {
86
+ await storage.storeSenderKey(senderName, new import_sender_key_record.SenderKeyRecord());
87
+ }
88
+ return parsedKeys.transaction(async () => {
89
+ const { [senderNameStr]: senderKey2 } = await auth.keys.get("sender-key", [senderNameStr]);
90
+ if (!senderKey2) {
91
+ await storage.storeSenderKey(senderName, new import_sender_key_record.SenderKeyRecord());
92
+ }
93
+ await builder.process(senderName, senderMsg);
94
+ }, item.groupId);
95
+ },
96
+ async decryptMessage({ jid, type, ciphertext }) {
97
+ const addr = jidToSignalProtocolAddress(jid);
98
+ const session = new import_Transport.SessionCipher(storage, addr);
99
+ if (type === "pkmsg") {
100
+ const identityKey = extractIdentityFromPkmsg(ciphertext);
101
+ if (identityKey) {
102
+ const addrStr = addr.toString();
103
+ const identityChanged = await storage.saveIdentity(addrStr, identityKey);
104
+ if (identityChanged) {
105
+ logger.info({ jid, addr: addrStr }, "identity key changed or new contact, session will be re-established");
106
+ }
107
+ }
108
+ }
109
+ async function doDecrypt() {
110
+ let result;
111
+ switch (type) {
112
+ case "pkmsg":
113
+ result = await session.decryptPreKeyWhisperMessage(ciphertext);
114
+ break;
115
+ case "msg":
116
+ result = await session.decryptWhisperMessage(ciphertext);
117
+ break;
118
+ }
119
+ return result;
120
+ }
121
+ return parsedKeys.transaction(async () => {
122
+ return await doDecrypt();
123
+ }, jid);
124
+ },
125
+ async encryptMessage({ jid, data }) {
126
+ const addr = jidToSignalProtocolAddress(jid);
127
+ const cipher = new import_Transport.SessionCipher(storage, addr);
128
+ return parsedKeys.transaction(async () => {
129
+ const { type: sigType, body } = await cipher.encrypt(data);
130
+ const type = sigType === 3 ? "pkmsg" : "msg";
131
+ return { type, ciphertext: Buffer.from(body, "binary") };
132
+ }, jid);
133
+ },
134
+ async encryptGroupMessage({ group, meId, data }) {
135
+ return parsedKeys.transaction(async () => {
136
+ const { senderName, skdm } = await ensureSenderKeyAndCreateSkdm(group, meId);
137
+ const ciphertext = await new import_Group.GroupCipher(storage, senderName).encrypt(data);
138
+ return { ciphertext, senderKeyDistributionMessage: skdm.serialize() };
139
+ }, group);
140
+ },
141
+ async getSenderKeyDistributionMessage({ group, meId }) {
142
+ return parsedKeys.transaction(async () => {
143
+ const { skdm } = await ensureSenderKeyAndCreateSkdm(group, meId);
144
+ return skdm.serialize();
145
+ }, group);
146
+ },
147
+ async hasSenderKey({ group, meId }) {
148
+ const senderName = jidToSignalSenderKeyName(group, meId).toString();
149
+ const { [senderName]: key } = await auth.keys.get("sender-key", [senderName]);
150
+ return !!key;
151
+ },
152
+ async getSessionInfo(jid) {
153
+ const addr = jidToSignalProtocolAddress(jid).toString();
154
+ const session = await storage.loadSession(addr);
155
+ if (!session) {
156
+ return null;
157
+ }
158
+ const open = session.getOpenSession?.();
159
+ const baseKey = open?.indexInfo?.baseKey;
160
+ const registrationId = open?.registrationId;
161
+ if (!baseKey || typeof registrationId !== "number") {
162
+ return null;
163
+ }
164
+ return { baseKey: new Uint8Array(baseKey), registrationId };
165
+ },
166
+ async injectE2ESession({ jid, session }) {
167
+ logger.trace({ jid }, "injecting E2EE session");
168
+ const cipher = new import_Transport.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
169
+ return parsedKeys.transaction(async () => {
170
+ await cipher.initOutgoing(session);
171
+ }, jid);
172
+ },
173
+ jidToSignalProtocolAddress(jid) {
174
+ return jidToSignalProtocolAddress(jid).toString();
175
+ },
176
+ // Optimized direct access to LID mapping store
177
+ lidMapping,
178
+ async validateSession(jid) {
179
+ try {
180
+ const addr = jidToSignalProtocolAddress(jid);
181
+ const session = await storage.loadSession(addr.toString());
182
+ if (!session) {
183
+ return { exists: false, reason: "no session" };
184
+ }
185
+ if (!session.haveOpenSession()) {
186
+ return { exists: false, reason: "no open session" };
187
+ }
188
+ return { exists: true };
189
+ } catch (error) {
190
+ return { exists: false, reason: "validation error" };
191
+ }
192
+ },
193
+ async deleteSession(jids) {
194
+ if (!jids.length)
195
+ return;
196
+ const sessionUpdates = {};
197
+ jids.forEach((jid) => {
198
+ const addr = jidToSignalProtocolAddress(jid);
199
+ sessionUpdates[addr.toString()] = null;
200
+ });
201
+ return parsedKeys.transaction(async () => {
202
+ await auth.keys.set({ session: sessionUpdates });
203
+ }, `delete-${jids.length}-sessions`);
204
+ },
205
+ close() {
206
+ migratedSessionCache.flushAll();
207
+ lidMapping.close();
208
+ },
209
+ async migrateSession(fromJid, toJid) {
210
+ if (!fromJid || !(0, import_WABinary.isLidUser)(toJid) && !(0, import_WABinary.isHostedLidUser)(toJid))
211
+ return { migrated: 0, skipped: 0, total: 0 };
212
+ if (!(0, import_WABinary.isPnUser)(fromJid) && !(0, import_WABinary.isHostedPnUser)(fromJid)) {
213
+ return { migrated: 0, skipped: 0, total: 1 };
214
+ }
215
+ const { user } = (0, import_WABinary.jidDecode)(fromJid);
216
+ logger.debug({ fromJid }, "bulk device migration - loading all user devices");
217
+ const { [user]: userDevices } = await parsedKeys.get("device-list", [user]);
218
+ if (!userDevices) {
219
+ return { migrated: 0, skipped: 0, total: 0 };
220
+ }
221
+ const { device: fromDevice } = (0, import_WABinary.jidDecode)(fromJid);
222
+ const fromDeviceStr = fromDevice?.toString() || "0";
223
+ if (!userDevices.includes(fromDeviceStr)) {
224
+ userDevices.push(fromDeviceStr);
225
+ }
226
+ const uncachedDevices = userDevices.filter((device) => {
227
+ const deviceKey = `${user}.${device}`;
228
+ return !migratedSessionCache.has(deviceKey);
229
+ });
230
+ const deviceSessionKeys = uncachedDevices.map((device) => `${user}.${device}`);
231
+ const existingSessions = await parsedKeys.get("session", deviceSessionKeys);
232
+ const deviceJids = [];
233
+ for (const [sessionKey, sessionData] of Object.entries(existingSessions)) {
234
+ if (sessionData) {
235
+ const deviceStr = sessionKey.split(".")[1];
236
+ if (!deviceStr)
237
+ continue;
238
+ const deviceNum = parseInt(deviceStr);
239
+ let jid = deviceNum === 0 ? `${user}@s.whatsapp.net` : `${user}:${deviceNum}@s.whatsapp.net`;
240
+ if (deviceNum === 99) {
241
+ jid = `${user}:99@hosted`;
242
+ }
243
+ deviceJids.push(jid);
244
+ }
245
+ }
246
+ logger.debug({
247
+ fromJid,
248
+ totalDevices: userDevices.length,
249
+ devicesWithSessions: deviceJids.length,
250
+ devices: deviceJids
251
+ }, "bulk device migration complete - all user devices processed");
252
+ return parsedKeys.transaction(async () => {
253
+ const migrationOps = deviceJids.map((jid) => {
254
+ const lidWithDevice = (0, import_WABinary.transferDevice)(jid, toJid);
255
+ const fromDecoded = (0, import_WABinary.jidDecode)(jid);
256
+ const toDecoded = (0, import_WABinary.jidDecode)(lidWithDevice);
257
+ return {
258
+ fromJid: jid,
259
+ toJid: lidWithDevice,
260
+ pnUser: fromDecoded.user,
261
+ lidUser: toDecoded.user,
262
+ deviceId: fromDecoded.device || 0,
263
+ fromAddr: jidToSignalProtocolAddress(jid),
264
+ toAddr: jidToSignalProtocolAddress(lidWithDevice)
265
+ };
266
+ });
267
+ const totalOps = migrationOps.length;
268
+ let migratedCount = 0;
269
+ const pnAddrStrings = Array.from(new Set(migrationOps.map((op) => op.fromAddr.toString())));
270
+ const pnSessions = await parsedKeys.get("session", pnAddrStrings);
271
+ const sessionUpdates = {};
272
+ for (const op of migrationOps) {
273
+ const pnAddrStr = op.fromAddr.toString();
274
+ const lidAddrStr = op.toAddr.toString();
275
+ const pnSession = pnSessions[pnAddrStr];
276
+ if (pnSession) {
277
+ const fromSession = import_Transport.SessionRecord.deserialize(pnSession);
278
+ if (fromSession.haveOpenSession()) {
279
+ sessionUpdates[lidAddrStr] = fromSession.serialize();
280
+ sessionUpdates[pnAddrStr] = null;
281
+ migratedCount++;
282
+ }
283
+ }
284
+ }
285
+ if (Object.keys(sessionUpdates).length > 0) {
286
+ await parsedKeys.set({ session: sessionUpdates });
287
+ logger.debug({ migratedSessions: migratedCount }, "bulk session migration complete");
288
+ for (const op of migrationOps) {
289
+ if (sessionUpdates[op.toAddr.toString()]) {
290
+ const deviceKey = `${op.pnUser}.${op.deviceId}`;
291
+ migratedSessionCache.set(deviceKey, true);
292
+ }
293
+ }
294
+ }
295
+ const skippedCount = totalOps - migratedCount;
296
+ return { migrated: migratedCount, skipped: skippedCount, total: totalOps };
297
+ }, `migrate-${deviceJids.length}-sessions-${(0, import_WABinary.jidDecode)(toJid)?.user}`);
298
+ }
299
+ };
300
+ return repository;
301
+ }
302
+ const jidToSignalProtocolAddress = (jid) => {
303
+ const decoded = (0, import_WABinary.jidDecode)(jid);
304
+ const { user, device, server, domainType } = decoded;
305
+ if (!user) {
306
+ throw new Error(`JID decoded but user is empty: "${jid}" -> user: "${user}", server: "${server}", device: ${device}`);
307
+ }
308
+ const signalUser = domainType !== import_WABinary.WAJIDDomains.WHATSAPP ? `${user}_${domainType}` : user;
309
+ const finalDevice = device || 0;
310
+ if (device === 99 && decoded.server !== "hosted" && decoded.server !== "hosted.lid") {
311
+ throw new Error("Unexpected non-hosted device JID with device 99. This ID seems invalid. ID:" + jid);
312
+ }
313
+ return new import_Transport.ProtocolAddress(signalUser, finalDevice);
314
+ };
315
+ const jidToSignalSenderKeyName = (group, user) => {
316
+ return new import_sender_key_name.SenderKeyName(group, jidToSignalProtocolAddress(user));
317
+ };
318
+ function signalStorage({ creds, keys }, lidMapping) {
319
+ const resolveLIDSignalAddress = async (id) => {
320
+ if (id.includes(".")) {
321
+ const [deviceId, device] = id.split(".");
322
+ const [user, domainType_] = deviceId.split("_");
323
+ const domainType = parseInt(domainType_ || "0");
324
+ if (domainType === import_WABinary.WAJIDDomains.LID || domainType === import_WABinary.WAJIDDomains.HOSTED_LID)
325
+ return id;
326
+ const pnJid = `${user}${device !== "0" ? `:${device}` : ""}@${domainType === import_WABinary.WAJIDDomains.HOSTED ? "hosted" : "s.whatsapp.net"}`;
327
+ const lidForPN = await lidMapping.getLIDForPN(pnJid);
328
+ if (lidForPN) {
329
+ const lidAddr = jidToSignalProtocolAddress(lidForPN);
330
+ return lidAddr.toString();
331
+ }
332
+ }
333
+ return id;
334
+ };
335
+ return {
336
+ loadSession: async (id) => {
337
+ try {
338
+ const wireJid = await resolveLIDSignalAddress(id);
339
+ const { [wireJid]: sess } = await keys.get("session", [wireJid]);
340
+ if (sess) {
341
+ return import_Transport.SessionRecord.deserialize(sess);
342
+ }
343
+ } catch (e) {
344
+ return null;
345
+ }
346
+ return null;
347
+ },
348
+ storeSession: async (id, session) => {
349
+ const wireJid = await resolveLIDSignalAddress(id);
350
+ await keys.set({ session: { [wireJid]: session.serialize() } });
351
+ },
352
+ isTrustedIdentity: () => {
353
+ return true;
354
+ },
355
+ loadIdentityKey: async (id) => {
356
+ const wireJid = await resolveLIDSignalAddress(id);
357
+ const { [wireJid]: key } = await keys.get("identity-key", [wireJid]);
358
+ return key || void 0;
359
+ },
360
+ saveIdentity: async (id, identityKey) => {
361
+ const wireJid = await resolveLIDSignalAddress(id);
362
+ const { [wireJid]: existingKey } = await keys.get("identity-key", [wireJid]);
363
+ const keysMatch = existingKey?.length === identityKey.length && existingKey.every((byte, i) => byte === identityKey[i]);
364
+ if (existingKey && !keysMatch) {
365
+ await keys.set({
366
+ session: { [wireJid]: null },
367
+ "identity-key": { [wireJid]: identityKey }
368
+ });
369
+ return true;
370
+ }
371
+ if (!existingKey) {
372
+ await keys.set({ "identity-key": { [wireJid]: identityKey } });
373
+ return true;
374
+ }
375
+ return false;
376
+ },
377
+ loadPreKey: async (id) => {
378
+ const keyId = id.toString();
379
+ const { [keyId]: key } = await keys.get("pre-key", [keyId]);
380
+ if (key) {
381
+ return {
382
+ privKey: Buffer.from(key.private),
383
+ pubKey: Buffer.from(key.public)
384
+ };
385
+ }
386
+ },
387
+ removePreKey: (id) => keys.set({ "pre-key": { [id]: null } }),
388
+ loadSignedPreKey: () => {
389
+ const key = creds.signedPreKey;
390
+ return {
391
+ privKey: Buffer.from(key.keyPair.private),
392
+ pubKey: Buffer.from(key.keyPair.public)
393
+ };
394
+ },
395
+ loadSenderKey: async (senderKeyName) => {
396
+ const keyId = senderKeyName.toString();
397
+ const { [keyId]: key } = await keys.get("sender-key", [keyId]);
398
+ if (key) {
399
+ return import_sender_key_record.SenderKeyRecord.deserialize(key);
400
+ }
401
+ return new import_sender_key_record.SenderKeyRecord();
402
+ },
403
+ storeSenderKey: async (senderKeyName, key) => {
404
+ const keyId = senderKeyName.toString();
405
+ const serialized = JSON.stringify(key.serialize());
406
+ await keys.set({ "sender-key": { [keyId]: Buffer.from(serialized, "utf-8") } });
407
+ },
408
+ getOurRegistrationId: () => creds.registrationId,
409
+ getOurIdentity: () => {
410
+ const { signedIdentityKey } = creds;
411
+ return {
412
+ privKey: Buffer.from(signedIdentityKey.private),
413
+ pubKey: Buffer.from((0, import_Utils.generateSignalPubKey)(signedIdentityKey.public))
414
+ };
415
+ }
416
+ };
417
+ }
418
+ // Annotate the CommonJS export names for ESM import in node:
419
+ 0 && (module.exports = {
420
+ makeLibSignalRepository
421
+ });
@@ -0,0 +1,20 @@
1
+ export class LIDMappingStore {
2
+ constructor(keys: any, logger: any, pnToLIDFunc: any);
3
+ mappingCache: any;
4
+ inflightLIDLookups: Map<any, any>;
5
+ inflightPNLookups: Map<any, any>;
6
+ keys: any;
7
+ pnToLIDFunc: any;
8
+ logger: any;
9
+ storeLIDPNMappings(pairs: any): Promise<void>;
10
+ getLIDForPN(pn: any): Promise<any>;
11
+ getLIDsForPNs(pns: any): Promise<any>;
12
+ _getLIDsForPNsImpl(pns: any): Promise<any[] | null>;
13
+ getPNForLID(lid: any): Promise<any>;
14
+ getPNsForLIDs(lids: any): Promise<any>;
15
+ _getPNsForLIDsImpl(lids: any): Promise<any[] | null>;
16
+ /**
17
+ * Close the cache and release resources
18
+ */
19
+ close(): void;
20
+ }