fhenix-client-sdk-encryption

Encrypt plaintext into InE* inputs with @cofhe/sdk encryptInputs + the Encryptable factory, then pass them into a contract call. Covers the 5-step ZK pipeline, the 2048-bit limit, builder options (setAccount/setChainId/onStep), and the EncryptedItemInput shape.

nickthelegend/fhenix-skills1 installsMITSynced Aug 22

Works with

Claude CodeCursorCodex CLIGitHub CopilotGemini CLI
---
name: fhenix-client-sdk-encryption
description: Encrypt plaintext into InE* inputs with @cofhe/sdk encryptInputs + the Encryptable factory, then pass them into a contract call. Covers the 5-step ZK pipeline, the 2048-bit limit, builder options (setAccount/setChainId/onStep), and the EncryptedItemInput shape.
license: MIT
---

# Fhenix Client SDK — Encrypting Inputs

## Overview
Values must be encrypted client-side before going on-chain. `encryptInputs([...])` takes `Encryptable.*` items, runs a ZK-proven encryption pipeline, and returns a typed tuple of `EncryptedItemInput` objects that map 1:1 to your contract's `InE*` struct parameters. The on-chain CoFHE library verifies each item's signature before using the ciphertext.

## Encrypt and call a contract
```typescript
import { Encryptable, assertCorrectEncryptedItemInput } from '@cofhe/sdk';

await cofheClient.connect(publicClient, walletClient);

const [inCount] = await cofheClient
  .encryptInputs([Encryptable.uint32(42n)])
  .execute();
assertCorrectEncryptedItemInput(inCount);

await contract.setCount(inCount); // Solidity: function setCount(InEuint32 _in)
```
A multi-value example returns a typed tuple mirroring the input array:
```typescript
const [eUint32, eBool, eAddress] = await cofheClient.encryptInputs([
  Encryptable.uint32(42n),
  Encryptable.bool(true),
  Encryptable.address('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'),
]).execute();
```

## Encryptable factory — type must match the Solidity param
| Factory | Value type | Solidity input |
| --- | --- | --- |
| `Encryptable.bool(v)` | `boolean` | `InEbool` |
| `Encryptable.uint8/16/32/64/128(v)` | `bigint \| string` | `InEuint8…128` |
| `Encryptable.address(v)` | `bigint \| string` | `InEaddress` |

Generic form: `Encryptable.create('uint32', 42n)`.

## The 5-step pipeline (what `.execute()` runs)
| Step | Description |
| --- | --- |
| `InitTfhe` | Lazy-init the TFHE WASM (no-op after first call) |
| `FetchKeys` | Fetch/cache FHE public key + CRS for the chain |
| `Pack` | Pack plaintext into a ZK list |
| `Prove` | Generate the zero-knowledge proof (ZKPoK); uses a Web Worker when available |
| `Verify` | Send proof to the CoFHE verifier; returns signed `EncryptedItemInput`s |

## Builder options
- `.execute()` — required, call last; returns `EncryptedItemInput[]`.
- `.setAccount(address)` — which address "owns"/may use the inputs on-chain (default: connected wallet).
- `.setChainId(chainId)` — target chain (default: connected chain).
- `.setUseWorker(bool)` — override Web Worker proving (default true; no-op in Node).
- `.onStep((step, ctx) => …)` — progress callback (`ctx.isStart`/`ctx.isEnd`/`ctx.duration`).

## EncryptedItemInput (result shape)
```typescript
type EncryptedItemInput = {
  ctHash: bigint;        // ciphertext hash registered with CoFHE
  securityZone: number;  // security zone used
  utype: FheTypes;       // Bool, Uint8…Uint160
  signature: string;     // CoFHE verifier signature authorizing this input
};
```
If hand-writing an ABI, the tuple order is `(ctHash, securityZone, utype, signature)`.

## Common pitfalls
- **Wrong `Encryptable` type** vs the Solidity `InE*` param (`uint32` vs `uint64`).
- **Wrong account/chain** — inputs are authorized for a specific `account + chainId`; overriding them can make the tx revert.
- **Bit limit** — a single `encryptInputs` call encrypts at most **2048 bits** total; exceeding throws `ZkPackFailed` (split into multiple calls).

## Source docs
- [`client-sdk/guides/encrypting-inputs.mdx`](../fhenix-docs/client-sdk/guides/encrypting-inputs.mdx)
- [`client-sdk/guides/writing-encrypted-data.mdx`](../fhenix-docs/client-sdk/guides/writing-encrypted-data.mdx)

## AI Agent Prompt
> "Encrypt a `uint64` amount and an `address` with `encryptInputs`, asserting the result, and call a `confidentialTransfer(address,InEuint64)` contract function via viem — handling the 2048-bit limit if more values are added."

More Security skills

azure-cost

microsoft/azure-skills

Azure cost management: query costs, forecast spending, optimize to reduce waste. WHEN: \"Azure costs\", \"Azure bill\", \"cost breakdown\", \"how much am I spending\", \"forecast spending\", \"optimize costs\", \"reduce spending\", \"orphaned resources\", \"rightsize VMs\", \"cost spike\", \"reduce storage costs\", \"AKS cost\". DO NOT USE FOR: deploying resources, provisioning, diagnostics, or security audits.

355.6k

entra-app-registration

microsoft/azure-skills

Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.

318.9k

azure-messaging

microsoft/azure-skills

Troubleshoot and resolve issues with Azure Messaging SDKs for Event Hubs and Service Bus. Covers connection failures, authentication errors, message processing issues, and SDK configuration problems. WHEN: event hub SDK error, service bus SDK issue, messaging connection failure, AMQP error, event processor host issue, message lock lost, message lock expired, lock renewal, lock renewal batch, send timeout, receiver disconnected, SDK troubleshooting, azure messaging SDK, event hub consumer, service bus queue issue, topic subscription error, enable logging event hub, service bus logging, eventhub python, servicebus java, eventhub javascript, servicebus dotnet, event hub checkpoint, event hub not receiving messages, service bus dead letter, batch processing lock, session lock expired, idle timeout, connection inactive, link detach, slow reconnect, session error, duplicate events, offset reset, receive batch.

310.3k

← All Security skills

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY