Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

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

OperationFunctionDescription
Encrypt inputsclient.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 viewclient.decryptForView(ctHash, utype).execute()Requests decryption of a ciphertext handle using a permit. Returns the plaintext locally (not published on-chain).
Decrypt for txclient.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 permitsclient.permits.createSelf(...) / getOrCreateSelfPermit()Creates, stores, and manages EIP-712 permits that authorize decryption of specific ciphertext handles.

Entrypoints

EntrypointContents
@cofhe/sdkCore types (Encryptable, FheTypes, EncryptStep, CofheError), shared across runtimes
@cofhe/sdk/webcreateCofheConfig / createCofheClient with browser defaults (IndexedDB storage, TFHE WASM, Web Workers)
@cofhe/sdk/nodecreateCofheConfig / createCofheClient with Node.js defaults (filesystem storage, node-tfhe)
@cofhe/sdk/permitsPermit creation, validation, serialization, and storage utilities
@cofhe/sdk/adaptersEthers5Adapter, Ethers6Adapter, WagmiAdapter, HardhatSignerAdapter
@cofhe/sdk/chainsBuilt-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