@@ -310,19 +310,56 @@ export type TDFReader = {
310310 attributes : ( ) => Promise < string [ ] > ;
311311} ;
312312
313- /** SDK for dealing with OpenTDF data and policy services. */
313+ /**
314+ * The main OpenTDF class that provides methods for creating and reading TDF files.
315+ * It supports both NanoTDF and ZTDF formats.
316+ * It can be used to create new TDF files and read existing ones.
317+ * This class is the entry point for using the OpenTDF SDK.
318+ * It requires an authentication provider to be passed in the constructor.
319+ * It also requires a platform URL to be set, which is used to fetch key access servers and policies.
320+ * @example
321+ * ```
322+ * import { type Chunker, OpenTDF } from '@opentdf/sdk';
323+ *
324+ * const oidcCredentials: RefreshTokenCredentials = {
325+ * clientId: keycloakClientId,
326+ * exchange: 'refresh',
327+ * refreshToken: refreshToken,
328+ * oidcOrigin: keycloakUrl,
329+ * };
330+ * const authProvider = await AuthProviders.refreshAuthProvider(oidcCredentials);
331+ *
332+ * const client = new OpenTDF({
333+ * authProvider,
334+ * platformUrl: 'https://platform.example.com',
335+ * });
336+ *
337+ * const cipherText = await client.createZTDF({
338+ * source: { type: 'stream', location: source },
339+ * autoconfigure: false,
340+ * });
341+ *
342+ * const clearText = await client.read({ type: 'stream', location: cipherText });
343+ * ```
344+ */
314345export class OpenTDF {
315- // Configuration service and more is at this URL/connectRPC endpoint
346+ /** The platform URL */
316347 readonly platformUrl : string ;
348+ /** The policy service endpoint */
317349 readonly policyEndpoint : string ;
350+ /** The auth provider for the OpenTDF instance. */
318351 readonly authProvider : AuthProvider ;
352+ /** If DPoP is enabled for this instance. */
319353 readonly dpopEnabled : boolean ;
354+ /** Default options for creating TDF objects. */
320355 defaultCreateOptions : Omit < CreateOptions , 'source' > ;
356+ /** Default options for reading TDF objects. */
321357 defaultReadOptions : Omit < ReadOptions , 'source' > ;
358+ /** The DPoP keys for this instance, if any. */
322359 readonly dpopKeys : Promise < CryptoKeyPair > ;
323-
324- // Header cache for reading nanotdf collections
360+ /** Cache for rewrapped keys */
325361 private readonly rewrapCache : RewrapCache ;
362+ /** The TDF3 client for encrypting and decrypting ZTDF files. */
326363 readonly tdf3Client : TDF3Client ;
327364
328365 constructor ( {
@@ -420,10 +457,7 @@ export class OpenTDF {
420457 return stream ;
421458 }
422459
423- /**
424- * Opens a TDF file for inspection and decryption.
425- * @param opts The file to open, and any appropriate configuration options.
426- */
460+ /** Opens a TDF file for inspection and decryption. */
427461 open ( opts : ReadOptions ) : TDFReader {
428462 opts = { ...this . defaultReadOptions , ...opts } ;
429463 return new UnknownTypeReader ( this , opts , this . rewrapCache ) ;
@@ -453,6 +487,7 @@ class UnknownTypeReader {
453487 this . delegate = this . resolveType ( ) ;
454488 }
455489
490+ /** Resolves the TDF type based on the file prefix. */
456491 async resolveType ( ) : Promise < TDFReader > {
457492 if ( this . state === 'done' ) {
458493 throw new ConfigurationError ( 'reader is closed' ) ;
@@ -474,21 +509,25 @@ class UnknownTypeReader {
474509 throw new InvalidFileError ( `unsupported format; prefix not recognized ${ prefix } ` ) ;
475510 }
476511
512+ /** Decrypts the TDF file */
477513 async decrypt ( ) : Promise < DecoratedStream > {
478514 const actual = await this . delegate ;
479515 return actual . decrypt ( ) ;
480516 }
481517
518+ /** Returns the attributes of the TDF file */
482519 async attributes ( ) : Promise < string [ ] > {
483520 const actual = await this . delegate ;
484521 return actual . attributes ( ) ;
485522 }
486523
524+ /** Returns the manifest of the TDF file */
487525 async manifest ( ) : Promise < Manifest > {
488526 const actual = await this . delegate ;
489527 return actual . manifest ( ) ;
490528 }
491529
530+ /** Closes the TDF reader */
492531 async close ( ) {
493532 if ( this . state === 'done' ) {
494533 return ;
@@ -534,6 +573,7 @@ class NanoTDFReader {
534573 } ) ;
535574 }
536575
576+ /** Decrypts the NanoTDF file and returns a decorated stream. */
537577 async decrypt ( ) : Promise < DecoratedStream > {
538578 const nanotdf = await this . container ;
539579 const cachedDEK = this . rewrapCache . get ( nanotdf . header . ephemeralPublicKey ) ;
@@ -576,10 +616,12 @@ class NanoTDFReader {
576616
577617 async close ( ) { }
578618
619+ /** Returns blank manifest. NanoTDF has no manifest. */
579620 async manifest ( ) : Promise < Manifest > {
580621 return { } as Manifest ;
581622 }
582623
624+ /** Returns the attributes of the NanoTDF file. */
583625 async attributes ( ) : Promise < string [ ] > {
584626 const nanotdf = await this . container ;
585627 if ( ! nanotdf . header . policy ?. content ) {
@@ -695,12 +737,16 @@ async function streamify(ab: Promise<ArrayBuffer>): Promise<ReadableStream<Uint8
695737
696738/** A writer for NanoTDF collections. */
697739export type NanoTDFCollectionWriter = {
740+ /** The NanoTDF client used for encrypting data in this collection. */
698741 encrypt : ( source : Source ) => Promise < ReadableStream < Uint8Array > > ;
742+ /** Closes the collection and releases any resources. */
699743 close : ( ) => Promise < void > ;
700744} ;
701745
702746class Collection {
747+ /** The NanoTDF client used for encrypting data in this collection. */
703748 client ?: NanoTDFDatasetClient ;
749+ /** Options for encrypting data in this collection. */
704750 encryptOptions ?: NanoEncryptOptions ;
705751
706752 constructor ( authProvider : AuthProvider , opts : CreateNanoTDFCollectionOptions ) {
@@ -733,6 +779,7 @@ class Collection {
733779 } ) ;
734780 }
735781
782+ /** Encrypts a source into a NanoTDF stream. */
736783 async encrypt ( source : Source ) : Promise < DecoratedStream > {
737784 if ( ! this . client ) {
738785 throw new ConfigurationError ( 'Collection is closed' ) ;
@@ -750,6 +797,7 @@ class Collection {
750797 return stream ;
751798 }
752799
800+ /** Releases client resources. */
753801 async close ( ) {
754802 delete this . client ;
755803 }
0 commit comments