@opentdf/sdk 0.11.0-beta.106 → 0.11.0-beta.107
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/README.md +17 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenTDF SDK for Browser Applications
|
|
2
2
|
|
|
3
3
|
This project presents client code to write and read OpenTDF data formats.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
|
-
import {
|
|
8
|
+
import { AuthProviders, OpenTDF } from '@opentdf/sdk';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
// Use refreshAuthProvider for browser applications.
|
|
11
|
+
// The refresh token is obtained after the user logs in via your OIDC provider.
|
|
12
|
+
const authProvider = await AuthProviders.refreshAuthProvider({
|
|
13
|
+
clientId: 'my-client-id',
|
|
13
14
|
refreshToken: refreshToken,
|
|
14
|
-
oidcOrigin:
|
|
15
|
-
};
|
|
16
|
-
|
|
15
|
+
oidcOrigin: 'https://keycloak.example.com/auth/realms/my-realm',
|
|
16
|
+
});
|
|
17
|
+
|
|
17
18
|
const client = new OpenTDF({
|
|
18
19
|
authProvider,
|
|
19
|
-
|
|
20
|
-
defaultKASEndpoint: kasEndpoint, // Server used for Key Access Control
|
|
21
|
-
},
|
|
22
|
-
dpopKeys: authProvider.getSigningKey(),
|
|
20
|
+
platformUrl: 'https://platform.example.com',
|
|
23
21
|
});
|
|
24
22
|
|
|
25
23
|
// Encrypt
|
|
26
24
|
const cipherText = await client.createTDF({
|
|
27
|
-
source: { type: '
|
|
28
|
-
|
|
25
|
+
source: { type: 'buffer', location: new TextEncoder().encode('hello, world') },
|
|
26
|
+
defaultKASEndpoint: 'https://platform.example.com/kas',
|
|
29
27
|
});
|
|
30
28
|
|
|
31
29
|
// Decrypt
|
|
32
|
-
const
|
|
33
|
-
const
|
|
30
|
+
const encrypted = new Uint8Array(await new Response(cipherText).arrayBuffer());
|
|
31
|
+
const plainText = await client.read({
|
|
32
|
+
source: { type: 'buffer', location: encrypted },
|
|
33
|
+
});
|
|
34
|
+
console.log(await new Response(plainText).text()); // "hello, world"
|
|
34
35
|
```
|