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: Your First Secure Computation
After installing the SDK, use algo_add.py to name and parametrize your linear algorithm. This Python script is located in the /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';
EnyaSMC.Configure({
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, ...];
EnyaSMC.input(user_data_array);
// if the data are provided as an object
const user_data_object = {data_1: number, data_2: number, data_3: number, ...};
EnyaSMC.input(Object.values(user_data_object));
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.
EnyaSMC.Linear()
Note: This method is asynchronous. Use promises to handle the asynchronous result of the operation. Suitable example code is:
EnyaSMC.Linear().then(function(result{
console.log(result)
}))