@opentdf/sdk 0.8.0-beta.74 → 0.8.0-rc.73
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 +30 -5
- package/dist/cjs/src/nanoclients.js +292 -0
- package/dist/cjs/src/nanoindex.js +47 -0
- package/dist/cjs/src/nanotdf/Client.js +315 -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 +28 -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/{crypto → nanotdf-crypto}/ciphers.js +1 -1
- package/dist/cjs/src/{crypto → nanotdf-crypto}/decrypt.js +1 -1
- package/dist/cjs/src/{crypto → nanotdf-crypto}/digest.js +1 -1
- package/dist/cjs/src/{crypto → nanotdf-crypto}/ecdsaSignature.js +2 -2
- package/dist/cjs/src/{crypto → nanotdf-crypto}/encrypt.js +1 -1
- package/dist/cjs/src/{crypto → nanotdf-crypto}/enums.js +1 -1
- package/dist/cjs/src/nanotdf-crypto/exportCryptoKey.js +20 -0
- package/dist/cjs/src/{crypto → nanotdf-crypto}/generateKeyPair.js +1 -1
- package/dist/cjs/src/{crypto → nanotdf-crypto}/generateRandomNumber.js +1 -1
- package/dist/cjs/src/{crypto → nanotdf-crypto}/index.js +1 -1
- package/dist/cjs/src/{crypto → nanotdf-crypto}/keyAgreement.js +1 -1
- package/dist/cjs/src/{crypto → nanotdf-crypto}/pemPublicToCrypto.js +1 -1
- package/dist/cjs/src/opentdf.js +260 -9
- package/dist/cjs/src/tdf/NanoTDF/NanoTDF.js +38 -0
- package/dist/cjs/src/types/index.js +3 -0
- package/dist/cjs/src/utils.js +2 -2
- package/dist/cjs/tdf3/index.js +8 -7
- package/dist/cjs/tdf3/src/models/key-access.js +4 -4
- package/dist/cjs/tdf3/src/tdf.js +4 -4
- package/dist/types/src/nanoclients.d.ts +106 -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 +91 -0
- package/dist/types/src/nanotdf/Client.d.ts.map +1 -0
- package/dist/types/src/nanotdf/NanoTDF.d.ts +24 -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 +11 -0
- package/dist/types/src/nanotdf/encrypt-dataset.d.ts.map +1 -0
- package/dist/types/src/nanotdf/encrypt.d.ts +13 -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 +8 -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.map +1 -0
- package/dist/types/src/nanotdf-crypto/decrypt.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/digest.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/ecdsaSignature.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/encrypt.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/enums.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/exportCryptoKey.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/index.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/keyAgreement.d.ts.map +1 -0
- package/dist/types/src/nanotdf-crypto/pemPublicToCrypto.d.ts.map +1 -0
- package/dist/types/src/opentdf.d.ts +65 -1
- package/dist/types/src/opentdf.d.ts.map +1 -1
- 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/types/index.d.ts +45 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/tdf3/index.d.ts +3 -4
- package/dist/types/tdf3/index.d.ts.map +1 -1
- package/dist/web/src/nanoclients.js +287 -0
- package/dist/web/src/nanoindex.js +5 -0
- package/dist/web/src/nanotdf/Client.js +310 -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/{crypto → nanotdf-crypto}/decrypt.js +1 -1
- package/dist/web/src/nanotdf-crypto/digest.js +4 -0
- package/dist/web/src/{crypto → nanotdf-crypto}/ecdsaSignature.js +2 -2
- package/dist/web/src/{crypto → nanotdf-crypto}/encrypt.js +1 -1
- package/dist/web/src/{crypto → nanotdf-crypto}/enums.js +1 -1
- 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/index.js +11 -0
- package/dist/web/src/{crypto → nanotdf-crypto}/keyAgreement.js +1 -1
- package/dist/web/src/{crypto → nanotdf-crypto}/pemPublicToCrypto.js +1 -1
- package/dist/web/src/opentdf.js +255 -8
- package/dist/web/src/tdf/NanoTDF/NanoTDF.js +35 -0
- package/dist/web/src/types/index.js +2 -0
- package/dist/web/src/utils.js +2 -2
- package/dist/web/tdf3/index.js +3 -4
- package/dist/web/tdf3/src/models/key-access.js +4 -4
- package/dist/web/tdf3/src/tdf.js +4 -4
- package/package.json +6 -1
- package/src/nanoclients.ts +406 -0
- package/src/nanoindex.ts +4 -0
- package/src/nanotdf/Client.ts +425 -0
- package/src/nanotdf/NanoTDF.ts +120 -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 +51 -0
- package/src/nanotdf/encrypt.ts +196 -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 +13 -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/{crypto → nanotdf-crypto}/ecdsaSignature.ts +1 -1
- package/src/opentdf.ts +343 -6
- package/src/tdf/NanoTDF/NanoTDF.ts +120 -0
- package/src/types/index.ts +55 -0
- package/src/utils.ts +1 -1
- package/tdf3/index.ts +12 -2
- package/tdf3/src/models/key-access.ts +3 -3
- package/tdf3/src/tdf.ts +3 -3
- package/dist/cjs/src/crypto/exportCryptoKey.js +0 -20
- package/dist/types/src/crypto/ciphers.d.ts.map +0 -1
- package/dist/types/src/crypto/decrypt.d.ts.map +0 -1
- package/dist/types/src/crypto/digest.d.ts.map +0 -1
- package/dist/types/src/crypto/ecdsaSignature.d.ts.map +0 -1
- package/dist/types/src/crypto/encrypt.d.ts.map +0 -1
- package/dist/types/src/crypto/enums.d.ts.map +0 -1
- package/dist/types/src/crypto/exportCryptoKey.d.ts.map +0 -1
- package/dist/types/src/crypto/generateKeyPair.d.ts.map +0 -1
- package/dist/types/src/crypto/generateRandomNumber.d.ts.map +0 -1
- package/dist/types/src/crypto/index.d.ts.map +0 -1
- package/dist/types/src/crypto/keyAgreement.d.ts.map +0 -1
- package/dist/types/src/crypto/pemPublicToCrypto.d.ts.map +0 -1
- package/dist/web/src/crypto/ciphers.js +0 -14
- package/dist/web/src/crypto/digest.js +0 -4
- package/dist/web/src/crypto/exportCryptoKey.js +0 -17
- package/dist/web/src/crypto/generateKeyPair.js +0 -10
- package/dist/web/src/crypto/generateRandomNumber.js +0 -9
- package/dist/web/src/crypto/index.js +0 -11
- /package/dist/types/src/{crypto → nanotdf-crypto}/ciphers.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/decrypt.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/digest.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/ecdsaSignature.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/encrypt.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/enums.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/exportCryptoKey.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/generateKeyPair.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/generateRandomNumber.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/index.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/keyAgreement.d.ts +0 -0
- /package/dist/types/src/{crypto → nanotdf-crypto}/pemPublicToCrypto.d.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/ciphers.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/decrypt.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/digest.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/encrypt.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/enums.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/exportCryptoKey.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/generateKeyPair.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/generateRandomNumber.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/index.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/keyAgreement.ts +0 -0
- /package/src/{crypto → nanotdf-crypto}/pemPublicToCrypto.ts +0 -0
package/src/opentdf.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { type AuthProvider } from './auth/providers.js';
|
|
2
2
|
import { ConfigurationError, InvalidFileError } from './errors.js';
|
|
3
|
+
import { type EncryptOptions as NanoEncryptOptions, NanoTDFDatasetClient } from './nanoclients.js';
|
|
3
4
|
export { Client as TDF3Client } from '../tdf3/src/client/index.js';
|
|
5
|
+
import NanoTDF from './nanotdf/NanoTDF.js';
|
|
6
|
+
import decryptNanoTDF from './nanotdf/decrypt.js';
|
|
7
|
+
import Client from './nanotdf/Client.js';
|
|
8
|
+
import Header from './nanotdf/models/Header.js';
|
|
4
9
|
import { Chunker, fromSource, sourceToStream, type Source } from './seekable.js';
|
|
5
10
|
import { Client as TDF3Client } from '../tdf3/src/client/index.js';
|
|
6
11
|
import {
|
|
@@ -29,6 +34,7 @@ import {
|
|
|
29
34
|
type IntegrityAlgorithm,
|
|
30
35
|
} from '../tdf3/src/tdf.js';
|
|
31
36
|
import { base64 } from './encodings/index.js';
|
|
37
|
+
import PolicyType from './nanotdf/enum/PolicyTypeEnum.js';
|
|
32
38
|
import { Policy } from '../tdf3/src/models/policy.js';
|
|
33
39
|
|
|
34
40
|
export {
|
|
@@ -79,6 +85,29 @@ export type CreateOptions = {
|
|
|
79
85
|
source: Source;
|
|
80
86
|
};
|
|
81
87
|
|
|
88
|
+
/** Options for creating a NanoTDF. */
|
|
89
|
+
export type CreateNanoTDFOptions = CreateOptions & {
|
|
90
|
+
/** The type of binding to use for the NanoTDF. */
|
|
91
|
+
bindingType?: 'ecdsa' | 'gmac';
|
|
92
|
+
|
|
93
|
+
/** When creating a new collection, use ECDSA binding with this key id from the signers, instead of the DEK. */
|
|
94
|
+
ecdsaBindingKeyID?: string;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* When creating a new collection, use the key in the `signers` list with this id
|
|
98
|
+
* to generate a signature for each element. When absent, the nanotdf is unsigned.
|
|
99
|
+
*/
|
|
100
|
+
signingKeyID?: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** Options for creating a NanoTDF collection. */
|
|
104
|
+
export type CreateNanoTDFCollectionOptions = CreateNanoTDFOptions & {
|
|
105
|
+
/** The platform URL. */
|
|
106
|
+
platformUrl: string;
|
|
107
|
+
/** The maximum number of key iterations to use for a single DEK. */
|
|
108
|
+
maxKeyIterations?: number;
|
|
109
|
+
};
|
|
110
|
+
|
|
82
111
|
/** Metadata for a TDF object. */
|
|
83
112
|
export type Metadata = object;
|
|
84
113
|
|
|
@@ -173,6 +202,9 @@ export type OpenTDFOptions = {
|
|
|
173
202
|
* which is out of the scope of this library.
|
|
174
203
|
*/
|
|
175
204
|
dpopKeys?: Promise<CryptoKeyPair>;
|
|
205
|
+
|
|
206
|
+
/** Configuration options for the collection header cache. */
|
|
207
|
+
rewrapCacheOptions?: RewrapCacheOptions;
|
|
176
208
|
};
|
|
177
209
|
|
|
178
210
|
/** A decorated readable stream. */
|
|
@@ -181,8 +213,86 @@ export type DecoratedStream = ReadableStream<Uint8Array> & {
|
|
|
181
213
|
metadata?: Promise<unknown>;
|
|
182
214
|
/** The TDF manifest. */
|
|
183
215
|
manifest?: Promise<Manifest>;
|
|
216
|
+
/** If the source is a NanoTDF, this will be set. */
|
|
217
|
+
header?: Header;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/** Configuration options for the collection header cache. */
|
|
221
|
+
export type RewrapCacheOptions = {
|
|
222
|
+
/** If we should disable (bypass) the cache. */
|
|
223
|
+
bypass?: boolean;
|
|
224
|
+
|
|
225
|
+
/** Evict keys after this many milliseconds. */
|
|
226
|
+
maxAge?: number;
|
|
227
|
+
|
|
228
|
+
/** Check for expired keys once every this many milliseconds. */
|
|
229
|
+
pollInterval?: number;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const defaultRewrapCacheOptions: Required<RewrapCacheOptions> = {
|
|
233
|
+
bypass: false,
|
|
234
|
+
maxAge: 300000,
|
|
235
|
+
pollInterval: 500,
|
|
184
236
|
};
|
|
185
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Cache for headers of nanotdf collections, to quickly open multiple entries of the same collection.
|
|
240
|
+
* It has a demon that removes all keys that have not been accessed in the last 5 minutes.
|
|
241
|
+
* To cancel the demon, and clear the cache, call `close()`.
|
|
242
|
+
* */
|
|
243
|
+
export class RewrapCache {
|
|
244
|
+
private cache?: Map<Uint8Array, { lastAccessTime: number; value: CryptoKey }>;
|
|
245
|
+
private closer?: ReturnType<typeof setInterval>;
|
|
246
|
+
constructor(opts?: RewrapCacheOptions) {
|
|
247
|
+
const { bypass, maxAge, pollInterval } = { ...defaultRewrapCacheOptions, ...opts };
|
|
248
|
+
if (bypass) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this.cache = new Map();
|
|
252
|
+
this.closer = setInterval(() => {
|
|
253
|
+
const now = Date.now();
|
|
254
|
+
const c = this.cache;
|
|
255
|
+
if (!c) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
for (const [key, value] of c.entries()) {
|
|
259
|
+
if (now - value.lastAccessTime > maxAge) {
|
|
260
|
+
c.delete(key);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}, pollInterval);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
get(key: Uint8Array): CryptoKey | undefined {
|
|
267
|
+
if (!this.cache) {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
const entry = this.cache.get(key);
|
|
271
|
+
if (entry) {
|
|
272
|
+
entry.lastAccessTime = Date.now();
|
|
273
|
+
return entry.value;
|
|
274
|
+
}
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Set a key in the cache. */
|
|
279
|
+
set(key: Uint8Array, value: CryptoKey) {
|
|
280
|
+
if (!this.cache) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
this.cache.set(key, { lastAccessTime: Date.now(), value });
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Close the cache and release any resources. */
|
|
287
|
+
close() {
|
|
288
|
+
if (this.closer !== undefined) {
|
|
289
|
+
clearInterval(this.closer);
|
|
290
|
+
delete this.closer;
|
|
291
|
+
delete this.cache;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
186
296
|
/**
|
|
187
297
|
* A TDF reader that can decrypt and inspect a TDF file.
|
|
188
298
|
*/
|
|
@@ -214,6 +324,7 @@ export type TDFReader = {
|
|
|
214
324
|
|
|
215
325
|
/**
|
|
216
326
|
* The main OpenTDF class that provides methods for creating and reading TDF files.
|
|
327
|
+
* It supports both NanoTDF and ZTDF formats.
|
|
217
328
|
* It can be used to create new TDF files and read existing ones.
|
|
218
329
|
* This class is the entry point for using the OpenTDF SDK.
|
|
219
330
|
* It requires an authentication provider to be passed in the constructor.
|
|
@@ -258,6 +369,8 @@ export class OpenTDF {
|
|
|
258
369
|
defaultReadOptions: Omit<ReadOptions, 'source'>;
|
|
259
370
|
/** The DPoP keys for this instance, if any. */
|
|
260
371
|
readonly dpopKeys: Promise<CryptoKeyPair>;
|
|
372
|
+
/** Cache for rewrapped keys */
|
|
373
|
+
private readonly rewrapCache: RewrapCache;
|
|
261
374
|
/** The TDF3 client for encrypting and decrypting ZTDF files. */
|
|
262
375
|
readonly tdf3Client: TDF3Client;
|
|
263
376
|
|
|
@@ -268,6 +381,7 @@ export class OpenTDF {
|
|
|
268
381
|
defaultReadOptions,
|
|
269
382
|
disableDPoP,
|
|
270
383
|
policyEndpoint,
|
|
384
|
+
rewrapCacheOptions,
|
|
271
385
|
platformUrl,
|
|
272
386
|
}: OpenTDFOptions) {
|
|
273
387
|
this.authProvider = authProvider;
|
|
@@ -282,6 +396,7 @@ export class OpenTDF {
|
|
|
282
396
|
);
|
|
283
397
|
}
|
|
284
398
|
this.policyEndpoint = policyEndpoint || '';
|
|
399
|
+
this.rewrapCache = new RewrapCache(rewrapCacheOptions);
|
|
285
400
|
this.tdf3Client = new TDF3Client({
|
|
286
401
|
authProvider,
|
|
287
402
|
dpopKeys,
|
|
@@ -303,6 +418,33 @@ export class OpenTDF {
|
|
|
303
418
|
);
|
|
304
419
|
}
|
|
305
420
|
|
|
421
|
+
/** Creates a new NanoTDF stream. */
|
|
422
|
+
async createNanoTDF(opts: CreateNanoTDFOptions): Promise<DecoratedStream> {
|
|
423
|
+
opts = {
|
|
424
|
+
...this.defaultCreateOptions,
|
|
425
|
+
...opts,
|
|
426
|
+
};
|
|
427
|
+
const collection = await this.createNanoTDFCollection({
|
|
428
|
+
...opts,
|
|
429
|
+
platformUrl: this.platformUrl,
|
|
430
|
+
});
|
|
431
|
+
try {
|
|
432
|
+
return await collection.encrypt(opts.source);
|
|
433
|
+
} finally {
|
|
434
|
+
await collection.close();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Creates a new collection object, which can be used to encrypt a series of data with the same policy.
|
|
440
|
+
*/
|
|
441
|
+
async createNanoTDFCollection(
|
|
442
|
+
opts: CreateNanoTDFCollectionOptions
|
|
443
|
+
): Promise<NanoTDFCollectionWriter> {
|
|
444
|
+
opts = { ...this.defaultCreateOptions, ...opts };
|
|
445
|
+
return new Collection(this.authProvider, opts);
|
|
446
|
+
}
|
|
447
|
+
|
|
306
448
|
/** Creates a new ZTDF stream. */
|
|
307
449
|
async createZTDF(opts: CreateZTDFOptions): Promise<DecoratedStream> {
|
|
308
450
|
opts = { ...this.defaultCreateOptions, ...opts };
|
|
@@ -331,7 +473,7 @@ export class OpenTDF {
|
|
|
331
473
|
/** Opens a TDF file for inspection and decryption. */
|
|
332
474
|
open(opts: ReadOptions): TDFReader {
|
|
333
475
|
opts = { ...this.defaultReadOptions, ...opts };
|
|
334
|
-
return new
|
|
476
|
+
return new UnknownTypeReader(this, opts, this.rewrapCache);
|
|
335
477
|
}
|
|
336
478
|
|
|
337
479
|
/** Decrypts a TDF file. */
|
|
@@ -342,17 +484,18 @@ export class OpenTDF {
|
|
|
342
484
|
|
|
343
485
|
/** Closes the OpenTDF instance and releases any resources. */
|
|
344
486
|
close() {
|
|
345
|
-
|
|
487
|
+
this.rewrapCache.close();
|
|
346
488
|
}
|
|
347
489
|
}
|
|
348
490
|
|
|
349
|
-
/** A TDF reader
|
|
350
|
-
class
|
|
491
|
+
/** A TDF reader that can automatically detect the TDF type. */
|
|
492
|
+
class UnknownTypeReader {
|
|
351
493
|
delegate: Promise<TDFReader>;
|
|
352
494
|
state: 'init' | 'resolving' | 'loaded' | 'decrypting' | 'closing' | 'done' | 'error' = 'init';
|
|
353
495
|
constructor(
|
|
354
496
|
readonly outer: OpenTDF,
|
|
355
|
-
readonly opts: ReadOptions
|
|
497
|
+
readonly opts: ReadOptions,
|
|
498
|
+
private readonly rewrapCache: RewrapCache
|
|
356
499
|
) {
|
|
357
500
|
this.delegate = this.resolveType();
|
|
358
501
|
}
|
|
@@ -371,6 +514,9 @@ class ZTDFReaderWrapper {
|
|
|
371
514
|
if (prefix[0] === 0x50 && prefix[1] === 0x4b) {
|
|
372
515
|
this.state = 'loaded';
|
|
373
516
|
return new ZTDFReader(this.outer.tdf3Client, this.opts, chunker);
|
|
517
|
+
} else if (prefix[0] === 0x4c && prefix[1] === 0x31 && prefix[2] === 0x4c) {
|
|
518
|
+
this.state = 'loaded';
|
|
519
|
+
return new NanoTDFReader(this.outer, this.opts, chunker, this.rewrapCache);
|
|
374
520
|
}
|
|
375
521
|
this.state = 'done';
|
|
376
522
|
throw new InvalidFileError(`unsupported format; prefix not recognized ${prefix}`);
|
|
@@ -417,7 +563,117 @@ class ZTDFReaderWrapper {
|
|
|
417
563
|
}
|
|
418
564
|
}
|
|
419
565
|
|
|
420
|
-
/** A reader for
|
|
566
|
+
/** A TDF reader for NanoTDF files. */
|
|
567
|
+
class NanoTDFReader {
|
|
568
|
+
container: Promise<NanoTDF>;
|
|
569
|
+
// Required obligation FQNs that must be fulfilled, provided via the decrypt flow.
|
|
570
|
+
private requiredObligations?: RequiredObligations;
|
|
571
|
+
constructor(
|
|
572
|
+
readonly outer: OpenTDF,
|
|
573
|
+
readonly opts: ReadOptions,
|
|
574
|
+
readonly chunker: Chunker,
|
|
575
|
+
private readonly rewrapCache: RewrapCache
|
|
576
|
+
) {
|
|
577
|
+
if (
|
|
578
|
+
!this.opts.ignoreAllowlist &&
|
|
579
|
+
!this.opts.platformUrl &&
|
|
580
|
+
!this.opts.allowedKASEndpoints?.length
|
|
581
|
+
) {
|
|
582
|
+
throw new ConfigurationError('platformUrl is required when allowedKasEndpoints is empty');
|
|
583
|
+
}
|
|
584
|
+
// lazily load the container
|
|
585
|
+
this.container = new Promise(async (resolve, reject) => {
|
|
586
|
+
try {
|
|
587
|
+
const ciphertext = await chunker();
|
|
588
|
+
const nanotdf = NanoTDF.from(ciphertext);
|
|
589
|
+
resolve(nanotdf);
|
|
590
|
+
} catch (e) {
|
|
591
|
+
reject(e);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Decrypts the NanoTDF file and returns a decorated stream.
|
|
598
|
+
* Sets required obligations on the reader when retrieved from KAS rewrap response.
|
|
599
|
+
*/
|
|
600
|
+
async decrypt(): Promise<DecoratedStream> {
|
|
601
|
+
const nanotdf = await this.container;
|
|
602
|
+
const cachedDEK = this.rewrapCache.get(nanotdf.header.ephemeralPublicKey);
|
|
603
|
+
if (cachedDEK) {
|
|
604
|
+
const r: DecoratedStream = await streamify(decryptNanoTDF(cachedDEK, nanotdf));
|
|
605
|
+
r.header = nanotdf.header;
|
|
606
|
+
return r;
|
|
607
|
+
}
|
|
608
|
+
const platformUrl = this.opts.platformUrl || this.outer.platformUrl;
|
|
609
|
+
const kasEndpoint =
|
|
610
|
+
this.opts.allowedKASEndpoints?.[0] || platformUrl || 'https://disallow.all.invalid';
|
|
611
|
+
const nc = new Client({
|
|
612
|
+
allowedKases: this.opts.allowedKASEndpoints,
|
|
613
|
+
fulfillableObligationFQNs: this.opts.fulfillableObligationFQNs,
|
|
614
|
+
authProvider: this.outer.authProvider,
|
|
615
|
+
ignoreAllowList: this.opts.ignoreAllowlist,
|
|
616
|
+
dpopEnabled: this.outer.dpopEnabled,
|
|
617
|
+
dpopKeys: this.outer.dpopKeys,
|
|
618
|
+
kasEndpoint,
|
|
619
|
+
platformUrl,
|
|
620
|
+
});
|
|
621
|
+
// TODO: The version number should be fetched from the API
|
|
622
|
+
const version = '0.0.1';
|
|
623
|
+
// Rewrap key on every request
|
|
624
|
+
const { unwrappedKey: dek, requiredObligations } = await nc.rewrapKey(
|
|
625
|
+
nanotdf.header.toBuffer(),
|
|
626
|
+
nanotdf.header.getKasRewrapUrl(),
|
|
627
|
+
nanotdf.header.magicNumberVersion,
|
|
628
|
+
version
|
|
629
|
+
);
|
|
630
|
+
if (!dek) {
|
|
631
|
+
// These should have thrown already.
|
|
632
|
+
throw new Error('internal: key rewrap failure');
|
|
633
|
+
}
|
|
634
|
+
this.requiredObligations = { fqns: requiredObligations };
|
|
635
|
+
this.rewrapCache.set(nanotdf.header.ephemeralPublicKey, dek);
|
|
636
|
+
const r: DecoratedStream = await streamify(decryptNanoTDF(dek, nanotdf));
|
|
637
|
+
// TODO figure out how to attach policy and metadata to the stream
|
|
638
|
+
r.header = nanotdf.header;
|
|
639
|
+
return r;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
async close() {}
|
|
643
|
+
|
|
644
|
+
/** Returns blank manifest. NanoTDF has no manifest. */
|
|
645
|
+
async manifest(): Promise<Manifest> {
|
|
646
|
+
return {} as Manifest;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** Returns the attributes of the NanoTDF file. */
|
|
650
|
+
async attributes(): Promise<string[]> {
|
|
651
|
+
const nanotdf = await this.container;
|
|
652
|
+
if (!nanotdf.header.policy?.content) {
|
|
653
|
+
return [];
|
|
654
|
+
}
|
|
655
|
+
if (nanotdf.header.policy.type !== PolicyType.EmbeddedText) {
|
|
656
|
+
throw new Error('unsupported policy type');
|
|
657
|
+
}
|
|
658
|
+
const policyString = new TextDecoder().decode(nanotdf.header.policy.content);
|
|
659
|
+
const policy = JSON.parse(policyString) as Policy;
|
|
660
|
+
return policy?.body?.dataAttributes.map((a) => a.attribute) || [];
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Returns obligations populated from the decrypt flow.
|
|
665
|
+
* If a decrypt has not occurred, attempts one to retrieve obligations.
|
|
666
|
+
*/
|
|
667
|
+
async obligations(): Promise<RequiredObligations> {
|
|
668
|
+
if (this.requiredObligations) {
|
|
669
|
+
return this.requiredObligations;
|
|
670
|
+
}
|
|
671
|
+
await this.decrypt();
|
|
672
|
+
return this.requiredObligations ?? { fqns: [] };
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/** A reader for TDF files. */
|
|
421
677
|
class ZTDFReader {
|
|
422
678
|
overview: Promise<InspectedTDFOverview>;
|
|
423
679
|
// Required obligation FQNs that must be fulfilled, provided via the decrypt flow.
|
|
@@ -522,3 +778,84 @@ class ZTDFReader {
|
|
|
522
778
|
return this.requiredObligations ?? { fqns: [] };
|
|
523
779
|
}
|
|
524
780
|
}
|
|
781
|
+
|
|
782
|
+
async function streamify(ab: Promise<ArrayBuffer>): Promise<ReadableStream<Uint8Array>> {
|
|
783
|
+
const stream = new ReadableStream<Uint8Array>({
|
|
784
|
+
start(controller) {
|
|
785
|
+
ab.then((arrayBuffer) => {
|
|
786
|
+
controller.enqueue(new Uint8Array(arrayBuffer));
|
|
787
|
+
controller.close();
|
|
788
|
+
});
|
|
789
|
+
},
|
|
790
|
+
});
|
|
791
|
+
return stream;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/** A writer for NanoTDF collections. */
|
|
795
|
+
export type NanoTDFCollectionWriter = {
|
|
796
|
+
/** The NanoTDF client used for encrypting data in this collection. */
|
|
797
|
+
encrypt: (source: Source) => Promise<ReadableStream<Uint8Array>>;
|
|
798
|
+
/** Closes the collection and releases any resources. */
|
|
799
|
+
close: () => Promise<void>;
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
class Collection {
|
|
803
|
+
/** The NanoTDF client used for encrypting data in this collection. */
|
|
804
|
+
client?: NanoTDFDatasetClient;
|
|
805
|
+
/** Options for encrypting data in this collection. */
|
|
806
|
+
encryptOptions?: NanoEncryptOptions;
|
|
807
|
+
|
|
808
|
+
constructor(authProvider: AuthProvider, opts: CreateNanoTDFCollectionOptions) {
|
|
809
|
+
if (opts.signers || opts.signingKeyID) {
|
|
810
|
+
throw new ConfigurationError('ntdf signing not implemented');
|
|
811
|
+
}
|
|
812
|
+
if (opts.autoconfigure) {
|
|
813
|
+
throw new ConfigurationError('autoconfigure not implemented');
|
|
814
|
+
}
|
|
815
|
+
if (opts.ecdsaBindingKeyID) {
|
|
816
|
+
throw new ConfigurationError('custom binding key not implemented');
|
|
817
|
+
}
|
|
818
|
+
switch (opts.bindingType) {
|
|
819
|
+
case 'ecdsa':
|
|
820
|
+
this.encryptOptions = { ecdsaBinding: true };
|
|
821
|
+
break;
|
|
822
|
+
case 'gmac':
|
|
823
|
+
this.encryptOptions = { ecdsaBinding: false };
|
|
824
|
+
break;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
const kasEndpoint =
|
|
828
|
+
opts.defaultKASEndpoint || opts.platformUrl || 'https://disallow.all.invalid';
|
|
829
|
+
|
|
830
|
+
this.client = new NanoTDFDatasetClient({
|
|
831
|
+
authProvider,
|
|
832
|
+
kasEndpoint: kasEndpoint,
|
|
833
|
+
maxKeyIterations: opts.maxKeyIterations,
|
|
834
|
+
platformUrl: opts.platformUrl,
|
|
835
|
+
});
|
|
836
|
+
this.client.dataAttributes = opts.attributes || [];
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** Encrypts a source into a NanoTDF stream. */
|
|
840
|
+
async encrypt(source: Source): Promise<DecoratedStream> {
|
|
841
|
+
if (!this.client) {
|
|
842
|
+
throw new ConfigurationError('Collection is closed');
|
|
843
|
+
}
|
|
844
|
+
const chunker = await fromSource(source);
|
|
845
|
+
const cipherChunk = await this.client.encrypt(await chunker(), this.encryptOptions);
|
|
846
|
+
const stream: DecoratedStream = new ReadableStream<Uint8Array>({
|
|
847
|
+
start(controller) {
|
|
848
|
+
controller.enqueue(new Uint8Array(cipherChunk));
|
|
849
|
+
controller.close();
|
|
850
|
+
},
|
|
851
|
+
});
|
|
852
|
+
// TODO: client's header object is private
|
|
853
|
+
// stream.header = this.client.header;
|
|
854
|
+
return stream;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** Releases client resources. */
|
|
858
|
+
async close() {
|
|
859
|
+
delete this.client;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
enum CipherType {
|
|
2
|
+
Aes256Gcm64, // Default cipher
|
|
3
|
+
Aes256Gcm96,
|
|
4
|
+
Aes256Gcm104,
|
|
5
|
+
Aes256Gcm112,
|
|
6
|
+
Aes256Gcm120,
|
|
7
|
+
Aes256Gcm128,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The Signature ECC Mode is used to determine the length of the signature at the end of a nanotdf. This, in
|
|
12
|
+
* combination with the previous HAS_SIGNATURE section, describe the signature of the nanotdf. The following table
|
|
13
|
+
* describes the valid values and the associated ECC Params.
|
|
14
|
+
*/
|
|
15
|
+
enum CurveName {
|
|
16
|
+
Secp256R1,
|
|
17
|
+
Secp384R1,
|
|
18
|
+
Secp521R1,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export enum ResourceLocatorProtocol {
|
|
22
|
+
Http,
|
|
23
|
+
Https,
|
|
24
|
+
Unreserverd,
|
|
25
|
+
SharedResourceDirectory = 0xff,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export enum PolicyType {
|
|
29
|
+
Remote,
|
|
30
|
+
EmbeddedText,
|
|
31
|
+
EmbeddedEncrypted, // Default policy
|
|
32
|
+
EmbeddedEncryptedPKA, // Todo: Not implemented
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Resource Locator interface
|
|
37
|
+
*/
|
|
38
|
+
export interface ResourceLocator {
|
|
39
|
+
protocol: ResourceLocatorProtocol;
|
|
40
|
+
length: number;
|
|
41
|
+
body: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Policy interface
|
|
46
|
+
*/
|
|
47
|
+
export interface Policy {
|
|
48
|
+
type: PolicyType;
|
|
49
|
+
binding: Uint8Array;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Remote policy interface
|
|
54
|
+
*/
|
|
55
|
+
export interface RemotePolicy extends Policy {
|
|
56
|
+
protocol: ResourceLocatorProtocol;
|
|
57
|
+
urn: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Embedded policy interface
|
|
62
|
+
*/
|
|
63
|
+
export interface EmbeddedPolicy extends Policy {
|
|
64
|
+
content: Uint8Array;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Header interface
|
|
69
|
+
*/
|
|
70
|
+
export interface Header {
|
|
71
|
+
// Magic Number & Version
|
|
72
|
+
magicNumberVersion: Uint8Array;
|
|
73
|
+
|
|
74
|
+
// KAS Resource Locator
|
|
75
|
+
kas: ResourceLocator;
|
|
76
|
+
|
|
77
|
+
// ECC & Binding Mode
|
|
78
|
+
useECDSABinding: boolean;
|
|
79
|
+
ephemeralCurveName: CurveName;
|
|
80
|
+
|
|
81
|
+
// Symmetric & Payload Config
|
|
82
|
+
hasSignature: boolean;
|
|
83
|
+
signatureCurveName: CurveName;
|
|
84
|
+
symmetricCipher: CipherType;
|
|
85
|
+
// Auth tag length is not part of the spec, but is needed for decrypt
|
|
86
|
+
authTagLength: number;
|
|
87
|
+
|
|
88
|
+
// Policy
|
|
89
|
+
policy: RemotePolicy | EmbeddedPolicy;
|
|
90
|
+
|
|
91
|
+
// Ephemeral Public Key
|
|
92
|
+
ephemeralPublicKey: Uint8Array;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Payload interface
|
|
97
|
+
*/
|
|
98
|
+
export interface Payload {
|
|
99
|
+
iv: Uint8Array;
|
|
100
|
+
ciphertext: Uint8Array;
|
|
101
|
+
authTag: Uint8Array;
|
|
102
|
+
ciphertextAuthTag: Uint8Array;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Signature interface
|
|
107
|
+
*/
|
|
108
|
+
export interface Signature {
|
|
109
|
+
publicKey: Uint8Array;
|
|
110
|
+
signature: Uint8Array;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* NanoTDF interface
|
|
115
|
+
*/
|
|
116
|
+
export interface NanoTDF {
|
|
117
|
+
header: Header;
|
|
118
|
+
payload: Payload;
|
|
119
|
+
signature: Signature;
|
|
120
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import PolicyTypeEnum from '../nanotdf/enum/PolicyTypeEnum.js';
|
|
2
|
+
|
|
3
|
+
export type InputSource =
|
|
4
|
+
| ReadableStream<Uint8Array>
|
|
5
|
+
| Uint8Array
|
|
6
|
+
| string
|
|
7
|
+
| ArrayBuffer
|
|
8
|
+
| Promise<ReadableStream<Uint8Array>>;
|
|
9
|
+
|
|
10
|
+
type Header = {
|
|
11
|
+
magicNumberVersion: string[];
|
|
12
|
+
kas: {
|
|
13
|
+
protocol: number;
|
|
14
|
+
length: number;
|
|
15
|
+
body: string;
|
|
16
|
+
};
|
|
17
|
+
eccBindingMode: {
|
|
18
|
+
useECDSABinding: boolean;
|
|
19
|
+
ephemeralCurveName: number;
|
|
20
|
+
};
|
|
21
|
+
symmetricPayloadConfig: {
|
|
22
|
+
hasSignature: boolean;
|
|
23
|
+
signatureCurveName: number;
|
|
24
|
+
symmetricCipher: number;
|
|
25
|
+
};
|
|
26
|
+
ephemeralPublicKey: string[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type HeaderPolicy = {
|
|
30
|
+
type: PolicyTypeEnum;
|
|
31
|
+
content: string[];
|
|
32
|
+
binding: string[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type RemotePolicy = {
|
|
36
|
+
protocol: number;
|
|
37
|
+
length: number;
|
|
38
|
+
body: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type PlainEmbeddedHeader = Header & {
|
|
42
|
+
policy: HeaderPolicy;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type EmbeddedHeader = Header & {
|
|
46
|
+
policy: HeaderPolicy;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type RemoteHeader = Header & {
|
|
50
|
+
policy: {
|
|
51
|
+
type: PolicyTypeEnum;
|
|
52
|
+
remotePolicy: RemotePolicy;
|
|
53
|
+
binding: string[];
|
|
54
|
+
};
|
|
55
|
+
};
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { exportSPKI, importX509 } from 'jose';
|
|
2
2
|
|
|
3
3
|
import { base64 } from './encodings/index.js';
|
|
4
|
-
import { pemCertToCrypto, pemPublicToCrypto } from './crypto/pemPublicToCrypto.js';
|
|
4
|
+
import { pemCertToCrypto, pemPublicToCrypto } from './nanotdf-crypto/pemPublicToCrypto.js';
|
|
5
5
|
import { ConfigurationError } from './errors.js';
|
|
6
6
|
import {
|
|
7
7
|
RewrapResponse,
|
package/tdf3/index.ts
CHANGED
|
@@ -27,8 +27,13 @@ import {
|
|
|
27
27
|
} from './src/models/encryption-information.js';
|
|
28
28
|
import { AuthProvider, type HttpMethod, HttpRequest, withHeaders } from '../src/auth/auth.js';
|
|
29
29
|
import { AesGcmCipher } from './src/ciphers/aes-gcm-cipher.js';
|
|
30
|
-
import
|
|
31
|
-
|
|
30
|
+
import {
|
|
31
|
+
NanoTDFClient,
|
|
32
|
+
NanoTDFDatasetClient,
|
|
33
|
+
AuthProviders,
|
|
34
|
+
version,
|
|
35
|
+
clientType,
|
|
36
|
+
} from '../src/nanoindex.js';
|
|
32
37
|
import { Algorithms, type AlgorithmName, type AlgorithmUrn } from './src/ciphers/algorithms.js';
|
|
33
38
|
import { type Chunker } from '../src/seekable.js';
|
|
34
39
|
|
|
@@ -66,6 +71,8 @@ export {
|
|
|
66
71
|
Errors,
|
|
67
72
|
HttpRequest,
|
|
68
73
|
KeyInfo,
|
|
74
|
+
NanoTDFClient,
|
|
75
|
+
NanoTDFDatasetClient,
|
|
69
76
|
SplitKey,
|
|
70
77
|
TDF3Client,
|
|
71
78
|
clientType,
|
|
@@ -76,11 +83,14 @@ export {
|
|
|
76
83
|
|
|
77
84
|
export * as WebCryptoService from './src/crypto/index.js';
|
|
78
85
|
export {
|
|
86
|
+
type CreateNanoTDFCollectionOptions,
|
|
87
|
+
type CreateNanoTDFOptions,
|
|
79
88
|
type CreateOptions,
|
|
80
89
|
type CreateZTDFOptions,
|
|
81
90
|
type DecoratedStream,
|
|
82
91
|
type Keys,
|
|
83
92
|
type OpenTDFOptions,
|
|
93
|
+
type NanoTDFCollectionWriter,
|
|
84
94
|
type ReadOptions,
|
|
85
95
|
type TDFReader,
|
|
86
96
|
OpenTDF,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { base64, hex } from '../../../src/encodings/index.js';
|
|
2
|
-
import { generateRandomNumber } from '../../../src/crypto/generateRandomNumber.js';
|
|
3
|
-
import { keyAgreement } from '../../../src/crypto/keyAgreement.js';
|
|
4
|
-
import { pemPublicToCrypto } from '../../../src/crypto/pemPublicToCrypto.js';
|
|
2
|
+
import { generateRandomNumber } from '../../../src/nanotdf-crypto/generateRandomNumber.js';
|
|
3
|
+
import { keyAgreement } from '../../../src/nanotdf-crypto/keyAgreement.js';
|
|
4
|
+
import { pemPublicToCrypto } from '../../../src/nanotdf-crypto/pemPublicToCrypto.js';
|
|
5
5
|
import { cryptoPublicToPem } from '../../../src/utils.js';
|
|
6
6
|
import { Binary } from '../binary.js';
|
|
7
7
|
import * as cryptoService from '../crypto/index.js';
|
package/tdf3/src/tdf.ts
CHANGED
|
@@ -29,9 +29,9 @@ import {
|
|
|
29
29
|
UnsafeUrlError,
|
|
30
30
|
UnsupportedFeatureError as UnsupportedError,
|
|
31
31
|
} from '../../src/errors.js';
|
|
32
|
-
import { generateKeyPair } from '../../src/crypto/generateKeyPair.js';
|
|
33
|
-
import { keyAgreement } from '../../src/crypto/keyAgreement.js';
|
|
34
|
-
import { pemPublicToCrypto } from '../../src/crypto/pemPublicToCrypto.js';
|
|
32
|
+
import { generateKeyPair } from '../../src/nanotdf-crypto/generateKeyPair.js';
|
|
33
|
+
import { keyAgreement } from '../../src/nanotdf-crypto/keyAgreement.js';
|
|
34
|
+
import { pemPublicToCrypto } from '../../src/nanotdf-crypto/pemPublicToCrypto.js';
|
|
35
35
|
import { type Chunker } from '../../src/seekable.js';
|
|
36
36
|
import { tdfSpecVersion } from '../../src/version.js';
|
|
37
37
|
import { AssertionConfig, AssertionKey, AssertionVerificationKeys } from './assertions.js';
|