zapo-js 0.1.2 → 0.2.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 (468) hide show
  1. package/README.md +12 -4
  2. package/dist/appstate/WaAppStateCrypto.js +1 -1
  3. package/dist/appstate/WaAppStateSyncClient.js +138 -93
  4. package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
  5. package/dist/appstate/index.js +8 -6
  6. package/dist/appstate/utils.js +0 -5
  7. package/dist/auth/WaAuthClient.js +36 -47
  8. package/dist/auth/flow/WaAuthCredentialsFlow.js +7 -7
  9. package/dist/auth/index.js +1 -6
  10. package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
  11. package/dist/auth/pairing/WaPairingFlow.js +13 -3
  12. package/dist/client/WaClient.js +225 -101
  13. package/dist/client/WaClientFactory.js +294 -44
  14. package/dist/client/connection/WaConnectionManager.js +19 -10
  15. package/dist/client/coordinators/WaBusinessCoordinator.js +241 -0
  16. package/dist/client/coordinators/WaGroupCoordinator.js +11 -7
  17. package/dist/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
  18. package/dist/client/coordinators/WaMessageDispatchCoordinator.js +292 -99
  19. package/dist/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
  20. package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
  21. package/dist/client/coordinators/WaProfileCoordinator.js +212 -0
  22. package/dist/client/coordinators/WaRetryCoordinator.js +179 -27
  23. package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
  24. package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
  25. package/dist/client/dirty.js +40 -20
  26. package/dist/client/events/devices.js +72 -0
  27. package/dist/client/events/group.js +3 -11
  28. package/dist/client/events/identity.js +22 -0
  29. package/dist/client/events/privacy-token.js +39 -0
  30. package/dist/client/history-sync.js +50 -9
  31. package/dist/client/incoming.js +37 -7
  32. package/dist/client/mailbox.js +24 -23
  33. package/dist/client/messages.js +107 -31
  34. package/dist/client/messaging/fanout.js +21 -11
  35. package/dist/client/messaging/participants.js +6 -4
  36. package/dist/client/persistence/WriteBehindPersistence.js +129 -0
  37. package/dist/client/tokens/cs-token.js +50 -0
  38. package/dist/client/tokens/tc-token.js +25 -0
  39. package/dist/crypto/core/index.js +2 -2
  40. package/dist/crypto/core/keys.js +4 -4
  41. package/dist/crypto/core/nonce.js +2 -0
  42. package/dist/crypto/core/primitives.js +0 -8
  43. package/dist/crypto/core/random.js +22 -0
  44. package/dist/crypto/curves/X25519.js +25 -6
  45. package/dist/crypto/index.js +3 -0
  46. package/dist/crypto/math/constants.js +13 -36
  47. package/dist/crypto/math/edwards.js +171 -44
  48. package/dist/crypto/math/fe.js +706 -0
  49. package/dist/crypto/math/mod.js +10 -3
  50. package/dist/esm/appstate/WaAppStateCrypto.js +1 -1
  51. package/dist/esm/appstate/WaAppStateSyncClient.js +138 -93
  52. package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
  53. package/dist/esm/appstate/index.js +2 -2
  54. package/dist/esm/appstate/utils.js +2 -5
  55. package/dist/esm/auth/WaAuthClient.js +36 -47
  56. package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +7 -7
  57. package/dist/esm/auth/index.js +0 -2
  58. package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
  59. package/dist/esm/auth/pairing/WaPairingFlow.js +14 -4
  60. package/dist/esm/client/WaClient.js +225 -101
  61. package/dist/esm/client/WaClientFactory.js +295 -45
  62. package/dist/esm/client/connection/WaConnectionManager.js +19 -10
  63. package/dist/esm/client/coordinators/WaBusinessCoordinator.js +238 -0
  64. package/dist/esm/client/coordinators/WaGroupCoordinator.js +11 -7
  65. package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
  66. package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +295 -102
  67. package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
  68. package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
  69. package/dist/esm/client/coordinators/WaProfileCoordinator.js +209 -0
  70. package/dist/esm/client/coordinators/WaRetryCoordinator.js +181 -29
  71. package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
  72. package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
  73. package/dist/esm/client/dirty.js +40 -20
  74. package/dist/esm/client/events/devices.js +68 -0
  75. package/dist/esm/client/events/group.js +3 -11
  76. package/dist/esm/client/events/identity.js +19 -0
  77. package/dist/esm/client/events/privacy-token.js +36 -0
  78. package/dist/esm/client/history-sync.js +50 -9
  79. package/dist/esm/client/incoming.js +38 -8
  80. package/dist/esm/client/mailbox.js +24 -23
  81. package/dist/esm/client/messages.js +108 -32
  82. package/dist/esm/client/messaging/fanout.js +22 -12
  83. package/dist/esm/client/messaging/participants.js +6 -4
  84. package/dist/esm/client/persistence/WriteBehindPersistence.js +125 -0
  85. package/dist/esm/client/tokens/cs-token.js +46 -0
  86. package/dist/esm/client/tokens/tc-token.js +18 -0
  87. package/dist/esm/crypto/core/index.js +2 -2
  88. package/dist/esm/crypto/core/keys.js +1 -1
  89. package/dist/esm/crypto/core/nonce.js +2 -0
  90. package/dist/esm/crypto/core/primitives.js +0 -7
  91. package/dist/esm/crypto/core/random.js +22 -1
  92. package/dist/esm/crypto/curves/X25519.js +25 -6
  93. package/dist/esm/crypto/index.js +1 -0
  94. package/dist/esm/crypto/math/constants.js +12 -35
  95. package/dist/esm/crypto/math/edwards.js +174 -47
  96. package/dist/esm/crypto/math/fe.js +691 -0
  97. package/dist/esm/crypto/math/mod.js +10 -1
  98. package/dist/esm/index.js +1 -1
  99. package/dist/esm/infra/perf/BackgroundQueue.js +478 -0
  100. package/dist/esm/infra/perf/BoundedTaskQueue.js +3 -1
  101. package/dist/esm/infra/perf/PromiseDedup.js +20 -0
  102. package/dist/esm/infra/perf/SharedExclusiveGate.js +109 -0
  103. package/dist/esm/infra/perf/StoreLock.js +77 -0
  104. package/dist/esm/media/WaMediaCrypto.js +95 -13
  105. package/dist/esm/media/WaMediaTransferClient.js +39 -47
  106. package/dist/esm/media/constants.js +2 -1
  107. package/dist/esm/message/WaMessageClient.js +26 -19
  108. package/dist/esm/message/content.js +195 -9
  109. package/dist/esm/message/icdc.js +76 -0
  110. package/dist/esm/message/incoming.js +24 -12
  111. package/dist/esm/message/phash.js +3 -1
  112. package/dist/esm/message/reporting-token.js +14 -27
  113. package/dist/esm/protocol/appstate.js +9 -40
  114. package/dist/esm/protocol/browser.js +10 -18
  115. package/dist/esm/protocol/constants.js +5 -3
  116. package/dist/esm/protocol/defaults.js +6 -0
  117. package/dist/esm/protocol/index.js +1 -2
  118. package/dist/esm/protocol/jid.js +105 -36
  119. package/dist/esm/protocol/message.js +61 -1
  120. package/dist/esm/protocol/nodes.js +2 -0
  121. package/dist/esm/protocol/notification.js +3 -1
  122. package/dist/esm/protocol/privacy-token.js +17 -0
  123. package/dist/esm/protocol/privacy.js +55 -0
  124. package/dist/esm/protocol/stream.js +26 -1
  125. package/dist/esm/retry/codec.js +216 -0
  126. package/dist/esm/retry/constants.js +1 -1
  127. package/dist/esm/retry/index.js +2 -2
  128. package/dist/esm/retry/parse.js +50 -30
  129. package/dist/esm/retry/replay.js +11 -7
  130. package/dist/esm/retry/tracker.js +50 -12
  131. package/dist/esm/signal/api/SignalDeviceSyncApi.js +49 -32
  132. package/dist/esm/signal/api/SignalDigestSyncApi.js +13 -9
  133. package/dist/esm/signal/api/SignalIdentitySyncApi.js +26 -11
  134. package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +18 -7
  135. package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
  136. package/dist/esm/signal/api/SignalSessionSyncApi.js +16 -7
  137. package/dist/esm/signal/api/result-map.js +10 -0
  138. package/dist/esm/signal/constants.js +0 -4
  139. package/dist/esm/signal/crypto/WaAdvSignature.js +12 -6
  140. package/dist/esm/signal/{store/sqlite.js → encoding.js} +78 -24
  141. package/dist/esm/signal/group/SenderKeyCodec.js +3 -2
  142. package/dist/esm/signal/group/SenderKeyManager.js +125 -106
  143. package/dist/esm/signal/index.js +1 -0
  144. package/dist/esm/signal/registration/keygen.js +6 -2
  145. package/dist/esm/signal/registration/utils.js +1 -0
  146. package/dist/esm/signal/session/SignalProtocol.js +150 -74
  147. package/dist/esm/signal/session/resolver.js +137 -102
  148. package/dist/esm/store/contracts/privacy-token.store.js +1 -0
  149. package/dist/esm/store/createStore.js +101 -187
  150. package/dist/esm/store/index.js +1 -10
  151. package/dist/esm/store/locks/appstate.lock.js +26 -0
  152. package/dist/esm/store/locks/auth.lock.js +15 -0
  153. package/dist/esm/store/locks/contact.lock.js +20 -0
  154. package/dist/esm/store/locks/device-list.lock.js +20 -0
  155. package/dist/esm/store/locks/message.lock.js +21 -0
  156. package/dist/esm/store/locks/participants.lock.js +20 -0
  157. package/dist/esm/store/locks/privacy-token.lock.js +18 -0
  158. package/dist/esm/store/locks/retry.lock.js +29 -0
  159. package/dist/esm/store/locks/sender-key.lock.js +52 -0
  160. package/dist/esm/store/locks/signal.lock.js +63 -0
  161. package/dist/esm/store/locks/thread.lock.js +21 -0
  162. package/dist/esm/store/noop.store.js +1 -1
  163. package/dist/esm/store/providers/memory/appstate.store.js +22 -24
  164. package/dist/esm/store/providers/memory/device-list.store.js +10 -5
  165. package/dist/esm/store/providers/memory/privacy-token.store.js +43 -0
  166. package/dist/esm/store/providers/memory/retry.store.js +77 -2
  167. package/dist/esm/store/providers/memory/sender-key.store.js +6 -1
  168. package/dist/esm/store/providers/memory/signal.store.js +36 -19
  169. package/dist/esm/transport/WaComms.js +3 -1
  170. package/dist/esm/transport/WaWebSocket.js +0 -6
  171. package/dist/esm/transport/binary/constants.js +0 -30
  172. package/dist/esm/transport/binary/decoder.js +4 -4
  173. package/dist/esm/transport/binary/encoder.js +8 -15
  174. package/dist/esm/transport/binary/index.js +0 -1
  175. package/dist/esm/transport/node/WaNodeOrchestrator.js +25 -19
  176. package/dist/esm/transport/node/builders/business.js +129 -0
  177. package/dist/esm/transport/node/builders/global.js +370 -0
  178. package/dist/esm/transport/node/builders/index.js +5 -2
  179. package/dist/esm/transport/node/builders/message.js +63 -239
  180. package/dist/esm/transport/node/builders/pairing.js +0 -24
  181. package/dist/esm/transport/node/builders/privacy-token.js +41 -0
  182. package/dist/esm/transport/node/builders/privacy.js +48 -0
  183. package/dist/esm/transport/node/builders/profile.js +70 -0
  184. package/dist/esm/transport/node/builders/retry.js +10 -22
  185. package/dist/esm/transport/node/builders/usync.js +6 -2
  186. package/dist/esm/transport/node/helpers.js +19 -1
  187. package/dist/esm/transport/node/usync.js +3 -33
  188. package/dist/esm/transport/node/xml.js +35 -14
  189. package/dist/esm/transport/noise/WaClientPayload.js +10 -10
  190. package/dist/esm/transport/noise/WaNoiseCert.js +3 -3
  191. package/dist/esm/transport/noise/WaNoiseSession.js +64 -23
  192. package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
  193. package/dist/esm/transport/stream/parse.js +8 -4
  194. package/dist/esm/util/bytes.js +22 -18
  195. package/dist/esm/util/index.js +5 -0
  196. package/dist/esm/util/primitives.js +3 -2
  197. package/dist/index.js +7 -1
  198. package/dist/infra/perf/BackgroundQueue.js +482 -0
  199. package/dist/infra/perf/BoundedTaskQueue.js +3 -1
  200. package/dist/infra/perf/PromiseDedup.js +24 -0
  201. package/dist/infra/perf/SharedExclusiveGate.js +113 -0
  202. package/dist/infra/perf/StoreLock.js +81 -0
  203. package/dist/media/WaMediaCrypto.js +94 -12
  204. package/dist/media/WaMediaTransferClient.js +39 -47
  205. package/dist/media/constants.js +2 -1
  206. package/dist/message/WaMessageClient.js +26 -19
  207. package/dist/message/content.js +198 -9
  208. package/dist/message/icdc.js +81 -0
  209. package/dist/message/incoming.js +24 -12
  210. package/dist/message/phash.js +3 -1
  211. package/dist/message/reporting-token.js +14 -28
  212. package/dist/protocol/appstate.js +10 -41
  213. package/dist/protocol/browser.js +10 -18
  214. package/dist/protocol/constants.js +21 -2
  215. package/dist/protocol/defaults.js +6 -0
  216. package/dist/protocol/index.js +8 -5
  217. package/dist/protocol/jid.js +111 -36
  218. package/dist/protocol/message.js +62 -2
  219. package/dist/protocol/nodes.js +2 -0
  220. package/dist/protocol/notification.js +3 -1
  221. package/dist/protocol/privacy-token.js +20 -0
  222. package/dist/protocol/privacy.js +58 -0
  223. package/dist/protocol/stream.js +27 -2
  224. package/dist/retry/codec.js +220 -0
  225. package/dist/retry/constants.js +1 -1
  226. package/dist/retry/index.js +5 -5
  227. package/dist/retry/parse.js +51 -30
  228. package/dist/retry/replay.js +10 -6
  229. package/dist/retry/tracker.js +50 -12
  230. package/dist/signal/api/SignalDeviceSyncApi.js +48 -31
  231. package/dist/signal/api/SignalDigestSyncApi.js +13 -9
  232. package/dist/signal/api/SignalIdentitySyncApi.js +25 -10
  233. package/dist/signal/api/SignalMissingPreKeysSyncApi.js +17 -6
  234. package/dist/signal/api/SignalRotateKeyApi.js +4 -2
  235. package/dist/signal/api/SignalSessionSyncApi.js +16 -7
  236. package/dist/signal/api/result-map.js +13 -0
  237. package/dist/signal/constants.js +1 -5
  238. package/dist/signal/crypto/WaAdvSignature.js +11 -5
  239. package/dist/signal/{store/sqlite.js → encoding.js} +79 -25
  240. package/dist/signal/group/SenderKeyCodec.js +4 -3
  241. package/dist/signal/group/SenderKeyManager.js +125 -106
  242. package/dist/signal/index.js +13 -1
  243. package/dist/signal/registration/keygen.js +6 -2
  244. package/dist/signal/registration/utils.js +1 -0
  245. package/dist/signal/session/SignalProtocol.js +150 -74
  246. package/dist/signal/session/resolver.js +135 -100
  247. package/dist/store/contracts/privacy-token.store.js +2 -0
  248. package/dist/store/createStore.js +101 -187
  249. package/dist/store/index.js +15 -33
  250. package/dist/store/locks/appstate.lock.js +29 -0
  251. package/dist/store/locks/auth.lock.js +18 -0
  252. package/dist/store/locks/contact.lock.js +23 -0
  253. package/dist/store/locks/device-list.lock.js +23 -0
  254. package/dist/store/locks/message.lock.js +24 -0
  255. package/dist/store/locks/participants.lock.js +23 -0
  256. package/dist/store/locks/privacy-token.lock.js +21 -0
  257. package/dist/store/locks/retry.lock.js +32 -0
  258. package/dist/store/locks/sender-key.lock.js +55 -0
  259. package/dist/store/locks/signal.lock.js +66 -0
  260. package/dist/store/locks/thread.lock.js +24 -0
  261. package/dist/store/noop.store.js +1 -1
  262. package/dist/store/providers/memory/appstate.store.js +22 -24
  263. package/dist/store/providers/memory/device-list.store.js +10 -5
  264. package/dist/store/providers/memory/privacy-token.store.js +47 -0
  265. package/dist/store/providers/memory/retry.store.js +77 -2
  266. package/dist/store/providers/memory/sender-key.store.js +6 -1
  267. package/dist/store/providers/memory/signal.store.js +36 -19
  268. package/dist/transport/WaComms.js +3 -1
  269. package/dist/transport/WaWebSocket.js +0 -6
  270. package/dist/transport/binary/constants.js +1 -31
  271. package/dist/transport/binary/decoder.js +4 -4
  272. package/dist/transport/binary/encoder.js +8 -15
  273. package/dist/transport/binary/index.js +0 -4
  274. package/dist/transport/node/WaNodeOrchestrator.js +24 -18
  275. package/dist/transport/node/builders/business.js +137 -0
  276. package/dist/transport/node/builders/global.js +375 -0
  277. package/dist/transport/node/builders/index.js +18 -9
  278. package/dist/transport/node/builders/message.js +64 -245
  279. package/dist/transport/node/builders/pairing.js +0 -26
  280. package/dist/transport/node/builders/privacy-token.js +46 -0
  281. package/dist/transport/node/builders/privacy.js +55 -0
  282. package/dist/transport/node/builders/profile.js +78 -0
  283. package/dist/transport/node/builders/retry.js +9 -21
  284. package/dist/transport/node/builders/usync.js +6 -2
  285. package/dist/transport/node/helpers.js +20 -1
  286. package/dist/transport/node/usync.js +2 -32
  287. package/dist/transport/node/xml.js +35 -14
  288. package/dist/transport/noise/WaClientPayload.js +13 -13
  289. package/dist/transport/noise/WaNoiseCert.js +2 -2
  290. package/dist/transport/noise/WaNoiseSession.js +64 -23
  291. package/dist/transport/noise/WaNoiseSocket.js +8 -4
  292. package/dist/transport/stream/parse.js +7 -3
  293. package/dist/types/appstate/encoding.d.ts +7 -0
  294. package/dist/types/appstate/index.d.ts +3 -3
  295. package/dist/types/appstate/utils.d.ts +0 -2
  296. package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
  297. package/dist/types/auth/index.d.ts +0 -2
  298. package/dist/types/auth/types.d.ts +1 -0
  299. package/dist/types/client/WaClient.d.ts +27 -12
  300. package/dist/types/client/WaClientFactory.d.ts +12 -4
  301. package/dist/types/client/connection/WaConnectionManager.d.ts +2 -0
  302. package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
  303. package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -1
  304. package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +14 -0
  305. package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -0
  306. package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
  307. package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +36 -0
  308. package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
  309. package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
  310. package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +45 -0
  311. package/dist/types/client/events/devices.d.ts +20 -0
  312. package/dist/types/client/events/identity.d.ts +9 -0
  313. package/dist/types/client/events/privacy-token.d.ts +7 -0
  314. package/dist/types/client/history-sync.d.ts +9 -6
  315. package/dist/types/client/incoming.d.ts +3 -1
  316. package/dist/types/client/index.d.ts +1 -1
  317. package/dist/types/client/mailbox.d.ts +3 -5
  318. package/dist/types/client/messages.d.ts +1 -2
  319. package/dist/types/client/persistence/WriteBehindPersistence.d.ts +34 -0
  320. package/dist/types/client/tokens/cs-token.d.ts +10 -0
  321. package/dist/types/client/tokens/tc-token.d.ts +5 -0
  322. package/dist/types/client/types.d.ts +51 -3
  323. package/dist/types/crypto/core/index.d.ts +2 -2
  324. package/dist/types/crypto/core/nonce.d.ts +2 -0
  325. package/dist/types/crypto/core/primitives.d.ts +0 -1
  326. package/dist/types/crypto/core/random.d.ts +1 -0
  327. package/dist/types/crypto/index.d.ts +1 -0
  328. package/dist/types/crypto/math/constants.d.ts +4 -2
  329. package/dist/types/crypto/math/fe.d.ts +30 -0
  330. package/dist/types/crypto/math/mod.d.ts +0 -2
  331. package/dist/types/crypto/math/types.d.ts +11 -4
  332. package/dist/types/index.d.ts +5 -3
  333. package/dist/types/infra/perf/BackgroundQueue.d.ts +58 -0
  334. package/dist/types/infra/perf/PromiseDedup.d.ts +4 -0
  335. package/dist/types/infra/perf/SharedExclusiveGate.d.ts +17 -0
  336. package/dist/types/infra/perf/StoreLock.d.ts +10 -0
  337. package/dist/types/media/WaMediaCrypto.d.ts +3 -2
  338. package/dist/types/media/WaMediaTransferClient.d.ts +3 -12
  339. package/dist/types/media/constants.d.ts +1 -1
  340. package/dist/types/media/index.d.ts +1 -1
  341. package/dist/types/media/types.d.ts +10 -2
  342. package/dist/types/message/content.d.ts +8 -0
  343. package/dist/types/message/icdc.d.ts +13 -0
  344. package/dist/types/message/reporting-token.d.ts +0 -1
  345. package/dist/types/message/types.d.ts +45 -6
  346. package/dist/types/protocol/appstate.d.ts +0 -11
  347. package/dist/types/protocol/constants.d.ts +7 -3
  348. package/dist/types/protocol/defaults.d.ts +6 -0
  349. package/dist/types/protocol/index.d.ts +1 -2
  350. package/dist/types/protocol/jid.d.ts +19 -2
  351. package/dist/types/protocol/message.d.ts +60 -0
  352. package/dist/types/protocol/nodes.d.ts +2 -0
  353. package/dist/types/protocol/notification.d.ts +2 -0
  354. package/dist/types/protocol/privacy-token.d.ts +17 -0
  355. package/dist/types/protocol/privacy.d.ts +75 -0
  356. package/dist/types/protocol/stream.d.ts +30 -0
  357. package/dist/types/retry/codec.d.ts +3 -0
  358. package/dist/types/retry/index.d.ts +3 -3
  359. package/dist/types/retry/parse.d.ts +5 -2
  360. package/dist/types/retry/tracker.d.ts +1 -0
  361. package/dist/types/retry/types.d.ts +6 -1
  362. package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +2 -1
  363. package/dist/types/signal/api/SignalDigestSyncApi.d.ts +6 -0
  364. package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +2 -0
  365. package/dist/types/signal/api/SignalRotateKeyApi.d.ts +4 -5
  366. package/dist/types/signal/api/SignalSessionSyncApi.d.ts +8 -6
  367. package/dist/types/signal/api/result-map.d.ts +1 -0
  368. package/dist/types/signal/constants.d.ts +0 -3
  369. package/dist/types/signal/{store/sqlite.d.ts → encoding.d.ts} +3 -3
  370. package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
  371. package/dist/types/signal/index.d.ts +2 -0
  372. package/dist/types/signal/session/SignalProtocol.d.ts +10 -4
  373. package/dist/types/signal/session/resolver.d.ts +7 -2
  374. package/dist/types/store/contracts/appstate.store.d.ts +1 -1
  375. package/dist/types/store/contracts/privacy-token.store.d.ts +16 -0
  376. package/dist/types/store/contracts/retry.store.d.ts +7 -0
  377. package/dist/types/store/contracts/signal.store.d.ts +7 -0
  378. package/dist/types/store/createStore.d.ts +1 -1
  379. package/dist/types/store/index.d.ts +5 -13
  380. package/dist/types/store/locks/appstate.lock.d.ts +3 -0
  381. package/dist/types/store/locks/auth.lock.d.ts +3 -0
  382. package/dist/types/store/locks/contact.lock.d.ts +3 -0
  383. package/dist/types/store/locks/device-list.lock.d.ts +2 -0
  384. package/dist/types/store/locks/message.lock.d.ts +3 -0
  385. package/dist/types/store/locks/participants.lock.d.ts +2 -0
  386. package/dist/types/store/locks/privacy-token.lock.d.ts +2 -0
  387. package/dist/types/store/locks/retry.lock.d.ts +2 -0
  388. package/dist/types/store/locks/sender-key.lock.d.ts +3 -0
  389. package/dist/types/store/locks/signal.lock.d.ts +3 -0
  390. package/dist/types/store/locks/thread.lock.d.ts +3 -0
  391. package/dist/types/store/providers/memory/appstate.store.d.ts +1 -1
  392. package/dist/types/store/providers/memory/privacy-token.store.d.ts +13 -0
  393. package/dist/types/store/providers/memory/retry.store.d.ts +8 -0
  394. package/dist/types/store/providers/memory/signal.store.d.ts +2 -1
  395. package/dist/types/store/types.d.ts +49 -61
  396. package/dist/types/transport/WaWebSocket.d.ts +0 -1
  397. package/dist/types/transport/binary/constants.d.ts +0 -30
  398. package/dist/types/transport/binary/index.d.ts +0 -1
  399. package/dist/types/transport/node/WaNodeOrchestrator.d.ts +3 -4
  400. package/dist/types/transport/node/builders/business.d.ts +29 -0
  401. package/dist/types/transport/node/builders/global.d.ts +102 -0
  402. package/dist/types/transport/node/builders/index.d.ts +5 -2
  403. package/dist/types/transport/node/builders/message.d.ts +8 -7
  404. package/dist/types/transport/node/builders/pairing.d.ts +0 -2
  405. package/dist/types/transport/node/builders/privacy-token.d.ts +9 -0
  406. package/dist/types/transport/node/builders/privacy.d.ts +7 -0
  407. package/dist/types/transport/node/builders/profile.d.ts +8 -0
  408. package/dist/types/transport/node/builders/retry.d.ts +0 -1
  409. package/dist/types/transport/node/helpers.d.ts +5 -0
  410. package/dist/types/transport/noise/WaNoiseSession.d.ts +3 -2
  411. package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
  412. package/dist/types/util/bytes.d.ts +1 -1
  413. package/dist/types/util/index.d.ts +5 -0
  414. package/dist/types/util/primitives.d.ts +0 -1
  415. package/dist/util/bytes.js +22 -18
  416. package/dist/util/index.js +23 -0
  417. package/dist/util/primitives.js +2 -2
  418. package/package.json +29 -7
  419. package/proto/index.js +1 -1
  420. package/dist/crypto/core/constants.js +0 -4
  421. package/dist/esm/crypto/core/constants.js +0 -1
  422. package/dist/esm/retry/outbound.js +0 -82
  423. package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
  424. package/dist/esm/store/providers/sqlite/appstate.store.js +0 -250
  425. package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
  426. package/dist/esm/store/providers/sqlite/connection.js +0 -245
  427. package/dist/esm/store/providers/sqlite/contact.store.js +0 -74
  428. package/dist/esm/store/providers/sqlite/device-list.store.js +0 -127
  429. package/dist/esm/store/providers/sqlite/message.store.js +0 -132
  430. package/dist/esm/store/providers/sqlite/migrations.js +0 -347
  431. package/dist/esm/store/providers/sqlite/participants.store.js +0 -77
  432. package/dist/esm/store/providers/sqlite/retry.store.js +0 -141
  433. package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -198
  434. package/dist/esm/store/providers/sqlite/signal.store.js +0 -435
  435. package/dist/esm/store/providers/sqlite/table-names.js +0 -107
  436. package/dist/esm/store/providers/sqlite/thread.store.js +0 -85
  437. package/dist/retry/outbound.js +0 -87
  438. package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
  439. package/dist/store/providers/sqlite/appstate.store.js +0 -254
  440. package/dist/store/providers/sqlite/auth.store.js +0 -180
  441. package/dist/store/providers/sqlite/connection.js +0 -281
  442. package/dist/store/providers/sqlite/contact.store.js +0 -78
  443. package/dist/store/providers/sqlite/device-list.store.js +0 -131
  444. package/dist/store/providers/sqlite/message.store.js +0 -136
  445. package/dist/store/providers/sqlite/migrations.js +0 -350
  446. package/dist/store/providers/sqlite/participants.store.js +0 -81
  447. package/dist/store/providers/sqlite/retry.store.js +0 -145
  448. package/dist/store/providers/sqlite/sender-key.store.js +0 -202
  449. package/dist/store/providers/sqlite/signal.store.js +0 -439
  450. package/dist/store/providers/sqlite/table-names.js +0 -113
  451. package/dist/store/providers/sqlite/thread.store.js +0 -89
  452. package/dist/types/appstate/store/sqlite.d.ts +0 -7
  453. package/dist/types/crypto/core/constants.d.ts +0 -1
  454. package/dist/types/retry/outbound.d.ts +0 -4
  455. package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +0 -12
  456. package/dist/types/store/providers/sqlite/appstate.store.d.ts +0 -17
  457. package/dist/types/store/providers/sqlite/auth.store.d.ts +0 -10
  458. package/dist/types/store/providers/sqlite/connection.d.ts +0 -10
  459. package/dist/types/store/providers/sqlite/contact.store.d.ts +0 -12
  460. package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -15
  461. package/dist/types/store/providers/sqlite/message.store.d.ts +0 -13
  462. package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
  463. package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -12
  464. package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -15
  465. package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -24
  466. package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -53
  467. package/dist/types/store/providers/sqlite/table-names.d.ts +0 -5
  468. package/dist/types/store/providers/sqlite/thread.store.d.ts +0 -13
@@ -1,14 +1,14 @@
1
1
  import { WA_DEFAULTS, WA_IQ_TYPES, WA_NODE_TAGS, WA_XMLNS } from '../../protocol/constants.js';
2
2
  import { toError } from '../../util/primitives.js';
3
- import { formatNodeIdPrefixFromSeed } from './helpers.js';
3
+ import { createNodeIdGenerator } from './helpers.js';
4
4
  export class WaNodeOrchestrator {
5
5
  constructor(options) {
6
6
  this.logger = options.logger;
7
7
  this.sendNodeFn = options.sendNode;
8
8
  this.defaultTimeoutMs = options.defaultTimeoutMs ?? WA_DEFAULTS.NODE_QUERY_TIMEOUT_MS;
9
9
  this.hostDomain = options.hostDomain ?? WA_DEFAULTS.HOST_DOMAIN;
10
- this.stanzaPrefix = null;
11
- this.stanzaCounter = 0;
10
+ this.idGenerator = null;
11
+ this.idGeneratorReady = null;
12
12
  this.pendingQueries = new Map();
13
13
  }
14
14
  hasPending() {
@@ -70,11 +70,11 @@ export class WaNodeOrchestrator {
70
70
  return true;
71
71
  }
72
72
  async sendNode(node) {
73
- const outbound = this.withAutoId(node);
73
+ const outbound = await this.withAutoId(node);
74
74
  await this.sendNodeFn(outbound);
75
75
  }
76
76
  async query(node, timeoutMs = this.defaultTimeoutMs) {
77
- const outbound = this.withAutoId(node);
77
+ const outbound = await this.withAutoId(node);
78
78
  const id = outbound.attrs.id;
79
79
  if (!id) {
80
80
  throw new Error('query node id is required');
@@ -110,13 +110,11 @@ export class WaNodeOrchestrator {
110
110
  });
111
111
  });
112
112
  }
113
- withAutoId(node) {
113
+ async withAutoId(node) {
114
114
  if (node.attrs.id) {
115
115
  return node;
116
116
  }
117
- const prefix = this.getStanzaPrefix();
118
- this.stanzaCounter += 1;
119
- const generatedId = `${prefix}${this.stanzaCounter}`;
117
+ const generatedId = (await this.getIdGenerator()).next();
120
118
  this.logger.trace('generated stanza id', { id: generatedId });
121
119
  return {
122
120
  ...node,
@@ -126,16 +124,24 @@ export class WaNodeOrchestrator {
126
124
  }
127
125
  };
128
126
  }
129
- getStanzaPrefix() {
130
- if (this.stanzaPrefix) {
131
- return this.stanzaPrefix;
127
+ async getIdGenerator() {
128
+ if (this.idGenerator) {
129
+ return this.idGenerator;
130
+ }
131
+ if (!this.idGeneratorReady) {
132
+ this.idGeneratorReady = createNodeIdGenerator();
133
+ }
134
+ try {
135
+ const generator = await this.idGeneratorReady;
136
+ if (!this.idGenerator) {
137
+ this.idGenerator = generator;
138
+ this.logger.debug('generated stanza prefix', { prefix: generator.prefix });
139
+ }
140
+ return generator;
141
+ }
142
+ catch (error) {
143
+ this.idGeneratorReady = null;
144
+ throw toError(error);
132
145
  }
133
- this.stanzaPrefix = this.generateStanzaPrefix();
134
- return this.stanzaPrefix;
135
- }
136
- generateStanzaPrefix() {
137
- const prefix = formatNodeIdPrefixFromSeed(crypto.getRandomValues(new Uint8Array(4)));
138
- this.logger.debug('generated stanza prefix', { prefix });
139
- return prefix;
140
146
  }
141
147
  }
@@ -0,0 +1,129 @@
1
+ import { WA_DEFAULTS, WA_XMLNS } from '../../../protocol/constants.js';
2
+ import { buildIqNode } from '../../node/query.js';
3
+ export const WA_BUSINESS_PROFILE_VERSION = 116;
4
+ export function buildGetBusinessProfileIq(jids, version = WA_BUSINESS_PROFILE_VERSION) {
5
+ return buildIqNode('get', WA_DEFAULTS.HOST_DOMAIN, WA_XMLNS.BUSINESS, [
6
+ {
7
+ tag: 'business_profile',
8
+ attrs: { v: `${version}` },
9
+ content: jids.map((jid) => ({
10
+ tag: 'profile',
11
+ attrs: { jid }
12
+ }))
13
+ }
14
+ ]);
15
+ }
16
+ export function buildEditBusinessProfileIq(input) {
17
+ const children = [];
18
+ if (input.address !== undefined) {
19
+ children.push({ tag: 'address', attrs: {}, content: input.address });
20
+ }
21
+ if (input.description !== undefined) {
22
+ children.push({ tag: 'description', attrs: {}, content: input.description });
23
+ }
24
+ if (input.email !== undefined) {
25
+ children.push({ tag: 'email', attrs: {}, content: input.email });
26
+ }
27
+ if (input.latitude !== undefined) {
28
+ children.push({ tag: 'latitude', attrs: {}, content: `${input.latitude}` });
29
+ }
30
+ if (input.longitude !== undefined) {
31
+ children.push({ tag: 'longitude', attrs: {}, content: `${input.longitude}` });
32
+ }
33
+ if (input.websites !== undefined) {
34
+ if (input.websites.length > 2) {
35
+ throw new Error('business profile supports at most 2 websites');
36
+ }
37
+ if (input.websites.length === 0) {
38
+ children.push({ tag: 'website', attrs: {} });
39
+ }
40
+ else {
41
+ children.push({ tag: 'website', attrs: {}, content: input.websites[0].url });
42
+ if (input.websites.length > 1) {
43
+ children.push({ tag: 'website', attrs: {}, content: input.websites[1].url });
44
+ }
45
+ }
46
+ }
47
+ if (input.categories !== undefined) {
48
+ children.push({
49
+ tag: 'categories',
50
+ attrs: {},
51
+ content: input.categories.map((cat) => ({
52
+ tag: 'category',
53
+ attrs: { id: cat.id }
54
+ }))
55
+ });
56
+ }
57
+ if (input.businessHours !== undefined) {
58
+ children.push(buildBusinessHoursNode(input.businessHours));
59
+ }
60
+ return buildIqNode('set', WA_DEFAULTS.HOST_DOMAIN, WA_XMLNS.BUSINESS, [
61
+ {
62
+ tag: 'business_profile',
63
+ attrs: { v: '3', mutation_type: 'delta' },
64
+ content: children
65
+ }
66
+ ]);
67
+ }
68
+ function buildBusinessHoursNode(hours) {
69
+ const configNodes = new Array(hours.config.length);
70
+ for (let i = 0; i < hours.config.length; i += 1) {
71
+ const entry = hours.config[i];
72
+ const attrs = {
73
+ day_of_week: entry.dayOfWeek,
74
+ mode: entry.mode
75
+ };
76
+ if (entry.openTime !== undefined) {
77
+ attrs.open_time = `${entry.openTime}`;
78
+ }
79
+ if (entry.closeTime !== undefined) {
80
+ attrs.close_time = `${entry.closeTime}`;
81
+ }
82
+ configNodes[i] = { tag: 'business_hours_config', attrs };
83
+ }
84
+ const hoursAttrs = {};
85
+ if (hours.timezone) {
86
+ hoursAttrs.timezone = hours.timezone;
87
+ }
88
+ return {
89
+ tag: 'business_hours',
90
+ attrs: hoursAttrs,
91
+ content: configNodes
92
+ };
93
+ }
94
+ export function buildGetVerifiedNameIq(jid) {
95
+ return buildIqNode('get', WA_DEFAULTS.HOST_DOMAIN, WA_XMLNS.BUSINESS, [
96
+ {
97
+ tag: 'verified_name',
98
+ attrs: { jid }
99
+ }
100
+ ]);
101
+ }
102
+ export function buildUpdateCoverPhotoIq(id, timestamp, token) {
103
+ return buildIqNode('set', WA_DEFAULTS.HOST_DOMAIN, WA_XMLNS.BUSINESS, [
104
+ {
105
+ tag: 'business_profile',
106
+ attrs: { v: '3', mutation_type: 'delta' },
107
+ content: [
108
+ {
109
+ tag: 'cover_photo',
110
+ attrs: { op: 'update', id, ts: timestamp, token }
111
+ }
112
+ ]
113
+ }
114
+ ]);
115
+ }
116
+ export function buildDeleteCoverPhotoIq(id) {
117
+ return buildIqNode('set', WA_DEFAULTS.HOST_DOMAIN, WA_XMLNS.BUSINESS, [
118
+ {
119
+ tag: 'business_profile',
120
+ attrs: { v: '3', mutation_type: 'delta' },
121
+ content: [
122
+ {
123
+ tag: 'cover_photo',
124
+ attrs: { op: 'delete', id }
125
+ }
126
+ ]
127
+ }
128
+ ]);
129
+ }
@@ -0,0 +1,370 @@
1
+ import { WA_DEFAULTS, WA_IQ_TYPES, WA_MESSAGE_TAGS, WA_MESSAGE_TYPES, WA_NODE_TAGS } from '../../../protocol/index.js';
2
+ import { isGroupOrBroadcastJid } from '../../../protocol/jid.js';
3
+ function buildListItemsNode(ids) {
4
+ if (ids.length < 2) {
5
+ return null;
6
+ }
7
+ const items = new Array(ids.length - 1);
8
+ for (let i = 1; i < ids.length; i += 1) {
9
+ items[i - 1] = {
10
+ tag: 'item',
11
+ attrs: { id: ids[i] }
12
+ };
13
+ }
14
+ return {
15
+ tag: WA_NODE_TAGS.LIST,
16
+ attrs: {},
17
+ content: items
18
+ };
19
+ }
20
+ function normalizeNackClass(stanzaTag) {
21
+ if (stanzaTag === WA_MESSAGE_TAGS.MESSAGE) {
22
+ return WA_MESSAGE_TYPES.ACK_CLASS_MESSAGE;
23
+ }
24
+ if (stanzaTag === WA_MESSAGE_TAGS.RECEIPT) {
25
+ return 'receipt';
26
+ }
27
+ if (stanzaTag === WA_NODE_TAGS.NOTIFICATION) {
28
+ return WA_NODE_TAGS.NOTIFICATION;
29
+ }
30
+ return stanzaTag;
31
+ }
32
+ export function buildAckNode(input) {
33
+ if (input.kind === 'notification') {
34
+ const attrs = {
35
+ to: input.node.attrs.from ?? WA_DEFAULTS.HOST_DOMAIN,
36
+ class: WA_NODE_TAGS.NOTIFICATION
37
+ };
38
+ const includeType = input.includeType ?? true;
39
+ if (includeType) {
40
+ attrs.type = input.typeOverride ?? input.node.attrs.type ?? WA_NODE_TAGS.NOTIFICATION;
41
+ }
42
+ if (input.node.attrs.id) {
43
+ attrs.id = input.node.attrs.id;
44
+ }
45
+ if (input.includeParticipant && input.node.attrs.participant) {
46
+ attrs.participant = input.node.attrs.participant;
47
+ }
48
+ return {
49
+ tag: WA_MESSAGE_TAGS.ACK,
50
+ attrs,
51
+ content: input.content
52
+ };
53
+ }
54
+ if (input.kind === 'message') {
55
+ const attrs = {
56
+ id: input.id,
57
+ to: input.to,
58
+ class: WA_MESSAGE_TYPES.ACK_CLASS_MESSAGE
59
+ };
60
+ const type = input.typeOverride ?? input.node.attrs.type;
61
+ if (type) {
62
+ attrs.type = type;
63
+ }
64
+ const participant = input.participant ?? input.node.attrs.participant;
65
+ if (participant) {
66
+ attrs.participant = participant;
67
+ }
68
+ if (input.recipient) {
69
+ attrs.recipient = input.recipient;
70
+ }
71
+ if (input.from) {
72
+ attrs.from = input.from;
73
+ }
74
+ return {
75
+ tag: WA_MESSAGE_TAGS.ACK,
76
+ attrs
77
+ };
78
+ }
79
+ if (input.kind === 'aggregate_message') {
80
+ if (input.ids.length === 0) {
81
+ throw new Error('aggregate message ack requires at least one id');
82
+ }
83
+ const attrs = {
84
+ id: input.ids[0],
85
+ to: input.to,
86
+ class: WA_MESSAGE_TYPES.ACK_CLASS_MESSAGE,
87
+ type: input.type ?? 'text'
88
+ };
89
+ if (input.recipient) {
90
+ attrs.recipient = input.recipient;
91
+ }
92
+ if (input.participant) {
93
+ attrs.participant = input.participant;
94
+ }
95
+ const listNode = buildListItemsNode(input.ids);
96
+ return {
97
+ tag: WA_MESSAGE_TAGS.ACK,
98
+ attrs,
99
+ content: listNode ? [listNode] : undefined
100
+ };
101
+ }
102
+ if (input.kind === 'nack') {
103
+ const attrs = {
104
+ id: input.id,
105
+ to: input.to,
106
+ class: normalizeNackClass(input.stanzaTag),
107
+ error: String(input.error)
108
+ };
109
+ if (input.type) {
110
+ attrs.type = input.type;
111
+ }
112
+ if (input.participant) {
113
+ attrs.participant = input.participant;
114
+ }
115
+ const content = input.failureReason === undefined
116
+ ? undefined
117
+ : [
118
+ {
119
+ tag: 'meta',
120
+ attrs: {
121
+ failure_reason: String(input.failureReason)
122
+ }
123
+ }
124
+ ];
125
+ return {
126
+ tag: WA_MESSAGE_TAGS.ACK,
127
+ attrs,
128
+ content
129
+ };
130
+ }
131
+ if (input.kind === 'custom') {
132
+ const attrs = {
133
+ class: input.ackClass,
134
+ to: input.to
135
+ };
136
+ if (input.id) {
137
+ attrs.id = input.id;
138
+ }
139
+ if (input.type) {
140
+ attrs.type = input.type;
141
+ }
142
+ if (input.participant) {
143
+ attrs.participant = input.participant;
144
+ }
145
+ if (input.recipient) {
146
+ attrs.recipient = input.recipient;
147
+ }
148
+ if (input.from) {
149
+ attrs.from = input.from;
150
+ }
151
+ if (input.error !== undefined) {
152
+ attrs.error = String(input.error);
153
+ }
154
+ return {
155
+ tag: WA_MESSAGE_TAGS.ACK,
156
+ attrs,
157
+ content: input.content
158
+ };
159
+ }
160
+ const attrs = {
161
+ class: 'receipt'
162
+ };
163
+ if (input.retryType) {
164
+ attrs.type = input.typeOverride ?? WA_MESSAGE_TYPES.RECEIPT_TYPE_RETRY;
165
+ }
166
+ else if (input.node.attrs.type) {
167
+ attrs.type = input.node.attrs.type;
168
+ }
169
+ if (input.node.attrs.id) {
170
+ attrs.id = input.node.attrs.id;
171
+ }
172
+ if (input.node.attrs.from) {
173
+ attrs.to = input.node.attrs.from;
174
+ }
175
+ if (input.retryType) {
176
+ if (input.node.attrs.participant) {
177
+ attrs.participant = input.node.attrs.participant;
178
+ }
179
+ }
180
+ else if ((input.includeParticipant ?? true) &&
181
+ input.node.attrs.participant &&
182
+ (!input.node.attrs.from || input.node.attrs.participant !== input.node.attrs.from)) {
183
+ attrs.participant = input.node.attrs.participant;
184
+ }
185
+ if (input.includeRecipient && input.node.attrs.recipient) {
186
+ attrs.recipient = input.node.attrs.recipient;
187
+ }
188
+ return {
189
+ tag: WA_MESSAGE_TAGS.ACK,
190
+ attrs
191
+ };
192
+ }
193
+ export function buildReceiptNode(input) {
194
+ if (input.kind === 'delivery') {
195
+ const attrs = {
196
+ id: input.id,
197
+ to: input.to
198
+ };
199
+ if (input.node.attrs.participant && isGroupOrBroadcastJid(input.to)) {
200
+ attrs.participant = input.node.attrs.participant;
201
+ }
202
+ if (input.node.attrs.category === 'peer') {
203
+ attrs.type = WA_MESSAGE_TYPES.RECEIPT_TYPE_PEER;
204
+ }
205
+ return {
206
+ tag: WA_MESSAGE_TAGS.RECEIPT,
207
+ attrs
208
+ };
209
+ }
210
+ if (input.kind === 'outbound') {
211
+ const attrs = {
212
+ id: input.id,
213
+ to: input.to
214
+ };
215
+ if (input.type) {
216
+ attrs.type = input.type;
217
+ }
218
+ if (input.participant) {
219
+ attrs.participant = input.participant;
220
+ }
221
+ if (input.recipient) {
222
+ attrs.recipient = input.recipient;
223
+ }
224
+ if (input.category) {
225
+ attrs.category = input.category;
226
+ }
227
+ if (input.from) {
228
+ attrs.from = input.from;
229
+ }
230
+ if (input.t) {
231
+ attrs.t = input.t;
232
+ }
233
+ if (input.peerParticipantPn) {
234
+ attrs.peer_participant_pn = input.peerParticipantPn;
235
+ }
236
+ const content = input.content ? [...input.content] : [];
237
+ const listNode = input.listIds ? buildListItemsNode(input.listIds) : null;
238
+ if (listNode) {
239
+ content.push(listNode);
240
+ }
241
+ return {
242
+ tag: WA_MESSAGE_TAGS.RECEIPT,
243
+ attrs,
244
+ content: content.length > 0 ? content : undefined
245
+ };
246
+ }
247
+ if (input.kind === 'retry_custom') {
248
+ const attrs = {
249
+ id: input.id,
250
+ to: input.to,
251
+ type: WA_MESSAGE_TYPES.RECEIPT_TYPE_RETRY
252
+ };
253
+ if (input.participant) {
254
+ attrs.participant = input.participant;
255
+ }
256
+ if (input.recipient) {
257
+ attrs.recipient = input.recipient;
258
+ }
259
+ if (input.categoryPeer) {
260
+ attrs.category = 'peer';
261
+ }
262
+ return {
263
+ tag: WA_MESSAGE_TAGS.RECEIPT,
264
+ attrs,
265
+ content: input.content
266
+ };
267
+ }
268
+ if (input.kind === 'server_error') {
269
+ const attrs = {
270
+ id: input.id,
271
+ to: input.to,
272
+ type: WA_MESSAGE_TYPES.RECEIPT_TYPE_SERVER_ERROR
273
+ };
274
+ if (input.categoryPeer) {
275
+ attrs.category = 'peer';
276
+ }
277
+ const content = [
278
+ {
279
+ tag: 'encrypt',
280
+ attrs: {},
281
+ content: [
282
+ {
283
+ tag: 'enc_p',
284
+ attrs: {},
285
+ content: input.encryptCiphertext
286
+ },
287
+ {
288
+ tag: 'enc_iv',
289
+ attrs: {},
290
+ content: input.encryptIv
291
+ }
292
+ ]
293
+ }
294
+ ];
295
+ if (input.rmrJid || input.rmrFromMe !== undefined || input.rmrParticipant) {
296
+ const rmrAttrs = {};
297
+ if (input.rmrJid) {
298
+ rmrAttrs.jid = input.rmrJid;
299
+ }
300
+ if (input.rmrFromMe !== undefined) {
301
+ rmrAttrs.from_me = String(input.rmrFromMe);
302
+ }
303
+ if (input.rmrParticipant) {
304
+ rmrAttrs.participant = input.rmrParticipant;
305
+ }
306
+ content.push({
307
+ tag: 'rmr',
308
+ attrs: rmrAttrs
309
+ });
310
+ }
311
+ return {
312
+ tag: WA_MESSAGE_TAGS.RECEIPT,
313
+ attrs,
314
+ content
315
+ };
316
+ }
317
+ if (input.kind === 'custom') {
318
+ return {
319
+ tag: WA_MESSAGE_TAGS.RECEIPT,
320
+ attrs: {
321
+ ...input.attrs
322
+ },
323
+ content: input.content
324
+ };
325
+ }
326
+ const attrs = {
327
+ id: input.id,
328
+ to: input.to,
329
+ type: WA_MESSAGE_TYPES.RECEIPT_TYPE_RETRY
330
+ };
331
+ if (input.node.attrs.category === 'peer') {
332
+ attrs.category = 'peer';
333
+ }
334
+ if (input.node.attrs.recipient && input.node.attrs.category !== 'peer') {
335
+ attrs.recipient = input.node.attrs.recipient;
336
+ }
337
+ if (input.node.attrs.participant && isGroupOrBroadcastJid(input.to)) {
338
+ attrs.participant = input.node.attrs.participant;
339
+ }
340
+ const retryCount = input.retryCount ?? 1;
341
+ const normalizedRetryCount = Number.isSafeInteger(retryCount) && retryCount > 0 ? retryCount : 1;
342
+ const retryAttrs = {
343
+ count: String(normalizedRetryCount),
344
+ id: input.id
345
+ };
346
+ const timestamp = input.node.attrs.t;
347
+ if (timestamp) {
348
+ retryAttrs.t = timestamp;
349
+ }
350
+ return {
351
+ tag: WA_MESSAGE_TAGS.RECEIPT,
352
+ attrs,
353
+ content: [
354
+ {
355
+ tag: 'retry',
356
+ attrs: retryAttrs
357
+ }
358
+ ]
359
+ };
360
+ }
361
+ export function buildIqResultNode(iqNode) {
362
+ return {
363
+ tag: WA_NODE_TAGS.IQ,
364
+ attrs: {
365
+ ...(iqNode.attrs.id ? { id: iqNode.attrs.id } : {}),
366
+ to: iqNode.attrs.from ?? WA_DEFAULTS.HOST_DOMAIN,
367
+ type: WA_IQ_TYPES.RESULT
368
+ }
369
+ };
370
+ }
@@ -1,8 +1,11 @@
1
1
  export { buildAccountBlocklistSyncIq, buildAccountDevicesSyncIq, buildAccountPictureSyncIq, buildAccountPrivacySyncIq, buildClearDirtyBitsIq, buildGroupsDirtySyncIq, buildNewsletterMetadataSyncIq } from '../../node/builders/account-sync.js';
2
- export { buildCompanionFinishRequestNode, buildCompanionHelloRequestNode, buildGetCountryCodeRequestNode, buildIqResultNode, buildNotificationAckNode } from '../../node/builders/pairing.js';
2
+ export { buildCompanionFinishRequestNode, buildCompanionHelloRequestNode, buildGetCountryCodeRequestNode } from '../../node/builders/pairing.js';
3
+ export { buildAckNode, buildReceiptNode, buildIqResultNode } from '../../node/builders/global.js';
3
4
  export { buildMediaConnIq } from '../../node/builders/media.js';
4
- export { buildDirectMessageFanoutNode, buildGroupDirectMessageNode, buildGroupRetryMessageNode, buildGroupSenderKeyMessageNode, buildInboundDeliveryReceiptNode, buildInboundMessageAckNode, buildInboundReceiptAckNode, buildInboundRetryReceiptNode, buildInboundRetryReceiptAckNode } from '../../node/builders/message.js';
5
+ export { buildDirectMessageFanoutNode, buildGroupRetryMessageNode, buildGroupSenderKeyMessageNode, buildMetaNode } from '../../node/builders/message.js';
5
6
  export { buildRetryReceiptNode } from '../../node/builders/retry.js';
6
7
  export { buildMissingPreKeysFetchIq, buildPreKeyUploadIq, buildSignedPreKeyRotateIq } from '../../node/builders/prekeys.js';
7
8
  export { buildCreateGroupIq, buildGroupParticipantChangeIq, buildLeaveGroupIq } from '../../node/builders/group.js';
8
9
  export { buildUsyncIq, buildUsyncUserNode } from '../../node/builders/usync.js';
10
+ export { buildDeleteProfilePictureIq, buildGetProfilePictureIq, buildGetStatusUsyncQueryNodes, buildSetProfilePictureIq } from '../../node/builders/profile.js';
11
+ export { buildDeleteCoverPhotoIq, buildEditBusinessProfileIq, buildGetBusinessProfileIq, buildGetVerifiedNameIq, buildUpdateCoverPhotoIq, WA_BUSINESS_PROFILE_VERSION } from '../../node/builders/business.js';