Branches:
master
: C++ addon for NodeJS, using node-addon-api - the OOP version of N-APIseal-wasm-external
: JavaScript (glue code) and WebAssembly files, using Emscriptenseal-wasm-embedded
: JavaScript with embedded WebAssembly, using Emscripten
Node.js port of SEAL C++ package released by Microsoft and containing homomorphic encryption primitives
Compile and build:
$ npm install
Then run a JS sample similar to example_bfv_basics_i()
from SEAL Examples :
$ npm run demo
or see our API in action:
$ npm start
var seal = require('bindings')('nodeseal');
The next statements create 4 contexts having the same encryption parameters (the scheme is 'BFV' by default):
var hc1 = seal.generateHomomorficContext();
var hc2 = new seal.HomomorphicContext();
var hc3 = new seal.HomomorphicContext(2048, 'coeff_modulus_128', 1<<8);
var hc4 = new seal.HomomorphicContext( hc3.getEncryptionParameters() );
The three parameters for hc3
are:
poly_modulus_degree
: Number - one of the values:1024
,2048
,4096
,8192
,16384
, or32768
coeff_modulus
: String - one of the values:"coeff_modulus_128"
,"coeff_modulus_192"
, or"coeff_modulus_256"
plain_modulus
: UINT64
GET/SET:
getEncryptionParameters()
//no setter; use HomomorphicContext(parms) insteadgetPublicKey()
setPublicKey()
getSecretKey()
setSecretKey()
INT32 <=> Ciphertext
converters:
encrypt()
decrypt()
Homomorphic arithmetic:
negate()
add()
sub()
multiply()
square()
The SEAL's EncryptionParameters
, PublicKey
, SecretKey
and Ciphertext
objects are serialized to/from the JS environment as Base64 encoded strings.
We adapted the module to build on both Windows 10 and Ubuntu 18.04 LTS (bionic), by adjusting:
- build parameters -
binding.gyp
- SEAL macrodefinitions -
seal/util/config.h
to a common code; please inspect config.h
for the list of enabled / disabled SEAL macros.