toc

Node.js SDK

A full reference of our Node.js SDK.

The Evervault Node.js SDK is a toolkit for encrypting data as it enters your server, and for working with Cages.

Installation

Our Node.js SDK is distributed via npm, and can be installed using your preferred package manager.

bash
# Install using npm
npm install @evervault/sdk
# Install using Yarn
yarn add @evervault/sdk

Initialization

javascript
const Evervault = require('@evervault/sdk');
// Initialize the client with your team’s API key
const evervault = new Evervault('<YOUR_API_KEY>');
// Encrypt your data
const encrypted = await evervault.encrypt({ name: 'Alice' });
// Process the encrypted data in a Cage
const result = await evervault.run('demo-cage', encrypted);

Reference

The Evervault Node.js SDK exposes three functions:

  • evervault.encrypt()
  • evervault.run()
  • evervault.cagify()

evervault.encrypt()

evervault.encrypt() encrypts data for use in your Cages. To encrypt data at the server, simply pass an object or string into the evervault.encrypt() function. Store the encrypted data in your database as normal.

javascript
async evervault.encrypt(data: Object | String);
ParameterTypeDescription
dataObject or StringData to be encrypted.

evervault.run()

evervault.run() lets you invoke a Cage with a given payload.

javascript
async evervault.run(cageName: String, data: Object[, options: Object]);
ParameterTypeDescription
cageNameStringName of the Cage to be run.
dataObjectPayload for the Cage.
optionsObjectOptions for the cage run.
OptionTypeDefaultDescription
asyncBooleanfalseRun your Cage in async mode. Async Cage runs will be queued for processing.
versionNumberundefinedSpecify the version of your Cage to run. By default, the latest version will be run.

evervault.cagify()

evervault.cagify() lets you deploy and run ordinary Node.js functions as Cages, inline.

This function will automatically deploy a function as a Cage and return a native async Node.js function that accepts the original parameters, but which invokes a Cage when run.

Note: evervault.cagify() is a synchronous function and will block your event loop if no cage-lock.json file is present for the Caged functions.

javascript
evervault.cagify(cageName: String, cageFunction: Function);
ParameterTypeDescription
cageNameStringName of the Cage to be run.
cageFunctionFunctionThe function to deploy as a Cage.