5.1.1 • Published 3 months ago

virtru-sdk v5.1.1

Weekly downloads
406
License
Proprietary
Repository
github
Last release
3 months ago

Virtru SDK for JavaScript

The Virtru SDK allows developers to securely and easily encrypt and manage access to sensitve data. This comprehensive documentation serves as the source of truth for the functionality and usage of the Virtru JavaScript SDK.

TDF Architecture

For more information, please see the Virtru Developer Hub or join us on Slack.

Core Concepts

The SDK

  • TDF Ciphertext - Ciphertext encrypted using the open TDF standard. Each TDF Ciphertext is encrypted with a unique data key and managed with independent access controls. See the Developer Hub and TDF whitepaper for more information.
  • Virtru Policy - An policy specifying access controls to enforce on encrypted data, such as expiry and ACL.
  • User - An entity authenticated with Virtru. SDK users can allow other users access to encrypted data. For instance, bob@virtru.com can authorize alice@virtru.com to access some encrypted data at either encryption-time or any time afterwords.

Getting Started

Currently the SDK is available in minified, Web-ready form via a Virtru CDN. It can be included via a <script> tag as shown below:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Virtru SDK for JavaScript - Sample Application</title>
    <script src="https://sdk.virtru.com/js/latest/virtru-sdk.min.js"></script>
</head>


<body>
  <script type="text/javascript">
    var client = new window.Virtru.Client.VirtruClient();
    document.body.innerHTML = `Version: ${client.getClientVersion()}<br/>Your page is now configured to use the Virtru Data Protection JS SDK!`; 
  </script>
</body>
</html>

In the near future, an npm distribution will also be available for use. Stay tuned.

Authentication

The SDK accepts an AuthProvider which handles authenticating to Virtru for all backend service calls. Several auth schemes are supported, including federated auth (shown below) and custom Virtru credentials. The AuthProvider is a required configuration property for all client operations (excluding getClientVersion(), as shown above.

// Set the AuthProvider during client construction.
const email = "alice@virtru.com"
const client = new Virtru.Client({authProvider: new Virtru.ClientAuth.Providers.GoogleAuthProvider({email})});

The Virtru Client will continue to use the federated Google identity to authenticate to the Virtru backend, refreshing credentials internally as necessary.

Encrypting Data

Once the client is constructed you can use it to start encrypting data.

// Configure and execute an encrypt.
// The creator (alice@virtru.com) always has access, so we don't need to specify her in the ACL.
const encryptParams = new Virtru.EncryptParamsBuilder()
  .withStringSource("Sokath, his eyes opened!")
  .withUsersWithAccess(["bob@virtru.com"]) 
  .build();
const ct = await client.encrypt(encryptParams);

You can use standard stream processing methods to handle the returned Readable stream.

// Write the TDF ciphertext to stdout, node style.
ct.pipe(process.stdout);

Or you can just use the built in helper methods to write out the TDF ciphertext contents.

// Write the TDF ciphertext to the console.
console.log(await ct.toString());

Decrypting Data

You can also start decrypting data with the client. If the authenticated user is authorized, this returns a Readable stream containing the decrypted plaintext and helper methods for writing.

// Configure the parameters to decrypt a local file.
const decryptParams = new Virtru.DecryptParamsBuilder()
  .withFileSource("plain.tdf")
  .build();

// Run the decrypt.
const pt = await client.decrypt(decryptParams);

// Write the result to a local file.
await pt.toFile("plain.txt");

Common Use-Cases

This section lists some example usages using the Virtru SDK. See the Developer Hub for examples of a wide range of common use-cases.

Example: Encrypting data with expiration.

// Construct an authorization policy to apply to the encrypted data.
// Note that *expiration only applies to other users*, not the creator.
const policy = new Virtru.PolicyBuilder()
  .enableExpirationDeadlineFromNow(60)
  .build();

// Configure the encrypt parameters to encrypt a provided string.
const encryptParams = new Virtru.EncryptParamsBuilder()
  .withStringSource("I expire in 60 seconds")
  .withUsersWithAccess(["bob@virtru.com", "charlie@virtru.com"])
  .withPolicy(policy)
  .build();

// Run the encrypt and write the result to stdout.
(await client.encrypt(encryptParams)).pipe(process.stdout);

Example: Adding users to the data ACL after encryption.

// Configure the encrypt parameters to encrypt a provided string.
const policyId = uuid.v4();
const encryptParams = new Virtru.EncryptParamsBuilder()
  .withPolicyId(policyId) // can alternatively set on the PolicyBuilder
  .build();

// Run the encrypt and write the result to stdout.
(await client.encrypt(encryptParams)).pipe(process.stdout);

// Time passes...

// Some time later we decide to allow bob access to the data.

// First fetch the Policy. We assume the policyId is already stored: 
// this could be retrived from a separate index, parsed from the TDF ciphertext 
// using the client helper (WS-9400), or pulled from the TDFCiphertextStream returned
// by `encrypt` (WS-9400).
const policy = await client.fetchPolicy(policyId)

// Update the policy locally, adding the new user.
const updatedPolicy = policy.builder().addUsers("bob@virtru.com").build();

// Commit the update to the Virtru backend.
await client.updatePolicy(updatedPolicy);
6.0.0-beta.7.4

3 months ago

5.2.2-beta.7.1

4 months ago

6.0.0-beta.7.2

4 months ago

5.2.2-beta.7

5 months ago

5.2.2-beta.1

6 months ago

5.2.2-beta.2

6 months ago

5.2.2-beta.2.2

6 months ago

5.2.0-beta.3.1

8 months ago

5.0.1-beta.0.5

10 months ago

5.1.1-beta.14.1

9 months ago

4.0.0-beta.45.2

11 months ago

5.0.0

11 months ago

5.0.1-beta.7.2

10 months ago

4.0.0-beta.46.3

11 months ago

5.1.1

9 months ago

5.1.0

9 months ago

5.1.0-rc.14

9 months ago

5.1.0-beta.4.8

10 months ago

5.0.1-beta.11

10 months ago

5.1.0-beta.14

9 months ago

5.2.1-beta.4.2

7 months ago

5.1.1-alpha.1.1

9 months ago

4.0.0-beta.48

11 months ago

5.2.0-beta.3

8 months ago

5.2.0-beta.1

9 months ago

5.0.1-beta.4

10 months ago

5.0.1-beta.6

10 months ago

5.1.1-rc.0

9 months ago

5.0.1-beta.5.5

10 months ago

5.1.0-beta.11.2

9 months ago

5.2.1-rc.5.2

7 months ago

4.0.0-beta.34.3

1 year ago

4.0.1-beta.18.7

1 year ago

4.0.0-beta.35.4

1 year ago

4.0.0-beta.24.6

1 year ago

4.0.0-beta.24.9

1 year ago

4.0.1-beta.24.2

1 year ago

4.0.0-beta.37.1

1 year ago

4.0.0-beta.30.2

1 year ago

4.0.0-beta.41.1

1 year ago

4.0.0-beta.43

1 year ago

4.0.0-beta.46

12 months ago

4.0.0-beta.40

1 year ago

4.0.0-beta.41

1 year ago

4.0.0-beta.16.1

1 year ago

4.0.0-beta.36

1 year ago

4.0.0-beta.28

1 year ago

4.0.0-beta.20

1 year ago

4.0.0-beta.20.1

1 year ago

4.0.0-beta.16

1 year ago

4.0.0-beta.43.2

1 year ago

4.0.0-beta.20.4

1 year ago

4.0.0-beta.28.7

1 year ago

4.0.0-beta.28.1

1 year ago

4.0.0-beta.19

1 year ago

4.0.0-beta.28.6

1 year ago

3.2.0-rc.17.1

1 year ago

3.2.3-beta.8.2

1 year ago

3.2.0-beta.7.4

1 year ago

3.2.3-beta.8.3

1 year ago

3.1.1-beta.9.6

1 year ago

3.0.3-beta.7.5

2 years ago

3.2.0-beta.4.16

1 year ago

3.2.3-beta.9.3

1 year ago

3.1.0

1 year ago

3.2.1-beta.7.8

1 year ago

3.0.4-beta.7.9

2 years ago

3.1.0-rc.6.12

2 years ago

3.0.3

2 years ago

3.0.2

1 year ago

3.0.2-rc.0.2

1 year ago

3.0.3-beta.9.1

2 years ago

3.0.3-rc.6.4

2 years ago

3.0.4-beta.6.8

2 years ago

3.2.0-beta.6.17

1 year ago

3.2.0-beta.6.15

1 year ago

3.1.1-beta.10.3

1 year ago

3.0.4-beta.8.7

2 years ago

3.2.0-beta.7.17

1 year ago

3.0.3-beta.4.7

2 years ago

3.1.0-beta.5.14

1 year ago

3.0.3-beta.5.4

2 years ago

3.1.0-beta.7

2 years ago

3.2.1-beta.6

1 year ago

3.0.4-beta.7.10

2 years ago

3.0.3-beta.5

2 years ago

3.0.3-beta.6

2 years ago

3.0.3-beta.4

2 years ago

3.0.3-beta.4.4

2 years ago

3.0.3-beta.6.1

2 years ago

2.5.0-beta.2.7

2 years ago

3.0.0-alpha.13.4

2 years ago

3.0.1-rc.17.16

2 years ago

3.0.0-beta.4.11

2 years ago

2.5.0-beta.8.3

2 years ago

2.5.0-beta.8.4

2 years ago

2.5.0-beta.4.4

2 years ago

3.0.1

2 years ago

3.0.0-beta.13.1

2 years ago

3.0.2-beta.3

2 years ago

3.0.2-beta.2

2 years ago

2.5.0-beta.2.11

2 years ago

2.5.0-beta.3.7

2 years ago

3.0.1-beta.3.13

2 years ago

2.5.0-beta.2.4

2 years ago

2.5.0-beta.3

2 years ago

2.5.0-beta.4

2 years ago

2.5.0-beta.5

2 years ago

2.5.0-beta.7

2 years ago

2.4.5-beta.2

2 years ago

2.4.4

2 years ago

2.4.4-beta.17

2 years ago

2.4.4-rc.17.1

2 years ago

2.4.4-alpha.2.11

2 years ago

2.4.4-beta.0.1

3 years ago

2.4.3-rc.3.5

3 years ago

2.4.3

3 years ago

2.4.3-beta.2.5

3 years ago

2.4.3-beta.4.2

3 years ago

2.4.3-beta.2.3

3 years ago

2.4.3-beta.2.2

3 years ago

2.4.1

3 years ago

2.4.2

3 years ago

2.4.0

3 years ago

2.4.0-beta.2.5

3 years ago

2.3.4

3 years ago

2.3.4-rc.0.7

3 years ago

2.3.2

3 years ago

2.3.3-beta.1.2

3 years ago

2.3.2-alpha.0.2

3 years ago

2.3.2-alpha.0.9

3 years ago

2.3.2-rc.1.2

3 years ago

2.3.3-rc.0.7

3 years ago

2.3.2-beta.0.1

3 years ago

2.3.2-beta.0.2

3 years ago

2.3.1

3 years ago

2.3.1-beta.2.1

3 years ago

2.3.1-alpha.2.4

3 years ago

2.3.1-beta.2

3 years ago

2.3.1-alpha.0.4

3 years ago

2.3.0

3 years ago

2.3.0-beta.2.12

3 years ago

2.3.0-rc.2.12

3 years ago

2.3.0-beta.2.11

3 years ago

2.3.0-beta.2.9

3 years ago

2.3.0-beta.2.10

3 years ago

2.2.1-alpha.2.9

3 years ago

2.2.1-alpha.2.7

3 years ago

2.2.1-beta.2.1

3 years ago

2.2.1-alpha.2.5

3 years ago

2.2.1-alpha.2.4

3 years ago

2.2.1-alpha.2.2

3 years ago

2.2.1-alpha.2.3

3 years ago

2.2.0-beta.1.4

3 years ago

2.2.0-beta.1.3

3 years ago

2.2.0-beta.1.2

3 years ago

2.2.0

3 years ago

2.2.0-beta.0.2

3 years ago

2.2.0-rc.1.2

3 years ago

2.2.0-beta.1

3 years ago

2.2.0-alpha.0.6

3 years ago

2.2.0-alpha.0.3

3 years ago

2.1.6-rc.1.1

3 years ago

2.1.5

3 years ago

2.1.5-rc.7.6

3 years ago

2.1.4-beta.3.9

3 years ago

2.1.4-rc.7.5

3 years ago

2.1.4-beta.4.7

4 years ago

2.1.4-beta.4.5

4 years ago

2.1.4-rc.4.3

4 years ago

2.1.3-beta.4

4 years ago

2.1.3-beta.3

4 years ago

2.1.2

4 years ago

2.1.3-beta.9

4 years ago

2.1.2-beta.8.10

4 years ago

2.1.2-rc.7.2

4 years ago

2.1.1-beta.63

4 years ago

2.1.0-alpha.21

4 years ago

2.1.1-alpha.3.4

4 years ago

2.1.1-alpha.3.8

4 years ago

2.1.0

4 years ago

2.1.0-beta.15

4 years ago

2.1.0-rc.15

4 years ago

2.1.0-beta.13

4 years ago

2.1.0-beta.19

4 years ago

2.0.1

4 years ago

2.0.1-beta.108

4 years ago

2.0.0

4 years ago

1.6.16

4 years ago

1.6.15

4 years ago

1.6.12

5 years ago

1.6.11

5 years ago

1.6.10

5 years ago

1.6.9

5 years ago

1.6.8

5 years ago

1.6.7

5 years ago

1.6.6

5 years ago

1.6.5

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.9

5 years ago

1.3.8

5 years ago

1.3.7

5 years ago

1.3.6

5 years ago

1.3.5

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.4-beta.1

5 years ago

1.1.4-beta.0

5 years ago

1.1.3

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago