Skip to main content
@cofhe/sdk is the TypeScript client SDK for CoFHE. It handles the client-side operations required to interact with FHE-enabled smart contracts: encrypting inputs with ZK proofs, decrypting ciphertext 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

Encrypt Inputs

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

Requests decryption of a ciphertext handle via the Threshold Network using a permit. Returns the plaintext locally, not published on-chain.

Decrypt for Tx

Requests decryption and returns the plaintext with a Threshold Network signature for on-chain verification.

Manage Permits

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

The SDK follows a three-step lifecycle: config → client → connect.
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();

Key concepts

Quick Start

Install the SDK, write a contract, and run your first encrypt → store → decrypt test in minutes.

Encrypting Inputs

Encrypt plaintext values with ZK proofs before passing them to your smart contract.

Permits

Create and manage EIP-712 permits that authorize decryption of confidential data.

Decrypt to View

Reveal encrypted values locally for UI display using permits.

Decrypt to Transact

Decrypt with a verifiable Threshold Network signature for on-chain use.