fhenix-sdk
/fhenix-sdk
Use when working with @cofhe/sdk in TypeScript — encrypting inputs, managing permits, choosing decrypt modes (decryptForView vs decryptForTx), or wiring CoFHE into a Next.js / wagmi / viem dApp. Activates on imports of @cofhe/sdk or its subpaths, on hooks named useCofhe* or usePermit*, and on prompts like "encrypt this input" or "set up cofhe in Next.js.
- Author
- fhenixprotocol ↗
- Repository
- fhenix-toolkit ↗
- Licence
- MIT
- Last repository change
- 01.10.2026
Assessment and security
- Files in this package
- 16
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 01.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when working with @cofhe/sdk in TypeScript — encrypting inputs, managing permits, choosing decrypt modes (decryptForView vs decryptForTx), or wiring CoFHE into a Next.js / wagmi / viem dApp. Activates on imports of @cofhe/sdk or its subpaths, on hooks named useCofhe* or usePermit*, and on prompts like "encrypt this input" or "set up cofhe in Next.js.
Triggers from the description
Original author description
Use when working with @cofhe/sdk in TypeScript — encrypting inputs, managing permits, choosing decrypt modes (decryptForView vs decryptForTx), or wiring CoFHE into a Next.js / wagmi / viem dApp. Activates on imports of @cofhe/sdk or its subpaths, on hooks named useCofhe* or usePermit*, and on prompts like "encrypt this input" or "set up cofhe in Next.js.
How it works
- Hard rules — never violate
- The three decryption modes
- Default init flow
- Default encrypt flow
- Default permit flow
- Concepts to read on demand
- Looking up @cofhe/sdk API surface
SKILL.md preview
---
name: fhenix-sdk
description: Use when working with @cofhe/sdk in TypeScript — encrypting inputs, managing permits, choosing decrypt modes (decryptForView vs decryptForTx), or wiring CoFHE into a Next.js / wagmi / viem dApp. Activates on imports of @cofhe/sdk or its subpaths, on hooks named useCofhe* or usePermit*, and on prompts like "encrypt this input" or "set up cofhe in Next.js."
---
# fhenix-sdk — integrate @cofhe/sdk in dApps
You activate when the user is writing TypeScript that uses Fhenix's `@cofhe/sdk` — initializing the client, encrypting inputs, managing permits, decrypting handles, or building React/Next.js hooks around any of the above.
## Hard rules — never violate
1. **Encryption is lazy.** SDK keys aren't fetched until the first `client.encryptInputs(...).execute()`. Don't await `createCofheClient` for crypto-readiness; only the first `.execute()` triggers the heavy init.
2. **`.connect(publicClient, walletClient)` is mandatory before any `.execute()`.** Without chain context, calls fail with opaque "no chain" errors.
3. **Permits are explicit — no auto-creation.** Unlike legacy `cofhejs`, the new SDK does NOT auto-generate permits. Call `client.permits.getOrCreateSelfPermit(...)` before any `decryptForView` or `decryptForTx().withPermit()` call. Verify the current signature via `references/lookup-recipes.md`.
4. **Permit expiration is Unix SECONDS, not milliseconds.** `Date.now()` returns ms — divide by 1000.
5. **`decryptForTx(...).withoutPermit()` requires on-chain `FHE.allowPublic(ct)`.** Otherwise the threshold network refuses. Pair them.
6. **The `InEuintXX` struct doesn't match wagmi's ABI inference** — cast `as any` at the wagmi boundary, or build a typed wrapper.
7. **SSR-unsafe by default.** In Next.js, wrap the client in a Proxy so it lazy-instantiates only in the browser. See `references/concepts/init-singleton.md`.
8. **`issuer` must equal the connected signer.** Always derive `issuer` from `client.getSnapshot().account` — never hardcode. Hardcoding is the single most common cause of "Invalid issuer signature." See `references/concepts/permit-issuer-gotcha.md`.
9. **`/web` and `/node` are not interchangeable.** `/node` is a strict subset. Don't alias `web → node` in your bundler. See `references/concepts/entry-points-web-vs-node.md`.
10. **Declare `@cofhe/abi` explicitly and pin it with `@cofhe/sdk`.** `@cofhe/sdk` imports from it but doesn't declare it as a runtime dep. Pin both versions (e.g. via `pnpm-workspace.yaml` overrides) so transitives can't drift.
11. **Don't externalize `@cofhe/sdk` server-side.** In Next.js use `transpilePackages: ['@cofhe/sdk']`, NOT `serverExternalPackages`. See `references/concepts/bundler-config.md`.
Full rule list: `references/hard-rules.md`.
## The three decryption modes
| Mode | Use when | Returns | Requires on-chain |
|---|---|---|---|
| `decryptForView(ctHash, utype).execute()` | UI display only | `{ decryptedValue }` | `FHE.allow(ct, user)` + valid permit |
| `decryptForTx(ctHash).withPermit().execute()` | User will call back into a contract that runs `FHE.verifyDecryptResult` | `{ decryptedValue, signature }` | `FHE.allow(ct, user)` + valid permit |
| `decryptForTx(ctHash).withoutPermit().execute()` | Contract called `FHE.allowPublic`; anyone can decrypt | `{ decryptedValue, signature }` | `FHE.allowPublic(ct)` |
Decision tree: `references/decision-trees.md`.
## Default init flow
```
const config = createCofheConfig({ chains: [...] });
const cofheClient = createCofheClient(config);
// in your wallet-ready hook:
await cofheClient.connect(publicClient, walletClient);
```
For SSR / Next.js: wrap `cofheClient` in a Proxy in `services/cofhe-client.ts`. See `references/concepts/init-singleton.md`.
## Default encrypt flow
```
const [encrypted] = await cofheClient
.encryptInputs([Encryptable.uint64(secretAmount)])
.execute();
await writeContractAsync({
abi, functionName: 'submit',
args: [{
ctHash: encrypted.ctHash,
securityZone: encrypted.securityZone,
utype: encrypted.utype,
signature: encrypted.signature as `0x${string}`,
} as any],
});
```
## Default permit flow
Real form per canonical examples (e.g. `miniapp-equle`'s `usePermit.ts`). The first two positional args are `publicClient` / `walletClient` overrides; options is the third:
```
const permit = await cofheClient.permits.getOrCreateSelfPermit(
undefined,
undefined,
{
issuer: address,
name: `myapp-${gameId}`, // scope per-cycle if state cycles
expiration: Math.floor(Date.now() / 1000) + 30 * 24 * 3600, // 30 days, in SECONDS
}
);
const { decryptedValue } = await cofheClient
.decryptForView(ctHash, FheTypes.Uint64)
.execute();
```
Verify the exact signature against `node_modules/@cofhe/sdk/dist/permits.d.ts` — see `references/lookup-recipes.md`.
## Concepts to read on demand
- `init-singleton.md` — SSR-safe Proxy singleton (Next.js / wagmi).
- `entry-points-web-vs-node.md` — `/web` vs `/node` subpath imports and what each exports.
- `bundler-config.md` — full Next.js `next.config.js` and Vite `vite.config.ts` recipes for the SDK's WASM, top-level await, CJS interop. Includes the Vite blank-page diagnostic checklist.
- `encrypt-input.md` — `Encryptable.uintN`, the struct cast, multi-input batching.
- `decrypt-view-vs-tx.md` — the three modes and their pairings with on-chain `allow*`.
- `permits.md` — the three permit types, self-permit lifecycle, scoping, expiration, `permitVersion` re-render trick.
- `sharing-permits.md` — issuer/recipient flow for selective off-chain disclosure with concrete code.
- `permit-issuer-gotcha.md` — "Invalid issuer signature," EOA vs SA, ERC-6492 not-deployed pitfall.
- `permit-dedup.md` — avoiding double wallet popups under React strict mode / concurrent callers.
- `debugging-decryption.md` — diagnostic playbook: client state, on-chain `isAllowed`, retry, stale-cache.
- `error-handling.md` — typed `CofheError`, recoverable vs fatal patterns.
- `hooks-pattern.md` — `useCofhe`, `usePermit`, Zustand integration.
## Looking up @cofhe/sdk API surface
For method signatures, type names, error codes, or version-specific shapes, **never recall — look up**. See `references/lookup-recipes.md` for the canonical commands (prefer the user's installed `node_modules/@cofhe/sdk/dist/*.d.ts` over remote sources).
Files in this package (16)
- SKILL.md 6 KB
- references/decision-trees.md 2 KB
- references/hard-rules.md 6 KB
- references/lookup-recipes.md 5 KB
- references/concepts/bundler-config.md 7 KB
- references/concepts/debugging-decryption.md 7 KB
- references/concepts/decrypt-view-vs-tx.md 4 KB
- references/concepts/encrypt-input.md 3 KB
- references/concepts/entry-points-web-vs-node.md 3 KB
- references/concepts/error-handling.md 3 KB
- references/concepts/hooks-pattern.md 4 KB
- references/concepts/init-singleton.md 3 KB
- references/concepts/permit-dedup.md 4 KB
- references/concepts/permit-issuer-gotcha.md 6 KB
- references/concepts/permits.md 5 KB
- references/concepts/sharing-permits.md 6 KB
Versions
The database has no other skills named fhenix-sdk.
Database snapshot: 13.11.2026 · package version d886404f59c9 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 2 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100fhenix-tests
Use when writing or extending tests for confidential CoFHE code — Foundry mocks, Hardhat plugin, encrypted input fixtures, SDK decrypt flows (decryptForView and decryptForTx) in tests. Activates on .test.ts / .t.sol files importing FHE.sol, @cofhe/sdk, @cofhe/hardhat-plugin, or… - 100fhenix-contracts
Use when working on Solidity files importing @fhenixprotocol/cofhe-contracts/FHE.sol or fhenix-confidential-contracts, or using euint*/ebool/eaddress types. Teaches confidential contract patterns — branchless updates with FHE.select, the four ACL verbs, the two decryption flows,… - 91ritual-dapp-frontend
Frontend development for Ritual dApps with async transaction state machines, wagmi/viem hooks, and event subscriptions. Use when building React/Next.js frontends for Ritual. - 100viem-integration
Integrate EVM blockchains using viem. Use when user says "read blockchain data", "send transaction", "interact with smart contract", "connect to Ethereum", "use viem", "use wagmi", "wallet integration", "viem setup", or mentions blockchain/EVM development with TypeScript. - 100wagmi
wagmi is a set of React hooks for Ethereum, built on viem, for connecting wallets, reading contracts, sending transactions and switching chains. Use it when a user asks to connect wallets in React, read blockchain data in components, send transactions from a frontend, upgrade… - 100viem
This skill should be used when the user asks about "viem", "viem client", "viem actions", "TypeScript Ethereum", "createPublicClient", "createWalletClient", "parseEther", "formatEther", "readContract", "writeContract", or mentions using viem for blockchain interactions.