node-seal

Homomorphic Encryption for TypeScript or JavaScript - Microsoft SEAL

https://github.com/s0l0ist/node-seal

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.4%) to scientific vocabulary

Keywords

crypto cryptography cryptosystem emscripten encryption homomorphic homomorphic-encryption homomorphism javascript microsoft microsoft-seal node-seal seal web-assembly webassembly
Last synced: 6 months ago · JSON representation ·

Repository

Homomorphic Encryption for TypeScript or JavaScript - Microsoft SEAL

Basic Info
Statistics
  • Stars: 206
  • Watchers: 5
  • Forks: 25
  • Open Issues: 0
  • Releases: 12
Topics
crypto cryptography cryptosystem emscripten encryption homomorphic homomorphic-encryption homomorphism javascript microsoft microsoft-seal node-seal seal web-assembly webassembly
Created over 6 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation

README.md

node-seal · GitHub license codecov npm version FOSSA Status

node-seal is a homomorphic encryption library for TypeScript or JavaScript.

  • Web Assembly: Fastest web implementation of the C++ Microsoft SEAL library
  • Zero dependencies: Very lean, only contains a low level API which is very close to the C++ calls from Microsoft SEAL.
  • Node.js, Browser: Install once, work in any server/client configuration.

Now supporting Microsoft SEAL 4.1.2

Installation

node-seal can be installed with your favorite package manager:

shell npm install node-seal

shell yarn add node-seal

Import the library using import or require syntax:

javascript // Auto-detects browser or nodejs. // Defaults to "node-seal/throws_wasm_node_umd" for NodeJS // Defaults to "node-seal/throws_wasm_web_umd" for Browsers // Defaults to "node-seal/throws_wasm_web_es" for Modules import SEAL from 'node-seal' const SEAL = require('node-seal')

You may also specify a deep import to target your environment better. This is useful for environments that aren't detected properly or do not support WebAssembly. In addition, there are two separate bundles for throwing on transparent ciphertexts and another for allowing transparent ciphertexts. If you're unsure what you need, start with the build that throws on transparent ciphertexts. This is also the default import that is used.

The deep import link is structured like the following:

node-seal / <throws|allows>_wasm_<node|web|worker>_<umd|es>

```javascript // Always Pick a variant which throws on transparent ciphertexts unless you // have a specific reason to allow the use of transparent ciphertexts. import SEAL from 'node-seal/throwswasmnode_umd'

// Or pick a variant which allows transparent ciphertexts (only use this if you know what you're doing) import SEAL from 'node-seal/allowswasmnode_umd' ```

React-Native

React-native does not support Wasm libraries; however, it is possible to run a Wasm library, including node-seal by using a WebView to load both the library and a simple interface to communicate with on top of the built-in postMessage API. Instead of publicly hosting the web application to be rendered by the WebView, it is possible to bundle the mini web application into a single HTML file (with JS inlined) and load the HTML file directly to the WebView.

Cloudflare Workers

The Wasm library needs to be explicitly imported, it will be compiled and provided by the Cloudflare Workers runtime. Example:

```javascript import SEAL from 'node-seal/throwswasmcfworkeres' import wasm from 'node-seal/sealthrowswasmcfworker.wasm'

export default { async fetch(request) { const seal = await SEAL(wasm) return new Response(seal.Version) } } ```

Demo

Go to the sandbox

This sandbox was built for users to experiment and learn how to use Microsoft SEAL featuring node-seal.

  • Encryption Parameters: experiment with many settings to prototype a context.
  • Keys: Create, download, upload Secret/Public Keys - even for Relinearization and Galois Keys.
  • Variables: Create, download, upload PlainTexts or CipherTexts
  • Functions: Create a list of HE functions to execute!
  • Code Generation: After your experimentation is complete, generate working code to use!

Usage

Checkout the basics

Documentation

View the latest docs here

Examples

Check out the Sandbox to run HE functions and even generate working code!

If you'd rather read an example, take a look here.

For more exhaustive examples, view the tests.

Changes

For changes in this library, take a look here.

For changes in Microsoft SEAL, take a look at their list of changes.

Benchmarking

Microsoft SEAL has a native benchmark tool that we compile directly to WASM.

  1. npm run seal:build:bench
  2. npm run benchmark

Benchmark

Checkout the benchmark

Caveats

Conversion from C++ to Web Assembly has some limitations:

  • ±2^53 bit numbers: JavaScript uses 2^53 numbers (not true 64 bit). This means we lose some precision after cryptographic operations are computed in WASM and we want to send the results to JS for consumption (across the WASM <> JS boundary). If you're using the CKKS scheme, you need to keep this in mind. BFV users will inherently adhere to these limitations due to the Int32Array/Uint32Array TypedArrays. Recently, BFV users now have support for BigInt64Array/BigUint64Array TypedArrays but at a significant encode/decode penalty - encyption/evaluation/decryption performance is the same.

  • Memory: Generating large keys and saving them in the browser could be problematic. We can control NodeJS heap size, but not inside a user's browser.

Saving keys is very memory intensive especially for polyModulusDegreess above 16384. This is because there's currently no way (that we have found) to use io streams across JS and Web Assembly code, so the strings have to be buffered completely in RAM and they can be very, very large when using the default zstd compression. User's who are experiencing OOM exceptions when saving GaloisKeys should try specifying a compression override such as none or the less performant zlib. Ex: galoisKeys.save(seal.ComprModeType.zlib)

  • Garbage Collection: By default, when a JavaScript object is dereferenced, the underlying WebAssembly (C++) object remains in memory.

You have two options for cleanup:

  • In performance-sensitive code (e.g. tight loops), explicitly call <instance>.delete() to release memory immediately.
  • If the environment supports FinalizationRegistry, the C++ resources will be released automatically once the object is garbage collected.

Contributing

The main purpose of this library is to continue to evolve and promote the adoption of homomorphic encryption (using Microsoft SEAL) in modern web applications today. Development of node-seal happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements.

See CONTRIBUTING.md.

License

node-seal is MIT licensed.

FOSSA
Status

Owner

  • Name: Nick Angelou
  • Login: s0l0ist
  • Kind: user
  • Location: Austin, Texas, USA

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use node-seal in your research, please cite it as below."
authors:
- family-names: "Angelou"
  given-names: "Nick"
  orcid: "https://orcid.org/0000-0001-7423-158X"
title: "node-seal, a Homomorphic Encryption library for TypeScript or JavaScript using Microsoft SEAL"
version: 6.0.0
doi: 10.5281/zenodo.1234
date-released: 2022-03-19
url: "https://github.com/s0l0ist/node-seal"

GitHub Events

Total
  • Create event: 5
  • Issues event: 5
  • Release event: 2
  • Watch event: 16
  • Delete event: 4
  • Issue comment event: 9
  • Push event: 13
  • Pull request review comment event: 6
  • Pull request review event: 5
  • Pull request event: 7
Last Year
  • Create event: 5
  • Issues event: 5
  • Release event: 2
  • Watch event: 16
  • Delete event: 4
  • Issue comment event: 9
  • Push event: 13
  • Pull request review comment event: 6
  • Pull request review event: 5
  • Pull request event: 7

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 35
  • Total pull requests: 75
  • Average time to close issues: 28 days
  • Average time to close pull requests: about 13 hours
  • Total issue authors: 24
  • Total pull request authors: 5
  • Average comments per issue: 2.8
  • Average comments per pull request: 0.13
  • Merged pull requests: 74
  • Bot issues: 0
  • Bot pull requests: 13
Past Year
  • Issues: 2
  • Pull requests: 3
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 21 minutes
  • Issue authors: 2
  • Pull request authors: 1
  • Average comments per issue: 3.0
  • Average comments per pull request: 0.33
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • amlwwalker (5)
  • AmitKawad (5)
  • alyai-ssvinoth22 (2)
  • eakeakarat (2)
  • patriciaOrtuno28 (2)
  • AZMCode (1)
  • nandsmalho (1)
  • starpl (1)
  • faustovanin (1)
  • Jongsic (1)
  • giammarcoromagnoli (1)
  • ekampp (1)
  • miaaaahmed97 (1)
  • iHaroon29 (1)
  • nk307 (1)
Pull Request Authors
  • s0l0ist (63)
  • dependabot[bot] (13)
  • fossabot (1)
  • willclarktech (1)
  • anish-yadav (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (13)

Packages

  • Total packages: 1
  • Total downloads:
    • npm 6,458 last-month
  • Total docker downloads: 171
  • Total dependent packages: 9
  • Total dependent repositories: 25
  • Total versions: 116
  • Total maintainers: 1
npmjs.org: node-seal

Homomorphic Encryption for TypeScript or JavaScript using Microsoft SEAL

  • Versions: 116
  • Dependent Packages: 9
  • Dependent Repositories: 25
  • Downloads: 6,458 Last month
  • Docker Downloads: 171
Rankings
Docker downloads count: 1.1%
Dependent packages count: 2.3%
Dependent repos count: 2.5%
Average: 3.2%
Downloads: 3.8%
Stargazers count: 4.3%
Forks count: 5.1%
Maintainers (1)
Last synced: 6 months ago

Dependencies

package-lock.json npm
  • 776 dependencies
package.json npm
  • @babel/core ^7.17.5 development
  • @babel/preset-env ^7.16.11 development
  • @rollup/plugin-alias ^3.1.9 development
  • @rollup/plugin-json ^4.1.0 development
  • @rollup/plugin-typescript ^8.3.1 development
  • @types/jest ^27.4.1 development
  • @typescript-eslint/eslint-plugin ^5.13.0 development
  • @typescript-eslint/parser ^5.13.0 development
  • better-docs ^2.7.2 development
  • codecov ^3.8.3 development
  • env-cmd ^10.1.0 development
  • eslint ^8.10.0 development
  • eslint-config-prettier ^8.4.0 development
  • eslint-plugin-jest ^26.1.1 development
  • eslint-plugin-jsdoc ^37.9.6 development
  • eslint-plugin-prettier ^4.0.0 development
  • esm ^3.2.25 development
  • jest ^27.5.1 development
  • jsdoc ^3.6.10 development
  • path ^0.12.7 development
  • prettier ^2.5.1 development
  • rollup ^2.69.0 development
  • rollup-plugin-node-builtins ^2.1.2 development
  • rollup-plugin-node-globals ^1.4.0 development
  • rollup-plugin-terser ^7.0.2 development
  • rollup-plugin-typescript2 ^0.31.2 development
  • ts-jest ^27.1.3 development
  • typescript ^4.6.2 development
.github/workflows/ci.yml actions
  • actions/cache v3 composite
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/setup-node v3 composite
  • actions/upload-artifact v3 composite
  • codecov/codecov-action v3 composite
.github/workflows/docs.yml actions
  • actions/checkout v3 composite
  • actions/configure-pages v3 composite
  • actions/deploy-pages v1 composite
  • actions/setup-node v3 composite
  • actions/upload-pages-artifact v1 composite