Cofhe SDK
@cofhe/sdk is the TypeScript client for CoFHE. It handles the client-side operations required to interact with FHE-enabled smart contracts: encrypting inputs with ZK proofs, decrypting handles via the Threshold Network, and managing EIP-712 permits for access control.
On-chain, contracts use FHE.sol to operate on encrypted data. Off-chain, this SDK prepares the inputs and reads the outputs.
What the SDK does
| Operation | Function | Description |
|---|---|---|
| Encrypt inputs | client.encryptInputs([...]).execute() | Packs plaintext values, generates a ZKPoK, and submits them to the CoFHE verifier. Returns signed EncryptedItemInput objects for use in contract calls. |
| Decrypt for view | client.decryptForView(ctHash, utype).execute() | Requests decryption of a ciphertext handle using a permit. Returns the plaintext locally (not published on-chain). |
| Decrypt for tx | client.decryptForTx(ctHash).execute() | Requests decryption and returns the plaintext with a Threshold Network signature. The signature can be verified on-chain via FHE.verifyDecryptResult(...). |
| Manage permits | client.permits.createSelf(...) / getOrCreateSelfPermit() | Creates, stores, and manages EIP-712 permits that authorize decryption of specific ciphertext handles. |
Entrypoints
| Entrypoint | Contents |
|---|---|
@cofhe/sdk | Core types (Encryptable, FheTypes, EncryptStep, CofheError), shared across runtimes |
@cofhe/sdk/web | createCofheConfig / createCofheClient with browser defaults (IndexedDB storage, TFHE WASM, Web Workers) |
@cofhe/sdk/node | createCofheConfig / createCofheClient with Node.js defaults (filesystem storage, node-tfhe) |
@cofhe/sdk/permits | Permit creation, validation, serialization, and storage utilities |
@cofhe/sdk/adapters | Ethers5Adapter, Ethers6Adapter, WagmiAdapter, HardhatSignerAdapter |
@cofhe/sdk/chains | Built-in chain definitions and getChainById / getChainByName helpers |
// Browser
import { createCofheConfig, createCofheClient } from '@cofhe/sdk/web';
// Node.js
import {
createCofheConfig as createCofheConfigNode,
createCofheClient as createCofheClientNode,
} from '@cofhe/sdk/node';
// Shared
import { Encryptable, FheTypes } from '@cofhe/sdk';
import { chains } from '@cofhe/sdk/chains';
import { Ethers6Adapter } from '@cofhe/sdk/adapters';Client lifecycle
createCofheConfig({ supportedChains }) → createCofheClient(config) → client.connect(publicClient, walletClient)import { createCofheConfig, createCofheClient } from '@cofhe/sdk/web';
import { Encryptable, FheTypes } from '@cofhe/sdk';
import { chains } from '@cofhe/sdk/chains';
const config = createCofheConfig({
supportedChains: [chains.sepolia],
});
const client = createCofheClient(config);
await client.connect(publicClient, walletClient);
// Encrypt and send
const [encrypted] = await client
.encryptInputs([Encryptable.uint64(100n)])
.execute();
await contract.deposit(encrypted);
// Decrypt for UI
await client.permits.getOrCreateSelfPermit();
const ctHash = await contract.getBalance();
const balance = await client
.decryptForView(ctHash, FheTypes.Uint64)
.execute();Hardhat plugin
@cofhe/hardhat-plugin deploys mock versions of the CoFHE on-chain components (TaskManager, ACL, ZK verifier, Threshold Network) onto the Hardhat network, so you can compile and test FHE contracts without the off-chain infrastructure.
The plugin extends hre with hre.cofhe:
import hre from 'hardhat';
const [signer] = await hre.ethers.getSigners();
const cofheClient = await hre.cofhe.createClientWithBatteries(signer);The mock TaskManager stores plaintext values on-chain, so you can assert encrypted state directly:
await hre.cofhe.mocks.expectPlaintext(ctHash, 42n);Mocks are deployed automatically before npx hardhat test. FHE operation logging is built in.
Pages
- Quick Start — install, write a contract, run a test.
- Client — config, connect, adapters, connection lifecycle.
- Encrypting Inputs — prepare encrypted inputs for a contract call.
- Decrypting to View — decrypt ciphertext handles for UI display.
- Decrypting to Transact — decrypt with a verifiable signature for on-chain use.
- Permits — create and manage decryption authorization.
- Hardhat Getting Started — plugin setup and first test.
- Mock Contracts —
getPlaintext,expectPlaintext, mock contract access. - Migrating from
cofhejs— side-by-side API mapping for existing cofhejs users.