@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
|
@@ -4,7 +4,6 @@ import { sign as signImpl, verify as verifyImpl, } from "./primitives/nodeCrypto
|
|
|
4
4
|
import { deriveKey as deriveKeyImpl } from "./operations/nodeCryptoProvider.derivation.js";
|
|
5
5
|
import { hashPassword as hashPasswordImpl, verifyPassword as verifyPasswordImpl, } from "./operations/nodeCryptoProvider.password.js";
|
|
6
6
|
import { randomBytesImpl, randomIntImpl, randomUUIDImpl, } from "./primitives/nodeCryptoProvider.random.js";
|
|
7
|
-
import { cryptoHashError, cryptoCipherError, cryptoSignatureError, cryptoKeyDerivationError, } from "@zudojs/errors";
|
|
8
7
|
export class NodeCryptoProvider {
|
|
9
8
|
name = "node";
|
|
10
9
|
capabilities = {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { HashAlgorithm, HmacAlgorithm } from "../../cryptoProvider/index.js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes any `CryptoInput` into bytes (strings are UTF-8 encoded).
|
|
4
|
+
*/
|
|
3
5
|
export declare function toBytes(input: Uint8Array | string | ArrayBuffer): Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* Maps a package hash algorithm name to the OpenSSL digest name.
|
|
8
|
+
*
|
|
9
|
+
* Only the allowlisted algorithms are accepted; anything else (md5, sha1,
|
|
10
|
+
* arbitrary strings from configuration) throws.
|
|
11
|
+
*/
|
|
4
12
|
export declare function nodeHashAlgorithm(algorithm: HashAlgorithm | HmacAlgorithm): string;
|
|
5
|
-
export declare function nodeSignatureAlgorithm(algorithm: SignatureAlgorithm): string;
|
|
6
|
-
export declare function toBase64Url(bytes: Uint8Array): string;
|
|
7
|
-
export declare function fromBase64Url(value: string): Uint8Array;
|
|
8
13
|
//# sourceMappingURL=nodeCryptoProvider.helper.d.ts.map
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes any `CryptoInput` into bytes (strings are UTF-8 encoded).
|
|
3
|
+
*/
|
|
1
4
|
export function toBytes(input) {
|
|
2
5
|
if (input instanceof Uint8Array) {
|
|
3
6
|
return input;
|
|
@@ -5,51 +8,30 @@ export function toBytes(input) {
|
|
|
5
8
|
if (typeof input === "string") {
|
|
6
9
|
return new Uint8Array(Buffer.from(input, "utf8"));
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export function nodeHashAlgorithm(algorithm) {
|
|
11
|
-
const map = {
|
|
12
|
-
sha256: "sha256",
|
|
13
|
-
sha384: "sha384",
|
|
14
|
-
sha512: "sha512",
|
|
15
|
-
"sha3-256": "sha3-256",
|
|
16
|
-
"sha3-384": "sha3-384",
|
|
17
|
-
"sha3-512": "sha3-512",
|
|
18
|
-
};
|
|
19
|
-
return map[algorithm] ?? algorithm;
|
|
20
|
-
}
|
|
21
|
-
export function nodeSignatureAlgorithm(algorithm) {
|
|
22
|
-
switch (algorithm) {
|
|
23
|
-
case "rsa-sha256":
|
|
24
|
-
return "RSA-SHA256";
|
|
25
|
-
case "rsa-sha384":
|
|
26
|
-
return "RSA-SHA384";
|
|
27
|
-
case "rsa-sha512":
|
|
28
|
-
return "RSA-SHA512";
|
|
29
|
-
case "ecdsa-sha256":
|
|
30
|
-
return "ecdsa-SHA256";
|
|
31
|
-
case "ecdsa-sha384":
|
|
32
|
-
return "ecdsa-SHA384";
|
|
33
|
-
case "ecdsa-sha512":
|
|
34
|
-
return "ecdsa-SHA512";
|
|
35
|
-
case "ed25519":
|
|
36
|
-
return "ed25519";
|
|
37
|
-
default:
|
|
38
|
-
throw new TypeError(`Unsupported signature algorithm: ${algorithm}.`);
|
|
11
|
+
if (input instanceof ArrayBuffer) {
|
|
12
|
+
return new Uint8Array(input);
|
|
39
13
|
}
|
|
14
|
+
throw new TypeError("Input must be a string, Uint8Array, or ArrayBuffer.");
|
|
40
15
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
16
|
+
const NODE_HASH_ALGORITHMS = Object.freeze({
|
|
17
|
+
sha256: "sha256",
|
|
18
|
+
sha384: "sha384",
|
|
19
|
+
sha512: "sha512",
|
|
20
|
+
"sha3-256": "sha3-256",
|
|
21
|
+
"sha3-384": "sha3-384",
|
|
22
|
+
"sha3-512": "sha3-512",
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Maps a package hash algorithm name to the OpenSSL digest name.
|
|
26
|
+
*
|
|
27
|
+
* Only the allowlisted algorithms are accepted; anything else (md5, sha1,
|
|
28
|
+
* arbitrary strings from configuration) throws.
|
|
29
|
+
*/
|
|
30
|
+
export function nodeHashAlgorithm(algorithm) {
|
|
31
|
+
const name = typeof algorithm === "string" ? NODE_HASH_ALGORITHMS[algorithm] : undefined;
|
|
32
|
+
if (name === undefined) {
|
|
33
|
+
throw new TypeError(`Unsupported hash algorithm: ${String(algorithm)}.`);
|
|
52
34
|
}
|
|
53
|
-
return
|
|
35
|
+
return name;
|
|
54
36
|
}
|
|
55
37
|
//# sourceMappingURL=nodeCryptoProvider.helper.js.map
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { DeriveKeyOptions } from "../../../cryptoProvider/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Computes a memory bound for scrypt from its parameters.
|
|
4
|
+
*
|
|
5
|
+
* OpenSSL requires roughly `128 * N * r` bytes plus `128 * r * p`; we
|
|
6
|
+
* double that for margin and never go below Node's own 32 MiB default.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defaultScryptMaxMemory(N: number, r: number, p: number): number;
|
|
2
9
|
export declare function deriveKey(options: DeriveKeyOptions): Promise<Uint8Array>;
|
|
3
10
|
//# sourceMappingURL=nodeCryptoProvider.derivation.d.ts.map
|
|
@@ -1,45 +1,127 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { isPbkdf2Digest } from "../../../cryptoProvider/cryptoProvider.type.js";
|
|
2
|
+
import { pbkdf2, scrypt } from "node:crypto";
|
|
3
|
+
import { toBytes } from "../nodeCryptoProvider.helper.js";
|
|
4
|
+
import { keyDerivationError } from "../../../cryptoErrors/cryptoErrors.helper.js";
|
|
5
|
+
import { PASSWORD_HASH } from "../../../cryptoConstants/cryptoConstants.security.js";
|
|
6
|
+
/** Hard floors applied at the provider boundary. */
|
|
7
|
+
const PROVIDER_MIN_SALT_BYTES = 16;
|
|
8
|
+
const PROVIDER_MIN_KEY_BYTES = 16;
|
|
9
|
+
const PROVIDER_MIN_PBKDF2_ITERATIONS = 1_000;
|
|
10
|
+
/**
|
|
11
|
+
* Hard ceilings applied at the provider boundary.
|
|
12
|
+
*
|
|
13
|
+
* The provider is reachable directly (`provider.deriveKey`) and through
|
|
14
|
+
* custom wrappers, so the same `PASSWORD_HASH.LIMITS` that bound stored
|
|
15
|
+
* password hashes are enforced here too. Without them the scrypt memory
|
|
16
|
+
* bound was computed from the requested cost, which is no bound at all.
|
|
17
|
+
*/
|
|
18
|
+
const PROVIDER_LIMITS = PASSWORD_HASH.LIMITS;
|
|
19
|
+
const DEFAULT_PBKDF2_ITERATIONS = 600_000;
|
|
20
|
+
const DEFAULT_SCRYPT_COST = 16_384;
|
|
21
|
+
const DEFAULT_SCRYPT_BLOCK_SIZE = 8;
|
|
22
|
+
const DEFAULT_SCRYPT_PARALLELISM = 1;
|
|
23
|
+
const NODE_DEFAULT_MAXMEM = 32 * 1024 * 1024;
|
|
24
|
+
/**
|
|
25
|
+
* Computes a memory bound for scrypt from its parameters.
|
|
26
|
+
*
|
|
27
|
+
* OpenSSL requires roughly `128 * N * r` bytes plus `128 * r * p`; we
|
|
28
|
+
* double that for margin and never go below Node's own 32 MiB default.
|
|
29
|
+
*/
|
|
30
|
+
export function defaultScryptMaxMemory(N, r, p) {
|
|
31
|
+
return Math.max(NODE_DEFAULT_MAXMEM, 2 * (128 * N * r + 128 * r * p));
|
|
32
|
+
}
|
|
33
|
+
function validateCommon(options, algorithm) {
|
|
5
34
|
const password = toBytes(options.password);
|
|
6
35
|
const salt = options.salt;
|
|
36
|
+
const keyLength = options.keyLength ?? 32;
|
|
37
|
+
if (!(salt instanceof Uint8Array) || salt.byteLength < PROVIDER_MIN_SALT_BYTES) {
|
|
38
|
+
throw keyDerivationError(`Salt must be at least ${PROVIDER_MIN_SALT_BYTES} bytes.`, algorithm);
|
|
39
|
+
}
|
|
40
|
+
if (!Number.isInteger(keyLength) ||
|
|
41
|
+
keyLength < PROVIDER_MIN_KEY_BYTES ||
|
|
42
|
+
keyLength > PROVIDER_LIMITS.MAX_DERIVED_KEY_BYTES) {
|
|
43
|
+
throw keyDerivationError(`keyLength must be an integer between ${PROVIDER_MIN_KEY_BYTES} and ${PROVIDER_LIMITS.MAX_DERIVED_KEY_BYTES}.`, algorithm);
|
|
44
|
+
}
|
|
45
|
+
return { password, salt, keyLength };
|
|
46
|
+
}
|
|
47
|
+
export async function deriveKey(options) {
|
|
7
48
|
switch (options.algorithm) {
|
|
8
49
|
case "pbkdf2": {
|
|
50
|
+
const { password, salt, keyLength } = validateCommon(options, "pbkdf2");
|
|
51
|
+
const iterations = options.iterations ?? DEFAULT_PBKDF2_ITERATIONS;
|
|
52
|
+
const digest = options.digest ?? "sha256";
|
|
53
|
+
if (!Number.isInteger(iterations) ||
|
|
54
|
+
iterations < PROVIDER_MIN_PBKDF2_ITERATIONS ||
|
|
55
|
+
iterations > PROVIDER_LIMITS.MAX_PBKDF2_ITERATIONS) {
|
|
56
|
+
throw keyDerivationError(`PBKDF2 iterations must be an integer between ${PROVIDER_MIN_PBKDF2_ITERATIONS} and ${PROVIDER_LIMITS.MAX_PBKDF2_ITERATIONS}.`, "pbkdf2");
|
|
57
|
+
}
|
|
58
|
+
if (!isPbkdf2Digest(digest)) {
|
|
59
|
+
throw keyDerivationError(`Unsupported PBKDF2 digest: ${String(digest)}.`, "pbkdf2");
|
|
60
|
+
}
|
|
9
61
|
return new Promise((resolve, reject) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
62
|
+
try {
|
|
63
|
+
pbkdf2(Buffer.from(password), Buffer.from(salt), iterations, keyLength, digest, (err, derived) => {
|
|
64
|
+
if (err) {
|
|
65
|
+
reject(keyDerivationError("Key derivation failed.", "pbkdf2", err));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
resolve(new Uint8Array(derived));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
reject(keyDerivationError("Key derivation failed.", "pbkdf2", error));
|
|
74
|
+
}
|
|
19
75
|
});
|
|
20
76
|
}
|
|
21
77
|
case "scrypt": {
|
|
78
|
+
const { password, salt, keyLength } = validateCommon(options, "scrypt");
|
|
79
|
+
const N = options.memoryCost ?? DEFAULT_SCRYPT_COST;
|
|
80
|
+
const r = options.blockSize ?? DEFAULT_SCRYPT_BLOCK_SIZE;
|
|
81
|
+
const p = options.parallelism ?? DEFAULT_SCRYPT_PARALLELISM;
|
|
82
|
+
if (!Number.isInteger(N) ||
|
|
83
|
+
N < 2 ||
|
|
84
|
+
N > PROVIDER_LIMITS.MAX_SCRYPT_COST ||
|
|
85
|
+
(N & (N - 1)) !== 0) {
|
|
86
|
+
throw keyDerivationError(`scrypt cost must be a power of two between 2 and ${PROVIDER_LIMITS.MAX_SCRYPT_COST}.`, "scrypt");
|
|
87
|
+
}
|
|
88
|
+
if (!Number.isInteger(r) ||
|
|
89
|
+
r <= 0 ||
|
|
90
|
+
r > PROVIDER_LIMITS.MAX_SCRYPT_BLOCK_SIZE) {
|
|
91
|
+
throw keyDerivationError(`scrypt blockSize must be an integer between 1 and ${PROVIDER_LIMITS.MAX_SCRYPT_BLOCK_SIZE}.`, "scrypt");
|
|
92
|
+
}
|
|
93
|
+
if (!Number.isInteger(p) ||
|
|
94
|
+
p <= 0 ||
|
|
95
|
+
p > PROVIDER_LIMITS.MAX_SCRYPT_PARALLELIZATION) {
|
|
96
|
+
throw keyDerivationError(`scrypt parallelism must be an integer between 1 and ${PROVIDER_LIMITS.MAX_SCRYPT_PARALLELIZATION}.`, "scrypt");
|
|
97
|
+
}
|
|
98
|
+
if (128 * N * r > PROVIDER_LIMITS.MAX_SCRYPT_MEMORY_BYTES) {
|
|
99
|
+
throw keyDerivationError(`scrypt cost * blockSize exceeds the memory bound of ${PROVIDER_LIMITS.MAX_SCRYPT_MEMORY_BYTES} bytes.`, "scrypt");
|
|
100
|
+
}
|
|
101
|
+
const maxmem = options.maxMemory ?? defaultScryptMaxMemory(N, r, p);
|
|
102
|
+
if (!Number.isInteger(maxmem) || maxmem <= 0) {
|
|
103
|
+
throw keyDerivationError("scrypt maxMemory must be a positive integer.", "scrypt");
|
|
104
|
+
}
|
|
22
105
|
return new Promise((resolve, reject) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
106
|
+
try {
|
|
107
|
+
scrypt(Buffer.from(password), Buffer.from(salt), keyLength, { N, r, p, maxmem }, (err, derived) => {
|
|
108
|
+
if (err) {
|
|
109
|
+
reject(keyDerivationError("Key derivation failed.", "scrypt", err));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
resolve(new Uint8Array(derived));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
reject(keyDerivationError("Key derivation failed.", "scrypt", error));
|
|
118
|
+
}
|
|
36
119
|
});
|
|
37
120
|
}
|
|
38
|
-
case "argon2id": {
|
|
39
|
-
throw new TypeError("Argon2id requires the argon2 package.");
|
|
40
|
-
}
|
|
41
121
|
default:
|
|
42
|
-
throw
|
|
122
|
+
throw keyDerivationError(`Unsupported key derivation algorithm: ${String(options.algorithm)}.`, typeof options.algorithm === "string"
|
|
123
|
+
? String(options.algorithm)
|
|
124
|
+
: undefined);
|
|
43
125
|
}
|
|
44
126
|
}
|
|
45
127
|
//# sourceMappingURL=nodeCryptoProvider.derivation.js.map
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import type { CryptoInput,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { CryptoInput, PasswordHashProviderOptions } from "../../../cryptoProvider/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Hashes a password with scrypt (default) or PBKDF2 and returns the
|
|
4
|
+
* self-describing, versioned encoding produced by `encodePasswordHash`.
|
|
5
|
+
*
|
|
6
|
+
* The encoded string is validated against `PASSWORD_HASH.LIMITS`, so the
|
|
7
|
+
* provider refuses insecure parameters (short salts, tiny work factors)
|
|
8
|
+
* instead of producing a hash that can never be verified.
|
|
9
|
+
*/
|
|
10
|
+
export declare function hashPassword(password: CryptoInput, options?: PasswordHashProviderOptions): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Verifies a password against an encoded hash.
|
|
13
|
+
*
|
|
14
|
+
* Returns false for any malformed, foreign or out-of-bounds hash string
|
|
15
|
+
* instead of throwing, so login paths fail closed. The hash is decoded
|
|
16
|
+
* and validated before any derivation work is done.
|
|
17
|
+
*/
|
|
11
18
|
export declare function verifyPassword(password: CryptoInput, hash: string): Promise<boolean>;
|
|
12
19
|
//# sourceMappingURL=nodeCryptoProvider.password.d.ts.map
|
|
@@ -1,94 +1,134 @@
|
|
|
1
|
-
import { randomBytes
|
|
2
|
-
import { toBytes
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { toBytes } from "../nodeCryptoProvider.helper.js";
|
|
3
|
+
import { timingSafeEqual } from "../../../compare/compare.helper.js";
|
|
4
|
+
import { CryptoAlgorithm } from "../../../cryptoConstants/cryptoConstants.type.js";
|
|
5
|
+
import { PASSWORD_HASH } from "../../../cryptoConstants/cryptoConstants.security.js";
|
|
6
|
+
import { PASSWORD_FORMAT_VERSION, decodePasswordHash, encodePasswordHash, pbkdf2PasswordAlgorithm, } from "../../../cryptoPassword/cryptoPassword.codec.js";
|
|
7
|
+
import { deriveKey } from "./nodeCryptoProvider.derivation.js";
|
|
8
|
+
import { keyDerivationError } from "../../../cryptoErrors/cryptoErrors.helper.js";
|
|
9
|
+
/**
|
|
10
|
+
* Hashes a password with scrypt (default) or PBKDF2 and returns the
|
|
11
|
+
* self-describing, versioned encoding produced by `encodePasswordHash`.
|
|
12
|
+
*
|
|
13
|
+
* The encoded string is validated against `PASSWORD_HASH.LIMITS`, so the
|
|
14
|
+
* provider refuses insecure parameters (short salts, tiny work factors)
|
|
15
|
+
* instead of producing a hash that can never be verified.
|
|
16
|
+
*/
|
|
5
17
|
export async function hashPassword(password, options) {
|
|
6
18
|
const algorithm = options?.algorithm ?? "scrypt";
|
|
7
|
-
const salt = options?.salt ?? randomBytes(
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
let hash;
|
|
19
|
+
const salt = options?.salt ?? new Uint8Array(randomBytes(PASSWORD_HASH.SALT_BYTES));
|
|
20
|
+
const keyBytes = options?.keyBytes ?? PASSWORD_HASH.KEY_BYTES;
|
|
21
|
+
const passwordBytes = toBytes(password);
|
|
11
22
|
switch (algorithm) {
|
|
12
23
|
case "scrypt": {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const cost = options?.memoryCost ?? PASSWORD_HASH.SCRYPT.COST;
|
|
25
|
+
const blockSize = options?.blockSize ?? PASSWORD_HASH.SCRYPT.BLOCK_SIZE;
|
|
26
|
+
const parallelization = options?.parallelism ?? PASSWORD_HASH.SCRYPT.PARALLELIZATION;
|
|
27
|
+
// Validate before deriving so invalid parameters fail fast.
|
|
28
|
+
const placeholder = new Uint8Array(keyBytes);
|
|
29
|
+
encodePasswordHash({
|
|
30
|
+
version: PASSWORD_FORMAT_VERSION,
|
|
31
|
+
algorithm: CryptoAlgorithm.SCRYPT,
|
|
32
|
+
salt,
|
|
33
|
+
hash: placeholder,
|
|
34
|
+
cost,
|
|
35
|
+
blockSize,
|
|
36
|
+
parallelization,
|
|
37
|
+
});
|
|
38
|
+
const hash = await deriveKey({
|
|
39
|
+
password: passwordBytes,
|
|
40
|
+
salt,
|
|
41
|
+
algorithm: "scrypt",
|
|
42
|
+
keyLength: keyBytes,
|
|
43
|
+
memoryCost: cost,
|
|
44
|
+
blockSize,
|
|
45
|
+
parallelism: parallelization,
|
|
46
|
+
});
|
|
47
|
+
return encodePasswordHash({
|
|
48
|
+
version: PASSWORD_FORMAT_VERSION,
|
|
49
|
+
algorithm: CryptoAlgorithm.SCRYPT,
|
|
50
|
+
salt,
|
|
51
|
+
hash,
|
|
52
|
+
cost,
|
|
53
|
+
blockSize,
|
|
54
|
+
parallelization,
|
|
27
55
|
});
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
case "argon2id": {
|
|
31
|
-
throw new TypeError("Argon2id requires the argon2 package.");
|
|
32
56
|
}
|
|
33
57
|
case "pbkdf2": {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
const iterations = options?.timeCost ?? PASSWORD_HASH.PBKDF2.ITERATIONS;
|
|
59
|
+
const digest = options?.digest ?? "sha256";
|
|
60
|
+
const label = pbkdf2PasswordAlgorithm(digest);
|
|
61
|
+
const placeholder = new Uint8Array(keyBytes);
|
|
62
|
+
encodePasswordHash({
|
|
63
|
+
version: PASSWORD_FORMAT_VERSION,
|
|
64
|
+
algorithm: label,
|
|
65
|
+
digest,
|
|
66
|
+
salt,
|
|
67
|
+
hash: placeholder,
|
|
68
|
+
iterations,
|
|
69
|
+
});
|
|
70
|
+
const hash = await deriveKey({
|
|
71
|
+
password: passwordBytes,
|
|
72
|
+
salt,
|
|
73
|
+
algorithm: "pbkdf2",
|
|
74
|
+
keyLength: keyBytes,
|
|
75
|
+
iterations,
|
|
76
|
+
digest,
|
|
77
|
+
});
|
|
78
|
+
return encodePasswordHash({
|
|
79
|
+
version: PASSWORD_FORMAT_VERSION,
|
|
80
|
+
algorithm: label,
|
|
81
|
+
digest,
|
|
82
|
+
salt,
|
|
83
|
+
hash,
|
|
84
|
+
iterations,
|
|
44
85
|
});
|
|
45
|
-
break;
|
|
46
86
|
}
|
|
47
87
|
default:
|
|
48
|
-
throw
|
|
88
|
+
throw keyDerivationError(`Unsupported password algorithm: ${String(algorithm)}.`, typeof algorithm === "string" ? algorithm : undefined);
|
|
49
89
|
}
|
|
50
|
-
const saltB64 = toBase64Url(salt);
|
|
51
|
-
const hashB64 = toBase64Url(hash);
|
|
52
|
-
return [
|
|
53
|
-
PASSWORD_FORMAT_VERSION,
|
|
54
|
-
algorithm,
|
|
55
|
-
options?.memoryCost ?? 16384,
|
|
56
|
-
blockSize,
|
|
57
|
-
options?.parallelism ?? 1,
|
|
58
|
-
`${saltB64}.${hashB64}`,
|
|
59
|
-
].join("$");
|
|
60
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Verifies a password against an encoded hash.
|
|
93
|
+
*
|
|
94
|
+
* Returns false for any malformed, foreign or out-of-bounds hash string
|
|
95
|
+
* instead of throwing, so login paths fail closed. The hash is decoded
|
|
96
|
+
* and validated before any derivation work is done.
|
|
97
|
+
*/
|
|
61
98
|
export async function verifyPassword(password, hash) {
|
|
62
|
-
|
|
63
|
-
if (parts.length !== 6 || parts[0] !== "v1") {
|
|
99
|
+
if (typeof hash !== "string") {
|
|
64
100
|
return false;
|
|
65
101
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
102
|
+
let decoded;
|
|
103
|
+
try {
|
|
104
|
+
decoded = decodePasswordHash(hash);
|
|
69
105
|
}
|
|
70
|
-
|
|
71
|
-
if (payloadParts.length !== 2) {
|
|
106
|
+
catch {
|
|
72
107
|
return false;
|
|
73
108
|
}
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
109
|
+
const passwordBytes = toBytes(password);
|
|
110
|
+
let expected;
|
|
111
|
+
if (decoded.algorithm === CryptoAlgorithm.SCRYPT) {
|
|
112
|
+
expected = await deriveKey({
|
|
113
|
+
password: passwordBytes,
|
|
114
|
+
salt: decoded.salt,
|
|
115
|
+
algorithm: "scrypt",
|
|
116
|
+
keyLength: decoded.hash.byteLength,
|
|
117
|
+
memoryCost: decoded.cost,
|
|
118
|
+
blockSize: decoded.blockSize,
|
|
119
|
+
parallelism: decoded.parallelization,
|
|
120
|
+
});
|
|
77
121
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (computedParts.length !== 6) {
|
|
88
|
-
return false;
|
|
122
|
+
else {
|
|
123
|
+
expected = await deriveKey({
|
|
124
|
+
password: passwordBytes,
|
|
125
|
+
salt: decoded.salt,
|
|
126
|
+
algorithm: "pbkdf2",
|
|
127
|
+
keyLength: decoded.hash.byteLength,
|
|
128
|
+
iterations: decoded.iterations,
|
|
129
|
+
digest: decoded.digest,
|
|
130
|
+
});
|
|
89
131
|
}
|
|
90
|
-
|
|
91
|
-
const decoded = decodePasswordHash(hash);
|
|
92
|
-
return timingSafeEqual(decoded.hash, expectedHash);
|
|
132
|
+
return timingSafeEqual(decoded.hash, expected);
|
|
93
133
|
}
|
|
94
134
|
//# sourceMappingURL=nodeCryptoProvider.password.js.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function encrypt(options:
|
|
3
|
-
|
|
4
|
-
plaintext: CryptoInput;
|
|
5
|
-
associatedData?: CryptoInput;
|
|
6
|
-
nonce?: Uint8Array;
|
|
7
|
-
}): Promise<EncryptedData>;
|
|
8
|
-
export declare function decrypt(options: {
|
|
9
|
-
key: CryptoInput;
|
|
10
|
-
encrypted: EncryptedData;
|
|
11
|
-
associatedData?: CryptoInput;
|
|
12
|
-
}): Promise<Uint8Array>;
|
|
1
|
+
import type { EncryptedData, EncryptOptions, DecryptOptions } from "../../../cryptoProvider/index.js";
|
|
2
|
+
export declare function encrypt(options: EncryptOptions): Promise<EncryptedData>;
|
|
3
|
+
export declare function decrypt(options: DecryptOptions): Promise<Uint8Array>;
|
|
13
4
|
//# sourceMappingURL=nodeCryptoProvider.encryption.d.ts.map
|
|
@@ -1,35 +1,84 @@
|
|
|
1
1
|
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
2
|
+
import { CryptoOperation } from "@zudojs/errors";
|
|
2
3
|
import { toBytes } from "../nodeCryptoProvider.helper.js";
|
|
4
|
+
import { AES_GCM } from "../../../cryptoConstants/cryptoConstants.type.js";
|
|
5
|
+
import { cipherError } from "../../../cryptoErrors/cryptoErrors.helper.js";
|
|
6
|
+
const ALGORITHM = "aes-256-gcm";
|
|
7
|
+
/**
|
|
8
|
+
* Validates the caller-controlled inputs to AES-256-GCM before they reach
|
|
9
|
+
* OpenSSL, so that the error surface is uniform and short tags / odd IVs
|
|
10
|
+
* are never accepted.
|
|
11
|
+
*/
|
|
12
|
+
function assertKey(key, operation) {
|
|
13
|
+
if (key.byteLength !== AES_GCM.KEY_BYTES) {
|
|
14
|
+
throw cipherError(`AES-256-GCM key must be ${AES_GCM.KEY_BYTES} bytes.`, operation, ALGORITHM);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function assertNonce(nonce, operation) {
|
|
18
|
+
if (!(nonce instanceof Uint8Array) || nonce.byteLength !== AES_GCM.IV_BYTES) {
|
|
19
|
+
throw cipherError(`AES-256-GCM nonce must be ${AES_GCM.IV_BYTES} bytes.`, operation, ALGORITHM);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function assertTag(tag) {
|
|
23
|
+
if (!(tag instanceof Uint8Array) ||
|
|
24
|
+
tag.byteLength !== AES_GCM.AUTH_TAG_BYTES) {
|
|
25
|
+
throw cipherError(`AES-256-GCM authentication tag must be ${AES_GCM.AUTH_TAG_BYTES} bytes.`, CryptoOperation.DECRYPT, ALGORITHM);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
3
28
|
export async function encrypt(options) {
|
|
4
29
|
const key = toBytes(options.key);
|
|
5
30
|
const plaintext = toBytes(options.plaintext);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
cipher
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ciphertext
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
const nonce = options.nonce ?? new Uint8Array(randomBytes(AES_GCM.IV_BYTES));
|
|
32
|
+
assertKey(key, CryptoOperation.ENCRYPT);
|
|
33
|
+
assertNonce(nonce, CryptoOperation.ENCRYPT);
|
|
34
|
+
try {
|
|
35
|
+
const cipher = createCipheriv(ALGORITHM, key, nonce, {
|
|
36
|
+
authTagLength: AES_GCM.AUTH_TAG_BYTES,
|
|
37
|
+
});
|
|
38
|
+
if (options.associatedData !== undefined) {
|
|
39
|
+
cipher.setAAD(toBytes(options.associatedData));
|
|
40
|
+
}
|
|
41
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
42
|
+
const tag = cipher.getAuthTag();
|
|
43
|
+
return Object.freeze({
|
|
44
|
+
algorithm: ALGORITHM,
|
|
45
|
+
ciphertext: new Uint8Array(ciphertext),
|
|
46
|
+
nonce: new Uint8Array(nonce),
|
|
47
|
+
tag: new Uint8Array(tag),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw cipherError("Encryption failed.", CryptoOperation.ENCRYPT, ALGORITHM, error);
|
|
52
|
+
}
|
|
20
53
|
}
|
|
21
54
|
export async function decrypt(options) {
|
|
22
55
|
const key = toBytes(options.key);
|
|
23
|
-
const { ciphertext, nonce, tag } = options.encrypted;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
56
|
+
const { ciphertext, nonce, tag, algorithm } = options.encrypted;
|
|
57
|
+
if (algorithm !== ALGORITHM) {
|
|
58
|
+
throw cipherError(`Unsupported encryption algorithm: ${String(algorithm)}.`, CryptoOperation.DECRYPT, typeof algorithm === "string" ? algorithm : undefined);
|
|
59
|
+
}
|
|
60
|
+
assertKey(key, CryptoOperation.DECRYPT);
|
|
61
|
+
assertNonce(nonce, CryptoOperation.DECRYPT);
|
|
62
|
+
assertTag(tag);
|
|
63
|
+
if (!(ciphertext instanceof Uint8Array)) {
|
|
64
|
+
throw cipherError("Ciphertext must be a Uint8Array.", CryptoOperation.DECRYPT, ALGORITHM);
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const decipher = createDecipheriv(ALGORITHM, key, nonce, {
|
|
68
|
+
authTagLength: AES_GCM.AUTH_TAG_BYTES,
|
|
69
|
+
});
|
|
70
|
+
if (options.associatedData !== undefined) {
|
|
71
|
+
decipher.setAAD(toBytes(options.associatedData));
|
|
72
|
+
}
|
|
73
|
+
decipher.setAuthTag(tag);
|
|
74
|
+
const decrypted = Buffer.concat([
|
|
75
|
+
decipher.update(ciphertext),
|
|
76
|
+
decipher.final(),
|
|
77
|
+
]);
|
|
78
|
+
return new Uint8Array(decrypted);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw cipherError("Decryption failed.", CryptoOperation.DECRYPT, ALGORITHM, error);
|
|
82
|
+
}
|
|
34
83
|
}
|
|
35
84
|
//# sourceMappingURL=nodeCryptoProvider.encryption.js.map
|