@zudojs/crypto 0.1.0 → 1.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/LICENSE +21 -0
- package/README.md +43 -14
- package/dist/compare/compare.helper.d.ts +10 -2
- package/dist/compare/compare.helper.js +22 -6
- package/dist/cryptoCipher/cryptoCipher.core.d.ts +11 -1
- package/dist/cryptoCipher/cryptoCipher.core.js +19 -3
- package/dist/cryptoCipher/cryptoCipher.envelope.d.ts +7 -2
- package/dist/cryptoCipher/cryptoCipher.envelope.js +33 -14
- package/dist/cryptoCipher/cryptoCipher.string.d.ts +2 -1
- package/dist/cryptoCipher/cryptoCipher.string.js +2 -2
- package/dist/cryptoConstants/cryptoConstants.guard.d.ts +9 -0
- package/dist/cryptoConstants/cryptoConstants.guard.js +16 -1
- package/dist/cryptoConstants/cryptoConstants.security.d.ts +42 -1
- package/dist/cryptoConstants/cryptoConstants.security.js +42 -1
- package/dist/cryptoConstants/cryptoConstants.token.d.ts +2 -0
- package/dist/cryptoConstants/cryptoConstants.token.js +2 -0
- package/dist/cryptoConstants/cryptoConstants.type.d.ts +36 -14
- package/dist/cryptoConstants/cryptoConstants.type.js +36 -14
- package/dist/cryptoEncoding/cryptoEncoding.compare.d.ts +4 -1
- package/dist/cryptoEncoding/cryptoEncoding.compare.js +11 -4
- package/dist/cryptoEncoding/cryptoEncoding.core.d.ts +22 -0
- package/dist/cryptoEncoding/cryptoEncoding.core.js +41 -3
- package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.d.ts +10 -2
- package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.js +24 -16
- package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.d.ts +9 -1
- package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.js +23 -20
- package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.d.ts +9 -2
- package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.js +17 -11
- package/dist/cryptoErrors/cryptoErrors.helper.d.ts +30 -0
- package/dist/cryptoErrors/cryptoErrors.helper.js +72 -0
- package/dist/cryptoFactory/cryptoFactory.core.d.ts +37 -6
- package/dist/cryptoFactory/cryptoFactory.core.js +56 -30
- package/dist/cryptoFactory/cryptoFactory.password.d.ts +4 -3
- package/dist/cryptoFactory/cryptoFactory.password.js +4 -4
- package/dist/cryptoFactory/cryptoFactory.token.d.ts +9 -8
- package/dist/cryptoFactory/cryptoFactory.token.js +16 -15
- package/dist/cryptoHash/cryptoHash.codec.d.ts +2 -0
- package/dist/cryptoHash/cryptoHash.codec.js +12 -12
- package/dist/cryptoHash/cryptoHash.compare.d.ts +3 -1
- package/dist/cryptoHash/cryptoHash.compare.js +5 -9
- package/dist/cryptoHash/cryptoHash.core.d.ts +6 -2
- package/dist/cryptoHash/cryptoHash.core.js +9 -2
- package/dist/cryptoHash/cryptoHmac.core.d.ts +8 -5
- package/dist/cryptoHash/cryptoHmac.core.js +22 -9
- package/dist/cryptoKey/cryptoKey.factory.d.ts +29 -2
- package/dist/cryptoKey/cryptoKey.factory.js +82 -18
- package/dist/cryptoKey/cryptoKey.utils.d.ts +5 -3
- package/dist/cryptoKey/cryptoKey.utils.js +5 -3
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.d.ts +7 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.js +40 -15
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.d.ts +2 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.js +2 -3
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.d.ts +5 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.d.ts +13 -2
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.js +53 -16
- package/dist/cryptoPassword/cryptoPassword.codec.d.ts +15 -1
- package/dist/cryptoPassword/cryptoPassword.codec.js +127 -56
- package/dist/cryptoPassword/cryptoPassword.core.d.ts +17 -3
- package/dist/cryptoPassword/cryptoPassword.core.js +29 -21
- package/dist/cryptoPassword/cryptoPassword.helper.js +6 -5
- package/dist/cryptoPassword/cryptoPassword.type.d.ts +33 -5
- package/dist/cryptoPassword/cryptoPassword.validate.d.ts +14 -3
- package/dist/cryptoPassword/cryptoPassword.validate.js +51 -20
- package/dist/cryptoProvider/cryptoProvider.default.d.ts +18 -0
- package/dist/cryptoProvider/cryptoProvider.default.js +31 -0
- package/dist/cryptoProvider/cryptoProvider.interface.d.ts +9 -34
- package/dist/cryptoProvider/cryptoProvider.type.d.ts +32 -3
- package/dist/cryptoProvider/cryptoProvider.type.js +40 -1
- package/dist/cryptoProvider/index.d.ts +5 -2
- package/dist/cryptoProvider/index.js +2 -0
- package/dist/cryptoProvider/types/cryptoCipher.type.d.ts +11 -6
- package/dist/cryptoProvider/types/cryptoKeyDerivation.type.d.ts +39 -3
- package/dist/cryptoProvider/types/cryptoSignature.type.d.ts +5 -5
- package/dist/cryptoProvider/types/index.d.ts +1 -1
- package/dist/cryptoRandom/cryptoRandom.choice.d.ts +6 -3
- package/dist/cryptoRandom/cryptoRandom.choice.js +10 -6
- package/dist/cryptoRandom/cryptoRandom.core.d.ts +8 -5
- package/dist/cryptoRandom/cryptoRandom.core.js +8 -7
- package/dist/cryptoRandom/cryptoRandom.string.d.ts +11 -9
- package/dist/cryptoRandom/cryptoRandom.string.js +28 -29
- package/dist/cryptoService/cryptoService.core.d.ts +47 -9
- package/dist/cryptoService/cryptoService.core.js +65 -33
- package/dist/cryptoService/cryptoService.derivation.d.ts +3 -3
- package/dist/cryptoService/cryptoService.derivation.js +8 -6
- package/dist/cryptoService/cryptoService.encoding.js +6 -5
- package/dist/cryptoService/index.d.ts +1 -5
- package/dist/cryptoService/index.js +1 -5
- package/dist/cryptoService/operations/cryptoService.cipher.d.ts +3 -2
- package/dist/cryptoService/operations/cryptoService.cipher.js +13 -9
- package/dist/cryptoService/operations/cryptoService.hash.d.ts +3 -2
- package/dist/cryptoService/operations/cryptoService.hash.js +7 -8
- package/dist/cryptoService/operations/cryptoService.password.d.ts +7 -2
- package/dist/cryptoService/operations/cryptoService.password.js +20 -9
- package/dist/cryptoService/operations/cryptoService.token.d.ts +9 -4
- package/dist/cryptoService/operations/cryptoService.token.js +31 -17
- package/dist/cryptoSignature/cryptoSignature.core.d.ts +10 -2
- package/dist/cryptoSignature/cryptoSignature.core.js +7 -3
- package/dist/cryptoToken/cryptoToken.core.d.ts +15 -9
- package/dist/cryptoToken/cryptoToken.core.js +63 -38
- package/dist/cryptoToken/cryptoToken.hash.d.ts +9 -7
- package/dist/cryptoToken/cryptoToken.hash.js +19 -43
- package/dist/cryptoUtils/cryptoUtils.compare.d.ts +3 -1
- package/dist/cryptoUtils/cryptoUtils.compare.js +5 -14
- package/dist/cryptoUtils/cryptoUtils.number.d.ts +3 -0
- package/dist/cryptoUtils/cryptoUtils.number.js +12 -6
- package/dist/cryptoUtils/cryptoUtils.validation.d.ts +2 -2
- package/dist/cryptoUtils/cryptoUtils.validation.js +6 -8
- package/dist/cryptoUtils/encoding/cryptoUtils.base64.d.ts +4 -4
- package/dist/cryptoUtils/encoding/cryptoUtils.base64.js +5 -23
- package/dist/cryptoUtils/encoding/cryptoUtils.base64url.d.ts +4 -4
- package/dist/cryptoUtils/encoding/cryptoUtils.base64url.js +5 -32
- package/dist/cryptoUtils/encoding/cryptoUtils.hex.d.ts +4 -4
- package/dist/cryptoUtils/encoding/cryptoUtils.hex.js +5 -20
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.d.ts +6 -29
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.js +0 -1
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.d.ts +9 -4
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.js +25 -43
- package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.d.ts +7 -0
- package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.js +112 -30
- package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.d.ts +17 -10
- package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.js +112 -72
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.d.ts +3 -12
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.js +74 -25
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.js +7 -2
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.d.ts +6 -0
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.js +18 -18
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.d.ts +10 -12
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.js +75 -20
- package/dist/node/signing/signing.conversion.d.ts +13 -3
- package/dist/node/signing/signing.conversion.js +35 -15
- package/dist/node/signing/signing.core.d.ts +2 -1
- package/dist/node/signing/signing.core.js +2 -3
- package/dist/node/signing/signing.utils.d.ts +10 -2
- package/dist/node/signing/signing.utils.js +26 -5
- package/package.json +28 -14
- package/dist/.tsbuildinfo +0 -1
- package/dist/compare/compare.helper.d.ts.map +0 -1
- package/dist/compare/compare.helper.js.map +0 -1
- package/dist/compare/index.d.ts.map +0 -1
- package/dist/compare/index.js.map +0 -1
- package/dist/cryptoAlgorithm/index.d.ts +0 -8
- package/dist/cryptoAlgorithm/index.d.ts.map +0 -1
- package/dist/cryptoAlgorithm/index.js +0 -8
- package/dist/cryptoAlgorithm/index.js.map +0 -1
- package/dist/cryptoCipher/cryptoCipher.core.d.ts.map +0 -1
- package/dist/cryptoCipher/cryptoCipher.core.js.map +0 -1
- package/dist/cryptoCipher/cryptoCipher.envelope.d.ts.map +0 -1
- package/dist/cryptoCipher/cryptoCipher.envelope.js.map +0 -1
- package/dist/cryptoCipher/cryptoCipher.string.d.ts.map +0 -1
- package/dist/cryptoCipher/cryptoCipher.string.js.map +0 -1
- package/dist/cryptoCipher/index.d.ts.map +0 -1
- package/dist/cryptoCipher/index.js.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.config.d.ts.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.config.js.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.guard.d.ts.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.guard.js.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.security.d.ts.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.security.js.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.token.d.ts.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.token.js.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.type.d.ts.map +0 -1
- package/dist/cryptoConstants/cryptoConstants.type.js.map +0 -1
- package/dist/cryptoConstants/index.d.ts.map +0 -1
- package/dist/cryptoConstants/index.js.map +0 -1
- package/dist/cryptoEncoding/cryptoEncoding.arrayBuffer.d.ts.map +0 -1
- package/dist/cryptoEncoding/cryptoEncoding.arrayBuffer.js.map +0 -1
- package/dist/cryptoEncoding/cryptoEncoding.compare.d.ts.map +0 -1
- package/dist/cryptoEncoding/cryptoEncoding.compare.js.map +0 -1
- package/dist/cryptoEncoding/cryptoEncoding.core.d.ts.map +0 -1
- package/dist/cryptoEncoding/cryptoEncoding.core.js.map +0 -1
- package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.d.ts.map +0 -1
- package/dist/cryptoEncoding/encoding/cryptoEncoding.base64.js.map +0 -1
- package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.d.ts.map +0 -1
- package/dist/cryptoEncoding/encoding/cryptoEncoding.base64url.js.map +0 -1
- package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.d.ts.map +0 -1
- package/dist/cryptoEncoding/encoding/cryptoEncoding.hex.js.map +0 -1
- package/dist/cryptoEncoding/encoding/index.d.ts.map +0 -1
- package/dist/cryptoEncoding/encoding/index.js.map +0 -1
- package/dist/cryptoEncoding/index.d.ts.map +0 -1
- package/dist/cryptoEncoding/index.js.map +0 -1
- package/dist/cryptoErrors/index.d.ts.map +0 -1
- package/dist/cryptoErrors/index.js.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.core.d.ts.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.core.js.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.encoding.d.ts.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.encoding.js.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.options.d.ts +0 -2
- package/dist/cryptoFactory/cryptoFactory.options.d.ts.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.options.js +0 -6
- package/dist/cryptoFactory/cryptoFactory.options.js.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.password.d.ts.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.password.js.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.token.d.ts.map +0 -1
- package/dist/cryptoFactory/cryptoFactory.token.js.map +0 -1
- package/dist/cryptoFactory/index.d.ts.map +0 -1
- package/dist/cryptoFactory/index.js.map +0 -1
- package/dist/cryptoHash/cryptoHash.codec.d.ts.map +0 -1
- package/dist/cryptoHash/cryptoHash.codec.js.map +0 -1
- package/dist/cryptoHash/cryptoHash.compare.d.ts.map +0 -1
- package/dist/cryptoHash/cryptoHash.compare.js.map +0 -1
- package/dist/cryptoHash/cryptoHash.convenience.d.ts.map +0 -1
- package/dist/cryptoHash/cryptoHash.convenience.js.map +0 -1
- package/dist/cryptoHash/cryptoHash.core.d.ts.map +0 -1
- package/dist/cryptoHash/cryptoHash.core.js.map +0 -1
- package/dist/cryptoHash/cryptoHmac.core.d.ts.map +0 -1
- package/dist/cryptoHash/cryptoHmac.core.js.map +0 -1
- package/dist/cryptoHash/index.d.ts.map +0 -1
- package/dist/cryptoHash/index.js.map +0 -1
- package/dist/cryptoKey/cryptoKey.factory.d.ts.map +0 -1
- package/dist/cryptoKey/cryptoKey.factory.js.map +0 -1
- package/dist/cryptoKey/cryptoKey.type.d.ts.map +0 -1
- package/dist/cryptoKey/cryptoKey.type.js.map +0 -1
- package/dist/cryptoKey/cryptoKey.utils.d.ts.map +0 -1
- package/dist/cryptoKey/cryptoKey.utils.js.map +0 -1
- package/dist/cryptoKey/index.d.ts.map +0 -1
- package/dist/cryptoKey/index.js.map +0 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.d.ts.map +0 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.core.js.map +0 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.d.ts.map +0 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.salt.js.map +0 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.d.ts.map +0 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.type.js.map +0 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.d.ts.map +0 -1
- package/dist/cryptoKeyDerivation/cryptoKeyDerivation.validate.js.map +0 -1
- package/dist/cryptoKeyDerivation/index.d.ts.map +0 -1
- package/dist/cryptoKeyDerivation/index.js.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.codec.d.ts.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.codec.js.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.core.d.ts.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.core.js.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.helper.d.ts.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.helper.js.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.type.d.ts.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.type.js.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.validate.d.ts.map +0 -1
- package/dist/cryptoPassword/cryptoPassword.validate.js.map +0 -1
- package/dist/cryptoPassword/index.d.ts.map +0 -1
- package/dist/cryptoPassword/index.js.map +0 -1
- package/dist/cryptoProvider/cryptoProvider.core.d.ts.map +0 -1
- package/dist/cryptoProvider/cryptoProvider.core.js.map +0 -1
- package/dist/cryptoProvider/cryptoProvider.interface.d.ts.map +0 -1
- package/dist/cryptoProvider/cryptoProvider.interface.js.map +0 -1
- package/dist/cryptoProvider/cryptoProvider.type.d.ts.map +0 -1
- package/dist/cryptoProvider/cryptoProvider.type.js.map +0 -1
- package/dist/cryptoProvider/index.d.ts.map +0 -1
- package/dist/cryptoProvider/index.js.map +0 -1
- package/dist/cryptoProvider/types/cryptoCipher.type.d.ts.map +0 -1
- package/dist/cryptoProvider/types/cryptoCipher.type.js.map +0 -1
- package/dist/cryptoProvider/types/cryptoHash.type.d.ts.map +0 -1
- package/dist/cryptoProvider/types/cryptoHash.type.js.map +0 -1
- package/dist/cryptoProvider/types/cryptoKeyDerivation.type.d.ts.map +0 -1
- package/dist/cryptoProvider/types/cryptoKeyDerivation.type.js.map +0 -1
- package/dist/cryptoProvider/types/cryptoRandom.type.d.ts.map +0 -1
- package/dist/cryptoProvider/types/cryptoRandom.type.js.map +0 -1
- package/dist/cryptoProvider/types/cryptoSignature.type.d.ts.map +0 -1
- package/dist/cryptoProvider/types/cryptoSignature.type.js.map +0 -1
- package/dist/cryptoProvider/types/index.d.ts.map +0 -1
- package/dist/cryptoProvider/types/index.js.map +0 -1
- package/dist/cryptoRandom/cryptoRandom.choice.d.ts.map +0 -1
- package/dist/cryptoRandom/cryptoRandom.choice.js.map +0 -1
- package/dist/cryptoRandom/cryptoRandom.core.d.ts.map +0 -1
- package/dist/cryptoRandom/cryptoRandom.core.js.map +0 -1
- package/dist/cryptoRandom/cryptoRandom.string.d.ts.map +0 -1
- package/dist/cryptoRandom/cryptoRandom.string.js.map +0 -1
- package/dist/cryptoRandom/index.d.ts.map +0 -1
- package/dist/cryptoRandom/index.js.map +0 -1
- package/dist/cryptoService/cryptoService.core.d.ts.map +0 -1
- package/dist/cryptoService/cryptoService.core.js.map +0 -1
- package/dist/cryptoService/cryptoService.derivation.d.ts.map +0 -1
- package/dist/cryptoService/cryptoService.derivation.js.map +0 -1
- package/dist/cryptoService/cryptoService.encoding.d.ts.map +0 -1
- package/dist/cryptoService/cryptoService.encoding.js.map +0 -1
- package/dist/cryptoService/index.d.ts.map +0 -1
- package/dist/cryptoService/index.js.map +0 -1
- package/dist/cryptoService/operations/cryptoService.cipher.d.ts.map +0 -1
- package/dist/cryptoService/operations/cryptoService.cipher.js.map +0 -1
- package/dist/cryptoService/operations/cryptoService.hash.d.ts.map +0 -1
- package/dist/cryptoService/operations/cryptoService.hash.js.map +0 -1
- package/dist/cryptoService/operations/cryptoService.password.d.ts.map +0 -1
- package/dist/cryptoService/operations/cryptoService.password.js.map +0 -1
- package/dist/cryptoService/operations/cryptoService.token.d.ts.map +0 -1
- package/dist/cryptoService/operations/cryptoService.token.js.map +0 -1
- package/dist/cryptoService/operations/index.d.ts.map +0 -1
- package/dist/cryptoService/operations/index.js.map +0 -1
- package/dist/cryptoSignature/cryptoSignature.core.d.ts.map +0 -1
- package/dist/cryptoSignature/cryptoSignature.core.js.map +0 -1
- package/dist/cryptoSignature/index.d.ts.map +0 -1
- package/dist/cryptoSignature/index.js.map +0 -1
- package/dist/cryptoToken/cryptoToken.core.d.ts.map +0 -1
- package/dist/cryptoToken/cryptoToken.core.js.map +0 -1
- package/dist/cryptoToken/cryptoToken.hash.d.ts.map +0 -1
- package/dist/cryptoToken/cryptoToken.hash.js.map +0 -1
- package/dist/cryptoToken/cryptoToken.utils.d.ts.map +0 -1
- package/dist/cryptoToken/cryptoToken.utils.js.map +0 -1
- package/dist/cryptoToken/index.d.ts.map +0 -1
- package/dist/cryptoToken/index.js.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.compare.d.ts.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.compare.js.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.conversion.d.ts.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.conversion.js.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.number.d.ts.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.number.js.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.text.d.ts.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.text.js.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.validation.d.ts.map +0 -1
- package/dist/cryptoUtils/cryptoUtils.validation.js.map +0 -1
- package/dist/cryptoUtils/encoding/cryptoUtils.base64.d.ts.map +0 -1
- package/dist/cryptoUtils/encoding/cryptoUtils.base64.js.map +0 -1
- package/dist/cryptoUtils/encoding/cryptoUtils.base64url.d.ts.map +0 -1
- package/dist/cryptoUtils/encoding/cryptoUtils.base64url.js.map +0 -1
- package/dist/cryptoUtils/encoding/cryptoUtils.hex.d.ts.map +0 -1
- package/dist/cryptoUtils/encoding/cryptoUtils.hex.js.map +0 -1
- package/dist/cryptoUtils/encoding/index.d.ts.map +0 -1
- package/dist/cryptoUtils/encoding/index.js.map +0 -1
- package/dist/cryptoUtils/index.d.ts.map +0 -1
- package/dist/cryptoUtils/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/node/index.d.ts.map +0 -1
- package/dist/node/index.js.map +0 -1
- package/dist/node/nodeCryptoProvider/index.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/index.js.map +0 -1
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.core.js.map +0 -1
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.factory.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.factory.js.map +0 -1
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/nodeCryptoProvider.helper.js.map +0 -1
- package/dist/node/nodeCryptoProvider/operations/index.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/operations/index.js.map +0 -1
- package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.derivation.js.map +0 -1
- package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/operations/nodeCryptoProvider.password.js.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/index.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/index.js.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.encryption.js.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.hash.js.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.random.js.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.d.ts.map +0 -1
- package/dist/node/nodeCryptoProvider/primitives/nodeCryptoProvider.signing.js.map +0 -1
- package/dist/node/signing/index.d.ts.map +0 -1
- package/dist/node/signing/index.js.map +0 -1
- package/dist/node/signing/signing.conversion.d.ts.map +0 -1
- package/dist/node/signing/signing.conversion.js.map +0 -1
- package/dist/node/signing/signing.core.d.ts.map +0 -1
- package/dist/node/signing/signing.core.js.map +0 -1
- package/dist/node/signing/signing.utils.d.ts.map +0 -1
- package/dist/node/signing/signing.utils.js.map +0 -1
|
@@ -1,29 +1,66 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
|
|
2
2
|
import { encode } from "../cryptoEncoding/cryptoEncoding.core.js";
|
|
3
|
-
|
|
3
|
+
import { CryptoOperation } from "@zudojs/errors";
|
|
4
|
+
import { keyError } from "../cryptoErrors/cryptoErrors.helper.js";
|
|
5
|
+
import { CryptoAlgorithm, AES_GCM, KEY_SIZE, } from "../cryptoConstants/cryptoConstants.type.js";
|
|
6
|
+
import { isAeadAlgorithm, isHashAlgorithm, isKeyDerivationAlgorithm, isMacAlgorithm, isSymmetricKeyAlgorithm, } from "../cryptoConstants/cryptoConstants.guard.js";
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
8
|
+
* Domain-separation label used for key fingerprints.
|
|
6
9
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
10
|
+
* Fingerprints are `HMAC-SHA256(label, keyBytes)` rather than a bare hash
|
|
11
|
+
* of the key so that they cannot be confused with any other digest of the
|
|
12
|
+
* same bytes. They are only safe to expose for keys with at least 128 bits
|
|
13
|
+
* of entropy, which `createCryptoKey` enforces by length; a fingerprint of
|
|
14
|
+
* a low-entropy key is still an offline brute-force oracle.
|
|
9
15
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
export const CRYPTO_KEY_FINGERPRINT_LABEL = "zudojs-crypto-key-fingerprint-v1";
|
|
17
|
+
const MIN_SYMMETRIC_KEY_BYTES = KEY_SIZE.MIN_SYMMETRIC_KEY_BITS / 8;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the required key length (in bytes) for an algorithm, or a
|
|
20
|
+
* minimum when any length above it is acceptable.
|
|
21
|
+
*/
|
|
22
|
+
export function expectedKeyLength(algorithm) {
|
|
23
|
+
if (isAeadAlgorithm(algorithm)) {
|
|
24
|
+
return { exact: AES_GCM.KEY_BYTES, minimum: AES_GCM.KEY_BYTES };
|
|
25
|
+
}
|
|
26
|
+
if (isMacAlgorithm(algorithm) || isKeyDerivationAlgorithm(algorithm)) {
|
|
27
|
+
return { minimum: MIN_SYMMETRIC_KEY_BYTES };
|
|
28
|
+
}
|
|
29
|
+
if (algorithm === CryptoAlgorithm.ED25519) {
|
|
30
|
+
// Raw 32-byte seed or a DER/PEM encoded key.
|
|
31
|
+
return { minimum: KEY_SIZE.ED25519_BITS / 8 };
|
|
32
|
+
}
|
|
33
|
+
throw keyError(`Algorithm "${String(algorithm)}" does not use cryptographic keys.`, CryptoOperation.KEY_IMPORT, typeof algorithm === "string" ? algorithm : undefined);
|
|
34
|
+
}
|
|
35
|
+
function validateKeyBytes(bytes, algorithm) {
|
|
36
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
37
|
+
throw keyError("Cryptographic key material must be a Uint8Array.", CryptoOperation.KEY_IMPORT, algorithm);
|
|
38
|
+
}
|
|
39
|
+
if (bytes.byteLength === 0) {
|
|
40
|
+
throw keyError("Cryptographic key cannot be empty.", CryptoOperation.KEY_IMPORT, algorithm);
|
|
41
|
+
}
|
|
42
|
+
if (isHashAlgorithm(algorithm)) {
|
|
43
|
+
throw keyError(`Hash algorithm "${algorithm}" does not use cryptographic keys.`, CryptoOperation.KEY_IMPORT, algorithm);
|
|
44
|
+
}
|
|
45
|
+
const { exact, minimum } = expectedKeyLength(algorithm);
|
|
46
|
+
if (exact !== undefined && bytes.byteLength !== exact) {
|
|
47
|
+
throw keyError(`Algorithm "${algorithm}" requires a ${exact}-byte key, received ${bytes.byteLength} bytes.`, CryptoOperation.KEY_IMPORT, algorithm);
|
|
48
|
+
}
|
|
49
|
+
if (bytes.byteLength < minimum) {
|
|
50
|
+
throw keyError(`Algorithm "${algorithm}" requires a key of at least ${minimum} bytes, received ${bytes.byteLength} bytes.`, CryptoOperation.KEY_IMPORT, algorithm);
|
|
13
51
|
}
|
|
14
|
-
return defaultProvider;
|
|
15
52
|
}
|
|
16
53
|
/**
|
|
17
54
|
* Creates a cryptographic key from raw bytes.
|
|
18
55
|
*
|
|
56
|
+
* The key length is validated against the declared algorithm (exactly 32
|
|
57
|
+
* bytes for AES-256-GCM, at least 16 bytes for HMAC and derived keys).
|
|
19
58
|
* Hashing and key-id generation are delegated to the supplied provider.
|
|
20
59
|
*/
|
|
21
|
-
export async function createCryptoKey(bytes, options, provider =
|
|
22
|
-
|
|
23
|
-
throw new TypeError("Cryptographic key cannot be empty.");
|
|
24
|
-
}
|
|
60
|
+
export async function createCryptoKey(bytes, options, provider = getDefaultCryptoProvider()) {
|
|
61
|
+
validateKeyBytes(bytes, options.algorithm);
|
|
25
62
|
const keyBytes = new Uint8Array(bytes);
|
|
26
|
-
const digest = await provider.
|
|
63
|
+
const digest = await provider.hmac("sha256", CRYPTO_KEY_FINGERPRINT_LABEL, keyBytes);
|
|
27
64
|
const fingerprint = encode(digest, "hex");
|
|
28
65
|
const createdAt = Date.now();
|
|
29
66
|
const keyId = options.keyId ?? `key_${await generateKeyId(provider)}`;
|
|
@@ -40,17 +77,44 @@ export async function createCryptoKey(bytes, options, provider = getDefaultProvi
|
|
|
40
77
|
});
|
|
41
78
|
}
|
|
42
79
|
/**
|
|
43
|
-
* Generates a cryptographically secure random key.
|
|
80
|
+
* Generates a cryptographically secure random symmetric key.
|
|
44
81
|
*
|
|
45
|
-
*
|
|
82
|
+
* Only symmetric algorithms (AES-GCM, HMAC, KDF outputs) are accepted:
|
|
83
|
+
* random bytes are not a usable Ed25519 key, so asymmetric algorithms are
|
|
84
|
+
* rejected. Use `generateEd25519KeyPair` for signing keys.
|
|
46
85
|
*/
|
|
47
|
-
export async function generateCryptoKey(length, options, provider =
|
|
86
|
+
export async function generateCryptoKey(length, options, provider = getDefaultCryptoProvider()) {
|
|
87
|
+
if (!isSymmetricKeyAlgorithm(options.algorithm)) {
|
|
88
|
+
throw keyError(`Random key generation is only supported for symmetric algorithms, not "${String(options.algorithm)}".`, CryptoOperation.KEY_GENERATION, typeof options.algorithm === "string" ? options.algorithm : undefined);
|
|
89
|
+
}
|
|
48
90
|
if (!Number.isInteger(length) || length <= 0) {
|
|
49
91
|
throw new RangeError("Cryptographic key length must be a positive integer.");
|
|
50
92
|
}
|
|
51
93
|
const bytes = await provider.randomBytes(length);
|
|
52
94
|
return createCryptoKey(bytes, options, provider);
|
|
53
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns the default key length in bytes for a symmetric algorithm.
|
|
98
|
+
*/
|
|
99
|
+
export function defaultKeyLength(algorithm) {
|
|
100
|
+
if (isAeadAlgorithm(algorithm)) {
|
|
101
|
+
return AES_GCM.KEY_BYTES;
|
|
102
|
+
}
|
|
103
|
+
switch (algorithm) {
|
|
104
|
+
case CryptoAlgorithm.HMAC_SHA256:
|
|
105
|
+
case CryptoAlgorithm.PBKDF2_SHA256:
|
|
106
|
+
case CryptoAlgorithm.SCRYPT:
|
|
107
|
+
return 32;
|
|
108
|
+
case CryptoAlgorithm.HMAC_SHA384:
|
|
109
|
+
case CryptoAlgorithm.PBKDF2_SHA384:
|
|
110
|
+
return 48;
|
|
111
|
+
case CryptoAlgorithm.HMAC_SHA512:
|
|
112
|
+
case CryptoAlgorithm.PBKDF2_SHA512:
|
|
113
|
+
return 64;
|
|
114
|
+
default:
|
|
115
|
+
throw keyError(`Random key generation is only supported for symmetric algorithms, not "${String(algorithm)}".`, CryptoOperation.KEY_GENERATION, typeof algorithm === "string" ? algorithm : undefined);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
54
118
|
/**
|
|
55
119
|
* Returns a defensive copy of a key's bytes.
|
|
56
120
|
*
|
|
@@ -58,7 +122,7 @@ export async function generateCryptoKey(length, options, provider = getDefaultPr
|
|
|
58
122
|
*/
|
|
59
123
|
export function exportCryptoKey(key) {
|
|
60
124
|
if (!key.extractable) {
|
|
61
|
-
throw
|
|
125
|
+
throw keyError(`Cryptographic key "${key.keyId}" is not extractable.`, CryptoOperation.KEY_EXPORT, key.algorithm);
|
|
62
126
|
}
|
|
63
127
|
return key.bytes();
|
|
64
128
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { CryptoKey } from "./cryptoKey.type.js";
|
|
2
2
|
/**
|
|
3
|
-
* Returns
|
|
3
|
+
* Returns the stable fingerprint of a key.
|
|
4
4
|
*
|
|
5
|
-
* The fingerprint
|
|
6
|
-
*
|
|
5
|
+
* The fingerprint is `HMAC-SHA256(CRYPTO_KEY_FINGERPRINT_LABEL, keyBytes)`
|
|
6
|
+
* in hex. It can be used to identify a key without exposing the secret
|
|
7
|
+
* material, provided the key has at least 128 bits of entropy (which
|
|
8
|
+
* `createCryptoKey` enforces by minimum length).
|
|
7
9
|
*/
|
|
8
10
|
export declare function getCryptoKeyFingerprint(key: CryptoKey): string;
|
|
9
11
|
/**
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns
|
|
2
|
+
* Returns the stable fingerprint of a key.
|
|
3
3
|
*
|
|
4
|
-
* The fingerprint
|
|
5
|
-
*
|
|
4
|
+
* The fingerprint is `HMAC-SHA256(CRYPTO_KEY_FINGERPRINT_LABEL, keyBytes)`
|
|
5
|
+
* in hex. It can be used to identify a key without exposing the secret
|
|
6
|
+
* material, provided the key has at least 128 bits of entropy (which
|
|
7
|
+
* `createCryptoKey` enforces by minimum length).
|
|
6
8
|
*/
|
|
7
9
|
export function getCryptoKeyFingerprint(key) {
|
|
8
10
|
return key.fingerprint;
|
|
@@ -2,11 +2,17 @@ import type { DerivedKeyResult } from "../cryptoProvider/index.js";
|
|
|
2
2
|
import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
|
|
3
3
|
import type { Pbkdf2Options, ScryptOptions } from "./cryptoKeyDerivation.type.js";
|
|
4
4
|
/**
|
|
5
|
-
* Derives a key from a password using PBKDF2.
|
|
5
|
+
* Derives a key from a password using PBKDF2-HMAC.
|
|
6
|
+
*
|
|
7
|
+
* The digest option is honoured end to end and reflected in
|
|
8
|
+
* `result.algorithm` (`pbkdf2-sha256`, `pbkdf2-sha384` or `pbkdf2-sha512`).
|
|
6
9
|
*/
|
|
7
10
|
export declare function derivePbkdf2(password: string | Uint8Array, options?: Pbkdf2Options): Promise<DerivedKeyResult>;
|
|
8
11
|
/**
|
|
9
12
|
* Derives a key using scrypt.
|
|
13
|
+
*
|
|
14
|
+
* `blockSize` and `maxMemory` are forwarded to the provider, so work
|
|
15
|
+
* factors above the default (e.g. N = 2^17) are usable.
|
|
10
16
|
*/
|
|
11
17
|
export declare function deriveScrypt(password: string | Uint8Array, options?: ScryptOptions): Promise<DerivedKeyResult>;
|
|
12
18
|
/**
|
|
@@ -1,50 +1,70 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
|
|
2
2
|
import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
|
|
3
|
+
import { PASSWORD_HASH } from "../cryptoConstants/cryptoConstants.security.js";
|
|
3
4
|
import { validatePbkdf2Options, validateScryptOptions, } from "./cryptoKeyDerivation.validate.js";
|
|
4
|
-
|
|
5
|
+
function pbkdf2Label(digest) {
|
|
6
|
+
switch (digest) {
|
|
7
|
+
case "sha256":
|
|
8
|
+
return CryptoAlgorithm.PBKDF2_SHA256;
|
|
9
|
+
case "sha384":
|
|
10
|
+
return CryptoAlgorithm.PBKDF2_SHA384;
|
|
11
|
+
case "sha512":
|
|
12
|
+
return CryptoAlgorithm.PBKDF2_SHA512;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
|
-
* Derives a key from a password using PBKDF2.
|
|
16
|
+
* Derives a key from a password using PBKDF2-HMAC.
|
|
17
|
+
*
|
|
18
|
+
* The digest option is honoured end to end and reflected in
|
|
19
|
+
* `result.algorithm` (`pbkdf2-sha256`, `pbkdf2-sha384` or `pbkdf2-sha512`).
|
|
7
20
|
*/
|
|
8
21
|
export async function derivePbkdf2(password, options = {}) {
|
|
9
|
-
const
|
|
22
|
+
const provider = options.provider ?? getDefaultCryptoProvider();
|
|
23
|
+
const iterations = options.iterations ?? PASSWORD_HASH.PBKDF2.ITERATIONS;
|
|
10
24
|
const keyLength = options.keyLength ?? 32;
|
|
25
|
+
const digest = options.digest ?? "sha256";
|
|
11
26
|
const salt = options.salt ??
|
|
12
27
|
new Uint8Array(await provider.randomBytes(options.saltLength ?? 16));
|
|
13
|
-
|
|
14
|
-
validatePbkdf2Options(iterations, keyLength, salt);
|
|
28
|
+
validatePbkdf2Options(iterations, keyLength, salt, digest);
|
|
15
29
|
const key = await provider.deriveKey({
|
|
16
30
|
password,
|
|
17
31
|
salt,
|
|
18
32
|
algorithm: "pbkdf2",
|
|
19
33
|
keyLength,
|
|
20
34
|
iterations,
|
|
35
|
+
digest,
|
|
21
36
|
});
|
|
22
37
|
return Object.freeze({
|
|
23
|
-
algorithm: digest
|
|
24
|
-
|
|
25
|
-
: CryptoAlgorithm.PBKDF2_SHA256,
|
|
38
|
+
algorithm: pbkdf2Label(digest),
|
|
39
|
+
digest,
|
|
26
40
|
key,
|
|
27
41
|
salt: new Uint8Array(salt),
|
|
28
42
|
});
|
|
29
43
|
}
|
|
30
44
|
/**
|
|
31
45
|
* Derives a key using scrypt.
|
|
46
|
+
*
|
|
47
|
+
* `blockSize` and `maxMemory` are forwarded to the provider, so work
|
|
48
|
+
* factors above the default (e.g. N = 2^17) are usable.
|
|
32
49
|
*/
|
|
33
50
|
export async function deriveScrypt(password, options = {}) {
|
|
51
|
+
const provider = options.provider ?? getDefaultCryptoProvider();
|
|
34
52
|
const keyLength = options.keyLength ?? 32;
|
|
35
|
-
const cost = options.cost ??
|
|
36
|
-
const blockSize = options.blockSize ??
|
|
37
|
-
const parallelization = options.parallelization ??
|
|
53
|
+
const cost = options.cost ?? PASSWORD_HASH.SCRYPT.COST;
|
|
54
|
+
const blockSize = options.blockSize ?? PASSWORD_HASH.SCRYPT.BLOCK_SIZE;
|
|
55
|
+
const parallelization = options.parallelization ?? PASSWORD_HASH.SCRYPT.PARALLELIZATION;
|
|
38
56
|
const salt = options.salt ??
|
|
39
57
|
new Uint8Array(await provider.randomBytes(options.saltLength ?? 16));
|
|
40
|
-
validateScryptOptions(keyLength, cost, blockSize, parallelization, salt);
|
|
58
|
+
validateScryptOptions(keyLength, cost, blockSize, parallelization, salt, options.maxMemory);
|
|
41
59
|
const key = await provider.deriveKey({
|
|
42
|
-
password
|
|
60
|
+
password,
|
|
43
61
|
salt,
|
|
44
62
|
algorithm: "scrypt",
|
|
45
63
|
keyLength,
|
|
46
64
|
memoryCost: cost,
|
|
65
|
+
blockSize,
|
|
47
66
|
parallelism: parallelization,
|
|
67
|
+
maxMemory: options.maxMemory,
|
|
48
68
|
});
|
|
49
69
|
return Object.freeze({
|
|
50
70
|
algorithm: CryptoAlgorithm.SCRYPT,
|
|
@@ -62,6 +82,11 @@ export async function deriveKey(password, algorithm, options = {}) {
|
|
|
62
82
|
...options,
|
|
63
83
|
digest: "sha256",
|
|
64
84
|
});
|
|
85
|
+
case CryptoAlgorithm.PBKDF2_SHA384:
|
|
86
|
+
return derivePbkdf2(password, {
|
|
87
|
+
...options,
|
|
88
|
+
digest: "sha384",
|
|
89
|
+
});
|
|
65
90
|
case CryptoAlgorithm.PBKDF2_SHA512:
|
|
66
91
|
return derivePbkdf2(password, {
|
|
67
92
|
...options,
|
|
@@ -70,7 +95,7 @@ export async function deriveKey(password, algorithm, options = {}) {
|
|
|
70
95
|
case CryptoAlgorithm.SCRYPT:
|
|
71
96
|
return deriveScrypt(password, options);
|
|
72
97
|
default:
|
|
73
|
-
throw new TypeError(`Unsupported key derivation algorithm: ${algorithm}.`);
|
|
98
|
+
throw new TypeError(`Unsupported key derivation algorithm: ${String(algorithm)}.`);
|
|
74
99
|
}
|
|
75
100
|
}
|
|
76
101
|
//# sourceMappingURL=cryptoKeyDerivation.core.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { CryptoProvider } from "../cryptoProvider/index.js";
|
|
1
2
|
/**
|
|
2
3
|
* Creates a random salt.
|
|
3
4
|
*/
|
|
4
|
-
export declare function generateSalt(length?: number): Promise<Uint8Array>;
|
|
5
|
+
export declare function generateSalt(length?: number, provider?: CryptoProvider): Promise<Uint8Array>;
|
|
5
6
|
//# sourceMappingURL=cryptoKeyDerivation.salt.d.ts.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a random salt.
|
|
4
4
|
*/
|
|
5
|
-
export async function generateSalt(length = 16) {
|
|
5
|
+
export async function generateSalt(length = 16, provider = getDefaultCryptoProvider()) {
|
|
6
6
|
if (!Number.isInteger(length) || length < 16) {
|
|
7
7
|
throw new RangeError("Salt length must be an integer of at least 16 bytes.");
|
|
8
8
|
}
|
|
9
|
-
const provider = createNodeCryptoProvider();
|
|
10
9
|
return provider.randomBytes(length);
|
|
11
10
|
}
|
|
12
11
|
//# sourceMappingURL=cryptoKeyDerivation.salt.js.map
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import type { CryptoProvider, Pbkdf2Digest } from "../cryptoProvider/index.js";
|
|
1
2
|
/**
|
|
2
3
|
* Options for PBKDF2 key derivation.
|
|
3
4
|
*/
|
|
4
5
|
export interface Pbkdf2Options {
|
|
5
6
|
readonly iterations?: number;
|
|
6
7
|
readonly keyLength?: number;
|
|
7
|
-
readonly digest?:
|
|
8
|
+
readonly digest?: Pbkdf2Digest;
|
|
8
9
|
readonly salt?: Uint8Array;
|
|
9
10
|
readonly saltLength?: number;
|
|
11
|
+
readonly provider?: CryptoProvider;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Options for scrypt key derivation.
|
|
@@ -18,6 +20,8 @@ export interface ScryptOptions {
|
|
|
18
20
|
readonly parallelization?: number;
|
|
19
21
|
readonly salt?: Uint8Array;
|
|
20
22
|
readonly saltLength?: number;
|
|
23
|
+
/** Memory upper bound in bytes; defaults to a value derived from cost/blockSize/parallelization. */
|
|
21
24
|
readonly maxMemory?: number;
|
|
25
|
+
readonly provider?: CryptoProvider;
|
|
22
26
|
}
|
|
23
27
|
//# sourceMappingURL=cryptoKeyDerivation.type.d.ts.map
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Validates PBKDF2 key derivation options.
|
|
3
|
+
*
|
|
4
|
+
* Both floors and ceilings are enforced: `iterations` is bounded by
|
|
5
|
+
* `PASSWORD_HASH.LIMITS.MAX_PBKDF2_ITERATIONS` and `keyLength` by
|
|
6
|
+
* `PASSWORD_HASH.LIMITS.MAX_DERIVED_KEY_BYTES`, so a work factor read from
|
|
7
|
+
* configuration cannot request unbounded CPU time.
|
|
3
8
|
*/
|
|
4
|
-
export declare function validatePbkdf2Options(iterations: number, keyLength: number, salt: Uint8Array): void;
|
|
9
|
+
export declare function validatePbkdf2Options(iterations: number, keyLength: number, salt: Uint8Array, digest?: unknown): void;
|
|
5
10
|
/**
|
|
6
11
|
* Validates scrypt key derivation options.
|
|
12
|
+
*
|
|
13
|
+
* `cost`, `blockSize` and `parallelization` are bounded by
|
|
14
|
+
* `PASSWORD_HASH.LIMITS`, and `128 * cost * blockSize` (the scrypt working
|
|
15
|
+
* memory) by `MAX_SCRYPT_MEMORY_BYTES`. Without these ceilings the memory
|
|
16
|
+
* "bound" passed to the provider was derived from the very parameters it
|
|
17
|
+
* was meant to bound, so a cost of 2^30 allocated terabytes.
|
|
7
18
|
*/
|
|
8
|
-
export declare function validateScryptOptions(keyLength: number, cost: number, blockSize: number, parallelization: number, salt: Uint8Array): void;
|
|
19
|
+
export declare function validateScryptOptions(keyLength: number, cost: number, blockSize: number, parallelization: number, salt: Uint8Array, maxMemory?: number): void;
|
|
9
20
|
//# sourceMappingURL=cryptoKeyDerivation.validate.d.ts.map
|
|
@@ -1,35 +1,72 @@
|
|
|
1
|
+
import { PASSWORD_HASH } from "../cryptoConstants/cryptoConstants.security.js";
|
|
2
|
+
import { isPbkdf2Digest } from "../cryptoProvider/cryptoProvider.type.js";
|
|
3
|
+
const LIMITS = PASSWORD_HASH.LIMITS;
|
|
1
4
|
/**
|
|
2
5
|
* Validates PBKDF2 key derivation options.
|
|
6
|
+
*
|
|
7
|
+
* Both floors and ceilings are enforced: `iterations` is bounded by
|
|
8
|
+
* `PASSWORD_HASH.LIMITS.MAX_PBKDF2_ITERATIONS` and `keyLength` by
|
|
9
|
+
* `PASSWORD_HASH.LIMITS.MAX_DERIVED_KEY_BYTES`, so a work factor read from
|
|
10
|
+
* configuration cannot request unbounded CPU time.
|
|
3
11
|
*/
|
|
4
|
-
export function validatePbkdf2Options(iterations, keyLength, salt) {
|
|
5
|
-
if (!Number.isInteger(iterations) ||
|
|
6
|
-
|
|
12
|
+
export function validatePbkdf2Options(iterations, keyLength, salt, digest = "sha256") {
|
|
13
|
+
if (!Number.isInteger(iterations) ||
|
|
14
|
+
iterations < PASSWORD_HASH.PBKDF2.MIN_ITERATIONS ||
|
|
15
|
+
iterations > LIMITS.MAX_PBKDF2_ITERATIONS) {
|
|
16
|
+
throw new RangeError(`PBKDF2 iterations must be an integer between ${PASSWORD_HASH.PBKDF2.MIN_ITERATIONS} and ${LIMITS.MAX_PBKDF2_ITERATIONS}.`);
|
|
7
17
|
}
|
|
8
|
-
if (!Number.isInteger(keyLength) ||
|
|
9
|
-
|
|
18
|
+
if (!Number.isInteger(keyLength) ||
|
|
19
|
+
keyLength < 16 ||
|
|
20
|
+
keyLength > LIMITS.MAX_DERIVED_KEY_BYTES) {
|
|
21
|
+
throw new RangeError(`PBKDF2 keyLength must be an integer between 16 and ${LIMITS.MAX_DERIVED_KEY_BYTES} bytes.`);
|
|
10
22
|
}
|
|
11
|
-
if (salt.byteLength < 16) {
|
|
23
|
+
if (!(salt instanceof Uint8Array) || salt.byteLength < 16) {
|
|
12
24
|
throw new RangeError("PBKDF2 salt must be at least 16 bytes.");
|
|
13
25
|
}
|
|
26
|
+
if (!isPbkdf2Digest(digest)) {
|
|
27
|
+
throw new TypeError(`Unsupported PBKDF2 digest: ${String(digest)}.`);
|
|
28
|
+
}
|
|
14
29
|
}
|
|
15
30
|
/**
|
|
16
31
|
* Validates scrypt key derivation options.
|
|
32
|
+
*
|
|
33
|
+
* `cost`, `blockSize` and `parallelization` are bounded by
|
|
34
|
+
* `PASSWORD_HASH.LIMITS`, and `128 * cost * blockSize` (the scrypt working
|
|
35
|
+
* memory) by `MAX_SCRYPT_MEMORY_BYTES`. Without these ceilings the memory
|
|
36
|
+
* "bound" passed to the provider was derived from the very parameters it
|
|
37
|
+
* was meant to bound, so a cost of 2^30 allocated terabytes.
|
|
17
38
|
*/
|
|
18
|
-
export function validateScryptOptions(keyLength, cost, blockSize, parallelization, salt) {
|
|
19
|
-
if (!Number.isInteger(keyLength) ||
|
|
20
|
-
|
|
39
|
+
export function validateScryptOptions(keyLength, cost, blockSize, parallelization, salt, maxMemory) {
|
|
40
|
+
if (!Number.isInteger(keyLength) ||
|
|
41
|
+
keyLength < 16 ||
|
|
42
|
+
keyLength > LIMITS.MAX_DERIVED_KEY_BYTES) {
|
|
43
|
+
throw new RangeError(`scrypt keyLength must be an integer between 16 and ${LIMITS.MAX_DERIVED_KEY_BYTES} bytes.`);
|
|
44
|
+
}
|
|
45
|
+
if (!Number.isInteger(cost) ||
|
|
46
|
+
cost < 2 ||
|
|
47
|
+
cost > LIMITS.MAX_SCRYPT_COST ||
|
|
48
|
+
(cost & (cost - 1)) !== 0) {
|
|
49
|
+
throw new RangeError(`scrypt cost must be a power of two between 2 and ${LIMITS.MAX_SCRYPT_COST}.`);
|
|
21
50
|
}
|
|
22
|
-
if (!Number.isInteger(
|
|
23
|
-
|
|
51
|
+
if (!Number.isInteger(blockSize) ||
|
|
52
|
+
blockSize <= 0 ||
|
|
53
|
+
blockSize > LIMITS.MAX_SCRYPT_BLOCK_SIZE) {
|
|
54
|
+
throw new RangeError(`scrypt blockSize must be an integer between 1 and ${LIMITS.MAX_SCRYPT_BLOCK_SIZE}.`);
|
|
24
55
|
}
|
|
25
|
-
if (!Number.isInteger(
|
|
26
|
-
|
|
56
|
+
if (!Number.isInteger(parallelization) ||
|
|
57
|
+
parallelization <= 0 ||
|
|
58
|
+
parallelization > LIMITS.MAX_SCRYPT_PARALLELIZATION) {
|
|
59
|
+
throw new RangeError(`scrypt parallelization must be an integer between 1 and ${LIMITS.MAX_SCRYPT_PARALLELIZATION}.`);
|
|
27
60
|
}
|
|
28
|
-
if (
|
|
29
|
-
throw new RangeError(
|
|
61
|
+
if (128 * cost * blockSize > LIMITS.MAX_SCRYPT_MEMORY_BYTES) {
|
|
62
|
+
throw new RangeError(`scrypt cost * blockSize exceeds the memory bound of ${LIMITS.MAX_SCRYPT_MEMORY_BYTES} bytes.`);
|
|
30
63
|
}
|
|
31
|
-
if (salt.byteLength < 16) {
|
|
64
|
+
if (!(salt instanceof Uint8Array) || salt.byteLength < 16) {
|
|
32
65
|
throw new RangeError("scrypt salt must be at least 16 bytes.");
|
|
33
66
|
}
|
|
67
|
+
if (maxMemory !== undefined &&
|
|
68
|
+
(!Number.isInteger(maxMemory) || maxMemory <= 0)) {
|
|
69
|
+
throw new RangeError("scrypt maxMemory must be a positive integer.");
|
|
70
|
+
}
|
|
34
71
|
}
|
|
35
72
|
//# sourceMappingURL=cryptoKeyDerivation.validate.js.map
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Pbkdf2Digest } from "../cryptoProvider/cryptoProvider.type.js";
|
|
2
|
+
import type { PasswordHashParameters, Pbkdf2PasswordAlgorithm } from "./cryptoPassword.type.js";
|
|
2
3
|
/**
|
|
3
4
|
* Current password hash encoding format version.
|
|
4
5
|
*/
|
|
5
6
|
export declare const PASSWORD_FORMAT_VERSION = "v1";
|
|
7
|
+
/**
|
|
8
|
+
* Returns the PBKDF2 password algorithm label for a digest.
|
|
9
|
+
*/
|
|
10
|
+
export declare function pbkdf2PasswordAlgorithm(digest: Pbkdf2Digest): Pbkdf2PasswordAlgorithm;
|
|
6
11
|
/**
|
|
7
12
|
* Decodes an encoded password hash into its parameters.
|
|
13
|
+
*
|
|
14
|
+
* Supported formats:
|
|
15
|
+
*
|
|
16
|
+
* - `v1$scrypt$<N>$<r>$<p>$<salt>.<hash>`
|
|
17
|
+
* - `v1$pbkdf2-<digest>$<iterations>$<salt>.<hash>`
|
|
18
|
+
*
|
|
19
|
+
* All binary fields are canonical Base64URL. Parameters are validated
|
|
20
|
+
* against `PASSWORD_HASH.LIMITS`, so a decoded hash is always safe to
|
|
21
|
+
* re-derive.
|
|
8
22
|
*/
|
|
9
23
|
export declare function decodePasswordHash(encoded: string): PasswordHashParameters;
|
|
10
24
|
/**
|