effect 4.0.7 → 4.1.1

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 (863) hide show
  1. package/README.md +31 -1
  2. package/THIRD_PARTY_NOTICES.md +62 -0
  3. package/dist/BigDecimal.d.ts +139 -7
  4. package/dist/BigDecimal.d.ts.map +1 -1
  5. package/dist/BigDecimal.js +86 -14
  6. package/dist/BigDecimal.js.map +1 -1
  7. package/dist/Channel.d.ts +12 -6
  8. package/dist/Channel.d.ts.map +1 -1
  9. package/dist/Channel.js +9 -3
  10. package/dist/Channel.js.map +1 -1
  11. package/dist/Config.d.ts +7 -1
  12. package/dist/Config.d.ts.map +1 -1
  13. package/dist/Config.js.map +1 -1
  14. package/dist/Context.d.ts +18 -1
  15. package/dist/Context.d.ts.map +1 -1
  16. package/dist/Context.js +27 -8
  17. package/dist/Context.js.map +1 -1
  18. package/dist/Cron.d.ts +81 -11
  19. package/dist/Cron.d.ts.map +1 -1
  20. package/dist/Cron.js +101 -26
  21. package/dist/Cron.js.map +1 -1
  22. package/dist/Duration.d.ts +78 -0
  23. package/dist/Duration.d.ts.map +1 -1
  24. package/dist/Duration.js +123 -0
  25. package/dist/Duration.js.map +1 -1
  26. package/dist/Effect.d.ts +164 -7
  27. package/dist/Effect.d.ts.map +1 -1
  28. package/dist/Effect.js +11 -1
  29. package/dist/Effect.js.map +1 -1
  30. package/dist/Equal.d.ts +2 -2
  31. package/dist/Equal.d.ts.map +1 -1
  32. package/dist/Equal.js +3 -3
  33. package/dist/Equal.js.map +1 -1
  34. package/dist/FileSystem.d.ts +59 -4
  35. package/dist/FileSystem.d.ts.map +1 -1
  36. package/dist/FileSystem.js +9 -2
  37. package/dist/FileSystem.js.map +1 -1
  38. package/dist/Glob.d.ts +165 -0
  39. package/dist/Glob.d.ts.map +1 -0
  40. package/dist/Glob.js +127 -0
  41. package/dist/Glob.js.map +1 -0
  42. package/dist/Hash.d.ts +3 -2
  43. package/dist/Hash.d.ts.map +1 -1
  44. package/dist/Hash.js +5 -4
  45. package/dist/Hash.js.map +1 -1
  46. package/dist/Iterable.d.ts.map +1 -1
  47. package/dist/Iterable.js +11 -8
  48. package/dist/Iterable.js.map +1 -1
  49. package/dist/Match.d.ts +86 -0
  50. package/dist/Match.d.ts.map +1 -1
  51. package/dist/Match.js +72 -0
  52. package/dist/Match.js.map +1 -1
  53. package/dist/Path.d.ts.map +1 -1
  54. package/dist/Path.js +5 -1
  55. package/dist/Path.js.map +1 -1
  56. package/dist/Pool.d.ts +51 -0
  57. package/dist/Pool.d.ts.map +1 -1
  58. package/dist/Pool.js +61 -10
  59. package/dist/Pool.js.map +1 -1
  60. package/dist/Random.d.ts.map +1 -1
  61. package/dist/Random.js +3 -3
  62. package/dist/Random.js.map +1 -1
  63. package/dist/RcMap.d.ts.map +1 -1
  64. package/dist/RcMap.js +8 -2
  65. package/dist/RcMap.js.map +1 -1
  66. package/dist/Schedule.d.ts +18 -1
  67. package/dist/Schedule.d.ts.map +1 -1
  68. package/dist/Schedule.js +7 -2
  69. package/dist/Schedule.js.map +1 -1
  70. package/dist/Schema.d.ts +668 -42
  71. package/dist/Schema.d.ts.map +1 -1
  72. package/dist/Schema.js +652 -1
  73. package/dist/Schema.js.map +1 -1
  74. package/dist/SchemaGetter.d.ts +6 -1
  75. package/dist/SchemaGetter.d.ts.map +1 -1
  76. package/dist/SchemaGetter.js +22 -11
  77. package/dist/SchemaGetter.js.map +1 -1
  78. package/dist/SchemaRepresentation.d.ts +18 -2
  79. package/dist/SchemaRepresentation.d.ts.map +1 -1
  80. package/dist/SchemaRepresentation.js +20 -2
  81. package/dist/SchemaRepresentation.js.map +1 -1
  82. package/dist/SchemaTransformation.d.ts +10 -5
  83. package/dist/SchemaTransformation.d.ts.map +1 -1
  84. package/dist/SchemaTransformation.js +8 -5
  85. package/dist/SchemaTransformation.js.map +1 -1
  86. package/dist/ScopedCache.d.ts.map +1 -1
  87. package/dist/ScopedCache.js +5 -7
  88. package/dist/ScopedCache.js.map +1 -1
  89. package/dist/Semaphore.d.ts +130 -0
  90. package/dist/Semaphore.d.ts.map +1 -1
  91. package/dist/Semaphore.js +40 -0
  92. package/dist/Semaphore.js.map +1 -1
  93. package/dist/Stream.d.ts +13 -4
  94. package/dist/Stream.d.ts.map +1 -1
  95. package/dist/Stream.js +9 -0
  96. package/dist/Stream.js.map +1 -1
  97. package/dist/Terminal.d.ts +18 -1
  98. package/dist/Terminal.d.ts.map +1 -1
  99. package/dist/Terminal.js +1 -1
  100. package/dist/Terminal.js.map +1 -1
  101. package/dist/ai/AiError.d.ts +43 -116
  102. package/dist/ai/AiError.d.ts.map +1 -1
  103. package/dist/ai/AiError.js +53 -72
  104. package/dist/ai/AiError.js.map +1 -1
  105. package/dist/ai/Decision.d.ts +196 -15
  106. package/dist/ai/Decision.d.ts.map +1 -1
  107. package/dist/ai/Decision.js +130 -0
  108. package/dist/ai/Decision.js.map +1 -1
  109. package/dist/ai/DecisionModel.d.ts +54 -13
  110. package/dist/ai/DecisionModel.d.ts.map +1 -1
  111. package/dist/ai/DecisionModel.js +123 -12
  112. package/dist/ai/DecisionModel.js.map +1 -1
  113. package/dist/ai/McpClient.d.ts +171 -19
  114. package/dist/ai/McpClient.d.ts.map +1 -1
  115. package/dist/ai/McpClient.js +277 -66
  116. package/dist/ai/McpClient.js.map +1 -1
  117. package/dist/ai/McpSchema.d.ts +108 -0
  118. package/dist/ai/McpSchema.d.ts.map +1 -1
  119. package/dist/ai/McpSchema.js +99 -0
  120. package/dist/ai/McpSchema.js.map +1 -1
  121. package/dist/ai/McpServer.d.ts +744 -29
  122. package/dist/ai/McpServer.d.ts.map +1 -1
  123. package/dist/ai/McpServer.js +763 -136
  124. package/dist/ai/McpServer.js.map +1 -1
  125. package/dist/ai/McpTest.d.ts +130 -0
  126. package/dist/ai/McpTest.d.ts.map +1 -0
  127. package/dist/ai/McpTest.js +237 -0
  128. package/dist/ai/McpTest.js.map +1 -0
  129. package/dist/ai/Prompt.d.ts.map +1 -1
  130. package/dist/ai/Prompt.js +20 -11
  131. package/dist/ai/Prompt.js.map +1 -1
  132. package/dist/ai/Response.d.ts +1 -25
  133. package/dist/ai/Response.d.ts.map +1 -1
  134. package/dist/ai/Response.js +1 -10
  135. package/dist/ai/Response.js.map +1 -1
  136. package/dist/ai/Tool.d.ts +19 -1
  137. package/dist/ai/Tool.d.ts.map +1 -1
  138. package/dist/ai/Tool.js +5 -7
  139. package/dist/ai/Tool.js.map +1 -1
  140. package/dist/ai/index.d.ts +5 -0
  141. package/dist/ai/index.d.ts.map +1 -1
  142. package/dist/ai/index.js +5 -0
  143. package/dist/ai/index.js.map +1 -1
  144. package/dist/ai/internal/mcpCore.js +89 -15
  145. package/dist/ai/internal/mcpCore.js.map +1 -1
  146. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +7 -6
  147. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  148. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +7 -6
  149. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  150. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +7 -6
  151. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  152. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +7 -6
  153. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  154. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +60 -17
  155. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  156. package/dist/ai/internal/mcpProtocol.js +25 -0
  157. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  158. package/dist/ai/internal/mcpRuntime.js +8 -6
  159. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  160. package/dist/ai/internal/mcpSkills.d.ts +2 -0
  161. package/dist/ai/internal/mcpSkills.d.ts.map +1 -0
  162. package/dist/ai/internal/mcpSkills.js +428 -0
  163. package/dist/ai/internal/mcpSkills.js.map +1 -0
  164. package/dist/ai/internal/mcpStatefulRuntime.js +6 -1
  165. package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
  166. package/dist/cli/Argument.d.ts +6 -0
  167. package/dist/cli/Argument.d.ts.map +1 -1
  168. package/dist/cli/Argument.js +2 -0
  169. package/dist/cli/Argument.js.map +1 -1
  170. package/dist/cli/CliOutput.d.ts +65 -1
  171. package/dist/cli/CliOutput.d.ts.map +1 -1
  172. package/dist/cli/CliOutput.js +94 -37
  173. package/dist/cli/CliOutput.js.map +1 -1
  174. package/dist/cli/Command.d.ts +23 -0
  175. package/dist/cli/Command.d.ts.map +1 -1
  176. package/dist/cli/Command.js +8 -0
  177. package/dist/cli/Command.js.map +1 -1
  178. package/dist/cli/Flag.d.ts +107 -0
  179. package/dist/cli/Flag.d.ts.map +1 -1
  180. package/dist/cli/Flag.js +37 -0
  181. package/dist/cli/Flag.js.map +1 -1
  182. package/dist/cli/HelpDoc.d.ts +15 -1
  183. package/dist/cli/HelpDoc.d.ts.map +1 -1
  184. package/dist/cli/Param.d.ts +6 -0
  185. package/dist/cli/Param.d.ts.map +1 -1
  186. package/dist/cli/Param.js +2 -0
  187. package/dist/cli/Param.js.map +1 -1
  188. package/dist/cli/Primitive.d.ts +14 -0
  189. package/dist/cli/Primitive.d.ts.map +1 -1
  190. package/dist/cli/Primitive.js +15 -1
  191. package/dist/cli/Primitive.js.map +1 -1
  192. package/dist/cli/Prompt.d.ts +1 -0
  193. package/dist/cli/Prompt.d.ts.map +1 -1
  194. package/dist/cli/Prompt.js +1 -0
  195. package/dist/cli/Prompt.js.map +1 -1
  196. package/dist/cli/internal/help.d.ts.map +1 -1
  197. package/dist/cli/internal/help.js +17 -10
  198. package/dist/cli/internal/help.js.map +1 -1
  199. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  200. package/dist/cluster/ClusterWorkflowEngine.js +15 -5
  201. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  202. package/dist/cluster/Reply.d.ts +1 -1
  203. package/dist/cluster/Reply.d.ts.map +1 -1
  204. package/dist/cluster/Reply.js.map +1 -1
  205. package/dist/cluster/Sharding.d.ts.map +1 -1
  206. package/dist/cluster/Sharding.js +93 -28
  207. package/dist/cluster/Sharding.js.map +1 -1
  208. package/dist/cluster/ShardingConfig.d.ts +72 -6
  209. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  210. package/dist/cluster/ShardingConfig.js +4 -0
  211. package/dist/cluster/ShardingConfig.js.map +1 -1
  212. package/dist/cluster/SingleRunner.d.ts +3 -3
  213. package/dist/cluster/SingleRunner.d.ts.map +1 -1
  214. package/dist/cluster/SingleRunner.js +1 -1
  215. package/dist/cluster/SqlMessageStorage.d.ts +37 -6
  216. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  217. package/dist/cluster/SqlMessageStorage.js +34 -7
  218. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  219. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  220. package/dist/cluster/SqlRunnerStorage.js +23 -8
  221. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  222. package/dist/cluster/internal/entityManager.js +15 -7
  223. package/dist/cluster/internal/entityManager.js.map +1 -1
  224. package/dist/crypto/Aead.d.ts +323 -0
  225. package/dist/crypto/Aead.d.ts.map +1 -0
  226. package/dist/crypto/Aead.js +331 -0
  227. package/dist/crypto/Aead.js.map +1 -0
  228. package/dist/crypto/Cipher.d.ts +236 -0
  229. package/dist/crypto/Cipher.d.ts.map +1 -0
  230. package/dist/crypto/Cipher.js +233 -0
  231. package/dist/crypto/Cipher.js.map +1 -0
  232. package/dist/crypto/CryptoError.d.ts +212 -0
  233. package/dist/crypto/CryptoError.d.ts.map +1 -0
  234. package/dist/crypto/CryptoError.js +202 -0
  235. package/dist/crypto/CryptoError.js.map +1 -0
  236. package/dist/crypto/Digest.d.ts +143 -0
  237. package/dist/crypto/Digest.d.ts.map +1 -0
  238. package/dist/crypto/Digest.js +146 -0
  239. package/dist/crypto/Digest.js.map +1 -0
  240. package/dist/crypto/Kdf.d.ts +220 -0
  241. package/dist/crypto/Kdf.d.ts.map +1 -0
  242. package/dist/crypto/Kdf.js +212 -0
  243. package/dist/crypto/Kdf.js.map +1 -0
  244. package/dist/crypto/KeyAgreement.d.ts +324 -0
  245. package/dist/crypto/KeyAgreement.d.ts.map +1 -0
  246. package/dist/crypto/KeyAgreement.js +303 -0
  247. package/dist/crypto/KeyAgreement.js.map +1 -0
  248. package/dist/crypto/KeyFormat.d.ts +341 -0
  249. package/dist/crypto/KeyFormat.d.ts.map +1 -0
  250. package/dist/crypto/KeyFormat.js +556 -0
  251. package/dist/crypto/KeyFormat.js.map +1 -0
  252. package/dist/crypto/KeyWrap.d.ts +390 -0
  253. package/dist/crypto/KeyWrap.d.ts.map +1 -0
  254. package/dist/crypto/KeyWrap.js +381 -0
  255. package/dist/crypto/KeyWrap.js.map +1 -0
  256. package/dist/crypto/Mac.d.ts +278 -0
  257. package/dist/crypto/Mac.d.ts.map +1 -0
  258. package/dist/crypto/Mac.js +288 -0
  259. package/dist/crypto/Mac.js.map +1 -0
  260. package/dist/crypto/SecureRandom.d.ts +340 -0
  261. package/dist/crypto/SecureRandom.d.ts.map +1 -0
  262. package/dist/crypto/SecureRandom.js +257 -0
  263. package/dist/crypto/SecureRandom.js.map +1 -0
  264. package/dist/crypto/Signature.d.ts +449 -0
  265. package/dist/crypto/Signature.d.ts.map +1 -0
  266. package/dist/crypto/Signature.js +484 -0
  267. package/dist/crypto/Signature.js.map +1 -0
  268. package/dist/crypto/WebCrypto.d.ts +80 -0
  269. package/dist/crypto/WebCrypto.d.ts.map +1 -0
  270. package/dist/crypto/WebCrypto.js +63 -0
  271. package/dist/crypto/WebCrypto.js.map +1 -0
  272. package/dist/crypto/index.d.ts +65 -0
  273. package/dist/crypto/index.d.ts.map +1 -0
  274. package/dist/crypto/index.js +66 -0
  275. package/dist/crypto/index.js.map +1 -0
  276. package/dist/crypto/internal/asymmetric.d.ts +2 -0
  277. package/dist/crypto/internal/asymmetric.d.ts.map +1 -0
  278. package/dist/crypto/internal/asymmetric.js +210 -0
  279. package/dist/crypto/internal/asymmetric.js.map +1 -0
  280. package/dist/crypto/internal/chacha.d.ts +46 -0
  281. package/dist/crypto/internal/chacha.d.ts.map +1 -0
  282. package/dist/crypto/internal/chacha.js +885 -0
  283. package/dist/crypto/internal/chacha.js.map +1 -0
  284. package/dist/crypto/internal/der.d.ts +6 -0
  285. package/dist/crypto/internal/der.d.ts.map +1 -0
  286. package/dist/crypto/internal/der.js +86 -0
  287. package/dist/crypto/internal/der.js.map +1 -0
  288. package/dist/crypto/internal/digest.d.ts +2 -0
  289. package/dist/crypto/internal/digest.d.ts.map +1 -0
  290. package/dist/crypto/internal/digest.js +15 -0
  291. package/dist/crypto/internal/digest.js.map +1 -0
  292. package/dist/crypto/internal/key.d.ts +2 -0
  293. package/dist/crypto/internal/key.d.ts.map +1 -0
  294. package/dist/crypto/internal/key.js +171 -0
  295. package/dist/crypto/internal/key.js.map +1 -0
  296. package/dist/crypto/internal/md5.d.ts +39 -0
  297. package/dist/crypto/internal/md5.d.ts.map +1 -0
  298. package/dist/crypto/internal/md5.js +179 -0
  299. package/dist/crypto/internal/md5.js.map +1 -0
  300. package/dist/crypto/internal/webCrypto.d.ts +2 -0
  301. package/dist/crypto/internal/webCrypto.d.ts.map +1 -0
  302. package/dist/crypto/internal/webCrypto.js +111 -0
  303. package/dist/crypto/internal/webCrypto.js.map +1 -0
  304. package/dist/encoding/Base64Url.d.ts.map +1 -1
  305. package/dist/encoding/Base64Url.js +29 -5
  306. package/dist/encoding/Base64Url.js.map +1 -1
  307. package/dist/encoding/Csv.d.ts +608 -0
  308. package/dist/encoding/Csv.d.ts.map +1 -0
  309. package/dist/encoding/Csv.js +718 -0
  310. package/dist/encoding/Csv.js.map +1 -0
  311. package/dist/encoding/Hex.d.ts +3 -2
  312. package/dist/encoding/Hex.d.ts.map +1 -1
  313. package/dist/encoding/Hex.js +3 -2
  314. package/dist/encoding/Hex.js.map +1 -1
  315. package/dist/encoding/Ndjson.d.ts +5 -4
  316. package/dist/encoding/Ndjson.d.ts.map +1 -1
  317. package/dist/encoding/Ndjson.js +6 -5
  318. package/dist/encoding/Ndjson.js.map +1 -1
  319. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  320. package/dist/encoding/SchemaBinary.js +42 -4
  321. package/dist/encoding/SchemaBinary.js.map +1 -1
  322. package/dist/encoding/Sse.d.ts +3 -1
  323. package/dist/encoding/Sse.d.ts.map +1 -1
  324. package/dist/encoding/Sse.js +5 -3
  325. package/dist/encoding/Sse.js.map +1 -1
  326. package/dist/encoding/Toml.d.ts +17 -3
  327. package/dist/encoding/Toml.d.ts.map +1 -1
  328. package/dist/encoding/Toml.js +104 -16
  329. package/dist/encoding/Toml.js.map +1 -1
  330. package/dist/encoding/Yaml.d.ts +8 -1
  331. package/dist/encoding/Yaml.d.ts.map +1 -1
  332. package/dist/encoding/Yaml.js +54 -18
  333. package/dist/encoding/Yaml.js.map +1 -1
  334. package/dist/encoding/index.d.ts +5 -0
  335. package/dist/encoding/index.d.ts.map +1 -1
  336. package/dist/encoding/index.js +5 -0
  337. package/dist/encoding/index.js.map +1 -1
  338. package/dist/eventlog/EventJournal.d.ts.map +1 -1
  339. package/dist/eventlog/EventJournal.js +6 -3
  340. package/dist/eventlog/EventJournal.js.map +1 -1
  341. package/dist/eventlog/EventLog.d.ts +126 -4
  342. package/dist/eventlog/EventLog.d.ts.map +1 -1
  343. package/dist/eventlog/EventLog.js +207 -12
  344. package/dist/eventlog/EventLog.js.map +1 -1
  345. package/dist/eventlog/EventLogEncryption.d.ts +41 -4
  346. package/dist/eventlog/EventLogEncryption.d.ts.map +1 -1
  347. package/dist/eventlog/EventLogEncryption.js +83 -64
  348. package/dist/eventlog/EventLogEncryption.js.map +1 -1
  349. package/dist/eventlog/EventLogMessage.d.ts +279 -0
  350. package/dist/eventlog/EventLogMessage.d.ts.map +1 -1
  351. package/dist/eventlog/EventLogMessage.js +217 -1
  352. package/dist/eventlog/EventLogMessage.js.map +1 -1
  353. package/dist/eventlog/EventLogRemote.d.ts +200 -28
  354. package/dist/eventlog/EventLogRemote.d.ts.map +1 -1
  355. package/dist/eventlog/EventLogRemote.js +186 -16
  356. package/dist/eventlog/EventLogRemote.js.map +1 -1
  357. package/dist/eventlog/EventLogServer.d.ts +10 -1
  358. package/dist/eventlog/EventLogServer.d.ts.map +1 -1
  359. package/dist/eventlog/EventLogServer.js +45 -22
  360. package/dist/eventlog/EventLogServer.js.map +1 -1
  361. package/dist/eventlog/EventLogServerEncrypted.d.ts +336 -5
  362. package/dist/eventlog/EventLogServerEncrypted.d.ts.map +1 -1
  363. package/dist/eventlog/EventLogServerEncrypted.js +769 -14
  364. package/dist/eventlog/EventLogServerEncrypted.js.map +1 -1
  365. package/dist/eventlog/EventLogServerUnencrypted.d.ts +17 -0
  366. package/dist/eventlog/EventLogServerUnencrypted.d.ts.map +1 -1
  367. package/dist/eventlog/EventLogServerUnencrypted.js +14 -2
  368. package/dist/eventlog/EventLogServerUnencrypted.js.map +1 -1
  369. package/dist/eventlog/EventLogSessionAuth.d.ts +26 -3
  370. package/dist/eventlog/EventLogSessionAuth.d.ts.map +1 -1
  371. package/dist/eventlog/EventLogSessionAuth.js +63 -64
  372. package/dist/eventlog/EventLogSessionAuth.js.map +1 -1
  373. package/dist/eventlog/EventRow.d.ts +4 -0
  374. package/dist/eventlog/EventRow.d.ts.map +1 -1
  375. package/dist/eventlog/EventRow.js +12 -2
  376. package/dist/eventlog/EventRow.js.map +1 -1
  377. package/dist/eventlog/SqlEventJournal.js +2 -2
  378. package/dist/eventlog/SqlEventJournal.js.map +1 -1
  379. package/dist/eventlog/SqlEventLogServerEncrypted.d.ts +21 -5
  380. package/dist/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
  381. package/dist/eventlog/SqlEventLogServerEncrypted.js +1048 -113
  382. package/dist/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  383. package/dist/eventlog/SqlEventLogServerUnencrypted.js +2 -2
  384. package/dist/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  385. package/dist/eventlog/internal/batches.d.ts +12 -0
  386. package/dist/eventlog/internal/batches.d.ts.map +1 -0
  387. package/dist/eventlog/internal/batches.js +26 -0
  388. package/dist/eventlog/internal/batches.js.map +1 -0
  389. package/dist/eventlog/internal/compaction.d.ts +38 -0
  390. package/dist/eventlog/internal/compaction.d.ts.map +1 -0
  391. package/dist/eventlog/internal/compaction.js +33 -0
  392. package/dist/eventlog/internal/compaction.js.map +1 -0
  393. package/dist/eventlog/internal/identityRootSecretDerivation.js +66 -67
  394. package/dist/eventlog/internal/identityRootSecretDerivation.js.map +1 -1
  395. package/dist/eventlog/internal/remoteCompaction.d.ts +31 -0
  396. package/dist/eventlog/internal/remoteCompaction.d.ts.map +1 -0
  397. package/dist/eventlog/internal/remoteCompaction.js +76 -0
  398. package/dist/eventlog/internal/remoteCompaction.js.map +1 -0
  399. package/dist/graphql/GraphQLClient.d.ts +3 -1
  400. package/dist/graphql/GraphQLClient.d.ts.map +1 -1
  401. package/dist/graphql/GraphQLClient.js.map +1 -1
  402. package/dist/graphql/GraphQLClientError.d.ts +14 -9
  403. package/dist/graphql/GraphQLClientError.d.ts.map +1 -1
  404. package/dist/graphql/GraphQLClientError.js +14 -21
  405. package/dist/graphql/GraphQLClientError.js.map +1 -1
  406. package/dist/graphql/GraphQLProtocol.d.ts +12 -3
  407. package/dist/graphql/GraphQLProtocol.d.ts.map +1 -1
  408. package/dist/graphql/GraphQLProtocol.js +4 -1
  409. package/dist/graphql/GraphQLProtocol.js.map +1 -1
  410. package/dist/http/Cookies.d.ts +172 -0
  411. package/dist/http/Cookies.d.ts.map +1 -1
  412. package/dist/http/Cookies.js +143 -1
  413. package/dist/http/Cookies.js.map +1 -1
  414. package/dist/http/FetchHttpClient.d.ts +26 -2
  415. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  416. package/dist/http/FetchHttpClient.js +78 -15
  417. package/dist/http/FetchHttpClient.js.map +1 -1
  418. package/dist/http/HttpClient.d.ts +268 -15
  419. package/dist/http/HttpClient.d.ts.map +1 -1
  420. package/dist/http/HttpClient.js +140 -7
  421. package/dist/http/HttpClient.js.map +1 -1
  422. package/dist/http/HttpClientRequest.d.ts +9 -5
  423. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  424. package/dist/http/HttpClientRequest.js +2 -3
  425. package/dist/http/HttpClientRequest.js.map +1 -1
  426. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  427. package/dist/http/HttpClientResponse.js +3 -2
  428. package/dist/http/HttpClientResponse.js.map +1 -1
  429. package/dist/http/HttpMethod.d.ts +7 -1
  430. package/dist/http/HttpMethod.d.ts.map +1 -1
  431. package/dist/http/HttpMethod.js +3 -8
  432. package/dist/http/HttpMethod.js.map +1 -1
  433. package/dist/http/HttpServerRequest.d.ts +5 -2
  434. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  435. package/dist/http/HttpServerRequest.js +44 -39
  436. package/dist/http/HttpServerRequest.js.map +1 -1
  437. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  438. package/dist/http/HttpServerResponse.js +3 -2
  439. package/dist/http/HttpServerResponse.js.map +1 -1
  440. package/dist/http/HttpTraceContext.d.ts +2 -1
  441. package/dist/http/HttpTraceContext.d.ts.map +1 -1
  442. package/dist/http/HttpTraceContext.js +7 -5
  443. package/dist/http/HttpTraceContext.js.map +1 -1
  444. package/dist/http/ProblemDetails.d.ts +96 -0
  445. package/dist/http/ProblemDetails.d.ts.map +1 -0
  446. package/dist/http/ProblemDetails.js +98 -0
  447. package/dist/http/ProblemDetails.js.map +1 -0
  448. package/dist/http/index.d.ts +5 -0
  449. package/dist/http/index.d.ts.map +1 -1
  450. package/dist/http/index.js +5 -0
  451. package/dist/http/index.js.map +1 -1
  452. package/dist/http/internal/decompression.js +3 -2
  453. package/dist/http/internal/decompression.js.map +1 -1
  454. package/dist/http/internal/mimeTypes.d.ts +4 -1
  455. package/dist/http/internal/mimeTypes.d.ts.map +1 -1
  456. package/dist/http/internal/mimeTypes.js +4 -1
  457. package/dist/http/internal/mimeTypes.js.map +1 -1
  458. package/dist/http/internal/urlParams.js +8 -0
  459. package/dist/http/internal/urlParams.js.map +1 -1
  460. package/dist/http-api/HttpApiBuilder.js +19 -5
  461. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  462. package/dist/http-api/HttpApiClient.d.ts +63 -0
  463. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  464. package/dist/http-api/HttpApiClient.js +51 -0
  465. package/dist/http-api/HttpApiClient.js.map +1 -1
  466. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  467. package/dist/http-api/HttpApiEndpoint.js +14 -5
  468. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  469. package/dist/http-api/HttpApiError.d.ts +185 -13
  470. package/dist/http-api/HttpApiError.d.ts.map +1 -1
  471. package/dist/http-api/HttpApiError.js +128 -0
  472. package/dist/http-api/HttpApiError.js.map +1 -1
  473. package/dist/http-api/HttpApiMiddleware.d.ts +64 -17
  474. package/dist/http-api/HttpApiMiddleware.d.ts.map +1 -1
  475. package/dist/http-api/HttpApiMiddleware.js +85 -1
  476. package/dist/http-api/HttpApiMiddleware.js.map +1 -1
  477. package/dist/http-api/HttpApiSchema.d.ts +76 -14
  478. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  479. package/dist/http-api/HttpApiSchema.js +54 -1
  480. package/dist/http-api/HttpApiSchema.js.map +1 -1
  481. package/dist/index.d.ts +5 -5
  482. package/dist/index.d.ts.map +1 -1
  483. package/dist/index.js +5 -5
  484. package/dist/index.js.map +1 -1
  485. package/dist/internal/dateTime.js +49 -24
  486. package/dist/internal/dateTime.js.map +1 -1
  487. package/dist/internal/effect.js +35 -14
  488. package/dist/internal/effect.js.map +1 -1
  489. package/dist/internal/glob.d.ts +2 -0
  490. package/dist/internal/glob.d.ts.map +1 -0
  491. package/dist/internal/glob.js +808 -0
  492. package/dist/internal/glob.js.map +1 -0
  493. package/dist/internal/graphql.js +21 -7
  494. package/dist/internal/graphql.js.map +1 -1
  495. package/dist/internal/graphqlHeaders.d.ts +7 -0
  496. package/dist/internal/graphqlHeaders.d.ts.map +1 -1
  497. package/dist/internal/graphqlHeaders.js +11 -0
  498. package/dist/internal/graphqlHeaders.js.map +1 -1
  499. package/dist/internal/matcher.js +10 -0
  500. package/dist/internal/matcher.js.map +1 -1
  501. package/dist/internal/persistence.js +9 -0
  502. package/dist/internal/persistence.js.map +1 -1
  503. package/dist/internal/rcRef.js +4 -1
  504. package/dist/internal/rcRef.js.map +1 -1
  505. package/dist/internal/request.js +29 -42
  506. package/dist/internal/request.js.map +1 -1
  507. package/dist/internal/schema/fromJsonSchemaDocument.js +7 -8
  508. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  509. package/dist/internal/schema/toCodeDocument.js +6 -3
  510. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  511. package/dist/internal/trie.js +42 -13
  512. package/dist/internal/trie.js.map +1 -1
  513. package/dist/internal/ulid.js +41 -0
  514. package/dist/internal/ulid.js.map +1 -1
  515. package/dist/internal/uuid.js +52 -8
  516. package/dist/internal/uuid.js.map +1 -1
  517. package/dist/internal/version.js +1 -1
  518. package/dist/jose/JoseError.d.ts +285 -0
  519. package/dist/jose/JoseError.d.ts.map +1 -0
  520. package/dist/jose/JoseError.js +269 -0
  521. package/dist/jose/JoseError.js.map +1 -0
  522. package/dist/jose/Jwe.d.ts +128 -0
  523. package/dist/jose/Jwe.d.ts.map +1 -0
  524. package/dist/jose/Jwe.js +134 -0
  525. package/dist/jose/Jwe.js.map +1 -0
  526. package/dist/jose/Jwk.d.ts +597 -0
  527. package/dist/jose/Jwk.d.ts.map +1 -0
  528. package/dist/jose/Jwk.js +503 -0
  529. package/dist/jose/Jwk.js.map +1 -0
  530. package/dist/jose/Jwks.d.ts +236 -0
  531. package/dist/jose/Jwks.d.ts.map +1 -0
  532. package/dist/jose/Jwks.js +306 -0
  533. package/dist/jose/Jwks.js.map +1 -0
  534. package/dist/jose/Jws.d.ts +177 -0
  535. package/dist/jose/Jws.d.ts.map +1 -0
  536. package/dist/jose/Jws.js +183 -0
  537. package/dist/jose/Jws.js.map +1 -0
  538. package/dist/jose/Jwt.d.ts +270 -0
  539. package/dist/jose/Jwt.d.ts.map +1 -0
  540. package/dist/jose/Jwt.js +293 -0
  541. package/dist/jose/Jwt.js.map +1 -0
  542. package/dist/jose/index.d.ts +51 -0
  543. package/dist/jose/index.d.ts.map +1 -0
  544. package/dist/jose/index.js +52 -0
  545. package/dist/jose/index.js.map +1 -0
  546. package/dist/jose/internal/compact.d.ts +2 -0
  547. package/dist/jose/internal/compact.d.ts.map +1 -0
  548. package/dist/jose/internal/compact.js +179 -0
  549. package/dist/jose/internal/compact.js.map +1 -0
  550. package/dist/net/Host.d.ts.map +1 -1
  551. package/dist/net/Host.js +5 -10
  552. package/dist/net/Host.js.map +1 -1
  553. package/dist/observability/Otlp.d.ts +15 -4
  554. package/dist/observability/Otlp.d.ts.map +1 -1
  555. package/dist/observability/Otlp.js +10 -0
  556. package/dist/observability/Otlp.js.map +1 -1
  557. package/dist/observability/OtlpResource.d.ts +7 -0
  558. package/dist/observability/OtlpResource.d.ts.map +1 -1
  559. package/dist/observability/OtlpResource.js +11 -1
  560. package/dist/observability/OtlpResource.js.map +1 -1
  561. package/dist/observability/OtlpSerialization.d.ts +1 -1
  562. package/dist/observability/OtlpSerialization.d.ts.map +1 -1
  563. package/dist/observability/OtlpSerialization.js +10 -4
  564. package/dist/observability/OtlpSerialization.js.map +1 -1
  565. package/dist/observability/internal/otlpProtobuf.js +3 -3
  566. package/dist/observability/internal/otlpProtobuf.js.map +1 -1
  567. package/dist/observability/internal/protobuf.js +6 -0
  568. package/dist/observability/internal/protobuf.js.map +1 -1
  569. package/dist/persistence/CircuitBreaker.d.ts +98 -38
  570. package/dist/persistence/CircuitBreaker.d.ts.map +1 -1
  571. package/dist/persistence/CircuitBreaker.js +67 -29
  572. package/dist/persistence/CircuitBreaker.js.map +1 -1
  573. package/dist/persistence/KeyValueStore.d.ts +47 -2
  574. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  575. package/dist/persistence/KeyValueStore.js +129 -18
  576. package/dist/persistence/KeyValueStore.js.map +1 -1
  577. package/dist/persistence/PersistedQueue.d.ts +9 -0
  578. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  579. package/dist/persistence/PersistedQueue.js +94 -52
  580. package/dist/persistence/PersistedQueue.js.map +1 -1
  581. package/dist/persistence/Persistence.d.ts +10 -4
  582. package/dist/persistence/Persistence.d.ts.map +1 -1
  583. package/dist/persistence/Persistence.js +18 -11
  584. package/dist/persistence/Persistence.js.map +1 -1
  585. package/dist/persistence/RateLimiter.d.ts +8 -0
  586. package/dist/persistence/RateLimiter.d.ts.map +1 -1
  587. package/dist/persistence/RateLimiter.js +63 -12
  588. package/dist/persistence/RateLimiter.js.map +1 -1
  589. package/dist/persistence/index.d.ts +1 -1
  590. package/dist/persistence/index.js +1 -1
  591. package/dist/process/ChildProcess.d.ts +207 -67
  592. package/dist/process/ChildProcess.d.ts.map +1 -1
  593. package/dist/process/ChildProcess.js +56 -158
  594. package/dist/process/ChildProcess.js.map +1 -1
  595. package/dist/process/ChildProcessSpawner.d.ts +5 -0
  596. package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
  597. package/dist/process/ChildProcessSpawner.js.map +1 -1
  598. package/dist/process/CommandLine.d.ts +294 -0
  599. package/dist/process/CommandLine.d.ts.map +1 -0
  600. package/dist/process/CommandLine.js +481 -0
  601. package/dist/process/CommandLine.js.map +1 -0
  602. package/dist/process/index.d.ts +5 -0
  603. package/dist/process/index.d.ts.map +1 -1
  604. package/dist/process/index.js +5 -0
  605. package/dist/process/index.js.map +1 -1
  606. package/dist/reactivity/Atom.d.ts +2 -1
  607. package/dist/reactivity/Atom.d.ts.map +1 -1
  608. package/dist/reactivity/Atom.js +3 -4
  609. package/dist/reactivity/Atom.js.map +1 -1
  610. package/dist/reactivity/AtomRegistry.js +17 -7
  611. package/dist/reactivity/AtomRegistry.js.map +1 -1
  612. package/dist/rpc/Rpc.d.ts +1 -1
  613. package/dist/rpc/Rpc.d.ts.map +1 -1
  614. package/dist/rpc/Rpc.js.map +1 -1
  615. package/dist/rpc/RpcClient.d.ts +28 -1
  616. package/dist/rpc/RpcClient.d.ts.map +1 -1
  617. package/dist/rpc/RpcClient.js +78 -27
  618. package/dist/rpc/RpcClient.js.map +1 -1
  619. package/dist/rpc/RpcMessage.d.ts +13 -3
  620. package/dist/rpc/RpcMessage.d.ts.map +1 -1
  621. package/dist/rpc/RpcMessage.js +1 -0
  622. package/dist/rpc/RpcMessage.js.map +1 -1
  623. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  624. package/dist/rpc/RpcSerialization.js +6 -0
  625. package/dist/rpc/RpcSerialization.js.map +1 -1
  626. package/dist/rpc/RpcServer.d.ts +31 -0
  627. package/dist/rpc/RpcServer.d.ts.map +1 -1
  628. package/dist/rpc/RpcServer.js +139 -66
  629. package/dist/rpc/RpcServer.js.map +1 -1
  630. package/dist/schema/Model.d.ts +14 -0
  631. package/dist/schema/Model.d.ts.map +1 -1
  632. package/dist/schema/Model.js +18 -3
  633. package/dist/schema/Model.js.map +1 -1
  634. package/dist/sql/Migrator.d.ts +9 -20
  635. package/dist/sql/Migrator.d.ts.map +1 -1
  636. package/dist/sql/Migrator.js +20 -53
  637. package/dist/sql/Migrator.js.map +1 -1
  638. package/dist/sql/MigratorFileSystem.d.ts +21 -0
  639. package/dist/sql/MigratorFileSystem.d.ts.map +1 -0
  640. package/dist/sql/MigratorFileSystem.js +57 -0
  641. package/dist/sql/MigratorFileSystem.js.map +1 -0
  642. package/dist/sql/SqlClient.d.ts +38 -3
  643. package/dist/sql/SqlClient.d.ts.map +1 -1
  644. package/dist/sql/SqlClient.js +9 -12
  645. package/dist/sql/SqlClient.js.map +1 -1
  646. package/dist/sql/Statement.d.ts +61 -9
  647. package/dist/sql/Statement.d.ts.map +1 -1
  648. package/dist/sql/Statement.js +24 -33
  649. package/dist/sql/Statement.js.map +1 -1
  650. package/dist/sql/index.js +1 -1
  651. package/dist/testing/index.d.ts +0 -5
  652. package/dist/testing/index.d.ts.map +1 -1
  653. package/dist/testing/index.js +0 -5
  654. package/dist/testing/index.js.map +1 -1
  655. package/dist/workflow/Workflow.d.ts +4 -0
  656. package/dist/workflow/Workflow.d.ts.map +1 -1
  657. package/dist/workflow/Workflow.js.map +1 -1
  658. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  659. package/dist/workflow/WorkflowEngine.js +5 -0
  660. package/dist/workflow/WorkflowEngine.js.map +1 -1
  661. package/dist/workflow/internal/crypto.js +9 -8
  662. package/dist/workflow/internal/crypto.js.map +1 -1
  663. package/package.json +7 -1
  664. package/src/BigDecimal.ts +173 -16
  665. package/src/Channel.ts +17 -11
  666. package/src/Config.ts +7 -1
  667. package/src/Context.ts +34 -10
  668. package/src/Cron.ts +178 -29
  669. package/src/Duration.ts +140 -0
  670. package/src/Effect.ts +914 -85
  671. package/src/Equal.ts +3 -3
  672. package/src/FileSystem.ts +65 -4
  673. package/src/Glob.ts +205 -0
  674. package/src/Hash.ts +5 -4
  675. package/src/Iterable.ts +8 -5
  676. package/src/Match.ts +127 -0
  677. package/src/Path.ts +6 -1
  678. package/src/Pool.ts +75 -16
  679. package/src/Random.ts +3 -3
  680. package/src/RcMap.ts +5 -1
  681. package/src/Schedule.ts +26 -3
  682. package/src/Schema.ts +1191 -63
  683. package/src/SchemaGetter.ts +27 -11
  684. package/src/SchemaRepresentation.ts +23 -2
  685. package/src/SchemaTransformation.ts +10 -5
  686. package/src/ScopedCache.ts +5 -9
  687. package/src/Semaphore.ts +141 -0
  688. package/src/Stream.ts +15 -6
  689. package/src/Terminal.ts +19 -1
  690. package/src/ai/AiError.ts +56 -80
  691. package/src/ai/Decision.ts +257 -6
  692. package/src/ai/DecisionModel.ts +171 -28
  693. package/src/ai/McpClient.ts +488 -91
  694. package/src/ai/McpSchema.ts +119 -0
  695. package/src/ai/McpServer.ts +1525 -319
  696. package/src/ai/McpTest.ts +380 -0
  697. package/src/ai/Prompt.ts +16 -11
  698. package/src/ai/Response.ts +2 -22
  699. package/src/ai/Tool.ts +32 -18
  700. package/src/ai/index.ts +6 -0
  701. package/src/ai/internal/mcpCore.ts +243 -56
  702. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +7 -8
  703. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +7 -8
  704. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +7 -8
  705. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +7 -8
  706. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +56 -17
  707. package/src/ai/internal/mcpProtocol.ts +44 -0
  708. package/src/ai/internal/mcpRuntime.ts +15 -8
  709. package/src/ai/internal/mcpSkills.ts +480 -0
  710. package/src/ai/internal/mcpStatefulRuntime.ts +14 -2
  711. package/src/cli/Argument.ts +6 -0
  712. package/src/cli/CliOutput.ts +117 -49
  713. package/src/cli/Command.ts +23 -0
  714. package/src/cli/Flag.ts +107 -0
  715. package/src/cli/HelpDoc.ts +18 -1
  716. package/src/cli/Param.ts +6 -0
  717. package/src/cli/Primitive.ts +16 -1
  718. package/src/cli/Prompt.ts +1 -0
  719. package/src/cli/internal/help.ts +21 -9
  720. package/src/cluster/ClusterWorkflowEngine.ts +22 -8
  721. package/src/cluster/Reply.ts +1 -1
  722. package/src/cluster/Sharding.ts +96 -26
  723. package/src/cluster/ShardingConfig.ts +41 -3
  724. package/src/cluster/SingleRunner.ts +3 -3
  725. package/src/cluster/SqlMessageStorage.ts +49 -17
  726. package/src/cluster/SqlRunnerStorage.ts +37 -27
  727. package/src/cluster/internal/entityManager.ts +24 -10
  728. package/src/crypto/Aead.ts +517 -0
  729. package/src/crypto/Cipher.ts +326 -0
  730. package/src/crypto/CryptoError.ts +242 -0
  731. package/src/crypto/Digest.ts +167 -0
  732. package/src/crypto/Kdf.ts +315 -0
  733. package/src/crypto/KeyAgreement.ts +489 -0
  734. package/src/crypto/KeyFormat.ts +741 -0
  735. package/src/crypto/KeyWrap.ts +639 -0
  736. package/src/crypto/Mac.ts +386 -0
  737. package/src/crypto/SecureRandom.ts +459 -0
  738. package/src/crypto/Signature.ts +673 -0
  739. package/src/crypto/WebCrypto.ts +84 -0
  740. package/src/crypto/index.ts +78 -0
  741. package/src/crypto/internal/asymmetric.ts +330 -0
  742. package/src/crypto/internal/chacha.ts +1088 -0
  743. package/src/crypto/internal/der.ts +110 -0
  744. package/src/crypto/internal/digest.ts +16 -0
  745. package/src/crypto/internal/key.ts +242 -0
  746. package/src/crypto/internal/md5.ts +170 -0
  747. package/src/crypto/internal/webCrypto.ts +150 -0
  748. package/src/encoding/Base64Url.ts +32 -5
  749. package/src/encoding/Csv.ts +1298 -0
  750. package/src/encoding/Hex.ts +3 -2
  751. package/src/encoding/Ndjson.ts +6 -5
  752. package/src/encoding/SchemaBinary.ts +40 -4
  753. package/src/encoding/Sse.ts +5 -3
  754. package/src/encoding/Toml.ts +85 -20
  755. package/src/encoding/Yaml.ts +61 -18
  756. package/src/encoding/index.ts +6 -0
  757. package/src/eventlog/EventJournal.ts +4 -3
  758. package/src/eventlog/EventLog.ts +347 -15
  759. package/src/eventlog/EventLogEncryption.ts +118 -110
  760. package/src/eventlog/EventLogMessage.ts +273 -1
  761. package/src/eventlog/EventLogRemote.ts +367 -23
  762. package/src/eventlog/EventLogServer.ts +54 -20
  763. package/src/eventlog/EventLogServerEncrypted.ts +1135 -67
  764. package/src/eventlog/EventLogServerUnencrypted.ts +19 -2
  765. package/src/eventlog/EventLogSessionAuth.ts +82 -70
  766. package/src/eventlog/EventRow.ts +12 -3
  767. package/src/eventlog/SqlEventJournal.ts +2 -2
  768. package/src/eventlog/SqlEventLogServerEncrypted.ts +1244 -136
  769. package/src/eventlog/SqlEventLogServerUnencrypted.ts +2 -2
  770. package/src/eventlog/internal/batches.ts +30 -0
  771. package/src/eventlog/internal/compaction.ts +64 -0
  772. package/src/eventlog/internal/identityRootSecretDerivation.ts +93 -123
  773. package/src/eventlog/internal/remoteCompaction.ts +92 -0
  774. package/src/graphql/GraphQLClient.ts +3 -1
  775. package/src/graphql/GraphQLClientError.ts +15 -22
  776. package/src/graphql/GraphQLProtocol.ts +12 -3
  777. package/src/http/Cookies.ts +281 -1
  778. package/src/http/FetchHttpClient.ts +88 -16
  779. package/src/http/HttpClient.ts +299 -33
  780. package/src/http/HttpClientRequest.ts +12 -9
  781. package/src/http/HttpClientResponse.ts +3 -2
  782. package/src/http/HttpMethod.ts +10 -2
  783. package/src/http/HttpServerRequest.ts +76 -53
  784. package/src/http/HttpServerResponse.ts +3 -2
  785. package/src/http/HttpTraceContext.ts +7 -4
  786. package/src/http/ProblemDetails.ts +149 -0
  787. package/src/http/index.ts +6 -0
  788. package/src/http/internal/decompression.ts +4 -4
  789. package/src/http/internal/mimeTypes.ts +4 -1
  790. package/src/http/internal/urlParams.ts +8 -0
  791. package/src/http-api/HttpApiBuilder.ts +24 -12
  792. package/src/http-api/HttpApiClient.ts +67 -1
  793. package/src/http-api/HttpApiEndpoint.ts +14 -5
  794. package/src/http-api/HttpApiError.ts +250 -0
  795. package/src/http-api/HttpApiMiddleware.ts +95 -1
  796. package/src/http-api/HttpApiSchema.ts +106 -15
  797. package/src/index.ts +6 -6
  798. package/src/internal/dateTime.ts +54 -24
  799. package/src/internal/effect.ts +40 -18
  800. package/src/internal/glob.ts +952 -0
  801. package/src/internal/graphql.ts +27 -9
  802. package/src/internal/graphqlHeaders.ts +13 -0
  803. package/src/internal/matcher.ts +17 -0
  804. package/src/internal/persistence.ts +11 -0
  805. package/src/internal/rcRef.ts +4 -1
  806. package/src/internal/request.ts +51 -58
  807. package/src/internal/schema/fromJsonSchemaDocument.ts +11 -10
  808. package/src/internal/schema/toCodeDocument.ts +7 -3
  809. package/src/internal/trie.ts +43 -14
  810. package/src/internal/ulid.ts +44 -0
  811. package/src/internal/uuid.ts +57 -16
  812. package/src/internal/version.ts +1 -1
  813. package/src/jose/JoseError.ts +329 -0
  814. package/src/jose/Jwe.ts +196 -0
  815. package/src/jose/Jwk.ts +777 -0
  816. package/src/jose/Jwks.ts +418 -0
  817. package/src/jose/Jws.ts +312 -0
  818. package/src/jose/Jwt.ts +493 -0
  819. package/src/jose/index.ts +58 -0
  820. package/src/jose/internal/compact.ts +195 -0
  821. package/src/net/Host.ts +5 -10
  822. package/src/observability/Otlp.ts +21 -4
  823. package/src/observability/OtlpResource.ts +9 -1
  824. package/src/observability/OtlpSerialization.ts +13 -5
  825. package/src/observability/internal/otlpProtobuf.ts +6 -6
  826. package/src/observability/internal/protobuf.ts +10 -0
  827. package/src/persistence/CircuitBreaker.ts +113 -48
  828. package/src/persistence/KeyValueStore.ts +219 -22
  829. package/src/persistence/PersistedQueue.ts +128 -59
  830. package/src/persistence/Persistence.ts +20 -13
  831. package/src/persistence/RateLimiter.ts +84 -15
  832. package/src/persistence/index.ts +1 -1
  833. package/src/process/ChildProcess.ts +255 -260
  834. package/src/process/ChildProcessSpawner.ts +5 -0
  835. package/src/process/CommandLine.ts +630 -0
  836. package/src/process/index.ts +6 -0
  837. package/src/reactivity/Atom.ts +5 -5
  838. package/src/reactivity/AtomRegistry.ts +20 -9
  839. package/src/rpc/Rpc.ts +3 -1
  840. package/src/rpc/RpcClient.ts +94 -38
  841. package/src/rpc/RpcMessage.ts +13 -3
  842. package/src/rpc/RpcSerialization.ts +3 -0
  843. package/src/rpc/RpcServer.ts +176 -78
  844. package/src/schema/Model.ts +26 -3
  845. package/src/sql/Migrator.ts +38 -80
  846. package/src/sql/MigratorFileSystem.ts +71 -0
  847. package/src/sql/SqlClient.ts +45 -24
  848. package/src/sql/Statement.ts +60 -29
  849. package/src/sql/index.ts +1 -1
  850. package/src/testing/index.ts +0 -6
  851. package/src/workflow/Workflow.ts +4 -0
  852. package/src/workflow/WorkflowEngine.ts +5 -0
  853. package/src/workflow/internal/crypto.ts +15 -11
  854. package/dist/Crypto.d.ts +0 -244
  855. package/dist/Crypto.d.ts.map +0 -1
  856. package/dist/Crypto.js +0 -139
  857. package/dist/Crypto.js.map +0 -1
  858. package/dist/testing/TestCrypto.d.ts +0 -73
  859. package/dist/testing/TestCrypto.d.ts.map +0 -1
  860. package/dist/testing/TestCrypto.js +0 -87
  861. package/dist/testing/TestCrypto.js.map +0 -1
  862. package/src/Crypto.ts +0 -347
  863. package/src/testing/TestCrypto.ts +0 -94
@@ -0,0 +1,885 @@
1
+ /**
2
+ * ChaCha20-Poly1305 (RFC 8439) and XChaCha20-Poly1305
3
+ * (draft-irtf-cfrg-xchacha-03), vendored from `@noble/ciphers`.
4
+ *
5
+ * Upstream: https://github.com/paulmillr/noble-ciphers
6
+ * Version: 2.4.0, commit d9e8a6a599e7ed729d9be03854c46a3c73bd9a79
7
+ * Files: `src/chacha.ts` (`chachaCore`, `hchacha`, `chacha20`, `xchacha20`,
8
+ * `_poly1305_aead`), `src/_arx.ts` (`createCipher`), `src/_poly1305.ts`
9
+ * (`Poly1305`), and the helpers they use from `src/utils.ts`. `@noble/ciphers`
10
+ * 1.0.0 was audited by Cure53 in 2024.
11
+ *
12
+ * Changes from upstream: merged into one file, removed the `TArg`/`TRet` type
13
+ * helpers, `@example` blocks, the reduced-round and original ChaCha variants,
14
+ * the PRGs, and the `wrapCipher` argument wrapper, whose checks the `Aead`
15
+ * layers run before calling this code. `Poly1305` is constructed directly
16
+ * instead of through `wrapMacConstructor`, and `decrypt` returns `undefined`
17
+ * on a tag mismatch instead of throwing, so any exception is a bug. The
18
+ * cipher core, Poly1305 arithmetic, and AEAD construction are unchanged.
19
+ *
20
+ * The MIT License (MIT)
21
+ *
22
+ * Copyright (c) 2022 Paul Miller (https://paulmillr.com)
23
+ * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
24
+ *
25
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
26
+ * of this software and associated documentation files (the "Software"), to deal
27
+ * in the Software without restriction, including without limitation the rights
28
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29
+ * copies of the Software, and to permit persons to whom the Software is
30
+ * furnished to do so, subject to the following conditions:
31
+ *
32
+ * The above copyright notice and this permission notice shall be included in
33
+ * all copies or substantial portions of the Software.
34
+ *
35
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
41
+ * THE SOFTWARE.
42
+ *
43
+ * @internal
44
+ */
45
+ function isBytes(a) {
46
+ // Plain `instanceof Uint8Array` is too strict for some Buffer / proxy /
47
+ // cross-realm cases. The fallback still requires a real ArrayBuffer view
48
+ // so plain JSON-deserialized `{ constructor: ... }`
49
+ // spoofing is rejected, and `BYTES_PER_ELEMENT === 1` keeps the fallback on byte-oriented views.
50
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
51
+ }
52
+ const atitle = title => title ? `"${title}" ` : "";
53
+ function abool(value, title = "") {
54
+ if (typeof value !== "boolean") {
55
+ throw new TypeError(atitle(title) + "expected boolean, got type=" + typeof value);
56
+ }
57
+ return value;
58
+ }
59
+ function anumber(n, title = "") {
60
+ if (typeof n !== "number") {
61
+ throw new TypeError(atitle(title) + "expected number, got " + typeof n);
62
+ }
63
+ if (!Number.isSafeInteger(n) || n < 0) {
64
+ throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
65
+ }
66
+ return n;
67
+ }
68
+ function abytes(value, length, title = "") {
69
+ // Success path first: this runs at the start of every update() / digestInto(), and the
70
+ // common `abytes(data)` form must not pay for length handling it does not use.
71
+ if (isBytes(value) && (length === undefined || value.length === length)) {
72
+ return value;
73
+ }
74
+ // Error path: recompute freely to build the exact message.
75
+ if (length !== undefined) anumber(length, "length");
76
+ const bytes = isBytes(value);
77
+ const ofLen = length !== undefined ? ` of length ${length}` : "";
78
+ const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
79
+ const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
80
+ if (!bytes) throw new TypeError(message);
81
+ throw new RangeError(message);
82
+ }
83
+ const aobject = (value, label) => {
84
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
85
+ throw new TypeError(label === "object" ? "expected valid options object" : `"${label}" expected object, got type=${typeof value}`);
86
+ }
87
+ };
88
+ function checkOpts(defaults, opts) {
89
+ aobject(defaults, "defaults");
90
+ aobject(opts, "opts");
91
+ // Mutates defaults by design. __proto__ follows Object.assign semantics here and can only
92
+ // affect this local option object; callers already control this low-level options surface.
93
+ const merged = Object.assign(defaults, opts);
94
+ return merged;
95
+ }
96
+ function aexists(instance, checkFinished = true) {
97
+ // Runs on every update()/digestInto(); the flags are library-owned booleans, so only their
98
+ // truthiness is checked - re-validating their type per call was pure hot-path overhead.
99
+ if (instance.destroyed) throw new Error("hash was destroyed");
100
+ if (checkFinished && instance.finished) throw new Error("digest() was already called");
101
+ }
102
+ function aoutput(out, instance) {
103
+ abytes(out, undefined, "output");
104
+ // `outputLen` is a library-owned readonly number; the negated comparison keeps failing fast
105
+ // when it is missing/NaN (comparisons with undefined/NaN are false) without an anumber() call.
106
+ const min = instance.outputLen;
107
+ if (!(out.length >= min)) {
108
+ throw new RangeError("\"output\" expected length >= " + min);
109
+ }
110
+ }
111
+ function u32(arr) {
112
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
113
+ }
114
+ function clean(...arrays) {
115
+ for (let i = 0; i < arrays.length; i++) {
116
+ arrays[i].fill(0);
117
+ }
118
+ }
119
+ function createView(arr) {
120
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
121
+ }
122
+ const isLE = /* @__PURE__ */(() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
123
+ function byteSwap(word) {
124
+ return word << 24 & 0xff000000 | word << 8 & 0xff0000 | word >>> 8 & 0xff00 | word >>> 24 & 0xff;
125
+ }
126
+ function byteSwap32(arr) {
127
+ for (let i = 0; i < arr.length; i++) {
128
+ arr[i] = byteSwap(arr[i]);
129
+ }
130
+ return arr;
131
+ }
132
+ const swap32IfBE = isLE ? u => u : byteSwap32;
133
+ function overlapBytes(a, b) {
134
+ // Zero-length views cannot overwrite anything, even if their offset sits inside another range.
135
+ if (!a.byteLength || !b.byteLength) return false;
136
+ return a.buffer === b.buffer &&
137
+ // best we can do, may fail with an obscure Proxy
138
+ a.byteOffset < b.byteOffset + b.byteLength &&
139
+ // a starts before b end
140
+ b.byteOffset < a.byteOffset + a.byteLength // b starts before a end
141
+ ;
142
+ }
143
+ function complexOverlapBytes(input, output) {
144
+ // This is very cursed. It works somehow, but I'm completely unsure,
145
+ // reasoning about overlapping aligned windows is very hard.
146
+ if (overlapBytes(input, output) && input.byteOffset < output.byteOffset) {
147
+ throw new Error("complex overlap of input and output is not supported");
148
+ }
149
+ }
150
+ function equalBytes(a, b) {
151
+ a = abytes(a);
152
+ b = abytes(b);
153
+ if (a.length !== b.length) return false;
154
+ let diff = 0;
155
+ for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
156
+ return diff === 0;
157
+ }
158
+ function getOutput(expectedLength, out, onlyAligned = true) {
159
+ if (out === undefined) return new Uint8Array(expectedLength);
160
+ // Keep Buffer/cross-realm Uint8Array support here instead of trusting a shape-compatible object.
161
+ abytes(out, expectedLength, "output");
162
+ if (onlyAligned && !isAligned32(out)) throw new Error("invalid output, must be aligned");
163
+ return out;
164
+ }
165
+ function u64Lengths(dataLength, aadLength, isLE) {
166
+ // Reject coercible non-number lengths like '10' and true before BigInt(...) accepts them.
167
+ anumber(dataLength);
168
+ anumber(aadLength);
169
+ abool(isLE);
170
+ const num = new Uint8Array(16);
171
+ const view = createView(num);
172
+ view.setBigUint64(0, BigInt(aadLength), isLE);
173
+ view.setBigUint64(8, BigInt(dataLength), isLE);
174
+ return num;
175
+ }
176
+ function isAligned32(bytes) {
177
+ return bytes.byteOffset % 4 === 0;
178
+ }
179
+ function copyBytes(bytes) {
180
+ // `Uint8Array.from(...)` would also accept arrays / other typed arrays. Keep this helper strict
181
+ // because callers use it at byte-validation boundaries before mutating the detached copy.
182
+ return Uint8Array.from(abytes(bytes));
183
+ }
184
+ // _arx.ts
185
+ // Replaces `TextEncoder` for ASCII literals, which is enough for sigma constants.
186
+ // Non-ASCII input would not match UTF-8 `TextEncoder` output.
187
+ const encodeStr = str => Uint8Array.from(str.split(""), c => c.charCodeAt(0));
188
+ // Raw `createCipher(...)` exports consume these native-endian `u32(...)` views directly.
189
+ // RFC 8439 §2.3 / RFC 7539 §2.3 only define the 256-bit-key constants; this 16-byte sigma is
190
+ // kept for legacy allowShortKeys Salsa/ChaCha variants.
191
+ const sigma16_32 = /* @__PURE__ */(() => swap32IfBE(u32(encodeStr("expand 16-byte k"))))();
192
+ // RFC 8439 §2.3 / RFC 7539 §2.3 define words 0-3 as
193
+ // `0x61707865 0x3320646e 0x79622d32 0x6b206574`, i.e. `expand 32-byte k`.
194
+ const sigma32_32 = /* @__PURE__ */(() => swap32IfBE(u32(encodeStr("expand 32-byte k"))))();
195
+ function rotl(a, b) {
196
+ return a << b | a >>> 32 - b;
197
+ }
198
+ // Salsa and Chacha block length is always 512-bit
199
+ const BLOCK_LEN = 64;
200
+ // RFC 8439 §2.2 / RFC 7539 §2.2: the ChaCha state has 16 32-bit words.
201
+ const BLOCK_LEN32 = 16;
202
+ // Counter policy for the shared public `counter` argument:
203
+ // - RFC/IETF ChaCha20 uses a 32-bit counter.
204
+ // - OpenSSL/Node `chacha20` instead treat the full 16-byte IV as a 128-bit
205
+ // counter state and carry into the next word.
206
+ // - Raw `chacha20orig`, `salsa20`, `xsalsa20`, and `xchacha20` use 64-bit counters in libsodium
207
+ // and libtomcrypt, while some libs (for example libtomcrypt's RFC/IETF path) reject the max
208
+ // boundary instead of carrying.
209
+ // - AEAD wrappers diverge too: libsodium `xchacha20poly1305` uses the IETF payload counter from
210
+ // block 1, while `secretstream_xchacha20poly1305` is a different protocol with rekey/reset.
211
+ // Noble intentionally throws instead of silently picking one wrap model for users. In the default
212
+ // path, even a 32-bit boundary would take 2^32 blocks * 64 bytes = 256 GiB, which is practically
213
+ // unreachable for normal JS callers; advanced users who pass `counter` explicitly can implement
214
+ // whatever wider carry / wrap policy they need on top.
215
+ const MAX_COUNTER = /* @__PURE__ */(() => 2 ** 32 - 1)();
216
+ const U32_EMPTY = /* @__PURE__ */Uint32Array.of();
217
+ function runCipher(core, sigma, key, nonce, data, output, counter, rounds) {
218
+ const len = data.length;
219
+ const block = new Uint8Array(BLOCK_LEN);
220
+ const b32 = u32(block);
221
+ // Make sure that buffers aligned to 4 bytes
222
+ const isAligned = isLE && isAligned32(data) && isAligned32(output);
223
+ const d32 = isAligned ? u32(data) : U32_EMPTY;
224
+ const o32 = isAligned ? u32(output) : U32_EMPTY;
225
+ // RFC 8439 §2.4.1 / RFC 7539 §2.4.1 allow XORing one keystream block at a time and
226
+ // truncating the final partial block instead of materializing the whole keystream.
227
+ if (!isLE) {
228
+ for (let pos = 0; pos < len; counter++) {
229
+ core(sigma, key, nonce, b32, counter, rounds);
230
+ // RFC 8439 §2.4 / RFC 7539 §2.4 serialize keystream words in little-endian order.
231
+ swap32IfBE(b32);
232
+ if (counter >= MAX_COUNTER) throw new Error("arx: counter overflow");
233
+ const take = Math.min(BLOCK_LEN, len - pos);
234
+ for (let j = 0, posj; j < take; j++) {
235
+ posj = pos + j;
236
+ output[posj] = data[posj] ^ block[j];
237
+ }
238
+ pos += take;
239
+ }
240
+ return;
241
+ }
242
+ for (let pos = 0; pos < len; counter++) {
243
+ core(sigma, key, nonce, b32, counter, rounds);
244
+ // See MAX_COUNTER policy note above: never silently wrap the shared public counter.
245
+ if (counter >= MAX_COUNTER) throw new Error("arx: counter overflow");
246
+ const take = Math.min(BLOCK_LEN, len - pos);
247
+ // aligned to 4 bytes
248
+ if (isAligned && take === BLOCK_LEN) {
249
+ const pos32 = pos / 4;
250
+ if (pos % 4 !== 0) throw new Error("arx: invalid block position");
251
+ for (let j = 0, posj; j < BLOCK_LEN32; j++) {
252
+ posj = pos32 + j;
253
+ o32[posj] = d32[posj] ^ b32[j];
254
+ }
255
+ pos += BLOCK_LEN;
256
+ continue;
257
+ }
258
+ for (let j = 0, posj; j < take; j++) {
259
+ posj = pos + j;
260
+ output[posj] = data[posj] ^ block[j];
261
+ }
262
+ pos += take;
263
+ }
264
+ }
265
+ function createCipher(core, opts) {
266
+ const {
267
+ allowShortKeys,
268
+ extendNonceFn,
269
+ counterLength,
270
+ counterRight,
271
+ rounds
272
+ } = checkOpts({
273
+ allowShortKeys: false,
274
+ counterLength: 8,
275
+ counterRight: false,
276
+ rounds: 20
277
+ }, opts);
278
+ if (typeof core !== "function") throw new Error("core must be a function");
279
+ anumber(counterLength);
280
+ anumber(rounds);
281
+ abool(counterRight);
282
+ abool(allowShortKeys);
283
+ return (key, nonce, data, output, counter = 0) => {
284
+ abytes(key, undefined, "key");
285
+ abytes(nonce, undefined, "nonce");
286
+ abytes(data, undefined, "data");
287
+ const len = data.length;
288
+ // Raw XorStream APIs return ciphertext/plaintext bytes directly, so caller-provided outputs
289
+ // must match the logical result length exactly instead of returning an oversized workspace.
290
+ const hasOutput = output !== undefined;
291
+ output = getOutput(len, output, false);
292
+ if (hasOutput) complexOverlapBytes(data, output);
293
+ anumber(counter);
294
+ // See MAX_COUNTER policy note above: reject advanced explicit-counter requests before any wrap.
295
+ if (counter < 0 || counter >= MAX_COUNTER) throw new Error("arx: counter overflow");
296
+ const toClean = [];
297
+ // Key & sigma
298
+ // key=16 -> sigma16, k=key|key
299
+ // key=32 -> sigma32, k=key
300
+ let l = key.length;
301
+ let k;
302
+ let sigma;
303
+ if (l === 32) {
304
+ // Copy caller keys too: big-endian normalization, extended-nonce subkey derivation, and
305
+ // final clean(...) all mutate or wipe the temporary buffer in place.
306
+ toClean.push(k = copyBytes(key));
307
+ sigma = sigma32_32;
308
+ } else if (l === 16 && allowShortKeys) {
309
+ k = new Uint8Array(32);
310
+ k.set(key);
311
+ k.set(key, 16);
312
+ sigma = sigma16_32;
313
+ toClean.push(k);
314
+ } else {
315
+ abytes(key, 32, "arx key");
316
+ throw new Error("invalid key size");
317
+ // throw new Error(`"arx key" expected Uint8Array of length 32, got length=${l}`);
318
+ }
319
+ // Nonce
320
+ // salsa20: 8 (8-byte counter)
321
+ // chacha20orig: 8 (8-byte counter)
322
+ // chacha20: 12 (4-byte counter)
323
+ // xsalsa20: 24 (16 -> hsalsa, 8 -> old nonce)
324
+ // xchacha20: 24 (16 -> hchacha, 8 -> old nonce)
325
+ // Copy before taking u32(...) views on misaligned inputs, and on big-endian so later
326
+ // swap32IfBE(...) never mutates caller nonce bytes in place.
327
+ if (!isLE || !isAligned32(nonce)) toClean.push(nonce = copyBytes(nonce));
328
+ let k32 = u32(k);
329
+ // hsalsa & hchacha: handle extended nonce
330
+ if (extendNonceFn) {
331
+ if (nonce.length !== 24) throw new Error("arx: extended nonce must be 24 bytes");
332
+ const n16 = nonce.subarray(0, 16);
333
+ if (isLE) extendNonceFn(sigma, k32, u32(n16), k32);else {
334
+ const sigmaRaw = swap32IfBE(Uint32Array.from(sigma));
335
+ extendNonceFn(sigmaRaw, k32, u32(n16), k32);
336
+ clean(sigmaRaw);
337
+ swap32IfBE(k32);
338
+ }
339
+ nonce = nonce.subarray(16);
340
+ } else if (!isLE) swap32IfBE(k32);
341
+ // Handle nonce counter
342
+ const nonceNcLen = 16 - counterLength;
343
+ if (nonceNcLen !== nonce.length) {
344
+ throw new Error(`arx: nonce must be ${nonceNcLen} or 16 bytes`);
345
+ }
346
+ // Normalize 64-bit-nonce layouts to the 12-byte core input: ChaCha/XChaCha prefix 4 zero
347
+ // counter bytes, while Salsa/XSalsa append them after the nonce words.
348
+ if (nonceNcLen !== 12) {
349
+ const nc = new Uint8Array(12);
350
+ nc.set(nonce, counterRight ? 0 : 12 - nonce.length);
351
+ nonce = nc;
352
+ toClean.push(nonce);
353
+ }
354
+ const n32 = swap32IfBE(u32(nonce));
355
+ // Ensure temporary key/nonce copies are wiped even if the remaining
356
+ // runtime guard in runCipher(...) throws on counter overflow.
357
+ try {
358
+ runCipher(core, sigma, k32, n32, data, output, counter, rounds);
359
+ return output;
360
+ } finally {
361
+ clean(...toClean);
362
+ }
363
+ };
364
+ }
365
+ // _poly1305.ts
366
+ // Little-endian 2-byte load used by the Poly1305 limb decomposition.
367
+ function u8to16(a, i) {
368
+ return a[i++] & 0xff | (a[i++] & 0xff) << 8;
369
+ }
370
+ class Poly1305 {
371
+ blockLen = 16;
372
+ outputLen = 16;
373
+ buffer = /*#__PURE__*/new Uint8Array(16);
374
+ r = /*#__PURE__*/new Uint16Array(10); // Allocating 1 array with .subarray() here is slower than 3
375
+ h = /*#__PURE__*/new Uint16Array(10);
376
+ pad = /*#__PURE__*/new Uint16Array(8);
377
+ pos = 0;
378
+ finished = false;
379
+ destroyed = false;
380
+ // Can be speed-up using BigUint64Array, at the cost of complexity
381
+ constructor(key) {
382
+ key = copyBytes(abytes(key, 32, "key"));
383
+ const t0 = u8to16(key, 0);
384
+ const t1 = u8to16(key, 2);
385
+ const t2 = u8to16(key, 4);
386
+ const t3 = u8to16(key, 6);
387
+ const t4 = u8to16(key, 8);
388
+ const t5 = u8to16(key, 10);
389
+ const t6 = u8to16(key, 12);
390
+ const t7 = u8to16(key, 14);
391
+ // RFC 8439 §2.5.1 / RFC 7539 §2.5.1 clamp r before multiplication.
392
+ // These masks unpack that clamped value into 13-bit limbs, while pad
393
+ // keeps the raw s half for finalize().
394
+ // {@link https://github.com/floodyberry/poly1305-donna/blob/e6ad6e091d30d7f4ec2d4f978be1fcfcbce72781/poly1305-donna-16.h#L47 | poly1305-donna reference}
395
+ this.r[0] = t0 & 0x1fff;
396
+ this.r[1] = (t0 >>> 13 | t1 << 3) & 0x1fff;
397
+ this.r[2] = (t1 >>> 10 | t2 << 6) & 0x1f03;
398
+ this.r[3] = (t2 >>> 7 | t3 << 9) & 0x1fff;
399
+ this.r[4] = (t3 >>> 4 | t4 << 12) & 0x00ff;
400
+ this.r[5] = t4 >>> 1 & 0x1ffe;
401
+ this.r[6] = (t4 >>> 14 | t5 << 2) & 0x1fff;
402
+ this.r[7] = (t5 >>> 11 | t6 << 5) & 0x1f81;
403
+ this.r[8] = (t6 >>> 8 | t7 << 8) & 0x1fff;
404
+ this.r[9] = t7 >>> 5 & 0x007f;
405
+ for (let i = 0; i < 8; i++) this.pad[i] = u8to16(key, 16 + 2 * i);
406
+ }
407
+ process(data, offset, isLast = false) {
408
+ // RFC 8439 §2.5 / §2.5.1 and RFC 7539 §2.5 / §2.5.1 add an extra high
409
+ // bit to every full 16-byte block. The final partial block gets its
410
+ // explicit `1` byte during digestInto(), so `hibit` stays zero there.
411
+ const hibit = isLast ? 0 : 1 << 11;
412
+ const {
413
+ h,
414
+ r
415
+ } = this;
416
+ const r0 = r[0];
417
+ const r1 = r[1];
418
+ const r2 = r[2];
419
+ const r3 = r[3];
420
+ const r4 = r[4];
421
+ const r5 = r[5];
422
+ const r6 = r[6];
423
+ const r7 = r[7];
424
+ const r8 = r[8];
425
+ const r9 = r[9];
426
+ const t0 = u8to16(data, offset + 0);
427
+ const t1 = u8to16(data, offset + 2);
428
+ const t2 = u8to16(data, offset + 4);
429
+ const t3 = u8to16(data, offset + 6);
430
+ const t4 = u8to16(data, offset + 8);
431
+ const t5 = u8to16(data, offset + 10);
432
+ const t6 = u8to16(data, offset + 12);
433
+ const t7 = u8to16(data, offset + 14);
434
+ let h0 = h[0] + (t0 & 0x1fff);
435
+ let h1 = h[1] + ((t0 >>> 13 | t1 << 3) & 0x1fff);
436
+ let h2 = h[2] + ((t1 >>> 10 | t2 << 6) & 0x1fff);
437
+ let h3 = h[3] + ((t2 >>> 7 | t3 << 9) & 0x1fff);
438
+ let h4 = h[4] + ((t3 >>> 4 | t4 << 12) & 0x1fff);
439
+ let h5 = h[5] + (t4 >>> 1 & 0x1fff);
440
+ let h6 = h[6] + ((t4 >>> 14 | t5 << 2) & 0x1fff);
441
+ let h7 = h[7] + ((t5 >>> 11 | t6 << 5) & 0x1fff);
442
+ let h8 = h[8] + ((t6 >>> 8 | t7 << 8) & 0x1fff);
443
+ let h9 = h[9] + (t7 >>> 5 | hibit);
444
+ let c = 0;
445
+ let d0 = c + h0 * r0 + h1 * (5 * r9) + h2 * (5 * r8) + h3 * (5 * r7) + h4 * (5 * r6);
446
+ c = d0 >>> 13;
447
+ d0 &= 0x1fff;
448
+ d0 += h5 * (5 * r5) + h6 * (5 * r4) + h7 * (5 * r3) + h8 * (5 * r2) + h9 * (5 * r1);
449
+ c += d0 >>> 13;
450
+ d0 &= 0x1fff;
451
+ let d1 = c + h0 * r1 + h1 * r0 + h2 * (5 * r9) + h3 * (5 * r8) + h4 * (5 * r7);
452
+ c = d1 >>> 13;
453
+ d1 &= 0x1fff;
454
+ d1 += h5 * (5 * r6) + h6 * (5 * r5) + h7 * (5 * r4) + h8 * (5 * r3) + h9 * (5 * r2);
455
+ c += d1 >>> 13;
456
+ d1 &= 0x1fff;
457
+ let d2 = c + h0 * r2 + h1 * r1 + h2 * r0 + h3 * (5 * r9) + h4 * (5 * r8);
458
+ c = d2 >>> 13;
459
+ d2 &= 0x1fff;
460
+ d2 += h5 * (5 * r7) + h6 * (5 * r6) + h7 * (5 * r5) + h8 * (5 * r4) + h9 * (5 * r3);
461
+ c += d2 >>> 13;
462
+ d2 &= 0x1fff;
463
+ let d3 = c + h0 * r3 + h1 * r2 + h2 * r1 + h3 * r0 + h4 * (5 * r9);
464
+ c = d3 >>> 13;
465
+ d3 &= 0x1fff;
466
+ d3 += h5 * (5 * r8) + h6 * (5 * r7) + h7 * (5 * r6) + h8 * (5 * r5) + h9 * (5 * r4);
467
+ c += d3 >>> 13;
468
+ d3 &= 0x1fff;
469
+ let d4 = c + h0 * r4 + h1 * r3 + h2 * r2 + h3 * r1 + h4 * r0;
470
+ c = d4 >>> 13;
471
+ d4 &= 0x1fff;
472
+ d4 += h5 * (5 * r9) + h6 * (5 * r8) + h7 * (5 * r7) + h8 * (5 * r6) + h9 * (5 * r5);
473
+ c += d4 >>> 13;
474
+ d4 &= 0x1fff;
475
+ let d5 = c + h0 * r5 + h1 * r4 + h2 * r3 + h3 * r2 + h4 * r1;
476
+ c = d5 >>> 13;
477
+ d5 &= 0x1fff;
478
+ d5 += h5 * r0 + h6 * (5 * r9) + h7 * (5 * r8) + h8 * (5 * r7) + h9 * (5 * r6);
479
+ c += d5 >>> 13;
480
+ d5 &= 0x1fff;
481
+ let d6 = c + h0 * r6 + h1 * r5 + h2 * r4 + h3 * r3 + h4 * r2;
482
+ c = d6 >>> 13;
483
+ d6 &= 0x1fff;
484
+ d6 += h5 * r1 + h6 * r0 + h7 * (5 * r9) + h8 * (5 * r8) + h9 * (5 * r7);
485
+ c += d6 >>> 13;
486
+ d6 &= 0x1fff;
487
+ let d7 = c + h0 * r7 + h1 * r6 + h2 * r5 + h3 * r4 + h4 * r3;
488
+ c = d7 >>> 13;
489
+ d7 &= 0x1fff;
490
+ d7 += h5 * r2 + h6 * r1 + h7 * r0 + h8 * (5 * r9) + h9 * (5 * r8);
491
+ c += d7 >>> 13;
492
+ d7 &= 0x1fff;
493
+ let d8 = c + h0 * r8 + h1 * r7 + h2 * r6 + h3 * r5 + h4 * r4;
494
+ c = d8 >>> 13;
495
+ d8 &= 0x1fff;
496
+ d8 += h5 * r3 + h6 * r2 + h7 * r1 + h8 * r0 + h9 * (5 * r9);
497
+ c += d8 >>> 13;
498
+ d8 &= 0x1fff;
499
+ let d9 = c + h0 * r9 + h1 * r8 + h2 * r7 + h3 * r6 + h4 * r5;
500
+ c = d9 >>> 13;
501
+ d9 &= 0x1fff;
502
+ d9 += h5 * r4 + h6 * r3 + h7 * r2 + h8 * r1 + h9 * r0;
503
+ c += d9 >>> 13;
504
+ d9 &= 0x1fff;
505
+ c = (c << 2) + c | 0;
506
+ c = c + d0 | 0;
507
+ d0 = c & 0x1fff;
508
+ c = c >>> 13;
509
+ d1 += c;
510
+ h[0] = d0;
511
+ h[1] = d1;
512
+ h[2] = d2;
513
+ h[3] = d3;
514
+ h[4] = d4;
515
+ h[5] = d5;
516
+ h[6] = d6;
517
+ h[7] = d7;
518
+ h[8] = d8;
519
+ h[9] = d9;
520
+ }
521
+ finalize() {
522
+ const {
523
+ h,
524
+ pad
525
+ } = this;
526
+ const g = new Uint16Array(10);
527
+ let c = h[1] >>> 13;
528
+ h[1] &= 0x1fff;
529
+ for (let i = 2; i < 10; i++) {
530
+ h[i] += c;
531
+ c = h[i] >>> 13;
532
+ h[i] &= 0x1fff;
533
+ }
534
+ h[0] += c * 5;
535
+ c = h[0] >>> 13;
536
+ h[0] &= 0x1fff;
537
+ h[1] += c;
538
+ c = h[1] >>> 13;
539
+ h[1] &= 0x1fff;
540
+ h[2] += c;
541
+ // RFC 8439 §2.5 / RFC 7539 §2.5 reduce modulo 2^130-5 before repacking
542
+ // to 16-bit words and adding the raw s half.
543
+ g[0] = h[0] + 5;
544
+ c = g[0] >>> 13;
545
+ g[0] &= 0x1fff;
546
+ for (let i = 1; i < 10; i++) {
547
+ g[i] = h[i] + c;
548
+ c = g[i] >>> 13;
549
+ g[i] &= 0x1fff;
550
+ }
551
+ g[9] -= 1 << 13;
552
+ let mask = (c ^ 1) - 1;
553
+ for (let i = 0; i < 10; i++) g[i] &= mask;
554
+ mask = ~mask;
555
+ for (let i = 0; i < 10; i++) h[i] = h[i] & mask | g[i];
556
+ h[0] = (h[0] | h[1] << 13) & 0xffff;
557
+ h[1] = (h[1] >>> 3 | h[2] << 10) & 0xffff;
558
+ h[2] = (h[2] >>> 6 | h[3] << 7) & 0xffff;
559
+ h[3] = (h[3] >>> 9 | h[4] << 4) & 0xffff;
560
+ h[4] = (h[4] >>> 12 | h[5] << 1 | h[6] << 14) & 0xffff;
561
+ h[5] = (h[6] >>> 2 | h[7] << 11) & 0xffff;
562
+ h[6] = (h[7] >>> 5 | h[8] << 8) & 0xffff;
563
+ h[7] = (h[8] >>> 8 | h[9] << 5) & 0xffff;
564
+ let f = h[0] + pad[0];
565
+ h[0] = f & 0xffff;
566
+ for (let i = 1; i < 8; i++) {
567
+ f = (h[i] + pad[i] | 0) + (f >>> 16) | 0;
568
+ h[i] = f & 0xffff;
569
+ }
570
+ clean(g);
571
+ }
572
+ update(data) {
573
+ aexists(this);
574
+ abytes(data);
575
+ data = copyBytes(data);
576
+ const {
577
+ buffer,
578
+ blockLen
579
+ } = this;
580
+ const len = data.length;
581
+ for (let pos = 0; pos < len;) {
582
+ const take = Math.min(blockLen - this.pos, len - pos);
583
+ // Fast path: we have at least one block in input
584
+ if (take === blockLen) {
585
+ for (; blockLen <= len - pos; pos += blockLen) this.process(data, pos);
586
+ continue;
587
+ }
588
+ buffer.set(data.subarray(pos, pos + take), this.pos);
589
+ this.pos += take;
590
+ pos += take;
591
+ if (this.pos === blockLen) {
592
+ this.process(buffer, 0, false);
593
+ this.pos = 0;
594
+ }
595
+ }
596
+ return this;
597
+ }
598
+ destroy() {
599
+ // `aexists(this)` guards update/digest paths, so destroy must mark the instance unusable too.
600
+ this.destroyed = true;
601
+ clean(this.h, this.r, this.buffer, this.pad);
602
+ }
603
+ digestInto(out) {
604
+ aexists(this);
605
+ aoutput(out, this);
606
+ this.finished = true;
607
+ const {
608
+ buffer,
609
+ h
610
+ } = this;
611
+ let {
612
+ pos
613
+ } = this;
614
+ if (pos) {
615
+ // RFC 8439 §2.5 / RFC 7539 §2.5: the final short block appends a
616
+ // single `0x01` byte and zero-fills the remaining bytes before the
617
+ // last multiplication step.
618
+ buffer[pos++] = 1;
619
+ for (; pos < 16; pos++) buffer[pos] = 0;
620
+ this.process(buffer, 0, true);
621
+ }
622
+ this.finalize();
623
+ let opos = 0;
624
+ for (let i = 0; i < 8; i++) {
625
+ out[opos++] = h[i] >>> 0;
626
+ out[opos++] = h[i] >>> 8;
627
+ }
628
+ }
629
+ digest() {
630
+ const {
631
+ buffer,
632
+ outputLen
633
+ } = this;
634
+ this.digestInto(buffer);
635
+ // Copy out before destroy() zeroes the internal buffer.
636
+ const res = buffer.slice(0, outputLen);
637
+ this.destroy();
638
+ return res;
639
+ }
640
+ }
641
+ // chacha.ts
642
+ /** RFC 8439 §2.3 block core for `state = constants | key | counter | nonce`. */
643
+ // prettier-ignore
644
+ function chachaCore(s, k, n, out, cnt, rounds = 20) {
645
+ let y00 = s[0],
646
+ y01 = s[1],
647
+ y02 = s[2],
648
+ y03 = s[3],
649
+ // "expa" "nd 3" "2-by" "te k"
650
+ y04 = k[0],
651
+ y05 = k[1],
652
+ y06 = k[2],
653
+ y07 = k[3],
654
+ // Key Key Key Key
655
+ y08 = k[4],
656
+ y09 = k[5],
657
+ y10 = k[6],
658
+ y11 = k[7],
659
+ // Key Key Key Key
660
+ y12 = cnt,
661
+ y13 = n[0],
662
+ y14 = n[1],
663
+ y15 = n[2]; // Counter Nonce Nonce Nonce
664
+ // Save state to temporary variables
665
+ let x00 = y00,
666
+ x01 = y01,
667
+ x02 = y02,
668
+ x03 = y03,
669
+ x04 = y04,
670
+ x05 = y05,
671
+ x06 = y06,
672
+ x07 = y07,
673
+ x08 = y08,
674
+ x09 = y09,
675
+ x10 = y10,
676
+ x11 = y11,
677
+ x12 = y12,
678
+ x13 = y13,
679
+ x14 = y14,
680
+ x15 = y15;
681
+ for (let r = 0; r < rounds; r += 2) {
682
+ x00 = x00 + x04 | 0;
683
+ x12 = rotl(x12 ^ x00, 16);
684
+ x08 = x08 + x12 | 0;
685
+ x04 = rotl(x04 ^ x08, 12);
686
+ x00 = x00 + x04 | 0;
687
+ x12 = rotl(x12 ^ x00, 8);
688
+ x08 = x08 + x12 | 0;
689
+ x04 = rotl(x04 ^ x08, 7);
690
+ x01 = x01 + x05 | 0;
691
+ x13 = rotl(x13 ^ x01, 16);
692
+ x09 = x09 + x13 | 0;
693
+ x05 = rotl(x05 ^ x09, 12);
694
+ x01 = x01 + x05 | 0;
695
+ x13 = rotl(x13 ^ x01, 8);
696
+ x09 = x09 + x13 | 0;
697
+ x05 = rotl(x05 ^ x09, 7);
698
+ x02 = x02 + x06 | 0;
699
+ x14 = rotl(x14 ^ x02, 16);
700
+ x10 = x10 + x14 | 0;
701
+ x06 = rotl(x06 ^ x10, 12);
702
+ x02 = x02 + x06 | 0;
703
+ x14 = rotl(x14 ^ x02, 8);
704
+ x10 = x10 + x14 | 0;
705
+ x06 = rotl(x06 ^ x10, 7);
706
+ x03 = x03 + x07 | 0;
707
+ x15 = rotl(x15 ^ x03, 16);
708
+ x11 = x11 + x15 | 0;
709
+ x07 = rotl(x07 ^ x11, 12);
710
+ x03 = x03 + x07 | 0;
711
+ x15 = rotl(x15 ^ x03, 8);
712
+ x11 = x11 + x15 | 0;
713
+ x07 = rotl(x07 ^ x11, 7);
714
+ x00 = x00 + x05 | 0;
715
+ x15 = rotl(x15 ^ x00, 16);
716
+ x10 = x10 + x15 | 0;
717
+ x05 = rotl(x05 ^ x10, 12);
718
+ x00 = x00 + x05 | 0;
719
+ x15 = rotl(x15 ^ x00, 8);
720
+ x10 = x10 + x15 | 0;
721
+ x05 = rotl(x05 ^ x10, 7);
722
+ x01 = x01 + x06 | 0;
723
+ x12 = rotl(x12 ^ x01, 16);
724
+ x11 = x11 + x12 | 0;
725
+ x06 = rotl(x06 ^ x11, 12);
726
+ x01 = x01 + x06 | 0;
727
+ x12 = rotl(x12 ^ x01, 8);
728
+ x11 = x11 + x12 | 0;
729
+ x06 = rotl(x06 ^ x11, 7);
730
+ x02 = x02 + x07 | 0;
731
+ x13 = rotl(x13 ^ x02, 16);
732
+ x08 = x08 + x13 | 0;
733
+ x07 = rotl(x07 ^ x08, 12);
734
+ x02 = x02 + x07 | 0;
735
+ x13 = rotl(x13 ^ x02, 8);
736
+ x08 = x08 + x13 | 0;
737
+ x07 = rotl(x07 ^ x08, 7);
738
+ x03 = x03 + x04 | 0;
739
+ x14 = rotl(x14 ^ x03, 16);
740
+ x09 = x09 + x14 | 0;
741
+ x04 = rotl(x04 ^ x09, 12);
742
+ x03 = x03 + x04 | 0;
743
+ x14 = rotl(x14 ^ x03, 8);
744
+ x09 = x09 + x14 | 0;
745
+ x04 = rotl(x04 ^ x09, 7);
746
+ }
747
+ // RFC 8439 §2.3 / §2.3.1: add the original state words back in state order.
748
+ let oi = 0;
749
+ out[oi++] = y00 + x00 | 0;
750
+ out[oi++] = y01 + x01 | 0;
751
+ out[oi++] = y02 + x02 | 0;
752
+ out[oi++] = y03 + x03 | 0;
753
+ out[oi++] = y04 + x04 | 0;
754
+ out[oi++] = y05 + x05 | 0;
755
+ out[oi++] = y06 + x06 | 0;
756
+ out[oi++] = y07 + x07 | 0;
757
+ out[oi++] = y08 + x08 | 0;
758
+ out[oi++] = y09 + x09 | 0;
759
+ out[oi++] = y10 + x10 | 0;
760
+ out[oi++] = y11 + x11 | 0;
761
+ out[oi++] = y12 + x12 | 0;
762
+ out[oi++] = y13 + x13 | 0;
763
+ out[oi++] = y14 + x14 | 0;
764
+ out[oi++] = y15 + x15 | 0;
765
+ }
766
+ // prettier-ignore
767
+ function hchacha(s, k, i, out) {
768
+ // Runs the shared chachaCore permutation, then subtracts the RFC 8439 feed-forward
769
+ // it applies, recovering the raw permutation words hchacha needs.
770
+ // LE hosts read the caller arrays in place (no copies); BE hosts get
771
+ // byte-swapped scratch copies, wiped before returning.
772
+ const s2 = isLE ? s : swap32IfBE(s.slice(0, 4));
773
+ const k2 = isLE ? k : swap32IfBE(k.slice(0, 8));
774
+ const i2 = isLE ? i : swap32IfBE(i.slice(0, 4));
775
+ const t = new Uint32Array(16);
776
+ chachaCore(s2, k2, i2.subarray(1), t, i2[0]);
777
+ let oi = 0;
778
+ out[oi++] = t[0] - s2[0] | 0;
779
+ out[oi++] = t[1] - s2[1] | 0;
780
+ out[oi++] = t[2] - s2[2] | 0;
781
+ out[oi++] = t[3] - s2[3] | 0;
782
+ out[oi++] = t[12] - i2[0] | 0;
783
+ out[oi++] = t[13] - i2[1] | 0;
784
+ out[oi++] = t[14] - i2[2] | 0;
785
+ out[oi++] = t[15] - i2[3] | 0;
786
+ swap32IfBE(out);
787
+ if (!isLE) clean(s2, k2, i2);
788
+ clean(t);
789
+ }
790
+ const chacha20 = /* @__PURE__ */createCipher(chachaCore, {
791
+ counterRight: false,
792
+ counterLength: 4,
793
+ allowShortKeys: false
794
+ });
795
+ const xchacha20 = /* @__PURE__ */createCipher(chachaCore, {
796
+ counterRight: false,
797
+ counterLength: 8,
798
+ extendNonceFn: hchacha,
799
+ allowShortKeys: false
800
+ });
801
+ // RFC 8439 §2.8.1 pad16(x): shared zero block for AAD/ciphertext padding.
802
+ const ZEROS16 = /* @__PURE__ */new Uint8Array(16);
803
+ // RFC 8439 §2.8 / §2.8.1: aligned inputs add nothing, otherwise append 16-(len%16) zero bytes.
804
+ const updatePadded = (h, msg) => {
805
+ h.update(msg);
806
+ const leftover = msg.length % 16;
807
+ if (leftover) h.update(ZEROS16.subarray(leftover));
808
+ };
809
+ // RFC 8439 §2.6.1 poly1305_key_gen returns `block[0..31]`, so AEAD key
810
+ // generation only needs 32 zero bytes.
811
+ const ZEROS32 = /* @__PURE__ */new Uint8Array(32);
812
+ function computeTag(fn, key, nonce, ciphertext, AAD) {
813
+ if (AAD !== undefined) abytes(AAD, undefined, "AAD");
814
+ // RFC 8439 §2.6 / §2.8: derive the Poly1305 one-time key from counter 0,
815
+ // then MAC AAD || pad16(AAD) || ciphertext || pad16(ciphertext) || len(AAD) || len(ciphertext).
816
+ const authKey = fn(key, nonce, ZEROS32);
817
+ const lengths = u64Lengths(ciphertext.length, AAD ? AAD.length : 0, true);
818
+ // Methods below can be replaced with
819
+ // `return poly1305_computeTag_small(authKey, lengths, ciphertext, AAD)`
820
+ // from `test/misc/micro-ciphers.ts`.
821
+ const h = new Poly1305(authKey);
822
+ if (AAD) updatePadded(h, AAD);
823
+ updatePadded(h, ciphertext);
824
+ h.update(lengths);
825
+ const res = h.digest();
826
+ clean(authKey, lengths);
827
+ return res;
828
+ }
829
+ /**
830
+ * AEAD algorithm from RFC 8439.
831
+ * Salsa20 and chacha (RFC 8439) use poly1305 differently.
832
+ * We could have composed them, but it's hard because of authKey:
833
+ * In salsa20, authKey changes position in salsa stream.
834
+ * In chacha, authKey can't be computed inside computeTag, it modifies the counter.
835
+ */
836
+ const _poly1305_aead = xorStream => (key, nonce, AAD) => {
837
+ // This borrows caller key/nonce/AAD buffers by reference; mutating them after construction
838
+ // changes future encrypt/decrypt results.
839
+ const tagLength = 16;
840
+ return {
841
+ encrypt(plaintext, output) {
842
+ const plength = plaintext.length;
843
+ output = getOutput(plength + tagLength, output, false);
844
+ output.set(plaintext);
845
+ const oPlain = output.subarray(0, -tagLength);
846
+ // RFC 8439 §2.8: payload encryption starts at counter 1 because counter 0 produced the OTK.
847
+ xorStream(key, nonce, oPlain, oPlain, 1);
848
+ const tag = computeTag(xorStream, key, nonce, oPlain, AAD);
849
+ output.set(tag, plength); // append tag
850
+ clean(tag);
851
+ return output;
852
+ },
853
+ decrypt(ciphertext, output) {
854
+ output = getOutput(ciphertext.length - tagLength, output, false);
855
+ const data = ciphertext.subarray(0, -tagLength);
856
+ const passedTag = ciphertext.subarray(-tagLength);
857
+ const tag = computeTag(xorStream, key, nonce, data, AAD);
858
+ // RFC 8439 §2.8 / §4: authenticate ciphertext before decrypting it, and compare tags with
859
+ // the constant-time equalBytes() helper rather than decrypting speculative plaintext first.
860
+ if (!equalBytes(passedTag, tag)) {
861
+ clean(tag);
862
+ return undefined;
863
+ }
864
+ output.set(ciphertext.subarray(0, -tagLength));
865
+ // Actual decryption
866
+ xorStream(key, nonce, output, output, 1); // start stream with i=1
867
+ clean(tag);
868
+ return output;
869
+ }
870
+ };
871
+ };
872
+ /**
873
+ * ChaCha20-Poly1305 from RFC 8439, with a 32-byte key and a 12-byte nonce.
874
+ *
875
+ * @internal
876
+ */
877
+ export const chacha20Poly1305 = /* @__PURE__ */_poly1305_aead(chacha20);
878
+ /**
879
+ * XChaCha20-Poly1305 from draft-irtf-cfrg-xchacha-03, with a 32-byte key and a
880
+ * 24-byte nonce.
881
+ *
882
+ * @internal
883
+ */
884
+ export const xchacha20Poly1305 = /* @__PURE__ */_poly1305_aead(xchacha20);
885
+ //# sourceMappingURL=chacha.js.map