@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,90 +1,115 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
|
|
2
2
|
import { randomInteger } from "../cryptoRandom/cryptoRandom.core.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Returns a lazily created default crypto provider.
|
|
6
|
-
*
|
|
7
|
-
* The provider abstraction keeps token generation free of direct
|
|
8
|
-
* `node:crypto` usage while still allowing callers to inject their own.
|
|
9
|
-
*/
|
|
10
|
-
function getDefaultProvider() {
|
|
11
|
-
if (defaultProvider === undefined) {
|
|
12
|
-
defaultProvider = createNodeCryptoProvider();
|
|
13
|
-
}
|
|
14
|
-
return defaultProvider;
|
|
15
|
-
}
|
|
3
|
+
import { assertBinaryEncoding } from "../cryptoEncoding/cryptoEncoding.core.js";
|
|
4
|
+
import { RANDOM, TOKEN, TOKEN_PREFIX, } from "../cryptoConstants/cryptoConstants.token.js";
|
|
16
5
|
/**
|
|
17
6
|
* Creates a cryptographically secure opaque token.
|
|
7
|
+
*
|
|
8
|
+
* The encoding is validated at runtime: only `hex`, `base64` and
|
|
9
|
+
* `base64url` are accepted, so a misconfigured `"utf8"` can never
|
|
10
|
+
* produce a lossy token.
|
|
18
11
|
*/
|
|
19
12
|
export async function generateToken(options = {}) {
|
|
20
|
-
const bytes = options.bytes ??
|
|
13
|
+
const bytes = options.bytes ?? TOKEN.DEFAULT_BYTES;
|
|
21
14
|
const encoding = options.encoding ?? "base64url";
|
|
22
|
-
if (!Number.isInteger(bytes) || bytes <
|
|
23
|
-
throw new RangeError(
|
|
15
|
+
if (!Number.isInteger(bytes) || bytes < RANDOM.MIN_BYTES) {
|
|
16
|
+
throw new RangeError(`Token byte length must be an integer of at least ${RANDOM.MIN_BYTES}.`);
|
|
17
|
+
}
|
|
18
|
+
assertBinaryEncoding(encoding);
|
|
19
|
+
if (options.prefix !== undefined && typeof options.prefix !== "string") {
|
|
20
|
+
throw new TypeError("Token prefix must be a string.");
|
|
24
21
|
}
|
|
25
|
-
const
|
|
22
|
+
const provider = options.provider ?? getDefaultCryptoProvider();
|
|
23
|
+
const raw = await provider.randomBytes(bytes);
|
|
26
24
|
const token = Buffer.from(raw).toString(encoding);
|
|
27
25
|
return options.prefix ? `${options.prefix}${token}` : token;
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
28
|
* Generates a secure API key.
|
|
31
29
|
*/
|
|
32
|
-
export async function generateApiKey(prefix =
|
|
33
|
-
return generateToken({ bytes, encoding: "base64url", prefix });
|
|
30
|
+
export async function generateApiKey(prefix = TOKEN_PREFIX.API_KEY, bytes = TOKEN.API_KEY_BYTES, provider) {
|
|
31
|
+
return generateToken({ bytes, encoding: "base64url", prefix, provider });
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
34
|
* Generates a secure session token.
|
|
37
35
|
*/
|
|
38
|
-
export async function generateSessionToken(bytes =
|
|
39
|
-
return generateToken({
|
|
36
|
+
export async function generateSessionToken(bytes = TOKEN.SESSION_BYTES, provider) {
|
|
37
|
+
return generateToken({
|
|
38
|
+
bytes,
|
|
39
|
+
encoding: "base64url",
|
|
40
|
+
prefix: TOKEN_PREFIX.SESSION,
|
|
41
|
+
provider,
|
|
42
|
+
});
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* Generates a secure refresh token.
|
|
43
46
|
*/
|
|
44
|
-
export async function generateRefreshToken(bytes =
|
|
45
|
-
return generateToken({
|
|
47
|
+
export async function generateRefreshToken(bytes = TOKEN.REFRESH_BYTES, provider) {
|
|
48
|
+
return generateToken({
|
|
49
|
+
bytes,
|
|
50
|
+
encoding: "base64url",
|
|
51
|
+
prefix: TOKEN_PREFIX.REFRESH,
|
|
52
|
+
provider,
|
|
53
|
+
});
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
48
56
|
* Generates a secure verification token.
|
|
49
57
|
*/
|
|
50
|
-
export async function generateVerificationToken(bytes =
|
|
51
|
-
return generateToken({
|
|
58
|
+
export async function generateVerificationToken(bytes = TOKEN.VERIFICATION_BYTES, provider) {
|
|
59
|
+
return generateToken({
|
|
60
|
+
bytes,
|
|
61
|
+
encoding: "base64url",
|
|
62
|
+
prefix: TOKEN_PREFIX.VERIFICATION,
|
|
63
|
+
provider,
|
|
64
|
+
});
|
|
52
65
|
}
|
|
53
66
|
/**
|
|
54
67
|
* Generates a secure password-reset token.
|
|
55
68
|
*/
|
|
56
|
-
export async function generatePasswordResetToken(bytes =
|
|
57
|
-
return generateToken({
|
|
69
|
+
export async function generatePasswordResetToken(bytes = TOKEN.PASSWORD_RESET_BYTES, provider) {
|
|
70
|
+
return generateToken({
|
|
71
|
+
bytes,
|
|
72
|
+
encoding: "base64url",
|
|
73
|
+
prefix: TOKEN_PREFIX.PASSWORD_RESET,
|
|
74
|
+
provider,
|
|
75
|
+
});
|
|
58
76
|
}
|
|
59
77
|
/**
|
|
60
78
|
* Generates a secure CSRF token.
|
|
61
79
|
*/
|
|
62
|
-
export async function generateCsrfToken(bytes =
|
|
63
|
-
return generateToken({
|
|
80
|
+
export async function generateCsrfToken(bytes = TOKEN.CSRF_BYTES, provider) {
|
|
81
|
+
return generateToken({
|
|
82
|
+
bytes,
|
|
83
|
+
encoding: "base64url",
|
|
84
|
+
prefix: TOKEN_PREFIX.CSRF,
|
|
85
|
+
provider,
|
|
86
|
+
});
|
|
64
87
|
}
|
|
65
88
|
/**
|
|
66
89
|
* Generates a numeric one-time password.
|
|
67
90
|
*
|
|
68
91
|
* Leading zeroes are preserved.
|
|
69
92
|
*/
|
|
70
|
-
export async function generateOtp(digits =
|
|
71
|
-
if (!Number.isInteger(digits) ||
|
|
72
|
-
|
|
93
|
+
export async function generateOtp(digits = TOKEN.OTP_DIGITS, provider) {
|
|
94
|
+
if (!Number.isInteger(digits) ||
|
|
95
|
+
digits < TOKEN.OTP_MIN_DIGITS ||
|
|
96
|
+
digits > TOKEN.OTP_MAX_DIGITS) {
|
|
97
|
+
throw new RangeError(`OTP digits must be an integer between ${TOKEN.OTP_MIN_DIGITS} and ${TOKEN.OTP_MAX_DIGITS}.`);
|
|
73
98
|
}
|
|
74
99
|
const max = 10 ** digits;
|
|
75
|
-
const value = await randomInteger(0, max);
|
|
100
|
+
const value = await randomInteger(0, max, provider);
|
|
76
101
|
return String(value).padStart(digits, "0");
|
|
77
102
|
}
|
|
78
103
|
/**
|
|
79
104
|
* Generates a short-lived email verification code.
|
|
80
105
|
*/
|
|
81
|
-
export async function generateEmailVerificationCode(digits =
|
|
82
|
-
return generateOtp(digits);
|
|
106
|
+
export async function generateEmailVerificationCode(digits = TOKEN.OTP_DIGITS, provider) {
|
|
107
|
+
return generateOtp(digits, provider);
|
|
83
108
|
}
|
|
84
109
|
/**
|
|
85
110
|
* Generates a short-lived login verification code.
|
|
86
111
|
*/
|
|
87
|
-
export async function generateLoginCode(digits =
|
|
88
|
-
return generateOtp(digits);
|
|
112
|
+
export async function generateLoginCode(digits = TOKEN.OTP_DIGITS, provider) {
|
|
113
|
+
return generateOtp(digits, provider);
|
|
89
114
|
}
|
|
90
115
|
//# sourceMappingURL=cryptoToken.core.js.map
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
+
import type { CryptoProvider } from "../cryptoProvider/index.js";
|
|
1
2
|
/**
|
|
2
3
|
* Creates a deterministic SHA-256 identifier from a token.
|
|
3
4
|
*
|
|
4
5
|
* The returned value does not expose the original token.
|
|
5
6
|
*/
|
|
6
|
-
export declare function hashToken(token: string): Promise<string>;
|
|
7
|
+
export declare function hashToken(token: string, provider?: CryptoProvider): Promise<string>;
|
|
7
8
|
/**
|
|
8
9
|
* Creates a Base64URL SHA-256 digest of a token.
|
|
9
10
|
*/
|
|
10
|
-
export declare function hashTokenBase64Url(token: string): Promise<string>;
|
|
11
|
+
export declare function hashTokenBase64Url(token: string, provider?: CryptoProvider): Promise<string>;
|
|
11
12
|
/**
|
|
12
|
-
* Compares a token with a stored hash.
|
|
13
|
+
* Compares a token with a stored hex SHA-256 hash.
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* The comparison is constant time and case-insensitive on the hex digits,
|
|
16
|
+
* so hashes upper-cased by a database or copied from another tool still
|
|
17
|
+
* match. Returns false for a malformed token or stored hash.
|
|
16
18
|
*/
|
|
17
|
-
export declare function verifyTokenHash(token: string, expectedHash: string): Promise<boolean>;
|
|
19
|
+
export declare function verifyTokenHash(token: string, expectedHash: string, provider?: CryptoProvider): Promise<boolean>;
|
|
18
20
|
/**
|
|
19
21
|
* Hashes a token using SHA-256 before storage.
|
|
20
22
|
*
|
|
21
23
|
* This is useful when a raw bearer token must never be persisted.
|
|
22
24
|
*/
|
|
23
|
-
export declare function hashTokenForStorage(token: string): Promise<string>;
|
|
25
|
+
export declare function hashTokenForStorage(token: string, provider?: CryptoProvider): Promise<string>;
|
|
24
26
|
//# sourceMappingURL=cryptoToken.hash.d.ts.map
|
|
@@ -1,49 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDefaultCryptoProvider } from "../cryptoProvider/cryptoProvider.default.js";
|
|
2
2
|
import { encode } from "../cryptoEncoding/cryptoEncoding.core.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Returns a lazily created default crypto provider.
|
|
6
|
-
*
|
|
7
|
-
* The provider abstraction keeps token hashing free of direct
|
|
8
|
-
* `node:crypto` usage while still allowing callers to inject their own.
|
|
9
|
-
*/
|
|
10
|
-
function getDefaultProvider() {
|
|
11
|
-
if (defaultProvider === undefined) {
|
|
12
|
-
defaultProvider = createNodeCryptoProvider();
|
|
13
|
-
}
|
|
14
|
-
return defaultProvider;
|
|
15
|
-
}
|
|
3
|
+
import { isHex } from "../cryptoEncoding/encoding/cryptoEncoding.hex.js";
|
|
4
|
+
import { timingSafeEqual } from "../compare/compare.helper.js";
|
|
16
5
|
/**
|
|
17
6
|
* Creates a deterministic SHA-256 identifier from a token.
|
|
18
7
|
*
|
|
19
8
|
* The returned value does not expose the original token.
|
|
20
9
|
*/
|
|
21
|
-
export async function hashToken(token) {
|
|
10
|
+
export async function hashToken(token, provider = getDefaultCryptoProvider()) {
|
|
22
11
|
assertToken(token);
|
|
23
|
-
const digest = await
|
|
12
|
+
const digest = await provider.hash("sha256", token);
|
|
24
13
|
return encode(digest, "hex");
|
|
25
14
|
}
|
|
26
15
|
/**
|
|
27
16
|
* Creates a Base64URL SHA-256 digest of a token.
|
|
28
17
|
*/
|
|
29
|
-
export async function hashTokenBase64Url(token) {
|
|
18
|
+
export async function hashTokenBase64Url(token, provider = getDefaultCryptoProvider()) {
|
|
30
19
|
assertToken(token);
|
|
31
|
-
const digest = await
|
|
20
|
+
const digest = await provider.hash("sha256", token);
|
|
32
21
|
return encode(digest, "base64url");
|
|
33
22
|
}
|
|
34
23
|
/**
|
|
35
|
-
* Compares a token with a stored hash.
|
|
24
|
+
* Compares a token with a stored hex SHA-256 hash.
|
|
36
25
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
26
|
+
* The comparison is constant time and case-insensitive on the hex digits,
|
|
27
|
+
* so hashes upper-cased by a database or copied from another tool still
|
|
28
|
+
* match. Returns false for a malformed token or stored hash.
|
|
39
29
|
*/
|
|
40
|
-
export async function verifyTokenHash(token, expectedHash) {
|
|
30
|
+
export async function verifyTokenHash(token, expectedHash, provider) {
|
|
31
|
+
if (typeof expectedHash !== "string" || !isHex(expectedHash)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
41
34
|
try {
|
|
42
|
-
const actual = await hashToken(token);
|
|
43
|
-
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return constantTimeEqual(actual, expectedHash);
|
|
35
|
+
const actual = await hashToken(token, provider);
|
|
36
|
+
return timingSafeEqual(Buffer.from(actual, "hex"), Buffer.from(expectedHash.toLowerCase(), "hex"));
|
|
47
37
|
}
|
|
48
38
|
catch {
|
|
49
39
|
return false;
|
|
@@ -54,22 +44,8 @@ export async function verifyTokenHash(token, expectedHash) {
|
|
|
54
44
|
*
|
|
55
45
|
* This is useful when a raw bearer token must never be persisted.
|
|
56
46
|
*/
|
|
57
|
-
export async function hashTokenForStorage(token) {
|
|
58
|
-
return hashToken(token);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Compares two hex-encoded strings in constant time.
|
|
62
|
-
*/
|
|
63
|
-
function constantTimeEqual(left, right) {
|
|
64
|
-
let mismatch = 0;
|
|
65
|
-
const length = left.length;
|
|
66
|
-
if (length !== right.length) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
for (let i = 0; i < length; i += 1) {
|
|
70
|
-
mismatch |= left.charCodeAt(i) ^ right.charCodeAt(i);
|
|
71
|
-
}
|
|
72
|
-
return mismatch === 0;
|
|
47
|
+
export async function hashTokenForStorage(token, provider) {
|
|
48
|
+
return hashToken(token, provider);
|
|
73
49
|
}
|
|
74
50
|
/**
|
|
75
51
|
* Validates the basic shape of an opaque token.
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Compares two byte arrays in constant time.
|
|
3
3
|
*
|
|
4
|
-
* Different lengths return false immediately.
|
|
4
|
+
* Different lengths return false immediately. Alias of `timingSafeEqual`.
|
|
5
5
|
*/
|
|
6
6
|
export declare function secureEqual(left: Uint8Array, right: Uint8Array): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Performs a constant-time comparison of two strings.
|
|
9
|
+
*
|
|
10
|
+
* Alias of `timingSafeEqualString`.
|
|
9
11
|
*/
|
|
10
12
|
export declare function secureStringEqual(left: string, right: string): boolean;
|
|
11
13
|
//# sourceMappingURL=cryptoUtils.compare.d.ts.map
|
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
import { timingSafeEqual } from "../compare/compare.helper.js";
|
|
1
|
+
import { timingSafeEqual, timingSafeEqualString, } from "../compare/compare.helper.js";
|
|
2
2
|
/**
|
|
3
3
|
* Compares two byte arrays in constant time.
|
|
4
4
|
*
|
|
5
|
-
* Different lengths return false immediately.
|
|
5
|
+
* Different lengths return false immediately. Alias of `timingSafeEqual`.
|
|
6
6
|
*/
|
|
7
7
|
export function secureEqual(left, right) {
|
|
8
|
-
if (left.byteLength !== right.byteLength) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
8
|
return timingSafeEqual(left, right);
|
|
12
9
|
}
|
|
13
10
|
/**
|
|
14
11
|
* Performs a constant-time comparison of two strings.
|
|
12
|
+
*
|
|
13
|
+
* Alias of `timingSafeEqualString`.
|
|
15
14
|
*/
|
|
16
15
|
export function secureStringEqual(left, right) {
|
|
17
|
-
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const leftBytes = new TextEncoder().encode(left);
|
|
21
|
-
const rightBytes = new TextEncoder().encode(right);
|
|
22
|
-
if (leftBytes.byteLength !== rightBytes.byteLength) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
return timingSafeEqual(leftBytes, rightBytes);
|
|
16
|
+
return timingSafeEqualString(left, right);
|
|
26
17
|
}
|
|
27
18
|
//# sourceMappingURL=cryptoUtils.compare.js.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Converts a number into an unsigned big-endian byte array.
|
|
3
|
+
*
|
|
4
|
+
* The default width of 6 bytes (48 bits) is the largest width for which
|
|
5
|
+
* every safe integer conversion is exact.
|
|
3
6
|
*/
|
|
4
7
|
export declare function numberToBytes(value: number, byteLength?: number): Uint8Array;
|
|
5
8
|
/**
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
const MAX_BYTE_LENGTH = 6;
|
|
1
2
|
/**
|
|
2
3
|
* Converts a number into an unsigned big-endian byte array.
|
|
4
|
+
*
|
|
5
|
+
* The default width of 6 bytes (48 bits) is the largest width for which
|
|
6
|
+
* every safe integer conversion is exact.
|
|
3
7
|
*/
|
|
4
|
-
export function numberToBytes(value, byteLength =
|
|
8
|
+
export function numberToBytes(value, byteLength = MAX_BYTE_LENGTH) {
|
|
5
9
|
if (!Number.isSafeInteger(value) || value < 0) {
|
|
6
10
|
throw new RangeError("value must be a non-negative safe integer.");
|
|
7
11
|
}
|
|
8
|
-
if (!Number.isInteger(byteLength) ||
|
|
9
|
-
|
|
12
|
+
if (!Number.isInteger(byteLength) ||
|
|
13
|
+
byteLength <= 0 ||
|
|
14
|
+
byteLength > MAX_BYTE_LENGTH) {
|
|
15
|
+
throw new RangeError(`byteLength must be an integer between 1 and ${MAX_BYTE_LENGTH}.`);
|
|
10
16
|
}
|
|
11
17
|
const result = new Uint8Array(byteLength);
|
|
12
18
|
let remaining = value;
|
|
13
19
|
for (let index = byteLength - 1; index >= 0; index -= 1) {
|
|
14
|
-
result[index] = remaining
|
|
20
|
+
result[index] = remaining % 256;
|
|
15
21
|
remaining = Math.floor(remaining / 256);
|
|
16
22
|
}
|
|
17
23
|
if (remaining !== 0) {
|
|
@@ -23,8 +29,8 @@ export function numberToBytes(value, byteLength = 8) {
|
|
|
23
29
|
* Converts unsigned big-endian bytes into a number.
|
|
24
30
|
*/
|
|
25
31
|
export function bytesToNumber(value) {
|
|
26
|
-
if (value.byteLength === 0 || value.byteLength >
|
|
27
|
-
throw new RangeError(
|
|
32
|
+
if (value.byteLength === 0 || value.byteLength > MAX_BYTE_LENGTH) {
|
|
33
|
+
throw new RangeError(`Byte array length must be between 1 and ${MAX_BYTE_LENGTH}.`);
|
|
28
34
|
}
|
|
29
35
|
let result = 0;
|
|
30
36
|
for (const byte of value) {
|
|
@@ -7,11 +7,11 @@ export declare function isBytes(value: unknown): value is Uint8Array;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
9
9
|
/**
|
|
10
|
-
* Returns whether a string
|
|
10
|
+
* Returns whether a string is valid hexadecimal. Alias of `isHex`.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isHexString(value: string): boolean;
|
|
13
13
|
/**
|
|
14
|
-
* Returns whether a string is
|
|
14
|
+
* Returns whether a string is valid, canonical Base64URL. Alias of `isBase64Url`.
|
|
15
15
|
*/
|
|
16
16
|
export declare function isBase64UrlString(value: string): boolean;
|
|
17
17
|
//# sourceMappingURL=cryptoUtils.validation.d.ts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isHex } from "../cryptoEncoding/encoding/cryptoEncoding.hex.js";
|
|
2
|
+
import { isBase64Url } from "../cryptoEncoding/encoding/cryptoEncoding.base64url.js";
|
|
1
3
|
/**
|
|
2
4
|
* Returns whether a value is a Uint8Array.
|
|
3
5
|
*/
|
|
@@ -11,19 +13,15 @@ export function isArrayBuffer(value) {
|
|
|
11
13
|
return value instanceof ArrayBuffer;
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
|
-
* Returns whether a string
|
|
16
|
+
* Returns whether a string is valid hexadecimal. Alias of `isHex`.
|
|
15
17
|
*/
|
|
16
18
|
export function isHexString(value) {
|
|
17
|
-
return (
|
|
18
|
-
value.length % 2 === 0 &&
|
|
19
|
-
/^[0-9a-fA-F]*$/.test(value));
|
|
19
|
+
return isHex(value);
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Returns whether a string is
|
|
22
|
+
* Returns whether a string is valid, canonical Base64URL. Alias of `isBase64Url`.
|
|
23
23
|
*/
|
|
24
24
|
export function isBase64UrlString(value) {
|
|
25
|
-
return (
|
|
26
|
-
value.length % 4 !== 1 &&
|
|
27
|
-
/^[A-Za-z0-9_-]*$/.test(value));
|
|
25
|
+
return isBase64Url(value);
|
|
28
26
|
}
|
|
29
27
|
//# sourceMappingURL=cryptoUtils.validation.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Converts bytes into Base64.
|
|
2
|
+
* Converts bytes into Base64. Alias of `toBase64`.
|
|
3
3
|
*/
|
|
4
|
-
export declare
|
|
4
|
+
export declare const bytesToBase64: (value: Uint8Array) => string;
|
|
5
5
|
/**
|
|
6
|
-
* Converts Base64 into bytes.
|
|
6
|
+
* Converts Base64 into bytes. Alias of `fromBase64`.
|
|
7
7
|
*/
|
|
8
|
-
export declare
|
|
8
|
+
export declare const base64ToBytes: (value: string) => Uint8Array;
|
|
9
9
|
//# sourceMappingURL=cryptoUtils.base64.d.ts.map
|
|
@@ -1,28 +1,10 @@
|
|
|
1
|
+
import { toBase64, fromBase64, } from "../../cryptoEncoding/encoding/cryptoEncoding.base64.js";
|
|
1
2
|
/**
|
|
2
|
-
* Converts bytes into Base64.
|
|
3
|
+
* Converts bytes into Base64. Alias of `toBase64`.
|
|
3
4
|
*/
|
|
4
|
-
export
|
|
5
|
-
const binary = Array.from(value)
|
|
6
|
-
.map((b) => String.fromCharCode(b))
|
|
7
|
-
.join("");
|
|
8
|
-
return btoa(binary);
|
|
9
|
-
}
|
|
5
|
+
export const bytesToBase64 = toBase64;
|
|
10
6
|
/**
|
|
11
|
-
* Converts Base64 into bytes.
|
|
7
|
+
* Converts Base64 into bytes. Alias of `fromBase64`.
|
|
12
8
|
*/
|
|
13
|
-
export
|
|
14
|
-
if (typeof value !== "string") {
|
|
15
|
-
throw new TypeError("Base64 value must be a string.");
|
|
16
|
-
}
|
|
17
|
-
if (value.length % 4 !== 0 ||
|
|
18
|
-
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {
|
|
19
|
-
throw new TypeError("Invalid Base64 value.");
|
|
20
|
-
}
|
|
21
|
-
const binary = atob(value);
|
|
22
|
-
const result = new Uint8Array(binary.length);
|
|
23
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
24
|
-
result[i] = binary.charCodeAt(i);
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
9
|
+
export const base64ToBytes = fromBase64;
|
|
28
10
|
//# sourceMappingURL=cryptoUtils.base64.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Converts bytes into URL-safe Base64 without padding.
|
|
2
|
+
* Converts bytes into URL-safe Base64 without padding. Alias of `toBase64Url`.
|
|
3
3
|
*/
|
|
4
|
-
export declare
|
|
4
|
+
export declare const bytesToBase64Url: (value: Uint8Array) => string;
|
|
5
5
|
/**
|
|
6
|
-
* Converts URL-safe Base64 into bytes.
|
|
6
|
+
* Converts URL-safe Base64 into bytes. Alias of `fromBase64Url`.
|
|
7
7
|
*/
|
|
8
|
-
export declare
|
|
8
|
+
export declare const base64UrlToBytes: (value: string) => Uint8Array;
|
|
9
9
|
//# sourceMappingURL=cryptoUtils.base64url.d.ts.map
|
|
@@ -1,37 +1,10 @@
|
|
|
1
|
+
import { toBase64Url, fromBase64Url, } from "../../cryptoEncoding/encoding/cryptoEncoding.base64url.js";
|
|
1
2
|
/**
|
|
2
|
-
* Converts bytes into URL-safe Base64 without padding.
|
|
3
|
+
* Converts bytes into URL-safe Base64 without padding. Alias of `toBase64Url`.
|
|
3
4
|
*/
|
|
4
|
-
export
|
|
5
|
-
const binary = Array.from(value)
|
|
6
|
-
.map((b) => String.fromCharCode(b))
|
|
7
|
-
.join("");
|
|
8
|
-
return btoa(binary)
|
|
9
|
-
.replace(/\+/g, "-")
|
|
10
|
-
.replace(/\//g, "_")
|
|
11
|
-
.replace(/=+$/, "");
|
|
12
|
-
}
|
|
5
|
+
export const bytesToBase64Url = toBase64Url;
|
|
13
6
|
/**
|
|
14
|
-
* Converts URL-safe Base64 into bytes.
|
|
7
|
+
* Converts URL-safe Base64 into bytes. Alias of `fromBase64Url`.
|
|
15
8
|
*/
|
|
16
|
-
export
|
|
17
|
-
if (typeof value !== "string") {
|
|
18
|
-
throw new TypeError("Base64URL value must be a string.");
|
|
19
|
-
}
|
|
20
|
-
if (!/^[A-Za-z0-9_-]*$/.test(value)) {
|
|
21
|
-
throw new TypeError("Invalid Base64URL value.");
|
|
22
|
-
}
|
|
23
|
-
if (value.length % 4 === 1) {
|
|
24
|
-
throw new TypeError("Invalid Base64URL length.");
|
|
25
|
-
}
|
|
26
|
-
let base64 = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
27
|
-
while (base64.length % 4) {
|
|
28
|
-
base64 += "=";
|
|
29
|
-
}
|
|
30
|
-
const binary = atob(base64);
|
|
31
|
-
const result = new Uint8Array(binary.length);
|
|
32
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
33
|
-
result[i] = binary.charCodeAt(i);
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
9
|
+
export const base64UrlToBytes = fromBase64Url;
|
|
37
10
|
//# sourceMappingURL=cryptoUtils.base64url.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Converts bytes into a hexadecimal string.
|
|
2
|
+
* Converts bytes into a hexadecimal string. Alias of `toHex`.
|
|
3
3
|
*/
|
|
4
|
-
export declare
|
|
4
|
+
export declare const bytesToHex: (value: Uint8Array) => string;
|
|
5
5
|
/**
|
|
6
|
-
* Converts a hexadecimal string into bytes.
|
|
6
|
+
* Converts a hexadecimal string into bytes. Alias of `fromHex`.
|
|
7
7
|
*/
|
|
8
|
-
export declare
|
|
8
|
+
export declare const hexToBytes: (value: string) => Uint8Array;
|
|
9
9
|
//# sourceMappingURL=cryptoUtils.hex.d.ts.map
|
|
@@ -1,25 +1,10 @@
|
|
|
1
|
+
import { toHex, fromHex } from "../../cryptoEncoding/encoding/cryptoEncoding.hex.js";
|
|
1
2
|
/**
|
|
2
|
-
* Converts bytes into a hexadecimal string.
|
|
3
|
+
* Converts bytes into a hexadecimal string. Alias of `toHex`.
|
|
3
4
|
*/
|
|
4
|
-
export
|
|
5
|
-
return Array.from(value)
|
|
6
|
-
.map((b) => b.toString(16).padStart(2, "0"))
|
|
7
|
-
.join("");
|
|
8
|
-
}
|
|
5
|
+
export const bytesToHex = toHex;
|
|
9
6
|
/**
|
|
10
|
-
* Converts a hexadecimal string into bytes.
|
|
7
|
+
* Converts a hexadecimal string into bytes. Alias of `fromHex`.
|
|
11
8
|
*/
|
|
12
|
-
export
|
|
13
|
-
if (typeof value !== "string") {
|
|
14
|
-
throw new TypeError("Hex value must be a string.");
|
|
15
|
-
}
|
|
16
|
-
if (value.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(value)) {
|
|
17
|
-
throw new TypeError("Invalid hexadecimal value.");
|
|
18
|
-
}
|
|
19
|
-
const result = new Uint8Array(value.length / 2);
|
|
20
|
-
for (let i = 0; i < value.length; i += 2) {
|
|
21
|
-
result[i / 2] = parseInt(value.slice(i, i + 2), 16);
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
9
|
+
export const hexToBytes = fromHex;
|
|
25
10
|
//# sourceMappingURL=cryptoUtils.hex.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
* @zudojs/crypto
|
|
3
3
|
*
|
|
4
4
|
* Cryptographic primitives for the Zudojs framework.
|
|
5
|
-
* Provides symmetric
|
|
5
|
+
* Provides symmetric encryption, hashing, password hashing,
|
|
6
6
|
* digital signatures, key derivation, and secure random generation.
|
|
7
7
|
*/
|
|
8
8
|
export * from "./compare/index.js";
|
|
9
9
|
export * from "./cryptoProvider/index.js";
|
|
10
10
|
export * from "./node/index.js";
|
|
11
|
-
export * from "./cryptoAlgorithm/index.js";
|
|
12
11
|
export * from "./cryptoCipher/index.js";
|
|
13
12
|
export * from "./cryptoConstants/index.js";
|
|
14
13
|
export * from "./cryptoEncoding/index.js";
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
* @zudojs/crypto
|
|
3
3
|
*
|
|
4
4
|
* Cryptographic primitives for the Zudojs framework.
|
|
5
|
-
* Provides symmetric
|
|
5
|
+
* Provides symmetric encryption, hashing, password hashing,
|
|
6
6
|
* digital signatures, key derivation, and secure random generation.
|
|
7
7
|
*/
|
|
8
8
|
export * from "./compare/index.js";
|
|
9
9
|
export * from "./cryptoProvider/index.js";
|
|
10
10
|
export * from "./node/index.js";
|
|
11
|
-
export * from "./cryptoAlgorithm/index.js";
|
|
12
11
|
export * from "./cryptoCipher/index.js";
|
|
13
12
|
export * from "./cryptoConstants/index.js";
|
|
14
13
|
export * from "./cryptoEncoding/index.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CryptoProvider, HashAlgorithm, HmacAlgorithm,
|
|
1
|
+
import type { CryptoProvider, HashAlgorithm, HmacAlgorithm, CryptoInput, EncryptedData, EncryptOptions, DecryptOptions, SignOptions, VerifyOptions, DeriveKeyOptions, PasswordHashProviderOptions } from "../../cryptoProvider/index.js";
|
|
2
2
|
import type { CryptoCapabilities } from "../../cryptoProvider/cryptoProvider.type.js";
|
|
3
3
|
export declare class NodeCryptoProvider implements CryptoProvider {
|
|
4
4
|
readonly name = "node";
|
|
@@ -8,35 +8,12 @@ export declare class NodeCryptoProvider implements CryptoProvider {
|
|
|
8
8
|
randomUUID(): Promise<string>;
|
|
9
9
|
hash(algorithm: HashAlgorithm, data: CryptoInput): Promise<Uint8Array>;
|
|
10
10
|
hmac(algorithm: HmacAlgorithm, key: CryptoInput, data: CryptoInput): Promise<Uint8Array>;
|
|
11
|
-
encrypt(options:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
nonce?: Uint8Array;
|
|
16
|
-
}): Promise<EncryptedData>;
|
|
17
|
-
decrypt(options: {
|
|
18
|
-
key: CryptoInput;
|
|
19
|
-
encrypted: EncryptedData;
|
|
20
|
-
associatedData?: CryptoInput;
|
|
21
|
-
}): Promise<Uint8Array>;
|
|
22
|
-
sign(options: {
|
|
23
|
-
key: CryptoInput;
|
|
24
|
-
data: CryptoInput;
|
|
25
|
-
algorithm?: SignatureAlgorithm;
|
|
26
|
-
}): Promise<Uint8Array>;
|
|
27
|
-
verify(options: {
|
|
28
|
-
key: CryptoInput;
|
|
29
|
-
data: CryptoInput;
|
|
30
|
-
signature: Uint8Array;
|
|
31
|
-
algorithm?: SignatureAlgorithm;
|
|
32
|
-
}): Promise<boolean>;
|
|
11
|
+
encrypt(options: EncryptOptions): Promise<EncryptedData>;
|
|
12
|
+
decrypt(options: DecryptOptions): Promise<Uint8Array>;
|
|
13
|
+
sign(options: SignOptions): Promise<Uint8Array>;
|
|
14
|
+
verify(options: VerifyOptions): Promise<boolean>;
|
|
33
15
|
deriveKey(options: DeriveKeyOptions): Promise<Uint8Array>;
|
|
34
|
-
hashPassword(password: CryptoInput, options?:
|
|
35
|
-
algorithm?: KeyDerivationAlgorithm;
|
|
36
|
-
memoryCost?: number;
|
|
37
|
-
timeCost?: number;
|
|
38
|
-
parallelism?: number;
|
|
39
|
-
}): Promise<string>;
|
|
16
|
+
hashPassword(password: CryptoInput, options?: PasswordHashProviderOptions): Promise<string>;
|
|
40
17
|
verifyPassword(password: CryptoInput, hash: string): Promise<boolean>;
|
|
41
18
|
}
|
|
42
19
|
//# sourceMappingURL=nodeCryptoProvider.core.d.ts.map
|