@cofhe/sdk is the successor to cofhejs, redesigned around an explicit, builder-pattern API that gives you full control over encryption, decryption, and ACP management.
Why migrate?
- Explicit API: no more implicit initialization or auto-generated ACPs. Every action is opt-in.
- Builder pattern:
encryptInputs,decryptForView, anddecryptForTxuse a chainable builder so you can set overrides (account, chain, callbacks) before calling.execute(). decryptForTxfeature:cofhejsdoes not provide an API for generating decryption signatures for onchain usage.- Deferred key loading: FHE keys and TFHE WASM are fetched lazily on the first
encryptInputscall, not during initialization. - Better multichain support: configure multiple chains up front and override per-call.
- Structured errors: typed
CofheErrorobjects with error codes replace theResultwrapper.
Requirements
- Node.js 18+
- TypeScript 5+
- Viem 2+
Installation
Removecofhejs and install @cofhe/sdk:
1. Initialization
The singlecofhejs.initializeWithEthers(...) / cofhejs.initializeWithViem(...) call is replaced by a three-step flow: create a config, create a client, then connect. FHE keys and WASM are no longer fetched eagerly during init, they are deferred until the first encryptInputs call.
Changes
Changes
Before (cofhejs)
After (@cofhe/sdk)
2. Encrypting inputs
cofhejs.encrypt(...) is replaced by a builder: client.encryptInputs([...]).setConsumingContract(address).execute(). setConsumingContract is required, because the verifier binds that address into the batch signature.
Changes
Changes
Before (cofhejs)
After (@cofhe/sdk)
The
Encryptable factory functions (Encryptable.uint32(...), Encryptable.bool(...), etc.) work the same way in both libraries.3. Decrypting / Unsealing
cofhejs has a single unseal function. @cofhe/sdk splits decryption into two purpose-built methods:
decryptForView: returns the plaintext for UI display (no onchain signature).decryptForTx: returns the plaintext and a Threshold Network signature for onchain verification.
Changes
Changes
Before (cofhejs)
After (@cofhe/sdk): viewing in UI
After (@cofhe/sdk): publishing onchain
4. Access Control Permissions
ACPs, whichcofhejs called permits, are no longer auto-generated during initialization. All ACP operations are now explicit through client.acp.
Changes
Changes
Before (cofhejs)
After (@cofhe/sdk)
5. Error handling
Before (cofhejs)
After (@cofhe/sdk)
6. Import path changes
7. Type renames
cofhejs had one input type per encrypted value. @cofhe/sdk 0.7 has none. encryptInputs returns plain ciphertext handles, and the signature that authenticates them covers the whole batch.
The
EncryptedItemInput family that 0.5 and 0.6 used as the replacement was itself removed in 0.7, along with asHashPlusProof().