Giter Club home page Giter Club logo

fhe-module-typescript-wrapper's Introduction

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

EasyFHE Typescript

A Fully Homomorphic Encryption WebAssembly module written in Rust based on Microsoft SEAL and node-SEAL homomorphic encryption libraries with Typescript bindings
Explore the docs »

· Report Bug · Request Feature ·

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Logo

The goal is to replace the current economic model of websites' monetization. Rather than showing paid ads, that confuse and annoy people, the websites could use some of the processing power of people's devices to make several computation on some chunks of data.

(back to top)

Built With

This implementation was possible with the help of certain languages, frameworks and libraries. The main used technologies are :

(back to top)

Getting Started

In order to use you just need to clone / fork / download this repository.

Prerequisites

In order for the library to work you need the following:

The library is tested on a Vue.js webapp which uses as framework quasar

  • npm
    npm install npm@latest -g
  • quasar
    npm install -g @quasar/cli

Installation

This is a example of installation on a quasar project

  1. Create a quasar project

    quasar create <project_name>
  2. Clone the repo

    git clone https://github.com/mihailpreda/fhe-wasm-module.git easyFHE
  3. Put into the project package.json dependecy property the following:

    easyFHE : file:../easyFHE
    
  4. Add into quasar.conf.js in webpack configuration into the build property, the following: (immediate after chainWebpack(chain){...} )

       extendWebpack(cfg) {
         cfg.experiments = {
           asyncWebAssembly: true
         }
       },

    For better understanding, check this quasar.conf.js sample

(back to top)

Usage

Example.vue

<template>
  <q-page> </q-page>
</template>

<script>
import { defineComponent } from "vue";
import getFheModule from "easyFHE";

export default defineComponent({
  name: "Example",
  async mounted() {
    const module = await getFheModule();
    const [publicKey, secretKey] = module.generateKeys();

    const plainText1 = new Uint8Array(10).fill(10);
    const encrypted1 = module.encrypt(plainText1, publicKey);
    const add = new Uint8Array(10).fill(5);
    const result1 = module.addConstantToCipher(encrypted1, add);
    const decryptedResult1 = module.decrypt(result1, secretKey);
    console.log("Decrypted addition: 10 + 5 = 15", decryptedResult1);

    const plainText2 = new Uint8Array(10).fill(10);
    const encrypted2 = module.encrypt(plainText2, publicKey);
    const sub = new Uint8Array(10).fill(7);
    const result2 = module.subtractConstantFromCipher(encrypted2, sub);
    const decryptedResult2 = module.decrypt(result2, secretKey);
    console.log("Decrypted subtraction: 10 - 7 = 3", decryptedResult2);

    const plainText3 = new Uint8Array(10).fill(10);
    const encrypted3 = module.encrypt(plainText3, publicKey);
    const mul = 8;
    const result3 = module.multiplyCipherByConstant(encrypted3, mul);
    const decryptedResult3 = module.decrypt(result3, secretKey);
    console.log("Decrypted multiplication: 10 * 8 = 80", decryptedResult3);

    const plainText4 = new Uint8Array(10).fill(20);
    const encrypted4 = module.encrypt(plainText4, publicKey);
    const div = new Uint8Array(10).fill(2);
    const iteration = 5;
    const result4 = module.divideCipherByConstant(encrypted4, div, iteration);
    const decryptedResult4 = module.decrypt(result4, secretKey);
    console.log("Decrypted division v1: 20 / 2 = 10", decryptedResult4);

    const plainText5 = new Uint8Array(10).fill(20);
    const plainText6 = new Uint8Array(10).fill(27);
    const encrypted5 = module.encrypt(plainText5, publicKey);
    const encrypted6 = module.encrypt(plainText6, publicKey);
    const result5 = module.addCiphers(encrypted5, encrypted6);
    const decryptedResult5 = module.decrypt(result5, secretKey);
    console.log(
      "Decrypted addition of 2 cipher texts v1: 20 + 27 = 47",
      decryptedResult5
    );

    const plainText7 = new Uint8Array(10).fill(78);
    const encrypted7 = module.encrypt(plainText7, publicKey);
    const encrypted8 = module.rerandomize(encrypted7, publicKey);
    const result6 = module.decrypt(encrypted7, secretKey);
    const result7 = module.decrypt(encrypted8, secretKey);
    console.log("Rerandomization example:");
    console.log("Initial encrypted values", encrypted7);
    console.log("Rerandozied encrypted values", encrypted8);
    console.log("Decrypted initial encrypted values", result6);
    console.log("Decrypted rerandomized encrypted values", result7);
  },
});
</script>

For better understanding, check this Example.vue sample

(back to top)

Roadmap

  • Generate keypair
  • Serialization of public key and secret key
  • Basic arithmetic operations between plaintexts and ciphertexts (Add / subtract / multiply / divide by a constant)
  • Exponentiation of a ciphertext
  • Improve processing speed
  • Improve memory usage

See the open issues for a full list of proposed features (and known issues).

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Preda Mihail Irinel - [email protected]

Project Link: https://github.com/mihailpreda/fhe-module-wasm

(back to top)

Acknowledgments

This project is a proof of concept developed for master's thesis and is neither production ready in terms of optimization, nor bug free.

(back to top)

fhe-module-typescript-wrapper's People

Contributors

mihailpreda avatar mmihaipreda avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.