@opentdf/sdk 0.1.0-beta.1718 → 0.2.0-beta.1941
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 +45 -38
- package/dist/cjs/src/access.js +99 -62
- package/dist/cjs/src/auth/auth.js +5 -26
- package/dist/cjs/src/auth/oidc-clientcredentials-provider.js +1 -1
- package/dist/cjs/src/auth/oidc-externaljwt-provider.js +1 -1
- package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +1 -1
- package/dist/cjs/src/auth/oidc.js +1 -1
- package/dist/cjs/src/auth/providers.js +1 -1
- package/dist/cjs/src/concurrency.js +3 -4
- package/dist/cjs/src/encodings/base64.js +4 -4
- package/dist/cjs/src/encodings/hex.js +5 -6
- package/dist/cjs/src/encodings/index.js +18 -8
- package/dist/cjs/src/errors.js +1 -1
- package/dist/cjs/src/index.js +28 -320
- package/dist/cjs/src/nanoclients.js +285 -0
- package/dist/cjs/src/nanoindex.js +47 -0
- package/dist/cjs/src/nanotdf/Client.js +35 -30
- package/dist/cjs/src/nanotdf/NanoTDF.js +1 -1
- package/dist/cjs/src/nanotdf/decrypt.js +2 -2
- package/dist/cjs/src/nanotdf/encrypt-dataset.js +2 -2
- package/dist/cjs/src/nanotdf/encrypt.js +2 -2
- package/dist/cjs/src/nanotdf/helpers/calculateByCurve.js +3 -4
- package/dist/cjs/src/nanotdf/helpers/getHkdfSalt.js +2 -2
- package/dist/cjs/src/nanotdf/models/Ciphers.js +3 -3
- package/dist/cjs/src/nanotdf/models/EcCurves.js +3 -3
- package/dist/cjs/src/nanotdf/models/Header.js +1 -1
- package/dist/cjs/src/nanotdf/models/Payload.js +1 -1
- package/dist/cjs/src/nanotdf/models/Policy/AbstractPolicy.js +1 -1
- package/dist/cjs/src/nanotdf/models/Policy/EmbeddedPolicy.js +1 -1
- package/dist/cjs/src/nanotdf/models/Policy/PolicyFactory.js +1 -1
- package/dist/cjs/src/nanotdf/models/ResourceLocator.js +1 -1
- package/dist/cjs/src/nanotdf/models/Signature.js +1 -1
- package/dist/cjs/src/nanotdf-crypto/ciphers.js +1 -1
- package/dist/cjs/src/nanotdf-crypto/decrypt.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/digest.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/ecdsaSignature.js +4 -5
- package/dist/cjs/src/nanotdf-crypto/encrypt.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/exportCryptoKey.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/generateKeyPair.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/generateRandomNumber.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/index.js +21 -13
- package/dist/cjs/src/nanotdf-crypto/keyAgreement.js +10 -8
- package/dist/cjs/src/nanotdf-crypto/pemPublicToCrypto.js +20 -11
- package/dist/cjs/src/opentdf.js +243 -0
- package/dist/cjs/src/policy/api.js +2 -3
- package/dist/cjs/src/policy/granter.js +3 -4
- package/dist/cjs/src/seekable.js +157 -0
- package/dist/cjs/src/tdf/AttributeObject.js +2 -4
- package/dist/cjs/src/tdf/Policy.js +3 -3
- package/dist/cjs/src/utils.js +13 -21
- package/dist/cjs/src/version.js +7 -3
- package/dist/cjs/tdf3/index.js +27 -16
- package/dist/cjs/tdf3/src/assertions.js +25 -11
- package/dist/cjs/tdf3/src/binary.js +1 -1
- package/dist/cjs/tdf3/src/ciphers/aes-gcm-cipher.js +1 -1
- package/dist/cjs/tdf3/src/ciphers/symmetric-cipher-base.js +1 -1
- package/dist/cjs/tdf3/src/client/DecoratedReadableStream.js +7 -74
- package/dist/cjs/tdf3/src/client/builders.js +26 -22
- package/dist/cjs/tdf3/src/client/index.js +91 -117
- package/dist/cjs/tdf3/src/client/validation.js +3 -3
- package/dist/cjs/tdf3/src/crypto/crypto-utils.js +1 -1
- package/dist/cjs/tdf3/src/crypto/index.js +18 -18
- package/dist/cjs/tdf3/src/index.js +22 -11
- package/dist/cjs/tdf3/src/models/attribute-set.js +1 -1
- package/dist/cjs/tdf3/src/models/encryption-information.js +3 -3
- package/dist/cjs/tdf3/src/models/index.js +1 -2
- package/dist/cjs/tdf3/src/models/key-access.js +67 -35
- package/dist/cjs/tdf3/src/models/policy.js +3 -3
- package/dist/cjs/tdf3/src/tdf.js +180 -395
- package/dist/cjs/tdf3/src/utils/buffer-crc32.js +2 -3
- package/dist/cjs/tdf3/src/utils/index.js +48 -38
- package/dist/cjs/tdf3/src/utils/keysplit.js +4 -5
- package/dist/cjs/tdf3/src/utils/unwrap.js +21 -0
- package/dist/cjs/tdf3/src/utils/zip-reader.js +4 -4
- package/dist/cjs/tdf3/src/utils/zip-writer.js +4 -4
- package/dist/types/src/access.d.ts +10 -4
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/auth/auth.d.ts +1 -28
- package/dist/types/src/auth/auth.d.ts.map +1 -1
- package/dist/types/src/auth/providers.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +5 -136
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/nanoclients.d.ts +107 -0
- package/dist/types/src/nanoclients.d.ts.map +1 -0
- package/dist/types/src/nanoindex.d.ts +5 -0
- package/dist/types/src/nanoindex.d.ts.map +1 -0
- package/dist/types/src/nanotdf/Client.d.ts +1 -13
- package/dist/types/src/nanotdf/Client.d.ts.map +1 -1
- package/dist/types/src/nanotdf/NanoTDF.d.ts +1 -1
- package/dist/types/src/nanotdf/NanoTDF.d.ts.map +1 -1
- package/dist/types/src/nanotdf/encrypt-dataset.d.ts +1 -1
- package/dist/types/src/nanotdf/encrypt-dataset.d.ts.map +1 -1
- package/dist/types/src/nanotdf/encrypt.d.ts +1 -1
- package/dist/types/src/nanotdf/encrypt.d.ts.map +1 -1
- package/dist/types/src/nanotdf/enum/CipherEnum.d.ts +1 -1
- package/dist/types/src/nanotdf/enum/CipherEnum.d.ts.map +1 -1
- package/dist/types/src/nanotdf/enum/PolicyTypeEnum.d.ts +1 -1
- package/dist/types/src/nanotdf/enum/PolicyTypeEnum.d.ts.map +1 -1
- package/dist/types/src/nanotdf/helpers/getHkdfSalt.d.ts +1 -1
- package/dist/types/src/nanotdf/helpers/getHkdfSalt.d.ts.map +1 -1
- package/dist/types/src/nanotdf/models/DefaultParams.d.ts +1 -1
- package/dist/types/src/nanotdf/models/ResourceLocator.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/digest.d.ts +1 -1
- package/dist/types/src/nanotdf-crypto/digest.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts +1 -1
- package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts +1 -1
- package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/index.d.ts +2 -3
- package/dist/types/src/nanotdf-crypto/index.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/keyAgreement.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +106 -0
- package/dist/types/src/opentdf.d.ts.map +1 -0
- package/dist/types/src/seekable.d.ts +39 -0
- package/dist/types/src/seekable.d.ts.map +1 -0
- package/dist/types/src/tdf/AttributeObject.d.ts +0 -2
- package/dist/types/src/tdf/AttributeObject.d.ts.map +1 -1
- package/dist/types/src/tdf/NanoTDF/NanoTDF.d.ts +2 -2
- package/dist/types/src/tdf/NanoTDF/NanoTDF.d.ts.map +1 -1
- package/dist/types/src/tdf/Policy.d.ts +1 -1
- package/dist/types/src/tdf/Policy.d.ts.map +1 -1
- package/dist/types/src/tdf/PolicyObject.d.ts +1 -2
- package/dist/types/src/tdf/PolicyObject.d.ts.map +1 -1
- package/dist/types/src/tdf/TypedArray.d.ts +1 -2
- package/dist/types/src/tdf/TypedArray.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts +1 -3
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +5 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/dist/types/tdf3/index.d.ts +5 -4
- package/dist/types/tdf3/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/assertions.d.ts +3 -3
- package/dist/types/tdf3/src/assertions.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts +2 -15
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/builders.d.ts +43 -42
- package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/index.d.ts +12 -17
- package/dist/types/tdf3/src/client/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/validation.d.ts +3 -3
- package/dist/types/tdf3/src/client/validation.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts.map +1 -1
- package/dist/types/tdf3/src/index.d.ts +1 -1
- package/dist/types/tdf3/src/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/index.d.ts +0 -1
- package/dist/types/tdf3/src/models/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/key-access.d.ts +63 -15
- package/dist/types/tdf3/src/models/key-access.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/manifest.d.ts +2 -0
- package/dist/types/tdf3/src/models/manifest.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/policy.d.ts +0 -1
- package/dist/types/tdf3/src/models/policy.d.ts.map +1 -1
- package/dist/types/tdf3/src/tdf.d.ts +24 -37
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/index.d.ts +0 -4
- package/dist/types/tdf3/src/utils/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/unwrap.d.ts +2 -0
- package/dist/types/tdf3/src/utils/unwrap.d.ts.map +1 -0
- package/dist/types/tdf3/src/utils/zip-reader.d.ts +1 -1
- package/dist/types/tdf3/src/utils/zip-reader.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/zip-writer.d.ts +2 -2
- package/dist/web/src/access.js +93 -58
- package/dist/web/src/auth/auth.js +1 -21
- package/dist/web/src/auth/oidc-clientcredentials-provider.js +1 -1
- package/dist/web/src/auth/oidc-externaljwt-provider.js +1 -1
- package/dist/web/src/auth/oidc-refreshtoken-provider.js +1 -1
- package/dist/web/src/auth/oidc.js +1 -1
- package/dist/web/src/auth/providers.js +1 -1
- package/dist/web/src/concurrency.js +1 -1
- package/dist/web/src/encodings/base64.js +1 -1
- package/dist/web/src/encodings/hex.js +1 -1
- package/dist/web/src/errors.js +1 -1
- package/dist/web/src/index.js +6 -312
- package/dist/web/src/nanoclients.js +280 -0
- package/dist/web/src/nanoindex.js +5 -0
- package/dist/web/src/nanotdf/Client.js +18 -23
- package/dist/web/src/nanotdf/NanoTDF.js +1 -1
- package/dist/web/src/nanotdf/encrypt-dataset.js +1 -1
- package/dist/web/src/nanotdf/encrypt.js +1 -1
- package/dist/web/src/nanotdf/models/Ciphers.js +1 -1
- package/dist/web/src/nanotdf/models/EcCurves.js +1 -1
- package/dist/web/src/nanotdf/models/Header.js +1 -1
- package/dist/web/src/nanotdf/models/Payload.js +1 -1
- package/dist/web/src/nanotdf/models/Policy/AbstractPolicy.js +1 -1
- package/dist/web/src/nanotdf/models/Policy/EmbeddedPolicy.js +1 -1
- package/dist/web/src/nanotdf/models/Policy/PolicyFactory.js +1 -1
- package/dist/web/src/nanotdf/models/ResourceLocator.js +1 -1
- package/dist/web/src/nanotdf/models/Signature.js +1 -1
- package/dist/web/src/nanotdf-crypto/ciphers.js +1 -1
- package/dist/web/src/nanotdf-crypto/ecdsaSignature.js +1 -1
- package/dist/web/src/nanotdf-crypto/generateKeyPair.js +2 -2
- package/dist/web/src/nanotdf-crypto/generateRandomNumber.js +2 -2
- package/dist/web/src/nanotdf-crypto/index.js +3 -4
- package/dist/web/src/nanotdf-crypto/keyAgreement.js +9 -6
- package/dist/web/src/nanotdf-crypto/pemPublicToCrypto.js +1 -1
- package/dist/web/src/opentdf.js +234 -0
- package/dist/web/src/policy/api.js +1 -1
- package/dist/web/src/policy/granter.js +1 -1
- package/dist/web/src/seekable.js +148 -0
- package/dist/web/src/tdf/AttributeObject.js +1 -2
- package/dist/web/src/tdf/Policy.js +2 -4
- package/dist/web/src/utils.js +3 -10
- package/dist/web/src/version.js +6 -2
- package/dist/web/tdf3/index.js +5 -4
- package/dist/web/tdf3/src/assertions.js +21 -6
- package/dist/web/tdf3/src/binary.js +1 -1
- package/dist/web/tdf3/src/ciphers/aes-gcm-cipher.js +1 -1
- package/dist/web/tdf3/src/ciphers/symmetric-cipher-base.js +1 -1
- package/dist/web/tdf3/src/client/DecoratedReadableStream.js +4 -68
- package/dist/web/tdf3/src/client/builders.js +26 -22
- package/dist/web/tdf3/src/client/index.js +74 -105
- package/dist/web/tdf3/src/client/validation.js +1 -1
- package/dist/web/tdf3/src/crypto/crypto-utils.js +1 -1
- package/dist/web/tdf3/src/crypto/index.js +1 -1
- package/dist/web/tdf3/src/index.js +2 -2
- package/dist/web/tdf3/src/models/attribute-set.js +1 -1
- package/dist/web/tdf3/src/models/encryption-information.js +3 -3
- package/dist/web/tdf3/src/models/index.js +1 -2
- package/dist/web/tdf3/src/models/key-access.js +47 -24
- package/dist/web/tdf3/src/models/policy.js +1 -1
- package/dist/web/tdf3/src/tdf.js +153 -371
- package/dist/web/tdf3/src/utils/buffer-crc32.js +1 -1
- package/dist/web/tdf3/src/utils/index.js +19 -14
- package/dist/web/tdf3/src/utils/keysplit.js +1 -1
- package/dist/web/tdf3/src/utils/unwrap.js +18 -0
- package/dist/web/tdf3/src/utils/zip-reader.js +1 -1
- package/dist/web/tdf3/src/utils/zip-writer.js +1 -1
- package/package.json +45 -45
- package/src/access.ts +111 -54
- package/src/auth/auth.ts +1 -31
- package/src/index.ts +5 -440
- package/src/nanoclients.ts +405 -0
- package/src/nanoindex.ts +4 -0
- package/src/nanotdf/Client.ts +18 -25
- package/src/nanotdf/NanoTDF.ts +1 -1
- package/src/nanotdf/encrypt-dataset.ts +1 -1
- package/src/nanotdf/encrypt.ts +1 -1
- package/src/nanotdf/helpers/getHkdfSalt.ts +1 -1
- package/src/nanotdf-crypto/digest.ts +1 -1
- package/src/nanotdf-crypto/generateKeyPair.ts +1 -1
- package/src/nanotdf-crypto/generateRandomNumber.ts +1 -1
- package/src/nanotdf-crypto/index.ts +2 -3
- package/src/nanotdf-crypto/keyAgreement.ts +14 -7
- package/src/opentdf.ts +441 -0
- package/src/seekable.ts +180 -0
- package/src/tdf/AttributeObject.ts +0 -3
- package/src/tdf/Policy.ts +1 -2
- package/src/tdf/PolicyObject.ts +1 -2
- package/src/tdf/TypedArray.ts +1 -3
- package/src/utils.ts +3 -11
- package/src/version.ts +6 -1
- package/tdf3/index.ts +15 -10
- package/tdf3/src/assertions.ts +33 -8
- package/tdf3/src/client/DecoratedReadableStream.ts +3 -80
- package/tdf3/src/client/builders.ts +44 -28
- package/tdf3/src/client/index.ts +109 -165
- package/tdf3/src/index.ts +1 -1
- package/tdf3/src/models/encryption-information.ts +2 -2
- package/tdf3/src/models/index.ts +0 -1
- package/tdf3/src/models/key-access.ts +120 -38
- package/tdf3/src/models/manifest.ts +3 -0
- package/tdf3/src/models/policy.ts +0 -1
- package/tdf3/src/tdf.ts +266 -522
- package/tdf3/src/utils/index.ts +19 -18
- package/tdf3/src/utils/unwrap.ts +17 -0
- package/tdf3/src/utils/zip-reader.ts +1 -1
- package/dist/cjs/src/auth/Eas.js +0 -60
- package/dist/cjs/src/nanotdf-crypto/importRawKey.js +0 -18
- package/dist/cjs/src/tdf/Crypto.js +0 -47
- package/dist/cjs/src/tdf/EntityObject.js +0 -3
- package/dist/cjs/src/tdf/index.js +0 -35
- package/dist/cjs/tdf3/src/models/upsert-response.js +0 -3
- package/dist/cjs/tdf3/src/templates/default.html.js +0 -98
- package/dist/cjs/tdf3/src/templates/escaper.js +0 -15
- package/dist/cjs/tdf3/src/templates/index.js +0 -12
- package/dist/cjs/tdf3/src/utils/chunkers.js +0 -106
- package/dist/cjs/tdf3/src/version.js +0 -6
- package/dist/types/src/auth/Eas.d.ts +0 -34
- package/dist/types/src/auth/Eas.d.ts.map +0 -1
- package/dist/types/src/nanotdf-crypto/importRawKey.d.ts +0 -13
- package/dist/types/src/nanotdf-crypto/importRawKey.d.ts.map +0 -1
- package/dist/types/src/tdf/Crypto.d.ts +0 -37
- package/dist/types/src/tdf/Crypto.d.ts.map +0 -1
- package/dist/types/src/tdf/EntityObject.d.ts +0 -18
- package/dist/types/src/tdf/EntityObject.d.ts.map +0 -1
- package/dist/types/src/tdf/index.d.ts +0 -7
- package/dist/types/src/tdf/index.d.ts.map +0 -1
- package/dist/types/tdf3/src/models/upsert-response.d.ts +0 -16
- package/dist/types/tdf3/src/models/upsert-response.d.ts.map +0 -1
- package/dist/types/tdf3/src/templates/default.html.d.ts +0 -8
- package/dist/types/tdf3/src/templates/default.html.d.ts.map +0 -1
- package/dist/types/tdf3/src/templates/escaper.d.ts +0 -6
- package/dist/types/tdf3/src/templates/escaper.d.ts.map +0 -1
- package/dist/types/tdf3/src/templates/index.d.ts +0 -3
- package/dist/types/tdf3/src/templates/index.d.ts.map +0 -1
- package/dist/types/tdf3/src/utils/chunkers.d.ts +0 -29
- package/dist/types/tdf3/src/utils/chunkers.d.ts.map +0 -1
- package/dist/types/tdf3/src/version.d.ts +0 -3
- package/dist/types/tdf3/src/version.d.ts.map +0 -1
- package/dist/web/src/auth/Eas.js +0 -55
- package/dist/web/src/nanotdf-crypto/importRawKey.js +0 -15
- package/dist/web/src/tdf/Crypto.js +0 -44
- package/dist/web/src/tdf/EntityObject.js +0 -2
- package/dist/web/src/tdf/index.js +0 -4
- package/dist/web/tdf3/src/models/upsert-response.js +0 -2
- package/dist/web/tdf3/src/templates/default.html.js +0 -96
- package/dist/web/tdf3/src/templates/escaper.js +0 -10
- package/dist/web/tdf3/src/templates/index.js +0 -3
- package/dist/web/tdf3/src/utils/chunkers.js +0 -96
- package/dist/web/tdf3/src/version.js +0 -3
- package/src/auth/Eas.ts +0 -79
- package/src/nanotdf-crypto/importRawKey.ts +0 -19
- package/src/tdf/Crypto.ts +0 -42
- package/src/tdf/EntityObject.ts +0 -18
- package/src/tdf/index.ts +0 -6
- package/tdf3/src/models/upsert-response.ts +0 -17
- package/tdf3/src/templates/default.html.ts +0 -105
- package/tdf3/src/templates/escaper.ts +0 -10
- package/tdf3/src/templates/index.ts +0 -2
- package/tdf3/src/utils/chunkers.ts +0 -118
- package/tdf3/src/version.ts +0 -2
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Client,
|
|
3
|
+
NanoTDF,
|
|
4
|
+
Header,
|
|
5
|
+
encrypt,
|
|
6
|
+
decrypt,
|
|
7
|
+
encryptDataset,
|
|
8
|
+
getHkdfSalt,
|
|
9
|
+
DefaultParams,
|
|
10
|
+
} from './nanotdf/index.js';
|
|
11
|
+
import { keyAgreement } from './nanotdf-crypto/index.js';
|
|
12
|
+
import { Policy } from './tdf/Policy.js';
|
|
13
|
+
import { type TypedArray } from './tdf/TypedArray.js';
|
|
14
|
+
import { createAttribute } from './tdf/AttributeObject.js';
|
|
15
|
+
import { fetchECKasPubKey } from './access.js';
|
|
16
|
+
import { ClientConfig } from './nanotdf/Client.js';
|
|
17
|
+
import { ConfigurationError } from './errors.js';
|
|
18
|
+
|
|
19
|
+
// Define the EncryptOptions type
|
|
20
|
+
export type EncryptOptions = {
|
|
21
|
+
ecdsaBinding: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Define default options
|
|
25
|
+
const defaultOptions: EncryptOptions = {
|
|
26
|
+
ecdsaBinding: false,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* NanoTDF SDK Client. Deprecated in favor of OpenTDF.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
export class NanoTDFClient extends Client {
|
|
34
|
+
/**
|
|
35
|
+
* Decrypt ciphertext
|
|
36
|
+
*
|
|
37
|
+
* Pass a base64 string, TypedArray, or ArrayBuffer ciphertext and get a promise which resolves plaintext
|
|
38
|
+
*
|
|
39
|
+
* @param ciphertext Ciphertext to decrypt
|
|
40
|
+
*/
|
|
41
|
+
async decrypt(ciphertext: string | TypedArray | ArrayBuffer): Promise<ArrayBuffer> {
|
|
42
|
+
// Parse ciphertext
|
|
43
|
+
const nanotdf = NanoTDF.from(ciphertext);
|
|
44
|
+
|
|
45
|
+
// TODO: The version number should be fetched from the API
|
|
46
|
+
const version = '0.0.1';
|
|
47
|
+
const kasUrl = nanotdf.header.getKasRewrapUrl();
|
|
48
|
+
|
|
49
|
+
// Rewrap key on every request
|
|
50
|
+
const ukey = await this.rewrapKey(
|
|
51
|
+
nanotdf.header.toBuffer(),
|
|
52
|
+
kasUrl,
|
|
53
|
+
nanotdf.header.magicNumberVersion,
|
|
54
|
+
version
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (!ukey) {
|
|
58
|
+
throw new Error('internal: key rewrap failure');
|
|
59
|
+
}
|
|
60
|
+
// Return decrypt promise
|
|
61
|
+
return decrypt(ukey, nanotdf);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Decrypt ciphertext of the legacy TDF, with the older, smaller i.v. calculation.
|
|
66
|
+
*
|
|
67
|
+
* Pass a base64 string, TypedArray, or ArrayBuffer ciphertext and get a promise which resolves plaintext
|
|
68
|
+
*
|
|
69
|
+
* @param ciphertext Ciphertext to decrypt
|
|
70
|
+
*/
|
|
71
|
+
async decryptLegacyTDF(ciphertext: string | TypedArray | ArrayBuffer): Promise<ArrayBuffer> {
|
|
72
|
+
// Parse ciphertext
|
|
73
|
+
const nanotdf = NanoTDF.from(ciphertext, undefined, true);
|
|
74
|
+
|
|
75
|
+
const legacyVersion = '0.0.0';
|
|
76
|
+
// Rewrap key on every request
|
|
77
|
+
const key = await this.rewrapKey(
|
|
78
|
+
nanotdf.header.toBuffer(),
|
|
79
|
+
nanotdf.header.getKasRewrapUrl(),
|
|
80
|
+
nanotdf.header.magicNumberVersion,
|
|
81
|
+
legacyVersion
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (!key) {
|
|
85
|
+
throw new Error('internal: failed unwrap');
|
|
86
|
+
}
|
|
87
|
+
// Return decrypt promise
|
|
88
|
+
return decrypt(key, nanotdf);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Encrypts the given data using the NanoTDF encryption scheme.
|
|
93
|
+
*
|
|
94
|
+
* @param {string | TypedArray | ArrayBuffer} data - The data to be encrypted.
|
|
95
|
+
* @param {EncryptOptions} [options=defaultOptions] - The encryption options (currently unused).
|
|
96
|
+
* @returns {Promise<ArrayBuffer>} A promise that resolves to the encrypted data as an ArrayBuffer.
|
|
97
|
+
* @throws {Error} If the initialization vector is not a number.
|
|
98
|
+
*/
|
|
99
|
+
async encrypt(
|
|
100
|
+
data: string | TypedArray | ArrayBuffer,
|
|
101
|
+
options?: EncryptOptions
|
|
102
|
+
): Promise<ArrayBuffer> {
|
|
103
|
+
// For encrypt always generate the client ephemeralKeyPair
|
|
104
|
+
const ephemeralKeyPair = await this.ephemeralKeyPair;
|
|
105
|
+
const initializationVector = this.iv;
|
|
106
|
+
|
|
107
|
+
if (typeof initializationVector !== 'number') {
|
|
108
|
+
throw new ConfigurationError(
|
|
109
|
+
'NanoTDF clients are single use. Please generate a new client and keypair.'
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
delete this.iv;
|
|
113
|
+
|
|
114
|
+
if (!this.kasPubKey) {
|
|
115
|
+
this.kasPubKey = await fetchECKasPubKey(this.kasUrl);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Create a policy for the tdf
|
|
119
|
+
const policy = new Policy();
|
|
120
|
+
|
|
121
|
+
// Add data attributes.
|
|
122
|
+
for (const dataAttribute of this.dataAttributes) {
|
|
123
|
+
const attribute = await createAttribute(dataAttribute, this.kasPubKey, this.kasUrl);
|
|
124
|
+
policy.addAttribute(attribute);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (this.dissems.length == 0 && this.dataAttributes.length == 0) {
|
|
128
|
+
console.warn(
|
|
129
|
+
'This policy has an empty attributes list and an empty dissemination list. This will allow any entity with a valid Entity Object to access this TDF.'
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Encrypt the policy.
|
|
134
|
+
const policyObjectAsStr = policy.toJSON();
|
|
135
|
+
|
|
136
|
+
// IV is always '1', since the new keypair is generated on encrypt
|
|
137
|
+
// using the same key is fine.
|
|
138
|
+
const lengthAsUint32 = new Uint32Array(1);
|
|
139
|
+
lengthAsUint32[0] = initializationVector;
|
|
140
|
+
|
|
141
|
+
const lengthAsUint24 = new Uint8Array(lengthAsUint32.buffer);
|
|
142
|
+
|
|
143
|
+
// NOTE: We are only interested in only first 3 bytes.
|
|
144
|
+
const payloadIV = new Uint8Array(12).fill(0);
|
|
145
|
+
payloadIV[9] = lengthAsUint24[2];
|
|
146
|
+
payloadIV[10] = lengthAsUint24[1];
|
|
147
|
+
payloadIV[11] = lengthAsUint24[0];
|
|
148
|
+
|
|
149
|
+
const mergedOptions: EncryptOptions = { ...defaultOptions, ...options };
|
|
150
|
+
return encrypt(
|
|
151
|
+
policyObjectAsStr,
|
|
152
|
+
this.kasPubKey,
|
|
153
|
+
ephemeralKeyPair,
|
|
154
|
+
payloadIV,
|
|
155
|
+
data,
|
|
156
|
+
mergedOptions.ecdsaBinding
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type DatasetConfig = ClientConfig & {
|
|
162
|
+
maxKeyIterations?: number;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* NanoTDF Dataset SDK Client
|
|
167
|
+
*
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```
|
|
171
|
+
* import { clientSecretAuthProvider, NanoTDFDatasetClient } from '@opentdf/sdk';
|
|
172
|
+
*
|
|
173
|
+
* const OIDC_ENDPOINT = 'http://localhost:65432/auth/realms/opentdf';
|
|
174
|
+
* const KAS_URL = 'http://localhost:65432/api/kas/';
|
|
175
|
+
*
|
|
176
|
+
* const ciphertext = '...';
|
|
177
|
+
* const client = new NanoTDFDatasetClient({
|
|
178
|
+
* authProvider: await clientSecretAuthProvider({
|
|
179
|
+
* clientId: 'tdf-client',
|
|
180
|
+
* clientSecret: '123-456',
|
|
181
|
+
* exchange: 'client',
|
|
182
|
+
* oidcOrigin: OIDC_ENDPOINT,
|
|
183
|
+
* }),
|
|
184
|
+
* kasEndpoint: KAS_URL,
|
|
185
|
+
* });
|
|
186
|
+
* const plaintext = client.decrypt(ciphertext);
|
|
187
|
+
* console.log('Plaintext', plaintext);
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export class NanoTDFDatasetClient extends Client {
|
|
191
|
+
// Total unique IVs(2^24 -1) used for encrypting the nano tdf payloads
|
|
192
|
+
// IV starts from 1 since the 0 IV is reserved for policy encryption
|
|
193
|
+
static readonly NTDF_MAX_KEY_ITERATIONS = 8388606;
|
|
194
|
+
|
|
195
|
+
private maxKeyIteration: number;
|
|
196
|
+
private keyIterationCount: number;
|
|
197
|
+
private cachedEphemeralKey?: Uint8Array;
|
|
198
|
+
private unwrappedKey?: CryptoKey;
|
|
199
|
+
private symmetricKey?: CryptoKey;
|
|
200
|
+
private cachedHeader?: Header;
|
|
201
|
+
private ecdsaBinding: boolean;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Create new NanoTDF Dataset Client
|
|
205
|
+
*
|
|
206
|
+
* The Ephemeral Key Pair can either be provided or will be generate when fetching the entity object. Once set it
|
|
207
|
+
* cannot be changed. If a new ephemeral key is desired it a new client should be initialized.
|
|
208
|
+
* There is no performance impact for creating a new client IFF the ephemeral key pair is provided.
|
|
209
|
+
*
|
|
210
|
+
* @param clientConfig OIDC client credentials
|
|
211
|
+
* @param kasUrl Key access service URL
|
|
212
|
+
* @param ephemeralKeyPair (optional) ephemeral key pair to use
|
|
213
|
+
* @param maxKeyIterations Max iteration to performe without a key rotation
|
|
214
|
+
*/
|
|
215
|
+
constructor(opts: DatasetConfig) {
|
|
216
|
+
if (
|
|
217
|
+
opts.maxKeyIterations &&
|
|
218
|
+
opts.maxKeyIterations > NanoTDFDatasetClient.NTDF_MAX_KEY_ITERATIONS
|
|
219
|
+
) {
|
|
220
|
+
throw new ConfigurationError(
|
|
221
|
+
`key iteration exceeds max iterations(${NanoTDFDatasetClient.NTDF_MAX_KEY_ITERATIONS})`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
super(opts);
|
|
225
|
+
|
|
226
|
+
this.maxKeyIteration = opts.maxKeyIterations || NanoTDFDatasetClient.NTDF_MAX_KEY_ITERATIONS;
|
|
227
|
+
this.keyIterationCount = 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Encrypt data
|
|
232
|
+
*
|
|
233
|
+
* Pass a string, TypedArray, or ArrayBuffer data and get a promise which resolves ciphertext
|
|
234
|
+
*
|
|
235
|
+
* @param data to decrypt
|
|
236
|
+
*/
|
|
237
|
+
async encrypt(
|
|
238
|
+
data: string | TypedArray | ArrayBuffer,
|
|
239
|
+
options?: EncryptOptions
|
|
240
|
+
): Promise<ArrayBuffer> {
|
|
241
|
+
// Intial encrypt
|
|
242
|
+
if (this.keyIterationCount == 0) {
|
|
243
|
+
const mergedOptions: EncryptOptions = { ...defaultOptions, ...options };
|
|
244
|
+
this.ecdsaBinding = mergedOptions.ecdsaBinding;
|
|
245
|
+
// For encrypt always generate the client ephemeralKeyPair
|
|
246
|
+
const ephemeralKeyPair = await this.ephemeralKeyPair;
|
|
247
|
+
|
|
248
|
+
if (!this.kasPubKey) {
|
|
249
|
+
this.kasPubKey = await fetchECKasPubKey(this.kasUrl);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Create a policy for the tdf
|
|
253
|
+
const policy = new Policy();
|
|
254
|
+
|
|
255
|
+
// Add data attributes.
|
|
256
|
+
for (const dataAttribute of this.dataAttributes) {
|
|
257
|
+
const attribute = await createAttribute(dataAttribute, this.kasPubKey, this.kasUrl);
|
|
258
|
+
policy.addAttribute(attribute);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (this.dissems.length == 0 || this.dataAttributes.length == 0) {
|
|
262
|
+
console.warn(
|
|
263
|
+
'This policy has an empty attributes list and an empty dissemination list. This will allow any entity with a valid Entity Object to access this TDF.'
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Encrypt the policy.
|
|
268
|
+
const policyObjectAsStr = policy.toJSON();
|
|
269
|
+
|
|
270
|
+
const ivVector = this.generateIV();
|
|
271
|
+
|
|
272
|
+
// Generate a symmetric key.
|
|
273
|
+
this.symmetricKey = await keyAgreement(
|
|
274
|
+
ephemeralKeyPair.privateKey,
|
|
275
|
+
await this.kasPubKey.key,
|
|
276
|
+
await getHkdfSalt(DefaultParams.magicNumberVersion)
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const nanoTDFBuffer = await encrypt(
|
|
280
|
+
policyObjectAsStr,
|
|
281
|
+
this.kasPubKey,
|
|
282
|
+
ephemeralKeyPair,
|
|
283
|
+
ivVector,
|
|
284
|
+
data,
|
|
285
|
+
this.ecdsaBinding
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
// Cache the header and increment the key iteration
|
|
289
|
+
if (!this.cachedHeader) {
|
|
290
|
+
const nanoTDF = NanoTDF.from(nanoTDFBuffer);
|
|
291
|
+
this.cachedHeader = nanoTDF.header;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
this.keyIterationCount += 1;
|
|
295
|
+
|
|
296
|
+
return nanoTDFBuffer;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
this.keyIterationCount += 1;
|
|
300
|
+
|
|
301
|
+
if (!this.cachedHeader) {
|
|
302
|
+
throw new ConfigurationError('invalid dataset client: empty nanoTDF header');
|
|
303
|
+
}
|
|
304
|
+
if (!this.symmetricKey) {
|
|
305
|
+
throw new ConfigurationError('invalid dataset client: empty dek');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
this.keyIterationCount += 1;
|
|
309
|
+
if (this.keyIterationCount == this.maxKeyIteration) {
|
|
310
|
+
// reset the key iteration
|
|
311
|
+
this.keyIterationCount = 0;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const ivVector = this.generateIV();
|
|
315
|
+
|
|
316
|
+
return encryptDataset(this.symmetricKey, this.cachedHeader, ivVector, data);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Decrypt ciphertext
|
|
321
|
+
*
|
|
322
|
+
* Pass a base64 string, TypedArray, or ArrayBuffer ciphertext and get a promise which resolves plaintext
|
|
323
|
+
*
|
|
324
|
+
* @param ciphertext Ciphertext to decrypt
|
|
325
|
+
*/
|
|
326
|
+
async decrypt(ciphertext: string | TypedArray | ArrayBuffer): Promise<ArrayBuffer> {
|
|
327
|
+
// Parse ciphertext
|
|
328
|
+
const nanotdf = NanoTDF.from(ciphertext);
|
|
329
|
+
|
|
330
|
+
if (!this.cachedEphemeralKey) {
|
|
331
|
+
// First decrypt
|
|
332
|
+
return this.rewrapAndDecrypt(nanotdf);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Other encrypts
|
|
336
|
+
if (this.cachedEphemeralKey.toString() == nanotdf.header.ephemeralPublicKey.toString()) {
|
|
337
|
+
const ukey = this.unwrappedKey;
|
|
338
|
+
if (!ukey) {
|
|
339
|
+
// These should have thrown already.
|
|
340
|
+
throw new Error('internal: key rewrap failure');
|
|
341
|
+
}
|
|
342
|
+
// Return decrypt promise
|
|
343
|
+
return decrypt(ukey, nanotdf);
|
|
344
|
+
} else {
|
|
345
|
+
return this.rewrapAndDecrypt(nanotdf);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async rewrapAndDecrypt(nanotdf: NanoTDF) {
|
|
350
|
+
// TODO: The version number should be fetched from the API
|
|
351
|
+
const version = '0.0.1';
|
|
352
|
+
// Rewrap key on every request
|
|
353
|
+
const ukey = await this.rewrapKey(
|
|
354
|
+
nanotdf.header.toBuffer(),
|
|
355
|
+
nanotdf.header.getKasRewrapUrl(),
|
|
356
|
+
nanotdf.header.magicNumberVersion,
|
|
357
|
+
version
|
|
358
|
+
);
|
|
359
|
+
if (!ukey) {
|
|
360
|
+
// These should have thrown already.
|
|
361
|
+
throw new Error('internal: key rewrap failure');
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
this.cachedEphemeralKey = nanotdf.header.ephemeralPublicKey;
|
|
365
|
+
this.unwrappedKey = ukey;
|
|
366
|
+
|
|
367
|
+
// Return decrypt promise
|
|
368
|
+
return decrypt(ukey, nanotdf);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
generateIV(): Uint8Array {
|
|
372
|
+
const iv = this.iv;
|
|
373
|
+
if (iv === undefined) {
|
|
374
|
+
// iv has passed the maximum iteration count for this dek
|
|
375
|
+
throw new ConfigurationError('dataset full');
|
|
376
|
+
}
|
|
377
|
+
// assert iv ∈ ℤ ∩ (0, 2^24)
|
|
378
|
+
if (!Number.isInteger(iv) || iv <= 0 || 0xff_ffff < iv) {
|
|
379
|
+
// Something has fiddled with the iv outside of the expected behavior
|
|
380
|
+
// could indicate a race condition, e.g. if two workers or handlers are
|
|
381
|
+
// processing the file at once, for example.
|
|
382
|
+
throw new Error('internal: invalid state');
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const lengthAsUint32 = new Uint32Array(1);
|
|
386
|
+
lengthAsUint32[0] = iv;
|
|
387
|
+
|
|
388
|
+
const lengthAsUint24 = new Uint8Array(lengthAsUint32.buffer);
|
|
389
|
+
|
|
390
|
+
// NOTE: We are only interested in only first 3 bytes.
|
|
391
|
+
const ivVector = new Uint8Array(Client.IV_SIZE).fill(0);
|
|
392
|
+
ivVector[9] = lengthAsUint24[2];
|
|
393
|
+
ivVector[10] = lengthAsUint24[1];
|
|
394
|
+
ivVector[11] = lengthAsUint24[0];
|
|
395
|
+
|
|
396
|
+
// Increment the IV
|
|
397
|
+
if (iv == 0xff_ffff) {
|
|
398
|
+
delete this.iv;
|
|
399
|
+
} else {
|
|
400
|
+
this.iv = iv + 1;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return ivVector;
|
|
404
|
+
}
|
|
405
|
+
}
|
package/src/nanoindex.ts
ADDED
package/src/nanotdf/Client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TypedArray } from '../tdf/
|
|
1
|
+
import { type TypedArray } from '../tdf/TypedArray.js';
|
|
2
2
|
import * as base64 from '../encodings/base64.js';
|
|
3
3
|
import { generateKeyPair, keyAgreement } from '../nanotdf-crypto/index.js';
|
|
4
4
|
import getHkdfSalt from './helpers/getHkdfSalt.js';
|
|
@@ -128,8 +128,23 @@ export default class Client {
|
|
|
128
128
|
ephemeralKeyPair?: CryptoKeyPair,
|
|
129
129
|
dpopEnabled = false
|
|
130
130
|
) {
|
|
131
|
+
const enwrapAuthProvider = (a: AuthProvider): AuthProvider => {
|
|
132
|
+
return {
|
|
133
|
+
updateClientPublicKey: async (signingKey) => {
|
|
134
|
+
await a.updateClientPublicKey(signingKey);
|
|
135
|
+
},
|
|
136
|
+
withCreds: async (httpReq) => {
|
|
137
|
+
const signer = await this.requestSignerKeyPair;
|
|
138
|
+
if (!signer) {
|
|
139
|
+
throw new ConfigurationError('failed to find or generate signer session key');
|
|
140
|
+
}
|
|
141
|
+
await a.updateClientPublicKey(signer);
|
|
142
|
+
return a.withCreds(httpReq);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
};
|
|
131
146
|
if (isAuthProvider(optsOrOldAuthProvider)) {
|
|
132
|
-
this.authProvider = optsOrOldAuthProvider;
|
|
147
|
+
this.authProvider = enwrapAuthProvider(optsOrOldAuthProvider);
|
|
133
148
|
if (!kasUrl) {
|
|
134
149
|
throw new ConfigurationError('please specify kasEndpoint');
|
|
135
150
|
}
|
|
@@ -155,7 +170,7 @@ export default class Client {
|
|
|
155
170
|
ephemeralKeyPair,
|
|
156
171
|
kasEndpoint,
|
|
157
172
|
} = optsOrOldAuthProvider;
|
|
158
|
-
this.authProvider = authProvider;
|
|
173
|
+
this.authProvider = enwrapAuthProvider(authProvider);
|
|
159
174
|
// TODO Disallow http KAS. For now just log as error
|
|
160
175
|
validateSecureUrl(kasEndpoint);
|
|
161
176
|
this.kasUrl = kasEndpoint;
|
|
@@ -185,26 +200,6 @@ export default class Client {
|
|
|
185
200
|
this.dataAttributes.push(attribute);
|
|
186
201
|
}
|
|
187
202
|
|
|
188
|
-
/**
|
|
189
|
-
* Explicitly get a new Entity Object using the supplied EntityAttributeService.
|
|
190
|
-
*
|
|
191
|
-
* This method is expected to be called at least once per encrypt/decrypt cycle. If the entityObject is expired then
|
|
192
|
-
* this will need to be called again.
|
|
193
|
-
*
|
|
194
|
-
* @security the ephemeralKeyPair must be set in the constructor if desired to use here. If this is wished to be changed
|
|
195
|
-
* then a new client should be initialized.
|
|
196
|
-
* @performance key pair is generated when the entity object is fetched IFF the ephemeralKeyPair is not set. This will
|
|
197
|
-
* either be set on the first call or passed in the constructor.
|
|
198
|
-
*/
|
|
199
|
-
async fetchOIDCToken(): Promise<void> {
|
|
200
|
-
const signer = await this.requestSignerKeyPair;
|
|
201
|
-
if (!signer) {
|
|
202
|
-
throw new ConfigurationError('failed to find or generate signer session key');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
await this.authProvider.updateClientPublicKey(signer);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
203
|
/**
|
|
209
204
|
* Rewrap key
|
|
210
205
|
*
|
|
@@ -224,8 +219,6 @@ export default class Client {
|
|
|
224
219
|
throw new UnsafeUrlError(`request URL ∉ ${this.allowedKases.origins};`, kasRewrapUrl);
|
|
225
220
|
}
|
|
226
221
|
|
|
227
|
-
// Ensure the ephemeral key pair has been set or generated (see createOidcServiceProvider)
|
|
228
|
-
await this.fetchOIDCToken();
|
|
229
222
|
const ephemeralKeyPair = await this.ephemeralKeyPair;
|
|
230
223
|
const requestSignerKeyPair = await this.requestSignerKeyPair;
|
|
231
224
|
|
package/src/nanotdf/NanoTDF.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Header from './models/Header.js';
|
|
|
3
3
|
import DefaultParams from './models/DefaultParams.js';
|
|
4
4
|
import Payload from './models/Payload.js';
|
|
5
5
|
import { getBitLength as authTagLengthForCipher } from './models/Ciphers.js';
|
|
6
|
-
import TypedArray from '../tdf/TypedArray.js';
|
|
6
|
+
import { TypedArray } from '../tdf/TypedArray.js';
|
|
7
7
|
import encrypt from '../nanotdf-crypto/encrypt.js';
|
|
8
8
|
|
|
9
9
|
/**
|
package/src/nanotdf/encrypt.ts
CHANGED
|
@@ -6,7 +6,7 @@ import EmbeddedPolicy from './models/Policy/EmbeddedPolicy.js';
|
|
|
6
6
|
import Payload from './models/Payload.js';
|
|
7
7
|
import getHkdfSalt from './helpers/getHkdfSalt.js';
|
|
8
8
|
import { getBitLength as authTagLengthForCipher } from './models/Ciphers.js';
|
|
9
|
-
import { TypedArray } from '../tdf/
|
|
9
|
+
import { TypedArray } from '../tdf/TypedArray.js';
|
|
10
10
|
import { GMAC_BINDING_LEN } from './constants.js';
|
|
11
11
|
import { AlgorithmName, KeyFormat, KeyUsageType } from './../nanotdf-crypto/enums.js';
|
|
12
12
|
|
|
@@ -7,7 +7,7 @@ interface GenerateKeyPairOptions {
|
|
|
7
7
|
isExtractable: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export
|
|
10
|
+
export async function generateKeyPair(
|
|
11
11
|
{ type: name, curve: namedCurve, keyUsages, isExtractable }: GenerateKeyPairOptions = {
|
|
12
12
|
type: AlgorithmName.ECDH,
|
|
13
13
|
curve: NamedCurve.P256,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate a random number of given length
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export function generateRandomNumber(length: number): Uint8Array {
|
|
5
5
|
const byteArray = new Uint8Array(length);
|
|
6
6
|
crypto.getRandomValues(byteArray);
|
|
7
7
|
return byteArray;
|
|
@@ -2,10 +2,9 @@ export { Ciphers } from './ciphers.js';
|
|
|
2
2
|
export { default as decrypt } from './decrypt.js';
|
|
3
3
|
export { default as digest } from './digest.js';
|
|
4
4
|
export { default as encrypt } from './encrypt.js';
|
|
5
|
-
export {
|
|
6
|
-
export { default as importRawKey } from './importRawKey.js';
|
|
5
|
+
export { generateKeyPair } from './generateKeyPair.js';
|
|
7
6
|
export { keyAgreement } from './keyAgreement.js';
|
|
8
7
|
export { default as exportCryptoKey } from './exportCryptoKey.js';
|
|
9
|
-
export {
|
|
8
|
+
export { generateRandomNumber } from './generateRandomNumber.js';
|
|
10
9
|
export { pemPublicToCrypto, pemCertToCrypto } from './pemPublicToCrypto.js';
|
|
11
10
|
export * as enums from './enums.js';
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
+
import { keyAlgorithmToPublicKeyAlgorithm } from '../access.js';
|
|
30
31
|
import { ConfigurationError } from '../errors.js';
|
|
31
32
|
import { AlgorithmName, CipherType, HashType, KeyFormat, KeyType, KeyUsageType } from './enums.js';
|
|
32
33
|
|
|
@@ -69,19 +70,25 @@ export async function keyAgreement(
|
|
|
69
70
|
isExtractable: true,
|
|
70
71
|
}
|
|
71
72
|
): Promise<CryptoKey> {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
for (const k of [privateKey, publicKey]) {
|
|
74
|
+
const mechanism = keyAlgorithmToPublicKeyAlgorithm(k.algorithm);
|
|
75
|
+
if (mechanism !== 'ec:secp256r1') {
|
|
76
|
+
throw new ConfigurationError(
|
|
77
|
+
`${k.type} CryptoKey is expected to be of type ECDSA or ECDH, not [${k.algorithm?.name}]`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
if (privateKey.type !== KeyType.Private) {
|
|
80
|
-
throw new ConfigurationError(
|
|
83
|
+
throw new ConfigurationError(
|
|
84
|
+
`Expected input of privateKey to be a CryptoKey of type private, not [${privateKey.type}]`
|
|
85
|
+
);
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
if (publicKey.type !== KeyType.Public) {
|
|
84
|
-
throw new ConfigurationError(
|
|
89
|
+
throw new ConfigurationError(
|
|
90
|
+
`Expected input of publicKey to be a CryptoKey of type public, not [${publicKey.type}]`
|
|
91
|
+
);
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
const {
|