Example App

Our sample app demonstrates the core features of the SDK. The fastest way to use our SDK for privacy-preserving computation is to build your app on our sample app. Once you have become familiar with the SDK, you will want to configure your own algorithm and tokens, but the App will run (and compute) right out of the box.

1. Run the sample app

Download the app from our GitHub repository for an introduction to the Enya platform and to learn what you can build with the SDK.

Download Sample App

You can also download our sample code via git:

$ git clone https://github.com/enyalabs/EnyaExpo

Our sample project is built on the Redux pattern of React Native. To run the sample code, follow these steps:

  1. Download and install Node JS if you haven't installed it yet.

  2. Open the terminal and use npm to install the Expo CLI command line utility:

$ npm install -g expo-cli
  1. Enter the following command in your project path:

$ npm install
#or if you prefer yarn
$ yarn install
  1. Run the sample code by entering the following command and using your phone to scan the QR code on the screen.

$ npm start

Before scanning the QR code, you need to install Expo Client on your phone or use the iOS or Android simulator.

2. Code Highlights

Once the example App is up and running, let's dig into how it works. Our sample app is built on the default folder structure that React Native gives us. The following folder structure lists the important files you should pay attention to.

    |-- screens
    |    |-- Questionnaire.js
    |-- node_modules
    |    |-- enyasmc
    |        |-- index.js
    |        |-- utility_client/add_algo.py
    |    |-- enyafhe
    |        |-- index.js
    |        |-- utility_client/add_algo.py
    |    |-- enyadeliver
    |        |-- module.js
    |-- redux
    |    |-- actions
    |        |-- actionCompute.js

node_modules/enyasmc/index.js is one of the main files of our SDK - in this case, it handles secure multiparty computation. You can use the utility_client/add_algo.py script to configure your own algorithm - see configure your own algorithm for instructions. Redux is a predictable state container for JavaScript apps, and redux/actions/actionAnswers.js is where we detect the user's inputs and - ultimately - call the secureCompute function from our JavaScript SDK. A basic version of the code is:

import EnyaSMC from 'enyasmc';

export const secureCompute = (data) => async (dispatch) => {
  //----------------- User's input ---------------------

  //-------------- Configure settings ------------------
      algo_name: "MySecretAlgorithm",

  //-------------- Run the model ------------------------
  const model = await EnyaSMC.Linear()

  //-------------- Get the result -----------------------
  if (model.status_code == 200) { 
    result = parseFloat(model.secure_result).toFixed(2); 
  //------------ Dispatch the result --------------------
  let updatedSMC = { result };
  dispatch( seccureComputeSuccess( updatedSMC ))

screens/Questionnaire.js is the user interface screen that allows a user to answer questions and verifies whether a user's input is complete. Once sufficient data are available, we then call the secureCompute function to perform the secure multi-party computation (or fhe, if you have configured things that way). You can find the result of the computation on the Home screen or SMC Result screen, and you can use the returned values to present different messages to the App user.

3. Understand the Computation

We will focus only on secure multiparty computation on this page. Once the user has entered their information in the Secure Compute screen, a object such as shown below is passed to the computation.

Object {
 "birthyear": 1950, 
 "country": 1, 
 "gender": 1, 
 "height": 166, 
 "weight": 81,
 "binary_1": 2, 
 "binary_2": 2, 

EnyaSMC.Input() accepts function.arguments as the input, so we extract an array from the object and use the .apply() method. Taking the above example data, the user's data array would be

[1950, 82, 166, 1, 1, 2, 2]

Assuming a simple linear computation in which the user's data are multiplied with an array of coefficients, and all terms are then summed, the MySecretAlgorithm coefficients could e.g. be:

[0.00005, 0.01, 0.005, 1, 1, 0.5, 0.5]

The result returned by model.secure_result would then be 5.7475, the dot product (the sum of the products of the corresponding entries of the two vectors) of user data values and algorithm coefficients.

/* pseudocode */
DOT([1950, 82, 166, 1, 1, 2, 2],[0.00005, 0.01, 0.005, 1, 1, 0.5, 0.5])
/* returns */
/* which is */