@cofhe/sdk is the successor to cofhejs, redesigned around an explicit, builder-pattern API that gives you full control over encryption, decryption, and permit management.
Why migrate?
- Explicit API — no more implicit initialization or auto-generated permits. 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 on-chain 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
cofhejs | @cofhe/sdk | |
|---|---|---|
| Entry | cofhejs.initializeWithEthers(...) / cofhejs.initializeWithViem(...) | createCofheConfig(...) → createCofheClient(config) → client.connect(...) |
| Key fetching | Immediate (during init) | Deferred (first encryptInputs call) |
| WASM init | Immediate (during init) | Deferred (first encryptInputs call) |
| Environment | "LOCAL" / "TESTNET" / "MAINNET" string | Chain objects via supportedChains: [chains.sepolia] |
| Provider format | Ethers provider/signer or viem clients | Always viem clients (use adapters for ethers) |
Before (cofhejs)
After (@cofhe/sdk)
2. Encrypting inputs
cofhejs.encrypt(...) is replaced by a builder: client.encryptInputs([...]).execute().
Changes
Changes
cofhejs | @cofhe/sdk | |
|---|---|---|
| Function | cofhejs.encrypt([...], callback) | client.encryptInputs([...]).execute() |
| Return value | Result<T> with .success / .data / .error | Direct value (throws CofheError on failure) |
| Progress callback | Second argument to encrypt | .onStep(callback) on the builder |
| Overrides | Not available | .setAccount(...), .setChainId(...), .setUseWorker(...) |
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 on-chain signature).decryptForTx— returns the plaintext and a Threshold Network signature for on-chain verification.
Changes
Changes
cofhejs | @cofhe/sdk | |
|---|---|---|
| Function | cofhejs.unseal(sealed, type) | client.decryptForView(ctHash, type) or client.decryptForTx(ctHash) |
| Permit handling | Automatic (uses most recent permit) | Explicit — .withPermit() / .withoutPermit() |
| Return value | Result<bigint | boolean | string> | Direct value for view; { ctHash, decryptedValue, signature } for tx |
| On-chain verification | Not built in | decryptForTx returns a signature for FHE.publishDecryptResult(...) |
Before (cofhejs)
After (@cofhe/sdk) — viewing in UI
After (@cofhe/sdk) — publishing on-chain
4. Permits
Permits are no longer auto-generated during initialization. All permit operations are now explicit throughclient.permits.
Changes
Changes
cofhejs | @cofhe/sdk | |
|---|---|---|
| Auto-generation | generatePermit: true (default) | Never — always explicit |
| Creation | cofhejs.createPermit({ type, issuer }) | client.permits.createSelf(...), client.permits.createSharing(...) |
| Return type | Result<Permit> | Direct Permit object |
| Active permit | Implicitly used by unseal | getOrCreateSelfPermit() sets active; used automatically by decrypt methods |
Before (cofhejs)
After (@cofhe/sdk)
5. Error handling
Before (cofhejs)
After (@cofhe/sdk)
6. Import path changes
cofhejs | @cofhe/sdk |
|---|---|
cofhejs/node | @cofhe/sdk/node |
cofhejs/web | @cofhe/sdk/web |
| N/A | @cofhe/sdk (core types, Encryptable, FheTypes) |
| N/A | @cofhe/sdk/permits |
| N/A | @cofhe/sdk/adapters |
| N/A | @cofhe/sdk/chains |
7. Type renames
cofhejs | @cofhe/sdk |
|---|---|
CoFheInItem | EncryptedItemInput |
CoFheInBool | EncryptedBoolInput |
CoFheInUint8 | EncryptedUint8Input |
CoFheInUint16 | EncryptedUint16Input |
CoFheInUint32 | EncryptedUint32Input |
CoFheInUint64 | EncryptedUint64Input |
CoFheInUint128 | EncryptedUint128Input |
CoFheInAddress | EncryptedAddressInput |