@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.
Files changed (189) hide show
  1. package/dist/cjs/src/access.js +16 -1
  2. package/dist/cjs/src/auth/oidc-clientcredentials-provider.js +4 -2
  3. package/dist/cjs/src/auth/oidc-externaljwt-provider.js +5 -3
  4. package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +19 -3
  5. package/dist/cjs/src/auth/oidc.js +9 -8
  6. package/dist/cjs/src/auth/providers.js +7 -1
  7. package/dist/cjs/src/index.js +4 -2
  8. package/dist/cjs/src/opentdf.js +66 -12
  9. package/dist/cjs/src/platform/authorization/v2/authorization_pb.js +112 -0
  10. package/dist/cjs/src/platform/buf/validate/validate_pb.js +114 -170
  11. package/dist/cjs/src/platform/common/common_pb.js +16 -5
  12. package/dist/cjs/src/platform/entity/entity_pb.js +51 -0
  13. package/dist/cjs/src/platform/entityresolution/entity_resolution_pb.js +1 -1
  14. package/dist/cjs/src/platform/entityresolution/v2/entity_resolution_pb.js +49 -0
  15. package/dist/cjs/src/platform/google/api/annotations_pb.js +1 -1
  16. package/dist/cjs/src/platform/google/api/http_pb.js +3 -3
  17. package/dist/cjs/src/platform/kas/kas_pb.js +2 -2
  18. package/dist/cjs/src/platform/policy/attributes/attributes_pb.js +12 -2
  19. package/dist/cjs/src/platform/policy/kasregistry/key_access_server_registry_pb.js +57 -4
  20. package/dist/cjs/src/platform/policy/keymanagement/key_management_pb.js +2 -2
  21. package/dist/cjs/src/platform/policy/namespaces/namespaces_pb.js +31 -4
  22. package/dist/cjs/src/platform/policy/objects_pb.js +116 -42
  23. package/dist/cjs/src/platform/policy/obligations/obligations_pb.js +159 -0
  24. package/dist/cjs/src/platform/policy/registeredresources/registered_resources_pb.js +20 -15
  25. package/dist/cjs/src/platform/policy/resourcemapping/resource_mapping_pb.js +2 -3
  26. package/dist/cjs/src/platform/policy/selectors_pb.js +1 -1
  27. package/dist/cjs/src/platform/policy/subjectmapping/subject_mapping_pb.js +2 -3
  28. package/dist/cjs/src/platform/policy/unsafe/unsafe_pb.js +2 -4
  29. package/dist/cjs/src/platform.js +16 -3
  30. package/dist/cjs/src/policy/api.js +27 -7
  31. package/dist/cjs/src/policy/granter.js +75 -48
  32. package/dist/cjs/src/seekable.js +32 -1
  33. package/dist/cjs/src/utils.js +57 -3
  34. package/dist/cjs/tdf3/src/assertions.js +39 -2
  35. package/dist/cjs/tdf3/src/client/builders.js +13 -1
  36. package/dist/cjs/tdf3/src/client/index.js +200 -53
  37. package/dist/cjs/tdf3/src/client/validation.js +3 -3
  38. package/dist/cjs/tdf3/src/tdf.js +20 -2
  39. package/dist/cjs/tdf3/src/utils/unwrap.js +2 -2
  40. package/dist/types/src/access.d.ts +15 -0
  41. package/dist/types/src/access.d.ts.map +1 -1
  42. package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts +1 -1
  43. package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts.map +1 -1
  44. package/dist/types/src/auth/oidc-externaljwt-provider.d.ts +1 -1
  45. package/dist/types/src/auth/oidc-externaljwt-provider.d.ts.map +1 -1
  46. package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +15 -1
  47. package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -1
  48. package/dist/types/src/auth/oidc.d.ts +4 -0
  49. package/dist/types/src/auth/oidc.d.ts.map +1 -1
  50. package/dist/types/src/auth/providers.d.ts.map +1 -1
  51. package/dist/types/src/index.d.ts +1 -0
  52. package/dist/types/src/index.d.ts.map +1 -1
  53. package/dist/types/src/opentdf.d.ts +126 -6
  54. package/dist/types/src/opentdf.d.ts.map +1 -1
  55. package/dist/types/src/platform/authorization/v2/authorization_pb.d.ts +439 -0
  56. package/dist/types/src/platform/authorization/v2/authorization_pb.d.ts.map +1 -0
  57. package/dist/types/src/platform/buf/validate/validate_pb.d.ts +495 -370
  58. package/dist/types/src/platform/buf/validate/validate_pb.d.ts.map +1 -1
  59. package/dist/types/src/platform/common/common_pb.d.ts +36 -0
  60. package/dist/types/src/platform/common/common_pb.d.ts.map +1 -1
  61. package/dist/types/src/platform/entity/entity_pb.d.ts +130 -0
  62. package/dist/types/src/platform/entity/entity_pb.d.ts.map +1 -0
  63. package/dist/types/src/platform/entityresolution/entity_resolution_pb.d.ts +4 -0
  64. package/dist/types/src/platform/entityresolution/entity_resolution_pb.d.ts.map +1 -1
  65. package/dist/types/src/platform/entityresolution/v2/entity_resolution_pb.d.ts +136 -0
  66. package/dist/types/src/platform/entityresolution/v2/entity_resolution_pb.d.ts.map +1 -0
  67. package/dist/types/src/platform/google/api/http_pb.d.ts.map +1 -1
  68. package/dist/types/src/platform/kas/kas_pb.d.ts +5 -0
  69. package/dist/types/src/platform/kas/kas_pb.d.ts.map +1 -1
  70. package/dist/types/src/platform/policy/attributes/attributes_pb.d.ts +44 -13
  71. package/dist/types/src/platform/policy/attributes/attributes_pb.d.ts.map +1 -1
  72. package/dist/types/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts +329 -24
  73. package/dist/types/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts.map +1 -1
  74. package/dist/types/src/platform/policy/keymanagement/key_management_pb.d.ts +20 -1
  75. package/dist/types/src/platform/policy/keymanagement/key_management_pb.d.ts.map +1 -1
  76. package/dist/types/src/platform/policy/namespaces/namespaces_pb.d.ts +143 -5
  77. package/dist/types/src/platform/policy/namespaces/namespaces_pb.d.ts.map +1 -1
  78. package/dist/types/src/platform/policy/objects_pb.d.ts +382 -33
  79. package/dist/types/src/platform/policy/objects_pb.d.ts.map +1 -1
  80. package/dist/types/src/platform/policy/obligations/obligations_pb.d.ts +670 -0
  81. package/dist/types/src/platform/policy/obligations/obligations_pb.d.ts.map +1 -0
  82. package/dist/types/src/platform/policy/registeredresources/registered_resources_pb.d.ts +67 -0
  83. package/dist/types/src/platform/policy/registeredresources/registered_resources_pb.d.ts.map +1 -1
  84. package/dist/types/src/platform/policy/resourcemapping/resource_mapping_pb.d.ts.map +1 -1
  85. package/dist/types/src/platform/policy/selectors_pb.d.ts +18 -0
  86. package/dist/types/src/platform/policy/selectors_pb.d.ts.map +1 -1
  87. package/dist/types/src/platform/policy/subjectmapping/subject_mapping_pb.d.ts.map +1 -1
  88. package/dist/types/src/platform/policy/unsafe/unsafe_pb.d.ts +18 -4
  89. package/dist/types/src/platform/policy/unsafe/unsafe_pb.d.ts.map +1 -1
  90. package/dist/types/src/platform.d.ts +16 -0
  91. package/dist/types/src/platform.d.ts.map +1 -1
  92. package/dist/types/src/policy/api.d.ts +2 -0
  93. package/dist/types/src/policy/api.d.ts.map +1 -1
  94. package/dist/types/src/policy/granter.d.ts +11 -6
  95. package/dist/types/src/policy/granter.d.ts.map +1 -1
  96. package/dist/types/src/seekable.d.ts +31 -0
  97. package/dist/types/src/seekable.d.ts.map +1 -1
  98. package/dist/types/src/utils.d.ts +56 -2
  99. package/dist/types/src/utils.d.ts.map +1 -1
  100. package/dist/types/tdf3/src/assertions.d.ts +4 -0
  101. package/dist/types/tdf3/src/assertions.d.ts.map +1 -1
  102. package/dist/types/tdf3/src/client/builders.d.ts +12 -0
  103. package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
  104. package/dist/types/tdf3/src/client/index.d.ts +11 -3
  105. package/dist/types/tdf3/src/client/index.d.ts.map +1 -1
  106. package/dist/types/tdf3/src/client/validation.d.ts +3 -3
  107. package/dist/types/tdf3/src/client/validation.d.ts.map +1 -1
  108. package/dist/types/tdf3/src/tdf.d.ts +2 -1
  109. package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
  110. package/dist/types/tdf3/src/utils/unwrap.d.ts.map +1 -1
  111. package/dist/web/src/access.js +16 -1
  112. package/dist/web/src/auth/oidc-clientcredentials-provider.js +4 -2
  113. package/dist/web/src/auth/oidc-externaljwt-provider.js +5 -3
  114. package/dist/web/src/auth/oidc-refreshtoken-provider.js +19 -3
  115. package/dist/web/src/auth/oidc.js +9 -8
  116. package/dist/web/src/auth/providers.js +7 -1
  117. package/dist/web/src/index.js +2 -1
  118. package/dist/web/src/opentdf.js +66 -12
  119. package/dist/web/src/platform/authorization/v2/authorization_pb.js +109 -0
  120. package/dist/web/src/platform/buf/validate/validate_pb.js +113 -169
  121. package/dist/web/src/platform/common/common_pb.js +15 -4
  122. package/dist/web/src/platform/entity/entity_pb.js +48 -0
  123. package/dist/web/src/platform/entityresolution/entity_resolution_pb.js +1 -1
  124. package/dist/web/src/platform/entityresolution/v2/entity_resolution_pb.js +46 -0
  125. package/dist/web/src/platform/google/api/annotations_pb.js +1 -1
  126. package/dist/web/src/platform/google/api/http_pb.js +3 -3
  127. package/dist/web/src/platform/kas/kas_pb.js +2 -2
  128. package/dist/web/src/platform/policy/attributes/attributes_pb.js +12 -2
  129. package/dist/web/src/platform/policy/kasregistry/key_access_server_registry_pb.js +55 -3
  130. package/dist/web/src/platform/policy/keymanagement/key_management_pb.js +2 -2
  131. package/dist/web/src/platform/policy/namespaces/namespaces_pb.js +30 -3
  132. package/dist/web/src/platform/policy/objects_pb.js +114 -41
  133. package/dist/web/src/platform/policy/obligations/obligations_pb.js +156 -0
  134. package/dist/web/src/platform/policy/registeredresources/registered_resources_pb.js +19 -14
  135. package/dist/web/src/platform/policy/resourcemapping/resource_mapping_pb.js +2 -3
  136. package/dist/web/src/platform/policy/selectors_pb.js +1 -1
  137. package/dist/web/src/platform/policy/subjectmapping/subject_mapping_pb.js +2 -3
  138. package/dist/web/src/platform/policy/unsafe/unsafe_pb.js +2 -4
  139. package/dist/web/src/platform.js +16 -3
  140. package/dist/web/src/policy/api.js +26 -7
  141. package/dist/web/src/policy/granter.js +75 -48
  142. package/dist/web/src/seekable.js +32 -1
  143. package/dist/web/src/utils.js +57 -3
  144. package/dist/web/tdf3/src/assertions.js +38 -2
  145. package/dist/web/tdf3/src/client/builders.js +13 -1
  146. package/dist/web/tdf3/src/client/index.js +202 -56
  147. package/dist/web/tdf3/src/client/validation.js +3 -3
  148. package/dist/web/tdf3/src/tdf.js +20 -2
  149. package/dist/web/tdf3/src/utils/unwrap.js +2 -2
  150. package/package.json +7 -5
  151. package/src/access.ts +15 -0
  152. package/src/auth/oidc-clientcredentials-provider.ts +4 -0
  153. package/src/auth/oidc-externaljwt-provider.ts +5 -1
  154. package/src/auth/oidc-refreshtoken-provider.ts +19 -1
  155. package/src/auth/oidc.ts +12 -7
  156. package/src/auth/providers.ts +6 -0
  157. package/src/index.ts +1 -0
  158. package/src/opentdf.ts +149 -72
  159. package/src/platform/authorization/v2/authorization_pb.ts +503 -0
  160. package/src/platform/buf/validate/validate_pb.ts +529 -401
  161. package/src/platform/common/common_pb.ts +48 -3
  162. package/src/platform/entity/entity_pb.ts +154 -0
  163. package/src/platform/entityresolution/entity_resolution_pb.ts +4 -0
  164. package/src/platform/entityresolution/v2/entity_resolution_pb.ts +170 -0
  165. package/src/platform/google/api/annotations_pb.ts +1 -1
  166. package/src/platform/google/api/http_pb.ts +2 -2
  167. package/src/platform/kas/kas_pb.ts +6 -1
  168. package/src/platform/policy/attributes/attributes_pb.ts +46 -16
  169. package/src/platform/policy/kasregistry/key_access_server_registry_pb.ts +371 -27
  170. package/src/platform/policy/keymanagement/key_management_pb.ts +24 -2
  171. package/src/platform/policy/namespaces/namespaces_pb.ts +163 -7
  172. package/src/platform/policy/objects_pb.ts +474 -59
  173. package/src/platform/policy/obligations/obligations_pb.ts +788 -0
  174. package/src/platform/policy/registeredresources/registered_resources_pb.ts +80 -13
  175. package/src/platform/policy/resourcemapping/resource_mapping_pb.ts +1 -2
  176. package/src/platform/policy/selectors_pb.ts +18 -0
  177. package/src/platform/policy/subjectmapping/subject_mapping_pb.ts +1 -2
  178. package/src/platform/policy/unsafe/unsafe_pb.ts +21 -6
  179. package/src/platform.ts +19 -5
  180. package/src/policy/api.ts +37 -6
  181. package/src/policy/granter.ts +82 -56
  182. package/src/seekable.ts +31 -0
  183. package/src/utils.ts +56 -2
  184. package/tdf3/src/assertions.ts +52 -1
  185. package/tdf3/src/client/builders.ts +15 -0
  186. package/tdf3/src/client/index.ts +279 -73
  187. package/tdf3/src/client/validation.ts +2 -2
  188. package/tdf3/src/tdf.ts +26 -2
  189. 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
- // Options when creating a new TDF object
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
- // If the policy service should be used to control creation options
60
+ /** If the policy service should be used to control creation options. */
61
61
  autoconfigure?: boolean;
62
62
 
63
- // List of attributes that will be assigned to the object's policy
63
+ /** List of attributes that will be assigned to the object's policy. */
64
64
  attributes?: string[];
65
65
 
66
- // If set and positive, this represents the maxiumum number of bytes to read from a stream to encrypt.
67
- // This is helpful for enforcing size limits and preventing DoS attacks.
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
- // The KAS to use for creation, if none is specified by the attribute service.
72
+ /** The KAS to use for creation, if none is specified by the attribute service. */
71
73
  defaultKASEndpoint?: string;
72
74
 
73
- // Private (or shared) keys for signing assertions and bindings
75
+ /** Private (or shared) keys for signing assertions and bindings. */
74
76
  signers?: Keys;
75
77
 
76
- // Source of plaintext data
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
- // When creating a new collection, use ECDSA binding with this key id from the signers,
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
- // When creating a new collection,
88
- // use the key in the `signers` list with this id
89
- // to generate a signature for each element.
90
- // When absent, the nanotdf is unsigned.
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
- // The maximum number of key iterations to use for a single DEK.
101
+ /** The maximum number of key iterations to use for a single DEK. */
97
102
  maxKeyIterations?: number;
98
103
  };
99
104
 
100
- // Metadata for a TDF object.
105
+ /** Metadata for a TDF object. */
101
106
  export type Metadata = object;
102
107
 
103
- // MIME type of the decrypted content.
108
+ /** MIME type of the decrypted content. */
104
109
  export type MimeType = `${string}/${string}`;
105
110
 
106
- // Template for a Key Access Object (KAO) to be filled in during encrypt.
111
+ /** Template for a Key Access Object (KAO) to be filled in during encrypt. */
107
112
  export type SplitStep = {
108
- // Which KAS to use to rewrap this segment of the key
113
+ /** Which KAS to use to rewrap this segment of the key. */
109
114
  kas: string;
110
-
111
- // An identifier for a key segment.
112
- // Leave empty to share the key.
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
- /// Options specific to the ZTDF container format.
122
+ /** Options specific to the ZTDF container format. */
117
123
  export type CreateZTDFOptions = CreateOptions & {
118
- // Configuration for bound metadata.
124
+ /** Configuration for bound metadata. */
119
125
  assertionConfigs?: AssertionConfig[];
120
126
 
121
- // Unbound metadata (deprecated)
127
+ /** Unbound metadata (deprecated). */
122
128
  metadata?: Metadata;
123
129
 
124
- // MIME type of the decrypted content. Used for display.
130
+ /** MIME type of the decrypted content. Used for display. */
125
131
  mimeType?: MimeType;
126
132
 
127
- // How to split or share the data encryption key across multiple KASes.
133
+ /** How to split or share the data encryption key across multiple KASes. */
128
134
  splitPlan?: SplitStep[];
129
135
 
130
- // The segment size for the content; smaller is slower, but allows faster random access.
131
- // The current default is 1 MiB (2^20 bytes).
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
- // Preferred algorithm to use for Key Access Objects.
142
+ /** Preferred algorithm to use for Key Access Objects. */
135
143
  wrappingKeyAlgorithm?: KasPublicKeyAlgorithm;
136
144
 
137
- // TDF spec version to target
145
+ /** TDF spec version to target. */
138
146
  tdfSpecVersion?: '4.2.2' | '4.3.0';
139
147
  };
140
148
 
141
- // Settings for decrypting any variety of TDF file.
149
+ /** Settings for decrypting any variety of TDF file. */
142
150
  export type ReadOptions = {
143
- // ciphertext
151
+ /** The ciphertext source. */
144
152
  source: Source;
145
- // Platform URL
153
+ /** The platform URL. */
146
154
  platformUrl?: string;
147
- // list of KASes that may be contacted for a rewrap
155
+ /** List of KASes that may be contacted for a rewrap. */
148
156
  allowedKASEndpoints?: string[];
149
- // Optionally disable checking the allowlist
157
+ /** Optionally disable checking the allowlist. */
150
158
  ignoreAllowlist?: boolean;
151
- // Public (or shared) keys for verifying assertions
159
+ /** Public (or shared) keys for verifying assertions. */
152
160
  assertionVerificationKeys?: AssertionVerificationKeys;
153
- // Optionally disable assertion verification
161
+ /** Optionally disable assertion verification. */
154
162
  noVerify?: boolean;
155
163
 
156
- // If set, prevents more than this number of concurrent requests to the KAS.
164
+ /** If set, prevents more than this number of concurrent requests to the KAS. */
157
165
  concurrencyLimit?: number;
158
166
 
159
- // Type of key to use for wrapping responses.
167
+ /** Type of key to use for wrapping responses. */
160
168
  wrappingKeyAlgorithm?: KasPublicKeyAlgorithm;
161
169
  };
162
170
 
163
- // Defaults and shared settings that are relevant to creating TDF objects.
171
+ /** Defaults and shared settings that are relevant to creating TDF objects. */
164
172
  export type OpenTDFOptions = {
165
- // Policy service endpoint
173
+ /** Policy service endpoint. */
166
174
  policyEndpoint?: string;
167
175
 
168
- // Platform URL
176
+ /** Platform URL. */
169
177
  platformUrl?: string;
170
178
 
171
- // Auth provider for connections to the policy service and KASes.
179
+ /** Auth provider for connections to the policy service and KASes. */
172
180
  authProvider: AuthProvider;
173
181
 
174
- // Default settings for 'encrypt' type requests.
182
+ /** Default settings for 'encrypt' type requests. */
175
183
  defaultCreateOptions?: Omit<CreateOptions, 'source'>;
176
184
 
177
- // Default settings for 'decrypt' type requests.
185
+ /** Default settings for 'decrypt' type requests. */
178
186
  defaultReadOptions?: Omit<ReadOptions, 'source'>;
179
187
 
180
- // If we want to *not* send a DPoP token
188
+ /** If we want to *not* send a DPoP token. */
181
189
  disableDPoP?: boolean;
182
190
 
183
- // Optional keys for DPoP requests to a server.
184
- // These often must be registered via a DPoP flow with the IdP
185
- // which is out of the scope of this library.
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
- // Configuration options for the collection header cache.
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
- // If the source is a TDF3/ZTDF, and includes metadata, and it has been read.
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
- // If the source is a NanoTDF, this will be set.
208
+ /** If the source is a NanoTDF, this will be set. */
197
209
  header?: Header;
198
210
  };
199
211
 
200
- // Configuration options for the collection header cache.
212
+ /** Configuration options for the collection header cache. */
201
213
  export type RewrapCacheOptions = {
202
- // If we should disable (bypass) the cache.
214
+ /** If we should disable (bypass) the cache. */
203
215
  bypass?: boolean;
204
216
 
205
- // Evict keys after this many milliseconds.
217
+ /** Evict keys after this many milliseconds. */
206
218
  maxAge?: number;
207
219
 
208
- // Check for expired keys once every this many milliseconds.
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
- // Cache for headers of nanotdf collections.
219
- // This allows the SDK to quickly open multiple entries of the same collection.
220
- // It has a demon that removes all keys that have not been accessed in the last 5 minutes.
221
- // To cancel the demon, and clear the cache, call `close()`.
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
- // SDK for dealing with OpenTDF data and policy services.
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
- // Configuration service and more is at this URL/connectRPC endpoint
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
  }