
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
node-seal
Advanced tools
Homomorphic Encryption for TypeScript or JavaScript using Microsoft SEAL
node-seal is a homomorphic encryption library for TypeScript or JavaScript.
Now supporting Microsoft SEAL 4.1.2
node-seal can be installed with your favorite package manager:
npm install node-seal
yarn add node-seal
Import the library using import
or require
syntax:
// 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>
// 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/throws_wasm_node_umd'
// Or pick a variant which allows transparent ciphertexts (only use this if you know what you're doing)
import SEAL from 'node-seal/allows_wasm_node_umd'
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.
The Wasm library needs to be explicitly imported, it will be compiled and provided by the Cloudflare Workers runtime. Example:
import SEAL from 'node-seal/throws_wasm_cf_worker_es'
import wasm from 'node-seal/seal_throws_wasm_cf_worker.wasm';
export default {
async fetch(request) {
const seal = await SEAL(wasm);
return new Response(seal.Version);
},
};
Go to the sandbox
This sandbox was built for users to experiment and learn how to use Microsoft SEAL featuring node-seal.
Checkout the basics
View the latest docs here
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.
For changes in this library, take a look here.
For changes in Microsoft SEAL, take a look at their list of changes.
Microsoft SEAL has a native benchmark tool that we compile directly to WASM.
npm run seal:build:bench
npm run benchmark
Checkout the benchmark
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 polyModulusDegrees
s
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: Unfortunately, the typical way of cleaning up dereferenced JS objects will leave behind a the Web Assembly (C++) object in memory. There is no way to automatically call the destructors on C++ objects. JavaScript code must explicitly delete any C++ object handles it has received, or the heap will grow indefinitely.
<instance>.delete()
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.
node-seal is MIT licensed.
Version 5.1.6
Feat:
Chore:
FAQs
Homomorphic Encryption for TypeScript or JavaScript using Microsoft SEAL
The npm package node-seal receives a total of 353 weekly downloads. As such, node-seal popularity was classified as not popular.
We found that node-seal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.