@eduh_dev021/baileys 1.0.0 → 1.1.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 (526) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +1526 -178
  3. package/WAProto/index.d.ts +1 -1
  4. package/WAProto/index.js +1 -1
  5. package/cjs/WAProto/index.d.ts +1 -1
  6. package/cjs/WAProto/index.js +0 -0
  7. package/cjs/engine-requirements.js +0 -0
  8. package/cjs/lib/Addon/cache.js +179 -0
  9. package/cjs/lib/Addon/crc32.js +41 -0
  10. package/cjs/lib/Addon/file-type.js +217 -0
  11. package/cjs/lib/Addon/get-file.js +99 -0
  12. package/cjs/lib/Addon/http-error.d.ts +0 -0
  13. package/cjs/lib/Addon/http-error.js +0 -0
  14. package/cjs/lib/Addon/index.d.ts +93 -0
  15. package/cjs/lib/Addon/index.js +18 -10
  16. package/cjs/lib/Addon/keyed-db.d.ts +0 -0
  17. package/cjs/lib/Addon/keyed-db.js +0 -0
  18. package/cjs/lib/Addon/link-preview.d.ts +0 -0
  19. package/cjs/lib/Addon/link-preview.js +0 -0
  20. package/cjs/lib/Addon/media-info.js +98 -0
  21. package/cjs/lib/Addon/mutex.js +78 -0
  22. package/cjs/lib/Addon/qr.js +464 -0
  23. package/cjs/lib/Addon/queue.js +54 -0
  24. package/cjs/lib/Addon/waveform.js +130 -0
  25. package/cjs/lib/Addon/zip.js +136 -0
  26. package/cjs/lib/Defaults/index.d.ts +2 -2
  27. package/cjs/lib/Defaults/index.js +2 -2
  28. package/cjs/lib/Signal/Group/ciphertext-message.d.ts +0 -0
  29. package/cjs/lib/Signal/Group/ciphertext-message.js +0 -0
  30. package/cjs/lib/Signal/Group/group-cipher.d.ts +0 -0
  31. package/cjs/lib/Signal/Group/group-cipher.js +0 -0
  32. package/cjs/lib/Signal/Group/group-session-builder.d.ts +0 -0
  33. package/cjs/lib/Signal/Group/group-session-builder.js +0 -0
  34. package/cjs/lib/Signal/Group/index.d.ts +0 -0
  35. package/cjs/lib/Signal/Group/index.js +0 -0
  36. package/cjs/lib/Signal/Group/keyhelper.d.ts +0 -0
  37. package/cjs/lib/Signal/Group/keyhelper.js +0 -0
  38. package/cjs/lib/Signal/Group/sender-chain-key.d.ts +0 -0
  39. package/cjs/lib/Signal/Group/sender-chain-key.js +0 -0
  40. package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -0
  41. package/cjs/lib/Signal/Group/sender-key-distribution-message.js +0 -0
  42. package/cjs/lib/Signal/Group/sender-key-message.d.ts +0 -0
  43. package/cjs/lib/Signal/Group/sender-key-message.js +0 -0
  44. package/cjs/lib/Signal/Group/sender-key-name.d.ts +0 -0
  45. package/cjs/lib/Signal/Group/sender-key-name.js +0 -0
  46. package/cjs/lib/Signal/Group/sender-key-record.d.ts +0 -0
  47. package/cjs/lib/Signal/Group/sender-key-record.js +0 -0
  48. package/cjs/lib/Signal/Group/sender-key-state.d.ts +0 -0
  49. package/cjs/lib/Signal/Group/sender-key-state.js +0 -0
  50. package/cjs/lib/Signal/Group/sender-message-key.d.ts +0 -0
  51. package/cjs/lib/Signal/Group/sender-message-key.js +0 -0
  52. package/cjs/lib/Signal/libsignal.d.ts +0 -0
  53. package/cjs/lib/Signal/libsignal.js +0 -0
  54. package/cjs/lib/Signal/lid-mapping.d.ts +0 -0
  55. package/cjs/lib/Signal/lid-mapping.js +0 -0
  56. package/cjs/lib/Socket/Client/index.d.ts +0 -0
  57. package/cjs/lib/Socket/Client/index.js +0 -0
  58. package/cjs/lib/Socket/Client/types.d.ts +0 -0
  59. package/cjs/lib/Socket/Client/types.js +0 -0
  60. package/cjs/lib/Socket/Client/websocket.d.ts +0 -0
  61. package/cjs/lib/Socket/Client/websocket.js +0 -0
  62. package/cjs/lib/Socket/business.d.ts +0 -0
  63. package/cjs/lib/Socket/business.js +0 -0
  64. package/cjs/lib/Socket/chats.d.ts +0 -0
  65. package/cjs/lib/Socket/chats.js +0 -0
  66. package/cjs/lib/Socket/communities.d.ts +0 -0
  67. package/cjs/lib/Socket/communities.js +0 -0
  68. package/cjs/lib/Socket/groups.d.ts +0 -0
  69. package/cjs/lib/Socket/groups.js +0 -0
  70. package/cjs/lib/Socket/index.d.ts +0 -0
  71. package/cjs/lib/Socket/index.js +0 -0
  72. package/cjs/lib/Socket/messages-recv.d.ts +0 -0
  73. package/cjs/lib/Socket/messages-recv.js +0 -0
  74. package/cjs/lib/Socket/messages-send.d.ts +0 -0
  75. package/cjs/lib/Socket/messages-send.js +7 -7
  76. package/cjs/lib/Socket/mex.d.ts +0 -0
  77. package/cjs/lib/Socket/mex.js +0 -0
  78. package/cjs/lib/Socket/newsletter.d.ts +0 -0
  79. package/cjs/lib/Socket/newsletter.js +1 -1
  80. package/cjs/lib/Socket/socket.d.ts +0 -0
  81. package/cjs/lib/Socket/socket.js +0 -0
  82. package/cjs/lib/Store/index.d.ts +0 -0
  83. package/cjs/lib/Store/index.js +0 -0
  84. package/cjs/lib/Store/make-in-memory-store.d.ts +0 -0
  85. package/cjs/lib/Store/make-in-memory-store.js +0 -0
  86. package/cjs/lib/Store/make-ordered-dictionary.d.ts +0 -0
  87. package/cjs/lib/Store/make-ordered-dictionary.js +0 -0
  88. package/cjs/lib/Store/object-repository.d.ts +0 -0
  89. package/cjs/lib/Store/object-repository.js +0 -0
  90. package/cjs/lib/Transport/crypto.d.ts +0 -0
  91. package/cjs/lib/Transport/crypto.js +0 -0
  92. package/cjs/lib/Transport/curve.d.ts +0 -0
  93. package/cjs/lib/Transport/curve.js +0 -0
  94. package/cjs/lib/Transport/index.d.ts +0 -0
  95. package/cjs/lib/Transport/index.js +0 -0
  96. package/cjs/lib/Transport/internals.d.ts +0 -0
  97. package/cjs/lib/Transport/internals.js +0 -0
  98. package/cjs/lib/Transport/session-builder.d.ts +0 -0
  99. package/cjs/lib/Transport/session-builder.js +0 -0
  100. package/cjs/lib/Transport/session-cipher.d.ts +0 -0
  101. package/cjs/lib/Transport/session-cipher.js +0 -0
  102. package/cjs/lib/Transport/session-record.d.ts +0 -0
  103. package/cjs/lib/Transport/session-record.js +0 -0
  104. package/cjs/lib/Types/Auth.d.ts +0 -0
  105. package/cjs/lib/Types/Auth.js +0 -0
  106. package/cjs/lib/Types/Bussines.d.ts +0 -0
  107. package/cjs/lib/Types/Bussines.js +0 -0
  108. package/cjs/lib/Types/Call.d.ts +0 -0
  109. package/cjs/lib/Types/Call.js +0 -0
  110. package/cjs/lib/Types/Chat.d.ts +0 -0
  111. package/cjs/lib/Types/Chat.js +0 -0
  112. package/cjs/lib/Types/Contact.d.ts +0 -0
  113. package/cjs/lib/Types/Contact.js +0 -0
  114. package/cjs/lib/Types/Events.d.ts +0 -0
  115. package/cjs/lib/Types/Events.js +0 -0
  116. package/cjs/lib/Types/GroupMetadata.d.ts +0 -0
  117. package/cjs/lib/Types/GroupMetadata.js +0 -0
  118. package/cjs/lib/Types/Label.d.ts +0 -0
  119. package/cjs/lib/Types/Label.js +0 -0
  120. package/cjs/lib/Types/LabelAssociation.d.ts +0 -0
  121. package/cjs/lib/Types/LabelAssociation.js +0 -0
  122. package/cjs/lib/Types/Message.d.ts +0 -0
  123. package/cjs/lib/Types/Message.js +0 -0
  124. package/cjs/lib/Types/Mex.d.ts +0 -0
  125. package/cjs/lib/Types/Mex.js +0 -0
  126. package/cjs/lib/Types/Product.d.ts +0 -0
  127. package/cjs/lib/Types/Product.js +0 -0
  128. package/cjs/lib/Types/RichType.d.ts +0 -0
  129. package/cjs/lib/Types/RichType.js +0 -0
  130. package/cjs/lib/Types/Signal.d.ts +0 -0
  131. package/cjs/lib/Types/Signal.js +0 -0
  132. package/cjs/lib/Types/Socket.d.ts +0 -0
  133. package/cjs/lib/Types/Socket.js +0 -0
  134. package/cjs/lib/Types/State.d.ts +0 -0
  135. package/cjs/lib/Types/State.js +0 -0
  136. package/cjs/lib/Types/USync.d.ts +0 -0
  137. package/cjs/lib/Types/USync.js +0 -0
  138. package/cjs/lib/Types/index.d.ts +0 -0
  139. package/cjs/lib/Types/index.js +0 -0
  140. package/cjs/lib/Utils/auth-utils.d.ts +0 -0
  141. package/cjs/lib/Utils/auth-utils.js +0 -0
  142. package/cjs/lib/Utils/browser-utils.d.ts +0 -0
  143. package/cjs/lib/Utils/browser-utils.js +0 -0
  144. package/cjs/lib/Utils/business.d.ts +0 -0
  145. package/cjs/lib/Utils/business.js +0 -0
  146. package/cjs/lib/Utils/chat-utils.d.ts +0 -0
  147. package/cjs/lib/Utils/chat-utils.js +0 -0
  148. package/cjs/lib/Utils/companion-reg-client-utils.d.ts +0 -0
  149. package/cjs/lib/Utils/companion-reg-client-utils.js +0 -0
  150. package/cjs/lib/Utils/crypto.d.ts +0 -0
  151. package/cjs/lib/Utils/crypto.js +0 -0
  152. package/cjs/lib/Utils/decode-wa-message.d.ts +0 -0
  153. package/cjs/lib/Utils/decode-wa-message.js +0 -0
  154. package/cjs/lib/Utils/event-buffer.d.ts +0 -0
  155. package/cjs/lib/Utils/event-buffer.js +0 -0
  156. package/cjs/lib/Utils/generics.d.ts +0 -0
  157. package/cjs/lib/Utils/generics.js +1 -1
  158. package/cjs/lib/Utils/history.d.ts +0 -0
  159. package/cjs/lib/Utils/history.js +0 -0
  160. package/cjs/lib/Utils/identity-change-handler.d.ts +0 -0
  161. package/cjs/lib/Utils/identity-change-handler.js +0 -0
  162. package/cjs/lib/Utils/index.d.ts +0 -0
  163. package/cjs/lib/Utils/index.js +0 -0
  164. package/cjs/lib/Utils/link-preview.d.ts +0 -0
  165. package/cjs/lib/Utils/link-preview.js +0 -0
  166. package/cjs/lib/Utils/logger.d.ts +0 -0
  167. package/cjs/lib/Utils/logger.js +0 -0
  168. package/cjs/lib/Utils/lt-hash.d.ts +0 -0
  169. package/cjs/lib/Utils/lt-hash.js +0 -0
  170. package/cjs/lib/Utils/make-mutex.d.ts +0 -0
  171. package/cjs/lib/Utils/make-mutex.js +0 -0
  172. package/cjs/lib/Utils/message-retry-manager.d.ts +0 -0
  173. package/cjs/lib/Utils/message-retry-manager.js +0 -0
  174. package/cjs/lib/Utils/messages-media.d.ts +0 -0
  175. package/cjs/lib/Utils/messages-media.js +0 -0
  176. package/cjs/lib/Utils/messages.d.ts +0 -0
  177. package/cjs/lib/Utils/messages.js +11 -11
  178. package/cjs/lib/Utils/noise-handler.d.ts +0 -0
  179. package/cjs/lib/Utils/noise-handler.js +0 -0
  180. package/cjs/lib/Utils/offline-node-processor.d.ts +0 -0
  181. package/cjs/lib/Utils/offline-node-processor.js +0 -0
  182. package/cjs/lib/Utils/pre-key-manager.d.ts +0 -0
  183. package/cjs/lib/Utils/pre-key-manager.js +0 -0
  184. package/cjs/lib/Utils/process-message.d.ts +0 -0
  185. package/cjs/lib/Utils/process-message.js +0 -0
  186. package/cjs/lib/Utils/reporting-utils.d.ts +0 -0
  187. package/cjs/lib/Utils/reporting-utils.js +0 -0
  188. package/cjs/lib/Utils/rich-message-utils.d.ts +0 -0
  189. package/cjs/lib/Utils/rich-message-utils.js +6 -6
  190. package/cjs/lib/Utils/signal.d.ts +0 -0
  191. package/cjs/lib/Utils/signal.js +0 -0
  192. package/cjs/lib/Utils/stanza-ack.d.ts +0 -0
  193. package/cjs/lib/Utils/stanza-ack.js +0 -0
  194. package/cjs/lib/Utils/sync-action-utils.d.ts +0 -0
  195. package/cjs/lib/Utils/sync-action-utils.js +0 -0
  196. package/cjs/lib/Utils/tc-token-utils.d.ts +0 -0
  197. package/cjs/lib/Utils/tc-token-utils.js +0 -0
  198. package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +0 -0
  199. package/cjs/lib/Utils/use-multi-file-auth-state.js +0 -0
  200. package/cjs/lib/Utils/use-single-file-auth-state.d.ts +0 -0
  201. package/cjs/lib/Utils/use-single-file-auth-state.js +0 -0
  202. package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +0 -0
  203. package/cjs/lib/Utils/use-sqlite-auth-state.js +0 -0
  204. package/cjs/lib/Utils/validate-connection.d.ts +0 -0
  205. package/cjs/lib/Utils/validate-connection.js +0 -0
  206. package/cjs/lib/WABinary/constants.d.ts +0 -0
  207. package/cjs/lib/WABinary/constants.js +0 -0
  208. package/cjs/lib/WABinary/decode.d.ts +0 -0
  209. package/cjs/lib/WABinary/decode.js +0 -0
  210. package/cjs/lib/WABinary/encode.d.ts +0 -0
  211. package/cjs/lib/WABinary/encode.js +0 -0
  212. package/cjs/lib/WABinary/generic-utils.d.ts +0 -0
  213. package/cjs/lib/WABinary/generic-utils.js +0 -0
  214. package/cjs/lib/WABinary/index.d.ts +0 -0
  215. package/cjs/lib/WABinary/index.js +0 -0
  216. package/cjs/lib/WABinary/jid-utils.d.ts +0 -0
  217. package/cjs/lib/WABinary/jid-utils.js +0 -0
  218. package/cjs/lib/WABinary/types.d.ts +0 -0
  219. package/cjs/lib/WABinary/types.js +0 -0
  220. package/cjs/lib/WACrypto/appstate-keys.js +0 -0
  221. package/cjs/lib/WACrypto/curves/constants.js +0 -0
  222. package/cjs/lib/WACrypto/hkdf.js +0 -0
  223. package/cjs/lib/WACrypto/index.js +0 -0
  224. package/cjs/lib/WACrypto/lthash.js +0 -0
  225. package/cjs/lib/WACrypto/math/constants.js +0 -0
  226. package/cjs/lib/WACrypto/math/edwards.js +0 -0
  227. package/cjs/lib/WACrypto/math/fe.js +0 -0
  228. package/cjs/lib/WACrypto/math/le.js +0 -0
  229. package/cjs/lib/WACrypto/math/mod.js +0 -0
  230. package/cjs/lib/WACrypto/util/bytes.js +0 -0
  231. package/cjs/lib/WACrypto/x25519.js +0 -0
  232. package/cjs/lib/WACrypto/xeddsa.js +0 -0
  233. package/cjs/lib/WAM/BinaryInfo.d.ts +0 -0
  234. package/cjs/lib/WAM/BinaryInfo.js +0 -0
  235. package/cjs/lib/WAM/constants.d.ts +0 -0
  236. package/cjs/lib/WAM/constants.js +0 -0
  237. package/cjs/lib/WAM/encode.d.ts +0 -0
  238. package/cjs/lib/WAM/encode.js +0 -0
  239. package/cjs/lib/WAM/index.d.ts +0 -0
  240. package/cjs/lib/WAM/index.js +0 -0
  241. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -0
  242. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -0
  243. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -0
  244. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -0
  245. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -0
  246. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -0
  247. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -0
  248. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -0
  249. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -0
  250. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -0
  251. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -0
  252. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -0
  253. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -0
  254. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -0
  255. package/cjs/lib/WAUSync/Protocols/index.d.ts +0 -0
  256. package/cjs/lib/WAUSync/Protocols/index.js +0 -0
  257. package/cjs/lib/WAUSync/USyncQuery.d.ts +0 -0
  258. package/cjs/lib/WAUSync/USyncQuery.js +0 -0
  259. package/cjs/lib/WAUSync/USyncUser.d.ts +0 -0
  260. package/cjs/lib/WAUSync/USyncUser.js +0 -0
  261. package/cjs/lib/WAUSync/index.d.ts +0 -0
  262. package/cjs/lib/WAUSync/index.js +0 -0
  263. package/cjs/lib/index.d.ts +0 -0
  264. package/cjs/lib/index.js +0 -0
  265. package/cjs/package.json +0 -0
  266. package/engine-requirements.js +0 -0
  267. package/lib/Addon/cache.js +201 -0
  268. package/lib/Addon/crc32.js +21 -0
  269. package/lib/Addon/file-type.js +198 -0
  270. package/lib/Addon/get-file.js +98 -0
  271. package/lib/Addon/http-error.d.ts +0 -0
  272. package/lib/Addon/http-error.js +0 -0
  273. package/lib/Addon/index.d.ts +93 -0
  274. package/lib/Addon/index.js +23 -1
  275. package/lib/Addon/keyed-db.d.ts +0 -0
  276. package/lib/Addon/keyed-db.js +0 -0
  277. package/lib/Addon/link-preview.d.ts +0 -0
  278. package/lib/Addon/link-preview.js +0 -0
  279. package/lib/Addon/media-info.js +96 -0
  280. package/lib/Addon/mutex.js +76 -0
  281. package/lib/Addon/qr.js +531 -0
  282. package/lib/Addon/queue.js +44 -0
  283. package/lib/Addon/waveform.js +135 -0
  284. package/lib/Addon/zip.js +144 -0
  285. package/lib/Defaults/index.d.ts +2 -2
  286. package/lib/Defaults/index.js +3 -3
  287. package/lib/Signal/Group/ciphertext-message.d.ts +0 -0
  288. package/lib/Signal/Group/ciphertext-message.js +0 -0
  289. package/lib/Signal/Group/group-cipher.d.ts +0 -0
  290. package/lib/Signal/Group/group-cipher.js +0 -0
  291. package/lib/Signal/Group/group-session-builder.d.ts +0 -0
  292. package/lib/Signal/Group/group-session-builder.js +0 -0
  293. package/lib/Signal/Group/index.d.ts +0 -0
  294. package/lib/Signal/Group/index.js +0 -0
  295. package/lib/Signal/Group/keyhelper.d.ts +0 -0
  296. package/lib/Signal/Group/keyhelper.js +0 -0
  297. package/lib/Signal/Group/sender-chain-key.d.ts +0 -0
  298. package/lib/Signal/Group/sender-chain-key.js +0 -0
  299. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -0
  300. package/lib/Signal/Group/sender-key-distribution-message.js +0 -0
  301. package/lib/Signal/Group/sender-key-message.d.ts +0 -0
  302. package/lib/Signal/Group/sender-key-message.js +0 -0
  303. package/lib/Signal/Group/sender-key-name.d.ts +0 -0
  304. package/lib/Signal/Group/sender-key-name.js +0 -0
  305. package/lib/Signal/Group/sender-key-record.d.ts +0 -0
  306. package/lib/Signal/Group/sender-key-record.js +0 -0
  307. package/lib/Signal/Group/sender-key-state.d.ts +0 -0
  308. package/lib/Signal/Group/sender-key-state.js +0 -0
  309. package/lib/Signal/Group/sender-message-key.d.ts +0 -0
  310. package/lib/Signal/Group/sender-message-key.js +0 -0
  311. package/lib/Signal/libsignal.d.ts +0 -0
  312. package/lib/Signal/libsignal.js +0 -0
  313. package/lib/Signal/lid-mapping.d.ts +0 -0
  314. package/lib/Signal/lid-mapping.js +0 -0
  315. package/lib/Socket/Client/index.d.ts +0 -0
  316. package/lib/Socket/Client/index.js +0 -0
  317. package/lib/Socket/Client/types.d.ts +0 -0
  318. package/lib/Socket/Client/types.js +0 -0
  319. package/lib/Socket/Client/websocket.d.ts +0 -0
  320. package/lib/Socket/Client/websocket.js +0 -0
  321. package/lib/Socket/business.d.ts +0 -0
  322. package/lib/Socket/business.js +0 -0
  323. package/lib/Socket/chats.d.ts +0 -0
  324. package/lib/Socket/chats.js +1 -1
  325. package/lib/Socket/communities.d.ts +0 -0
  326. package/lib/Socket/communities.js +0 -0
  327. package/lib/Socket/groups.d.ts +0 -0
  328. package/lib/Socket/groups.js +0 -0
  329. package/lib/Socket/index.d.ts +0 -0
  330. package/lib/Socket/index.js +0 -0
  331. package/lib/Socket/messages-recv.d.ts +0 -0
  332. package/lib/Socket/messages-recv.js +2 -2
  333. package/lib/Socket/messages-send.d.ts +0 -0
  334. package/lib/Socket/messages-send.js +19 -19
  335. package/lib/Socket/mex.d.ts +0 -0
  336. package/lib/Socket/mex.js +0 -0
  337. package/lib/Socket/newsletter.d.ts +0 -0
  338. package/lib/Socket/newsletter.js +1 -1
  339. package/lib/Socket/socket.d.ts +0 -0
  340. package/lib/Socket/socket.js +0 -0
  341. package/lib/Store/index.d.ts +0 -0
  342. package/lib/Store/index.js +0 -0
  343. package/lib/Store/make-in-memory-store.d.ts +0 -0
  344. package/lib/Store/make-in-memory-store.js +1 -1
  345. package/lib/Store/make-ordered-dictionary.d.ts +0 -0
  346. package/lib/Store/make-ordered-dictionary.js +0 -0
  347. package/lib/Store/object-repository.d.ts +0 -0
  348. package/lib/Store/object-repository.js +0 -0
  349. package/lib/Transport/crypto.d.ts +0 -0
  350. package/lib/Transport/crypto.js +0 -0
  351. package/lib/Transport/curve.d.ts +0 -0
  352. package/lib/Transport/curve.js +0 -0
  353. package/lib/Transport/index.d.ts +0 -0
  354. package/lib/Transport/index.js +0 -0
  355. package/lib/Transport/internals.d.ts +0 -0
  356. package/lib/Transport/internals.js +0 -0
  357. package/lib/Transport/session-builder.d.ts +0 -0
  358. package/lib/Transport/session-builder.js +0 -0
  359. package/lib/Transport/session-cipher.d.ts +0 -0
  360. package/lib/Transport/session-cipher.js +0 -0
  361. package/lib/Transport/session-record.d.ts +0 -0
  362. package/lib/Transport/session-record.js +0 -0
  363. package/lib/Types/Auth.d.ts +0 -0
  364. package/lib/Types/Auth.js +0 -0
  365. package/lib/Types/Bussines.d.ts +0 -0
  366. package/lib/Types/Bussines.js +0 -0
  367. package/lib/Types/Call.d.ts +0 -0
  368. package/lib/Types/Call.js +0 -0
  369. package/lib/Types/Chat.d.ts +0 -0
  370. package/lib/Types/Chat.js +0 -0
  371. package/lib/Types/Contact.d.ts +0 -0
  372. package/lib/Types/Contact.js +0 -0
  373. package/lib/Types/Events.d.ts +0 -0
  374. package/lib/Types/Events.js +0 -0
  375. package/lib/Types/GroupMetadata.d.ts +0 -0
  376. package/lib/Types/GroupMetadata.js +0 -0
  377. package/lib/Types/Label.d.ts +0 -0
  378. package/lib/Types/Label.js +0 -0
  379. package/lib/Types/LabelAssociation.d.ts +0 -0
  380. package/lib/Types/LabelAssociation.js +0 -0
  381. package/lib/Types/Message.d.ts +0 -0
  382. package/lib/Types/Message.js +1 -1
  383. package/lib/Types/Mex.d.ts +0 -0
  384. package/lib/Types/Mex.js +0 -0
  385. package/lib/Types/Product.d.ts +0 -0
  386. package/lib/Types/Product.js +0 -0
  387. package/lib/Types/RichType.d.ts +0 -0
  388. package/lib/Types/RichType.js +0 -0
  389. package/lib/Types/Signal.d.ts +0 -0
  390. package/lib/Types/Signal.js +0 -0
  391. package/lib/Types/Socket.d.ts +0 -0
  392. package/lib/Types/Socket.js +0 -0
  393. package/lib/Types/State.d.ts +0 -0
  394. package/lib/Types/State.js +0 -0
  395. package/lib/Types/USync.d.ts +0 -0
  396. package/lib/Types/USync.js +0 -0
  397. package/lib/Types/index.d.ts +0 -0
  398. package/lib/Types/index.js +0 -0
  399. package/lib/Utils/auth-utils.d.ts +0 -0
  400. package/lib/Utils/auth-utils.js +0 -0
  401. package/lib/Utils/browser-utils.d.ts +0 -0
  402. package/lib/Utils/browser-utils.js +0 -0
  403. package/lib/Utils/business.d.ts +0 -0
  404. package/lib/Utils/business.js +0 -0
  405. package/lib/Utils/chat-utils.d.ts +0 -0
  406. package/lib/Utils/chat-utils.js +0 -0
  407. package/lib/Utils/companion-reg-client-utils.d.ts +0 -0
  408. package/lib/Utils/companion-reg-client-utils.js +0 -0
  409. package/lib/Utils/crypto.d.ts +0 -0
  410. package/lib/Utils/crypto.js +0 -0
  411. package/lib/Utils/decode-wa-message.d.ts +0 -0
  412. package/lib/Utils/decode-wa-message.js +0 -0
  413. package/lib/Utils/event-buffer.d.ts +0 -0
  414. package/lib/Utils/event-buffer.js +0 -0
  415. package/lib/Utils/generics.d.ts +0 -0
  416. package/lib/Utils/generics.js +1 -1
  417. package/lib/Utils/history.d.ts +0 -0
  418. package/lib/Utils/history.js +0 -0
  419. package/lib/Utils/identity-change-handler.d.ts +0 -0
  420. package/lib/Utils/identity-change-handler.js +0 -0
  421. package/lib/Utils/index.d.ts +0 -0
  422. package/lib/Utils/index.js +0 -0
  423. package/lib/Utils/link-preview.d.ts +0 -0
  424. package/lib/Utils/link-preview.js +0 -0
  425. package/lib/Utils/logger.d.ts +0 -0
  426. package/lib/Utils/logger.js +0 -0
  427. package/lib/Utils/lt-hash.d.ts +0 -0
  428. package/lib/Utils/lt-hash.js +0 -0
  429. package/lib/Utils/make-mutex.d.ts +0 -0
  430. package/lib/Utils/make-mutex.js +0 -0
  431. package/lib/Utils/message-retry-manager.d.ts +0 -0
  432. package/lib/Utils/message-retry-manager.js +0 -0
  433. package/lib/Utils/messages-media.d.ts +0 -0
  434. package/lib/Utils/messages-media.js +2 -2
  435. package/lib/Utils/messages.d.ts +0 -0
  436. package/lib/Utils/messages.js +46 -50
  437. package/lib/Utils/noise-handler.d.ts +0 -0
  438. package/lib/Utils/noise-handler.js +0 -0
  439. package/lib/Utils/offline-node-processor.d.ts +0 -0
  440. package/lib/Utils/offline-node-processor.js +0 -0
  441. package/lib/Utils/pre-key-manager.d.ts +0 -0
  442. package/lib/Utils/pre-key-manager.js +0 -0
  443. package/lib/Utils/process-message.d.ts +0 -0
  444. package/lib/Utils/process-message.js +0 -0
  445. package/lib/Utils/reporting-utils.d.ts +0 -0
  446. package/lib/Utils/reporting-utils.js +0 -0
  447. package/lib/Utils/rich-message-utils.d.ts +0 -0
  448. package/lib/Utils/rich-message-utils.js +10 -13
  449. package/lib/Utils/signal.d.ts +0 -0
  450. package/lib/Utils/signal.js +0 -0
  451. package/lib/Utils/stanza-ack.d.ts +0 -0
  452. package/lib/Utils/stanza-ack.js +0 -0
  453. package/lib/Utils/sync-action-utils.d.ts +0 -0
  454. package/lib/Utils/sync-action-utils.js +0 -0
  455. package/lib/Utils/tc-token-utils.d.ts +0 -0
  456. package/lib/Utils/tc-token-utils.js +0 -0
  457. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -0
  458. package/lib/Utils/use-multi-file-auth-state.js +1 -1
  459. package/lib/Utils/use-single-file-auth-state.d.ts +0 -0
  460. package/lib/Utils/use-single-file-auth-state.js +1 -1
  461. package/lib/Utils/use-sqlite-auth-state.d.ts +0 -0
  462. package/lib/Utils/use-sqlite-auth-state.js +1 -1
  463. package/lib/Utils/validate-connection.d.ts +0 -0
  464. package/lib/Utils/validate-connection.js +0 -0
  465. package/lib/WABinary/constants.d.ts +0 -0
  466. package/lib/WABinary/constants.js +0 -0
  467. package/lib/WABinary/decode.d.ts +0 -0
  468. package/lib/WABinary/decode.js +0 -0
  469. package/lib/WABinary/encode.d.ts +0 -0
  470. package/lib/WABinary/encode.js +0 -0
  471. package/lib/WABinary/generic-utils.d.ts +0 -0
  472. package/lib/WABinary/generic-utils.js +0 -2
  473. package/lib/WABinary/index.d.ts +0 -0
  474. package/lib/WABinary/index.js +0 -0
  475. package/lib/WABinary/jid-utils.d.ts +0 -0
  476. package/lib/WABinary/jid-utils.js +0 -0
  477. package/lib/WABinary/types.d.ts +0 -0
  478. package/lib/WABinary/types.js +0 -0
  479. package/lib/WACrypto/appstate-keys.js +0 -0
  480. package/lib/WACrypto/curves/constants.js +0 -0
  481. package/lib/WACrypto/hkdf.js +0 -0
  482. package/lib/WACrypto/index.js +0 -0
  483. package/lib/WACrypto/lthash.js +1 -1
  484. package/lib/WACrypto/math/constants.js +0 -0
  485. package/lib/WACrypto/math/edwards.js +0 -0
  486. package/lib/WACrypto/math/fe.js +0 -0
  487. package/lib/WACrypto/math/le.js +0 -0
  488. package/lib/WACrypto/math/mod.js +0 -0
  489. package/lib/WACrypto/util/bytes.js +0 -0
  490. package/lib/WACrypto/x25519.js +3 -3
  491. package/lib/WACrypto/xeddsa.js +0 -0
  492. package/lib/WAM/BinaryInfo.d.ts +0 -0
  493. package/lib/WAM/BinaryInfo.js +0 -0
  494. package/lib/WAM/constants.d.ts +0 -0
  495. package/lib/WAM/constants.js +0 -0
  496. package/lib/WAM/encode.d.ts +0 -0
  497. package/lib/WAM/encode.js +0 -0
  498. package/lib/WAM/index.d.ts +0 -0
  499. package/lib/WAM/index.js +0 -0
  500. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -0
  501. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -0
  502. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -0
  503. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -0
  504. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -0
  505. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -0
  506. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -0
  507. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -0
  508. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -0
  509. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -0
  510. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -0
  511. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -0
  512. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -0
  513. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -0
  514. package/lib/WAUSync/Protocols/index.d.ts +0 -0
  515. package/lib/WAUSync/Protocols/index.js +0 -0
  516. package/lib/WAUSync/USyncQuery.d.ts +0 -0
  517. package/lib/WAUSync/USyncQuery.js +0 -0
  518. package/lib/WAUSync/USyncUser.d.ts +0 -0
  519. package/lib/WAUSync/USyncUser.js +0 -0
  520. package/lib/WAUSync/index.d.ts +0 -0
  521. package/lib/WAUSync/index.js +0 -0
  522. package/lib/index.d.ts +0 -0
  523. package/lib/index.js +0 -0
  524. package/package.json +4 -9
  525. package/tests/addon-test.mjs +162 -0
  526. package/tests/differential-test.mjs +90 -0
@@ -18,18 +18,26 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var index_exports = {};
20
20
  __export(index_exports, {
21
- createCache: () => import_starforge.createCache,
22
- createMutex: () => import_starforge.createMutex,
23
- createQueue: () => import_starforge.createQueue,
24
- createZip: () => import_starforge.createZip,
25
- detectFileType: () => import_starforge.detectFileType,
26
- detectMediaInfo: () => import_starforge.detectMediaInfo,
27
- encodeQR: () => import_starforge.encodeQR,
28
- getAudioWaveform: () => import_starforge.getAudioWaveform,
29
- getFile: () => import_starforge.getFile
21
+ createCache: () => import_cache.createCache,
22
+ createMutex: () => import_mutex.createMutex,
23
+ createQueue: () => import_queue.createQueue,
24
+ createZip: () => import_zip.createZip,
25
+ detectFileType: () => import_file_type.detectFileType,
26
+ detectMediaInfo: () => import_media_info.detectMediaInfo,
27
+ encodeQR: () => import_qr.encodeQR,
28
+ getAudioWaveform: () => import_waveform.getAudioWaveform,
29
+ getFile: () => import_get_file.getFile
30
30
  });
31
31
  module.exports = __toCommonJS(index_exports);
32
- var import_starforge = require("@itsliaaa/starforge");
32
+ var import_cache = require("./cache.js");
33
+ var import_mutex = require("./mutex.js");
34
+ var import_queue = require("./queue.js");
35
+ var import_zip = require("./zip.js");
36
+ var import_file_type = require("./file-type.js");
37
+ var import_media_info = require("./media-info.js");
38
+ var import_qr = require("./qr.js");
39
+ var import_waveform = require("./waveform.js");
40
+ var import_get_file = require("./get-file.js");
33
41
  __reExport(index_exports, require("./http-error.js"), module.exports);
34
42
  __reExport(index_exports, require("./keyed-db.js"), module.exports);
35
43
  __reExport(index_exports, require("./link-preview.js"), module.exports);
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,98 @@
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 media_info_exports = {};
19
+ __export(media_info_exports, {
20
+ detectMediaInfo: () => detectMediaInfo
21
+ });
22
+ module.exports = __toCommonJS(media_info_exports);
23
+ var import_node_child_process = require("node:child_process");
24
+ const PROBE_TIMEOUT_MS = 15e3;
25
+ function runFfprobe(args, stdinData) {
26
+ return new Promise((resolve, reject) => {
27
+ const child = (0, import_node_child_process.spawn)("ffprobe", [
28
+ "-v",
29
+ "quiet",
30
+ "-print_format",
31
+ "json",
32
+ "-show_format",
33
+ "-show_streams",
34
+ ...args
35
+ ], { stdio: stdinData ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"] });
36
+ let stdout = "";
37
+ let stderr = "";
38
+ const timer = setTimeout(() => {
39
+ child.kill("SIGKILL");
40
+ reject(new Error("ffprobe timed out"));
41
+ }, PROBE_TIMEOUT_MS);
42
+ child.stdout.on("data", (c) => stdout += c);
43
+ child.stderr.on("data", (c) => stderr += c);
44
+ child.on("error", (err) => {
45
+ clearTimeout(timer);
46
+ reject(err);
47
+ });
48
+ child.on("close", (code) => {
49
+ clearTimeout(timer);
50
+ if (code !== 0) {
51
+ reject(new Error(stderr.trim() || `ffprobe exited with code ${code}`));
52
+ return;
53
+ }
54
+ try {
55
+ resolve(JSON.parse(stdout));
56
+ } catch {
57
+ resolve({});
58
+ }
59
+ });
60
+ if (stdinData) {
61
+ child.stdin.on("error", () => {
62
+ });
63
+ child.stdin.end(stdinData);
64
+ }
65
+ });
66
+ }
67
+ function mapProbeReport(report) {
68
+ const info = {};
69
+ const duration = Number(report?.format?.duration);
70
+ if (Number.isFinite(duration)) {
71
+ info.durationSeconds = Math.round(duration);
72
+ }
73
+ const streams = Array.isArray(report?.streams) ? report.streams : [];
74
+ const video = streams.find((s) => s.width && s.height || s.codec_type === "video");
75
+ if (video?.width && video?.height) {
76
+ info.width = video.width;
77
+ info.height = video.height;
78
+ }
79
+ return info;
80
+ }
81
+ async function detectMediaInfo(input) {
82
+ let args;
83
+ let stdinData;
84
+ if (typeof input === "string") {
85
+ args = [input];
86
+ } else if (Buffer.isBuffer(input) || input instanceof Uint8Array) {
87
+ args = ["-i", "pipe:0"];
88
+ stdinData = Buffer.from(input.buffer, input.byteOffset, input.byteLength);
89
+ } else {
90
+ throw new TypeError("detectMediaInfo: expects a Buffer, Uint8Array or a file path");
91
+ }
92
+ const report = await runFfprobe(args, stdinData);
93
+ return mapProbeReport(report);
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ detectMediaInfo
98
+ });
@@ -0,0 +1,78 @@
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 mutex_exports = {};
19
+ __export(mutex_exports, {
20
+ createMutex: () => createMutex
21
+ });
22
+ module.exports = __toCommonJS(mutex_exports);
23
+ function createMutex() {
24
+ let locked = false;
25
+ const queue = [];
26
+ function dispatchNext() {
27
+ const next = queue.shift();
28
+ if (next) {
29
+ next.resolve(release);
30
+ } else {
31
+ locked = false;
32
+ }
33
+ }
34
+ function release() {
35
+ dispatchNext();
36
+ }
37
+ function acquire() {
38
+ return new Promise((resolve, reject) => {
39
+ if (!locked) {
40
+ locked = true;
41
+ resolve(release);
42
+ } else {
43
+ queue.push({ resolve, reject });
44
+ }
45
+ });
46
+ }
47
+ function tryAcquire() {
48
+ if (locked) return void 0;
49
+ locked = true;
50
+ return release;
51
+ }
52
+ async function runExclusive(task) {
53
+ const releaseFn = await acquire();
54
+ try {
55
+ return await task();
56
+ } finally {
57
+ releaseFn();
58
+ }
59
+ }
60
+ return {
61
+ /** Alias of acquire(). */
62
+ lock: acquire,
63
+ /** Acquires the lock, resolving to a release function. */
64
+ acquire,
65
+ /** Acquires without waiting: returns a release function, or undefined when locked. */
66
+ tryAcquire,
67
+ /** Alias of tryAcquire(). */
68
+ tryLock: tryAcquire,
69
+ /** Runs `task` while holding the lock; resolves/rejects with the task result. */
70
+ runExclusive,
71
+ /** True while the lock is held. */
72
+ isLocked: () => locked
73
+ };
74
+ }
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ createMutex
78
+ });
@@ -0,0 +1,464 @@
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 qr_exports = {};
19
+ __export(qr_exports, {
20
+ encodeQR: () => encodeQR
21
+ });
22
+ module.exports = __toCommonJS(qr_exports);
23
+ var import_node_zlib = require("node:zlib");
24
+ var import_crc32 = require("./crc32.js");
25
+ const ECC_CODEWORDS_PER_BLOCK = [
26
+ // Low
27
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
28
+ // Medium
29
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
30
+ // Quartile
31
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
32
+ // High
33
+ [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
34
+ ];
35
+ const NUM_ERROR_CORRECTION_BLOCKS = [
36
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
37
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
38
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
39
+ [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
40
+ ];
41
+ const ECC_FORMAT_BITS = { L: 1, M: 0, Q: 3, H: 2 };
42
+ const PENALTY_N1 = 3, PENALTY_N2 = 3, PENALTY_N3 = 40, PENALTY_N4 = 10;
43
+ function rsDivisor(degree) {
44
+ const result = new Uint8Array(degree);
45
+ result[degree - 1] = 1;
46
+ let root = 1;
47
+ for (let i = 0; i < degree; i++) {
48
+ for (let j = 0; j < degree; j++) {
49
+ let z = 0;
50
+ for (let bit = 7; bit >= 0; bit--) {
51
+ z = z << 1 ^ (z >>> 7) * 285;
52
+ z ^= (root >>> bit & 1) * result[j];
53
+ }
54
+ result[j] = z & 255;
55
+ if (j + 1 < degree) result[j] ^= result[j + 1];
56
+ }
57
+ root = rsMultiply(root, 2);
58
+ }
59
+ return result;
60
+ }
61
+ function rsMultiply(x, y) {
62
+ let z = 0;
63
+ for (let i = 7; i >= 0; i--) {
64
+ z = z << 1 ^ (z >>> 7) * 285;
65
+ z ^= (y >>> i & 1) * x;
66
+ }
67
+ return z & 255;
68
+ }
69
+ function rsRemainder(data, divisor) {
70
+ const result = new Uint8Array(divisor.length);
71
+ for (const b of data) {
72
+ const factor = b ^ result[0];
73
+ result.copyWithin(0, 1);
74
+ result[result.length - 1] = 0;
75
+ for (let i = 0; i < divisor.length; i++) {
76
+ result[i] ^= rsMultiply(divisor[i], factor);
77
+ }
78
+ }
79
+ return result;
80
+ }
81
+ function numRawDataModules(ver) {
82
+ let result = (16 * ver + 128) * ver + 64;
83
+ if (ver >= 2) {
84
+ const numAlign = Math.floor(ver / 7) + 2;
85
+ result -= (25 * numAlign - 10) * numAlign - 55;
86
+ if (ver >= 7) result -= 36;
87
+ }
88
+ return result;
89
+ }
90
+ function numDataCodewords(ver, level) {
91
+ return Math.floor(numRawDataModules(ver) / 8) - ECC_CODEWORDS_PER_BLOCK[level][ver] * NUM_ERROR_CORRECTION_BLOCKS[level][ver];
92
+ }
93
+ function alignmentPositions(size, ver) {
94
+ if (ver === 1) return [];
95
+ const numAlign = Math.floor(ver / 7) + 2;
96
+ const step = Math.floor((ver * 8 + numAlign * 3 + 5) / (numAlign * 4 - 4)) * 2;
97
+ const result = [6];
98
+ for (let pos = size - 7; result.length < numAlign; pos -= step) {
99
+ result.splice(1, 0, pos);
100
+ }
101
+ return result;
102
+ }
103
+ class QrMatrix {
104
+ constructor(version) {
105
+ this.version = version;
106
+ this.size = version * 4 + 17;
107
+ this.modules = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
108
+ this.isFunction = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
109
+ }
110
+ set(x, y, dark) {
111
+ this.modules[y][x] = dark;
112
+ this.isFunction[y][x] = true;
113
+ }
114
+ drawFunctionPatterns(level) {
115
+ for (let i = 0; i < this.size; i++) {
116
+ this.set(6, i, i % 2 === 0);
117
+ this.set(i, 6, i % 2 === 0);
118
+ }
119
+ for (const [cx, cy] of [[3, 3], [this.size - 4, 3], [3, this.size - 4]]) {
120
+ for (let dy = -4; dy <= 4; dy++) {
121
+ for (let dx = -4; dx <= 4; dx++) {
122
+ const dist = Math.max(Math.abs(dx), Math.abs(dy));
123
+ const x = cx + dx, y = cy + dy;
124
+ if (x >= 0 && x < this.size && y >= 0 && y < this.size) {
125
+ this.set(x, y, dist !== 2 && dist !== 4);
126
+ }
127
+ }
128
+ }
129
+ }
130
+ const positions = alignmentPositions(this.size, this.version);
131
+ for (let i = 0; i < positions.length; i++) {
132
+ for (let j = 0; j < positions.length; j++) {
133
+ const isCorner = i === 0 && j === 0 || i === 0 && j === positions.length - 1 || i === positions.length - 1 && j === 0;
134
+ if (!isCorner) this.drawAlignment(positions[i], positions[j]);
135
+ }
136
+ }
137
+ this.drawFormatBits(level, 0);
138
+ this.drawVersionBits();
139
+ }
140
+ drawAlignment(cx, cy) {
141
+ for (let dy = -2; dy <= 2; dy++) {
142
+ for (let dx = -2; dx <= 2; dx++) {
143
+ this.set(cx + dx, cy + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
144
+ }
145
+ }
146
+ }
147
+ drawFormatBits(level, mask) {
148
+ const data = ECC_FORMAT_BITS[level] << 3 | mask;
149
+ let rem = data;
150
+ for (let i = 0; i < 10; i++) {
151
+ rem = rem << 1 ^ (rem >>> 9) * 1335;
152
+ }
153
+ const bits = (data << 10 | rem) ^ 21522;
154
+ const bitAt = (i) => (bits >>> i & 1) !== 0;
155
+ for (let i = 0; i <= 5; i++) this.set(8, i, bitAt(i));
156
+ this.set(8, 7, bitAt(6));
157
+ this.set(8, 8, bitAt(7));
158
+ this.set(7, 8, bitAt(8));
159
+ for (let i = 9; i < 15; i++) this.set(14 - i, 8, bitAt(i));
160
+ for (let i = 0; i < 8; i++) this.set(this.size - 1 - i, 8, bitAt(i));
161
+ for (let i = 8; i < 15; i++) this.set(8, this.size - 15 + i, bitAt(i));
162
+ this.set(8, this.size - 8, true);
163
+ }
164
+ drawVersionBits() {
165
+ if (this.version < 7) return;
166
+ let rem = this.version;
167
+ for (let i = 0; i < 12; i++) {
168
+ rem = rem << 1 ^ (rem >>> 11) * 7973;
169
+ }
170
+ const bits = this.version << 12 | rem;
171
+ for (let i = 0; i < 18; i++) {
172
+ const dark = (bits >>> i & 1) !== 0;
173
+ const a = this.size - 11 + i % 3;
174
+ const b = Math.floor(i / 3);
175
+ this.set(a, b, dark);
176
+ this.set(b, a, dark);
177
+ }
178
+ }
179
+ /** Places the interleaved codewords into the non-function modules. */
180
+ drawCodewords(data) {
181
+ let bitIndex = 0;
182
+ for (let right = this.size - 1; right >= 1; right -= 2) {
183
+ if (right === 6) right = 5;
184
+ for (let vert = 0; vert < this.size; vert++) {
185
+ for (let j = 0; j < 2; j++) {
186
+ const x = right - j;
187
+ const upward = (right + 1 & 2) === 0;
188
+ const y = upward ? this.size - 1 - vert : vert;
189
+ if (!this.isFunction[y][x] && bitIndex < data.length * 8) {
190
+ this.modules[y][x] = (data[bitIndex >>> 3] >>> 7 - (bitIndex & 7) & 1) !== 0;
191
+ bitIndex++;
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+ applyMask(mask) {
198
+ for (let y = 0; y < this.size; y++) {
199
+ for (let x = 0; x < this.size; x++) {
200
+ let invert;
201
+ switch (mask) {
202
+ case 0:
203
+ invert = (x + y) % 2 === 0;
204
+ break;
205
+ case 1:
206
+ invert = y % 2 === 0;
207
+ break;
208
+ case 2:
209
+ invert = x % 3 === 0;
210
+ break;
211
+ case 3:
212
+ invert = (x + y) % 3 === 0;
213
+ break;
214
+ case 4:
215
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
216
+ break;
217
+ case 5:
218
+ invert = x * y % 2 + x * y % 3 === 0;
219
+ break;
220
+ case 6:
221
+ invert = (x * y % 2 + x * y % 3) % 2 === 0;
222
+ break;
223
+ case 7:
224
+ invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
225
+ break;
226
+ }
227
+ if (!this.isFunction[y][x] && invert) {
228
+ this.modules[y][x] = !this.modules[y][x];
229
+ }
230
+ }
231
+ }
232
+ }
233
+ penaltyScore() {
234
+ const size = this.size;
235
+ let result = 0;
236
+ const lines = [];
237
+ for (let y = 0; y < size; y++) lines.push({ get: (i) => this.modules[y][i] });
238
+ for (let x = 0; x < size; x++) lines.push({ get: (i) => this.modules[i][x] });
239
+ for (const line of lines) {
240
+ let runColor = line.get(0);
241
+ let runLength = 1;
242
+ const runs = [];
243
+ for (let i = 1; i < size; i++) {
244
+ if (line.get(i) === runColor) {
245
+ runLength++;
246
+ } else {
247
+ runs.push({ color: runColor, length: runLength });
248
+ runColor = line.get(i);
249
+ runLength = 1;
250
+ }
251
+ }
252
+ runs.push({ color: runColor, length: runLength });
253
+ for (const run of runs) {
254
+ if (run.length >= 5) result += PENALTY_N1 + (run.length - 5);
255
+ }
256
+ let s = "";
257
+ for (let i = 0; i < size; i++) s += line.get(i) ? "1" : "0";
258
+ result += countFinderPatterns("0".repeat(size) + s + "0".repeat(size)) * PENALTY_N3;
259
+ }
260
+ for (let y = 0; y < size - 1; y++) {
261
+ for (let x = 0; x < size - 1; x++) {
262
+ const c = this.modules[y][x];
263
+ if (c === this.modules[y][x + 1] && c === this.modules[y + 1][x] && c === this.modules[y + 1][x + 1]) {
264
+ result += PENALTY_N2;
265
+ }
266
+ }
267
+ }
268
+ let dark = 0;
269
+ for (const row of this.modules) {
270
+ for (const cell of row) if (cell) dark++;
271
+ }
272
+ const total = size * size;
273
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
274
+ result += Math.max(0, k) * PENALTY_N4;
275
+ return result;
276
+ }
277
+ clone() {
278
+ const copy = new QrMatrix(this.version);
279
+ for (let y = 0; y < this.size; y++) {
280
+ copy.modules[y] = [...this.modules[y]];
281
+ copy.isFunction[y] = [...this.isFunction[y]];
282
+ }
283
+ return copy;
284
+ }
285
+ }
286
+ function countFinderPatterns(s) {
287
+ let count = 0;
288
+ for (let i = 0; i + 7 <= s.length; i++) {
289
+ if (s.startsWith("1011101", i)) {
290
+ const lightBefore = i >= 4 && s.slice(i - 4, i) === "0000";
291
+ const lightAfter = s.slice(i + 7, i + 11) === "0000";
292
+ if (lightBefore || lightAfter) count++;
293
+ }
294
+ }
295
+ return count;
296
+ }
297
+ function buildCodewords(text, level) {
298
+ const data = Buffer.from(text, "utf8");
299
+ if (data.length > 2953) {
300
+ throw new RangeError("QR payload too long (byte mode supports up to 2953 bytes at ECC L)");
301
+ }
302
+ let version = 0;
303
+ let usedBits = 0;
304
+ for (let v = 1; v <= 40; v++) {
305
+ const capacityBits2 = numDataCodewords(v, 0) * 8;
306
+ const bits2 = 4 + (v <= 9 ? 8 : 16) + data.length * 8;
307
+ if (bits2 <= capacityBits2) {
308
+ version = v;
309
+ usedBits = bits2;
310
+ break;
311
+ }
312
+ }
313
+ if (version === 0) {
314
+ throw new RangeError("QR payload too long (exceeds version 40 capacity)");
315
+ }
316
+ let levelIndex = 0;
317
+ const levels = ["L", "M", "Q", "H"];
318
+ for (let i = 1; i < 4; i++) {
319
+ if (usedBits <= numDataCodewords(version, i) * 8) levelIndex = i;
320
+ }
321
+ const levelName = levels[levelIndex];
322
+ const capacityBits = numDataCodewords(version, levelIndex) * 8;
323
+ const bits = [];
324
+ const appendBits = (value, length) => {
325
+ for (let i = length - 1; i >= 0; i--) bits.push(value >>> i & 1);
326
+ };
327
+ appendBits(4, 4);
328
+ appendBits(data.length, version <= 9 ? 8 : 16);
329
+ for (const byte of data) appendBits(byte, 8);
330
+ appendBits(0, Math.min(4, capacityBits - bits.length));
331
+ while (bits.length % 8 !== 0) bits.push(0);
332
+ for (let pad = 236; bits.length < capacityBits; pad ^= 236 ^ 17) {
333
+ appendBits(pad, 8);
334
+ }
335
+ const dataCodewords = new Uint8Array(bits.length / 8);
336
+ for (let i = 0; i < dataCodewords.length; i++) {
337
+ for (let j = 0; j < 8; j++) {
338
+ dataCodewords[i] = dataCodewords[i] << 1 | bits[i * 8 + j];
339
+ }
340
+ }
341
+ const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[levelIndex][version];
342
+ const blockEccLen = ECC_CODEWORDS_PER_BLOCK[levelIndex][version];
343
+ const rawCodewords = Math.floor(numRawDataModules(version) / 8);
344
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
345
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
346
+ const blocks = [];
347
+ const divisor = rsDivisor(blockEccLen);
348
+ for (let i = 0, k = 0; i < numBlocks; i++) {
349
+ const dat = dataCodewords.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
350
+ k += dat.length;
351
+ const ecc = rsRemainder(dat, divisor);
352
+ const isShort = i < numShortBlocks;
353
+ const block = new Uint8Array(dat.length + ecc.length + (isShort ? 1 : 0));
354
+ block.set(dat, 0);
355
+ if (isShort) block[dat.length] = 0;
356
+ block.set(ecc, dat.length + (isShort ? 1 : 0));
357
+ blocks.push(block);
358
+ }
359
+ const result = [];
360
+ for (let i = 0; i < blocks[0].length; i++) {
361
+ for (let j = 0; j < numBlocks; j++) {
362
+ if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks) {
363
+ result.push(blocks[j][i]);
364
+ }
365
+ }
366
+ }
367
+ return { version, levelName, codewords: new Uint8Array(result) };
368
+ }
369
+ function encodeMatrix(text) {
370
+ const { version, levelName, codewords } = buildCodewords(text);
371
+ let best = null;
372
+ let bestPenalty = Infinity;
373
+ for (let mask = 0; mask < 8; mask++) {
374
+ const matrix = new QrMatrix(version);
375
+ matrix.drawFunctionPatterns(levelName);
376
+ matrix.drawCodewords(codewords);
377
+ matrix.applyMask(mask);
378
+ matrix.drawFormatBits(levelName, mask);
379
+ const penalty = matrix.penaltyScore();
380
+ if (penalty < bestPenalty) {
381
+ bestPenalty = penalty;
382
+ best = matrix;
383
+ }
384
+ }
385
+ return best;
386
+ }
387
+ function renderAscii(matrix) {
388
+ const border = 2;
389
+ const size = matrix.size + border * 2;
390
+ const get = (x, y) => {
391
+ const mx = x - border, my = y - border;
392
+ if (mx < 0 || my < 0 || mx >= matrix.size || my >= matrix.size) return false;
393
+ return matrix.modules[my][mx];
394
+ };
395
+ const lines = [];
396
+ for (let y = 0; y < size; y += 2) {
397
+ let line = "";
398
+ for (let x = 0; x < size; x++) {
399
+ const top = get(x, y);
400
+ const bottom = y + 1 < size ? get(x, y + 1) : false;
401
+ if (top && bottom) line += "\u2588";
402
+ else if (top) line += "\u2580";
403
+ else if (bottom) line += "\u2584";
404
+ else line += " ";
405
+ }
406
+ lines.push(line);
407
+ }
408
+ return lines.join("\n") + "\n";
409
+ }
410
+ function renderPng(matrix, scale, border) {
411
+ const dim = (matrix.size + border * 2) * scale;
412
+ const width = dim, height = dim;
413
+ const stride = width + 1;
414
+ const raw = Buffer.alloc(stride * height);
415
+ for (let y = 0; y < height; y++) {
416
+ const rowStart = y * stride;
417
+ raw[rowStart] = 0;
418
+ for (let x = 0; x < width; x++) {
419
+ const mx = Math.floor(x / scale) - border;
420
+ const my = Math.floor(y / scale) - border;
421
+ const dark = mx >= 0 && my >= 0 && mx < matrix.size && my < matrix.size && matrix.modules[my][mx];
422
+ raw[rowStart + 1 + x] = dark ? 0 : 255;
423
+ }
424
+ }
425
+ const IHDR = Buffer.alloc(13);
426
+ IHDR.writeUInt32BE(width, 0);
427
+ IHDR.writeUInt32BE(height, 4);
428
+ IHDR[8] = 8;
429
+ IHDR[9] = 0;
430
+ IHDR[10] = 0;
431
+ IHDR[11] = 0;
432
+ IHDR[12] = 0;
433
+ const chunks = [];
434
+ const chunk = (type, data) => {
435
+ const len = Buffer.alloc(4);
436
+ len.writeUInt32BE(data.length, 0);
437
+ const typeBuf = Buffer.from(type, "latin1");
438
+ const crcBuf = Buffer.concat([typeBuf, data]);
439
+ const crc = Buffer.alloc(4);
440
+ crc.writeUInt32BE((0, import_crc32.crc32)(crcBuf), 0);
441
+ chunks.push(len, typeBuf, data, crc);
442
+ };
443
+ chunk("IHDR", IHDR);
444
+ chunk("IDAT", (0, import_node_zlib.deflateSync)(raw, { level: 9 }));
445
+ chunk("IEND", Buffer.alloc(0));
446
+ return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), ...chunks]);
447
+ }
448
+ async function encodeQR(text) {
449
+ if (typeof text !== "string") {
450
+ throw new TypeError("encodeQR: expects a string payload");
451
+ }
452
+ const matrix = encodeMatrix(text);
453
+ return {
454
+ ascii: renderAscii(matrix),
455
+ getPngBuffer: async () => renderPng(matrix, 8, 4),
456
+ getRaw: async () => matrix.modules.map((row) => [...row]),
457
+ version: matrix.version,
458
+ errorCorrectionLevel: "L"
459
+ };
460
+ }
461
+ // Annotate the CommonJS export names for ESM import in node:
462
+ 0 && (module.exports = {
463
+ encodeQR
464
+ });