Creating Permits
After encryption, values can be passed into FHE-enabled smart contracts, and the contract can operate on this data securely, within its own logic. However, to ensure that only the respective user can view the processed (encrypted) data, permissions and sealing mechanisms are used. These ensure that data remains private and viewable exclusively by the user who owns it.Prerequisites
Before creating permits, ensure you have:- Cofhejs installed and initialized
- A web3 provider and signer configured
- Access to a Fhenix network (local or testnet)
sealoutput and decrypt. These operations are exposed and handled by cofhejs.
Purpose of Permits
Permissions serve two main purposes:- Verify User Identity: They ensure that the data access request comes from the correct user by verifying that the message is signed with the user’s private key.
- Sealing User Data: They provide a public key to “seal” the encrypted data, meaning it is encrypted in such a way that only the user holding the corresponding private key (stored securely on the user’s client) can decrypt it later.
Fhenix uses EIP712, a widely used Ethereum standard for signing structured data. This means: first, a user must sign a permit in their wallet to authenticate themselves and authorize the creation of the permit; second, permits are stored locally in local storage and can be reused for future interactions with the same contract. Currently, each contract that the user interacts with requires its own unique permit (subject to change).
Quick Start
Basic Integration
In a development environment, permit management can be handled automatically byCofhejs. When initialized with a valid provider and signer, the SDK will prompt users to sign a new permit, granting them access to their encrypted data:
When initialized with automatic permit generation, Cofhejs will prompt users to sign a permit automatically.
Production Setup
For production environments, you’ll want more control over the permit generation process. Disable automatic permit generation by settinggeneratePermit: false:
cofhejs.createPermit() to generate user permits. It’s recommended to inform users about the purpose of permits before requesting their signature.
Creating a Permit
Here’s the basic code for creating a permit:The permit is created and stored locally for future use with the same contract.
User Interface Example
Here’s an example modal that explains permits to users:cofhejs.unseal operations.
Sharing Permits
Overview
Sharing permits enables users to grant others access to their encrypted data in a secure way. The sharing process involves three steps:- Original data owner creates a sharing permit.
- Owner sends the permit to the recipient.
- Recipient activates the permit with their signature.
Implementation
Here’s how to implement permit sharing:Advanced Features
Permit Validation
Permits include built-in validation mechanisms:- Expiration: Permits automatically expire after 24 hours (configurable).
- Signature Verification: Ensures permits are only used by authorized parties.
- Chain Validation: Permits are bound to specific networks.
Custom Validators
You can implement custom validation logic by specifying a validator contract:Error Handling
Always handle permit operations with proper error checking:API Reference
SeePermitOptions interface for the complete list of options available when creating permits: