effect 4.0.7 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (679) hide show
  1. package/README.md +1 -1
  2. package/dist/BigDecimal.d.ts.map +1 -1
  3. package/dist/BigDecimal.js +3 -0
  4. package/dist/BigDecimal.js.map +1 -1
  5. package/dist/Channel.d.ts +12 -6
  6. package/dist/Channel.d.ts.map +1 -1
  7. package/dist/Channel.js +9 -3
  8. package/dist/Channel.js.map +1 -1
  9. package/dist/Config.d.ts +7 -1
  10. package/dist/Config.d.ts.map +1 -1
  11. package/dist/Config.js.map +1 -1
  12. package/dist/Context.d.ts +18 -1
  13. package/dist/Context.d.ts.map +1 -1
  14. package/dist/Context.js +27 -8
  15. package/dist/Context.js.map +1 -1
  16. package/dist/Cron.d.ts +81 -11
  17. package/dist/Cron.d.ts.map +1 -1
  18. package/dist/Cron.js +101 -26
  19. package/dist/Cron.js.map +1 -1
  20. package/dist/Duration.d.ts +78 -0
  21. package/dist/Duration.d.ts.map +1 -1
  22. package/dist/Duration.js +123 -0
  23. package/dist/Duration.js.map +1 -1
  24. package/dist/Effect.d.ts +164 -7
  25. package/dist/Effect.d.ts.map +1 -1
  26. package/dist/Effect.js +11 -1
  27. package/dist/Effect.js.map +1 -1
  28. package/dist/FileSystem.d.ts +59 -4
  29. package/dist/FileSystem.d.ts.map +1 -1
  30. package/dist/FileSystem.js +9 -2
  31. package/dist/FileSystem.js.map +1 -1
  32. package/dist/Glob.d.ts +165 -0
  33. package/dist/Glob.d.ts.map +1 -0
  34. package/dist/Glob.js +127 -0
  35. package/dist/Glob.js.map +1 -0
  36. package/dist/Match.d.ts +86 -0
  37. package/dist/Match.d.ts.map +1 -1
  38. package/dist/Match.js +72 -0
  39. package/dist/Match.js.map +1 -1
  40. package/dist/Pool.d.ts +51 -0
  41. package/dist/Pool.d.ts.map +1 -1
  42. package/dist/Pool.js +59 -9
  43. package/dist/Pool.js.map +1 -1
  44. package/dist/Random.d.ts.map +1 -1
  45. package/dist/Random.js +3 -3
  46. package/dist/Random.js.map +1 -1
  47. package/dist/RcMap.d.ts.map +1 -1
  48. package/dist/RcMap.js +8 -2
  49. package/dist/RcMap.js.map +1 -1
  50. package/dist/Schedule.d.ts +18 -1
  51. package/dist/Schedule.d.ts.map +1 -1
  52. package/dist/Schedule.js +7 -2
  53. package/dist/Schedule.js.map +1 -1
  54. package/dist/Schema.d.ts +666 -41
  55. package/dist/Schema.d.ts.map +1 -1
  56. package/dist/Schema.js +650 -0
  57. package/dist/Schema.js.map +1 -1
  58. package/dist/SchemaGetter.d.ts +6 -1
  59. package/dist/SchemaGetter.d.ts.map +1 -1
  60. package/dist/SchemaGetter.js +22 -11
  61. package/dist/SchemaGetter.js.map +1 -1
  62. package/dist/SchemaRepresentation.d.ts +14 -0
  63. package/dist/SchemaRepresentation.d.ts.map +1 -1
  64. package/dist/SchemaRepresentation.js +16 -0
  65. package/dist/SchemaRepresentation.js.map +1 -1
  66. package/dist/SchemaTransformation.d.ts +8 -3
  67. package/dist/SchemaTransformation.d.ts.map +1 -1
  68. package/dist/SchemaTransformation.js +6 -3
  69. package/dist/SchemaTransformation.js.map +1 -1
  70. package/dist/ScopedCache.d.ts.map +1 -1
  71. package/dist/ScopedCache.js +5 -7
  72. package/dist/ScopedCache.js.map +1 -1
  73. package/dist/Semaphore.d.ts +130 -0
  74. package/dist/Semaphore.d.ts.map +1 -1
  75. package/dist/Semaphore.js +40 -0
  76. package/dist/Semaphore.js.map +1 -1
  77. package/dist/Stream.d.ts +13 -4
  78. package/dist/Stream.d.ts.map +1 -1
  79. package/dist/Stream.js +9 -0
  80. package/dist/Stream.js.map +1 -1
  81. package/dist/Terminal.d.ts +18 -1
  82. package/dist/Terminal.d.ts.map +1 -1
  83. package/dist/Terminal.js +1 -1
  84. package/dist/Terminal.js.map +1 -1
  85. package/dist/ai/AiError.d.ts +43 -116
  86. package/dist/ai/AiError.d.ts.map +1 -1
  87. package/dist/ai/AiError.js +53 -72
  88. package/dist/ai/AiError.js.map +1 -1
  89. package/dist/ai/Decision.d.ts +196 -15
  90. package/dist/ai/Decision.d.ts.map +1 -1
  91. package/dist/ai/Decision.js +130 -0
  92. package/dist/ai/Decision.js.map +1 -1
  93. package/dist/ai/DecisionModel.d.ts +54 -13
  94. package/dist/ai/DecisionModel.d.ts.map +1 -1
  95. package/dist/ai/DecisionModel.js +123 -12
  96. package/dist/ai/DecisionModel.js.map +1 -1
  97. package/dist/ai/McpServer.d.ts +630 -29
  98. package/dist/ai/McpServer.d.ts.map +1 -1
  99. package/dist/ai/McpServer.js +562 -116
  100. package/dist/ai/McpServer.js.map +1 -1
  101. package/dist/ai/McpTest.d.ts +130 -0
  102. package/dist/ai/McpTest.d.ts.map +1 -0
  103. package/dist/ai/McpTest.js +237 -0
  104. package/dist/ai/McpTest.js.map +1 -0
  105. package/dist/ai/Response.d.ts +1 -25
  106. package/dist/ai/Response.d.ts.map +1 -1
  107. package/dist/ai/Response.js +1 -10
  108. package/dist/ai/Response.js.map +1 -1
  109. package/dist/ai/Tool.d.ts +19 -1
  110. package/dist/ai/Tool.d.ts.map +1 -1
  111. package/dist/ai/Tool.js.map +1 -1
  112. package/dist/ai/index.d.ts +5 -0
  113. package/dist/ai/index.d.ts.map +1 -1
  114. package/dist/ai/index.js +5 -0
  115. package/dist/ai/index.js.map +1 -1
  116. package/dist/ai/internal/mcpCore.js +17 -12
  117. package/dist/ai/internal/mcpCore.js.map +1 -1
  118. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +4 -5
  119. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  120. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +4 -5
  121. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  122. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +4 -5
  123. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  124. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +4 -5
  125. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  126. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +18 -10
  127. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  128. package/dist/ai/internal/mcpProtocol.js +13 -0
  129. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  130. package/dist/ai/internal/mcpRuntime.js +5 -3
  131. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  132. package/dist/ai/internal/mcpStatefulRuntime.js +6 -1
  133. package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
  134. package/dist/cli/Argument.d.ts +6 -0
  135. package/dist/cli/Argument.d.ts.map +1 -1
  136. package/dist/cli/Argument.js +2 -0
  137. package/dist/cli/Argument.js.map +1 -1
  138. package/dist/cli/CliOutput.d.ts +65 -1
  139. package/dist/cli/CliOutput.d.ts.map +1 -1
  140. package/dist/cli/CliOutput.js +94 -37
  141. package/dist/cli/CliOutput.js.map +1 -1
  142. package/dist/cli/Command.d.ts +23 -0
  143. package/dist/cli/Command.d.ts.map +1 -1
  144. package/dist/cli/Command.js +8 -0
  145. package/dist/cli/Command.js.map +1 -1
  146. package/dist/cli/Flag.d.ts +107 -0
  147. package/dist/cli/Flag.d.ts.map +1 -1
  148. package/dist/cli/Flag.js +37 -0
  149. package/dist/cli/Flag.js.map +1 -1
  150. package/dist/cli/HelpDoc.d.ts +15 -1
  151. package/dist/cli/HelpDoc.d.ts.map +1 -1
  152. package/dist/cli/Param.d.ts +6 -0
  153. package/dist/cli/Param.d.ts.map +1 -1
  154. package/dist/cli/Param.js +2 -0
  155. package/dist/cli/Param.js.map +1 -1
  156. package/dist/cli/Primitive.d.ts +14 -0
  157. package/dist/cli/Primitive.d.ts.map +1 -1
  158. package/dist/cli/Primitive.js +15 -1
  159. package/dist/cli/Primitive.js.map +1 -1
  160. package/dist/cli/Prompt.d.ts +1 -0
  161. package/dist/cli/Prompt.d.ts.map +1 -1
  162. package/dist/cli/Prompt.js +1 -0
  163. package/dist/cli/Prompt.js.map +1 -1
  164. package/dist/cli/internal/help.d.ts.map +1 -1
  165. package/dist/cli/internal/help.js +17 -10
  166. package/dist/cli/internal/help.js.map +1 -1
  167. package/dist/cluster/Sharding.d.ts.map +1 -1
  168. package/dist/cluster/Sharding.js +90 -28
  169. package/dist/cluster/Sharding.js.map +1 -1
  170. package/dist/cluster/ShardingConfig.d.ts +72 -6
  171. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  172. package/dist/cluster/ShardingConfig.js +4 -0
  173. package/dist/cluster/ShardingConfig.js.map +1 -1
  174. package/dist/cluster/SingleRunner.d.ts +3 -3
  175. package/dist/cluster/SingleRunner.d.ts.map +1 -1
  176. package/dist/cluster/SingleRunner.js +1 -1
  177. package/dist/cluster/SqlMessageStorage.d.ts +37 -6
  178. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  179. package/dist/cluster/SqlMessageStorage.js +34 -7
  180. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  181. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  182. package/dist/cluster/SqlRunnerStorage.js +23 -8
  183. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  184. package/dist/crypto/Aead.d.ts +322 -0
  185. package/dist/crypto/Aead.d.ts.map +1 -0
  186. package/dist/crypto/Aead.js +331 -0
  187. package/dist/crypto/Aead.js.map +1 -0
  188. package/dist/crypto/Cipher.d.ts +235 -0
  189. package/dist/crypto/Cipher.d.ts.map +1 -0
  190. package/dist/crypto/Cipher.js +233 -0
  191. package/dist/crypto/Cipher.js.map +1 -0
  192. package/dist/crypto/CryptoError.d.ts +212 -0
  193. package/dist/crypto/CryptoError.d.ts.map +1 -0
  194. package/dist/crypto/CryptoError.js +202 -0
  195. package/dist/crypto/CryptoError.js.map +1 -0
  196. package/dist/crypto/Digest.d.ts +143 -0
  197. package/dist/crypto/Digest.d.ts.map +1 -0
  198. package/dist/crypto/Digest.js +146 -0
  199. package/dist/crypto/Digest.js.map +1 -0
  200. package/dist/crypto/Kdf.d.ts +220 -0
  201. package/dist/crypto/Kdf.d.ts.map +1 -0
  202. package/dist/crypto/Kdf.js +212 -0
  203. package/dist/crypto/Kdf.js.map +1 -0
  204. package/dist/crypto/KeyAgreement.d.ts +323 -0
  205. package/dist/crypto/KeyAgreement.d.ts.map +1 -0
  206. package/dist/crypto/KeyAgreement.js +303 -0
  207. package/dist/crypto/KeyAgreement.js.map +1 -0
  208. package/dist/crypto/KeyFormat.d.ts +309 -0
  209. package/dist/crypto/KeyFormat.d.ts.map +1 -0
  210. package/dist/crypto/KeyFormat.js +556 -0
  211. package/dist/crypto/KeyFormat.js.map +1 -0
  212. package/dist/crypto/KeyWrap.d.ts +389 -0
  213. package/dist/crypto/KeyWrap.d.ts.map +1 -0
  214. package/dist/crypto/KeyWrap.js +381 -0
  215. package/dist/crypto/KeyWrap.js.map +1 -0
  216. package/dist/crypto/Mac.d.ts +277 -0
  217. package/dist/crypto/Mac.d.ts.map +1 -0
  218. package/dist/crypto/Mac.js +288 -0
  219. package/dist/crypto/Mac.js.map +1 -0
  220. package/dist/crypto/SecureRandom.d.ts +340 -0
  221. package/dist/crypto/SecureRandom.d.ts.map +1 -0
  222. package/dist/crypto/SecureRandom.js +257 -0
  223. package/dist/crypto/SecureRandom.js.map +1 -0
  224. package/dist/crypto/Signature.d.ts +448 -0
  225. package/dist/crypto/Signature.d.ts.map +1 -0
  226. package/dist/crypto/Signature.js +484 -0
  227. package/dist/crypto/Signature.js.map +1 -0
  228. package/dist/crypto/WebCrypto.d.ts +61 -0
  229. package/dist/crypto/WebCrypto.d.ts.map +1 -0
  230. package/dist/crypto/WebCrypto.js +63 -0
  231. package/dist/crypto/WebCrypto.js.map +1 -0
  232. package/dist/crypto/index.d.ts +65 -0
  233. package/dist/crypto/index.d.ts.map +1 -0
  234. package/dist/crypto/index.js +66 -0
  235. package/dist/crypto/index.js.map +1 -0
  236. package/dist/crypto/internal/asymmetric.d.ts +2 -0
  237. package/dist/crypto/internal/asymmetric.d.ts.map +1 -0
  238. package/dist/crypto/internal/asymmetric.js +210 -0
  239. package/dist/crypto/internal/asymmetric.js.map +1 -0
  240. package/dist/crypto/internal/chacha.d.ts +46 -0
  241. package/dist/crypto/internal/chacha.d.ts.map +1 -0
  242. package/dist/crypto/internal/chacha.js +885 -0
  243. package/dist/crypto/internal/chacha.js.map +1 -0
  244. package/dist/crypto/internal/der.d.ts +6 -0
  245. package/dist/crypto/internal/der.d.ts.map +1 -0
  246. package/dist/crypto/internal/der.js +86 -0
  247. package/dist/crypto/internal/der.js.map +1 -0
  248. package/dist/crypto/internal/digest.d.ts +2 -0
  249. package/dist/crypto/internal/digest.d.ts.map +1 -0
  250. package/dist/crypto/internal/digest.js +15 -0
  251. package/dist/crypto/internal/digest.js.map +1 -0
  252. package/dist/crypto/internal/key.d.ts +2 -0
  253. package/dist/crypto/internal/key.d.ts.map +1 -0
  254. package/dist/crypto/internal/key.js +170 -0
  255. package/dist/crypto/internal/key.js.map +1 -0
  256. package/dist/crypto/internal/md5.d.ts +39 -0
  257. package/dist/crypto/internal/md5.d.ts.map +1 -0
  258. package/dist/crypto/internal/md5.js +179 -0
  259. package/dist/crypto/internal/md5.js.map +1 -0
  260. package/dist/crypto/internal/webCrypto.d.ts +2 -0
  261. package/dist/crypto/internal/webCrypto.d.ts.map +1 -0
  262. package/dist/crypto/internal/webCrypto.js +111 -0
  263. package/dist/crypto/internal/webCrypto.js.map +1 -0
  264. package/dist/encoding/Base64Url.d.ts.map +1 -1
  265. package/dist/encoding/Base64Url.js +3 -2
  266. package/dist/encoding/Base64Url.js.map +1 -1
  267. package/dist/encoding/Csv.d.ts +608 -0
  268. package/dist/encoding/Csv.d.ts.map +1 -0
  269. package/dist/encoding/Csv.js +718 -0
  270. package/dist/encoding/Csv.js.map +1 -0
  271. package/dist/encoding/Hex.d.ts +3 -2
  272. package/dist/encoding/Hex.d.ts.map +1 -1
  273. package/dist/encoding/Hex.js +3 -2
  274. package/dist/encoding/Hex.js.map +1 -1
  275. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  276. package/dist/encoding/SchemaBinary.js +42 -4
  277. package/dist/encoding/SchemaBinary.js.map +1 -1
  278. package/dist/encoding/Toml.d.ts +17 -3
  279. package/dist/encoding/Toml.d.ts.map +1 -1
  280. package/dist/encoding/Toml.js +104 -16
  281. package/dist/encoding/Toml.js.map +1 -1
  282. package/dist/encoding/Yaml.d.ts +8 -1
  283. package/dist/encoding/Yaml.d.ts.map +1 -1
  284. package/dist/encoding/Yaml.js +54 -18
  285. package/dist/encoding/Yaml.js.map +1 -1
  286. package/dist/encoding/index.d.ts +5 -0
  287. package/dist/encoding/index.d.ts.map +1 -1
  288. package/dist/encoding/index.js +5 -0
  289. package/dist/encoding/index.js.map +1 -1
  290. package/dist/eventlog/EventJournal.d.ts.map +1 -1
  291. package/dist/eventlog/EventJournal.js +6 -3
  292. package/dist/eventlog/EventJournal.js.map +1 -1
  293. package/dist/eventlog/EventLog.d.ts +119 -4
  294. package/dist/eventlog/EventLog.d.ts.map +1 -1
  295. package/dist/eventlog/EventLog.js +200 -12
  296. package/dist/eventlog/EventLog.js.map +1 -1
  297. package/dist/eventlog/EventLogEncryption.d.ts +41 -4
  298. package/dist/eventlog/EventLogEncryption.d.ts.map +1 -1
  299. package/dist/eventlog/EventLogEncryption.js +83 -64
  300. package/dist/eventlog/EventLogEncryption.js.map +1 -1
  301. package/dist/eventlog/EventLogMessage.d.ts +279 -0
  302. package/dist/eventlog/EventLogMessage.d.ts.map +1 -1
  303. package/dist/eventlog/EventLogMessage.js +217 -1
  304. package/dist/eventlog/EventLogMessage.js.map +1 -1
  305. package/dist/eventlog/EventLogRemote.d.ts +200 -28
  306. package/dist/eventlog/EventLogRemote.d.ts.map +1 -1
  307. package/dist/eventlog/EventLogRemote.js +186 -16
  308. package/dist/eventlog/EventLogRemote.js.map +1 -1
  309. package/dist/eventlog/EventLogServer.d.ts +3 -0
  310. package/dist/eventlog/EventLogServer.d.ts.map +1 -1
  311. package/dist/eventlog/EventLogServer.js +18 -10
  312. package/dist/eventlog/EventLogServer.js.map +1 -1
  313. package/dist/eventlog/EventLogServerEncrypted.d.ts +326 -5
  314. package/dist/eventlog/EventLogServerEncrypted.d.ts.map +1 -1
  315. package/dist/eventlog/EventLogServerEncrypted.js +769 -14
  316. package/dist/eventlog/EventLogServerEncrypted.js.map +1 -1
  317. package/dist/eventlog/EventLogSessionAuth.d.ts +5 -3
  318. package/dist/eventlog/EventLogSessionAuth.d.ts.map +1 -1
  319. package/dist/eventlog/EventLogSessionAuth.js +41 -64
  320. package/dist/eventlog/EventLogSessionAuth.js.map +1 -1
  321. package/dist/eventlog/EventRow.d.ts +4 -0
  322. package/dist/eventlog/EventRow.d.ts.map +1 -1
  323. package/dist/eventlog/EventRow.js +12 -2
  324. package/dist/eventlog/EventRow.js.map +1 -1
  325. package/dist/eventlog/SqlEventJournal.js +2 -2
  326. package/dist/eventlog/SqlEventJournal.js.map +1 -1
  327. package/dist/eventlog/SqlEventLogServerEncrypted.d.ts +21 -5
  328. package/dist/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
  329. package/dist/eventlog/SqlEventLogServerEncrypted.js +1048 -113
  330. package/dist/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  331. package/dist/eventlog/SqlEventLogServerUnencrypted.js +2 -2
  332. package/dist/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  333. package/dist/eventlog/internal/batches.d.ts +12 -0
  334. package/dist/eventlog/internal/batches.d.ts.map +1 -0
  335. package/dist/eventlog/internal/batches.js +26 -0
  336. package/dist/eventlog/internal/batches.js.map +1 -0
  337. package/dist/eventlog/internal/compaction.d.ts +38 -0
  338. package/dist/eventlog/internal/compaction.d.ts.map +1 -0
  339. package/dist/eventlog/internal/compaction.js +33 -0
  340. package/dist/eventlog/internal/compaction.js.map +1 -0
  341. package/dist/eventlog/internal/identityRootSecretDerivation.js +66 -67
  342. package/dist/eventlog/internal/identityRootSecretDerivation.js.map +1 -1
  343. package/dist/eventlog/internal/remoteCompaction.d.ts +31 -0
  344. package/dist/eventlog/internal/remoteCompaction.d.ts.map +1 -0
  345. package/dist/eventlog/internal/remoteCompaction.js +76 -0
  346. package/dist/eventlog/internal/remoteCompaction.js.map +1 -0
  347. package/dist/http/Cookies.d.ts +172 -0
  348. package/dist/http/Cookies.d.ts.map +1 -1
  349. package/dist/http/Cookies.js +143 -1
  350. package/dist/http/Cookies.js.map +1 -1
  351. package/dist/http/FetchHttpClient.d.ts +26 -2
  352. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  353. package/dist/http/FetchHttpClient.js +78 -15
  354. package/dist/http/FetchHttpClient.js.map +1 -1
  355. package/dist/http/HttpClient.d.ts +79 -8
  356. package/dist/http/HttpClient.d.ts.map +1 -1
  357. package/dist/http/HttpClient.js +65 -5
  358. package/dist/http/HttpClient.js.map +1 -1
  359. package/dist/http/HttpClientRequest.d.ts +9 -5
  360. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  361. package/dist/http/HttpClientRequest.js +2 -3
  362. package/dist/http/HttpClientRequest.js.map +1 -1
  363. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  364. package/dist/http/HttpClientResponse.js +3 -2
  365. package/dist/http/HttpClientResponse.js.map +1 -1
  366. package/dist/http/HttpMethod.d.ts +7 -1
  367. package/dist/http/HttpMethod.d.ts.map +1 -1
  368. package/dist/http/HttpMethod.js +3 -8
  369. package/dist/http/HttpMethod.js.map +1 -1
  370. package/dist/http/HttpServerRequest.d.ts +5 -2
  371. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  372. package/dist/http/HttpServerRequest.js +6 -17
  373. package/dist/http/HttpServerRequest.js.map +1 -1
  374. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  375. package/dist/http/HttpServerResponse.js +3 -2
  376. package/dist/http/HttpServerResponse.js.map +1 -1
  377. package/dist/http/HttpTraceContext.d.ts +2 -1
  378. package/dist/http/HttpTraceContext.d.ts.map +1 -1
  379. package/dist/http/HttpTraceContext.js +7 -5
  380. package/dist/http/HttpTraceContext.js.map +1 -1
  381. package/dist/http/ProblemDetails.d.ts +96 -0
  382. package/dist/http/ProblemDetails.d.ts.map +1 -0
  383. package/dist/http/ProblemDetails.js +98 -0
  384. package/dist/http/ProblemDetails.js.map +1 -0
  385. package/dist/http/index.d.ts +5 -0
  386. package/dist/http/index.d.ts.map +1 -1
  387. package/dist/http/index.js +5 -0
  388. package/dist/http/index.js.map +1 -1
  389. package/dist/http/internal/decompression.js +3 -2
  390. package/dist/http/internal/decompression.js.map +1 -1
  391. package/dist/http/internal/urlParams.js +8 -0
  392. package/dist/http/internal/urlParams.js.map +1 -1
  393. package/dist/http-api/HttpApiBuilder.js +19 -5
  394. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  395. package/dist/http-api/HttpApiClient.d.ts +63 -0
  396. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  397. package/dist/http-api/HttpApiClient.js +51 -0
  398. package/dist/http-api/HttpApiClient.js.map +1 -1
  399. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  400. package/dist/http-api/HttpApiEndpoint.js +14 -5
  401. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  402. package/dist/http-api/HttpApiError.d.ts +185 -13
  403. package/dist/http-api/HttpApiError.d.ts.map +1 -1
  404. package/dist/http-api/HttpApiError.js +128 -0
  405. package/dist/http-api/HttpApiError.js.map +1 -1
  406. package/dist/http-api/HttpApiMiddleware.d.ts +64 -17
  407. package/dist/http-api/HttpApiMiddleware.d.ts.map +1 -1
  408. package/dist/http-api/HttpApiMiddleware.js +85 -1
  409. package/dist/http-api/HttpApiMiddleware.js.map +1 -1
  410. package/dist/http-api/HttpApiSchema.d.ts +76 -14
  411. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  412. package/dist/http-api/HttpApiSchema.js +53 -0
  413. package/dist/http-api/HttpApiSchema.js.map +1 -1
  414. package/dist/index.d.ts +5 -5
  415. package/dist/index.d.ts.map +1 -1
  416. package/dist/index.js +5 -5
  417. package/dist/index.js.map +1 -1
  418. package/dist/internal/effect.js +25 -14
  419. package/dist/internal/effect.js.map +1 -1
  420. package/dist/internal/glob.d.ts +2 -0
  421. package/dist/internal/glob.d.ts.map +1 -0
  422. package/dist/internal/glob.js +630 -0
  423. package/dist/internal/glob.js.map +1 -0
  424. package/dist/internal/matcher.js +10 -0
  425. package/dist/internal/matcher.js.map +1 -1
  426. package/dist/internal/persistence.js +9 -0
  427. package/dist/internal/persistence.js.map +1 -1
  428. package/dist/internal/rcRef.js +4 -1
  429. package/dist/internal/rcRef.js.map +1 -1
  430. package/dist/internal/schema/toCodeDocument.js +6 -3
  431. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  432. package/dist/internal/trie.js +42 -13
  433. package/dist/internal/trie.js.map +1 -1
  434. package/dist/internal/ulid.js +41 -0
  435. package/dist/internal/ulid.js.map +1 -1
  436. package/dist/internal/uuid.js +52 -8
  437. package/dist/internal/uuid.js.map +1 -1
  438. package/dist/internal/version.js +1 -1
  439. package/dist/observability/Otlp.d.ts +15 -4
  440. package/dist/observability/Otlp.d.ts.map +1 -1
  441. package/dist/observability/Otlp.js +10 -0
  442. package/dist/observability/Otlp.js.map +1 -1
  443. package/dist/observability/OtlpResource.d.ts +7 -0
  444. package/dist/observability/OtlpResource.d.ts.map +1 -1
  445. package/dist/observability/OtlpResource.js +11 -1
  446. package/dist/observability/OtlpResource.js.map +1 -1
  447. package/dist/persistence/KeyValueStore.d.ts +47 -2
  448. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  449. package/dist/persistence/KeyValueStore.js +129 -18
  450. package/dist/persistence/KeyValueStore.js.map +1 -1
  451. package/dist/persistence/PersistedQueue.d.ts +9 -0
  452. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  453. package/dist/persistence/PersistedQueue.js +94 -52
  454. package/dist/persistence/PersistedQueue.js.map +1 -1
  455. package/dist/persistence/Persistence.d.ts +10 -4
  456. package/dist/persistence/Persistence.d.ts.map +1 -1
  457. package/dist/persistence/Persistence.js +18 -11
  458. package/dist/persistence/Persistence.js.map +1 -1
  459. package/dist/process/ChildProcess.d.ts +207 -67
  460. package/dist/process/ChildProcess.d.ts.map +1 -1
  461. package/dist/process/ChildProcess.js +56 -158
  462. package/dist/process/ChildProcess.js.map +1 -1
  463. package/dist/process/ChildProcessSpawner.d.ts +5 -0
  464. package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
  465. package/dist/process/ChildProcessSpawner.js.map +1 -1
  466. package/dist/process/CommandLine.d.ts +294 -0
  467. package/dist/process/CommandLine.d.ts.map +1 -0
  468. package/dist/process/CommandLine.js +481 -0
  469. package/dist/process/CommandLine.js.map +1 -0
  470. package/dist/process/index.d.ts +5 -0
  471. package/dist/process/index.d.ts.map +1 -1
  472. package/dist/process/index.js +5 -0
  473. package/dist/process/index.js.map +1 -1
  474. package/dist/reactivity/Atom.d.ts +2 -1
  475. package/dist/reactivity/Atom.d.ts.map +1 -1
  476. package/dist/reactivity/Atom.js +3 -4
  477. package/dist/reactivity/Atom.js.map +1 -1
  478. package/dist/reactivity/AtomRegistry.js.map +1 -1
  479. package/dist/rpc/RpcClient.d.ts +16 -1
  480. package/dist/rpc/RpcClient.d.ts.map +1 -1
  481. package/dist/rpc/RpcClient.js +50 -16
  482. package/dist/rpc/RpcClient.js.map +1 -1
  483. package/dist/rpc/RpcMessage.d.ts +10 -1
  484. package/dist/rpc/RpcMessage.d.ts.map +1 -1
  485. package/dist/rpc/RpcMessage.js +1 -0
  486. package/dist/rpc/RpcMessage.js.map +1 -1
  487. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  488. package/dist/rpc/RpcSerialization.js +6 -0
  489. package/dist/rpc/RpcSerialization.js.map +1 -1
  490. package/dist/rpc/RpcServer.d.ts +31 -0
  491. package/dist/rpc/RpcServer.d.ts.map +1 -1
  492. package/dist/rpc/RpcServer.js +139 -66
  493. package/dist/rpc/RpcServer.js.map +1 -1
  494. package/dist/schema/Model.d.ts +14 -0
  495. package/dist/schema/Model.d.ts.map +1 -1
  496. package/dist/schema/Model.js +18 -3
  497. package/dist/schema/Model.js.map +1 -1
  498. package/dist/sql/Migrator.d.ts +0 -19
  499. package/dist/sql/Migrator.d.ts.map +1 -1
  500. package/dist/sql/Migrator.js +3 -48
  501. package/dist/sql/Migrator.js.map +1 -1
  502. package/dist/sql/MigratorFileSystem.d.ts +21 -0
  503. package/dist/sql/MigratorFileSystem.d.ts.map +1 -0
  504. package/dist/sql/MigratorFileSystem.js +57 -0
  505. package/dist/sql/MigratorFileSystem.js.map +1 -0
  506. package/dist/sql/SqlClient.d.ts.map +1 -1
  507. package/dist/sql/SqlClient.js +5 -9
  508. package/dist/sql/SqlClient.js.map +1 -1
  509. package/dist/sql/Statement.d.ts +20 -6
  510. package/dist/sql/Statement.d.ts.map +1 -1
  511. package/dist/sql/Statement.js +0 -13
  512. package/dist/sql/Statement.js.map +1 -1
  513. package/dist/sql/index.js +1 -1
  514. package/dist/testing/index.d.ts +0 -5
  515. package/dist/testing/index.d.ts.map +1 -1
  516. package/dist/testing/index.js +0 -5
  517. package/dist/testing/index.js.map +1 -1
  518. package/dist/workflow/internal/crypto.js +9 -8
  519. package/dist/workflow/internal/crypto.js.map +1 -1
  520. package/package.json +3 -1
  521. package/src/BigDecimal.ts +3 -0
  522. package/src/Channel.ts +17 -11
  523. package/src/Config.ts +7 -1
  524. package/src/Context.ts +34 -10
  525. package/src/Cron.ts +178 -29
  526. package/src/Duration.ts +140 -0
  527. package/src/Effect.ts +914 -85
  528. package/src/FileSystem.ts +65 -4
  529. package/src/Glob.ts +205 -0
  530. package/src/Match.ts +127 -0
  531. package/src/Pool.ts +73 -15
  532. package/src/Random.ts +3 -3
  533. package/src/RcMap.ts +5 -1
  534. package/src/Schedule.ts +26 -3
  535. package/src/Schema.ts +1189 -62
  536. package/src/SchemaGetter.ts +27 -11
  537. package/src/SchemaRepresentation.ts +19 -0
  538. package/src/SchemaTransformation.ts +8 -3
  539. package/src/ScopedCache.ts +5 -9
  540. package/src/Semaphore.ts +141 -0
  541. package/src/Stream.ts +15 -6
  542. package/src/Terminal.ts +19 -1
  543. package/src/ai/AiError.ts +56 -80
  544. package/src/ai/Decision.ts +257 -6
  545. package/src/ai/DecisionModel.ts +171 -28
  546. package/src/ai/McpServer.ts +1269 -286
  547. package/src/ai/McpTest.ts +380 -0
  548. package/src/ai/Response.ts +2 -22
  549. package/src/ai/Tool.ts +27 -8
  550. package/src/ai/index.ts +6 -0
  551. package/src/ai/internal/mcpCore.ts +78 -44
  552. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +4 -7
  553. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +4 -7
  554. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +4 -7
  555. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +4 -7
  556. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +15 -10
  557. package/src/ai/internal/mcpProtocol.ts +29 -0
  558. package/src/ai/internal/mcpRuntime.ts +9 -5
  559. package/src/ai/internal/mcpStatefulRuntime.ts +14 -2
  560. package/src/cli/Argument.ts +6 -0
  561. package/src/cli/CliOutput.ts +117 -49
  562. package/src/cli/Command.ts +23 -0
  563. package/src/cli/Flag.ts +107 -0
  564. package/src/cli/HelpDoc.ts +18 -1
  565. package/src/cli/Param.ts +6 -0
  566. package/src/cli/Primitive.ts +16 -1
  567. package/src/cli/Prompt.ts +1 -0
  568. package/src/cli/internal/help.ts +21 -9
  569. package/src/cluster/Sharding.ts +93 -26
  570. package/src/cluster/ShardingConfig.ts +41 -3
  571. package/src/cluster/SingleRunner.ts +3 -3
  572. package/src/cluster/SqlMessageStorage.ts +49 -17
  573. package/src/cluster/SqlRunnerStorage.ts +37 -27
  574. package/src/crypto/Aead.ts +517 -0
  575. package/src/crypto/Cipher.ts +326 -0
  576. package/src/crypto/CryptoError.ts +242 -0
  577. package/src/crypto/Digest.ts +167 -0
  578. package/src/crypto/Kdf.ts +315 -0
  579. package/src/crypto/KeyAgreement.ts +489 -0
  580. package/src/crypto/KeyFormat.ts +712 -0
  581. package/src/crypto/KeyWrap.ts +639 -0
  582. package/src/crypto/Mac.ts +386 -0
  583. package/src/crypto/SecureRandom.ts +459 -0
  584. package/src/crypto/Signature.ts +673 -0
  585. package/src/crypto/WebCrypto.ts +64 -0
  586. package/src/crypto/index.ts +78 -0
  587. package/src/crypto/internal/asymmetric.ts +329 -0
  588. package/src/crypto/internal/chacha.ts +1088 -0
  589. package/src/crypto/internal/der.ts +110 -0
  590. package/src/crypto/internal/digest.ts +16 -0
  591. package/src/crypto/internal/key.ts +235 -0
  592. package/src/crypto/internal/md5.ts +170 -0
  593. package/src/crypto/internal/webCrypto.ts +150 -0
  594. package/src/encoding/Base64Url.ts +5 -2
  595. package/src/encoding/Csv.ts +1298 -0
  596. package/src/encoding/Hex.ts +3 -2
  597. package/src/encoding/SchemaBinary.ts +40 -4
  598. package/src/encoding/Toml.ts +85 -20
  599. package/src/encoding/Yaml.ts +61 -18
  600. package/src/encoding/index.ts +6 -0
  601. package/src/eventlog/EventJournal.ts +4 -3
  602. package/src/eventlog/EventLog.ts +340 -15
  603. package/src/eventlog/EventLogEncryption.ts +118 -110
  604. package/src/eventlog/EventLogMessage.ts +273 -1
  605. package/src/eventlog/EventLogRemote.ts +367 -23
  606. package/src/eventlog/EventLogServer.ts +23 -8
  607. package/src/eventlog/EventLogServerEncrypted.ts +1130 -67
  608. package/src/eventlog/EventLogSessionAuth.ts +56 -70
  609. package/src/eventlog/EventRow.ts +12 -3
  610. package/src/eventlog/SqlEventJournal.ts +2 -2
  611. package/src/eventlog/SqlEventLogServerEncrypted.ts +1244 -136
  612. package/src/eventlog/SqlEventLogServerUnencrypted.ts +2 -2
  613. package/src/eventlog/internal/batches.ts +30 -0
  614. package/src/eventlog/internal/compaction.ts +64 -0
  615. package/src/eventlog/internal/identityRootSecretDerivation.ts +93 -123
  616. package/src/eventlog/internal/remoteCompaction.ts +92 -0
  617. package/src/http/Cookies.ts +281 -1
  618. package/src/http/FetchHttpClient.ts +88 -16
  619. package/src/http/HttpClient.ts +89 -22
  620. package/src/http/HttpClientRequest.ts +12 -9
  621. package/src/http/HttpClientResponse.ts +3 -2
  622. package/src/http/HttpMethod.ts +10 -2
  623. package/src/http/HttpServerRequest.ts +15 -30
  624. package/src/http/HttpServerResponse.ts +3 -2
  625. package/src/http/HttpTraceContext.ts +7 -4
  626. package/src/http/ProblemDetails.ts +149 -0
  627. package/src/http/index.ts +6 -0
  628. package/src/http/internal/decompression.ts +4 -4
  629. package/src/http/internal/urlParams.ts +8 -0
  630. package/src/http-api/HttpApiBuilder.ts +24 -12
  631. package/src/http-api/HttpApiClient.ts +67 -1
  632. package/src/http-api/HttpApiEndpoint.ts +14 -5
  633. package/src/http-api/HttpApiError.ts +250 -0
  634. package/src/http-api/HttpApiMiddleware.ts +95 -1
  635. package/src/http-api/HttpApiSchema.ts +105 -14
  636. package/src/index.ts +6 -6
  637. package/src/internal/effect.ts +34 -18
  638. package/src/internal/glob.ts +736 -0
  639. package/src/internal/matcher.ts +17 -0
  640. package/src/internal/persistence.ts +11 -0
  641. package/src/internal/rcRef.ts +4 -1
  642. package/src/internal/schema/toCodeDocument.ts +7 -3
  643. package/src/internal/trie.ts +43 -14
  644. package/src/internal/ulid.ts +44 -0
  645. package/src/internal/uuid.ts +57 -16
  646. package/src/internal/version.ts +1 -1
  647. package/src/observability/Otlp.ts +21 -4
  648. package/src/observability/OtlpResource.ts +9 -1
  649. package/src/persistence/KeyValueStore.ts +219 -22
  650. package/src/persistence/PersistedQueue.ts +128 -59
  651. package/src/persistence/Persistence.ts +20 -13
  652. package/src/process/ChildProcess.ts +255 -260
  653. package/src/process/ChildProcessSpawner.ts +5 -0
  654. package/src/process/CommandLine.ts +630 -0
  655. package/src/process/index.ts +6 -0
  656. package/src/reactivity/Atom.ts +5 -5
  657. package/src/reactivity/AtomRegistry.ts +1 -1
  658. package/src/rpc/RpcClient.ts +62 -26
  659. package/src/rpc/RpcMessage.ts +10 -1
  660. package/src/rpc/RpcSerialization.ts +3 -0
  661. package/src/rpc/RpcServer.ts +176 -78
  662. package/src/schema/Model.ts +26 -3
  663. package/src/sql/Migrator.ts +4 -63
  664. package/src/sql/MigratorFileSystem.ts +71 -0
  665. package/src/sql/SqlClient.ts +2 -16
  666. package/src/sql/Statement.ts +8 -7
  667. package/src/sql/index.ts +1 -1
  668. package/src/testing/index.ts +0 -6
  669. package/src/workflow/internal/crypto.ts +15 -11
  670. package/dist/Crypto.d.ts +0 -244
  671. package/dist/Crypto.d.ts.map +0 -1
  672. package/dist/Crypto.js +0 -139
  673. package/dist/Crypto.js.map +0 -1
  674. package/dist/testing/TestCrypto.d.ts +0 -73
  675. package/dist/testing/TestCrypto.d.ts.map +0 -1
  676. package/dist/testing/TestCrypto.js +0 -87
  677. package/dist/testing/TestCrypto.js.map +0 -1
  678. package/src/Crypto.ts +0 -347
  679. package/src/testing/TestCrypto.ts +0 -94
@@ -0,0 +1,322 @@
1
+ /**
2
+ * Authenticated encryption: AES-GCM, ChaCha20-Poly1305, and
3
+ * XChaCha20-Poly1305.
4
+ *
5
+ * The {@link Aead} service generates keys, encrypts, and decrypts. The
6
+ * top-level {@link key}, {@link fromCryptoKey}, and {@link toBytes} functions
7
+ * build and export keys without a service.
8
+ *
9
+ * Ciphertext is `ciphertext‖tag` with a 16-byte tag for every algorithm, the
10
+ * layout WebCrypto produces. A tampered ciphertext, tag, or additional data
11
+ * fails decryption with a `DecryptionFailed` reason that carries no detail.
12
+ *
13
+ * AES-GCM runs on `crypto.subtle`. ChaCha20-Poly1305 and XChaCha20-Poly1305
14
+ * run a pure TypeScript implementation vendored from `@noble/ciphers` 2.4.0,
15
+ * because WebCrypto does not provide them everywhere. Cure53 audited
16
+ * `@noble/ciphers` 1.0.0 in 2024.
17
+ *
18
+ * Keys are opaque. They hold either key bytes or, for AES-GCM, a `CryptoKey`,
19
+ * display only their algorithm, and compare by reference.
20
+ *
21
+ * **Gotchas**
22
+ *
23
+ * Never reuse a nonce with the same key. Random 12-byte nonces risk a
24
+ * collision after about 2^32 messages under one key: use a counter, or
25
+ * XChaCha20-Poly1305, whose 24-byte nonces can be random.
26
+ *
27
+ * @stability unstable
28
+ * @since 4.0.0
29
+ */
30
+ import * as Context from "../Context.ts";
31
+ import * as Effect from "../Effect.ts";
32
+ import type { Inspectable } from "../Inspectable.ts";
33
+ import * as Layer from "../Layer.ts";
34
+ import * as CryptoError from "./CryptoError.ts";
35
+ import * as SecureRandom from "./SecureRandom.ts";
36
+ declare const TypeId: "~effect/crypto/Aead/Key";
37
+ /**
38
+ * The synchronous code of an algorithm: the pure TypeScript code of one that
39
+ * WebCrypto does not provide, or a native implementation passed to
40
+ * {@link layerWebCryptoWith}.
41
+ *
42
+ * **Details**
43
+ *
44
+ * `encrypt` returns `ciphertext‖tag`. `decrypt` takes `ciphertext‖tag` and
45
+ * returns `undefined` when the tag does not match. Both receive arguments the
46
+ * layer has already checked.
47
+ *
48
+ * @stability unstable
49
+ * @category models
50
+ * @since 4.0.0
51
+ */
52
+ export interface Implementation {
53
+ readonly encrypt: (key: Uint8Array, nonce: Uint8Array, plaintext: Uint8Array, aad: Uint8Array) => Uint8Array;
54
+ readonly decrypt: (key: Uint8Array, nonce: Uint8Array, ciphertext: Uint8Array, aad: Uint8Array) => Uint8Array | undefined;
55
+ }
56
+ /**
57
+ * An authenticated encryption algorithm, such as {@link aes256Gcm}.
58
+ *
59
+ * **Details**
60
+ *
61
+ * `keyLength` and `nonceLength` are in bytes. `implementation` is the pure
62
+ * TypeScript code for algorithms that WebCrypto does not provide, which a
63
+ * layer calls when it has no native mapping for `name`.
64
+ *
65
+ * @stability unstable
66
+ * @category models
67
+ * @since 4.0.0
68
+ */
69
+ export interface Algorithm {
70
+ readonly name: "aes128Gcm" | "aes256Gcm" | "chacha20Poly1305" | "xchacha20Poly1305";
71
+ readonly keyLength: 16 | 32;
72
+ readonly nonceLength: 12 | 24;
73
+ readonly implementation: Implementation | undefined;
74
+ }
75
+ /**
76
+ * AES-GCM, from {@link aes128Gcm} or {@link aes256Gcm}: the algorithms that
77
+ * run on `crypto.subtle`, and the only ones {@link fromCryptoKey} accepts.
78
+ *
79
+ * @stability unstable
80
+ * @category models
81
+ * @since 4.0.0
82
+ */
83
+ export interface AesGcm extends Algorithm {
84
+ readonly name: "aes128Gcm" | "aes256Gcm";
85
+ readonly nonceLength: 12;
86
+ readonly implementation: undefined;
87
+ }
88
+ /**
89
+ * AES-128-GCM, with a 16-byte key and a 12-byte nonce.
90
+ *
91
+ * @stability unstable
92
+ * @category algorithms
93
+ * @since 4.0.0
94
+ */
95
+ export declare const aes128Gcm: AesGcm;
96
+ /**
97
+ * AES-256-GCM, with a 32-byte key and a 12-byte nonce.
98
+ *
99
+ * @stability unstable
100
+ * @category algorithms
101
+ * @since 4.0.0
102
+ */
103
+ export declare const aes256Gcm: AesGcm;
104
+ /**
105
+ * ChaCha20-Poly1305 (RFC 8439), with a 32-byte key and a 12-byte nonce.
106
+ *
107
+ * **Details**
108
+ *
109
+ * Runs the pure TypeScript implementation under `layerWebCrypto`, even where
110
+ * `crypto.subtle` provides it, so every runtime takes one code path.
111
+ *
112
+ * @stability unstable
113
+ * @category algorithms
114
+ * @since 4.0.0
115
+ */
116
+ export declare const chacha20Poly1305: Algorithm;
117
+ /**
118
+ * XChaCha20-Poly1305 (draft-irtf-cfrg-xchacha-03), with a 32-byte key and a
119
+ * 24-byte nonce.
120
+ *
121
+ * **When to use**
122
+ *
123
+ * Use when nonces are generated randomly, since 24-byte nonces make
124
+ * collisions negligible. The output is compatible with libsodium's
125
+ * `crypto_aead_xchacha20poly1305_ietf`.
126
+ *
127
+ * @stability unstable
128
+ * @category algorithms
129
+ * @since 4.0.0
130
+ */
131
+ export declare const xchacha20Poly1305: Algorithm;
132
+ /**
133
+ * An opaque authenticated encryption key for the algorithm `A`.
134
+ *
135
+ * **Details**
136
+ *
137
+ * The key holds either key bytes or a `CryptoKey` from {@link fromCryptoKey}.
138
+ * `toString`, `toJSON`, and `inspect` show only the algorithm. Keys compare
139
+ * by reference and do not implement `Equal`, because comparing key bytes is
140
+ * not constant time.
141
+ *
142
+ * @stability unstable
143
+ * @category models
144
+ * @since 4.0.0
145
+ */
146
+ export interface Key<out A extends Algorithm = Algorithm> extends Inspectable {
147
+ readonly [TypeId]: typeof TypeId;
148
+ readonly algorithm: A;
149
+ }
150
+ /**
151
+ * Checks whether a value is a {@link Key}.
152
+ *
153
+ * @stability unstable
154
+ * @category guards
155
+ * @since 4.0.0
156
+ */
157
+ export declare const isKey: (u: unknown) => u is Key;
158
+ declare const Aead_base: Context.ServiceClass<Aead, "effect/crypto/Aead", {
159
+ /**
160
+ * Generates a random key of the algorithm's length from `SecureRandom`
161
+ * bytes.
162
+ */
163
+ readonly generateKey: <A extends Algorithm>(algorithm: A) => Effect.Effect<Key<A>, CryptoError.CryptoError>;
164
+ /**
165
+ * Encrypts `plaintext` and appends the 16-byte tag.
166
+ *
167
+ * `nonce` must have the algorithm's nonce length. `aad` is authenticated
168
+ * without being encrypted and defaults to empty.
169
+ */
170
+ readonly encrypt: (key: Key, plaintext: Uint8Array, options: {
171
+ readonly nonce: Uint8Array;
172
+ readonly aad?: Uint8Array | undefined;
173
+ }) => Effect.Effect<Uint8Array, CryptoError.CryptoError>;
174
+ /**
175
+ * Checks the tag at the end of `ciphertext` and decrypts the rest, failing
176
+ * with a `DecryptionFailed` reason when the tag does not match.
177
+ *
178
+ * `nonce` and `aad` must be the ones used to encrypt.
179
+ */
180
+ readonly decrypt: (key: Key, ciphertext: Uint8Array, options: {
181
+ readonly nonce: Uint8Array;
182
+ readonly aad?: Uint8Array | undefined;
183
+ }) => Effect.Effect<Uint8Array, CryptoError.CryptoError>;
184
+ }>;
185
+ /**
186
+ * Service that generates keys, encrypts, and decrypts with authentication.
187
+ *
188
+ * **Example** (Encrypting with XChaCha20-Poly1305)
189
+ *
190
+ * ```ts import.meta.vitest
191
+ * import { Effect, Layer } from "effect"
192
+ * import { Aead, SecureRandom } from "effect/crypto"
193
+ *
194
+ * const program = Effect.gen(function*() {
195
+ * const aead = yield* Aead.Aead
196
+ * const random = yield* SecureRandom.SecureRandom
197
+ * const key = yield* aead.generateKey(Aead.xchacha20Poly1305)
198
+ * const nonce = yield* random.randomBytes(24)
199
+ * const sealed = yield* aead.encrypt(key, new TextEncoder().encode("secret"), { nonce })
200
+ * const opened = yield* aead.decrypt(key, sealed, { nonce })
201
+ * return [sealed.length, new TextDecoder().decode(opened)]
202
+ * })
203
+ *
204
+ * const layer = Aead.layerWebCrypto.pipe(Layer.provideMerge(SecureRandom.layerWebCrypto))
205
+ * await Effect.runPromise(program.pipe(Effect.provide(layer))) // => [22, "secret"]
206
+ * ```
207
+ *
208
+ * @stability unstable
209
+ * @category services
210
+ * @since 4.0.0
211
+ */
212
+ export declare class Aead extends Aead_base {
213
+ }
214
+ /**
215
+ * Builds an `Aead` layer on the `WebCrypto` reference that runs the given
216
+ * implementations for byte-backed keys.
217
+ *
218
+ * **When to use**
219
+ *
220
+ * Use to run an algorithm on a runtime's native code, as `NodeCrypto.layerAead`
221
+ * does for ChaCha20-Poly1305 with `node:crypto`.
222
+ *
223
+ * **Details**
224
+ *
225
+ * `implementations` maps algorithm names to implementations that replace
226
+ * `crypto.subtle` or the algorithm's pure TypeScript code. They follow the
227
+ * {@link Implementation} contract and run only for byte-backed keys, after the
228
+ * layer has checked the nonce, plaintext, and ciphertext lengths, so errors are
229
+ * those of {@link layerWebCrypto}. `CryptoKey`-backed keys run on
230
+ * `crypto.subtle`, and generated keys come from `SecureRandom`. Without
231
+ * `implementations`, the layer is {@link layerWebCrypto}.
232
+ *
233
+ * **Gotchas**
234
+ *
235
+ * An implementation receives the key's own bytes, not a copy, so it must not
236
+ * modify or keep them.
237
+ *
238
+ * **Example** (Running ChaCha20-Poly1305 natively)
239
+ *
240
+ * ```ts
241
+ * import { Layer } from "effect"
242
+ * import { Aead, SecureRandom } from "effect/crypto"
243
+ *
244
+ * declare const nativeChacha: Aead.Implementation
245
+ *
246
+ * const layer = Aead.layerWebCryptoWith({
247
+ * implementations: { chacha20Poly1305: nativeChacha }
248
+ * }).pipe(Layer.provide(SecureRandom.layerWebCrypto))
249
+ * ```
250
+ *
251
+ * @stability unstable
252
+ * @category layers
253
+ * @since 4.0.0
254
+ */
255
+ export declare const layerWebCryptoWith: (options: {
256
+ readonly implementations?: Partial<Record<Algorithm["name"], Implementation>> | undefined;
257
+ }) => Layer.Layer<Aead, never, SecureRandom.SecureRandom>;
258
+ /**
259
+ * Layer that provides `Aead` on the `WebCrypto` reference.
260
+ *
261
+ * **Details**
262
+ *
263
+ * AES-GCM runs on `crypto.subtle`. The layer imports a byte-backed key on
264
+ * first use and caches the `CryptoKey`. ChaCha20-Poly1305 and
265
+ * XChaCha20-Poly1305 always run the pure TypeScript implementation, with no
266
+ * feature detection. Generated keys come from `SecureRandom`, so a seeded
267
+ * `SecureRandom` gives reproducible keys.
268
+ *
269
+ * @stability unstable
270
+ * @category layers
271
+ * @since 4.0.0
272
+ */
273
+ export declare const layerWebCrypto: Layer.Layer<Aead, never, SecureRandom.SecureRandom>;
274
+ /**
275
+ * Builds a key from raw key bytes.
276
+ *
277
+ * **Details**
278
+ *
279
+ * Copies the bytes, including Node.js `Buffer` inputs. A length other than
280
+ * the algorithm's key length fails with an `InvalidKey` reason. AES-192 is
281
+ * not supported.
282
+ *
283
+ * @stability unstable
284
+ * @category constructors
285
+ * @since 4.0.0
286
+ */
287
+ export declare const key: <A extends Algorithm>(algorithm: A, bytes: Uint8Array) => Effect.Effect<Key<A>, CryptoError.CryptoError>;
288
+ /**
289
+ * Builds an AES-GCM key from an existing `CryptoKey`, such as a
290
+ * non-extractable one.
291
+ *
292
+ * **Details**
293
+ *
294
+ * The `CryptoKey` must be a secret AES-GCM key of the algorithm's length with
295
+ * both the `encrypt` and `decrypt` usages, since a key reaches both
296
+ * operations. Otherwise the constructor fails with an `InvalidKey` reason. It
297
+ * must come from the `Crypto` object of the `WebCrypto` reference.
298
+ *
299
+ * ChaCha20-Poly1305 and XChaCha20-Poly1305 never run on `crypto.subtle`, so
300
+ * passing them is a type error.
301
+ *
302
+ * @stability unstable
303
+ * @category constructors
304
+ * @since 4.0.0
305
+ */
306
+ export declare const fromCryptoKey: <A extends AesGcm>(algorithm: A, cryptoKey: CryptoKey) => Effect.Effect<Key<A>, CryptoError.CryptoError>;
307
+ /**
308
+ * Exports a key's bytes.
309
+ *
310
+ * **Details**
311
+ *
312
+ * Returns a fresh `Uint8Array` that shares no memory with the key. A
313
+ * `CryptoKey`-backed key is exported on the `WebCrypto` reference, and fails
314
+ * with a `NotExtractable` reason when the `CryptoKey` is not extractable.
315
+ *
316
+ * @stability unstable
317
+ * @category converting
318
+ * @since 4.0.0
319
+ */
320
+ export declare const toBytes: (key: Key) => Effect.Effect<Uint8Array, CryptoError.CryptoError>;
321
+ export {};
322
+ //# sourceMappingURL=Aead.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Aead.d.ts","sourceRoot":"","sources":["../../src/crypto/Aead.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,KAAK,MAAM,aAAa,CAAA;AAEpC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAI/C,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAGjD,QAAA,MAAM,MAAM,EAAG,yBAAkC,CAAA;AAEjD;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,KAA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AY,CAA0B,CAAA;AAEzG;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,SAAS,SAAS,aAC1B,CAAC,SACL,UAAU,KAChB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,WAAW,CACmD,CAAA;AAEnG;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,MAAM,aACjC,CAAC,aACD,SAAS,KACnB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,WAAW,CAS1C,CAAA;AAEN;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,QAAS,GAAG,KAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,WAAW,CACjC,CAAA"}
@@ -0,0 +1,331 @@
1
+ /**
2
+ * Authenticated encryption: AES-GCM, ChaCha20-Poly1305, and
3
+ * XChaCha20-Poly1305.
4
+ *
5
+ * The {@link Aead} service generates keys, encrypts, and decrypts. The
6
+ * top-level {@link key}, {@link fromCryptoKey}, and {@link toBytes} functions
7
+ * build and export keys without a service.
8
+ *
9
+ * Ciphertext is `ciphertext‖tag` with a 16-byte tag for every algorithm, the
10
+ * layout WebCrypto produces. A tampered ciphertext, tag, or additional data
11
+ * fails decryption with a `DecryptionFailed` reason that carries no detail.
12
+ *
13
+ * AES-GCM runs on `crypto.subtle`. ChaCha20-Poly1305 and XChaCha20-Poly1305
14
+ * run a pure TypeScript implementation vendored from `@noble/ciphers` 2.4.0,
15
+ * because WebCrypto does not provide them everywhere. Cure53 audited
16
+ * `@noble/ciphers` 1.0.0 in 2024.
17
+ *
18
+ * Keys are opaque. They hold either key bytes or, for AES-GCM, a `CryptoKey`,
19
+ * display only their algorithm, and compare by reference.
20
+ *
21
+ * **Gotchas**
22
+ *
23
+ * Never reuse a nonce with the same key. Random 12-byte nonces risk a
24
+ * collision after about 2^32 messages under one key: use a counter, or
25
+ * XChaCha20-Poly1305, whose 24-byte nonces can be random.
26
+ *
27
+ * @stability unstable
28
+ * @since 4.0.0
29
+ */
30
+ import * as Context from "../Context.js";
31
+ import * as Effect from "../Effect.js";
32
+ import * as Layer from "../Layer.js";
33
+ import * as Predicate from "../Predicate.js";
34
+ import * as CryptoError from "./CryptoError.js";
35
+ import * as Chacha from "./internal/chacha.js";
36
+ import * as KeyModel from "./internal/key.js";
37
+ import * as internal from "./internal/webCrypto.js";
38
+ import * as SecureRandom from "./SecureRandom.js";
39
+ import { WebCrypto } from "./WebCrypto.js";
40
+ const TypeId = "~effect/crypto/Aead/Key";
41
+ /**
42
+ * AES-128-GCM, with a 16-byte key and a 12-byte nonce.
43
+ *
44
+ * @stability unstable
45
+ * @category algorithms
46
+ * @since 4.0.0
47
+ */
48
+ export const aes128Gcm = {
49
+ name: "aes128Gcm",
50
+ keyLength: 16,
51
+ nonceLength: 12,
52
+ implementation: undefined
53
+ };
54
+ /**
55
+ * AES-256-GCM, with a 32-byte key and a 12-byte nonce.
56
+ *
57
+ * @stability unstable
58
+ * @category algorithms
59
+ * @since 4.0.0
60
+ */
61
+ export const aes256Gcm = {
62
+ name: "aes256Gcm",
63
+ keyLength: 32,
64
+ nonceLength: 12,
65
+ implementation: undefined
66
+ };
67
+ const chachaImplementation = aead => ({
68
+ encrypt: (key, nonce, plaintext, aad) => aead(key, nonce, aad).encrypt(plaintext),
69
+ decrypt: (key, nonce, ciphertext, aad) => aead(key, nonce, aad).decrypt(ciphertext)
70
+ });
71
+ /**
72
+ * ChaCha20-Poly1305 (RFC 8439), with a 32-byte key and a 12-byte nonce.
73
+ *
74
+ * **Details**
75
+ *
76
+ * Runs the pure TypeScript implementation under `layerWebCrypto`, even where
77
+ * `crypto.subtle` provides it, so every runtime takes one code path.
78
+ *
79
+ * @stability unstable
80
+ * @category algorithms
81
+ * @since 4.0.0
82
+ */
83
+ export const chacha20Poly1305 = {
84
+ name: "chacha20Poly1305",
85
+ keyLength: 32,
86
+ nonceLength: 12,
87
+ implementation: /* @__PURE__ */chachaImplementation(Chacha.chacha20Poly1305)
88
+ };
89
+ /**
90
+ * XChaCha20-Poly1305 (draft-irtf-cfrg-xchacha-03), with a 32-byte key and a
91
+ * 24-byte nonce.
92
+ *
93
+ * **When to use**
94
+ *
95
+ * Use when nonces are generated randomly, since 24-byte nonces make
96
+ * collisions negligible. The output is compatible with libsodium's
97
+ * `crypto_aead_xchacha20poly1305_ietf`.
98
+ *
99
+ * @stability unstable
100
+ * @category algorithms
101
+ * @since 4.0.0
102
+ */
103
+ export const xchacha20Poly1305 = {
104
+ name: "xchacha20Poly1305",
105
+ keyLength: 32,
106
+ nonceLength: 24,
107
+ implementation: /* @__PURE__ */chachaImplementation(Chacha.xchacha20Poly1305)
108
+ };
109
+ const KeyProto = /*#__PURE__*/KeyModel.redactedProto(TypeId, "Aead.Key");
110
+ /**
111
+ * Checks whether a value is a {@link Key}.
112
+ *
113
+ * @stability unstable
114
+ * @category guards
115
+ * @since 4.0.0
116
+ */
117
+ export const isKey = u => Predicate.hasProperty(u, TypeId);
118
+ /**
119
+ * Service that generates keys, encrypts, and decrypts with authentication.
120
+ *
121
+ * **Example** (Encrypting with XChaCha20-Poly1305)
122
+ *
123
+ * ```ts import.meta.vitest
124
+ * import { Effect, Layer } from "effect"
125
+ * import { Aead, SecureRandom } from "effect/crypto"
126
+ *
127
+ * const program = Effect.gen(function*() {
128
+ * const aead = yield* Aead.Aead
129
+ * const random = yield* SecureRandom.SecureRandom
130
+ * const key = yield* aead.generateKey(Aead.xchacha20Poly1305)
131
+ * const nonce = yield* random.randomBytes(24)
132
+ * const sealed = yield* aead.encrypt(key, new TextEncoder().encode("secret"), { nonce })
133
+ * const opened = yield* aead.decrypt(key, sealed, { nonce })
134
+ * return [sealed.length, new TextDecoder().decode(opened)]
135
+ * })
136
+ *
137
+ * const layer = Aead.layerWebCrypto.pipe(Layer.provideMerge(SecureRandom.layerWebCrypto))
138
+ * await Effect.runPromise(program.pipe(Effect.provide(layer))) // => [22, "secret"]
139
+ * ```
140
+ *
141
+ * @stability unstable
142
+ * @category services
143
+ * @since 4.0.0
144
+ */
145
+ export class Aead extends /*#__PURE__*/Context.Service()("effect/crypto/Aead") {}
146
+ const fail = (method, reason) => internal.fail("Aead", method, reason);
147
+ const decryptionFailed = () => fail("decrypt", new CryptoError.DecryptionFailed());
148
+ // GCM limits the plaintext to 2^39 - 256 bits.
149
+ const maxGcmPlaintext = 2 ** 36 - 32;
150
+ const tagLength = 16;
151
+ // Every check runs before any work, so the pure TypeScript code only throws on
152
+ // a bug, and WebCrypto's `OperationError` only means a failed tag check.
153
+ const checkArguments = (method, key, data, options) => {
154
+ const algorithm = key.algorithm;
155
+ if (options.nonce.length !== algorithm.nonceLength) {
156
+ return fail(method, new CryptoError.InvalidArgument({
157
+ description: `${algorithm.name} nonces must contain exactly ${algorithm.nonceLength} bytes`
158
+ }));
159
+ }
160
+ if (method === "encrypt") {
161
+ if (algorithm.implementation === undefined && data.length > maxGcmPlaintext) {
162
+ return fail(method, new CryptoError.InvalidArgument({
163
+ description: "AES-GCM plaintext cannot exceed 2^36 - 32 bytes"
164
+ }));
165
+ }
166
+ } else if (data.length < tagLength) {
167
+ return decryptionFailed();
168
+ }
169
+ return undefined;
170
+ };
171
+ const runImplementation = (method, implementation, key, data, options) => {
172
+ const stored = KeyModel.material(key);
173
+ if (stored._tag !== "Bytes") {
174
+ return fail(method, new CryptoError.InvalidKey({
175
+ description: `${key.algorithm.name} keys must hold bytes`
176
+ }));
177
+ }
178
+ const aad = options.aad ?? new Uint8Array(0);
179
+ if (method === "encrypt") {
180
+ return Effect.sync(() => implementation.encrypt(stored.bytes, options.nonce, data, aad));
181
+ }
182
+ return Effect.suspend(() => {
183
+ const plaintext = implementation.decrypt(stored.bytes, options.nonce, data, aad);
184
+ return plaintext === undefined ? decryptionFailed() : Effect.succeed(plaintext);
185
+ });
186
+ };
187
+ /**
188
+ * Builds an `Aead` layer on the `WebCrypto` reference that runs the given
189
+ * implementations for byte-backed keys.
190
+ *
191
+ * **When to use**
192
+ *
193
+ * Use to run an algorithm on a runtime's native code, as `NodeCrypto.layerAead`
194
+ * does for ChaCha20-Poly1305 with `node:crypto`.
195
+ *
196
+ * **Details**
197
+ *
198
+ * `implementations` maps algorithm names to implementations that replace
199
+ * `crypto.subtle` or the algorithm's pure TypeScript code. They follow the
200
+ * {@link Implementation} contract and run only for byte-backed keys, after the
201
+ * layer has checked the nonce, plaintext, and ciphertext lengths, so errors are
202
+ * those of {@link layerWebCrypto}. `CryptoKey`-backed keys run on
203
+ * `crypto.subtle`, and generated keys come from `SecureRandom`. Without
204
+ * `implementations`, the layer is {@link layerWebCrypto}.
205
+ *
206
+ * **Gotchas**
207
+ *
208
+ * An implementation receives the key's own bytes, not a copy, so it must not
209
+ * modify or keep them.
210
+ *
211
+ * **Example** (Running ChaCha20-Poly1305 natively)
212
+ *
213
+ * ```ts
214
+ * import { Layer } from "effect"
215
+ * import { Aead, SecureRandom } from "effect/crypto"
216
+ *
217
+ * declare const nativeChacha: Aead.Implementation
218
+ *
219
+ * const layer = Aead.layerWebCryptoWith({
220
+ * implementations: { chacha20Poly1305: nativeChacha }
221
+ * }).pipe(Layer.provide(SecureRandom.layerWebCrypto))
222
+ * ```
223
+ *
224
+ * @stability unstable
225
+ * @category layers
226
+ * @since 4.0.0
227
+ */
228
+ export const layerWebCryptoWith = options => Layer.effect(Aead, Effect.gen(function* () {
229
+ const random = yield* SecureRandom.SecureRandom;
230
+ const crypto = yield* WebCrypto;
231
+ const cryptoKeyFor = KeyModel.makeCache((subtle, bytes) => subtle.importKey("raw", bytes, "AES-GCM", false, ["encrypt", "decrypt"]));
232
+ const implementations = options.implementations;
233
+ // A supplied implementation runs only for byte-backed keys, so CryptoKeys
234
+ // stay on `crypto.subtle`.
235
+ const implementationFor = key => {
236
+ const supplied = implementations?.[key.algorithm.name];
237
+ return supplied !== undefined && KeyModel.material(key)._tag === "Bytes" ? supplied : key.algorithm.implementation;
238
+ };
239
+ const gcm = (method, key, data, options) => {
240
+ const params = {
241
+ name: "AES-GCM",
242
+ iv: options.nonce,
243
+ tagLength: 128,
244
+ ...(options.aad === undefined ? {} : {
245
+ additionalData: options.aad
246
+ })
247
+ };
248
+ return internal.run("Aead", method, key.algorithm.name, crypto, async subtle => new Uint8Array(await subtle[method](params, await cryptoKeyFor(subtle, key), data)), cause => internal.webCryptoError("Aead", method, key.algorithm.name, cause, method === "decrypt" ? () => new CryptoError.DecryptionFailed() : undefined));
249
+ };
250
+ const run = method => (key, data, options) => Effect.suspend(() => {
251
+ const failure = checkArguments(method, key, data, options);
252
+ if (failure !== undefined) return failure;
253
+ const implementation = implementationFor(key);
254
+ return implementation === undefined ? gcm(method, key, data, options) : runImplementation(method, implementation, key, data, options);
255
+ });
256
+ return Aead.of({
257
+ generateKey: algorithm => Effect.map(random.randomBytes(algorithm.keyLength), bytes => KeyModel.makeBytes(KeyProto, algorithm, bytes)),
258
+ encrypt: run("encrypt"),
259
+ decrypt: run("decrypt")
260
+ });
261
+ }));
262
+ /**
263
+ * Layer that provides `Aead` on the `WebCrypto` reference.
264
+ *
265
+ * **Details**
266
+ *
267
+ * AES-GCM runs on `crypto.subtle`. The layer imports a byte-backed key on
268
+ * first use and caches the `CryptoKey`. ChaCha20-Poly1305 and
269
+ * XChaCha20-Poly1305 always run the pure TypeScript implementation, with no
270
+ * feature detection. Generated keys come from `SecureRandom`, so a seeded
271
+ * `SecureRandom` gives reproducible keys.
272
+ *
273
+ * @stability unstable
274
+ * @category layers
275
+ * @since 4.0.0
276
+ */
277
+ export const layerWebCrypto = /*#__PURE__*/layerWebCryptoWith({});
278
+ /**
279
+ * Builds a key from raw key bytes.
280
+ *
281
+ * **Details**
282
+ *
283
+ * Copies the bytes, including Node.js `Buffer` inputs. A length other than
284
+ * the algorithm's key length fails with an `InvalidKey` reason. AES-192 is
285
+ * not supported.
286
+ *
287
+ * @stability unstable
288
+ * @category constructors
289
+ * @since 4.0.0
290
+ */
291
+ export const key = (algorithm, bytes) => KeyModel.fromBytes("Aead", "key", KeyProto, algorithm, bytes, KeyModel.checkKeyLength(algorithm));
292
+ /**
293
+ * Builds an AES-GCM key from an existing `CryptoKey`, such as a
294
+ * non-extractable one.
295
+ *
296
+ * **Details**
297
+ *
298
+ * The `CryptoKey` must be a secret AES-GCM key of the algorithm's length with
299
+ * both the `encrypt` and `decrypt` usages, since a key reaches both
300
+ * operations. Otherwise the constructor fails with an `InvalidKey` reason. It
301
+ * must come from the `Crypto` object of the `WebCrypto` reference.
302
+ *
303
+ * ChaCha20-Poly1305 and XChaCha20-Poly1305 never run on `crypto.subtle`, so
304
+ * passing them is a type error.
305
+ *
306
+ * @stability unstable
307
+ * @category constructors
308
+ * @since 4.0.0
309
+ */
310
+ export const fromCryptoKey = (algorithm, cryptoKey) => algorithm.implementation !== undefined ? internal.invalidKey("Aead", "fromCryptoKey", `${algorithm.name} keys cannot be CryptoKeys`) : KeyModel.fromCryptoKey("Aead", "fromCryptoKey", KeyProto, algorithm, cryptoKey, {
311
+ type: "secret",
312
+ name: "AES-GCM",
313
+ usages: ["encrypt", "decrypt"],
314
+ usagePolicy: "all",
315
+ check: KeyModel.checkAesLength("AES-GCM", algorithm.keyLength)
316
+ });
317
+ /**
318
+ * Exports a key's bytes.
319
+ *
320
+ * **Details**
321
+ *
322
+ * Returns a fresh `Uint8Array` that shares no memory with the key. A
323
+ * `CryptoKey`-backed key is exported on the `WebCrypto` reference, and fails
324
+ * with a `NotExtractable` reason when the `CryptoKey` is not extractable.
325
+ *
326
+ * @stability unstable
327
+ * @category converting
328
+ * @since 4.0.0
329
+ */
330
+ export const toBytes = key => KeyModel.toBytes("Aead", key, KeyModel.exportRaw);
331
+ //# sourceMappingURL=Aead.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Aead.js","names":[],"sources":["../../src/crypto/Aead.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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