@fgv/ts-extras 5.1.0-5 → 5.1.0-50
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/LICENSE +1 -1
- package/README.md +90 -0
- package/dist/index.browser.js +6 -2
- package/dist/index.browser.js.map +1 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/packlets/ai-assist/chatRequestBuilders.js +282 -0
- package/dist/packlets/ai-assist/chatRequestBuilders.js.map +1 -0
- package/dist/packlets/ai-assist/{apiClient.js → completionClient.js} +165 -214
- package/dist/packlets/ai-assist/completionClient.js.map +1 -0
- package/dist/packlets/ai-assist/converters.js +47 -3
- package/dist/packlets/ai-assist/converters.js.map +1 -0
- package/dist/packlets/ai-assist/embeddingClient.js +345 -0
- package/dist/packlets/ai-assist/embeddingClient.js.map +1 -0
- package/dist/packlets/ai-assist/endpoint.js +107 -0
- package/dist/packlets/ai-assist/endpoint.js.map +1 -0
- package/dist/packlets/ai-assist/http.js +104 -0
- package/dist/packlets/ai-assist/http.js.map +1 -0
- package/dist/packlets/ai-assist/imageGenerationClient.js +454 -0
- package/dist/packlets/ai-assist/imageGenerationClient.js.map +1 -0
- package/dist/packlets/ai-assist/imageOptionsResolver.js +193 -0
- package/dist/packlets/ai-assist/imageOptionsResolver.js.map +1 -0
- package/dist/packlets/ai-assist/index.js +12 -4
- package/dist/packlets/ai-assist/index.js.map +1 -0
- package/dist/packlets/ai-assist/jsonCompletion.js +93 -0
- package/dist/packlets/ai-assist/jsonCompletion.js.map +1 -0
- package/dist/packlets/ai-assist/jsonResponse.js +423 -0
- package/dist/packlets/ai-assist/jsonResponse.js.map +1 -0
- package/dist/packlets/ai-assist/listModelsClient.js +294 -0
- package/dist/packlets/ai-assist/listModelsClient.js.map +1 -0
- package/dist/packlets/ai-assist/model.js +301 -9
- package/dist/packlets/ai-assist/model.js.map +1 -0
- package/dist/packlets/ai-assist/registry.js +376 -12
- package/dist/packlets/ai-assist/registry.js.map +1 -0
- package/dist/packlets/ai-assist/sseParser.js +123 -0
- package/dist/packlets/ai-assist/sseParser.js.map +1 -0
- package/dist/packlets/ai-assist/streamingAdapters/anthropic.js +376 -0
- package/dist/packlets/ai-assist/streamingAdapters/anthropic.js.map +1 -0
- package/dist/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.js +687 -0
- package/dist/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.js.map +1 -0
- package/dist/packlets/ai-assist/streamingAdapters/common.js +187 -0
- package/dist/packlets/ai-assist/streamingAdapters/common.js.map +1 -0
- package/dist/packlets/ai-assist/streamingAdapters/gemini.js +208 -0
- package/dist/packlets/ai-assist/streamingAdapters/gemini.js.map +1 -0
- package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js +175 -0
- package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js.map +1 -0
- package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js +390 -0
- package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js.map +1 -0
- package/dist/packlets/ai-assist/streamingAdapters/proxy.js +178 -0
- package/dist/packlets/ai-assist/streamingAdapters/proxy.js.map +1 -0
- package/dist/packlets/ai-assist/streamingClient.js +140 -0
- package/dist/packlets/ai-assist/streamingClient.js.map +1 -0
- package/dist/packlets/ai-assist/thinkingOptionsResolver.js +288 -0
- package/dist/packlets/ai-assist/thinkingOptionsResolver.js.map +1 -0
- package/dist/packlets/ai-assist/toolFormats.js +106 -10
- package/dist/packlets/ai-assist/toolFormats.js.map +1 -0
- package/dist/packlets/conversion/converters.js +35 -1
- package/dist/packlets/conversion/converters.js.map +1 -0
- package/dist/packlets/conversion/index.js.map +1 -0
- package/dist/packlets/crypto-utils/constants.js.map +1 -0
- package/dist/packlets/crypto-utils/converters.js +42 -4
- package/dist/packlets/crypto-utils/converters.js.map +1 -0
- package/dist/packlets/crypto-utils/directEncryptionProvider.js.map +1 -0
- package/dist/packlets/crypto-utils/encryptedFile.js +37 -0
- package/dist/packlets/crypto-utils/encryptedFile.js.map +1 -0
- package/dist/packlets/crypto-utils/hpkeProvider.js +355 -0
- package/dist/packlets/crypto-utils/hpkeProvider.js.map +1 -0
- package/dist/packlets/crypto-utils/index.browser.js +13 -2
- package/dist/packlets/crypto-utils/index.browser.js.map +1 -0
- package/dist/packlets/crypto-utils/index.js +9 -1
- package/dist/packlets/crypto-utils/index.js.map +1 -0
- package/dist/packlets/crypto-utils/keyPairAlgorithmParams.js +71 -0
- package/dist/packlets/crypto-utils/keyPairAlgorithmParams.js.map +1 -0
- package/dist/packlets/crypto-utils/keystore/converters.js +111 -16
- package/dist/packlets/crypto-utils/keystore/converters.js.map +1 -0
- package/dist/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.js +287 -0
- package/dist/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.js.map +1 -0
- package/dist/packlets/crypto-utils/keystore/index.browser.js +36 -0
- package/dist/packlets/crypto-utils/keystore/index.browser.js.map +1 -0
- package/dist/packlets/crypto-utils/keystore/index.js +3 -0
- package/dist/packlets/crypto-utils/keystore/index.js.map +1 -0
- package/dist/packlets/crypto-utils/keystore/keyStore.js +872 -119
- package/dist/packlets/crypto-utils/keystore/keyStore.js.map +1 -0
- package/dist/packlets/crypto-utils/keystore/model.js +35 -4
- package/dist/packlets/crypto-utils/keystore/model.js.map +1 -0
- package/dist/packlets/crypto-utils/keystore/privateKeyStorage.js +21 -0
- package/dist/packlets/crypto-utils/keystore/privateKeyStorage.js.map +1 -0
- package/dist/packlets/crypto-utils/model.js +32 -0
- package/dist/packlets/crypto-utils/model.js.map +1 -0
- package/dist/packlets/crypto-utils/nodeCryptoProvider.js +347 -1
- package/dist/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -0
- package/dist/packlets/crypto-utils/seedDerivedKeyPair.js +120 -0
- package/dist/packlets/crypto-utils/seedDerivedKeyPair.js.map +1 -0
- package/dist/packlets/crypto-utils/spkiHelpers.js +284 -0
- package/dist/packlets/crypto-utils/spkiHelpers.js.map +1 -0
- package/dist/packlets/csv/csvFileHelpers.js +0 -14
- package/dist/packlets/csv/csvFileHelpers.js.map +1 -0
- package/dist/packlets/csv/csvHelpers.js +14 -0
- package/dist/packlets/csv/csvHelpers.js.map +1 -0
- package/dist/packlets/csv/index.browser.js +1 -3
- package/dist/packlets/csv/index.browser.js.map +1 -0
- package/dist/packlets/csv/index.js.map +1 -0
- package/dist/packlets/experimental/extendedArray.js.map +1 -0
- package/dist/packlets/experimental/formatter.js.map +1 -0
- package/dist/packlets/experimental/index.js.map +1 -0
- package/dist/packlets/experimental/rangeOf.js.map +1 -0
- package/dist/packlets/hash/index.browser.js.map +1 -0
- package/dist/packlets/hash/index.js.map +1 -0
- package/dist/packlets/hash/index.node.js.map +1 -0
- package/dist/packlets/hash/md5Normalizer.browser.js.map +1 -0
- package/dist/packlets/hash/md5Normalizer.js.map +1 -0
- package/dist/packlets/mustache/index.js.map +1 -0
- package/dist/packlets/mustache/interfaces.js.map +1 -0
- package/dist/packlets/mustache/mustacheTemplate.js +42 -4
- package/dist/packlets/mustache/mustacheTemplate.js.map +1 -0
- package/dist/packlets/record-jar/index.browser.js +1 -3
- package/dist/packlets/record-jar/index.browser.js.map +1 -0
- package/dist/packlets/record-jar/index.js.map +1 -0
- package/dist/packlets/record-jar/recordJarFileHelpers.js +0 -18
- package/dist/packlets/record-jar/recordJarFileHelpers.js.map +1 -0
- package/dist/packlets/record-jar/recordJarHelpers.js +18 -0
- package/dist/packlets/record-jar/recordJarHelpers.js.map +1 -0
- package/dist/packlets/safer-fetch/addressClassification.js +438 -0
- package/dist/packlets/safer-fetch/addressClassification.js.map +1 -0
- package/dist/packlets/safer-fetch/addressPolicy.js +119 -0
- package/dist/packlets/safer-fetch/addressPolicy.js.map +1 -0
- package/dist/packlets/safer-fetch/contentType.js +120 -0
- package/dist/packlets/safer-fetch/contentType.js.map +1 -0
- package/dist/packlets/safer-fetch/deadline.js +254 -0
- package/dist/packlets/safer-fetch/deadline.js.map +1 -0
- package/dist/packlets/safer-fetch/defaults.js +131 -0
- package/dist/packlets/safer-fetch/defaults.js.map +1 -0
- package/dist/packlets/safer-fetch/failureReason.js +21 -0
- package/dist/packlets/safer-fetch/failureReason.js.map +1 -0
- package/dist/packlets/safer-fetch/guards.js +148 -0
- package/dist/packlets/safer-fetch/guards.js.map +1 -0
- package/dist/packlets/safer-fetch/index.browser.js +58 -0
- package/dist/packlets/safer-fetch/index.browser.js.map +1 -0
- package/dist/packlets/safer-fetch/index.js +52 -0
- package/dist/packlets/safer-fetch/index.js.map +1 -0
- package/dist/packlets/safer-fetch/model.js +21 -0
- package/dist/packlets/safer-fetch/model.js.map +1 -0
- package/dist/packlets/safer-fetch/nodeAddressGuard.js +191 -0
- package/dist/packlets/safer-fetch/nodeAddressGuard.js.map +1 -0
- package/dist/packlets/safer-fetch/redirect.js +93 -0
- package/dist/packlets/safer-fetch/redirect.js.map +1 -0
- package/dist/packlets/safer-fetch/retry.js +188 -0
- package/dist/packlets/safer-fetch/retry.js.map +1 -0
- package/dist/packlets/safer-fetch/saferFetch.js +755 -0
- package/dist/packlets/safer-fetch/saferFetch.js.map +1 -0
- package/dist/packlets/safer-fetch/transport.js +50 -0
- package/dist/packlets/safer-fetch/transport.js.map +1 -0
- package/dist/packlets/yaml/converters.js.map +1 -0
- package/dist/packlets/yaml/index.js +1 -0
- package/dist/packlets/yaml/index.js.map +1 -0
- package/dist/packlets/yaml/serializers.js +48 -0
- package/dist/packlets/yaml/serializers.js.map +1 -0
- package/dist/packlets/zip-file-tree/index.js.map +1 -0
- package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +99 -9
- package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js.map +1 -0
- package/dist/packlets/zip-file-tree/zipFileTreeWriter.js +16 -1
- package/dist/packlets/zip-file-tree/zipFileTreeWriter.js.map +1 -0
- package/dist/ts-extras.d.ts +6648 -553
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +5 -2
- package/lib/index.browser.d.ts.map +1 -0
- package/lib/index.browser.js +11 -3
- package/lib/index.browser.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -0
- package/lib/packlets/ai-assist/chatRequestBuilders.d.ts +149 -0
- package/lib/packlets/ai-assist/chatRequestBuilders.d.ts.map +1 -0
- package/lib/packlets/ai-assist/chatRequestBuilders.js +293 -0
- package/lib/packlets/ai-assist/chatRequestBuilders.js.map +1 -0
- package/lib/packlets/ai-assist/completionClient.d.ts +74 -0
- package/lib/packlets/ai-assist/completionClient.d.ts.map +1 -0
- package/lib/packlets/ai-assist/{apiClient.js → completionClient.js} +164 -213
- package/lib/packlets/ai-assist/completionClient.js.map +1 -0
- package/lib/packlets/ai-assist/converters.d.ts +15 -1
- package/lib/packlets/ai-assist/converters.d.ts.map +1 -0
- package/lib/packlets/ai-assist/converters.js +47 -3
- package/lib/packlets/ai-assist/converters.js.map +1 -0
- package/lib/packlets/ai-assist/embeddingClient.d.ts +69 -0
- package/lib/packlets/ai-assist/embeddingClient.d.ts.map +1 -0
- package/lib/packlets/ai-assist/embeddingClient.js +349 -0
- package/lib/packlets/ai-assist/embeddingClient.js.map +1 -0
- package/lib/packlets/ai-assist/endpoint.d.ts +49 -0
- package/lib/packlets/ai-assist/endpoint.d.ts.map +1 -0
- package/lib/packlets/ai-assist/endpoint.js +113 -0
- package/lib/packlets/ai-assist/endpoint.js.map +1 -0
- package/lib/packlets/ai-assist/http.d.ts +34 -0
- package/lib/packlets/ai-assist/http.d.ts.map +1 -0
- package/lib/packlets/ai-assist/http.js +109 -0
- package/lib/packlets/ai-assist/http.js.map +1 -0
- package/lib/packlets/ai-assist/imageGenerationClient.d.ts +46 -0
- package/lib/packlets/ai-assist/imageGenerationClient.d.ts.map +1 -0
- package/lib/packlets/ai-assist/imageGenerationClient.js +458 -0
- package/lib/packlets/ai-assist/imageGenerationClient.js.map +1 -0
- package/lib/packlets/ai-assist/imageOptionsResolver.d.ts +66 -0
- package/lib/packlets/ai-assist/imageOptionsResolver.d.ts.map +1 -0
- package/lib/packlets/ai-assist/imageOptionsResolver.js +197 -0
- package/lib/packlets/ai-assist/imageOptionsResolver.js.map +1 -0
- package/lib/packlets/ai-assist/index.d.ts +12 -4
- package/lib/packlets/ai-assist/index.d.ts.map +1 -0
- package/lib/packlets/ai-assist/index.js +47 -4
- package/lib/packlets/ai-assist/index.js.map +1 -0
- package/lib/packlets/ai-assist/jsonCompletion.d.ts +93 -0
- package/lib/packlets/ai-assist/jsonCompletion.d.ts.map +1 -0
- package/lib/packlets/ai-assist/jsonCompletion.js +97 -0
- package/lib/packlets/ai-assist/jsonCompletion.js.map +1 -0
- package/lib/packlets/ai-assist/jsonResponse.d.ts +194 -0
- package/lib/packlets/ai-assist/jsonResponse.d.ts.map +1 -0
- package/lib/packlets/ai-assist/jsonResponse.js +429 -0
- package/lib/packlets/ai-assist/jsonResponse.js.map +1 -0
- package/lib/packlets/ai-assist/listModelsClient.d.ts +46 -0
- package/lib/packlets/ai-assist/listModelsClient.d.ts.map +1 -0
- package/lib/packlets/ai-assist/listModelsClient.js +298 -0
- package/lib/packlets/ai-assist/listModelsClient.js.map +1 -0
- package/lib/packlets/ai-assist/model.d.ts +1346 -12
- package/lib/packlets/ai-assist/model.d.ts.map +1 -0
- package/lib/packlets/ai-assist/model.js +309 -10
- package/lib/packlets/ai-assist/model.js.map +1 -0
- package/lib/packlets/ai-assist/registry.d.ts +76 -1
- package/lib/packlets/ai-assist/registry.d.ts.map +1 -0
- package/lib/packlets/ai-assist/registry.js +381 -13
- package/lib/packlets/ai-assist/registry.js.map +1 -0
- package/lib/packlets/ai-assist/sseParser.d.ts +45 -0
- package/lib/packlets/ai-assist/sseParser.d.ts.map +1 -0
- package/lib/packlets/ai-assist/sseParser.js +128 -0
- package/lib/packlets/ai-assist/sseParser.js.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts +72 -0
- package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/anthropic.js +379 -0
- package/lib/packlets/ai-assist/streamingAdapters/anthropic.js.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.d.ts +269 -0
- package/lib/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.d.ts.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.js +694 -0
- package/lib/packlets/ai-assist/streamingAdapters/clientToolContinuationBuilder.js.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/common.d.ts +163 -0
- package/lib/packlets/ai-assist/streamingAdapters/common.d.ts.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/common.js +193 -0
- package/lib/packlets/ai-assist/streamingAdapters/common.js.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts +43 -0
- package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/gemini.js +211 -0
- package/lib/packlets/ai-assist/streamingAdapters/gemini.js.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts +19 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js +178 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts +33 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js +393 -0
- package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/proxy.d.ts +34 -0
- package/lib/packlets/ai-assist/streamingAdapters/proxy.d.ts.map +1 -0
- package/lib/packlets/ai-assist/streamingAdapters/proxy.js +181 -0
- package/lib/packlets/ai-assist/streamingAdapters/proxy.js.map +1 -0
- package/lib/packlets/ai-assist/streamingClient.d.ts +50 -0
- package/lib/packlets/ai-assist/streamingClient.d.ts.map +1 -0
- package/lib/packlets/ai-assist/streamingClient.js +146 -0
- package/lib/packlets/ai-assist/streamingClient.js.map +1 -0
- package/lib/packlets/ai-assist/thinkingOptionsResolver.d.ts +87 -0
- package/lib/packlets/ai-assist/thinkingOptionsResolver.d.ts.map +1 -0
- package/lib/packlets/ai-assist/thinkingOptionsResolver.js +294 -0
- package/lib/packlets/ai-assist/thinkingOptionsResolver.js.map +1 -0
- package/lib/packlets/ai-assist/toolFormats.d.ts +40 -9
- package/lib/packlets/ai-assist/toolFormats.d.ts.map +1 -0
- package/lib/packlets/ai-assist/toolFormats.js +107 -10
- package/lib/packlets/ai-assist/toolFormats.js.map +1 -0
- package/lib/packlets/conversion/converters.d.ts +8 -1
- package/lib/packlets/conversion/converters.d.ts.map +1 -0
- package/lib/packlets/conversion/converters.js +36 -2
- package/lib/packlets/conversion/converters.js.map +1 -0
- package/lib/packlets/conversion/index.d.ts.map +1 -0
- package/lib/packlets/conversion/index.js.map +1 -0
- package/lib/packlets/crypto-utils/constants.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/constants.js.map +1 -0
- package/lib/packlets/crypto-utils/converters.d.ts +20 -1
- package/lib/packlets/crypto-utils/converters.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/converters.js +43 -5
- package/lib/packlets/crypto-utils/converters.js.map +1 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/directEncryptionProvider.js.map +1 -0
- package/lib/packlets/crypto-utils/encryptedFile.d.ts +25 -0
- package/lib/packlets/crypto-utils/encryptedFile.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/encryptedFile.js +38 -0
- package/lib/packlets/crypto-utils/encryptedFile.js.map +1 -0
- package/lib/packlets/crypto-utils/hpkeProvider.d.ts +150 -0
- package/lib/packlets/crypto-utils/hpkeProvider.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/hpkeProvider.js +359 -0
- package/lib/packlets/crypto-utils/hpkeProvider.js.map +1 -0
- package/lib/packlets/crypto-utils/index.browser.d.ts +5 -1
- package/lib/packlets/crypto-utils/index.browser.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/index.browser.js +28 -3
- package/lib/packlets/crypto-utils/index.browser.js.map +1 -0
- package/lib/packlets/crypto-utils/index.d.ts +5 -1
- package/lib/packlets/crypto-utils/index.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/index.js +24 -1
- package/lib/packlets/crypto-utils/index.js.map +1 -0
- package/lib/packlets/crypto-utils/keyPairAlgorithmParams.d.ts +54 -0
- package/lib/packlets/crypto-utils/keyPairAlgorithmParams.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/keyPairAlgorithmParams.js +74 -0
- package/lib/packlets/crypto-utils/keyPairAlgorithmParams.js.map +1 -0
- package/lib/packlets/crypto-utils/keystore/converters.d.ts +68 -6
- package/lib/packlets/crypto-utils/keystore/converters.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/keystore/converters.js +109 -14
- package/lib/packlets/crypto-utils/keystore/converters.js.map +1 -0
- package/lib/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.d.ts +148 -0
- package/lib/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.js +324 -0
- package/lib/packlets/crypto-utils/keystore/encryptedFilePrivateKeyStorage.js.map +1 -0
- package/lib/packlets/crypto-utils/keystore/index.browser.d.ts +10 -0
- package/lib/packlets/crypto-utils/keystore/index.browser.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/keystore/index.browser.js +76 -0
- package/lib/packlets/crypto-utils/keystore/index.browser.js.map +1 -0
- package/lib/packlets/crypto-utils/keystore/index.d.ts +2 -0
- package/lib/packlets/crypto-utils/keystore/index.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/keystore/index.js +5 -1
- package/lib/packlets/crypto-utils/keystore/index.js.map +1 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +314 -13
- package/lib/packlets/crypto-utils/keystore/keyStore.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/keystore/keyStore.js +877 -124
- package/lib/packlets/crypto-utils/keystore/keyStore.js.map +1 -0
- package/lib/packlets/crypto-utils/keystore/model.d.ts +404 -21
- package/lib/packlets/crypto-utils/keystore/model.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/keystore/model.js +37 -5
- package/lib/packlets/crypto-utils/keystore/model.js.map +1 -0
- package/lib/packlets/crypto-utils/keystore/privateKeyStorage.d.ts +53 -0
- package/lib/packlets/crypto-utils/keystore/privateKeyStorage.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/keystore/privateKeyStorage.js +22 -0
- package/lib/packlets/crypto-utils/keystore/privateKeyStorage.js.map +1 -0
- package/lib/packlets/crypto-utils/model.d.ts +518 -10
- package/lib/packlets/crypto-utils/model.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/model.js +33 -1
- package/lib/packlets/crypto-utils/model.js.map +1 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +142 -2
- package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.js +346 -0
- package/lib/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -0
- package/lib/packlets/crypto-utils/seedDerivedKeyPair.d.ts +42 -0
- package/lib/packlets/crypto-utils/seedDerivedKeyPair.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/seedDerivedKeyPair.js +123 -0
- package/lib/packlets/crypto-utils/seedDerivedKeyPair.js.map +1 -0
- package/lib/packlets/crypto-utils/spkiHelpers.d.ts +151 -0
- package/lib/packlets/crypto-utils/spkiHelpers.d.ts.map +1 -0
- package/lib/packlets/crypto-utils/spkiHelpers.js +297 -0
- package/lib/packlets/crypto-utils/spkiHelpers.js.map +1 -0
- package/lib/packlets/csv/csvFileHelpers.d.ts +0 -10
- package/lib/packlets/csv/csvFileHelpers.d.ts.map +1 -0
- package/lib/packlets/csv/csvFileHelpers.js +0 -15
- package/lib/packlets/csv/csvFileHelpers.js.map +1 -0
- package/lib/packlets/csv/csvHelpers.d.ts +10 -0
- package/lib/packlets/csv/csvHelpers.d.ts.map +1 -0
- package/lib/packlets/csv/csvHelpers.js +15 -0
- package/lib/packlets/csv/csvHelpers.js.map +1 -0
- package/lib/packlets/csv/index.browser.d.ts +0 -1
- package/lib/packlets/csv/index.browser.d.ts.map +1 -0
- package/lib/packlets/csv/index.browser.js +1 -5
- package/lib/packlets/csv/index.browser.js.map +1 -0
- package/lib/packlets/csv/index.d.ts.map +1 -0
- package/lib/packlets/csv/index.js.map +1 -0
- package/lib/packlets/experimental/extendedArray.d.ts.map +1 -0
- package/lib/packlets/experimental/extendedArray.js.map +1 -0
- package/lib/packlets/experimental/formatter.d.ts.map +1 -0
- package/lib/packlets/experimental/formatter.js.map +1 -0
- package/lib/packlets/experimental/index.d.ts.map +1 -0
- package/lib/packlets/experimental/index.js.map +1 -0
- package/lib/packlets/experimental/rangeOf.d.ts.map +1 -0
- package/lib/packlets/experimental/rangeOf.js.map +1 -0
- package/lib/packlets/hash/index.browser.d.ts.map +1 -0
- package/lib/packlets/hash/index.browser.js.map +1 -0
- package/lib/packlets/hash/index.d.ts.map +1 -0
- package/lib/packlets/hash/index.js.map +1 -0
- package/lib/packlets/hash/index.node.d.ts.map +1 -0
- package/lib/packlets/hash/index.node.js.map +1 -0
- package/lib/packlets/hash/md5Normalizer.browser.d.ts.map +1 -0
- package/lib/packlets/hash/md5Normalizer.browser.js.map +1 -0
- package/lib/packlets/hash/md5Normalizer.d.ts.map +1 -0
- package/lib/packlets/hash/md5Normalizer.js.map +1 -0
- package/lib/packlets/mustache/index.d.ts +1 -1
- package/lib/packlets/mustache/index.d.ts.map +1 -0
- package/lib/packlets/mustache/index.js.map +1 -0
- package/lib/packlets/mustache/interfaces.d.ts +34 -0
- package/lib/packlets/mustache/interfaces.d.ts.map +1 -0
- package/lib/packlets/mustache/interfaces.js.map +1 -0
- package/lib/packlets/mustache/mustacheTemplate.d.ts +2 -0
- package/lib/packlets/mustache/mustacheTemplate.d.ts.map +1 -0
- package/lib/packlets/mustache/mustacheTemplate.js +42 -4
- package/lib/packlets/mustache/mustacheTemplate.js.map +1 -0
- package/lib/packlets/record-jar/index.browser.d.ts +0 -1
- package/lib/packlets/record-jar/index.browser.d.ts.map +1 -0
- package/lib/packlets/record-jar/index.browser.js +1 -5
- package/lib/packlets/record-jar/index.browser.js.map +1 -0
- package/lib/packlets/record-jar/index.d.ts.map +1 -0
- package/lib/packlets/record-jar/index.js.map +1 -0
- package/lib/packlets/record-jar/recordJarFileHelpers.d.ts +0 -11
- package/lib/packlets/record-jar/recordJarFileHelpers.d.ts.map +1 -0
- package/lib/packlets/record-jar/recordJarFileHelpers.js +0 -19
- package/lib/packlets/record-jar/recordJarFileHelpers.js.map +1 -0
- package/lib/packlets/record-jar/recordJarHelpers.d.ts +11 -0
- package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +1 -0
- package/lib/packlets/record-jar/recordJarHelpers.js +19 -0
- package/lib/packlets/record-jar/recordJarHelpers.js.map +1 -0
- package/lib/packlets/safer-fetch/addressClassification.d.ts +144 -0
- package/lib/packlets/safer-fetch/addressClassification.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/addressClassification.js +441 -0
- package/lib/packlets/safer-fetch/addressClassification.js.map +1 -0
- package/lib/packlets/safer-fetch/addressPolicy.d.ts +113 -0
- package/lib/packlets/safer-fetch/addressPolicy.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/addressPolicy.js +123 -0
- package/lib/packlets/safer-fetch/addressPolicy.js.map +1 -0
- package/lib/packlets/safer-fetch/contentType.d.ts +51 -0
- package/lib/packlets/safer-fetch/contentType.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/contentType.js +127 -0
- package/lib/packlets/safer-fetch/contentType.js.map +1 -0
- package/lib/packlets/safer-fetch/deadline.d.ts +138 -0
- package/lib/packlets/safer-fetch/deadline.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/deadline.js +258 -0
- package/lib/packlets/safer-fetch/deadline.js.map +1 -0
- package/lib/packlets/safer-fetch/defaults.d.ts +108 -0
- package/lib/packlets/safer-fetch/defaults.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/defaults.js +134 -0
- package/lib/packlets/safer-fetch/defaults.js.map +1 -0
- package/lib/packlets/safer-fetch/failureReason.d.ts +148 -0
- package/lib/packlets/safer-fetch/failureReason.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/failureReason.js +22 -0
- package/lib/packlets/safer-fetch/failureReason.js.map +1 -0
- package/lib/packlets/safer-fetch/guards.d.ts +62 -0
- package/lib/packlets/safer-fetch/guards.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/guards.js +153 -0
- package/lib/packlets/safer-fetch/guards.js.map +1 -0
- package/lib/packlets/safer-fetch/index.browser.d.ts +33 -0
- package/lib/packlets/safer-fetch/index.browser.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/index.browser.js +82 -0
- package/lib/packlets/safer-fetch/index.browser.js.map +1 -0
- package/lib/packlets/safer-fetch/index.d.ts +27 -0
- package/lib/packlets/safer-fetch/index.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/index.js +78 -0
- package/lib/packlets/safer-fetch/index.js.map +1 -0
- package/lib/packlets/safer-fetch/model.d.ts +373 -0
- package/lib/packlets/safer-fetch/model.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/model.js +22 -0
- package/lib/packlets/safer-fetch/model.js.map +1 -0
- package/lib/packlets/safer-fetch/nodeAddressGuard.d.ts +129 -0
- package/lib/packlets/safer-fetch/nodeAddressGuard.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/nodeAddressGuard.js +196 -0
- package/lib/packlets/safer-fetch/nodeAddressGuard.js.map +1 -0
- package/lib/packlets/safer-fetch/redirect.d.ts +62 -0
- package/lib/packlets/safer-fetch/redirect.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/redirect.js +98 -0
- package/lib/packlets/safer-fetch/redirect.js.map +1 -0
- package/lib/packlets/safer-fetch/retry.d.ts +162 -0
- package/lib/packlets/safer-fetch/retry.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/retry.js +197 -0
- package/lib/packlets/safer-fetch/retry.js.map +1 -0
- package/lib/packlets/safer-fetch/saferFetch.d.ts +108 -0
- package/lib/packlets/safer-fetch/saferFetch.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/saferFetch.js +760 -0
- package/lib/packlets/safer-fetch/saferFetch.js.map +1 -0
- package/lib/packlets/safer-fetch/transport.d.ts +18 -0
- package/lib/packlets/safer-fetch/transport.d.ts.map +1 -0
- package/lib/packlets/safer-fetch/transport.js +53 -0
- package/lib/packlets/safer-fetch/transport.js.map +1 -0
- package/lib/packlets/yaml/converters.d.ts.map +1 -0
- package/lib/packlets/yaml/converters.js.map +1 -0
- package/lib/packlets/yaml/index.d.ts +1 -0
- package/lib/packlets/yaml/index.d.ts.map +1 -0
- package/lib/packlets/yaml/index.js +1 -0
- package/lib/packlets/yaml/index.js.map +1 -0
- package/lib/packlets/yaml/serializers.d.ts +45 -0
- package/lib/packlets/yaml/serializers.d.ts.map +1 -0
- package/lib/packlets/yaml/serializers.js +84 -0
- package/lib/packlets/yaml/serializers.js.map +1 -0
- package/lib/packlets/zip-file-tree/index.d.ts.map +1 -0
- package/lib/packlets/zip-file-tree/index.js.map +1 -0
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +84 -8
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +99 -9
- package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js.map +1 -0
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts +26 -1
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts.map +1 -0
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.js +17 -1
- package/lib/packlets/zip-file-tree/zipFileTreeWriter.js.map +1 -0
- package/package.json +30 -15
- package/lib/packlets/ai-assist/apiClient.d.ts +0 -60
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { JsonValue } from '@fgv/ts-json-base';
|
|
2
|
-
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { Brand, Result, Uuid } from '@fgv/ts-utils';
|
|
3
3
|
import * as Constants from './constants';
|
|
4
4
|
export { Constants };
|
|
5
|
+
/**
|
|
6
|
+
* A multibase base64url-encoded SPKI (SubjectPublicKeyInfo) public key string —
|
|
7
|
+
* a `'m'` multibase prefix followed by a base64url-no-pad body. Produced by
|
|
8
|
+
* {@link CryptoUtils.exportPublicKeyAsMultibaseSpki} and consumed by
|
|
9
|
+
* {@link CryptoUtils.importPublicKeyFromMultibaseSpki}. Obtain the brand at a
|
|
10
|
+
* boundary via {@link CryptoUtils.isValidMultibaseSpkiPublicKey} or the
|
|
11
|
+
* {@link CryptoUtils.Converters.multibaseSpkiPublicKey} converter.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export type MultibaseSpkiPublicKey = Brand<string, 'MultibaseSpkiPublicKey'>;
|
|
5
15
|
/**
|
|
6
16
|
* Supported encryption algorithms.
|
|
7
17
|
* @public
|
|
@@ -45,28 +55,269 @@ export interface IEncryptionResult {
|
|
|
45
55
|
readonly encryptedData: Uint8Array;
|
|
46
56
|
}
|
|
47
57
|
/**
|
|
48
|
-
*
|
|
58
|
+
* Result of a raw-byte AES-256-GCM encryption via
|
|
59
|
+
* {@link CryptoUtils.ICryptoProvider.encryptBytes | encryptBytes}. The
|
|
60
|
+
* authentication tag is returned separately from the ciphertext, mirroring the
|
|
61
|
+
* separated-tag convention of {@link CryptoUtils.IEncryptionResult}. The exact
|
|
62
|
+
* byte layout is:
|
|
63
|
+
* - `ciphertext`: the AES-GCM ciphertext, byte-for-byte the same length as the
|
|
64
|
+
* input plaintext (GCM is a stream cipher — no padding). Empty plaintext
|
|
65
|
+
* yields an empty `ciphertext`.
|
|
66
|
+
* - `authTag`: the 16-byte (128-bit) GCM authentication tag, computed over the
|
|
67
|
+
* ciphertext, the nonce, and any `aad`.
|
|
68
|
+
*
|
|
69
|
+
* The caller persists both fields alongside the (caller-owned) nonce and feeds
|
|
70
|
+
* them back to {@link CryptoUtils.ICryptoProvider.decryptBytes | decryptBytes}.
|
|
49
71
|
* @public
|
|
50
72
|
*/
|
|
51
|
-
export
|
|
73
|
+
export interface IEncryptBytesResult {
|
|
74
|
+
/**
|
|
75
|
+
* The AES-256-GCM ciphertext. Same length as the input plaintext (no tag
|
|
76
|
+
* appended — the tag is carried separately in the `authTag` field).
|
|
77
|
+
*/
|
|
78
|
+
readonly ciphertext: Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* The 16-byte (128-bit) GCM authentication tag.
|
|
81
|
+
*/
|
|
82
|
+
readonly authTag: Uint8Array;
|
|
83
|
+
}
|
|
52
84
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
85
|
+
* Asymmetric keypair algorithms supported by the crypto provider.
|
|
86
|
+
* - `'ecdsa-p256'`: ECDSA over the P-256 curve, for signing.
|
|
87
|
+
* - `'rsa-oaep-2048'`: RSA-OAEP, 2048-bit modulus with SHA-256, for encryption.
|
|
88
|
+
* - `'ecdh-p256'`: ECDH over the P-256 curve, for key agreement
|
|
89
|
+
* (e.g. as the recipient keypair in
|
|
90
|
+
* {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes} /
|
|
91
|
+
* {@link CryptoUtils.ICryptoProvider.unwrapBytes | unwrapBytes}).
|
|
92
|
+
* - `'ed25519'`: EdDSA over the Edwards25519 curve, for signing.
|
|
93
|
+
* Deterministic — the per-signature nonce is derived from the private key
|
|
94
|
+
* and message rather than sampled randomly, eliminating the random-nonce
|
|
95
|
+
* reuse risk that ECDSA carries. Distinct from X25519 (key agreement over
|
|
96
|
+
* the Montgomery form, Curve25519).
|
|
97
|
+
* - `'x25519'`: Diffie-Hellman key agreement over the Montgomery form of
|
|
98
|
+
* Curve25519. Key-agreement only — use `deriveBits`/`deriveKey` to produce
|
|
99
|
+
* a shared secret from one party's private key and the peer's public key.
|
|
100
|
+
* Distinct from Ed25519 (which uses the twisted-Edwards form for signing).
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
export type KeyPairAlgorithm = 'ecdsa-p256' | 'rsa-oaep-2048' | 'ecdh-p256' | 'ed25519' | 'x25519';
|
|
104
|
+
/**
|
|
105
|
+
* The subset of {@link CryptoUtils.KeyPairAlgorithm} whose keypair can be
|
|
106
|
+
* derived *deterministically* from a fixed secret seed, for use with
|
|
107
|
+
* {@link CryptoUtils.ICryptoProvider.importKeyPairFromSeed | importKeyPairFromSeed}.
|
|
108
|
+
*
|
|
109
|
+
* Two algorithms are supported, both of whose 32-byte private scalar *is* the
|
|
110
|
+
* seed and whose public key is a deterministic function of it, so the same seed
|
|
111
|
+
* always yields the same keypair on every runtime:
|
|
112
|
+
* - `'ed25519'` — signing keypair (RFC 8032). Private usage `'sign'`, public
|
|
113
|
+
* usage `'verify'`.
|
|
114
|
+
* - `'x25519'` — Diffie-Hellman key-agreement keypair (RFC 7748), the recipient
|
|
115
|
+
* keypair consumed by {@link CryptoUtils.HpkeProvider}. Private usage
|
|
116
|
+
* `'deriveBits'`, public key imported with no usages. Deriving a fixed X25519
|
|
117
|
+
* recipient keypair from a checked-in seed is what makes a deterministic HPKE
|
|
118
|
+
* seal/open round-trip vector possible.
|
|
119
|
+
*
|
|
120
|
+
* The type is a proper subset of {@link CryptoUtils.KeyPairAlgorithm} because
|
|
121
|
+
* algorithms like RSA or the NIST curves are not recoverable from a bare seed.
|
|
55
122
|
* @public
|
|
56
123
|
*/
|
|
57
|
-
export
|
|
124
|
+
export type SeedDerivableAlgorithm = 'ed25519' | 'x25519';
|
|
125
|
+
/**
|
|
126
|
+
* Caller-supplied HKDF parameters that domain-separate one
|
|
127
|
+
* {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes} call from another.
|
|
128
|
+
* Two wraps that share recipient but differ on `salt` or `info` derive distinct
|
|
129
|
+
* wrap keys, so callers should pick values that bind the wrap to its
|
|
130
|
+
* application context (e.g. a content hash for `salt` and a secret name for
|
|
131
|
+
* `info`).
|
|
132
|
+
*
|
|
133
|
+
* Both fields are required; pass an empty `Uint8Array` if the caller has no
|
|
134
|
+
* value to bind on a given axis. Silent defaulting would hide protocol
|
|
135
|
+
* mistakes, so the API does not pick defaults.
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
export interface IWrapBytesOptions {
|
|
58
139
|
/**
|
|
59
|
-
*
|
|
140
|
+
* HKDF salt. Domain-separates this wrap from others in different contexts.
|
|
141
|
+
* Caller picks; common choices include a content hash, document id, channel
|
|
142
|
+
* id, etc.
|
|
60
143
|
*/
|
|
61
|
-
readonly
|
|
144
|
+
readonly salt: Uint8Array;
|
|
62
145
|
/**
|
|
63
|
-
*
|
|
146
|
+
* HKDF info. Further binds the derived key to a specific use within the
|
|
147
|
+
* calling application. Caller picks; common choices include a secret name,
|
|
148
|
+
* message type, or version tag.
|
|
64
149
|
*/
|
|
150
|
+
readonly info: Uint8Array;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Output of {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes}. The
|
|
154
|
+
* shape is JSON-serializable so it can travel directly over the wire or be
|
|
155
|
+
* persisted as-is.
|
|
156
|
+
* @public
|
|
157
|
+
*/
|
|
158
|
+
export interface IWrappedBytes {
|
|
159
|
+
/**
|
|
160
|
+
* Sender's ephemeral ECDH P-256 public key as a JSON Web Key. The matching
|
|
161
|
+
* ephemeral private key is dropped after the shared-secret derive.
|
|
162
|
+
*/
|
|
163
|
+
readonly ephemeralPublicKey: JsonWebKey;
|
|
164
|
+
/**
|
|
165
|
+
* AES-GCM nonce, base64-encoded. 12 bytes (96 bits) — the standard AES-GCM
|
|
166
|
+
* nonce length.
|
|
167
|
+
*/
|
|
168
|
+
readonly nonce: string;
|
|
169
|
+
/**
|
|
170
|
+
* AES-GCM ciphertext concatenated with the 16-byte authentication tag,
|
|
171
|
+
* base64-encoded. Tampering with either the nonce or the ciphertext causes
|
|
172
|
+
* unwrap to fail GCM authentication.
|
|
173
|
+
*/
|
|
174
|
+
readonly ciphertext: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* All valid key pair algorithms.
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
180
|
+
export declare const allKeyPairAlgorithms: ReadonlyArray<KeyPairAlgorithm>;
|
|
181
|
+
/**
|
|
182
|
+
* Supported key derivation functions.
|
|
183
|
+
* @public
|
|
184
|
+
*/
|
|
185
|
+
export type KeyDerivationFunction = 'pbkdf2' | 'argon2id';
|
|
186
|
+
/**
|
|
187
|
+
* PBKDF2 key derivation parameters.
|
|
188
|
+
* @public
|
|
189
|
+
*/
|
|
190
|
+
export interface IPbkdf2KeyDerivationParams {
|
|
191
|
+
/** Key derivation function discriminator. */
|
|
192
|
+
readonly kdf: 'pbkdf2';
|
|
193
|
+
/** Base64-encoded salt used for key derivation. */
|
|
65
194
|
readonly salt: string;
|
|
195
|
+
/** Number of iterations used for key derivation. */
|
|
196
|
+
readonly iterations: number;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Argon2id key derivation parameters (RFC 9106).
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
export interface IArgon2idKeyDerivationParams {
|
|
203
|
+
/** Key derivation function discriminator. */
|
|
204
|
+
readonly kdf: 'argon2id';
|
|
205
|
+
/** Base64-encoded salt used for key derivation. */
|
|
206
|
+
readonly salt: string;
|
|
207
|
+
/** Memory cost in kibibytes. */
|
|
208
|
+
readonly memoryKiB: number;
|
|
209
|
+
/** Number of passes (time cost). */
|
|
210
|
+
readonly iterations: number;
|
|
211
|
+
/** Degree of parallelism. */
|
|
212
|
+
readonly parallelism: number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Key derivation parameters stored in encrypted files.
|
|
216
|
+
* Discriminated union on `kdf` field: `'pbkdf2'` or `'argon2id'`.
|
|
217
|
+
* @public
|
|
218
|
+
*/
|
|
219
|
+
export type IKeyDerivationParams = IPbkdf2KeyDerivationParams | IArgon2idKeyDerivationParams;
|
|
220
|
+
/**
|
|
221
|
+
* Parameters for Argon2id key derivation (RFC 9106).
|
|
222
|
+
* All fields are required; fgv does not pick defaults silently.
|
|
223
|
+
* @public
|
|
224
|
+
*/
|
|
225
|
+
export interface IArgon2idParams {
|
|
226
|
+
/**
|
|
227
|
+
* Memory cost in kibibytes (KiB).
|
|
228
|
+
* OWASP 2023 minimum: 19456 (19 MiB). Stronger: 65536 (64 MiB).
|
|
229
|
+
* Constraint: \>= 8.
|
|
230
|
+
*/
|
|
231
|
+
readonly memoryKiB: number;
|
|
66
232
|
/**
|
|
67
|
-
* Number of iterations
|
|
233
|
+
* Number of passes (iterations / time cost).
|
|
234
|
+
* OWASP 2023 minimum: 2. Range: \>= 1.
|
|
68
235
|
*/
|
|
69
236
|
readonly iterations: number;
|
|
237
|
+
/**
|
|
238
|
+
* Degree of parallelism (threads).
|
|
239
|
+
* Note: WASM-based implementations compute sequentially regardless of this value,
|
|
240
|
+
* but the value is wired into the algorithm and AFFECTS the output hash bytes.
|
|
241
|
+
* Callers must use the same parallelism value consistently for a given secret.
|
|
242
|
+
* Range: 1–255.
|
|
243
|
+
*/
|
|
244
|
+
readonly parallelism: number;
|
|
245
|
+
/**
|
|
246
|
+
* Number of output bytes (hash length).
|
|
247
|
+
* Typical values: 16 (128-bit), 32 (256-bit, AES-256 key), 64 (512-bit).
|
|
248
|
+
* Constraint: \>= 4.
|
|
249
|
+
*/
|
|
250
|
+
readonly outputBytes: number;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Recommended OWASP 2023 minimum Argon2id parameters.
|
|
254
|
+
* Suitable for recovery-row key derivation (high-entropy inputs).
|
|
255
|
+
* @public
|
|
256
|
+
*/
|
|
257
|
+
export declare const ARGON2ID_OWASP_MIN: IArgon2idParams;
|
|
258
|
+
/**
|
|
259
|
+
* Stronger Argon2id parameters suitable for user-typed passphrases.
|
|
260
|
+
* @public
|
|
261
|
+
*/
|
|
262
|
+
export declare const ARGON2ID_PASSPHRASE: IArgon2idParams;
|
|
263
|
+
/**
|
|
264
|
+
* Optional keyed-hashing inputs for {@link CryptoUtils.IArgon2idProvider.argon2id | argon2id}
|
|
265
|
+
* (RFC 9106 §3.1). These are distinct from the cost parameters in
|
|
266
|
+
* {@link CryptoUtils.IArgon2idParams} — they change the derived output but are
|
|
267
|
+
* not tuning knobs. Both fields are optional; omitting a field (or passing an
|
|
268
|
+
* empty `Uint8Array`) is a no-op that leaves the output byte-identical to a call
|
|
269
|
+
* with no options at all.
|
|
270
|
+
* @public
|
|
271
|
+
*/
|
|
272
|
+
export interface IArgon2idKeyingOptions {
|
|
273
|
+
/**
|
|
274
|
+
* Optional secret key K (RFC 9106 keyed hashing, sometimes called a "pepper").
|
|
275
|
+
* When present and non-empty it is mixed into the hash so that the derived
|
|
276
|
+
* output cannot be reproduced without also knowing K. Empty or omitted means
|
|
277
|
+
* no secret. Honored by both the Node and browser backends.
|
|
278
|
+
*/
|
|
279
|
+
readonly secret?: Uint8Array;
|
|
280
|
+
/**
|
|
281
|
+
* Optional associated data X (RFC 9106 §3.1). When present and non-empty it is
|
|
282
|
+
* mixed into the hash. **Node-only:** the WASM (`hash-wasm`) browser backend
|
|
283
|
+
* has no associated-data input, so `BrowserArgon2Provider` fails loudly rather
|
|
284
|
+
* than silently dropping it (which would produce wrong bytes). Empty or omitted
|
|
285
|
+
* means no associated data and is accepted by both backends.
|
|
286
|
+
*/
|
|
287
|
+
readonly associatedData?: Uint8Array;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Argon2id key derivation provider (RFC 9106).
|
|
291
|
+
*
|
|
292
|
+
* Implementations are in separate packages to avoid WASM bundle costs for
|
|
293
|
+
* consumers who don't need Argon2id:
|
|
294
|
+
* - Node: `@fgv/ts-extras-argon2` (`NodeArgon2Provider`)
|
|
295
|
+
* - Browser: `@fgv/ts-web-extras-argon2` (`BrowserArgon2Provider`)
|
|
296
|
+
*
|
|
297
|
+
* @public
|
|
298
|
+
*/
|
|
299
|
+
export interface IArgon2idProvider {
|
|
300
|
+
/**
|
|
301
|
+
* Derives key material from a password using Argon2id (RFC 9106 §3.1).
|
|
302
|
+
*
|
|
303
|
+
* Returns the raw derived bytes as a `Uint8Array`. For the same inputs that
|
|
304
|
+
* both backends support, the Node and browser implementations produce
|
|
305
|
+
* byte-identical output. The optional `associatedData` in
|
|
306
|
+
* {@link CryptoUtils.IArgon2idKeyingOptions} is the one exception: it is
|
|
307
|
+
* Node-only (the browser WASM backend has no associated-data input), so a call
|
|
308
|
+
* that supplies non-empty `associatedData` is not portable to the browser
|
|
309
|
+
* backend. Every input the browser backend *does* support (including the
|
|
310
|
+
* optional `secret`) is byte-identical across the two.
|
|
311
|
+
*
|
|
312
|
+
* @param password - Password or passphrase. Accepts string (UTF-8) or raw bytes.
|
|
313
|
+
* @param salt - Salt bytes. Must be random and unique per credential (\>= 16 bytes recommended).
|
|
314
|
+
* @param params - Argon2id parameters. Use `ARGON2ID_OWASP_MIN` as a starting point.
|
|
315
|
+
* @param options - Optional {@link CryptoUtils.IArgon2idKeyingOptions | keyed-hashing inputs}
|
|
316
|
+
* (secret K and/or associated data X). Omitting them (the default) leaves the
|
|
317
|
+
* output byte-identical to prior behavior.
|
|
318
|
+
* @returns Success with derived bytes, Failure with error context.
|
|
319
|
+
*/
|
|
320
|
+
argon2id(password: Uint8Array | string, salt: Uint8Array, params: IArgon2idParams, options?: IArgon2idKeyingOptions): Promise<Result<Uint8Array>>;
|
|
70
321
|
}
|
|
71
322
|
/**
|
|
72
323
|
* Generic encrypted file format.
|
|
@@ -132,6 +383,68 @@ export interface ICryptoProvider {
|
|
|
132
383
|
* @returns Success with decrypted UTF-8 string, or Failure with error
|
|
133
384
|
*/
|
|
134
385
|
decrypt(encryptedData: Uint8Array, key: Uint8Array, iv: Uint8Array, authTag: Uint8Array): Promise<Result<string>>;
|
|
386
|
+
/**
|
|
387
|
+
* Encrypts raw bytes using AES-256-GCM with a **caller-supplied nonce** and
|
|
388
|
+
* optional additional authenticated data (AAD).
|
|
389
|
+
*
|
|
390
|
+
* This is the raw-byte sibling of {@link CryptoUtils.ICryptoProvider.encrypt | encrypt}.
|
|
391
|
+
* Unlike `encrypt`, it takes and returns `Uint8Array` (no UTF-8 coding), the
|
|
392
|
+
* caller owns the nonce (rather than the provider generating one), and it
|
|
393
|
+
* binds optional `aad` into the GCM authentication. Use it when you need to
|
|
394
|
+
* bind context (e.g. an actor id, key version, or row kind) into the
|
|
395
|
+
* authentication so a wrapped secret cannot be replayed across
|
|
396
|
+
* users/versions/kinds, or when you manage nonces yourself.
|
|
397
|
+
*
|
|
398
|
+
* @remarks
|
|
399
|
+
* **⚠️ NONCE UNIQUENESS IS THE CALLER'S RESPONSIBILITY AND IS CRITICAL.**
|
|
400
|
+
* Because the caller supplies the nonce, this primitive cannot guarantee
|
|
401
|
+
* uniqueness. Reusing a `(key, nonce)` pair for two different messages is
|
|
402
|
+
* **catastrophic** for AES-GCM: it breaks confidentiality (the XOR of the two
|
|
403
|
+
* plaintexts leaks) AND authentication (the GCM authentication key can be
|
|
404
|
+
* recovered, letting an attacker forge tags for arbitrary messages under that
|
|
405
|
+
* key). The caller MUST use a unique nonce for every message encrypted under a
|
|
406
|
+
* given key — draw it from {@link CryptoUtils.ICryptoProvider.generateRandomBytes | generateRandomBytes(12)}
|
|
407
|
+
* (12 random bytes has negligible collision probability well within a single
|
|
408
|
+
* key's message budget) or from a strictly-increasing counter. Never hardcode
|
|
409
|
+
* a nonce and never reuse one.
|
|
410
|
+
*
|
|
411
|
+
* @param key - 32-byte AES-256 key. Wrong lengths fail with error context.
|
|
412
|
+
* @param nonce - 12-byte (96-bit) GCM nonce. MUST be unique per message under
|
|
413
|
+
* `key` (see the nonce-uniqueness warning above). Wrong lengths fail with
|
|
414
|
+
* error context.
|
|
415
|
+
* @param plaintext - The bytes to encrypt. Empty plaintext is permitted and
|
|
416
|
+
* round-trips (GCM produces a valid tag over zero-length plaintext).
|
|
417
|
+
* @param aad - Optional additional authenticated data bound into the GCM tag
|
|
418
|
+
* but NOT encrypted. If provided at encrypt time, the identical bytes must be
|
|
419
|
+
* supplied to `decryptBytes` or decryption fails authentication. Absent means
|
|
420
|
+
* no AAD.
|
|
421
|
+
* @returns `Success` with the {@link CryptoUtils.IEncryptBytesResult | ciphertext and 16-byte auth tag},
|
|
422
|
+
* or `Failure` with error context.
|
|
423
|
+
*/
|
|
424
|
+
encryptBytes(key: Uint8Array, nonce: Uint8Array, plaintext: Uint8Array, aad?: Uint8Array): Promise<Result<IEncryptBytesResult>>;
|
|
425
|
+
/**
|
|
426
|
+
* Decrypts raw bytes produced by
|
|
427
|
+
* {@link CryptoUtils.ICryptoProvider.encryptBytes | encryptBytes} using
|
|
428
|
+
* AES-256-GCM. The inverse of `encryptBytes`: the `ciphertext` and `authTag`
|
|
429
|
+
* from an `encryptBytes` result, together with the same `key`, `nonce`, and
|
|
430
|
+
* `aad`, recover the original plaintext.
|
|
431
|
+
*
|
|
432
|
+
* Fails (never throws) on any authentication failure: a tampered ciphertext
|
|
433
|
+
* or tag, the wrong key or nonce, or an `aad` that differs from the one used
|
|
434
|
+
* at encrypt time. AES-GCM authentication is fail-closed — a mismatched `aad`
|
|
435
|
+
* fails exactly as a tampered ciphertext does.
|
|
436
|
+
*
|
|
437
|
+
* @param key - 32-byte AES-256 key (the same key used to encrypt).
|
|
438
|
+
* @param nonce - 12-byte (96-bit) GCM nonce (the same nonce used to encrypt).
|
|
439
|
+
* @param ciphertext - The ciphertext from the `encryptBytes` result.
|
|
440
|
+
* @param authTag - The 16-byte (128-bit) GCM authentication tag from the
|
|
441
|
+
* `encryptBytes` result.
|
|
442
|
+
* @param aad - The identical additional authenticated data supplied at encrypt
|
|
443
|
+
* time (or absent if none was supplied). A mismatch fails authentication.
|
|
444
|
+
* @returns `Success` with the decrypted plaintext bytes, or `Failure` with
|
|
445
|
+
* error context (including all authentication failures).
|
|
446
|
+
*/
|
|
447
|
+
decryptBytes(key: Uint8Array, nonce: Uint8Array, ciphertext: Uint8Array, authTag: Uint8Array, aad?: Uint8Array): Promise<Result<Uint8Array>>;
|
|
135
448
|
/**
|
|
136
449
|
* Generates a random 32-byte key suitable for AES-256.
|
|
137
450
|
* @returns Success with generated key, or Failure with error
|
|
@@ -145,12 +458,27 @@ export interface ICryptoProvider {
|
|
|
145
458
|
* @returns Success with derived 32-byte key, or Failure with error
|
|
146
459
|
*/
|
|
147
460
|
deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
|
|
461
|
+
/**
|
|
462
|
+
* Computes a SHA-256 hash of the given data.
|
|
463
|
+
* @param data - UTF-8 string to hash
|
|
464
|
+
* @returns Success with hex-encoded hash string, or Failure with error
|
|
465
|
+
*/
|
|
466
|
+
sha256(data: string): Promise<Result<string>>;
|
|
148
467
|
/**
|
|
149
468
|
* Generates cryptographically secure random bytes.
|
|
150
469
|
* @param length - Number of bytes to generate
|
|
151
470
|
* @returns Success with random bytes, or Failure with error
|
|
152
471
|
*/
|
|
153
472
|
generateRandomBytes(length: number): Result<Uint8Array>;
|
|
473
|
+
/**
|
|
474
|
+
* Generates a cryptographically random UUIDv4 using the provider's
|
|
475
|
+
* underlying source of randomness. The default Node and browser
|
|
476
|
+
* implementations delegate to `globalThis.crypto.randomUUID`;
|
|
477
|
+
* deterministic providers (e.g. test stubs) may override to produce
|
|
478
|
+
* reproducible values.
|
|
479
|
+
* @returns Success with a canonical UUID, or Failure with error.
|
|
480
|
+
*/
|
|
481
|
+
generateUuid(): Result<Uuid>;
|
|
154
482
|
/**
|
|
155
483
|
* Encodes binary data to base64 string.
|
|
156
484
|
* @param data - Binary data to encode
|
|
@@ -163,6 +491,186 @@ export interface ICryptoProvider {
|
|
|
163
491
|
* @returns Success with decoded bytes, or Failure if invalid base64
|
|
164
492
|
*/
|
|
165
493
|
fromBase64(base64: string): Result<Uint8Array>;
|
|
494
|
+
/**
|
|
495
|
+
* Generates a new asymmetric keypair for the requested algorithm.
|
|
496
|
+
* @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} to use.
|
|
497
|
+
* @param extractable - Whether the resulting `CryptoKey` objects may be exported.
|
|
498
|
+
* Set `false` on backends that store `CryptoKey` references directly (e.g.
|
|
499
|
+
* IndexedDB). Set `true` when the private key must round-trip through JWK or
|
|
500
|
+
* PKCS#8 (e.g. encrypted-file backends).
|
|
501
|
+
* @returns Success with the generated `CryptoKeyPair`, or Failure with error context.
|
|
502
|
+
*/
|
|
503
|
+
generateKeyPair(algorithm: KeyPairAlgorithm, extractable: boolean): Promise<Result<CryptoKeyPair>>;
|
|
504
|
+
/**
|
|
505
|
+
* Derives an asymmetric keypair *deterministically* from a fixed secret seed.
|
|
506
|
+
* The same `seed` always yields the same keypair on every runtime, so this is
|
|
507
|
+
* the primitive to use when a keypair must be reconstructable from stored seed
|
|
508
|
+
* material (key escrow, HD-style derivation, deterministic test vectors) rather
|
|
509
|
+
* than freshly sampled by {@link CryptoUtils.ICryptoProvider.generateKeyPair | generateKeyPair}.
|
|
510
|
+
*
|
|
511
|
+
* For both `'ed25519'` and `'x25519'` the private key *is* its 32-byte seed and
|
|
512
|
+
* the public key is a deterministic function of that seed (RFC 8032 / RFC 7748),
|
|
513
|
+
* so the returned public key is recovered even when the caller requests a
|
|
514
|
+
* non-extractable private key. The transient extractable key used internally to
|
|
515
|
+
* recover the public half is never returned or logged when `extractable` is
|
|
516
|
+
* `false`. The returned keys carry the algorithm's usages: `'ed25519'` →
|
|
517
|
+
* private `'sign'` / public `'verify'`; `'x25519'` → private `'deriveBits'` /
|
|
518
|
+
* public no-usage (ready to hand to {@link CryptoUtils.HpkeProvider}).
|
|
519
|
+
* @param algorithm - The {@link CryptoUtils.SeedDerivableAlgorithm | seed-derivable algorithm}
|
|
520
|
+
* (`'ed25519'` or `'x25519'`); any other value fails loudly with context.
|
|
521
|
+
* @param seed - The secret seed. It must be exactly 32 bytes for both supported
|
|
522
|
+
* algorithms; any other length fails loudly, before any WebCrypto call. The
|
|
523
|
+
* bytes are copied, not retained or mutated.
|
|
524
|
+
* @param extractable - Whether the returned private key may be exported. The
|
|
525
|
+
* returned public key is identical for a given seed regardless of this flag.
|
|
526
|
+
* @returns Success with the derived `CryptoKeyPair`, or Failure with error context.
|
|
527
|
+
*/
|
|
528
|
+
importKeyPairFromSeed(algorithm: SeedDerivableAlgorithm, seed: Uint8Array, extractable: boolean): Promise<Result<CryptoKeyPair>>;
|
|
529
|
+
/**
|
|
530
|
+
* Exports the public half of a keypair as a JSON Web Key.
|
|
531
|
+
* @param publicKey - The public `CryptoKey` to export. Must be an `extractable`
|
|
532
|
+
* key generated for an asymmetric algorithm.
|
|
533
|
+
* @returns Success with the JWK, or Failure with error context.
|
|
534
|
+
*/
|
|
535
|
+
exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>>;
|
|
536
|
+
/**
|
|
537
|
+
* Re-imports a public-key JWK as a `CryptoKey` usable for verification or
|
|
538
|
+
* encryption (depending on algorithm).
|
|
539
|
+
* @param jwk - The JSON Web Key produced by {@link CryptoUtils.ICryptoProvider.exportPublicKeyJwk | exportPublicKeyJwk}.
|
|
540
|
+
* @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} the
|
|
541
|
+
* key was generated for. Determines the import parameters and key usages.
|
|
542
|
+
* @returns Success with the imported public `CryptoKey`, or Failure with error context.
|
|
543
|
+
*/
|
|
544
|
+
importPublicKeyJwk(jwk: JsonWebKey, algorithm: KeyPairAlgorithm): Promise<Result<CryptoKey>>;
|
|
545
|
+
/**
|
|
546
|
+
* Exports a public `CryptoKey` as a DER-encoded SPKI (SubjectPublicKeyInfo) blob.
|
|
547
|
+
* SPKI is the standard algorithm-agnostic format for public key storage and transport.
|
|
548
|
+
* @param publicKey - The `CryptoKey` to export. Must have `key.type === 'public'`.
|
|
549
|
+
* @returns `Success` with the raw SPKI bytes, or `Failure` with error context.
|
|
550
|
+
*/
|
|
551
|
+
exportPublicKeySpki(publicKey: CryptoKey): Promise<Result<Uint8Array>>;
|
|
552
|
+
/**
|
|
553
|
+
* Imports a public key from a DER-encoded SPKI blob.
|
|
554
|
+
* @param spkiBytes - The raw SPKI bytes produced by {@link CryptoUtils.ICryptoProvider.exportPublicKeySpki | exportPublicKeySpki}.
|
|
555
|
+
* @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} the key was generated for.
|
|
556
|
+
* @returns `Success` with the imported public `CryptoKey`, or `Failure` with error context.
|
|
557
|
+
*/
|
|
558
|
+
importPublicKeySpki(spkiBytes: Uint8Array, algorithm: KeyPairAlgorithm): Promise<Result<CryptoKey>>;
|
|
559
|
+
/**
|
|
560
|
+
* Wraps `plaintext` for delivery to the holder of the private key paired
|
|
561
|
+
* with `recipientPublicKey`. Uses ECIES with ECDH P-256, HKDF-SHA256, and
|
|
562
|
+
* AES-GCM-256.
|
|
563
|
+
*
|
|
564
|
+
* Generates a fresh ephemeral keypair per call; the ephemeral private key
|
|
565
|
+
* is discarded after the shared-secret derive. Only the recipient (with the
|
|
566
|
+
* matching private key) and the same HKDF parameters can recover
|
|
567
|
+
* `plaintext`.
|
|
568
|
+
*
|
|
569
|
+
* Empty `plaintext` is permitted; the resulting wrap contains only the
|
|
570
|
+
* 16-byte GCM authentication tag and round-trips back to an empty
|
|
571
|
+
* `Uint8Array`.
|
|
572
|
+
* @param plaintext - The bytes to wrap. Any length supported by AES-GCM
|
|
573
|
+
* (in practice, well below 2^39 - 256 bits).
|
|
574
|
+
* @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
|
|
575
|
+
* Must have algorithm name `'ECDH'` and named curve `'P-256'`; mismatched
|
|
576
|
+
* algorithm or curve yields a `Failure` with error context.
|
|
577
|
+
* @param options - HKDF parameters; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
|
|
578
|
+
* @returns `Success` with the wrapped payload, or `Failure` with error context.
|
|
579
|
+
*/
|
|
580
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<IWrappedBytes>>;
|
|
581
|
+
/**
|
|
582
|
+
* Inverse of {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes}.
|
|
583
|
+
* Recovers the original `plaintext` from a wrapped payload using the
|
|
584
|
+
* recipient's private key.
|
|
585
|
+
*
|
|
586
|
+
* Returns a `Failure` (never throws) on any of:
|
|
587
|
+
* - Tampered nonce or ciphertext (AES-GCM authentication fails)
|
|
588
|
+
* - Wrong private key (different shared secret derives a different wrap key)
|
|
589
|
+
* - Wrong HKDF parameters (different wrap key)
|
|
590
|
+
* - Malformed `ephemeralPublicKey` JWK
|
|
591
|
+
* - Malformed base64 in `nonce` or `ciphertext`
|
|
592
|
+
* @param wrapped - The wrapped payload produced by `wrapBytes`.
|
|
593
|
+
* @param recipientPrivateKey - The recipient's ECDH P-256 private
|
|
594
|
+
* `CryptoKey`. Must have algorithm name `'ECDH'` and named curve `'P-256'`,
|
|
595
|
+
* and key usages including `'deriveKey'` or `'deriveBits'`.
|
|
596
|
+
* @param options - The same HKDF parameters used at wrap time.
|
|
597
|
+
* @returns `Success` with the original `plaintext`, or `Failure` with error context.
|
|
598
|
+
*/
|
|
599
|
+
unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array>>;
|
|
600
|
+
/**
|
|
601
|
+
* Signs `data` with `privateKey` using the algorithm inferred from the key.
|
|
602
|
+
* Delegates to `crypto.subtle.sign`; the algorithm is derived from
|
|
603
|
+
* `privateKey.algorithm.name` — ECDSA keys are augmented with
|
|
604
|
+
* `hash: 'SHA-256'` at sign time (the hash is not stored in the key);
|
|
605
|
+
* all other algorithm names are passed through as-is.
|
|
606
|
+
* Intended for Ed25519 and ECDSA-P256 asymmetric private keys; for
|
|
607
|
+
* HMAC-SHA256 authentication codes use {@link ICryptoProvider.hmacSha256} instead.
|
|
608
|
+
* @param privateKey - A `CryptoKey` with `'sign'` usage (e.g. generated by
|
|
609
|
+
* {@link CryptoUtils.ICryptoProvider.generateKeyPair | generateKeyPair} with
|
|
610
|
+
* `'ecdsa-p256'` or `'ed25519'`).
|
|
611
|
+
* @param data - The bytes to sign.
|
|
612
|
+
* @returns `Success` with the raw signature bytes, or `Failure` with error context.
|
|
613
|
+
*/
|
|
614
|
+
sign(privateKey: CryptoKey, data: Uint8Array): Promise<Result<Uint8Array>>;
|
|
615
|
+
/**
|
|
616
|
+
* Verifies a signature produced by {@link ICryptoProvider.sign}.
|
|
617
|
+
* Delegates to `crypto.subtle.verify`; the algorithm is derived from
|
|
618
|
+
* `publicKey.algorithm.name` — ECDSA keys are augmented with
|
|
619
|
+
* `hash: 'SHA-256'`; all other algorithm names are passed through as-is.
|
|
620
|
+
* Intended for Ed25519 and ECDSA-P256 asymmetric public keys; for
|
|
621
|
+
* HMAC-SHA256 verification use {@link ICryptoProvider.verifyHmacSha256} instead.
|
|
622
|
+
* @param publicKey - A `CryptoKey` with `'verify'` usage (e.g. the public
|
|
623
|
+
* half of a keypair generated by
|
|
624
|
+
* {@link CryptoUtils.ICryptoProvider.generateKeyPair | generateKeyPair} with
|
|
625
|
+
* `'ecdsa-p256'` or `'ed25519'`).
|
|
626
|
+
* @param signature - The raw signature bytes produced by `sign`.
|
|
627
|
+
* @param data - The original data that was signed.
|
|
628
|
+
* @returns `Success` with `true` if the signature is valid, `false` if it is
|
|
629
|
+
* not, or `Failure` with error context if the operation itself failed.
|
|
630
|
+
*/
|
|
631
|
+
verify(publicKey: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<Result<boolean>>;
|
|
632
|
+
/**
|
|
633
|
+
* Compares two byte arrays in constant time.
|
|
634
|
+
*
|
|
635
|
+
* The comparison visits all bytes of `a` and `b` regardless of where they
|
|
636
|
+
* diverge, accumulating XOR differences with bitwise-OR. No early-return is
|
|
637
|
+
* possible once the length check passes, making timing independent of the
|
|
638
|
+
* byte values. This prevents timing side-channels when comparing MAC outputs,
|
|
639
|
+
* signed-token bytes, or any secret-derived byte sequences.
|
|
640
|
+
*
|
|
641
|
+
* Returns `false` immediately (before the loop) when `a.length !== b.length`;
|
|
642
|
+
* the length mismatch itself is not secret in normal use.
|
|
643
|
+
* @param a - First byte array.
|
|
644
|
+
* @param b - Second byte array.
|
|
645
|
+
* @returns `true` if the arrays have the same length and identical contents,
|
|
646
|
+
* `false` otherwise.
|
|
647
|
+
*/
|
|
648
|
+
timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
|
|
649
|
+
/**
|
|
650
|
+
* Computes an HMAC-SHA256 authentication code for `data` using `key`.
|
|
651
|
+
*
|
|
652
|
+
* The key must be a `CryptoKey` with `'sign'` usage and algorithm name
|
|
653
|
+
* `'HMAC'` (e.g. derived via PBKDF2 or imported with
|
|
654
|
+
* `crypto.subtle.importKey`). Use {@link ICryptoProvider.verifyHmacSha256}
|
|
655
|
+
* for constant-time verification of the output.
|
|
656
|
+
* @param key - An HMAC `CryptoKey` with `'sign'` usage.
|
|
657
|
+
* @param data - The bytes to authenticate.
|
|
658
|
+
* @returns `Success` with the 32-byte MAC, or `Failure` with error context.
|
|
659
|
+
*/
|
|
660
|
+
hmacSha256(key: CryptoKey, data: Uint8Array): Promise<Result<Uint8Array>>;
|
|
661
|
+
/**
|
|
662
|
+
* Verifies an HMAC-SHA256 authentication code in constant time.
|
|
663
|
+
*
|
|
664
|
+
* Computes the expected MAC over `data` with `key`, then compares it to
|
|
665
|
+
* `signature` using {@link ICryptoProvider.timingSafeEqual} so that
|
|
666
|
+
* mismatches do not leak information through timing.
|
|
667
|
+
* @param key - An HMAC `CryptoKey` with `'sign'` usage.
|
|
668
|
+
* @param signature - The MAC bytes to verify (typically 32 bytes).
|
|
669
|
+
* @param data - The original data that was authenticated.
|
|
670
|
+
* @returns `Success` with `true` if the MAC is valid, `false` if it is not,
|
|
671
|
+
* or `Failure` with error context if the MAC computation itself failed.
|
|
672
|
+
*/
|
|
673
|
+
verifyHmacSha256(key: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<Result<boolean>>;
|
|
166
674
|
}
|
|
167
675
|
/**
|
|
168
676
|
* High-level interface for encrypting JSON content by secret name.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/packlets/crypto-utils/model.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,CAAC;AAMrB;;;;;;;;GAQG;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;AAM7E;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,SAAS,CAAC,iBAAiB,CAAC;AAErE;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,SAAS,CAAC,qBAAqB,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,UAAU,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAE7B;;OA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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
-
exports.Constants = void 0;
|
|
55
|
+
exports.ARGON2ID_PASSPHRASE = exports.ARGON2ID_OWASP_MIN = exports.allKeyPairAlgorithms = exports.Constants = void 0;
|
|
56
56
|
exports.isEncryptedFile = isEncryptedFile;
|
|
57
57
|
const Constants = __importStar(require("./constants"));
|
|
58
58
|
exports.Constants = Constants;
|
|
59
|
+
/**
|
|
60
|
+
* All valid key pair algorithms.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
exports.allKeyPairAlgorithms = [
|
|
64
|
+
'ecdsa-p256',
|
|
65
|
+
'rsa-oaep-2048',
|
|
66
|
+
'ecdh-p256',
|
|
67
|
+
'ed25519',
|
|
68
|
+
'x25519'
|
|
69
|
+
];
|
|
70
|
+
/**
|
|
71
|
+
* Recommended OWASP 2023 minimum Argon2id parameters.
|
|
72
|
+
* Suitable for recovery-row key derivation (high-entropy inputs).
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
exports.ARGON2ID_OWASP_MIN = {
|
|
76
|
+
memoryKiB: 19456,
|
|
77
|
+
iterations: 2,
|
|
78
|
+
parallelism: 1,
|
|
79
|
+
outputBytes: 32
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Stronger Argon2id parameters suitable for user-typed passphrases.
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
exports.ARGON2ID_PASSPHRASE = {
|
|
86
|
+
memoryKiB: 65536,
|
|
87
|
+
iterations: 3,
|
|
88
|
+
parallelism: 1,
|
|
89
|
+
outputBytes: 32
|
|
90
|
+
};
|
|
59
91
|
// ============================================================================
|
|
60
92
|
// Detection Helper
|
|
61
93
|
// ============================================================================
|