@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,12 +1,14 @@
|
|
|
1
|
-
import { TimeMs } from "@zudojs/constants";
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* Cryptographic algorithms implemented by Zudojs.
|
|
3
|
+
*
|
|
4
|
+
* Every member listed here is implemented by the Node provider. Algorithms
|
|
5
|
+
* that are not implemented (AES-CBC, ChaCha20-Poly1305, Argon2id, X25519,
|
|
6
|
+
* bcrypt) are deliberately absent so that the type system and the runtime
|
|
7
|
+
* agree on what is supported.
|
|
4
8
|
*/
|
|
5
9
|
export var CryptoAlgorithm;
|
|
6
10
|
(function (CryptoAlgorithm) {
|
|
7
11
|
CryptoAlgorithm["AES_256_GCM"] = "aes-256-gcm";
|
|
8
|
-
CryptoAlgorithm["AES_256_CBC"] = "aes-256-cbc";
|
|
9
|
-
CryptoAlgorithm["CHACHA20_POLY1305"] = "chacha20-poly1305";
|
|
10
12
|
CryptoAlgorithm["SHA_256"] = "sha256";
|
|
11
13
|
CryptoAlgorithm["SHA_384"] = "sha384";
|
|
12
14
|
CryptoAlgorithm["SHA_512"] = "sha512";
|
|
@@ -17,18 +19,16 @@ export var CryptoAlgorithm;
|
|
|
17
19
|
CryptoAlgorithm["HMAC_SHA384"] = "hmac-sha384";
|
|
18
20
|
CryptoAlgorithm["HMAC_SHA512"] = "hmac-sha512";
|
|
19
21
|
CryptoAlgorithm["PBKDF2_SHA256"] = "pbkdf2-sha256";
|
|
22
|
+
CryptoAlgorithm["PBKDF2_SHA384"] = "pbkdf2-sha384";
|
|
20
23
|
CryptoAlgorithm["PBKDF2_SHA512"] = "pbkdf2-sha512";
|
|
21
24
|
CryptoAlgorithm["SCRYPT"] = "scrypt";
|
|
22
|
-
CryptoAlgorithm["ARGON2ID"] = "argon2id";
|
|
23
25
|
CryptoAlgorithm["ED25519"] = "ed25519";
|
|
24
|
-
CryptoAlgorithm["X25519"] = "x25519";
|
|
25
26
|
})(CryptoAlgorithm || (CryptoAlgorithm = {}));
|
|
26
27
|
/**
|
|
27
28
|
* Algorithms that provide authenticated encryption.
|
|
28
29
|
*/
|
|
29
30
|
export const AEAD_ALGORITHMS = Object.freeze([
|
|
30
31
|
CryptoAlgorithm.AES_256_GCM,
|
|
31
|
-
CryptoAlgorithm.CHACHA20_POLY1305,
|
|
32
32
|
]);
|
|
33
33
|
/**
|
|
34
34
|
* Algorithms intended for hashing.
|
|
@@ -46,9 +46,9 @@ export const HASH_ALGORITHMS = Object.freeze([
|
|
|
46
46
|
*/
|
|
47
47
|
export const KEY_DERIVATION_ALGORITHMS = Object.freeze([
|
|
48
48
|
CryptoAlgorithm.PBKDF2_SHA256,
|
|
49
|
+
CryptoAlgorithm.PBKDF2_SHA384,
|
|
49
50
|
CryptoAlgorithm.PBKDF2_SHA512,
|
|
50
51
|
CryptoAlgorithm.SCRYPT,
|
|
51
|
-
CryptoAlgorithm.ARGON2ID,
|
|
52
52
|
]);
|
|
53
53
|
/**
|
|
54
54
|
* Algorithms intended for message authentication.
|
|
@@ -58,8 +58,22 @@ export const MAC_ALGORITHMS = Object.freeze([
|
|
|
58
58
|
CryptoAlgorithm.HMAC_SHA384,
|
|
59
59
|
CryptoAlgorithm.HMAC_SHA512,
|
|
60
60
|
]);
|
|
61
|
+
/**
|
|
62
|
+
* Key algorithms intended for digital signatures.
|
|
63
|
+
*
|
|
64
|
+
* Only Ed25519 keys are representable as a `CryptoKey`. RSA and ECDSA
|
|
65
|
+
* signing is supported through `SignatureAlgorithm` with PEM/DER key
|
|
66
|
+
* material rather than through this enum.
|
|
67
|
+
*/
|
|
68
|
+
export const SIGNATURE_ALGORITHMS = Object.freeze([
|
|
69
|
+
CryptoAlgorithm.ED25519,
|
|
70
|
+
]);
|
|
61
71
|
/**
|
|
62
72
|
* AES-GCM constants.
|
|
73
|
+
*
|
|
74
|
+
* The 96-bit IV and 128-bit authentication tag are the only sizes accepted
|
|
75
|
+
* by this package: shorter tags weaken forgery resistance and non-96-bit
|
|
76
|
+
* IVs are GHASH-derived, which shrinks the effective nonce space.
|
|
63
77
|
*/
|
|
64
78
|
export const AES_GCM = Object.freeze({
|
|
65
79
|
KEY_BYTES: 32,
|
|
@@ -87,6 +101,7 @@ export const KEY_SIZE = Object.freeze({
|
|
|
87
101
|
AES_256_BITS: 256,
|
|
88
102
|
ED25519_BITS: 256,
|
|
89
103
|
MIN_SYMMETRIC_KEY_BITS: 128,
|
|
104
|
+
MIN_HMAC_KEY_BYTES: 16,
|
|
90
105
|
});
|
|
91
106
|
/**
|
|
92
107
|
* Encoding constants.
|
|
@@ -98,19 +113,26 @@ export const ENCODING = Object.freeze({
|
|
|
98
113
|
UTF8: "utf8",
|
|
99
114
|
});
|
|
100
115
|
/**
|
|
101
|
-
* Cryptographic algorithm identifiers.
|
|
116
|
+
* Cryptographic algorithm identifiers as a plain constant object.
|
|
117
|
+
*
|
|
118
|
+
* Mirrors `CryptoAlgorithm` exactly (same names and values) for callers
|
|
119
|
+
* that prefer `as const` objects over enums.
|
|
102
120
|
*/
|
|
103
121
|
export const CRYPTO_ALGORITHM = Object.freeze({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
AES_256_GCM: "aes-256-gcm",
|
|
123
|
+
SHA_256: "sha256",
|
|
124
|
+
SHA_384: "sha384",
|
|
125
|
+
SHA_512: "sha512",
|
|
107
126
|
SHA3_256: "sha3-256",
|
|
108
127
|
SHA3_384: "sha3-384",
|
|
109
128
|
SHA3_512: "sha3-512",
|
|
110
|
-
|
|
111
|
-
|
|
129
|
+
HMAC_SHA256: "hmac-sha256",
|
|
130
|
+
HMAC_SHA384: "hmac-sha384",
|
|
131
|
+
HMAC_SHA512: "hmac-sha512",
|
|
112
132
|
PBKDF2_SHA256: "pbkdf2-sha256",
|
|
133
|
+
PBKDF2_SHA384: "pbkdf2-sha384",
|
|
113
134
|
PBKDF2_SHA512: "pbkdf2-sha512",
|
|
114
135
|
SCRYPT: "scrypt",
|
|
136
|
+
ED25519: "ed25519",
|
|
115
137
|
});
|
|
116
138
|
//# sourceMappingURL=cryptoConstants.type.js.map
|
|
@@ -2,7 +2,10 @@ import type { CryptoEncoding } from "./cryptoEncoding.core.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Compares two encoded values using constant-time comparison.
|
|
4
4
|
*
|
|
5
|
-
* Both values must use the same encoding.
|
|
5
|
+
* Both values must use the same encoding. Returns false (rather than
|
|
6
|
+
* throwing) when either value is not a valid, canonical encoding, so
|
|
7
|
+
* malleable encodings of the same bytes never compare equal to each other
|
|
8
|
+
* through a non-canonical form.
|
|
6
9
|
*/
|
|
7
10
|
export declare function timingSafeEqualEncoded(left: string, right: string, encoding?: CryptoEncoding): boolean;
|
|
8
11
|
//# sourceMappingURL=cryptoEncoding.compare.d.ts.map
|
|
@@ -3,12 +3,19 @@ import { decode } from "./cryptoEncoding.core.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Compares two encoded values using constant-time comparison.
|
|
5
5
|
*
|
|
6
|
-
* Both values must use the same encoding.
|
|
6
|
+
* Both values must use the same encoding. Returns false (rather than
|
|
7
|
+
* throwing) when either value is not a valid, canonical encoding, so
|
|
8
|
+
* malleable encodings of the same bytes never compare equal to each other
|
|
9
|
+
* through a non-canonical form.
|
|
7
10
|
*/
|
|
8
11
|
export function timingSafeEqualEncoded(left, right, encoding = "base64url") {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
let leftBytes;
|
|
13
|
+
let rightBytes;
|
|
14
|
+
try {
|
|
15
|
+
leftBytes = decode(left, encoding);
|
|
16
|
+
rightBytes = decode(right, encoding);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
12
19
|
return false;
|
|
13
20
|
}
|
|
14
21
|
return timingSafeEqual(leftBytes, rightBytes);
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Supported binary encodings.
|
|
3
|
+
*
|
|
4
|
+
* `utf8` is a text encoding, not a binary one: `encode(bytes, "utf8")`
|
|
5
|
+
* throws when the bytes are not valid UTF-8 rather than producing
|
|
6
|
+
* replacement characters.
|
|
3
7
|
*/
|
|
4
8
|
export type CryptoEncoding = "hex" | "base64" | "base64url" | "utf8";
|
|
9
|
+
/**
|
|
10
|
+
* Binary-safe encodings (every byte sequence round-trips).
|
|
11
|
+
*/
|
|
12
|
+
export type BinaryEncoding = Exclude<CryptoEncoding, "utf8">;
|
|
13
|
+
/**
|
|
14
|
+
* Returns whether a value names a supported encoding.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isCryptoEncoding(value: unknown): value is CryptoEncoding;
|
|
17
|
+
/**
|
|
18
|
+
* Returns whether a value names a binary-safe encoding.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isBinaryEncoding(value: unknown): value is BinaryEncoding;
|
|
21
|
+
/**
|
|
22
|
+
* Asserts that a value names a binary-safe encoding.
|
|
23
|
+
*/
|
|
24
|
+
export declare function assertBinaryEncoding(value: unknown): asserts value is BinaryEncoding;
|
|
5
25
|
/**
|
|
6
26
|
* Encodes bytes into a string.
|
|
7
27
|
*/
|
|
@@ -16,6 +36,8 @@ export declare function decode(value: string, encoding?: CryptoEncoding): Uint8A
|
|
|
16
36
|
export declare function utf8Encode(value: string): Uint8Array;
|
|
17
37
|
/**
|
|
18
38
|
* Decodes UTF-8 bytes into a string.
|
|
39
|
+
*
|
|
40
|
+
* Throws when the bytes are not well-formed UTF-8.
|
|
19
41
|
*/
|
|
20
42
|
export declare function utf8Decode(value: Uint8Array): string;
|
|
21
43
|
//# sourceMappingURL=cryptoEncoding.core.d.ts.map
|
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import { toHex, fromHex } from "./encoding/cryptoEncoding.hex.js";
|
|
2
2
|
import { toBase64, fromBase64 } from "./encoding/cryptoEncoding.base64.js";
|
|
3
3
|
import { toBase64Url, fromBase64Url, } from "./encoding/cryptoEncoding.base64url.js";
|
|
4
|
+
const CRYPTO_ENCODINGS = new Set([
|
|
5
|
+
"hex",
|
|
6
|
+
"base64",
|
|
7
|
+
"base64url",
|
|
8
|
+
"utf8",
|
|
9
|
+
]);
|
|
10
|
+
const BINARY_ENCODINGS = new Set([
|
|
11
|
+
"hex",
|
|
12
|
+
"base64",
|
|
13
|
+
"base64url",
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* Returns whether a value names a supported encoding.
|
|
17
|
+
*/
|
|
18
|
+
export function isCryptoEncoding(value) {
|
|
19
|
+
return typeof value === "string" && CRYPTO_ENCODINGS.has(value);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns whether a value names a binary-safe encoding.
|
|
23
|
+
*/
|
|
24
|
+
export function isBinaryEncoding(value) {
|
|
25
|
+
return typeof value === "string" && BINARY_ENCODINGS.has(value);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Asserts that a value names a binary-safe encoding.
|
|
29
|
+
*/
|
|
30
|
+
export function assertBinaryEncoding(value) {
|
|
31
|
+
if (!isBinaryEncoding(value)) {
|
|
32
|
+
throw new TypeError(`Unsupported binary encoding: ${String(value)}. Use hex, base64 or base64url.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
4
35
|
/**
|
|
5
36
|
* Encodes bytes into a string.
|
|
6
37
|
*/
|
|
@@ -14,7 +45,7 @@ export function encode(value, encoding = "base64url") {
|
|
|
14
45
|
case "base64url":
|
|
15
46
|
return toBase64Url(value);
|
|
16
47
|
case "utf8":
|
|
17
|
-
return
|
|
48
|
+
return utf8Decode(value);
|
|
18
49
|
default:
|
|
19
50
|
throw new TypeError(`Unsupported crypto encoding: ${String(encoding)}.`);
|
|
20
51
|
}
|
|
@@ -34,7 +65,7 @@ export function decode(value, encoding = "base64url") {
|
|
|
34
65
|
case "base64url":
|
|
35
66
|
return fromBase64Url(value);
|
|
36
67
|
case "utf8":
|
|
37
|
-
return
|
|
68
|
+
return utf8Encode(value);
|
|
38
69
|
default:
|
|
39
70
|
throw new TypeError(`Unsupported crypto encoding: ${String(encoding)}.`);
|
|
40
71
|
}
|
|
@@ -50,10 +81,17 @@ export function utf8Encode(value) {
|
|
|
50
81
|
}
|
|
51
82
|
/**
|
|
52
83
|
* Decodes UTF-8 bytes into a string.
|
|
84
|
+
*
|
|
85
|
+
* Throws when the bytes are not well-formed UTF-8.
|
|
53
86
|
*/
|
|
54
87
|
export function utf8Decode(value) {
|
|
55
88
|
assertBytes(value);
|
|
56
|
-
|
|
89
|
+
try {
|
|
90
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(value);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
throw new TypeError("Value is not valid UTF-8.", { cause: error });
|
|
94
|
+
}
|
|
57
95
|
}
|
|
58
96
|
function assertBytes(value) {
|
|
59
97
|
if (!(value instanceof Uint8Array)) {
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Encodes bytes as standard Base64.
|
|
2
|
+
* Encodes bytes as standard, padded Base64.
|
|
3
|
+
*
|
|
4
|
+
* An empty byte array encodes to the empty string.
|
|
3
5
|
*/
|
|
4
6
|
export declare function toBase64(value: Uint8Array): string;
|
|
5
7
|
/**
|
|
6
8
|
* Decodes standard Base64 into bytes.
|
|
9
|
+
*
|
|
10
|
+
* Input must be canonical: padded to a multiple of four characters, using
|
|
11
|
+
* only the standard alphabet, with zero-valued trailing bits. The empty
|
|
12
|
+
* string decodes to an empty byte array.
|
|
7
13
|
*/
|
|
8
14
|
export declare function fromBase64(value: string): Uint8Array;
|
|
9
15
|
/**
|
|
10
|
-
* Returns whether a string is valid standard Base64.
|
|
16
|
+
* Returns whether a string is valid, canonical standard Base64.
|
|
17
|
+
*
|
|
18
|
+
* The empty string is valid (it encodes zero bytes).
|
|
11
19
|
*/
|
|
12
20
|
export declare function isBase64(value: string): boolean;
|
|
13
21
|
//# sourceMappingURL=cryptoEncoding.base64.d.ts.map
|
|
@@ -1,35 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Encodes bytes as standard Base64.
|
|
2
|
+
* Encodes bytes as standard, padded Base64.
|
|
3
|
+
*
|
|
4
|
+
* An empty byte array encodes to the empty string.
|
|
3
5
|
*/
|
|
4
6
|
export function toBase64(value) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.join("");
|
|
8
|
-
return btoa(binary);
|
|
7
|
+
assertBytes(value);
|
|
8
|
+
return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64");
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Decodes standard Base64 into bytes.
|
|
12
|
+
*
|
|
13
|
+
* Input must be canonical: padded to a multiple of four characters, using
|
|
14
|
+
* only the standard alphabet, with zero-valued trailing bits. The empty
|
|
15
|
+
* string decodes to an empty byte array.
|
|
12
16
|
*/
|
|
13
17
|
export function fromBase64(value) {
|
|
14
18
|
if (!isBase64(value)) {
|
|
15
19
|
throw new TypeError("Invalid Base64 value.");
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
const result = new Uint8Array(binary.length);
|
|
19
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
20
|
-
result[i] = binary.charCodeAt(i);
|
|
21
|
-
}
|
|
22
|
-
return result;
|
|
21
|
+
return new Uint8Array(Buffer.from(value, "base64"));
|
|
23
22
|
}
|
|
24
23
|
/**
|
|
25
|
-
* Returns whether a string is valid standard Base64.
|
|
24
|
+
* Returns whether a string is valid, canonical standard Base64.
|
|
25
|
+
*
|
|
26
|
+
* The empty string is valid (it encodes zero bytes).
|
|
26
27
|
*/
|
|
27
28
|
export function isBase64(value) {
|
|
28
|
-
if (typeof value !== "string" ||
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
if (typeof value !== "string" || value.length % 4 !== 0) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {
|
|
31
33
|
return false;
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
// Reject non-canonical encodings (non-zero trailing bits).
|
|
36
|
+
return Buffer.from(value, "base64").toString("base64") === value;
|
|
37
|
+
}
|
|
38
|
+
function assertBytes(value) {
|
|
39
|
+
if (!(value instanceof Uint8Array)) {
|
|
40
|
+
throw new TypeError("Value must be a Uint8Array.");
|
|
41
|
+
}
|
|
34
42
|
}
|
|
35
43
|
//# sourceMappingURL=cryptoEncoding.base64.js.map
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Encodes bytes as URL-safe Base64 without padding.
|
|
3
|
+
*
|
|
4
|
+
* An empty byte array encodes to the empty string.
|
|
3
5
|
*/
|
|
4
6
|
export declare function toBase64Url(value: Uint8Array): string;
|
|
5
7
|
/**
|
|
6
8
|
* Decodes URL-safe Base64 into bytes.
|
|
9
|
+
*
|
|
10
|
+
* Input must be canonical: unpadded, using only the URL-safe alphabet,
|
|
11
|
+
* never of length ≡ 1 (mod 4), and with zero-valued trailing bits. The
|
|
12
|
+
* empty string decodes to an empty byte array.
|
|
7
13
|
*/
|
|
8
14
|
export declare function fromBase64Url(value: string): Uint8Array;
|
|
9
15
|
/**
|
|
10
|
-
* Returns whether a string is valid URL-safe Base64.
|
|
16
|
+
* Returns whether a string is valid, canonical URL-safe Base64.
|
|
17
|
+
*
|
|
18
|
+
* The empty string is valid (it encodes zero bytes).
|
|
11
19
|
*/
|
|
12
20
|
export declare function isBase64Url(value: string): boolean;
|
|
13
21
|
//# sourceMappingURL=cryptoEncoding.base64url.d.ts.map
|
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
import { toBase64 } from "./cryptoEncoding.base64.js";
|
|
2
|
-
import { fromBase64 } from "./cryptoEncoding.base64.js";
|
|
3
1
|
/**
|
|
4
2
|
* Encodes bytes as URL-safe Base64 without padding.
|
|
3
|
+
*
|
|
4
|
+
* An empty byte array encodes to the empty string.
|
|
5
5
|
*/
|
|
6
6
|
export function toBase64Url(value) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.replace(/\//g, "_")
|
|
10
|
-
.replace(/=+$/, "");
|
|
7
|
+
assertBytes(value);
|
|
8
|
+
return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64url");
|
|
11
9
|
}
|
|
12
10
|
/**
|
|
13
11
|
* Decodes URL-safe Base64 into bytes.
|
|
12
|
+
*
|
|
13
|
+
* Input must be canonical: unpadded, using only the URL-safe alphabet,
|
|
14
|
+
* never of length ≡ 1 (mod 4), and with zero-valued trailing bits. The
|
|
15
|
+
* empty string decodes to an empty byte array.
|
|
14
16
|
*/
|
|
15
17
|
export function fromBase64Url(value) {
|
|
16
|
-
if (value.length === 0) {
|
|
17
|
-
return new Uint8Array();
|
|
18
|
-
}
|
|
19
18
|
if (!isBase64Url(value)) {
|
|
20
19
|
throw new TypeError("Invalid Base64URL value.");
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
throw new TypeError("Invalid Base64URL length.");
|
|
24
|
-
}
|
|
25
|
-
let base64 = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
26
|
-
while (base64.length % 4) {
|
|
27
|
-
base64 += "=";
|
|
28
|
-
}
|
|
29
|
-
return fromBase64(base64);
|
|
21
|
+
return new Uint8Array(Buffer.from(value, "base64url"));
|
|
30
22
|
}
|
|
31
23
|
/**
|
|
32
|
-
* Returns whether a string is valid URL-safe Base64.
|
|
24
|
+
* Returns whether a string is valid, canonical URL-safe Base64.
|
|
25
|
+
*
|
|
26
|
+
* The empty string is valid (it encodes zero bytes).
|
|
33
27
|
*/
|
|
34
28
|
export function isBase64Url(value) {
|
|
35
|
-
if (typeof value !== "string" || value.length ===
|
|
29
|
+
if (typeof value !== "string" || value.length % 4 === 1) {
|
|
36
30
|
return false;
|
|
37
31
|
}
|
|
38
|
-
|
|
32
|
+
if (!/^[A-Za-z0-9_-]*$/.test(value)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
// Reject non-canonical encodings (non-zero trailing bits).
|
|
36
|
+
return Buffer.from(value, "base64url").toString("base64url") === value;
|
|
37
|
+
}
|
|
38
|
+
function assertBytes(value) {
|
|
39
|
+
if (!(value instanceof Uint8Array)) {
|
|
40
|
+
throw new TypeError("Value must be a Uint8Array.");
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
//# sourceMappingURL=cryptoEncoding.base64url.js.map
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Encodes bytes as hexadecimal.
|
|
2
|
+
* Encodes bytes as lowercase hexadecimal.
|
|
3
|
+
*
|
|
4
|
+
* An empty byte array encodes to the empty string.
|
|
3
5
|
*/
|
|
4
6
|
export declare function toHex(value: Uint8Array): string;
|
|
5
7
|
/**
|
|
6
8
|
* Decodes hexadecimal into bytes.
|
|
9
|
+
*
|
|
10
|
+
* Both upper- and lowercase digits are accepted. The empty string decodes
|
|
11
|
+
* to an empty byte array. Throws for odd lengths or non-hex characters.
|
|
7
12
|
*/
|
|
8
13
|
export declare function fromHex(value: string): Uint8Array;
|
|
9
14
|
/**
|
|
10
|
-
* Returns whether a string is valid hexadecimal.
|
|
15
|
+
* Returns whether a string is valid hexadecimal (even length, hex digits only).
|
|
16
|
+
*
|
|
17
|
+
* The empty string is valid (it encodes zero bytes).
|
|
11
18
|
*/
|
|
12
19
|
export declare function isHex(value: string): boolean;
|
|
13
20
|
//# sourceMappingURL=cryptoEncoding.hex.d.ts.map
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Encodes bytes as hexadecimal.
|
|
2
|
+
* Encodes bytes as lowercase hexadecimal.
|
|
3
|
+
*
|
|
4
|
+
* An empty byte array encodes to the empty string.
|
|
3
5
|
*/
|
|
4
6
|
export function toHex(value) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.join("");
|
|
7
|
+
assertBytes(value);
|
|
8
|
+
return Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("hex");
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* Decodes hexadecimal into bytes.
|
|
12
|
+
*
|
|
13
|
+
* Both upper- and lowercase digits are accepted. The empty string decodes
|
|
14
|
+
* to an empty byte array. Throws for odd lengths or non-hex characters.
|
|
11
15
|
*/
|
|
12
16
|
export function fromHex(value) {
|
|
13
17
|
if (!isHex(value)) {
|
|
14
18
|
throw new TypeError("Invalid hexadecimal value.");
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
for (let i = 0; i < value.length; i += 2) {
|
|
18
|
-
result[i / 2] = parseInt(value.slice(i, i + 2), 16);
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
20
|
+
return new Uint8Array(Buffer.from(value, "hex"));
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Returns whether a string is valid hexadecimal.
|
|
23
|
+
* Returns whether a string is valid hexadecimal (even length, hex digits only).
|
|
24
|
+
*
|
|
25
|
+
* The empty string is valid (it encodes zero bytes).
|
|
24
26
|
*/
|
|
25
27
|
export function isHex(value) {
|
|
26
28
|
return (typeof value === "string" &&
|
|
27
|
-
value.length > 0 &&
|
|
28
29
|
value.length % 2 === 0 &&
|
|
29
30
|
/^[0-9a-fA-F]*$/.test(value));
|
|
30
31
|
}
|
|
32
|
+
function assertBytes(value) {
|
|
33
|
+
if (!(value instanceof Uint8Array)) {
|
|
34
|
+
throw new TypeError("Value must be a Uint8Array.");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
31
37
|
//# sourceMappingURL=cryptoEncoding.hex.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CryptoError, CryptoOperation } from "@zudojs/errors";
|
|
2
|
+
/**
|
|
3
|
+
* Builds a cipher error that preserves the underlying failure as `cause`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function cipherError(message: string, operation: CryptoOperation.ENCRYPT | CryptoOperation.DECRYPT, algorithm: string | undefined, cause?: unknown): CryptoError;
|
|
6
|
+
/**
|
|
7
|
+
* Builds a hashing error that preserves the underlying failure as `cause`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function hashError(message: string, algorithm: string | undefined, cause?: unknown): CryptoError;
|
|
10
|
+
/**
|
|
11
|
+
* Builds a signature error that preserves the underlying failure as `cause`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function signatureError(message: string, operation: CryptoOperation.SIGN | CryptoOperation.VERIFY_SIGNATURE, algorithm: string | undefined, cause?: unknown): CryptoError;
|
|
14
|
+
/**
|
|
15
|
+
* Builds a key derivation error that preserves the underlying failure as `cause`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function keyDerivationError(message: string, algorithm: string | undefined, cause?: unknown): CryptoError;
|
|
18
|
+
/**
|
|
19
|
+
* Builds a key error that preserves the underlying failure as `cause`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function keyError(message: string, operation: CryptoOperation.KEY_GENERATION | CryptoOperation.KEY_IMPORT | CryptoOperation.KEY_EXPORT, algorithm: string | undefined, cause?: unknown): CryptoError;
|
|
22
|
+
/**
|
|
23
|
+
* Builds a generic crypto error for an operation, preserving `cause`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function operationError(message: string, operation: CryptoOperation, cause?: unknown): CryptoError;
|
|
26
|
+
/**
|
|
27
|
+
* Re-throws CryptoErrors unchanged and wraps anything else.
|
|
28
|
+
*/
|
|
29
|
+
export declare function rethrowAsCryptoError(error: unknown, wrap: (cause: unknown) => CryptoError): never;
|
|
30
|
+
//# sourceMappingURL=cryptoErrors.helper.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CryptoError, CryptoOperation, ErrorCode, isCryptoError, } from "@zudojs/errors";
|
|
2
|
+
/**
|
|
3
|
+
* Builds a cipher error that preserves the underlying failure as `cause`.
|
|
4
|
+
*/
|
|
5
|
+
export function cipherError(message, operation, algorithm, cause) {
|
|
6
|
+
return new CryptoError(message, {
|
|
7
|
+
code: ErrorCode.CRYPTO_CIPHER,
|
|
8
|
+
operation,
|
|
9
|
+
algorithm,
|
|
10
|
+
cause,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Builds a hashing error that preserves the underlying failure as `cause`.
|
|
15
|
+
*/
|
|
16
|
+
export function hashError(message, algorithm, cause) {
|
|
17
|
+
return new CryptoError(message, {
|
|
18
|
+
code: ErrorCode.CRYPTO_HASH,
|
|
19
|
+
operation: CryptoOperation.HASH,
|
|
20
|
+
algorithm,
|
|
21
|
+
cause,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Builds a signature error that preserves the underlying failure as `cause`.
|
|
26
|
+
*/
|
|
27
|
+
export function signatureError(message, operation, algorithm, cause) {
|
|
28
|
+
return new CryptoError(message, {
|
|
29
|
+
code: ErrorCode.CRYPTO_SIGNATURE,
|
|
30
|
+
operation,
|
|
31
|
+
algorithm,
|
|
32
|
+
cause,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds a key derivation error that preserves the underlying failure as `cause`.
|
|
37
|
+
*/
|
|
38
|
+
export function keyDerivationError(message, algorithm, cause) {
|
|
39
|
+
return new CryptoError(message, {
|
|
40
|
+
code: ErrorCode.CRYPTO_DERIVATION,
|
|
41
|
+
operation: CryptoOperation.KEY_DERIVATION,
|
|
42
|
+
algorithm,
|
|
43
|
+
cause,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Builds a key error that preserves the underlying failure as `cause`.
|
|
48
|
+
*/
|
|
49
|
+
export function keyError(message, operation, algorithm, cause) {
|
|
50
|
+
return new CryptoError(message, {
|
|
51
|
+
code: ErrorCode.CRYPTO_KEY,
|
|
52
|
+
operation,
|
|
53
|
+
algorithm,
|
|
54
|
+
cause,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Builds a generic crypto error for an operation, preserving `cause`.
|
|
59
|
+
*/
|
|
60
|
+
export function operationError(message, operation, cause) {
|
|
61
|
+
return new CryptoError(message, { operation, cause });
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Re-throws CryptoErrors unchanged and wraps anything else.
|
|
65
|
+
*/
|
|
66
|
+
export function rethrowAsCryptoError(error, wrap) {
|
|
67
|
+
if (isCryptoError(error)) {
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
throw wrap(error);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=cryptoErrors.helper.js.map
|