Overview
In Fhenix’s FHE system, data returned from smart contracts is “sealed” (internally re-encrypted since it already exists in an encrypted state) to maintain confidentiality during transmission. The unsealing process converts this encrypted data back into readable values using your permit’s sealing key pair. After encryption, the data can be securely processed by the contract and sealed with your public key (from your permit), and it is returned to you when you request it. To access and interpret this data, you must unseal it using your private key, which is securely stored on your device. The unsealing process is essential to ensure that only you can view the final result. When the contract returns the encrypted data to you, it remains sealed. This means the data is still encrypted with your public key and cannot be read until the corresponding private key is used to unlock it. Cofhejs provides a simple method to handle this.Basic Usage
Prerequisites
Before unsealing data, ensure you have:- Cofhejs initialized with a provider and signer
- A permit created for your address
- Encrypted data returned from your FHE-enabled smart contract
Simple Unsealing
The most straightforward way to unseal data is usingcofhejs.unseal():
Unsealing requires
Cofhejs to be initialized and for a permit to be created.Supported Types
The unsealing process supports all FHE data types:Advanced Usage
Direct Permit Unsealing
For lower-level control, you can use the Permit class directly to unseal data:Type Conversions
Internally, data types require specific handling when unsealed:cofhejs.unseal. Unsealing an encrypted boolean will return a bool, an encrypted address will return a 0x prefixed string, and an encrypted number will return a JavaScript BigInt.
You don’t need to manually handle type conversions when using
cofhejs.unseal() - it handles all conversions automatically based on the FHE type you specify.Return Types
When usingcofhejs.unseal(), the function returns a result object with the following structure:
data field will contain:
- BigInt for integer types (Uint8, Uint16, Uint32, Uint64, Uint128)
- boolean for Bool type
- string (with
0xprefix) for Address type