diff --git a/docs/.gitbook/assets/Zama (3).png b/docs/.gitbook/assets/Zama (3).png deleted file mode 100644 index a726a92..0000000 Binary files a/docs/.gitbook/assets/Zama (3).png and /dev/null differ diff --git a/docs/.gitbook/assets/zama_fhevm_summary.png b/docs/.gitbook/assets/zama_fhevm_summary.png deleted file mode 100644 index f8559ab..0000000 Binary files a/docs/.gitbook/assets/zama_fhevm_summary.png and /dev/null differ diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index 06dce99..0000000 --- a/docs/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# What is Zama's fhEVM? - -📁 [Github](https://github.com/zama-ai/fhevm) | 💛 [Community support](https://zama.ai/community) | 🟹 [Zama Bounty Program](https://github.com/zama-ai/bounty-program) - -
- -## Bring confidential smart contracts to your blockchain with Zama's fhEVM - -There used to be a dilemma in blockchain: keep your application and user data on-chain, allowing everyone to see it, or keep it privately off-chain and lose contract composability. Thanks to a breakthrough in homomorphic encryption, Zama’s fhEVM makes it possible to run confidential smart contracts on encrypted data, guaranteeing both confidentiality and composability. - -## fhevmjs - -fhevmjs is a javascript library that enables developers to interact with blockchains using Zama's cutting-edge technology based on TFHE (Fully Homomorphic Encryption over the Torus). This library provides a seamless integration of TFHE encryption capabilities into web3 applications, allowing for secure and private interactions with smart contracts. - -## Solidity library - -The Solidity library we introduce is a powerful tool that empowers developers to manipulate encrypted data using TFHE within smart contracts. With this library, developers can perform computations over encrypted data, such as addition, multiplication, comparison and more, while maintaining the confidentiality of the underlying information. - -## Tutorials and Examples - -* [Workshop during ETHcc](https://www.youtube.com/watch?v=eivfVykPP8U) \[by Morten Dahl — Zama] -* [Confidential ERC-20 Tokens Using Homomorphic Encryption](https://www.zama.ai/post/confidential-erc-20-tokens-using-homomorphic-encryption) \[by \[ClĂ©ment Danjou — Zama] -* [On-chain Blind Auctions Using Homomorphic Encryption](https://www.zama.ai/post/on-chain-blind-auctions-using-homomorphic-encryption) \[by ClĂ©ment Danjou — Zama] -* [ERC-20](https://github.com/zama-ai/fhevm-solidity/blob/main/examples/EncryptedERC20.sol) -* [Blind Auction](https://github.com/zama-ai/fhevm-solidity/blob/main/examples/BlindAuction.sol) -* [Governor DAO](https://github.com/zama-ai/fhevm-solidity/tree/main/examples/Governor) -* [Mixnet](https://github.com/anonymousGifter/mixnet-core) \[by [Remi Gai](https://github.com/remi-gai)] -* [Battleship](https://github.com/battleship-fhevm/battleship-hardhat) \[by [Owen Murovec](https://github.com/omurovec)] -* [Darkpool](https://github.com/omurovec/fhe-darkpools) \[by [Owen Murovec](https://github.com/omurovec)] - - - diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md deleted file mode 100644 index 7484d6a..0000000 --- a/docs/SUMMARY.md +++ /dev/null @@ -1,24 +0,0 @@ -# Table of contents - -* [What is Zama's fhEVM?](README.md) - -## Contract - -* [Getting Started](solidity/getting\_started.md) -* [TFHE Library](solidity/library.md) -* [Function specifications](solidity/functions.md) -* [Decryption and control structures](solidity/decryption.md) - -## fhevmjs - -* [Getting Started](sdk/getting\_started.md) -* [Using the CLI](sdk/cli.md) -* [Setup an instance](sdk/instance.md) -* [Inputs](sdk/inputs.md) -* [Reencryption](sdk/reencryption.md) -* [Examples](sdk/examples.md) - -## Resources - -* [Tutorials](resources/tutorials.md) -* [Examples](resources/examples.md) diff --git a/docs/resources/examples.md b/docs/resources/examples.md deleted file mode 100644 index d804576..0000000 --- a/docs/resources/examples.md +++ /dev/null @@ -1,10 +0,0 @@ -# Examples - -## Contracts - -- [ERC-20](https://github.com/zama-ai/fhevm-solidity/blob/main/examples/EncryptedERC20.sol) -- [Blind Auction](https://github.com/zama-ai/fhevm-solidity/blob/main/examples/BlindAuction.sol) -- [Governor DAO](https://github.com/zama-ai/fhevm-solidity/tree/main/examples/Governor) -- [Mixnet](https://github.com/anonymousGifter/mixnet-core) by [Remi Gai](https://github.com/remi-gai) -- [Battleship](https://github.com/battleship-fhevm/battleship-hardhat) by [Owen Murovec](https://github.com/omurovec) -- [Darkpool](https://github.com/omurovec/fhe-darkpools) by [Owen Murovec](https://github.com/omurovec) diff --git a/docs/resources/tutorials.md b/docs/resources/tutorials.md deleted file mode 100644 index 76d5fe4..0000000 --- a/docs/resources/tutorials.md +++ /dev/null @@ -1,5 +0,0 @@ -# Tutorials - -- [Workshop during ETHcc](https://www.youtube.com/watch?v=eivfVykPP8U) by Morten Dahl (Zama) -- [Confidential ERC-20 Tokens Using Homomorphic Encryption](https://www.zama.ai/post/confidential-erc-20-tokens-using-homomorphic-encryption) by ClĂ©ment Danjou (Zama) -- [On-chain Blind Auctions Using Homomorphic Encryption](https://www.zama.ai/post/on-chain-blind-auctions-using-homomorphic-encryption) by ClĂ©ment Danjou (Zama) diff --git a/docs/sdk/cli.md b/docs/sdk/cli.md deleted file mode 100644 index 07977e9..0000000 --- a/docs/sdk/cli.md +++ /dev/null @@ -1,18 +0,0 @@ -# Using the CLI - -fhevmjs include a Command-Line Interface (CLI) tool. With this handy utility, you can encrypt 8/16/32bits integer with the blockchain's FHE public key. -To get started with fhevmjs CLI, first, ensure you have Node.js installed on your system. Next, install the fhevmjs package globally using the '-g' flag, which allows you to access the CLI tool from any directory: - -```bash -npm install -g fhevmjs -``` - -Once installed, `fhevm` command should be available. You can get all commands and options available with `fhevm help` or `fhevm encrypt help`. - -## Examples - -Encrypt 71721075 as 32bits integer: - -```bash -fhevm encrypt --node devnet.zama.ai 32 71721075 -``` diff --git a/docs/sdk/examples.md b/docs/sdk/examples.md deleted file mode 100644 index 530f53e..0000000 --- a/docs/sdk/examples.md +++ /dev/null @@ -1,129 +0,0 @@ -# Examples - -## Nodejs - -### Transfer ERC-20 tokens - -```javascript -const { createInstance } = require('fhevmjs'); -const { Wallet, JsonRpcProvider, Contract } = require('ethers'); - -const contractInfo = require('./EncryptedERC20.json'); - -const CONTRACT_ADDRESS = '0x309cf2aae85ad8a1db70ca88cfd4225bf17a7482'; - -const provider = new JsonRpcProvider(`https://devnet.zama.ai/`); - -const signer = new Wallet( - '0x92293977156de6e03b20b26708cb4496b523116190b5c32d77cee8286d0c41f6', - provider, -); - -let _instance; - -const getInstance = async () => { - if (_instance) return _instance; - - // 1. Get chain id - const network = await provider.getNetwork(); - const chainId = +network.chainId.toString(); // Need to be a number - - // Get blockchain public key - const publicKey = await provider.call({ - to: '0x0000000000000000000000000000000000000044', - }); - - // Create instance - _instance = createInstance({ chainId, publicKey }); - return _instance; -}; - -const transfer = async (to, amount) => { - // Initialize contract with ethers - const contract = new Contract(CONTRACT_ADDRESS, contractInfo.abi, signer); - // Get instance to encrypt amount parameter - const instance = await getInstance(); - const encryptedAmount = instance.encrypt32(amount); - - const transaction = await contract['transfer(address,bytes)']( - to, - encryptedAmount, - ); - return transaction; -}; - -transfer('0xa83a498Eee26f9594E3A784f204e507a5Fae3210', 10); -``` - -## Get balance - -```javascript -const { createInstance } = require('fhevmjs'); -const { Wallet, JsonRpcProvider, Contract } = require('ethers'); - -const contractInfo = require('./EncryptedERC20.json'); - -const CONTRACT_ADDRESS = '0x309cf2aae85ad8a1db70ca88cfd4225bf17a7482'; - -const provider = new JsonRpcProvider(`https://devnet.zama.ai/`); - -const signer = new Wallet( - '0x92293977156de6e03b20b26708cb4496b523116190b5c32d77cee8286d0c41f6', - provider, -); - -let _instance; - -const getInstance = async () => { - if (_instance) return _instance; - - // 1. Get chain id - const network = await provider.getNetwork(); - - const chainId = +network.chainId.toString(); - - // Get blockchain public key - const publicKey = await provider.call({ - to: '0x0000000000000000000000000000000000000044', - }); - - // Create instance - _instance = createInstance({ chainId, publicKey }); - return _instance; -}; - -const getBalance = async () => { - // Initialize contract with ethers - const contract = new Contract(CONTRACT_ADDRESS, contractInfo.abi, signer); - - // Get instance to encrypt amount parameter - const instance = await getInstance(); - - // Generate token to decrypt - const generatedToken = instance.generateToken({ - verifyingContract: CONTRACT_ADDRESS, - }); - - // Sign the public key - const signature = await signer.signTypedData( - generatedToken.token.domain, - { Reencrypt: generatedToken.token.types.Reencrypt }, // Need to remove EIP712Domain from types - generatedToken.token.message, - ); - instance.setTokenSignature(CONTRACT_ADDRESS, signature); - - // Call the method - const encryptedBalance = await contract.balanceOf( - generatedToken.publicKey, - signature, - ); - - // Decrypt the balance - const balance = instance.decrypt(CONTRACT_ADDRESS, encryptedBalance); - return balance; -}; - -getBalance().then((balance) => { - console.log(balance); -}); -``` diff --git a/docs/sdk/getting_started.md b/docs/sdk/getting_started.md deleted file mode 100644 index 8771934..0000000 --- a/docs/sdk/getting_started.md +++ /dev/null @@ -1,106 +0,0 @@ -# Getting Started - -Welcome to the documentation for fhevmjs, a JavaScript library that enables interaction with blockchain using Zama's technology! This comprehensive guide provides developers with detailed information on encryption of data using TFHE (Fully Homomorphic Encryption over the Torus) and generation of EIP-719 tokens for reencrypt data. - -## Installation - -To get started with fhevmjs, you need to install it as a dependency in your JavaScript project. You can do this using npm, Yarn or pnpm. Open your terminal and navigate to your project's directory, then run one of the following commands: - -```bash -# Using npm -npm install fhevmjs - -# Using Yarn -yarn add fhevmjs - -# Using pnpm -pnpm add fhevmjs -``` - -This will download and install the fhevmjs library and its dependencies into your project. - -## Quick start - -{% tabs %} -{% tab title="Node" %} -```javascript -const { createInstance } = require('fhevmjs'); -createInstance({ chainId, publicKey }).then((instance) => { - console.log(instance); -}); -``` -{% endtab %} - -{% tab title="Browser" %} -To use the library in your project, you need to load WASM of [TFHE](https://www.npmjs.com/package/tfhe) first with `initFhevm`. - -```javascript -import { BrowserProvider } from 'ethers'; -import { initFhevm, createInstance } from 'fhevmjs'; - -const createFhevmInstance = async () => { - const provider = new BrowserProvider(window.ethereum); - const network = await provider.getNetwork(); - const chainId = +network.chainId.toString(); - const publicKey = await provider.call({ - from: null, - to: '0x0000000000000000000000000000000000000044', - }); - return createInstance({ chainId, publicKey }); -}; - -const init = async () => { - await initFhevm(); // Load TFHE - return createFhevmInstance(); -}; - -init().then((instance) => { - console.log(instance); -}); -``` - -You can take a look at [this template](https://github.com/zama-ai/fhevmjs-react-template) for an example using Vite, React and TypeScript. - -### Troubleshooting - -#### Webpack: "Module not found: Error: Can't resolve 'tfhe\_bg.wasm'" - -In the codebase, there is a `new URL('tfhe_bg.wasm')` which triggers a resolve by Webpack. If yo u encounter an issue, you can add a fallback for this file by adding a resolve configuration in y our `webpack.config.js`: - -```javascript - resolve: { - fallback: { - 'tfhe_bg.wasm': require.resolve('tfhe/tfhe_bg.wasm'), - }, - }, -``` - -#### Issue with importing ESM version - -With a bundler such as Webpack or Rollup, imports will be replaced with the version mentioned in the `"browser"` field of the `package.json`. If you encounter issue with typing, you can use this [tsconfig.json](https://github.com/zama-ai/fhevmjs-react-template/blob/main/tsconfig.json) using TypeScript 5. - -If you encounter any other issue, you can force import of the browser package. - -```javascript -import { initFhevm, createInstance } from 'fhevmjs/web'; -``` - -#### Use bundled version - -If you have an issue with bundling the library (for example with some SSR framework), you can use the prebundled version available in `fhevmjs/bundle`. Just embed the library with a `