This repo contains the full toolkit for interacting with Fhenix's CoFHE coprocessor. The repo is split into the following packages:
@cofhe/sdkCore SDK that fetches FHE keys, encrypts inputs, decrypts handles, and exposes subpath modules such as@cofhe/sdk/adapters,@cofhe/sdk/permits,@cofhe/sdk/web, and@cofhe/sdk/node.@cofhe/reactReact-specific hooks and pre-built components for building CoFHE-enabled frontends.@cofhe/mock-contractsMock contracts replicating the off-chain CoFHE functionality on-chain for local testing.@cofhe/hardhat-pluginHardhat plugin that deploys mock contracts and provides utilities for testing CoFHE flows.
This is a community-maintained example. If you experience a problem, please submit a pull request with a fix. GitHub Issues will be closed.
Run the following command:
npx create-turbo@latest -e with-changesetsThis Turborepo includes the following:
@cofhe/sdk: Core SDK with adapters, permits, node, and web subpath exports.@cofhe/react: React bindings and components built on top of the core SDK.@cofhe/mock-contracts: Solidity contracts and build pipeline for local CoFHE testing.@cofhe/hardhat-plugin: Hardhat integration that deploys mock contracts and exposes CoFHE utilities.@cofhe/hardhat-plugin(tests): Tests for the hardhat-plugin.@cofhe/eslint-config: Shared ESLint preset.@cofhe/tsconfig: Shared TypeScript configuration.
Each package and app is 100% TypeScript.
This Turborepo has some additional tools already setup for you:
- TypeScript for static type checking
- ESLint for code linting
- Prettier for code formatting
pnpm build- Build all packagespnpm dev- Develop all packagespnpm lint- Lint all packagespnpm changeset- Generate a changesetpnpm clean- Clean up allnode_modulesanddistfolders (runs each package's clean script)
To see the React components in action:
# Run the interactive example
./run-example.sh
# Or manually:
cd example && pnpm devVisit http://localhost:3000 to explore all React components with live examples.
The npm organization scope for this design system starter is @cofhe. To change this, it's a bit manual at the moment, but you'll need to do the following:
- Rename folders in
packages/*to replaceacmewith your desired scope - Search and replace
acmewith your desired scope - Re-run
yarn install
Package publishing has been configured using Changesets. Please review their documentation to familiarize yourself with the workflow.
This example comes with automated npm releases setup in a GitHub Action. To get this working, you will need to create an NPM_TOKEN and GITHUB_TOKEN in your repository settings. You should also install the Changesets bot on your GitHub repository as well.
For more information about this automation, refer to the official changesets documentation
If you want to publish package to the public npm registry and make them publicly available, this is already setup.
To publish packages to a private npm organization scope, remove the following from each of the package.json's
- "publishConfig": {
- "access": "public"
- },See Working with the npm registry
Type CofheInUint8 -> EncryptedUint8Input
- Fhe keys aren't fetched until
client.encryptInputs(...).encrypt(), they aren't used anywhere else other than encrypting inputs, so their fetching is deferred until then. - Initializing the tfhe wasm is also deferred until
client.encryptInputs(...).encrypt()is called