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.
- package/README.md +1 -1
- package/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +3 -0
- package/dist/BigDecimal.js.map +1 -1
- package/dist/Channel.d.ts +12 -6
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +9 -3
- package/dist/Channel.js.map +1 -1
- package/dist/Config.d.ts +7 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js.map +1 -1
- package/dist/Context.d.ts +18 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +27 -8
- package/dist/Context.js.map +1 -1
- package/dist/Cron.d.ts +81 -11
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +101 -26
- package/dist/Cron.js.map +1 -1
- package/dist/Duration.d.ts +78 -0
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +123 -0
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +164 -7
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +11 -1
- package/dist/Effect.js.map +1 -1
- package/dist/FileSystem.d.ts +59 -4
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +9 -2
- package/dist/FileSystem.js.map +1 -1
- package/dist/Glob.d.ts +165 -0
- package/dist/Glob.d.ts.map +1 -0
- package/dist/Glob.js +127 -0
- package/dist/Glob.js.map +1 -0
- package/dist/Match.d.ts +86 -0
- package/dist/Match.d.ts.map +1 -1
- package/dist/Match.js +72 -0
- package/dist/Match.js.map +1 -1
- package/dist/Pool.d.ts +51 -0
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +59 -9
- package/dist/Pool.js.map +1 -1
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +3 -3
- package/dist/Random.js.map +1 -1
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +8 -2
- package/dist/RcMap.js.map +1 -1
- package/dist/Schedule.d.ts +18 -1
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +7 -2
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +666 -41
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +650 -0
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaGetter.d.ts +6 -1
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +22 -11
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +14 -0
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +16 -0
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +8 -3
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +6 -3
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +5 -7
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Semaphore.d.ts +130 -0
- package/dist/Semaphore.d.ts.map +1 -1
- package/dist/Semaphore.js +40 -0
- package/dist/Semaphore.js.map +1 -1
- package/dist/Stream.d.ts +13 -4
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +9 -0
- package/dist/Stream.js.map +1 -1
- package/dist/Terminal.d.ts +18 -1
- package/dist/Terminal.d.ts.map +1 -1
- package/dist/Terminal.js +1 -1
- package/dist/Terminal.js.map +1 -1
- package/dist/ai/AiError.d.ts +43 -116
- package/dist/ai/AiError.d.ts.map +1 -1
- package/dist/ai/AiError.js +53 -72
- package/dist/ai/AiError.js.map +1 -1
- package/dist/ai/Decision.d.ts +196 -15
- package/dist/ai/Decision.d.ts.map +1 -1
- package/dist/ai/Decision.js +130 -0
- package/dist/ai/Decision.js.map +1 -1
- package/dist/ai/DecisionModel.d.ts +54 -13
- package/dist/ai/DecisionModel.d.ts.map +1 -1
- package/dist/ai/DecisionModel.js +123 -12
- package/dist/ai/DecisionModel.js.map +1 -1
- package/dist/ai/McpServer.d.ts +630 -29
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +562 -116
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/McpTest.d.ts +130 -0
- package/dist/ai/McpTest.d.ts.map +1 -0
- package/dist/ai/McpTest.js +237 -0
- package/dist/ai/McpTest.js.map +1 -0
- package/dist/ai/Response.d.ts +1 -25
- package/dist/ai/Response.d.ts.map +1 -1
- package/dist/ai/Response.js +1 -10
- package/dist/ai/Response.js.map +1 -1
- package/dist/ai/Tool.d.ts +19 -1
- package/dist/ai/Tool.d.ts.map +1 -1
- package/dist/ai/Tool.js.map +1 -1
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/internal/mcpCore.js +17 -12
- package/dist/ai/internal/mcpCore.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js +4 -5
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js +4 -5
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js +4 -5
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js +4 -5
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js +18 -10
- package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
- package/dist/ai/internal/mcpProtocol.js +13 -0
- package/dist/ai/internal/mcpProtocol.js.map +1 -1
- package/dist/ai/internal/mcpRuntime.js +5 -3
- package/dist/ai/internal/mcpRuntime.js.map +1 -1
- package/dist/ai/internal/mcpStatefulRuntime.js +6 -1
- package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
- package/dist/cli/Argument.d.ts +6 -0
- package/dist/cli/Argument.d.ts.map +1 -1
- package/dist/cli/Argument.js +2 -0
- package/dist/cli/Argument.js.map +1 -1
- package/dist/cli/CliOutput.d.ts +65 -1
- package/dist/cli/CliOutput.d.ts.map +1 -1
- package/dist/cli/CliOutput.js +94 -37
- package/dist/cli/CliOutput.js.map +1 -1
- package/dist/cli/Command.d.ts +23 -0
- package/dist/cli/Command.d.ts.map +1 -1
- package/dist/cli/Command.js +8 -0
- package/dist/cli/Command.js.map +1 -1
- package/dist/cli/Flag.d.ts +107 -0
- package/dist/cli/Flag.d.ts.map +1 -1
- package/dist/cli/Flag.js +37 -0
- package/dist/cli/Flag.js.map +1 -1
- package/dist/cli/HelpDoc.d.ts +15 -1
- package/dist/cli/HelpDoc.d.ts.map +1 -1
- package/dist/cli/Param.d.ts +6 -0
- package/dist/cli/Param.d.ts.map +1 -1
- package/dist/cli/Param.js +2 -0
- package/dist/cli/Param.js.map +1 -1
- package/dist/cli/Primitive.d.ts +14 -0
- package/dist/cli/Primitive.d.ts.map +1 -1
- package/dist/cli/Primitive.js +15 -1
- package/dist/cli/Primitive.js.map +1 -1
- package/dist/cli/Prompt.d.ts +1 -0
- package/dist/cli/Prompt.d.ts.map +1 -1
- package/dist/cli/Prompt.js +1 -0
- package/dist/cli/Prompt.js.map +1 -1
- package/dist/cli/internal/help.d.ts.map +1 -1
- package/dist/cli/internal/help.js +17 -10
- package/dist/cli/internal/help.js.map +1 -1
- package/dist/cluster/Sharding.d.ts.map +1 -1
- package/dist/cluster/Sharding.js +90 -28
- package/dist/cluster/Sharding.js.map +1 -1
- package/dist/cluster/ShardingConfig.d.ts +72 -6
- package/dist/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/cluster/ShardingConfig.js +4 -0
- package/dist/cluster/ShardingConfig.js.map +1 -1
- package/dist/cluster/SingleRunner.d.ts +3 -3
- package/dist/cluster/SingleRunner.d.ts.map +1 -1
- package/dist/cluster/SingleRunner.js +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts +37 -6
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +34 -7
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/cluster/SqlRunnerStorage.js +23 -8
- package/dist/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/crypto/Aead.d.ts +322 -0
- package/dist/crypto/Aead.d.ts.map +1 -0
- package/dist/crypto/Aead.js +331 -0
- package/dist/crypto/Aead.js.map +1 -0
- package/dist/crypto/Cipher.d.ts +235 -0
- package/dist/crypto/Cipher.d.ts.map +1 -0
- package/dist/crypto/Cipher.js +233 -0
- package/dist/crypto/Cipher.js.map +1 -0
- package/dist/crypto/CryptoError.d.ts +212 -0
- package/dist/crypto/CryptoError.d.ts.map +1 -0
- package/dist/crypto/CryptoError.js +202 -0
- package/dist/crypto/CryptoError.js.map +1 -0
- package/dist/crypto/Digest.d.ts +143 -0
- package/dist/crypto/Digest.d.ts.map +1 -0
- package/dist/crypto/Digest.js +146 -0
- package/dist/crypto/Digest.js.map +1 -0
- package/dist/crypto/Kdf.d.ts +220 -0
- package/dist/crypto/Kdf.d.ts.map +1 -0
- package/dist/crypto/Kdf.js +212 -0
- package/dist/crypto/Kdf.js.map +1 -0
- package/dist/crypto/KeyAgreement.d.ts +323 -0
- package/dist/crypto/KeyAgreement.d.ts.map +1 -0
- package/dist/crypto/KeyAgreement.js +303 -0
- package/dist/crypto/KeyAgreement.js.map +1 -0
- package/dist/crypto/KeyFormat.d.ts +309 -0
- package/dist/crypto/KeyFormat.d.ts.map +1 -0
- package/dist/crypto/KeyFormat.js +556 -0
- package/dist/crypto/KeyFormat.js.map +1 -0
- package/dist/crypto/KeyWrap.d.ts +389 -0
- package/dist/crypto/KeyWrap.d.ts.map +1 -0
- package/dist/crypto/KeyWrap.js +381 -0
- package/dist/crypto/KeyWrap.js.map +1 -0
- package/dist/crypto/Mac.d.ts +277 -0
- package/dist/crypto/Mac.d.ts.map +1 -0
- package/dist/crypto/Mac.js +288 -0
- package/dist/crypto/Mac.js.map +1 -0
- package/dist/crypto/SecureRandom.d.ts +340 -0
- package/dist/crypto/SecureRandom.d.ts.map +1 -0
- package/dist/crypto/SecureRandom.js +257 -0
- package/dist/crypto/SecureRandom.js.map +1 -0
- package/dist/crypto/Signature.d.ts +448 -0
- package/dist/crypto/Signature.d.ts.map +1 -0
- package/dist/crypto/Signature.js +484 -0
- package/dist/crypto/Signature.js.map +1 -0
- package/dist/crypto/WebCrypto.d.ts +61 -0
- package/dist/crypto/WebCrypto.d.ts.map +1 -0
- package/dist/crypto/WebCrypto.js +63 -0
- package/dist/crypto/WebCrypto.js.map +1 -0
- package/dist/crypto/index.d.ts +65 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +66 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/internal/asymmetric.d.ts +2 -0
- package/dist/crypto/internal/asymmetric.d.ts.map +1 -0
- package/dist/crypto/internal/asymmetric.js +210 -0
- package/dist/crypto/internal/asymmetric.js.map +1 -0
- package/dist/crypto/internal/chacha.d.ts +46 -0
- package/dist/crypto/internal/chacha.d.ts.map +1 -0
- package/dist/crypto/internal/chacha.js +885 -0
- package/dist/crypto/internal/chacha.js.map +1 -0
- package/dist/crypto/internal/der.d.ts +6 -0
- package/dist/crypto/internal/der.d.ts.map +1 -0
- package/dist/crypto/internal/der.js +86 -0
- package/dist/crypto/internal/der.js.map +1 -0
- package/dist/crypto/internal/digest.d.ts +2 -0
- package/dist/crypto/internal/digest.d.ts.map +1 -0
- package/dist/crypto/internal/digest.js +15 -0
- package/dist/crypto/internal/digest.js.map +1 -0
- package/dist/crypto/internal/key.d.ts +2 -0
- package/dist/crypto/internal/key.d.ts.map +1 -0
- package/dist/crypto/internal/key.js +170 -0
- package/dist/crypto/internal/key.js.map +1 -0
- package/dist/crypto/internal/md5.d.ts +39 -0
- package/dist/crypto/internal/md5.d.ts.map +1 -0
- package/dist/crypto/internal/md5.js +179 -0
- package/dist/crypto/internal/md5.js.map +1 -0
- package/dist/crypto/internal/webCrypto.d.ts +2 -0
- package/dist/crypto/internal/webCrypto.d.ts.map +1 -0
- package/dist/crypto/internal/webCrypto.js +111 -0
- package/dist/crypto/internal/webCrypto.js.map +1 -0
- package/dist/encoding/Base64Url.d.ts.map +1 -1
- package/dist/encoding/Base64Url.js +3 -2
- package/dist/encoding/Base64Url.js.map +1 -1
- package/dist/encoding/Csv.d.ts +608 -0
- package/dist/encoding/Csv.d.ts.map +1 -0
- package/dist/encoding/Csv.js +718 -0
- package/dist/encoding/Csv.js.map +1 -0
- package/dist/encoding/Hex.d.ts +3 -2
- package/dist/encoding/Hex.d.ts.map +1 -1
- package/dist/encoding/Hex.js +3 -2
- package/dist/encoding/Hex.js.map +1 -1
- package/dist/encoding/SchemaBinary.d.ts.map +1 -1
- package/dist/encoding/SchemaBinary.js +42 -4
- package/dist/encoding/SchemaBinary.js.map +1 -1
- package/dist/encoding/Toml.d.ts +17 -3
- package/dist/encoding/Toml.d.ts.map +1 -1
- package/dist/encoding/Toml.js +104 -16
- package/dist/encoding/Toml.js.map +1 -1
- package/dist/encoding/Yaml.d.ts +8 -1
- package/dist/encoding/Yaml.d.ts.map +1 -1
- package/dist/encoding/Yaml.js +54 -18
- package/dist/encoding/Yaml.js.map +1 -1
- package/dist/encoding/index.d.ts +5 -0
- package/dist/encoding/index.d.ts.map +1 -1
- package/dist/encoding/index.js +5 -0
- package/dist/encoding/index.js.map +1 -1
- package/dist/eventlog/EventJournal.d.ts.map +1 -1
- package/dist/eventlog/EventJournal.js +6 -3
- package/dist/eventlog/EventJournal.js.map +1 -1
- package/dist/eventlog/EventLog.d.ts +119 -4
- package/dist/eventlog/EventLog.d.ts.map +1 -1
- package/dist/eventlog/EventLog.js +200 -12
- package/dist/eventlog/EventLog.js.map +1 -1
- package/dist/eventlog/EventLogEncryption.d.ts +41 -4
- package/dist/eventlog/EventLogEncryption.d.ts.map +1 -1
- package/dist/eventlog/EventLogEncryption.js +83 -64
- package/dist/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/eventlog/EventLogMessage.d.ts +279 -0
- package/dist/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/eventlog/EventLogMessage.js +217 -1
- package/dist/eventlog/EventLogMessage.js.map +1 -1
- package/dist/eventlog/EventLogRemote.d.ts +200 -28
- package/dist/eventlog/EventLogRemote.d.ts.map +1 -1
- package/dist/eventlog/EventLogRemote.js +186 -16
- package/dist/eventlog/EventLogRemote.js.map +1 -1
- package/dist/eventlog/EventLogServer.d.ts +3 -0
- package/dist/eventlog/EventLogServer.d.ts.map +1 -1
- package/dist/eventlog/EventLogServer.js +18 -10
- package/dist/eventlog/EventLogServer.js.map +1 -1
- package/dist/eventlog/EventLogServerEncrypted.d.ts +326 -5
- package/dist/eventlog/EventLogServerEncrypted.d.ts.map +1 -1
- package/dist/eventlog/EventLogServerEncrypted.js +769 -14
- package/dist/eventlog/EventLogServerEncrypted.js.map +1 -1
- package/dist/eventlog/EventLogSessionAuth.d.ts +5 -3
- package/dist/eventlog/EventLogSessionAuth.d.ts.map +1 -1
- package/dist/eventlog/EventLogSessionAuth.js +41 -64
- package/dist/eventlog/EventLogSessionAuth.js.map +1 -1
- package/dist/eventlog/EventRow.d.ts +4 -0
- package/dist/eventlog/EventRow.d.ts.map +1 -1
- package/dist/eventlog/EventRow.js +12 -2
- package/dist/eventlog/EventRow.js.map +1 -1
- package/dist/eventlog/SqlEventJournal.js +2 -2
- package/dist/eventlog/SqlEventJournal.js.map +1 -1
- package/dist/eventlog/SqlEventLogServerEncrypted.d.ts +21 -5
- package/dist/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
- package/dist/eventlog/SqlEventLogServerEncrypted.js +1048 -113
- package/dist/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
- package/dist/eventlog/SqlEventLogServerUnencrypted.js +2 -2
- package/dist/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
- package/dist/eventlog/internal/batches.d.ts +12 -0
- package/dist/eventlog/internal/batches.d.ts.map +1 -0
- package/dist/eventlog/internal/batches.js +26 -0
- package/dist/eventlog/internal/batches.js.map +1 -0
- package/dist/eventlog/internal/compaction.d.ts +38 -0
- package/dist/eventlog/internal/compaction.d.ts.map +1 -0
- package/dist/eventlog/internal/compaction.js +33 -0
- package/dist/eventlog/internal/compaction.js.map +1 -0
- package/dist/eventlog/internal/identityRootSecretDerivation.js +66 -67
- package/dist/eventlog/internal/identityRootSecretDerivation.js.map +1 -1
- package/dist/eventlog/internal/remoteCompaction.d.ts +31 -0
- package/dist/eventlog/internal/remoteCompaction.d.ts.map +1 -0
- package/dist/eventlog/internal/remoteCompaction.js +76 -0
- package/dist/eventlog/internal/remoteCompaction.js.map +1 -0
- package/dist/http/Cookies.d.ts +172 -0
- package/dist/http/Cookies.d.ts.map +1 -1
- package/dist/http/Cookies.js +143 -1
- package/dist/http/Cookies.js.map +1 -1
- package/dist/http/FetchHttpClient.d.ts +26 -2
- package/dist/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/http/FetchHttpClient.js +78 -15
- package/dist/http/FetchHttpClient.js.map +1 -1
- package/dist/http/HttpClient.d.ts +79 -8
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/http/HttpClient.js +65 -5
- package/dist/http/HttpClient.js.map +1 -1
- package/dist/http/HttpClientRequest.d.ts +9 -5
- package/dist/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/http/HttpClientRequest.js +2 -3
- package/dist/http/HttpClientRequest.js.map +1 -1
- package/dist/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/http/HttpClientResponse.js +3 -2
- package/dist/http/HttpClientResponse.js.map +1 -1
- package/dist/http/HttpMethod.d.ts +7 -1
- package/dist/http/HttpMethod.d.ts.map +1 -1
- package/dist/http/HttpMethod.js +3 -8
- package/dist/http/HttpMethod.js.map +1 -1
- package/dist/http/HttpServerRequest.d.ts +5 -2
- package/dist/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/http/HttpServerRequest.js +6 -17
- package/dist/http/HttpServerRequest.js.map +1 -1
- package/dist/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/http/HttpServerResponse.js +3 -2
- package/dist/http/HttpServerResponse.js.map +1 -1
- package/dist/http/HttpTraceContext.d.ts +2 -1
- package/dist/http/HttpTraceContext.d.ts.map +1 -1
- package/dist/http/HttpTraceContext.js +7 -5
- package/dist/http/HttpTraceContext.js.map +1 -1
- package/dist/http/ProblemDetails.d.ts +96 -0
- package/dist/http/ProblemDetails.d.ts.map +1 -0
- package/dist/http/ProblemDetails.js +98 -0
- package/dist/http/ProblemDetails.js.map +1 -0
- package/dist/http/index.d.ts +5 -0
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +5 -0
- package/dist/http/index.js.map +1 -1
- package/dist/http/internal/decompression.js +3 -2
- package/dist/http/internal/decompression.js.map +1 -1
- package/dist/http/internal/urlParams.js +8 -0
- package/dist/http/internal/urlParams.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +19 -5
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts +63 -0
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +51 -0
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/http-api/HttpApiEndpoint.js +14 -5
- package/dist/http-api/HttpApiEndpoint.js.map +1 -1
- package/dist/http-api/HttpApiError.d.ts +185 -13
- package/dist/http-api/HttpApiError.d.ts.map +1 -1
- package/dist/http-api/HttpApiError.js +128 -0
- package/dist/http-api/HttpApiError.js.map +1 -1
- package/dist/http-api/HttpApiMiddleware.d.ts +64 -17
- package/dist/http-api/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/http-api/HttpApiMiddleware.js +85 -1
- package/dist/http-api/HttpApiMiddleware.js.map +1 -1
- package/dist/http-api/HttpApiSchema.d.ts +76 -14
- package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
- package/dist/http-api/HttpApiSchema.js +53 -0
- package/dist/http-api/HttpApiSchema.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +25 -14
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/glob.d.ts +2 -0
- package/dist/internal/glob.d.ts.map +1 -0
- package/dist/internal/glob.js +630 -0
- package/dist/internal/glob.js.map +1 -0
- package/dist/internal/matcher.js +10 -0
- package/dist/internal/matcher.js.map +1 -1
- package/dist/internal/persistence.js +9 -0
- package/dist/internal/persistence.js.map +1 -1
- package/dist/internal/rcRef.js +4 -1
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/internal/schema/toCodeDocument.js +6 -3
- package/dist/internal/schema/toCodeDocument.js.map +1 -1
- package/dist/internal/trie.js +42 -13
- package/dist/internal/trie.js.map +1 -1
- package/dist/internal/ulid.js +41 -0
- package/dist/internal/ulid.js.map +1 -1
- package/dist/internal/uuid.js +52 -8
- package/dist/internal/uuid.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/observability/Otlp.d.ts +15 -4
- package/dist/observability/Otlp.d.ts.map +1 -1
- package/dist/observability/Otlp.js +10 -0
- package/dist/observability/Otlp.js.map +1 -1
- package/dist/observability/OtlpResource.d.ts +7 -0
- package/dist/observability/OtlpResource.d.ts.map +1 -1
- package/dist/observability/OtlpResource.js +11 -1
- package/dist/observability/OtlpResource.js.map +1 -1
- package/dist/persistence/KeyValueStore.d.ts +47 -2
- package/dist/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/persistence/KeyValueStore.js +129 -18
- package/dist/persistence/KeyValueStore.js.map +1 -1
- package/dist/persistence/PersistedQueue.d.ts +9 -0
- package/dist/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/persistence/PersistedQueue.js +94 -52
- package/dist/persistence/PersistedQueue.js.map +1 -1
- package/dist/persistence/Persistence.d.ts +10 -4
- package/dist/persistence/Persistence.d.ts.map +1 -1
- package/dist/persistence/Persistence.js +18 -11
- package/dist/persistence/Persistence.js.map +1 -1
- package/dist/process/ChildProcess.d.ts +207 -67
- package/dist/process/ChildProcess.d.ts.map +1 -1
- package/dist/process/ChildProcess.js +56 -158
- package/dist/process/ChildProcess.js.map +1 -1
- package/dist/process/ChildProcessSpawner.d.ts +5 -0
- package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
- package/dist/process/ChildProcessSpawner.js.map +1 -1
- package/dist/process/CommandLine.d.ts +294 -0
- package/dist/process/CommandLine.d.ts.map +1 -0
- package/dist/process/CommandLine.js +481 -0
- package/dist/process/CommandLine.js.map +1 -0
- package/dist/process/index.d.ts +5 -0
- package/dist/process/index.d.ts.map +1 -1
- package/dist/process/index.js +5 -0
- package/dist/process/index.js.map +1 -1
- package/dist/reactivity/Atom.d.ts +2 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +3 -4
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/reactivity/AtomRegistry.js.map +1 -1
- package/dist/rpc/RpcClient.d.ts +16 -1
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +50 -16
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcMessage.d.ts +10 -1
- package/dist/rpc/RpcMessage.d.ts.map +1 -1
- package/dist/rpc/RpcMessage.js +1 -0
- package/dist/rpc/RpcMessage.js.map +1 -1
- package/dist/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/rpc/RpcSerialization.js +6 -0
- package/dist/rpc/RpcSerialization.js.map +1 -1
- package/dist/rpc/RpcServer.d.ts +31 -0
- package/dist/rpc/RpcServer.d.ts.map +1 -1
- package/dist/rpc/RpcServer.js +139 -66
- package/dist/rpc/RpcServer.js.map +1 -1
- package/dist/schema/Model.d.ts +14 -0
- package/dist/schema/Model.d.ts.map +1 -1
- package/dist/schema/Model.js +18 -3
- package/dist/schema/Model.js.map +1 -1
- package/dist/sql/Migrator.d.ts +0 -19
- package/dist/sql/Migrator.d.ts.map +1 -1
- package/dist/sql/Migrator.js +3 -48
- package/dist/sql/Migrator.js.map +1 -1
- package/dist/sql/MigratorFileSystem.d.ts +21 -0
- package/dist/sql/MigratorFileSystem.d.ts.map +1 -0
- package/dist/sql/MigratorFileSystem.js +57 -0
- package/dist/sql/MigratorFileSystem.js.map +1 -0
- package/dist/sql/SqlClient.d.ts.map +1 -1
- package/dist/sql/SqlClient.js +5 -9
- package/dist/sql/SqlClient.js.map +1 -1
- package/dist/sql/Statement.d.ts +20 -6
- package/dist/sql/Statement.d.ts.map +1 -1
- package/dist/sql/Statement.js +0 -13
- package/dist/sql/Statement.js.map +1 -1
- package/dist/sql/index.js +1 -1
- package/dist/testing/index.d.ts +0 -5
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +0 -5
- package/dist/testing/index.js.map +1 -1
- package/dist/workflow/internal/crypto.js +9 -8
- package/dist/workflow/internal/crypto.js.map +1 -1
- package/package.json +3 -1
- package/src/BigDecimal.ts +3 -0
- package/src/Channel.ts +17 -11
- package/src/Config.ts +7 -1
- package/src/Context.ts +34 -10
- package/src/Cron.ts +178 -29
- package/src/Duration.ts +140 -0
- package/src/Effect.ts +914 -85
- package/src/FileSystem.ts +65 -4
- package/src/Glob.ts +205 -0
- package/src/Match.ts +127 -0
- package/src/Pool.ts +73 -15
- package/src/Random.ts +3 -3
- package/src/RcMap.ts +5 -1
- package/src/Schedule.ts +26 -3
- package/src/Schema.ts +1189 -62
- package/src/SchemaGetter.ts +27 -11
- package/src/SchemaRepresentation.ts +19 -0
- package/src/SchemaTransformation.ts +8 -3
- package/src/ScopedCache.ts +5 -9
- package/src/Semaphore.ts +141 -0
- package/src/Stream.ts +15 -6
- package/src/Terminal.ts +19 -1
- package/src/ai/AiError.ts +56 -80
- package/src/ai/Decision.ts +257 -6
- package/src/ai/DecisionModel.ts +171 -28
- package/src/ai/McpServer.ts +1269 -286
- package/src/ai/McpTest.ts +380 -0
- package/src/ai/Response.ts +2 -22
- package/src/ai/Tool.ts +27 -8
- package/src/ai/index.ts +6 -0
- package/src/ai/internal/mcpCore.ts +78 -44
- package/src/ai/internal/mcpProtocol/v2024_11_05.ts +4 -7
- package/src/ai/internal/mcpProtocol/v2025_03_26.ts +4 -7
- package/src/ai/internal/mcpProtocol/v2025_06_18.ts +4 -7
- package/src/ai/internal/mcpProtocol/v2025_11_25.ts +4 -7
- package/src/ai/internal/mcpProtocol/v2026_07_28.ts +15 -10
- package/src/ai/internal/mcpProtocol.ts +29 -0
- package/src/ai/internal/mcpRuntime.ts +9 -5
- package/src/ai/internal/mcpStatefulRuntime.ts +14 -2
- package/src/cli/Argument.ts +6 -0
- package/src/cli/CliOutput.ts +117 -49
- package/src/cli/Command.ts +23 -0
- package/src/cli/Flag.ts +107 -0
- package/src/cli/HelpDoc.ts +18 -1
- package/src/cli/Param.ts +6 -0
- package/src/cli/Primitive.ts +16 -1
- package/src/cli/Prompt.ts +1 -0
- package/src/cli/internal/help.ts +21 -9
- package/src/cluster/Sharding.ts +93 -26
- package/src/cluster/ShardingConfig.ts +41 -3
- package/src/cluster/SingleRunner.ts +3 -3
- package/src/cluster/SqlMessageStorage.ts +49 -17
- package/src/cluster/SqlRunnerStorage.ts +37 -27
- package/src/crypto/Aead.ts +517 -0
- package/src/crypto/Cipher.ts +326 -0
- package/src/crypto/CryptoError.ts +242 -0
- package/src/crypto/Digest.ts +167 -0
- package/src/crypto/Kdf.ts +315 -0
- package/src/crypto/KeyAgreement.ts +489 -0
- package/src/crypto/KeyFormat.ts +712 -0
- package/src/crypto/KeyWrap.ts +639 -0
- package/src/crypto/Mac.ts +386 -0
- package/src/crypto/SecureRandom.ts +459 -0
- package/src/crypto/Signature.ts +673 -0
- package/src/crypto/WebCrypto.ts +64 -0
- package/src/crypto/index.ts +78 -0
- package/src/crypto/internal/asymmetric.ts +329 -0
- package/src/crypto/internal/chacha.ts +1088 -0
- package/src/crypto/internal/der.ts +110 -0
- package/src/crypto/internal/digest.ts +16 -0
- package/src/crypto/internal/key.ts +235 -0
- package/src/crypto/internal/md5.ts +170 -0
- package/src/crypto/internal/webCrypto.ts +150 -0
- package/src/encoding/Base64Url.ts +5 -2
- package/src/encoding/Csv.ts +1298 -0
- package/src/encoding/Hex.ts +3 -2
- package/src/encoding/SchemaBinary.ts +40 -4
- package/src/encoding/Toml.ts +85 -20
- package/src/encoding/Yaml.ts +61 -18
- package/src/encoding/index.ts +6 -0
- package/src/eventlog/EventJournal.ts +4 -3
- package/src/eventlog/EventLog.ts +340 -15
- package/src/eventlog/EventLogEncryption.ts +118 -110
- package/src/eventlog/EventLogMessage.ts +273 -1
- package/src/eventlog/EventLogRemote.ts +367 -23
- package/src/eventlog/EventLogServer.ts +23 -8
- package/src/eventlog/EventLogServerEncrypted.ts +1130 -67
- package/src/eventlog/EventLogSessionAuth.ts +56 -70
- package/src/eventlog/EventRow.ts +12 -3
- package/src/eventlog/SqlEventJournal.ts +2 -2
- package/src/eventlog/SqlEventLogServerEncrypted.ts +1244 -136
- package/src/eventlog/SqlEventLogServerUnencrypted.ts +2 -2
- package/src/eventlog/internal/batches.ts +30 -0
- package/src/eventlog/internal/compaction.ts +64 -0
- package/src/eventlog/internal/identityRootSecretDerivation.ts +93 -123
- package/src/eventlog/internal/remoteCompaction.ts +92 -0
- package/src/http/Cookies.ts +281 -1
- package/src/http/FetchHttpClient.ts +88 -16
- package/src/http/HttpClient.ts +89 -22
- package/src/http/HttpClientRequest.ts +12 -9
- package/src/http/HttpClientResponse.ts +3 -2
- package/src/http/HttpMethod.ts +10 -2
- package/src/http/HttpServerRequest.ts +15 -30
- package/src/http/HttpServerResponse.ts +3 -2
- package/src/http/HttpTraceContext.ts +7 -4
- package/src/http/ProblemDetails.ts +149 -0
- package/src/http/index.ts +6 -0
- package/src/http/internal/decompression.ts +4 -4
- package/src/http/internal/urlParams.ts +8 -0
- package/src/http-api/HttpApiBuilder.ts +24 -12
- package/src/http-api/HttpApiClient.ts +67 -1
- package/src/http-api/HttpApiEndpoint.ts +14 -5
- package/src/http-api/HttpApiError.ts +250 -0
- package/src/http-api/HttpApiMiddleware.ts +95 -1
- package/src/http-api/HttpApiSchema.ts +105 -14
- package/src/index.ts +6 -6
- package/src/internal/effect.ts +34 -18
- package/src/internal/glob.ts +736 -0
- package/src/internal/matcher.ts +17 -0
- package/src/internal/persistence.ts +11 -0
- package/src/internal/rcRef.ts +4 -1
- package/src/internal/schema/toCodeDocument.ts +7 -3
- package/src/internal/trie.ts +43 -14
- package/src/internal/ulid.ts +44 -0
- package/src/internal/uuid.ts +57 -16
- package/src/internal/version.ts +1 -1
- package/src/observability/Otlp.ts +21 -4
- package/src/observability/OtlpResource.ts +9 -1
- package/src/persistence/KeyValueStore.ts +219 -22
- package/src/persistence/PersistedQueue.ts +128 -59
- package/src/persistence/Persistence.ts +20 -13
- package/src/process/ChildProcess.ts +255 -260
- package/src/process/ChildProcessSpawner.ts +5 -0
- package/src/process/CommandLine.ts +630 -0
- package/src/process/index.ts +6 -0
- package/src/reactivity/Atom.ts +5 -5
- package/src/reactivity/AtomRegistry.ts +1 -1
- package/src/rpc/RpcClient.ts +62 -26
- package/src/rpc/RpcMessage.ts +10 -1
- package/src/rpc/RpcSerialization.ts +3 -0
- package/src/rpc/RpcServer.ts +176 -78
- package/src/schema/Model.ts +26 -3
- package/src/sql/Migrator.ts +4 -63
- package/src/sql/MigratorFileSystem.ts +71 -0
- package/src/sql/SqlClient.ts +2 -16
- package/src/sql/Statement.ts +8 -7
- package/src/sql/index.ts +1 -1
- package/src/testing/index.ts +0 -6
- package/src/workflow/internal/crypto.ts +15 -11
- package/dist/Crypto.d.ts +0 -244
- package/dist/Crypto.d.ts.map +0 -1
- package/dist/Crypto.js +0 -139
- package/dist/Crypto.js.map +0 -1
- package/dist/testing/TestCrypto.d.ts +0 -73
- package/dist/testing/TestCrypto.d.ts.map +0 -1
- package/dist/testing/TestCrypto.js +0 -87
- package/dist/testing/TestCrypto.js.map +0 -1
- package/src/Crypto.ts +0 -347
- package/src/testing/TestCrypto.ts +0 -94
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key wrapping: AES-KW (RFC 3394) and RSA-OAEP (RFC 8017).
|
|
3
|
+
*
|
|
4
|
+
* The {@link KeyWrap} service generates AES-KW keys and RSA-OAEP key pairs,
|
|
5
|
+
* wraps keys, and unwraps them. The top-level {@link key},
|
|
6
|
+
* {@link fromCryptoKey}, {@link privateKeyFromCryptoKey},
|
|
7
|
+
* {@link publicKeyFromCryptoKey}, and {@link toBytes} functions build and
|
|
8
|
+
* export keys without a service.
|
|
9
|
+
*
|
|
10
|
+
* `wrap` takes an `Aead`, `Cipher`, `Mac`, or `KeyWrap` key, never raw bytes,
|
|
11
|
+
* which keeps RSA-OAEP limited to key transport. `unwrap` returns a typed key
|
|
12
|
+
* of the algorithm it is given.
|
|
13
|
+
*
|
|
14
|
+
* A key-encryption key is the key most worth keeping non-extractable, so in
|
|
15
|
+
* browsers {@link fromCryptoKey} is the main way to build one.
|
|
16
|
+
*
|
|
17
|
+
* Keys are opaque. They hold either bytes or a `CryptoKey`, display only their
|
|
18
|
+
* algorithm, and compare by reference. The bytes are the AES-KW key, and
|
|
19
|
+
* PKCS#8 or SPKI DER for RSA-OAEP.
|
|
20
|
+
*
|
|
21
|
+
* **Gotchas**
|
|
22
|
+
*
|
|
23
|
+
* - AES-KW wraps keys whose length is a multiple of 8 bytes and at least 16
|
|
24
|
+
* bytes. Other lengths fail with an `InvalidArgument` reason.
|
|
25
|
+
* - RSA-OAEP key generation and encryption use WebCrypto's own randomness and
|
|
26
|
+
* cannot be seeded through `SecureRandom`.
|
|
27
|
+
* - Safari rejects RSA-OAEP keys over 4096 bits.
|
|
28
|
+
*
|
|
29
|
+
* @stability unstable
|
|
30
|
+
* @since 4.0.0
|
|
31
|
+
*/
|
|
32
|
+
import * as Context from "../Context.js";
|
|
33
|
+
import * as Effect from "../Effect.js";
|
|
34
|
+
import * as Layer from "../Layer.js";
|
|
35
|
+
import * as Predicate from "../Predicate.js";
|
|
36
|
+
import * as Aead from "./Aead.js";
|
|
37
|
+
import * as Cipher from "./Cipher.js";
|
|
38
|
+
import * as CryptoError from "./CryptoError.js";
|
|
39
|
+
import * as Digest from "./Digest.js";
|
|
40
|
+
import * as Asymmetric from "./internal/asymmetric.js";
|
|
41
|
+
import * as KeyModel from "./internal/key.js";
|
|
42
|
+
import * as internal from "./internal/webCrypto.js";
|
|
43
|
+
import * as Mac from "./Mac.js";
|
|
44
|
+
import * as SecureRandom from "./SecureRandom.js";
|
|
45
|
+
import { WebCrypto } from "./WebCrypto.js";
|
|
46
|
+
const KeyTypeId = "~effect/crypto/KeyWrap/Key";
|
|
47
|
+
const PrivateKeyTypeId = "~effect/crypto/KeyWrap/PrivateKey";
|
|
48
|
+
const PublicKeyTypeId = "~effect/crypto/KeyWrap/PublicKey";
|
|
49
|
+
/**
|
|
50
|
+
* AES-128-KW (JOSE A128KW), with a 16-byte key.
|
|
51
|
+
*
|
|
52
|
+
* @stability unstable
|
|
53
|
+
* @category algorithms
|
|
54
|
+
* @since 4.0.0
|
|
55
|
+
*/
|
|
56
|
+
export const aes128Kw = {
|
|
57
|
+
_tag: "AesKw",
|
|
58
|
+
name: "aes128Kw",
|
|
59
|
+
keyLength: 16
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* AES-256-KW (JOSE A256KW), with a 32-byte key.
|
|
63
|
+
*
|
|
64
|
+
* @stability unstable
|
|
65
|
+
* @category algorithms
|
|
66
|
+
* @since 4.0.0
|
|
67
|
+
*/
|
|
68
|
+
export const aes256Kw = {
|
|
69
|
+
_tag: "AesKw",
|
|
70
|
+
name: "aes256Kw",
|
|
71
|
+
keyLength: 32
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Builds an RSA-OAEP algorithm for a hash and a modulus length in bits.
|
|
75
|
+
*
|
|
76
|
+
* **Details**
|
|
77
|
+
*
|
|
78
|
+
* MGF1 uses the same hash. There is no OAEP label.
|
|
79
|
+
*
|
|
80
|
+
* @stability unstable
|
|
81
|
+
* @category algorithms
|
|
82
|
+
* @since 4.0.0
|
|
83
|
+
*/
|
|
84
|
+
export const rsaOaep = options => ({
|
|
85
|
+
_tag: "RsaOaep",
|
|
86
|
+
name: `rsaOaep${Digest.nameSuffix(options.hash)}`,
|
|
87
|
+
hash: options.hash,
|
|
88
|
+
modulusLength: options.modulusLength
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* RSA-OAEP with SHA-256 (JOSE RSA-OAEP-256), generating 3072-bit keys. This is
|
|
92
|
+
* the default RSA-OAEP algorithm.
|
|
93
|
+
*
|
|
94
|
+
* @stability unstable
|
|
95
|
+
* @category algorithms
|
|
96
|
+
* @since 4.0.0
|
|
97
|
+
*/
|
|
98
|
+
export const rsaOaepSha256 = /*#__PURE__*/rsaOaep({
|
|
99
|
+
hash: Digest.sha256,
|
|
100
|
+
modulusLength: 3072
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* RSA-OAEP with SHA-1 (JOSE RSA-OAEP), generating 3072-bit keys.
|
|
104
|
+
*
|
|
105
|
+
* **When to use**
|
|
106
|
+
*
|
|
107
|
+
* Use to interoperate with JOSE `RSA-OAEP`. Otherwise prefer
|
|
108
|
+
* {@link rsaOaepSha256}.
|
|
109
|
+
*
|
|
110
|
+
* @stability unstable
|
|
111
|
+
* @category algorithms
|
|
112
|
+
* @since 4.0.0
|
|
113
|
+
*/
|
|
114
|
+
export const rsaOaepSha1 = /*#__PURE__*/rsaOaep({
|
|
115
|
+
hash: Digest.sha1,
|
|
116
|
+
modulusLength: 3072
|
|
117
|
+
});
|
|
118
|
+
const KeyProto = /*#__PURE__*/KeyModel.redactedProto(KeyTypeId, "KeyWrap.Key");
|
|
119
|
+
const PrivateKeyProto = /*#__PURE__*/KeyModel.redactedProto(PrivateKeyTypeId, "KeyWrap.PrivateKey");
|
|
120
|
+
const PublicKeyProto = /*#__PURE__*/KeyModel.redactedProto(PublicKeyTypeId, "KeyWrap.PublicKey");
|
|
121
|
+
/**
|
|
122
|
+
* Checks whether a value is an AES-KW {@link Key}.
|
|
123
|
+
*
|
|
124
|
+
* @stability unstable
|
|
125
|
+
* @category guards
|
|
126
|
+
* @since 4.0.0
|
|
127
|
+
*/
|
|
128
|
+
export const isKey = u => Predicate.hasProperty(u, KeyTypeId);
|
|
129
|
+
/**
|
|
130
|
+
* Checks whether a value is an RSA-OAEP {@link PrivateKey}.
|
|
131
|
+
*
|
|
132
|
+
* @stability unstable
|
|
133
|
+
* @category guards
|
|
134
|
+
* @since 4.0.0
|
|
135
|
+
*/
|
|
136
|
+
export const isPrivateKey = u => Predicate.hasProperty(u, PrivateKeyTypeId);
|
|
137
|
+
/**
|
|
138
|
+
* Checks whether a value is an RSA-OAEP {@link PublicKey}.
|
|
139
|
+
*
|
|
140
|
+
* @stability unstable
|
|
141
|
+
* @category guards
|
|
142
|
+
* @since 4.0.0
|
|
143
|
+
*/
|
|
144
|
+
export const isPublicKey = u => Predicate.hasProperty(u, PublicKeyTypeId);
|
|
145
|
+
const specOf = algorithm => ({
|
|
146
|
+
name: "RSA-OAEP",
|
|
147
|
+
importParams: {
|
|
148
|
+
name: "RSA-OAEP",
|
|
149
|
+
hash: algorithm.hash.name
|
|
150
|
+
},
|
|
151
|
+
privateUsages: ["decrypt"],
|
|
152
|
+
publicUsages: ["encrypt"],
|
|
153
|
+
seedPrefix: undefined,
|
|
154
|
+
publicFormat: "spki",
|
|
155
|
+
check: Asymmetric.checkHash(algorithm.hash.name)
|
|
156
|
+
});
|
|
157
|
+
/** @internal */
|
|
158
|
+
export const family = {
|
|
159
|
+
module: "KeyWrap",
|
|
160
|
+
specOf,
|
|
161
|
+
privateKeyProto: PrivateKeyProto,
|
|
162
|
+
publicKeyProto: PublicKeyProto,
|
|
163
|
+
isPrivateKey
|
|
164
|
+
};
|
|
165
|
+
/** @internal */
|
|
166
|
+
export const secretFamily = algorithm => "nonceLength" in algorithm ? Aead : "mode" in algorithm ? Cipher : "_tag" in algorithm ? {
|
|
167
|
+
key,
|
|
168
|
+
toBytes
|
|
169
|
+
} : Mac;
|
|
170
|
+
// AES-KW in WebCrypto only wraps `CryptoKey`s, so the key bytes go through a
|
|
171
|
+
// temporary extractable HMAC key, which imports any non-empty length.
|
|
172
|
+
const hmacParams = {
|
|
173
|
+
name: "HMAC",
|
|
174
|
+
hash: "SHA-256"
|
|
175
|
+
};
|
|
176
|
+
const rsaOaepParams = {
|
|
177
|
+
name: "RSA-OAEP"
|
|
178
|
+
};
|
|
179
|
+
const invalidArgument = description => new internal.Failure(new CryptoError.InvalidArgument({
|
|
180
|
+
description
|
|
181
|
+
}));
|
|
182
|
+
// RFC 8017, section 7.1.1: the message fits the modulus minus two hashes and
|
|
183
|
+
// two bytes.
|
|
184
|
+
const checkOaepLength = (algorithm, cryptoKey, length) => {
|
|
185
|
+
const modulusLength = cryptoKey.algorithm.modulusLength;
|
|
186
|
+
const max = Math.ceil(modulusLength / 8) - 2 * algorithm.hash.outputLength - 2;
|
|
187
|
+
if (length > max) {
|
|
188
|
+
throw invalidArgument(`A ${modulusLength}-bit RSA-OAEP key with ${algorithm.hash.name} wraps at most ${max} bytes, not ${length}`);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
// RFC 3394, section 2: keys are at least two 64-bit blocks, and the wrapped
|
|
192
|
+
// form adds one block.
|
|
193
|
+
const checkKwLength = (length, overhead) => {
|
|
194
|
+
if (length % 8 !== 0 || length < 16 + overhead) {
|
|
195
|
+
throw invalidArgument(`AES-KW needs a multiple of 8 bytes and at least ${16 + overhead} bytes, not ${length}`);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Service that generates keys, wraps keys, and unwraps them.
|
|
200
|
+
*
|
|
201
|
+
* **Example** (Wrapping an AES-GCM key with AES-KW)
|
|
202
|
+
*
|
|
203
|
+
* ```ts import.meta.vitest
|
|
204
|
+
* import { Effect, Layer } from "effect"
|
|
205
|
+
* import { Aead, KeyWrap, SecureRandom } from "effect/crypto"
|
|
206
|
+
*
|
|
207
|
+
* const program = Effect.gen(function*() {
|
|
208
|
+
* const keyWrap = yield* KeyWrap.KeyWrap
|
|
209
|
+
* const kek = yield* keyWrap.generateKey(KeyWrap.aes256Kw)
|
|
210
|
+
* const key = yield* Aead.key(Aead.aes256Gcm, new Uint8Array(32))
|
|
211
|
+
* const wrapped = yield* keyWrap.wrap(kek, key)
|
|
212
|
+
* const unwrapped = yield* keyWrap.unwrap(kek, Aead.aes256Gcm, wrapped)
|
|
213
|
+
* return [wrapped.length, unwrapped.algorithm.name]
|
|
214
|
+
* })
|
|
215
|
+
*
|
|
216
|
+
* const layer = KeyWrap.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto))
|
|
217
|
+
* await Effect.runPromise(program.pipe(Effect.provide(layer))) // => [40, "aes256Gcm"]
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* @stability unstable
|
|
221
|
+
* @category services
|
|
222
|
+
* @since 4.0.0
|
|
223
|
+
*/
|
|
224
|
+
export class KeyWrap extends /*#__PURE__*/Context.Service()("effect/crypto/KeyWrap") {}
|
|
225
|
+
/**
|
|
226
|
+
* Layer that provides `KeyWrap` on the `WebCrypto` reference.
|
|
227
|
+
*
|
|
228
|
+
* **Details**
|
|
229
|
+
*
|
|
230
|
+
* The layer imports a byte-backed key on first use and caches the
|
|
231
|
+
* `CryptoKey`. AES-KW keys come from `SecureRandom`, so a seeded
|
|
232
|
+
* `SecureRandom` reproduces them.
|
|
233
|
+
*
|
|
234
|
+
* WebCrypto's AES-KW only wraps `CryptoKey`s, so the layer imports the target
|
|
235
|
+
* bytes as a temporary extractable HMAC key and wraps that. RSA-OAEP uses
|
|
236
|
+
* `encrypt` and `decrypt` when the key allows them, and otherwise the same
|
|
237
|
+
* route through `wrapKey` and `unwrapKey`. Both give the same ciphertext.
|
|
238
|
+
*
|
|
239
|
+
* @stability unstable
|
|
240
|
+
* @category layers
|
|
241
|
+
* @since 4.0.0
|
|
242
|
+
*/
|
|
243
|
+
export const layerWebCrypto = /*#__PURE__*/Layer.effect(KeyWrap, /*#__PURE__*/Effect.gen(function* () {
|
|
244
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
245
|
+
const crypto = yield* WebCrypto;
|
|
246
|
+
const kwCryptoKey = KeyModel.makeCache((subtle, bytes) => subtle.importKey("raw", bytes, "AES-KW", false, ["wrapKey", "unwrapKey"]));
|
|
247
|
+
const caches = Asymmetric.makeCaches(family);
|
|
248
|
+
const wrapBytes = (wrapKey, bytes) => internal.run("KeyWrap", "wrap", wrapKey.algorithm.name, crypto, async subtle => {
|
|
249
|
+
if (isKey(wrapKey)) {
|
|
250
|
+
checkKwLength(bytes.length, 0);
|
|
251
|
+
const kek = await kwCryptoKey(subtle, wrapKey);
|
|
252
|
+
const target = await subtle.importKey("raw", bytes, hmacParams, true, ["sign"]);
|
|
253
|
+
return new Uint8Array(await subtle.wrapKey("raw", target, kek, "AES-KW"));
|
|
254
|
+
}
|
|
255
|
+
const publicKey = await caches.publicKey(subtle, wrapKey);
|
|
256
|
+
checkOaepLength(wrapKey.algorithm, publicKey, bytes.length);
|
|
257
|
+
if (publicKey.usages.includes("encrypt")) {
|
|
258
|
+
return new Uint8Array(await subtle.encrypt(rsaOaepParams, publicKey, bytes));
|
|
259
|
+
}
|
|
260
|
+
const target = await subtle.importKey("raw", bytes, hmacParams, true, ["sign"]);
|
|
261
|
+
return new Uint8Array(await subtle.wrapKey("raw", target, publicKey, rsaOaepParams));
|
|
262
|
+
});
|
|
263
|
+
const unwrapBytes = (unwrapKey, wrapped) => internal.run("KeyWrap", "unwrap", unwrapKey.algorithm.name, crypto, async subtle => {
|
|
264
|
+
if (isKey(unwrapKey)) {
|
|
265
|
+
checkKwLength(wrapped.length, 8);
|
|
266
|
+
const kek = await kwCryptoKey(subtle, unwrapKey);
|
|
267
|
+
const target = await subtle.unwrapKey("raw", wrapped, kek, "AES-KW", hmacParams, true, ["sign"]);
|
|
268
|
+
return KeyModel.exportRaw(subtle, target);
|
|
269
|
+
}
|
|
270
|
+
const privateKey = await caches.privateKey(subtle, unwrapKey);
|
|
271
|
+
if (privateKey.usages.includes("decrypt")) {
|
|
272
|
+
return new Uint8Array(await subtle.decrypt(rsaOaepParams, privateKey, wrapped));
|
|
273
|
+
}
|
|
274
|
+
const target = await subtle.unwrapKey("raw", wrapped, privateKey, rsaOaepParams, hmacParams, true, ["sign"]);
|
|
275
|
+
return KeyModel.exportRaw(subtle, target);
|
|
276
|
+
}, cause => internal.webCryptoError("KeyWrap", "unwrap", unwrapKey.algorithm.name, cause, () => new CryptoError.DecryptionFailed()));
|
|
277
|
+
return KeyWrap.of({
|
|
278
|
+
generateKey: algorithm => Effect.map(random.randomBytes(algorithm.keyLength), bytes => KeyModel.makeBytes(KeyProto, algorithm, bytes)),
|
|
279
|
+
generateKeyPair: algorithm => Asymmetric.generateKeyPair(family, crypto, random, algorithm, Asymmetric.rsaGenerateParams(specOf(algorithm), algorithm.modulusLength)),
|
|
280
|
+
wrap: (wrapKey, key) => Effect.suspend(() => {
|
|
281
|
+
const stored = KeyModel.material(key);
|
|
282
|
+
if (stored._tag === "CryptoKey" && !stored.cryptoKey.extractable) {
|
|
283
|
+
return internal.notExtractable("KeyWrap", "wrap");
|
|
284
|
+
}
|
|
285
|
+
return secretFamily(key.algorithm).toBytes(key).pipe(Effect.catch(internal.rehome("KeyWrap", "wrap")), Effect.flatMap(bytes => wrapBytes(wrapKey, bytes)));
|
|
286
|
+
}),
|
|
287
|
+
unwrap: (unwrapKey, algorithm, wrapped) => Effect.flatMap(unwrapBytes(unwrapKey, wrapped), bytes => secretFamily(algorithm).key(algorithm, bytes).pipe(Effect.catch(internal.rehome("KeyWrap", "unwrap"))))
|
|
288
|
+
});
|
|
289
|
+
}));
|
|
290
|
+
/**
|
|
291
|
+
* Builds an AES-KW key from its bytes.
|
|
292
|
+
*
|
|
293
|
+
* **Details**
|
|
294
|
+
*
|
|
295
|
+
* The bytes are copied. A length other than the algorithm's key length fails
|
|
296
|
+
* with an `InvalidKey` reason. RSA-OAEP keys have no raw form, so passing
|
|
297
|
+
* them is a type error.
|
|
298
|
+
*
|
|
299
|
+
* @stability unstable
|
|
300
|
+
* @category constructors
|
|
301
|
+
* @since 4.0.0
|
|
302
|
+
*/
|
|
303
|
+
export const key = (algorithm, bytes) => KeyModel.fromBytes("KeyWrap", "key", KeyProto, algorithm, bytes, KeyModel.checkKeyLength(algorithm));
|
|
304
|
+
/**
|
|
305
|
+
* Builds an AES-KW key from an existing `CryptoKey`, such as a
|
|
306
|
+
* non-extractable one.
|
|
307
|
+
*
|
|
308
|
+
* **Details**
|
|
309
|
+
*
|
|
310
|
+
* The `CryptoKey` must be a secret AES-KW key of the algorithm's length with
|
|
311
|
+
* both the `wrapKey` and `unwrapKey` usages, since a key reaches both
|
|
312
|
+
* operations. Otherwise the constructor fails with an `InvalidKey` reason. It
|
|
313
|
+
* must come from the `Crypto` object of the `WebCrypto` reference.
|
|
314
|
+
*
|
|
315
|
+
* @stability unstable
|
|
316
|
+
* @category constructors
|
|
317
|
+
* @since 4.0.0
|
|
318
|
+
*/
|
|
319
|
+
export const fromCryptoKey = (algorithm, cryptoKey) => KeyModel.fromCryptoKey("KeyWrap", "fromCryptoKey", KeyProto, algorithm, cryptoKey, {
|
|
320
|
+
type: "secret",
|
|
321
|
+
name: "AES-KW",
|
|
322
|
+
usages: ["wrapKey", "unwrapKey"],
|
|
323
|
+
usagePolicy: "all",
|
|
324
|
+
check: KeyModel.checkAesLength("AES-KW", algorithm.keyLength)
|
|
325
|
+
});
|
|
326
|
+
// RSA-OAEP keys need one usage the layer can use for the key's role, since
|
|
327
|
+
// `wrapKey` and `encrypt` produce the same ciphertext.
|
|
328
|
+
const rsaFromCryptoKey = (method, proto, algorithm, role, cryptoKey) => KeyModel.fromCryptoKey("KeyWrap", method, proto, algorithm, cryptoKey, {
|
|
329
|
+
type: role,
|
|
330
|
+
name: "RSA-OAEP",
|
|
331
|
+
usages: role === "private" ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"],
|
|
332
|
+
usagePolicy: "any",
|
|
333
|
+
check: Asymmetric.checkHash(algorithm.hash.name)
|
|
334
|
+
});
|
|
335
|
+
/**
|
|
336
|
+
* Builds an RSA-OAEP private key from an existing `CryptoKey`, such as a
|
|
337
|
+
* non-extractable one.
|
|
338
|
+
*
|
|
339
|
+
* **Details**
|
|
340
|
+
*
|
|
341
|
+
* The `CryptoKey` must be an RSA-OAEP private key with the algorithm's hash
|
|
342
|
+
* and the `decrypt` or `unwrapKey` usage. Otherwise the constructor fails
|
|
343
|
+
* with an `InvalidKey` reason. The modulus length is not checked. The key must
|
|
344
|
+
* come from the `Crypto` object of the `WebCrypto` reference.
|
|
345
|
+
*
|
|
346
|
+
* @stability unstable
|
|
347
|
+
* @category constructors
|
|
348
|
+
* @since 4.0.0
|
|
349
|
+
*/
|
|
350
|
+
export const privateKeyFromCryptoKey = (algorithm, cryptoKey) => rsaFromCryptoKey("privateKeyFromCryptoKey", PrivateKeyProto, algorithm, "private", cryptoKey);
|
|
351
|
+
/**
|
|
352
|
+
* Builds an RSA-OAEP public key from an existing `CryptoKey`.
|
|
353
|
+
*
|
|
354
|
+
* **Details**
|
|
355
|
+
*
|
|
356
|
+
* The `CryptoKey` must be an RSA-OAEP public key with the algorithm's hash and
|
|
357
|
+
* the `encrypt` or `wrapKey` usage. Otherwise the constructor fails with an
|
|
358
|
+
* `InvalidKey` reason. The key must come from the `Crypto` object of the
|
|
359
|
+
* `WebCrypto` reference.
|
|
360
|
+
*
|
|
361
|
+
* @stability unstable
|
|
362
|
+
* @category constructors
|
|
363
|
+
* @since 4.0.0
|
|
364
|
+
*/
|
|
365
|
+
export const publicKeyFromCryptoKey = (algorithm, cryptoKey) => rsaFromCryptoKey("publicKeyFromCryptoKey", PublicKeyProto, algorithm, "public", cryptoKey);
|
|
366
|
+
/**
|
|
367
|
+
* Exports a key's stored bytes.
|
|
368
|
+
*
|
|
369
|
+
* **Details**
|
|
370
|
+
*
|
|
371
|
+
* Returns a fresh `Uint8Array`: the AES-KW key, or PKCS#8 or SPKI DER for
|
|
372
|
+
* RSA-OAEP. A `CryptoKey`-backed key is exported on the `WebCrypto`
|
|
373
|
+
* reference, and fails with a `NotExtractable` reason when the `CryptoKey` is
|
|
374
|
+
* not extractable.
|
|
375
|
+
*
|
|
376
|
+
* @stability unstable
|
|
377
|
+
* @category converting
|
|
378
|
+
* @since 4.0.0
|
|
379
|
+
*/
|
|
380
|
+
export const toBytes = key => isKey(key) ? KeyModel.toBytes("KeyWrap", key, KeyModel.exportRaw) : Asymmetric.toBytes(family, key);
|
|
381
|
+
//# sourceMappingURL=KeyWrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyWrap.js","names":[],"sources":["../../src/crypto/KeyWrap.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,OAAO,KAAK,OAAO,MAAM,eAAe;AACxC,OAAO,KAAK,MAAM,MAAM,cAAc;AAEtC,OAAO,KAAK,KAAK,MAAM,aAAa;AACpC,OAAO,KAAK,SAAS,MAAM,iBAAiB;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW;AACjC,OAAO,KAAK,MAAM,MAAM,aAAa;AACrC,OAAO,KAAK,WAAW,MAAM,kBAAkB;AAC/C,OAAO,KAAK,MAAM,MAAM,aAAa;AACrC,OAAO,KAAK,UAAU,MAAM,0BAA0B;AACtD,OAAO,KAAK,QAAQ,MAAM,mBAAmB;AAC7C,OAAO,KAAK,QAAQ,MAAM,yBAAyB;AAEnD,OAAO,KAAK,GAAG,MAAM,UAAU;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AS,CAAC;AAE/F;;;;;;;;;;;;;;AAcA,OAAO,MAAM,sBAAsB,GAAG,CACpC,SAAY,EACZ,SAAoB,KAEpB,gBAAgB,CAAC,wBAAwB,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC;AAE5F;;;;;;;;;;;;;;AAcA,OAAO,MAAM,OAAO,GAAI,GAAiC,IACvD,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message authentication codes: HMAC with SHA-1, SHA-256, SHA-384, or
|
|
3
|
+
* SHA-512.
|
|
4
|
+
*
|
|
5
|
+
* The {@link Mac} service generates keys, signs data, and verifies tags. The
|
|
6
|
+
* top-level {@link key}, {@link fromCryptoKey}, and {@link toBytes} functions
|
|
7
|
+
* build and export keys without a service, and {@link timingSafeEqual}
|
|
8
|
+
* compares byte arrays in constant time.
|
|
9
|
+
*
|
|
10
|
+
* Keys are opaque. They hold either key bytes or a `CryptoKey`, display only
|
|
11
|
+
* their algorithm, and compare by reference.
|
|
12
|
+
*
|
|
13
|
+
* @stability unstable
|
|
14
|
+
* @since 4.0.0
|
|
15
|
+
*/
|
|
16
|
+
import * as Context from "../Context.ts";
|
|
17
|
+
import * as Effect from "../Effect.ts";
|
|
18
|
+
import type { Inspectable } from "../Inspectable.ts";
|
|
19
|
+
import * as Layer from "../Layer.ts";
|
|
20
|
+
import type * as CryptoError from "./CryptoError.ts";
|
|
21
|
+
import * as Digest from "./Digest.ts";
|
|
22
|
+
import * as SecureRandom from "./SecureRandom.ts";
|
|
23
|
+
declare const TypeId: "~effect/crypto/Mac/Key";
|
|
24
|
+
/**
|
|
25
|
+
* An HMAC algorithm, such as {@link hmacSha256}.
|
|
26
|
+
*
|
|
27
|
+
* **Details**
|
|
28
|
+
*
|
|
29
|
+
* `hash` is the digest the HMAC is built on.
|
|
30
|
+
*
|
|
31
|
+
* @stability unstable
|
|
32
|
+
* @category models
|
|
33
|
+
* @since 4.0.0
|
|
34
|
+
*/
|
|
35
|
+
export interface Algorithm {
|
|
36
|
+
readonly name: "hmacSha1" | "hmacSha256" | "hmacSha384" | "hmacSha512";
|
|
37
|
+
readonly hash: Digest.Algorithm;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* HMAC with SHA-1, with a 20-byte tag.
|
|
41
|
+
*
|
|
42
|
+
* **Gotchas**
|
|
43
|
+
*
|
|
44
|
+
* HMAC-SHA-1 is still secure as a MAC, but use it only for interoperability
|
|
45
|
+
* with existing protocols.
|
|
46
|
+
*
|
|
47
|
+
* @stability unstable
|
|
48
|
+
* @category algorithms
|
|
49
|
+
* @since 4.0.0
|
|
50
|
+
*/
|
|
51
|
+
export declare const hmacSha1: Algorithm;
|
|
52
|
+
/**
|
|
53
|
+
* HMAC with SHA-256, with a 32-byte tag.
|
|
54
|
+
*
|
|
55
|
+
* @stability unstable
|
|
56
|
+
* @category algorithms
|
|
57
|
+
* @since 4.0.0
|
|
58
|
+
*/
|
|
59
|
+
export declare const hmacSha256: Algorithm;
|
|
60
|
+
/**
|
|
61
|
+
* HMAC with SHA-384, with a 48-byte tag.
|
|
62
|
+
*
|
|
63
|
+
* @stability unstable
|
|
64
|
+
* @category algorithms
|
|
65
|
+
* @since 4.0.0
|
|
66
|
+
*/
|
|
67
|
+
export declare const hmacSha384: Algorithm;
|
|
68
|
+
/**
|
|
69
|
+
* HMAC with SHA-512, with a 64-byte tag.
|
|
70
|
+
*
|
|
71
|
+
* @stability unstable
|
|
72
|
+
* @category algorithms
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
*/
|
|
75
|
+
export declare const hmacSha512: Algorithm;
|
|
76
|
+
/**
|
|
77
|
+
* An opaque HMAC key for the algorithm `A`.
|
|
78
|
+
*
|
|
79
|
+
* **Details**
|
|
80
|
+
*
|
|
81
|
+
* The key holds either key bytes or a `CryptoKey` from {@link fromCryptoKey}.
|
|
82
|
+
* `toString`, `toJSON`, and `inspect` show only the algorithm. Keys compare
|
|
83
|
+
* by reference and do not implement `Equal`, because comparing key bytes is
|
|
84
|
+
* not constant time.
|
|
85
|
+
*
|
|
86
|
+
* @stability unstable
|
|
87
|
+
* @category models
|
|
88
|
+
* @since 4.0.0
|
|
89
|
+
*/
|
|
90
|
+
export interface Key<out A extends Algorithm = Algorithm> extends Inspectable {
|
|
91
|
+
readonly [TypeId]: typeof TypeId;
|
|
92
|
+
readonly algorithm: A;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Checks whether a value is a {@link Key}.
|
|
96
|
+
*
|
|
97
|
+
* @stability unstable
|
|
98
|
+
* @category guards
|
|
99
|
+
* @since 4.0.0
|
|
100
|
+
*/
|
|
101
|
+
export declare const isKey: (u: unknown) => u is Key;
|
|
102
|
+
declare const Mac_base: Context.ServiceClass<Mac, "effect/crypto/Mac", {
|
|
103
|
+
/**
|
|
104
|
+
* Generates a random key of the hash's block size from `SecureRandom`
|
|
105
|
+
* bytes.
|
|
106
|
+
*/
|
|
107
|
+
readonly generateKey: <A extends Algorithm>(algorithm: A) => Effect.Effect<Key<A>, CryptoError.CryptoError>;
|
|
108
|
+
/**
|
|
109
|
+
* Computes the tag of `data`.
|
|
110
|
+
*/
|
|
111
|
+
readonly sign: (key: Key, data: Uint8Array) => Effect.Effect<Uint8Array, CryptoError.CryptoError>;
|
|
112
|
+
/**
|
|
113
|
+
* Checks `tag` against the tag of `data` in constant time. A wrong tag, or
|
|
114
|
+
* a tag of the wrong length, returns `false`.
|
|
115
|
+
*/
|
|
116
|
+
readonly verify: (key: Key, tag: Uint8Array, data: Uint8Array) => Effect.Effect<boolean, CryptoError.CryptoError>;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Service that generates HMAC keys, signs data, and verifies tags.
|
|
120
|
+
*
|
|
121
|
+
* **Example** (Signing and verifying a message)
|
|
122
|
+
*
|
|
123
|
+
* ```ts import.meta.vitest
|
|
124
|
+
* import { Effect, Layer } from "effect"
|
|
125
|
+
* import { Mac, SecureRandom } from "effect/crypto"
|
|
126
|
+
*
|
|
127
|
+
* const program = Effect.gen(function*() {
|
|
128
|
+
* const mac = yield* Mac.Mac
|
|
129
|
+
* const key = yield* mac.generateKey(Mac.hmacSha256)
|
|
130
|
+
* const data = new TextEncoder().encode("message")
|
|
131
|
+
* const tag = yield* mac.sign(key, data)
|
|
132
|
+
* return yield* mac.verify(key, tag, data)
|
|
133
|
+
* })
|
|
134
|
+
*
|
|
135
|
+
* const layer = Mac.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto))
|
|
136
|
+
* const valid = await Effect.runPromise(program.pipe(Effect.provide(layer)))
|
|
137
|
+
* valid // => true
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @stability unstable
|
|
141
|
+
* @category services
|
|
142
|
+
* @since 4.0.0
|
|
143
|
+
*/
|
|
144
|
+
export declare class Mac extends Mac_base {
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Builds a `Mac` layer on the `WebCrypto` reference that can sign and verify
|
|
148
|
+
* byte-backed keys with a synchronous HMAC primitive.
|
|
149
|
+
*
|
|
150
|
+
* **When to use**
|
|
151
|
+
*
|
|
152
|
+
* Use to run HMAC on a runtime's native code, as `NodeCrypto.layerMac` does
|
|
153
|
+
* with `createHmac` from `node:crypto`.
|
|
154
|
+
*
|
|
155
|
+
* **Details**
|
|
156
|
+
*
|
|
157
|
+
* `hmac` receives the hash name, the key bytes, and the data, and returns the
|
|
158
|
+
* tag. It runs only for byte-backed keys. `CryptoKey`-backed keys run on
|
|
159
|
+
* `crypto.subtle`, and generated keys come from `SecureRandom`, as in
|
|
160
|
+
* {@link layerWebCrypto}. `verify` computes the tag with `hmac` and compares
|
|
161
|
+
* it with {@link timingSafeEqual}. Without `hmac`, the layer is
|
|
162
|
+
* {@link layerWebCrypto}.
|
|
163
|
+
*
|
|
164
|
+
* **Gotchas**
|
|
165
|
+
*
|
|
166
|
+
* `hmac` receives the key's own bytes, not a copy, so it must not modify or
|
|
167
|
+
* keep them.
|
|
168
|
+
*
|
|
169
|
+
* **Example** (Signing with a native HMAC)
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { Layer } from "effect"
|
|
173
|
+
* import { Mac, SecureRandom } from "effect/crypto"
|
|
174
|
+
*
|
|
175
|
+
* declare const nativeHmac: (hash: string, key: Uint8Array, data: Uint8Array) => Uint8Array
|
|
176
|
+
*
|
|
177
|
+
* const layer = Mac.layerWebCryptoWith({ hmac: nativeHmac }).pipe(
|
|
178
|
+
* Layer.provide(SecureRandom.layerWebCrypto)
|
|
179
|
+
* )
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @stability unstable
|
|
183
|
+
* @category layers
|
|
184
|
+
* @since 4.0.0
|
|
185
|
+
*/
|
|
186
|
+
export declare const layerWebCryptoWith: (options: {
|
|
187
|
+
readonly hmac?: ((hash: Digest.Algorithm["name"], key: Uint8Array, data: Uint8Array) => Uint8Array) | undefined;
|
|
188
|
+
}) => Layer.Layer<Mac, never, SecureRandom.SecureRandom>;
|
|
189
|
+
/**
|
|
190
|
+
* Layer that provides `Mac` on the `WebCrypto` reference.
|
|
191
|
+
*
|
|
192
|
+
* **Details**
|
|
193
|
+
*
|
|
194
|
+
* Signing and verification run on `crypto.subtle`. The layer imports a
|
|
195
|
+
* byte-backed key on first use and caches the `CryptoKey`. Generated keys come
|
|
196
|
+
* from `SecureRandom`, so a seeded `SecureRandom` gives reproducible keys.
|
|
197
|
+
*
|
|
198
|
+
* @stability unstable
|
|
199
|
+
* @category layers
|
|
200
|
+
* @since 4.0.0
|
|
201
|
+
*/
|
|
202
|
+
export declare const layerWebCrypto: Layer.Layer<Mac, never, SecureRandom.SecureRandom>;
|
|
203
|
+
/**
|
|
204
|
+
* Builds a key from raw key bytes.
|
|
205
|
+
*
|
|
206
|
+
* **Details**
|
|
207
|
+
*
|
|
208
|
+
* The bytes are copied into a new `Uint8Array`, so later changes to the input,
|
|
209
|
+
* including a Node.js `Buffer`, do not reach the key. Any non-empty length is
|
|
210
|
+
* accepted; RFC 2104 recommends at least the hash's output length. An empty key
|
|
211
|
+
* fails with an `InvalidKey` reason.
|
|
212
|
+
*
|
|
213
|
+
* @stability unstable
|
|
214
|
+
* @category constructors
|
|
215
|
+
* @since 4.0.0
|
|
216
|
+
*/
|
|
217
|
+
export declare const key: <A extends Algorithm>(algorithm: A, bytes: Uint8Array) => Effect.Effect<Key<A>, CryptoError.CryptoError>;
|
|
218
|
+
/**
|
|
219
|
+
* Builds a key from an existing `CryptoKey`, such as a non-extractable one.
|
|
220
|
+
*
|
|
221
|
+
* **Details**
|
|
222
|
+
*
|
|
223
|
+
* The `CryptoKey` must be a secret HMAC key with the algorithm's hash and both
|
|
224
|
+
* the `sign` and `verify` usages, since a key reaches both operations.
|
|
225
|
+
* Otherwise the constructor fails with an `InvalidKey` reason. It must come
|
|
226
|
+
* from the `Crypto` object of the `WebCrypto` reference.
|
|
227
|
+
*
|
|
228
|
+
* @stability unstable
|
|
229
|
+
* @category constructors
|
|
230
|
+
* @since 4.0.0
|
|
231
|
+
*/
|
|
232
|
+
export declare const fromCryptoKey: <A extends Algorithm>(algorithm: A, cryptoKey: CryptoKey) => Effect.Effect<Key<A>, CryptoError.CryptoError>;
|
|
233
|
+
/**
|
|
234
|
+
* Exports a key's bytes.
|
|
235
|
+
*
|
|
236
|
+
* **Details**
|
|
237
|
+
*
|
|
238
|
+
* Returns a fresh `Uint8Array` that shares no memory with the key. A
|
|
239
|
+
* `CryptoKey`-backed key is exported on the `WebCrypto` reference, and fails
|
|
240
|
+
* with a `NotExtractable` reason when the `CryptoKey` is not extractable.
|
|
241
|
+
*
|
|
242
|
+
* @stability unstable
|
|
243
|
+
* @category converting
|
|
244
|
+
* @since 4.0.0
|
|
245
|
+
*/
|
|
246
|
+
export declare const toBytes: (key: Key) => Effect.Effect<Uint8Array, CryptoError.CryptoError>;
|
|
247
|
+
/**
|
|
248
|
+
* Compares two byte arrays in constant time.
|
|
249
|
+
*
|
|
250
|
+
* **When to use**
|
|
251
|
+
*
|
|
252
|
+
* Use to compare secrets of a fixed, known length, such as tags computed
|
|
253
|
+
* outside {@link Mac}. To check an HMAC tag, use `Mac.verify`.
|
|
254
|
+
*
|
|
255
|
+
* **Gotchas**
|
|
256
|
+
*
|
|
257
|
+
* Arrays of different lengths return `false` immediately, revealing their
|
|
258
|
+
* lengths. Equal-length arrays are compared with an XOR-accumulate loop;
|
|
259
|
+
* JavaScript runtimes do not guarantee constant-time execution.
|
|
260
|
+
*
|
|
261
|
+
* **Example** (Comparing fixed-length secrets)
|
|
262
|
+
*
|
|
263
|
+
* ```ts import.meta.vitest
|
|
264
|
+
* import { Mac } from "effect/crypto"
|
|
265
|
+
*
|
|
266
|
+
* const expected = new Uint8Array([1, 2, 3])
|
|
267
|
+
* const received = new Uint8Array([1, 2, 3])
|
|
268
|
+
* Mac.timingSafeEqual(expected, received) // => true
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @stability unstable
|
|
272
|
+
* @category utils
|
|
273
|
+
* @since 4.0.0
|
|
274
|
+
*/
|
|
275
|
+
export declare const timingSafeEqual: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
276
|
+
export {};
|
|
277
|
+
//# sourceMappingURL=Mac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mac.d.ts","sourceRoot":"","sources":["../../src/crypto/Mac.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD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