@opentdf/sdk 0.1.0-beta.1701
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/README.md +52 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/src/access.js +155 -0
- package/dist/cjs/src/auth/Eas.js +60 -0
- package/dist/cjs/src/auth/auth.js +79 -0
- package/dist/cjs/src/auth/oidc-clientcredentials-provider.js +26 -0
- package/dist/cjs/src/auth/oidc-externaljwt-provider.js +33 -0
- package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +34 -0
- package/dist/cjs/src/auth/oidc.js +222 -0
- package/dist/cjs/src/auth/providers.js +143 -0
- package/dist/cjs/src/encodings/base64.js +154 -0
- package/dist/cjs/src/encodings/hex.js +70 -0
- package/dist/cjs/src/encodings/index.js +29 -0
- package/dist/cjs/src/errors.js +138 -0
- package/dist/cjs/src/index.js +344 -0
- package/dist/cjs/src/nanotdf/Client.js +296 -0
- package/dist/cjs/src/nanotdf/NanoTDF.js +94 -0
- package/dist/cjs/src/nanotdf/browser-entry.js +19 -0
- package/dist/cjs/src/nanotdf/constants.js +5 -0
- package/dist/cjs/src/nanotdf/decrypt.js +17 -0
- package/dist/cjs/src/nanotdf/encrypt-dataset.js +38 -0
- package/dist/cjs/src/nanotdf/encrypt.js +132 -0
- package/dist/cjs/src/nanotdf/enum/CipherEnum.js +13 -0
- package/dist/cjs/src/nanotdf/enum/CurveNameEnum.js +15 -0
- package/dist/cjs/src/nanotdf/enum/EncodingEnum.js +8 -0
- package/dist/cjs/src/nanotdf/enum/PolicyTypeEnum.js +11 -0
- package/dist/cjs/src/nanotdf/enum/ProtocolEnum.js +10 -0
- package/dist/cjs/src/nanotdf/enum/ResourceLocatorIdentifierEnum.js +11 -0
- package/dist/cjs/src/nanotdf/helpers/calculateByCurve.js +29 -0
- package/dist/cjs/src/nanotdf/helpers/getHkdfSalt.js +11 -0
- package/dist/cjs/src/nanotdf/index.js +25 -0
- package/dist/cjs/src/nanotdf/interfaces/PolicyInterface.js +3 -0
- package/dist/cjs/src/nanotdf/models/Ciphers.js +61 -0
- package/dist/cjs/src/nanotdf/models/DefaultParams.js +27 -0
- package/dist/cjs/src/nanotdf/models/EcCurves.js +39 -0
- package/dist/cjs/src/nanotdf/models/Header.js +255 -0
- package/dist/cjs/src/nanotdf/models/Payload.js +158 -0
- package/dist/cjs/src/nanotdf/models/Policy/AbstractPolicy.js +73 -0
- package/dist/cjs/src/nanotdf/models/Policy/EmbeddedPolicy.js +82 -0
- package/dist/cjs/src/nanotdf/models/Policy/PolicyFactory.js +38 -0
- package/dist/cjs/src/nanotdf/models/Policy/RemotePolicy.js +62 -0
- package/dist/cjs/src/nanotdf/models/ResourceLocator.js +211 -0
- package/dist/cjs/src/nanotdf/models/Signature.js +77 -0
- package/dist/cjs/src/nanotdf-crypto/ciphers.js +17 -0
- package/dist/cjs/src/nanotdf-crypto/decrypt.js +24 -0
- package/dist/cjs/src/nanotdf-crypto/digest.js +7 -0
- package/dist/cjs/src/nanotdf-crypto/ecdsaSignature.js +83 -0
- package/dist/cjs/src/nanotdf-crypto/encrypt.js +24 -0
- package/dist/cjs/src/nanotdf-crypto/enums.js +52 -0
- package/dist/cjs/src/nanotdf-crypto/exportCryptoKey.js +20 -0
- package/dist/cjs/src/nanotdf-crypto/generateKeyPair.js +13 -0
- package/dist/cjs/src/nanotdf-crypto/generateRandomNumber.js +12 -0
- package/dist/cjs/src/nanotdf-crypto/importRawKey.js +18 -0
- package/dist/cjs/src/nanotdf-crypto/index.js +52 -0
- package/dist/cjs/src/nanotdf-crypto/keyAgreement.js +91 -0
- package/dist/cjs/src/nanotdf-crypto/pemPublicToCrypto.js +225 -0
- package/dist/cjs/src/policy/api.js +58 -0
- package/dist/cjs/src/policy/attributes.js +3 -0
- package/dist/cjs/src/policy/granter.js +146 -0
- package/dist/cjs/src/tdf/AttributeObject.js +15 -0
- package/dist/cjs/src/tdf/AttributeObjectJwt.js +3 -0
- package/dist/cjs/src/tdf/Crypto.js +47 -0
- package/dist/cjs/src/tdf/EntityObject.js +3 -0
- package/dist/cjs/src/tdf/NanoTDF/NanoTDF.js +38 -0
- package/dist/cjs/src/tdf/Policy.js +50 -0
- package/dist/cjs/src/tdf/PolicyObject.js +3 -0
- package/dist/cjs/src/tdf/TypedArray.js +3 -0
- package/dist/cjs/src/tdf/index.js +35 -0
- package/dist/cjs/src/types/index.js +3 -0
- package/dist/cjs/src/utils.js +147 -0
- package/dist/cjs/src/version.js +12 -0
- package/dist/cjs/tdf3/index.js +57 -0
- package/dist/cjs/tdf3/src/assertions.js +118 -0
- package/dist/cjs/tdf3/src/binary.js +153 -0
- package/dist/cjs/tdf3/src/ciphers/aes-gcm-cipher.js +56 -0
- package/dist/cjs/tdf3/src/ciphers/algorithms.js +8 -0
- package/dist/cjs/tdf3/src/ciphers/index.js +8 -0
- package/dist/cjs/tdf3/src/ciphers/symmetric-cipher-base.js +22 -0
- package/dist/cjs/tdf3/src/client/DecoratedReadableStream.js +116 -0
- package/dist/cjs/tdf3/src/client/builders.js +561 -0
- package/dist/cjs/tdf3/src/client/index.js +460 -0
- package/dist/cjs/tdf3/src/client/validation.js +63 -0
- package/dist/cjs/tdf3/src/crypto/crypto-utils.js +116 -0
- package/dist/cjs/tdf3/src/crypto/declarations.js +8 -0
- package/dist/cjs/tdf3/src/crypto/index.js +315 -0
- package/dist/cjs/tdf3/src/index.js +34 -0
- package/dist/cjs/tdf3/src/models/attribute-set.js +122 -0
- package/dist/cjs/tdf3/src/models/encryption-information.js +90 -0
- package/dist/cjs/tdf3/src/models/index.js +25 -0
- package/dist/cjs/tdf3/src/models/key-access.js +103 -0
- package/dist/cjs/tdf3/src/models/manifest.js +3 -0
- package/dist/cjs/tdf3/src/models/payload.js +3 -0
- package/dist/cjs/tdf3/src/models/policy.js +24 -0
- package/dist/cjs/tdf3/src/models/upsert-response.js +3 -0
- package/dist/cjs/tdf3/src/tdf.js +907 -0
- package/dist/cjs/tdf3/src/templates/default.html.js +98 -0
- package/dist/cjs/tdf3/src/templates/escaper.js +15 -0
- package/dist/cjs/tdf3/src/templates/index.js +12 -0
- package/dist/cjs/tdf3/src/utils/buffer-crc32.js +48 -0
- package/dist/cjs/tdf3/src/utils/chunkers.js +106 -0
- package/dist/cjs/tdf3/src/utils/index.js +296 -0
- package/dist/cjs/tdf3/src/utils/keysplit.js +61 -0
- package/dist/cjs/tdf3/src/utils/zip-reader.js +253 -0
- package/dist/cjs/tdf3/src/utils/zip-writer.js +308 -0
- package/dist/cjs/tdf3/src/version.js +6 -0
- package/dist/types/src/access.d.ts +47 -0
- package/dist/types/src/access.d.ts.map +1 -0
- package/dist/types/src/auth/Eas.d.ts +34 -0
- package/dist/types/src/auth/Eas.d.ts.map +1 -0
- package/dist/types/src/auth/auth.d.ts +86 -0
- package/dist/types/src/auth/auth.d.ts.map +1 -0
- package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts +9 -0
- package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts.map +1 -0
- package/dist/types/src/auth/oidc-externaljwt-provider.d.ts +10 -0
- package/dist/types/src/auth/oidc-externaljwt-provider.d.ts.map +1 -0
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +10 -0
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -0
- package/dist/types/src/auth/oidc.d.ts +104 -0
- package/dist/types/src/auth/oidc.d.ts.map +1 -0
- package/dist/types/src/auth/providers.d.ts +67 -0
- package/dist/types/src/auth/providers.d.ts.map +1 -0
- package/dist/types/src/encodings/base64.d.ts +18 -0
- package/dist/types/src/encodings/base64.d.ts.map +1 -0
- package/dist/types/src/encodings/hex.d.ts +5 -0
- package/dist/types/src/encodings/hex.d.ts.map +1 -0
- package/dist/types/src/encodings/index.d.ts +3 -0
- package/dist/types/src/encodings/index.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +72 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +138 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/nanotdf/Client.d.ts +95 -0
- package/dist/types/src/nanotdf/Client.d.ts.map +1 -0
- package/dist/types/src/nanotdf/NanoTDF.d.ts +25 -0
- package/dist/types/src/nanotdf/NanoTDF.d.ts.map +1 -0
- package/dist/types/src/nanotdf/browser-entry.d.ts +17 -0
- package/dist/types/src/nanotdf/browser-entry.d.ts.map +1 -0
- package/dist/types/src/nanotdf/constants.d.ts +2 -0
- package/dist/types/src/nanotdf/constants.d.ts.map +1 -0
- package/dist/types/src/nanotdf/decrypt.d.ts +9 -0
- package/dist/types/src/nanotdf/decrypt.d.ts.map +1 -0
- package/dist/types/src/nanotdf/encrypt-dataset.d.ts +12 -0
- package/dist/types/src/nanotdf/encrypt-dataset.d.ts.map +1 -0
- package/dist/types/src/nanotdf/encrypt.d.ts +14 -0
- package/dist/types/src/nanotdf/encrypt.d.ts.map +1 -0
- package/dist/types/src/nanotdf/enum/CipherEnum.d.ts +10 -0
- package/dist/types/src/nanotdf/enum/CipherEnum.d.ts.map +1 -0
- package/dist/types/src/nanotdf/enum/CurveNameEnum.d.ts +12 -0
- package/dist/types/src/nanotdf/enum/CurveNameEnum.d.ts.map +1 -0
- package/dist/types/src/nanotdf/enum/EncodingEnum.d.ts +5 -0
- package/dist/types/src/nanotdf/enum/EncodingEnum.d.ts.map +1 -0
- package/dist/types/src/nanotdf/enum/PolicyTypeEnum.d.ts +8 -0
- package/dist/types/src/nanotdf/enum/PolicyTypeEnum.d.ts.map +1 -0
- package/dist/types/src/nanotdf/enum/ProtocolEnum.d.ts +7 -0
- package/dist/types/src/nanotdf/enum/ProtocolEnum.d.ts.map +1 -0
- package/dist/types/src/nanotdf/enum/ResourceLocatorIdentifierEnum.d.ts +8 -0
- package/dist/types/src/nanotdf/enum/ResourceLocatorIdentifierEnum.d.ts.map +1 -0
- package/dist/types/src/nanotdf/helpers/calculateByCurve.d.ts +20 -0
- package/dist/types/src/nanotdf/helpers/calculateByCurve.d.ts.map +1 -0
- package/dist/types/src/nanotdf/helpers/getHkdfSalt.d.ts +9 -0
- package/dist/types/src/nanotdf/helpers/getHkdfSalt.d.ts.map +1 -0
- package/dist/types/src/nanotdf/index.d.ts +9 -0
- package/dist/types/src/nanotdf/index.d.ts.map +1 -0
- package/dist/types/src/nanotdf/interfaces/PolicyInterface.d.ts +17 -0
- package/dist/types/src/nanotdf/interfaces/PolicyInterface.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/Ciphers.d.ts +14 -0
- package/dist/types/src/nanotdf/models/Ciphers.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/DefaultParams.d.ts +21 -0
- package/dist/types/src/nanotdf/models/DefaultParams.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/EcCurves.d.ts +15 -0
- package/dist/types/src/nanotdf/models/EcCurves.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/Header.d.ts +73 -0
- package/dist/types/src/nanotdf/models/Header.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/Payload.d.ts +47 -0
- package/dist/types/src/nanotdf/models/Payload.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/Policy/AbstractPolicy.d.ts +52 -0
- package/dist/types/src/nanotdf/models/Policy/AbstractPolicy.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/Policy/EmbeddedPolicy.d.ts +35 -0
- package/dist/types/src/nanotdf/models/Policy/EmbeddedPolicy.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/Policy/PolicyFactory.d.ts +11 -0
- package/dist/types/src/nanotdf/models/Policy/PolicyFactory.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/Policy/RemotePolicy.d.ts +31 -0
- package/dist/types/src/nanotdf/models/Policy/RemotePolicy.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/ResourceLocator.d.ts +65 -0
- package/dist/types/src/nanotdf/models/ResourceLocator.d.ts.map +1 -0
- package/dist/types/src/nanotdf/models/Signature.d.ts +33 -0
- package/dist/types/src/nanotdf/models/Signature.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/ciphers.d.ts +8 -0
- package/dist/types/src/nanotdf-crypto/ciphers.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/decrypt.d.ts +14 -0
- package/dist/types/src/nanotdf-crypto/decrypt.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/digest.d.ts +3 -0
- package/dist/types/src/nanotdf-crypto/digest.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/ecdsaSignature.d.ts +35 -0
- package/dist/types/src/nanotdf-crypto/ecdsaSignature.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/encrypt.d.ts +14 -0
- package/dist/types/src/nanotdf-crypto/encrypt.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/enums.d.ts +42 -0
- package/dist/types/src/nanotdf-crypto/enums.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/exportCryptoKey.d.ts +7 -0
- package/dist/types/src/nanotdf-crypto/exportCryptoKey.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts +10 -0
- package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts +5 -0
- package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/importRawKey.d.ts +13 -0
- package/dist/types/src/nanotdf-crypto/importRawKey.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/index.d.ts +12 -0
- package/dist/types/src/nanotdf-crypto/index.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/keyAgreement.d.ts +28 -0
- package/dist/types/src/nanotdf-crypto/keyAgreement.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/pemPublicToCrypto.d.ts +28 -0
- package/dist/types/src/nanotdf-crypto/pemPublicToCrypto.d.ts.map +1 -0
- package/dist/types/src/policy/api.d.ts +4 -0
- package/dist/types/src/policy/api.d.ts.map +1 -0
- package/dist/types/src/policy/attributes.d.ts +95 -0
- package/dist/types/src/policy/attributes.d.ts.map +1 -0
- package/dist/types/src/policy/granter.d.ts +23 -0
- package/dist/types/src/policy/granter.d.ts.map +1 -0
- package/dist/types/src/tdf/AttributeObject.d.ts +13 -0
- package/dist/types/src/tdf/AttributeObject.d.ts.map +1 -0
- package/dist/types/src/tdf/AttributeObjectJwt.d.ts +4 -0
- package/dist/types/src/tdf/AttributeObjectJwt.d.ts.map +1 -0
- package/dist/types/src/tdf/Crypto.d.ts +37 -0
- package/dist/types/src/tdf/Crypto.d.ts.map +1 -0
- package/dist/types/src/tdf/EntityObject.d.ts +18 -0
- package/dist/types/src/tdf/EntityObject.d.ts.map +1 -0
- package/dist/types/src/tdf/NanoTDF/NanoTDF.d.ts +99 -0
- package/dist/types/src/tdf/NanoTDF/NanoTDF.d.ts.map +1 -0
- package/dist/types/src/tdf/Policy.d.ts +28 -0
- package/dist/types/src/tdf/Policy.d.ts.map +1 -0
- package/dist/types/src/tdf/PolicyObject.d.ts +11 -0
- package/dist/types/src/tdf/PolicyObject.d.ts.map +1 -0
- package/dist/types/src/tdf/TypedArray.d.ts +3 -0
- package/dist/types/src/tdf/TypedArray.d.ts.map +1 -0
- package/dist/types/src/tdf/index.d.ts +7 -0
- package/dist/types/src/tdf/index.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +45 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/utils.d.ts +45 -0
- package/dist/types/src/utils.d.ts.map +1 -0
- package/dist/types/src/version.d.ts +9 -0
- package/dist/types/src/version.d.ts.map +1 -0
- package/dist/types/tdf3/index.d.ts +16 -0
- package/dist/types/tdf3/index.d.ts.map +1 -0
- package/dist/types/tdf3/src/assertions.d.ts +63 -0
- package/dist/types/tdf3/src/assertions.d.ts.map +1 -0
- package/dist/types/tdf3/src/binary.d.ts +38 -0
- package/dist/types/tdf3/src/binary.d.ts.map +1 -0
- package/dist/types/tdf3/src/ciphers/aes-gcm-cipher.d.ts +18 -0
- package/dist/types/tdf3/src/ciphers/aes-gcm-cipher.d.ts.map +1 -0
- package/dist/types/tdf3/src/ciphers/algorithms.d.ts +4 -0
- package/dist/types/tdf3/src/ciphers/algorithms.d.ts.map +1 -0
- package/dist/types/tdf3/src/ciphers/index.d.ts +3 -0
- package/dist/types/tdf3/src/ciphers/index.d.ts.map +1 -0
- package/dist/types/tdf3/src/ciphers/symmetric-cipher-base.d.ts +14 -0
- package/dist/types/tdf3/src/ciphers/symmetric-cipher-base.d.ts.map +1 -0
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts +53 -0
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts.map +1 -0
- package/dist/types/tdf3/src/client/builders.d.ts +436 -0
- package/dist/types/tdf3/src/client/builders.d.ts.map +1 -0
- package/dist/types/tdf3/src/client/index.d.ts +139 -0
- package/dist/types/tdf3/src/client/index.d.ts.map +1 -0
- package/dist/types/tdf3/src/client/validation.d.ts +8 -0
- package/dist/types/tdf3/src/client/validation.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts +34 -0
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/declarations.d.ts +60 -0
- package/dist/types/tdf3/src/crypto/declarations.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/index.d.ts +103 -0
- package/dist/types/tdf3/src/crypto/index.d.ts.map +1 -0
- package/dist/types/tdf3/src/index.d.ts +5 -0
- package/dist/types/tdf3/src/index.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/attribute-set.d.ts +65 -0
- package/dist/types/tdf3/src/models/attribute-set.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/encryption-information.d.ts +49 -0
- package/dist/types/tdf3/src/models/encryption-information.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/index.d.ts +9 -0
- package/dist/types/tdf3/src/models/index.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/key-access.d.ts +42 -0
- package/dist/types/tdf3/src/models/key-access.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/manifest.d.ts +9 -0
- package/dist/types/tdf3/src/models/manifest.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/payload.d.ts +7 -0
- package/dist/types/tdf3/src/models/payload.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/policy.d.ts +13 -0
- package/dist/types/tdf3/src/models/policy.d.ts.map +1 -0
- package/dist/types/tdf3/src/models/upsert-response.d.ts +16 -0
- package/dist/types/tdf3/src/models/upsert-response.d.ts.map +1 -0
- package/dist/types/tdf3/src/tdf.d.ts +152 -0
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -0
- package/dist/types/tdf3/src/templates/default.html.d.ts +8 -0
- package/dist/types/tdf3/src/templates/default.html.d.ts.map +1 -0
- package/dist/types/tdf3/src/templates/escaper.d.ts +6 -0
- package/dist/types/tdf3/src/templates/escaper.d.ts.map +1 -0
- package/dist/types/tdf3/src/templates/index.d.ts +3 -0
- package/dist/types/tdf3/src/templates/index.d.ts.map +1 -0
- package/dist/types/tdf3/src/utils/buffer-crc32.d.ts +2 -0
- package/dist/types/tdf3/src/utils/buffer-crc32.d.ts.map +1 -0
- package/dist/types/tdf3/src/utils/chunkers.d.ts +29 -0
- package/dist/types/tdf3/src/utils/chunkers.d.ts.map +1 -0
- package/dist/types/tdf3/src/utils/index.d.ts +36 -0
- package/dist/types/tdf3/src/utils/index.d.ts.map +1 -0
- package/dist/types/tdf3/src/utils/keysplit.d.ts +19 -0
- package/dist/types/tdf3/src/utils/keysplit.d.ts.map +1 -0
- package/dist/types/tdf3/src/utils/zip-reader.d.ts +63 -0
- package/dist/types/tdf3/src/utils/zip-reader.d.ts.map +1 -0
- package/dist/types/tdf3/src/utils/zip-writer.d.ts +35 -0
- package/dist/types/tdf3/src/utils/zip-writer.d.ts.map +1 -0
- package/dist/types/tdf3/src/version.d.ts +3 -0
- package/dist/types/tdf3/src/version.d.ts.map +1 -0
- package/dist/web/package.json +3 -0
- package/dist/web/src/access.js +147 -0
- package/dist/web/src/auth/Eas.js +55 -0
- package/dist/web/src/auth/auth.js +71 -0
- package/dist/web/src/auth/oidc-clientcredentials-provider.js +22 -0
- package/dist/web/src/auth/oidc-externaljwt-provider.js +29 -0
- package/dist/web/src/auth/oidc-refreshtoken-provider.js +30 -0
- package/dist/web/src/auth/oidc.js +215 -0
- package/dist/web/src/auth/providers.js +119 -0
- package/dist/web/src/encodings/base64.js +147 -0
- package/dist/web/src/encodings/hex.js +63 -0
- package/dist/web/src/encodings/index.js +3 -0
- package/dist/web/src/errors.js +123 -0
- package/dist/web/src/index.js +313 -0
- package/dist/web/src/nanotdf/Client.js +268 -0
- package/dist/web/src/nanotdf/NanoTDF.js +89 -0
- package/dist/web/src/nanotdf/browser-entry.js +14 -0
- package/dist/web/src/nanotdf/constants.js +2 -0
- package/dist/web/src/nanotdf/decrypt.js +14 -0
- package/dist/web/src/nanotdf/encrypt-dataset.js +32 -0
- package/dist/web/src/nanotdf/encrypt.js +126 -0
- package/dist/web/src/nanotdf/enum/CipherEnum.js +11 -0
- package/dist/web/src/nanotdf/enum/CurveNameEnum.js +13 -0
- package/dist/web/src/nanotdf/enum/EncodingEnum.js +6 -0
- package/dist/web/src/nanotdf/enum/PolicyTypeEnum.js +9 -0
- package/dist/web/src/nanotdf/enum/ProtocolEnum.js +8 -0
- package/dist/web/src/nanotdf/enum/ResourceLocatorIdentifierEnum.js +9 -0
- package/dist/web/src/nanotdf/helpers/calculateByCurve.js +24 -0
- package/dist/web/src/nanotdf/helpers/getHkdfSalt.js +8 -0
- package/dist/web/src/nanotdf/index.js +11 -0
- package/dist/web/src/nanotdf/interfaces/PolicyInterface.js +2 -0
- package/dist/web/src/nanotdf/models/Ciphers.js +54 -0
- package/dist/web/src/nanotdf/models/DefaultParams.js +22 -0
- package/dist/web/src/nanotdf/models/EcCurves.js +32 -0
- package/dist/web/src/nanotdf/models/Header.js +250 -0
- package/dist/web/src/nanotdf/models/Payload.js +156 -0
- package/dist/web/src/nanotdf/models/Policy/AbstractPolicy.js +71 -0
- package/dist/web/src/nanotdf/models/Policy/EmbeddedPolicy.js +77 -0
- package/dist/web/src/nanotdf/models/Policy/PolicyFactory.js +33 -0
- package/dist/web/src/nanotdf/models/Policy/RemotePolicy.js +57 -0
- package/dist/web/src/nanotdf/models/ResourceLocator.js +206 -0
- package/dist/web/src/nanotdf/models/Signature.js +74 -0
- package/dist/web/src/nanotdf-crypto/ciphers.js +14 -0
- package/dist/web/src/nanotdf-crypto/decrypt.js +21 -0
- package/dist/web/src/nanotdf-crypto/digest.js +4 -0
- package/dist/web/src/nanotdf-crypto/ecdsaSignature.js +77 -0
- package/dist/web/src/nanotdf-crypto/encrypt.js +21 -0
- package/dist/web/src/nanotdf-crypto/enums.js +49 -0
- package/dist/web/src/nanotdf-crypto/exportCryptoKey.js +17 -0
- package/dist/web/src/nanotdf-crypto/generateKeyPair.js +10 -0
- package/dist/web/src/nanotdf-crypto/generateRandomNumber.js +9 -0
- package/dist/web/src/nanotdf-crypto/importRawKey.js +15 -0
- package/dist/web/src/nanotdf-crypto/index.js +12 -0
- package/dist/web/src/nanotdf-crypto/keyAgreement.js +87 -0
- package/dist/web/src/nanotdf-crypto/pemPublicToCrypto.js +197 -0
- package/dist/web/src/policy/api.js +54 -0
- package/dist/web/src/policy/attributes.js +2 -0
- package/dist/web/src/policy/granter.js +141 -0
- package/dist/web/src/tdf/AttributeObject.js +11 -0
- package/dist/web/src/tdf/AttributeObjectJwt.js +2 -0
- package/dist/web/src/tdf/Crypto.js +44 -0
- package/dist/web/src/tdf/EntityObject.js +2 -0
- package/dist/web/src/tdf/NanoTDF/NanoTDF.js +35 -0
- package/dist/web/src/tdf/Policy.js +48 -0
- package/dist/web/src/tdf/PolicyObject.js +2 -0
- package/dist/web/src/tdf/TypedArray.js +2 -0
- package/dist/web/src/tdf/index.js +4 -0
- package/dist/web/src/types/index.js +2 -0
- package/dist/web/src/utils.js +133 -0
- package/dist/web/src/version.js +9 -0
- package/dist/web/tdf3/index.js +13 -0
- package/dist/web/tdf3/src/assertions.js +111 -0
- package/dist/web/tdf3/src/binary.js +149 -0
- package/dist/web/tdf3/src/ciphers/aes-gcm-cipher.js +52 -0
- package/dist/web/tdf3/src/ciphers/algorithms.js +5 -0
- package/dist/web/tdf3/src/ciphers/index.js +3 -0
- package/dist/web/tdf3/src/ciphers/symmetric-cipher-base.js +18 -0
- package/dist/web/tdf3/src/client/DecoratedReadableStream.js +107 -0
- package/dist/web/tdf3/src/client/builders.js +557 -0
- package/dist/web/tdf3/src/client/index.js +423 -0
- package/dist/web/tdf3/src/client/validation.js +58 -0
- package/dist/web/tdf3/src/crypto/crypto-utils.js +107 -0
- package/dist/web/tdf3/src/crypto/declarations.js +5 -0
- package/dist/web/tdf3/src/crypto/index.js +296 -0
- package/dist/web/tdf3/src/index.js +5 -0
- package/dist/web/tdf3/src/models/attribute-set.js +118 -0
- package/dist/web/tdf3/src/models/encryption-information.js +86 -0
- package/dist/web/tdf3/src/models/index.js +9 -0
- package/dist/web/tdf3/src/models/key-access.js +74 -0
- package/dist/web/tdf3/src/models/manifest.js +2 -0
- package/dist/web/tdf3/src/models/payload.js +2 -0
- package/dist/web/tdf3/src/models/policy.js +20 -0
- package/dist/web/tdf3/src/models/upsert-response.js +2 -0
- package/dist/web/tdf3/src/tdf.js +866 -0
- package/dist/web/tdf3/src/templates/default.html.js +96 -0
- package/dist/web/tdf3/src/templates/escaper.js +10 -0
- package/dist/web/tdf3/src/templates/index.js +3 -0
- package/dist/web/tdf3/src/utils/buffer-crc32.js +44 -0
- package/dist/web/tdf3/src/utils/chunkers.js +96 -0
- package/dist/web/tdf3/src/utils/index.js +248 -0
- package/dist/web/tdf3/src/utils/keysplit.js +55 -0
- package/dist/web/tdf3/src/utils/zip-reader.js +247 -0
- package/dist/web/tdf3/src/utils/zip-writer.js +302 -0
- package/dist/web/tdf3/src/version.js +3 -0
- package/package.json +126 -0
- package/src/access.ts +198 -0
- package/src/auth/Eas.ts +79 -0
- package/src/auth/auth.ts +141 -0
- package/src/auth/oidc-clientcredentials-provider.ts +32 -0
- package/src/auth/oidc-externaljwt-provider.ts +41 -0
- package/src/auth/oidc-refreshtoken-provider.ts +41 -0
- package/src/auth/oidc.ts +307 -0
- package/src/auth/providers.ts +139 -0
- package/src/encodings/base64.ts +160 -0
- package/src/encodings/hex.ts +69 -0
- package/src/encodings/index.ts +2 -0
- package/src/errors.ts +113 -0
- package/src/index.ts +441 -0
- package/src/nanotdf/Client.ts +349 -0
- package/src/nanotdf/NanoTDF.ts +121 -0
- package/src/nanotdf/browser-entry.ts +20 -0
- package/src/nanotdf/constants.ts +1 -0
- package/src/nanotdf/decrypt.ts +19 -0
- package/src/nanotdf/encrypt-dataset.ts +52 -0
- package/src/nanotdf/encrypt.ts +197 -0
- package/src/nanotdf/enum/CipherEnum.ts +10 -0
- package/src/nanotdf/enum/CurveNameEnum.ts +12 -0
- package/src/nanotdf/enum/EncodingEnum.ts +5 -0
- package/src/nanotdf/enum/PolicyTypeEnum.ts +8 -0
- package/src/nanotdf/enum/ProtocolEnum.ts +7 -0
- package/src/nanotdf/enum/ResourceLocatorIdentifierEnum.ts +8 -0
- package/src/nanotdf/helpers/calculateByCurve.ts +26 -0
- package/src/nanotdf/helpers/getHkdfSalt.ts +15 -0
- package/src/nanotdf/index.ts +10 -0
- package/src/nanotdf/interfaces/PolicyInterface.ts +27 -0
- package/src/nanotdf/models/Ciphers.ts +67 -0
- package/src/nanotdf/models/DefaultParams.ts +24 -0
- package/src/nanotdf/models/EcCurves.ts +40 -0
- package/src/nanotdf/models/Header.ts +322 -0
- package/src/nanotdf/models/Payload.ts +196 -0
- package/src/nanotdf/models/Policy/AbstractPolicy.ts +90 -0
- package/src/nanotdf/models/Policy/EmbeddedPolicy.ts +101 -0
- package/src/nanotdf/models/Policy/PolicyFactory.ts +48 -0
- package/src/nanotdf/models/Policy/RemotePolicy.ts +74 -0
- package/src/nanotdf/models/ResourceLocator.ts +212 -0
- package/src/nanotdf/models/Signature.ts +85 -0
- package/src/nanotdf-crypto/ciphers.ts +13 -0
- package/src/nanotdf-crypto/decrypt.ts +30 -0
- package/src/nanotdf-crypto/digest.ts +8 -0
- package/src/nanotdf-crypto/ecdsaSignature.ts +109 -0
- package/src/nanotdf-crypto/encrypt.ts +30 -0
- package/src/nanotdf-crypto/enums.ts +47 -0
- package/src/nanotdf-crypto/exportCryptoKey.ts +17 -0
- package/src/nanotdf-crypto/generateKeyPair.ts +19 -0
- package/src/nanotdf-crypto/generateRandomNumber.ts +8 -0
- package/src/nanotdf-crypto/importRawKey.ts +19 -0
- package/src/nanotdf-crypto/index.ts +11 -0
- package/src/nanotdf-crypto/keyAgreement.ts +139 -0
- package/src/nanotdf-crypto/pemPublicToCrypto.ts +232 -0
- package/src/package-lock.json +6 -0
- package/src/package.json +3 -0
- package/src/platform/authorization/authorization_connect.d.ts +44 -0
- package/src/platform/authorization/authorization_connect.js +44 -0
- package/src/platform/authorization/authorization_pb.d.ts +707 -0
- package/src/platform/authorization/authorization_pb.js +372 -0
- package/src/platform/common/common_pb.d.ts +129 -0
- package/src/platform/common/common_pb.js +58 -0
- package/src/platform/entityresolution/entity_resolution_connect.d.ts +35 -0
- package/src/platform/entityresolution/entity_resolution_connect.js +35 -0
- package/src/platform/entityresolution/entity_resolution_pb.d.ts +242 -0
- package/src/platform/entityresolution/entity_resolution_pb.js +139 -0
- package/src/platform/kas/kas_connect.d.ts +59 -0
- package/src/platform/kas/kas_connect.js +59 -0
- package/src/platform/kas/kas_pb.d.ts +200 -0
- package/src/platform/kas/kas_pb.js +84 -0
- package/src/platform/policy/attributes/attributes_connect.d.ts +168 -0
- package/src/platform/policy/attributes/attributes_connect.js +168 -0
- package/src/platform/policy/attributes/attributes_pb.d.ts +929 -0
- package/src/platform/policy/attributes/attributes_pb.js +363 -0
- package/src/platform/policy/kasregistry/key_access_server_registry_connect.d.ts +62 -0
- package/src/platform/policy/kasregistry/key_access_server_registry_connect.js +62 -0
- package/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts +283 -0
- package/src/platform/policy/kasregistry/key_access_server_registry_pb.js +113 -0
- package/src/platform/policy/namespaces/namespaces_connect.d.ts +62 -0
- package/src/platform/policy/namespaces/namespaces_connect.js +62 -0
- package/src/platform/policy/namespaces/namespaces_pb.d.ts +270 -0
- package/src/platform/policy/namespaces/namespaces_pb.js +110 -0
- package/src/platform/policy/objects_pb.d.ts +725 -0
- package/src/platform/policy/objects_pb.js +288 -0
- package/src/platform/policy/resourcemapping/resource_mapping_connect.d.ts +259 -0
- package/src/platform/policy/resourcemapping/resource_mapping_connect.js +259 -0
- package/src/platform/policy/resourcemapping/resource_mapping_pb.d.ts +314 -0
- package/src/platform/policy/resourcemapping/resource_mapping_pb.js +142 -0
- package/src/platform/policy/selectors_pb.d.ts +269 -0
- package/src/platform/policy/selectors_pb.js +110 -0
- package/src/platform/policy/subjectmapping/subject_mapping_connect.d.ts +118 -0
- package/src/platform/policy/subjectmapping/subject_mapping_connect.js +118 -0
- package/src/platform/policy/subjectmapping/subject_mapping_pb.d.ts +672 -0
- package/src/platform/policy/subjectmapping/subject_mapping_pb.js +260 -0
- package/src/platform/wellknownconfiguration/wellknown_configuration_connect.d.ts +26 -0
- package/src/platform/wellknownconfiguration/wellknown_configuration_connect.js +26 -0
- package/src/platform/wellknownconfiguration/wellknown_configuration_pb.d.ts +75 -0
- package/src/platform/wellknownconfiguration/wellknown_configuration_pb.js +35 -0
- package/src/policy/api.ts +61 -0
- package/src/policy/attributes.ts +117 -0
- package/src/policy/granter.ts +181 -0
- package/src/tdf/AttributeObject.ts +27 -0
- package/src/tdf/AttributeObjectJwt.ts +3 -0
- package/src/tdf/Crypto.ts +42 -0
- package/src/tdf/EntityObject.ts +18 -0
- package/src/tdf/NanoTDF/NanoTDF.ts +120 -0
- package/src/tdf/Policy.ts +51 -0
- package/src/tdf/PolicyObject.ts +12 -0
- package/src/tdf/TypedArray.ts +12 -0
- package/src/tdf/index.ts +6 -0
- package/src/types/index.ts +55 -0
- package/src/utils.ts +149 -0
- package/src/version.ts +9 -0
- package/tdf3/index.ts +91 -0
- package/tdf3/package-lock.json +6 -0
- package/tdf3/package.json +3 -0
- package/tdf3/src/assertions.ts +191 -0
- package/tdf3/src/binary.ts +195 -0
- package/tdf3/src/ciphers/aes-gcm-cipher.ts +76 -0
- package/tdf3/src/ciphers/algorithms.ts +9 -0
- package/tdf3/src/ciphers/index.ts +2 -0
- package/tdf3/src/ciphers/symmetric-cipher-base.ts +38 -0
- package/tdf3/src/client/DecoratedReadableStream.ts +148 -0
- package/tdf3/src/client/builders.ts +701 -0
- package/tdf3/src/client/index.ts +637 -0
- package/tdf3/src/client/validation.ts +79 -0
- package/tdf3/src/crypto/crypto-utils.ts +119 -0
- package/tdf3/src/crypto/declarations.ts +89 -0
- package/tdf3/src/crypto/index.ts +394 -0
- package/tdf3/src/index.ts +4 -0
- package/tdf3/src/models/attribute-set.ts +142 -0
- package/tdf3/src/models/encryption-information.ts +172 -0
- package/tdf3/src/models/index.ts +8 -0
- package/tdf3/src/models/key-access.ts +128 -0
- package/tdf3/src/models/manifest.ts +9 -0
- package/tdf3/src/models/payload.ts +6 -0
- package/tdf3/src/models/policy.ts +35 -0
- package/tdf3/src/models/upsert-response.ts +17 -0
- package/tdf3/src/tdf.ts +1351 -0
- package/tdf3/src/templates/default.html.ts +105 -0
- package/tdf3/src/templates/escaper.ts +10 -0
- package/tdf3/src/templates/index.ts +2 -0
- package/tdf3/src/utils/buffer-crc32.ts +46 -0
- package/tdf3/src/utils/chunkers.ts +118 -0
- package/tdf3/src/utils/index.ts +309 -0
- package/tdf3/src/utils/keysplit.ts +63 -0
- package/tdf3/src/utils/zip-reader.ts +341 -0
- package/tdf3/src/utils/zip-writer.ts +375 -0
- package/tdf3/src/version.ts +2 -0
- package/tdf3/types.d.ts +14 -0
package/package.json
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opentdf/sdk",
|
|
3
|
+
"version": "0.1.0-beta.1701",
|
|
4
|
+
"description": "OpenTDF for the Web",
|
|
5
|
+
"homepage": "https://github.com/opentdf/web-sdk",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/opentdf/web-sdk/issues"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/*/src/**",
|
|
11
|
+
"dist/*/tdf3/**",
|
|
12
|
+
"dist/*/*.json",
|
|
13
|
+
"src/**",
|
|
14
|
+
"tdf3/**",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/opentdf/web-sdk.git",
|
|
20
|
+
"directory": "lib"
|
|
21
|
+
},
|
|
22
|
+
"license": "BSD-3-Clause-Clear",
|
|
23
|
+
"author": "Virtru",
|
|
24
|
+
"types": "./dist/types/tdf3/index.d.ts",
|
|
25
|
+
"main": "./dist/cjs/tdf3/index.js",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/types/tdf3/index.d.ts",
|
|
29
|
+
"require": "./dist/cjs/tdf3/index.js",
|
|
30
|
+
"import": "./dist/web/tdf3/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./assertions": {
|
|
33
|
+
"default": {
|
|
34
|
+
"types": "./dist/types/tdf3/src/assertions.d.ts",
|
|
35
|
+
"require": "./dist/cjs/tdf3/src/assertions.js",
|
|
36
|
+
"import": "./dist/web/tdf3/src/assertions.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./encodings": {
|
|
40
|
+
"default": {
|
|
41
|
+
"types": "./dist/types/src/encodings/index.d.ts",
|
|
42
|
+
"require": "./dist/cjs/src/encodings/index.js",
|
|
43
|
+
"import": "./dist/web/src/encodings/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"./nano": {
|
|
47
|
+
"types": "./dist/types/src/index.d.ts",
|
|
48
|
+
"require": "./dist/cjs/src/index.js",
|
|
49
|
+
"import": "./dist/web/src/index.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "npm run clean && tsc && tsc --project tsconfig.commonjs.json && ../scripts/add-module-types.sh",
|
|
54
|
+
"build:watch": "tsc --watch",
|
|
55
|
+
"clean": "rm -rf {build,coverage,dist,tests/mocha/dist}",
|
|
56
|
+
"coverage:merge": "for x in mocha wtr; do cp coverage/$x/coverage-final.json coverage/$x.json; done; nyc report --reporter text --reporter lcov -t coverage --lines 75 --statements 75 --branches 70 --functions 65 --check-coverage >coverage/coverage.txt",
|
|
57
|
+
"doc": "typedoc --out dist/docs src/index.ts",
|
|
58
|
+
"format": "prettier --write \"{src,tdf3,tests}/**/*.ts\"",
|
|
59
|
+
"license-check": "license-checker-rseidelsohn --production --onlyAllow 'Apache-2.0; BSD; CC-BY-4.0; ISC; MIT'",
|
|
60
|
+
"lint": "eslint ./src/**/*.ts ./tdf3/**/*.ts ./tests/**/*.ts",
|
|
61
|
+
"prepack": "npm run build",
|
|
62
|
+
"test": "npm run build && npm run test:with-server",
|
|
63
|
+
"test:with-server": "node dist/web/tests/server.js & trap \"node dist/web/tests/stopServer.js\" EXIT; npm run test:mocha && npm run test:wtr && npm run test:browser && npm run coverage:merge",
|
|
64
|
+
"test:browser": "npx webpack --config webpack.test.config.cjs && npx karma start karma.conf.cjs",
|
|
65
|
+
"test:mocha": "c8 --exclude=\"dist/web/tests/**/*\" --report-dir=./coverage/mocha mocha 'dist/web/tests/mocha/**/*.spec.js' --file dist/web/tests/mocha/setup.js && npx c8 report --reporter=json --report-dir=./coverage/mocha",
|
|
66
|
+
"test:wtr": "web-test-runner",
|
|
67
|
+
"watch": "(trap 'kill 0' SIGINT; npm run build && (npm run build:watch & npm run test -- --watch))"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"axios": "^1.6.1",
|
|
71
|
+
"axios-retry": "^3.9.0",
|
|
72
|
+
"base64-js": "^1.5.1",
|
|
73
|
+
"browser-fs-access": "^0.34.1",
|
|
74
|
+
"buffer-crc32": "^0.2.13",
|
|
75
|
+
"dpop": "^1.2.0",
|
|
76
|
+
"eventemitter3": "^5.0.1",
|
|
77
|
+
"jose": "^4.14.4",
|
|
78
|
+
"json-canonicalize": "^1.0.6",
|
|
79
|
+
"streamsaver": "^2.0.6",
|
|
80
|
+
"uuid": "~9.0.0"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@esm-bundle/chai": "~4.3.4-fix.0",
|
|
84
|
+
"@types/buffer-crc32": "^0.2.4",
|
|
85
|
+
"@types/chai": "~4.3.5",
|
|
86
|
+
"@types/jest": "^29.5.3",
|
|
87
|
+
"@types/jsdom": "^21.1.7",
|
|
88
|
+
"@types/jsonwebtoken": "~9.0.2",
|
|
89
|
+
"@types/mocha": "~10.0.1",
|
|
90
|
+
"@types/node": "^20.4.5",
|
|
91
|
+
"@types/send": "^0.17.1",
|
|
92
|
+
"@types/sinon": "~10.0.15",
|
|
93
|
+
"@types/streamsaver": "^2.0.1",
|
|
94
|
+
"@types/uuid": "~9.0.2",
|
|
95
|
+
"@types/wicg-file-system-access": "^2020.9.6",
|
|
96
|
+
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
97
|
+
"@typescript-eslint/parser": "^6.2.1",
|
|
98
|
+
"@web/dev-server-esbuild": "^1.0.3",
|
|
99
|
+
"@web/dev-server-rollup": "^0.6.4",
|
|
100
|
+
"@web/test-runner": "^0.19.0",
|
|
101
|
+
"@web/test-runner-commands": "^0.9.0",
|
|
102
|
+
"audit-ci": "^6.6.1",
|
|
103
|
+
"c8": "^8.0.1",
|
|
104
|
+
"chai": "^4.3.7",
|
|
105
|
+
"colors": "^1.4.0",
|
|
106
|
+
"eslint": "^8.46.0",
|
|
107
|
+
"eslint-config-prettier": "^8.9.0",
|
|
108
|
+
"glob": "^10.3.3",
|
|
109
|
+
"jsdom": "^25.0.1",
|
|
110
|
+
"karma": "^6.4.4",
|
|
111
|
+
"karma-chrome-launcher": "^3.2.0",
|
|
112
|
+
"karma-mocha": "^2.0.1",
|
|
113
|
+
"license-checker-rseidelsohn": "^4.2.6",
|
|
114
|
+
"mocha": "^10.8.2",
|
|
115
|
+
"nyc": "^17.1.0",
|
|
116
|
+
"prettier": "^3.3.3",
|
|
117
|
+
"process": "^0.11.10",
|
|
118
|
+
"rollup": "^4.25.0",
|
|
119
|
+
"sinon": "~15.2.0",
|
|
120
|
+
"tsconfig-paths": "^4.2.0",
|
|
121
|
+
"typedoc": "^0.24.8",
|
|
122
|
+
"typescript": "5.1.6",
|
|
123
|
+
"webpack": "^5.96.1",
|
|
124
|
+
"webpack-cli": "^5.1.4"
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/access.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { type AuthProvider } from './auth/auth.js';
|
|
2
|
+
import {
|
|
3
|
+
InvalidFileError,
|
|
4
|
+
NetworkError,
|
|
5
|
+
PermissionDeniedError,
|
|
6
|
+
ServiceError,
|
|
7
|
+
UnauthenticatedError,
|
|
8
|
+
} from './errors.js';
|
|
9
|
+
import { pemToCryptoPublicKey, validateSecureUrl } from './utils.js';
|
|
10
|
+
|
|
11
|
+
export class RewrapRequest {
|
|
12
|
+
signedRequestToken = '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class RewrapResponse {
|
|
16
|
+
entityWrappedKey = '';
|
|
17
|
+
sessionPublicKey = '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get a rewrapped access key to the document, if possible
|
|
22
|
+
* @param url Key access server rewrap endpoint
|
|
23
|
+
* @param requestBody a signed request with an encrypted document key
|
|
24
|
+
* @param authProvider Authorization middleware
|
|
25
|
+
* @param clientVersion
|
|
26
|
+
*/
|
|
27
|
+
export async function fetchWrappedKey(
|
|
28
|
+
url: string,
|
|
29
|
+
requestBody: RewrapRequest,
|
|
30
|
+
authProvider: AuthProvider,
|
|
31
|
+
clientVersion: string
|
|
32
|
+
): Promise<RewrapResponse> {
|
|
33
|
+
const req = await authProvider.withCreds({
|
|
34
|
+
url,
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
'virtru-ntdf-version': clientVersion,
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify(requestBody),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch(req.url, {
|
|
45
|
+
method: req.method,
|
|
46
|
+
mode: 'cors', // no-cors, *cors, same-origin
|
|
47
|
+
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
|
|
48
|
+
credentials: 'same-origin', // include, *same-origin, omit
|
|
49
|
+
headers: req.headers,
|
|
50
|
+
redirect: 'follow', // manual, *follow, error
|
|
51
|
+
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
|
|
52
|
+
body: req.body as BodyInit,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
switch (response.status) {
|
|
57
|
+
case 400:
|
|
58
|
+
throw new InvalidFileError(
|
|
59
|
+
`400 for [${req.url}]: rewrap failure [${await response.text()}]`
|
|
60
|
+
);
|
|
61
|
+
case 401:
|
|
62
|
+
throw new UnauthenticatedError(`401 for [${req.url}]`);
|
|
63
|
+
case 403:
|
|
64
|
+
throw new PermissionDeniedError(`403 for [${req.url}]`);
|
|
65
|
+
default:
|
|
66
|
+
throw new NetworkError(
|
|
67
|
+
`${req.method} ${req.url} => ${response.status} ${response.statusText}`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return response.json();
|
|
73
|
+
} catch (e) {
|
|
74
|
+
throw new NetworkError(`unable to fetch wrapped key from [${url}]: ${e}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type KasPublicKeyAlgorithm = 'ec:secp256r1' | 'rsa:2048';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Information about one of a KAS's published public keys.
|
|
82
|
+
* A KAS may publish multiple keys with a given algorithm type.
|
|
83
|
+
*/
|
|
84
|
+
export type KasPublicKeyInfo = {
|
|
85
|
+
/** The locator to the given KAS associated with this key */
|
|
86
|
+
url: string;
|
|
87
|
+
|
|
88
|
+
/** The encryption algorithm the key is to be used with. */
|
|
89
|
+
algorithm: KasPublicKeyAlgorithm;
|
|
90
|
+
|
|
91
|
+
/** If present, an identifier which is tied to this specific key. */
|
|
92
|
+
kid?: string;
|
|
93
|
+
|
|
94
|
+
/** The key value, encoded within a PEM envelope */
|
|
95
|
+
publicKey: string;
|
|
96
|
+
|
|
97
|
+
/** A subtle crypto version of the key.
|
|
98
|
+
* This can be used for wrapping key data for key access objects (with RSA)
|
|
99
|
+
* or to derive key data (with EC keys). */
|
|
100
|
+
key: Promise<CryptoKey>;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
async function noteInvalidPublicKey(url: string, r: Promise<CryptoKey>): Promise<CryptoKey> {
|
|
104
|
+
try {
|
|
105
|
+
return await r;
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (e instanceof TypeError) {
|
|
108
|
+
throw new ServiceError(`invalid public key from [${url}]`, e);
|
|
109
|
+
}
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* If we have KAS url but not public key we can fetch it from KAS, fetching
|
|
116
|
+
* the value from `${kas}/kas_public_key`.
|
|
117
|
+
*/
|
|
118
|
+
export async function fetchECKasPubKey(kasEndpoint: string): Promise<KasPublicKeyInfo> {
|
|
119
|
+
validateSecureUrl(kasEndpoint);
|
|
120
|
+
const pkUrlV2 = `${kasEndpoint}/v2/kas_public_key?algorithm=ec:secp256r1&v=2`;
|
|
121
|
+
const kasPubKeyResponseV2 = await fetch(pkUrlV2);
|
|
122
|
+
if (!kasPubKeyResponseV2.ok) {
|
|
123
|
+
switch (kasPubKeyResponseV2.status) {
|
|
124
|
+
case 404:
|
|
125
|
+
// v2 not implemented, perhaps a legacy server
|
|
126
|
+
break;
|
|
127
|
+
case 401:
|
|
128
|
+
throw new UnauthenticatedError(`401 for [${pkUrlV2}]`);
|
|
129
|
+
case 403:
|
|
130
|
+
throw new PermissionDeniedError(`403 for [${pkUrlV2}]`);
|
|
131
|
+
default:
|
|
132
|
+
throw new NetworkError(
|
|
133
|
+
`${pkUrlV2} => ${kasPubKeyResponseV2.status} ${kasPubKeyResponseV2.statusText}`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
// most likely a server that does not implement v2 endpoint, so no key identifier
|
|
137
|
+
const pkUrlV1 = `${kasEndpoint}/kas_public_key?algorithm=ec:secp256r1`;
|
|
138
|
+
const r2 = await fetch(pkUrlV1);
|
|
139
|
+
if (!r2.ok) {
|
|
140
|
+
switch (r2.status) {
|
|
141
|
+
case 401:
|
|
142
|
+
throw new UnauthenticatedError(`401 for [${pkUrlV2}]`);
|
|
143
|
+
case 403:
|
|
144
|
+
throw new PermissionDeniedError(`403 for [${pkUrlV2}]`);
|
|
145
|
+
default:
|
|
146
|
+
throw new NetworkError(
|
|
147
|
+
`unable to load KAS public key from [${pkUrlV1}]. Received [${r2.status}:${r2.statusText}]`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const pem = await r2.json();
|
|
152
|
+
return {
|
|
153
|
+
key: noteInvalidPublicKey(pkUrlV1, pemToCryptoPublicKey(pem)),
|
|
154
|
+
publicKey: pem,
|
|
155
|
+
url: kasEndpoint,
|
|
156
|
+
algorithm: 'ec:secp256r1',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const jsonContent = await kasPubKeyResponseV2.json();
|
|
160
|
+
const { publicKey, kid }: KasPublicKeyInfo = jsonContent;
|
|
161
|
+
if (!publicKey) {
|
|
162
|
+
throw new NetworkError(
|
|
163
|
+
`invalid response from public key endpoint [${JSON.stringify(jsonContent)}]`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
key: noteInvalidPublicKey(pkUrlV2, pemToCryptoPublicKey(publicKey)),
|
|
168
|
+
publicKey,
|
|
169
|
+
url: kasEndpoint,
|
|
170
|
+
algorithm: 'ec:secp256r1',
|
|
171
|
+
...(kid && { kid }),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const origin = (u: string): string => {
|
|
176
|
+
try {
|
|
177
|
+
return new URL(u).origin;
|
|
178
|
+
} catch (e) {
|
|
179
|
+
console.log(`invalid kas url: [${u}]`);
|
|
180
|
+
throw e;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export class OriginAllowList {
|
|
185
|
+
origins: string[];
|
|
186
|
+
allowAll: boolean;
|
|
187
|
+
constructor(urls: string[], allowAll?: boolean) {
|
|
188
|
+
this.origins = urls.map(origin);
|
|
189
|
+
urls.forEach(validateSecureUrl);
|
|
190
|
+
this.allowAll = !!allowAll;
|
|
191
|
+
}
|
|
192
|
+
allows(url: string): boolean {
|
|
193
|
+
if (this.allowAll) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
return this.origins.includes(origin(url));
|
|
197
|
+
}
|
|
198
|
+
}
|
package/src/auth/Eas.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import axios, { type AxiosResponse, type RawAxiosRequestConfig } from 'axios';
|
|
2
|
+
|
|
3
|
+
import { AppIdAuthProvider, HttpRequest } from './auth.js';
|
|
4
|
+
|
|
5
|
+
const { request } = axios;
|
|
6
|
+
|
|
7
|
+
// Required `any` below is to match type from axios library.
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
type RequestFunctor = <T = any, R = AxiosResponse<T>>(config: RawAxiosRequestConfig) => Promise<R>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Client for EAS interaction, specifically fetching entity object.
|
|
13
|
+
*/
|
|
14
|
+
class Eas {
|
|
15
|
+
authProvider: AppIdAuthProvider;
|
|
16
|
+
|
|
17
|
+
endpoint: string;
|
|
18
|
+
|
|
19
|
+
requestFunctor: RequestFunctor;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create an object for accessing an Entity Attribute Service.
|
|
23
|
+
* @param {object} config - options to configure this EAS accessor
|
|
24
|
+
* @param {AuthProvider|function} config.authProvider - interceptor for `http-request.Request` object manipulation
|
|
25
|
+
* @param {string} config.endpoint - the URI to connect to
|
|
26
|
+
* @param {function} [config.requestFunctor=request] - http request async function object
|
|
27
|
+
*/
|
|
28
|
+
constructor({
|
|
29
|
+
authProvider,
|
|
30
|
+
endpoint,
|
|
31
|
+
requestFunctor,
|
|
32
|
+
}: {
|
|
33
|
+
authProvider: AppIdAuthProvider;
|
|
34
|
+
endpoint: string;
|
|
35
|
+
requestFunctor?: RequestFunctor;
|
|
36
|
+
}) {
|
|
37
|
+
this.authProvider = authProvider;
|
|
38
|
+
this.endpoint = endpoint;
|
|
39
|
+
this.requestFunctor = requestFunctor || request;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Request an entity object for the current user.
|
|
44
|
+
* @param {object} config - options for the request
|
|
45
|
+
* @param {string} config.publicKey - String encoded public key from the keypair to be used with any subsequent requests refering to the returned EO
|
|
46
|
+
* @param {object} [config.etc] - additional parameters to be passed to the EAS entity-object endpoint
|
|
47
|
+
*/
|
|
48
|
+
async fetchEntityObject({ publicKey, ...etc }: { publicKey: string }) {
|
|
49
|
+
// Create a skeleton http request for EAS.
|
|
50
|
+
const incredibleHttpReq: HttpRequest = {
|
|
51
|
+
url: this.endpoint,
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: { 'Content-Type': 'application/json' },
|
|
54
|
+
body: { publicKey, ...etc },
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Delegate modifications to the auth provider.
|
|
58
|
+
// TODO: Handle various exception cases from interface docs.
|
|
59
|
+
const httpReq = await this.authProvider.withCreds(incredibleHttpReq);
|
|
60
|
+
|
|
61
|
+
// Execute the http request using axios.
|
|
62
|
+
const axiosParams: RawAxiosRequestConfig = {
|
|
63
|
+
method: httpReq.method,
|
|
64
|
+
headers: httpReq.headers,
|
|
65
|
+
url: httpReq.url,
|
|
66
|
+
params: undefined,
|
|
67
|
+
data: undefined,
|
|
68
|
+
};
|
|
69
|
+
// Allow the authProvider to change the method.
|
|
70
|
+
if (httpReq.method === 'POST' || httpReq.method === 'PATCH' || httpReq.method === 'PUT') {
|
|
71
|
+
axiosParams.data = httpReq.body;
|
|
72
|
+
} else {
|
|
73
|
+
axiosParams.params = httpReq.body;
|
|
74
|
+
}
|
|
75
|
+
return (await this.requestFunctor(axiosParams)).data;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default Eas;
|
package/src/auth/auth.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { type JWTHeaderParameters, type JWTPayload, type KeyLike, SignJWT } from 'jose';
|
|
2
|
+
|
|
3
|
+
export type HttpMethod =
|
|
4
|
+
| 'GET'
|
|
5
|
+
| 'HEAD'
|
|
6
|
+
| 'POST'
|
|
7
|
+
| 'PUT'
|
|
8
|
+
| 'DELETE'
|
|
9
|
+
| 'CONNECT'
|
|
10
|
+
| 'OPTIONS'
|
|
11
|
+
| 'TRACE'
|
|
12
|
+
| 'PATCH';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generic HTTP request interface used by AuthProvider implementers.
|
|
16
|
+
*/
|
|
17
|
+
export class HttpRequest {
|
|
18
|
+
headers: Record<string, string>;
|
|
19
|
+
|
|
20
|
+
method: HttpMethod;
|
|
21
|
+
|
|
22
|
+
params?: object;
|
|
23
|
+
|
|
24
|
+
url: string;
|
|
25
|
+
|
|
26
|
+
body?: BodyInit | null | unknown;
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
this.headers = {};
|
|
30
|
+
this.params = {};
|
|
31
|
+
this.method = 'POST';
|
|
32
|
+
this.url = '';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Appends the given `newHeaders` to the headers listed in HttpRequest, overwriting
|
|
38
|
+
* any with the same name. NOTE: Case sensitive.
|
|
39
|
+
* @param httpReq the source request
|
|
40
|
+
* @param newHeaders header name/value pairs
|
|
41
|
+
* @returns an updated variant of the request
|
|
42
|
+
*/
|
|
43
|
+
export function withHeaders(httpReq: HttpRequest, newHeaders: Record<string, string>): HttpRequest {
|
|
44
|
+
const headers = {
|
|
45
|
+
...httpReq.headers,
|
|
46
|
+
...newHeaders,
|
|
47
|
+
};
|
|
48
|
+
return { ...httpReq, headers };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getTimestampInSeconds() {
|
|
52
|
+
return Math.floor(Date.now() / 1000);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Generate a JWT (or JWS-ed object)
|
|
57
|
+
* @param toSign the data to sign. Interpreted as JWTPayload but AFAIK this isn't required
|
|
58
|
+
* @param privateKey an RSA key
|
|
59
|
+
* @returns the signed object, with a JWS header. This may be a JWT.
|
|
60
|
+
*/
|
|
61
|
+
export async function reqSignature(
|
|
62
|
+
toSign: unknown,
|
|
63
|
+
privateKey: KeyLike,
|
|
64
|
+
jwtProtectedHeader: JWTHeaderParameters = { alg: 'RS256' }
|
|
65
|
+
) {
|
|
66
|
+
const now = getTimestampInSeconds();
|
|
67
|
+
const anHour = 3600;
|
|
68
|
+
return new SignJWT(toSign as JWTPayload)
|
|
69
|
+
.setProtectedHeader(jwtProtectedHeader)
|
|
70
|
+
.setIssuedAt(now - anHour)
|
|
71
|
+
.setExpirationTime(now + anHour)
|
|
72
|
+
.sign(privateKey);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A utility type for getting and updating a bearer token to associate with
|
|
77
|
+
* HTTP requests to the backend services, notably rewrap and upsert endpoints.
|
|
78
|
+
*
|
|
79
|
+
* In the TDF protocol, this bearer token will be a wrapper around a signed
|
|
80
|
+
* ephemeral key, to be included in
|
|
81
|
+
* [the claims object](https://github.com/opentdf/spec/blob/main/schema/ClaimsObject.md).
|
|
82
|
+
*/
|
|
83
|
+
export type AuthProvider = {
|
|
84
|
+
/**
|
|
85
|
+
* This function should be called if the consumer of this auth provider
|
|
86
|
+
* changes the client keypair, or wishes to set the keypair after creating
|
|
87
|
+
* the object.
|
|
88
|
+
*
|
|
89
|
+
* Calling this function will (optionally) trigger a forcible token refresh
|
|
90
|
+
* using the cached refresh token, and update the auth server config with the
|
|
91
|
+
* current key.
|
|
92
|
+
*
|
|
93
|
+
* @param signingKey the client signing key pair. Will be bound
|
|
94
|
+
* to the OIDC token and require a DPoP header, when set.
|
|
95
|
+
*/
|
|
96
|
+
updateClientPublicKey(signingKey?: CryptoKeyPair): Promise<void>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Augment the provided http request with custom auth info to be used by backend services.
|
|
100
|
+
*
|
|
101
|
+
* @param httpReq - Required. An http request pre-populated with the data public key.
|
|
102
|
+
*/
|
|
103
|
+
withCreds(httpReq: HttpRequest): Promise<HttpRequest>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export function isAuthProvider(a?: unknown): a is AuthProvider {
|
|
107
|
+
if (!a || typeof a != 'object') {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return 'withCreds' in a;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* An AuthProvider encapsulates all logic necessary to authenticate to a backend service, in the
|
|
115
|
+
* vein of <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html">AWS.Credentials</a>.
|
|
116
|
+
* <br/><br/>
|
|
117
|
+
* The client will call into its configured AuthProvider to decorate remote TDF service calls with necessary
|
|
118
|
+
* authentication info. This approach allows the client to be agnostic to the auth scheme, allowing for
|
|
119
|
+
* methods like identify federation and custom service credentials to be used and changed at the developer's will.
|
|
120
|
+
* <br/><br/>
|
|
121
|
+
* This class is not intended to be used on its own. See the documented subclasses for public-facing implementations.
|
|
122
|
+
* <ul>
|
|
123
|
+
* <li><a href="EmailCodeAuthProvider.html">EmailCodeAuthProvider</li>
|
|
124
|
+
* <li><a href="GoogleAuthProvider.html">GoogleAuthProvider</li>
|
|
125
|
+
* <li><a href="O365AuthProvider.html">O365AuthProvider</li>
|
|
126
|
+
* <li><a href="OutlookAuthProvider.html">OutlookAuthProvider</li>
|
|
127
|
+
* <li><a href="VirtruCredentialsAuthProvider.html">VirtruCredentialsAuthProvider</li>
|
|
128
|
+
* </ul>
|
|
129
|
+
*/
|
|
130
|
+
export abstract class AppIdAuthProvider {
|
|
131
|
+
/**
|
|
132
|
+
* Augment the provided http request with custom auth info to be used by backend services.
|
|
133
|
+
*
|
|
134
|
+
* @param httpReq - Required. An http request pre-populated with the data public key.
|
|
135
|
+
*/
|
|
136
|
+
abstract withCreds(httpReq: HttpRequest): Promise<HttpRequest>;
|
|
137
|
+
|
|
138
|
+
abstract _getName(): string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export default AppIdAuthProvider;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ConfigurationError } from '../errors.js';
|
|
2
|
+
import { AuthProvider, type HttpRequest } from './auth.js';
|
|
3
|
+
import { AccessToken, type ClientSecretCredentials } from './oidc.js';
|
|
4
|
+
|
|
5
|
+
export class OIDCClientCredentialsProvider implements AuthProvider {
|
|
6
|
+
oidcAuth: AccessToken;
|
|
7
|
+
|
|
8
|
+
constructor({
|
|
9
|
+
clientId,
|
|
10
|
+
clientSecret,
|
|
11
|
+
oidcOrigin,
|
|
12
|
+
}: Partial<ClientSecretCredentials> & Omit<ClientSecretCredentials, 'exchange'>) {
|
|
13
|
+
if (!clientId || !clientSecret) {
|
|
14
|
+
throw new ConfigurationError('clientId & clientSecret required for client credentials flow');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.oidcAuth = new AccessToken({
|
|
18
|
+
exchange: 'client',
|
|
19
|
+
clientId,
|
|
20
|
+
clientSecret,
|
|
21
|
+
oidcOrigin,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async updateClientPublicKey(signingKey: CryptoKeyPair): Promise<void> {
|
|
26
|
+
await this.oidcAuth.refreshTokenClaimsWithClientPubkeyIfNeeded(signingKey);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async withCreds(httpReq: HttpRequest): Promise<HttpRequest> {
|
|
30
|
+
return this.oidcAuth.withCreds(httpReq);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ConfigurationError } from '../errors.js';
|
|
2
|
+
import { type AuthProvider, type HttpRequest } from './auth.js';
|
|
3
|
+
import { AccessToken, type ExternalJwtCredentials } from './oidc.js';
|
|
4
|
+
|
|
5
|
+
export class OIDCExternalJwtProvider implements AuthProvider {
|
|
6
|
+
oidcAuth: AccessToken;
|
|
7
|
+
externalJwt?: string;
|
|
8
|
+
|
|
9
|
+
constructor({
|
|
10
|
+
clientId,
|
|
11
|
+
externalJwt,
|
|
12
|
+
oidcOrigin,
|
|
13
|
+
}: Partial<ExternalJwtCredentials> & Omit<ExternalJwtCredentials, 'exchange'>) {
|
|
14
|
+
if (!clientId || !externalJwt) {
|
|
15
|
+
throw new ConfigurationError('external JWT exchange reequires client id and jwt');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.oidcAuth = new AccessToken({
|
|
19
|
+
exchange: 'external',
|
|
20
|
+
clientId,
|
|
21
|
+
oidcOrigin,
|
|
22
|
+
externalJwt,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
this.externalJwt = externalJwt;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async updateClientPublicKey(signingKey: CryptoKeyPair): Promise<void> {
|
|
29
|
+
this.oidcAuth.refreshTokenClaimsWithClientPubkeyIfNeeded(signingKey);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async withCreds(httpReq: HttpRequest): Promise<HttpRequest> {
|
|
33
|
+
//If we've been seeded with an externally-issued JWT, consume it
|
|
34
|
+
//and exchange it for a Virtru bearer token.
|
|
35
|
+
if (this.externalJwt) {
|
|
36
|
+
await this.oidcAuth.exchangeForRefreshToken();
|
|
37
|
+
delete this.externalJwt;
|
|
38
|
+
}
|
|
39
|
+
return this.oidcAuth.withCreds(httpReq);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ConfigurationError } from '../errors.js';
|
|
2
|
+
import { type AuthProvider, type HttpRequest } from './auth.js';
|
|
3
|
+
import { AccessToken, type RefreshTokenCredentials } from './oidc.js';
|
|
4
|
+
|
|
5
|
+
export class OIDCRefreshTokenProvider implements AuthProvider {
|
|
6
|
+
oidcAuth: AccessToken;
|
|
7
|
+
refreshToken?: string;
|
|
8
|
+
|
|
9
|
+
constructor({
|
|
10
|
+
clientId,
|
|
11
|
+
refreshToken,
|
|
12
|
+
oidcOrigin,
|
|
13
|
+
}: Partial<RefreshTokenCredentials> & Omit<RefreshTokenCredentials, 'exchange'>) {
|
|
14
|
+
if (!clientId || !refreshToken) {
|
|
15
|
+
throw new ConfigurationError('refresh token or client id missing');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.oidcAuth = new AccessToken({
|
|
19
|
+
exchange: 'refresh',
|
|
20
|
+
clientId,
|
|
21
|
+
refreshToken: refreshToken,
|
|
22
|
+
oidcOrigin,
|
|
23
|
+
});
|
|
24
|
+
this.refreshToken = refreshToken;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async updateClientPublicKey(signingKey: CryptoKeyPair): Promise<void> {
|
|
28
|
+
await this.oidcAuth.refreshTokenClaimsWithClientPubkeyIfNeeded(signingKey);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async withCreds(httpReq: HttpRequest): Promise<HttpRequest> {
|
|
32
|
+
//If we've been seeded with an externally-issued refresh token, consume it
|
|
33
|
+
//and exchange it for a Virtru bearer token - if it's already been consumed,
|
|
34
|
+
//skip this step
|
|
35
|
+
if (this.refreshToken) {
|
|
36
|
+
await this.oidcAuth.exchangeForRefreshToken();
|
|
37
|
+
delete this.refreshToken;
|
|
38
|
+
}
|
|
39
|
+
return this.oidcAuth.withCreds(httpReq);
|
|
40
|
+
}
|
|
41
|
+
}
|