@opentdf/sdk 0.4.0-beta.4 → 0.4.0-beta.41
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/access-fetch.js +2 -1
- package/dist/cjs/src/access/access-rpc.js +11 -5
- package/dist/cjs/src/access/constants.js +6 -0
- package/dist/cjs/src/access.js +39 -4
- 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/nanoclients.js +4 -4
- package/dist/cjs/src/nanotdf/Client.js +10 -6
- package/dist/cjs/src/opentdf.js +103 -13
- 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 +20 -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 +85 -3
- package/dist/cjs/tdf3/src/assertions.js +39 -2
- package/dist/cjs/tdf3/src/client/DecoratedReadableStream.js +8 -1
- package/dist/cjs/tdf3/src/client/builders.js +13 -1
- package/dist/cjs/tdf3/src/client/index.js +213 -54
- package/dist/cjs/tdf3/src/client/validation.js +3 -3
- package/dist/cjs/tdf3/src/tdf.js +42 -9
- package/dist/cjs/tdf3/src/utils/unwrap.js +2 -2
- package/dist/types/src/access/access-fetch.d.ts +1 -0
- package/dist/types/src/access/access-fetch.d.ts.map +1 -1
- package/dist/types/src/access/access-rpc.d.ts +2 -1
- package/dist/types/src/access/access-rpc.d.ts.map +1 -1
- package/dist/types/src/access/constants.d.ts +3 -0
- package/dist/types/src/access/constants.d.ts.map +1 -0
- package/dist/types/src/access.d.ts +30 -1
- 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/nanotdf/Client.d.ts +8 -1
- package/dist/types/src/nanotdf/Client.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +137 -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 +21 -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 +61 -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/DecoratedReadableStream.d.ts +6 -0
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/builders.d.ts +14 -0
- package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/index.d.ts +25 -4
- 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 +3 -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/access-fetch.js +2 -1
- package/dist/web/src/access/access-rpc.js +11 -5
- package/dist/web/src/access/constants.js +3 -0
- package/dist/web/src/access.js +37 -3
- 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/nanoclients.js +4 -4
- package/dist/web/src/nanotdf/Client.js +11 -7
- package/dist/web/src/opentdf.js +103 -13
- 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 +20 -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 +84 -3
- package/dist/web/tdf3/src/assertions.js +38 -2
- package/dist/web/tdf3/src/client/DecoratedReadableStream.js +8 -1
- package/dist/web/tdf3/src/client/builders.js +13 -1
- package/dist/web/tdf3/src/client/index.js +215 -57
- package/dist/web/tdf3/src/client/validation.js +3 -3
- package/dist/web/tdf3/src/tdf.js +42 -9
- package/dist/web/tdf3/src/utils/unwrap.js +2 -2
- package/package.json +7 -5
- package/src/access/access-fetch.ts +1 -0
- package/src/access/access-rpc.ts +13 -4
- package/src/access/constants.ts +2 -0
- package/src/access.ts +54 -2
- 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/nanoclients.ts +3 -3
- package/src/nanotdf/Client.ts +28 -6
- package/src/opentdf.ts +206 -73
- 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 +29 -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 +88 -2
- package/tdf3/src/assertions.ts +52 -1
- package/tdf3/src/client/DecoratedReadableStream.ts +9 -0
- package/tdf3/src/client/builders.ts +16 -0
- package/tdf3/src/client/index.ts +309 -73
- package/tdf3/src/client/validation.ts +2 -2
- package/tdf3/src/tdf.ts +53 -9
- package/tdf3/src/utils/unwrap.ts +2 -1
package/src/opentdf.ts
CHANGED
|
@@ -50,162 +50,182 @@ 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
|
-
|
|
58
|
+
/** The fully qualified obligations that the caller is required to fulfill. */
|
|
59
|
+
export type RequiredObligations = {
|
|
60
|
+
/** List of obligations values' fully qualified names. */
|
|
61
|
+
fqns: string[];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** Options for creating a new TDF object, shared between all container types. */
|
|
59
65
|
export type CreateOptions = {
|
|
60
|
-
|
|
66
|
+
/** If the policy service should be used to control creation options. */
|
|
61
67
|
autoconfigure?: boolean;
|
|
62
68
|
|
|
63
|
-
|
|
69
|
+
/** List of attributes that will be assigned to the object's policy. */
|
|
64
70
|
attributes?: string[];
|
|
65
71
|
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
/**
|
|
73
|
+
* If set and positive, this represents the maxiumum number of bytes to read from a stream to encrypt.
|
|
74
|
+
* This is helpful for enforcing size limits and preventing DoS attacks.
|
|
75
|
+
*/
|
|
68
76
|
byteLimit?: number;
|
|
69
77
|
|
|
70
|
-
|
|
78
|
+
/** The KAS to use for creation, if none is specified by the attribute service. */
|
|
71
79
|
defaultKASEndpoint?: string;
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
/** Private (or shared) keys for signing assertions and bindings. */
|
|
74
82
|
signers?: Keys;
|
|
75
83
|
|
|
76
|
-
|
|
84
|
+
/** Source of plaintext data. */
|
|
77
85
|
source: Source;
|
|
78
86
|
};
|
|
79
87
|
|
|
88
|
+
/** Options for creating a NanoTDF. */
|
|
80
89
|
export type CreateNanoTDFOptions = CreateOptions & {
|
|
90
|
+
/** The type of binding to use for the NanoTDF. */
|
|
81
91
|
bindingType?: 'ecdsa' | 'gmac';
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
// instead of the DEK.
|
|
93
|
+
/** When creating a new collection, use ECDSA binding with this key id from the signers, instead of the DEK. */
|
|
85
94
|
ecdsaBindingKeyID?: string;
|
|
86
95
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
*/
|
|
91
100
|
signingKeyID?: string;
|
|
92
101
|
};
|
|
93
102
|
|
|
103
|
+
/** Options for creating a NanoTDF collection. */
|
|
94
104
|
export type CreateNanoTDFCollectionOptions = CreateNanoTDFOptions & {
|
|
105
|
+
/** The platform URL. */
|
|
95
106
|
platformUrl: string;
|
|
96
|
-
|
|
107
|
+
/** The maximum number of key iterations to use for a single DEK. */
|
|
97
108
|
maxKeyIterations?: number;
|
|
98
109
|
};
|
|
99
110
|
|
|
100
|
-
|
|
111
|
+
/** Metadata for a TDF object. */
|
|
101
112
|
export type Metadata = object;
|
|
102
113
|
|
|
103
|
-
|
|
114
|
+
/** MIME type of the decrypted content. */
|
|
104
115
|
export type MimeType = `${string}/${string}`;
|
|
105
116
|
|
|
106
|
-
|
|
117
|
+
/** Template for a Key Access Object (KAO) to be filled in during encrypt. */
|
|
107
118
|
export type SplitStep = {
|
|
108
|
-
|
|
119
|
+
/** Which KAS to use to rewrap this segment of the key. */
|
|
109
120
|
kas: string;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
121
|
+
/**
|
|
122
|
+
* An identifier for a key segment.
|
|
123
|
+
* Leave empty to share the key.
|
|
124
|
+
*/
|
|
113
125
|
sid?: string;
|
|
114
126
|
};
|
|
115
127
|
|
|
116
|
-
|
|
128
|
+
/** Options specific to the ZTDF container format. */
|
|
117
129
|
export type CreateZTDFOptions = CreateOptions & {
|
|
118
|
-
|
|
130
|
+
/** Configuration for bound metadata. */
|
|
119
131
|
assertionConfigs?: AssertionConfig[];
|
|
120
132
|
|
|
121
|
-
|
|
133
|
+
/** Unbound metadata (deprecated). */
|
|
122
134
|
metadata?: Metadata;
|
|
123
135
|
|
|
124
|
-
|
|
136
|
+
/** MIME type of the decrypted content. Used for display. */
|
|
125
137
|
mimeType?: MimeType;
|
|
126
138
|
|
|
127
|
-
|
|
139
|
+
/** How to split or share the data encryption key across multiple KASes. */
|
|
128
140
|
splitPlan?: SplitStep[];
|
|
129
141
|
|
|
130
|
-
|
|
131
|
-
|
|
142
|
+
/**
|
|
143
|
+
* The segment size for the content; smaller is slower, but allows faster random access.
|
|
144
|
+
* The current default is 1 MiB (2^20 bytes).
|
|
145
|
+
*/
|
|
132
146
|
windowSize?: number;
|
|
133
147
|
|
|
134
|
-
|
|
148
|
+
/** Preferred algorithm to use for Key Access Objects. */
|
|
135
149
|
wrappingKeyAlgorithm?: KasPublicKeyAlgorithm;
|
|
136
150
|
|
|
137
|
-
|
|
151
|
+
/** TDF spec version to target. */
|
|
138
152
|
tdfSpecVersion?: '4.2.2' | '4.3.0';
|
|
139
153
|
};
|
|
140
154
|
|
|
141
|
-
|
|
155
|
+
/** Settings for decrypting any variety of TDF file. */
|
|
142
156
|
export type ReadOptions = {
|
|
143
|
-
|
|
157
|
+
/** The ciphertext source. */
|
|
144
158
|
source: Source;
|
|
145
|
-
|
|
159
|
+
/** The platform URL. */
|
|
146
160
|
platformUrl?: string;
|
|
147
|
-
|
|
161
|
+
/** List of KASes that may be contacted for a rewrap. */
|
|
148
162
|
allowedKASEndpoints?: string[];
|
|
149
|
-
|
|
163
|
+
/** Optionally disable checking the allowlist. */
|
|
150
164
|
ignoreAllowlist?: boolean;
|
|
151
|
-
|
|
165
|
+
/** Optionally override client fulfillableObligationFQNs. */
|
|
166
|
+
fulfillableObligationFQNs?: string[];
|
|
167
|
+
/** Public (or shared) keys for verifying assertions. */
|
|
152
168
|
assertionVerificationKeys?: AssertionVerificationKeys;
|
|
153
|
-
|
|
169
|
+
/** Optionally disable assertion verification. */
|
|
154
170
|
noVerify?: boolean;
|
|
155
171
|
|
|
156
|
-
|
|
172
|
+
/** If set, prevents more than this number of concurrent requests to the KAS. */
|
|
157
173
|
concurrencyLimit?: number;
|
|
158
174
|
|
|
159
|
-
|
|
175
|
+
/** Type of key to use for wrapping responses. */
|
|
160
176
|
wrappingKeyAlgorithm?: KasPublicKeyAlgorithm;
|
|
161
177
|
};
|
|
162
178
|
|
|
163
|
-
|
|
179
|
+
/** Defaults and shared settings that are relevant to creating TDF objects. */
|
|
164
180
|
export type OpenTDFOptions = {
|
|
165
|
-
|
|
181
|
+
/** Policy service endpoint. */
|
|
166
182
|
policyEndpoint?: string;
|
|
167
183
|
|
|
168
|
-
|
|
184
|
+
/** Platform URL. */
|
|
169
185
|
platformUrl?: string;
|
|
170
186
|
|
|
171
|
-
|
|
187
|
+
/** Auth provider for connections to the policy service and KASes. */
|
|
172
188
|
authProvider: AuthProvider;
|
|
173
189
|
|
|
174
|
-
|
|
190
|
+
/** Default settings for 'encrypt' type requests. */
|
|
175
191
|
defaultCreateOptions?: Omit<CreateOptions, 'source'>;
|
|
176
192
|
|
|
177
|
-
|
|
193
|
+
/** Default settings for 'decrypt' type requests. */
|
|
178
194
|
defaultReadOptions?: Omit<ReadOptions, 'source'>;
|
|
179
195
|
|
|
180
|
-
|
|
196
|
+
/** If we want to *not* send a DPoP token. */
|
|
181
197
|
disableDPoP?: boolean;
|
|
182
198
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Optional keys for DPoP requests to a server.
|
|
201
|
+
* These often must be registered via a DPoP flow with the IdP
|
|
202
|
+
* which is out of the scope of this library.
|
|
203
|
+
*/
|
|
186
204
|
dpopKeys?: Promise<CryptoKeyPair>;
|
|
187
205
|
|
|
188
|
-
|
|
206
|
+
/** Configuration options for the collection header cache. */
|
|
189
207
|
rewrapCacheOptions?: RewrapCacheOptions;
|
|
190
208
|
};
|
|
191
209
|
|
|
210
|
+
/** A decorated readable stream. */
|
|
192
211
|
export type DecoratedStream = ReadableStream<Uint8Array> & {
|
|
193
|
-
|
|
212
|
+
/** If the source is a TDF3/ZTDF, and includes metadata, and it has been read. */
|
|
194
213
|
metadata?: Promise<unknown>;
|
|
214
|
+
/** The TDF manifest. */
|
|
195
215
|
manifest?: Promise<Manifest>;
|
|
196
|
-
|
|
216
|
+
/** If the source is a NanoTDF, this will be set. */
|
|
197
217
|
header?: Header;
|
|
198
218
|
};
|
|
199
219
|
|
|
200
|
-
|
|
220
|
+
/** Configuration options for the collection header cache. */
|
|
201
221
|
export type RewrapCacheOptions = {
|
|
202
|
-
|
|
222
|
+
/** If we should disable (bypass) the cache. */
|
|
203
223
|
bypass?: boolean;
|
|
204
224
|
|
|
205
|
-
|
|
225
|
+
/** Evict keys after this many milliseconds. */
|
|
206
226
|
maxAge?: number;
|
|
207
227
|
|
|
208
|
-
|
|
228
|
+
/** Check for expired keys once every this many milliseconds. */
|
|
209
229
|
pollInterval?: number;
|
|
210
230
|
};
|
|
211
231
|
|
|
@@ -215,10 +235,11 @@ const defaultRewrapCacheOptions: Required<RewrapCacheOptions> = {
|
|
|
215
235
|
pollInterval: 500,
|
|
216
236
|
};
|
|
217
237
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
* */
|
|
222
243
|
export class RewrapCache {
|
|
223
244
|
private cache?: Map<Uint8Array, { lastAccessTime: number; value: CryptoKey }>;
|
|
224
245
|
private closer?: ReturnType<typeof setInterval>;
|
|
@@ -254,6 +275,7 @@ export class RewrapCache {
|
|
|
254
275
|
return undefined;
|
|
255
276
|
}
|
|
256
277
|
|
|
278
|
+
/** Set a key in the cache. */
|
|
257
279
|
set(key: Uint8Array, value: CryptoKey) {
|
|
258
280
|
if (!this.cache) {
|
|
259
281
|
return;
|
|
@@ -261,6 +283,7 @@ export class RewrapCache {
|
|
|
261
283
|
this.cache.set(key, { lastAccessTime: Date.now(), value });
|
|
262
284
|
}
|
|
263
285
|
|
|
286
|
+
/** Close the cache and release any resources. */
|
|
264
287
|
close() {
|
|
265
288
|
if (this.closer !== undefined) {
|
|
266
289
|
clearInterval(this.closer);
|
|
@@ -292,21 +315,63 @@ export type TDFReader = {
|
|
|
292
315
|
* @returns Any data attributes found in the policy. Currently only works for plain text, embedded policies (not remote or encrypted policies)
|
|
293
316
|
*/
|
|
294
317
|
attributes: () => Promise<string[]>;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @returns Any obligation value FQNs that are required to be fulfilled on the TDF, populated during the decrypt flow.
|
|
321
|
+
*/
|
|
322
|
+
obligations: () => Promise<RequiredObligations>;
|
|
295
323
|
};
|
|
296
324
|
|
|
297
|
-
|
|
325
|
+
/**
|
|
326
|
+
* The main OpenTDF class that provides methods for creating and reading TDF files.
|
|
327
|
+
* It supports both NanoTDF and ZTDF formats.
|
|
328
|
+
* It can be used to create new TDF files and read existing ones.
|
|
329
|
+
* This class is the entry point for using the OpenTDF SDK.
|
|
330
|
+
* It requires an authentication provider to be passed in the constructor.
|
|
331
|
+
* It also requires a platform URL to be set, which is used to fetch key access servers and policies.
|
|
332
|
+
* @example
|
|
333
|
+
* ```
|
|
334
|
+
* import { type Chunker, OpenTDF } from '@opentdf/sdk';
|
|
335
|
+
*
|
|
336
|
+
* const oidcCredentials: RefreshTokenCredentials = {
|
|
337
|
+
* clientId: keycloakClientId,
|
|
338
|
+
* exchange: 'refresh',
|
|
339
|
+
* refreshToken: refreshToken,
|
|
340
|
+
* oidcOrigin: keycloakUrl,
|
|
341
|
+
* };
|
|
342
|
+
* const authProvider = await AuthProviders.refreshAuthProvider(oidcCredentials);
|
|
343
|
+
*
|
|
344
|
+
* const client = new OpenTDF({
|
|
345
|
+
* authProvider,
|
|
346
|
+
* platformUrl: 'https://platform.example.com',
|
|
347
|
+
* });
|
|
348
|
+
*
|
|
349
|
+
* const cipherText = await client.createZTDF({
|
|
350
|
+
* source: { type: 'stream', location: source },
|
|
351
|
+
* autoconfigure: false,
|
|
352
|
+
* });
|
|
353
|
+
*
|
|
354
|
+
* const clearText = await client.read({ type: 'stream', location: cipherText });
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
298
357
|
export class OpenTDF {
|
|
299
|
-
|
|
358
|
+
/** The platform URL */
|
|
300
359
|
readonly platformUrl: string;
|
|
360
|
+
/** The policy service endpoint */
|
|
301
361
|
readonly policyEndpoint: string;
|
|
362
|
+
/** The auth provider for the OpenTDF instance. */
|
|
302
363
|
readonly authProvider: AuthProvider;
|
|
364
|
+
/** If DPoP is enabled for this instance. */
|
|
303
365
|
readonly dpopEnabled: boolean;
|
|
366
|
+
/** Default options for creating TDF objects. */
|
|
304
367
|
defaultCreateOptions: Omit<CreateOptions, 'source'>;
|
|
368
|
+
/** Default options for reading TDF objects. */
|
|
305
369
|
defaultReadOptions: Omit<ReadOptions, 'source'>;
|
|
370
|
+
/** The DPoP keys for this instance, if any. */
|
|
306
371
|
readonly dpopKeys: Promise<CryptoKeyPair>;
|
|
307
|
-
|
|
308
|
-
// Header cache for reading nanotdf collections
|
|
372
|
+
/** Cache for rewrapped keys */
|
|
309
373
|
private readonly rewrapCache: RewrapCache;
|
|
374
|
+
/** The TDF3 client for encrypting and decrypting ZTDF files. */
|
|
310
375
|
readonly tdf3Client: TDF3Client;
|
|
311
376
|
|
|
312
377
|
constructor({
|
|
@@ -336,6 +401,7 @@ export class OpenTDF {
|
|
|
336
401
|
authProvider,
|
|
337
402
|
dpopKeys,
|
|
338
403
|
kasEndpoint: this.platformUrl || 'https://disallow.all.invalid',
|
|
404
|
+
platformUrl,
|
|
339
405
|
policyEndpoint,
|
|
340
406
|
});
|
|
341
407
|
this.dpopKeys =
|
|
@@ -352,6 +418,7 @@ export class OpenTDF {
|
|
|
352
418
|
);
|
|
353
419
|
}
|
|
354
420
|
|
|
421
|
+
/** Creates a new NanoTDF stream. */
|
|
355
422
|
async createNanoTDF(opts: CreateNanoTDFOptions): Promise<DecoratedStream> {
|
|
356
423
|
opts = {
|
|
357
424
|
...this.defaultCreateOptions,
|
|
@@ -370,7 +437,6 @@ export class OpenTDF {
|
|
|
370
437
|
|
|
371
438
|
/**
|
|
372
439
|
* Creates a new collection object, which can be used to encrypt a series of data with the same policy.
|
|
373
|
-
* @returns
|
|
374
440
|
*/
|
|
375
441
|
async createNanoTDFCollection(
|
|
376
442
|
opts: CreateNanoTDFCollectionOptions
|
|
@@ -379,6 +445,7 @@ export class OpenTDF {
|
|
|
379
445
|
return new Collection(this.authProvider, opts);
|
|
380
446
|
}
|
|
381
447
|
|
|
448
|
+
/** Creates a new ZTDF stream. */
|
|
382
449
|
async createZTDF(opts: CreateZTDFOptions): Promise<DecoratedStream> {
|
|
383
450
|
opts = { ...this.defaultCreateOptions, ...opts };
|
|
384
451
|
const oldStream = await this.tdf3Client.encrypt({
|
|
@@ -403,26 +470,25 @@ export class OpenTDF {
|
|
|
403
470
|
return stream;
|
|
404
471
|
}
|
|
405
472
|
|
|
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
|
-
*/
|
|
473
|
+
/** Opens a TDF file for inspection and decryption. */
|
|
411
474
|
open(opts: ReadOptions): TDFReader {
|
|
412
475
|
opts = { ...this.defaultReadOptions, ...opts };
|
|
413
476
|
return new UnknownTypeReader(this, opts, this.rewrapCache);
|
|
414
477
|
}
|
|
415
478
|
|
|
479
|
+
/** Decrypts a TDF file. */
|
|
416
480
|
async read(opts: ReadOptions): Promise<DecoratedStream> {
|
|
417
481
|
const reader = this.open(opts);
|
|
418
482
|
return reader.decrypt();
|
|
419
483
|
}
|
|
420
484
|
|
|
485
|
+
/** Closes the OpenTDF instance and releases any resources. */
|
|
421
486
|
close() {
|
|
422
487
|
this.rewrapCache.close();
|
|
423
488
|
}
|
|
424
489
|
}
|
|
425
490
|
|
|
491
|
+
/** A TDF reader that can automatically detect the TDF type. */
|
|
426
492
|
class UnknownTypeReader {
|
|
427
493
|
delegate: Promise<TDFReader>;
|
|
428
494
|
state: 'init' | 'resolving' | 'loaded' | 'decrypting' | 'closing' | 'done' | 'error' = 'init';
|
|
@@ -434,6 +500,7 @@ class UnknownTypeReader {
|
|
|
434
500
|
this.delegate = this.resolveType();
|
|
435
501
|
}
|
|
436
502
|
|
|
503
|
+
/** Resolves the TDF type based on the file prefix. */
|
|
437
504
|
async resolveType(): Promise<TDFReader> {
|
|
438
505
|
if (this.state === 'done') {
|
|
439
506
|
throw new ConfigurationError('reader is closed');
|
|
@@ -455,21 +522,25 @@ class UnknownTypeReader {
|
|
|
455
522
|
throw new InvalidFileError(`unsupported format; prefix not recognized ${prefix}`);
|
|
456
523
|
}
|
|
457
524
|
|
|
525
|
+
/** Decrypts the TDF file */
|
|
458
526
|
async decrypt(): Promise<DecoratedStream> {
|
|
459
527
|
const actual = await this.delegate;
|
|
460
528
|
return actual.decrypt();
|
|
461
529
|
}
|
|
462
530
|
|
|
531
|
+
/** Returns the attributes of the TDF file */
|
|
463
532
|
async attributes(): Promise<string[]> {
|
|
464
533
|
const actual = await this.delegate;
|
|
465
534
|
return actual.attributes();
|
|
466
535
|
}
|
|
467
536
|
|
|
537
|
+
/** Returns the manifest of the TDF file */
|
|
468
538
|
async manifest(): Promise<Manifest> {
|
|
469
539
|
const actual = await this.delegate;
|
|
470
540
|
return actual.manifest();
|
|
471
541
|
}
|
|
472
542
|
|
|
543
|
+
/** Closes the TDF reader */
|
|
473
544
|
async close() {
|
|
474
545
|
if (this.state === 'done') {
|
|
475
546
|
return;
|
|
@@ -485,10 +556,18 @@ class UnknownTypeReader {
|
|
|
485
556
|
this.state = 'done';
|
|
486
557
|
});
|
|
487
558
|
}
|
|
559
|
+
|
|
560
|
+
async obligations() {
|
|
561
|
+
const actual = await this.delegate;
|
|
562
|
+
return actual.obligations();
|
|
563
|
+
}
|
|
488
564
|
}
|
|
489
565
|
|
|
566
|
+
/** A TDF reader for NanoTDF files. */
|
|
490
567
|
class NanoTDFReader {
|
|
491
568
|
container: Promise<NanoTDF>;
|
|
569
|
+
// Required obligation FQNs that must be fulfilled, provided via the decrypt flow.
|
|
570
|
+
private requiredObligations?: RequiredObligations;
|
|
492
571
|
constructor(
|
|
493
572
|
readonly outer: OpenTDF,
|
|
494
573
|
readonly opts: ReadOptions,
|
|
@@ -514,6 +593,10 @@ class NanoTDFReader {
|
|
|
514
593
|
});
|
|
515
594
|
}
|
|
516
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
|
+
*/
|
|
517
600
|
async decrypt(): Promise<DecoratedStream> {
|
|
518
601
|
const nanotdf = await this.container;
|
|
519
602
|
const cachedDEK = this.rewrapCache.get(nanotdf.header.ephemeralPublicKey);
|
|
@@ -527,6 +610,7 @@ class NanoTDFReader {
|
|
|
527
610
|
this.opts.allowedKASEndpoints?.[0] || platformUrl || 'https://disallow.all.invalid';
|
|
528
611
|
const nc = new Client({
|
|
529
612
|
allowedKases: this.opts.allowedKASEndpoints,
|
|
613
|
+
fulfillableObligationFQNs: this.opts.fulfillableObligationFQNs,
|
|
530
614
|
authProvider: this.outer.authProvider,
|
|
531
615
|
ignoreAllowList: this.opts.ignoreAllowlist,
|
|
532
616
|
dpopEnabled: this.outer.dpopEnabled,
|
|
@@ -537,7 +621,7 @@ class NanoTDFReader {
|
|
|
537
621
|
// TODO: The version number should be fetched from the API
|
|
538
622
|
const version = '0.0.1';
|
|
539
623
|
// Rewrap key on every request
|
|
540
|
-
const dek = await nc.rewrapKey(
|
|
624
|
+
const { unwrappedKey: dek, requiredObligations } = await nc.rewrapKey(
|
|
541
625
|
nanotdf.header.toBuffer(),
|
|
542
626
|
nanotdf.header.getKasRewrapUrl(),
|
|
543
627
|
nanotdf.header.magicNumberVersion,
|
|
@@ -547,6 +631,7 @@ class NanoTDFReader {
|
|
|
547
631
|
// These should have thrown already.
|
|
548
632
|
throw new Error('internal: key rewrap failure');
|
|
549
633
|
}
|
|
634
|
+
this.requiredObligations = { fqns: requiredObligations };
|
|
550
635
|
this.rewrapCache.set(nanotdf.header.ephemeralPublicKey, dek);
|
|
551
636
|
const r: DecoratedStream = await streamify(decryptNanoTDF(dek, nanotdf));
|
|
552
637
|
// TODO figure out how to attach policy and metadata to the stream
|
|
@@ -556,10 +641,12 @@ class NanoTDFReader {
|
|
|
556
641
|
|
|
557
642
|
async close() {}
|
|
558
643
|
|
|
644
|
+
/** Returns blank manifest. NanoTDF has no manifest. */
|
|
559
645
|
async manifest(): Promise<Manifest> {
|
|
560
646
|
return {} as Manifest;
|
|
561
647
|
}
|
|
562
648
|
|
|
649
|
+
/** Returns the attributes of the NanoTDF file. */
|
|
563
650
|
async attributes(): Promise<string[]> {
|
|
564
651
|
const nanotdf = await this.container;
|
|
565
652
|
if (!nanotdf.header.policy?.content) {
|
|
@@ -572,10 +659,25 @@ class NanoTDFReader {
|
|
|
572
659
|
const policy = JSON.parse(policyString) as Policy;
|
|
573
660
|
return policy?.body?.dataAttributes.map((a) => a.attribute) || [];
|
|
574
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
|
+
}
|
|
575
674
|
}
|
|
576
675
|
|
|
676
|
+
/** A reader for TDF files. */
|
|
577
677
|
class ZTDFReader {
|
|
578
678
|
overview: Promise<InspectedTDFOverview>;
|
|
679
|
+
// Required obligation FQNs that must be fulfilled, provided via the decrypt flow.
|
|
680
|
+
private requiredObligations?: RequiredObligations;
|
|
579
681
|
constructor(
|
|
580
682
|
readonly client: TDF3Client,
|
|
581
683
|
readonly opts: ReadOptions,
|
|
@@ -584,6 +686,11 @@ class ZTDFReader {
|
|
|
584
686
|
this.overview = loadTDFStream(source);
|
|
585
687
|
}
|
|
586
688
|
|
|
689
|
+
/**
|
|
690
|
+
* Decrypts the TDF file and returns a decorated stream.
|
|
691
|
+
* The stream will have a manifest and metadata attached if available.
|
|
692
|
+
* Sets required obligations on the reader when retrieved from KAS rewrap response.
|
|
693
|
+
*/
|
|
587
694
|
async decrypt(): Promise<DecoratedStream> {
|
|
588
695
|
const {
|
|
589
696
|
assertionVerificationKeys,
|
|
@@ -628,9 +735,13 @@ class ZTDFReader {
|
|
|
628
735
|
assertionVerificationKeys,
|
|
629
736
|
noVerifyAssertions,
|
|
630
737
|
wrappingKeyAlgorithm,
|
|
738
|
+
fulfillableObligations: this.opts.fulfillableObligationFQNs || [],
|
|
631
739
|
},
|
|
632
740
|
overview
|
|
633
741
|
);
|
|
742
|
+
this.requiredObligations = {
|
|
743
|
+
fqns: oldStream.obligations(),
|
|
744
|
+
};
|
|
634
745
|
const stream: DecoratedStream = oldStream.stream;
|
|
635
746
|
stream.manifest = Promise.resolve(overview.manifest);
|
|
636
747
|
stream.metadata = Promise.resolve(oldStream.metadata);
|
|
@@ -641,17 +752,31 @@ class ZTDFReader {
|
|
|
641
752
|
// TODO figure out how to close a chunker, if we want to.
|
|
642
753
|
}
|
|
643
754
|
|
|
755
|
+
/** Returns the manifest of the TDF file. */
|
|
644
756
|
async manifest(): Promise<Manifest> {
|
|
645
757
|
const overview = await this.overview;
|
|
646
758
|
return overview.manifest;
|
|
647
759
|
}
|
|
648
760
|
|
|
761
|
+
/** Returns the attributes of the TDF file. */
|
|
649
762
|
async attributes(): Promise<string[]> {
|
|
650
763
|
const manifest = await this.manifest();
|
|
651
764
|
const policyJSON = base64.decode(manifest.encryptionInformation.policy);
|
|
652
765
|
const policy = JSON.parse(policyJSON) as Policy;
|
|
653
766
|
return policy?.body?.dataAttributes.map((a) => a.attribute) || [];
|
|
654
767
|
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Returns obligations populated from the decrypt flow.
|
|
771
|
+
* If a decrypt has not occurred, attempts one to retrieve obligations.
|
|
772
|
+
*/
|
|
773
|
+
async obligations(): Promise<RequiredObligations> {
|
|
774
|
+
if (this.requiredObligations) {
|
|
775
|
+
return this.requiredObligations;
|
|
776
|
+
}
|
|
777
|
+
await this.decrypt();
|
|
778
|
+
return this.requiredObligations ?? { fqns: [] };
|
|
779
|
+
}
|
|
655
780
|
}
|
|
656
781
|
|
|
657
782
|
async function streamify(ab: Promise<ArrayBuffer>): Promise<ReadableStream<Uint8Array>> {
|
|
@@ -666,13 +791,18 @@ async function streamify(ab: Promise<ArrayBuffer>): Promise<ReadableStream<Uint8
|
|
|
666
791
|
return stream;
|
|
667
792
|
}
|
|
668
793
|
|
|
794
|
+
/** A writer for NanoTDF collections. */
|
|
669
795
|
export type NanoTDFCollectionWriter = {
|
|
796
|
+
/** The NanoTDF client used for encrypting data in this collection. */
|
|
670
797
|
encrypt: (source: Source) => Promise<ReadableStream<Uint8Array>>;
|
|
798
|
+
/** Closes the collection and releases any resources. */
|
|
671
799
|
close: () => Promise<void>;
|
|
672
800
|
};
|
|
673
801
|
|
|
674
802
|
class Collection {
|
|
803
|
+
/** The NanoTDF client used for encrypting data in this collection. */
|
|
675
804
|
client?: NanoTDFDatasetClient;
|
|
805
|
+
/** Options for encrypting data in this collection. */
|
|
676
806
|
encryptOptions?: NanoEncryptOptions;
|
|
677
807
|
|
|
678
808
|
constructor(authProvider: AuthProvider, opts: CreateNanoTDFCollectionOptions) {
|
|
@@ -703,8 +833,10 @@ class Collection {
|
|
|
703
833
|
maxKeyIterations: opts.maxKeyIterations,
|
|
704
834
|
platformUrl: opts.platformUrl,
|
|
705
835
|
});
|
|
836
|
+
this.client.dataAttributes = opts.attributes || [];
|
|
706
837
|
}
|
|
707
838
|
|
|
839
|
+
/** Encrypts a source into a NanoTDF stream. */
|
|
708
840
|
async encrypt(source: Source): Promise<DecoratedStream> {
|
|
709
841
|
if (!this.client) {
|
|
710
842
|
throw new ConfigurationError('Collection is closed');
|
|
@@ -722,6 +854,7 @@ class Collection {
|
|
|
722
854
|
return stream;
|
|
723
855
|
}
|
|
724
856
|
|
|
857
|
+
/** Releases client resources. */
|
|
725
858
|
async close() {
|
|
726
859
|
delete this.client;
|
|
727
860
|
}
|