@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,30 +1,145 @@
|
|
|
1
1
|
import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
|
|
2
|
-
import { decodeBase64Url, parsePositiveInteger, validateParameters, } from "./cryptoPassword.validate.js";
|
|
2
|
+
import { decodeBase64Url, parsePositiveInteger, validateParameters, validatePbkdf2Parameters, } from "./cryptoPassword.validate.js";
|
|
3
3
|
/**
|
|
4
4
|
* Current password hash encoding format version.
|
|
5
5
|
*/
|
|
6
6
|
export const PASSWORD_FORMAT_VERSION = "v1";
|
|
7
|
+
const PBKDF2_ALGORITHMS = new Map([
|
|
8
|
+
[CryptoAlgorithm.PBKDF2_SHA256, "sha256"],
|
|
9
|
+
[CryptoAlgorithm.PBKDF2_SHA384, "sha384"],
|
|
10
|
+
[CryptoAlgorithm.PBKDF2_SHA512, "sha512"],
|
|
11
|
+
]);
|
|
12
|
+
/**
|
|
13
|
+
* Returns the PBKDF2 password algorithm label for a digest.
|
|
14
|
+
*/
|
|
15
|
+
export function pbkdf2PasswordAlgorithm(digest) {
|
|
16
|
+
switch (digest) {
|
|
17
|
+
case "sha256":
|
|
18
|
+
return CryptoAlgorithm.PBKDF2_SHA256;
|
|
19
|
+
case "sha384":
|
|
20
|
+
return CryptoAlgorithm.PBKDF2_SHA384;
|
|
21
|
+
case "sha512":
|
|
22
|
+
return CryptoAlgorithm.PBKDF2_SHA512;
|
|
23
|
+
default:
|
|
24
|
+
throw new TypeError(`Unsupported PBKDF2 digest: ${String(digest)}.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
7
27
|
/**
|
|
8
28
|
* Decodes an encoded password hash into its parameters.
|
|
29
|
+
*
|
|
30
|
+
* Supported formats:
|
|
31
|
+
*
|
|
32
|
+
* - `v1$scrypt$<N>$<r>$<p>$<salt>.<hash>`
|
|
33
|
+
* - `v1$pbkdf2-<digest>$<iterations>$<salt>.<hash>`
|
|
34
|
+
*
|
|
35
|
+
* All binary fields are canonical Base64URL. Parameters are validated
|
|
36
|
+
* against `PASSWORD_HASH.LIMITS`, so a decoded hash is always safe to
|
|
37
|
+
* re-derive.
|
|
9
38
|
*/
|
|
10
39
|
export function decodePasswordHash(encoded) {
|
|
11
40
|
if (typeof encoded !== "string" || encoded.length === 0) {
|
|
12
41
|
throw new TypeError("Password hash must be a non-empty string.");
|
|
13
42
|
}
|
|
14
43
|
const parts = encoded.split("$");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
const [version, algorithm, costPart, blockSizePart, parallelizationPart, payload,] = parts;
|
|
44
|
+
const version = parts[0];
|
|
45
|
+
const algorithm = parts[1];
|
|
19
46
|
if (version !== PASSWORD_FORMAT_VERSION) {
|
|
20
|
-
throw new TypeError(`Unsupported password hash version: ${version}.`);
|
|
47
|
+
throw new TypeError(`Unsupported password hash version: ${String(version)}.`);
|
|
48
|
+
}
|
|
49
|
+
if (algorithm === CryptoAlgorithm.SCRYPT) {
|
|
50
|
+
if (parts.length !== 6) {
|
|
51
|
+
throw new TypeError("Invalid password hash format.");
|
|
52
|
+
}
|
|
53
|
+
const [, , costPart, blockSizePart, parallelizationPart, payload] = parts;
|
|
54
|
+
const cost = parsePositiveInteger(costPart, "cost");
|
|
55
|
+
const blockSize = parsePositiveInteger(blockSizePart, "blockSize");
|
|
56
|
+
const parallelization = parsePositiveInteger(parallelizationPart, "parallelization");
|
|
57
|
+
const { salt, hash } = decodePayload(payload);
|
|
58
|
+
validateParameters({
|
|
59
|
+
saltBytes: salt.byteLength,
|
|
60
|
+
keyBytes: hash.byteLength,
|
|
61
|
+
cost,
|
|
62
|
+
blockSize,
|
|
63
|
+
parallelization,
|
|
64
|
+
});
|
|
65
|
+
return Object.freeze({
|
|
66
|
+
version,
|
|
67
|
+
algorithm: CryptoAlgorithm.SCRYPT,
|
|
68
|
+
salt,
|
|
69
|
+
hash,
|
|
70
|
+
cost,
|
|
71
|
+
blockSize,
|
|
72
|
+
parallelization,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const digest = algorithm === undefined ? undefined : PBKDF2_ALGORITHMS.get(algorithm);
|
|
76
|
+
if (digest !== undefined) {
|
|
77
|
+
if (parts.length !== 4) {
|
|
78
|
+
throw new TypeError("Invalid password hash format.");
|
|
79
|
+
}
|
|
80
|
+
const [, , iterationsPart, payload] = parts;
|
|
81
|
+
const iterations = parsePositiveInteger(iterationsPart, "iterations");
|
|
82
|
+
const { salt, hash } = decodePayload(payload);
|
|
83
|
+
validatePbkdf2Parameters({
|
|
84
|
+
saltBytes: salt.byteLength,
|
|
85
|
+
keyBytes: hash.byteLength,
|
|
86
|
+
iterations,
|
|
87
|
+
});
|
|
88
|
+
return Object.freeze({
|
|
89
|
+
version,
|
|
90
|
+
algorithm: algorithm,
|
|
91
|
+
digest,
|
|
92
|
+
salt,
|
|
93
|
+
hash,
|
|
94
|
+
iterations,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
throw new TypeError(`Unsupported password hash algorithm: ${String(algorithm)}.`);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Encodes password hashing parameters into a portable string.
|
|
101
|
+
*/
|
|
102
|
+
export function encodePasswordHash(parameters) {
|
|
103
|
+
if (parameters.version !== PASSWORD_FORMAT_VERSION) {
|
|
104
|
+
throw new TypeError(`Unsupported password hash version: ${parameters.version}.`);
|
|
21
105
|
}
|
|
22
|
-
|
|
23
|
-
|
|
106
|
+
const payload = [
|
|
107
|
+
Buffer.from(parameters.salt).toString("base64url"),
|
|
108
|
+
Buffer.from(parameters.hash).toString("base64url"),
|
|
109
|
+
].join(".");
|
|
110
|
+
if (parameters.algorithm === CryptoAlgorithm.SCRYPT) {
|
|
111
|
+
validateParameters({
|
|
112
|
+
saltBytes: parameters.salt.byteLength,
|
|
113
|
+
keyBytes: parameters.hash.byteLength,
|
|
114
|
+
cost: parameters.cost,
|
|
115
|
+
blockSize: parameters.blockSize,
|
|
116
|
+
parallelization: parameters.parallelization,
|
|
117
|
+
});
|
|
118
|
+
return [
|
|
119
|
+
parameters.version,
|
|
120
|
+
parameters.algorithm,
|
|
121
|
+
parameters.cost,
|
|
122
|
+
parameters.blockSize,
|
|
123
|
+
parameters.parallelization,
|
|
124
|
+
payload,
|
|
125
|
+
].join("$");
|
|
24
126
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
127
|
+
if (PBKDF2_ALGORITHMS.has(parameters.algorithm)) {
|
|
128
|
+
validatePbkdf2Parameters({
|
|
129
|
+
saltBytes: parameters.salt.byteLength,
|
|
130
|
+
keyBytes: parameters.hash.byteLength,
|
|
131
|
+
iterations: parameters.iterations,
|
|
132
|
+
});
|
|
133
|
+
return [
|
|
134
|
+
parameters.version,
|
|
135
|
+
parameters.algorithm,
|
|
136
|
+
parameters.iterations,
|
|
137
|
+
payload,
|
|
138
|
+
].join("$");
|
|
139
|
+
}
|
|
140
|
+
throw new TypeError(`Unsupported password hash algorithm: ${String(parameters.algorithm)}.`);
|
|
141
|
+
}
|
|
142
|
+
function decodePayload(payload) {
|
|
28
143
|
const payloadParts = payload.split(".");
|
|
29
144
|
if (payloadParts.length !== 2) {
|
|
30
145
|
throw new TypeError("Invalid password hash payload.");
|
|
@@ -38,50 +153,6 @@ export function decodePasswordHash(encoded) {
|
|
|
38
153
|
if (hash.byteLength === 0) {
|
|
39
154
|
throw new TypeError("Password hash cannot be empty.");
|
|
40
155
|
}
|
|
41
|
-
|
|
42
|
-
saltBytes: salt.byteLength,
|
|
43
|
-
keyBytes: hash.byteLength,
|
|
44
|
-
cost,
|
|
45
|
-
blockSize,
|
|
46
|
-
parallelization,
|
|
47
|
-
});
|
|
48
|
-
return Object.freeze({
|
|
49
|
-
version,
|
|
50
|
-
algorithm: CryptoAlgorithm.SCRYPT,
|
|
51
|
-
salt,
|
|
52
|
-
hash,
|
|
53
|
-
cost,
|
|
54
|
-
blockSize,
|
|
55
|
-
parallelization,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Encodes password hashing parameters into a portable string.
|
|
60
|
-
*/
|
|
61
|
-
export function encodePasswordHash(parameters) {
|
|
62
|
-
if (parameters.algorithm !== CryptoAlgorithm.SCRYPT) {
|
|
63
|
-
throw new TypeError("Only scrypt password hashes are supported.");
|
|
64
|
-
}
|
|
65
|
-
validateParameters({
|
|
66
|
-
saltBytes: parameters.salt.byteLength,
|
|
67
|
-
keyBytes: parameters.hash.byteLength,
|
|
68
|
-
cost: parameters.cost,
|
|
69
|
-
blockSize: parameters.blockSize,
|
|
70
|
-
parallelization: parameters.parallelization,
|
|
71
|
-
});
|
|
72
|
-
if (parameters.version !== PASSWORD_FORMAT_VERSION) {
|
|
73
|
-
throw new TypeError(`Unsupported password hash version: ${parameters.version}.`);
|
|
74
|
-
}
|
|
75
|
-
return [
|
|
76
|
-
parameters.version,
|
|
77
|
-
parameters.algorithm,
|
|
78
|
-
parameters.cost,
|
|
79
|
-
parameters.blockSize,
|
|
80
|
-
parameters.parallelization,
|
|
81
|
-
[
|
|
82
|
-
Buffer.from(parameters.salt).toString("base64url"),
|
|
83
|
-
Buffer.from(parameters.hash).toString("base64url"),
|
|
84
|
-
].join("."),
|
|
85
|
-
].join("$");
|
|
156
|
+
return { salt, hash };
|
|
86
157
|
}
|
|
87
158
|
//# sourceMappingURL=cryptoPassword.codec.js.map
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
import type { CryptoProvider } from "../cryptoProvider/index.js";
|
|
1
2
|
import type { PasswordHashOptions, PasswordHashResult } from "./cryptoPassword.type.js";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* Options for `hashPassword` including an optional provider override.
|
|
4
5
|
*/
|
|
5
|
-
export
|
|
6
|
+
export interface HashPasswordOptions extends PasswordHashOptions {
|
|
7
|
+
readonly provider?: CryptoProvider;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Hashes a password using scrypt.
|
|
11
|
+
*
|
|
12
|
+
* `saltBytes` and `keyBytes` are honoured, and the returned `salt`/`hash`
|
|
13
|
+
* are exactly the values inside `encoded`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function hashPassword(password: string, options?: HashPasswordOptions): Promise<PasswordHashResult>;
|
|
6
16
|
/**
|
|
7
17
|
* Verifies a password against an encoded password hash.
|
|
18
|
+
*
|
|
19
|
+
* Returns false (never throws) for wrong passwords and for malformed,
|
|
20
|
+
* foreign or out-of-bounds hash strings. A non-string or over-long
|
|
21
|
+
* password also yields false.
|
|
8
22
|
*/
|
|
9
|
-
export declare function verifyPassword(password: string, encoded: string): Promise<boolean>;
|
|
23
|
+
export declare function verifyPassword(password: string, encoded: string, provider?: CryptoProvider): Promise<boolean>;
|
|
10
24
|
//# sourceMappingURL=cryptoPassword.core.d.ts.map
|
|
@@ -1,23 +1,22 @@
|
|
|
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 { assertPassword, validateParameters, } from "./cryptoPassword.validate.js";
|
|
4
5
|
import { decodePasswordHash, PASSWORD_FORMAT_VERSION, } from "./cryptoPassword.codec.js";
|
|
5
|
-
const provider = createNodeCryptoProvider();
|
|
6
6
|
/**
|
|
7
|
-
* Hashes a password using
|
|
7
|
+
* Hashes a password using scrypt.
|
|
8
|
+
*
|
|
9
|
+
* `saltBytes` and `keyBytes` are honoured, and the returned `salt`/`hash`
|
|
10
|
+
* are exactly the values inside `encoded`.
|
|
8
11
|
*/
|
|
9
12
|
export async function hashPassword(password, options = {}) {
|
|
10
13
|
assertPassword(password);
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const keyBytes = options.keyBytes ?? 32;
|
|
18
|
-
const cost = options.cost ?? 16_384;
|
|
19
|
-
const blockSize = options.blockSize ?? 8;
|
|
20
|
-
const parallelization = options.parallelization ?? 1;
|
|
14
|
+
const provider = options.provider ?? getDefaultCryptoProvider();
|
|
15
|
+
const saltBytes = options.saltBytes ?? PASSWORD_HASH.SALT_BYTES;
|
|
16
|
+
const keyBytes = options.keyBytes ?? PASSWORD_HASH.KEY_BYTES;
|
|
17
|
+
const cost = options.cost ?? PASSWORD_HASH.SCRYPT.COST;
|
|
18
|
+
const blockSize = options.blockSize ?? PASSWORD_HASH.SCRYPT.BLOCK_SIZE;
|
|
19
|
+
const parallelization = options.parallelization ?? PASSWORD_HASH.SCRYPT.PARALLELIZATION;
|
|
21
20
|
validateParameters({
|
|
22
21
|
saltBytes,
|
|
23
22
|
keyBytes,
|
|
@@ -31,26 +30,35 @@ export async function hashPassword(password, options = {}) {
|
|
|
31
30
|
memoryCost: cost,
|
|
32
31
|
blockSize,
|
|
33
32
|
parallelism: parallelization,
|
|
33
|
+
keyBytes,
|
|
34
|
+
salt,
|
|
34
35
|
});
|
|
35
|
-
const
|
|
36
|
+
const decoded = decodePasswordHash(encoded);
|
|
37
|
+
if (decoded.algorithm !== CryptoAlgorithm.SCRYPT) {
|
|
38
|
+
throw new TypeError("Provider returned a non-scrypt password hash.");
|
|
39
|
+
}
|
|
36
40
|
return Object.freeze({
|
|
37
41
|
algorithm: CryptoAlgorithm.SCRYPT,
|
|
38
42
|
version: PASSWORD_FORMAT_VERSION,
|
|
39
|
-
salt,
|
|
40
|
-
hash,
|
|
43
|
+
salt: decoded.salt,
|
|
44
|
+
hash: decoded.hash,
|
|
41
45
|
encoded,
|
|
42
|
-
cost,
|
|
43
|
-
blockSize,
|
|
44
|
-
parallelization,
|
|
46
|
+
cost: decoded.cost,
|
|
47
|
+
blockSize: decoded.blockSize,
|
|
48
|
+
parallelization: decoded.parallelization,
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
51
|
/**
|
|
48
52
|
* Verifies a password against an encoded password hash.
|
|
53
|
+
*
|
|
54
|
+
* Returns false (never throws) for wrong passwords and for malformed,
|
|
55
|
+
* foreign or out-of-bounds hash strings. A non-string or over-long
|
|
56
|
+
* password also yields false.
|
|
49
57
|
*/
|
|
50
|
-
export async function verifyPassword(password, encoded) {
|
|
58
|
+
export async function verifyPassword(password, encoded, provider = getDefaultCryptoProvider()) {
|
|
51
59
|
try {
|
|
52
60
|
assertPassword(password);
|
|
53
|
-
return provider.verifyPassword(password, encoded);
|
|
61
|
+
return await provider.verifyPassword(password, encoded);
|
|
54
62
|
}
|
|
55
63
|
catch {
|
|
56
64
|
return false;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PASSWORD_HASH } from "../cryptoConstants/cryptoConstants.security.js";
|
|
1
2
|
import { decodePasswordHash } from "./cryptoPassword.codec.js";
|
|
2
3
|
const PASSWORD_MINIMUM_DEFAULT_LENGTH = 8;
|
|
3
4
|
/**
|
|
@@ -5,11 +6,11 @@ const PASSWORD_MINIMUM_DEFAULT_LENGTH = 8;
|
|
|
5
6
|
*/
|
|
6
7
|
export function getDefaultPasswordHashOptions() {
|
|
7
8
|
return {
|
|
8
|
-
saltBytes:
|
|
9
|
-
keyBytes:
|
|
10
|
-
cost:
|
|
11
|
-
blockSize:
|
|
12
|
-
parallelization:
|
|
9
|
+
saltBytes: PASSWORD_HASH.SALT_BYTES,
|
|
10
|
+
keyBytes: PASSWORD_HASH.KEY_BYTES,
|
|
11
|
+
cost: PASSWORD_HASH.SCRYPT.COST,
|
|
12
|
+
blockSize: PASSWORD_HASH.SCRYPT.BLOCK_SIZE,
|
|
13
|
+
parallelization: PASSWORD_HASH.SCRYPT.PARALLELIZATION,
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CryptoAlgorithm } from "../cryptoConstants/cryptoConstants.type.js";
|
|
2
|
+
import type { Pbkdf2Digest } from "../cryptoProvider/cryptoProvider.type.js";
|
|
2
3
|
/**
|
|
3
|
-
* Options used for password hashing.
|
|
4
|
+
* Options used for password hashing (scrypt).
|
|
4
5
|
*/
|
|
5
6
|
export interface PasswordHashOptions {
|
|
6
7
|
readonly saltBytes?: number;
|
|
@@ -11,9 +12,13 @@ export interface PasswordHashOptions {
|
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Result returned by password hashing.
|
|
15
|
+
*
|
|
16
|
+
* `salt` and `hash` are exactly the values encoded in `encoded`, so a
|
|
17
|
+
* record that stores them in separate columns can be re-encoded with
|
|
18
|
+
* `encodePasswordHash` and verified.
|
|
14
19
|
*/
|
|
15
20
|
export interface PasswordHashResult {
|
|
16
|
-
readonly algorithm: CryptoAlgorithm;
|
|
21
|
+
readonly algorithm: CryptoAlgorithm.SCRYPT;
|
|
17
22
|
readonly version: string;
|
|
18
23
|
readonly salt: Uint8Array;
|
|
19
24
|
readonly hash: Uint8Array;
|
|
@@ -23,15 +28,38 @@ export interface PasswordHashResult {
|
|
|
23
28
|
readonly parallelization: number;
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
|
-
* Parameters encoded into a password hash
|
|
31
|
+
* Parameters encoded into a scrypt password hash
|
|
32
|
+
* (`v1$scrypt$N$r$p$salt.hash`).
|
|
27
33
|
*/
|
|
28
|
-
export interface
|
|
34
|
+
export interface ScryptPasswordHashParameters {
|
|
29
35
|
readonly version: string;
|
|
30
|
-
readonly algorithm: CryptoAlgorithm;
|
|
36
|
+
readonly algorithm: CryptoAlgorithm.SCRYPT;
|
|
31
37
|
readonly salt: Uint8Array;
|
|
32
38
|
readonly hash: Uint8Array;
|
|
33
39
|
readonly cost: number;
|
|
34
40
|
readonly blockSize: number;
|
|
35
41
|
readonly parallelization: number;
|
|
36
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Algorithm labels used for PBKDF2 password hashes.
|
|
45
|
+
*/
|
|
46
|
+
export type Pbkdf2PasswordAlgorithm = CryptoAlgorithm.PBKDF2_SHA256 | CryptoAlgorithm.PBKDF2_SHA384 | CryptoAlgorithm.PBKDF2_SHA512;
|
|
47
|
+
/**
|
|
48
|
+
* Parameters encoded into a PBKDF2 password hash
|
|
49
|
+
* (`v1$pbkdf2-<digest>$iterations$salt.hash`).
|
|
50
|
+
*/
|
|
51
|
+
export interface Pbkdf2PasswordHashParameters {
|
|
52
|
+
readonly version: string;
|
|
53
|
+
readonly algorithm: Pbkdf2PasswordAlgorithm;
|
|
54
|
+
readonly digest: Pbkdf2Digest;
|
|
55
|
+
readonly salt: Uint8Array;
|
|
56
|
+
readonly hash: Uint8Array;
|
|
57
|
+
readonly iterations: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parameters decoded from any supported password hash string.
|
|
61
|
+
*
|
|
62
|
+
* Discriminate on `algorithm` to access algorithm-specific fields.
|
|
63
|
+
*/
|
|
64
|
+
export type PasswordHashParameters = ScryptPasswordHashParameters | Pbkdf2PasswordHashParameters;
|
|
37
65
|
//# sourceMappingURL=cryptoPassword.type.d.ts.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Validates the structural constraints of password hashing
|
|
2
|
+
* Validates the structural constraints of scrypt password hashing
|
|
3
|
+
* parameters, including upper bounds so that parameters read back from a
|
|
4
|
+
* stored hash cannot force unbounded CPU or memory usage.
|
|
3
5
|
*/
|
|
4
6
|
export declare function validateParameters(parameters: {
|
|
5
7
|
readonly saltBytes: number;
|
|
@@ -8,16 +10,25 @@ export declare function validateParameters(parameters: {
|
|
|
8
10
|
readonly blockSize: number;
|
|
9
11
|
readonly parallelization: number;
|
|
10
12
|
}): void;
|
|
13
|
+
/**
|
|
14
|
+
* Validates PBKDF2 password hashing parameters, including upper bounds.
|
|
15
|
+
*/
|
|
16
|
+
export declare function validatePbkdf2Parameters(parameters: {
|
|
17
|
+
readonly saltBytes: number;
|
|
18
|
+
readonly keyBytes: number;
|
|
19
|
+
readonly iterations: number;
|
|
20
|
+
}): void;
|
|
11
21
|
/**
|
|
12
22
|
* Parses a string into a positive safe integer.
|
|
13
23
|
*/
|
|
14
24
|
export declare function parsePositiveInteger(value: string, name: string): number;
|
|
15
25
|
/**
|
|
16
|
-
* Decodes a Base64URL string into bytes.
|
|
26
|
+
* Decodes a non-empty, canonical Base64URL string into bytes.
|
|
17
27
|
*/
|
|
18
28
|
export declare function decodeBase64Url(value: string): Uint8Array;
|
|
19
29
|
/**
|
|
20
|
-
* Asserts that a value is a
|
|
30
|
+
* Asserts that a value is a password string within the policy length
|
|
31
|
+
* bounds (non-empty, at most `PASSWORD_POLICY.MAX_LENGTH` code units).
|
|
21
32
|
*/
|
|
22
33
|
export declare function assertPassword(password: string): void;
|
|
23
34
|
//# sourceMappingURL=cryptoPassword.validate.d.ts.map
|
|
@@ -1,24 +1,54 @@
|
|
|
1
|
+
import { PASSWORD_HASH, PASSWORD_POLICY, } from "../cryptoConstants/cryptoConstants.security.js";
|
|
2
|
+
import { fromBase64Url } from "../cryptoEncoding/encoding/cryptoEncoding.base64url.js";
|
|
3
|
+
const LIMITS = PASSWORD_HASH.LIMITS;
|
|
1
4
|
/**
|
|
2
|
-
* Validates the structural constraints of password hashing
|
|
5
|
+
* Validates the structural constraints of scrypt password hashing
|
|
6
|
+
* parameters, including upper bounds so that parameters read back from a
|
|
7
|
+
* stored hash cannot force unbounded CPU or memory usage.
|
|
3
8
|
*/
|
|
4
9
|
export function validateParameters(parameters) {
|
|
5
|
-
|
|
6
|
-
throw new RangeError("saltBytes must be an integer of at least 16.");
|
|
7
|
-
}
|
|
8
|
-
if (!Number.isInteger(parameters.keyBytes) || parameters.keyBytes < 16) {
|
|
9
|
-
throw new RangeError("keyBytes must be an integer of at least 16.");
|
|
10
|
-
}
|
|
10
|
+
validateSaltAndKeyBytes(parameters.saltBytes, parameters.keyBytes);
|
|
11
11
|
if (!Number.isInteger(parameters.cost) ||
|
|
12
|
-
parameters.cost <
|
|
12
|
+
parameters.cost < LIMITS.MIN_SCRYPT_COST ||
|
|
13
|
+
parameters.cost > LIMITS.MAX_SCRYPT_COST ||
|
|
13
14
|
(parameters.cost & (parameters.cost - 1)) !== 0) {
|
|
14
|
-
throw new RangeError(
|
|
15
|
+
throw new RangeError(`cost must be a power of two between ${LIMITS.MIN_SCRYPT_COST} and ${LIMITS.MAX_SCRYPT_COST}.`);
|
|
15
16
|
}
|
|
16
|
-
if (!Number.isInteger(parameters.blockSize) ||
|
|
17
|
-
|
|
17
|
+
if (!Number.isInteger(parameters.blockSize) ||
|
|
18
|
+
parameters.blockSize <= 0 ||
|
|
19
|
+
parameters.blockSize > LIMITS.MAX_SCRYPT_BLOCK_SIZE) {
|
|
20
|
+
throw new RangeError(`blockSize must be an integer between 1 and ${LIMITS.MAX_SCRYPT_BLOCK_SIZE}.`);
|
|
18
21
|
}
|
|
19
22
|
if (!Number.isInteger(parameters.parallelization) ||
|
|
20
|
-
parameters.parallelization <= 0
|
|
21
|
-
|
|
23
|
+
parameters.parallelization <= 0 ||
|
|
24
|
+
parameters.parallelization > LIMITS.MAX_SCRYPT_PARALLELIZATION) {
|
|
25
|
+
throw new RangeError(`parallelization must be an integer between 1 and ${LIMITS.MAX_SCRYPT_PARALLELIZATION}.`);
|
|
26
|
+
}
|
|
27
|
+
if (128 * parameters.cost * parameters.blockSize > LIMITS.MAX_SCRYPT_MEMORY_BYTES) {
|
|
28
|
+
throw new RangeError(`cost * blockSize exceeds the scrypt memory bound of ${LIMITS.MAX_SCRYPT_MEMORY_BYTES} bytes.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates PBKDF2 password hashing parameters, including upper bounds.
|
|
33
|
+
*/
|
|
34
|
+
export function validatePbkdf2Parameters(parameters) {
|
|
35
|
+
validateSaltAndKeyBytes(parameters.saltBytes, parameters.keyBytes);
|
|
36
|
+
if (!Number.isInteger(parameters.iterations) ||
|
|
37
|
+
parameters.iterations < PASSWORD_HASH.PBKDF2.MIN_ITERATIONS ||
|
|
38
|
+
parameters.iterations > LIMITS.MAX_PBKDF2_ITERATIONS) {
|
|
39
|
+
throw new RangeError(`iterations must be an integer between ${PASSWORD_HASH.PBKDF2.MIN_ITERATIONS} and ${LIMITS.MAX_PBKDF2_ITERATIONS}.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function validateSaltAndKeyBytes(saltBytes, keyBytes) {
|
|
43
|
+
if (!Number.isInteger(saltBytes) ||
|
|
44
|
+
saltBytes < LIMITS.MIN_SALT_BYTES ||
|
|
45
|
+
saltBytes > LIMITS.MAX_SALT_BYTES) {
|
|
46
|
+
throw new RangeError(`saltBytes must be an integer between ${LIMITS.MIN_SALT_BYTES} and ${LIMITS.MAX_SALT_BYTES}.`);
|
|
47
|
+
}
|
|
48
|
+
if (!Number.isInteger(keyBytes) ||
|
|
49
|
+
keyBytes < LIMITS.MIN_KEY_BYTES ||
|
|
50
|
+
keyBytes > LIMITS.MAX_KEY_BYTES) {
|
|
51
|
+
throw new RangeError(`keyBytes must be an integer between ${LIMITS.MIN_KEY_BYTES} and ${LIMITS.MAX_KEY_BYTES}.`);
|
|
22
52
|
}
|
|
23
53
|
}
|
|
24
54
|
/**
|
|
@@ -35,19 +65,17 @@ export function parsePositiveInteger(value, name) {
|
|
|
35
65
|
return parsed;
|
|
36
66
|
}
|
|
37
67
|
/**
|
|
38
|
-
* Decodes a Base64URL string into bytes.
|
|
68
|
+
* Decodes a non-empty, canonical Base64URL string into bytes.
|
|
39
69
|
*/
|
|
40
70
|
export function decodeBase64Url(value) {
|
|
41
|
-
if (value.length === 0
|
|
71
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
42
72
|
throw new TypeError("Invalid Base64URL value.");
|
|
43
73
|
}
|
|
44
|
-
|
|
45
|
-
throw new TypeError("Invalid Base64URL length.");
|
|
46
|
-
}
|
|
47
|
-
return new Uint8Array(Buffer.from(value, "base64url"));
|
|
74
|
+
return fromBase64Url(value);
|
|
48
75
|
}
|
|
49
76
|
/**
|
|
50
|
-
* Asserts that a value is a
|
|
77
|
+
* Asserts that a value is a password string within the policy length
|
|
78
|
+
* bounds (non-empty, at most `PASSWORD_POLICY.MAX_LENGTH` code units).
|
|
51
79
|
*/
|
|
52
80
|
export function assertPassword(password) {
|
|
53
81
|
if (typeof password !== "string") {
|
|
@@ -56,5 +84,8 @@ export function assertPassword(password) {
|
|
|
56
84
|
if (password.length === 0) {
|
|
57
85
|
throw new TypeError("Password cannot be empty.");
|
|
58
86
|
}
|
|
87
|
+
if (password.length > PASSWORD_POLICY.MAX_LENGTH) {
|
|
88
|
+
throw new RangeError(`Password must not exceed ${PASSWORD_POLICY.MAX_LENGTH} characters.`);
|
|
89
|
+
}
|
|
59
90
|
}
|
|
60
91
|
//# sourceMappingURL=cryptoPassword.validate.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CryptoProvider } from "./cryptoProvider.core.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the process-wide default crypto provider, creating the Node
|
|
4
|
+
* provider lazily on first use.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getDefaultCryptoProvider(): CryptoProvider;
|
|
7
|
+
/**
|
|
8
|
+
* Replaces the process-wide default crypto provider.
|
|
9
|
+
*
|
|
10
|
+
* Every module-level helper (hash, encrypt, hashPassword, generateToken,
|
|
11
|
+
* ...) that is not given an explicit provider uses this one.
|
|
12
|
+
*/
|
|
13
|
+
export declare function setDefaultCryptoProvider(provider: CryptoProvider): void;
|
|
14
|
+
/**
|
|
15
|
+
* Restores the built-in Node provider as the default.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resetDefaultCryptoProvider(): void;
|
|
18
|
+
//# sourceMappingURL=cryptoProvider.default.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createNodeCryptoProvider } from "../node/nodeCryptoProvider/nodeCryptoProvider.factory.js";
|
|
2
|
+
let defaultProvider;
|
|
3
|
+
/**
|
|
4
|
+
* Returns the process-wide default crypto provider, creating the Node
|
|
5
|
+
* provider lazily on first use.
|
|
6
|
+
*/
|
|
7
|
+
export function getDefaultCryptoProvider() {
|
|
8
|
+
if (defaultProvider === undefined) {
|
|
9
|
+
defaultProvider = createNodeCryptoProvider();
|
|
10
|
+
}
|
|
11
|
+
return defaultProvider;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Replaces the process-wide default crypto provider.
|
|
15
|
+
*
|
|
16
|
+
* Every module-level helper (hash, encrypt, hashPassword, generateToken,
|
|
17
|
+
* ...) that is not given an explicit provider uses this one.
|
|
18
|
+
*/
|
|
19
|
+
export function setDefaultCryptoProvider(provider) {
|
|
20
|
+
if (typeof provider !== "object" || provider === null) {
|
|
21
|
+
throw new TypeError("Crypto provider must be an object.");
|
|
22
|
+
}
|
|
23
|
+
defaultProvider = provider;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Restores the built-in Node provider as the default.
|
|
27
|
+
*/
|
|
28
|
+
export function resetDefaultCryptoProvider() {
|
|
29
|
+
defaultProvider = undefined;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=cryptoProvider.default.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { HashAlgorithm, HmacAlgorithm,
|
|
2
|
-
import type { EncryptedData } from "./types/cryptoCipher.type.js";
|
|
3
|
-
import type {
|
|
1
|
+
import type { HashAlgorithm, HmacAlgorithm, CryptoInput, CryptoCapabilities } from "./cryptoProvider.type.js";
|
|
2
|
+
import type { EncryptedData, EncryptOptions, DecryptOptions } from "./types/cryptoCipher.type.js";
|
|
3
|
+
import type { SignOptions, VerifyOptions } from "./types/cryptoSignature.type.js";
|
|
4
|
+
import type { DeriveKeyOptions, PasswordHashProviderOptions } from "./types/cryptoKeyDerivation.type.js";
|
|
4
5
|
/**
|
|
5
6
|
* Provider for cryptographically secure random bytes.
|
|
6
7
|
*/
|
|
@@ -33,17 +34,8 @@ export interface HmacProvider {
|
|
|
33
34
|
export interface EncryptionProvider {
|
|
34
35
|
readonly name: string;
|
|
35
36
|
readonly capabilities: CryptoCapabilities;
|
|
36
|
-
encrypt(options:
|
|
37
|
-
|
|
38
|
-
plaintext: CryptoInput;
|
|
39
|
-
associatedData?: CryptoInput;
|
|
40
|
-
nonce?: Uint8Array;
|
|
41
|
-
}): Promise<EncryptedData>;
|
|
42
|
-
decrypt(options: {
|
|
43
|
-
key: CryptoInput;
|
|
44
|
-
encrypted: EncryptedData;
|
|
45
|
-
associatedData?: CryptoInput;
|
|
46
|
-
}): Promise<Uint8Array>;
|
|
37
|
+
encrypt(options: EncryptOptions): Promise<EncryptedData>;
|
|
38
|
+
decrypt(options: DecryptOptions): Promise<Uint8Array>;
|
|
47
39
|
}
|
|
48
40
|
/**
|
|
49
41
|
* Provider for digital signing.
|
|
@@ -51,17 +43,8 @@ export interface EncryptionProvider {
|
|
|
51
43
|
export interface SigningProvider {
|
|
52
44
|
readonly name: string;
|
|
53
45
|
readonly capabilities: CryptoCapabilities;
|
|
54
|
-
sign(options:
|
|
55
|
-
|
|
56
|
-
data: CryptoInput;
|
|
57
|
-
algorithm?: SignatureAlgorithm;
|
|
58
|
-
}): Promise<Uint8Array>;
|
|
59
|
-
verify(options: {
|
|
60
|
-
key: CryptoInput;
|
|
61
|
-
data: CryptoInput;
|
|
62
|
-
signature: Uint8Array;
|
|
63
|
-
algorithm?: SignatureAlgorithm;
|
|
64
|
-
}): Promise<boolean>;
|
|
46
|
+
sign(options: SignOptions): Promise<Uint8Array>;
|
|
47
|
+
verify(options: VerifyOptions): Promise<boolean>;
|
|
65
48
|
}
|
|
66
49
|
/**
|
|
67
50
|
* Provider for key derivation.
|
|
@@ -77,15 +60,7 @@ export interface KeyDerivationProvider {
|
|
|
77
60
|
export interface PasswordProvider {
|
|
78
61
|
readonly name: string;
|
|
79
62
|
readonly capabilities: CryptoCapabilities;
|
|
80
|
-
hashPassword(password: CryptoInput, options?:
|
|
81
|
-
algorithm?: KeyDerivationAlgorithm;
|
|
82
|
-
memoryCost?: number;
|
|
83
|
-
timeCost?: number;
|
|
84
|
-
blockSize?: number;
|
|
85
|
-
parallelism?: number;
|
|
86
|
-
keyBytes?: number;
|
|
87
|
-
salt?: Uint8Array;
|
|
88
|
-
}): Promise<string>;
|
|
63
|
+
hashPassword(password: CryptoInput, options?: PasswordHashProviderOptions): Promise<string>;
|
|
89
64
|
verifyPassword(password: CryptoInput, hash: string): Promise<boolean>;
|
|
90
65
|
}
|
|
91
66
|
//# sourceMappingURL=cryptoProvider.interface.d.ts.map
|