Quick Start

Integrate privacy-preserving computation in your JavaScript client apps with speed and efficiency. Our JavaScript SDK allows you to focus on the client-side implementation of privacy-preserving computation, which amounts to sending protected user data to our API and reporting the results to the user. On the server side, Enya.ai and our SDK ensures reliable infra management and security.

This quick-start gives a brief overview of the SDK and walks you through the steps of using the SDK in your own project. We will focus on secure multiparty computation (SMC) in this quick-start - there is another approach called fully-homomorphic encryption (FHE), which you can learn more about elsewhere in the documentation.

1. Install the SDK

To integrate SMC into your app, follow the step-by-step instructions below.

Step 1: Obtain your access tokens

Email [email protected] to request your secret tokens. You will receive a MASTER_TOKEN and a CLIENT_TOKEN - the MASTER_TOKEN is used to configure the back-end (e.g. to configure your algorithms). The CLIENT_TOKEN allows your app to access the Enya servers. Please keep the tokens safe do not share your tokens with others - a typical security mistake is to hard-code tokens into code that is then made available through a public github repo. If you lose your tokens or they have been compromised, please contact us and we will send you new ones.

Step 2: Set up a node environment

To use our JavaScript SDK you need nodejs and the Node Package Manager (NPM). There are many ways to install node and npm, depending on your platform. One simple way is to use the installer from nodejs.org:

  1. Download the installer from nodejs and select the LTS build that is "Recommended for most users".

  2. Install Node by double-clicking on the downloaded file and following the installation prompts.

Step 3: Set up a react native environment

Our example project is built on the Redux pattern of React Native. To run the example app, you will need the Expo CLI command line utility:

$ npm install -g expo-cli

Step 4: Install the SMC SDK

Installing the JavaScript SDK is simple if you’re familiar with using external libraries or SDKs. Install the Enya secure multiparty computation SDK ('enyasmc') using npm by running the following command in your project path.

$ npm install enyasmc

Make sure that your module is added to the package.json file, which the various package managers npm and yarn will usually do for you.


Note: Before proceeding, we encourage you to spend some time with the example app. It showcases all the core features of our SDK and it's the fastest starting point for building your own app.

2. Your First Secure Computation

The Enya SDK makes privacy-preserving computation effortless and straightforward. There are only a few simple steps to computing your first result:

Step 1: Configure your algorithm

After installing the SDK, use algo_add.py to name and parametrize your linear algorithm. This Python script is located in the ./node_modules/enyasmc/utility_client folder. Assuming your master token is c8b85fcc3c3a13673251e109, you wish to call your algorithm 'MyFirstAlgo', you have three coefficients, and you have decided to use secure multiparty computation, run

# algo_add.py [-h] -s MASTER_TOKEN -n ALGO_NAME -t ALGO_TYPE (='smc'|'fhe') -c COEFFICIENT
python3 algo_add.py -s c8b85fcc3c3a13673251e109 -n MyFirstAlgo -t smc -c [1, 0.1, 1]

Your coefficients are stored securely and can't be accessed by others. Note that algo_add.py needs the requests module to run. Make sure to install it (e.g. with pip) before running the script.

After adding your algorithm, you can use algo_list.py to check your algorithm.

# algo_list.py [-h] -s MASTER_TOKEN
python3 algo_list.py -s master_token

algo_list.py returns all configured algorithms, each identified via a unique id. You can use algo_delete.py to delete algorithms that you no longer need using their unique ids.

# algo_delete.py [-h] -s MASTER_TOKEN -i ALGO_ID
python3 algo_delete.py -s master_token -i algo_id

Step 2: Configure the SDK in the client App

Specifiy your CLIENT_TOKEN and algo_name to configure the SDK.

import EnyaSMC from 'enyasmc';

  CLIENT_TOKEN: "f7edB8a8A4D7dff85d2CB7E5",
  algo_name: "MyFirstAlgo"

Step 3: Provide the client data

// if the data are in array form
const user_data_array = [number, number, number, ...];

// if the data are provided as an object
const user_data_object = {data_1: number, data_2: number, data_3: number, ...};

Make sure that the length of client data vector is the same as the number of terms you configured for your algorithm, otherwise the computation will return an error.

// example of well formed inputs and settings 
client_input           = [  1, 23,   3, 0.7,   5, 0.4] // (sent by the app)
algorithm_coefficients = [0.1,  2, 0.1,  19, 0.8,   9] // (specified when configuring the compute back end)

Step 4: Compute

Finally, compute and get the result:

//EnyaSMC.Linear() returns the inner product of the client vector and the algorithm_coefficients.

Note: This method is asynchronous. Use promises to handle the asynchronous result of the operation. Suitable example code is:


3. The Computation Result

The EnyaSMC.Linear() function returns the result of the computation and various status flags which can be used to determine whether the calculation was successful.

/* Successful */
{secure_result: dot_product_final, status_code: 200}
/* Failed */
{status_code: 404}

The status code of a successful computation is 200 and of a failed computation is 404. Calculations may fail due to setting errors (see error messages). Additional information about algorithm settings is given here.