@opentdf/sdk 0.4.0-beta.4 → 0.4.0-beta.40
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/dist/cjs/src/access.js +16 -1
- package/dist/cjs/src/auth/oidc-clientcredentials-provider.js +4 -2
- package/dist/cjs/src/auth/oidc-externaljwt-provider.js +5 -3
- package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +19 -3
- package/dist/cjs/src/auth/oidc.js +9 -8
- package/dist/cjs/src/auth/providers.js +7 -1
- package/dist/cjs/src/index.js +4 -2
- package/dist/cjs/src/opentdf.js +66 -12
- package/dist/cjs/src/platform/authorization/v2/authorization_pb.js +112 -0
- package/dist/cjs/src/platform/buf/validate/validate_pb.js +114 -170
- package/dist/cjs/src/platform/common/common_pb.js +16 -5
- package/dist/cjs/src/platform/entity/entity_pb.js +51 -0
- package/dist/cjs/src/platform/entityresolution/entity_resolution_pb.js +1 -1
- package/dist/cjs/src/platform/entityresolution/v2/entity_resolution_pb.js +49 -0
- package/dist/cjs/src/platform/google/api/annotations_pb.js +1 -1
- package/dist/cjs/src/platform/google/api/http_pb.js +3 -3
- package/dist/cjs/src/platform/kas/kas_pb.js +2 -2
- package/dist/cjs/src/platform/policy/attributes/attributes_pb.js +12 -2
- package/dist/cjs/src/platform/policy/kasregistry/key_access_server_registry_pb.js +57 -4
- package/dist/cjs/src/platform/policy/keymanagement/key_management_pb.js +2 -2
- package/dist/cjs/src/platform/policy/namespaces/namespaces_pb.js +31 -4
- package/dist/cjs/src/platform/policy/objects_pb.js +116 -42
- package/dist/cjs/src/platform/policy/obligations/obligations_pb.js +159 -0
- package/dist/cjs/src/platform/policy/registeredresources/registered_resources_pb.js +20 -15
- package/dist/cjs/src/platform/policy/resourcemapping/resource_mapping_pb.js +2 -3
- package/dist/cjs/src/platform/policy/selectors_pb.js +1 -1
- package/dist/cjs/src/platform/policy/subjectmapping/subject_mapping_pb.js +2 -3
- package/dist/cjs/src/platform/policy/unsafe/unsafe_pb.js +2 -4
- package/dist/cjs/src/platform.js +16 -3
- package/dist/cjs/src/policy/api.js +27 -7
- package/dist/cjs/src/policy/granter.js +75 -48
- package/dist/cjs/src/seekable.js +32 -1
- package/dist/cjs/src/utils.js +57 -3
- package/dist/cjs/tdf3/src/assertions.js +39 -2
- package/dist/cjs/tdf3/src/client/builders.js +13 -1
- package/dist/cjs/tdf3/src/client/index.js +200 -53
- package/dist/cjs/tdf3/src/client/validation.js +3 -3
- package/dist/cjs/tdf3/src/tdf.js +20 -2
- package/dist/cjs/tdf3/src/utils/unwrap.js +2 -2
- package/dist/types/src/access.d.ts +15 -0
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts +1 -1
- package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-externaljwt-provider.d.ts +1 -1
- package/dist/types/src/auth/oidc-externaljwt-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +15 -1
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc.d.ts +4 -0
- package/dist/types/src/auth/oidc.d.ts.map +1 -1
- package/dist/types/src/auth/providers.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +126 -6
- package/dist/types/src/opentdf.d.ts.map +1 -1
- package/dist/types/src/platform/authorization/v2/authorization_pb.d.ts +439 -0
- package/dist/types/src/platform/authorization/v2/authorization_pb.d.ts.map +1 -0
- package/dist/types/src/platform/buf/validate/validate_pb.d.ts +495 -370
- package/dist/types/src/platform/buf/validate/validate_pb.d.ts.map +1 -1
- package/dist/types/src/platform/common/common_pb.d.ts +36 -0
- package/dist/types/src/platform/common/common_pb.d.ts.map +1 -1
- package/dist/types/src/platform/entity/entity_pb.d.ts +130 -0
- package/dist/types/src/platform/entity/entity_pb.d.ts.map +1 -0
- package/dist/types/src/platform/entityresolution/entity_resolution_pb.d.ts +4 -0
- package/dist/types/src/platform/entityresolution/entity_resolution_pb.d.ts.map +1 -1
- package/dist/types/src/platform/entityresolution/v2/entity_resolution_pb.d.ts +136 -0
- package/dist/types/src/platform/entityresolution/v2/entity_resolution_pb.d.ts.map +1 -0
- package/dist/types/src/platform/google/api/http_pb.d.ts.map +1 -1
- package/dist/types/src/platform/kas/kas_pb.d.ts +5 -0
- package/dist/types/src/platform/kas/kas_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/attributes/attributes_pb.d.ts +44 -13
- package/dist/types/src/platform/policy/attributes/attributes_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts +329 -24
- package/dist/types/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/keymanagement/key_management_pb.d.ts +20 -1
- package/dist/types/src/platform/policy/keymanagement/key_management_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/namespaces/namespaces_pb.d.ts +143 -5
- package/dist/types/src/platform/policy/namespaces/namespaces_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/objects_pb.d.ts +382 -33
- package/dist/types/src/platform/policy/objects_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/obligations/obligations_pb.d.ts +670 -0
- package/dist/types/src/platform/policy/obligations/obligations_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/registeredresources/registered_resources_pb.d.ts +67 -0
- package/dist/types/src/platform/policy/registeredresources/registered_resources_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/resourcemapping/resource_mapping_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/selectors_pb.d.ts +18 -0
- package/dist/types/src/platform/policy/selectors_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/subjectmapping/subject_mapping_pb.d.ts.map +1 -1
- package/dist/types/src/platform/policy/unsafe/unsafe_pb.d.ts +18 -4
- package/dist/types/src/platform/policy/unsafe/unsafe_pb.d.ts.map +1 -1
- package/dist/types/src/platform.d.ts +16 -0
- package/dist/types/src/platform.d.ts.map +1 -1
- package/dist/types/src/policy/api.d.ts +2 -0
- package/dist/types/src/policy/api.d.ts.map +1 -1
- package/dist/types/src/policy/granter.d.ts +11 -6
- package/dist/types/src/policy/granter.d.ts.map +1 -1
- package/dist/types/src/seekable.d.ts +31 -0
- package/dist/types/src/seekable.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts +56 -2
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/tdf3/src/assertions.d.ts +4 -0
- package/dist/types/tdf3/src/assertions.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/builders.d.ts +12 -0
- package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/index.d.ts +11 -3
- 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/tdf.d.ts +2 -1
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/unwrap.d.ts.map +1 -1
- package/dist/web/src/access.js +16 -1
- package/dist/web/src/auth/oidc-clientcredentials-provider.js +4 -2
- package/dist/web/src/auth/oidc-externaljwt-provider.js +5 -3
- package/dist/web/src/auth/oidc-refreshtoken-provider.js +19 -3
- package/dist/web/src/auth/oidc.js +9 -8
- package/dist/web/src/auth/providers.js +7 -1
- package/dist/web/src/index.js +2 -1
- package/dist/web/src/opentdf.js +66 -12
- package/dist/web/src/platform/authorization/v2/authorization_pb.js +109 -0
- package/dist/web/src/platform/buf/validate/validate_pb.js +113 -169
- package/dist/web/src/platform/common/common_pb.js +15 -4
- package/dist/web/src/platform/entity/entity_pb.js +48 -0
- package/dist/web/src/platform/entityresolution/entity_resolution_pb.js +1 -1
- package/dist/web/src/platform/entityresolution/v2/entity_resolution_pb.js +46 -0
- package/dist/web/src/platform/google/api/annotations_pb.js +1 -1
- package/dist/web/src/platform/google/api/http_pb.js +3 -3
- package/dist/web/src/platform/kas/kas_pb.js +2 -2
- package/dist/web/src/platform/policy/attributes/attributes_pb.js +12 -2
- package/dist/web/src/platform/policy/kasregistry/key_access_server_registry_pb.js +55 -3
- package/dist/web/src/platform/policy/keymanagement/key_management_pb.js +2 -2
- package/dist/web/src/platform/policy/namespaces/namespaces_pb.js +30 -3
- package/dist/web/src/platform/policy/objects_pb.js +114 -41
- package/dist/web/src/platform/policy/obligations/obligations_pb.js +156 -0
- package/dist/web/src/platform/policy/registeredresources/registered_resources_pb.js +19 -14
- package/dist/web/src/platform/policy/resourcemapping/resource_mapping_pb.js +2 -3
- package/dist/web/src/platform/policy/selectors_pb.js +1 -1
- package/dist/web/src/platform/policy/subjectmapping/subject_mapping_pb.js +2 -3
- package/dist/web/src/platform/policy/unsafe/unsafe_pb.js +2 -4
- package/dist/web/src/platform.js +16 -3
- package/dist/web/src/policy/api.js +26 -7
- package/dist/web/src/policy/granter.js +75 -48
- package/dist/web/src/seekable.js +32 -1
- package/dist/web/src/utils.js +57 -3
- package/dist/web/tdf3/src/assertions.js +38 -2
- package/dist/web/tdf3/src/client/builders.js +13 -1
- package/dist/web/tdf3/src/client/index.js +202 -56
- package/dist/web/tdf3/src/client/validation.js +3 -3
- package/dist/web/tdf3/src/tdf.js +20 -2
- package/dist/web/tdf3/src/utils/unwrap.js +2 -2
- package/package.json +7 -5
- package/src/access.ts +15 -0
- package/src/auth/oidc-clientcredentials-provider.ts +4 -0
- package/src/auth/oidc-externaljwt-provider.ts +5 -1
- package/src/auth/oidc-refreshtoken-provider.ts +19 -1
- package/src/auth/oidc.ts +12 -7
- package/src/auth/providers.ts +6 -0
- package/src/index.ts +1 -0
- package/src/opentdf.ts +149 -72
- package/src/platform/authorization/v2/authorization_pb.ts +503 -0
- package/src/platform/buf/validate/validate_pb.ts +529 -401
- package/src/platform/common/common_pb.ts +48 -3
- package/src/platform/entity/entity_pb.ts +154 -0
- package/src/platform/entityresolution/entity_resolution_pb.ts +4 -0
- package/src/platform/entityresolution/v2/entity_resolution_pb.ts +170 -0
- package/src/platform/google/api/annotations_pb.ts +1 -1
- package/src/platform/google/api/http_pb.ts +2 -2
- package/src/platform/kas/kas_pb.ts +6 -1
- package/src/platform/policy/attributes/attributes_pb.ts +46 -16
- package/src/platform/policy/kasregistry/key_access_server_registry_pb.ts +371 -27
- package/src/platform/policy/keymanagement/key_management_pb.ts +24 -2
- package/src/platform/policy/namespaces/namespaces_pb.ts +163 -7
- package/src/platform/policy/objects_pb.ts +474 -59
- package/src/platform/policy/obligations/obligations_pb.ts +788 -0
- package/src/platform/policy/registeredresources/registered_resources_pb.ts +80 -13
- package/src/platform/policy/resourcemapping/resource_mapping_pb.ts +1 -2
- package/src/platform/policy/selectors_pb.ts +18 -0
- package/src/platform/policy/subjectmapping/subject_mapping_pb.ts +1 -2
- package/src/platform/policy/unsafe/unsafe_pb.ts +21 -6
- package/src/platform.ts +19 -5
- package/src/policy/api.ts +37 -6
- package/src/policy/granter.ts +82 -56
- package/src/seekable.ts +31 -0
- package/src/utils.ts +56 -2
- package/tdf3/src/assertions.ts +52 -1
- package/tdf3/src/client/builders.ts +15 -0
- package/tdf3/src/client/index.ts +279 -73
- package/tdf3/src/client/validation.ts +2 -2
- package/tdf3/src/tdf.ts +26 -2
- package/tdf3/src/utils/unwrap.ts +2 -1
package/src/opentdf.ts
CHANGED
|
@@ -50,162 +50,174 @@ export {
|
|
|
50
50
|
isPublicKeyAlgorithm,
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
/** A map of key identifiers to cryptographic keys. */
|
|
53
54
|
export type Keys = {
|
|
54
55
|
[keyID: string]: CryptoKey | CryptoKeyPair;
|
|
55
56
|
};
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
// that are shared between all container types.
|
|
58
|
+
/** Options for creating a new TDF object, shared between all container types. */
|
|
59
59
|
export type CreateOptions = {
|
|
60
|
-
|
|
60
|
+
/** If the policy service should be used to control creation options. */
|
|
61
61
|
autoconfigure?: boolean;
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
/** List of attributes that will be assigned to the object's policy. */
|
|
64
64
|
attributes?: string[];
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
/**
|
|
67
|
+
* If set and positive, this represents the maxiumum number of bytes to read from a stream to encrypt.
|
|
68
|
+
* This is helpful for enforcing size limits and preventing DoS attacks.
|
|
69
|
+
*/
|
|
68
70
|
byteLimit?: number;
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
/** The KAS to use for creation, if none is specified by the attribute service. */
|
|
71
73
|
defaultKASEndpoint?: string;
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
/** Private (or shared) keys for signing assertions and bindings. */
|
|
74
76
|
signers?: Keys;
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
/** Source of plaintext data. */
|
|
77
79
|
source: Source;
|
|
78
80
|
};
|
|
79
81
|
|
|
82
|
+
/** Options for creating a NanoTDF. */
|
|
80
83
|
export type CreateNanoTDFOptions = CreateOptions & {
|
|
84
|
+
/** The type of binding to use for the NanoTDF. */
|
|
81
85
|
bindingType?: 'ecdsa' | 'gmac';
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
// instead of the DEK.
|
|
87
|
+
/** When creating a new collection, use ECDSA binding with this key id from the signers, instead of the DEK. */
|
|
85
88
|
ecdsaBindingKeyID?: string;
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
/**
|
|
91
|
+
* When creating a new collection, use the key in the `signers` list with this id
|
|
92
|
+
* to generate a signature for each element. When absent, the nanotdf is unsigned.
|
|
93
|
+
*/
|
|
91
94
|
signingKeyID?: string;
|
|
92
95
|
};
|
|
93
96
|
|
|
97
|
+
/** Options for creating a NanoTDF collection. */
|
|
94
98
|
export type CreateNanoTDFCollectionOptions = CreateNanoTDFOptions & {
|
|
99
|
+
/** The platform URL. */
|
|
95
100
|
platformUrl: string;
|
|
96
|
-
|
|
101
|
+
/** The maximum number of key iterations to use for a single DEK. */
|
|
97
102
|
maxKeyIterations?: number;
|
|
98
103
|
};
|
|
99
104
|
|
|
100
|
-
|
|
105
|
+
/** Metadata for a TDF object. */
|
|
101
106
|
export type Metadata = object;
|
|
102
107
|
|
|
103
|
-
|
|
108
|
+
/** MIME type of the decrypted content. */
|
|
104
109
|
export type MimeType = `${string}/${string}`;
|
|
105
110
|
|
|
106
|
-
|
|
111
|
+
/** Template for a Key Access Object (KAO) to be filled in during encrypt. */
|
|
107
112
|
export type SplitStep = {
|
|
108
|
-
|
|
113
|
+
/** Which KAS to use to rewrap this segment of the key. */
|
|
109
114
|
kas: string;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
/**
|
|
116
|
+
* An identifier for a key segment.
|
|
117
|
+
* Leave empty to share the key.
|
|
118
|
+
*/
|
|
113
119
|
sid?: string;
|
|
114
120
|
};
|
|
115
121
|
|
|
116
|
-
|
|
122
|
+
/** Options specific to the ZTDF container format. */
|
|
117
123
|
export type CreateZTDFOptions = CreateOptions & {
|
|
118
|
-
|
|
124
|
+
/** Configuration for bound metadata. */
|
|
119
125
|
assertionConfigs?: AssertionConfig[];
|
|
120
126
|
|
|
121
|
-
|
|
127
|
+
/** Unbound metadata (deprecated). */
|
|
122
128
|
metadata?: Metadata;
|
|
123
129
|
|
|
124
|
-
|
|
130
|
+
/** MIME type of the decrypted content. Used for display. */
|
|
125
131
|
mimeType?: MimeType;
|
|
126
132
|
|
|
127
|
-
|
|
133
|
+
/** How to split or share the data encryption key across multiple KASes. */
|
|
128
134
|
splitPlan?: SplitStep[];
|
|
129
135
|
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
/**
|
|
137
|
+
* The segment size for the content; smaller is slower, but allows faster random access.
|
|
138
|
+
* The current default is 1 MiB (2^20 bytes).
|
|
139
|
+
*/
|
|
132
140
|
windowSize?: number;
|
|
133
141
|
|
|
134
|
-
|
|
142
|
+
/** Preferred algorithm to use for Key Access Objects. */
|
|
135
143
|
wrappingKeyAlgorithm?: KasPublicKeyAlgorithm;
|
|
136
144
|
|
|
137
|
-
|
|
145
|
+
/** TDF spec version to target. */
|
|
138
146
|
tdfSpecVersion?: '4.2.2' | '4.3.0';
|
|
139
147
|
};
|
|
140
148
|
|
|
141
|
-
|
|
149
|
+
/** Settings for decrypting any variety of TDF file. */
|
|
142
150
|
export type ReadOptions = {
|
|
143
|
-
|
|
151
|
+
/** The ciphertext source. */
|
|
144
152
|
source: Source;
|
|
145
|
-
|
|
153
|
+
/** The platform URL. */
|
|
146
154
|
platformUrl?: string;
|
|
147
|
-
|
|
155
|
+
/** List of KASes that may be contacted for a rewrap. */
|
|
148
156
|
allowedKASEndpoints?: string[];
|
|
149
|
-
|
|
157
|
+
/** Optionally disable checking the allowlist. */
|
|
150
158
|
ignoreAllowlist?: boolean;
|
|
151
|
-
|
|
159
|
+
/** Public (or shared) keys for verifying assertions. */
|
|
152
160
|
assertionVerificationKeys?: AssertionVerificationKeys;
|
|
153
|
-
|
|
161
|
+
/** Optionally disable assertion verification. */
|
|
154
162
|
noVerify?: boolean;
|
|
155
163
|
|
|
156
|
-
|
|
164
|
+
/** If set, prevents more than this number of concurrent requests to the KAS. */
|
|
157
165
|
concurrencyLimit?: number;
|
|
158
166
|
|
|
159
|
-
|
|
167
|
+
/** Type of key to use for wrapping responses. */
|
|
160
168
|
wrappingKeyAlgorithm?: KasPublicKeyAlgorithm;
|
|
161
169
|
};
|
|
162
170
|
|
|
163
|
-
|
|
171
|
+
/** Defaults and shared settings that are relevant to creating TDF objects. */
|
|
164
172
|
export type OpenTDFOptions = {
|
|
165
|
-
|
|
173
|
+
/** Policy service endpoint. */
|
|
166
174
|
policyEndpoint?: string;
|
|
167
175
|
|
|
168
|
-
|
|
176
|
+
/** Platform URL. */
|
|
169
177
|
platformUrl?: string;
|
|
170
178
|
|
|
171
|
-
|
|
179
|
+
/** Auth provider for connections to the policy service and KASes. */
|
|
172
180
|
authProvider: AuthProvider;
|
|
173
181
|
|
|
174
|
-
|
|
182
|
+
/** Default settings for 'encrypt' type requests. */
|
|
175
183
|
defaultCreateOptions?: Omit<CreateOptions, 'source'>;
|
|
176
184
|
|
|
177
|
-
|
|
185
|
+
/** Default settings for 'decrypt' type requests. */
|
|
178
186
|
defaultReadOptions?: Omit<ReadOptions, 'source'>;
|
|
179
187
|
|
|
180
|
-
|
|
188
|
+
/** If we want to *not* send a DPoP token. */
|
|
181
189
|
disableDPoP?: boolean;
|
|
182
190
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Optional keys for DPoP requests to a server.
|
|
193
|
+
* These often must be registered via a DPoP flow with the IdP
|
|
194
|
+
* which is out of the scope of this library.
|
|
195
|
+
*/
|
|
186
196
|
dpopKeys?: Promise<CryptoKeyPair>;
|
|
187
197
|
|
|
188
|
-
|
|
198
|
+
/** Configuration options for the collection header cache. */
|
|
189
199
|
rewrapCacheOptions?: RewrapCacheOptions;
|
|
190
200
|
};
|
|
191
201
|
|
|
202
|
+
/** A decorated readable stream. */
|
|
192
203
|
export type DecoratedStream = ReadableStream<Uint8Array> & {
|
|
193
|
-
|
|
204
|
+
/** If the source is a TDF3/ZTDF, and includes metadata, and it has been read. */
|
|
194
205
|
metadata?: Promise<unknown>;
|
|
206
|
+
/** The TDF manifest. */
|
|
195
207
|
manifest?: Promise<Manifest>;
|
|
196
|
-
|
|
208
|
+
/** If the source is a NanoTDF, this will be set. */
|
|
197
209
|
header?: Header;
|
|
198
210
|
};
|
|
199
211
|
|
|
200
|
-
|
|
212
|
+
/** Configuration options for the collection header cache. */
|
|
201
213
|
export type RewrapCacheOptions = {
|
|
202
|
-
|
|
214
|
+
/** If we should disable (bypass) the cache. */
|
|
203
215
|
bypass?: boolean;
|
|
204
216
|
|
|
205
|
-
|
|
217
|
+
/** Evict keys after this many milliseconds. */
|
|
206
218
|
maxAge?: number;
|
|
207
219
|
|
|
208
|
-
|
|
220
|
+
/** Check for expired keys once every this many milliseconds. */
|
|
209
221
|
pollInterval?: number;
|
|
210
222
|
};
|
|
211
223
|
|
|
@@ -215,10 +227,11 @@ const defaultRewrapCacheOptions: Required<RewrapCacheOptions> = {
|
|
|
215
227
|
pollInterval: 500,
|
|
216
228
|
};
|
|
217
229
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Cache for headers of nanotdf collections, to quickly open multiple entries of the same collection.
|
|
232
|
+
* It has a demon that removes all keys that have not been accessed in the last 5 minutes.
|
|
233
|
+
* To cancel the demon, and clear the cache, call `close()`.
|
|
234
|
+
* */
|
|
222
235
|
export class RewrapCache {
|
|
223
236
|
private cache?: Map<Uint8Array, { lastAccessTime: number; value: CryptoKey }>;
|
|
224
237
|
private closer?: ReturnType<typeof setInterval>;
|
|
@@ -254,6 +267,7 @@ export class RewrapCache {
|
|
|
254
267
|
return undefined;
|
|
255
268
|
}
|
|
256
269
|
|
|
270
|
+
/** Set a key in the cache. */
|
|
257
271
|
set(key: Uint8Array, value: CryptoKey) {
|
|
258
272
|
if (!this.cache) {
|
|
259
273
|
return;
|
|
@@ -261,6 +275,7 @@ export class RewrapCache {
|
|
|
261
275
|
this.cache.set(key, { lastAccessTime: Date.now(), value });
|
|
262
276
|
}
|
|
263
277
|
|
|
278
|
+
/** Close the cache and release any resources. */
|
|
264
279
|
close() {
|
|
265
280
|
if (this.closer !== undefined) {
|
|
266
281
|
clearInterval(this.closer);
|
|
@@ -294,19 +309,56 @@ export type TDFReader = {
|
|
|
294
309
|
attributes: () => Promise<string[]>;
|
|
295
310
|
};
|
|
296
311
|
|
|
297
|
-
|
|
312
|
+
/**
|
|
313
|
+
* The main OpenTDF class that provides methods for creating and reading TDF files.
|
|
314
|
+
* It supports both NanoTDF and ZTDF formats.
|
|
315
|
+
* It can be used to create new TDF files and read existing ones.
|
|
316
|
+
* This class is the entry point for using the OpenTDF SDK.
|
|
317
|
+
* It requires an authentication provider to be passed in the constructor.
|
|
318
|
+
* It also requires a platform URL to be set, which is used to fetch key access servers and policies.
|
|
319
|
+
* @example
|
|
320
|
+
* ```
|
|
321
|
+
* import { type Chunker, OpenTDF } from '@opentdf/sdk';
|
|
322
|
+
*
|
|
323
|
+
* const oidcCredentials: RefreshTokenCredentials = {
|
|
324
|
+
* clientId: keycloakClientId,
|
|
325
|
+
* exchange: 'refresh',
|
|
326
|
+
* refreshToken: refreshToken,
|
|
327
|
+
* oidcOrigin: keycloakUrl,
|
|
328
|
+
* };
|
|
329
|
+
* const authProvider = await AuthProviders.refreshAuthProvider(oidcCredentials);
|
|
330
|
+
*
|
|
331
|
+
* const client = new OpenTDF({
|
|
332
|
+
* authProvider,
|
|
333
|
+
* platformUrl: 'https://platform.example.com',
|
|
334
|
+
* });
|
|
335
|
+
*
|
|
336
|
+
* const cipherText = await client.createZTDF({
|
|
337
|
+
* source: { type: 'stream', location: source },
|
|
338
|
+
* autoconfigure: false,
|
|
339
|
+
* });
|
|
340
|
+
*
|
|
341
|
+
* const clearText = await client.read({ type: 'stream', location: cipherText });
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
298
344
|
export class OpenTDF {
|
|
299
|
-
|
|
345
|
+
/** The platform URL */
|
|
300
346
|
readonly platformUrl: string;
|
|
347
|
+
/** The policy service endpoint */
|
|
301
348
|
readonly policyEndpoint: string;
|
|
349
|
+
/** The auth provider for the OpenTDF instance. */
|
|
302
350
|
readonly authProvider: AuthProvider;
|
|
351
|
+
/** If DPoP is enabled for this instance. */
|
|
303
352
|
readonly dpopEnabled: boolean;
|
|
353
|
+
/** Default options for creating TDF objects. */
|
|
304
354
|
defaultCreateOptions: Omit<CreateOptions, 'source'>;
|
|
355
|
+
/** Default options for reading TDF objects. */
|
|
305
356
|
defaultReadOptions: Omit<ReadOptions, 'source'>;
|
|
357
|
+
/** The DPoP keys for this instance, if any. */
|
|
306
358
|
readonly dpopKeys: Promise<CryptoKeyPair>;
|
|
307
|
-
|
|
308
|
-
// Header cache for reading nanotdf collections
|
|
359
|
+
/** Cache for rewrapped keys */
|
|
309
360
|
private readonly rewrapCache: RewrapCache;
|
|
361
|
+
/** The TDF3 client for encrypting and decrypting ZTDF files. */
|
|
310
362
|
readonly tdf3Client: TDF3Client;
|
|
311
363
|
|
|
312
364
|
constructor({
|
|
@@ -336,6 +388,7 @@ export class OpenTDF {
|
|
|
336
388
|
authProvider,
|
|
337
389
|
dpopKeys,
|
|
338
390
|
kasEndpoint: this.platformUrl || 'https://disallow.all.invalid',
|
|
391
|
+
platformUrl,
|
|
339
392
|
policyEndpoint,
|
|
340
393
|
});
|
|
341
394
|
this.dpopKeys =
|
|
@@ -352,6 +405,7 @@ export class OpenTDF {
|
|
|
352
405
|
);
|
|
353
406
|
}
|
|
354
407
|
|
|
408
|
+
/** Creates a new NanoTDF stream. */
|
|
355
409
|
async createNanoTDF(opts: CreateNanoTDFOptions): Promise<DecoratedStream> {
|
|
356
410
|
opts = {
|
|
357
411
|
...this.defaultCreateOptions,
|
|
@@ -370,7 +424,6 @@ export class OpenTDF {
|
|
|
370
424
|
|
|
371
425
|
/**
|
|
372
426
|
* Creates a new collection object, which can be used to encrypt a series of data with the same policy.
|
|
373
|
-
* @returns
|
|
374
427
|
*/
|
|
375
428
|
async createNanoTDFCollection(
|
|
376
429
|
opts: CreateNanoTDFCollectionOptions
|
|
@@ -379,6 +432,7 @@ export class OpenTDF {
|
|
|
379
432
|
return new Collection(this.authProvider, opts);
|
|
380
433
|
}
|
|
381
434
|
|
|
435
|
+
/** Creates a new ZTDF stream. */
|
|
382
436
|
async createZTDF(opts: CreateZTDFOptions): Promise<DecoratedStream> {
|
|
383
437
|
opts = { ...this.defaultCreateOptions, ...opts };
|
|
384
438
|
const oldStream = await this.tdf3Client.encrypt({
|
|
@@ -403,26 +457,25 @@ export class OpenTDF {
|
|
|
403
457
|
return stream;
|
|
404
458
|
}
|
|
405
459
|
|
|
406
|
-
/**
|
|
407
|
-
* Opens a TDF file for inspection and decryption.
|
|
408
|
-
* @param opts the file to open, and any appropriate configuration options
|
|
409
|
-
* @returns
|
|
410
|
-
*/
|
|
460
|
+
/** Opens a TDF file for inspection and decryption. */
|
|
411
461
|
open(opts: ReadOptions): TDFReader {
|
|
412
462
|
opts = { ...this.defaultReadOptions, ...opts };
|
|
413
463
|
return new UnknownTypeReader(this, opts, this.rewrapCache);
|
|
414
464
|
}
|
|
415
465
|
|
|
466
|
+
/** Decrypts a TDF file. */
|
|
416
467
|
async read(opts: ReadOptions): Promise<DecoratedStream> {
|
|
417
468
|
const reader = this.open(opts);
|
|
418
469
|
return reader.decrypt();
|
|
419
470
|
}
|
|
420
471
|
|
|
472
|
+
/** Closes the OpenTDF instance and releases any resources. */
|
|
421
473
|
close() {
|
|
422
474
|
this.rewrapCache.close();
|
|
423
475
|
}
|
|
424
476
|
}
|
|
425
477
|
|
|
478
|
+
/** A TDF reader that can automatically detect the TDF type. */
|
|
426
479
|
class UnknownTypeReader {
|
|
427
480
|
delegate: Promise<TDFReader>;
|
|
428
481
|
state: 'init' | 'resolving' | 'loaded' | 'decrypting' | 'closing' | 'done' | 'error' = 'init';
|
|
@@ -434,6 +487,7 @@ class UnknownTypeReader {
|
|
|
434
487
|
this.delegate = this.resolveType();
|
|
435
488
|
}
|
|
436
489
|
|
|
490
|
+
/** Resolves the TDF type based on the file prefix. */
|
|
437
491
|
async resolveType(): Promise<TDFReader> {
|
|
438
492
|
if (this.state === 'done') {
|
|
439
493
|
throw new ConfigurationError('reader is closed');
|
|
@@ -455,21 +509,25 @@ class UnknownTypeReader {
|
|
|
455
509
|
throw new InvalidFileError(`unsupported format; prefix not recognized ${prefix}`);
|
|
456
510
|
}
|
|
457
511
|
|
|
512
|
+
/** Decrypts the TDF file */
|
|
458
513
|
async decrypt(): Promise<DecoratedStream> {
|
|
459
514
|
const actual = await this.delegate;
|
|
460
515
|
return actual.decrypt();
|
|
461
516
|
}
|
|
462
517
|
|
|
518
|
+
/** Returns the attributes of the TDF file */
|
|
463
519
|
async attributes(): Promise<string[]> {
|
|
464
520
|
const actual = await this.delegate;
|
|
465
521
|
return actual.attributes();
|
|
466
522
|
}
|
|
467
523
|
|
|
524
|
+
/** Returns the manifest of the TDF file */
|
|
468
525
|
async manifest(): Promise<Manifest> {
|
|
469
526
|
const actual = await this.delegate;
|
|
470
527
|
return actual.manifest();
|
|
471
528
|
}
|
|
472
529
|
|
|
530
|
+
/** Closes the TDF reader */
|
|
473
531
|
async close() {
|
|
474
532
|
if (this.state === 'done') {
|
|
475
533
|
return;
|
|
@@ -487,6 +545,7 @@ class UnknownTypeReader {
|
|
|
487
545
|
}
|
|
488
546
|
}
|
|
489
547
|
|
|
548
|
+
/** A TDF reader for NanoTDF files. */
|
|
490
549
|
class NanoTDFReader {
|
|
491
550
|
container: Promise<NanoTDF>;
|
|
492
551
|
constructor(
|
|
@@ -514,6 +573,7 @@ class NanoTDFReader {
|
|
|
514
573
|
});
|
|
515
574
|
}
|
|
516
575
|
|
|
576
|
+
/** Decrypts the NanoTDF file and returns a decorated stream. */
|
|
517
577
|
async decrypt(): Promise<DecoratedStream> {
|
|
518
578
|
const nanotdf = await this.container;
|
|
519
579
|
const cachedDEK = this.rewrapCache.get(nanotdf.header.ephemeralPublicKey);
|
|
@@ -556,10 +616,12 @@ class NanoTDFReader {
|
|
|
556
616
|
|
|
557
617
|
async close() {}
|
|
558
618
|
|
|
619
|
+
/** Returns blank manifest. NanoTDF has no manifest. */
|
|
559
620
|
async manifest(): Promise<Manifest> {
|
|
560
621
|
return {} as Manifest;
|
|
561
622
|
}
|
|
562
623
|
|
|
624
|
+
/** Returns the attributes of the NanoTDF file. */
|
|
563
625
|
async attributes(): Promise<string[]> {
|
|
564
626
|
const nanotdf = await this.container;
|
|
565
627
|
if (!nanotdf.header.policy?.content) {
|
|
@@ -574,6 +636,7 @@ class NanoTDFReader {
|
|
|
574
636
|
}
|
|
575
637
|
}
|
|
576
638
|
|
|
639
|
+
/** A reader for TDF files. */
|
|
577
640
|
class ZTDFReader {
|
|
578
641
|
overview: Promise<InspectedTDFOverview>;
|
|
579
642
|
constructor(
|
|
@@ -584,6 +647,10 @@ class ZTDFReader {
|
|
|
584
647
|
this.overview = loadTDFStream(source);
|
|
585
648
|
}
|
|
586
649
|
|
|
650
|
+
/**
|
|
651
|
+
* Decrypts the TDF file and returns a decorated stream.
|
|
652
|
+
* The stream will have a manifest and metadata attached if available.
|
|
653
|
+
*/
|
|
587
654
|
async decrypt(): Promise<DecoratedStream> {
|
|
588
655
|
const {
|
|
589
656
|
assertionVerificationKeys,
|
|
@@ -641,11 +708,13 @@ class ZTDFReader {
|
|
|
641
708
|
// TODO figure out how to close a chunker, if we want to.
|
|
642
709
|
}
|
|
643
710
|
|
|
711
|
+
/** Returns the manifest of the TDF file. */
|
|
644
712
|
async manifest(): Promise<Manifest> {
|
|
645
713
|
const overview = await this.overview;
|
|
646
714
|
return overview.manifest;
|
|
647
715
|
}
|
|
648
716
|
|
|
717
|
+
/** Returns the attributes of the TDF file. */
|
|
649
718
|
async attributes(): Promise<string[]> {
|
|
650
719
|
const manifest = await this.manifest();
|
|
651
720
|
const policyJSON = base64.decode(manifest.encryptionInformation.policy);
|
|
@@ -666,13 +735,18 @@ async function streamify(ab: Promise<ArrayBuffer>): Promise<ReadableStream<Uint8
|
|
|
666
735
|
return stream;
|
|
667
736
|
}
|
|
668
737
|
|
|
738
|
+
/** A writer for NanoTDF collections. */
|
|
669
739
|
export type NanoTDFCollectionWriter = {
|
|
740
|
+
/** The NanoTDF client used for encrypting data in this collection. */
|
|
670
741
|
encrypt: (source: Source) => Promise<ReadableStream<Uint8Array>>;
|
|
742
|
+
/** Closes the collection and releases any resources. */
|
|
671
743
|
close: () => Promise<void>;
|
|
672
744
|
};
|
|
673
745
|
|
|
674
746
|
class Collection {
|
|
747
|
+
/** The NanoTDF client used for encrypting data in this collection. */
|
|
675
748
|
client?: NanoTDFDatasetClient;
|
|
749
|
+
/** Options for encrypting data in this collection. */
|
|
676
750
|
encryptOptions?: NanoEncryptOptions;
|
|
677
751
|
|
|
678
752
|
constructor(authProvider: AuthProvider, opts: CreateNanoTDFCollectionOptions) {
|
|
@@ -703,8 +777,10 @@ class Collection {
|
|
|
703
777
|
maxKeyIterations: opts.maxKeyIterations,
|
|
704
778
|
platformUrl: opts.platformUrl,
|
|
705
779
|
});
|
|
780
|
+
this.client.dataAttributes = opts.attributes || [];
|
|
706
781
|
}
|
|
707
782
|
|
|
783
|
+
/** Encrypts a source into a NanoTDF stream. */
|
|
708
784
|
async encrypt(source: Source): Promise<DecoratedStream> {
|
|
709
785
|
if (!this.client) {
|
|
710
786
|
throw new ConfigurationError('Collection is closed');
|
|
@@ -722,6 +798,7 @@ class Collection {
|
|
|
722
798
|
return stream;
|
|
723
799
|
}
|
|
724
800
|
|
|
801
|
+
/** Releases client resources. */
|
|
725
802
|
async close() {
|
|
726
803
|
delete this.client;
|
|
727
804
|
}
|