Skip to content

Commit 6eb5019

Browse files
chore(sdk): Updates readme and fixes typedoc (#453)
1 parent 6713334 commit 6eb5019

File tree

3 files changed

+226
-38
lines changed

3 files changed

+226
-38
lines changed

lib/README.md

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,59 @@
11
# An OpenTDF Library for Browser Applications
22

3-
This project presents client code to write and read a OpenTDF data formats.
4-
This included NanoTDF, Dataset TDF, and ZTDF.
3+
This project presents client code to write and read a OpenTDF data formats. This included NanoTDF
4+
and collections and Base TDF3.
55

66
## Usage
77

88
### NanoTDF
99

1010
```typescript
11-
const oidcCredentials: RefreshTokenCredentials = {
12-
clientId: keycloakClientId,
13-
exchange: 'refresh',
14-
refreshToken: refreshToken,
15-
oidcOrigin: keycloakUrl,
16-
}
17-
const authProvider = await AuthProviders.refreshAuthProvider(oidcCredentials);
18-
const client = new NanoTDFClient({authProvider, kasEndpoint});
19-
const cipherText = await client.encrypt(plainText);
20-
const clearText = await client.decrypt(cipherText);
11+
import { type Chunker, OpenTDF } from '@opentdf/sdk';
12+
13+
const oidcCredentials: RefreshTokenCredentials = {
14+
clientId: keycloakClientId,
15+
exchange: 'refresh',
16+
refreshToken: refreshToken,
17+
oidcOrigin: keycloakUrl,
18+
};
19+
const authProvider = await AuthProviders.refreshAuthProvider(oidcCredentials);
20+
const client = new OpenTDF({
21+
authProvider,
22+
defaultCreateOptions: {
23+
defaultKASEndpoint: kasEndpoint, // Server used for Key Access Control
24+
},
25+
dpopKeys: authProvider.getSigningKey(),
26+
});
27+
const cipherText = await client.createNanoTDF({
28+
source: { type: 'stream', location: source },
29+
});
30+
31+
const clearText = await client.read({ type: 'stream', location: cipherText });
2132
```
2233

2334
### ZTDF
2435

2536
```typescript
26-
const client = new TDF3Client({
27-
clientId: "tdf-client",
28-
kasEndpoint: 'http://localhost/kas',
29-
refreshToken: 'token', // Here is only difference in usage, browser build needs oidc tocken
30-
oidcOrigin: 'http://localhost/oidc',
31-
});
32-
const source = new ReadableStream({
33-
pull(controller) {
34-
controller.enqueue(new TextEncoder().encode(string));
35-
controller.close();
36-
},
37-
});
38-
const ciphertextStream = await client.encrypt({ offline: true, source });
39-
// Optionally: Save ciphertextStream to file or remote here.
40-
// For demo purposes, we pipe to decrypt.
41-
const plaintextStream = await client.decrypt({
42-
source: { type: 'stream', location: ciphertextStream }
43-
});
44-
const plaintext = await plaintextStream.toString(); // could be also ct.toFile('img.jpg');
45-
console.log(`deciphered text :${plaintext}`);
37+
import { type Chunker, OpenTDF } from '@opentdf/sdk';
38+
39+
const oidcCredentials: RefreshTokenCredentials = {
40+
clientId: keycloakClientId,
41+
exchange: 'refresh',
42+
refreshToken: refreshToken,
43+
oidcOrigin: keycloakUrl,
44+
};
45+
const authProvider = await AuthProviders.refreshAuthProvider(oidcCredentials);
46+
const client = new OpenTDF({
47+
authProvider,
48+
defaultCreateOptions: {
49+
defaultKASEndpoint: kasEndpoint, // Server used for Key Access Control
50+
},
51+
dpopKeys: authProvider.getSigningKey(),
52+
});
53+
const cipherText = await client.createZTDF({
54+
source: { type: 'stream', location: source },
55+
autoconfigure: false,
56+
});
57+
58+
const clearText = await client.read({ type: 'stream', location: cipherText });
4659
```
47-
48-
## Upgrading from 1.x
49-
50-
- The 'RemoteStorage' features have been moved into a separate library, @opentdf/remote-storage.
51-
- We have replaced all usages of node's `Buffer` with the web-friendlier `UInt8Array`.
52-
You will most likely see this in the return types of some functions.

lib/package-lock.json

Lines changed: 180 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"process": "^0.11.10",
118118
"sinon": "~19.0.2",
119119
"tsconfig-paths": "^4.2.0",
120+
"typedoc": "^0.27.9",
120121
"typescript": "^5.7.3",
121122
"typescript-eslint": "^8.24.1",
122123
"webpack": "^5.98.0",

0 commit comments

Comments
 (0)