@randomredltd/mm-homomorphic
v1.2.2
Published
MorphMetro Homomorphic library
Readme
MorphMetro - Homomorphic calculations library
About
Homomorphic-lib is used to calculate two metrics (z-score and E_n number) that are used during ILC (Inter Laboratory Comparison) and PT (Proficiency Testing). All accredited measuring laboratories are required to periodically conduct ILC/PT. They do so by comparing their measurements with referent data provided by the referent laboratory.
To use homomorphic-lib, two data sets are needed. First is the referent data which consists of 3 to 10 referent values (X_RD) and one value representing measuring uncertainty of the referent laboratory (U_RD). Second data set is the data from the accredited measuring laboratory. It consists of 3 to 10 measured values (X_MD) and one value representing the uncertainty of the measuring laboratory (U_MD).
To calculate two metrics (z-score and E_n number) the following equations are used:
$z=(X_{MD}-X_{RD})/S_{MD}$
$E_n=(X_{MD}-X_{RD})/\sqrt{U_{MD}2+U_{RD}2}$
,where
$X_{MD}$ – average value of measured data
$X_{RD}$ – average value of referent data
$S_{MD}$ – standard deviation of measured data
$U_{MD}$ – expanded measurement uncertainty of measured data
$U_{RD}$ – expanded measurement uncertainty of referent data
From equations it can be seen that for calculation of z-score and E_n number, both referent and measured data are required. To preserve data privacy, homomorphic-lib encrypts both data sets and performs the calculations in encrypted form by using homomorphic encryption (Microsoft SEAL library).
Install
Install all packages
npm iTest
Run tests
npm run testBuild
Build and bundle with webpack
npm run build:prodPublish to NPM
Publish to RandomRed internal NPM
npm run co:login
npm run publishExample usage
Example usage of the library
const {generateKeys, referenceLabCalculation, measuringLabCalculation, referenceLabFinalCalculation} = require('mm-homomorphic')
//******************************************
// REFERENCE LABORATORY
const referenceData = [3.65, 3.72, 3.77, 3.68, 3.73, 3.72, 3.70, 3.71];
const uBRD = 0.02;
const {secretKey, publicKey, relin_keys, galKeys} = await generateKeys();
const {cipher_average_RD, cipher_u_RD_square} = await referenceLabCalculation(publicKey, secretKey, referenceData, uBRD )
//******************************************
//******************************************
// MEASURING LABORATORY
// measured data input
const measured_data = [3.45, 3.74, 3.854, 3.54, 3.71];
const uB_MD = 0.05;
const {cipher_z_score, cipher_En} = await measuringLabCalculation(cipher_average_RD, publicKey, relin_keys, cipher_u_RD_square, measured_data, uB_MD);
//******************************************
//******************************************
// REFERENCE LABORATORY
const results = await referenceLabFinalCalculation(cipher_z_score, publicKey, cipher_En, secretKey)
//******************************************Acknowledgments
This package was developed under MorphMetro project, funded by the EU in the framework of the NGI TRUSTCHAIN project, grant No. 101093274.
