New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@zama-fhe/tfhe-js

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zama-fhe/tfhe-js

TFHE-js is a JS wrapper for TFHE-rs client-side WASM API.

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-89.47%
Maintainers
1
Weekly downloads
 
Created
Source

TFHE-js

TFHE-js is a JS wrapper for TFHE-rs client-side WASM API.

This package includes:

  • High-level API which simplifies usage of TFHE-rs WASM (at the moment, only number)
  • TFHE-rs native wasm export

Install

npm i --save @zama-fhe/tfhe-js
yarn add @zama-fhe/tfhe-js

Usage

Importing the cks from passphrase and private enc/dec

import { createKeyFromPassPhrase } from '@zama-fhe/tfhe-js';

const instance1 = await createKeyFromPassPhrase({ passPhrase: 'beyond sorry curtain ...', withPublicKey: false });
let input = 3n;
let c1 = instance1.encryptToBase64(input);
let plaintext = instance1.decryptFromBase64(c1);
expect(input).toBe(plaintext);

Importing the cks from passphrase and pub enc private dec

Another example, importing a base64 secret key:

import { createKeyFromPassPhrase } from '@zama-fhe/tfhe-js';

const instance1 = await createKeyFromPassPhrase({ passPhrase: 'beyond sorry curtain ...', withPublicKey: true });
let input = 3n;
let c1 = instance1.encryptWithPublicKeyToBase64(input);
let plaintext = instance1.decryptFromBase64(c1);
expect(input).toBe(plaintext);

Importing a key and create a Key object

import { importKey, Key } from '@zama-fhe/tfhe-js';

const createKey = (cks) => {
  let secretKey = importKey(cks, 'hex');
  let input = 3n;
  const key = new Key({ secretKey });
  return key;
};

Generate cks and pks from passphrase

import { createKeyFromPassPhrase } from '@zama-fhe/tfhe-js';

const instance1 = await createKeyFromPassPhrase({
  passPhrase: 'churn agent language session winner drip present morning skirt early fiscal grit',
  withPublicKey: true,
});
let pks = instance1.exportPublicKey('hex');
let cks = instance1.exportKey('hex');
fs.writeFileSync('alice_pks.hex', pks as string);
fs.writeFileSync('alice_cks.hex', cks as string);

Use directly TFHE-rs WASM binding

import { TFHERs } from '@zama-fhe/tfhe-js';

const importKey = (key) => {
  let serialized_cks = Buffer.from(key, 'base64');
  return TFHERs.Shortint.deserialize_shortint_client_key(serialized_cks);
};

Use browser version

To use the browser version, first you need to load the wasm. For this, you need to use the initSDK method.

import { initSDK, createKeyFromPassPhrase } from '@zama-fhe/tfhe-js/browser';

const generateKey = async (key) => {
  let path = undefined;
  await initSDK(path); // you can replace path with a custom path if you store the wasm on a specific address

  const key = await createKeyFromPassPhrase({
    passPhrase: 'churn agent language session winner drip present morning skirt early fiscal grit',
  });
  return key;
};

Development

Install dependencies

npm i

Run test

npm run test

Up to date pkg

To get the last version of this package which contains the wasm package and the JS API, check this repo that explains how to generate it.

#web
make build_web_js_api
cp pkg/tfhe* tfhe-rs/browser/

#node
make build_node_js_api
cp pkg/tfhe* tfhe-rs/node/


Once generated copy web version in vendors/pkg folder and the nodejs version into vendors/pkg/mocks folder.

Keywords

FAQs

Package last updated on 03 Feb 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc