ACPs
ACPs (Access Control Permissions, formerly called permits) are EIP-712 signatures that authorize decryption of confidential data. The issuer field identifies who is accessing the data - the issuer must have been granted access on-chain via FHE.allow(handle, address). When an ACP is used, CoFHE validates it against the ACL contract to confirm that the issuer has access to the requested encrypted handle.
Each ACP includes a sealing keypair. The public key is sent to CoFHE so it can re-encrypt the data for the ACP holder. The private key stays client-side and is used to unseal the returned data. ACPs are stored locally and identified by a deterministic hash of their fields.
ACPs can be used to decrypt your own data (self ACPs), or to delegate your access to another party (sharing ACPs).
When do you need an ACP?
decryptForView: always requires an ACP.decryptForTx: depends on the contract's ACL policy for that handle (ctHashin code).- If the policy allows anyone to decrypt, you can use
.withoutACP(). - If the policy restricts decryption, you must use
.withACP(...).
- If the policy allows anyone to decrypt, you can use
Prerequisites
- Create and connect a client (see the client page).
ACPs are scoped to a chainId + account. The SDK uses the connected chain and account by default.
Quickstart
The recommended approach is to create (or reuse) a self ACP. Once created, it is stored and set as the active ACP for the connected chain and account.
await client.connect(publicClient, walletClient);
// Returns the active self ACP if one exists, otherwise creates and signs a new one.
const acp = await client.acp.getOrCreateSelfACP();After this, the active ACP is picked up automatically:
decryptForView(...).execute()uses the active ACP.decryptForTx(...).withACP().execute()uses the active ACP.
ACP types
The SDK supports three ACP types:
| Type | Who signs | Use case |
|---|---|---|
self | issuer only | Decrypt your own data (most common) |
sharing | issuer only | A shareable "offer" created by the issuer for a recipient |
recipient | recipient (and includes issuer signature) | The imported ACP after the recipient signs it |
Notes:
- An ACP includes a sealing keypair. The public key is sent to CoFHE for re-encryption. The private key stays client-side for unsealing.
- ACP
expirationis a unix timestamp in seconds. The default is the client'sdefaultACPExpiration(7 days), counted from the latest block. - When an ACP is created via
client.acp.*, it is automatically stored and set as the active ACP for the current chain and account.
Creating a self ACP
A self ACP lets you decrypt data that was allowed to your address. Use createSelf to always create a new ACP, or getOrCreateSelfACP to reuse an existing active ACP.
createSelf
await client.connect(publicClient, walletClient);
const acp = await client.acp.createSelf({
issuer: walletClient.account!.address,
name: 'My self ACP',
});
acp.type;
acp.hash;getOrCreateSelfACP
Only available via the client.acp API. Returns the active self ACP if one exists. Otherwise creates and signs a new one. This is the recommended approach for most applications.
await client.connect(publicClient, walletClient);
const acp = await client.acp.getOrCreateSelfACP();
acp.type;Sharing ACPs
Sharing ACPs let an issuer delegate their ACL access to a recipient. The recipient can then decrypt the issuer's data without needing their own FHE.allow. This flow may be useful for auditors or other parties that need to access data but do not have the ability to grant themselves access.
Issuer creates a sharing ACP
The issuer creates a sharing ACP specifying the recipient's address. The issuer's signature does not include a sealing key.
await client.connect(publicClient, walletClient);
const sharingACP = await client.acp.createSharing({
issuer: walletClient.account!.address,
recipient,
name: 'Share with recipient',
});Issuer exports the ACP
Export the ACP as a JSON blob and share it with the recipient.
const exported = ACPUtils.export(sharingACP);Recipient imports and signs
The recipient imports the exported JSON and signs it with their wallet. On import, a new sealing key is generated for the recipient. The recipient's sealing key is the one CoFHE uses for re-encryption. The resulting ACP is stored and set as active.
await client.connect(publicClient, walletClient);
const recipientACP = await client.acp.importShared(exported);
recipientACP.type;
recipientACP.hash;The imported ACP is named after its issuer ("Shared by 0x1234…abcd"); pass name to give it your own, e.g. importShared(exported, { name: 'Payroll from Bob' }). A name in the JSON is ignored.
To store the imported ACP without making it active, pass activate: false. Decrypts that use the active ACP keep using the current one, and the imported ACP is used only where you pass it, for example .withACP(recipientACP). This fits an app that shows someone else's shared data in one view while the rest of the app keeps using the user's own ACP.
const recipientACP = await client.acp.importShared(exported, { activate: false });In React, see ACPs in React.
Sharing on-chain
Instead of exporting JSON and sending it over a second channel, the issuer can post the share to the on-chain ACP share registry. The recipient finds it from any cofhesdk-enabled app and imports it directly — no copy-paste.
Configure the registry address per chain:
const config = createCofheConfig({
// ...
acp: {
sharingRegistry: { 11155111: '0x…' },
},
});Post a share
const sharingAcp = await client.acp.createSharing({
issuer: '0x…', // connected account
recipient: recipientAddress,
});
// posts the signed share payload to the registry
const { txHash, shareId } = await client.acp.shareOnChain(sharingAcp);Only signed sharing ACPs can be posted (same rule as export()), and only by their issuer. To retract a pending share, call client.acp.cancelShare(shareId).
Find and import incoming shares
// importable shares addressed to the connected account (unexpired, not revoked)
const incoming = await client.acp.getIncomingShares();
// fills in the recipient's sealing key, signs, stores and activates
// (pass { activate: false } to only store it, { name } to name it)
const acp = await client.acp.importFromChain(incoming[0]);
// optionally clean up the on-chain entry afterwards (or decline a share)
await client.acp.dismissShare(incoming[0].shareId);getIncomingShares lists only importable shares: expired shares and shares whose ACP was revoked are left out. A share whose event the node cannot serve yet (a node that lags behind its own sharesFor answer) is left out too and appears on a later read; it never fails the rest. client.acp.getShareFromChain(shareId) reads one share by id.
Mark shares for your app
Shares from every app land in the same registry. To tell yours apart, name your app in the config:
const config = createCofheConfig({
// ...
acp: { app: 'explorer.fhenix.io' },
});Every share this client creates then carries the app's key, keccak256('explorer.fhenix.io'), in its metadata, and getIncomingShares lists only the shares posted with that key. A client without app marks nothing and lists everything. The name itself is never on-chain; shareAppKey(app) from @cofhe/sdk/acps computes the key, and each IncomingShare exposes the one it carries as appKey.
An app that sends these writes through its own transaction path can use the same pieces from @cofhe/sdk/acps: ACP_SHARE_REGISTRY_ABI, ACP_REVOKER_ABI, toChainShare(acp) (the registry payload), computeShareId(acp) (the id the registry assigns), readSharesFor / readShare (shares read back from the registry) and getAclServedAddresses(publicClient, chainId) (the registry and default revoker the chain ACL serves). How the registry stores a share, and what posting costs, is in Share registry internals.
Labelling a SNAPSHOT share
A SNAPSHOT share (handles scope) lists ctHashes only, so the recipient cannot tell what each one is. The issuer can say, with one label per handle:
- a stored value: what a view function returned at a block, e.g. the issuer's
confidentialBalanceOfon a token; - an event value: a value carried by one log, e.g. the amount of a
ConfidentialTransfer; - or unlabelled, when the issuer prefers not to say.
Labels are written once, with the share, and cannot be changed afterwards. They are the issuer's claim: the recipient checks them against the chain before relying on them.
Add labels to a share
Pass labels to createSharing, one per handle and in the same order. viewFunctionLabel labels a value a view function returned, from the contract's ABI; eventLogLabel(log) labels a value a log carried, from the log as viem returns it (a receipt's logs, getLogs, getContractEvents). For a handle you don't want to describe, pass { kind: 'unlabelled' }.
import { ERC7984_ABI, eventLogLabel, viewFunctionLabel } from '@cofhe/sdk/acps';
import { parseEventLogs } from 'viem';
// the transfer whose amount is shared: its log, from the receipt
const { logs } = await publicClient.waitForTransactionReceipt({ hash: transferTxHash });
const [transferLog] = parseEventLogs({ abi: ERC7984_ABI, eventName: 'ConfidentialTransfer', logs });
const sharingAcp = await client.acp.createSharing({
issuer,
recipient: '0x…',
handles: [balanceHandle, transferHandle, otherHandle],
labels: [
viewFunctionLabel({
contract: token,
abi: ERC7984_ABI,
functionName: 'confidentialBalanceOf',
args: [issuer], // your own balance: stored as "the issuer", not as an address
block,
}),
eventLogLabel(transferLog), // the amount of that transfer
{ kind: 'unlabelled' }, // say nothing about this one
],
});The labels travel with the share whichever way you hand it over:
await client.acp.shareOnChain(sharingAcp); // on-chain
const exported = client.acp.export(sharingAcp); // or in the JSONTo post different labels than the ones on the ACP, pass them to shareOnChain(acp, { labels }).
In viewFunctionLabel, an argument equal to the issuer's address (your own, when you share your balance) is stored as "the issuer" rather than as an address: the SDK compresses it when it encodes the labels, and the recipient fills it in from the share. Arguments must be static ABI types (one 32-byte word each), and the ctHash is the first return word unless you pass returnWord. ERC7984_ABI holds the confidentialBalanceOf read and the ConfidentialTransfer event of a confidential token; any other contract's ABI works the same way.
Show and check the labels
On the recipient side, every IncomingShare carries its metadata (0x when posted without labels), and an imported ACP keeps it whichever way it came in — so both readers below take either one.
- Describe the labels for display with
describeShareMetadata(share, abis). Pass the ABIs of the contracts you know; a missing ABI never fails, it leavesfunction/eventasnull. - Verify them with
client.acp.verifyShareLabels, which checks each label against the chain and returns one result per handle.
import { describeShareMetadata } from '@cofhe/sdk/acps';
const [share] = await client.acp.getIncomingShares();
// one item per handle: kind, and function / event names and params from the ABIs you pass
const items = describeShareMetadata(share, { [token]: tokenAbi });
// one result per handle: 'verified' | 'mismatch' | 'unverifiable' | 'skipped'
const checks = await client.acp.verifyShareLabels(share, { verify: 'all' });| Result | Meaning |
|---|---|
'verified' | The chain confirms the label: the ctHash is where the issuer said it is. |
'mismatch' | The chain contradicts the label. Treat the handle as unlabelled, and the share with care. |
'verified' confirms the chain, not the contract: it proves the named contract returned the handle, and anyone can deploy a contract that does. So name a contract only when you know it (your token list), pass ABIs only for those, and show the rest as unknown contracts with their address. The labels are the issuer's claim about where a value came from; what the value is worth to you follows from the contract, which only you can vouch for.
| 'unverifiable' | The node could not answer; usually the state of an old block is gone (see below). |
| 'skipped' | Not checked, because of the verify mode. |
Both return null for a share without labels. Use verify to trade thoroughness for requests:
verify | Checks | Requests |
|---|---|---|
'all' (default) | every label | one getLogs per contract and block, one eth_call per stored value |
'events' | event values only | one getLogs per contract and block |
'none' | nothing; trust the labels as written | none |
In React, useCofheShareLabels(share, { verify, abis }) does both steps at once: see Share labels in React. The exact checks, and the byte layout of the labels, are in Share registry internals.
Checking an ACP on-chain
The ACL reverts when an ACP is expired, revoked or wrongly signed. client.acp.checkAccess runs the same checks and returns the outcome as a status, so an app can tell the user why instead of catching reverts:
// the ACP itself
const status = await client.acp.checkAccess(acp);
// the ACP and one encrypted value
const access = await client.acp.checkAccess(acp, ctHash);| Status | Meaning |
|---|---|
valid | The ACP passes the ACL checks (no handle given). |
allowed | The ACP may read the handle. |
out-of-scope | The ACP is valid, but its scope does not cover the handle. |
issuer-not-allowed | The issuer may not read the handle, so no ACP of theirs can. |
expired | Past its expiration. |
revoked | Disabled by its revoker (e.g. client.acp.revokeACP). |
invalid-issuer-signature / invalid-recipient-signature | A signature does not match. |
Each check is one view call to the ACL, plus a second only to tell out-of-scope from issuer-not-allowed. A network error still throws.
Active ACP management
The SDK tracks all stored ACPs and an active ACP hash per chainId + account. Creating or importing an ACP via client.acp.* automatically stores it and selects it as active, except for sharing ACPs and imports made with activate: false, which are only stored.
List stored ACPs
await client.connect(publicClient, walletClient);
const acps = client.acp.getACPs();
Object.keys(acps);Read / select the active ACP
await client.connect(publicClient, walletClient);
const active = client.acp.getActiveACP();
active?.hash;
client.acp.selectActiveACP(someACPHash);Removing ACPs
await client.connect(publicClient, walletClient);
client.acp.removeACP(acpHash);
client.acp.removeActiveACP();Persistence and security
- The SDK persists ACPs in a store keyed by
chainId + account. - In web and React environments, this store uses
localStorageunder the keycofhesdk-acps. - A stored ACP includes the sealing private key. Treat it like a secret.
- Never share serialized ACPs with other users.
- To share access, use
ACPUtils.export(...)which strips sensitive fields.